1 From 457d9772e8a5cdae64f66b5f7d5b0247365191ec Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Tue, 1 Apr 2025 15:50:21 +0200
4 Subject: [PATCH] pinctrl: airoha: fix wrong PHY LED mapping and PHY2 LED
7 The current PHY2 LED define are wrong and actually set BITs outside the
8 related mask. Fix it and set the correct value. While at it, also use
9 FIELD_PREP_CONST macro to make it simple to understand what values are
10 actually applied for the mask.
12 Also fix wrong PHY LED mapping. The SoC Switch supports up to 4 port but
13 the register define mapping for 5 PHY port, starting from 0. The mapping
14 was wrongly defined starting from PHY1. Reorder the function group to
15 start from PHY0. PHY4 is actually never supported as we don't have a
18 Cc: stable@vger.kernel.org
19 Fixes: 1c8ace2d0725 ("pinctrl: airoha: Add support for EN7581 SoC")
20 Reviewed-by: Benjamin Larsson <benjamin.larsson@genexis.eu>
21 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
22 Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
23 Link: https://lore.kernel.org/20250401135026.18018-1-ansuelsmth@gmail.com
24 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
26 drivers/pinctrl/mediatek/pinctrl-airoha.c | 159 ++++++++++------------
27 1 file changed, 70 insertions(+), 89 deletions(-)
29 --- a/drivers/pinctrl/mediatek/pinctrl-airoha.c
30 +++ b/drivers/pinctrl/mediatek/pinctrl-airoha.c
34 #include <dt-bindings/pinctrl/mt65xx.h>
35 +#include <linux/bitfield.h>
36 #include <linux/bits.h>
37 #include <linux/cleanup.h>
38 #include <linux/gpio/driver.h>
40 #define REG_LAN_LED1_MAPPING 0x0280
42 #define LAN4_LED_MAPPING_MASK GENMASK(18, 16)
43 -#define LAN4_PHY4_LED_MAP BIT(18)
44 -#define LAN4_PHY2_LED_MAP BIT(17)
45 -#define LAN4_PHY1_LED_MAP BIT(16)
46 -#define LAN4_PHY0_LED_MAP 0
47 -#define LAN4_PHY3_LED_MAP GENMASK(17, 16)
48 +#define LAN4_PHY_LED_MAP(_n) FIELD_PREP_CONST(LAN4_LED_MAPPING_MASK, (_n))
50 #define LAN3_LED_MAPPING_MASK GENMASK(14, 12)
51 -#define LAN3_PHY4_LED_MAP BIT(14)
52 -#define LAN3_PHY2_LED_MAP BIT(13)
53 -#define LAN3_PHY1_LED_MAP BIT(12)
54 -#define LAN3_PHY0_LED_MAP 0
55 -#define LAN3_PHY3_LED_MAP GENMASK(13, 12)
56 +#define LAN3_PHY_LED_MAP(_n) FIELD_PREP_CONST(LAN3_LED_MAPPING_MASK, (_n))
58 #define LAN2_LED_MAPPING_MASK GENMASK(10, 8)
59 -#define LAN2_PHY4_LED_MAP BIT(12)
60 -#define LAN2_PHY2_LED_MAP BIT(11)
61 -#define LAN2_PHY1_LED_MAP BIT(10)
62 -#define LAN2_PHY0_LED_MAP 0
63 -#define LAN2_PHY3_LED_MAP GENMASK(11, 10)
64 +#define LAN2_PHY_LED_MAP(_n) FIELD_PREP_CONST(LAN2_LED_MAPPING_MASK, (_n))
66 #define LAN1_LED_MAPPING_MASK GENMASK(6, 4)
67 -#define LAN1_PHY4_LED_MAP BIT(6)
68 -#define LAN1_PHY2_LED_MAP BIT(5)
69 -#define LAN1_PHY1_LED_MAP BIT(4)
70 -#define LAN1_PHY0_LED_MAP 0
71 -#define LAN1_PHY3_LED_MAP GENMASK(5, 4)
72 +#define LAN1_PHY_LED_MAP(_n) FIELD_PREP_CONST(LAN1_LED_MAPPING_MASK, (_n))
74 #define LAN0_LED_MAPPING_MASK GENMASK(2, 0)
75 -#define LAN0_PHY4_LED_MAP BIT(3)
76 -#define LAN0_PHY2_LED_MAP BIT(2)
77 -#define LAN0_PHY1_LED_MAP BIT(1)
78 -#define LAN0_PHY0_LED_MAP 0
79 -#define LAN0_PHY3_LED_MAP GENMASK(2, 1)
80 +#define LAN0_PHY_LED_MAP(_n) FIELD_PREP_CONST(LAN0_LED_MAPPING_MASK, (_n))
83 #define REG_I2C_SDA_E2 0x001c
84 @@ -1470,8 +1451,8 @@ static const struct airoha_pinctrl_func_
88 - LAN1_LED_MAPPING_MASK,
90 + LAN0_LED_MAPPING_MASK,
95 @@ -1485,8 +1466,8 @@ static const struct airoha_pinctrl_func_
99 - LAN2_LED_MAPPING_MASK,
101 + LAN1_LED_MAPPING_MASK,
102 + LAN1_PHY_LED_MAP(0)
106 @@ -1500,8 +1481,8 @@ static const struct airoha_pinctrl_func_
109 REG_LAN_LED0_MAPPING,
110 - LAN3_LED_MAPPING_MASK,
112 + LAN2_LED_MAPPING_MASK,
113 + LAN2_PHY_LED_MAP(0)
117 @@ -1515,8 +1496,8 @@ static const struct airoha_pinctrl_func_
120 REG_LAN_LED0_MAPPING,
121 - LAN4_LED_MAPPING_MASK,
123 + LAN3_LED_MAPPING_MASK,
124 + LAN3_PHY_LED_MAP(0)
128 @@ -1534,8 +1515,8 @@ static const struct airoha_pinctrl_func_
131 REG_LAN_LED0_MAPPING,
132 - LAN1_LED_MAPPING_MASK,
134 + LAN0_LED_MAPPING_MASK,
135 + LAN0_PHY_LED_MAP(1)
139 @@ -1549,8 +1530,8 @@ static const struct airoha_pinctrl_func_
142 REG_LAN_LED0_MAPPING,
143 - LAN2_LED_MAPPING_MASK,
145 + LAN1_LED_MAPPING_MASK,
146 + LAN1_PHY_LED_MAP(1)
150 @@ -1564,8 +1545,8 @@ static const struct airoha_pinctrl_func_
153 REG_LAN_LED0_MAPPING,
154 - LAN3_LED_MAPPING_MASK,
156 + LAN2_LED_MAPPING_MASK,
157 + LAN2_PHY_LED_MAP(1)
161 @@ -1579,8 +1560,8 @@ static const struct airoha_pinctrl_func_
164 REG_LAN_LED0_MAPPING,
165 - LAN4_LED_MAPPING_MASK,
167 + LAN3_LED_MAPPING_MASK,
168 + LAN3_PHY_LED_MAP(1)
172 @@ -1598,8 +1579,8 @@ static const struct airoha_pinctrl_func_
175 REG_LAN_LED0_MAPPING,
176 - LAN1_LED_MAPPING_MASK,
178 + LAN0_LED_MAPPING_MASK,
179 + LAN0_PHY_LED_MAP(2)
183 @@ -1613,8 +1594,8 @@ static const struct airoha_pinctrl_func_
186 REG_LAN_LED0_MAPPING,
187 - LAN2_LED_MAPPING_MASK,
189 + LAN1_LED_MAPPING_MASK,
190 + LAN1_PHY_LED_MAP(2)
194 @@ -1628,8 +1609,8 @@ static const struct airoha_pinctrl_func_
197 REG_LAN_LED0_MAPPING,
198 - LAN3_LED_MAPPING_MASK,
200 + LAN2_LED_MAPPING_MASK,
201 + LAN2_PHY_LED_MAP(2)
205 @@ -1643,8 +1624,8 @@ static const struct airoha_pinctrl_func_
208 REG_LAN_LED0_MAPPING,
209 - LAN4_LED_MAPPING_MASK,
211 + LAN3_LED_MAPPING_MASK,
212 + LAN3_PHY_LED_MAP(2)
216 @@ -1662,8 +1643,8 @@ static const struct airoha_pinctrl_func_
219 REG_LAN_LED0_MAPPING,
220 - LAN1_LED_MAPPING_MASK,
222 + LAN0_LED_MAPPING_MASK,
223 + LAN0_PHY_LED_MAP(3)
227 @@ -1677,8 +1658,8 @@ static const struct airoha_pinctrl_func_
230 REG_LAN_LED0_MAPPING,
231 - LAN2_LED_MAPPING_MASK,
233 + LAN1_LED_MAPPING_MASK,
234 + LAN1_PHY_LED_MAP(3)
238 @@ -1692,8 +1673,8 @@ static const struct airoha_pinctrl_func_
241 REG_LAN_LED0_MAPPING,
242 - LAN3_LED_MAPPING_MASK,
244 + LAN2_LED_MAPPING_MASK,
245 + LAN2_PHY_LED_MAP(3)
249 @@ -1707,8 +1688,8 @@ static const struct airoha_pinctrl_func_
252 REG_LAN_LED0_MAPPING,
253 - LAN4_LED_MAPPING_MASK,
255 + LAN3_LED_MAPPING_MASK,
256 + LAN3_PHY_LED_MAP(3)
260 @@ -1726,8 +1707,8 @@ static const struct airoha_pinctrl_func_
263 REG_LAN_LED1_MAPPING,
264 - LAN1_LED_MAPPING_MASK,
266 + LAN0_LED_MAPPING_MASK,
267 + LAN0_PHY_LED_MAP(0)
271 @@ -1741,8 +1722,8 @@ static const struct airoha_pinctrl_func_
274 REG_LAN_LED1_MAPPING,
275 - LAN2_LED_MAPPING_MASK,
277 + LAN1_LED_MAPPING_MASK,
278 + LAN1_PHY_LED_MAP(0)
282 @@ -1756,8 +1737,8 @@ static const struct airoha_pinctrl_func_
285 REG_LAN_LED1_MAPPING,
286 - LAN3_LED_MAPPING_MASK,
288 + LAN2_LED_MAPPING_MASK,
289 + LAN2_PHY_LED_MAP(0)
293 @@ -1771,8 +1752,8 @@ static const struct airoha_pinctrl_func_
296 REG_LAN_LED1_MAPPING,
297 - LAN4_LED_MAPPING_MASK,
299 + LAN3_LED_MAPPING_MASK,
300 + LAN3_PHY_LED_MAP(0)
304 @@ -1790,8 +1771,8 @@ static const struct airoha_pinctrl_func_
307 REG_LAN_LED1_MAPPING,
308 - LAN1_LED_MAPPING_MASK,
310 + LAN0_LED_MAPPING_MASK,
311 + LAN0_PHY_LED_MAP(1)
315 @@ -1805,8 +1786,8 @@ static const struct airoha_pinctrl_func_
318 REG_LAN_LED1_MAPPING,
319 - LAN2_LED_MAPPING_MASK,
321 + LAN1_LED_MAPPING_MASK,
322 + LAN1_PHY_LED_MAP(1)
326 @@ -1820,8 +1801,8 @@ static const struct airoha_pinctrl_func_
329 REG_LAN_LED1_MAPPING,
330 - LAN3_LED_MAPPING_MASK,
332 + LAN2_LED_MAPPING_MASK,
333 + LAN2_PHY_LED_MAP(1)
337 @@ -1835,8 +1816,8 @@ static const struct airoha_pinctrl_func_
340 REG_LAN_LED1_MAPPING,
341 - LAN4_LED_MAPPING_MASK,
343 + LAN3_LED_MAPPING_MASK,
344 + LAN3_PHY_LED_MAP(1)
348 @@ -1854,8 +1835,8 @@ static const struct airoha_pinctrl_func_
351 REG_LAN_LED1_MAPPING,
352 - LAN1_LED_MAPPING_MASK,
354 + LAN0_LED_MAPPING_MASK,
355 + LAN0_PHY_LED_MAP(2)
359 @@ -1869,8 +1850,8 @@ static const struct airoha_pinctrl_func_
362 REG_LAN_LED1_MAPPING,
363 - LAN2_LED_MAPPING_MASK,
365 + LAN1_LED_MAPPING_MASK,
366 + LAN1_PHY_LED_MAP(2)
370 @@ -1884,8 +1865,8 @@ static const struct airoha_pinctrl_func_
373 REG_LAN_LED1_MAPPING,
374 - LAN3_LED_MAPPING_MASK,
376 + LAN2_LED_MAPPING_MASK,
377 + LAN2_PHY_LED_MAP(2)
381 @@ -1899,8 +1880,8 @@ static const struct airoha_pinctrl_func_
384 REG_LAN_LED1_MAPPING,
385 - LAN4_LED_MAPPING_MASK,
387 + LAN3_LED_MAPPING_MASK,
388 + LAN3_PHY_LED_MAP(2)
392 @@ -1918,8 +1899,8 @@ static const struct airoha_pinctrl_func_
395 REG_LAN_LED1_MAPPING,
396 - LAN1_LED_MAPPING_MASK,
398 + LAN0_LED_MAPPING_MASK,
399 + LAN0_PHY_LED_MAP(3)
403 @@ -1933,8 +1914,8 @@ static const struct airoha_pinctrl_func_
406 REG_LAN_LED1_MAPPING,
407 - LAN2_LED_MAPPING_MASK,
409 + LAN1_LED_MAPPING_MASK,
410 + LAN1_PHY_LED_MAP(3)
414 @@ -1948,8 +1929,8 @@ static const struct airoha_pinctrl_func_
417 REG_LAN_LED1_MAPPING,
418 - LAN3_LED_MAPPING_MASK,
420 + LAN2_LED_MAPPING_MASK,
421 + LAN2_PHY_LED_MAP(3)
425 @@ -1963,8 +1944,8 @@ static const struct airoha_pinctrl_func_
428 REG_LAN_LED1_MAPPING,
429 - LAN4_LED_MAPPING_MASK,
431 + LAN3_LED_MAPPING_MASK,
432 + LAN3_PHY_LED_MAP(3)