2020-04-24 19:32:48 +08:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Western Digital Corporation or its affiliates.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anup Patel <anup.patel@wdc.com>
|
|
|
|
*/
|
|
|
|
|
2021-11-06 17:54:51 +08:00
|
|
|
#include <sbi/sbi_console.h>
|
2021-05-20 23:46:25 +08:00
|
|
|
#include <sbi/sbi_error.h>
|
2020-04-24 19:32:48 +08:00
|
|
|
#include <sbi/sbi_scratch.h>
|
|
|
|
#include <sbi_utils/fdt/fdt_helper.h>
|
|
|
|
#include <sbi_utils/reset/fdt_reset.h>
|
|
|
|
|
2021-07-22 18:53:59 +08:00
|
|
|
extern struct fdt_reset fdt_poweroff_gpio;
|
2021-07-13 11:23:45 +08:00
|
|
|
extern struct fdt_reset fdt_reset_gpio;
|
2020-04-24 19:32:48 +08:00
|
|
|
extern struct fdt_reset fdt_reset_htif;
|
2021-09-09 10:10:08 +08:00
|
|
|
extern struct fdt_reset fdt_reset_sifive_test;
|
2021-09-09 10:10:09 +08:00
|
|
|
extern struct fdt_reset fdt_reset_sunxi_wdt;
|
2021-04-18 00:26:17 +08:00
|
|
|
extern struct fdt_reset fdt_reset_thead;
|
2020-04-24 19:32:48 +08:00
|
|
|
|
|
|
|
static struct fdt_reset *reset_drivers[] = {
|
2021-07-22 18:53:59 +08:00
|
|
|
&fdt_poweroff_gpio,
|
2021-07-13 11:23:45 +08:00
|
|
|
&fdt_reset_gpio,
|
2020-04-24 19:32:48 +08:00
|
|
|
&fdt_reset_htif,
|
2021-09-09 10:10:08 +08:00
|
|
|
&fdt_reset_sifive_test,
|
2021-09-09 10:10:09 +08:00
|
|
|
&fdt_reset_sunxi_wdt,
|
2021-04-18 00:26:17 +08:00
|
|
|
&fdt_reset_thead,
|
2020-04-24 19:32:48 +08:00
|
|
|
};
|
|
|
|
|
2021-11-10 17:42:26 +08:00
|
|
|
int fdt_reset_driver_init(void *fdt, struct fdt_reset *drv)
|
2020-04-24 19:32:48 +08:00
|
|
|
{
|
2021-11-10 17:42:26 +08:00
|
|
|
int noff, rc = SBI_ENODEV;
|
2020-04-24 19:32:48 +08:00
|
|
|
const struct fdt_match *match;
|
|
|
|
|
2021-11-10 17:42:26 +08:00
|
|
|
noff = fdt_find_match(fdt, -1, drv->match_table, &match);
|
|
|
|
if (noff < 0)
|
|
|
|
return SBI_ENODEV;
|
2020-04-24 19:32:48 +08:00
|
|
|
|
2021-11-10 17:42:26 +08:00
|
|
|
if (drv->init) {
|
|
|
|
rc = drv->init(fdt, noff, match);
|
|
|
|
if (rc && rc != SBI_ENODEV) {
|
|
|
|
sbi_printf("%s: %s init failed, %d\n",
|
|
|
|
__func__, match->compatible, rc);
|
2020-04-24 19:32:48 +08:00
|
|
|
}
|
|
|
|
}
|
2021-11-10 17:42:26 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fdt_reset_init(void)
|
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
void *fdt = fdt_get_address();
|
|
|
|
|
|
|
|
for (pos = 0; pos < array_size(reset_drivers); pos++)
|
|
|
|
fdt_reset_driver_init(fdt, reset_drivers[pos]);
|
2020-04-24 19:32:48 +08:00
|
|
|
}
|