blob: c21ede2aec91ba25be7da5598ce331d64e1aeef7 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Patrice Chotard23a06412017-09-13 18:00:07 +02002/*
Patrice Chotard3bc599c2017-10-23 09:53:58 +02003 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
Patrice Chotard23a06412017-09-13 18:00:07 +02005 */
6
7#include <common.h>
8#include <dm.h>
9#include <errno.h>
10#include <reset-uclass.h>
11#include <asm/io.h>
12
Patrick Delaunaya7519b32018-03-12 10:46:14 +010013/* reset clear offset for STM32MP RCC */
14#define RCC_CL 0x4
15
16enum rcc_type {
17 RCC_STM32 = 0,
18 RCC_STM32MP,
19};
Patrice Chotard23a06412017-09-13 18:00:07 +020020
21struct stm32_reset_priv {
22 fdt_addr_t base;
23};
24
25static int stm32_reset_request(struct reset_ctl *reset_ctl)
26{
27 return 0;
28}
29
30static int stm32_reset_free(struct reset_ctl *reset_ctl)
31{
32 return 0;
33}
34
35static int stm32_reset_assert(struct reset_ctl *reset_ctl)
36{
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);
42
Patrick Delaunaya7519b32018-03-12 10:46:14 +010043 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);
46 else
47 setbits_le32(priv->base + bank, BIT(offset));
Patrice Chotard23a06412017-09-13 18:00:07 +020048
49 return 0;
50}
51
52static int stm32_reset_deassert(struct reset_ctl *reset_ctl)
53{
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);
59
Patrick Delaunaya7519b32018-03-12 10:46:14 +010060 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);
63 else
64 clrbits_le32(priv->base + bank, BIT(offset));
Patrice Chotard23a06412017-09-13 18:00:07 +020065
66 return 0;
67}
68
69static 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,
74};
75
76static int stm32_reset_probe(struct udevice *dev)
77{
78 struct stm32_reset_priv *priv = dev_get_priv(dev);
79
Patrick Delaunaya7519b32018-03-12 10:46:14 +010080 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)
85 return -EINVAL;
86 }
Patrice Chotard23a06412017-09-13 18:00:07 +020087
88 return 0;
89}
90
Patrick Delaunaya7519b32018-03-12 10:46:14 +010091static const struct udevice_id stm32_reset_ids[] = {
92 { .compatible = "st,stm32mp1-rcc-rst", .data = RCC_STM32MP },
93 { }
94};
95
Patrice Chotard23a06412017-09-13 18:00:07 +020096U_BOOT_DRIVER(stm32_rcc_reset) = {
97 .name = "stm32_rcc_reset",
98 .id = UCLASS_RESET,
Patrick Delaunaya7519b32018-03-12 10:46:14 +010099 .of_match = stm32_reset_ids,
Patrice Chotard23a06412017-09-13 18:00:07 +0200100 .probe = stm32_reset_probe,
101 .priv_auto_alloc_size = sizeof(struct stm32_reset_priv),
102 .ops = &stm32_reset_ops,
103};