Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2017 Google, Inc |
Chia-Wei, Wang | 611a28c | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 4 | * Copyright 2020 ASPEED Technology Inc. |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
maxims@google.com | 858d497 | 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 | 611a28c | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 13 | #include <linux/err.h> |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/scu_ast2500.h> |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 16 | |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 17 | struct ast2500_reset_priv { |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 18 | struct ast2500_scu *scu; |
| 19 | }; |
| 20 | |
Chia-Wei, Wang | 611a28c | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 21 | static 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 | |
| 36 | static 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 | |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 51 | static int ast2500_reset_probe(struct udevice *dev) |
| 52 | { |
Chia-Wei, Wang | 611a28c | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 53 | int rc; |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 54 | struct ast2500_reset_priv *priv = dev_get_priv(dev); |
Chia-Wei, Wang | 611a28c | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 55 | struct udevice *scu_dev; |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 56 | |
Chia-Wei, Wang | 611a28c | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 57 | /* get SCU base from clock device */ |
| 58 | rc = uclass_get_device_by_driver(UCLASS_CLK, |
Simon Glass | 65e25be | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 59 | DM_DRIVER_GET(aspeed_ast2500_scu), &scu_dev); |
Chia-Wei, Wang | 611a28c | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 60 | if (rc) { |
| 61 | debug("%s: clock device not found, rc=%d\n", __func__, rc); |
| 62 | return rc; |
| 63 | } |
| 64 | |
| 65 | priv->scu = devfdt_get_addr_ptr(scu_dev); |
| 66 | if (IS_ERR_OR_NULL(priv->scu)) { |
| 67 | debug("%s: invalid SCU base pointer\n", __func__); |
| 68 | return PTR_ERR(priv->scu); |
| 69 | } |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static const struct udevice_id ast2500_reset_ids[] = { |
| 75 | { .compatible = "aspeed,ast2500-reset" }, |
| 76 | { } |
| 77 | }; |
| 78 | |
| 79 | struct reset_ops ast2500_reset_ops = { |
Chia-Wei, Wang | 611a28c | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 80 | .rst_assert = ast2500_reset_assert, |
| 81 | .rst_deassert = ast2500_reset_deassert, |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | U_BOOT_DRIVER(ast2500_reset) = { |
Chia-Wei, Wang | 611a28c | 2020-10-15 10:25:13 +0800 | [diff] [blame] | 85 | .name = "ast2500_reset", |
| 86 | .id = UCLASS_RESET, |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 87 | .of_match = ast2500_reset_ids, |
| 88 | .probe = ast2500_reset_probe, |
| 89 | .ops = &ast2500_reset_ops, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 90 | .priv_auto = sizeof(struct ast2500_reset_priv), |
maxims@google.com | 858d497 | 2017-04-17 12:00:24 -0700 | [diff] [blame] | 91 | }; |