pinctrl-xway.c 24 KB

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