mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 15:31:22 +01:00
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:

committed by
Anup Patel

parent
1f8db2f18f
commit
6d9ad492db
@@ -11,19 +11,10 @@
|
|||||||
#define __FDT_RESET_H__
|
#define __FDT_RESET_H__
|
||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
#include <sbi_utils/fdt/fdt_driver.h>
|
||||||
struct fdt_reset {
|
|
||||||
const struct fdt_match *match_table;
|
|
||||||
int (*init)(const void *fdt, int nodeoff, const struct fdt_match *match);
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef CONFIG_FDT_RESET
|
#ifdef CONFIG_FDT_RESET
|
||||||
|
|
||||||
/**
|
|
||||||
* fdt_reset_driver_init() - initialize reset driver based on the device-tree
|
|
||||||
*/
|
|
||||||
int fdt_reset_driver_init(const void *fdt, struct fdt_reset *drv);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_reset_init() - initialize reset drivers based on the device-tree
|
* fdt_reset_init() - initialize reset drivers based on the device-tree
|
||||||
*
|
*
|
||||||
@@ -33,10 +24,6 @@ void fdt_reset_init(const void *fdt);
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static inline int fdt_reset_driver_init(const void *fdt, struct fdt_reset *drv)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static inline void fdt_reset_init(const void *fdt) { }
|
static inline void fdt_reset_init(const void *fdt) { }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -7,44 +7,12 @@
|
|||||||
* Anup Patel <anup.patel@wdc.com>
|
* 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>
|
#include <sbi_utils/reset/fdt_reset.h>
|
||||||
|
|
||||||
/* List of FDT reset drivers generated at compile time */
|
/* List of FDT reset drivers generated at compile time */
|
||||||
extern struct fdt_reset *const fdt_reset_drivers[];
|
extern const struct fdt_driver *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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fdt_reset_init(const void *fdt)
|
void fdt_reset_init(const void *fdt)
|
||||||
{
|
{
|
||||||
int pos;
|
fdt_driver_init_all(fdt, fdt_reset_drivers);
|
||||||
|
|
||||||
for (pos = 0; fdt_reset_drivers[pos]; pos++)
|
|
||||||
fdt_reset_driver_init(fdt, fdt_reset_drivers[pos]);
|
|
||||||
}
|
}
|
||||||
|
@@ -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,
|
.match_table = atcwdt200_reset_match,
|
||||||
.init = atcwdt200_reset_init,
|
.init = atcwdt200_reset_init,
|
||||||
};
|
};
|
||||||
|
@@ -1,3 +1,3 @@
|
|||||||
HEADER: sbi_utils/reset/fdt_reset.h
|
HEADER: sbi_utils/reset/fdt_reset.h
|
||||||
TYPE: struct fdt_reset
|
TYPE: const struct fdt_driver
|
||||||
NAME: fdt_reset_drivers
|
NAME: fdt_reset_drivers
|
||||||
|
@@ -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,
|
.match_table = gpio_poweroff_match,
|
||||||
.init = gpio_reset_init,
|
.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,
|
.match_table = gpio_reset_match,
|
||||||
.init = gpio_reset_init,
|
.init = gpio_reset_init,
|
||||||
};
|
};
|
||||||
|
@@ -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,
|
.match_table = htif_reset_match,
|
||||||
.init = htif_reset_init
|
.init = htif_reset_init
|
||||||
};
|
};
|
||||||
|
@@ -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,
|
.match_table = sg2042_mcu_reset_match,
|
||||||
.init = sg2042_mcu_reset_init,
|
.init = sg2042_mcu_reset_init,
|
||||||
};
|
};
|
||||||
|
@@ -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,
|
.match_table = sunxi_wdt_reset_match,
|
||||||
.init = sunxi_wdt_reset_init,
|
.init = sunxi_wdt_reset_init,
|
||||||
};
|
};
|
||||||
|
@@ -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,
|
.match_table = syscon_poweroff_match,
|
||||||
.init = syscon_reset_init,
|
.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,
|
.match_table = syscon_reboot_match,
|
||||||
.init = syscon_reset_init,
|
.init = syscon_reset_init,
|
||||||
};
|
};
|
||||||
|
@@ -209,11 +209,16 @@ static const struct fdt_match da9063_reset_match[] = {
|
|||||||
{ },
|
{ },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fdt_reset fdt_reset_da9063 = {
|
const struct fdt_driver fdt_reset_da9063 = {
|
||||||
.match_table = da9063_reset_match,
|
.match_table = da9063_reset_match,
|
||||||
.init = da9063_reset_init,
|
.init = da9063_reset_init,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct fdt_driver *const sifive_fu740_reset_drivers[] = {
|
||||||
|
&fdt_reset_da9063,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
static u64 sifive_fu740_tlbr_flush_limit(const struct fdt_match *match)
|
static u64 sifive_fu740_tlbr_flush_limit(const struct fdt_match *match)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -232,7 +237,7 @@ static int sifive_fu740_final_init(bool cold_boot, void *fdt,
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (cold_boot) {
|
if (cold_boot) {
|
||||||
rc = fdt_reset_driver_init(fdt, &fdt_reset_da9063);
|
rc = fdt_driver_init_one(fdt, sifive_fu740_reset_drivers);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_printf("%s: failed to find da9063 for reset\n",
|
sbi_printf("%s: failed to find da9063 for reset\n",
|
||||||
__func__);
|
__func__);
|
||||||
|
@@ -227,11 +227,16 @@ static const struct fdt_match pm_reset_match[] = {
|
|||||||
{ },
|
{ },
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct fdt_reset fdt_reset_pmic = {
|
static const struct fdt_driver fdt_reset_pmic = {
|
||||||
.match_table = pm_reset_match,
|
.match_table = pm_reset_match,
|
||||||
.init = pm_reset_init,
|
.init = pm_reset_init,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct fdt_driver *const starfive_jh7110_reset_drivers[] = {
|
||||||
|
&fdt_reset_pmic,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
static int starfive_jh7110_inst_init(const void *fdt)
|
static int starfive_jh7110_inst_init(const void *fdt)
|
||||||
{
|
{
|
||||||
int noff, rc = 0;
|
int noff, rc = 0;
|
||||||
@@ -281,7 +286,7 @@ static int starfive_jh7110_final_init(bool cold_boot, void *fdt,
|
|||||||
const struct fdt_match *match)
|
const struct fdt_match *match)
|
||||||
{
|
{
|
||||||
if (cold_boot) {
|
if (cold_boot) {
|
||||||
fdt_reset_driver_init(fdt, &fdt_reset_pmic);
|
fdt_driver_init_one(fdt, starfive_jh7110_reset_drivers);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user