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