mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 15:31:22 +01:00
lib: utils/regmap: Use FDT node offset as regmap ID
Since the FDT is not modified during driver initialization, node offsets are just as suitable as phandles for use as identifiers: they are stable and unique. With this change, it is no longer necessary to pass the phandle to the driver init functions, so these init functions now use the same prototype as other kinds of drivers. This matches what is already done for I2C adapters. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:

committed by
Anup Patel

parent
d71150ee70
commit
9782b8847d
@@ -17,7 +17,7 @@ struct fdt_phandle_args;
|
|||||||
/** FDT based regmap driver */
|
/** FDT based regmap driver */
|
||||||
struct fdt_regmap {
|
struct fdt_regmap {
|
||||||
const struct fdt_match *match_table;
|
const struct fdt_match *match_table;
|
||||||
int (*init)(const void *fdt, int nodeoff, u32 phandle,
|
int (*init)(const void *fdt, int nodeoff,
|
||||||
const struct fdt_match *match);
|
const struct fdt_match *match);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
extern struct fdt_regmap *fdt_regmap_drivers[];
|
extern struct fdt_regmap *fdt_regmap_drivers[];
|
||||||
extern unsigned long fdt_regmap_drivers_size;
|
extern unsigned long fdt_regmap_drivers_size;
|
||||||
|
|
||||||
static int fdt_regmap_init(const void *fdt, int nodeoff, u32 phandle)
|
static int fdt_regmap_init(const void *fdt, int nodeoff)
|
||||||
{
|
{
|
||||||
int pos, rc;
|
int pos, rc;
|
||||||
struct fdt_regmap *drv;
|
struct fdt_regmap *drv;
|
||||||
@@ -27,7 +27,7 @@ static int fdt_regmap_init(const void *fdt, int nodeoff, u32 phandle)
|
|||||||
drv = fdt_regmap_drivers[pos];
|
drv = fdt_regmap_drivers[pos];
|
||||||
match = fdt_match_node(fdt, nodeoff, drv->match_table);
|
match = fdt_match_node(fdt, nodeoff, drv->match_table);
|
||||||
if (match && drv->init) {
|
if (match && drv->init) {
|
||||||
rc = drv->init(fdt, nodeoff, phandle, match);
|
rc = drv->init(fdt, nodeoff, match);
|
||||||
if (rc == SBI_ENODEV)
|
if (rc == SBI_ENODEV)
|
||||||
continue;
|
continue;
|
||||||
if (rc)
|
if (rc)
|
||||||
@@ -39,20 +39,20 @@ static int fdt_regmap_init(const void *fdt, int nodeoff, u32 phandle)
|
|||||||
return SBI_ENOSYS;
|
return SBI_ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fdt_regmap_find(const void *fdt, int nodeoff, u32 phandle,
|
static int fdt_regmap_find(const void *fdt, int nodeoff,
|
||||||
struct regmap **out_rmap)
|
struct regmap **out_rmap)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
struct regmap *rmap = regmap_find(phandle);
|
struct regmap *rmap = regmap_find(nodeoff);
|
||||||
|
|
||||||
if (!rmap) {
|
if (!rmap) {
|
||||||
/* Regmap not found so initialize matching driver */
|
/* Regmap not found so initialize matching driver */
|
||||||
rc = fdt_regmap_init(fdt, nodeoff, phandle);
|
rc = fdt_regmap_init(fdt, nodeoff);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* Try to find regmap again */
|
/* Try to find regmap again */
|
||||||
rmap = regmap_find(phandle);
|
rmap = regmap_find(nodeoff);
|
||||||
if (!rmap)
|
if (!rmap)
|
||||||
return SBI_ENOSYS;
|
return SBI_ENOSYS;
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ int fdt_regmap_get_by_phandle(const void *fdt, u32 phandle,
|
|||||||
if (pnodeoff < 0)
|
if (pnodeoff < 0)
|
||||||
return pnodeoff;
|
return pnodeoff;
|
||||||
|
|
||||||
return fdt_regmap_find(fdt, pnodeoff, phandle, out_rmap);
|
return fdt_regmap_find(fdt, pnodeoff, out_rmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdt_regmap_get(const void *fdt, int nodeoff, struct regmap **out_rmap)
|
int fdt_regmap_get(const void *fdt, int nodeoff, struct regmap **out_rmap)
|
||||||
|
@@ -159,7 +159,7 @@ static int regmap_syscon_write_be32(struct regmap *rmap, unsigned int reg,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regmap_syscon_init(const void *fdt, int nodeoff, u32 phandle,
|
static int regmap_syscon_init(const void *fdt, int nodeoff,
|
||||||
const struct fdt_match *match)
|
const struct fdt_match *match)
|
||||||
{
|
{
|
||||||
struct syscon_regmap *srm;
|
struct syscon_regmap *srm;
|
||||||
@@ -188,7 +188,7 @@ static int regmap_syscon_init(const void *fdt, int nodeoff, u32 phandle,
|
|||||||
goto fail_free_syscon;
|
goto fail_free_syscon;
|
||||||
srm->addr = addr;
|
srm->addr = addr;
|
||||||
|
|
||||||
srm->rmap.id = phandle;
|
srm->rmap.id = nodeoff;
|
||||||
srm->rmap.reg_shift = 0;
|
srm->rmap.reg_shift = 0;
|
||||||
srm->rmap.reg_stride = srm->reg_io_width * 8;
|
srm->rmap.reg_stride = srm->reg_io_width * 8;
|
||||||
srm->rmap.reg_base = 0;
|
srm->rmap.reg_base = 0;
|
||||||
|
Reference in New Issue
Block a user