2 * Copyright 2017 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0
11 #include <reset-uclass.h>
14 #include <asm/arch/scu_ast2500.h>
15 #include <asm/arch/wdt.h>
17 DECLARE_GLOBAL_DATA_PTR;
19 struct ast2500_reset_priv {
20 /* WDT used to perform resets. */
22 struct ast2500_scu *scu;
25 static int ast2500_ofdata_to_platdata(struct udevice *dev)
27 struct ast2500_reset_priv *priv = dev_get_priv(dev);
30 ret = uclass_get_device_by_phandle(UCLASS_WDT, dev, "aspeed,wdt",
33 debug("%s: can't find WDT for reset controller", __func__);
40 static int ast2500_reset_assert(struct reset_ctl *reset_ctl)
42 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
43 u32 reset_mode, reset_mask;
48 * To reset SDRAM, a specifal flag in SYSRESET register
49 * needs to be enabled first
51 reset_mode = ast_reset_mode_from_flags(reset_ctl->id);
52 reset_mask = ast_reset_mask_from_flags(reset_ctl->id);
53 reset_sdram = reset_mode == WDT_CTRL_RESET_SOC &&
54 (reset_mask & WDT_RESET_SDRAM);
57 ast_scu_unlock(priv->scu);
58 setbits_le32(&priv->scu->sysreset_ctrl1,
59 SCU_SYSRESET_SDRAM_WDT);
60 ret = wdt_expire_now(priv->wdt, reset_ctl->id);
61 clrbits_le32(&priv->scu->sysreset_ctrl1,
62 SCU_SYSRESET_SDRAM_WDT);
63 ast_scu_lock(priv->scu);
65 ret = wdt_expire_now(priv->wdt, reset_ctl->id);
71 static int ast2500_reset_request(struct reset_ctl *reset_ctl)
73 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
74 reset_ctl->dev, reset_ctl->id);
79 static int ast2500_reset_probe(struct udevice *dev)
81 struct ast2500_reset_priv *priv = dev_get_priv(dev);
83 priv->scu = ast_get_scu();
88 static const struct udevice_id ast2500_reset_ids[] = {
89 { .compatible = "aspeed,ast2500-reset" },
93 struct reset_ops ast2500_reset_ops = {
94 .rst_assert = ast2500_reset_assert,
95 .request = ast2500_reset_request,
98 U_BOOT_DRIVER(ast2500_reset) = {
99 .name = "ast2500_reset",
101 .of_match = ast2500_reset_ids,
102 .probe = ast2500_reset_probe,
103 .ops = &ast2500_reset_ops,
104 .ofdata_to_platdata = ast2500_ofdata_to_platdata,
105 .priv_auto_alloc_size = sizeof(struct ast2500_reset_priv),