1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
7 #define LOG_CATEGORY UCLASS_RESET
13 #include <reset-uclass.h>
14 #include <stm32_rcc.h>
16 #include <dm/device_compat.h>
17 #include <linux/bitops.h>
19 /* offset of register without set/clear management */
20 #define RCC_MP_GCR_OFFSET 0x10C
22 /* reset clear offset for STM32MP RCC */
25 struct stm32_reset_priv {
29 static int stm32_reset_assert(struct reset_ctl *reset_ctl)
31 struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
32 int bank = (reset_ctl->id / (sizeof(u32) * BITS_PER_BYTE)) * 4;
33 int offset = reset_ctl->id % (sizeof(u32) * BITS_PER_BYTE);
35 dev_dbg(reset_ctl->dev, "reset id = %ld bank = %d offset = %d)\n",
36 reset_ctl->id, bank, offset);
38 if (dev_get_driver_data(reset_ctl->dev) == STM32MP1)
39 if (bank != RCC_MP_GCR_OFFSET)
40 /* reset assert is done in rcc set register */
41 writel(BIT(offset), priv->base + bank);
43 clrbits_le32(priv->base + bank, BIT(offset));
45 setbits_le32(priv->base + bank, BIT(offset));
50 static int stm32_reset_deassert(struct reset_ctl *reset_ctl)
52 struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
53 int bank = (reset_ctl->id / (sizeof(u32) * BITS_PER_BYTE)) * 4;
54 int offset = reset_ctl->id % (sizeof(u32) * BITS_PER_BYTE);
56 dev_dbg(reset_ctl->dev, "reset id = %ld bank = %d offset = %d)\n",
57 reset_ctl->id, bank, offset);
59 if (dev_get_driver_data(reset_ctl->dev) == STM32MP1)
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);
64 setbits_le32(priv->base + bank, BIT(offset));
66 clrbits_le32(priv->base + bank, BIT(offset));
71 static const struct reset_ops stm32_reset_ops = {
72 .rst_assert = stm32_reset_assert,
73 .rst_deassert = stm32_reset_deassert,
76 static int stm32_reset_probe(struct udevice *dev)
78 struct stm32_reset_priv *priv = dev_get_priv(dev);
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)
91 U_BOOT_DRIVER(stm32_rcc_reset) = {
92 .name = "stm32_rcc_reset",
94 .probe = stm32_reset_probe,
95 .priv_auto = sizeof(struct stm32_reset_priv),
96 .ops = &stm32_reset_ops,