2 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
3 * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <reset-uclass.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 struct stm32_reset_priv {
20 static int stm32_reset_request(struct reset_ctl *reset_ctl)
25 static int stm32_reset_free(struct reset_ctl *reset_ctl)
30 static int stm32_reset_assert(struct reset_ctl *reset_ctl)
32 struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
33 int bank = (reset_ctl->id / BITS_PER_LONG) * 4;
34 int offset = reset_ctl->id % BITS_PER_LONG;
35 debug("%s: reset id = %ld bank = %d offset = %d)\n", __func__,
36 reset_ctl->id, bank, offset);
38 setbits_le32(priv->base + bank, BIT(offset));
43 static int stm32_reset_deassert(struct reset_ctl *reset_ctl)
45 struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
46 int bank = (reset_ctl->id / BITS_PER_LONG) * 4;
47 int offset = reset_ctl->id % BITS_PER_LONG;
48 debug("%s: reset id = %ld bank = %d offset = %d)\n", __func__,
49 reset_ctl->id, bank, offset);
51 clrbits_le32(priv->base + bank, BIT(offset));
56 static const struct reset_ops stm32_reset_ops = {
57 .request = stm32_reset_request,
58 .free = stm32_reset_free,
59 .rst_assert = stm32_reset_assert,
60 .rst_deassert = stm32_reset_deassert,
63 static int stm32_reset_probe(struct udevice *dev)
65 struct stm32_reset_priv *priv = dev_get_priv(dev);
67 priv->base = devfdt_get_addr(dev);
68 if (priv->base == FDT_ADDR_T_NONE)
74 U_BOOT_DRIVER(stm32_rcc_reset) = {
75 .name = "stm32_rcc_reset",
77 .probe = stm32_reset_probe,
78 .priv_auto_alloc_size = sizeof(struct stm32_reset_priv),
79 .ops = &stm32_reset_ops,