x86: refresh kernel patches
[openwrt.git] / target / linux / ramips / patches-3.14 / 0030-pinctrl-ralink-add-pinctrl-driver.patch
1 From 675c6ddd9432c39f508f9d6bdda17d9c675788cf Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sun, 27 Jul 2014 09:34:05 +0100
4 Subject: [PATCH 30/57] pinctrl: ralink: add pinctrl driver
5
6 Signed-off-by: John Crispin <blogic@openwrt.org>
7 ---
8  arch/mips/Kconfig                          |    2 +
9  arch/mips/include/asm/mach-ralink/mt7620.h |   41 ++-
10  arch/mips/include/asm/mach-ralink/pinmux.h |   53 ++++
11  arch/mips/include/asm/mach-ralink/rt305x.h |   35 ++-
12  arch/mips/include/asm/mach-ralink/rt3883.h |   16 +-
13  arch/mips/ralink/common.h                  |   19 --
14  arch/mips/ralink/mt7620.c                  |  159 +++-------
15  arch/mips/ralink/rt288x.c                  |   62 ++--
16  arch/mips/ralink/rt305x.c                  |  151 ++++-----
17  arch/mips/ralink/rt3883.c                  |  173 +++--------
18  drivers/pinctrl/Kconfig                    |    5 +
19  drivers/pinctrl/Makefile                   |    1 +
20  drivers/pinctrl/pinctrl-rt2880.c           |  467 ++++++++++++++++++++++++++++
21  13 files changed, 764 insertions(+), 420 deletions(-)
22  create mode 100644 arch/mips/include/asm/mach-ralink/pinmux.h
23  create mode 100644 drivers/pinctrl/pinctrl-rt2880.c
24
25 --- a/arch/mips/Kconfig
26 +++ b/arch/mips/Kconfig
27 @@ -436,6 +436,8 @@ config RALINK
28         select CLKDEV_LOOKUP
29         select ARCH_HAS_RESET_CONTROLLER
30         select RESET_CONTROLLER
31 +       select PINCTRL
32 +       select PINCTRL_RT2880
33  
34  config SGI_IP22
35         bool "SGI IP22 (Indy/Indigo2)"
36 --- a/arch/mips/include/asm/mach-ralink/mt7620.h
37 +++ b/arch/mips/include/asm/mach-ralink/mt7620.h
38 @@ -90,7 +90,6 @@ enum mt762x_soc_type {
39  #define MT7620_DDR2_SIZE_MIN           32
40  #define MT7620_DDR2_SIZE_MAX           256
41  
42 -#define MT7620_GPIO_MODE_I2C           BIT(0)
43  #define MT7620_GPIO_MODE_UART0_SHIFT   2
44  #define MT7620_GPIO_MODE_UART0_MASK    0x7
45  #define MT7620_GPIO_MODE_UART0(x)      ((x) << MT7620_GPIO_MODE_UART0_SHIFT)
46 @@ -102,16 +101,36 @@ enum mt762x_soc_type {
47  #define MT7620_GPIO_MODE_GPIO_UARTF    0x5
48  #define MT7620_GPIO_MODE_GPIO_I2S      0x6
49  #define MT7620_GPIO_MODE_GPIO          0x7
50 -#define MT7620_GPIO_MODE_UART1         BIT(5)
51 -#define MT7620_GPIO_MODE_MDIO          BIT(8)
52 -#define MT7620_GPIO_MODE_RGMII1                BIT(9)
53 -#define MT7620_GPIO_MODE_RGMII2                BIT(10)
54 -#define MT7620_GPIO_MODE_SPI           BIT(11)
55 -#define MT7620_GPIO_MODE_SPI_REF_CLK   BIT(12)
56 -#define MT7620_GPIO_MODE_WLED          BIT(13)
57 -#define MT7620_GPIO_MODE_JTAG          BIT(15)
58 -#define MT7620_GPIO_MODE_EPHY          BIT(15)
59 -#define MT7620_GPIO_MODE_WDT           BIT(22)
60 +
61 +#define MT7620_GPIO_MODE_NAND          0
62 +#define MT7620_GPIO_MODE_SD            1
63 +#define MT7620_GPIO_MODE_ND_SD_GPIO    2
64 +#define MT7620_GPIO_MODE_ND_SD_MASK    0x3
65 +#define MT7620_GPIO_MODE_ND_SD_SHIFT   18
66 +
67 +#define MT7620_GPIO_MODE_PCIE_RST      0
68 +#define MT7620_GPIO_MODE_PCIE_REF      1
69 +#define MT7620_GPIO_MODE_PCIE_GPIO     2
70 +#define MT7620_GPIO_MODE_PCIE_MASK     0x3
71 +#define MT7620_GPIO_MODE_PCIE_SHIFT    16
72 +
73 +#define MT7620_GPIO_MODE_WDT_RST       0
74 +#define MT7620_GPIO_MODE_WDT_REF       1
75 +#define MT7620_GPIO_MODE_WDT_GPIO      2
76 +#define MT7620_GPIO_MODE_WDT_MASK      0x3
77 +#define MT7620_GPIO_MODE_WDT_SHIFT     21
78 +
79 +#define MT7620_GPIO_MODE_I2C           0
80 +#define MT7620_GPIO_MODE_UART1         5
81 +#define MT7620_GPIO_MODE_MDIO          8
82 +#define MT7620_GPIO_MODE_RGMII1                9
83 +#define MT7620_GPIO_MODE_RGMII2                10
84 +#define MT7620_GPIO_MODE_SPI           11
85 +#define MT7620_GPIO_MODE_SPI_REF_CLK   12
86 +#define MT7620_GPIO_MODE_WLED          13
87 +#define MT7620_GPIO_MODE_JTAG          15
88 +#define MT7620_GPIO_MODE_EPHY          15
89 +#define MT7620_GPIO_MODE_PA            20
90  
91  static inline int mt7620_get_eco(void)
92  {
93 --- /dev/null
94 +++ b/arch/mips/include/asm/mach-ralink/pinmux.h
95 @@ -0,0 +1,53 @@
96 +/*
97 + *  This program is free software; you can redistribute it and/or modify
98 + *  it under the terms of the GNU General Public License version 2 as
99 + *  publishhed by the Free Software Foundation.
100 + *
101 + *  Copyright (C) 2012 John Crispin <blogic@openwrt.org>
102 + */
103 +
104 +#ifndef _RT288X_PINMUX_H__
105 +#define _RT288X_PINMUX_H__
106 +
107 +#define FUNC(name, value, pin_first, pin_count) { name, value, pin_first, pin_count }
108 +#define GRP(_name, _func, _mask, _shift) \
109 +       { .name = _name, .mask = _mask, .shift = _shift, \
110 +         .func = _func, .gpio = _mask, \
111 +         .func_count = ARRAY_SIZE(_func) }
112 +
113 +#define GRP_G(_name, _func, _mask, _gpio, _shift) \
114 +       { .name = _name, .mask = _mask, .shift = _shift, \
115 +         .func = _func, .gpio = _gpio, \
116 +         .func_count = ARRAY_SIZE(_func) }
117 +
118 +struct rt2880_pmx_group;
119 +
120 +struct rt2880_pmx_func {
121 +       const char *name;
122 +       const char value;
123 +
124 +       int pin_first;
125 +       int pin_count;
126 +       int *pins;
127 +
128 +       int *groups;
129 +       int group_count;
130 +
131 +       int enabled;
132 +};
133 +
134 +struct rt2880_pmx_group {
135 +       const char *name;
136 +       int enabled;
137 +
138 +       const u32 shift;
139 +       const char mask;
140 +       const char gpio;
141 +
142 +       struct rt2880_pmx_func *func;
143 +       int func_count;
144 +};
145 +
146 +extern struct rt2880_pmx_group *rt2880_pinmux_data;
147 +
148 +#endif
149 --- a/arch/mips/include/asm/mach-ralink/rt305x.h
150 +++ b/arch/mips/include/asm/mach-ralink/rt305x.h
151 @@ -125,24 +125,29 @@ static inline int soc_is_rt5350(void)
152  #define RT305X_GPIO_GE0_TXD0           40
153  #define RT305X_GPIO_GE0_RXCLK          51
154  
155 -#define RT305X_GPIO_MODE_I2C           BIT(0)
156 -#define RT305X_GPIO_MODE_SPI           BIT(1)
157  #define RT305X_GPIO_MODE_UART0_SHIFT   2
158  #define RT305X_GPIO_MODE_UART0_MASK    0x7
159  #define RT305X_GPIO_MODE_UART0(x)      ((x) << RT305X_GPIO_MODE_UART0_SHIFT)
160 -#define RT305X_GPIO_MODE_UARTF         0x0
161 -#define RT305X_GPIO_MODE_PCM_UARTF     0x1
162 -#define RT305X_GPIO_MODE_PCM_I2S       0x2
163 -#define RT305X_GPIO_MODE_I2S_UARTF     0x3
164 -#define RT305X_GPIO_MODE_PCM_GPIO      0x4
165 -#define RT305X_GPIO_MODE_GPIO_UARTF    0x5
166 -#define RT305X_GPIO_MODE_GPIO_I2S      0x6
167 -#define RT305X_GPIO_MODE_GPIO          0x7
168 -#define RT305X_GPIO_MODE_UART1         BIT(5)
169 -#define RT305X_GPIO_MODE_JTAG          BIT(6)
170 -#define RT305X_GPIO_MODE_MDIO          BIT(7)
171 -#define RT305X_GPIO_MODE_SDRAM         BIT(8)
172 -#define RT305X_GPIO_MODE_RGMII         BIT(9)
173 +#define RT305X_GPIO_MODE_UARTF         0
174 +#define RT305X_GPIO_MODE_PCM_UARTF     1
175 +#define RT305X_GPIO_MODE_PCM_I2S       2
176 +#define RT305X_GPIO_MODE_I2S_UARTF     3
177 +#define RT305X_GPIO_MODE_PCM_GPIO      4
178 +#define RT305X_GPIO_MODE_GPIO_UARTF    5
179 +#define RT305X_GPIO_MODE_GPIO_I2S      6
180 +#define RT305X_GPIO_MODE_GPIO          7
181 +
182 +#define RT305X_GPIO_MODE_I2C           0
183 +#define RT305X_GPIO_MODE_SPI           1
184 +#define RT305X_GPIO_MODE_UART1         5
185 +#define RT305X_GPIO_MODE_JTAG          6
186 +#define RT305X_GPIO_MODE_MDIO          7
187 +#define RT305X_GPIO_MODE_SDRAM         8
188 +#define RT305X_GPIO_MODE_RGMII         9
189 +#define RT5350_GPIO_MODE_PHY_LED       14
190 +#define RT5350_GPIO_MODE_SPI_CS1       21
191 +#define RT3352_GPIO_MODE_LNA           18
192 +#define RT3352_GPIO_MODE_PA            20
193  
194  #define RT3352_SYSC_REG_SYSCFG0                0x010
195  #define RT3352_SYSC_REG_SYSCFG1         0x014
196 --- a/arch/mips/include/asm/mach-ralink/rt3883.h
197 +++ b/arch/mips/include/asm/mach-ralink/rt3883.h
198 @@ -112,8 +112,6 @@
199  #define RT3883_CLKCFG1_PCI_CLK_EN      BIT(19)
200  #define RT3883_CLKCFG1_UPHY0_CLK_EN    BIT(18)
201  
202 -#define RT3883_GPIO_MODE_I2C           BIT(0)
203 -#define RT3883_GPIO_MODE_SPI           BIT(1)
204  #define RT3883_GPIO_MODE_UART0_SHIFT   2
205  #define RT3883_GPIO_MODE_UART0_MASK    0x7
206  #define RT3883_GPIO_MODE_UART0(x)      ((x) << RT3883_GPIO_MODE_UART0_SHIFT)
207 @@ -125,11 +123,15 @@
208  #define RT3883_GPIO_MODE_GPIO_UARTF    0x5
209  #define RT3883_GPIO_MODE_GPIO_I2S      0x6
210  #define RT3883_GPIO_MODE_GPIO          0x7
211 -#define RT3883_GPIO_MODE_UART1         BIT(5)
212 -#define RT3883_GPIO_MODE_JTAG          BIT(6)
213 -#define RT3883_GPIO_MODE_MDIO          BIT(7)
214 -#define RT3883_GPIO_MODE_GE1           BIT(9)
215 -#define RT3883_GPIO_MODE_GE2           BIT(10)
216 +
217 +#define RT3883_GPIO_MODE_I2C           0
218 +#define RT3883_GPIO_MODE_SPI           1
219 +#define RT3883_GPIO_MODE_UART1         5
220 +#define RT3883_GPIO_MODE_JTAG          6
221 +#define RT3883_GPIO_MODE_MDIO          7
222 +#define RT3883_GPIO_MODE_GE1           9
223 +#define RT3883_GPIO_MODE_GE2           10
224 +
225  #define RT3883_GPIO_MODE_PCI_SHIFT     11
226  #define RT3883_GPIO_MODE_PCI_MASK      0x7
227  #define RT3883_GPIO_MODE_PCI           (RT3883_GPIO_MODE_PCI_MASK << RT3883_GPIO_MODE_PCI_SHIFT)
228 --- a/arch/mips/ralink/common.h
229 +++ b/arch/mips/ralink/common.h
230 @@ -11,25 +11,6 @@
231  
232  #define RAMIPS_SYS_TYPE_LEN    32
233  
234 -struct ralink_pinmux_grp {
235 -       const char *name;
236 -       u32 mask;
237 -       int gpio_first;
238 -       int gpio_last;
239 -};
240 -
241 -struct ralink_pinmux {
242 -       struct ralink_pinmux_grp *mode;
243 -       struct ralink_pinmux_grp *uart;
244 -       int uart_shift;
245 -       u32 uart_mask;
246 -       void (*wdt_reset)(void);
247 -       struct ralink_pinmux_grp *pci;
248 -       int pci_shift;
249 -       u32 pci_mask;
250 -};
251 -extern struct ralink_pinmux rt_gpio_pinmux;
252 -
253  struct ralink_soc_info {
254         unsigned char sys_type[RAMIPS_SYS_TYPE_LEN];
255         unsigned char *compatible;
256 --- a/arch/mips/ralink/mt7620.c
257 +++ b/arch/mips/ralink/mt7620.c
258 @@ -17,6 +17,7 @@
259  #include <asm/mipsregs.h>
260  #include <asm/mach-ralink/ralink_regs.h>
261  #include <asm/mach-ralink/mt7620.h>
262 +#include <asm/mach-ralink/pinmux.h>
263  
264  #include "common.h"
265  
266 @@ -47,118 +48,58 @@ enum mt762x_soc_type mt762x_soc;
267  /* does the board have sdram or ddram */
268  static int dram_type;
269  
270 -static struct ralink_pinmux_grp mode_mux[] = {
271 -       {
272 -               .name = "i2c",
273 -               .mask = MT7620_GPIO_MODE_I2C,
274 -               .gpio_first = 1,
275 -               .gpio_last = 2,
276 -       }, {
277 -               .name = "spi",
278 -               .mask = MT7620_GPIO_MODE_SPI,
279 -               .gpio_first = 3,
280 -               .gpio_last = 6,
281 -       }, {
282 -               .name = "uartlite",
283 -               .mask = MT7620_GPIO_MODE_UART1,
284 -               .gpio_first = 15,
285 -               .gpio_last = 16,
286 -       }, {
287 -               .name = "wdt",
288 -               .mask = MT7620_GPIO_MODE_WDT,
289 -               .gpio_first = 17,
290 -               .gpio_last = 17,
291 -       }, {
292 -               .name = "mdio",
293 -               .mask = MT7620_GPIO_MODE_MDIO,
294 -               .gpio_first = 22,
295 -               .gpio_last = 23,
296 -       }, {
297 -               .name = "rgmii1",
298 -               .mask = MT7620_GPIO_MODE_RGMII1,
299 -               .gpio_first = 24,
300 -               .gpio_last = 35,
301 -       }, {
302 -               .name = "spi refclk",
303 -               .mask = MT7620_GPIO_MODE_SPI_REF_CLK,
304 -               .gpio_first = 37,
305 -               .gpio_last = 39,
306 -       }, {
307 -               .name = "jtag",
308 -               .mask = MT7620_GPIO_MODE_JTAG,
309 -               .gpio_first = 40,
310 -               .gpio_last = 44,
311 -       }, {
312 -               /* shared lines with jtag */
313 -               .name = "ephy",
314 -               .mask = MT7620_GPIO_MODE_EPHY,
315 -               .gpio_first = 40,
316 -               .gpio_last = 44,
317 -       }, {
318 -               .name = "nand",
319 -               .mask = MT7620_GPIO_MODE_JTAG,
320 -               .gpio_first = 45,
321 -               .gpio_last = 59,
322 -       }, {
323 -               .name = "rgmii2",
324 -               .mask = MT7620_GPIO_MODE_RGMII2,
325 -               .gpio_first = 60,
326 -               .gpio_last = 71,
327 -       }, {
328 -               .name = "wled",
329 -               .mask = MT7620_GPIO_MODE_WLED,
330 -               .gpio_first = 72,
331 -               .gpio_last = 72,
332 -       }, {0}
333 +static struct rt2880_pmx_func i2c_grp[] =  { FUNC("i2c", 0, 1, 2) };
334 +static struct rt2880_pmx_func spi_grp[] = { FUNC("spi", 0, 3, 4) };
335 +static struct rt2880_pmx_func uartlite_grp[] = { FUNC("uartlite", 0, 15, 2) };
336 +static struct rt2880_pmx_func mdio_grp[] = { FUNC("mdio", 0, 22, 2) };
337 +static struct rt2880_pmx_func rgmii1_grp[] = { FUNC("rgmii1", 0, 24, 12) };
338 +static struct rt2880_pmx_func refclk_grp[] = { FUNC("spi refclk", 0, 37, 3) };
339 +static struct rt2880_pmx_func ephy_grp[] = { FUNC("ephy", 0, 40, 5) };
340 +static struct rt2880_pmx_func rgmii2_grp[] = { FUNC("rgmii2", 0, 60, 12) };
341 +static struct rt2880_pmx_func wled_grp[] = { FUNC("wled", 0, 72, 1) };
342 +static struct rt2880_pmx_func pa_grp[] = { FUNC("pa", 0, 18, 4) };
343 +static struct rt2880_pmx_func uartf_grp[] = {
344 +       FUNC("uartf", MT7620_GPIO_MODE_UARTF, 7, 8),
345 +       FUNC("pcm uartf", MT7620_GPIO_MODE_PCM_UARTF, 7, 8),
346 +       FUNC("pcm i2s", MT7620_GPIO_MODE_PCM_I2S, 7, 8),
347 +       FUNC("i2s uartf", MT7620_GPIO_MODE_I2S_UARTF, 7, 8),
348 +       FUNC("pcm gpio", MT7620_GPIO_MODE_PCM_GPIO, 11, 4),
349 +       FUNC("gpio uartf", MT7620_GPIO_MODE_GPIO_UARTF, 7, 4),
350 +       FUNC("gpio i2s", MT7620_GPIO_MODE_GPIO_I2S, 7, 4),
351  };
352 -
353 -static struct ralink_pinmux_grp uart_mux[] = {
354 -       {
355 -               .name = "uartf",
356 -               .mask = MT7620_GPIO_MODE_UARTF,
357 -               .gpio_first = 7,
358 -               .gpio_last = 14,
359 -       }, {
360 -               .name = "pcm uartf",
361 -               .mask = MT7620_GPIO_MODE_PCM_UARTF,
362 -               .gpio_first = 7,
363 -               .gpio_last = 14,
364 -       }, {
365 -               .name = "pcm i2s",
366 -               .mask = MT7620_GPIO_MODE_PCM_I2S,
367 -               .gpio_first = 7,
368 -               .gpio_last = 14,
369 -       }, {
370 -               .name = "i2s uartf",
371 -               .mask = MT7620_GPIO_MODE_I2S_UARTF,
372 -               .gpio_first = 7,
373 -               .gpio_last = 14,
374 -       }, {
375 -               .name = "pcm gpio",
376 -               .mask = MT7620_GPIO_MODE_PCM_GPIO,
377 -               .gpio_first = 11,
378 -               .gpio_last = 14,
379 -       }, {
380 -               .name = "gpio uartf",
381 -               .mask = MT7620_GPIO_MODE_GPIO_UARTF,
382 -               .gpio_first = 7,
383 -               .gpio_last = 10,
384 -       }, {
385 -               .name = "gpio i2s",
386 -               .mask = MT7620_GPIO_MODE_GPIO_I2S,
387 -               .gpio_first = 7,
388 -               .gpio_last = 10,
389 -       }, {
390 -               .name = "gpio",
391 -               .mask = MT7620_GPIO_MODE_GPIO,
392 -       }, {0}
393 +static struct rt2880_pmx_func wdt_grp[] = {
394 +       FUNC("wdt rst", 0, 17, 1),
395 +       FUNC("wdt refclk", 0, 17, 1),
396 +       };
397 +static struct rt2880_pmx_func pcie_rst_grp[] = {
398 +       FUNC("pcie rst", MT7620_GPIO_MODE_PCIE_RST, 36, 1),
399 +       FUNC("pcie refclk", MT7620_GPIO_MODE_PCIE_REF, 36, 1)
400 +};
401 +static struct rt2880_pmx_func nd_sd_grp[] = {
402 +       FUNC("nand", MT7620_GPIO_MODE_NAND, 45, 15),
403 +       FUNC("sd", MT7620_GPIO_MODE_SD, 45, 15)
404  };
405  
406 -struct ralink_pinmux rt_gpio_pinmux = {
407 -       .mode = mode_mux,
408 -       .uart = uart_mux,
409 -       .uart_shift = MT7620_GPIO_MODE_UART0_SHIFT,
410 -       .uart_mask = MT7620_GPIO_MODE_UART0_MASK,
411 +static struct rt2880_pmx_group mt7620a_pinmux_data[] = {
412 +       GRP("i2c", i2c_grp, 1, MT7620_GPIO_MODE_I2C),
413 +       GRP("uartf", uartf_grp, MT7620_GPIO_MODE_UART0_MASK,
414 +               MT7620_GPIO_MODE_UART0_SHIFT),
415 +       GRP("spi", spi_grp, 1, MT7620_GPIO_MODE_SPI),
416 +       GRP("uartlite", uartlite_grp, 1, MT7620_GPIO_MODE_UART1),
417 +       GRP_G("wdt", wdt_grp, MT7620_GPIO_MODE_WDT_MASK,
418 +               MT7620_GPIO_MODE_WDT_GPIO, MT7620_GPIO_MODE_WDT_SHIFT),
419 +       GRP("mdio", mdio_grp, 1, MT7620_GPIO_MODE_MDIO),
420 +       GRP("rgmii1", rgmii1_grp, 1, MT7620_GPIO_MODE_RGMII1),
421 +       GRP("spi refclk", refclk_grp, 1, MT7620_GPIO_MODE_SPI_REF_CLK),
422 +       GRP_G("pcie", pcie_rst_grp, MT7620_GPIO_MODE_PCIE_MASK,
423 +               MT7620_GPIO_MODE_PCIE_GPIO, MT7620_GPIO_MODE_PCIE_SHIFT),
424 +       GRP_G("nd_sd", nd_sd_grp, MT7620_GPIO_MODE_ND_SD_MASK,
425 +               MT7620_GPIO_MODE_ND_SD_GPIO, MT7620_GPIO_MODE_ND_SD_SHIFT),
426 +       GRP("rgmii2", rgmii2_grp, 1, MT7620_GPIO_MODE_RGMII2),
427 +       GRP("wled", wled_grp, 1, MT7620_GPIO_MODE_WLED),
428 +       GRP("ephy", ephy_grp, 1, MT7620_GPIO_MODE_EPHY),
429 +       GRP("pa", pa_grp, 1, MT7620_GPIO_MODE_PA),
430 +       { 0 }
431  };
432  
433  static struct rt2880_pmx_func pwm1_grp_mt7628[] = {
434 --- a/arch/mips/ralink/rt288x.c
435 +++ b/arch/mips/ralink/rt288x.c
436 @@ -17,46 +17,27 @@
437  #include <asm/mipsregs.h>
438  #include <asm/mach-ralink/ralink_regs.h>
439  #include <asm/mach-ralink/rt288x.h>
440 +#include <asm/mach-ralink/pinmux.h>
441  
442  #include "common.h"
443  
444 -static struct ralink_pinmux_grp mode_mux[] = {
445 -       {
446 -               .name = "i2c",
447 -               .mask = RT2880_GPIO_MODE_I2C,
448 -               .gpio_first = 1,
449 -               .gpio_last = 2,
450 -       }, {
451 -               .name = "spi",
452 -               .mask = RT2880_GPIO_MODE_SPI,
453 -               .gpio_first = 3,
454 -               .gpio_last = 6,
455 -       }, {
456 -               .name = "uartlite",
457 -               .mask = RT2880_GPIO_MODE_UART0,
458 -               .gpio_first = 7,
459 -               .gpio_last = 14,
460 -       }, {
461 -               .name = "jtag",
462 -               .mask = RT2880_GPIO_MODE_JTAG,
463 -               .gpio_first = 17,
464 -               .gpio_last = 21,
465 -       }, {
466 -               .name = "mdio",
467 -               .mask = RT2880_GPIO_MODE_MDIO,
468 -               .gpio_first = 22,
469 -               .gpio_last = 23,
470 -       }, {
471 -               .name = "sdram",
472 -               .mask = RT2880_GPIO_MODE_SDRAM,
473 -               .gpio_first = 24,
474 -               .gpio_last = 39,
475 -       }, {
476 -               .name = "pci",
477 -               .mask = RT2880_GPIO_MODE_PCI,
478 -               .gpio_first = 40,
479 -               .gpio_last = 71,
480 -       }, {0}
481 +static struct rt2880_pmx_func i2c_func[] = { FUNC("i2c", 0, 1, 2) };
482 +static struct rt2880_pmx_func spi_func[] = { FUNC("spi", 0, 3, 4) };
483 +static struct rt2880_pmx_func uartlite_func[] = { FUNC("uartlite", 0, 7, 8) };
484 +static struct rt2880_pmx_func jtag_func[] = { FUNC("jtag", 0, 17, 5) };
485 +static struct rt2880_pmx_func mdio_func[] = { FUNC("mdio", 0, 22, 2) };
486 +static struct rt2880_pmx_func sdram_func[] = { FUNC("sdram", 0, 24, 16) };
487 +static struct rt2880_pmx_func pci_func[] = { FUNC("pci", 0, 40, 32) };
488 +
489 +static struct rt2880_pmx_group rt2880_pinmux_data_act[] = {
490 +    GRP("i2c", i2c_func, 1, RT2880_GPIO_MODE_I2C),
491 +    GRP("spi", spi_func, 1, RT2880_GPIO_MODE_SPI),
492 +    GRP("uartlite", uartlite_func, 1, RT2880_GPIO_MODE_UART0),
493 +    GRP("jtag", jtag_func, 1, RT2880_GPIO_MODE_JTAG),
494 +    GRP("mdio", mdio_func, 1, RT2880_GPIO_MODE_MDIO),
495 +    GRP("sdram", sdram_func, 1, RT2880_GPIO_MODE_SDRAM),
496 +    GRP("pci", pci_func, 1, RT2880_GPIO_MODE_PCI),
497 +    { 0 }
498  };
499  
500  static void rt288x_wdt_reset(void)
501 @@ -69,11 +50,6 @@ static void rt288x_wdt_reset(void)
502         rt_sysc_w32(t, SYSC_REG_CLKCFG);
503  }
504  
505 -struct ralink_pinmux rt_gpio_pinmux = {
506 -       .mode = mode_mux,
507 -       .wdt_reset = rt288x_wdt_reset,
508 -};
509 -
510  void __init ralink_clk_init(void)
511  {
512         unsigned long cpu_rate, wmac_rate = 40000000;
513 @@ -141,4 +117,6 @@ void prom_soc_init(struct ralink_soc_inf
514         soc_info->mem_base = RT2880_SDRAM_BASE;
515         soc_info->mem_size_min = RT2880_MEM_SIZE_MIN;
516         soc_info->mem_size_max = RT2880_MEM_SIZE_MAX;
517 +
518 +        rt2880_pinmux_data = rt2880_pinmux_data_act;
519  }
520 --- a/arch/mips/ralink/rt305x.c
521 +++ b/arch/mips/ralink/rt305x.c
522 @@ -17,90 +17,76 @@
523  #include <asm/mipsregs.h>
524  #include <asm/mach-ralink/ralink_regs.h>
525  #include <asm/mach-ralink/rt305x.h>
526 +#include <asm/mach-ralink/pinmux.h>
527  
528  #include "common.h"
529  
530  enum rt305x_soc_type rt305x_soc;
531  
532 -static struct ralink_pinmux_grp mode_mux[] = {
533 -       {
534 -               .name = "i2c",
535 -               .mask = RT305X_GPIO_MODE_I2C,
536 -               .gpio_first = RT305X_GPIO_I2C_SD,
537 -               .gpio_last = RT305X_GPIO_I2C_SCLK,
538 -       }, {
539 -               .name = "spi",
540 -               .mask = RT305X_GPIO_MODE_SPI,
541 -               .gpio_first = RT305X_GPIO_SPI_EN,
542 -               .gpio_last = RT305X_GPIO_SPI_CLK,
543 -       }, {
544 -               .name = "uartlite",
545 -               .mask = RT305X_GPIO_MODE_UART1,
546 -               .gpio_first = RT305X_GPIO_UART1_TXD,
547 -               .gpio_last = RT305X_GPIO_UART1_RXD,
548 -       }, {
549 -               .name = "jtag",
550 -               .mask = RT305X_GPIO_MODE_JTAG,
551 -               .gpio_first = RT305X_GPIO_JTAG_TDO,
552 -               .gpio_last = RT305X_GPIO_JTAG_TDI,
553 -       }, {
554 -               .name = "mdio",
555 -               .mask = RT305X_GPIO_MODE_MDIO,
556 -               .gpio_first = RT305X_GPIO_MDIO_MDC,
557 -               .gpio_last = RT305X_GPIO_MDIO_MDIO,
558 -       }, {
559 -               .name = "sdram",
560 -               .mask = RT305X_GPIO_MODE_SDRAM,
561 -               .gpio_first = RT305X_GPIO_SDRAM_MD16,
562 -               .gpio_last = RT305X_GPIO_SDRAM_MD31,
563 -       }, {
564 -               .name = "rgmii",
565 -               .mask = RT305X_GPIO_MODE_RGMII,
566 -               .gpio_first = RT305X_GPIO_GE0_TXD0,
567 -               .gpio_last = RT305X_GPIO_GE0_RXCLK,
568 -       }, {0}
569 +static struct rt2880_pmx_func i2c_func[] =  { FUNC("i2c", 0, 1, 2) };
570 +static struct rt2880_pmx_func spi_func[] = { FUNC("spi", 0, 3, 4) };
571 +static struct rt2880_pmx_func uartf_func[] = {
572 +       FUNC("uartf", RT305X_GPIO_MODE_UARTF, 7, 8),
573 +       FUNC("pcm uartf", RT305X_GPIO_MODE_PCM_UARTF, 7, 8),
574 +       FUNC("pcm i2s", RT305X_GPIO_MODE_PCM_I2S, 7, 8),
575 +       FUNC("i2s uartf", RT305X_GPIO_MODE_I2S_UARTF, 7, 8),
576 +       FUNC("pcm gpio", RT305X_GPIO_MODE_PCM_GPIO, 11, 4),
577 +       FUNC("gpio uartf", RT305X_GPIO_MODE_GPIO_UARTF, 7, 4),
578 +       FUNC("gpio i2s", RT305X_GPIO_MODE_GPIO_I2S, 7, 4),
579 +};
580 +static struct rt2880_pmx_func uartlite_func[] = { FUNC("uartlite", 0, 15, 2) };
581 +static struct rt2880_pmx_func jtag_func[] = { FUNC("jtag", 0, 17, 5) };
582 +static struct rt2880_pmx_func mdio_func[] = { FUNC("mdio", 0, 22, 2) };
583 +static struct rt2880_pmx_func rt5350_led_func[] = { FUNC("led", 0, 22, 5) };
584 +static struct rt2880_pmx_func rt5350_cs1_func[] = {
585 +       FUNC("spi_cs1", 0, 27, 1),
586 +       FUNC("wdg_cs1", 1, 27, 1),
587 +};
588 +static struct rt2880_pmx_func sdram_func[] = { FUNC("sdram", 0, 24, 16) };
589 +static struct rt2880_pmx_func rt3352_rgmii_func[] = { FUNC("rgmii", 0, 24, 12) };
590 +static struct rt2880_pmx_func rgmii_func[] = { FUNC("rgmii", 0, 40, 12) };
591 +static struct rt2880_pmx_func rt3352_lna_func[] = { FUNC("lna", 0, 36, 2) };
592 +static struct rt2880_pmx_func rt3352_pa_func[] = { FUNC("pa", 0, 38, 2) };
593 +static struct rt2880_pmx_func rt3352_led_func[] = { FUNC("led", 0, 40, 5) };
594 +
595 +static struct rt2880_pmx_group rt3050_pinmux_data[] = {
596 +       GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C),
597 +       GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI),
598 +       GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK,
599 +               RT305X_GPIO_MODE_UART0_SHIFT),
600 +       GRP("uartlite", uartlite_func, 1, RT305X_GPIO_MODE_UART1),
601 +       GRP("jtag", jtag_func, 1, RT305X_GPIO_MODE_JTAG),
602 +       GRP("mdio", mdio_func, 1, RT305X_GPIO_MODE_MDIO),
603 +       GRP("rgmii", rgmii_func, 1, RT305X_GPIO_MODE_RGMII),
604 +       GRP("sdram", sdram_func, 1, RT305X_GPIO_MODE_SDRAM),
605 +       { 0 }
606 +};
607 +
608 +static struct rt2880_pmx_group rt3352_pinmux_data[] = {
609 +       GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C),
610 +       GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI),
611 +       GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK,
612 +               RT305X_GPIO_MODE_UART0_SHIFT),
613 +       GRP("uartlite", uartlite_func, 1, RT305X_GPIO_MODE_UART1),
614 +       GRP("jtag", jtag_func, 1, RT305X_GPIO_MODE_JTAG),
615 +       GRP("mdio", mdio_func, 1, RT305X_GPIO_MODE_MDIO),
616 +       GRP("rgmii", rt3352_rgmii_func, 1, RT305X_GPIO_MODE_RGMII),
617 +       GRP("lna", rt3352_lna_func, 1, RT3352_GPIO_MODE_LNA),
618 +       GRP("pa", rt3352_pa_func, 1, RT3352_GPIO_MODE_PA),
619 +       GRP("led", rt3352_led_func, 1, RT5350_GPIO_MODE_PHY_LED),
620 +       { 0 }
621  };
622  
623 -static struct ralink_pinmux_grp uart_mux[] = {
624 -       {
625 -               .name = "uartf",
626 -               .mask = RT305X_GPIO_MODE_UARTF,
627 -               .gpio_first = RT305X_GPIO_7,
628 -               .gpio_last = RT305X_GPIO_14,
629 -       }, {
630 -               .name = "pcm uartf",
631 -               .mask = RT305X_GPIO_MODE_PCM_UARTF,
632 -               .gpio_first = RT305X_GPIO_7,
633 -               .gpio_last = RT305X_GPIO_14,
634 -       }, {
635 -               .name = "pcm i2s",
636 -               .mask = RT305X_GPIO_MODE_PCM_I2S,
637 -               .gpio_first = RT305X_GPIO_7,
638 -               .gpio_last = RT305X_GPIO_14,
639 -       }, {
640 -               .name = "i2s uartf",
641 -               .mask = RT305X_GPIO_MODE_I2S_UARTF,
642 -               .gpio_first = RT305X_GPIO_7,
643 -               .gpio_last = RT305X_GPIO_14,
644 -       }, {
645 -               .name = "pcm gpio",
646 -               .mask = RT305X_GPIO_MODE_PCM_GPIO,
647 -               .gpio_first = RT305X_GPIO_10,
648 -               .gpio_last = RT305X_GPIO_14,
649 -       }, {
650 -               .name = "gpio uartf",
651 -               .mask = RT305X_GPIO_MODE_GPIO_UARTF,
652 -               .gpio_first = RT305X_GPIO_7,
653 -               .gpio_last = RT305X_GPIO_10,
654 -       }, {
655 -               .name = "gpio i2s",
656 -               .mask = RT305X_GPIO_MODE_GPIO_I2S,
657 -               .gpio_first = RT305X_GPIO_7,
658 -               .gpio_last = RT305X_GPIO_10,
659 -       }, {
660 -               .name = "gpio",
661 -               .mask = RT305X_GPIO_MODE_GPIO,
662 -       }, {0}
663 +static struct rt2880_pmx_group rt5350_pinmux_data[] = {
664 +       GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C),
665 +       GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI),
666 +       GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK,
667 +               RT305X_GPIO_MODE_UART0_SHIFT),
668 +       GRP("uartlite", uartlite_func, 1, RT305X_GPIO_MODE_UART1),
669 +       GRP("jtag", jtag_func, 1, RT305X_GPIO_MODE_JTAG),
670 +       GRP("led", rt5350_led_func, 1, RT5350_GPIO_MODE_PHY_LED),
671 +       GRP("spi_cs1", rt5350_cs1_func, 2, RT5350_GPIO_MODE_SPI_CS1),
672 +       { 0 }
673  };
674  
675  static void rt305x_wdt_reset(void)
676 @@ -114,14 +100,6 @@ static void rt305x_wdt_reset(void)
677         rt_sysc_w32(t, SYSC_REG_SYSTEM_CONFIG);
678  }
679  
680 -struct ralink_pinmux rt_gpio_pinmux = {
681 -       .mode = mode_mux,
682 -       .uart = uart_mux,
683 -       .uart_shift = RT305X_GPIO_MODE_UART0_SHIFT,
684 -       .uart_mask = RT305X_GPIO_MODE_UART0_MASK,
685 -       .wdt_reset = rt305x_wdt_reset,
686 -};
687 -
688  static unsigned long rt5350_get_mem_size(void)
689  {
690         void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT305X_SYSC_BASE);
691 @@ -290,11 +268,14 @@ void prom_soc_init(struct ralink_soc_inf
692         soc_info->mem_base = RT305X_SDRAM_BASE;
693         if (soc_is_rt5350()) {
694                 soc_info->mem_size = rt5350_get_mem_size();
695 +               rt2880_pinmux_data = rt5350_pinmux_data;
696         } else if (soc_is_rt305x() || soc_is_rt3350()) {
697                 soc_info->mem_size_min = RT305X_MEM_SIZE_MIN;
698                 soc_info->mem_size_max = RT305X_MEM_SIZE_MAX;
699 +               rt2880_pinmux_data = rt3050_pinmux_data;
700         } else if (soc_is_rt3352()) {
701                 soc_info->mem_size_min = RT3352_MEM_SIZE_MIN;
702                 soc_info->mem_size_max = RT3352_MEM_SIZE_MAX;
703 +               rt2880_pinmux_data = rt3352_pinmux_data;
704         }
705  }
706 --- a/arch/mips/ralink/rt3883.c
707 +++ b/arch/mips/ralink/rt3883.c
708 @@ -17,132 +17,50 @@
709  #include <asm/mipsregs.h>
710  #include <asm/mach-ralink/ralink_regs.h>
711  #include <asm/mach-ralink/rt3883.h>
712 +#include <asm/mach-ralink/pinmux.h>
713  
714  #include "common.h"
715  
716 -static struct ralink_pinmux_grp mode_mux[] = {
717 -       {
718 -               .name = "i2c",
719 -               .mask = RT3883_GPIO_MODE_I2C,
720 -               .gpio_first = RT3883_GPIO_I2C_SD,
721 -               .gpio_last = RT3883_GPIO_I2C_SCLK,
722 -       }, {
723 -               .name = "spi",
724 -               .mask = RT3883_GPIO_MODE_SPI,
725 -               .gpio_first = RT3883_GPIO_SPI_CS0,
726 -               .gpio_last = RT3883_GPIO_SPI_MISO,
727 -       }, {
728 -               .name = "uartlite",
729 -               .mask = RT3883_GPIO_MODE_UART1,
730 -               .gpio_first = RT3883_GPIO_UART1_TXD,
731 -               .gpio_last = RT3883_GPIO_UART1_RXD,
732 -       }, {
733 -               .name = "jtag",
734 -               .mask = RT3883_GPIO_MODE_JTAG,
735 -               .gpio_first = RT3883_GPIO_JTAG_TDO,
736 -               .gpio_last = RT3883_GPIO_JTAG_TCLK,
737 -       }, {
738 -               .name = "mdio",
739 -               .mask = RT3883_GPIO_MODE_MDIO,
740 -               .gpio_first = RT3883_GPIO_MDIO_MDC,
741 -               .gpio_last = RT3883_GPIO_MDIO_MDIO,
742 -       }, {
743 -               .name = "ge1",
744 -               .mask = RT3883_GPIO_MODE_GE1,
745 -               .gpio_first = RT3883_GPIO_GE1_TXD0,
746 -               .gpio_last = RT3883_GPIO_GE1_RXCLK,
747 -       }, {
748 -               .name = "ge2",
749 -               .mask = RT3883_GPIO_MODE_GE2,
750 -               .gpio_first = RT3883_GPIO_GE2_TXD0,
751 -               .gpio_last = RT3883_GPIO_GE2_RXCLK,
752 -       }, {
753 -               .name = "pci",
754 -               .mask = RT3883_GPIO_MODE_PCI,
755 -               .gpio_first = RT3883_GPIO_PCI_AD0,
756 -               .gpio_last = RT3883_GPIO_PCI_AD31,
757 -       }, {
758 -               .name = "lna a",
759 -               .mask = RT3883_GPIO_MODE_LNA_A,
760 -               .gpio_first = RT3883_GPIO_LNA_PE_A0,
761 -               .gpio_last = RT3883_GPIO_LNA_PE_A2,
762 -       }, {
763 -               .name = "lna g",
764 -               .mask = RT3883_GPIO_MODE_LNA_G,
765 -               .gpio_first = RT3883_GPIO_LNA_PE_G0,
766 -               .gpio_last = RT3883_GPIO_LNA_PE_G2,
767 -       }, {0}
768 +static struct rt2880_pmx_func i2c_func[] =  { FUNC("i2c", 0, 1, 2) };
769 +static struct rt2880_pmx_func spi_func[] = { FUNC("spi", 0, 3, 4) };
770 +static struct rt2880_pmx_func uartf_func[] = {
771 +       FUNC("uartf", RT3883_GPIO_MODE_UARTF, 7, 8),
772 +       FUNC("pcm uartf", RT3883_GPIO_MODE_PCM_UARTF, 7, 8),
773 +       FUNC("pcm i2s", RT3883_GPIO_MODE_PCM_I2S, 7, 8),
774 +       FUNC("i2s uartf", RT3883_GPIO_MODE_I2S_UARTF, 7, 8),
775 +       FUNC("pcm gpio", RT3883_GPIO_MODE_PCM_GPIO, 11, 4),
776 +       FUNC("gpio uartf", RT3883_GPIO_MODE_GPIO_UARTF, 7, 4),
777 +       FUNC("gpio i2s", RT3883_GPIO_MODE_GPIO_I2S, 7, 4),
778  };
779 -
780 -static struct ralink_pinmux_grp uart_mux[] = {
781 -       {
782 -               .name = "uartf",
783 -               .mask = RT3883_GPIO_MODE_UARTF,
784 -               .gpio_first = RT3883_GPIO_7,
785 -               .gpio_last = RT3883_GPIO_14,
786 -       }, {
787 -               .name = "pcm uartf",
788 -               .mask = RT3883_GPIO_MODE_PCM_UARTF,
789 -               .gpio_first = RT3883_GPIO_7,
790 -               .gpio_last = RT3883_GPIO_14,
791 -       }, {
792 -               .name = "pcm i2s",
793 -               .mask = RT3883_GPIO_MODE_PCM_I2S,
794 -               .gpio_first = RT3883_GPIO_7,
795 -               .gpio_last = RT3883_GPIO_14,
796 -       }, {
797 -               .name = "i2s uartf",
798 -               .mask = RT3883_GPIO_MODE_I2S_UARTF,
799 -               .gpio_first = RT3883_GPIO_7,
800 -               .gpio_last = RT3883_GPIO_14,
801 -       }, {
802 -               .name = "pcm gpio",
803 -               .mask = RT3883_GPIO_MODE_PCM_GPIO,
804 -               .gpio_first = RT3883_GPIO_11,
805 -               .gpio_last = RT3883_GPIO_14,
806 -       }, {
807 -               .name = "gpio uartf",
808 -               .mask = RT3883_GPIO_MODE_GPIO_UARTF,
809 -               .gpio_first = RT3883_GPIO_7,
810 -               .gpio_last = RT3883_GPIO_10,
811 -       }, {
812 -               .name = "gpio i2s",
813 -               .mask = RT3883_GPIO_MODE_GPIO_I2S,
814 -               .gpio_first = RT3883_GPIO_7,
815 -               .gpio_last = RT3883_GPIO_10,
816 -       }, {
817 -               .name = "gpio",
818 -               .mask = RT3883_GPIO_MODE_GPIO,
819 -       }, {0}
820 +static struct rt2880_pmx_func uartlite_func[] = { FUNC("uartlite", 0, 15, 2) };
821 +static struct rt2880_pmx_func jtag_func[] = { FUNC("jtag", 0, 17, 5) };
822 +static struct rt2880_pmx_func mdio_func[] = { FUNC("mdio", 0, 22, 2) };
823 +static struct rt2880_pmx_func lna_a_func[] = { FUNC("lna a", 0, 32, 3) };
824 +static struct rt2880_pmx_func lna_g_func[] = { FUNC("lna a", 0, 35, 3) };
825 +static struct rt2880_pmx_func pci_func[] = {
826 +       FUNC("pci-dev", 0, 40, 32),
827 +       FUNC("pci-host2", 1, 40, 32),
828 +       FUNC("pci-host1", 2, 40, 32),
829 +       FUNC("pci-fnc", 3, 40, 32)
830  };
831 +static struct rt2880_pmx_func ge1_func[] = { FUNC("ge1", 0, 72, 12) };
832 +static struct rt2880_pmx_func ge2_func[] = { FUNC("ge1", 0, 84, 12) };
833  
834 -static struct ralink_pinmux_grp pci_mux[] = {
835 -       {
836 -               .name = "pci-dev",
837 -               .mask = 0,
838 -               .gpio_first = RT3883_GPIO_PCI_AD0,
839 -               .gpio_last = RT3883_GPIO_PCI_AD31,
840 -       }, {
841 -               .name = "pci-host2",
842 -               .mask = 1,
843 -               .gpio_first = RT3883_GPIO_PCI_AD0,
844 -               .gpio_last = RT3883_GPIO_PCI_AD31,
845 -       }, {
846 -               .name = "pci-host1",
847 -               .mask = 2,
848 -               .gpio_first = RT3883_GPIO_PCI_AD0,
849 -               .gpio_last = RT3883_GPIO_PCI_AD31,
850 -       }, {
851 -               .name = "pci-fnc",
852 -               .mask = 3,
853 -               .gpio_first = RT3883_GPIO_PCI_AD0,
854 -               .gpio_last = RT3883_GPIO_PCI_AD31,
855 -       }, {
856 -               .name = "pci-gpio",
857 -               .mask = 7,
858 -               .gpio_first = RT3883_GPIO_PCI_AD0,
859 -               .gpio_last = RT3883_GPIO_PCI_AD31,
860 -       }, {0}
861 +static struct rt2880_pmx_group rt3883_pinmux_data[] = {
862 +       GRP("i2c", i2c_func, 1, RT3883_GPIO_MODE_I2C),
863 +       GRP("spi", spi_func, 1, RT3883_GPIO_MODE_SPI),
864 +       GRP("uartf", uartf_func, RT3883_GPIO_MODE_UART0_MASK,
865 +               RT3883_GPIO_MODE_UART0_SHIFT),
866 +       GRP("uartlite", uartlite_func, 1, RT3883_GPIO_MODE_UART1),
867 +       GRP("jtag", jtag_func, 1, RT3883_GPIO_MODE_JTAG),
868 +       GRP("mdio", mdio_func, 1, RT3883_GPIO_MODE_MDIO),
869 +       GRP("lna a", lna_a_func, 1, RT3883_GPIO_MODE_LNA_A),
870 +       GRP("lna g", lna_g_func, 1, RT3883_GPIO_MODE_LNA_G),
871 +       GRP("pci", pci_func, RT3883_GPIO_MODE_PCI_MASK,
872 +               RT3883_GPIO_MODE_PCI_SHIFT),
873 +       GRP("ge1", ge1_func, 1, RT3883_GPIO_MODE_GE1),
874 +       GRP("ge2", ge2_func, 1, RT3883_GPIO_MODE_GE2),
875 +       { 0 }
876  };
877  
878  static void rt3883_wdt_reset(void)
879 @@ -155,17 +73,6 @@ static void rt3883_wdt_reset(void)
880         rt_sysc_w32(t, RT3883_SYSC_REG_SYSCFG1);
881  }
882  
883 -struct ralink_pinmux rt_gpio_pinmux = {
884 -       .mode = mode_mux,
885 -       .uart = uart_mux,
886 -       .uart_shift = RT3883_GPIO_MODE_UART0_SHIFT,
887 -       .uart_mask = RT3883_GPIO_MODE_UART0_MASK,
888 -       .wdt_reset = rt3883_wdt_reset,
889 -       .pci = pci_mux,
890 -       .pci_shift = RT3883_GPIO_MODE_PCI_SHIFT,
891 -       .pci_mask = RT3883_GPIO_MODE_PCI_MASK,
892 -};
893 -
894  void __init ralink_clk_init(void)
895  {
896         unsigned long cpu_rate, sys_rate;
897 @@ -244,4 +151,6 @@ void prom_soc_init(struct ralink_soc_inf
898         soc_info->mem_base = RT3883_SDRAM_BASE;
899         soc_info->mem_size_min = RT3883_MEM_SIZE_MIN;
900         soc_info->mem_size_max = RT3883_MEM_SIZE_MAX;
901 +
902 +       rt2880_pinmux_data = rt3883_pinmux_data;
903  }
904 --- a/drivers/pinctrl/Kconfig
905 +++ b/drivers/pinctrl/Kconfig
906 @@ -198,6 +198,11 @@ config PINCTRL_LANTIQ
907         select PINMUX
908         select PINCONF
909  
910 +config PINCTRL_RT2880
911 +       bool
912 +       depends on RALINK
913 +       select PINMUX
914 +
915  config PINCTRL_FALCON
916         bool
917         depends on SOC_FALCON
918 --- a/drivers/pinctrl/Makefile
919 +++ b/drivers/pinctrl/Makefile
920 @@ -45,6 +45,7 @@ obj-$(CONFIG_PINCTRL_DB8500)  += pinctrl-
921  obj-$(CONFIG_PINCTRL_DB8540)   += pinctrl-nomadik-db8540.o
922  obj-$(CONFIG_PINCTRL_PALMAS)   += pinctrl-palmas.o
923  obj-$(CONFIG_PINCTRL_ROCKCHIP) += pinctrl-rockchip.o
924 +obj-$(CONFIG_PINCTRL_RT2880)   += pinctrl-rt2880.o
925  obj-$(CONFIG_PINCTRL_SINGLE)   += pinctrl-single.o
926  obj-$(CONFIG_PINCTRL_SIRF)     += sirf/
927  obj-$(CONFIG_PINCTRL_SUNXI)    += pinctrl-sunxi.o
928 --- /dev/null
929 +++ b/drivers/pinctrl/pinctrl-rt2880.c
930 @@ -0,0 +1,467 @@
931 +/*
932 + *  linux/drivers/pinctrl/pinctrl-rt2880.c
933 + *
934 + *  This program is free software; you can redistribute it and/or modify
935 + *  it under the terms of the GNU General Public License version 2 as
936 + *  publishhed by the Free Software Foundation.
937 + *
938 + *  Copyright (C) 2013 John Crispin <blogic@openwrt.org>
939 + */
940 +
941 +#include <linux/module.h>
942 +#include <linux/device.h>
943 +#include <linux/io.h>
944 +#include <linux/platform_device.h>
945 +#include <linux/slab.h>
946 +#include <linux/of.h>
947 +#include <linux/pinctrl/pinctrl.h>
948 +#include <linux/pinctrl/pinconf.h>
949 +#include <linux/pinctrl/pinmux.h>
950 +#include <linux/pinctrl/consumer.h>
951 +#include <linux/pinctrl/machine.h>
952 +
953 +#include <asm/mach-ralink/ralink_regs.h>
954 +#include <asm/mach-ralink/pinmux.h>
955 +#include <asm/mach-ralink/mt7620.h>
956 +
957 +#include "core.h"
958 +
959 +#define SYSC_REG_GPIO_MODE     0x60
960 +
961 +struct rt2880_priv {
962 +       struct device *dev;
963 +
964 +       struct pinctrl_pin_desc *pads;
965 +       struct pinctrl_desc *desc;
966 +
967 +       struct rt2880_pmx_func **func;
968 +       int func_count;
969 +
970 +       struct rt2880_pmx_group *groups;
971 +       const char **group_names;
972 +       int group_count;
973 +
974 +       uint8_t *gpio;
975 +       int max_pins;
976 +};
977 +
978 +struct rt2880_pmx_group *rt2880_pinmux_data = NULL;
979 +
980 +static int rt2880_get_group_count(struct pinctrl_dev *pctrldev)
981 +{
982 +       struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev);
983 +
984 +       return p->group_count;
985 +}
986 +
987 +static const char *rt2880_get_group_name(struct pinctrl_dev *pctrldev,
988 +                                        unsigned group)
989 +{
990 +       struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev);
991 +
992 +       if (group >= p->group_count)
993 +               return NULL;
994 +
995 +       return p->group_names[group];
996 +}
997 +
998 +static int rt2880_get_group_pins(struct pinctrl_dev *pctrldev,
999 +                                unsigned group,
1000 +                                const unsigned **pins,
1001 +                                unsigned *num_pins)
1002 +{
1003 +       struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev);
1004 +
1005 +       if (group >= p->group_count)
1006 +               return -EINVAL;
1007 +
1008 +       *pins = p->groups[group].func[0].pins;
1009 +       *num_pins = p->groups[group].func[0].pin_count;
1010 +
1011 +       return 0;
1012 +}
1013 +
1014 +static void rt2880_pinctrl_dt_free_map(struct pinctrl_dev *pctrldev,
1015 +                                   struct pinctrl_map *map, unsigned num_maps)
1016 +{
1017 +       int i;
1018 +
1019 +       for (i = 0; i < num_maps; i++)
1020 +               if (map[i].type == PIN_MAP_TYPE_CONFIGS_PIN ||
1021 +                   map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP)
1022 +                       kfree(map[i].data.configs.configs);
1023 +       kfree(map);
1024 +}
1025 +
1026 +static void rt2880_pinctrl_pin_dbg_show(struct pinctrl_dev *pctrldev,
1027 +                                       struct seq_file *s,
1028 +                                       unsigned offset)
1029 +{
1030 +       seq_printf(s, "ralink pio");
1031 +}
1032 +
1033 +static void rt2880_pinctrl_dt_subnode_to_map(struct pinctrl_dev *pctrldev,
1034 +                               struct device_node *np,
1035 +                               struct pinctrl_map **map)
1036 +{
1037 +        const char *function;
1038 +       int func = of_property_read_string(np, "ralink,function", &function);
1039 +       int grps = of_property_count_strings(np, "ralink,group");
1040 +       int i;
1041 +
1042 +       if (func || !grps)
1043 +               return;
1044 +
1045 +       for (i = 0; i < grps; i++) {
1046 +               const char *group;
1047 +
1048 +               of_property_read_string_index(np, "ralink,group", i, &group);
1049 +
1050 +               (*map)->type = PIN_MAP_TYPE_MUX_GROUP;
1051 +               (*map)->name = function;
1052 +               (*map)->data.mux.group = group;
1053 +               (*map)->data.mux.function = function;
1054 +               (*map)++;
1055 +       }
1056 +}
1057 +
1058 +static int rt2880_pinctrl_dt_node_to_map(struct pinctrl_dev *pctrldev,
1059 +                               struct device_node *np_config,
1060 +                               struct pinctrl_map **map,
1061 +                               unsigned *num_maps)
1062 +{
1063 +       int max_maps = 0;
1064 +       struct pinctrl_map *tmp;
1065 +       struct device_node *np;
1066 +
1067 +       for_each_child_of_node(np_config, np) {
1068 +               int ret = of_property_count_strings(np, "ralink,group");
1069 +
1070 +               if (ret >= 0)
1071 +                       max_maps += ret;
1072 +       }
1073 +
1074 +       if (!max_maps)
1075 +               return max_maps;
1076 +
1077 +       *map = kzalloc(max_maps * sizeof(struct pinctrl_map), GFP_KERNEL);
1078 +       if (!*map)
1079 +               return -ENOMEM;
1080 +
1081 +       tmp = *map;
1082 +
1083 +       for_each_child_of_node(np_config, np)
1084 +               rt2880_pinctrl_dt_subnode_to_map(pctrldev, np, &tmp);
1085 +       *num_maps = max_maps;
1086 +
1087 +       return 0;
1088 +}
1089 +
1090 +static const struct pinctrl_ops rt2880_pctrl_ops = {
1091 +       .get_groups_count       = rt2880_get_group_count,
1092 +       .get_group_name         = rt2880_get_group_name,
1093 +       .get_group_pins         = rt2880_get_group_pins,
1094 +       .pin_dbg_show           = rt2880_pinctrl_pin_dbg_show,
1095 +       .dt_node_to_map         = rt2880_pinctrl_dt_node_to_map,
1096 +       .dt_free_map            = rt2880_pinctrl_dt_free_map,
1097 +};
1098 +
1099 +static int rt2880_pmx_func_count(struct pinctrl_dev *pctrldev)
1100 +{
1101 +       struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev);
1102 +
1103 +       return p->func_count;
1104 +}
1105 +
1106 +static const char *rt2880_pmx_func_name(struct pinctrl_dev *pctrldev,
1107 +                                        unsigned func)
1108 +{
1109 +       struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev);
1110 +
1111 +       return p->func[func]->name;
1112 +}
1113 +
1114 +static int rt2880_pmx_group_get_groups(struct pinctrl_dev *pctrldev,
1115 +                               unsigned func,
1116 +                               const char * const **groups,
1117 +                               unsigned * const num_groups)
1118 +{
1119 +       struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev);
1120 +
1121 +       if (p->func[func]->group_count == 1)
1122 +               *groups = &p->group_names[p->func[func]->groups[0]];
1123 +       else
1124 +               *groups = p->group_names;
1125 +
1126 +       *num_groups = p->func[func]->group_count;
1127 +
1128 +       return 0;
1129 +}
1130 +
1131 +static int rt2880_pmx_group_enable(struct pinctrl_dev *pctrldev,
1132 +                               unsigned func,
1133 +                               unsigned group)
1134 +{
1135 +       struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev);
1136 +        u32 mode = 0;
1137 +       int i;
1138 +
1139 +       /* dont allow double use */
1140 +       if (p->groups[group].enabled) {
1141 +               dev_err(p->dev, "%s is already enabled\n", p->groups[group].name);
1142 +               return -EBUSY;
1143 +       }
1144 +
1145 +       p->groups[group].enabled = 1;
1146 +       p->func[func]->enabled = 1;
1147 +
1148 +       mode = rt_sysc_r32(SYSC_REG_GPIO_MODE);
1149 +       mode &= ~(p->groups[group].mask << p->groups[group].shift);
1150 +
1151 +       /* mark the pins as gpio */
1152 +       for (i = 0; i < p->groups[group].func[0].pin_count; i++)
1153 +               p->gpio[p->groups[group].func[0].pins[i]] = 1;
1154 +
1155 +       /* function 0 is gpio and needs special handling */
1156 +       if (func == 0) {
1157 +               mode |= p->groups[group].gpio << p->groups[group].shift;
1158 +       } else {
1159 +               for (i = 0; i < p->func[func]->pin_count; i++)
1160 +                       p->gpio[p->func[func]->pins[i]] = 0;
1161 +               mode |= p->func[func]->value << p->groups[group].shift;
1162 +       }
1163 +       rt_sysc_w32(mode, SYSC_REG_GPIO_MODE);
1164 +
1165 +
1166 +       return 0;
1167 +}
1168 +
1169 +static int rt2880_pmx_group_gpio_request_enable(struct pinctrl_dev *pctrldev,
1170 +                               struct pinctrl_gpio_range *range,
1171 +                               unsigned pin)
1172 +{
1173 +       struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev);
1174 +
1175 +       if (!p->gpio[pin]) {
1176 +               dev_err(p->dev, "pin %d is not set to gpio mux\n", pin);
1177 +               return -EINVAL;
1178 +       }
1179 +
1180 +       return 0;
1181 +}
1182 +
1183 +static const struct pinmux_ops rt2880_pmx_group_ops = {
1184 +       .get_functions_count    = rt2880_pmx_func_count,
1185 +       .get_function_name      = rt2880_pmx_func_name,
1186 +       .get_function_groups    = rt2880_pmx_group_get_groups,
1187 +       .enable                 = rt2880_pmx_group_enable,
1188 +       .gpio_request_enable    = rt2880_pmx_group_gpio_request_enable,
1189 +};
1190 +
1191 +static struct pinctrl_desc rt2880_pctrl_desc = {
1192 +       .owner          = THIS_MODULE,
1193 +       .name           = "rt2880-pinmux",
1194 +       .pctlops        = &rt2880_pctrl_ops,
1195 +       .pmxops         = &rt2880_pmx_group_ops,
1196 +};
1197 +
1198 +static struct rt2880_pmx_func gpio_func = {
1199 +       .name = "gpio",
1200 +};
1201 +
1202 +static int rt2880_pinmux_index(struct rt2880_priv *p)
1203 +{
1204 +       struct rt2880_pmx_func **f;
1205 +       struct rt2880_pmx_group *mux = p->groups;
1206 +       int i, j, c = 0;
1207 +
1208 +       /* count the mux functions */
1209 +       while (mux->name) {
1210 +               p->group_count++;
1211 +               mux++;
1212 +       }
1213 +
1214 +       /* allocate the group names array needed by the gpio function */
1215 +       p->group_names = devm_kzalloc(p->dev, sizeof(char *) * p->group_count, GFP_KERNEL);
1216 +       if (!p->group_names)
1217 +               return -1;
1218 +
1219 +       for (i = 0; i < p->group_count; i++) {
1220 +               p->group_names[i] = p->groups[i].name;
1221 +               p->func_count += p->groups[i].func_count;
1222 +       }
1223 +
1224 +       /* we have a dummy function[0] for gpio */
1225 +       p->func_count++;
1226 +
1227 +       /* allocate our function and group mapping index buffers */
1228 +       f = p->func = devm_kzalloc(p->dev, sizeof(struct rt2880_pmx_func) * p->func_count, GFP_KERNEL);
1229 +       gpio_func.groups = devm_kzalloc(p->dev, sizeof(int) * p->group_count, GFP_KERNEL);
1230 +       if (!f || !gpio_func.groups)
1231 +               return -1;
1232 +
1233 +       /* add a backpointer to the function so it knows its group */
1234 +       gpio_func.group_count = p->group_count;
1235 +       for (i = 0; i < gpio_func.group_count; i++)
1236 +               gpio_func.groups[i] = i;
1237 +
1238 +       f[c] = &gpio_func;
1239 +       c++;
1240 +
1241 +       /* add remaining functions */
1242 +       for (i = 0; i < p->group_count; i++) {
1243 +               for (j = 0; j < p->groups[i].func_count; j++) {
1244 +                       f[c] = &p->groups[i].func[j];
1245 +                       f[c]->groups = devm_kzalloc(p->dev, sizeof(int), GFP_KERNEL);
1246 +                       f[c]->groups[0] = i;
1247 +                       f[c]->group_count = 1;
1248 +                       c++;
1249 +               }
1250 +       }
1251 +       return 0;
1252 +}
1253 +
1254 +static int rt2880_pinmux_pins(struct rt2880_priv *p)
1255 +{
1256 +       int i, j;
1257 +
1258 +       /* loop over the functions and initialize the pins array. also work out the highest pin used */
1259 +       for (i = 0; i < p->func_count; i++) {
1260 +               int pin;
1261 +
1262 +               if (!p->func[i]->pin_count)
1263 +                       continue;
1264 +
1265 +               p->func[i]->pins = devm_kzalloc(p->dev, sizeof(int) * p->func[i]->pin_count, GFP_KERNEL);
1266 +               for (j = 0; j < p->func[i]->pin_count; j++)
1267 +                       p->func[i]->pins[j] = p->func[i]->pin_first + j;
1268 +
1269 +               pin = p->func[i]->pin_first + p->func[i]->pin_count;
1270 +               if (pin > p->max_pins)
1271 +                       p->max_pins = pin;
1272 +       }
1273 +
1274 +       /* the buffer that tells us which pins are gpio */
1275 +       p->gpio = devm_kzalloc(p->dev,sizeof(uint8_t) * p->max_pins,
1276 +               GFP_KERNEL);
1277 +       /* the pads needed to tell pinctrl about our pins */
1278 +       p->pads = devm_kzalloc(p->dev,
1279 +               sizeof(struct pinctrl_pin_desc) * p->max_pins,
1280 +               GFP_KERNEL);
1281 +       if (!p->pads || !p->gpio ) {
1282 +               dev_err(p->dev, "Failed to allocate gpio data\n");
1283 +               return -ENOMEM;
1284 +       }
1285 +
1286 +       memset(p->gpio, 1, sizeof(uint8_t) * p->max_pins);
1287 +       for (i = 0; i < p->func_count; i++) {
1288 +               if (!p->func[i]->pin_count)
1289 +                       continue;
1290 +
1291 +               for (j = 0; j < p->func[i]->pin_count; j++)
1292 +                       p->gpio[p->func[i]->pins[j]] = 0;
1293 +       }
1294 +
1295 +       /* pin 0 is always a gpio */
1296 +       p->gpio[0] = 1;
1297 +
1298 +       /* set the pads */
1299 +       for (i = 0; i < p->max_pins; i++) {
1300 +               /* strlen("ioXY") + 1 = 5 */
1301 +               char *name = devm_kzalloc(p->dev, 5, GFP_KERNEL);
1302 +
1303 +               if (!name) {
1304 +                       dev_err(p->dev, "Failed to allocate pad name\n");
1305 +                       return -ENOMEM;
1306 +               }
1307 +               snprintf(name, 5, "io%d", i);
1308 +               p->pads[i].number = i;
1309 +               p->pads[i].name = name;
1310 +       }
1311 +       p->desc->pins = p->pads;
1312 +       p->desc->npins = p->max_pins;
1313 +
1314 +       return 0;
1315 +}
1316 +
1317 +static int rt2880_pinmux_probe(struct platform_device *pdev)
1318 +{
1319 +       struct rt2880_priv *p;
1320 +       struct pinctrl_dev *dev;
1321 +       struct device_node *np;
1322 +
1323 +       if (!rt2880_pinmux_data)
1324 +               return -ENOSYS;
1325 +
1326 +       /* setup the private data */
1327 +       p = devm_kzalloc(&pdev->dev, sizeof(struct rt2880_priv), GFP_KERNEL);
1328 +       if (!p)
1329 +               return -ENOMEM;
1330 +
1331 +       p->dev = &pdev->dev;
1332 +       p->desc = &rt2880_pctrl_desc;
1333 +       p->groups = rt2880_pinmux_data;
1334 +       platform_set_drvdata(pdev, p);
1335 +
1336 +       /* init the device */
1337 +       if (rt2880_pinmux_index(p)) {
1338 +               dev_err(&pdev->dev, "failed to load index\n");
1339 +               return -EINVAL;
1340 +       }
1341 +       if (rt2880_pinmux_pins(p)) {
1342 +               dev_err(&pdev->dev, "failed to load pins\n");
1343 +               return -EINVAL;
1344 +       }
1345 +       dev = pinctrl_register(p->desc, &pdev->dev, p);
1346 +       if (IS_ERR(dev))
1347 +               return PTR_ERR(dev);
1348 +
1349 +       /* finalize by adding gpio ranges for enables gpio controllers */
1350 +       for_each_compatible_node(np, NULL, "ralink,rt2880-gpio") {
1351 +               const __be32 *ngpio, *gpiobase;
1352 +               struct pinctrl_gpio_range *range;
1353 +               char *name;
1354 +
1355 +               if (!of_device_is_available(np))
1356 +                       continue;
1357 +
1358 +               ngpio = of_get_property(np, "ralink,num-gpios", NULL);
1359 +               gpiobase = of_get_property(np, "ralink,gpio-base", NULL);
1360 +               if (!ngpio || !gpiobase) {
1361 +                       dev_err(&pdev->dev, "failed to load chip info\n");
1362 +                       return -EINVAL;
1363 +               }
1364 +
1365 +               range = devm_kzalloc(p->dev, sizeof(struct pinctrl_gpio_range) + 4, GFP_KERNEL);
1366 +               range->name = name = (char *) &range[1];
1367 +               sprintf(name, "pio");
1368 +               range->npins = __be32_to_cpu(*ngpio);
1369 +               range->base = __be32_to_cpu(*gpiobase);
1370 +               range->pin_base = range->base;
1371 +               pinctrl_add_gpio_range(dev, range);
1372 +       }
1373 +
1374 +       return 0;
1375 +}
1376 +
1377 +static const struct of_device_id rt2880_pinmux_match[] = {
1378 +       { .compatible = "ralink,rt2880-pinmux" },
1379 +       {},
1380 +};
1381 +MODULE_DEVICE_TABLE(of, rt2880_pinmux_match);
1382 +
1383 +static struct platform_driver rt2880_pinmux_driver = {
1384 +       .probe = rt2880_pinmux_probe,
1385 +       .driver = {
1386 +               .name = "rt2880-pinmux",
1387 +               .owner = THIS_MODULE,
1388 +               .of_match_table = rt2880_pinmux_match,
1389 +       },
1390 +};
1391 +
1392 +int __init rt2880_pinmux_init(void)
1393 +{
1394 +       return platform_driver_register(&rt2880_pinmux_driver);
1395 +}
1396 +
1397 +core_initcall_sync(rt2880_pinmux_init);