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.
10 #include <reset-uclass.h>
13 /* reset clear offset for STM32MP RCC */
21 struct stm32_reset_priv {
25 static int stm32_reset_request(struct reset_ctl *reset_ctl)
30 static int stm32_reset_free(struct reset_ctl *reset_ctl)
35 static int stm32_reset_assert(struct reset_ctl *reset_ctl)
37 struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
38 int bank = (reset_ctl->id / BITS_PER_LONG) * 4;
39 int offset = reset_ctl->id % BITS_PER_LONG;
40 debug("%s: reset id = %ld bank = %d offset = %d)\n", __func__,
41 reset_ctl->id, bank, offset);
43 if (dev_get_driver_data(reset_ctl->dev) == RCC_STM32MP)
44 /* reset assert is done in rcc set register */
45 writel(BIT(offset), priv->base + bank);
47 setbits_le32(priv->base + bank, BIT(offset));
52 static int stm32_reset_deassert(struct reset_ctl *reset_ctl)
54 struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
55 int bank = (reset_ctl->id / BITS_PER_LONG) * 4;
56 int offset = reset_ctl->id % BITS_PER_LONG;
57 debug("%s: reset id = %ld bank = %d offset = %d)\n", __func__,
58 reset_ctl->id, bank, offset);
60 if (dev_get_driver_data(reset_ctl->dev) == RCC_STM32MP)
61 /* reset deassert is done in rcc clr register */
62 writel(BIT(offset), priv->base + bank + RCC_CL);
64 clrbits_le32(priv->base + bank, BIT(offset));
69 static const struct reset_ops stm32_reset_ops = {
70 .request = stm32_reset_request,
71 .free = stm32_reset_free,
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 static const struct udevice_id stm32_reset_ids[] = {
92 { .compatible = "st,stm32mp1-rcc-rst", .data = RCC_STM32MP },
96 U_BOOT_DRIVER(stm32_rcc_reset) = {
97 .name = "stm32_rcc_reset",
99 .of_match = stm32_reset_ids,
100 .probe = stm32_reset_probe,
101 .priv_auto_alloc_size = sizeof(struct stm32_reset_priv),
102 .ops = &stm32_reset_ops,