blob: b84c9daec74b4214a8da43041520122d8f42edae [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Patrice Chotard5c121e12017-09-13 18:00:07 +02002/*
Patrice Chotard789ee0e2017-10-23 09:53:58 +02003 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
Patrice Chotard5d9950d2020-12-02 18:47:30 +01004 * Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
Patrice Chotard5c121e12017-09-13 18:00:07 +02005 */
6
7#include <common.h>
8#include <dm.h>
9#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070011#include <malloc.h>
Patrice Chotard5c121e12017-09-13 18:00:07 +020012#include <reset-uclass.h>
Patrick Delaunayb139a5b2018-07-09 15:17:20 +020013#include <stm32_rcc.h>
Patrice Chotard5c121e12017-09-13 18:00:07 +020014#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060015#include <linux/bitops.h>
Patrice Chotard5c121e12017-09-13 18:00:07 +020016
Patrick Delaunay42905732020-10-15 15:01:11 +020017/* offset of register without set/clear management */
18#define RCC_MP_GCR_OFFSET 0x10C
19
Patrick Delaunayb925d622018-03-12 10:46:14 +010020/* reset clear offset for STM32MP RCC */
21#define RCC_CL 0x4
22
Patrice Chotard5c121e12017-09-13 18:00:07 +020023struct stm32_reset_priv {
24 fdt_addr_t base;
25};
26
27static int stm32_reset_request(struct reset_ctl *reset_ctl)
28{
29 return 0;
30}
31
32static int stm32_reset_free(struct reset_ctl *reset_ctl)
33{
34 return 0;
35}
36
37static int stm32_reset_assert(struct reset_ctl *reset_ctl)
38{
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);
44
Patrick Delaunayb139a5b2018-07-09 15:17:20 +020045 if (dev_get_driver_data(reset_ctl->dev) == STM32MP1)
Patrick Delaunay42905732020-10-15 15:01:11 +020046 if (bank != RCC_MP_GCR_OFFSET)
47 /* reset assert is done in rcc set register */
48 writel(BIT(offset), priv->base + bank);
49 else
50 clrbits_le32(priv->base + bank, BIT(offset));
Patrick Delaunayb925d622018-03-12 10:46:14 +010051 else
52 setbits_le32(priv->base + bank, BIT(offset));
Patrice Chotard5c121e12017-09-13 18:00:07 +020053
54 return 0;
55}
56
57static int stm32_reset_deassert(struct reset_ctl *reset_ctl)
58{
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);
64
Patrick Delaunayb139a5b2018-07-09 15:17:20 +020065 if (dev_get_driver_data(reset_ctl->dev) == STM32MP1)
Patrick Delaunay42905732020-10-15 15:01:11 +020066 if (bank != RCC_MP_GCR_OFFSET)
67 /* reset deassert is done in rcc clr register */
68 writel(BIT(offset), priv->base + bank + RCC_CL);
69 else
70 setbits_le32(priv->base + bank, BIT(offset));
Patrick Delaunayb925d622018-03-12 10:46:14 +010071 else
72 clrbits_le32(priv->base + bank, BIT(offset));
Patrice Chotard5c121e12017-09-13 18:00:07 +020073
74 return 0;
75}
76
77static const struct reset_ops stm32_reset_ops = {
78 .request = stm32_reset_request,
Simon Glass1928cd42020-02-03 07:35:52 -070079 .rfree = stm32_reset_free,
Patrice Chotard5c121e12017-09-13 18:00:07 +020080 .rst_assert = stm32_reset_assert,
81 .rst_deassert = stm32_reset_deassert,
82};
83
84static int stm32_reset_probe(struct udevice *dev)
85{
86 struct stm32_reset_priv *priv = dev_get_priv(dev);
87
Patrick Delaunayb925d622018-03-12 10:46:14 +010088 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)
93 return -EINVAL;
94 }
Patrice Chotard5c121e12017-09-13 18:00:07 +020095
96 return 0;
97}
98
99U_BOOT_DRIVER(stm32_rcc_reset) = {
100 .name = "stm32_rcc_reset",
101 .id = UCLASS_RESET,
Patrice Chotard5c121e12017-09-13 18:00:07 +0200102 .probe = stm32_reset_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700103 .priv_auto = sizeof(struct stm32_reset_priv),
Patrice Chotard5c121e12017-09-13 18:00:07 +0200104 .ops = &stm32_reset_ops,
105};