blob: d1d44f372812f6d2ff32f7f0f82c41cfd7a047b1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
maxims@google.com858d4972017-04-17 12:00:24 -07002/*
3 * Copyright 2017 Google, Inc
maxims@google.com858d4972017-04-17 12:00:24 -07004 */
5
6#include <common.h>
7#include <dm.h>
8#include <misc.h>
9#include <reset.h>
10#include <reset-uclass.h>
11#include <wdt.h>
12#include <asm/io.h>
13#include <asm/arch/scu_ast2500.h>
14#include <asm/arch/wdt.h>
15
maxims@google.com858d4972017-04-17 12:00:24 -070016struct ast2500_reset_priv {
17 /* WDT used to perform resets. */
18 struct udevice *wdt;
19 struct ast2500_scu *scu;
20};
21
22static int ast2500_ofdata_to_platdata(struct udevice *dev)
23{
24 struct ast2500_reset_priv *priv = dev_get_priv(dev);
25 int ret;
26
27 ret = uclass_get_device_by_phandle(UCLASS_WDT, dev, "aspeed,wdt",
28 &priv->wdt);
29 if (ret) {
30 debug("%s: can't find WDT for reset controller", __func__);
31 return ret;
32 }
33
34 return 0;
35}
36
37static int ast2500_reset_assert(struct reset_ctl *reset_ctl)
38{
39 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
40 u32 reset_mode, reset_mask;
41 bool reset_sdram;
42 int ret;
43
44 /*
45 * To reset SDRAM, a specifal flag in SYSRESET register
46 * needs to be enabled first
47 */
48 reset_mode = ast_reset_mode_from_flags(reset_ctl->id);
49 reset_mask = ast_reset_mask_from_flags(reset_ctl->id);
50 reset_sdram = reset_mode == WDT_CTRL_RESET_SOC &&
51 (reset_mask & WDT_RESET_SDRAM);
52
53 if (reset_sdram) {
54 ast_scu_unlock(priv->scu);
55 setbits_le32(&priv->scu->sysreset_ctrl1,
56 SCU_SYSRESET_SDRAM_WDT);
57 ret = wdt_expire_now(priv->wdt, reset_ctl->id);
58 clrbits_le32(&priv->scu->sysreset_ctrl1,
59 SCU_SYSRESET_SDRAM_WDT);
60 ast_scu_lock(priv->scu);
61 } else {
62 ret = wdt_expire_now(priv->wdt, reset_ctl->id);
63 }
64
65 return ret;
66}
67
68static int ast2500_reset_request(struct reset_ctl *reset_ctl)
69{
70 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
71 reset_ctl->dev, reset_ctl->id);
72
73 return 0;
74}
75
76static int ast2500_reset_probe(struct udevice *dev)
77{
78 struct ast2500_reset_priv *priv = dev_get_priv(dev);
79
80 priv->scu = ast_get_scu();
81
82 return 0;
83}
84
85static const struct udevice_id ast2500_reset_ids[] = {
86 { .compatible = "aspeed,ast2500-reset" },
87 { }
88};
89
90struct reset_ops ast2500_reset_ops = {
91 .rst_assert = ast2500_reset_assert,
92 .request = ast2500_reset_request,
93};
94
95U_BOOT_DRIVER(ast2500_reset) = {
96 .name = "ast2500_reset",
97 .id = UCLASS_RESET,
98 .of_match = ast2500_reset_ids,
99 .probe = ast2500_reset_probe,
100 .ops = &ast2500_reset_ops,
101 .ofdata_to_platdata = ast2500_ofdata_to_platdata,
102 .priv_auto_alloc_size = sizeof(struct ast2500_reset_priv),
103};