1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2019 Pepperl+Fuchs
4 * Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
5 */
6
7 #include <common.h>
8 #include <dm.h>
9 #include <errno.h>
10 #include <sysreset.h>
11 #include <asm/io.h>
12 #include <asm/arch/reset_manager.h>
13 #include <linux/bitops.h>
14
15 struct socfpga_sysreset_data {
16 void __iomem *rstmgr_base;
17 };
18
socfpga_sysreset_request(struct udevice * dev,enum sysreset_t type)19 static int socfpga_sysreset_request(struct udevice *dev,
20 enum sysreset_t type)
21 {
22 struct socfpga_sysreset_data *data = dev_get_priv(dev);
23
24 switch (type) {
25 case SYSRESET_WARM:
26 writel(BIT(RSTMGR_CTRL_SWWARMRSTREQ_LSB),
27 data->rstmgr_base + RSTMGR_CTRL);
28 break;
29 case SYSRESET_COLD:
30 writel(BIT(RSTMGR_CTRL_SWCOLDRSTREQ_LSB),
31 data->rstmgr_base + RSTMGR_CTRL);
32 break;
33 default:
34 return -EPROTONOSUPPORT;
35 }
36 return -EINPROGRESS;
37 }
38
socfpga_sysreset_probe(struct udevice * dev)39 static int socfpga_sysreset_probe(struct udevice *dev)
40 {
41 struct socfpga_sysreset_data *data = dev_get_priv(dev);
42
43 data->rstmgr_base = dev_read_addr_ptr(dev);
44 return 0;
45 }
46
47 static struct sysreset_ops socfpga_sysreset = {
48 .request = socfpga_sysreset_request,
49 };
50
51 U_BOOT_DRIVER(sysreset_socfpga) = {
52 .id = UCLASS_SYSRESET,
53 .name = "socfpga_sysreset",
54 .priv_auto = sizeof(struct socfpga_sysreset_data),
55 .ops = &socfpga_sysreset,
56 .probe = socfpga_sysreset_probe,
57 };
58