1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
12 #include <reset-uclass.h>
13 #include <stm32_rcc.h>
15 #include <linux/bitops.h>
17 /* offset of register without set/clear management */
18 #define RCC_MP_GCR_OFFSET 0x10C
20 /* reset clear offset for STM32MP RCC */
23 struct stm32_reset_priv {
27 static int stm32_reset_request(struct reset_ctl *reset_ctl)
32 static int stm32_reset_free(struct reset_ctl *reset_ctl)
37 static int stm32_reset_assert(struct reset_ctl *reset_ctl)
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);
45 if (dev_get_driver_data(reset_ctl->dev) == STM32MP1)
46 if (bank != RCC_MP_GCR_OFFSET)
47 /* reset assert is done in rcc set register */
48 writel(BIT(offset), priv->base + bank);
50 clrbits_le32(priv->base + bank, BIT(offset));
52 setbits_le32(priv->base + bank, BIT(offset));
57 static int stm32_reset_deassert(struct reset_ctl *reset_ctl)
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);
65 if (dev_get_driver_data(reset_ctl->dev) == STM32MP1)
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);
70 setbits_le32(priv->base + bank, BIT(offset));
72 clrbits_le32(priv->base + bank, BIT(offset));
77 static const struct reset_ops stm32_reset_ops = {
78 .request = stm32_reset_request,
79 .rfree = stm32_reset_free,
80 .rst_assert = stm32_reset_assert,
81 .rst_deassert = stm32_reset_deassert,
84 static int stm32_reset_probe(struct udevice *dev)
86 struct stm32_reset_priv *priv = dev_get_priv(dev);
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)
99 U_BOOT_DRIVER(stm32_rcc_reset) = {
100 .name = "stm32_rcc_reset",
102 .probe = stm32_reset_probe,
103 .priv_auto = sizeof(struct stm32_reset_priv),
104 .ops = &stm32_reset_ops,