diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2016-08-02 00:18:29 -0400 |
---|---|---|
committer | Philipp Zabel <p.zabel@pengutronix.de> | 2016-08-24 09:21:35 -0400 |
commit | 54e991b56639437f922113b6b12f34e8044418d8 (patch) | |
tree | 6c0a79118f33dd0ada5730791c75e9ccdb2a1a7b | |
parent | 9af80712985562b40fa37e6b80b82bedb57fcbc6 (diff) |
reset: uniphier: add reset controller driver for UniPhier SoCs
This is the initial commit for UniPhier reset controller driver.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
-rw-r--r-- | Documentation/devicetree/bindings/reset/uniphier-reset.txt | 93 | ||||
-rw-r--r-- | MAINTAINERS | 1 | ||||
-rw-r--r-- | drivers/reset/Kconfig | 10 | ||||
-rw-r--r-- | drivers/reset/Makefile | 1 | ||||
-rw-r--r-- | drivers/reset/reset-uniphier.c | 440 |
5 files changed, 545 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/reset/uniphier-reset.txt b/Documentation/devicetree/bindings/reset/uniphier-reset.txt new file mode 100644 index 000000000000..e6bbfccd56c3 --- /dev/null +++ b/Documentation/devicetree/bindings/reset/uniphier-reset.txt | |||
@@ -0,0 +1,93 @@ | |||
1 | UniPhier reset controller | ||
2 | |||
3 | |||
4 | System reset | ||
5 | ------------ | ||
6 | |||
7 | Required properties: | ||
8 | - compatible: should be one of the following: | ||
9 | "socionext,uniphier-sld3-reset" - for PH1-sLD3 SoC. | ||
10 | "socionext,uniphier-ld4-reset" - for PH1-LD4 SoC. | ||
11 | "socionext,uniphier-pro4-reset" - for PH1-Pro4 SoC. | ||
12 | "socionext,uniphier-sld8-reset" - for PH1-sLD8 SoC. | ||
13 | "socionext,uniphier-pro5-reset" - for PH1-Pro5 SoC. | ||
14 | "socionext,uniphier-pxs2-reset" - for ProXstream2/PH1-LD6b SoC. | ||
15 | "socionext,uniphier-ld11-reset" - for PH1-LD11 SoC. | ||
16 | "socionext,uniphier-ld20-reset" - for PH1-LD20 SoC. | ||
17 | - #reset-cells: should be 1. | ||
18 | |||
19 | Example: | ||
20 | |||
21 | sysctrl@61840000 { | ||
22 | compatible = "socionext,uniphier-ld20-sysctrl", | ||
23 | "simple-mfd", "syscon"; | ||
24 | reg = <0x61840000 0x4000>; | ||
25 | |||
26 | reset { | ||
27 | compatible = "socionext,uniphier-ld20-reset"; | ||
28 | #reset-cells = <1>; | ||
29 | }; | ||
30 | |||
31 | other nodes ... | ||
32 | }; | ||
33 | |||
34 | |||
35 | Media I/O (MIO) reset | ||
36 | --------------------- | ||
37 | |||
38 | Required properties: | ||
39 | - compatible: should be one of the following: | ||
40 | "socionext,uniphier-sld3-mio-reset" - for PH1-sLD3 SoC. | ||
41 | "socionext,uniphier-ld4-mio-reset" - for PH1-LD4 SoC. | ||
42 | "socionext,uniphier-pro4-mio-reset" - for PH1-Pro4 SoC. | ||
43 | "socionext,uniphier-sld8-mio-reset" - for PH1-sLD8 SoC. | ||
44 | "socionext,uniphier-pro5-mio-reset" - for PH1-Pro5 SoC. | ||
45 | "socionext,uniphier-pxs2-mio-reset" - for ProXstream2/PH1-LD6b SoC. | ||
46 | "socionext,uniphier-ld11-mio-reset" - for PH1-LD11 SoC. | ||
47 | "socionext,uniphier-ld20-mio-reset" - for PH1-LD20 SoC. | ||
48 | - #reset-cells: should be 1. | ||
49 | |||
50 | Example: | ||
51 | |||
52 | mioctrl@59810000 { | ||
53 | compatible = "socionext,uniphier-ld20-mioctrl", | ||
54 | "simple-mfd", "syscon"; | ||
55 | reg = <0x59810000 0x800>; | ||
56 | |||
57 | reset { | ||
58 | compatible = "socionext,uniphier-ld20-mio-reset"; | ||
59 | #reset-cells = <1>; | ||
60 | }; | ||
61 | |||
62 | other nodes ... | ||
63 | }; | ||
64 | |||
65 | |||
66 | Peripheral reset | ||
67 | ---------------- | ||
68 | |||
69 | Required properties: | ||
70 | - compatible: should be one of the following: | ||
71 | "socionext,uniphier-ld4-peri-reset" - for PH1-LD4 SoC. | ||
72 | "socionext,uniphier-pro4-peri-reset" - for PH1-Pro4 SoC. | ||
73 | "socionext,uniphier-sld8-peri-reset" - for PH1-sLD8 SoC. | ||
74 | "socionext,uniphier-pro5-peri-reset" - for PH1-Pro5 SoC. | ||
75 | "socionext,uniphier-pxs2-peri-reset" - for ProXstream2/PH1-LD6b SoC. | ||
76 | "socionext,uniphier-ld11-peri-reset" - for PH1-LD11 SoC. | ||
77 | "socionext,uniphier-ld20-peri-reset" - for PH1-LD20 SoC. | ||
78 | - #reset-cells: should be 1. | ||
79 | |||
80 | Example: | ||
81 | |||
82 | perictrl@59820000 { | ||
83 | compatible = "socionext,uniphier-ld20-perictrl", | ||
84 | "simple-mfd", "syscon"; | ||
85 | reg = <0x59820000 0x200>; | ||
86 | |||
87 | reset { | ||
88 | compatible = "socionext,uniphier-ld20-peri-reset"; | ||
89 | #reset-cells = <1>; | ||
90 | }; | ||
91 | |||
92 | other nodes ... | ||
93 | }; | ||
diff --git a/MAINTAINERS b/MAINTAINERS index 20bb1d00098c..fde95b8f37db 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -1830,6 +1830,7 @@ F: arch/arm64/boot/dts/socionext/ | |||
1830 | F: drivers/bus/uniphier-system-bus.c | 1830 | F: drivers/bus/uniphier-system-bus.c |
1831 | F: drivers/i2c/busses/i2c-uniphier* | 1831 | F: drivers/i2c/busses/i2c-uniphier* |
1832 | F: drivers/pinctrl/uniphier/ | 1832 | F: drivers/pinctrl/uniphier/ |
1833 | F: drivers/reset/reset-uniphier.c | ||
1833 | F: drivers/tty/serial/8250/8250_uniphier.c | 1834 | F: drivers/tty/serial/8250/8250_uniphier.c |
1834 | N: uniphier | 1835 | N: uniphier |
1835 | 1836 | ||
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig index 4be1b8c21f6f..7dfe8d84d6bb 100644 --- a/drivers/reset/Kconfig +++ b/drivers/reset/Kconfig | |||
@@ -27,6 +27,16 @@ config TI_SYSCON_RESET | |||
27 | you wish to use the reset framework for such memory-mapped devices, | 27 | you wish to use the reset framework for such memory-mapped devices, |
28 | say Y here. Otherwise, say N. | 28 | say Y here. Otherwise, say N. |
29 | 29 | ||
30 | config RESET_UNIPHIER | ||
31 | tristate "Reset controller driver for UniPhier SoCs" | ||
32 | depends on ARCH_UNIPHIER || COMPILE_TEST | ||
33 | depends on OF && MFD_SYSCON | ||
34 | default ARCH_UNIPHIER | ||
35 | help | ||
36 | Support for reset controllers on UniPhier SoCs. | ||
37 | Say Y if you want to control reset signals provided by System Control | ||
38 | block, Media I/O block, Peripheral Block. | ||
39 | |||
30 | source "drivers/reset/sti/Kconfig" | 40 | source "drivers/reset/sti/Kconfig" |
31 | source "drivers/reset/hisilicon/Kconfig" | 41 | source "drivers/reset/hisilicon/Kconfig" |
32 | 42 | ||
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile index 64ebb0c4615c..9b45dcfa2a5f 100644 --- a/drivers/reset/Makefile +++ b/drivers/reset/Makefile | |||
@@ -12,3 +12,4 @@ obj-$(CONFIG_ARCH_ZYNQ) += reset-zynq.o | |||
12 | obj-$(CONFIG_ATH79) += reset-ath79.o | 12 | obj-$(CONFIG_ATH79) += reset-ath79.o |
13 | obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o | 13 | obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o |
14 | obj-$(CONFIG_TI_SYSCON_RESET) += reset-ti-syscon.o | 14 | obj-$(CONFIG_TI_SYSCON_RESET) += reset-ti-syscon.o |
15 | obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o | ||
diff --git a/drivers/reset/reset-uniphier.c b/drivers/reset/reset-uniphier.c new file mode 100644 index 000000000000..8b2558e7363e --- /dev/null +++ b/drivers/reset/reset-uniphier.c | |||
@@ -0,0 +1,440 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Socionext Inc. | ||
3 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | */ | ||
15 | |||
16 | #include <linux/mfd/syscon.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/of.h> | ||
19 | #include <linux/of_device.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/regmap.h> | ||
22 | #include <linux/reset-controller.h> | ||
23 | |||
24 | struct uniphier_reset_data { | ||
25 | unsigned int id; | ||
26 | unsigned int reg; | ||
27 | unsigned int bit; | ||
28 | unsigned int flags; | ||
29 | #define UNIPHIER_RESET_ACTIVE_LOW BIT(0) | ||
30 | }; | ||
31 | |||
32 | #define UNIPHIER_RESET_ID_END (unsigned int)(-1) | ||
33 | |||
34 | #define UNIPHIER_RESET_END \ | ||
35 | { .id = UNIPHIER_RESET_ID_END } | ||
36 | |||
37 | #define UNIPHIER_RESET(_id, _reg, _bit) \ | ||
38 | { \ | ||
39 | .id = (_id), \ | ||
40 | .reg = (_reg), \ | ||
41 | .bit = (_bit), \ | ||
42 | } | ||
43 | |||
44 | #define UNIPHIER_RESETX(_id, _reg, _bit) \ | ||
45 | { \ | ||
46 | .id = (_id), \ | ||
47 | .reg = (_reg), \ | ||
48 | .bit = (_bit), \ | ||
49 | .flags = UNIPHIER_RESET_ACTIVE_LOW, \ | ||
50 | } | ||
51 | |||
52 | /* System reset data */ | ||
53 | #define UNIPHIER_SLD3_SYS_RESET_STDMAC(id) \ | ||
54 | UNIPHIER_RESETX((id), 0x2000, 10) | ||
55 | |||
56 | #define UNIPHIER_LD11_SYS_RESET_STDMAC(id) \ | ||
57 | UNIPHIER_RESETX((id), 0x200c, 8) | ||
58 | |||
59 | #define UNIPHIER_PRO4_SYS_RESET_GIO(id) \ | ||
60 | UNIPHIER_RESETX((id), 0x2000, 6) | ||
61 | |||
62 | #define UNIPHIER_LD20_SYS_RESET_GIO(id) \ | ||
63 | UNIPHIER_RESETX((id), 0x200c, 5) | ||
64 | |||
65 | #define UNIPHIER_PRO4_SYS_RESET_USB3(id, ch) \ | ||
66 | UNIPHIER_RESETX((id), 0x2000 + 0x4 * (ch), 17) | ||
67 | |||
68 | const struct uniphier_reset_data uniphier_sld3_sys_reset_data[] = { | ||
69 | UNIPHIER_SLD3_SYS_RESET_STDMAC(8), /* Ether, HSC, MIO */ | ||
70 | UNIPHIER_RESET_END, | ||
71 | }; | ||
72 | |||
73 | const struct uniphier_reset_data uniphier_pro4_sys_reset_data[] = { | ||
74 | UNIPHIER_SLD3_SYS_RESET_STDMAC(8), /* HSC, MIO, RLE */ | ||
75 | UNIPHIER_PRO4_SYS_RESET_GIO(12), /* Ether, SATA, USB3 */ | ||
76 | UNIPHIER_PRO4_SYS_RESET_USB3(14, 0), | ||
77 | UNIPHIER_PRO4_SYS_RESET_USB3(15, 1), | ||
78 | UNIPHIER_RESET_END, | ||
79 | }; | ||
80 | |||
81 | const struct uniphier_reset_data uniphier_pro5_sys_reset_data[] = { | ||
82 | UNIPHIER_SLD3_SYS_RESET_STDMAC(8), /* HSC */ | ||
83 | UNIPHIER_PRO4_SYS_RESET_GIO(12), /* PCIe, USB3 */ | ||
84 | UNIPHIER_PRO4_SYS_RESET_USB3(14, 0), | ||
85 | UNIPHIER_PRO4_SYS_RESET_USB3(15, 1), | ||
86 | UNIPHIER_RESET_END, | ||
87 | }; | ||
88 | |||
89 | const struct uniphier_reset_data uniphier_pxs2_sys_reset_data[] = { | ||
90 | UNIPHIER_SLD3_SYS_RESET_STDMAC(8), /* HSC, RLE */ | ||
91 | UNIPHIER_PRO4_SYS_RESET_USB3(14, 0), | ||
92 | UNIPHIER_PRO4_SYS_RESET_USB3(15, 1), | ||
93 | UNIPHIER_RESETX(16, 0x2014, 4), /* USB30-PHY0 */ | ||
94 | UNIPHIER_RESETX(17, 0x2014, 0), /* USB30-PHY1 */ | ||
95 | UNIPHIER_RESETX(18, 0x2014, 2), /* USB30-PHY2 */ | ||
96 | UNIPHIER_RESETX(20, 0x2014, 5), /* USB31-PHY0 */ | ||
97 | UNIPHIER_RESETX(21, 0x2014, 1), /* USB31-PHY1 */ | ||
98 | UNIPHIER_RESETX(28, 0x2014, 12), /* SATA */ | ||
99 | UNIPHIER_RESET(29, 0x2014, 8), /* SATA-PHY (active high) */ | ||
100 | UNIPHIER_RESET_END, | ||
101 | }; | ||
102 | |||
103 | const struct uniphier_reset_data uniphier_ld11_sys_reset_data[] = { | ||
104 | UNIPHIER_LD11_SYS_RESET_STDMAC(8), /* HSC, MIO */ | ||
105 | UNIPHIER_RESET_END, | ||
106 | }; | ||
107 | |||
108 | const struct uniphier_reset_data uniphier_ld20_sys_reset_data[] = { | ||
109 | UNIPHIER_LD11_SYS_RESET_STDMAC(8), /* HSC */ | ||
110 | UNIPHIER_LD20_SYS_RESET_GIO(12), /* PCIe, USB3 */ | ||
111 | UNIPHIER_RESETX(16, 0x200c, 12), /* USB30-PHY0 */ | ||
112 | UNIPHIER_RESETX(17, 0x200c, 13), /* USB30-PHY1 */ | ||
113 | UNIPHIER_RESETX(18, 0x200c, 14), /* USB30-PHY2 */ | ||
114 | UNIPHIER_RESETX(19, 0x200c, 15), /* USB30-PHY3 */ | ||
115 | UNIPHIER_RESET_END, | ||
116 | }; | ||
117 | |||
118 | /* Media I/O reset data */ | ||
119 | #define UNIPHIER_MIO_RESET_SD(id, ch) \ | ||
120 | UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 0) | ||
121 | |||
122 | #define UNIPHIER_MIO_RESET_SD_BRIDGE(id, ch) \ | ||
123 | UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 26) | ||
124 | |||
125 | #define UNIPHIER_MIO_RESET_EMMC_HW_RESET(id, ch) \ | ||
126 | UNIPHIER_RESETX((id), 0x80 + 0x200 * (ch), 0) | ||
127 | |||
128 | #define UNIPHIER_MIO_RESET_USB2(id, ch) \ | ||
129 | UNIPHIER_RESETX((id), 0x114 + 0x200 * (ch), 0) | ||
130 | |||
131 | #define UNIPHIER_MIO_RESET_USB2_BRIDGE(id, ch) \ | ||
132 | UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 24) | ||
133 | |||
134 | #define UNIPHIER_MIO_RESET_DMAC(id) \ | ||
135 | UNIPHIER_RESETX((id), 0x110, 17) | ||
136 | |||
137 | const struct uniphier_reset_data uniphier_sld3_mio_reset_data[] = { | ||
138 | UNIPHIER_MIO_RESET_SD(0, 0), | ||
139 | UNIPHIER_MIO_RESET_SD(1, 1), | ||
140 | UNIPHIER_MIO_RESET_SD(2, 2), | ||
141 | UNIPHIER_MIO_RESET_SD_BRIDGE(3, 0), | ||
142 | UNIPHIER_MIO_RESET_SD_BRIDGE(4, 1), | ||
143 | UNIPHIER_MIO_RESET_SD_BRIDGE(5, 2), | ||
144 | UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1), | ||
145 | UNIPHIER_MIO_RESET_DMAC(7), | ||
146 | UNIPHIER_MIO_RESET_USB2(8, 0), | ||
147 | UNIPHIER_MIO_RESET_USB2(9, 1), | ||
148 | UNIPHIER_MIO_RESET_USB2(10, 2), | ||
149 | UNIPHIER_MIO_RESET_USB2(11, 3), | ||
150 | UNIPHIER_MIO_RESET_USB2_BRIDGE(12, 0), | ||
151 | UNIPHIER_MIO_RESET_USB2_BRIDGE(13, 1), | ||
152 | UNIPHIER_MIO_RESET_USB2_BRIDGE(14, 2), | ||
153 | UNIPHIER_MIO_RESET_USB2_BRIDGE(15, 3), | ||
154 | UNIPHIER_RESET_END, | ||
155 | }; | ||
156 | |||
157 | const struct uniphier_reset_data uniphier_pro5_mio_reset_data[] = { | ||
158 | UNIPHIER_MIO_RESET_SD(0, 0), | ||
159 | UNIPHIER_MIO_RESET_SD(1, 1), | ||
160 | UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1), | ||
161 | UNIPHIER_RESET_END, | ||
162 | }; | ||
163 | |||
164 | /* Peripheral reset data */ | ||
165 | #define UNIPHIER_PERI_RESET_UART(id, ch) \ | ||
166 | UNIPHIER_RESETX((id), 0x114, 19 + (ch)) | ||
167 | |||
168 | #define UNIPHIER_PERI_RESET_I2C(id, ch) \ | ||
169 | UNIPHIER_RESETX((id), 0x114, 5 + (ch)) | ||
170 | |||
171 | #define UNIPHIER_PERI_RESET_FI2C(id, ch) \ | ||
172 | UNIPHIER_RESETX((id), 0x114, 24 + (ch)) | ||
173 | |||
174 | const struct uniphier_reset_data uniphier_ld4_peri_reset_data[] = { | ||
175 | UNIPHIER_PERI_RESET_UART(0, 0), | ||
176 | UNIPHIER_PERI_RESET_UART(1, 1), | ||
177 | UNIPHIER_PERI_RESET_UART(2, 2), | ||
178 | UNIPHIER_PERI_RESET_UART(3, 3), | ||
179 | UNIPHIER_PERI_RESET_I2C(4, 0), | ||
180 | UNIPHIER_PERI_RESET_I2C(5, 1), | ||
181 | UNIPHIER_PERI_RESET_I2C(6, 2), | ||
182 | UNIPHIER_PERI_RESET_I2C(7, 3), | ||
183 | UNIPHIER_PERI_RESET_I2C(8, 4), | ||
184 | UNIPHIER_RESET_END, | ||
185 | }; | ||
186 | |||
187 | const struct uniphier_reset_data uniphier_pro4_peri_reset_data[] = { | ||
188 | UNIPHIER_PERI_RESET_UART(0, 0), | ||
189 | UNIPHIER_PERI_RESET_UART(1, 1), | ||
190 | UNIPHIER_PERI_RESET_UART(2, 2), | ||
191 | UNIPHIER_PERI_RESET_UART(3, 3), | ||
192 | UNIPHIER_PERI_RESET_FI2C(4, 0), | ||
193 | UNIPHIER_PERI_RESET_FI2C(5, 1), | ||
194 | UNIPHIER_PERI_RESET_FI2C(6, 2), | ||
195 | UNIPHIER_PERI_RESET_FI2C(7, 3), | ||
196 | UNIPHIER_PERI_RESET_FI2C(8, 4), | ||
197 | UNIPHIER_PERI_RESET_FI2C(9, 5), | ||
198 | UNIPHIER_PERI_RESET_FI2C(10, 6), | ||
199 | UNIPHIER_RESET_END, | ||
200 | }; | ||
201 | |||
202 | /* core implementaton */ | ||
203 | struct uniphier_reset_priv { | ||
204 | struct reset_controller_dev rcdev; | ||
205 | struct device *dev; | ||
206 | struct regmap *regmap; | ||
207 | const struct uniphier_reset_data *data; | ||
208 | }; | ||
209 | |||
210 | #define to_uniphier_reset_priv(_rcdev) \ | ||
211 | container_of(_rcdev, struct uniphier_reset_priv, rcdev) | ||
212 | |||
213 | static int uniphier_reset_update(struct reset_controller_dev *rcdev, | ||
214 | unsigned long id, int assert) | ||
215 | { | ||
216 | struct uniphier_reset_priv *priv = to_uniphier_reset_priv(rcdev); | ||
217 | const struct uniphier_reset_data *p; | ||
218 | |||
219 | for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) { | ||
220 | unsigned int mask, val; | ||
221 | |||
222 | if (p->id != id) | ||
223 | continue; | ||
224 | |||
225 | mask = BIT(p->bit); | ||
226 | |||
227 | if (assert) | ||
228 | val = mask; | ||
229 | else | ||
230 | val = ~mask; | ||
231 | |||
232 | if (p->flags & UNIPHIER_RESET_ACTIVE_LOW) | ||
233 | val = ~val; | ||
234 | |||
235 | return regmap_write_bits(priv->regmap, p->reg, mask, val); | ||
236 | } | ||
237 | |||
238 | dev_err(priv->dev, "reset_id=%lu was not handled\n", id); | ||
239 | return -EINVAL; | ||
240 | } | ||
241 | |||
242 | static int uniphier_reset_assert(struct reset_controller_dev *rcdev, | ||
243 | unsigned long id) | ||
244 | { | ||
245 | return uniphier_reset_update(rcdev, id, 1); | ||
246 | } | ||
247 | |||
248 | static int uniphier_reset_deassert(struct reset_controller_dev *rcdev, | ||
249 | unsigned long id) | ||
250 | { | ||
251 | return uniphier_reset_update(rcdev, id, 0); | ||
252 | } | ||
253 | |||
254 | static int uniphier_reset_status(struct reset_controller_dev *rcdev, | ||
255 | unsigned long id) | ||
256 | { | ||
257 | struct uniphier_reset_priv *priv = to_uniphier_reset_priv(rcdev); | ||
258 | const struct uniphier_reset_data *p; | ||
259 | |||
260 | for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) { | ||
261 | unsigned int val; | ||
262 | int ret, asserted; | ||
263 | |||
264 | if (p->id != id) | ||
265 | continue; | ||
266 | |||
267 | ret = regmap_read(priv->regmap, p->reg, &val); | ||
268 | if (ret) | ||
269 | return ret; | ||
270 | |||
271 | asserted = !!(val & BIT(p->bit)); | ||
272 | |||
273 | if (p->flags & UNIPHIER_RESET_ACTIVE_LOW) | ||
274 | asserted = !asserted; | ||
275 | |||
276 | return asserted; | ||
277 | } | ||
278 | |||
279 | dev_err(priv->dev, "reset_id=%lu was not found\n", id); | ||
280 | return -EINVAL; | ||
281 | } | ||
282 | |||
283 | static const struct reset_control_ops uniphier_reset_ops = { | ||
284 | .assert = uniphier_reset_assert, | ||
285 | .deassert = uniphier_reset_deassert, | ||
286 | .status = uniphier_reset_status, | ||
287 | }; | ||
288 | |||
289 | static int uniphier_reset_probe(struct platform_device *pdev) | ||
290 | { | ||
291 | struct device *dev = &pdev->dev; | ||
292 | struct uniphier_reset_priv *priv; | ||
293 | const struct uniphier_reset_data *p, *data; | ||
294 | struct regmap *regmap; | ||
295 | struct device_node *parent; | ||
296 | unsigned int nr_resets = 0; | ||
297 | |||
298 | data = of_device_get_match_data(dev); | ||
299 | if (WARN_ON(!data)) | ||
300 | return -EINVAL; | ||
301 | |||
302 | parent = of_get_parent(dev->of_node); /* parent should be syscon node */ | ||
303 | regmap = syscon_node_to_regmap(parent); | ||
304 | of_node_put(parent); | ||
305 | if (IS_ERR(regmap)) { | ||
306 | dev_err(dev, "failed to get regmap (error %ld)\n", | ||
307 | PTR_ERR(regmap)); | ||
308 | return PTR_ERR(regmap); | ||
309 | } | ||
310 | |||
311 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | ||
312 | if (!priv) | ||
313 | return -ENOMEM; | ||
314 | |||
315 | for (p = data; p->id != UNIPHIER_RESET_ID_END; p++) | ||
316 | nr_resets = max(nr_resets, p->id + 1); | ||
317 | |||
318 | priv->rcdev.ops = &uniphier_reset_ops; | ||
319 | priv->rcdev.owner = dev->driver->owner; | ||
320 | priv->rcdev.of_node = dev->of_node; | ||
321 | priv->rcdev.nr_resets = nr_resets; | ||
322 | priv->dev = dev; | ||
323 | priv->regmap = regmap; | ||
324 | priv->data = data; | ||
325 | |||
326 | return devm_reset_controller_register(&pdev->dev, &priv->rcdev); | ||
327 | } | ||
328 | |||
329 | static const struct of_device_id uniphier_reset_match[] = { | ||
330 | /* System reset */ | ||
331 | { | ||
332 | .compatible = "socionext,uniphier-sld3-reset", | ||
333 | .data = uniphier_sld3_sys_reset_data, | ||
334 | }, | ||
335 | { | ||
336 | .compatible = "socionext,uniphier-ld4-reset", | ||
337 | .data = uniphier_sld3_sys_reset_data, | ||
338 | }, | ||
339 | { | ||
340 | .compatible = "socionext,uniphier-pro4-reset", | ||
341 | .data = uniphier_pro4_sys_reset_data, | ||
342 | }, | ||
343 | { | ||
344 | .compatible = "socionext,uniphier-sld8-reset", | ||
345 | .data = uniphier_sld3_sys_reset_data, | ||
346 | }, | ||
347 | { | ||
348 | .compatible = "socionext,uniphier-pro5-reset", | ||
349 | .data = uniphier_pro5_sys_reset_data, | ||
350 | }, | ||
351 | { | ||
352 | .compatible = "socionext,uniphier-pxs2-reset", | ||
353 | .data = uniphier_pxs2_sys_reset_data, | ||
354 | }, | ||
355 | { | ||
356 | .compatible = "socionext,uniphier-ld11-reset", | ||
357 | .data = uniphier_ld11_sys_reset_data, | ||
358 | }, | ||
359 | { | ||
360 | .compatible = "socionext,uniphier-ld20-reset", | ||
361 | .data = uniphier_ld20_sys_reset_data, | ||
362 | }, | ||
363 | /* Media I/O reset */ | ||
364 | { | ||
365 | .compatible = "socionext,uniphier-sld3-mio-reset", | ||
366 | .data = uniphier_sld3_mio_reset_data, | ||
367 | }, | ||
368 | { | ||
369 | .compatible = "socionext,uniphier-ld4-mio-reset", | ||
370 | .data = uniphier_sld3_mio_reset_data, | ||
371 | }, | ||
372 | { | ||
373 | .compatible = "socionext,uniphier-pro4-mio-reset", | ||
374 | .data = uniphier_sld3_mio_reset_data, | ||
375 | }, | ||
376 | { | ||
377 | .compatible = "socionext,uniphier-sld8-mio-reset", | ||
378 | .data = uniphier_sld3_mio_reset_data, | ||
379 | }, | ||
380 | { | ||
381 | .compatible = "socionext,uniphier-pro5-mio-reset", | ||
382 | .data = uniphier_pro5_mio_reset_data, | ||
383 | }, | ||
384 | { | ||
385 | .compatible = "socionext,uniphier-pxs2-mio-reset", | ||
386 | .data = uniphier_pro5_mio_reset_data, | ||
387 | }, | ||
388 | { | ||
389 | .compatible = "socionext,uniphier-ld11-mio-reset", | ||
390 | .data = uniphier_sld3_mio_reset_data, | ||
391 | }, | ||
392 | { | ||
393 | .compatible = "socionext,uniphier-ld20-mio-reset", | ||
394 | .data = uniphier_pro5_mio_reset_data, | ||
395 | }, | ||
396 | /* Peripheral reset */ | ||
397 | { | ||
398 | .compatible = "socionext,uniphier-ld4-peri-reset", | ||
399 | .data = uniphier_ld4_peri_reset_data, | ||
400 | }, | ||
401 | { | ||
402 | .compatible = "socionext,uniphier-pro4-peri-reset", | ||
403 | .data = uniphier_pro4_peri_reset_data, | ||
404 | }, | ||
405 | { | ||
406 | .compatible = "socionext,uniphier-sld8-peri-reset", | ||
407 | .data = uniphier_ld4_peri_reset_data, | ||
408 | }, | ||
409 | { | ||
410 | .compatible = "socionext,uniphier-pro5-peri-reset", | ||
411 | .data = uniphier_pro4_peri_reset_data, | ||
412 | }, | ||
413 | { | ||
414 | .compatible = "socionext,uniphier-pxs2-peri-reset", | ||
415 | .data = uniphier_pro4_peri_reset_data, | ||
416 | }, | ||
417 | { | ||
418 | .compatible = "socionext,uniphier-ld11-peri-reset", | ||
419 | .data = uniphier_pro4_peri_reset_data, | ||
420 | }, | ||
421 | { | ||
422 | .compatible = "socionext,uniphier-ld20-peri-reset", | ||
423 | .data = uniphier_pro4_peri_reset_data, | ||
424 | }, | ||
425 | { /* sentinel */ } | ||
426 | }; | ||
427 | MODULE_DEVICE_TABLE(of, uniphier_reset_match); | ||
428 | |||
429 | static struct platform_driver uniphier_reset_driver = { | ||
430 | .probe = uniphier_reset_probe, | ||
431 | .driver = { | ||
432 | .name = "uniphier-reset", | ||
433 | .of_match_table = uniphier_reset_match, | ||
434 | }, | ||
435 | }; | ||
436 | module_platform_driver(uniphier_reset_driver); | ||
437 | |||
438 | MODULE_AUTHOR("Masahiro Yamada <yamada.masahiro@socionext.com>"); | ||
439 | MODULE_DESCRIPTION("UniPhier Reset Controller Driver"); | ||
440 | MODULE_LICENSE("GPL"); | ||