1 // SPDX-License-Identifier: GPL-2.0
2
3 #include <common.h>
4 #include <dm.h>
5 #include <misc.h>
6 #include <reset.h>
7 #include <reset-uclass.h>
8 #include <wdt.h>
9 #include <asm/io.h>
10 #include <asm/arch/scu_ast2400.h>
11
12 struct ast2400_reset_priv {
13 /* WDT used to perform resets. */
14 struct udevice *wdt;
15 struct ast2400_scu *scu;
16 };
17
ast2400_reset_deassert(struct reset_ctl * reset_ctl)18 static int ast2400_reset_deassert(struct reset_ctl *reset_ctl)
19 {
20 struct ast2400_reset_priv *priv = dev_get_priv(reset_ctl->dev);
21 struct ast2400_scu *scu = priv->scu;
22 int ret = 0;
23
24 debug("ast2400_reset_deassert reset_ctl->id %ld \n", reset_ctl->id);
25 clrbits_le32(&scu->sysreset_ctrl1 , BIT(reset_ctl->id));
26
27 return ret;
28 }
29
ast2400_reset_assert(struct reset_ctl * reset_ctl)30 static int ast2400_reset_assert(struct reset_ctl *reset_ctl)
31 {
32 struct ast2400_reset_priv *priv = dev_get_priv(reset_ctl->dev);
33 struct ast2400_scu *scu = priv->scu;
34 // u32 reset_mode, reset_mask;
35 // bool reset_sdram;
36 int ret = 0;
37
38 debug("ast2400_reset_assert reset_ctl->id %ld \n", reset_ctl->id);
39 setbits_le32(&scu->sysreset_ctrl1 , BIT(reset_ctl->id));
40
41 return ret;
42 }
43
44
ast2400_reset_request(struct reset_ctl * reset_ctl)45 static int ast2400_reset_request(struct reset_ctl *reset_ctl)
46 {
47 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
48 reset_ctl->dev, reset_ctl->id);
49
50 return 0;
51 }
52
ast2400_reset_probe(struct udevice * dev)53 static int ast2400_reset_probe(struct udevice *dev)
54 {
55 struct ast2400_reset_priv *priv = dev_get_priv(dev);
56 struct udevice *clk_dev;
57 int ret = 0;
58
59 /* find SCU base address from clock device */
60 ret = uclass_get_device_by_driver(UCLASS_CLK, DM_GET_DRIVER(aspeed_scu),
61 &clk_dev);
62 if (ret) {
63 debug("clock device not found\n");
64 return ret;
65 }
66
67 priv->scu = devfdt_get_addr_ptr(clk_dev);
68 if (IS_ERR(priv->scu)) {
69 debug("%s(): can't get SCU\n", __func__);
70 return PTR_ERR(priv->scu);
71 }
72
73 return 0;
74 }
75
ast2400_ofdata_to_platdata(struct udevice * dev)76 static int ast2400_ofdata_to_platdata(struct udevice *dev)
77 {
78 struct ast2400_reset_priv *priv = dev_get_priv(dev);
79 int ret;
80
81 ret = uclass_get_device_by_phandle(UCLASS_WDT, dev, "aspeed,wdt",
82 &priv->wdt);
83 if (ret) {
84 debug("%s: can't find WDT for reset controller", __func__);
85 return ret;
86 }
87
88 return 0;
89 }
90
91 static const struct udevice_id aspeed_reset_ids[] = {
92 { .compatible = "aspeed,ast2400-reset" },
93 { }
94 };
95
96 struct reset_ops aspeed_reset_ops = {
97 .rst_assert = ast2400_reset_assert,
98 .rst_deassert = ast2400_reset_deassert,
99 .request = ast2400_reset_request,
100 };
101
102 U_BOOT_DRIVER(aspeed_reset) = {
103 .name = "aspeed_reset",
104 .id = UCLASS_RESET,
105 .of_match = aspeed_reset_ids,
106 .probe = ast2400_reset_probe,
107 .ops = &aspeed_reset_ops,
108 .ofdata_to_platdata = ast2400_ofdata_to_platdata,
109 .priv_auto_alloc_size = sizeof(struct ast2400_reset_priv),
110 };
111