1 // SPDX-License-Identifier: GPL-2.0-only
3 * Oxford Semiconductor OXNAS SoC Family pinctrl driver
5 * Copyright (C) 2016 Neil Armstrong <narmstrong@baylibre.com>
7 * Based on pinctrl-pic32.c
8 * Joshua Henderson, <joshua.henderson@microchip.com>
9 * Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
11 #include <linux/gpio/driver.h>
12 #include <linux/interrupt.h>
14 #include <linux/irq.h>
16 #include <linux/of_device.h>
17 #include <linux/pinctrl/pinconf.h>
18 #include <linux/pinctrl/pinconf-generic.h>
19 #include <linux/pinctrl/pinctrl.h>
20 #include <linux/pinctrl/pinmux.h>
21 #include <linux/platform_device.h>
22 #include <linux/slab.h>
23 #include <linux/regmap.h>
24 #include <linux/mfd/syscon.h>
26 #include "pinctrl-utils.h"
28 #define PINS_PER_BANK 32
30 #define GPIO_BANK_START(bank) ((bank) * PINS_PER_BANK)
32 /* OX810 Regmap Offsets */
33 #define PINMUX_810_PRIMARY_SEL0 0x0c
34 #define PINMUX_810_SECONDARY_SEL0 0x14
35 #define PINMUX_810_TERTIARY_SEL0 0x8c
36 #define PINMUX_810_PRIMARY_SEL1 0x10
37 #define PINMUX_810_SECONDARY_SEL1 0x18
38 #define PINMUX_810_TERTIARY_SEL1 0x90
39 #define PINMUX_810_PULLUP_CTRL0 0xac
40 #define PINMUX_810_PULLUP_CTRL1 0xb0
42 /* OX820 Regmap Offsets */
43 #define PINMUX_820_BANK_OFFSET 0x100000
44 #define PINMUX_820_SECONDARY_SEL 0x14
45 #define PINMUX_820_TERTIARY_SEL 0x8c
46 #define PINMUX_820_QUATERNARY_SEL 0x94
47 #define PINMUX_820_DEBUG_SEL 0x9c
48 #define PINMUX_820_ALTERNATIVE_SEL 0xa4
49 #define PINMUX_820_PULLUP_CTRL 0xac
52 #define INPUT_VALUE 0x00
53 #define OUTPUT_EN 0x04
54 #define IRQ_PENDING 0x0c
55 #define OUTPUT_SET 0x14
56 #define OUTPUT_CLEAR 0x18
57 #define OUTPUT_EN_SET 0x1c
58 #define OUTPUT_EN_CLEAR 0x20
59 #define RE_IRQ_ENABLE 0x28
60 #define FE_IRQ_ENABLE 0x2c
62 struct oxnas_function {
64 const char * const *groups;
68 struct oxnas_pin_group {
72 struct oxnas_desc_function *functions;
75 struct oxnas_desc_function {
80 struct oxnas_gpio_bank {
81 void __iomem *reg_base;
82 struct gpio_chip gpio_chip;
83 struct irq_chip irq_chip;
87 struct oxnas_pinctrl {
88 struct regmap *regmap;
90 struct pinctrl_dev *pctldev;
91 const struct oxnas_function *functions;
92 unsigned int nfunctions;
93 const struct oxnas_pin_group *groups;
95 struct oxnas_gpio_bank *gpio_banks;
99 struct oxnas_pinctrl_data {
100 struct pinctrl_desc *desc;
101 struct oxnas_pinctrl *pctl;
104 static const struct pinctrl_pin_desc oxnas_ox810se_pins[] = {
105 PINCTRL_PIN(0, "gpio0"),
106 PINCTRL_PIN(1, "gpio1"),
107 PINCTRL_PIN(2, "gpio2"),
108 PINCTRL_PIN(3, "gpio3"),
109 PINCTRL_PIN(4, "gpio4"),
110 PINCTRL_PIN(5, "gpio5"),
111 PINCTRL_PIN(6, "gpio6"),
112 PINCTRL_PIN(7, "gpio7"),
113 PINCTRL_PIN(8, "gpio8"),
114 PINCTRL_PIN(9, "gpio9"),
115 PINCTRL_PIN(10, "gpio10"),
116 PINCTRL_PIN(11, "gpio11"),
117 PINCTRL_PIN(12, "gpio12"),
118 PINCTRL_PIN(13, "gpio13"),
119 PINCTRL_PIN(14, "gpio14"),
120 PINCTRL_PIN(15, "gpio15"),
121 PINCTRL_PIN(16, "gpio16"),
122 PINCTRL_PIN(17, "gpio17"),
123 PINCTRL_PIN(18, "gpio18"),
124 PINCTRL_PIN(19, "gpio19"),
125 PINCTRL_PIN(20, "gpio20"),
126 PINCTRL_PIN(21, "gpio21"),
127 PINCTRL_PIN(22, "gpio22"),
128 PINCTRL_PIN(23, "gpio23"),
129 PINCTRL_PIN(24, "gpio24"),
130 PINCTRL_PIN(25, "gpio25"),
131 PINCTRL_PIN(26, "gpio26"),
132 PINCTRL_PIN(27, "gpio27"),
133 PINCTRL_PIN(28, "gpio28"),
134 PINCTRL_PIN(29, "gpio29"),
135 PINCTRL_PIN(30, "gpio30"),
136 PINCTRL_PIN(31, "gpio31"),
137 PINCTRL_PIN(32, "gpio32"),
138 PINCTRL_PIN(33, "gpio33"),
139 PINCTRL_PIN(34, "gpio34"),
142 static const struct pinctrl_pin_desc oxnas_ox820_pins[] = {
143 PINCTRL_PIN(0, "gpio0"),
144 PINCTRL_PIN(1, "gpio1"),
145 PINCTRL_PIN(2, "gpio2"),
146 PINCTRL_PIN(3, "gpio3"),
147 PINCTRL_PIN(4, "gpio4"),
148 PINCTRL_PIN(5, "gpio5"),
149 PINCTRL_PIN(6, "gpio6"),
150 PINCTRL_PIN(7, "gpio7"),
151 PINCTRL_PIN(8, "gpio8"),
152 PINCTRL_PIN(9, "gpio9"),
153 PINCTRL_PIN(10, "gpio10"),
154 PINCTRL_PIN(11, "gpio11"),
155 PINCTRL_PIN(12, "gpio12"),
156 PINCTRL_PIN(13, "gpio13"),
157 PINCTRL_PIN(14, "gpio14"),
158 PINCTRL_PIN(15, "gpio15"),
159 PINCTRL_PIN(16, "gpio16"),
160 PINCTRL_PIN(17, "gpio17"),
161 PINCTRL_PIN(18, "gpio18"),
162 PINCTRL_PIN(19, "gpio19"),
163 PINCTRL_PIN(20, "gpio20"),
164 PINCTRL_PIN(21, "gpio21"),
165 PINCTRL_PIN(22, "gpio22"),
166 PINCTRL_PIN(23, "gpio23"),
167 PINCTRL_PIN(24, "gpio24"),
168 PINCTRL_PIN(25, "gpio25"),
169 PINCTRL_PIN(26, "gpio26"),
170 PINCTRL_PIN(27, "gpio27"),
171 PINCTRL_PIN(28, "gpio28"),
172 PINCTRL_PIN(29, "gpio29"),
173 PINCTRL_PIN(30, "gpio30"),
174 PINCTRL_PIN(31, "gpio31"),
175 PINCTRL_PIN(32, "gpio32"),
176 PINCTRL_PIN(33, "gpio33"),
177 PINCTRL_PIN(34, "gpio34"),
178 PINCTRL_PIN(35, "gpio35"),
179 PINCTRL_PIN(36, "gpio36"),
180 PINCTRL_PIN(37, "gpio37"),
181 PINCTRL_PIN(38, "gpio38"),
182 PINCTRL_PIN(39, "gpio39"),
183 PINCTRL_PIN(40, "gpio40"),
184 PINCTRL_PIN(41, "gpio41"),
185 PINCTRL_PIN(42, "gpio42"),
186 PINCTRL_PIN(43, "gpio43"),
187 PINCTRL_PIN(44, "gpio44"),
188 PINCTRL_PIN(45, "gpio45"),
189 PINCTRL_PIN(46, "gpio46"),
190 PINCTRL_PIN(47, "gpio47"),
191 PINCTRL_PIN(48, "gpio48"),
192 PINCTRL_PIN(49, "gpio49"),
195 static const char * const oxnas_ox810se_fct0_group[] = {
196 "gpio0", "gpio1", "gpio2", "gpio3",
197 "gpio4", "gpio5", "gpio6", "gpio7",
198 "gpio8", "gpio9", "gpio10", "gpio11",
199 "gpio12", "gpio13", "gpio14", "gpio15",
200 "gpio16", "gpio17", "gpio18", "gpio19",
201 "gpio20", "gpio21", "gpio22", "gpio23",
202 "gpio24", "gpio25", "gpio26", "gpio27",
203 "gpio28", "gpio29", "gpio30", "gpio31",
204 "gpio32", "gpio33", "gpio34"
207 static const char * const oxnas_ox810se_fct3_group[] = {
208 "gpio0", "gpio1", "gpio2", "gpio3",
209 "gpio4", "gpio5", "gpio6", "gpio7",
212 "gpio22", "gpio23", "gpio24", "gpio25",
213 "gpio26", "gpio27", "gpio28", "gpio29",
214 "gpio30", "gpio31", "gpio32", "gpio33",
218 static const char * const oxnas_ox820_fct0_group[] = {
219 "gpio0", "gpio1", "gpio2", "gpio3",
220 "gpio4", "gpio5", "gpio6", "gpio7",
221 "gpio8", "gpio9", "gpio10", "gpio11",
222 "gpio12", "gpio13", "gpio14", "gpio15",
223 "gpio16", "gpio17", "gpio18", "gpio19",
224 "gpio20", "gpio21", "gpio22", "gpio23",
225 "gpio24", "gpio25", "gpio26", "gpio27",
226 "gpio28", "gpio29", "gpio30", "gpio31",
227 "gpio32", "gpio33", "gpio34", "gpio35",
228 "gpio36", "gpio37", "gpio38", "gpio39",
229 "gpio40", "gpio41", "gpio42", "gpio43",
230 "gpio44", "gpio45", "gpio46", "gpio47",
234 static const char * const oxnas_ox820_fct1_group[] = {
236 "gpio12", "gpio13", "gpio14", "gpio15",
237 "gpio16", "gpio17", "gpio18", "gpio19",
238 "gpio20", "gpio21", "gpio22", "gpio23",
242 static const char * const oxnas_ox820_fct4_group[] = {
243 "gpio5", "gpio6", "gpio7", "gpio8",
244 "gpio24", "gpio25", "gpio26", "gpio27",
245 "gpio40", "gpio41", "gpio42", "gpio43"
248 static const char * const oxnas_ox820_fct5_group[] = {
249 "gpio28", "gpio29", "gpio30", "gpio31"
252 #define FUNCTION(_name, _gr) \
255 .groups = oxnas_##_gr##_group, \
256 .ngroups = ARRAY_SIZE(oxnas_##_gr##_group), \
259 static const struct oxnas_function oxnas_ox810se_functions[] = {
260 FUNCTION(gpio, ox810se_fct0),
261 FUNCTION(fct3, ox810se_fct3),
264 static const struct oxnas_function oxnas_ox820_functions[] = {
265 FUNCTION(gpio, ox820_fct0),
266 FUNCTION(fct1, ox820_fct1),
267 FUNCTION(fct4, ox820_fct4),
268 FUNCTION(fct5, ox820_fct5),
271 #define OXNAS_PINCTRL_GROUP(_pin, _name, ...) \
275 .bank = _pin / PINS_PER_BANK, \
276 .functions = (struct oxnas_desc_function[]){ \
277 __VA_ARGS__, { } }, \
280 #define OXNAS_PINCTRL_FUNCTION(_name, _fct) \
286 static const struct oxnas_pin_group oxnas_ox810se_groups[] = {
287 OXNAS_PINCTRL_GROUP(0, gpio0,
288 OXNAS_PINCTRL_FUNCTION(gpio, 0),
289 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
290 OXNAS_PINCTRL_GROUP(1, gpio1,
291 OXNAS_PINCTRL_FUNCTION(gpio, 0),
292 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
293 OXNAS_PINCTRL_GROUP(2, gpio2,
294 OXNAS_PINCTRL_FUNCTION(gpio, 0),
295 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
296 OXNAS_PINCTRL_GROUP(3, gpio3,
297 OXNAS_PINCTRL_FUNCTION(gpio, 0),
298 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
299 OXNAS_PINCTRL_GROUP(4, gpio4,
300 OXNAS_PINCTRL_FUNCTION(gpio, 0),
301 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
302 OXNAS_PINCTRL_GROUP(5, gpio5,
303 OXNAS_PINCTRL_FUNCTION(gpio, 0),
304 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
305 OXNAS_PINCTRL_GROUP(6, gpio6,
306 OXNAS_PINCTRL_FUNCTION(gpio, 0),
307 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
308 OXNAS_PINCTRL_GROUP(7, gpio7,
309 OXNAS_PINCTRL_FUNCTION(gpio, 0),
310 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
311 OXNAS_PINCTRL_GROUP(8, gpio8,
312 OXNAS_PINCTRL_FUNCTION(gpio, 0),
313 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
314 OXNAS_PINCTRL_GROUP(9, gpio9,
315 OXNAS_PINCTRL_FUNCTION(gpio, 0),
316 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
317 OXNAS_PINCTRL_GROUP(10, gpio10,
318 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
319 OXNAS_PINCTRL_GROUP(11, gpio11,
320 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
321 OXNAS_PINCTRL_GROUP(12, gpio12,
322 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
323 OXNAS_PINCTRL_GROUP(13, gpio13,
324 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
325 OXNAS_PINCTRL_GROUP(14, gpio14,
326 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
327 OXNAS_PINCTRL_GROUP(15, gpio15,
328 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
329 OXNAS_PINCTRL_GROUP(16, gpio16,
330 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
331 OXNAS_PINCTRL_GROUP(17, gpio17,
332 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
333 OXNAS_PINCTRL_GROUP(18, gpio18,
334 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
335 OXNAS_PINCTRL_GROUP(19, gpio19,
336 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
337 OXNAS_PINCTRL_GROUP(20, gpio20,
338 OXNAS_PINCTRL_FUNCTION(gpio, 0),
339 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
340 OXNAS_PINCTRL_GROUP(21, gpio21,
341 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
342 OXNAS_PINCTRL_GROUP(22, gpio22,
343 OXNAS_PINCTRL_FUNCTION(gpio, 0),
344 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
345 OXNAS_PINCTRL_GROUP(23, gpio23,
346 OXNAS_PINCTRL_FUNCTION(gpio, 0),
347 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
348 OXNAS_PINCTRL_GROUP(24, gpio24,
349 OXNAS_PINCTRL_FUNCTION(gpio, 0),
350 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
351 OXNAS_PINCTRL_GROUP(25, gpio25,
352 OXNAS_PINCTRL_FUNCTION(gpio, 0),
353 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
354 OXNAS_PINCTRL_GROUP(26, gpio26,
355 OXNAS_PINCTRL_FUNCTION(gpio, 0),
356 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
357 OXNAS_PINCTRL_GROUP(27, gpio27,
358 OXNAS_PINCTRL_FUNCTION(gpio, 0),
359 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
360 OXNAS_PINCTRL_GROUP(28, gpio28,
361 OXNAS_PINCTRL_FUNCTION(gpio, 0),
362 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
363 OXNAS_PINCTRL_GROUP(29, gpio29,
364 OXNAS_PINCTRL_FUNCTION(gpio, 0),
365 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
366 OXNAS_PINCTRL_GROUP(30, gpio30,
367 OXNAS_PINCTRL_FUNCTION(gpio, 0),
368 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
369 OXNAS_PINCTRL_GROUP(31, gpio31,
370 OXNAS_PINCTRL_FUNCTION(gpio, 0),
371 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
372 OXNAS_PINCTRL_GROUP(32, gpio32,
373 OXNAS_PINCTRL_FUNCTION(gpio, 0),
374 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
375 OXNAS_PINCTRL_GROUP(33, gpio33,
376 OXNAS_PINCTRL_FUNCTION(gpio, 0),
377 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
378 OXNAS_PINCTRL_GROUP(34, gpio34,
379 OXNAS_PINCTRL_FUNCTION(gpio, 0),
380 OXNAS_PINCTRL_FUNCTION(fct3, 3)),
383 static const struct oxnas_pin_group oxnas_ox820_groups[] = {
384 OXNAS_PINCTRL_GROUP(0, gpio0,
385 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
386 OXNAS_PINCTRL_GROUP(1, gpio1,
387 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
388 OXNAS_PINCTRL_GROUP(2, gpio2,
389 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
390 OXNAS_PINCTRL_GROUP(3, gpio3,
391 OXNAS_PINCTRL_FUNCTION(gpio, 0),
392 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
393 OXNAS_PINCTRL_GROUP(4, gpio4,
394 OXNAS_PINCTRL_FUNCTION(gpio, 0),
395 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
396 OXNAS_PINCTRL_GROUP(5, gpio5,
397 OXNAS_PINCTRL_FUNCTION(gpio, 0),
398 OXNAS_PINCTRL_FUNCTION(fct4, 4)),
399 OXNAS_PINCTRL_GROUP(6, gpio6,
400 OXNAS_PINCTRL_FUNCTION(gpio, 0),
401 OXNAS_PINCTRL_FUNCTION(fct4, 4)),
402 OXNAS_PINCTRL_GROUP(7, gpio7,
403 OXNAS_PINCTRL_FUNCTION(gpio, 0),
404 OXNAS_PINCTRL_FUNCTION(fct4, 4)),
405 OXNAS_PINCTRL_GROUP(8, gpio8,
406 OXNAS_PINCTRL_FUNCTION(gpio, 0),
407 OXNAS_PINCTRL_FUNCTION(fct4, 4)),
408 OXNAS_PINCTRL_GROUP(9, gpio9,
409 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
410 OXNAS_PINCTRL_GROUP(10, gpio10,
411 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
412 OXNAS_PINCTRL_GROUP(11, gpio11,
413 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
414 OXNAS_PINCTRL_GROUP(12, gpio12,
415 OXNAS_PINCTRL_FUNCTION(gpio, 0),
416 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
417 OXNAS_PINCTRL_GROUP(13, gpio13,
418 OXNAS_PINCTRL_FUNCTION(gpio, 0),
419 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
420 OXNAS_PINCTRL_GROUP(14, gpio14,
421 OXNAS_PINCTRL_FUNCTION(gpio, 0),
422 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
423 OXNAS_PINCTRL_GROUP(15, gpio15,
424 OXNAS_PINCTRL_FUNCTION(gpio, 0),
425 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
426 OXNAS_PINCTRL_GROUP(16, gpio16,
427 OXNAS_PINCTRL_FUNCTION(gpio, 0),
428 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
429 OXNAS_PINCTRL_GROUP(17, gpio17,
430 OXNAS_PINCTRL_FUNCTION(gpio, 0),
431 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
432 OXNAS_PINCTRL_GROUP(18, gpio18,
433 OXNAS_PINCTRL_FUNCTION(gpio, 0),
434 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
435 OXNAS_PINCTRL_GROUP(19, gpio19,
436 OXNAS_PINCTRL_FUNCTION(gpio, 0),
437 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
438 OXNAS_PINCTRL_GROUP(20, gpio20,
439 OXNAS_PINCTRL_FUNCTION(gpio, 0),
440 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
441 OXNAS_PINCTRL_GROUP(21, gpio21,
442 OXNAS_PINCTRL_FUNCTION(gpio, 0),
443 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
444 OXNAS_PINCTRL_GROUP(22, gpio22,
445 OXNAS_PINCTRL_FUNCTION(gpio, 0),
446 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
447 OXNAS_PINCTRL_GROUP(23, gpio23,
448 OXNAS_PINCTRL_FUNCTION(gpio, 0),
449 OXNAS_PINCTRL_FUNCTION(fct1, 1)),
450 OXNAS_PINCTRL_GROUP(24, gpio24,
451 OXNAS_PINCTRL_FUNCTION(gpio, 0),
452 OXNAS_PINCTRL_FUNCTION(fct1, 1),
453 OXNAS_PINCTRL_FUNCTION(fct4, 5)),
454 OXNAS_PINCTRL_GROUP(25, gpio25,
455 OXNAS_PINCTRL_FUNCTION(gpio, 0),
456 OXNAS_PINCTRL_FUNCTION(fct4, 4)),
457 OXNAS_PINCTRL_GROUP(26, gpio26,
458 OXNAS_PINCTRL_FUNCTION(gpio, 0),
459 OXNAS_PINCTRL_FUNCTION(fct4, 4)),
460 OXNAS_PINCTRL_GROUP(27, gpio27,
461 OXNAS_PINCTRL_FUNCTION(gpio, 0),
462 OXNAS_PINCTRL_FUNCTION(fct4, 4)),
463 OXNAS_PINCTRL_GROUP(28, gpio28,
464 OXNAS_PINCTRL_FUNCTION(gpio, 0),
465 OXNAS_PINCTRL_FUNCTION(fct5, 5)),
466 OXNAS_PINCTRL_GROUP(29, gpio29,
467 OXNAS_PINCTRL_FUNCTION(gpio, 0),
468 OXNAS_PINCTRL_FUNCTION(fct5, 5)),
469 OXNAS_PINCTRL_GROUP(30, gpio30,
470 OXNAS_PINCTRL_FUNCTION(gpio, 0),
471 OXNAS_PINCTRL_FUNCTION(fct5, 5)),
472 OXNAS_PINCTRL_GROUP(31, gpio31,
473 OXNAS_PINCTRL_FUNCTION(gpio, 0),
474 OXNAS_PINCTRL_FUNCTION(fct5, 5)),
475 OXNAS_PINCTRL_GROUP(32, gpio32,
476 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
477 OXNAS_PINCTRL_GROUP(33, gpio33,
478 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
479 OXNAS_PINCTRL_GROUP(34, gpio34,
480 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
481 OXNAS_PINCTRL_GROUP(35, gpio35,
482 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
483 OXNAS_PINCTRL_GROUP(36, gpio36,
484 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
485 OXNAS_PINCTRL_GROUP(37, gpio37,
486 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
487 OXNAS_PINCTRL_GROUP(38, gpio38,
488 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
489 OXNAS_PINCTRL_GROUP(39, gpio39,
490 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
491 OXNAS_PINCTRL_GROUP(40, gpio40,
492 OXNAS_PINCTRL_FUNCTION(gpio, 0),
493 OXNAS_PINCTRL_FUNCTION(fct4, 4)),
494 OXNAS_PINCTRL_GROUP(41, gpio41,
495 OXNAS_PINCTRL_FUNCTION(gpio, 0),
496 OXNAS_PINCTRL_FUNCTION(fct4, 4)),
497 OXNAS_PINCTRL_GROUP(42, gpio42,
498 OXNAS_PINCTRL_FUNCTION(gpio, 0),
499 OXNAS_PINCTRL_FUNCTION(fct4, 4)),
500 OXNAS_PINCTRL_GROUP(43, gpio43,
501 OXNAS_PINCTRL_FUNCTION(gpio, 0),
502 OXNAS_PINCTRL_FUNCTION(fct4, 4)),
503 OXNAS_PINCTRL_GROUP(44, gpio44,
504 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
505 OXNAS_PINCTRL_GROUP(45, gpio45,
506 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
507 OXNAS_PINCTRL_GROUP(46, gpio46,
508 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
509 OXNAS_PINCTRL_GROUP(47, gpio47,
510 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
511 OXNAS_PINCTRL_GROUP(48, gpio48,
512 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
513 OXNAS_PINCTRL_GROUP(49, gpio49,
514 OXNAS_PINCTRL_FUNCTION(gpio, 0)),
517 static inline struct oxnas_gpio_bank *pctl_to_bank(struct oxnas_pinctrl *pctl,
520 return &pctl->gpio_banks[pin / PINS_PER_BANK];
523 static int oxnas_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
525 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
527 return pctl->ngroups;
530 static const char *oxnas_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
533 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
535 return pctl->groups[group].name;
538 static int oxnas_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
540 const unsigned int **pins,
541 unsigned int *num_pins)
543 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
545 *pins = &pctl->groups[group].pin;
551 static const struct pinctrl_ops oxnas_pinctrl_ops = {
552 .get_groups_count = oxnas_pinctrl_get_groups_count,
553 .get_group_name = oxnas_pinctrl_get_group_name,
554 .get_group_pins = oxnas_pinctrl_get_group_pins,
555 .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
556 .dt_free_map = pinctrl_utils_free_map,
559 static int oxnas_pinmux_get_functions_count(struct pinctrl_dev *pctldev)
561 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
563 return pctl->nfunctions;
567 oxnas_pinmux_get_function_name(struct pinctrl_dev *pctldev, unsigned int func)
569 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
571 return pctl->functions[func].name;
574 static int oxnas_pinmux_get_function_groups(struct pinctrl_dev *pctldev,
576 const char * const **groups,
577 unsigned int * const num_groups)
579 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
581 *groups = pctl->functions[func].groups;
582 *num_groups = pctl->functions[func].ngroups;
587 static int oxnas_ox810se_pinmux_enable(struct pinctrl_dev *pctldev,
588 unsigned int func, unsigned int group)
590 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
591 const struct oxnas_pin_group *pg = &pctl->groups[group];
592 const struct oxnas_function *pf = &pctl->functions[func];
593 const char *fname = pf->name;
594 struct oxnas_desc_function *functions = pg->functions;
595 u32 mask = BIT(pg->pin);
597 while (functions->name) {
598 if (!strcmp(functions->name, fname)) {
600 "setting function %s bank %d pin %d fct %d mask %x\n",
601 fname, pg->bank, pg->pin,
602 functions->fct, mask);
604 regmap_write_bits(pctl->regmap,
606 PINMUX_810_PRIMARY_SEL1 :
607 PINMUX_810_PRIMARY_SEL0),
609 (functions->fct == 1 ?
611 regmap_write_bits(pctl->regmap,
613 PINMUX_810_SECONDARY_SEL1 :
614 PINMUX_810_SECONDARY_SEL0),
616 (functions->fct == 2 ?
618 regmap_write_bits(pctl->regmap,
620 PINMUX_810_TERTIARY_SEL1 :
621 PINMUX_810_TERTIARY_SEL0),
623 (functions->fct == 3 ?
632 dev_err(pctl->dev, "cannot mux pin %u to function %u\n", group, func);
637 static int oxnas_ox820_pinmux_enable(struct pinctrl_dev *pctldev,
638 unsigned int func, unsigned int group)
640 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
641 const struct oxnas_pin_group *pg = &pctl->groups[group];
642 const struct oxnas_function *pf = &pctl->functions[func];
643 const char *fname = pf->name;
644 struct oxnas_desc_function *functions = pg->functions;
645 unsigned int offset = (pg->bank ? PINMUX_820_BANK_OFFSET : 0);
646 u32 mask = BIT(pg->pin);
648 while (functions->name) {
649 if (!strcmp(functions->name, fname)) {
651 "setting function %s bank %d pin %d fct %d mask %x\n",
652 fname, pg->bank, pg->pin,
653 functions->fct, mask);
655 regmap_write_bits(pctl->regmap,
656 offset + PINMUX_820_SECONDARY_SEL,
658 (functions->fct == 1 ?
660 regmap_write_bits(pctl->regmap,
661 offset + PINMUX_820_TERTIARY_SEL,
663 (functions->fct == 2 ?
665 regmap_write_bits(pctl->regmap,
666 offset + PINMUX_820_QUATERNARY_SEL,
668 (functions->fct == 3 ?
670 regmap_write_bits(pctl->regmap,
671 offset + PINMUX_820_DEBUG_SEL,
673 (functions->fct == 4 ?
675 regmap_write_bits(pctl->regmap,
676 offset + PINMUX_820_ALTERNATIVE_SEL,
678 (functions->fct == 5 ?
687 dev_err(pctl->dev, "cannot mux pin %u to function %u\n", group, func);
692 static int oxnas_ox810se_gpio_request_enable(struct pinctrl_dev *pctldev,
693 struct pinctrl_gpio_range *range,
696 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
697 struct oxnas_gpio_bank *bank = gpiochip_get_data(range->gc);
698 u32 mask = BIT(offset - bank->gpio_chip.base);
700 dev_dbg(pctl->dev, "requesting gpio %d in bank %d (id %d) with mask 0x%x\n",
701 offset, bank->gpio_chip.base, bank->id, mask);
703 regmap_write_bits(pctl->regmap,
705 PINMUX_810_PRIMARY_SEL1 :
706 PINMUX_810_PRIMARY_SEL0),
708 regmap_write_bits(pctl->regmap,
710 PINMUX_810_SECONDARY_SEL1 :
711 PINMUX_810_SECONDARY_SEL0),
713 regmap_write_bits(pctl->regmap,
715 PINMUX_810_TERTIARY_SEL1 :
716 PINMUX_810_TERTIARY_SEL0),
722 static int oxnas_ox820_gpio_request_enable(struct pinctrl_dev *pctldev,
723 struct pinctrl_gpio_range *range,
726 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
727 struct oxnas_gpio_bank *bank = gpiochip_get_data(range->gc);
728 unsigned int bank_offset = (bank->id ? PINMUX_820_BANK_OFFSET : 0);
729 u32 mask = BIT(offset - bank->gpio_chip.base);
731 dev_dbg(pctl->dev, "requesting gpio %d in bank %d (id %d) with mask 0x%x\n",
732 offset, bank->gpio_chip.base, bank->id, mask);
734 regmap_write_bits(pctl->regmap,
735 bank_offset + PINMUX_820_SECONDARY_SEL,
737 regmap_write_bits(pctl->regmap,
738 bank_offset + PINMUX_820_TERTIARY_SEL,
740 regmap_write_bits(pctl->regmap,
741 bank_offset + PINMUX_820_QUATERNARY_SEL,
743 regmap_write_bits(pctl->regmap,
744 bank_offset + PINMUX_820_DEBUG_SEL,
746 regmap_write_bits(pctl->regmap,
747 bank_offset + PINMUX_820_ALTERNATIVE_SEL,
753 static int oxnas_gpio_get_direction(struct gpio_chip *chip,
756 struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
757 u32 mask = BIT(offset);
759 if (readl_relaxed(bank->reg_base + OUTPUT_EN) & mask)
760 return GPIO_LINE_DIRECTION_OUT;
762 return GPIO_LINE_DIRECTION_IN;
765 static int oxnas_gpio_direction_input(struct gpio_chip *chip,
768 struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
769 u32 mask = BIT(offset);
771 writel_relaxed(mask, bank->reg_base + OUTPUT_EN_CLEAR);
776 static int oxnas_gpio_get(struct gpio_chip *chip, unsigned int offset)
778 struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
779 u32 mask = BIT(offset);
781 return (readl_relaxed(bank->reg_base + INPUT_VALUE) & mask) != 0;
784 static void oxnas_gpio_set(struct gpio_chip *chip, unsigned int offset,
787 struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
788 u32 mask = BIT(offset);
791 writel_relaxed(mask, bank->reg_base + OUTPUT_SET);
793 writel_relaxed(mask, bank->reg_base + OUTPUT_CLEAR);
796 static int oxnas_gpio_direction_output(struct gpio_chip *chip,
797 unsigned int offset, int value)
799 struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
800 u32 mask = BIT(offset);
802 oxnas_gpio_set(chip, offset, value);
803 writel_relaxed(mask, bank->reg_base + OUTPUT_EN_SET);
808 static int oxnas_gpio_set_direction(struct pinctrl_dev *pctldev,
809 struct pinctrl_gpio_range *range,
810 unsigned int offset, bool input)
812 struct gpio_chip *chip = range->gc;
815 oxnas_gpio_direction_input(chip, offset);
817 oxnas_gpio_direction_output(chip, offset, 0);
822 static const struct pinmux_ops oxnas_ox810se_pinmux_ops = {
823 .get_functions_count = oxnas_pinmux_get_functions_count,
824 .get_function_name = oxnas_pinmux_get_function_name,
825 .get_function_groups = oxnas_pinmux_get_function_groups,
826 .set_mux = oxnas_ox810se_pinmux_enable,
827 .gpio_request_enable = oxnas_ox810se_gpio_request_enable,
828 .gpio_set_direction = oxnas_gpio_set_direction,
831 static const struct pinmux_ops oxnas_ox820_pinmux_ops = {
832 .get_functions_count = oxnas_pinmux_get_functions_count,
833 .get_function_name = oxnas_pinmux_get_function_name,
834 .get_function_groups = oxnas_pinmux_get_function_groups,
835 .set_mux = oxnas_ox820_pinmux_enable,
836 .gpio_request_enable = oxnas_ox820_gpio_request_enable,
837 .gpio_set_direction = oxnas_gpio_set_direction,
840 static int oxnas_ox810se_pinconf_get(struct pinctrl_dev *pctldev,
841 unsigned int pin, unsigned long *config)
843 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
844 struct oxnas_gpio_bank *bank = pctl_to_bank(pctl, pin);
845 unsigned int param = pinconf_to_config_param(*config);
846 u32 mask = BIT(pin - bank->gpio_chip.base);
851 case PIN_CONFIG_BIAS_PULL_UP:
852 ret = regmap_read(pctl->regmap,
854 PINMUX_810_PULLUP_CTRL1 :
855 PINMUX_810_PULLUP_CTRL0),
860 arg = !!(arg & mask);
866 *config = pinconf_to_config_packed(param, arg);
871 static int oxnas_ox820_pinconf_get(struct pinctrl_dev *pctldev,
872 unsigned int pin, unsigned long *config)
874 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
875 struct oxnas_gpio_bank *bank = pctl_to_bank(pctl, pin);
876 unsigned int param = pinconf_to_config_param(*config);
877 unsigned int bank_offset = (bank->id ? PINMUX_820_BANK_OFFSET : 0);
878 u32 mask = BIT(pin - bank->gpio_chip.base);
883 case PIN_CONFIG_BIAS_PULL_UP:
884 ret = regmap_read(pctl->regmap,
885 bank_offset + PINMUX_820_PULLUP_CTRL,
890 arg = !!(arg & mask);
896 *config = pinconf_to_config_packed(param, arg);
901 static int oxnas_ox810se_pinconf_set(struct pinctrl_dev *pctldev,
902 unsigned int pin, unsigned long *configs,
903 unsigned int num_configs)
905 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
906 struct oxnas_gpio_bank *bank = pctl_to_bank(pctl, pin);
909 u32 offset = pin - bank->gpio_chip.base;
910 u32 mask = BIT(offset);
912 dev_dbg(pctl->dev, "setting pin %d bank %d mask 0x%x\n",
913 pin, bank->gpio_chip.base, mask);
915 for (i = 0; i < num_configs; i++) {
916 param = pinconf_to_config_param(configs[i]);
919 case PIN_CONFIG_BIAS_PULL_UP:
920 dev_dbg(pctl->dev, " pullup\n");
921 regmap_write_bits(pctl->regmap,
923 PINMUX_810_PULLUP_CTRL1 :
924 PINMUX_810_PULLUP_CTRL0),
928 dev_err(pctl->dev, "Property %u not supported\n",
937 static int oxnas_ox820_pinconf_set(struct pinctrl_dev *pctldev,
938 unsigned int pin, unsigned long *configs,
939 unsigned int num_configs)
941 struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
942 struct oxnas_gpio_bank *bank = pctl_to_bank(pctl, pin);
943 unsigned int bank_offset = (bank->id ? PINMUX_820_BANK_OFFSET : 0);
946 u32 offset = pin - bank->gpio_chip.base;
947 u32 mask = BIT(offset);
949 dev_dbg(pctl->dev, "setting pin %d bank %d mask 0x%x\n",
950 pin, bank->gpio_chip.base, mask);
952 for (i = 0; i < num_configs; i++) {
953 param = pinconf_to_config_param(configs[i]);
956 case PIN_CONFIG_BIAS_PULL_UP:
957 dev_dbg(pctl->dev, " pullup\n");
958 regmap_write_bits(pctl->regmap,
959 bank_offset + PINMUX_820_PULLUP_CTRL,
963 dev_err(pctl->dev, "Property %u not supported\n",
972 static const struct pinconf_ops oxnas_ox810se_pinconf_ops = {
973 .pin_config_get = oxnas_ox810se_pinconf_get,
974 .pin_config_set = oxnas_ox810se_pinconf_set,
978 static const struct pinconf_ops oxnas_ox820_pinconf_ops = {
979 .pin_config_get = oxnas_ox820_pinconf_get,
980 .pin_config_set = oxnas_ox820_pinconf_set,
984 static void oxnas_gpio_irq_ack(struct irq_data *data)
986 struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
987 struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
988 u32 mask = BIT(data->hwirq);
990 writel(mask, bank->reg_base + IRQ_PENDING);
993 static void oxnas_gpio_irq_mask(struct irq_data *data)
995 struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
996 struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
997 unsigned int type = irqd_get_trigger_type(data);
998 u32 mask = BIT(data->hwirq);
1000 if (type & IRQ_TYPE_EDGE_RISING)
1001 writel(readl(bank->reg_base + RE_IRQ_ENABLE) & ~mask,
1002 bank->reg_base + RE_IRQ_ENABLE);
1004 if (type & IRQ_TYPE_EDGE_FALLING)
1005 writel(readl(bank->reg_base + FE_IRQ_ENABLE) & ~mask,
1006 bank->reg_base + FE_IRQ_ENABLE);
1009 static void oxnas_gpio_irq_unmask(struct irq_data *data)
1011 struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
1012 struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
1013 unsigned int type = irqd_get_trigger_type(data);
1014 u32 mask = BIT(data->hwirq);
1016 if (type & IRQ_TYPE_EDGE_RISING)
1017 writel(readl(bank->reg_base + RE_IRQ_ENABLE) | mask,
1018 bank->reg_base + RE_IRQ_ENABLE);
1020 if (type & IRQ_TYPE_EDGE_FALLING)
1021 writel(readl(bank->reg_base + FE_IRQ_ENABLE) | mask,
1022 bank->reg_base + FE_IRQ_ENABLE);
1025 static unsigned int oxnas_gpio_irq_startup(struct irq_data *data)
1027 struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
1029 oxnas_gpio_direction_input(chip, data->hwirq);
1030 oxnas_gpio_irq_unmask(data);
1035 static int oxnas_gpio_irq_set_type(struct irq_data *data, unsigned int type)
1037 if ((type & (IRQ_TYPE_EDGE_RISING|IRQ_TYPE_EDGE_FALLING)) == 0)
1040 irq_set_handler_locked(data, handle_edge_irq);
1045 static void oxnas_gpio_irq_handler(struct irq_desc *desc)
1047 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
1048 struct oxnas_gpio_bank *bank = gpiochip_get_data(gc);
1049 struct irq_chip *chip = irq_desc_get_chip(desc);
1053 chained_irq_enter(chip, desc);
1055 stat = readl(bank->reg_base + IRQ_PENDING);
1057 for_each_set_bit(pin, &stat, BITS_PER_LONG)
1058 generic_handle_domain_irq(gc->irq.domain, pin);
1060 chained_irq_exit(chip, desc);
1063 #define GPIO_BANK(_bank) \
1066 .label = "GPIO" #_bank, \
1067 .request = gpiochip_generic_request, \
1068 .free = gpiochip_generic_free, \
1069 .get_direction = oxnas_gpio_get_direction, \
1070 .direction_input = oxnas_gpio_direction_input, \
1071 .direction_output = oxnas_gpio_direction_output, \
1072 .get = oxnas_gpio_get, \
1073 .set = oxnas_gpio_set, \
1074 .ngpio = PINS_PER_BANK, \
1075 .base = GPIO_BANK_START(_bank), \
1076 .owner = THIS_MODULE, \
1080 .name = "GPIO" #_bank, \
1081 .irq_startup = oxnas_gpio_irq_startup, \
1082 .irq_ack = oxnas_gpio_irq_ack, \
1083 .irq_mask = oxnas_gpio_irq_mask, \
1084 .irq_unmask = oxnas_gpio_irq_unmask, \
1085 .irq_set_type = oxnas_gpio_irq_set_type, \
1089 static struct oxnas_gpio_bank oxnas_gpio_banks[] = {
1094 static struct oxnas_pinctrl ox810se_pinctrl = {
1095 .functions = oxnas_ox810se_functions,
1096 .nfunctions = ARRAY_SIZE(oxnas_ox810se_functions),
1097 .groups = oxnas_ox810se_groups,
1098 .ngroups = ARRAY_SIZE(oxnas_ox810se_groups),
1099 .gpio_banks = oxnas_gpio_banks,
1100 .nbanks = ARRAY_SIZE(oxnas_gpio_banks),
1103 static struct pinctrl_desc oxnas_ox810se_pinctrl_desc = {
1104 .name = "oxnas-pinctrl",
1105 .pins = oxnas_ox810se_pins,
1106 .npins = ARRAY_SIZE(oxnas_ox810se_pins),
1107 .pctlops = &oxnas_pinctrl_ops,
1108 .pmxops = &oxnas_ox810se_pinmux_ops,
1109 .confops = &oxnas_ox810se_pinconf_ops,
1110 .owner = THIS_MODULE,
1113 static struct oxnas_pinctrl ox820_pinctrl = {
1114 .functions = oxnas_ox820_functions,
1115 .nfunctions = ARRAY_SIZE(oxnas_ox820_functions),
1116 .groups = oxnas_ox820_groups,
1117 .ngroups = ARRAY_SIZE(oxnas_ox820_groups),
1118 .gpio_banks = oxnas_gpio_banks,
1119 .nbanks = ARRAY_SIZE(oxnas_gpio_banks),
1122 static struct pinctrl_desc oxnas_ox820_pinctrl_desc = {
1123 .name = "oxnas-pinctrl",
1124 .pins = oxnas_ox820_pins,
1125 .npins = ARRAY_SIZE(oxnas_ox820_pins),
1126 .pctlops = &oxnas_pinctrl_ops,
1127 .pmxops = &oxnas_ox820_pinmux_ops,
1128 .confops = &oxnas_ox820_pinconf_ops,
1129 .owner = THIS_MODULE,
1132 static struct oxnas_pinctrl_data oxnas_ox810se_pinctrl_data = {
1133 .desc = &oxnas_ox810se_pinctrl_desc,
1134 .pctl = &ox810se_pinctrl,
1137 static struct oxnas_pinctrl_data oxnas_ox820_pinctrl_data = {
1138 .desc = &oxnas_ox820_pinctrl_desc,
1139 .pctl = &ox820_pinctrl,
1142 static const struct of_device_id oxnas_pinctrl_of_match[] = {
1143 { .compatible = "oxsemi,ox810se-pinctrl",
1144 .data = &oxnas_ox810se_pinctrl_data
1146 { .compatible = "oxsemi,ox820-pinctrl",
1147 .data = &oxnas_ox820_pinctrl_data,
1152 static int oxnas_pinctrl_probe(struct platform_device *pdev)
1154 const struct of_device_id *id;
1155 const struct oxnas_pinctrl_data *data;
1156 struct oxnas_pinctrl *pctl;
1158 id = of_match_node(oxnas_pinctrl_of_match, pdev->dev.of_node);
1163 if (!data || !data->pctl || !data->desc)
1166 pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL);
1169 pctl->dev = &pdev->dev;
1170 dev_set_drvdata(&pdev->dev, pctl);
1172 pctl->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
1174 if (IS_ERR(pctl->regmap)) {
1175 dev_err(&pdev->dev, "failed to get sys ctrl regmap\n");
1179 pctl->functions = data->pctl->functions;
1180 pctl->nfunctions = data->pctl->nfunctions;
1181 pctl->groups = data->pctl->groups;
1182 pctl->ngroups = data->pctl->ngroups;
1183 pctl->gpio_banks = data->pctl->gpio_banks;
1184 pctl->nbanks = data->pctl->nbanks;
1186 pctl->pctldev = pinctrl_register(data->desc, &pdev->dev, pctl);
1187 if (IS_ERR(pctl->pctldev)) {
1188 dev_err(&pdev->dev, "Failed to register pinctrl device\n");
1189 return PTR_ERR(pctl->pctldev);
1195 static int oxnas_gpio_probe(struct platform_device *pdev)
1197 struct device_node *np = pdev->dev.of_node;
1198 struct of_phandle_args pinspec;
1199 struct oxnas_gpio_bank *bank;
1200 unsigned int id, ngpios;
1202 struct gpio_irq_chip *girq;
1204 if (of_parse_phandle_with_fixed_args(np, "gpio-ranges",
1206 dev_err(&pdev->dev, "gpio-ranges property not found\n");
1210 id = pinspec.args[1] / PINS_PER_BANK;
1211 ngpios = pinspec.args[2];
1213 if (id >= ARRAY_SIZE(oxnas_gpio_banks)) {
1214 dev_err(&pdev->dev, "invalid gpio-ranges base arg\n");
1218 if (ngpios > PINS_PER_BANK) {
1219 dev_err(&pdev->dev, "invalid gpio-ranges count arg\n");
1223 bank = &oxnas_gpio_banks[id];
1225 bank->reg_base = devm_platform_ioremap_resource(pdev, 0);
1226 if (IS_ERR(bank->reg_base))
1227 return PTR_ERR(bank->reg_base);
1229 irq = platform_get_irq(pdev, 0);
1234 bank->gpio_chip.parent = &pdev->dev;
1235 bank->gpio_chip.ngpio = ngpios;
1236 girq = &bank->gpio_chip.irq;
1237 girq->chip = &bank->irq_chip;
1238 girq->parent_handler = oxnas_gpio_irq_handler;
1239 girq->num_parents = 1;
1240 girq->parents = devm_kcalloc(&pdev->dev, 1, sizeof(*girq->parents),
1244 girq->parents[0] = irq;
1245 girq->default_type = IRQ_TYPE_NONE;
1246 girq->handler = handle_level_irq;
1248 ret = gpiochip_add_data(&bank->gpio_chip, bank);
1250 dev_err(&pdev->dev, "Failed to add GPIO chip %u: %d\n",
1258 static struct platform_driver oxnas_pinctrl_driver = {
1260 .name = "oxnas-pinctrl",
1261 .of_match_table = oxnas_pinctrl_of_match,
1262 .suppress_bind_attrs = true,
1264 .probe = oxnas_pinctrl_probe,
1267 static const struct of_device_id oxnas_gpio_of_match[] = {
1268 { .compatible = "oxsemi,ox810se-gpio", },
1269 { .compatible = "oxsemi,ox820-gpio", },
1273 static struct platform_driver oxnas_gpio_driver = {
1275 .name = "oxnas-gpio",
1276 .of_match_table = oxnas_gpio_of_match,
1277 .suppress_bind_attrs = true,
1279 .probe = oxnas_gpio_probe,
1282 static int __init oxnas_gpio_register(void)
1284 return platform_driver_register(&oxnas_gpio_driver);
1286 arch_initcall(oxnas_gpio_register);
1288 static int __init oxnas_pinctrl_register(void)
1290 return platform_driver_register(&oxnas_pinctrl_driver);
1292 arch_initcall(oxnas_pinctrl_register);