pinctrl-xway.c 25 KB

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