0030-pinctrl-ralink-add-pinctrl-driver.patch 41 KB

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