xref: /openbmc/u-boot/drivers/reset/stm32-reset.c (revision 193f6fb9)
1 /*
2  * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
3  * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #include <common.h>
9 #include <dm.h>
10 #include <errno.h>
11 #include <reset-uclass.h>
12 #include <asm/io.h>
13 
14 DECLARE_GLOBAL_DATA_PTR;
15 
16 struct stm32_reset_priv {
17 	fdt_addr_t base;
18 };
19 
20 static int stm32_reset_request(struct reset_ctl *reset_ctl)
21 {
22 	return 0;
23 }
24 
25 static int stm32_reset_free(struct reset_ctl *reset_ctl)
26 {
27 	return 0;
28 }
29 
30 static int stm32_reset_assert(struct reset_ctl *reset_ctl)
31 {
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);
37 
38 	setbits_le32(priv->base + bank, BIT(offset));
39 
40 	return 0;
41 }
42 
43 static int stm32_reset_deassert(struct reset_ctl *reset_ctl)
44 {
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);
50 
51 	clrbits_le32(priv->base + bank, BIT(offset));
52 
53 	return 0;
54 }
55 
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,
61 };
62 
63 static int stm32_reset_probe(struct udevice *dev)
64 {
65 	struct stm32_reset_priv *priv = dev_get_priv(dev);
66 
67 	priv->base = devfdt_get_addr(dev);
68 	if (priv->base == FDT_ADDR_T_NONE)
69 		return -EINVAL;
70 
71 	return 0;
72 }
73 
74 U_BOOT_DRIVER(stm32_rcc_reset) = {
75 	.name			= "stm32_rcc_reset",
76 	.id			= UCLASS_RESET,
77 	.probe			= stm32_reset_probe,
78 	.priv_auto_alloc_size	= sizeof(struct stm32_reset_priv),
79 	.ops			= &stm32_reset_ops,
80 };
81