blob: d9cecf3a72e8aa59ad704654aac0dfc8a0145b8f [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
Chia-Wei, Wang611a28c2020-10-15 10:25:13 +08004 * Copyright 2020 ASPEED Technology Inc.
maxims@google.com858d4972017-04-17 12:00:24 -07005 */
6
7#include <common.h>
8#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
maxims@google.com858d4972017-04-17 12:00:24 -070010#include <misc.h>
11#include <reset.h>
12#include <reset-uclass.h>
Chia-Wei, Wang611a28c2020-10-15 10:25:13 +080013#include <linux/err.h>
maxims@google.com858d4972017-04-17 12:00:24 -070014#include <asm/io.h>
15#include <asm/arch/scu_ast2500.h>
maxims@google.com858d4972017-04-17 12:00:24 -070016
maxims@google.com858d4972017-04-17 12:00:24 -070017struct ast2500_reset_priv {
maxims@google.com858d4972017-04-17 12:00:24 -070018 struct ast2500_scu *scu;
19};
20
Chia-Wei, Wang611a28c2020-10-15 10:25:13 +080021static int ast2500_reset_assert(struct reset_ctl *reset_ctl)
22{
23 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
24 struct ast2500_scu *scu = priv->scu;
25
26 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
27
28 if (reset_ctl->id < 32)
29 setbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
30 else
31 setbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
32
33 return 0;
34}
35
36static int ast2500_reset_deassert(struct reset_ctl *reset_ctl)
37{
38 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
39 struct ast2500_scu *scu = priv->scu;
40
41 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
42
43 if (reset_ctl->id < 32)
44 clrbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
45 else
46 clrbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
47
48 return 0;
49}
50
Joel Stanley0a8bd972022-06-23 14:40:37 +093051static int ast2500_reset_status(struct reset_ctl *reset_ctl)
52{
53 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
54 struct ast2500_scu *scu = priv->scu;
55 int status;
56
57 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
58
59 if (reset_ctl->id < 32)
60 status = BIT(reset_ctl->id) & readl(&scu->sysreset_ctrl1);
61 else
62 status = BIT(reset_ctl->id - 32) & readl(&scu->sysreset_ctrl2);
63
64 return !!status;
65}
66
67
68
maxims@google.com858d4972017-04-17 12:00:24 -070069static int ast2500_reset_probe(struct udevice *dev)
70{
Chia-Wei, Wang611a28c2020-10-15 10:25:13 +080071 int rc;
maxims@google.com858d4972017-04-17 12:00:24 -070072 struct ast2500_reset_priv *priv = dev_get_priv(dev);
Chia-Wei, Wang611a28c2020-10-15 10:25:13 +080073 struct udevice *scu_dev;
maxims@google.com858d4972017-04-17 12:00:24 -070074
Chia-Wei, Wang611a28c2020-10-15 10:25:13 +080075 /* get SCU base from clock device */
76 rc = uclass_get_device_by_driver(UCLASS_CLK,
Simon Glass65e25be2020-12-28 20:34:56 -070077 DM_DRIVER_GET(aspeed_ast2500_scu), &scu_dev);
Chia-Wei, Wang611a28c2020-10-15 10:25:13 +080078 if (rc) {
79 debug("%s: clock device not found, rc=%d\n", __func__, rc);
80 return rc;
81 }
82
83 priv->scu = devfdt_get_addr_ptr(scu_dev);
84 if (IS_ERR_OR_NULL(priv->scu)) {
85 debug("%s: invalid SCU base pointer\n", __func__);
86 return PTR_ERR(priv->scu);
87 }
maxims@google.com858d4972017-04-17 12:00:24 -070088
89 return 0;
90}
91
92static const struct udevice_id ast2500_reset_ids[] = {
93 { .compatible = "aspeed,ast2500-reset" },
94 { }
95};
96
97struct reset_ops ast2500_reset_ops = {
Chia-Wei, Wang611a28c2020-10-15 10:25:13 +080098 .rst_assert = ast2500_reset_assert,
99 .rst_deassert = ast2500_reset_deassert,
Joel Stanley0a8bd972022-06-23 14:40:37 +0930100 .rst_status = ast2500_reset_status,
maxims@google.com858d4972017-04-17 12:00:24 -0700101};
102
103U_BOOT_DRIVER(ast2500_reset) = {
Chia-Wei, Wang611a28c2020-10-15 10:25:13 +0800104 .name = "ast2500_reset",
105 .id = UCLASS_RESET,
maxims@google.com858d4972017-04-17 12:00:24 -0700106 .of_match = ast2500_reset_ids,
107 .probe = ast2500_reset_probe,
108 .ops = &ast2500_reset_ops,
Simon Glass41575d82020-12-03 16:55:17 -0700109 .priv_auto = sizeof(struct ast2500_reset_priv),
maxims@google.com858d4972017-04-17 12:00:24 -0700110};