pinctrl-xway.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. /*
  2. * linux/drivers/pinctrl/pinmux-xway.c
  3. * based on linux/drivers/pinctrl/pinmux-pxa910.c
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * publishhed by the Free Software Foundation.
  8. *
  9. * Copyright (C) 2012 John Crispin <blogic@openwrt.org>
  10. */
  11. #include <linux/err.h>
  12. #include <linux/slab.h>
  13. #include <linux/module.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/of_address.h>
  16. #include <linux/of_gpio.h>
  17. #include <linux/ioport.h>
  18. #include <linux/io.h>
  19. #include <linux/device.h>
  20. #include <linux/platform_device.h>
  21. #include "pinctrl-lantiq.h"
  22. #include <lantiq_soc.h>
  23. /* we have 3 1/2 banks of 16 bit each */
  24. #define PINS 16
  25. #define PORT3 3
  26. #define PORT(x) (x / PINS)
  27. #define PORT_PIN(x) (x % PINS)
  28. /* we have 2 mux bits that can be set for each pin */
  29. #define MUX_ALT0 0x1
  30. #define MUX_ALT1 0x2
  31. /*
  32. * each bank has this offset apart from the 1/2 bank that is mixed into the
  33. * other 3 ranges
  34. */
  35. #define REG_OFF 0x30
  36. /* these are the offsets to our registers */
  37. #define GPIO_BASE(p) (REG_OFF * PORT(p))
  38. #define GPIO_OUT(p) GPIO_BASE(p)
  39. #define GPIO_IN(p) (GPIO_BASE(p) + 0x04)
  40. #define GPIO_DIR(p) (GPIO_BASE(p) + 0x08)
  41. #define GPIO_ALT0(p) (GPIO_BASE(p) + 0x0C)
  42. #define GPIO_ALT1(p) (GPIO_BASE(p) + 0x10)
  43. #define GPIO_OD(p) (GPIO_BASE(p) + 0x14)
  44. #define GPIO_PUDSEL(p) (GPIO_BASE(p) + 0x1c)
  45. #define GPIO_PUDEN(p) (GPIO_BASE(p) + 0x20)
  46. /* the 1/2 port needs special offsets for some registers */
  47. #define GPIO3_OD (GPIO_BASE(0) + 0x24)
  48. #define GPIO3_PUDSEL (GPIO_BASE(0) + 0x28)
  49. #define GPIO3_PUDEN (GPIO_BASE(0) + 0x2C)
  50. #define GPIO3_ALT1 (GPIO_BASE(PINS) + 0x24)
  51. /* macros to help us access the registers */
  52. #define gpio_getbit(m, r, p) (!!(ltq_r32(m + r) & BIT(p)))
  53. #define gpio_setbit(m, r, p) ltq_w32_mask(0, BIT(p), m + r)
  54. #define gpio_clearbit(m, r, p) ltq_w32_mask(BIT(p), 0, m + r)
  55. #define MFP_XWAY(a, f0, f1, f2, f3) \
  56. { \
  57. .name = #a, \
  58. .pin = a, \
  59. .func = { \
  60. XWAY_MUX_##f0, \
  61. XWAY_MUX_##f1, \
  62. XWAY_MUX_##f2, \
  63. XWAY_MUX_##f3, \
  64. }, \
  65. }
  66. #define GRP_MUX(a, m, p) \
  67. { .name = a, .mux = XWAY_MUX_##m, .pins = p, .npins = ARRAY_SIZE(p), }
  68. #define FUNC_MUX(f, m) \
  69. { .func = f, .mux = XWAY_MUX_##m, }
  70. #define XWAY_MAX_PIN 32
  71. #define XR9_MAX_PIN 56
  72. enum xway_mux {
  73. XWAY_MUX_GPIO = 0,
  74. XWAY_MUX_SPI,
  75. XWAY_MUX_ASC,
  76. XWAY_MUX_PCI,
  77. XWAY_MUX_CGU,
  78. XWAY_MUX_EBU,
  79. XWAY_MUX_JTAG,
  80. XWAY_MUX_EXIN,
  81. XWAY_MUX_TDM,
  82. XWAY_MUX_STP,
  83. XWAY_MUX_SIN,
  84. XWAY_MUX_GPT,
  85. XWAY_MUX_NMI,
  86. XWAY_MUX_MDIO,
  87. XWAY_MUX_MII,
  88. XWAY_MUX_EPHY,
  89. XWAY_MUX_DFE,
  90. XWAY_MUX_SDIO,
  91. XWAY_MUX_GPHY,
  92. XWAY_MUX_NONE = 0xffff,
  93. };
  94. static const struct ltq_mfp_pin xway_mfp[] = {
  95. /* pin f0 f1 f2 f3 */
  96. MFP_XWAY(GPIO0, GPIO, EXIN, NONE, TDM),
  97. MFP_XWAY(GPIO1, GPIO, EXIN, NONE, NONE),
  98. MFP_XWAY(GPIO2, GPIO, CGU, EXIN, GPHY),
  99. MFP_XWAY(GPIO3, GPIO, CGU, NONE, PCI),
  100. MFP_XWAY(GPIO4, GPIO, STP, NONE, ASC),
  101. MFP_XWAY(GPIO5, GPIO, STP, NONE, GPHY),
  102. MFP_XWAY(GPIO6, GPIO, STP, GPT, ASC),
  103. MFP_XWAY(GPIO7, GPIO, CGU, PCI, GPHY),
  104. MFP_XWAY(GPIO8, GPIO, CGU, NMI, NONE),
  105. MFP_XWAY(GPIO9, GPIO, ASC, SPI, EXIN),
  106. MFP_XWAY(GPIO10, GPIO, ASC, SPI, NONE),
  107. MFP_XWAY(GPIO11, GPIO, ASC, PCI, SPI),
  108. MFP_XWAY(GPIO12, GPIO, ASC, NONE, NONE),
  109. MFP_XWAY(GPIO13, GPIO, EBU, SPI, NONE),
  110. MFP_XWAY(GPIO14, GPIO, CGU, PCI, NONE),
  111. MFP_XWAY(GPIO15, GPIO, SPI, JTAG, NONE),
  112. MFP_XWAY(GPIO16, GPIO, SPI, NONE, JTAG),
  113. MFP_XWAY(GPIO17, GPIO, SPI, NONE, JTAG),
  114. MFP_XWAY(GPIO18, GPIO, SPI, NONE, JTAG),
  115. MFP_XWAY(GPIO19, GPIO, PCI, NONE, NONE),
  116. MFP_XWAY(GPIO20, GPIO, JTAG, NONE, NONE),
  117. MFP_XWAY(GPIO21, GPIO, PCI, EBU, GPT),
  118. MFP_XWAY(GPIO22, GPIO, SPI, NONE, NONE),
  119. MFP_XWAY(GPIO23, GPIO, EBU, PCI, STP),
  120. MFP_XWAY(GPIO24, GPIO, EBU, TDM, PCI),
  121. MFP_XWAY(GPIO25, GPIO, TDM, NONE, ASC),
  122. MFP_XWAY(GPIO26, GPIO, EBU, NONE, TDM),
  123. MFP_XWAY(GPIO27, GPIO, TDM, NONE, ASC),
  124. MFP_XWAY(GPIO28, GPIO, GPT, NONE, NONE),
  125. MFP_XWAY(GPIO29, GPIO, PCI, NONE, NONE),
  126. MFP_XWAY(GPIO30, GPIO, PCI, NONE, NONE),
  127. MFP_XWAY(GPIO31, GPIO, EBU, PCI, NONE),
  128. MFP_XWAY(GPIO32, GPIO, NONE, NONE, EBU),
  129. MFP_XWAY(GPIO33, GPIO, NONE, NONE, EBU),
  130. MFP_XWAY(GPIO34, GPIO, NONE, NONE, EBU),
  131. MFP_XWAY(GPIO35, GPIO, NONE, NONE, EBU),
  132. MFP_XWAY(GPIO36, GPIO, SIN, NONE, EBU),
  133. MFP_XWAY(GPIO37, GPIO, PCI, NONE, NONE),
  134. MFP_XWAY(GPIO38, GPIO, PCI, NONE, NONE),
  135. MFP_XWAY(GPIO39, GPIO, EXIN, NONE, NONE),
  136. MFP_XWAY(GPIO40, GPIO, NONE, NONE, NONE),
  137. MFP_XWAY(GPIO41, GPIO, NONE, NONE, NONE),
  138. MFP_XWAY(GPIO42, GPIO, MDIO, NONE, NONE),
  139. MFP_XWAY(GPIO43, GPIO, MDIO, NONE, NONE),
  140. MFP_XWAY(GPIO44, GPIO, NONE, GPHY, SIN),
  141. MFP_XWAY(GPIO45, GPIO, NONE, GPHY, SIN),
  142. MFP_XWAY(GPIO46, GPIO, NONE, NONE, EXIN),
  143. MFP_XWAY(GPIO47, GPIO, NONE, GPHY, SIN),
  144. MFP_XWAY(GPIO48, GPIO, EBU, NONE, NONE),
  145. MFP_XWAY(GPIO49, GPIO, EBU, NONE, NONE),
  146. MFP_XWAY(GPIO50, GPIO, NONE, NONE, NONE),
  147. MFP_XWAY(GPIO51, GPIO, NONE, NONE, NONE),
  148. MFP_XWAY(GPIO52, GPIO, NONE, NONE, NONE),
  149. MFP_XWAY(GPIO53, GPIO, NONE, NONE, NONE),
  150. MFP_XWAY(GPIO54, GPIO, NONE, NONE, NONE),
  151. MFP_XWAY(GPIO55, GPIO, NONE, NONE, NONE),
  152. };
  153. static const struct ltq_mfp_pin ase_mfp[] = {
  154. /* pin f0 f1 f2 f3 */
  155. MFP_XWAY(GPIO0, GPIO, EXIN, MII, TDM),
  156. MFP_XWAY(GPIO1, GPIO, STP, DFE, EBU),
  157. MFP_XWAY(GPIO2, GPIO, STP, DFE, EPHY),
  158. MFP_XWAY(GPIO3, GPIO, STP, EPHY, EBU),
  159. MFP_XWAY(GPIO4, GPIO, GPT, EPHY, MII),
  160. MFP_XWAY(GPIO5, GPIO, MII, ASC, GPT),
  161. MFP_XWAY(GPIO6, GPIO, MII, ASC, EXIN),
  162. MFP_XWAY(GPIO7, GPIO, SPI, MII, JTAG),
  163. MFP_XWAY(GPIO8, GPIO, SPI, MII, JTAG),
  164. MFP_XWAY(GPIO9, GPIO, SPI, MII, JTAG),
  165. MFP_XWAY(GPIO10, GPIO, SPI, MII, JTAG),
  166. MFP_XWAY(GPIO11, GPIO, EBU, CGU, JTAG),
  167. MFP_XWAY(GPIO12, GPIO, EBU, MII, SDIO),
  168. MFP_XWAY(GPIO13, GPIO, EBU, MII, CGU),
  169. MFP_XWAY(GPIO14, GPIO, EBU, SPI, CGU),
  170. MFP_XWAY(GPIO15, GPIO, EBU, SPI, SDIO),
  171. MFP_XWAY(GPIO16, GPIO, NONE, NONE, NONE),
  172. MFP_XWAY(GPIO17, GPIO, NONE, NONE, NONE),
  173. MFP_XWAY(GPIO18, GPIO, NONE, NONE, NONE),
  174. MFP_XWAY(GPIO19, GPIO, EBU, MII, SDIO),
  175. MFP_XWAY(GPIO20, GPIO, EBU, MII, SDIO),
  176. MFP_XWAY(GPIO21, GPIO, EBU, MII, SDIO),
  177. MFP_XWAY(GPIO22, GPIO, EBU, MII, CGU),
  178. MFP_XWAY(GPIO23, GPIO, EBU, MII, CGU),
  179. MFP_XWAY(GPIO24, GPIO, EBU, NONE, MII),
  180. MFP_XWAY(GPIO25, GPIO, EBU, MII, GPT),
  181. MFP_XWAY(GPIO26, GPIO, EBU, MII, SDIO),
  182. MFP_XWAY(GPIO27, GPIO, EBU, NONE, MII),
  183. MFP_XWAY(GPIO28, GPIO, MII, EBU, SDIO),
  184. MFP_XWAY(GPIO29, GPIO, EBU, MII, EXIN),
  185. MFP_XWAY(GPIO30, GPIO, NONE, NONE, NONE),
  186. MFP_XWAY(GPIO31, GPIO, NONE, NONE, NONE),
  187. };
  188. static const unsigned pins_jtag[] = {GPIO15, GPIO16, GPIO17, GPIO19, GPIO35};
  189. static const unsigned pins_asc0[] = {GPIO11, GPIO12};
  190. static const unsigned pins_asc0_cts_rts[] = {GPIO9, GPIO10};
  191. static const unsigned pins_stp[] = {GPIO4, GPIO5, GPIO6};
  192. static const unsigned pins_nmi[] = {GPIO8};
  193. static const unsigned pins_mdio[] = {GPIO42, GPIO43};
  194. static const unsigned pins_gphy0_led0[] = {GPIO5};
  195. static const unsigned pins_gphy0_led1[] = {GPIO7};
  196. static const unsigned pins_gphy0_led2[] = {GPIO2};
  197. static const unsigned pins_gphy1_led0[] = {GPIO44};
  198. static const unsigned pins_gphy1_led1[] = {GPIO45};
  199. static const unsigned pins_gphy1_led2[] = {GPIO47};
  200. static const unsigned pins_ebu_a24[] = {GPIO13};
  201. static const unsigned pins_ebu_clk[] = {GPIO21};
  202. static const unsigned pins_ebu_cs1[] = {GPIO23};
  203. static const unsigned pins_ebu_a23[] = {GPIO24};
  204. static const unsigned pins_ebu_wait[] = {GPIO26};
  205. static const unsigned pins_ebu_a25[] = {GPIO31};
  206. static const unsigned pins_ebu_rdy[] = {GPIO48};
  207. static const unsigned pins_ebu_rd[] = {GPIO49};
  208. static const unsigned pins_nand_ale[] = {GPIO13};
  209. static const unsigned pins_nand_cs1[] = {GPIO23};
  210. static const unsigned pins_nand_cle[] = {GPIO24};
  211. static const unsigned pins_nand_rdy[] = {GPIO48};
  212. static const unsigned pins_nand_rd[] = {GPIO49};
  213. static const unsigned pins_exin0[] = {GPIO0};
  214. static const unsigned pins_exin1[] = {GPIO1};
  215. static const unsigned pins_exin2[] = {GPIO2};
  216. static const unsigned pins_exin3[] = {GPIO39};
  217. static const unsigned pins_exin4[] = {GPIO46};
  218. static const unsigned pins_exin5[] = {GPIO9};
  219. static const unsigned pins_spi[] = {GPIO16, GPIO17, GPIO18};
  220. static const unsigned pins_spi_cs1[] = {GPIO15};
  221. static const unsigned pins_spi_cs2[] = {GPIO21};
  222. static const unsigned pins_spi_cs3[] = {GPIO13};
  223. static const unsigned pins_spi_cs4[] = {GPIO10};
  224. static const unsigned pins_spi_cs5[] = {GPIO9};
  225. static const unsigned pins_spi_cs6[] = {GPIO11};
  226. static const unsigned pins_gpt1[] = {GPIO28};
  227. static const unsigned pins_gpt2[] = {GPIO21};
  228. static const unsigned pins_gpt3[] = {GPIO6};
  229. static const unsigned pins_clkout0[] = {GPIO8};
  230. static const unsigned pins_clkout1[] = {GPIO7};
  231. static const unsigned pins_clkout2[] = {GPIO3};
  232. static const unsigned pins_clkout3[] = {GPIO2};
  233. static const unsigned pins_pci_gnt1[] = {GPIO30};
  234. static const unsigned pins_pci_gnt2[] = {GPIO23};
  235. static const unsigned pins_pci_gnt3[] = {GPIO19};
  236. static const unsigned pins_pci_gnt4[] = {GPIO38};
  237. static const unsigned pins_pci_req1[] = {GPIO29};
  238. static const unsigned pins_pci_req2[] = {GPIO31};
  239. static const unsigned pins_pci_req3[] = {GPIO3};
  240. static const unsigned pins_pci_req4[] = {GPIO37};
  241. static const unsigned ase_pins_jtag[] = {GPIO7, GPIO8, GPIO9, GPIO10, GPIO11};
  242. static const unsigned ase_pins_asc[] = {GPIO5, GPIO6};
  243. static const unsigned ase_pins_stp[] = {GPIO1, GPIO2, GPIO3};
  244. static const unsigned ase_pins_ephy[] = {GPIO2, GPIO3, GPIO4};
  245. static const unsigned ase_pins_dfe[] = {GPIO1, GPIO2};
  246. static const unsigned ase_pins_spi[] = {GPIO8, GPIO9, GPIO10};
  247. static const unsigned ase_pins_spi_cs1[] = {GPIO7};
  248. static const unsigned ase_pins_spi_cs2[] = {GPIO15};
  249. static const unsigned ase_pins_spi_cs3[] = {GPIO14};
  250. static const unsigned ase_pins_exin0[] = {GPIO6};
  251. static const unsigned ase_pins_exin1[] = {GPIO29};
  252. static const unsigned ase_pins_exin2[] = {GPIO0};
  253. static const unsigned ase_pins_gpt1[] = {GPIO5};
  254. static const unsigned ase_pins_gpt2[] = {GPIO4};
  255. static const unsigned ase_pins_gpt3[] = {GPIO25};
  256. static const struct ltq_pin_group xway_grps[] = {
  257. GRP_MUX("exin0", EXIN, pins_exin0),
  258. GRP_MUX("exin1", EXIN, pins_exin1),
  259. GRP_MUX("exin2", EXIN, pins_exin2),
  260. GRP_MUX("jtag", JTAG, pins_jtag),
  261. GRP_MUX("ebu a23", EBU, pins_ebu_a23),
  262. GRP_MUX("ebu a24", EBU, pins_ebu_a24),
  263. GRP_MUX("ebu a25", EBU, pins_ebu_a25),
  264. GRP_MUX("ebu clk", EBU, pins_ebu_clk),
  265. GRP_MUX("ebu cs1", EBU, pins_ebu_cs1),
  266. GRP_MUX("ebu wait", EBU, pins_ebu_wait),
  267. GRP_MUX("nand ale", EBU, pins_nand_ale),
  268. GRP_MUX("nand cs1", EBU, pins_nand_cs1),
  269. GRP_MUX("nand cle", EBU, pins_nand_cle),
  270. GRP_MUX("spi", SPI, pins_spi),
  271. GRP_MUX("spi_cs1", SPI, pins_spi_cs1),
  272. GRP_MUX("spi_cs2", SPI, pins_spi_cs2),
  273. GRP_MUX("spi_cs3", SPI, pins_spi_cs3),
  274. GRP_MUX("spi_cs4", SPI, pins_spi_cs4),
  275. GRP_MUX("spi_cs5", SPI, pins_spi_cs5),
  276. GRP_MUX("spi_cs6", SPI, pins_spi_cs6),
  277. GRP_MUX("asc0", ASC, pins_asc0),
  278. GRP_MUX("asc0 cts rts", ASC, pins_asc0_cts_rts),
  279. GRP_MUX("stp", STP, pins_stp),
  280. GRP_MUX("nmi", NMI, pins_nmi),
  281. GRP_MUX("gpt1", GPT, pins_gpt1),
  282. GRP_MUX("gpt2", GPT, pins_gpt2),
  283. GRP_MUX("gpt3", GPT, pins_gpt3),
  284. GRP_MUX("clkout0", CGU, pins_clkout0),
  285. GRP_MUX("clkout1", CGU, pins_clkout1),
  286. GRP_MUX("clkout2", CGU, pins_clkout2),
  287. GRP_MUX("clkout3", CGU, pins_clkout3),
  288. GRP_MUX("gnt1", PCI, pins_pci_gnt1),
  289. GRP_MUX("gnt2", PCI, pins_pci_gnt2),
  290. GRP_MUX("gnt3", PCI, pins_pci_gnt3),
  291. GRP_MUX("req1", PCI, pins_pci_req1),
  292. GRP_MUX("req2", PCI, pins_pci_req2),
  293. GRP_MUX("req3", PCI, pins_pci_req3),
  294. /* xrx only */
  295. GRP_MUX("nand rdy", EBU, pins_nand_rdy),
  296. GRP_MUX("nand rd", EBU, pins_nand_rd),
  297. GRP_MUX("exin3", EXIN, pins_exin3),
  298. GRP_MUX("exin4", EXIN, pins_exin4),
  299. GRP_MUX("exin5", EXIN, pins_exin5),
  300. GRP_MUX("gnt4", PCI, pins_pci_gnt4),
  301. GRP_MUX("req4", PCI, pins_pci_gnt4),
  302. GRP_MUX("mdio", MDIO, pins_mdio),
  303. GRP_MUX("gphy0 led0", GPHY, pins_gphy0_led0),
  304. GRP_MUX("gphy0 led1", GPHY, pins_gphy0_led1),
  305. GRP_MUX("gphy0 led2", GPHY, pins_gphy0_led2),
  306. GRP_MUX("gphy1 led0", GPHY, pins_gphy1_led0),
  307. GRP_MUX("gphy1 led1", GPHY, pins_gphy1_led1),
  308. GRP_MUX("gphy1 led2", GPHY, pins_gphy1_led2),
  309. };
  310. static const struct ltq_pin_group ase_grps[] = {
  311. GRP_MUX("exin0", EXIN, ase_pins_exin0),
  312. GRP_MUX("exin1", EXIN, ase_pins_exin1),
  313. GRP_MUX("exin2", EXIN, ase_pins_exin2),
  314. GRP_MUX("jtag", JTAG, ase_pins_jtag),
  315. GRP_MUX("stp", STP, ase_pins_stp),
  316. GRP_MUX("asc", ASC, ase_pins_asc),
  317. GRP_MUX("gpt1", GPT, ase_pins_gpt1),
  318. GRP_MUX("gpt2", GPT, ase_pins_gpt2),
  319. GRP_MUX("gpt3", GPT, ase_pins_gpt3),
  320. GRP_MUX("ephy", EPHY, ase_pins_ephy),
  321. GRP_MUX("dfe", DFE, ase_pins_dfe),
  322. GRP_MUX("spi", SPI, ase_pins_spi),
  323. GRP_MUX("spi_cs1", SPI, ase_pins_spi_cs1),
  324. GRP_MUX("spi_cs2", SPI, ase_pins_spi_cs2),
  325. GRP_MUX("spi_cs3", SPI, ase_pins_spi_cs3),
  326. };
  327. static const char * const xway_pci_grps[] = {"gnt1", "gnt2",
  328. "gnt3", "req1",
  329. "req2", "req3"};
  330. static const char * const xway_spi_grps[] = {"spi", "spi_cs1",
  331. "spi_cs2", "spi_cs3",
  332. "spi_cs4", "spi_cs5",
  333. "spi_cs6"};
  334. static const char * const xway_cgu_grps[] = {"clkout0", "clkout1",
  335. "clkout2", "clkout3"};
  336. static const char * const xway_ebu_grps[] = {"ebu a23", "ebu a24",
  337. "ebu a25", "ebu cs1",
  338. "ebu wait", "ebu clk",
  339. "nand ale", "nand cs1",
  340. "nand cle"};
  341. static const char * const xway_exin_grps[] = {"exin0", "exin1", "exin2"};
  342. static const char * const xway_gpt_grps[] = {"gpt1", "gpt2", "gpt3"};
  343. static const char * const xway_asc_grps[] = {"asc0", "asc0 cts rts"};
  344. static const char * const xway_jtag_grps[] = {"jtag"};
  345. static const char * const xway_stp_grps[] = {"stp"};
  346. static const char * const xway_nmi_grps[] = {"nmi"};
  347. /* ar9/vr9/gr9 */
  348. static const char * const xrx_mdio_grps[] = {"mdio"};
  349. static const char * const xrx_gphy_grps[] = {"gphy0 led0", "gphy0 led1",
  350. "gphy0 led2", "gphy1 led0",
  351. "gphy1 led1", "gphy1 led2"};
  352. static const char * const xrx_ebu_grps[] = {"ebu a23", "ebu a24",
  353. "ebu a25", "ebu cs1",
  354. "ebu wait", "ebu clk",
  355. "nand ale", "nand cs1",
  356. "nand cle", "nand rdy",
  357. "nand rd"};
  358. static const char * const xrx_exin_grps[] = {"exin0", "exin1", "exin2",
  359. "exin3", "exin4", "exin5"};
  360. static const char * const xrx_pci_grps[] = {"gnt1", "gnt2",
  361. "gnt3", "gnt4",
  362. "req1", "req2",
  363. "req3", "req4"};
  364. /* ase */
  365. static const char * const ase_exin_grps[] = {"exin0", "exin1", "exin2"};
  366. static const char * const ase_gpt_grps[] = {"gpt1", "gpt2", "gpt3"};
  367. static const char * const ase_dfe_grps[] = {"dfe"};
  368. static const char * const ase_ephy_grps[] = {"ephy"};
  369. static const char * const ase_asc_grps[] = {"asc"};
  370. static const char * const ase_jtag_grps[] = {"jtag"};
  371. static const char * const ase_stp_grps[] = {"stp"};
  372. static const char * const ase_spi_grps[] = {"spi", "spi_cs1",
  373. "spi_cs2", "spi_cs3"};
  374. static const struct ltq_pmx_func danube_funcs[] = {
  375. {"spi", ARRAY_AND_SIZE(xway_spi_grps)},
  376. {"asc", ARRAY_AND_SIZE(xway_asc_grps)},
  377. {"cgu", ARRAY_AND_SIZE(xway_cgu_grps)},
  378. {"jtag", ARRAY_AND_SIZE(xway_jtag_grps)},
  379. {"exin", ARRAY_AND_SIZE(xway_exin_grps)},
  380. {"stp", ARRAY_AND_SIZE(xway_stp_grps)},
  381. {"gpt", ARRAY_AND_SIZE(xway_gpt_grps)},
  382. {"nmi", ARRAY_AND_SIZE(xway_nmi_grps)},
  383. {"pci", ARRAY_AND_SIZE(xway_pci_grps)},
  384. {"ebu", ARRAY_AND_SIZE(xway_ebu_grps)},
  385. };
  386. static const struct ltq_pmx_func xrx_funcs[] = {
  387. {"spi", ARRAY_AND_SIZE(xway_spi_grps)},
  388. {"asc", ARRAY_AND_SIZE(xway_asc_grps)},
  389. {"cgu", ARRAY_AND_SIZE(xway_cgu_grps)},
  390. {"jtag", ARRAY_AND_SIZE(xway_jtag_grps)},
  391. {"exin", ARRAY_AND_SIZE(xrx_exin_grps)},
  392. {"stp", ARRAY_AND_SIZE(xway_stp_grps)},
  393. {"gpt", ARRAY_AND_SIZE(xway_gpt_grps)},
  394. {"nmi", ARRAY_AND_SIZE(xway_nmi_grps)},
  395. {"pci", ARRAY_AND_SIZE(xrx_pci_grps)},
  396. {"ebu", ARRAY_AND_SIZE(xrx_ebu_grps)},
  397. {"mdio", ARRAY_AND_SIZE(xrx_mdio_grps)},
  398. {"gphy", ARRAY_AND_SIZE(xrx_gphy_grps)},
  399. };
  400. static const struct ltq_pmx_func ase_funcs[] = {
  401. {"spi", ARRAY_AND_SIZE(ase_spi_grps)},
  402. {"asc", ARRAY_AND_SIZE(ase_asc_grps)},
  403. {"jtag", ARRAY_AND_SIZE(ase_jtag_grps)},
  404. {"exin", ARRAY_AND_SIZE(ase_exin_grps)},
  405. {"stp", ARRAY_AND_SIZE(ase_stp_grps)},
  406. {"gpt", ARRAY_AND_SIZE(ase_gpt_grps)},
  407. {"ephy", ARRAY_AND_SIZE(ase_ephy_grps)},
  408. {"dfe", ARRAY_AND_SIZE(ase_dfe_grps)},
  409. };
  410. /* --------- pinconf related code --------- */
  411. static int xway_pinconf_get(struct pinctrl_dev *pctldev,
  412. unsigned pin,
  413. unsigned long *config)
  414. {
  415. struct ltq_pinmux_info *info = pinctrl_dev_get_drvdata(pctldev);
  416. enum ltq_pinconf_param param = LTQ_PINCONF_UNPACK_PARAM(*config);
  417. int port = PORT(pin);
  418. u32 reg;
  419. switch (param) {
  420. case LTQ_PINCONF_PARAM_OPEN_DRAIN:
  421. if (port == PORT3)
  422. reg = GPIO3_OD;
  423. else
  424. reg = GPIO_OD(pin);
  425. *config = LTQ_PINCONF_PACK(param,
  426. !gpio_getbit(info->membase[0], reg, PORT_PIN(pin)));
  427. break;
  428. case LTQ_PINCONF_PARAM_PULL:
  429. if (port == PORT3)
  430. reg = GPIO3_PUDEN;
  431. else
  432. reg = GPIO_PUDEN(pin);
  433. if (!gpio_getbit(info->membase[0], reg, PORT_PIN(pin))) {
  434. *config = LTQ_PINCONF_PACK(param, 0);
  435. break;
  436. }
  437. if (port == PORT3)
  438. reg = GPIO3_PUDSEL;
  439. else
  440. reg = GPIO_PUDSEL(pin);
  441. if (!gpio_getbit(info->membase[0], reg, PORT_PIN(pin)))
  442. *config = LTQ_PINCONF_PACK(param, 2);
  443. else
  444. *config = LTQ_PINCONF_PACK(param, 1);
  445. break;
  446. case LTQ_PINCONF_PARAM_OUTPUT:
  447. reg = GPIO_DIR(pin);
  448. *config = LTQ_PINCONF_PACK(param,
  449. gpio_getbit(info->membase[0], reg, PORT_PIN(pin)));
  450. break;
  451. default:
  452. dev_err(pctldev->dev, "Invalid config param %04x\n", param);
  453. return -ENOTSUPP;
  454. }
  455. return 0;
  456. }
  457. static int xway_pinconf_set(struct pinctrl_dev *pctldev,
  458. unsigned pin,
  459. unsigned long *configs,
  460. unsigned num_configs)
  461. {
  462. struct ltq_pinmux_info *info = pinctrl_dev_get_drvdata(pctldev);
  463. enum ltq_pinconf_param param;
  464. int arg;
  465. int port = PORT(pin);
  466. u32 reg;
  467. int i;
  468. for (i = 0; i < num_configs; i++) {
  469. param = LTQ_PINCONF_UNPACK_PARAM(configs[i]);
  470. arg = LTQ_PINCONF_UNPACK_ARG(configs[i]);
  471. switch (param) {
  472. case LTQ_PINCONF_PARAM_OPEN_DRAIN:
  473. if (port == PORT3)
  474. reg = GPIO3_OD;
  475. else
  476. reg = GPIO_OD(pin);
  477. if (arg == 0)
  478. gpio_setbit(info->membase[0],
  479. reg,
  480. PORT_PIN(pin));
  481. else
  482. gpio_clearbit(info->membase[0],
  483. reg,
  484. PORT_PIN(pin));
  485. break;
  486. case LTQ_PINCONF_PARAM_PULL:
  487. if (port == PORT3)
  488. reg = GPIO3_PUDEN;
  489. else
  490. reg = GPIO_PUDEN(pin);
  491. if (arg == 0) {
  492. gpio_clearbit(info->membase[0],
  493. reg,
  494. PORT_PIN(pin));
  495. break;
  496. }
  497. gpio_setbit(info->membase[0], reg, PORT_PIN(pin));
  498. if (port == PORT3)
  499. reg = GPIO3_PUDSEL;
  500. else
  501. reg = GPIO_PUDSEL(pin);
  502. if (arg == 1)
  503. gpio_clearbit(info->membase[0],
  504. reg,
  505. PORT_PIN(pin));
  506. else if (arg == 2)
  507. gpio_setbit(info->membase[0],
  508. reg,
  509. PORT_PIN(pin));
  510. else
  511. dev_err(pctldev->dev,
  512. "Invalid pull value %d\n", arg);
  513. break;
  514. case LTQ_PINCONF_PARAM_OUTPUT:
  515. reg = GPIO_DIR(pin);
  516. if (arg == 0)
  517. gpio_clearbit(info->membase[0],
  518. reg,
  519. PORT_PIN(pin));
  520. else
  521. gpio_setbit(info->membase[0],
  522. reg,
  523. PORT_PIN(pin));
  524. break;
  525. default:
  526. dev_err(pctldev->dev,
  527. "Invalid config param %04x\n", param);
  528. return -ENOTSUPP;
  529. }
  530. } /* for each config */
  531. return 0;
  532. }
  533. int xway_pinconf_group_set(struct pinctrl_dev *pctldev,
  534. unsigned selector,
  535. unsigned long *configs,
  536. unsigned num_configs)
  537. {
  538. struct ltq_pinmux_info *info = pinctrl_dev_get_drvdata(pctldev);
  539. int i, ret = 0;
  540. for (i = 0; i < info->grps[selector].npins && !ret; i++)
  541. ret = xway_pinconf_set(pctldev,
  542. info->grps[selector].pins[i],
  543. configs,
  544. num_configs);
  545. return ret;
  546. }
  547. static const struct pinconf_ops xway_pinconf_ops = {
  548. .pin_config_get = xway_pinconf_get,
  549. .pin_config_set = xway_pinconf_set,
  550. .pin_config_group_set = xway_pinconf_group_set,
  551. };
  552. static struct pinctrl_desc xway_pctrl_desc = {
  553. .owner = THIS_MODULE,
  554. .confops = &xway_pinconf_ops,
  555. };
  556. static inline int xway_mux_apply(struct pinctrl_dev *pctrldev,
  557. int pin, int mux)
  558. {
  559. struct ltq_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev);
  560. int port = PORT(pin);
  561. u32 alt1_reg = GPIO_ALT1(pin);
  562. if (port == PORT3)
  563. alt1_reg = GPIO3_ALT1;
  564. if (mux & MUX_ALT0)
  565. gpio_setbit(info->membase[0], GPIO_ALT0(pin), PORT_PIN(pin));
  566. else
  567. gpio_clearbit(info->membase[0], GPIO_ALT0(pin), PORT_PIN(pin));
  568. if (mux & MUX_ALT1)
  569. gpio_setbit(info->membase[0], alt1_reg, PORT_PIN(pin));
  570. else
  571. gpio_clearbit(info->membase[0], alt1_reg, PORT_PIN(pin));
  572. return 0;
  573. }
  574. static const struct ltq_cfg_param xway_cfg_params[] = {
  575. {"lantiq,pull", LTQ_PINCONF_PARAM_PULL},
  576. {"lantiq,open-drain", LTQ_PINCONF_PARAM_OPEN_DRAIN},
  577. {"lantiq,output", LTQ_PINCONF_PARAM_OUTPUT},
  578. };
  579. static struct ltq_pinmux_info xway_info = {
  580. .desc = &xway_pctrl_desc,
  581. .apply_mux = xway_mux_apply,
  582. .params = xway_cfg_params,
  583. .num_params = ARRAY_SIZE(xway_cfg_params),
  584. };
  585. /* --------- gpio_chip related code --------- */
  586. static void xway_gpio_set(struct gpio_chip *chip, unsigned int pin, int val)
  587. {
  588. struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev);
  589. if (val)
  590. gpio_setbit(info->membase[0], GPIO_OUT(pin), PORT_PIN(pin));
  591. else
  592. gpio_clearbit(info->membase[0], GPIO_OUT(pin), PORT_PIN(pin));
  593. }
  594. static int xway_gpio_get(struct gpio_chip *chip, unsigned int pin)
  595. {
  596. struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev);
  597. return gpio_getbit(info->membase[0], GPIO_IN(pin), PORT_PIN(pin));
  598. }
  599. static int xway_gpio_dir_in(struct gpio_chip *chip, unsigned int pin)
  600. {
  601. struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev);
  602. gpio_clearbit(info->membase[0], GPIO_DIR(pin), PORT_PIN(pin));
  603. return 0;
  604. }
  605. static int xway_gpio_dir_out(struct gpio_chip *chip, unsigned int pin, int val)
  606. {
  607. struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev);
  608. gpio_setbit(info->membase[0], GPIO_DIR(pin), PORT_PIN(pin));
  609. xway_gpio_set(chip, pin, val);
  610. return 0;
  611. }
  612. static struct gpio_chip xway_chip = {
  613. .label = "gpio-xway",
  614. .direction_input = xway_gpio_dir_in,
  615. .direction_output = xway_gpio_dir_out,
  616. .get = xway_gpio_get,
  617. .set = xway_gpio_set,
  618. .request = gpiochip_generic_request,
  619. .free = gpiochip_generic_free,
  620. .base = -1,
  621. };
  622. /* --------- register the pinctrl layer --------- */
  623. static const unsigned xway_exin_pin_map[] = {GPIO0, GPIO1, GPIO2, GPIO39, GPIO46, GPIO9};
  624. static const unsigned ase_exin_pins_map[] = {GPIO6, GPIO29, GPIO0};
  625. static struct pinctrl_xway_soc {
  626. int pin_count;
  627. const struct ltq_mfp_pin *mfp;
  628. const struct ltq_pin_group *grps;
  629. unsigned int num_grps;
  630. const struct ltq_pmx_func *funcs;
  631. unsigned int num_funcs;
  632. const unsigned *exin;
  633. unsigned int num_exin;
  634. } soc_cfg[] = {
  635. /* legacy xway */
  636. {XWAY_MAX_PIN, xway_mfp,
  637. xway_grps, ARRAY_SIZE(xway_grps),
  638. danube_funcs, ARRAY_SIZE(danube_funcs),
  639. xway_exin_pin_map, 3},
  640. /* xway xr9 series */
  641. {XR9_MAX_PIN, xway_mfp,
  642. xway_grps, ARRAY_SIZE(xway_grps),
  643. xrx_funcs, ARRAY_SIZE(xrx_funcs),
  644. xway_exin_pin_map, 6},
  645. /* xway ase series */
  646. {XWAY_MAX_PIN, ase_mfp,
  647. ase_grps, ARRAY_SIZE(ase_grps),
  648. ase_funcs, ARRAY_SIZE(ase_funcs),
  649. ase_exin_pins_map, 3},
  650. };
  651. static struct pinctrl_gpio_range xway_gpio_range = {
  652. .name = "XWAY GPIO",
  653. .gc = &xway_chip,
  654. };
  655. static const struct of_device_id xway_match[] = {
  656. { .compatible = "lantiq,pinctrl-xway", .data = &soc_cfg[0]},
  657. { .compatible = "lantiq,pinctrl-xr9", .data = &soc_cfg[1]},
  658. { .compatible = "lantiq,pinctrl-ase", .data = &soc_cfg[2]},
  659. {},
  660. };
  661. MODULE_DEVICE_TABLE(of, xway_match);
  662. static int pinmux_xway_probe(struct platform_device *pdev)
  663. {
  664. const struct of_device_id *match;
  665. const struct pinctrl_xway_soc *xway_soc;
  666. struct resource *res;
  667. int ret, i;
  668. /* get and remap our register range */
  669. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  670. xway_info.membase[0] = devm_ioremap_resource(&pdev->dev, res);
  671. if (IS_ERR(xway_info.membase[0]))
  672. return PTR_ERR(xway_info.membase[0]);
  673. match = of_match_device(xway_match, &pdev->dev);
  674. if (match)
  675. xway_soc = (const struct pinctrl_xway_soc *) match->data;
  676. else
  677. xway_soc = &soc_cfg[0];
  678. /* find out how many pads we have */
  679. xway_chip.ngpio = xway_soc->pin_count;
  680. /* load our pad descriptors */
  681. xway_info.pads = devm_kzalloc(&pdev->dev,
  682. sizeof(struct pinctrl_pin_desc) * xway_chip.ngpio,
  683. GFP_KERNEL);
  684. if (!xway_info.pads) {
  685. dev_err(&pdev->dev, "Failed to allocate pads\n");
  686. return -ENOMEM;
  687. }
  688. for (i = 0; i < xway_chip.ngpio; i++) {
  689. /* strlen("ioXY") + 1 = 5 */
  690. char *name = devm_kzalloc(&pdev->dev, 5, GFP_KERNEL);
  691. if (!name) {
  692. dev_err(&pdev->dev, "Failed to allocate pad name\n");
  693. return -ENOMEM;
  694. }
  695. snprintf(name, 5, "io%d", i);
  696. xway_info.pads[i].number = GPIO0 + i;
  697. xway_info.pads[i].name = name;
  698. }
  699. xway_pctrl_desc.pins = xway_info.pads;
  700. /* load the gpio chip */
  701. xway_chip.dev = &pdev->dev;
  702. ret = gpiochip_add(&xway_chip);
  703. if (ret) {
  704. dev_err(&pdev->dev, "Failed to register gpio chip\n");
  705. return ret;
  706. }
  707. /* setup the data needed by pinctrl */
  708. xway_pctrl_desc.name = dev_name(&pdev->dev);
  709. xway_pctrl_desc.npins = xway_chip.ngpio;
  710. xway_info.num_pads = xway_chip.ngpio;
  711. xway_info.num_mfp = xway_chip.ngpio;
  712. xway_info.mfp = xway_soc->mfp;
  713. xway_info.grps = xway_soc->grps;
  714. xway_info.num_grps = xway_soc->num_grps;
  715. xway_info.funcs = xway_soc->funcs;
  716. xway_info.num_funcs = xway_soc->num_funcs;
  717. xway_info.exin = xway_soc->exin;
  718. xway_info.num_exin = xway_soc->num_exin;
  719. /* register with the generic lantiq layer */
  720. ret = ltq_pinctrl_register(pdev, &xway_info);
  721. if (ret) {
  722. gpiochip_remove(&xway_chip);
  723. dev_err(&pdev->dev, "Failed to register pinctrl driver\n");
  724. return ret;
  725. }
  726. /* finish with registering the gpio range in pinctrl */
  727. xway_gpio_range.npins = xway_chip.ngpio;
  728. xway_gpio_range.base = xway_chip.base;
  729. pinctrl_add_gpio_range(xway_info.pctrl, &xway_gpio_range);
  730. dev_info(&pdev->dev, "Init done\n");
  731. return 0;
  732. }
  733. static struct platform_driver pinmux_xway_driver = {
  734. .probe = pinmux_xway_probe,
  735. .driver = {
  736. .name = "pinctrl-xway",
  737. .of_match_table = xway_match,
  738. },
  739. };
  740. static int __init pinmux_xway_init(void)
  741. {
  742. return platform_driver_register(&pinmux_xway_driver);
  743. }
  744. core_initcall_sync(pinmux_xway_init);