forked from Mirrors/opensbi
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
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user