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 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 10 | #include <misc.h> |
| 11 | #include <reset.h> |
| 12 | #include <reset-uclass.h> |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 13 | #include <linux/err.h> |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/scu_ast2500.h> |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 16 | |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 17 | struct ast2500_reset_priv { |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 18 | struct ast2500_scu *scu; |
| 19 | }; |
| 20 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 21 | static int ast2500_reset_request(struct reset_ctl *reset_ctl) |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 22 | { |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 23 | debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl, |
| 24 | reset_ctl->dev, reset_ctl->id); |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 25 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | static 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.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static int ast2500_reset_assert(struct reset_ctl *reset_ctl) |
| 38 | { |
| 39 | struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 40 | struct ast2500_scu *scu = priv->scu; |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 41 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 42 | debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id); |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 43 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 44 | 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.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 48 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 49 | return 0; |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 52 | static int ast2500_reset_deassert(struct reset_ctl *reset_ctl) |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 53 | { |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 54 | 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.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static int ast2500_reset_probe(struct udevice *dev) |
| 68 | { |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 69 | int rc; |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 70 | struct ast2500_reset_priv *priv = dev_get_priv(dev); |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 71 | 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.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 80 | |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 81 | 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.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static const struct udevice_id ast2500_reset_ids[] = { |
| 91 | { .compatible = "aspeed,ast2500-reset" }, |
| 92 | { } |
| 93 | }; |
| 94 | |
| 95 | struct reset_ops ast2500_reset_ops = { |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 96 | .request = ast2500_reset_request, |
Chia-Wei, Wang | acc7836 | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 97 | .rfree = ast2500_reset_free, |
| 98 | .rst_assert = ast2500_reset_assert, |
| 99 | .rst_deassert = ast2500_reset_deassert, |
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, |
maxims@google.com | 750875c | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 108 | .priv_auto_alloc_size = sizeof(struct ast2500_reset_priv), |
| 109 | }; |