pinctrl-xway.c 24 KB

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