blob: 4ef4040cd702b99c3cf47b656dccec48bf10eb86 [file] [log] [blame]
Horatiu Vultur2d4fb842019-01-12 18:56:55 +01001// SPDX-License-Identifier: (GPL-2.0 OR MIT)
2/*
3 * Microsemi SoCs pinctrl driver
4 *
5 * Author: <horatiu.vultur@microchip.com>
6 * Copyright (c) 2018 Microsemi Corporation
7 */
8
Horatiu Vultur2d4fb842019-01-12 18:56:55 +01009#include <config.h>
10#include <dm.h>
11#include <dm/device-internal.h>
12#include <dm/lists.h>
13#include <dm/pinctrl.h>
14#include <dm/root.h>
15#include <errno.h>
16#include <fdtdec.h>
17#include <linux/io.h>
18#include <asm/gpio.h>
19#include <asm/system.h>
20#include "mscc-common.h"
21
22enum {
23 FUNC_NONE,
24 FUNC_GPIO,
25 FUNC_IRQ0_IN,
26 FUNC_IRQ0_OUT,
27 FUNC_IRQ1_IN,
28 FUNC_IRQ1_OUT,
29 FUNC_MIIM1,
30 FUNC_MIIM2,
31 FUNC_PCI_WAKE,
32 FUNC_PTP0,
33 FUNC_PTP1,
34 FUNC_PTP2,
35 FUNC_PTP3,
36 FUNC_PWM,
37 FUNC_RECO_CLK0,
38 FUNC_RECO_CLK1,
39 FUNC_SFP0,
40 FUNC_SFP1,
41 FUNC_SFP2,
42 FUNC_SFP3,
43 FUNC_SFP4,
44 FUNC_SFP5,
45 FUNC_SFP6,
46 FUNC_SFP7,
47 FUNC_SFP8,
48 FUNC_SFP9,
49 FUNC_SFP10,
50 FUNC_SFP11,
51 FUNC_SFP12,
52 FUNC_SFP13,
53 FUNC_SFP14,
54 FUNC_SFP15,
55 FUNC_SG0,
56 FUNC_SG1,
57 FUNC_SG2,
58 FUNC_SI,
59 FUNC_TACHO,
60 FUNC_TWI,
61 FUNC_TWI2,
62 FUNC_TWI_SCL_M,
63 FUNC_UART,
64 FUNC_UART2,
65 FUNC_MAX
66};
67
68static char * const jr2_function_names[] = {
69 [FUNC_NONE] = "none",
70 [FUNC_GPIO] = "gpio",
71 [FUNC_IRQ0_IN] = "irq0_in",
72 [FUNC_IRQ0_OUT] = "irq0_out",
73 [FUNC_IRQ1_IN] = "irq1_in",
74 [FUNC_IRQ1_OUT] = "irq1_out",
75 [FUNC_MIIM1] = "miim1",
76 [FUNC_MIIM2] = "miim2",
77 [FUNC_PCI_WAKE] = "pci_wake",
78 [FUNC_PTP0] = "ptp0",
79 [FUNC_PTP1] = "ptp1",
80 [FUNC_PTP2] = "ptp2",
81 [FUNC_PTP3] = "ptp3",
82 [FUNC_PWM] = "pwm",
83 [FUNC_RECO_CLK0] = "reco_clk0",
84 [FUNC_RECO_CLK1] = "reco_clk1",
85 [FUNC_SFP0] = "sfp0",
86 [FUNC_SFP1] = "sfp1",
87 [FUNC_SFP2] = "sfp2",
88 [FUNC_SFP3] = "sfp3",
89 [FUNC_SFP4] = "sfp4",
90 [FUNC_SFP5] = "sfp5",
91 [FUNC_SFP6] = "sfp6",
92 [FUNC_SFP7] = "sfp7",
93 [FUNC_SFP8] = "sfp8",
94 [FUNC_SFP9] = "sfp9",
95 [FUNC_SFP10] = "sfp10",
96 [FUNC_SFP11] = "sfp11",
97 [FUNC_SFP12] = "sfp12",
98 [FUNC_SFP13] = "sfp13",
99 [FUNC_SFP14] = "sfp14",
100 [FUNC_SFP15] = "sfp15",
101 [FUNC_SG0] = "sg0",
102 [FUNC_SG1] = "sg1",
103 [FUNC_SG2] = "sg2",
104 [FUNC_SI] = "si",
105 [FUNC_TACHO] = "tacho",
106 [FUNC_TWI] = "twi",
107 [FUNC_TWI2] = "twi2",
108 [FUNC_TWI_SCL_M] = "twi_scl_m",
109 [FUNC_UART] = "uart",
110 [FUNC_UART2] = "uart2",
111};
112
113#define JR2_P(p, f0, f1) \
114static struct mscc_pin_caps jr2_pin_##p = { \
115 .pin = p, \
116 .functions = { \
117 FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_NONE \
118 }, \
119}
120
121JR2_P(0, SG0, NONE);
122JR2_P(1, SG0, NONE);
123JR2_P(2, SG0, NONE);
124JR2_P(3, SG0, NONE);
125JR2_P(4, SG1, NONE);
126JR2_P(5, SG1, NONE);
127JR2_P(6, IRQ0_IN, IRQ0_OUT);
128JR2_P(7, IRQ1_IN, IRQ1_OUT);
129JR2_P(8, PTP0, NONE);
130JR2_P(9, PTP1, NONE);
131JR2_P(10, UART, NONE);
132JR2_P(11, UART, NONE);
133JR2_P(12, SG1, NONE);
134JR2_P(13, SG1, NONE);
135JR2_P(14, TWI, TWI_SCL_M);
136JR2_P(15, TWI, NONE);
137JR2_P(16, SI, TWI_SCL_M);
138JR2_P(17, SI, TWI_SCL_M);
139JR2_P(18, SI, TWI_SCL_M);
140JR2_P(19, PCI_WAKE, NONE);
141JR2_P(20, IRQ0_OUT, TWI_SCL_M);
142JR2_P(21, IRQ1_OUT, TWI_SCL_M);
143JR2_P(22, TACHO, NONE);
144JR2_P(23, PWM, NONE);
145JR2_P(24, UART2, NONE);
146JR2_P(25, UART2, SI);
147JR2_P(26, PTP2, SI);
148JR2_P(27, PTP3, SI);
149JR2_P(28, TWI2, SI);
150JR2_P(29, TWI, SI);
151JR2_P(30, SG2, SI);
152JR2_P(31, SG2, SI);
153JR2_P(32, SG2, SI);
154JR2_P(33, SG2, SI);
155JR2_P(34, NONE, TWI_SCL_M);
156JR2_P(35, NONE, TWI_SCL_M);
157JR2_P(36, NONE, TWI_SCL_M);
158JR2_P(37, NONE, TWI_SCL_M);
159JR2_P(38, NONE, TWI_SCL_M);
160JR2_P(39, NONE, TWI_SCL_M);
161JR2_P(40, NONE, TWI_SCL_M);
162JR2_P(41, NONE, TWI_SCL_M);
163JR2_P(42, NONE, TWI_SCL_M);
164JR2_P(43, NONE, TWI_SCL_M);
165JR2_P(44, NONE, SFP8);
166JR2_P(45, NONE, SFP9);
167JR2_P(46, NONE, SFP10);
168JR2_P(47, NONE, SFP11);
169JR2_P(48, SFP0, NONE);
170JR2_P(49, SFP1, SI);
171JR2_P(50, SFP2, SI);
172JR2_P(51, SFP3, SI);
173JR2_P(52, SFP4, NONE);
174JR2_P(53, SFP5, NONE);
175JR2_P(54, SFP6, NONE);
176JR2_P(55, SFP7, NONE);
177JR2_P(56, MIIM1, SFP12);
178JR2_P(57, MIIM1, SFP13);
179JR2_P(58, MIIM2, SFP14);
180JR2_P(59, MIIM2, SFP15);
181JR2_P(60, NONE, NONE);
182JR2_P(61, NONE, NONE);
183JR2_P(62, NONE, NONE);
184JR2_P(63, NONE, NONE);
185
186#define JR2_PIN(n) { \
187 .name = "GPIO_"#n, \
188 .drv_data = &jr2_pin_##n \
189}
190
191static const struct mscc_pin_data jr2_pins[] = {
192 JR2_PIN(0),
193 JR2_PIN(1),
194 JR2_PIN(2),
195 JR2_PIN(3),
196 JR2_PIN(4),
197 JR2_PIN(5),
198 JR2_PIN(6),
199 JR2_PIN(7),
200 JR2_PIN(8),
201 JR2_PIN(9),
202 JR2_PIN(10),
203 JR2_PIN(11),
204 JR2_PIN(12),
205 JR2_PIN(13),
206 JR2_PIN(14),
207 JR2_PIN(15),
208 JR2_PIN(16),
209 JR2_PIN(17),
210 JR2_PIN(18),
211 JR2_PIN(19),
212 JR2_PIN(20),
213 JR2_PIN(21),
214 JR2_PIN(22),
215 JR2_PIN(23),
216 JR2_PIN(24),
217 JR2_PIN(25),
218 JR2_PIN(26),
219 JR2_PIN(27),
220 JR2_PIN(28),
221 JR2_PIN(29),
222 JR2_PIN(30),
223 JR2_PIN(31),
224 JR2_PIN(32),
225 JR2_PIN(33),
226 JR2_PIN(34),
227 JR2_PIN(35),
228 JR2_PIN(36),
229 JR2_PIN(37),
230 JR2_PIN(38),
231 JR2_PIN(39),
232 JR2_PIN(40),
233 JR2_PIN(41),
234 JR2_PIN(42),
235 JR2_PIN(43),
236 JR2_PIN(44),
237 JR2_PIN(45),
238 JR2_PIN(46),
239 JR2_PIN(47),
240 JR2_PIN(48),
241 JR2_PIN(49),
242 JR2_PIN(50),
243 JR2_PIN(51),
244 JR2_PIN(52),
245 JR2_PIN(53),
246 JR2_PIN(54),
247 JR2_PIN(55),
248 JR2_PIN(56),
249 JR2_PIN(57),
250 JR2_PIN(58),
251 JR2_PIN(59),
252 JR2_PIN(60),
253 JR2_PIN(61),
254 JR2_PIN(62),
255 JR2_PIN(63),
256};
257
258static const unsigned long jr2_gpios[] = {
259 [MSCC_GPIO_OUT_SET] = 0x00,
260 [MSCC_GPIO_OUT_CLR] = 0x08,
261 [MSCC_GPIO_OUT] = 0x10,
262 [MSCC_GPIO_IN] = 0x18,
263 [MSCC_GPIO_OE] = 0x20,
264 [MSCC_GPIO_INTR] = 0x28,
265 [MSCC_GPIO_INTR_ENA] = 0x30,
266 [MSCC_GPIO_INTR_IDENT] = 0x38,
267 [MSCC_GPIO_ALT0] = 0x40,
268 [MSCC_GPIO_ALT1] = 0x48,
269};
270
271static int jr2_gpio_probe(struct udevice *dev)
272{
273 struct gpio_dev_priv *uc_priv;
274
275 uc_priv = dev_get_uclass_priv(dev);
276 uc_priv->bank_name = "jr2-gpio";
277 uc_priv->gpio_count = ARRAY_SIZE(jr2_pins);
278
279 return 0;
280}
281
282static struct driver jr2_gpio_driver = {
283 .name = "jr2-gpio",
284 .id = UCLASS_GPIO,
285 .probe = jr2_gpio_probe,
286 .ops = &mscc_gpio_ops,
287};
288
289static int jr2_pinctrl_probe(struct udevice *dev)
290{
291 int ret;
292
293 ret = mscc_pinctrl_probe(dev, FUNC_MAX, jr2_pins,
294 ARRAY_SIZE(jr2_pins),
295 jr2_function_names,
296 jr2_gpios);
297
298 if (ret)
299 return ret;
300
Simon Glass6996c662020-11-28 17:50:03 -0700301 ret = device_bind(dev, &jr2_gpio_driver, "jr2-gpio", NULL,
302 dev_ofnode(dev), NULL);
Horatiu Vultur2d4fb842019-01-12 18:56:55 +0100303
304 if (ret)
305 return ret;
306
307 return 0;
308}
309
310static const struct udevice_id jr2_pinctrl_of_match[] = {
311 { .compatible = "mscc,jaguar2-pinctrl" },
312 {},
313};
314
315U_BOOT_DRIVER(jr2_pinctrl) = {
316 .name = "jr2-pinctrl",
317 .id = UCLASS_PINCTRL,
318 .of_match = of_match_ptr(jr2_pinctrl_of_match),
319 .probe = jr2_pinctrl_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700320 .priv_auto = sizeof(struct mscc_pinctrl),
Horatiu Vultur2d4fb842019-01-12 18:56:55 +0100321 .ops = &mscc_pinctrl_ops,
322};