blob: e7b5c7decab7540803139f7ee6c85f323e095324 [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
7#include <common.h>
8#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
maxims@google.com750875c2017-04-17 12:00:24 -070010#include <misc.h>
11#include <reset.h>
12#include <reset-uclass.h>
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080013#include <linux/err.h>
maxims@google.com750875c2017-04-17 12:00:24 -070014#include <asm/io.h>
15#include <asm/arch/scu_ast2500.h>
maxims@google.com750875c2017-04-17 12:00:24 -070016
maxims@google.com750875c2017-04-17 12:00:24 -070017struct ast2500_reset_priv {
maxims@google.com750875c2017-04-17 12:00:24 -070018 struct ast2500_scu *scu;
19};
20
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080021static int ast2500_reset_request(struct reset_ctl *reset_ctl)
maxims@google.com750875c2017-04-17 12:00:24 -070022{
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080023 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
24 reset_ctl->dev, reset_ctl->id);
maxims@google.com750875c2017-04-17 12:00:24 -070025
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080026 return 0;
27}
28
29static int ast2500_reset_free(struct reset_ctl *reset_ctl)
30{
31 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
32 reset_ctl->dev, reset_ctl->id);
maxims@google.com750875c2017-04-17 12:00:24 -070033
34 return 0;
35}
36
37static int ast2500_reset_assert(struct reset_ctl *reset_ctl)
38{
39 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080040 struct ast2500_scu *scu = priv->scu;
maxims@google.com750875c2017-04-17 12:00:24 -070041
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080042 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
maxims@google.com750875c2017-04-17 12:00:24 -070043
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080044 if (reset_ctl->id < 32)
45 setbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
46 else
47 setbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
maxims@google.com750875c2017-04-17 12:00:24 -070048
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080049 return 0;
maxims@google.com750875c2017-04-17 12:00:24 -070050}
51
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080052static int ast2500_reset_deassert(struct reset_ctl *reset_ctl)
maxims@google.com750875c2017-04-17 12:00:24 -070053{
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080054 struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
55 struct ast2500_scu *scu = priv->scu;
56
57 debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
58
59 if (reset_ctl->id < 32)
60 clrbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
61 else
62 clrbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
maxims@google.com750875c2017-04-17 12:00:24 -070063
64 return 0;
65}
66
67static int ast2500_reset_probe(struct udevice *dev)
68{
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080069 int rc;
maxims@google.com750875c2017-04-17 12:00:24 -070070 struct ast2500_reset_priv *priv = dev_get_priv(dev);
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080071 struct udevice *scu_dev;
72
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);
76 if (rc) {
77 debug("%s: clock device not found, rc=%d\n", __func__, rc);
78 return rc;
79 }
maxims@google.com750875c2017-04-17 12:00:24 -070080
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080081 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);
85 }
maxims@google.com750875c2017-04-17 12:00:24 -070086
87 return 0;
88}
89
90static const struct udevice_id ast2500_reset_ids[] = {
91 { .compatible = "aspeed,ast2500-reset" },
92 { }
93};
94
95struct reset_ops ast2500_reset_ops = {
maxims@google.com750875c2017-04-17 12:00:24 -070096 .request = ast2500_reset_request,
Chia-Wei, Wangacc78362020-10-15 10:25:13 +080097 .rfree = ast2500_reset_free,
98 .rst_assert = ast2500_reset_assert,
99 .rst_deassert = ast2500_reset_deassert,
maxims@google.com750875c2017-04-17 12:00:24 -0700100};
101
102U_BOOT_DRIVER(ast2500_reset) = {
Chia-Wei, Wangacc78362020-10-15 10:25:13 +0800103 .name = "ast2500_reset",
104 .id = UCLASS_RESET,
maxims@google.com750875c2017-04-17 12:00:24 -0700105 .of_match = ast2500_reset_ids,
106 .probe = ast2500_reset_probe,
107 .ops = &ast2500_reset_ops,
maxims@google.com750875c2017-04-17 12:00:24 -0700108 .priv_auto_alloc_size = sizeof(struct ast2500_reset_priv),
109};