1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2017 Google, Inc
4 * Copyright 2020 ASPEED Technology Inc.
12 #include <reset-uclass.h>
13 #include <linux/err.h>
15 #include <asm/arch/scu_ast2500.h>
17 struct ast2500_reset_priv {
18 struct ast2500_scu *scu;
21 static int ast2500_reset_request(struct reset_ctl *reset_ctl)
23 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
24 reset_ctl->dev, reset_ctl->id);
29 static int ast2500_reset_free(struct reset_ctl *reset_ctl)
31 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
32 reset_ctl->dev, reset_ctl->id);
37 static int ast2500_reset_assert(struct reset_ctl *reset_ctl)
39 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
40 struct ast2500_scu *scu = priv->scu;
42 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
44 if (reset_ctl->id < 32)
45 setbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
47 setbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
52 static int ast2500_reset_deassert(struct reset_ctl *reset_ctl)
54 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
55 struct ast2500_scu *scu = priv->scu;
57 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
59 if (reset_ctl->id < 32)
60 clrbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
62 clrbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
67 static int ast2500_reset_probe(struct udevice *dev)
70 struct ast2500_reset_priv *priv = dev_get_priv(dev);
71 struct udevice *scu_dev;
73 /* get SCU base from clock device */
74 rc = uclass_get_device_by_driver(UCLASS_CLK,
75 DM_GET_DRIVER(aspeed_ast2500_scu), &scu_dev);
77 debug("%s: clock device not found, rc=%d\n", __func__, rc);
81 priv->scu = devfdt_get_addr_ptr(scu_dev);
82 if (IS_ERR_OR_NULL(priv->scu)) {
83 debug("%s: invalid SCU base pointer\n", __func__);
84 return PTR_ERR(priv->scu);
90 static const struct udevice_id ast2500_reset_ids[] = {
91 { .compatible = "aspeed,ast2500-reset" },
95 struct reset_ops ast2500_reset_ops = {
96 .request = ast2500_reset_request,
97 .rfree = ast2500_reset_free,
98 .rst_assert = ast2500_reset_assert,
99 .rst_deassert = ast2500_reset_deassert,
102 U_BOOT_DRIVER(ast2500_reset) = {
103 .name = "ast2500_reset",
105 .of_match = ast2500_reset_ids,
106 .probe = ast2500_reset_probe,
107 .ops = &ast2500_reset_ops,
108 .priv_auto = sizeof(struct ast2500_reset_priv),