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 return !(readl_relaxed(bank
->reg_base
+ OUTPUT_EN
) & mask
);
762 static int oxnas_gpio_direction_input(struct gpio_chip
*chip
,
765 struct oxnas_gpio_bank
*bank
= gpiochip_get_data(chip
);
766 u32 mask
= BIT(offset
);
768 writel_relaxed(mask
, bank
->reg_base
+ OUTPUT_EN_CLEAR
);
773 static int oxnas_gpio_get(struct gpio_chip
*chip
, unsigned int offset
)
775 struct oxnas_gpio_bank
*bank
= gpiochip_get_data(chip
);
776 u32 mask
= BIT(offset
);
778 return (readl_relaxed(bank
->reg_base
+ INPUT_VALUE
) & mask
) != 0;
781 static void oxnas_gpio_set(struct gpio_chip
*chip
, unsigned int offset
,
784 struct oxnas_gpio_bank
*bank
= gpiochip_get_data(chip
);
785 u32 mask
= BIT(offset
);
788 writel_relaxed(mask
, bank
->reg_base
+ OUTPUT_SET
);
790 writel_relaxed(mask
, bank
->reg_base
+ OUTPUT_CLEAR
);
793 static int oxnas_gpio_direction_output(struct gpio_chip
*chip
,
794 unsigned int offset
, int value
)
796 struct oxnas_gpio_bank
*bank
= gpiochip_get_data(chip
);
797 u32 mask
= BIT(offset
);
799 oxnas_gpio_set(chip
, offset
, value
);
800 writel_relaxed(mask
, bank
->reg_base
+ OUTPUT_EN_SET
);
805 static int oxnas_gpio_set_direction(struct pinctrl_dev
*pctldev
,
806 struct pinctrl_gpio_range
*range
,
807 unsigned int offset
, bool input
)
809 struct gpio_chip
*chip
= range
->gc
;
812 oxnas_gpio_direction_input(chip
, offset
);
814 oxnas_gpio_direction_output(chip
, offset
, 0);
819 static const struct pinmux_ops oxnas_ox810se_pinmux_ops
= {
820 .get_functions_count
= oxnas_pinmux_get_functions_count
,
821 .get_function_name
= oxnas_pinmux_get_function_name
,
822 .get_function_groups
= oxnas_pinmux_get_function_groups
,
823 .set_mux
= oxnas_ox810se_pinmux_enable
,
824 .gpio_request_enable
= oxnas_ox810se_gpio_request_enable
,
825 .gpio_set_direction
= oxnas_gpio_set_direction
,
828 static const struct pinmux_ops oxnas_ox820_pinmux_ops
= {
829 .get_functions_count
= oxnas_pinmux_get_functions_count
,
830 .get_function_name
= oxnas_pinmux_get_function_name
,
831 .get_function_groups
= oxnas_pinmux_get_function_groups
,
832 .set_mux
= oxnas_ox820_pinmux_enable
,
833 .gpio_request_enable
= oxnas_ox820_gpio_request_enable
,
834 .gpio_set_direction
= oxnas_gpio_set_direction
,
837 static int oxnas_ox810se_pinconf_get(struct pinctrl_dev
*pctldev
,
838 unsigned int pin
, unsigned long *config
)
840 struct oxnas_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
841 struct oxnas_gpio_bank
*bank
= pctl_to_bank(pctl
, pin
);
842 unsigned int param
= pinconf_to_config_param(*config
);
843 u32 mask
= BIT(pin
- bank
->gpio_chip
.base
);
848 case PIN_CONFIG_BIAS_PULL_UP
:
849 ret
= regmap_read(pctl
->regmap
,
851 PINMUX_810_PULLUP_CTRL1
:
852 PINMUX_810_PULLUP_CTRL0
),
857 arg
= !!(arg
& mask
);
863 *config
= pinconf_to_config_packed(param
, arg
);
868 static int oxnas_ox820_pinconf_get(struct pinctrl_dev
*pctldev
,
869 unsigned int pin
, unsigned long *config
)
871 struct oxnas_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
872 struct oxnas_gpio_bank
*bank
= pctl_to_bank(pctl
, pin
);
873 unsigned int param
= pinconf_to_config_param(*config
);
874 unsigned int bank_offset
= (bank
->id
? PINMUX_820_BANK_OFFSET
: 0);
875 u32 mask
= BIT(pin
- bank
->gpio_chip
.base
);
880 case PIN_CONFIG_BIAS_PULL_UP
:
881 ret
= regmap_read(pctl
->regmap
,
882 bank_offset
+ PINMUX_820_PULLUP_CTRL
,
887 arg
= !!(arg
& mask
);
893 *config
= pinconf_to_config_packed(param
, arg
);
898 static int oxnas_ox810se_pinconf_set(struct pinctrl_dev
*pctldev
,
899 unsigned int pin
, unsigned long *configs
,
900 unsigned int num_configs
)
902 struct oxnas_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
903 struct oxnas_gpio_bank
*bank
= pctl_to_bank(pctl
, pin
);
906 u32 offset
= pin
- bank
->gpio_chip
.base
;
907 u32 mask
= BIT(offset
);
909 dev_dbg(pctl
->dev
, "setting pin %d bank %d mask 0x%x\n",
910 pin
, bank
->gpio_chip
.base
, mask
);
912 for (i
= 0; i
< num_configs
; i
++) {
913 param
= pinconf_to_config_param(configs
[i
]);
916 case PIN_CONFIG_BIAS_PULL_UP
:
917 dev_dbg(pctl
->dev
, " pullup\n");
918 regmap_write_bits(pctl
->regmap
,
920 PINMUX_810_PULLUP_CTRL1
:
921 PINMUX_810_PULLUP_CTRL0
),
925 dev_err(pctl
->dev
, "Property %u not supported\n",
934 static int oxnas_ox820_pinconf_set(struct pinctrl_dev
*pctldev
,
935 unsigned int pin
, unsigned long *configs
,
936 unsigned int num_configs
)
938 struct oxnas_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
939 struct oxnas_gpio_bank
*bank
= pctl_to_bank(pctl
, pin
);
940 unsigned int bank_offset
= (bank
->id
? PINMUX_820_BANK_OFFSET
: 0);
943 u32 offset
= pin
- bank
->gpio_chip
.base
;
944 u32 mask
= BIT(offset
);
946 dev_dbg(pctl
->dev
, "setting pin %d bank %d mask 0x%x\n",
947 pin
, bank
->gpio_chip
.base
, mask
);
949 for (i
= 0; i
< num_configs
; i
++) {
950 param
= pinconf_to_config_param(configs
[i
]);
953 case PIN_CONFIG_BIAS_PULL_UP
:
954 dev_dbg(pctl
->dev
, " pullup\n");
955 regmap_write_bits(pctl
->regmap
,
956 bank_offset
+ PINMUX_820_PULLUP_CTRL
,
960 dev_err(pctl
->dev
, "Property %u not supported\n",
969 static const struct pinconf_ops oxnas_ox810se_pinconf_ops
= {
970 .pin_config_get
= oxnas_ox810se_pinconf_get
,
971 .pin_config_set
= oxnas_ox810se_pinconf_set
,
975 static const struct pinconf_ops oxnas_ox820_pinconf_ops
= {
976 .pin_config_get
= oxnas_ox820_pinconf_get
,
977 .pin_config_set
= oxnas_ox820_pinconf_set
,
981 static void oxnas_gpio_irq_ack(struct irq_data
*data
)
983 struct gpio_chip
*chip
= irq_data_get_irq_chip_data(data
);
984 struct oxnas_gpio_bank
*bank
= gpiochip_get_data(chip
);
985 u32 mask
= BIT(data
->hwirq
);
987 writel(mask
, bank
->reg_base
+ IRQ_PENDING
);
990 static void oxnas_gpio_irq_mask(struct irq_data
*data
)
992 struct gpio_chip
*chip
= irq_data_get_irq_chip_data(data
);
993 struct oxnas_gpio_bank
*bank
= gpiochip_get_data(chip
);
994 unsigned int type
= irqd_get_trigger_type(data
);
995 u32 mask
= BIT(data
->hwirq
);
997 if (type
& IRQ_TYPE_EDGE_RISING
)
998 writel(readl(bank
->reg_base
+ RE_IRQ_ENABLE
) & ~mask
,
999 bank
->reg_base
+ RE_IRQ_ENABLE
);
1001 if (type
& IRQ_TYPE_EDGE_FALLING
)
1002 writel(readl(bank
->reg_base
+ FE_IRQ_ENABLE
) & ~mask
,
1003 bank
->reg_base
+ FE_IRQ_ENABLE
);
1006 static void oxnas_gpio_irq_unmask(struct irq_data
*data
)
1008 struct gpio_chip
*chip
= irq_data_get_irq_chip_data(data
);
1009 struct oxnas_gpio_bank
*bank
= gpiochip_get_data(chip
);
1010 unsigned int type
= irqd_get_trigger_type(data
);
1011 u32 mask
= BIT(data
->hwirq
);
1013 if (type
& IRQ_TYPE_EDGE_RISING
)
1014 writel(readl(bank
->reg_base
+ RE_IRQ_ENABLE
) | mask
,
1015 bank
->reg_base
+ RE_IRQ_ENABLE
);
1017 if (type
& IRQ_TYPE_EDGE_FALLING
)
1018 writel(readl(bank
->reg_base
+ FE_IRQ_ENABLE
) | mask
,
1019 bank
->reg_base
+ FE_IRQ_ENABLE
);
1022 static unsigned int oxnas_gpio_irq_startup(struct irq_data
*data
)
1024 struct gpio_chip
*chip
= irq_data_get_irq_chip_data(data
);
1026 oxnas_gpio_direction_input(chip
, data
->hwirq
);
1027 oxnas_gpio_irq_unmask(data
);
1032 static int oxnas_gpio_irq_set_type(struct irq_data
*data
, unsigned int type
)
1034 if ((type
& (IRQ_TYPE_EDGE_RISING
|IRQ_TYPE_EDGE_FALLING
)) == 0)
1037 irq_set_handler_locked(data
, handle_edge_irq
);
1042 static void oxnas_gpio_irq_handler(struct irq_desc
*desc
)
1044 struct gpio_chip
*gc
= irq_desc_get_handler_data(desc
);
1045 struct oxnas_gpio_bank
*bank
= gpiochip_get_data(gc
);
1046 struct irq_chip
*chip
= irq_desc_get_chip(desc
);
1050 chained_irq_enter(chip
, desc
);
1052 stat
= readl(bank
->reg_base
+ IRQ_PENDING
);
1054 for_each_set_bit(pin
, &stat
, BITS_PER_LONG
)
1055 generic_handle_irq(irq_linear_revmap(gc
->irq
.domain
, pin
));
1057 chained_irq_exit(chip
, desc
);
1060 #define GPIO_BANK(_bank) \
1063 .label = "GPIO" #_bank, \
1064 .request = gpiochip_generic_request, \
1065 .free = gpiochip_generic_free, \
1066 .get_direction = oxnas_gpio_get_direction, \
1067 .direction_input = oxnas_gpio_direction_input, \
1068 .direction_output = oxnas_gpio_direction_output, \
1069 .get = oxnas_gpio_get, \
1070 .set = oxnas_gpio_set, \
1071 .ngpio = PINS_PER_BANK, \
1072 .base = GPIO_BANK_START(_bank), \
1073 .owner = THIS_MODULE, \
1077 .name = "GPIO" #_bank, \
1078 .irq_startup = oxnas_gpio_irq_startup, \
1079 .irq_ack = oxnas_gpio_irq_ack, \
1080 .irq_mask = oxnas_gpio_irq_mask, \
1081 .irq_unmask = oxnas_gpio_irq_unmask, \
1082 .irq_set_type = oxnas_gpio_irq_set_type, \
1086 static struct oxnas_gpio_bank oxnas_gpio_banks
[] = {
1091 static struct oxnas_pinctrl ox810se_pinctrl
= {
1092 .functions
= oxnas_ox810se_functions
,
1093 .nfunctions
= ARRAY_SIZE(oxnas_ox810se_functions
),
1094 .groups
= oxnas_ox810se_groups
,
1095 .ngroups
= ARRAY_SIZE(oxnas_ox810se_groups
),
1096 .gpio_banks
= oxnas_gpio_banks
,
1097 .nbanks
= ARRAY_SIZE(oxnas_gpio_banks
),
1100 static struct pinctrl_desc oxnas_ox810se_pinctrl_desc
= {
1101 .name
= "oxnas-pinctrl",
1102 .pins
= oxnas_ox810se_pins
,
1103 .npins
= ARRAY_SIZE(oxnas_ox810se_pins
),
1104 .pctlops
= &oxnas_pinctrl_ops
,
1105 .pmxops
= &oxnas_ox810se_pinmux_ops
,
1106 .confops
= &oxnas_ox810se_pinconf_ops
,
1107 .owner
= THIS_MODULE
,
1110 static struct oxnas_pinctrl ox820_pinctrl
= {
1111 .functions
= oxnas_ox820_functions
,
1112 .nfunctions
= ARRAY_SIZE(oxnas_ox820_functions
),
1113 .groups
= oxnas_ox820_groups
,
1114 .ngroups
= ARRAY_SIZE(oxnas_ox820_groups
),
1115 .gpio_banks
= oxnas_gpio_banks
,
1116 .nbanks
= ARRAY_SIZE(oxnas_gpio_banks
),
1119 static struct pinctrl_desc oxnas_ox820_pinctrl_desc
= {
1120 .name
= "oxnas-pinctrl",
1121 .pins
= oxnas_ox820_pins
,
1122 .npins
= ARRAY_SIZE(oxnas_ox820_pins
),
1123 .pctlops
= &oxnas_pinctrl_ops
,
1124 .pmxops
= &oxnas_ox820_pinmux_ops
,
1125 .confops
= &oxnas_ox820_pinconf_ops
,
1126 .owner
= THIS_MODULE
,
1129 static struct oxnas_pinctrl_data oxnas_ox810se_pinctrl_data
= {
1130 .desc
= &oxnas_ox810se_pinctrl_desc
,
1131 .pctl
= &ox810se_pinctrl
,
1134 static struct oxnas_pinctrl_data oxnas_ox820_pinctrl_data
= {
1135 .desc
= &oxnas_ox820_pinctrl_desc
,
1136 .pctl
= &ox820_pinctrl
,
1139 static const struct of_device_id oxnas_pinctrl_of_match
[] = {
1140 { .compatible
= "oxsemi,ox810se-pinctrl",
1141 .data
= &oxnas_ox810se_pinctrl_data
1143 { .compatible
= "oxsemi,ox820-pinctrl",
1144 .data
= &oxnas_ox820_pinctrl_data
,
1149 static int oxnas_pinctrl_probe(struct platform_device
*pdev
)
1151 const struct of_device_id
*id
;
1152 const struct oxnas_pinctrl_data
*data
;
1153 struct oxnas_pinctrl
*pctl
;
1155 id
= of_match_node(oxnas_pinctrl_of_match
, pdev
->dev
.of_node
);
1160 if (!data
|| !data
->pctl
|| !data
->desc
)
1163 pctl
= devm_kzalloc(&pdev
->dev
, sizeof(*pctl
), GFP_KERNEL
);
1166 pctl
->dev
= &pdev
->dev
;
1167 dev_set_drvdata(&pdev
->dev
, pctl
);
1169 pctl
->regmap
= syscon_regmap_lookup_by_phandle(pdev
->dev
.of_node
,
1171 if (IS_ERR(pctl
->regmap
)) {
1172 dev_err(&pdev
->dev
, "failed to get sys ctrl regmap\n");
1176 pctl
->functions
= data
->pctl
->functions
;
1177 pctl
->nfunctions
= data
->pctl
->nfunctions
;
1178 pctl
->groups
= data
->pctl
->groups
;
1179 pctl
->ngroups
= data
->pctl
->ngroups
;
1180 pctl
->gpio_banks
= data
->pctl
->gpio_banks
;
1181 pctl
->nbanks
= data
->pctl
->nbanks
;
1183 pctl
->pctldev
= pinctrl_register(data
->desc
, &pdev
->dev
, pctl
);
1184 if (IS_ERR(pctl
->pctldev
)) {
1185 dev_err(&pdev
->dev
, "Failed to register pinctrl device\n");
1186 return PTR_ERR(pctl
->pctldev
);
1192 static int oxnas_gpio_probe(struct platform_device
*pdev
)
1194 struct device_node
*np
= pdev
->dev
.of_node
;
1195 struct of_phandle_args pinspec
;
1196 struct oxnas_gpio_bank
*bank
;
1197 unsigned int id
, ngpios
;
1199 struct gpio_irq_chip
*girq
;
1201 if (of_parse_phandle_with_fixed_args(np
, "gpio-ranges",
1203 dev_err(&pdev
->dev
, "gpio-ranges property not found\n");
1207 id
= pinspec
.args
[1] / PINS_PER_BANK
;
1208 ngpios
= pinspec
.args
[2];
1210 if (id
>= ARRAY_SIZE(oxnas_gpio_banks
)) {
1211 dev_err(&pdev
->dev
, "invalid gpio-ranges base arg\n");
1215 if (ngpios
> PINS_PER_BANK
) {
1216 dev_err(&pdev
->dev
, "invalid gpio-ranges count arg\n");
1220 bank
= &oxnas_gpio_banks
[id
];
1222 bank
->reg_base
= devm_platform_ioremap_resource(pdev
, 0);
1223 if (IS_ERR(bank
->reg_base
))
1224 return PTR_ERR(bank
->reg_base
);
1226 irq
= platform_get_irq(pdev
, 0);
1231 bank
->gpio_chip
.parent
= &pdev
->dev
;
1232 bank
->gpio_chip
.of_node
= np
;
1233 bank
->gpio_chip
.ngpio
= ngpios
;
1234 girq
= &bank
->gpio_chip
.irq
;
1235 girq
->chip
= &bank
->irq_chip
;
1236 girq
->parent_handler
= oxnas_gpio_irq_handler
;
1237 girq
->num_parents
= 1;
1238 girq
->parents
= devm_kcalloc(&pdev
->dev
, 1, sizeof(*girq
->parents
),
1242 girq
->parents
[0] = irq
;
1243 girq
->default_type
= IRQ_TYPE_NONE
;
1244 girq
->handler
= handle_level_irq
;
1246 ret
= gpiochip_add_data(&bank
->gpio_chip
, bank
);
1248 dev_err(&pdev
->dev
, "Failed to add GPIO chip %u: %d\n",
1256 static struct platform_driver oxnas_pinctrl_driver
= {
1258 .name
= "oxnas-pinctrl",
1259 .of_match_table
= oxnas_pinctrl_of_match
,
1260 .suppress_bind_attrs
= true,
1262 .probe
= oxnas_pinctrl_probe
,
1265 static const struct of_device_id oxnas_gpio_of_match
[] = {
1266 { .compatible
= "oxsemi,ox810se-gpio", },
1267 { .compatible
= "oxsemi,ox820-gpio", },
1271 static struct platform_driver oxnas_gpio_driver
= {
1273 .name
= "oxnas-gpio",
1274 .of_match_table
= oxnas_gpio_of_match
,
1275 .suppress_bind_attrs
= true,
1277 .probe
= oxnas_gpio_probe
,
1280 static int __init
oxnas_gpio_register(void)
1282 return platform_driver_register(&oxnas_gpio_driver
);
1284 arch_initcall(oxnas_gpio_register
);
1286 static int __init
oxnas_pinctrl_register(void)
1288 return platform_driver_register(&oxnas_pinctrl_driver
);
1290 arch_initcall(oxnas_pinctrl_register
);