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