blob: 458191206b2c89a05dc0be4880eb16c2df61122c [file] [log] [blame]
Heinrich Schuchardtcc382ff2021-09-12 21:11:46 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2021, Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
4 */
5
Heinrich Schuchardtcc382ff2021-09-12 21:11:46 +02006#include <dm.h>
7#include <errno.h>
8#include <log.h>
9#include <sysreset.h>
10#include <asm/sbi.h>
11
12static enum sbi_srst_reset_type reset_type_map[SYSRESET_COUNT] = {
13 [SYSRESET_WARM] = SBI_SRST_RESET_TYPE_WARM_REBOOT,
14 [SYSRESET_COLD] = SBI_SRST_RESET_TYPE_COLD_REBOOT,
15 [SYSRESET_POWER] = SBI_SRST_RESET_TYPE_COLD_REBOOT,
16 [SYSRESET_POWER_OFF] = SBI_SRST_RESET_TYPE_SHUTDOWN,
17};
18
19static int sbi_sysreset_request(struct udevice *dev, enum sysreset_t type)
20{
21 enum sbi_srst_reset_type reset_type;
22
23 reset_type = reset_type_map[type];
24 sbi_srst_reset(reset_type, SBI_SRST_RESET_REASON_NONE);
25
26 return -EINPROGRESS;
27}
28
29static int sbi_sysreset_probe(struct udevice *dev)
30{
31 long have_reset;
32
33 have_reset = sbi_probe_extension(SBI_EXT_SRST);
34 if (have_reset)
35 return 0;
36
37 log_warning("SBI has no system reset extension\n");
38 return -ENOENT;
39}
40
41static struct sysreset_ops sbi_sysreset_ops = {
42 .request = sbi_sysreset_request,
43};
44
45U_BOOT_DRIVER(sbi_sysreset) = {
46 .name = "sbi-sysreset",
47 .id = UCLASS_SYSRESET,
48 .ops = &sbi_sysreset_ops,
49 .probe = sbi_sysreset_probe,
50};