Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Patrice Chotard | 5c121e1 | 2017-09-13 18:00:07 +0200 | [diff] [blame] | 2 | /* |
Patrice Chotard | 789ee0e | 2017-10-23 09:53:58 +0200 | [diff] [blame] | 3 | * Copyright (C) 2017, STMicroelectronics - All Rights Reserved |
| 4 | * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics. |
Patrice Chotard | 5c121e1 | 2017-09-13 18:00:07 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
Patrice Chotard | 5c121e1 | 2017-09-13 18:00:07 +0200 | [diff] [blame] | 12 | #include <reset-uclass.h> |
Patrick Delaunay | b139a5b | 2018-07-09 15:17:20 +0200 | [diff] [blame] | 13 | #include <stm32_rcc.h> |
Patrice Chotard | 5c121e1 | 2017-09-13 18:00:07 +0200 | [diff] [blame] | 14 | #include <asm/io.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Patrice Chotard | 5c121e1 | 2017-09-13 18:00:07 +0200 | [diff] [blame] | 16 | |
Patrick Delaunay | 4290573 | 2020-10-15 15:01:11 +0200 | [diff] [blame] | 17 | /* offset of register without set/clear management */ |
| 18 | #define RCC_MP_GCR_OFFSET 0x10C |
| 19 | |
Patrick Delaunay | b925d62 | 2018-03-12 10:46:14 +0100 | [diff] [blame] | 20 | /* reset clear offset for STM32MP RCC */ |
| 21 | #define RCC_CL 0x4 |
| 22 | |
Patrice Chotard | 5c121e1 | 2017-09-13 18:00:07 +0200 | [diff] [blame] | 23 | struct stm32_reset_priv { |
| 24 | fdt_addr_t base; |
| 25 | }; |
| 26 | |
| 27 | static int stm32_reset_request(struct reset_ctl *reset_ctl) |
| 28 | { |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | static int stm32_reset_free(struct reset_ctl *reset_ctl) |
| 33 | { |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static int stm32_reset_assert(struct reset_ctl *reset_ctl) |
| 38 | { |
| 39 | struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
| 40 | int bank = (reset_ctl->id / BITS_PER_LONG) * 4; |
| 41 | int offset = reset_ctl->id % BITS_PER_LONG; |
| 42 | debug("%s: reset id = %ld bank = %d offset = %d)\n", __func__, |
| 43 | reset_ctl->id, bank, offset); |
| 44 | |
Patrick Delaunay | b139a5b | 2018-07-09 15:17:20 +0200 | [diff] [blame] | 45 | if (dev_get_driver_data(reset_ctl->dev) == STM32MP1) |
Patrick Delaunay | 4290573 | 2020-10-15 15:01:11 +0200 | [diff] [blame] | 46 | if (bank != RCC_MP_GCR_OFFSET) |
| 47 | /* reset assert is done in rcc set register */ |
| 48 | writel(BIT(offset), priv->base + bank); |
| 49 | else |
| 50 | clrbits_le32(priv->base + bank, BIT(offset)); |
Patrick Delaunay | b925d62 | 2018-03-12 10:46:14 +0100 | [diff] [blame] | 51 | else |
| 52 | setbits_le32(priv->base + bank, BIT(offset)); |
Patrice Chotard | 5c121e1 | 2017-09-13 18:00:07 +0200 | [diff] [blame] | 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static int stm32_reset_deassert(struct reset_ctl *reset_ctl) |
| 58 | { |
| 59 | struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
| 60 | int bank = (reset_ctl->id / BITS_PER_LONG) * 4; |
| 61 | int offset = reset_ctl->id % BITS_PER_LONG; |
| 62 | debug("%s: reset id = %ld bank = %d offset = %d)\n", __func__, |
| 63 | reset_ctl->id, bank, offset); |
| 64 | |
Patrick Delaunay | b139a5b | 2018-07-09 15:17:20 +0200 | [diff] [blame] | 65 | if (dev_get_driver_data(reset_ctl->dev) == STM32MP1) |
Patrick Delaunay | 4290573 | 2020-10-15 15:01:11 +0200 | [diff] [blame] | 66 | if (bank != RCC_MP_GCR_OFFSET) |
| 67 | /* reset deassert is done in rcc clr register */ |
| 68 | writel(BIT(offset), priv->base + bank + RCC_CL); |
| 69 | else |
| 70 | setbits_le32(priv->base + bank, BIT(offset)); |
Patrick Delaunay | b925d62 | 2018-03-12 10:46:14 +0100 | [diff] [blame] | 71 | else |
| 72 | clrbits_le32(priv->base + bank, BIT(offset)); |
Patrice Chotard | 5c121e1 | 2017-09-13 18:00:07 +0200 | [diff] [blame] | 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static const struct reset_ops stm32_reset_ops = { |
| 78 | .request = stm32_reset_request, |
Simon Glass | 1928cd4 | 2020-02-03 07:35:52 -0700 | [diff] [blame] | 79 | .rfree = stm32_reset_free, |
Patrice Chotard | 5c121e1 | 2017-09-13 18:00:07 +0200 | [diff] [blame] | 80 | .rst_assert = stm32_reset_assert, |
| 81 | .rst_deassert = stm32_reset_deassert, |
| 82 | }; |
| 83 | |
| 84 | static int stm32_reset_probe(struct udevice *dev) |
| 85 | { |
| 86 | struct stm32_reset_priv *priv = dev_get_priv(dev); |
| 87 | |
Patrick Delaunay | b925d62 | 2018-03-12 10:46:14 +0100 | [diff] [blame] | 88 | priv->base = dev_read_addr(dev); |
| 89 | if (priv->base == FDT_ADDR_T_NONE) { |
| 90 | /* for MFD, get address of parent */ |
| 91 | priv->base = dev_read_addr(dev->parent); |
| 92 | if (priv->base == FDT_ADDR_T_NONE) |
| 93 | return -EINVAL; |
| 94 | } |
Patrice Chotard | 5c121e1 | 2017-09-13 18:00:07 +0200 | [diff] [blame] | 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | U_BOOT_DRIVER(stm32_rcc_reset) = { |
| 100 | .name = "stm32_rcc_reset", |
| 101 | .id = UCLASS_RESET, |
Patrice Chotard | 5c121e1 | 2017-09-13 18:00:07 +0200 | [diff] [blame] | 102 | .probe = stm32_reset_probe, |
| 103 | .priv_auto_alloc_size = sizeof(struct stm32_reset_priv), |
| 104 | .ops = &stm32_reset_ops, |
| 105 | }; |