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 | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 12 | #include <reset-uclass.h> |
| 13 | #include <regmap.h> |
| 14 | |
| 15 | #define REG_COUNT 8 |
| 16 | #define BITS_PER_REG 32 |
| 17 | #define LEVEL_OFFSET 0x7c |
| 18 | |
| 19 | struct meson_reset_priv { |
| 20 | struct regmap *regmap; |
| 21 | }; |
| 22 | |
| 23 | static int meson_reset_request(struct reset_ctl *reset_ctl) |
| 24 | { |
| 25 | if (reset_ctl->id > (REG_COUNT * BITS_PER_REG)) |
| 26 | return -EINVAL; |
| 27 | |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | static int meson_reset_free(struct reset_ctl *reset_ctl) |
| 32 | { |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static int meson_reset_level(struct reset_ctl *reset_ctl, bool assert) |
| 37 | { |
| 38 | struct meson_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
| 39 | uint bank = reset_ctl->id / BITS_PER_REG; |
| 40 | uint offset = reset_ctl->id % BITS_PER_REG; |
| 41 | uint reg_offset = LEVEL_OFFSET + (bank << 2); |
| 42 | uint val; |
| 43 | |
| 44 | regmap_read(priv->regmap, reg_offset, &val); |
| 45 | if (assert) |
| 46 | val &= ~BIT(offset); |
| 47 | else |
| 48 | val |= BIT(offset); |
| 49 | regmap_write(priv->regmap, reg_offset, val); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static int meson_reset_assert(struct reset_ctl *reset_ctl) |
| 55 | { |
| 56 | return meson_reset_level(reset_ctl, true); |
| 57 | } |
| 58 | |
| 59 | static int meson_reset_deassert(struct reset_ctl *reset_ctl) |
| 60 | { |
| 61 | return meson_reset_level(reset_ctl, false); |
| 62 | } |
| 63 | |
| 64 | struct reset_ops meson_reset_ops = { |
| 65 | .request = meson_reset_request, |
Simon Glass | 1928cd4 | 2020-02-03 07:35:52 -0700 | [diff] [blame] | 66 | .rfree = meson_reset_free, |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 67 | .rst_assert = meson_reset_assert, |
| 68 | .rst_deassert = meson_reset_deassert, |
| 69 | }; |
| 70 | |
| 71 | static const struct udevice_id meson_reset_ids[] = { |
| 72 | { .compatible = "amlogic,meson-gxbb-reset" }, |
Neil Armstrong | cbf5ea5 | 2019-03-26 11:25:44 +0100 | [diff] [blame] | 73 | { .compatible = "amlogic,meson-axg-reset" }, |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 74 | { } |
| 75 | }; |
| 76 | |
| 77 | static int meson_reset_probe(struct udevice *dev) |
| 78 | { |
| 79 | struct meson_reset_priv *priv = dev_get_priv(dev); |
| 80 | |
Masahiro Yamada | e4873e3 | 2018-04-19 12:14:03 +0900 | [diff] [blame] | 81 | return regmap_init_mem(dev_ofnode(dev), &priv->regmap); |
Neil Armstrong | 4f03d6b | 2018-03-29 14:55:25 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | U_BOOT_DRIVER(meson_reset) = { |
| 85 | .name = "meson_reset", |
| 86 | .id = UCLASS_RESET, |
| 87 | .of_match = meson_reset_ids, |
| 88 | .probe = meson_reset_probe, |
| 89 | .ops = &meson_reset_ops, |
| 90 | .priv_auto_alloc_size = sizeof(struct meson_reset_priv), |
| 91 | }; |