Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2017 Google, Inc |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 4 | * Copyright 2020 ASPEED Technology Inc. |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 9 | #include <misc.h> |
| 10 | #include <reset.h> |
| 11 | #include <reset-uclass.h> |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 12 | #include <linux/err.h> |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | #include <asm/arch/scu_ast2500.h> |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 15 | |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 16 | struct ast2500_reset_priv { |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 17 | struct ast2500_scu *scu; |
| 18 | }; |
| 19 | |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 20 | static int ast2500_reset_assert(struct reset_ctl *reset_ctl) |
| 21 | { |
| 22 | struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 23 | struct ast2500_scu *scu = priv->scu; |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 24 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 25 | debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id); |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 26 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 27 | 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.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 31 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 32 | return 0; |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 35 | static int ast2500_reset_deassert(struct reset_ctl *reset_ctl) |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 36 | { |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 37 | 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.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
Joel Stanley | 09df10d | 2022-06-23 14:40:37 +0930 | [diff] [blame] | 50 | static 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 | |
| 66 | |
| 67 | |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 68 | static int ast2500_reset_probe(struct udevice *dev) |
| 69 | { |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 70 | int rc; |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 71 | struct ast2500_reset_priv *priv = dev_get_priv(dev); |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 72 | struct udevice *scu_dev; |
| 73 | |
| 74 | /* get SCU base from clock device */ |
| 75 | rc = uclass_get_device_by_driver(UCLASS_CLK, |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 76 | DM_DRIVER_GET(aspeed_ast2500_scu), &scu_dev); |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 77 | if (rc) { |
| 78 | debug("%s: clock device not found, rc=%d\n", __func__, rc); |
| 79 | return rc; |
| 80 | } |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 81 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 82 | priv->scu = devfdt_get_addr_ptr(scu_dev); |
| 83 | if (IS_ERR_OR_NULL(priv->scu)) { |
| 84 | debug("%s: invalid SCU base pointer\n", __func__); |
| 85 | return PTR_ERR(priv->scu); |
| 86 | } |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | static const struct udevice_id ast2500_reset_ids[] = { |
| 92 | { .compatible = "aspeed,ast2500-reset" }, |
| 93 | { } |
| 94 | }; |
| 95 | |
| 96 | struct reset_ops ast2500_reset_ops = { |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 97 | .rst_assert = ast2500_reset_assert, |
| 98 | .rst_deassert = ast2500_reset_deassert, |
Joel Stanley | 09df10d | 2022-06-23 14:40:37 +0930 | [diff] [blame] | 99 | .rst_status = ast2500_reset_status, |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | U_BOOT_DRIVER(ast2500_reset) = { |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 103 | .name = "ast2500_reset", |
| 104 | .id = UCLASS_RESET, |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 105 | .of_match = ast2500_reset_ids, |
| 106 | .probe = ast2500_reset_probe, |
| 107 | .ops = &ast2500_reset_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 108 | .priv_auto = sizeof(struct ast2500_reset_priv), |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 109 | }; |