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