lib: utils/reset: Use fdt_driver for initialization

The reset driver subsystem does not need any extra data, so it can use
`struct fdt_driver` directly. The generic fdt_reset_init() performs a
best-effort initialization of all matching DT nodes. Platform-specific
logic expects exactly one DT node to match a single driver. This is
accomplished by using fdt_driver_init_one() with a local list containing
that one driver.

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:53 -08:00
committed by Anup Patel
parent 1f8db2f18f
commit 6d9ad492db
11 changed files with 26 additions and 61 deletions

View File

@@ -7,44 +7,12 @@
* Anup Patel <anup.patel@wdc.com>
*/
#include <sbi/sbi_console.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_scratch.h>
#include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/reset/fdt_reset.h>
/* List of FDT reset drivers generated at compile time */
extern struct fdt_reset *const fdt_reset_drivers[];
int fdt_reset_driver_init(const void *fdt, struct fdt_reset *drv)
{
int noff, rc, cnt = 0;
const struct fdt_match *match;
noff = -1;
while ((noff = fdt_find_match(fdt, noff,
drv->match_table, &match)) >= 0) {
if (!fdt_node_is_enabled(fdt, noff))
continue;
if (drv->init) {
rc = drv->init(fdt, noff, match);
if (!rc)
cnt++;
else if (rc != SBI_ENODEV) {
sbi_printf("%s: %s init failed, %d\n",
__func__, match->compatible, rc);
}
}
}
return cnt > 0 ? 0 : SBI_ENODEV;
}
extern const struct fdt_driver *const fdt_reset_drivers[];
void fdt_reset_init(const void *fdt)
{
int pos;
for (pos = 0; fdt_reset_drivers[pos]; pos++)
fdt_reset_driver_init(fdt, fdt_reset_drivers[pos]);
fdt_driver_init_all(fdt, fdt_reset_drivers);
}

View File

@@ -111,7 +111,7 @@ static const struct fdt_match atcwdt200_reset_match[] = {
{},
};
struct fdt_reset fdt_reset_atcwdt200 = {
const struct fdt_driver fdt_reset_atcwdt200 = {
.match_table = atcwdt200_reset_match,
.init = atcwdt200_reset_init,
};

View File

@@ -1,3 +1,3 @@
HEADER: sbi_utils/reset/fdt_reset.h
TYPE: struct fdt_reset
TYPE: const struct fdt_driver
NAME: fdt_reset_drivers

View File

@@ -153,7 +153,7 @@ static const struct fdt_match gpio_poweroff_match[] = {
{ },
};
struct fdt_reset fdt_poweroff_gpio = {
const struct fdt_driver fdt_poweroff_gpio = {
.match_table = gpio_poweroff_match,
.init = gpio_reset_init,
};
@@ -163,7 +163,7 @@ static const struct fdt_match gpio_reset_match[] = {
{ },
};
struct fdt_reset fdt_reset_gpio = {
const struct fdt_driver fdt_reset_gpio = {
.match_table = gpio_reset_match,
.init = gpio_reset_init,
};

View File

@@ -32,7 +32,7 @@ static const struct fdt_match htif_reset_match[] = {
{ },
};
struct fdt_reset fdt_reset_htif = {
const struct fdt_driver fdt_reset_htif = {
.match_table = htif_reset_match,
.init = htif_reset_init
};

View File

@@ -108,7 +108,7 @@ static const struct fdt_match sg2042_mcu_reset_match[] = {
{ },
};
struct fdt_reset fdt_reset_sg2042_mcu = {
const struct fdt_driver fdt_reset_sg2042_mcu = {
.match_table = sg2042_mcu_reset_match,
.init = sg2042_mcu_reset_init,
};

View File

@@ -71,7 +71,7 @@ static const struct fdt_match sunxi_wdt_reset_match[] = {
{ },
};
struct fdt_reset fdt_reset_sunxi_wdt = {
const struct fdt_driver fdt_reset_sunxi_wdt = {
.match_table = sunxi_wdt_reset_match,
.init = sunxi_wdt_reset_init,
};

View File

@@ -151,7 +151,7 @@ static const struct fdt_match syscon_poweroff_match[] = {
{ },
};
struct fdt_reset fdt_syscon_poweroff = {
const struct fdt_driver fdt_syscon_poweroff = {
.match_table = syscon_poweroff_match,
.init = syscon_reset_init,
};
@@ -161,7 +161,7 @@ static const struct fdt_match syscon_reboot_match[] = {
{ },
};
struct fdt_reset fdt_syscon_reboot = {
const struct fdt_driver fdt_syscon_reboot = {
.match_table = syscon_reboot_match,
.init = syscon_reset_init,
};