blob: 1732a450efc07a16569ca83578a2c323a87ad710 [file] [log] [blame]
Chia-Wei, Wang9fc21082020-12-14 13:54:26 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2020 ASPEED Technology Inc.
4 */
5
6#include <common.h>
7#include <dm.h>
8#include <log.h>
9#include <misc.h>
10#include <reset.h>
11#include <reset-uclass.h>
12#include <linux/err.h>
13#include <asm/io.h>
14#include <asm/arch/scu_ast2600.h>
15
16struct ast2600_reset_priv {
17 struct ast2600_scu *scu;
18};
19
Chia-Wei, Wang9fc21082020-12-14 13:54:26 +080020static int ast2600_reset_assert(struct reset_ctl *reset_ctl)
21{
22 struct ast2600_reset_priv *priv = dev_get_priv(reset_ctl->dev);
23 struct ast2600_scu *scu = priv->scu;
24
25 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
26
27 if (reset_ctl->id < 32)
Chia-Wei Wangbc7b3842021-07-20 15:01:36 +080028 writel(BIT(reset_ctl->id), &scu->modrst_ctrl1);
Chia-Wei, Wang9fc21082020-12-14 13:54:26 +080029 else
Chia-Wei Wangbc7b3842021-07-20 15:01:36 +080030 writel(BIT(reset_ctl->id - 32), &scu->modrst_ctrl2);
Chia-Wei, Wang9fc21082020-12-14 13:54:26 +080031
32 return 0;
33}
34
35static int ast2600_reset_deassert(struct reset_ctl *reset_ctl)
36{
37 struct ast2600_reset_priv *priv = dev_get_priv(reset_ctl->dev);
38 struct ast2600_scu *scu = priv->scu;
39
40 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
41
42 if (reset_ctl->id < 32)
Chia-Wei Wangbc7b3842021-07-20 15:01:36 +080043 writel(BIT(reset_ctl->id), &scu->modrst_clr1);
Chia-Wei, Wang9fc21082020-12-14 13:54:26 +080044 else
Chia-Wei Wangbc7b3842021-07-20 15:01:36 +080045 writel(BIT(reset_ctl->id - 32), &scu->modrst_clr2);
Chia-Wei, Wang9fc21082020-12-14 13:54:26 +080046
47 return 0;
48}
49
Joel Stanley0a8bd972022-06-23 14:40:37 +093050static int ast2600_reset_status(struct reset_ctl *reset_ctl)
51{
52 struct ast2600_reset_priv *priv = dev_get_priv(reset_ctl->dev);
53 struct ast2600_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->modrst_ctrl1);
60 else
61 status = BIT(reset_ctl->id - 32) & readl(&scu->modrst_ctrl2);
62
63 return !!status;
64}
65
Chia-Wei, Wang9fc21082020-12-14 13:54:26 +080066static int ast2600_reset_probe(struct udevice *dev)
67{
68 int rc;
69 struct ast2600_reset_priv *priv = dev_get_priv(dev);
70 struct udevice *scu_dev;
71
72 /* get SCU base from clock device */
73 rc = uclass_get_device_by_driver(UCLASS_CLK,
74 DM_DRIVER_GET(aspeed_ast2600_scu), &scu_dev);
75 if (rc) {
76 debug("%s: clock device not found, rc=%d\n", __func__, rc);
77 return rc;
78 }
79
80 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 }
85
86 return 0;
87}
88
89static const struct udevice_id ast2600_reset_ids[] = {
90 { .compatible = "aspeed,ast2600-reset" },
91 { }
92};
93
94struct reset_ops ast2600_reset_ops = {
Chia-Wei, Wang9fc21082020-12-14 13:54:26 +080095 .rst_assert = ast2600_reset_assert,
96 .rst_deassert = ast2600_reset_deassert,
Joel Stanley0a8bd972022-06-23 14:40:37 +093097 .rst_status = ast2600_reset_status,
Chia-Wei, Wang9fc21082020-12-14 13:54:26 +080098};
99
100U_BOOT_DRIVER(ast2600_reset) = {
101 .name = "ast2600_reset",
102 .id = UCLASS_RESET,
103 .of_match = ast2600_reset_ids,
104 .probe = ast2600_reset_probe,
105 .ops = &ast2600_reset_ops,
106 .priv_auto = sizeof(struct ast2600_reset_priv),
107};