lib: utils/regmap: Use fdt_driver for initialization

The regmap driver subsystem does not need any extra data, so it can use
`struct fdt_driver` directly. It always initializes the driver for a
specific DT node.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Samuel Holland
2024-11-11 14:02:52 -08:00
committed by Anup Patel
parent 5fa510c5f6
commit 1f8db2f18f
4 changed files with 6 additions and 34 deletions

View File

@@ -10,17 +10,11 @@
#ifndef __FDT_REGMAP_H__ #ifndef __FDT_REGMAP_H__
#define __FDT_REGMAP_H__ #define __FDT_REGMAP_H__
#include <sbi_utils/fdt/fdt_driver.h>
#include <sbi_utils/regmap/regmap.h> #include <sbi_utils/regmap/regmap.h>
struct fdt_phandle_args; struct fdt_phandle_args;
/** FDT based regmap driver */
struct fdt_regmap {
const struct fdt_match *match_table;
int (*init)(const void *fdt, int nodeoff,
const struct fdt_match *match);
};
/** Get regmap instance based on phandle */ /** Get regmap instance based on phandle */
int fdt_regmap_get_by_phandle(const void *fdt, u32 phandle, int fdt_regmap_get_by_phandle(const void *fdt, u32 phandle,
struct regmap **out_rmap); struct regmap **out_rmap);

View File

@@ -13,30 +13,7 @@
#include <sbi_utils/regmap/fdt_regmap.h> #include <sbi_utils/regmap/fdt_regmap.h>
/* List of FDT regmap drivers generated at compile time */ /* List of FDT regmap drivers generated at compile time */
extern struct fdt_regmap *const fdt_regmap_drivers[]; extern const struct fdt_driver *const fdt_regmap_drivers[];
static int fdt_regmap_init(const void *fdt, int nodeoff)
{
int pos, rc;
struct fdt_regmap *drv;
const struct fdt_match *match;
/* Try all I2C drivers one-by-one */
for (pos = 0; fdt_regmap_drivers[pos]; pos++) {
drv = fdt_regmap_drivers[pos];
match = fdt_match_node(fdt, nodeoff, drv->match_table);
if (match && drv->init) {
rc = drv->init(fdt, nodeoff, match);
if (rc == SBI_ENODEV)
continue;
if (rc)
return rc;
return 0;
}
}
return SBI_ENOSYS;
}
static int fdt_regmap_find(const void *fdt, int nodeoff, static int fdt_regmap_find(const void *fdt, int nodeoff,
struct regmap **out_rmap) struct regmap **out_rmap)
@@ -46,7 +23,8 @@ static int fdt_regmap_find(const void *fdt, int 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); rc = fdt_driver_init_by_offset(fdt, nodeoff,
fdt_regmap_drivers);
if (rc) if (rc)
return rc; return rc;

View File

@@ -1,3 +1,3 @@
HEADER: sbi_utils/regmap/fdt_regmap.h HEADER: sbi_utils/regmap/fdt_regmap.h
TYPE: struct fdt_regmap TYPE: const struct fdt_driver
NAME: fdt_regmap_drivers NAME: fdt_regmap_drivers

View File

@@ -263,7 +263,7 @@ static const struct fdt_match regmap_syscon_match[] = {
{ }, { },
}; };
struct fdt_regmap fdt_regmap_syscon = { const struct fdt_driver fdt_regmap_syscon = {
.match_table = regmap_syscon_match, .match_table = regmap_syscon_match,
.init = regmap_syscon_init, .init = regmap_syscon_init,
}; };