1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2021, Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
4  */
5 
6 #include <dm.h>
7 #include <errno.h>
8 #include <log.h>
9 #include <sysreset.h>
10 #include <asm/sbi.h>
11 
12 static 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 
sbi_sysreset_request(struct udevice * dev,enum sysreset_t type)19 static 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 
sbi_sysreset_probe(struct udevice * dev)29 static 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 
41 static struct sysreset_ops sbi_sysreset_ops = {
42 	.request = sbi_sysreset_request,
43 };
44 
45 U_BOOT_DRIVER(sbi_sysreset) = {
46 	.name = "sbi-sysreset",
47 	.id = UCLASS_SYSRESET,
48 	.ops = &sbi_sysreset_ops,
49 	.probe = sbi_sysreset_probe,
50 };
51