Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Amlogic Meson Reset Controller driver |
| 4 | * |
| 5 | * Copyright (c) 2018 BayLibre, SAS. |
| 6 | * Author: Neil Armstrong <narmstrong@baylibre.com> |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 13 | #include <reset-uclass.h> |
| 14 | #include <regmap.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 16 | |
| 17 | #define REG_COUNT 8 |
| 18 | #define BITS_PER_REG 32 |
| 19 | #define LEVEL_OFFSET 0x7c |
| 20 | |
| 21 | struct meson_reset_priv { |
| 22 | struct regmap *regmap; |
| 23 | }; |
| 24 | |
| 25 | static int meson_reset_request(struct reset_ctl *reset_ctl) |
| 26 | { |
| 27 | if (reset_ctl->id > (REG_COUNT * BITS_PER_REG)) |
| 28 | return -EINVAL; |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 33 | static int meson_reset_level(struct reset_ctl *reset_ctl, bool assert) |
| 34 | { |
| 35 | struct meson_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
| 36 | uint bank = reset_ctl->id / BITS_PER_REG; |
| 37 | uint offset = reset_ctl->id % BITS_PER_REG; |
| 38 | uint reg_offset = LEVEL_OFFSET + (bank << 2); |
| 39 | uint val; |
| 40 | |
| 41 | regmap_read(priv->regmap, reg_offset, &val); |
| 42 | if (assert) |
| 43 | val &= ~BIT(offset); |
| 44 | else |
| 45 | val |= BIT(offset); |
| 46 | regmap_write(priv->regmap, reg_offset, val); |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static int meson_reset_assert(struct reset_ctl *reset_ctl) |
| 52 | { |
| 53 | return meson_reset_level(reset_ctl, true); |
| 54 | } |
| 55 | |
| 56 | static int meson_reset_deassert(struct reset_ctl *reset_ctl) |
| 57 | { |
| 58 | return meson_reset_level(reset_ctl, false); |
| 59 | } |
| 60 | |
| 61 | struct reset_ops meson_reset_ops = { |
| 62 | .request = meson_reset_request, |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 63 | .rst_assert = meson_reset_assert, |
| 64 | .rst_deassert = meson_reset_deassert, |
| 65 | }; |
| 66 | |
Wolfgang Denk | 9d328a6 | 2021-09-27 17:42:38 +0200 | [diff] [blame] | 67 | static const struct udevice_id meson_reset_ids[] = { |
| 68 | { .compatible = "amlogic,meson-gxbb-reset" }, |
Neil Armstrong | cbf5ea5 | 2019-03-26 11:25:44 +0100 | [diff] [blame] | 69 | { .compatible = "amlogic,meson-axg-reset" }, |
Wolfgang Denk | 9d328a6 | 2021-09-27 17:42:38 +0200 | [diff] [blame] | 70 | { } |
| 71 | }; |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 72 | |
| 73 | static int meson_reset_probe(struct udevice *dev) |
| 74 | { |
| 75 | struct meson_reset_priv *priv = dev_get_priv(dev); |
Wolfgang Denk | 9d328a6 | 2021-09-27 17:42:38 +0200 | [diff] [blame] | 76 | |
Masahiro Yamada | e4873e3 | 2018-04-19 12:14:03 +0900 | [diff] [blame] | 77 | return regmap_init_mem(dev_ofnode(dev), &priv->regmap); |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | U_BOOT_DRIVER(meson_reset) = { |
| 81 | .name = "meson_reset", |
| 82 | .id = UCLASS_RESET, |
| 83 | .of_match = meson_reset_ids, |
| 84 | .probe = meson_reset_probe, |
| 85 | .ops = &meson_reset_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 86 | .priv_auto = sizeof(struct meson_reset_priv), |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 87 | }; |