blob: f3543fa8cc1995df5e55098a09dd8d3e2943f94f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
maxims@google.com750875c2017-04-17 12:00:24 -07002/*
3 * Copyright 2017 Google, Inc
Chia-Wei, Wangacc78362020-10-15 10:25:13 +08004 * Copyright 2020 ASPEED Technology Inc.
maxims@google.com750875c2017-04-17 12:00:24 -07005 */
6
maxims@google.com750875c2017-04-17 12:00:24 -07007#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
maxims@google.com750875c2017-04-17 12:00:24 -07009#include <misc.h>
10#include <reset.h>
11#include <reset-uclass.h>
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080012#include <linux/err.h>
maxims@google.com750875c2017-04-17 12:00:24 -070013#include <asm/io.h>
14#include <asm/arch/scu_ast2500.h>
maxims@google.com750875c2017-04-17 12:00:24 -070015
maxims@google.com750875c2017-04-17 12:00:24 -070016struct ast2500_reset_priv {
maxims@google.com750875c2017-04-17 12:00:24 -070017 struct ast2500_scu *scu;
18};
19
maxims@google.com750875c2017-04-17 12:00:24 -070020static int ast2500_reset_assert(struct reset_ctl *reset_ctl)
21{
22 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080023 struct ast2500_scu *scu = priv->scu;
maxims@google.com750875c2017-04-17 12:00:24 -070024
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080025 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
maxims@google.com750875c2017-04-17 12:00:24 -070026
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080027 if (reset_ctl->id < 32)
28 setbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
29 else
30 setbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
maxims@google.com750875c2017-04-17 12:00:24 -070031
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080032 return 0;
maxims@google.com750875c2017-04-17 12:00:24 -070033}
34
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080035static int ast2500_reset_deassert(struct reset_ctl *reset_ctl)
maxims@google.com750875c2017-04-17 12:00:24 -070036{
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080037 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
38 struct ast2500_scu *scu = priv->scu;
39
40 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
41
42 if (reset_ctl->id < 32)
43 clrbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
44 else
45 clrbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
maxims@google.com750875c2017-04-17 12:00:24 -070046
47 return 0;
48}
49
Joel Stanley09df10d2022-06-23 14:40:37 +093050static int ast2500_reset_status(struct reset_ctl *reset_ctl)
51{
52 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
53 struct ast2500_scu *scu = priv->scu;
54 int status;
55
56 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
57
58 if (reset_ctl->id < 32)
59 status = BIT(reset_ctl->id) & readl(&scu->sysreset_ctrl1);
60 else
61 status = BIT(reset_ctl->id - 32) & readl(&scu->sysreset_ctrl2);
62
63 return !!status;
64}
65
maxims@google.com750875c2017-04-17 12:00:24 -070066static int ast2500_reset_probe(struct udevice *dev)
67{
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080068 int rc;
maxims@google.com750875c2017-04-17 12:00:24 -070069 struct ast2500_reset_priv *priv = dev_get_priv(dev);
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080070 struct udevice *scu_dev;
71
72 /* get SCU base from clock device */
73 rc = uclass_get_device_by_driver(UCLASS_CLK,
Simon Glass65130cd2020-12-28 20:34:56 -070074 DM_DRIVER_GET(aspeed_ast2500_scu), &scu_dev);
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080075 if (rc) {
76 debug("%s: clock device not found, rc=%d\n", __func__, rc);
77 return rc;
78 }
maxims@google.com750875c2017-04-17 12:00:24 -070079
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080080 priv->scu = devfdt_get_addr_ptr(scu_dev);
81 if (IS_ERR_OR_NULL(priv->scu)) {
82 debug("%s: invalid SCU base pointer\n", __func__);
83 return PTR_ERR(priv->scu);
84 }
maxims@google.com750875c2017-04-17 12:00:24 -070085
86 return 0;
87}
88
89static const struct udevice_id ast2500_reset_ids[] = {
90 { .compatible = "aspeed,ast2500-reset" },
91 { }
92};
93
94struct reset_ops ast2500_reset_ops = {
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080095 .rst_assert = ast2500_reset_assert,
96 .rst_deassert = ast2500_reset_deassert,
Joel Stanley09df10d2022-06-23 14:40:37 +093097 .rst_status = ast2500_reset_status,
maxims@google.com750875c2017-04-17 12:00:24 -070098};
99
100U_BOOT_DRIVER(ast2500_reset) = {
Chia-Wei, Wangacc78362020-10-15 10:25:13 +0800101 .name = "ast2500_reset",
102 .id = UCLASS_RESET,
maxims@google.com750875c2017-04-17 12:00:24 -0700103 .of_match = ast2500_reset_ids,
104 .probe = ast2500_reset_probe,
105 .ops = &ast2500_reset_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700106 .priv_auto = sizeof(struct ast2500_reset_priv),
maxims@google.com750875c2017-04-17 12:00:24 -0700107};