blob: 5e8090d62bfc7d66c487937eb78ec78b25b8918a [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
Tom Riniabb9a042024-05-18 20:20:43 -06006#include <common.h>
Heinrich Schuchardtcc382ff2021-09-12 21:11:46 +02007#include <dm.h>
8#include <errno.h>
9#include <log.h>
10#include <sysreset.h>
11#include <asm/sbi.h>
12
13static 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
20static 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
30static 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
42static struct sysreset_ops sbi_sysreset_ops = {
43 .request = sbi_sysreset_request,
44};
45
46U_BOOT_DRIVER(sbi_sysreset) = {
47 .name = "sbi-sysreset",
48 .id = UCLASS_SYSRESET,
49 .ops = &sbi_sysreset_ops,
50 .probe = sbi_sysreset_probe,
51};