1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Author: Lorenzo Bianconi <lorenzo@kernel.org>
4 * Author: Benjamin Larsson <benjamin.larsson@genexis.eu>
5 * Author: Markus Gothe <markus.gothe@genexis.eu>
6 */
7
8 #include <dt-bindings/pinctrl/mt65xx.h>
9 #include <linux/bitfield.h>
10 #include <linux/bits.h>
11 #include <linux/cleanup.h>
12 #include <linux/gpio/driver.h>
13 #include <linux/interrupt.h>
14 #include <linux/io.h>
15 #include <linux/irq.h>
16 #include <linux/irqdomain.h>
17 #include <linux/mfd/syscon.h>
18 #include <linux/of.h>
19 #include <linux/of_irq.h>
20 #include <linux/of_platform.h>
21 #include <linux/pinctrl/consumer.h>
22 #include <linux/pinctrl/pinctrl.h>
23 #include <linux/pinctrl/pinconf.h>
24 #include <linux/pinctrl/pinconf-generic.h>
25 #include <linux/pinctrl/pinmux.h>
26 #include <linux/platform_device.h>
27 #include <linux/regmap.h>
28
29 #include "../core.h"
30 #include "../pinconf.h"
31 #include "../pinmux.h"
32
33 #define PINCTRL_PIN_GROUP(id) \
34 PINCTRL_PINGROUP(#id, id##_pins, ARRAY_SIZE(id##_pins))
35
36 #define PINCTRL_FUNC_DESC(id) \
37 { \
38 .desc = { \
39 .func = { \
40 .name = #id, \
41 .groups = id##_groups, \
42 .ngroups = ARRAY_SIZE(id##_groups), \
43 } \
44 }, \
45 .groups = id##_func_group, \
46 .group_size = ARRAY_SIZE(id##_func_group), \
47 }
48
49 #define PINCTRL_CONF_DESC(p, offset, mask) \
50 { \
51 .pin = p, \
52 .reg = { offset, mask }, \
53 }
54
55 /* MUX */
56 #define REG_GPIO_2ND_I2C_MODE 0x0214
57 #define GPIO_MDC_IO_MASTER_MODE_MODE BIT(14)
58 #define GPIO_I2C_MASTER_MODE_MODE BIT(13)
59 #define GPIO_I2S_MODE_MASK BIT(12)
60 #define GPIO_I2C_SLAVE_MODE_MODE BIT(11)
61 #define GPIO_LAN3_LED1_MODE_MASK BIT(10)
62 #define GPIO_LAN3_LED0_MODE_MASK BIT(9)
63 #define GPIO_LAN2_LED1_MODE_MASK BIT(8)
64 #define GPIO_LAN2_LED0_MODE_MASK BIT(7)
65 #define GPIO_LAN1_LED1_MODE_MASK BIT(6)
66 #define GPIO_LAN1_LED0_MODE_MASK BIT(5)
67 #define GPIO_LAN0_LED1_MODE_MASK BIT(4)
68 #define GPIO_LAN0_LED0_MODE_MASK BIT(3)
69 #define PON_TOD_1PPS_MODE_MASK BIT(2)
70 #define GSW_TOD_1PPS_MODE_MASK BIT(1)
71 #define GPIO_2ND_I2C_MODE_MASK BIT(0)
72
73 #define REG_GPIO_SPI_CS1_MODE 0x0218
74 #define GPIO_PCM_SPI_CS4_MODE_MASK BIT(21)
75 #define GPIO_PCM_SPI_CS3_MODE_MASK BIT(20)
76 #define GPIO_PCM_SPI_CS2_MODE_P156_MASK BIT(19)
77 #define GPIO_PCM_SPI_CS2_MODE_P128_MASK BIT(18)
78 #define GPIO_PCM_SPI_CS1_MODE_MASK BIT(17)
79 #define GPIO_PCM_SPI_MODE_MASK BIT(16)
80 #define GPIO_PCM2_MODE_MASK BIT(13)
81 #define GPIO_PCM1_MODE_MASK BIT(12)
82 #define GPIO_PCM_INT_MODE_MASK BIT(9)
83 #define GPIO_PCM_RESET_MODE_MASK BIT(8)
84 #define GPIO_SPI_QUAD_MODE_MASK BIT(4)
85 #define GPIO_SPI_CS4_MODE_MASK BIT(3)
86 #define GPIO_SPI_CS3_MODE_MASK BIT(2)
87 #define GPIO_SPI_CS2_MODE_MASK BIT(1)
88 #define GPIO_SPI_CS1_MODE_MASK BIT(0)
89
90 #define REG_GPIO_PON_MODE 0x021c
91 #define GPIO_PARALLEL_NAND_MODE_MASK BIT(14)
92 #define GPIO_SGMII_MDIO_MODE_MASK BIT(13)
93 #define GPIO_PCIE_RESET2_MASK BIT(12)
94 #define SIPO_RCLK_MODE_MASK BIT(11)
95 #define GPIO_PCIE_RESET1_MASK BIT(10)
96 #define GPIO_PCIE_RESET0_MASK BIT(9)
97 #define GPIO_UART5_MODE_MASK BIT(8)
98 #define GPIO_UART4_MODE_MASK BIT(7)
99 #define GPIO_HSUART_CTS_RTS_MODE_MASK BIT(6)
100 #define GPIO_HSUART_MODE_MASK BIT(5)
101 #define GPIO_UART2_CTS_RTS_MODE_MASK BIT(4)
102 #define GPIO_UART2_MODE_MASK BIT(3)
103 #define GPIO_SIPO_MODE_MASK BIT(2)
104 #define GPIO_EMMC_MODE_MASK BIT(1)
105 #define GPIO_PON_MODE_MASK BIT(0)
106
107 #define REG_NPU_UART_EN 0x0224
108 #define JTAG_UDI_EN_MASK BIT(4)
109 #define JTAG_DFD_EN_MASK BIT(3)
110
111 /* LED MAP */
112 #define REG_LAN_LED0_MAPPING 0x027c
113 #define REG_LAN_LED1_MAPPING 0x0280
114
115 #define LAN4_LED_MAPPING_MASK GENMASK(18, 16)
116 #define LAN4_PHY_LED_MAP(_n) FIELD_PREP_CONST(LAN4_LED_MAPPING_MASK, (_n))
117
118 #define LAN3_LED_MAPPING_MASK GENMASK(14, 12)
119 #define LAN3_PHY_LED_MAP(_n) FIELD_PREP_CONST(LAN3_LED_MAPPING_MASK, (_n))
120
121 #define LAN2_LED_MAPPING_MASK GENMASK(10, 8)
122 #define LAN2_PHY_LED_MAP(_n) FIELD_PREP_CONST(LAN2_LED_MAPPING_MASK, (_n))
123
124 #define LAN1_LED_MAPPING_MASK GENMASK(6, 4)
125 #define LAN1_PHY_LED_MAP(_n) FIELD_PREP_CONST(LAN1_LED_MAPPING_MASK, (_n))
126
127 #define LAN0_LED_MAPPING_MASK GENMASK(2, 0)
128 #define LAN0_PHY_LED_MAP(_n) FIELD_PREP_CONST(LAN0_LED_MAPPING_MASK, (_n))
129
130 /* CONF */
131 #define REG_I2C_SDA_E2 0x001c
132 #define SPI_MISO_E2_MASK BIT(14)
133 #define SPI_MOSI_E2_MASK BIT(13)
134 #define SPI_CLK_E2_MASK BIT(12)
135 #define SPI_CS0_E2_MASK BIT(11)
136 #define PCIE2_RESET_E2_MASK BIT(10)
137 #define PCIE1_RESET_E2_MASK BIT(9)
138 #define PCIE0_RESET_E2_MASK BIT(8)
139 #define UART1_RXD_E2_MASK BIT(3)
140 #define UART1_TXD_E2_MASK BIT(2)
141 #define I2C_SCL_E2_MASK BIT(1)
142 #define I2C_SDA_E2_MASK BIT(0)
143
144 #define REG_I2C_SDA_E4 0x0020
145 #define SPI_MISO_E4_MASK BIT(14)
146 #define SPI_MOSI_E4_MASK BIT(13)
147 #define SPI_CLK_E4_MASK BIT(12)
148 #define SPI_CS0_E4_MASK BIT(11)
149 #define PCIE2_RESET_E4_MASK BIT(10)
150 #define PCIE1_RESET_E4_MASK BIT(9)
151 #define PCIE0_RESET_E4_MASK BIT(8)
152 #define UART1_RXD_E4_MASK BIT(3)
153 #define UART1_TXD_E4_MASK BIT(2)
154 #define I2C_SCL_E4_MASK BIT(1)
155 #define I2C_SDA_E4_MASK BIT(0)
156
157 #define REG_GPIO_L_E2 0x0024
158 #define REG_GPIO_L_E4 0x0028
159 #define REG_GPIO_H_E2 0x002c
160 #define REG_GPIO_H_E4 0x0030
161
162 #define REG_I2C_SDA_PU 0x0044
163 #define SPI_MISO_PU_MASK BIT(14)
164 #define SPI_MOSI_PU_MASK BIT(13)
165 #define SPI_CLK_PU_MASK BIT(12)
166 #define SPI_CS0_PU_MASK BIT(11)
167 #define PCIE2_RESET_PU_MASK BIT(10)
168 #define PCIE1_RESET_PU_MASK BIT(9)
169 #define PCIE0_RESET_PU_MASK BIT(8)
170 #define UART1_RXD_PU_MASK BIT(3)
171 #define UART1_TXD_PU_MASK BIT(2)
172 #define I2C_SCL_PU_MASK BIT(1)
173 #define I2C_SDA_PU_MASK BIT(0)
174
175 #define REG_I2C_SDA_PD 0x0048
176 #define SPI_MISO_PD_MASK BIT(14)
177 #define SPI_MOSI_PD_MASK BIT(13)
178 #define SPI_CLK_PD_MASK BIT(12)
179 #define SPI_CS0_PD_MASK BIT(11)
180 #define PCIE2_RESET_PD_MASK BIT(10)
181 #define PCIE1_RESET_PD_MASK BIT(9)
182 #define PCIE0_RESET_PD_MASK BIT(8)
183 #define UART1_RXD_PD_MASK BIT(3)
184 #define UART1_TXD_PD_MASK BIT(2)
185 #define I2C_SCL_PD_MASK BIT(1)
186 #define I2C_SDA_PD_MASK BIT(0)
187
188 #define REG_GPIO_L_PU 0x004c
189 #define REG_GPIO_L_PD 0x0050
190 #define REG_GPIO_H_PU 0x0054
191 #define REG_GPIO_H_PD 0x0058
192
193 #define REG_PCIE_RESET_OD 0x018c
194 #define PCIE2_RESET_OD_MASK BIT(2)
195 #define PCIE1_RESET_OD_MASK BIT(1)
196 #define PCIE0_RESET_OD_MASK BIT(0)
197
198 /* GPIOs */
199 #define REG_GPIO_CTRL 0x0000
200 #define REG_GPIO_DATA 0x0004
201 #define REG_GPIO_INT 0x0008
202 #define REG_GPIO_INT_EDGE 0x000c
203 #define REG_GPIO_INT_LEVEL 0x0010
204 #define REG_GPIO_OE 0x0014
205 #define REG_GPIO_CTRL1 0x0020
206
207 /* PWM MODE CONF */
208 #define REG_GPIO_FLASH_MODE_CFG 0x0034
209 #define GPIO15_FLASH_MODE_CFG BIT(15)
210 #define GPIO14_FLASH_MODE_CFG BIT(14)
211 #define GPIO13_FLASH_MODE_CFG BIT(13)
212 #define GPIO12_FLASH_MODE_CFG BIT(12)
213 #define GPIO11_FLASH_MODE_CFG BIT(11)
214 #define GPIO10_FLASH_MODE_CFG BIT(10)
215 #define GPIO9_FLASH_MODE_CFG BIT(9)
216 #define GPIO8_FLASH_MODE_CFG BIT(8)
217 #define GPIO7_FLASH_MODE_CFG BIT(7)
218 #define GPIO6_FLASH_MODE_CFG BIT(6)
219 #define GPIO5_FLASH_MODE_CFG BIT(5)
220 #define GPIO4_FLASH_MODE_CFG BIT(4)
221 #define GPIO3_FLASH_MODE_CFG BIT(3)
222 #define GPIO2_FLASH_MODE_CFG BIT(2)
223 #define GPIO1_FLASH_MODE_CFG BIT(1)
224 #define GPIO0_FLASH_MODE_CFG BIT(0)
225
226 #define REG_GPIO_CTRL2 0x0060
227 #define REG_GPIO_CTRL3 0x0064
228
229 /* PWM MODE CONF EXT */
230 #define REG_GPIO_FLASH_MODE_CFG_EXT 0x0068
231 #define GPIO51_FLASH_MODE_CFG BIT(31)
232 #define GPIO50_FLASH_MODE_CFG BIT(30)
233 #define GPIO49_FLASH_MODE_CFG BIT(29)
234 #define GPIO48_FLASH_MODE_CFG BIT(28)
235 #define GPIO47_FLASH_MODE_CFG BIT(27)
236 #define GPIO46_FLASH_MODE_CFG BIT(26)
237 #define GPIO45_FLASH_MODE_CFG BIT(25)
238 #define GPIO44_FLASH_MODE_CFG BIT(24)
239 #define GPIO43_FLASH_MODE_CFG BIT(23)
240 #define GPIO42_FLASH_MODE_CFG BIT(22)
241 #define GPIO41_FLASH_MODE_CFG BIT(21)
242 #define GPIO40_FLASH_MODE_CFG BIT(20)
243 #define GPIO39_FLASH_MODE_CFG BIT(19)
244 #define GPIO38_FLASH_MODE_CFG BIT(18)
245 #define GPIO37_FLASH_MODE_CFG BIT(17)
246 #define GPIO36_FLASH_MODE_CFG BIT(16)
247 #define GPIO31_FLASH_MODE_CFG BIT(15)
248 #define GPIO30_FLASH_MODE_CFG BIT(14)
249 #define GPIO29_FLASH_MODE_CFG BIT(13)
250 #define GPIO28_FLASH_MODE_CFG BIT(12)
251 #define GPIO27_FLASH_MODE_CFG BIT(11)
252 #define GPIO26_FLASH_MODE_CFG BIT(10)
253 #define GPIO25_FLASH_MODE_CFG BIT(9)
254 #define GPIO24_FLASH_MODE_CFG BIT(8)
255 #define GPIO23_FLASH_MODE_CFG BIT(7)
256 #define GPIO22_FLASH_MODE_CFG BIT(6)
257 #define GPIO21_FLASH_MODE_CFG BIT(5)
258 #define GPIO20_FLASH_MODE_CFG BIT(4)
259 #define GPIO19_FLASH_MODE_CFG BIT(3)
260 #define GPIO18_FLASH_MODE_CFG BIT(2)
261 #define GPIO17_FLASH_MODE_CFG BIT(1)
262 #define GPIO16_FLASH_MODE_CFG BIT(0)
263
264 #define REG_GPIO_DATA1 0x0070
265 #define REG_GPIO_OE1 0x0078
266 #define REG_GPIO_INT1 0x007c
267 #define REG_GPIO_INT_EDGE1 0x0080
268 #define REG_GPIO_INT_EDGE2 0x0084
269 #define REG_GPIO_INT_EDGE3 0x0088
270 #define REG_GPIO_INT_LEVEL1 0x008c
271 #define REG_GPIO_INT_LEVEL2 0x0090
272 #define REG_GPIO_INT_LEVEL3 0x0094
273
274 #define AIROHA_NUM_PINS 64
275 #define AIROHA_PIN_BANK_SIZE (AIROHA_NUM_PINS / 2)
276 #define AIROHA_REG_GPIOCTRL_NUM_PIN (AIROHA_NUM_PINS / 4)
277
278 static const u32 gpio_data_regs[] = {
279 REG_GPIO_DATA,
280 REG_GPIO_DATA1
281 };
282
283 static const u32 gpio_out_regs[] = {
284 REG_GPIO_OE,
285 REG_GPIO_OE1
286 };
287
288 static const u32 gpio_dir_regs[] = {
289 REG_GPIO_CTRL,
290 REG_GPIO_CTRL1,
291 REG_GPIO_CTRL2,
292 REG_GPIO_CTRL3
293 };
294
295 static const u32 irq_status_regs[] = {
296 REG_GPIO_INT,
297 REG_GPIO_INT1
298 };
299
300 static const u32 irq_level_regs[] = {
301 REG_GPIO_INT_LEVEL,
302 REG_GPIO_INT_LEVEL1,
303 REG_GPIO_INT_LEVEL2,
304 REG_GPIO_INT_LEVEL3
305 };
306
307 static const u32 irq_edge_regs[] = {
308 REG_GPIO_INT_EDGE,
309 REG_GPIO_INT_EDGE1,
310 REG_GPIO_INT_EDGE2,
311 REG_GPIO_INT_EDGE3
312 };
313
314 struct airoha_pinctrl_reg {
315 u32 offset;
316 u32 mask;
317 };
318
319 enum airoha_pinctrl_mux_func {
320 AIROHA_FUNC_MUX,
321 AIROHA_FUNC_PWM_MUX,
322 AIROHA_FUNC_PWM_EXT_MUX,
323 };
324
325 struct airoha_pinctrl_func_group {
326 const char *name;
327 struct {
328 enum airoha_pinctrl_mux_func mux;
329 u32 offset;
330 u32 mask;
331 u32 val;
332 } regmap[2];
333 int regmap_size;
334 };
335
336 struct airoha_pinctrl_func {
337 const struct function_desc desc;
338 const struct airoha_pinctrl_func_group *groups;
339 u8 group_size;
340 };
341
342 struct airoha_pinctrl_conf {
343 u32 pin;
344 struct airoha_pinctrl_reg reg;
345 };
346
347 struct airoha_pinctrl_gpiochip {
348 struct gpio_chip chip;
349
350 /* gpio */
351 const u32 *data;
352 const u32 *dir;
353 const u32 *out;
354 /* irq */
355 const u32 *status;
356 const u32 *level;
357 const u32 *edge;
358
359 u32 irq_type[AIROHA_NUM_PINS];
360 };
361
362 struct airoha_pinctrl {
363 struct pinctrl_dev *ctrl;
364
365 struct regmap *chip_scu;
366 struct regmap *regmap;
367
368 struct airoha_pinctrl_gpiochip gpiochip;
369 };
370
371 static struct pinctrl_pin_desc airoha_pinctrl_pins[] = {
372 PINCTRL_PIN(0, "uart1_txd"),
373 PINCTRL_PIN(1, "uart1_rxd"),
374 PINCTRL_PIN(2, "i2c_scl"),
375 PINCTRL_PIN(3, "i2c_sda"),
376 PINCTRL_PIN(4, "spi_cs0"),
377 PINCTRL_PIN(5, "spi_clk"),
378 PINCTRL_PIN(6, "spi_mosi"),
379 PINCTRL_PIN(7, "spi_miso"),
380 PINCTRL_PIN(13, "gpio0"),
381 PINCTRL_PIN(14, "gpio1"),
382 PINCTRL_PIN(15, "gpio2"),
383 PINCTRL_PIN(16, "gpio3"),
384 PINCTRL_PIN(17, "gpio4"),
385 PINCTRL_PIN(18, "gpio5"),
386 PINCTRL_PIN(19, "gpio6"),
387 PINCTRL_PIN(20, "gpio7"),
388 PINCTRL_PIN(21, "gpio8"),
389 PINCTRL_PIN(22, "gpio9"),
390 PINCTRL_PIN(23, "gpio10"),
391 PINCTRL_PIN(24, "gpio11"),
392 PINCTRL_PIN(25, "gpio12"),
393 PINCTRL_PIN(26, "gpio13"),
394 PINCTRL_PIN(27, "gpio14"),
395 PINCTRL_PIN(28, "gpio15"),
396 PINCTRL_PIN(29, "gpio16"),
397 PINCTRL_PIN(30, "gpio17"),
398 PINCTRL_PIN(31, "gpio18"),
399 PINCTRL_PIN(32, "gpio19"),
400 PINCTRL_PIN(33, "gpio20"),
401 PINCTRL_PIN(34, "gpio21"),
402 PINCTRL_PIN(35, "gpio22"),
403 PINCTRL_PIN(36, "gpio23"),
404 PINCTRL_PIN(37, "gpio24"),
405 PINCTRL_PIN(38, "gpio25"),
406 PINCTRL_PIN(39, "gpio26"),
407 PINCTRL_PIN(40, "gpio27"),
408 PINCTRL_PIN(41, "gpio28"),
409 PINCTRL_PIN(42, "gpio29"),
410 PINCTRL_PIN(43, "gpio30"),
411 PINCTRL_PIN(44, "gpio31"),
412 PINCTRL_PIN(45, "gpio32"),
413 PINCTRL_PIN(46, "gpio33"),
414 PINCTRL_PIN(47, "gpio34"),
415 PINCTRL_PIN(48, "gpio35"),
416 PINCTRL_PIN(49, "gpio36"),
417 PINCTRL_PIN(50, "gpio37"),
418 PINCTRL_PIN(51, "gpio38"),
419 PINCTRL_PIN(52, "gpio39"),
420 PINCTRL_PIN(53, "gpio40"),
421 PINCTRL_PIN(54, "gpio41"),
422 PINCTRL_PIN(55, "gpio42"),
423 PINCTRL_PIN(56, "gpio43"),
424 PINCTRL_PIN(57, "gpio44"),
425 PINCTRL_PIN(58, "gpio45"),
426 PINCTRL_PIN(59, "gpio46"),
427 PINCTRL_PIN(61, "pcie_reset0"),
428 PINCTRL_PIN(62, "pcie_reset1"),
429 PINCTRL_PIN(63, "pcie_reset2"),
430 };
431
432 static const int pon_pins[] = { 49, 50, 51, 52, 53, 54 };
433 static const int pon_tod_1pps_pins[] = { 46 };
434 static const int gsw_tod_1pps_pins[] = { 46 };
435 static const int sipo_pins[] = { 16, 17 };
436 static const int sipo_rclk_pins[] = { 16, 17, 43 };
437 static const int mdio_pins[] = { 14, 15 };
438 static const int uart2_pins[] = { 48, 55 };
439 static const int uart2_cts_rts_pins[] = { 46, 47 };
440 static const int hsuart_pins[] = { 28, 29 };
441 static const int hsuart_cts_rts_pins[] = { 26, 27 };
442 static const int uart4_pins[] = { 38, 39 };
443 static const int uart5_pins[] = { 18, 19 };
444 static const int i2c0_pins[] = { 2, 3 };
445 static const int i2c1_pins[] = { 14, 15 };
446 static const int jtag_udi_pins[] = { 16, 17, 18, 19, 20 };
447 static const int jtag_dfd_pins[] = { 16, 17, 18, 19, 20 };
448 static const int i2s_pins[] = { 26, 27, 28, 29 };
449 static const int pcm1_pins[] = { 22, 23, 24, 25 };
450 static const int pcm2_pins[] = { 18, 19, 20, 21 };
451 static const int spi_quad_pins[] = { 32, 33 };
452 static const int spi_pins[] = { 4, 5, 6, 7 };
453 static const int spi_cs1_pins[] = { 34 };
454 static const int pcm_spi_pins[] = { 18, 19, 20, 21, 22, 23, 24, 25 };
455 static const int pcm_spi_int_pins[] = { 14 };
456 static const int pcm_spi_rst_pins[] = { 15 };
457 static const int pcm_spi_cs1_pins[] = { 43 };
458 static const int pcm_spi_cs2_pins[] = { 40 };
459 static const int pcm_spi_cs2_p128_pins[] = { 40 };
460 static const int pcm_spi_cs2_p156_pins[] = { 40 };
461 static const int pcm_spi_cs3_pins[] = { 41 };
462 static const int pcm_spi_cs4_pins[] = { 42 };
463 static const int emmc_pins[] = { 4, 5, 6, 30, 31, 32, 33, 34, 35, 36, 37 };
464 static const int pnand_pins[] = { 4, 5, 6, 7, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 };
465 static const int gpio0_pins[] = { 13 };
466 static const int gpio1_pins[] = { 14 };
467 static const int gpio2_pins[] = { 15 };
468 static const int gpio3_pins[] = { 16 };
469 static const int gpio4_pins[] = { 17 };
470 static const int gpio5_pins[] = { 18 };
471 static const int gpio6_pins[] = { 19 };
472 static const int gpio7_pins[] = { 20 };
473 static const int gpio8_pins[] = { 21 };
474 static const int gpio9_pins[] = { 22 };
475 static const int gpio10_pins[] = { 23 };
476 static const int gpio11_pins[] = { 24 };
477 static const int gpio12_pins[] = { 25 };
478 static const int gpio13_pins[] = { 26 };
479 static const int gpio14_pins[] = { 27 };
480 static const int gpio15_pins[] = { 28 };
481 static const int gpio16_pins[] = { 29 };
482 static const int gpio17_pins[] = { 30 };
483 static const int gpio18_pins[] = { 31 };
484 static const int gpio19_pins[] = { 32 };
485 static const int gpio20_pins[] = { 33 };
486 static const int gpio21_pins[] = { 34 };
487 static const int gpio22_pins[] = { 35 };
488 static const int gpio23_pins[] = { 36 };
489 static const int gpio24_pins[] = { 37 };
490 static const int gpio25_pins[] = { 38 };
491 static const int gpio26_pins[] = { 39 };
492 static const int gpio27_pins[] = { 40 };
493 static const int gpio28_pins[] = { 41 };
494 static const int gpio29_pins[] = { 42 };
495 static const int gpio30_pins[] = { 43 };
496 static const int gpio31_pins[] = { 44 };
497 static const int gpio33_pins[] = { 46 };
498 static const int gpio34_pins[] = { 47 };
499 static const int gpio35_pins[] = { 48 };
500 static const int gpio36_pins[] = { 49 };
501 static const int gpio37_pins[] = { 50 };
502 static const int gpio38_pins[] = { 51 };
503 static const int gpio39_pins[] = { 52 };
504 static const int gpio40_pins[] = { 53 };
505 static const int gpio41_pins[] = { 54 };
506 static const int gpio42_pins[] = { 55 };
507 static const int gpio43_pins[] = { 56 };
508 static const int gpio44_pins[] = { 57 };
509 static const int gpio45_pins[] = { 58 };
510 static const int gpio46_pins[] = { 59 };
511 static const int pcie_reset0_pins[] = { 61 };
512 static const int pcie_reset1_pins[] = { 62 };
513 static const int pcie_reset2_pins[] = { 63 };
514
515 static const struct pingroup airoha_pinctrl_groups[] = {
516 PINCTRL_PIN_GROUP(pon),
517 PINCTRL_PIN_GROUP(pon_tod_1pps),
518 PINCTRL_PIN_GROUP(gsw_tod_1pps),
519 PINCTRL_PIN_GROUP(sipo),
520 PINCTRL_PIN_GROUP(sipo_rclk),
521 PINCTRL_PIN_GROUP(mdio),
522 PINCTRL_PIN_GROUP(uart2),
523 PINCTRL_PIN_GROUP(uart2_cts_rts),
524 PINCTRL_PIN_GROUP(hsuart),
525 PINCTRL_PIN_GROUP(hsuart_cts_rts),
526 PINCTRL_PIN_GROUP(uart4),
527 PINCTRL_PIN_GROUP(uart5),
528 PINCTRL_PIN_GROUP(i2c0),
529 PINCTRL_PIN_GROUP(i2c1),
530 PINCTRL_PIN_GROUP(jtag_udi),
531 PINCTRL_PIN_GROUP(jtag_dfd),
532 PINCTRL_PIN_GROUP(i2s),
533 PINCTRL_PIN_GROUP(pcm1),
534 PINCTRL_PIN_GROUP(pcm2),
535 PINCTRL_PIN_GROUP(spi),
536 PINCTRL_PIN_GROUP(spi_quad),
537 PINCTRL_PIN_GROUP(spi_cs1),
538 PINCTRL_PIN_GROUP(pcm_spi),
539 PINCTRL_PIN_GROUP(pcm_spi_int),
540 PINCTRL_PIN_GROUP(pcm_spi_rst),
541 PINCTRL_PIN_GROUP(pcm_spi_cs1),
542 PINCTRL_PIN_GROUP(pcm_spi_cs2_p128),
543 PINCTRL_PIN_GROUP(pcm_spi_cs2_p156),
544 PINCTRL_PIN_GROUP(pcm_spi_cs2),
545 PINCTRL_PIN_GROUP(pcm_spi_cs3),
546 PINCTRL_PIN_GROUP(pcm_spi_cs4),
547 PINCTRL_PIN_GROUP(emmc),
548 PINCTRL_PIN_GROUP(pnand),
549 PINCTRL_PIN_GROUP(gpio0),
550 PINCTRL_PIN_GROUP(gpio1),
551 PINCTRL_PIN_GROUP(gpio2),
552 PINCTRL_PIN_GROUP(gpio3),
553 PINCTRL_PIN_GROUP(gpio4),
554 PINCTRL_PIN_GROUP(gpio5),
555 PINCTRL_PIN_GROUP(gpio6),
556 PINCTRL_PIN_GROUP(gpio7),
557 PINCTRL_PIN_GROUP(gpio8),
558 PINCTRL_PIN_GROUP(gpio9),
559 PINCTRL_PIN_GROUP(gpio10),
560 PINCTRL_PIN_GROUP(gpio11),
561 PINCTRL_PIN_GROUP(gpio12),
562 PINCTRL_PIN_GROUP(gpio13),
563 PINCTRL_PIN_GROUP(gpio14),
564 PINCTRL_PIN_GROUP(gpio15),
565 PINCTRL_PIN_GROUP(gpio16),
566 PINCTRL_PIN_GROUP(gpio17),
567 PINCTRL_PIN_GROUP(gpio18),
568 PINCTRL_PIN_GROUP(gpio19),
569 PINCTRL_PIN_GROUP(gpio20),
570 PINCTRL_PIN_GROUP(gpio21),
571 PINCTRL_PIN_GROUP(gpio22),
572 PINCTRL_PIN_GROUP(gpio23),
573 PINCTRL_PIN_GROUP(gpio24),
574 PINCTRL_PIN_GROUP(gpio25),
575 PINCTRL_PIN_GROUP(gpio26),
576 PINCTRL_PIN_GROUP(gpio27),
577 PINCTRL_PIN_GROUP(gpio28),
578 PINCTRL_PIN_GROUP(gpio29),
579 PINCTRL_PIN_GROUP(gpio30),
580 PINCTRL_PIN_GROUP(gpio31),
581 PINCTRL_PIN_GROUP(gpio33),
582 PINCTRL_PIN_GROUP(gpio34),
583 PINCTRL_PIN_GROUP(gpio35),
584 PINCTRL_PIN_GROUP(gpio36),
585 PINCTRL_PIN_GROUP(gpio37),
586 PINCTRL_PIN_GROUP(gpio38),
587 PINCTRL_PIN_GROUP(gpio39),
588 PINCTRL_PIN_GROUP(gpio40),
589 PINCTRL_PIN_GROUP(gpio41),
590 PINCTRL_PIN_GROUP(gpio42),
591 PINCTRL_PIN_GROUP(gpio43),
592 PINCTRL_PIN_GROUP(gpio44),
593 PINCTRL_PIN_GROUP(gpio45),
594 PINCTRL_PIN_GROUP(gpio46),
595 PINCTRL_PIN_GROUP(pcie_reset0),
596 PINCTRL_PIN_GROUP(pcie_reset1),
597 PINCTRL_PIN_GROUP(pcie_reset2),
598 };
599
600 static const char *const pon_groups[] = { "pon" };
601 static const char *const tod_1pps_groups[] = { "pon_tod_1pps", "gsw_tod_1pps" };
602 static const char *const sipo_groups[] = { "sipo", "sipo_rclk" };
603 static const char *const mdio_groups[] = { "mdio" };
604 static const char *const uart_groups[] = { "uart2", "uart2_cts_rts", "hsuart",
605 "hsuart_cts_rts", "uart4",
606 "uart5" };
607 static const char *const i2c_groups[] = { "i2c1" };
608 static const char *const jtag_groups[] = { "jtag_udi", "jtag_dfd" };
609 static const char *const pcm_groups[] = { "pcm1", "pcm2" };
610 static const char *const spi_groups[] = { "spi_quad", "spi_cs1" };
611 static const char *const pcm_spi_groups[] = { "pcm_spi", "pcm_spi_int",
612 "pcm_spi_rst", "pcm_spi_cs1",
613 "pcm_spi_cs2_p156",
614 "pcm_spi_cs2_p128",
615 "pcm_spi_cs3", "pcm_spi_cs4" };
616 static const char *const i2s_groups[] = { "i2s" };
617 static const char *const emmc_groups[] = { "emmc" };
618 static const char *const pnand_groups[] = { "pnand" };
619 static const char *const pcie_reset_groups[] = { "pcie_reset0", "pcie_reset1",
620 "pcie_reset2" };
621 static const char *const pwm_groups[] = { "gpio0", "gpio1",
622 "gpio2", "gpio3",
623 "gpio4", "gpio5",
624 "gpio6", "gpio7",
625 "gpio8", "gpio9",
626 "gpio10", "gpio11",
627 "gpio12", "gpio13",
628 "gpio14", "gpio15",
629 "gpio16", "gpio17",
630 "gpio18", "gpio19",
631 "gpio20", "gpio21",
632 "gpio22", "gpio23",
633 "gpio24", "gpio25",
634 "gpio26", "gpio27",
635 "gpio28", "gpio29",
636 "gpio30", "gpio31",
637 "gpio36", "gpio37",
638 "gpio38", "gpio39",
639 "gpio40", "gpio41",
640 "gpio42", "gpio43",
641 "gpio44", "gpio45",
642 "gpio46", "gpio47" };
643 static const char *const phy1_led0_groups[] = { "gpio33", "gpio34",
644 "gpio35", "gpio42" };
645 static const char *const phy2_led0_groups[] = { "gpio33", "gpio34",
646 "gpio35", "gpio42" };
647 static const char *const phy3_led0_groups[] = { "gpio33", "gpio34",
648 "gpio35", "gpio42" };
649 static const char *const phy4_led0_groups[] = { "gpio33", "gpio34",
650 "gpio35", "gpio42" };
651 static const char *const phy1_led1_groups[] = { "gpio43", "gpio44",
652 "gpio45", "gpio46" };
653 static const char *const phy2_led1_groups[] = { "gpio43", "gpio44",
654 "gpio45", "gpio46" };
655 static const char *const phy3_led1_groups[] = { "gpio43", "gpio44",
656 "gpio45", "gpio46" };
657 static const char *const phy4_led1_groups[] = { "gpio43", "gpio44",
658 "gpio45", "gpio46" };
659
660 static const struct airoha_pinctrl_func_group pon_func_group[] = {
661 {
662 .name = "pon",
663 .regmap[0] = {
664 AIROHA_FUNC_MUX,
665 REG_GPIO_PON_MODE,
666 GPIO_PON_MODE_MASK,
667 GPIO_PON_MODE_MASK
668 },
669 .regmap_size = 1,
670 },
671 };
672
673 static const struct airoha_pinctrl_func_group tod_1pps_func_group[] = {
674 {
675 .name = "pon_tod_1pps",
676 .regmap[0] = {
677 AIROHA_FUNC_MUX,
678 REG_GPIO_2ND_I2C_MODE,
679 PON_TOD_1PPS_MODE_MASK,
680 PON_TOD_1PPS_MODE_MASK
681 },
682 .regmap_size = 1,
683 }, {
684 .name = "gsw_tod_1pps",
685 .regmap[0] = {
686 AIROHA_FUNC_MUX,
687 REG_GPIO_2ND_I2C_MODE,
688 GSW_TOD_1PPS_MODE_MASK,
689 GSW_TOD_1PPS_MODE_MASK
690 },
691 .regmap_size = 1,
692 },
693 };
694
695 static const struct airoha_pinctrl_func_group sipo_func_group[] = {
696 {
697 .name = "sipo",
698 .regmap[0] = {
699 AIROHA_FUNC_MUX,
700 REG_GPIO_PON_MODE,
701 GPIO_SIPO_MODE_MASK | SIPO_RCLK_MODE_MASK,
702 GPIO_SIPO_MODE_MASK
703 },
704 .regmap_size = 1,
705 }, {
706 .name = "sipo_rclk",
707 .regmap[0] = {
708 AIROHA_FUNC_MUX,
709 REG_GPIO_PON_MODE,
710 GPIO_SIPO_MODE_MASK | SIPO_RCLK_MODE_MASK,
711 GPIO_SIPO_MODE_MASK | SIPO_RCLK_MODE_MASK
712 },
713 .regmap_size = 1,
714 },
715 };
716
717 static const struct airoha_pinctrl_func_group mdio_func_group[] = {
718 {
719 .name = "mdio",
720 .regmap[0] = {
721 AIROHA_FUNC_MUX,
722 REG_GPIO_PON_MODE,
723 GPIO_SGMII_MDIO_MODE_MASK,
724 GPIO_SGMII_MDIO_MODE_MASK
725 },
726 .regmap[1] = {
727 AIROHA_FUNC_MUX,
728 REG_GPIO_2ND_I2C_MODE,
729 GPIO_MDC_IO_MASTER_MODE_MODE,
730 GPIO_MDC_IO_MASTER_MODE_MODE
731 },
732 .regmap_size = 2,
733 },
734 };
735
736 static const struct airoha_pinctrl_func_group uart_func_group[] = {
737 {
738 .name = "uart2",
739 .regmap[0] = {
740 AIROHA_FUNC_MUX,
741 REG_GPIO_PON_MODE,
742 GPIO_UART2_MODE_MASK,
743 GPIO_UART2_MODE_MASK
744 },
745 .regmap_size = 1,
746 }, {
747 .name = "uart2_cts_rts",
748 .regmap[0] = {
749 AIROHA_FUNC_MUX,
750 REG_GPIO_PON_MODE,
751 GPIO_UART2_MODE_MASK | GPIO_UART2_CTS_RTS_MODE_MASK,
752 GPIO_UART2_MODE_MASK | GPIO_UART2_CTS_RTS_MODE_MASK
753 },
754 .regmap_size = 1,
755 }, {
756 .name = "hsuart",
757 .regmap[0] = {
758 AIROHA_FUNC_MUX,
759 REG_GPIO_PON_MODE,
760 GPIO_HSUART_MODE_MASK | GPIO_HSUART_CTS_RTS_MODE_MASK,
761 GPIO_HSUART_MODE_MASK
762 },
763 .regmap_size = 1,
764 },
765 {
766 .name = "hsuart_cts_rts",
767 .regmap[0] = {
768 AIROHA_FUNC_MUX,
769 REG_GPIO_PON_MODE,
770 GPIO_HSUART_MODE_MASK | GPIO_HSUART_CTS_RTS_MODE_MASK,
771 GPIO_HSUART_MODE_MASK | GPIO_HSUART_CTS_RTS_MODE_MASK
772 },
773 .regmap_size = 1,
774 }, {
775 .name = "uart4",
776 .regmap[0] = {
777 AIROHA_FUNC_MUX,
778 REG_GPIO_PON_MODE,
779 GPIO_UART4_MODE_MASK,
780 GPIO_UART4_MODE_MASK
781 },
782 .regmap_size = 1,
783 }, {
784 .name = "uart5",
785 .regmap[0] = {
786 AIROHA_FUNC_MUX,
787 REG_GPIO_PON_MODE,
788 GPIO_UART5_MODE_MASK,
789 GPIO_UART5_MODE_MASK
790 },
791 .regmap_size = 1,
792 },
793 };
794
795 static const struct airoha_pinctrl_func_group i2c_func_group[] = {
796 {
797 .name = "i2c1",
798 .regmap[0] = {
799 AIROHA_FUNC_MUX,
800 REG_GPIO_2ND_I2C_MODE,
801 GPIO_2ND_I2C_MODE_MASK,
802 GPIO_2ND_I2C_MODE_MASK
803 },
804 .regmap_size = 1,
805 },
806 };
807
808 static const struct airoha_pinctrl_func_group jtag_func_group[] = {
809 {
810 .name = "jtag_udi",
811 .regmap[0] = {
812 AIROHA_FUNC_MUX,
813 REG_NPU_UART_EN,
814 JTAG_UDI_EN_MASK,
815 JTAG_UDI_EN_MASK
816 },
817 .regmap_size = 1,
818 }, {
819 .name = "jtag_dfd",
820 .regmap[0] = {
821 AIROHA_FUNC_MUX,
822 REG_NPU_UART_EN,
823 JTAG_DFD_EN_MASK,
824 JTAG_DFD_EN_MASK
825 },
826 .regmap_size = 1,
827 },
828 };
829
830 static const struct airoha_pinctrl_func_group pcm_func_group[] = {
831 {
832 .name = "pcm1",
833 .regmap[0] = {
834 AIROHA_FUNC_MUX,
835 REG_GPIO_SPI_CS1_MODE,
836 GPIO_PCM1_MODE_MASK,
837 GPIO_PCM1_MODE_MASK
838 },
839 .regmap_size = 1,
840 }, {
841 .name = "pcm2",
842 .regmap[0] = {
843 AIROHA_FUNC_MUX,
844 REG_GPIO_SPI_CS1_MODE,
845 GPIO_PCM2_MODE_MASK,
846 GPIO_PCM2_MODE_MASK
847 },
848 .regmap_size = 1,
849 },
850 };
851
852 static const struct airoha_pinctrl_func_group spi_func_group[] = {
853 {
854 .name = "spi_quad",
855 .regmap[0] = {
856 AIROHA_FUNC_MUX,
857 REG_GPIO_SPI_CS1_MODE,
858 GPIO_SPI_QUAD_MODE_MASK,
859 GPIO_SPI_QUAD_MODE_MASK
860 },
861 .regmap_size = 1,
862 }, {
863 .name = "spi_cs1",
864 .regmap[0] = {
865 AIROHA_FUNC_MUX,
866 REG_GPIO_SPI_CS1_MODE,
867 GPIO_SPI_CS1_MODE_MASK,
868 GPIO_SPI_CS1_MODE_MASK
869 },
870 .regmap_size = 1,
871 }, {
872 .name = "spi_cs2",
873 .regmap[0] = {
874 AIROHA_FUNC_MUX,
875 REG_GPIO_SPI_CS1_MODE,
876 GPIO_SPI_CS2_MODE_MASK,
877 GPIO_SPI_CS2_MODE_MASK
878 },
879 .regmap_size = 1,
880 }, {
881 .name = "spi_cs3",
882 .regmap[0] = {
883 AIROHA_FUNC_MUX,
884 REG_GPIO_SPI_CS1_MODE,
885 GPIO_SPI_CS3_MODE_MASK,
886 GPIO_SPI_CS3_MODE_MASK
887 },
888 .regmap_size = 1,
889 }, {
890 .name = "spi_cs4",
891 .regmap[0] = {
892 AIROHA_FUNC_MUX,
893 REG_GPIO_SPI_CS1_MODE,
894 GPIO_SPI_CS4_MODE_MASK,
895 GPIO_SPI_CS4_MODE_MASK
896 },
897 .regmap_size = 1,
898 },
899 };
900
901 static const struct airoha_pinctrl_func_group pcm_spi_func_group[] = {
902 {
903 .name = "pcm_spi",
904 .regmap[0] = {
905 AIROHA_FUNC_MUX,
906 REG_GPIO_SPI_CS1_MODE,
907 GPIO_PCM_SPI_MODE_MASK,
908 GPIO_PCM_SPI_MODE_MASK
909 },
910 .regmap_size = 1,
911 }, {
912 .name = "pcm_spi_int",
913 .regmap[0] = {
914 AIROHA_FUNC_MUX,
915 REG_GPIO_SPI_CS1_MODE,
916 GPIO_PCM_INT_MODE_MASK,
917 GPIO_PCM_INT_MODE_MASK
918 },
919 .regmap_size = 1,
920 }, {
921 .name = "pcm_spi_rst",
922 .regmap[0] = {
923 AIROHA_FUNC_MUX,
924 REG_GPIO_SPI_CS1_MODE,
925 GPIO_PCM_RESET_MODE_MASK,
926 GPIO_PCM_RESET_MODE_MASK
927 },
928 .regmap_size = 1,
929 }, {
930 .name = "pcm_spi_cs1",
931 .regmap[0] = {
932 AIROHA_FUNC_MUX,
933 REG_GPIO_SPI_CS1_MODE,
934 GPIO_PCM_SPI_CS1_MODE_MASK,
935 GPIO_PCM_SPI_CS1_MODE_MASK
936 },
937 .regmap_size = 1,
938 }, {
939 .name = "pcm_spi_cs2_p128",
940 .regmap[0] = {
941 AIROHA_FUNC_MUX,
942 REG_GPIO_SPI_CS1_MODE,
943 GPIO_PCM_SPI_CS2_MODE_P128_MASK,
944 GPIO_PCM_SPI_CS2_MODE_P128_MASK
945 },
946 .regmap_size = 1,
947 }, {
948 .name = "pcm_spi_cs2_p156",
949 .regmap[0] = {
950 AIROHA_FUNC_MUX,
951 REG_GPIO_SPI_CS1_MODE,
952 GPIO_PCM_SPI_CS2_MODE_P156_MASK,
953 GPIO_PCM_SPI_CS2_MODE_P156_MASK
954 },
955 .regmap_size = 1,
956 }, {
957 .name = "pcm_spi_cs3",
958 .regmap[0] = {
959 AIROHA_FUNC_MUX,
960 REG_GPIO_SPI_CS1_MODE,
961 GPIO_PCM_SPI_CS3_MODE_MASK,
962 GPIO_PCM_SPI_CS3_MODE_MASK
963 },
964 .regmap_size = 1,
965 }, {
966 .name = "pcm_spi_cs4",
967 .regmap[0] = {
968 AIROHA_FUNC_MUX,
969 REG_GPIO_SPI_CS1_MODE,
970 GPIO_PCM_SPI_CS4_MODE_MASK,
971 GPIO_PCM_SPI_CS4_MODE_MASK
972 },
973 .regmap_size = 1,
974 },
975 };
976
977 static const struct airoha_pinctrl_func_group i2s_func_group[] = {
978 {
979 .name = "i2s",
980 .regmap[0] = {
981 AIROHA_FUNC_MUX,
982 REG_GPIO_2ND_I2C_MODE,
983 GPIO_I2S_MODE_MASK,
984 GPIO_I2S_MODE_MASK
985 },
986 .regmap_size = 1,
987 },
988 };
989
990 static const struct airoha_pinctrl_func_group emmc_func_group[] = {
991 {
992 .name = "emmc",
993 .regmap[0] = {
994 AIROHA_FUNC_MUX,
995 REG_GPIO_PON_MODE,
996 GPIO_EMMC_MODE_MASK,
997 GPIO_EMMC_MODE_MASK
998 },
999 .regmap_size = 1,
1000 },
1001 };
1002
1003 static const struct airoha_pinctrl_func_group pnand_func_group[] = {
1004 {
1005 .name = "pnand",
1006 .regmap[0] = {
1007 AIROHA_FUNC_MUX,
1008 REG_GPIO_PON_MODE,
1009 GPIO_PARALLEL_NAND_MODE_MASK,
1010 GPIO_PARALLEL_NAND_MODE_MASK
1011 },
1012 .regmap_size = 1,
1013 },
1014 };
1015
1016 static const struct airoha_pinctrl_func_group pcie_reset_func_group[] = {
1017 {
1018 .name = "pcie_reset0",
1019 .regmap[0] = {
1020 AIROHA_FUNC_MUX,
1021 REG_GPIO_PON_MODE,
1022 GPIO_PCIE_RESET0_MASK,
1023 GPIO_PCIE_RESET0_MASK
1024 },
1025 .regmap_size = 1,
1026 }, {
1027 .name = "pcie_reset1",
1028 .regmap[0] = {
1029 AIROHA_FUNC_MUX,
1030 REG_GPIO_PON_MODE,
1031 GPIO_PCIE_RESET1_MASK,
1032 GPIO_PCIE_RESET1_MASK
1033 },
1034 .regmap_size = 1,
1035 }, {
1036 .name = "pcie_reset2",
1037 .regmap[0] = {
1038 AIROHA_FUNC_MUX,
1039 REG_GPIO_PON_MODE,
1040 GPIO_PCIE_RESET2_MASK,
1041 GPIO_PCIE_RESET2_MASK
1042 },
1043 .regmap_size = 1,
1044 },
1045 };
1046
1047 /* PWM */
1048 static const struct airoha_pinctrl_func_group pwm_func_group[] = {
1049 {
1050 .name = "gpio0",
1051 .regmap[0] = {
1052 AIROHA_FUNC_PWM_MUX,
1053 REG_GPIO_FLASH_MODE_CFG,
1054 GPIO0_FLASH_MODE_CFG,
1055 GPIO0_FLASH_MODE_CFG
1056 },
1057 .regmap_size = 1,
1058 }, {
1059 .name = "gpio1",
1060 .regmap[0] = {
1061 AIROHA_FUNC_PWM_MUX,
1062 REG_GPIO_FLASH_MODE_CFG,
1063 GPIO1_FLASH_MODE_CFG,
1064 GPIO1_FLASH_MODE_CFG
1065 },
1066 .regmap_size = 1,
1067 }, {
1068 .name = "gpio2",
1069 .regmap[0] = {
1070 AIROHA_FUNC_PWM_MUX,
1071 REG_GPIO_FLASH_MODE_CFG,
1072 GPIO2_FLASH_MODE_CFG,
1073 GPIO2_FLASH_MODE_CFG
1074 },
1075 .regmap_size = 1,
1076 }, {
1077 .name = "gpio3",
1078 .regmap[0] = {
1079 AIROHA_FUNC_PWM_MUX,
1080 REG_GPIO_FLASH_MODE_CFG,
1081 GPIO3_FLASH_MODE_CFG,
1082 GPIO3_FLASH_MODE_CFG
1083 },
1084 .regmap_size = 1,
1085 }, {
1086 .name = "gpio4",
1087 .regmap[0] = {
1088 AIROHA_FUNC_PWM_MUX,
1089 REG_GPIO_FLASH_MODE_CFG,
1090 GPIO4_FLASH_MODE_CFG,
1091 GPIO4_FLASH_MODE_CFG
1092 },
1093 .regmap_size = 1,
1094 }, {
1095 .name = "gpio5",
1096 .regmap[0] = {
1097 AIROHA_FUNC_PWM_MUX,
1098 REG_GPIO_FLASH_MODE_CFG,
1099 GPIO5_FLASH_MODE_CFG,
1100 GPIO5_FLASH_MODE_CFG
1101 },
1102 .regmap_size = 1,
1103 }, {
1104 .name = "gpio6",
1105 .regmap[0] = {
1106 AIROHA_FUNC_PWM_MUX,
1107 REG_GPIO_FLASH_MODE_CFG,
1108 GPIO6_FLASH_MODE_CFG,
1109 GPIO6_FLASH_MODE_CFG
1110 },
1111 .regmap_size = 1,
1112 }, {
1113 .name = "gpio7",
1114 .regmap[0] = {
1115 AIROHA_FUNC_PWM_MUX,
1116 REG_GPIO_FLASH_MODE_CFG,
1117 GPIO7_FLASH_MODE_CFG,
1118 GPIO7_FLASH_MODE_CFG
1119 },
1120 .regmap_size = 1,
1121 }, {
1122 .name = "gpio8",
1123 .regmap[0] = {
1124 AIROHA_FUNC_PWM_MUX,
1125 REG_GPIO_FLASH_MODE_CFG,
1126 GPIO8_FLASH_MODE_CFG,
1127 GPIO8_FLASH_MODE_CFG
1128 },
1129 .regmap_size = 1,
1130 }, {
1131 .name = "gpio9",
1132 .regmap[0] = {
1133 AIROHA_FUNC_PWM_MUX,
1134 REG_GPIO_FLASH_MODE_CFG,
1135 GPIO9_FLASH_MODE_CFG,
1136 GPIO9_FLASH_MODE_CFG
1137 },
1138 .regmap_size = 1,
1139 }, {
1140 .name = "gpio10",
1141 .regmap[0] = {
1142 AIROHA_FUNC_PWM_MUX,
1143 REG_GPIO_FLASH_MODE_CFG,
1144 GPIO10_FLASH_MODE_CFG,
1145 GPIO10_FLASH_MODE_CFG
1146 },
1147 .regmap_size = 1,
1148 }, {
1149 .name = "gpio11",
1150 .regmap[0] = {
1151 AIROHA_FUNC_PWM_MUX,
1152 REG_GPIO_FLASH_MODE_CFG,
1153 GPIO11_FLASH_MODE_CFG,
1154 GPIO11_FLASH_MODE_CFG
1155 },
1156 .regmap_size = 1,
1157 }, {
1158 .name = "gpio12",
1159 .regmap[0] = {
1160 AIROHA_FUNC_PWM_MUX,
1161 REG_GPIO_FLASH_MODE_CFG,
1162 GPIO12_FLASH_MODE_CFG,
1163 GPIO12_FLASH_MODE_CFG
1164 },
1165 .regmap_size = 1,
1166 }, {
1167 .name = "gpio13",
1168 .regmap[0] = {
1169 AIROHA_FUNC_PWM_MUX,
1170 REG_GPIO_FLASH_MODE_CFG,
1171 GPIO13_FLASH_MODE_CFG,
1172 GPIO13_FLASH_MODE_CFG
1173 },
1174 .regmap_size = 1,
1175 }, {
1176 .name = "gpio14",
1177 .regmap[0] = {
1178 AIROHA_FUNC_PWM_MUX,
1179 REG_GPIO_FLASH_MODE_CFG,
1180 GPIO14_FLASH_MODE_CFG,
1181 GPIO14_FLASH_MODE_CFG
1182 },
1183 .regmap_size = 1,
1184 }, {
1185 .name = "gpio15",
1186 .regmap[0] = {
1187 AIROHA_FUNC_PWM_MUX,
1188 REG_GPIO_FLASH_MODE_CFG,
1189 GPIO15_FLASH_MODE_CFG,
1190 GPIO15_FLASH_MODE_CFG
1191 },
1192 .regmap_size = 1,
1193 }, {
1194 .name = "gpio16",
1195 .regmap[0] = {
1196 AIROHA_FUNC_PWM_EXT_MUX,
1197 REG_GPIO_FLASH_MODE_CFG_EXT,
1198 GPIO16_FLASH_MODE_CFG,
1199 GPIO16_FLASH_MODE_CFG
1200 },
1201 .regmap_size = 1,
1202 }, {
1203 .name = "gpio17",
1204 .regmap[0] = {
1205 AIROHA_FUNC_PWM_EXT_MUX,
1206 REG_GPIO_FLASH_MODE_CFG_EXT,
1207 GPIO17_FLASH_MODE_CFG,
1208 GPIO17_FLASH_MODE_CFG
1209 },
1210 .regmap_size = 1,
1211 }, {
1212 .name = "gpio18",
1213 .regmap[0] = {
1214 AIROHA_FUNC_PWM_EXT_MUX,
1215 REG_GPIO_FLASH_MODE_CFG_EXT,
1216 GPIO18_FLASH_MODE_CFG,
1217 GPIO18_FLASH_MODE_CFG
1218 },
1219 .regmap_size = 1,
1220 }, {
1221 .name = "gpio19",
1222 .regmap[0] = {
1223 AIROHA_FUNC_PWM_EXT_MUX,
1224 REG_GPIO_FLASH_MODE_CFG_EXT,
1225 GPIO19_FLASH_MODE_CFG,
1226 GPIO19_FLASH_MODE_CFG
1227 },
1228 .regmap_size = 1,
1229 }, {
1230 .name = "gpio20",
1231 .regmap[0] = {
1232 AIROHA_FUNC_PWM_EXT_MUX,
1233 REG_GPIO_FLASH_MODE_CFG_EXT,
1234 GPIO20_FLASH_MODE_CFG,
1235 GPIO20_FLASH_MODE_CFG
1236 },
1237 .regmap_size = 1,
1238 }, {
1239 .name = "gpio21",
1240 .regmap[0] = {
1241 AIROHA_FUNC_PWM_EXT_MUX,
1242 REG_GPIO_FLASH_MODE_CFG_EXT,
1243 GPIO21_FLASH_MODE_CFG,
1244 GPIO21_FLASH_MODE_CFG
1245 },
1246 .regmap_size = 1,
1247 }, {
1248 .name = "gpio22",
1249 .regmap[0] = {
1250 AIROHA_FUNC_PWM_EXT_MUX,
1251 REG_GPIO_FLASH_MODE_CFG_EXT,
1252 GPIO22_FLASH_MODE_CFG,
1253 GPIO22_FLASH_MODE_CFG
1254 },
1255 .regmap_size = 1,
1256 }, {
1257 .name = "gpio23",
1258 .regmap[0] = {
1259 AIROHA_FUNC_PWM_EXT_MUX,
1260 REG_GPIO_FLASH_MODE_CFG_EXT,
1261 GPIO23_FLASH_MODE_CFG,
1262 GPIO23_FLASH_MODE_CFG
1263 },
1264 .regmap_size = 1,
1265 }, {
1266 .name = "gpio24",
1267 .regmap[0] = {
1268 AIROHA_FUNC_PWM_EXT_MUX,
1269 REG_GPIO_FLASH_MODE_CFG_EXT,
1270 GPIO24_FLASH_MODE_CFG,
1271 GPIO24_FLASH_MODE_CFG
1272 },
1273 .regmap_size = 1,
1274 }, {
1275 .name = "gpio25",
1276 .regmap[0] = {
1277 AIROHA_FUNC_PWM_EXT_MUX,
1278 REG_GPIO_FLASH_MODE_CFG_EXT,
1279 GPIO25_FLASH_MODE_CFG,
1280 GPIO25_FLASH_MODE_CFG
1281 },
1282 .regmap_size = 1,
1283 }, {
1284 .name = "gpio26",
1285 .regmap[0] = {
1286 AIROHA_FUNC_PWM_EXT_MUX,
1287 REG_GPIO_FLASH_MODE_CFG_EXT,
1288 GPIO26_FLASH_MODE_CFG,
1289 GPIO26_FLASH_MODE_CFG
1290 },
1291 .regmap_size = 1,
1292 }, {
1293 .name = "gpio27",
1294 .regmap[0] = {
1295 AIROHA_FUNC_PWM_EXT_MUX,
1296 REG_GPIO_FLASH_MODE_CFG_EXT,
1297 GPIO27_FLASH_MODE_CFG,
1298 GPIO27_FLASH_MODE_CFG
1299 },
1300 .regmap_size = 1,
1301 }, {
1302 .name = "gpio28",
1303 .regmap[0] = {
1304 AIROHA_FUNC_PWM_EXT_MUX,
1305 REG_GPIO_FLASH_MODE_CFG_EXT,
1306 GPIO28_FLASH_MODE_CFG,
1307 GPIO28_FLASH_MODE_CFG
1308 },
1309 .regmap_size = 1,
1310 }, {
1311 .name = "gpio29",
1312 .regmap[0] = {
1313 AIROHA_FUNC_PWM_EXT_MUX,
1314 REG_GPIO_FLASH_MODE_CFG_EXT,
1315 GPIO29_FLASH_MODE_CFG,
1316 GPIO29_FLASH_MODE_CFG
1317 },
1318 .regmap_size = 1,
1319 }, {
1320 .name = "gpio30",
1321 .regmap[0] = {
1322 AIROHA_FUNC_PWM_EXT_MUX,
1323 REG_GPIO_FLASH_MODE_CFG_EXT,
1324 GPIO30_FLASH_MODE_CFG,
1325 GPIO30_FLASH_MODE_CFG
1326 },
1327 .regmap_size = 1,
1328 }, {
1329 .name = "gpio31",
1330 .regmap[0] = {
1331 AIROHA_FUNC_PWM_EXT_MUX,
1332 REG_GPIO_FLASH_MODE_CFG_EXT,
1333 GPIO31_FLASH_MODE_CFG,
1334 GPIO31_FLASH_MODE_CFG
1335 },
1336 .regmap_size = 1,
1337 }, {
1338 .name = "gpio36",
1339 .regmap[0] = {
1340 AIROHA_FUNC_PWM_EXT_MUX,
1341 REG_GPIO_FLASH_MODE_CFG_EXT,
1342 GPIO36_FLASH_MODE_CFG,
1343 GPIO36_FLASH_MODE_CFG
1344 },
1345 .regmap_size = 1,
1346 }, {
1347 .name = "gpio37",
1348 .regmap[0] = {
1349 AIROHA_FUNC_PWM_EXT_MUX,
1350 REG_GPIO_FLASH_MODE_CFG_EXT,
1351 GPIO37_FLASH_MODE_CFG,
1352 GPIO37_FLASH_MODE_CFG
1353 },
1354 .regmap_size = 1,
1355 }, {
1356 .name = "gpio38",
1357 .regmap[0] = {
1358 AIROHA_FUNC_PWM_EXT_MUX,
1359 REG_GPIO_FLASH_MODE_CFG_EXT,
1360 GPIO38_FLASH_MODE_CFG,
1361 GPIO38_FLASH_MODE_CFG
1362 },
1363 .regmap_size = 1,
1364 }, {
1365 .name = "gpio39",
1366 .regmap[0] = {
1367 AIROHA_FUNC_PWM_EXT_MUX,
1368 REG_GPIO_FLASH_MODE_CFG_EXT,
1369 GPIO39_FLASH_MODE_CFG,
1370 GPIO39_FLASH_MODE_CFG
1371 },
1372 .regmap_size = 1,
1373 }, {
1374 .name = "gpio40",
1375 .regmap[0] = {
1376 AIROHA_FUNC_PWM_EXT_MUX,
1377 REG_GPIO_FLASH_MODE_CFG_EXT,
1378 GPIO40_FLASH_MODE_CFG,
1379 GPIO40_FLASH_MODE_CFG
1380 },
1381 .regmap_size = 1,
1382 }, {
1383 .name = "gpio41",
1384 .regmap[0] = {
1385 AIROHA_FUNC_PWM_EXT_MUX,
1386 REG_GPIO_FLASH_MODE_CFG_EXT,
1387 GPIO41_FLASH_MODE_CFG,
1388 GPIO41_FLASH_MODE_CFG
1389 },
1390 .regmap_size = 1,
1391 }, {
1392 .name = "gpio42",
1393 .regmap[0] = {
1394 AIROHA_FUNC_PWM_EXT_MUX,
1395 REG_GPIO_FLASH_MODE_CFG_EXT,
1396 GPIO42_FLASH_MODE_CFG,
1397 GPIO42_FLASH_MODE_CFG
1398 },
1399 .regmap_size = 1,
1400 }, {
1401 .name = "gpio43",
1402 .regmap[0] = {
1403 AIROHA_FUNC_PWM_EXT_MUX,
1404 REG_GPIO_FLASH_MODE_CFG_EXT,
1405 GPIO43_FLASH_MODE_CFG,
1406 GPIO43_FLASH_MODE_CFG
1407 },
1408 .regmap_size = 1,
1409 }, {
1410 .name = "gpio44",
1411 .regmap[0] = {
1412 AIROHA_FUNC_PWM_EXT_MUX,
1413 REG_GPIO_FLASH_MODE_CFG_EXT,
1414 GPIO44_FLASH_MODE_CFG,
1415 GPIO44_FLASH_MODE_CFG
1416 },
1417 .regmap_size = 1,
1418 }, {
1419 .name = "gpio45",
1420 .regmap[0] = {
1421 AIROHA_FUNC_PWM_EXT_MUX,
1422 REG_GPIO_FLASH_MODE_CFG_EXT,
1423 GPIO45_FLASH_MODE_CFG,
1424 GPIO45_FLASH_MODE_CFG
1425 },
1426 .regmap_size = 1,
1427 }, {
1428 .name = "gpio46",
1429 .regmap[0] = {
1430 AIROHA_FUNC_PWM_EXT_MUX,
1431 REG_GPIO_FLASH_MODE_CFG_EXT,
1432 GPIO46_FLASH_MODE_CFG,
1433 GPIO46_FLASH_MODE_CFG
1434 },
1435 .regmap_size = 1,
1436 }, {
1437 .name = "gpio47",
1438 .regmap[0] = {
1439 AIROHA_FUNC_PWM_EXT_MUX,
1440 REG_GPIO_FLASH_MODE_CFG_EXT,
1441 GPIO47_FLASH_MODE_CFG,
1442 GPIO47_FLASH_MODE_CFG
1443 },
1444 .regmap_size = 1,
1445 },
1446 };
1447
1448 static const struct airoha_pinctrl_func_group phy1_led0_func_group[] = {
1449 {
1450 .name = "gpio33",
1451 .regmap[0] = {
1452 AIROHA_FUNC_MUX,
1453 REG_GPIO_2ND_I2C_MODE,
1454 GPIO_LAN0_LED0_MODE_MASK,
1455 GPIO_LAN0_LED0_MODE_MASK
1456 },
1457 .regmap[1] = {
1458 AIROHA_FUNC_MUX,
1459 REG_LAN_LED0_MAPPING,
1460 LAN0_LED_MAPPING_MASK,
1461 LAN0_PHY_LED_MAP(0)
1462 },
1463 .regmap_size = 2,
1464 }, {
1465 .name = "gpio34",
1466 .regmap[0] = {
1467 AIROHA_FUNC_MUX,
1468 REG_GPIO_2ND_I2C_MODE,
1469 GPIO_LAN1_LED0_MODE_MASK,
1470 GPIO_LAN1_LED0_MODE_MASK
1471 },
1472 .regmap[1] = {
1473 AIROHA_FUNC_MUX,
1474 REG_LAN_LED0_MAPPING,
1475 LAN1_LED_MAPPING_MASK,
1476 LAN1_PHY_LED_MAP(0)
1477 },
1478 .regmap_size = 2,
1479 }, {
1480 .name = "gpio35",
1481 .regmap[0] = {
1482 AIROHA_FUNC_MUX,
1483 REG_GPIO_2ND_I2C_MODE,
1484 GPIO_LAN2_LED0_MODE_MASK,
1485 GPIO_LAN2_LED0_MODE_MASK
1486 },
1487 .regmap[1] = {
1488 AIROHA_FUNC_MUX,
1489 REG_LAN_LED0_MAPPING,
1490 LAN2_LED_MAPPING_MASK,
1491 LAN2_PHY_LED_MAP(0)
1492 },
1493 .regmap_size = 2,
1494 }, {
1495 .name = "gpio42",
1496 .regmap[0] = {
1497 AIROHA_FUNC_MUX,
1498 REG_GPIO_2ND_I2C_MODE,
1499 GPIO_LAN3_LED0_MODE_MASK,
1500 GPIO_LAN3_LED0_MODE_MASK
1501 },
1502 .regmap[1] = {
1503 AIROHA_FUNC_MUX,
1504 REG_LAN_LED0_MAPPING,
1505 LAN3_LED_MAPPING_MASK,
1506 LAN3_PHY_LED_MAP(0)
1507 },
1508 .regmap_size = 2,
1509 },
1510 };
1511
1512 static const struct airoha_pinctrl_func_group phy2_led0_func_group[] = {
1513 {
1514 .name = "gpio33",
1515 .regmap[0] = {
1516 AIROHA_FUNC_MUX,
1517 REG_GPIO_2ND_I2C_MODE,
1518 GPIO_LAN0_LED0_MODE_MASK,
1519 GPIO_LAN0_LED0_MODE_MASK
1520 },
1521 .regmap[1] = {
1522 AIROHA_FUNC_MUX,
1523 REG_LAN_LED0_MAPPING,
1524 LAN0_LED_MAPPING_MASK,
1525 LAN0_PHY_LED_MAP(1)
1526 },
1527 .regmap_size = 2,
1528 }, {
1529 .name = "gpio34",
1530 .regmap[0] = {
1531 AIROHA_FUNC_MUX,
1532 REG_GPIO_2ND_I2C_MODE,
1533 GPIO_LAN1_LED0_MODE_MASK,
1534 GPIO_LAN1_LED0_MODE_MASK
1535 },
1536 .regmap[1] = {
1537 AIROHA_FUNC_MUX,
1538 REG_LAN_LED0_MAPPING,
1539 LAN1_LED_MAPPING_MASK,
1540 LAN1_PHY_LED_MAP(1)
1541 },
1542 .regmap_size = 2,
1543 }, {
1544 .name = "gpio35",
1545 .regmap[0] = {
1546 AIROHA_FUNC_MUX,
1547 REG_GPIO_2ND_I2C_MODE,
1548 GPIO_LAN2_LED0_MODE_MASK,
1549 GPIO_LAN2_LED0_MODE_MASK
1550 },
1551 .regmap[1] = {
1552 AIROHA_FUNC_MUX,
1553 REG_LAN_LED0_MAPPING,
1554 LAN2_LED_MAPPING_MASK,
1555 LAN2_PHY_LED_MAP(1)
1556 },
1557 .regmap_size = 2,
1558 }, {
1559 .name = "gpio42",
1560 .regmap[0] = {
1561 AIROHA_FUNC_MUX,
1562 REG_GPIO_2ND_I2C_MODE,
1563 GPIO_LAN3_LED0_MODE_MASK,
1564 GPIO_LAN3_LED0_MODE_MASK
1565 },
1566 .regmap[1] = {
1567 AIROHA_FUNC_MUX,
1568 REG_LAN_LED0_MAPPING,
1569 LAN3_LED_MAPPING_MASK,
1570 LAN3_PHY_LED_MAP(1)
1571 },
1572 .regmap_size = 2,
1573 },
1574 };
1575
1576 static const struct airoha_pinctrl_func_group phy3_led0_func_group[] = {
1577 {
1578 .name = "gpio33",
1579 .regmap[0] = {
1580 AIROHA_FUNC_MUX,
1581 REG_GPIO_2ND_I2C_MODE,
1582 GPIO_LAN0_LED0_MODE_MASK,
1583 GPIO_LAN0_LED0_MODE_MASK
1584 },
1585 .regmap[1] = {
1586 AIROHA_FUNC_MUX,
1587 REG_LAN_LED0_MAPPING,
1588 LAN0_LED_MAPPING_MASK,
1589 LAN0_PHY_LED_MAP(2)
1590 },
1591 .regmap_size = 2,
1592 }, {
1593 .name = "gpio34",
1594 .regmap[0] = {
1595 AIROHA_FUNC_MUX,
1596 REG_GPIO_2ND_I2C_MODE,
1597 GPIO_LAN1_LED0_MODE_MASK,
1598 GPIO_LAN1_LED0_MODE_MASK
1599 },
1600 .regmap[1] = {
1601 AIROHA_FUNC_MUX,
1602 REG_LAN_LED0_MAPPING,
1603 LAN1_LED_MAPPING_MASK,
1604 LAN1_PHY_LED_MAP(2)
1605 },
1606 .regmap_size = 2,
1607 }, {
1608 .name = "gpio35",
1609 .regmap[0] = {
1610 AIROHA_FUNC_MUX,
1611 REG_GPIO_2ND_I2C_MODE,
1612 GPIO_LAN2_LED0_MODE_MASK,
1613 GPIO_LAN2_LED0_MODE_MASK
1614 },
1615 .regmap[1] = {
1616 AIROHA_FUNC_MUX,
1617 REG_LAN_LED0_MAPPING,
1618 LAN2_LED_MAPPING_MASK,
1619 LAN2_PHY_LED_MAP(2)
1620 },
1621 .regmap_size = 2,
1622 }, {
1623 .name = "gpio42",
1624 .regmap[0] = {
1625 AIROHA_FUNC_MUX,
1626 REG_GPIO_2ND_I2C_MODE,
1627 GPIO_LAN3_LED0_MODE_MASK,
1628 GPIO_LAN3_LED0_MODE_MASK
1629 },
1630 .regmap[1] = {
1631 AIROHA_FUNC_MUX,
1632 REG_LAN_LED0_MAPPING,
1633 LAN3_LED_MAPPING_MASK,
1634 LAN3_PHY_LED_MAP(2)
1635 },
1636 .regmap_size = 2,
1637 },
1638 };
1639
1640 static const struct airoha_pinctrl_func_group phy4_led0_func_group[] = {
1641 {
1642 .name = "gpio33",
1643 .regmap[0] = {
1644 AIROHA_FUNC_MUX,
1645 REG_GPIO_2ND_I2C_MODE,
1646 GPIO_LAN0_LED0_MODE_MASK,
1647 GPIO_LAN0_LED0_MODE_MASK
1648 },
1649 .regmap[1] = {
1650 AIROHA_FUNC_MUX,
1651 REG_LAN_LED0_MAPPING,
1652 LAN0_LED_MAPPING_MASK,
1653 LAN0_PHY_LED_MAP(3)
1654 },
1655 .regmap_size = 2,
1656 }, {
1657 .name = "gpio34",
1658 .regmap[0] = {
1659 AIROHA_FUNC_MUX,
1660 REG_GPIO_2ND_I2C_MODE,
1661 GPIO_LAN1_LED0_MODE_MASK,
1662 GPIO_LAN1_LED0_MODE_MASK
1663 },
1664 .regmap[1] = {
1665 AIROHA_FUNC_MUX,
1666 REG_LAN_LED0_MAPPING,
1667 LAN1_LED_MAPPING_MASK,
1668 LAN1_PHY_LED_MAP(3)
1669 },
1670 .regmap_size = 2,
1671 }, {
1672 .name = "gpio35",
1673 .regmap[0] = {
1674 AIROHA_FUNC_MUX,
1675 REG_GPIO_2ND_I2C_MODE,
1676 GPIO_LAN2_LED0_MODE_MASK,
1677 GPIO_LAN2_LED0_MODE_MASK
1678 },
1679 .regmap[1] = {
1680 AIROHA_FUNC_MUX,
1681 REG_LAN_LED0_MAPPING,
1682 LAN2_LED_MAPPING_MASK,
1683 LAN2_PHY_LED_MAP(3)
1684 },
1685 .regmap_size = 2,
1686 }, {
1687 .name = "gpio42",
1688 .regmap[0] = {
1689 AIROHA_FUNC_MUX,
1690 REG_GPIO_2ND_I2C_MODE,
1691 GPIO_LAN3_LED0_MODE_MASK,
1692 GPIO_LAN3_LED0_MODE_MASK
1693 },
1694 .regmap[1] = {
1695 AIROHA_FUNC_MUX,
1696 REG_LAN_LED0_MAPPING,
1697 LAN3_LED_MAPPING_MASK,
1698 LAN3_PHY_LED_MAP(3)
1699 },
1700 .regmap_size = 2,
1701 },
1702 };
1703
1704 static const struct airoha_pinctrl_func_group phy1_led1_func_group[] = {
1705 {
1706 .name = "gpio43",
1707 .regmap[0] = {
1708 AIROHA_FUNC_MUX,
1709 REG_GPIO_2ND_I2C_MODE,
1710 GPIO_LAN0_LED1_MODE_MASK,
1711 GPIO_LAN0_LED1_MODE_MASK
1712 },
1713 .regmap[1] = {
1714 AIROHA_FUNC_MUX,
1715 REG_LAN_LED1_MAPPING,
1716 LAN0_LED_MAPPING_MASK,
1717 LAN0_PHY_LED_MAP(0)
1718 },
1719 .regmap_size = 2,
1720 }, {
1721 .name = "gpio44",
1722 .regmap[0] = {
1723 AIROHA_FUNC_MUX,
1724 REG_GPIO_2ND_I2C_MODE,
1725 GPIO_LAN1_LED1_MODE_MASK,
1726 GPIO_LAN1_LED1_MODE_MASK
1727 },
1728 .regmap[1] = {
1729 AIROHA_FUNC_MUX,
1730 REG_LAN_LED1_MAPPING,
1731 LAN1_LED_MAPPING_MASK,
1732 LAN1_PHY_LED_MAP(0)
1733 },
1734 .regmap_size = 2,
1735 }, {
1736 .name = "gpio45",
1737 .regmap[0] = {
1738 AIROHA_FUNC_MUX,
1739 REG_GPIO_2ND_I2C_MODE,
1740 GPIO_LAN2_LED1_MODE_MASK,
1741 GPIO_LAN2_LED1_MODE_MASK
1742 },
1743 .regmap[1] = {
1744 AIROHA_FUNC_MUX,
1745 REG_LAN_LED1_MAPPING,
1746 LAN2_LED_MAPPING_MASK,
1747 LAN2_PHY_LED_MAP(0)
1748 },
1749 .regmap_size = 2,
1750 }, {
1751 .name = "gpio46",
1752 .regmap[0] = {
1753 AIROHA_FUNC_MUX,
1754 REG_GPIO_2ND_I2C_MODE,
1755 GPIO_LAN3_LED0_MODE_MASK,
1756 GPIO_LAN3_LED0_MODE_MASK
1757 },
1758 .regmap[1] = {
1759 AIROHA_FUNC_MUX,
1760 REG_LAN_LED1_MAPPING,
1761 LAN3_LED_MAPPING_MASK,
1762 LAN3_PHY_LED_MAP(0)
1763 },
1764 .regmap_size = 2,
1765 },
1766 };
1767
1768 static const struct airoha_pinctrl_func_group phy2_led1_func_group[] = {
1769 {
1770 .name = "gpio43",
1771 .regmap[0] = {
1772 AIROHA_FUNC_MUX,
1773 REG_GPIO_2ND_I2C_MODE,
1774 GPIO_LAN0_LED1_MODE_MASK,
1775 GPIO_LAN0_LED1_MODE_MASK
1776 },
1777 .regmap[1] = {
1778 AIROHA_FUNC_MUX,
1779 REG_LAN_LED1_MAPPING,
1780 LAN0_LED_MAPPING_MASK,
1781 LAN0_PHY_LED_MAP(1)
1782 },
1783 .regmap_size = 2,
1784 }, {
1785 .name = "gpio44",
1786 .regmap[0] = {
1787 AIROHA_FUNC_MUX,
1788 REG_GPIO_2ND_I2C_MODE,
1789 GPIO_LAN1_LED1_MODE_MASK,
1790 GPIO_LAN1_LED1_MODE_MASK
1791 },
1792 .regmap[1] = {
1793 AIROHA_FUNC_MUX,
1794 REG_LAN_LED1_MAPPING,
1795 LAN1_LED_MAPPING_MASK,
1796 LAN1_PHY_LED_MAP(1)
1797 },
1798 .regmap_size = 2,
1799 }, {
1800 .name = "gpio45",
1801 .regmap[0] = {
1802 AIROHA_FUNC_MUX,
1803 REG_GPIO_2ND_I2C_MODE,
1804 GPIO_LAN2_LED1_MODE_MASK,
1805 GPIO_LAN2_LED1_MODE_MASK
1806 },
1807 .regmap[1] = {
1808 AIROHA_FUNC_MUX,
1809 REG_LAN_LED1_MAPPING,
1810 LAN2_LED_MAPPING_MASK,
1811 LAN2_PHY_LED_MAP(1)
1812 },
1813 .regmap_size = 2,
1814 }, {
1815 .name = "gpio46",
1816 .regmap[0] = {
1817 AIROHA_FUNC_MUX,
1818 REG_GPIO_2ND_I2C_MODE,
1819 GPIO_LAN3_LED0_MODE_MASK,
1820 GPIO_LAN3_LED0_MODE_MASK
1821 },
1822 .regmap[1] = {
1823 AIROHA_FUNC_MUX,
1824 REG_LAN_LED1_MAPPING,
1825 LAN3_LED_MAPPING_MASK,
1826 LAN3_PHY_LED_MAP(1)
1827 },
1828 .regmap_size = 2,
1829 },
1830 };
1831
1832 static const struct airoha_pinctrl_func_group phy3_led1_func_group[] = {
1833 {
1834 .name = "gpio43",
1835 .regmap[0] = {
1836 AIROHA_FUNC_MUX,
1837 REG_GPIO_2ND_I2C_MODE,
1838 GPIO_LAN0_LED1_MODE_MASK,
1839 GPIO_LAN0_LED1_MODE_MASK
1840 },
1841 .regmap[1] = {
1842 AIROHA_FUNC_MUX,
1843 REG_LAN_LED1_MAPPING,
1844 LAN0_LED_MAPPING_MASK,
1845 LAN0_PHY_LED_MAP(2)
1846 },
1847 .regmap_size = 2,
1848 }, {
1849 .name = "gpio44",
1850 .regmap[0] = {
1851 AIROHA_FUNC_MUX,
1852 REG_GPIO_2ND_I2C_MODE,
1853 GPIO_LAN1_LED1_MODE_MASK,
1854 GPIO_LAN1_LED1_MODE_MASK
1855 },
1856 .regmap[1] = {
1857 AIROHA_FUNC_MUX,
1858 REG_LAN_LED1_MAPPING,
1859 LAN1_LED_MAPPING_MASK,
1860 LAN1_PHY_LED_MAP(2)
1861 },
1862 .regmap_size = 2,
1863 }, {
1864 .name = "gpio45",
1865 .regmap[0] = {
1866 AIROHA_FUNC_MUX,
1867 REG_GPIO_2ND_I2C_MODE,
1868 GPIO_LAN2_LED1_MODE_MASK,
1869 GPIO_LAN2_LED1_MODE_MASK
1870 },
1871 .regmap[1] = {
1872 AIROHA_FUNC_MUX,
1873 REG_LAN_LED1_MAPPING,
1874 LAN2_LED_MAPPING_MASK,
1875 LAN2_PHY_LED_MAP(2)
1876 },
1877 .regmap_size = 2,
1878 }, {
1879 .name = "gpio46",
1880 .regmap[0] = {
1881 AIROHA_FUNC_MUX,
1882 REG_GPIO_2ND_I2C_MODE,
1883 GPIO_LAN3_LED0_MODE_MASK,
1884 GPIO_LAN3_LED0_MODE_MASK
1885 },
1886 .regmap[1] = {
1887 AIROHA_FUNC_MUX,
1888 REG_LAN_LED1_MAPPING,
1889 LAN3_LED_MAPPING_MASK,
1890 LAN3_PHY_LED_MAP(2)
1891 },
1892 .regmap_size = 2,
1893 },
1894 };
1895
1896 static const struct airoha_pinctrl_func_group phy4_led1_func_group[] = {
1897 {
1898 .name = "gpio43",
1899 .regmap[0] = {
1900 AIROHA_FUNC_MUX,
1901 REG_GPIO_2ND_I2C_MODE,
1902 GPIO_LAN0_LED1_MODE_MASK,
1903 GPIO_LAN0_LED1_MODE_MASK
1904 },
1905 .regmap[1] = {
1906 AIROHA_FUNC_MUX,
1907 REG_LAN_LED1_MAPPING,
1908 LAN0_LED_MAPPING_MASK,
1909 LAN0_PHY_LED_MAP(3)
1910 },
1911 .regmap_size = 2,
1912 }, {
1913 .name = "gpio44",
1914 .regmap[0] = {
1915 AIROHA_FUNC_MUX,
1916 REG_GPIO_2ND_I2C_MODE,
1917 GPIO_LAN1_LED1_MODE_MASK,
1918 GPIO_LAN1_LED1_MODE_MASK
1919 },
1920 .regmap[1] = {
1921 AIROHA_FUNC_MUX,
1922 REG_LAN_LED1_MAPPING,
1923 LAN1_LED_MAPPING_MASK,
1924 LAN1_PHY_LED_MAP(3)
1925 },
1926 .regmap_size = 2,
1927 }, {
1928 .name = "gpio45",
1929 .regmap[0] = {
1930 AIROHA_FUNC_MUX,
1931 REG_GPIO_2ND_I2C_MODE,
1932 GPIO_LAN2_LED1_MODE_MASK,
1933 GPIO_LAN2_LED1_MODE_MASK
1934 },
1935 .regmap[1] = {
1936 AIROHA_FUNC_MUX,
1937 REG_LAN_LED1_MAPPING,
1938 LAN2_LED_MAPPING_MASK,
1939 LAN2_PHY_LED_MAP(3)
1940 },
1941 .regmap_size = 2,
1942 }, {
1943 .name = "gpio46",
1944 .regmap[0] = {
1945 AIROHA_FUNC_MUX,
1946 REG_GPIO_2ND_I2C_MODE,
1947 GPIO_LAN3_LED0_MODE_MASK,
1948 GPIO_LAN3_LED0_MODE_MASK
1949 },
1950 .regmap[1] = {
1951 AIROHA_FUNC_MUX,
1952 REG_LAN_LED1_MAPPING,
1953 LAN3_LED_MAPPING_MASK,
1954 LAN3_PHY_LED_MAP(3)
1955 },
1956 .regmap_size = 2,
1957 },
1958 };
1959
1960 static const struct airoha_pinctrl_func airoha_pinctrl_funcs[] = {
1961 PINCTRL_FUNC_DESC(pon),
1962 PINCTRL_FUNC_DESC(tod_1pps),
1963 PINCTRL_FUNC_DESC(sipo),
1964 PINCTRL_FUNC_DESC(mdio),
1965 PINCTRL_FUNC_DESC(uart),
1966 PINCTRL_FUNC_DESC(i2c),
1967 PINCTRL_FUNC_DESC(jtag),
1968 PINCTRL_FUNC_DESC(pcm),
1969 PINCTRL_FUNC_DESC(spi),
1970 PINCTRL_FUNC_DESC(pcm_spi),
1971 PINCTRL_FUNC_DESC(i2s),
1972 PINCTRL_FUNC_DESC(emmc),
1973 PINCTRL_FUNC_DESC(pnand),
1974 PINCTRL_FUNC_DESC(pcie_reset),
1975 PINCTRL_FUNC_DESC(pwm),
1976 PINCTRL_FUNC_DESC(phy1_led0),
1977 PINCTRL_FUNC_DESC(phy2_led0),
1978 PINCTRL_FUNC_DESC(phy3_led0),
1979 PINCTRL_FUNC_DESC(phy4_led0),
1980 PINCTRL_FUNC_DESC(phy1_led1),
1981 PINCTRL_FUNC_DESC(phy2_led1),
1982 PINCTRL_FUNC_DESC(phy3_led1),
1983 PINCTRL_FUNC_DESC(phy4_led1),
1984 };
1985
1986 static const struct airoha_pinctrl_conf airoha_pinctrl_pullup_conf[] = {
1987 PINCTRL_CONF_DESC(0, REG_I2C_SDA_PU, UART1_TXD_PU_MASK),
1988 PINCTRL_CONF_DESC(1, REG_I2C_SDA_PU, UART1_RXD_PU_MASK),
1989 PINCTRL_CONF_DESC(2, REG_I2C_SDA_PU, I2C_SDA_PU_MASK),
1990 PINCTRL_CONF_DESC(3, REG_I2C_SDA_PU, I2C_SCL_PU_MASK),
1991 PINCTRL_CONF_DESC(4, REG_I2C_SDA_PU, SPI_CS0_PU_MASK),
1992 PINCTRL_CONF_DESC(5, REG_I2C_SDA_PU, SPI_CLK_PU_MASK),
1993 PINCTRL_CONF_DESC(6, REG_I2C_SDA_PU, SPI_MOSI_PU_MASK),
1994 PINCTRL_CONF_DESC(7, REG_I2C_SDA_PU, SPI_MISO_PU_MASK),
1995 PINCTRL_CONF_DESC(13, REG_GPIO_L_PU, BIT(0)),
1996 PINCTRL_CONF_DESC(14, REG_GPIO_L_PU, BIT(1)),
1997 PINCTRL_CONF_DESC(15, REG_GPIO_L_PU, BIT(2)),
1998 PINCTRL_CONF_DESC(16, REG_GPIO_L_PU, BIT(3)),
1999 PINCTRL_CONF_DESC(17, REG_GPIO_L_PU, BIT(4)),
2000 PINCTRL_CONF_DESC(18, REG_GPIO_L_PU, BIT(5)),
2001 PINCTRL_CONF_DESC(19, REG_GPIO_L_PU, BIT(6)),
2002 PINCTRL_CONF_DESC(20, REG_GPIO_L_PU, BIT(7)),
2003 PINCTRL_CONF_DESC(21, REG_GPIO_L_PU, BIT(8)),
2004 PINCTRL_CONF_DESC(22, REG_GPIO_L_PU, BIT(9)),
2005 PINCTRL_CONF_DESC(23, REG_GPIO_L_PU, BIT(10)),
2006 PINCTRL_CONF_DESC(24, REG_GPIO_L_PU, BIT(11)),
2007 PINCTRL_CONF_DESC(25, REG_GPIO_L_PU, BIT(12)),
2008 PINCTRL_CONF_DESC(26, REG_GPIO_L_PU, BIT(13)),
2009 PINCTRL_CONF_DESC(27, REG_GPIO_L_PU, BIT(14)),
2010 PINCTRL_CONF_DESC(28, REG_GPIO_L_PU, BIT(15)),
2011 PINCTRL_CONF_DESC(29, REG_GPIO_L_PU, BIT(16)),
2012 PINCTRL_CONF_DESC(30, REG_GPIO_L_PU, BIT(17)),
2013 PINCTRL_CONF_DESC(31, REG_GPIO_L_PU, BIT(18)),
2014 PINCTRL_CONF_DESC(32, REG_GPIO_L_PU, BIT(18)),
2015 PINCTRL_CONF_DESC(33, REG_GPIO_L_PU, BIT(20)),
2016 PINCTRL_CONF_DESC(34, REG_GPIO_L_PU, BIT(21)),
2017 PINCTRL_CONF_DESC(35, REG_GPIO_L_PU, BIT(22)),
2018 PINCTRL_CONF_DESC(36, REG_GPIO_L_PU, BIT(23)),
2019 PINCTRL_CONF_DESC(37, REG_GPIO_L_PU, BIT(24)),
2020 PINCTRL_CONF_DESC(38, REG_GPIO_L_PU, BIT(25)),
2021 PINCTRL_CONF_DESC(39, REG_GPIO_L_PU, BIT(26)),
2022 PINCTRL_CONF_DESC(40, REG_GPIO_L_PU, BIT(27)),
2023 PINCTRL_CONF_DESC(41, REG_GPIO_L_PU, BIT(28)),
2024 PINCTRL_CONF_DESC(42, REG_GPIO_L_PU, BIT(29)),
2025 PINCTRL_CONF_DESC(43, REG_GPIO_L_PU, BIT(30)),
2026 PINCTRL_CONF_DESC(44, REG_GPIO_L_PU, BIT(31)),
2027 PINCTRL_CONF_DESC(45, REG_GPIO_H_PU, BIT(0)),
2028 PINCTRL_CONF_DESC(46, REG_GPIO_H_PU, BIT(1)),
2029 PINCTRL_CONF_DESC(47, REG_GPIO_H_PU, BIT(2)),
2030 PINCTRL_CONF_DESC(48, REG_GPIO_H_PU, BIT(3)),
2031 PINCTRL_CONF_DESC(49, REG_GPIO_H_PU, BIT(4)),
2032 PINCTRL_CONF_DESC(50, REG_GPIO_H_PU, BIT(5)),
2033 PINCTRL_CONF_DESC(51, REG_GPIO_H_PU, BIT(6)),
2034 PINCTRL_CONF_DESC(52, REG_GPIO_H_PU, BIT(7)),
2035 PINCTRL_CONF_DESC(53, REG_GPIO_H_PU, BIT(8)),
2036 PINCTRL_CONF_DESC(54, REG_GPIO_H_PU, BIT(9)),
2037 PINCTRL_CONF_DESC(55, REG_GPIO_H_PU, BIT(10)),
2038 PINCTRL_CONF_DESC(56, REG_GPIO_H_PU, BIT(11)),
2039 PINCTRL_CONF_DESC(57, REG_GPIO_H_PU, BIT(12)),
2040 PINCTRL_CONF_DESC(58, REG_GPIO_H_PU, BIT(13)),
2041 PINCTRL_CONF_DESC(59, REG_GPIO_H_PU, BIT(14)),
2042 PINCTRL_CONF_DESC(61, REG_I2C_SDA_PU, PCIE0_RESET_PU_MASK),
2043 PINCTRL_CONF_DESC(62, REG_I2C_SDA_PU, PCIE1_RESET_PU_MASK),
2044 PINCTRL_CONF_DESC(63, REG_I2C_SDA_PU, PCIE2_RESET_PU_MASK),
2045 };
2046
2047 static const struct airoha_pinctrl_conf airoha_pinctrl_pulldown_conf[] = {
2048 PINCTRL_CONF_DESC(0, REG_I2C_SDA_PD, UART1_TXD_PD_MASK),
2049 PINCTRL_CONF_DESC(1, REG_I2C_SDA_PD, UART1_RXD_PD_MASK),
2050 PINCTRL_CONF_DESC(2, REG_I2C_SDA_PD, I2C_SDA_PD_MASK),
2051 PINCTRL_CONF_DESC(3, REG_I2C_SDA_PD, I2C_SCL_PD_MASK),
2052 PINCTRL_CONF_DESC(4, REG_I2C_SDA_PD, SPI_CS0_PD_MASK),
2053 PINCTRL_CONF_DESC(5, REG_I2C_SDA_PD, SPI_CLK_PD_MASK),
2054 PINCTRL_CONF_DESC(6, REG_I2C_SDA_PD, SPI_MOSI_PD_MASK),
2055 PINCTRL_CONF_DESC(7, REG_I2C_SDA_PD, SPI_MISO_PD_MASK),
2056 PINCTRL_CONF_DESC(13, REG_GPIO_L_PD, BIT(0)),
2057 PINCTRL_CONF_DESC(14, REG_GPIO_L_PD, BIT(1)),
2058 PINCTRL_CONF_DESC(15, REG_GPIO_L_PD, BIT(2)),
2059 PINCTRL_CONF_DESC(16, REG_GPIO_L_PD, BIT(3)),
2060 PINCTRL_CONF_DESC(17, REG_GPIO_L_PD, BIT(4)),
2061 PINCTRL_CONF_DESC(18, REG_GPIO_L_PD, BIT(5)),
2062 PINCTRL_CONF_DESC(19, REG_GPIO_L_PD, BIT(6)),
2063 PINCTRL_CONF_DESC(20, REG_GPIO_L_PD, BIT(7)),
2064 PINCTRL_CONF_DESC(21, REG_GPIO_L_PD, BIT(8)),
2065 PINCTRL_CONF_DESC(22, REG_GPIO_L_PD, BIT(9)),
2066 PINCTRL_CONF_DESC(23, REG_GPIO_L_PD, BIT(10)),
2067 PINCTRL_CONF_DESC(24, REG_GPIO_L_PD, BIT(11)),
2068 PINCTRL_CONF_DESC(25, REG_GPIO_L_PD, BIT(12)),
2069 PINCTRL_CONF_DESC(26, REG_GPIO_L_PD, BIT(13)),
2070 PINCTRL_CONF_DESC(27, REG_GPIO_L_PD, BIT(14)),
2071 PINCTRL_CONF_DESC(28, REG_GPIO_L_PD, BIT(15)),
2072 PINCTRL_CONF_DESC(29, REG_GPIO_L_PD, BIT(16)),
2073 PINCTRL_CONF_DESC(30, REG_GPIO_L_PD, BIT(17)),
2074 PINCTRL_CONF_DESC(31, REG_GPIO_L_PD, BIT(18)),
2075 PINCTRL_CONF_DESC(32, REG_GPIO_L_PD, BIT(18)),
2076 PINCTRL_CONF_DESC(33, REG_GPIO_L_PD, BIT(20)),
2077 PINCTRL_CONF_DESC(34, REG_GPIO_L_PD, BIT(21)),
2078 PINCTRL_CONF_DESC(35, REG_GPIO_L_PD, BIT(22)),
2079 PINCTRL_CONF_DESC(36, REG_GPIO_L_PD, BIT(23)),
2080 PINCTRL_CONF_DESC(37, REG_GPIO_L_PD, BIT(24)),
2081 PINCTRL_CONF_DESC(38, REG_GPIO_L_PD, BIT(25)),
2082 PINCTRL_CONF_DESC(39, REG_GPIO_L_PD, BIT(26)),
2083 PINCTRL_CONF_DESC(40, REG_GPIO_L_PD, BIT(27)),
2084 PINCTRL_CONF_DESC(41, REG_GPIO_L_PD, BIT(28)),
2085 PINCTRL_CONF_DESC(42, REG_GPIO_L_PD, BIT(29)),
2086 PINCTRL_CONF_DESC(43, REG_GPIO_L_PD, BIT(30)),
2087 PINCTRL_CONF_DESC(44, REG_GPIO_L_PD, BIT(31)),
2088 PINCTRL_CONF_DESC(45, REG_GPIO_H_PD, BIT(0)),
2089 PINCTRL_CONF_DESC(46, REG_GPIO_H_PD, BIT(1)),
2090 PINCTRL_CONF_DESC(47, REG_GPIO_H_PD, BIT(2)),
2091 PINCTRL_CONF_DESC(48, REG_GPIO_H_PD, BIT(3)),
2092 PINCTRL_CONF_DESC(49, REG_GPIO_H_PD, BIT(4)),
2093 PINCTRL_CONF_DESC(50, REG_GPIO_H_PD, BIT(5)),
2094 PINCTRL_CONF_DESC(51, REG_GPIO_H_PD, BIT(6)),
2095 PINCTRL_CONF_DESC(52, REG_GPIO_H_PD, BIT(7)),
2096 PINCTRL_CONF_DESC(53, REG_GPIO_H_PD, BIT(8)),
2097 PINCTRL_CONF_DESC(54, REG_GPIO_H_PD, BIT(9)),
2098 PINCTRL_CONF_DESC(55, REG_GPIO_H_PD, BIT(10)),
2099 PINCTRL_CONF_DESC(56, REG_GPIO_H_PD, BIT(11)),
2100 PINCTRL_CONF_DESC(57, REG_GPIO_H_PD, BIT(12)),
2101 PINCTRL_CONF_DESC(58, REG_GPIO_H_PD, BIT(13)),
2102 PINCTRL_CONF_DESC(59, REG_GPIO_H_PD, BIT(14)),
2103 PINCTRL_CONF_DESC(61, REG_I2C_SDA_PD, PCIE0_RESET_PD_MASK),
2104 PINCTRL_CONF_DESC(62, REG_I2C_SDA_PD, PCIE1_RESET_PD_MASK),
2105 PINCTRL_CONF_DESC(63, REG_I2C_SDA_PD, PCIE2_RESET_PD_MASK),
2106 };
2107
2108 static const struct airoha_pinctrl_conf airoha_pinctrl_drive_e2_conf[] = {
2109 PINCTRL_CONF_DESC(0, REG_I2C_SDA_E2, UART1_TXD_E2_MASK),
2110 PINCTRL_CONF_DESC(1, REG_I2C_SDA_E2, UART1_RXD_E2_MASK),
2111 PINCTRL_CONF_DESC(2, REG_I2C_SDA_E2, I2C_SDA_E2_MASK),
2112 PINCTRL_CONF_DESC(3, REG_I2C_SDA_E2, I2C_SCL_E2_MASK),
2113 PINCTRL_CONF_DESC(4, REG_I2C_SDA_E2, SPI_CS0_E2_MASK),
2114 PINCTRL_CONF_DESC(5, REG_I2C_SDA_E2, SPI_CLK_E2_MASK),
2115 PINCTRL_CONF_DESC(6, REG_I2C_SDA_E2, SPI_MOSI_E2_MASK),
2116 PINCTRL_CONF_DESC(7, REG_I2C_SDA_E2, SPI_MISO_E2_MASK),
2117 PINCTRL_CONF_DESC(13, REG_GPIO_L_E2, BIT(0)),
2118 PINCTRL_CONF_DESC(14, REG_GPIO_L_E2, BIT(1)),
2119 PINCTRL_CONF_DESC(15, REG_GPIO_L_E2, BIT(2)),
2120 PINCTRL_CONF_DESC(16, REG_GPIO_L_E2, BIT(3)),
2121 PINCTRL_CONF_DESC(17, REG_GPIO_L_E2, BIT(4)),
2122 PINCTRL_CONF_DESC(18, REG_GPIO_L_E2, BIT(5)),
2123 PINCTRL_CONF_DESC(19, REG_GPIO_L_E2, BIT(6)),
2124 PINCTRL_CONF_DESC(20, REG_GPIO_L_E2, BIT(7)),
2125 PINCTRL_CONF_DESC(21, REG_GPIO_L_E2, BIT(8)),
2126 PINCTRL_CONF_DESC(22, REG_GPIO_L_E2, BIT(9)),
2127 PINCTRL_CONF_DESC(23, REG_GPIO_L_E2, BIT(10)),
2128 PINCTRL_CONF_DESC(24, REG_GPIO_L_E2, BIT(11)),
2129 PINCTRL_CONF_DESC(25, REG_GPIO_L_E2, BIT(12)),
2130 PINCTRL_CONF_DESC(26, REG_GPIO_L_E2, BIT(13)),
2131 PINCTRL_CONF_DESC(27, REG_GPIO_L_E2, BIT(14)),
2132 PINCTRL_CONF_DESC(28, REG_GPIO_L_E2, BIT(15)),
2133 PINCTRL_CONF_DESC(29, REG_GPIO_L_E2, BIT(16)),
2134 PINCTRL_CONF_DESC(30, REG_GPIO_L_E2, BIT(17)),
2135 PINCTRL_CONF_DESC(31, REG_GPIO_L_E2, BIT(18)),
2136 PINCTRL_CONF_DESC(32, REG_GPIO_L_E2, BIT(18)),
2137 PINCTRL_CONF_DESC(33, REG_GPIO_L_E2, BIT(20)),
2138 PINCTRL_CONF_DESC(34, REG_GPIO_L_E2, BIT(21)),
2139 PINCTRL_CONF_DESC(35, REG_GPIO_L_E2, BIT(22)),
2140 PINCTRL_CONF_DESC(36, REG_GPIO_L_E2, BIT(23)),
2141 PINCTRL_CONF_DESC(37, REG_GPIO_L_E2, BIT(24)),
2142 PINCTRL_CONF_DESC(38, REG_GPIO_L_E2, BIT(25)),
2143 PINCTRL_CONF_DESC(39, REG_GPIO_L_E2, BIT(26)),
2144 PINCTRL_CONF_DESC(40, REG_GPIO_L_E2, BIT(27)),
2145 PINCTRL_CONF_DESC(41, REG_GPIO_L_E2, BIT(28)),
2146 PINCTRL_CONF_DESC(42, REG_GPIO_L_E2, BIT(29)),
2147 PINCTRL_CONF_DESC(43, REG_GPIO_L_E2, BIT(30)),
2148 PINCTRL_CONF_DESC(44, REG_GPIO_L_E2, BIT(31)),
2149 PINCTRL_CONF_DESC(45, REG_GPIO_H_E2, BIT(0)),
2150 PINCTRL_CONF_DESC(46, REG_GPIO_H_E2, BIT(1)),
2151 PINCTRL_CONF_DESC(47, REG_GPIO_H_E2, BIT(2)),
2152 PINCTRL_CONF_DESC(48, REG_GPIO_H_E2, BIT(3)),
2153 PINCTRL_CONF_DESC(49, REG_GPIO_H_E2, BIT(4)),
2154 PINCTRL_CONF_DESC(50, REG_GPIO_H_E2, BIT(5)),
2155 PINCTRL_CONF_DESC(51, REG_GPIO_H_E2, BIT(6)),
2156 PINCTRL_CONF_DESC(52, REG_GPIO_H_E2, BIT(7)),
2157 PINCTRL_CONF_DESC(53, REG_GPIO_H_E2, BIT(8)),
2158 PINCTRL_CONF_DESC(54, REG_GPIO_H_E2, BIT(9)),
2159 PINCTRL_CONF_DESC(55, REG_GPIO_H_E2, BIT(10)),
2160 PINCTRL_CONF_DESC(56, REG_GPIO_H_E2, BIT(11)),
2161 PINCTRL_CONF_DESC(57, REG_GPIO_H_E2, BIT(12)),
2162 PINCTRL_CONF_DESC(58, REG_GPIO_H_E2, BIT(13)),
2163 PINCTRL_CONF_DESC(59, REG_GPIO_H_E2, BIT(14)),
2164 PINCTRL_CONF_DESC(61, REG_I2C_SDA_E2, PCIE0_RESET_E2_MASK),
2165 PINCTRL_CONF_DESC(62, REG_I2C_SDA_E2, PCIE1_RESET_E2_MASK),
2166 PINCTRL_CONF_DESC(63, REG_I2C_SDA_E2, PCIE2_RESET_E2_MASK),
2167 };
2168
2169 static const struct airoha_pinctrl_conf airoha_pinctrl_drive_e4_conf[] = {
2170 PINCTRL_CONF_DESC(0, REG_I2C_SDA_E4, UART1_TXD_E4_MASK),
2171 PINCTRL_CONF_DESC(1, REG_I2C_SDA_E4, UART1_RXD_E4_MASK),
2172 PINCTRL_CONF_DESC(2, REG_I2C_SDA_E4, I2C_SDA_E4_MASK),
2173 PINCTRL_CONF_DESC(3, REG_I2C_SDA_E4, I2C_SCL_E4_MASK),
2174 PINCTRL_CONF_DESC(4, REG_I2C_SDA_E4, SPI_CS0_E4_MASK),
2175 PINCTRL_CONF_DESC(5, REG_I2C_SDA_E4, SPI_CLK_E4_MASK),
2176 PINCTRL_CONF_DESC(6, REG_I2C_SDA_E4, SPI_MOSI_E4_MASK),
2177 PINCTRL_CONF_DESC(7, REG_I2C_SDA_E4, SPI_MISO_E4_MASK),
2178 PINCTRL_CONF_DESC(13, REG_GPIO_L_E4, BIT(0)),
2179 PINCTRL_CONF_DESC(14, REG_GPIO_L_E4, BIT(1)),
2180 PINCTRL_CONF_DESC(15, REG_GPIO_L_E4, BIT(2)),
2181 PINCTRL_CONF_DESC(16, REG_GPIO_L_E4, BIT(3)),
2182 PINCTRL_CONF_DESC(17, REG_GPIO_L_E4, BIT(4)),
2183 PINCTRL_CONF_DESC(18, REG_GPIO_L_E4, BIT(5)),
2184 PINCTRL_CONF_DESC(19, REG_GPIO_L_E4, BIT(6)),
2185 PINCTRL_CONF_DESC(20, REG_GPIO_L_E4, BIT(7)),
2186 PINCTRL_CONF_DESC(21, REG_GPIO_L_E4, BIT(8)),
2187 PINCTRL_CONF_DESC(22, REG_GPIO_L_E4, BIT(9)),
2188 PINCTRL_CONF_DESC(23, REG_GPIO_L_E4, BIT(10)),
2189 PINCTRL_CONF_DESC(24, REG_GPIO_L_E4, BIT(11)),
2190 PINCTRL_CONF_DESC(25, REG_GPIO_L_E4, BIT(12)),
2191 PINCTRL_CONF_DESC(26, REG_GPIO_L_E4, BIT(13)),
2192 PINCTRL_CONF_DESC(27, REG_GPIO_L_E4, BIT(14)),
2193 PINCTRL_CONF_DESC(28, REG_GPIO_L_E4, BIT(15)),
2194 PINCTRL_CONF_DESC(29, REG_GPIO_L_E4, BIT(16)),
2195 PINCTRL_CONF_DESC(30, REG_GPIO_L_E4, BIT(17)),
2196 PINCTRL_CONF_DESC(31, REG_GPIO_L_E4, BIT(18)),
2197 PINCTRL_CONF_DESC(32, REG_GPIO_L_E4, BIT(18)),
2198 PINCTRL_CONF_DESC(33, REG_GPIO_L_E4, BIT(20)),
2199 PINCTRL_CONF_DESC(34, REG_GPIO_L_E4, BIT(21)),
2200 PINCTRL_CONF_DESC(35, REG_GPIO_L_E4, BIT(22)),
2201 PINCTRL_CONF_DESC(36, REG_GPIO_L_E4, BIT(23)),
2202 PINCTRL_CONF_DESC(37, REG_GPIO_L_E4, BIT(24)),
2203 PINCTRL_CONF_DESC(38, REG_GPIO_L_E4, BIT(25)),
2204 PINCTRL_CONF_DESC(39, REG_GPIO_L_E4, BIT(26)),
2205 PINCTRL_CONF_DESC(40, REG_GPIO_L_E4, BIT(27)),
2206 PINCTRL_CONF_DESC(41, REG_GPIO_L_E4, BIT(28)),
2207 PINCTRL_CONF_DESC(42, REG_GPIO_L_E4, BIT(29)),
2208 PINCTRL_CONF_DESC(43, REG_GPIO_L_E4, BIT(30)),
2209 PINCTRL_CONF_DESC(44, REG_GPIO_L_E4, BIT(31)),
2210 PINCTRL_CONF_DESC(45, REG_GPIO_H_E4, BIT(0)),
2211 PINCTRL_CONF_DESC(46, REG_GPIO_H_E4, BIT(1)),
2212 PINCTRL_CONF_DESC(47, REG_GPIO_H_E4, BIT(2)),
2213 PINCTRL_CONF_DESC(48, REG_GPIO_H_E4, BIT(3)),
2214 PINCTRL_CONF_DESC(49, REG_GPIO_H_E4, BIT(4)),
2215 PINCTRL_CONF_DESC(50, REG_GPIO_H_E4, BIT(5)),
2216 PINCTRL_CONF_DESC(51, REG_GPIO_H_E4, BIT(6)),
2217 PINCTRL_CONF_DESC(52, REG_GPIO_H_E4, BIT(7)),
2218 PINCTRL_CONF_DESC(53, REG_GPIO_H_E4, BIT(8)),
2219 PINCTRL_CONF_DESC(54, REG_GPIO_H_E4, BIT(9)),
2220 PINCTRL_CONF_DESC(55, REG_GPIO_H_E4, BIT(10)),
2221 PINCTRL_CONF_DESC(56, REG_GPIO_H_E4, BIT(11)),
2222 PINCTRL_CONF_DESC(57, REG_GPIO_H_E4, BIT(12)),
2223 PINCTRL_CONF_DESC(58, REG_GPIO_H_E4, BIT(13)),
2224 PINCTRL_CONF_DESC(59, REG_GPIO_H_E4, BIT(14)),
2225 PINCTRL_CONF_DESC(61, REG_I2C_SDA_E4, PCIE0_RESET_E4_MASK),
2226 PINCTRL_CONF_DESC(62, REG_I2C_SDA_E4, PCIE1_RESET_E4_MASK),
2227 PINCTRL_CONF_DESC(63, REG_I2C_SDA_E4, PCIE2_RESET_E4_MASK),
2228 };
2229
2230 static const struct airoha_pinctrl_conf airoha_pinctrl_pcie_rst_od_conf[] = {
2231 PINCTRL_CONF_DESC(61, REG_PCIE_RESET_OD, PCIE0_RESET_OD_MASK),
2232 PINCTRL_CONF_DESC(62, REG_PCIE_RESET_OD, PCIE1_RESET_OD_MASK),
2233 PINCTRL_CONF_DESC(63, REG_PCIE_RESET_OD, PCIE2_RESET_OD_MASK),
2234 };
2235
airoha_convert_pin_to_reg_offset(struct pinctrl_dev * pctrl_dev,struct pinctrl_gpio_range * range,int pin)2236 static int airoha_convert_pin_to_reg_offset(struct pinctrl_dev *pctrl_dev,
2237 struct pinctrl_gpio_range *range,
2238 int pin)
2239 {
2240 if (!range)
2241 range = pinctrl_find_gpio_range_from_pin_nolock(pctrl_dev,
2242 pin);
2243 if (!range)
2244 return -EINVAL;
2245
2246 return pin - range->pin_base;
2247 }
2248
2249 /* gpio callbacks */
airoha_gpio_set(struct gpio_chip * chip,unsigned int gpio,int value)2250 static int airoha_gpio_set(struct gpio_chip *chip, unsigned int gpio,
2251 int value)
2252 {
2253 struct airoha_pinctrl *pinctrl = gpiochip_get_data(chip);
2254 u32 offset = gpio % AIROHA_PIN_BANK_SIZE;
2255 u8 index = gpio / AIROHA_PIN_BANK_SIZE;
2256
2257 return regmap_update_bits(pinctrl->regmap,
2258 pinctrl->gpiochip.data[index],
2259 BIT(offset), value ? BIT(offset) : 0);
2260 }
2261
airoha_gpio_get(struct gpio_chip * chip,unsigned int gpio)2262 static int airoha_gpio_get(struct gpio_chip *chip, unsigned int gpio)
2263 {
2264 struct airoha_pinctrl *pinctrl = gpiochip_get_data(chip);
2265 u32 val, pin = gpio % AIROHA_PIN_BANK_SIZE;
2266 u8 index = gpio / AIROHA_PIN_BANK_SIZE;
2267 int err;
2268
2269 err = regmap_read(pinctrl->regmap,
2270 pinctrl->gpiochip.data[index], &val);
2271
2272 return err ? err : !!(val & BIT(pin));
2273 }
2274
airoha_gpio_direction_output(struct gpio_chip * chip,unsigned int gpio,int value)2275 static int airoha_gpio_direction_output(struct gpio_chip *chip,
2276 unsigned int gpio, int value)
2277 {
2278 int err;
2279
2280 err = pinctrl_gpio_direction_output(chip, gpio);
2281 if (err)
2282 return err;
2283
2284 return airoha_gpio_set(chip, gpio, value);
2285 }
2286
2287 /* irq callbacks */
airoha_irq_unmask(struct irq_data * data)2288 static void airoha_irq_unmask(struct irq_data *data)
2289 {
2290 u8 offset = data->hwirq % AIROHA_REG_GPIOCTRL_NUM_PIN;
2291 u8 index = data->hwirq / AIROHA_REG_GPIOCTRL_NUM_PIN;
2292 u32 mask = GENMASK(2 * offset + 1, 2 * offset);
2293 struct airoha_pinctrl_gpiochip *gpiochip;
2294 struct airoha_pinctrl *pinctrl;
2295 u32 val = BIT(2 * offset);
2296
2297 gpiochip = irq_data_get_irq_chip_data(data);
2298 if (WARN_ON_ONCE(data->hwirq >= ARRAY_SIZE(gpiochip->irq_type)))
2299 return;
2300
2301 pinctrl = container_of(gpiochip, struct airoha_pinctrl, gpiochip);
2302 switch (gpiochip->irq_type[data->hwirq]) {
2303 case IRQ_TYPE_LEVEL_LOW:
2304 val = val << 1;
2305 fallthrough;
2306 case IRQ_TYPE_LEVEL_HIGH:
2307 regmap_update_bits(pinctrl->regmap, gpiochip->level[index],
2308 mask, val);
2309 break;
2310 case IRQ_TYPE_EDGE_FALLING:
2311 val = val << 1;
2312 fallthrough;
2313 case IRQ_TYPE_EDGE_RISING:
2314 regmap_update_bits(pinctrl->regmap, gpiochip->edge[index],
2315 mask, val);
2316 break;
2317 case IRQ_TYPE_EDGE_BOTH:
2318 regmap_set_bits(pinctrl->regmap, gpiochip->edge[index], mask);
2319 break;
2320 default:
2321 break;
2322 }
2323 }
2324
airoha_irq_mask(struct irq_data * data)2325 static void airoha_irq_mask(struct irq_data *data)
2326 {
2327 u8 offset = data->hwirq % AIROHA_REG_GPIOCTRL_NUM_PIN;
2328 u8 index = data->hwirq / AIROHA_REG_GPIOCTRL_NUM_PIN;
2329 u32 mask = GENMASK(2 * offset + 1, 2 * offset);
2330 struct airoha_pinctrl_gpiochip *gpiochip;
2331 struct airoha_pinctrl *pinctrl;
2332
2333 gpiochip = irq_data_get_irq_chip_data(data);
2334 pinctrl = container_of(gpiochip, struct airoha_pinctrl, gpiochip);
2335
2336 regmap_clear_bits(pinctrl->regmap, gpiochip->level[index], mask);
2337 regmap_clear_bits(pinctrl->regmap, gpiochip->edge[index], mask);
2338 }
2339
airoha_irq_type(struct irq_data * data,unsigned int type)2340 static int airoha_irq_type(struct irq_data *data, unsigned int type)
2341 {
2342 struct airoha_pinctrl_gpiochip *gpiochip;
2343
2344 gpiochip = irq_data_get_irq_chip_data(data);
2345 if (data->hwirq >= ARRAY_SIZE(gpiochip->irq_type))
2346 return -EINVAL;
2347
2348 if (type == IRQ_TYPE_PROBE) {
2349 if (gpiochip->irq_type[data->hwirq])
2350 return 0;
2351
2352 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
2353 }
2354 gpiochip->irq_type[data->hwirq] = type & IRQ_TYPE_SENSE_MASK;
2355
2356 return 0;
2357 }
2358
airoha_irq_handler(int irq,void * data)2359 static irqreturn_t airoha_irq_handler(int irq, void *data)
2360 {
2361 struct airoha_pinctrl *pinctrl = data;
2362 bool handled = false;
2363 int i;
2364
2365 for (i = 0; i < ARRAY_SIZE(irq_status_regs); i++) {
2366 struct gpio_irq_chip *girq = &pinctrl->gpiochip.chip.irq;
2367 u32 regmap;
2368 unsigned long status;
2369 int irq;
2370
2371 if (regmap_read(pinctrl->regmap, pinctrl->gpiochip.status[i],
2372 ®map))
2373 continue;
2374
2375 status = regmap;
2376 for_each_set_bit(irq, &status, AIROHA_PIN_BANK_SIZE) {
2377 u32 offset = irq + i * AIROHA_PIN_BANK_SIZE;
2378
2379 generic_handle_irq(irq_find_mapping(girq->domain,
2380 offset));
2381 regmap_write(pinctrl->regmap,
2382 pinctrl->gpiochip.status[i], BIT(irq));
2383 }
2384 handled |= !!status;
2385 }
2386
2387 return handled ? IRQ_HANDLED : IRQ_NONE;
2388 }
2389
2390 static const struct irq_chip airoha_gpio_irq_chip = {
2391 .name = "airoha-gpio-irq",
2392 .irq_unmask = airoha_irq_unmask,
2393 .irq_mask = airoha_irq_mask,
2394 .irq_mask_ack = airoha_irq_mask,
2395 .irq_set_type = airoha_irq_type,
2396 .flags = IRQCHIP_SET_TYPE_MASKED | IRQCHIP_IMMUTABLE,
2397 };
2398
airoha_pinctrl_add_gpiochip(struct airoha_pinctrl * pinctrl,struct platform_device * pdev)2399 static int airoha_pinctrl_add_gpiochip(struct airoha_pinctrl *pinctrl,
2400 struct platform_device *pdev)
2401 {
2402 struct airoha_pinctrl_gpiochip *chip = &pinctrl->gpiochip;
2403 struct gpio_chip *gc = &chip->chip;
2404 struct gpio_irq_chip *girq = &gc->irq;
2405 struct device *dev = &pdev->dev;
2406 int irq, err;
2407
2408 chip->data = gpio_data_regs;
2409 chip->dir = gpio_dir_regs;
2410 chip->out = gpio_out_regs;
2411 chip->status = irq_status_regs;
2412 chip->level = irq_level_regs;
2413 chip->edge = irq_edge_regs;
2414
2415 gc->parent = dev;
2416 gc->label = dev_name(dev);
2417 gc->request = gpiochip_generic_request;
2418 gc->free = gpiochip_generic_free;
2419 gc->direction_input = pinctrl_gpio_direction_input;
2420 gc->direction_output = airoha_gpio_direction_output;
2421 gc->set_rv = airoha_gpio_set;
2422 gc->get = airoha_gpio_get;
2423 gc->base = -1;
2424 gc->ngpio = AIROHA_NUM_PINS;
2425
2426 girq->default_type = IRQ_TYPE_NONE;
2427 girq->handler = handle_simple_irq;
2428 gpio_irq_chip_set_chip(girq, &airoha_gpio_irq_chip);
2429
2430 irq = platform_get_irq(pdev, 0);
2431 if (irq < 0)
2432 return irq;
2433
2434 err = devm_request_irq(dev, irq, airoha_irq_handler, IRQF_SHARED,
2435 dev_name(dev), pinctrl);
2436 if (err) {
2437 dev_err(dev, "error requesting irq %d: %d\n", irq, err);
2438 return err;
2439 }
2440
2441 return devm_gpiochip_add_data(dev, gc, pinctrl);
2442 }
2443
2444 /* pinmux callbacks */
airoha_pinmux_set_mux(struct pinctrl_dev * pctrl_dev,unsigned int selector,unsigned int group)2445 static int airoha_pinmux_set_mux(struct pinctrl_dev *pctrl_dev,
2446 unsigned int selector,
2447 unsigned int group)
2448 {
2449 struct airoha_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
2450 const struct airoha_pinctrl_func *func;
2451 struct function_desc *desc;
2452 struct group_desc *grp;
2453 int i;
2454
2455 desc = pinmux_generic_get_function(pctrl_dev, selector);
2456 if (!desc)
2457 return -EINVAL;
2458
2459 grp = pinctrl_generic_get_group(pctrl_dev, group);
2460 if (!grp)
2461 return -EINVAL;
2462
2463 dev_dbg(pctrl_dev->dev, "enable function %s group %s\n",
2464 desc->func.name, grp->grp.name);
2465
2466 func = desc->data;
2467 for (i = 0; i < func->group_size; i++) {
2468 const struct airoha_pinctrl_func_group *group;
2469 int j;
2470
2471 group = &func->groups[i];
2472 if (strcmp(group->name, grp->grp.name))
2473 continue;
2474
2475 for (j = 0; j < group->regmap_size; j++) {
2476 switch (group->regmap[j].mux) {
2477 case AIROHA_FUNC_PWM_EXT_MUX:
2478 case AIROHA_FUNC_PWM_MUX:
2479 regmap_update_bits(pinctrl->regmap,
2480 group->regmap[j].offset,
2481 group->regmap[j].mask,
2482 group->regmap[j].val);
2483 break;
2484 default:
2485 regmap_update_bits(pinctrl->chip_scu,
2486 group->regmap[j].offset,
2487 group->regmap[j].mask,
2488 group->regmap[j].val);
2489 break;
2490 }
2491 }
2492 return 0;
2493 }
2494
2495 return -EINVAL;
2496 }
2497
airoha_pinmux_set_direction(struct pinctrl_dev * pctrl_dev,struct pinctrl_gpio_range * range,unsigned int p,bool input)2498 static int airoha_pinmux_set_direction(struct pinctrl_dev *pctrl_dev,
2499 struct pinctrl_gpio_range *range,
2500 unsigned int p, bool input)
2501 {
2502 struct airoha_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
2503 u32 mask, index;
2504 int err, pin;
2505
2506 pin = airoha_convert_pin_to_reg_offset(pctrl_dev, range, p);
2507 if (pin < 0)
2508 return pin;
2509
2510 /* set output enable */
2511 mask = BIT(pin % AIROHA_PIN_BANK_SIZE);
2512 index = pin / AIROHA_PIN_BANK_SIZE;
2513 err = regmap_update_bits(pinctrl->regmap, pinctrl->gpiochip.out[index],
2514 mask, !input ? mask : 0);
2515 if (err)
2516 return err;
2517
2518 /* set direction */
2519 mask = BIT(2 * (pin % AIROHA_REG_GPIOCTRL_NUM_PIN));
2520 index = pin / AIROHA_REG_GPIOCTRL_NUM_PIN;
2521 return regmap_update_bits(pinctrl->regmap,
2522 pinctrl->gpiochip.dir[index], mask,
2523 !input ? mask : 0);
2524 }
2525
2526 static const struct pinmux_ops airoha_pmxops = {
2527 .get_functions_count = pinmux_generic_get_function_count,
2528 .get_function_name = pinmux_generic_get_function_name,
2529 .get_function_groups = pinmux_generic_get_function_groups,
2530 .gpio_set_direction = airoha_pinmux_set_direction,
2531 .set_mux = airoha_pinmux_set_mux,
2532 .strict = true,
2533 };
2534
2535 /* pinconf callbacks */
2536 static const struct airoha_pinctrl_reg *
airoha_pinctrl_get_conf_reg(const struct airoha_pinctrl_conf * conf,int conf_size,int pin)2537 airoha_pinctrl_get_conf_reg(const struct airoha_pinctrl_conf *conf,
2538 int conf_size, int pin)
2539 {
2540 int i;
2541
2542 for (i = 0; i < conf_size; i++) {
2543 if (conf[i].pin == pin)
2544 return &conf[i].reg;
2545 }
2546
2547 return NULL;
2548 }
2549
airoha_pinctrl_get_conf(struct airoha_pinctrl * pinctrl,const struct airoha_pinctrl_conf * conf,int conf_size,int pin,u32 * val)2550 static int airoha_pinctrl_get_conf(struct airoha_pinctrl *pinctrl,
2551 const struct airoha_pinctrl_conf *conf,
2552 int conf_size, int pin, u32 *val)
2553 {
2554 const struct airoha_pinctrl_reg *reg;
2555
2556 reg = airoha_pinctrl_get_conf_reg(conf, conf_size, pin);
2557 if (!reg)
2558 return -EINVAL;
2559
2560 if (regmap_read(pinctrl->chip_scu, reg->offset, val))
2561 return -EINVAL;
2562
2563 *val = (*val & reg->mask) >> __ffs(reg->mask);
2564
2565 return 0;
2566 }
2567
airoha_pinctrl_set_conf(struct airoha_pinctrl * pinctrl,const struct airoha_pinctrl_conf * conf,int conf_size,int pin,u32 val)2568 static int airoha_pinctrl_set_conf(struct airoha_pinctrl *pinctrl,
2569 const struct airoha_pinctrl_conf *conf,
2570 int conf_size, int pin, u32 val)
2571 {
2572 const struct airoha_pinctrl_reg *reg = NULL;
2573
2574 reg = airoha_pinctrl_get_conf_reg(conf, conf_size, pin);
2575 if (!reg)
2576 return -EINVAL;
2577
2578
2579 if (regmap_update_bits(pinctrl->chip_scu, reg->offset, reg->mask,
2580 val << __ffs(reg->mask)))
2581 return -EINVAL;
2582
2583 return 0;
2584 }
2585
2586 #define airoha_pinctrl_get_pullup_conf(pinctrl, pin, val) \
2587 airoha_pinctrl_get_conf((pinctrl), airoha_pinctrl_pullup_conf, \
2588 ARRAY_SIZE(airoha_pinctrl_pullup_conf), \
2589 (pin), (val))
2590 #define airoha_pinctrl_get_pulldown_conf(pinctrl, pin, val) \
2591 airoha_pinctrl_get_conf((pinctrl), airoha_pinctrl_pulldown_conf, \
2592 ARRAY_SIZE(airoha_pinctrl_pulldown_conf), \
2593 (pin), (val))
2594 #define airoha_pinctrl_get_drive_e2_conf(pinctrl, pin, val) \
2595 airoha_pinctrl_get_conf((pinctrl), airoha_pinctrl_drive_e2_conf, \
2596 ARRAY_SIZE(airoha_pinctrl_drive_e2_conf), \
2597 (pin), (val))
2598 #define airoha_pinctrl_get_drive_e4_conf(pinctrl, pin, val) \
2599 airoha_pinctrl_get_conf((pinctrl), airoha_pinctrl_drive_e4_conf, \
2600 ARRAY_SIZE(airoha_pinctrl_drive_e4_conf), \
2601 (pin), (val))
2602 #define airoha_pinctrl_get_pcie_rst_od_conf(pinctrl, pin, val) \
2603 airoha_pinctrl_get_conf((pinctrl), airoha_pinctrl_pcie_rst_od_conf, \
2604 ARRAY_SIZE(airoha_pinctrl_pcie_rst_od_conf), \
2605 (pin), (val))
2606 #define airoha_pinctrl_set_pullup_conf(pinctrl, pin, val) \
2607 airoha_pinctrl_set_conf((pinctrl), airoha_pinctrl_pullup_conf, \
2608 ARRAY_SIZE(airoha_pinctrl_pullup_conf), \
2609 (pin), (val))
2610 #define airoha_pinctrl_set_pulldown_conf(pinctrl, pin, val) \
2611 airoha_pinctrl_set_conf((pinctrl), airoha_pinctrl_pulldown_conf, \
2612 ARRAY_SIZE(airoha_pinctrl_pulldown_conf), \
2613 (pin), (val))
2614 #define airoha_pinctrl_set_drive_e2_conf(pinctrl, pin, val) \
2615 airoha_pinctrl_set_conf((pinctrl), airoha_pinctrl_drive_e2_conf, \
2616 ARRAY_SIZE(airoha_pinctrl_drive_e2_conf), \
2617 (pin), (val))
2618 #define airoha_pinctrl_set_drive_e4_conf(pinctrl, pin, val) \
2619 airoha_pinctrl_set_conf((pinctrl), airoha_pinctrl_drive_e4_conf, \
2620 ARRAY_SIZE(airoha_pinctrl_drive_e4_conf), \
2621 (pin), (val))
2622 #define airoha_pinctrl_set_pcie_rst_od_conf(pinctrl, pin, val) \
2623 airoha_pinctrl_set_conf((pinctrl), airoha_pinctrl_pcie_rst_od_conf, \
2624 ARRAY_SIZE(airoha_pinctrl_pcie_rst_od_conf), \
2625 (pin), (val))
2626
airoha_pinconf_get_direction(struct pinctrl_dev * pctrl_dev,u32 p)2627 static int airoha_pinconf_get_direction(struct pinctrl_dev *pctrl_dev, u32 p)
2628 {
2629 struct airoha_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
2630 u32 val, mask;
2631 int err, pin;
2632 u8 index;
2633
2634 pin = airoha_convert_pin_to_reg_offset(pctrl_dev, NULL, p);
2635 if (pin < 0)
2636 return pin;
2637
2638 index = pin / AIROHA_REG_GPIOCTRL_NUM_PIN;
2639 err = regmap_read(pinctrl->regmap, pinctrl->gpiochip.dir[index], &val);
2640 if (err)
2641 return err;
2642
2643 mask = BIT(2 * (pin % AIROHA_REG_GPIOCTRL_NUM_PIN));
2644 return val & mask ? PIN_CONFIG_OUTPUT_ENABLE : PIN_CONFIG_INPUT_ENABLE;
2645 }
2646
airoha_pinconf_get(struct pinctrl_dev * pctrl_dev,unsigned int pin,unsigned long * config)2647 static int airoha_pinconf_get(struct pinctrl_dev *pctrl_dev,
2648 unsigned int pin, unsigned long *config)
2649 {
2650 struct airoha_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
2651 enum pin_config_param param = pinconf_to_config_param(*config);
2652 u32 arg;
2653
2654 switch (param) {
2655 case PIN_CONFIG_BIAS_PULL_DOWN:
2656 case PIN_CONFIG_BIAS_DISABLE:
2657 case PIN_CONFIG_BIAS_PULL_UP: {
2658 u32 pull_up, pull_down;
2659
2660 if (airoha_pinctrl_get_pullup_conf(pinctrl, pin, &pull_up) ||
2661 airoha_pinctrl_get_pulldown_conf(pinctrl, pin, &pull_down))
2662 return -EINVAL;
2663
2664 if (param == PIN_CONFIG_BIAS_PULL_UP &&
2665 !(pull_up && !pull_down))
2666 return -EINVAL;
2667 else if (param == PIN_CONFIG_BIAS_PULL_DOWN &&
2668 !(pull_down && !pull_up))
2669 return -EINVAL;
2670 else if (pull_up || pull_down)
2671 return -EINVAL;
2672
2673 arg = 1;
2674 break;
2675 }
2676 case PIN_CONFIG_DRIVE_STRENGTH: {
2677 u32 e2, e4;
2678
2679 if (airoha_pinctrl_get_drive_e2_conf(pinctrl, pin, &e2) ||
2680 airoha_pinctrl_get_drive_e4_conf(pinctrl, pin, &e4))
2681 return -EINVAL;
2682
2683 arg = e4 << 1 | e2;
2684 break;
2685 }
2686 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
2687 if (airoha_pinctrl_get_pcie_rst_od_conf(pinctrl, pin, &arg))
2688 return -EINVAL;
2689 break;
2690 case PIN_CONFIG_OUTPUT_ENABLE:
2691 case PIN_CONFIG_INPUT_ENABLE:
2692 arg = airoha_pinconf_get_direction(pctrl_dev, pin);
2693 if (arg != param)
2694 return -EINVAL;
2695
2696 arg = 1;
2697 break;
2698 default:
2699 return -EOPNOTSUPP;
2700 }
2701
2702 *config = pinconf_to_config_packed(param, arg);
2703
2704 return 0;
2705 }
2706
airoha_pinconf_set_pin_value(struct pinctrl_dev * pctrl_dev,unsigned int p,bool value)2707 static int airoha_pinconf_set_pin_value(struct pinctrl_dev *pctrl_dev,
2708 unsigned int p, bool value)
2709 {
2710 struct airoha_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
2711 int pin;
2712
2713 pin = airoha_convert_pin_to_reg_offset(pctrl_dev, NULL, p);
2714 if (pin < 0)
2715 return pin;
2716
2717 return airoha_gpio_set(&pinctrl->gpiochip.chip, pin, value);
2718 }
2719
airoha_pinconf_set(struct pinctrl_dev * pctrl_dev,unsigned int pin,unsigned long * configs,unsigned int num_configs)2720 static int airoha_pinconf_set(struct pinctrl_dev *pctrl_dev,
2721 unsigned int pin, unsigned long *configs,
2722 unsigned int num_configs)
2723 {
2724 struct airoha_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
2725 int i;
2726
2727 for (i = 0; i < num_configs; i++) {
2728 u32 param = pinconf_to_config_param(configs[i]);
2729 u32 arg = pinconf_to_config_argument(configs[i]);
2730
2731 switch (param) {
2732 case PIN_CONFIG_BIAS_DISABLE:
2733 airoha_pinctrl_set_pulldown_conf(pinctrl, pin, 0);
2734 airoha_pinctrl_set_pullup_conf(pinctrl, pin, 0);
2735 break;
2736 case PIN_CONFIG_BIAS_PULL_UP:
2737 airoha_pinctrl_set_pulldown_conf(pinctrl, pin, 0);
2738 airoha_pinctrl_set_pullup_conf(pinctrl, pin, 1);
2739 break;
2740 case PIN_CONFIG_BIAS_PULL_DOWN:
2741 airoha_pinctrl_set_pulldown_conf(pinctrl, pin, 1);
2742 airoha_pinctrl_set_pullup_conf(pinctrl, pin, 0);
2743 break;
2744 case PIN_CONFIG_DRIVE_STRENGTH: {
2745 u32 e2 = 0, e4 = 0;
2746
2747 switch (arg) {
2748 case MTK_DRIVE_2mA:
2749 break;
2750 case MTK_DRIVE_4mA:
2751 e2 = 1;
2752 break;
2753 case MTK_DRIVE_6mA:
2754 e4 = 1;
2755 break;
2756 case MTK_DRIVE_8mA:
2757 e2 = 1;
2758 e4 = 1;
2759 break;
2760 default:
2761 return -EINVAL;
2762 }
2763
2764 airoha_pinctrl_set_drive_e2_conf(pinctrl, pin, e2);
2765 airoha_pinctrl_set_drive_e4_conf(pinctrl, pin, e4);
2766 break;
2767 }
2768 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
2769 airoha_pinctrl_set_pcie_rst_od_conf(pinctrl, pin, !!arg);
2770 break;
2771 case PIN_CONFIG_OUTPUT_ENABLE:
2772 case PIN_CONFIG_INPUT_ENABLE:
2773 case PIN_CONFIG_OUTPUT: {
2774 bool input = param == PIN_CONFIG_INPUT_ENABLE;
2775 int err;
2776
2777 err = airoha_pinmux_set_direction(pctrl_dev, NULL, pin,
2778 input);
2779 if (err)
2780 return err;
2781
2782 if (param == PIN_CONFIG_OUTPUT) {
2783 err = airoha_pinconf_set_pin_value(pctrl_dev,
2784 pin, !!arg);
2785 if (err)
2786 return err;
2787 }
2788 break;
2789 }
2790 default:
2791 return -EOPNOTSUPP;
2792 }
2793 }
2794
2795 return 0;
2796 }
2797
airoha_pinconf_group_get(struct pinctrl_dev * pctrl_dev,unsigned int group,unsigned long * config)2798 static int airoha_pinconf_group_get(struct pinctrl_dev *pctrl_dev,
2799 unsigned int group, unsigned long *config)
2800 {
2801 u32 cur_config = 0;
2802 int i;
2803
2804 for (i = 0; i < airoha_pinctrl_groups[group].npins; i++) {
2805 if (airoha_pinconf_get(pctrl_dev,
2806 airoha_pinctrl_groups[group].pins[i],
2807 config))
2808 return -EOPNOTSUPP;
2809
2810 if (i && cur_config != *config)
2811 return -EOPNOTSUPP;
2812
2813 cur_config = *config;
2814 }
2815
2816 return 0;
2817 }
2818
airoha_pinconf_group_set(struct pinctrl_dev * pctrl_dev,unsigned int group,unsigned long * configs,unsigned int num_configs)2819 static int airoha_pinconf_group_set(struct pinctrl_dev *pctrl_dev,
2820 unsigned int group, unsigned long *configs,
2821 unsigned int num_configs)
2822 {
2823 int i;
2824
2825 for (i = 0; i < airoha_pinctrl_groups[group].npins; i++) {
2826 int err;
2827
2828 err = airoha_pinconf_set(pctrl_dev,
2829 airoha_pinctrl_groups[group].pins[i],
2830 configs, num_configs);
2831 if (err)
2832 return err;
2833 }
2834
2835 return 0;
2836 }
2837
2838 static const struct pinconf_ops airoha_confops = {
2839 .is_generic = true,
2840 .pin_config_get = airoha_pinconf_get,
2841 .pin_config_set = airoha_pinconf_set,
2842 .pin_config_group_get = airoha_pinconf_group_get,
2843 .pin_config_group_set = airoha_pinconf_group_set,
2844 .pin_config_config_dbg_show = pinconf_generic_dump_config,
2845 };
2846
2847 static const struct pinctrl_ops airoha_pctlops = {
2848 .get_groups_count = pinctrl_generic_get_group_count,
2849 .get_group_name = pinctrl_generic_get_group_name,
2850 .get_group_pins = pinctrl_generic_get_group_pins,
2851 .dt_node_to_map = pinconf_generic_dt_node_to_map_all,
2852 .dt_free_map = pinconf_generic_dt_free_map,
2853 };
2854
2855 static struct pinctrl_desc airoha_pinctrl_desc = {
2856 .name = KBUILD_MODNAME,
2857 .owner = THIS_MODULE,
2858 .pctlops = &airoha_pctlops,
2859 .pmxops = &airoha_pmxops,
2860 .confops = &airoha_confops,
2861 .pins = airoha_pinctrl_pins,
2862 .npins = ARRAY_SIZE(airoha_pinctrl_pins),
2863 };
2864
airoha_pinctrl_probe(struct platform_device * pdev)2865 static int airoha_pinctrl_probe(struct platform_device *pdev)
2866 {
2867 struct device *dev = &pdev->dev;
2868 struct airoha_pinctrl *pinctrl;
2869 struct regmap *map;
2870 int err, i;
2871
2872 pinctrl = devm_kzalloc(dev, sizeof(*pinctrl), GFP_KERNEL);
2873 if (!pinctrl)
2874 return -ENOMEM;
2875
2876 pinctrl->regmap = device_node_to_regmap(dev->parent->of_node);
2877 if (IS_ERR(pinctrl->regmap))
2878 return PTR_ERR(pinctrl->regmap);
2879
2880 map = syscon_regmap_lookup_by_compatible("airoha,en7581-chip-scu");
2881 if (IS_ERR(map))
2882 return PTR_ERR(map);
2883
2884 pinctrl->chip_scu = map;
2885
2886 err = devm_pinctrl_register_and_init(dev, &airoha_pinctrl_desc,
2887 pinctrl, &pinctrl->ctrl);
2888 if (err)
2889 return err;
2890
2891 /* build pin groups */
2892 for (i = 0; i < ARRAY_SIZE(airoha_pinctrl_groups); i++) {
2893 const struct pingroup *grp = &airoha_pinctrl_groups[i];
2894
2895 err = pinctrl_generic_add_group(pinctrl->ctrl, grp->name,
2896 grp->pins, grp->npins,
2897 (void *)grp);
2898 if (err < 0) {
2899 dev_err(&pdev->dev, "Failed to register group %s\n",
2900 grp->name);
2901 return err;
2902 }
2903 }
2904
2905 /* build functions */
2906 for (i = 0; i < ARRAY_SIZE(airoha_pinctrl_funcs); i++) {
2907 const struct airoha_pinctrl_func *func;
2908
2909 func = &airoha_pinctrl_funcs[i];
2910 err = pinmux_generic_add_function(pinctrl->ctrl,
2911 func->desc.func.name,
2912 func->desc.func.groups,
2913 func->desc.func.ngroups,
2914 (void *)func);
2915 if (err < 0) {
2916 dev_err(dev, "Failed to register function %s\n",
2917 func->desc.func.name);
2918 return err;
2919 }
2920 }
2921
2922 err = pinctrl_enable(pinctrl->ctrl);
2923 if (err)
2924 return err;
2925
2926 /* build gpio-chip */
2927 return airoha_pinctrl_add_gpiochip(pinctrl, pdev);
2928 }
2929
2930 static const struct of_device_id airoha_pinctrl_of_match[] = {
2931 { .compatible = "airoha,en7581-pinctrl" },
2932 { /* sentinel */ }
2933 };
2934 MODULE_DEVICE_TABLE(of, airoha_pinctrl_of_match);
2935
2936 static struct platform_driver airoha_pinctrl_driver = {
2937 .probe = airoha_pinctrl_probe,
2938 .driver = {
2939 .name = "pinctrl-airoha",
2940 .of_match_table = airoha_pinctrl_of_match,
2941 },
2942 };
2943 module_platform_driver(airoha_pinctrl_driver);
2944
2945 MODULE_LICENSE("GPL");
2946 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo@kernel.org>");
2947 MODULE_AUTHOR("Benjamin Larsson <benjamin.larsson@genexis.eu>");
2948 MODULE_AUTHOR("Markus Gothe <markus.gothe@genexis.eu>");
2949 MODULE_DESCRIPTION("Pinctrl driver for Airoha SoC");
2950