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