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