pinctrl-lpc18xx.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  1. /*
  2. * Pinctrl driver for NXP LPC18xx/LPC43xx System Control Unit (SCU)
  3. *
  4. * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/bitops.h>
  11. #include <linux/clk.h>
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/of.h>
  15. #include <linux/of_device.h>
  16. #include <linux/pinctrl/pinctrl.h>
  17. #include <linux/pinctrl/pinmux.h>
  18. #include <linux/pinctrl/pinconf-generic.h>
  19. #include "core.h"
  20. #include "pinctrl-utils.h"
  21. /* LPC18XX SCU analog function registers */
  22. #define LPC18XX_SCU_REG_ENAIO0 0xc88
  23. #define LPC18XX_SCU_REG_ENAIO1 0xc8c
  24. #define LPC18XX_SCU_REG_ENAIO2 0xc90
  25. #define LPC18XX_SCU_REG_ENAIO2_DAC BIT(0)
  26. /* LPC18XX SCU pin register definitions */
  27. #define LPC18XX_SCU_PIN_MODE_MASK 0x7
  28. #define LPC18XX_SCU_PIN_EPD BIT(3)
  29. #define LPC18XX_SCU_PIN_EPUN BIT(4)
  30. #define LPC18XX_SCU_PIN_EHS BIT(5)
  31. #define LPC18XX_SCU_PIN_EZI BIT(6)
  32. #define LPC18XX_SCU_PIN_ZIF BIT(7)
  33. #define LPC18XX_SCU_PIN_EHD_MASK 0x300
  34. #define LPC18XX_SCU_PIN_EHD_POS 8
  35. #define LPC18XX_SCU_USB1_EPD BIT(2)
  36. #define LPC18XX_SCU_USB1_EPWR BIT(4)
  37. #define LPC18XX_SCU_I2C0_EFP BIT(0)
  38. #define LPC18XX_SCU_I2C0_EHD BIT(2)
  39. #define LPC18XX_SCU_I2C0_EZI BIT(3)
  40. #define LPC18XX_SCU_I2C0_ZIF BIT(7)
  41. #define LPC18XX_SCU_I2C0_SCL_SHIFT 0
  42. #define LPC18XX_SCU_I2C0_SDA_SHIFT 8
  43. #define LPC18XX_SCU_FUNC_PER_PIN 8
  44. /* LPC18xx pin types */
  45. enum {
  46. TYPE_ND, /* Normal-drive */
  47. TYPE_HD, /* High-drive */
  48. TYPE_HS, /* High-speed */
  49. TYPE_I2C0,
  50. TYPE_USB1,
  51. };
  52. /* LPC18xx pin functions */
  53. enum {
  54. FUNC_R, /* Reserved */
  55. FUNC_ADC,
  56. FUNC_ADCTRIG,
  57. FUNC_CAN0,
  58. FUNC_CAN1,
  59. FUNC_CGU_OUT,
  60. FUNC_CLKIN,
  61. FUNC_CLKOUT,
  62. FUNC_CTIN,
  63. FUNC_CTOUT,
  64. FUNC_DAC,
  65. FUNC_EMC,
  66. FUNC_EMC_ALT,
  67. FUNC_ENET,
  68. FUNC_ENET_ALT,
  69. FUNC_GPIO,
  70. FUNC_I2C0,
  71. FUNC_I2C1,
  72. FUNC_I2S0_RX_MCLK,
  73. FUNC_I2S0_RX_SCK,
  74. FUNC_I2S0_RX_SDA,
  75. FUNC_I2S0_RX_WS,
  76. FUNC_I2S0_TX_MCLK,
  77. FUNC_I2S0_TX_SCK,
  78. FUNC_I2S0_TX_SDA,
  79. FUNC_I2S0_TX_WS,
  80. FUNC_I2S1,
  81. FUNC_LCD,
  82. FUNC_LCD_ALT,
  83. FUNC_MCTRL,
  84. FUNC_NMI,
  85. FUNC_QEI,
  86. FUNC_SDMMC,
  87. FUNC_SGPIO,
  88. FUNC_SPI,
  89. FUNC_SPIFI,
  90. FUNC_SSP0,
  91. FUNC_SSP0_ALT,
  92. FUNC_SSP1,
  93. FUNC_TIMER0,
  94. FUNC_TIMER1,
  95. FUNC_TIMER2,
  96. FUNC_TIMER3,
  97. FUNC_TRACE,
  98. FUNC_UART0,
  99. FUNC_UART1,
  100. FUNC_UART2,
  101. FUNC_UART3,
  102. FUNC_USB0,
  103. FUNC_USB1,
  104. FUNC_MAX
  105. };
  106. static const char *const lpc18xx_function_names[] = {
  107. [FUNC_R] = "reserved",
  108. [FUNC_ADC] = "adc",
  109. [FUNC_ADCTRIG] = "adctrig",
  110. [FUNC_CAN0] = "can0",
  111. [FUNC_CAN1] = "can1",
  112. [FUNC_CGU_OUT] = "cgu_out",
  113. [FUNC_CLKIN] = "clkin",
  114. [FUNC_CLKOUT] = "clkout",
  115. [FUNC_CTIN] = "ctin",
  116. [FUNC_CTOUT] = "ctout",
  117. [FUNC_DAC] = "dac",
  118. [FUNC_EMC] = "emc",
  119. [FUNC_EMC_ALT] = "emc_alt",
  120. [FUNC_ENET] = "enet",
  121. [FUNC_ENET_ALT] = "enet_alt",
  122. [FUNC_GPIO] = "gpio",
  123. [FUNC_I2C0] = "i2c0",
  124. [FUNC_I2C1] = "i2c1",
  125. [FUNC_I2S0_RX_MCLK] = "i2s0_rx_mclk",
  126. [FUNC_I2S0_RX_SCK] = "i2s0_rx_sck",
  127. [FUNC_I2S0_RX_SDA] = "i2s0_rx_sda",
  128. [FUNC_I2S0_RX_WS] = "i2s0_rx_ws",
  129. [FUNC_I2S0_TX_MCLK] = "i2s0_tx_mclk",
  130. [FUNC_I2S0_TX_SCK] = "i2s0_tx_sck",
  131. [FUNC_I2S0_TX_SDA] = "i2s0_tx_sda",
  132. [FUNC_I2S0_TX_WS] = "i2s0_tx_ws",
  133. [FUNC_I2S1] = "i2s1",
  134. [FUNC_LCD] = "lcd",
  135. [FUNC_LCD_ALT] = "lcd_alt",
  136. [FUNC_MCTRL] = "mctrl",
  137. [FUNC_NMI] = "nmi",
  138. [FUNC_QEI] = "qei",
  139. [FUNC_SDMMC] = "sdmmc",
  140. [FUNC_SGPIO] = "sgpio",
  141. [FUNC_SPI] = "spi",
  142. [FUNC_SPIFI] = "spifi",
  143. [FUNC_SSP0] = "ssp0",
  144. [FUNC_SSP0_ALT] = "ssp0_alt",
  145. [FUNC_SSP1] = "ssp1",
  146. [FUNC_TIMER0] = "timer0",
  147. [FUNC_TIMER1] = "timer1",
  148. [FUNC_TIMER2] = "timer2",
  149. [FUNC_TIMER3] = "timer3",
  150. [FUNC_TRACE] = "trace",
  151. [FUNC_UART0] = "uart0",
  152. [FUNC_UART1] = "uart1",
  153. [FUNC_UART2] = "uart2",
  154. [FUNC_UART3] = "uart3",
  155. [FUNC_USB0] = "usb0",
  156. [FUNC_USB1] = "usb1",
  157. };
  158. struct lpc18xx_pmx_func {
  159. const char **groups;
  160. unsigned ngroups;
  161. };
  162. struct lpc18xx_scu_data {
  163. struct pinctrl_dev *pctl;
  164. void __iomem *base;
  165. struct clk *clk;
  166. struct lpc18xx_pmx_func func[FUNC_MAX];
  167. };
  168. struct lpc18xx_pin_caps {
  169. unsigned int offset;
  170. unsigned char functions[LPC18XX_SCU_FUNC_PER_PIN];
  171. unsigned char analog;
  172. unsigned char type;
  173. };
  174. /* Analog pins are required to have both bias and input disabled */
  175. #define LPC18XX_SCU_ANALOG_PIN_CFG 0x10
  176. /* Macros to maniupluate analog member in lpc18xx_pin_caps */
  177. #define LPC18XX_ANALOG_PIN BIT(7)
  178. #define LPC18XX_ANALOG_ADC(a) ((a >> 5) & 0x3)
  179. #define LPC18XX_ANALOG_BIT_MASK 0x1f
  180. #define ADC0 (LPC18XX_ANALOG_PIN | (0x00 << 5))
  181. #define ADC1 (LPC18XX_ANALOG_PIN | (0x01 << 5))
  182. #define DAC LPC18XX_ANALOG_PIN
  183. #define LPC_P(port, pin, f0, f1, f2, f3, f4, f5, f6, f7, a, t) \
  184. static struct lpc18xx_pin_caps lpc18xx_pin_p##port##_##pin = { \
  185. .offset = 0x##port * 32 * 4 + pin * 4, \
  186. .functions = { \
  187. FUNC_##f0, FUNC_##f1, FUNC_##f2, \
  188. FUNC_##f3, FUNC_##f4, FUNC_##f5, \
  189. FUNC_##f6, FUNC_##f7, \
  190. }, \
  191. .analog = a, \
  192. .type = TYPE_##t, \
  193. }
  194. #define LPC_N(pname, off, f0, f1, f2, f3, f4, f5, f6, f7, a, t) \
  195. static struct lpc18xx_pin_caps lpc18xx_pin_##pname = { \
  196. .offset = off, \
  197. .functions = { \
  198. FUNC_##f0, FUNC_##f1, FUNC_##f2, \
  199. FUNC_##f3, FUNC_##f4, FUNC_##f5, \
  200. FUNC_##f6, FUNC_##f7, \
  201. }, \
  202. .analog = a, \
  203. .type = TYPE_##t, \
  204. }
  205. /* Pinmuxing table taken from data sheet */
  206. /* Pin FUNC0 FUNC1 FUNC2 FUNC3 FUNC4 FUNC5 FUNC6 FUNC7 ANALOG TYPE */
  207. LPC_P(0,0, GPIO, SSP1, ENET, SGPIO, R, R, I2S0_TX_WS,I2S1, 0, ND);
  208. LPC_P(0,1, GPIO, SSP1,ENET_ALT,SGPIO, R, R, ENET, I2S1, 0, ND);
  209. LPC_P(1,0, GPIO, CTIN, EMC, R, R, SSP0, SGPIO, R, 0, ND);
  210. LPC_P(1,1, GPIO, CTOUT, EMC, SGPIO, R, SSP0, R, R, 0, ND);
  211. LPC_P(1,2, GPIO, CTOUT, EMC, SGPIO, R, SSP0, R, R, 0, ND);
  212. LPC_P(1,3, GPIO, CTOUT, SGPIO, EMC, USB0, SSP1, R, SDMMC, 0, ND);
  213. LPC_P(1,4, GPIO, CTOUT, SGPIO, EMC, USB0, SSP1, R, SDMMC, 0, ND);
  214. LPC_P(1,5, GPIO, CTOUT, R, EMC, USB0, SSP1, SGPIO, SDMMC, 0, ND);
  215. LPC_P(1,6, GPIO, CTIN, R, EMC, R, R, SGPIO, SDMMC, 0, ND);
  216. LPC_P(1,7, GPIO, UART1, CTOUT, EMC, USB0, R, R, R, 0, ND);
  217. LPC_P(1,8, GPIO, UART1, CTOUT, EMC, R, R, R, SDMMC, 0, ND);
  218. LPC_P(1,9, GPIO, UART1, CTOUT, EMC, R, R, R, SDMMC, 0, ND);
  219. LPC_P(1,10, GPIO, UART1, CTOUT, EMC, R, R, R, SDMMC, 0, ND);
  220. LPC_P(1,11, GPIO, UART1, CTOUT, EMC, R, R, R, SDMMC, 0, ND);
  221. LPC_P(1,12, GPIO, UART1, R, EMC, TIMER0, R, SGPIO, SDMMC, 0, ND);
  222. LPC_P(1,13, GPIO, UART1, R, EMC, TIMER0, R, SGPIO, SDMMC, 0, ND);
  223. LPC_P(1,14, GPIO, UART1, R, EMC, TIMER0, R, SGPIO, R, 0, ND);
  224. LPC_P(1,15, GPIO, UART2, SGPIO, ENET, TIMER0, R, R, R, 0, ND);
  225. LPC_P(1,16, GPIO, UART2, SGPIO,ENET_ALT,TIMER0, R, R, ENET, 0, ND);
  226. LPC_P(1,17, GPIO, UART2, R, ENET, TIMER0, CAN1, SGPIO, R, 0, HD);
  227. LPC_P(1,18, GPIO, UART2, R, ENET, TIMER0, CAN1, SGPIO, R, 0, ND);
  228. LPC_P(1,19, ENET, SSP1, R, R, CLKOUT, R, I2S0_RX_MCLK,I2S1, 0, ND);
  229. LPC_P(1,20, GPIO, SSP1, R, ENET, TIMER0, R, SGPIO, R, 0, ND);
  230. LPC_P(2,0, SGPIO, UART0, EMC, USB0, GPIO, R, TIMER3, ENET, 0, ND);
  231. LPC_P(2,1, SGPIO, UART0, EMC, USB0, GPIO, R, TIMER3, R, 0, ND);
  232. LPC_P(2,2, SGPIO, UART0, EMC, USB0, GPIO, CTIN, TIMER3, R, 0, ND);
  233. LPC_P(2,3, SGPIO, I2C1, UART3, CTIN, GPIO, R, TIMER3, USB0, 0, HD);
  234. LPC_P(2,4, SGPIO, I2C1, UART3, CTIN, GPIO, R, TIMER3, USB0, 0, HD);
  235. LPC_P(2,5, SGPIO, CTIN, USB1, ADCTRIG, GPIO, R, TIMER3, USB0, 0, HD);
  236. LPC_P(2,6, SGPIO, UART0, EMC, USB0, GPIO, CTIN, TIMER3, R, 0, ND);
  237. LPC_P(2,7, GPIO, CTOUT, UART3, EMC, R, R, TIMER3, R, 0, ND);
  238. LPC_P(2,8, SGPIO, CTOUT, UART3, EMC, GPIO, R, R, R, 0, ND);
  239. LPC_P(2,9, GPIO, CTOUT, UART3, EMC, R, R, R, R, 0, ND);
  240. LPC_P(2,10, GPIO, CTOUT, UART2, EMC, R, R, R, R, 0, ND);
  241. LPC_P(2,11, GPIO, CTOUT, UART2, EMC, R, R, R, R, 0, ND);
  242. LPC_P(2,12, GPIO, CTOUT, R, EMC, R, R, R, UART2, 0, ND);
  243. LPC_P(2,13, GPIO, CTIN, R, EMC, R, R, R, UART2, 0, ND);
  244. LPC_P(3,0, I2S0_RX_SCK, I2S0_RX_MCLK, I2S0_TX_SCK, I2S0_TX_MCLK,SSP0,R,R,R, 0, ND);
  245. LPC_P(3,1, I2S0_TX_WS, I2S0_RX_WS,CAN0,USB1,GPIO, R, LCD, R, 0, ND);
  246. LPC_P(3,2, I2S0_TX_SDA, I2S0_RX_SDA,CAN0,USB1,GPIO, R, LCD, R, 0, ND);
  247. LPC_P(3,3, R, SPI, SSP0, SPIFI, CGU_OUT,R, I2S0_TX_MCLK, I2S1, 0, HS);
  248. LPC_P(3,4, GPIO, R, R, SPIFI, UART1, I2S0_TX_WS, I2S1, LCD, 0, ND);
  249. LPC_P(3,5, GPIO, R, R, SPIFI, UART1, I2S0_TX_SDA,I2S1, LCD, 0, ND);
  250. LPC_P(3,6, GPIO, SPI, SSP0, SPIFI, R, SSP0_ALT, R, R, 0, ND);
  251. LPC_P(3,7, R, SPI, SSP0, SPIFI, GPIO, SSP0_ALT, R, R, 0, ND);
  252. LPC_P(3,8, R, SPI, SSP0, SPIFI, GPIO, SSP0_ALT, R, R, 0, ND);
  253. LPC_P(4,0, GPIO, MCTRL, NMI, R, R, LCD, UART3, R, 0, ND);
  254. LPC_P(4,1, GPIO, CTOUT, LCD, R, R, LCD_ALT, UART3, ENET, ADC0|1, ND);
  255. LPC_P(4,2, GPIO, CTOUT, LCD, R, R, LCD_ALT, UART3, SGPIO, 0, ND);
  256. LPC_P(4,3, GPIO, CTOUT, LCD, R, R, LCD_ALT, UART3, SGPIO, ADC0|0, ND);
  257. LPC_P(4,4, GPIO, CTOUT, LCD, R, R, LCD_ALT, UART3, SGPIO, DAC, ND);
  258. LPC_P(4,5, GPIO, CTOUT, LCD, R, R, R, R, SGPIO, 0, ND);
  259. LPC_P(4,6, GPIO, CTOUT, LCD, R, R, R, R, SGPIO, 0, ND);
  260. LPC_P(4,7, LCD, CLKIN, R, R, R, R, I2S1,I2S0_TX_SCK, 0, ND);
  261. LPC_P(4,8, R, CTIN, LCD, R, GPIO, LCD_ALT, CAN1, SGPIO, 0, ND);
  262. LPC_P(4,9, R, CTIN, LCD, R, GPIO, LCD_ALT, CAN1, SGPIO, 0, ND);
  263. LPC_P(4,10, R, CTIN, LCD, R, GPIO, LCD_ALT, R, SGPIO, 0, ND);
  264. LPC_P(5,0, GPIO, MCTRL, EMC, R, UART1, TIMER1, R, R, 0, ND);
  265. LPC_P(5,1, GPIO, MCTRL, EMC, R, UART1, TIMER1, R, R, 0, ND);
  266. LPC_P(5,2, GPIO, MCTRL, EMC, R, UART1, TIMER1, R, R, 0, ND);
  267. LPC_P(5,3, GPIO, MCTRL, EMC, R, UART1, TIMER1, R, R, 0, ND);
  268. LPC_P(5,4, GPIO, MCTRL, EMC, R, UART1, TIMER1, R, R, 0, ND);
  269. LPC_P(5,5, GPIO, MCTRL, EMC, R, UART1, TIMER1, R, R, 0, ND);
  270. LPC_P(5,6, GPIO, MCTRL, EMC, R, UART1, TIMER1, R, R, 0, ND);
  271. LPC_P(5,7, GPIO, MCTRL, EMC, R, UART1, TIMER1, R, R, 0, ND);
  272. LPC_P(6,0, R, I2S0_RX_MCLK,R, R, I2S0_RX_SCK, R, R, R, 0, ND);
  273. LPC_P(6,1, GPIO, EMC, UART0, I2S0_RX_WS, R, TIMER2, R, R, 0, ND);
  274. LPC_P(6,2, GPIO, EMC, UART0, I2S0_RX_SDA, R, TIMER2, R, R, 0, ND);
  275. LPC_P(6,3, GPIO, USB0, SGPIO, EMC, R, TIMER2, R, R, 0, ND);
  276. LPC_P(6,4, GPIO, CTIN, UART0, EMC, R, R, R, R, 0, ND);
  277. LPC_P(6,5, GPIO, CTOUT, UART0, EMC, R, R, R, R, 0, ND);
  278. LPC_P(6,6, GPIO, EMC, SGPIO, USB0, R, TIMER2, R, R, 0, ND);
  279. LPC_P(6,7, R, EMC, SGPIO, USB0, GPIO, TIMER2, R, R, 0, ND);
  280. LPC_P(6,8, R, EMC, SGPIO, USB0, GPIO, TIMER2, R, R, 0, ND);
  281. LPC_P(6,9, GPIO, R, R, EMC, R, TIMER2, R, R, 0, ND);
  282. LPC_P(6,10, GPIO, MCTRL, R, EMC, R, R, R, R, 0, ND);
  283. LPC_P(6,11, GPIO, R, R, EMC, R, TIMER2, R, R, 0, ND);
  284. LPC_P(6,12, GPIO, CTOUT, R, EMC, R, R, R, R, 0, ND);
  285. LPC_P(7,0, GPIO, CTOUT, R, LCD, R, R, R, SGPIO, 0, ND);
  286. LPC_P(7,1, GPIO, CTOUT,I2S0_TX_WS,LCD,LCD_ALT, R, UART2, SGPIO, 0, ND);
  287. LPC_P(7,2, GPIO, CTIN,I2S0_TX_SDA,LCD,LCD_ALT, R, UART2, SGPIO, 0, ND);
  288. LPC_P(7,3, GPIO, CTIN, R, LCD,LCD_ALT, R, R, R, 0, ND);
  289. LPC_P(7,4, GPIO, CTOUT, R, LCD,LCD_ALT, TRACE, R, R, ADC0|4, ND);
  290. LPC_P(7,5, GPIO, CTOUT, R, LCD,LCD_ALT, TRACE, R, R, ADC0|3, ND);
  291. LPC_P(7,6, GPIO, CTOUT, R, LCD, R, TRACE, R, R, 0, ND);
  292. LPC_P(7,7, GPIO, CTOUT, R, LCD, R, TRACE, ENET, SGPIO, ADC1|6, ND);
  293. LPC_P(8,0, GPIO, USB0, R, MCTRL, SGPIO, R, R, TIMER0, 0, HD);
  294. LPC_P(8,1, GPIO, USB0, R, MCTRL, SGPIO, R, R, TIMER0, 0, HD);
  295. LPC_P(8,2, GPIO, USB0, R, MCTRL, SGPIO, R, R, TIMER0, 0, HD);
  296. LPC_P(8,3, GPIO, USB1, R, LCD, LCD_ALT, R, R, TIMER0, 0, ND);
  297. LPC_P(8,4, GPIO, USB1, R, LCD, LCD_ALT, R, R, TIMER0, 0, ND);
  298. LPC_P(8,5, GPIO, USB1, R, LCD, LCD_ALT, R, R, TIMER0, 0, ND);
  299. LPC_P(8,6, GPIO, USB1, R, LCD, LCD_ALT, R, R, TIMER0, 0, ND);
  300. LPC_P(8,7, GPIO, USB1, R, LCD, LCD_ALT, R, R, TIMER0, 0, ND);
  301. LPC_P(8,8, R, USB1, R, R, R, R,CGU_OUT, I2S1, 0, ND);
  302. LPC_P(9,0, GPIO, MCTRL, R, R, R, ENET, SGPIO, SSP0, 0, ND);
  303. LPC_P(9,1, GPIO, MCTRL, R, R, I2S0_TX_WS,ENET, SGPIO, SSP0, 0, ND);
  304. LPC_P(9,2, GPIO, MCTRL, R, R, I2S0_TX_SDA,ENET,SGPIO, SSP0, 0, ND);
  305. LPC_P(9,3, GPIO, MCTRL, USB1, R, R, ENET, SGPIO, UART3, 0, ND);
  306. LPC_P(9,4, R, MCTRL, USB1, R, GPIO, ENET, SGPIO, UART3, 0, ND);
  307. LPC_P(9,5, R, MCTRL, USB1, R, GPIO, ENET, SGPIO, UART0, 0, ND);
  308. LPC_P(9,6, GPIO, MCTRL, USB1, R, R, ENET, SGPIO, UART0, 0, ND);
  309. LPC_P(a,0, R, R, R, R, R, I2S1, CGU_OUT, R, 0, ND);
  310. LPC_P(a,1, GPIO, QEI, R, UART2, R, R, R, R, 0, HD);
  311. LPC_P(a,2, GPIO, QEI, R, UART2, R, R, R, R, 0, HD);
  312. LPC_P(a,3, GPIO, QEI, R, R, R, R, R, R, 0, HD);
  313. LPC_P(a,4, R, CTOUT, R, EMC, GPIO, R, R, R, 0, ND);
  314. LPC_P(b,0, R, CTOUT, LCD, R, GPIO, R, R, R, 0, ND);
  315. LPC_P(b,1, R, USB1, LCD, R, GPIO, CTOUT, R, R, 0, ND);
  316. LPC_P(b,2, R, USB1, LCD, R, GPIO, CTOUT, R, R, 0, ND);
  317. LPC_P(b,3, R, USB1, LCD, R, GPIO, CTOUT, R, R, 0, ND);
  318. LPC_P(b,4, R, USB1, LCD, R, GPIO, CTIN, R, R, 0, ND);
  319. LPC_P(b,5, R, USB1, LCD, R, GPIO, CTIN, LCD_ALT, R, 0, ND);
  320. LPC_P(b,6, R, USB1, LCD, R, GPIO, CTIN, LCD_ALT, R, ADC0|6, ND);
  321. LPC_P(c,0, R, USB1, R, ENET, LCD, R, R, SDMMC, ADC1|1, ND);
  322. LPC_P(c,1, USB1, R, UART1, ENET, GPIO, R, TIMER3, SDMMC, 0, ND);
  323. LPC_P(c,2, USB1, R, UART1, ENET, GPIO, R, R, SDMMC, 0, ND);
  324. LPC_P(c,3, USB1, R, UART1, ENET, GPIO, R, R, SDMMC, ADC1|0, ND);
  325. LPC_P(c,4, R, USB1, R, ENET, GPIO, R, TIMER3, SDMMC, 0, ND);
  326. LPC_P(c,5, R, USB1, R, ENET, GPIO, R, TIMER3, SDMMC, 0, ND);
  327. LPC_P(c,6, R, USB1, R, ENET, GPIO, R, TIMER3, SDMMC, 0, ND);
  328. LPC_P(c,7, R, USB1, R, ENET, GPIO, R, TIMER3, SDMMC, 0, ND);
  329. LPC_P(c,8, R, USB1, R, ENET, GPIO, R, TIMER3, SDMMC, 0, ND);
  330. LPC_P(c,9, R, USB1, R, ENET, GPIO, R, TIMER3, SDMMC, 0, ND);
  331. LPC_P(c,10, R, USB1, UART1, R, GPIO, R, TIMER3, SDMMC, 0, ND);
  332. LPC_P(c,11, R, USB1, UART1, R, GPIO, R, R, SDMMC, 0, ND);
  333. LPC_P(c,12, R, R, UART1, R, GPIO, SGPIO, I2S0_TX_SDA,SDMMC, 0, ND);
  334. LPC_P(c,13, R, R, UART1, R, GPIO, SGPIO, I2S0_TX_WS, SDMMC, 0, ND);
  335. LPC_P(c,14, R, R, UART1, R, GPIO, SGPIO, ENET, SDMMC, 0, ND);
  336. LPC_P(d,0, R, CTOUT, EMC, R, GPIO, R, R, SGPIO, 0, ND);
  337. LPC_P(d,1, R, R, EMC, R, GPIO, SDMMC, R, SGPIO, 0, ND);
  338. LPC_P(d,2, R, CTOUT, EMC, R, GPIO, R, R, SGPIO, 0, ND);
  339. LPC_P(d,3, R, CTOUT, EMC, R, GPIO, R, R, SGPIO, 0, ND);
  340. LPC_P(d,4, R, CTOUT, EMC, R, GPIO, R, R, SGPIO, 0, ND);
  341. LPC_P(d,5, R, CTOUT, EMC, R, GPIO, R, R, SGPIO, 0, ND);
  342. LPC_P(d,6, R, CTOUT, EMC, R, GPIO, R, R, SGPIO, 0, ND);
  343. LPC_P(d,7, R, CTIN, EMC, R, GPIO, R, R, SGPIO, 0, ND);
  344. LPC_P(d,8, R, CTIN, EMC, R, GPIO, R, R, SGPIO, 0, ND);
  345. LPC_P(d,9, R, CTOUT, EMC, R, GPIO, R, R, SGPIO, 0, ND);
  346. LPC_P(d,10, R, CTIN, EMC, R, GPIO, R, R, R, 0, ND);
  347. LPC_P(d,11, R, R, EMC, R, GPIO, USB1, CTOUT, R, 0, ND);
  348. LPC_P(d,12, R, R, EMC, R, GPIO, R, CTOUT, R, 0, ND);
  349. LPC_P(d,13, R, CTIN, EMC, R, GPIO, R, CTOUT, R, 0, ND);
  350. LPC_P(d,14, R, R, EMC, R, GPIO, R, CTOUT, R, 0, ND);
  351. LPC_P(d,15, R, R, EMC, R, GPIO, SDMMC, CTOUT, R, 0, ND);
  352. LPC_P(d,16, R, R, EMC, R, GPIO, SDMMC, CTOUT, R, 0, ND);
  353. LPC_P(e,0, R, R, R, EMC, GPIO, CAN1, R, R, 0, ND);
  354. LPC_P(e,1, R, R, R, EMC, GPIO, CAN1, R, R, 0, ND);
  355. LPC_P(e,2,ADCTRIG, CAN0, R, EMC, GPIO, R, R, R, 0, ND);
  356. LPC_P(e,3, R, CAN0,ADCTRIG, EMC, GPIO, R, R, R, 0, ND);
  357. LPC_P(e,4, R, NMI, R, EMC, GPIO, R, R, R, 0, ND);
  358. LPC_P(e,5, R, CTOUT, UART1, EMC, GPIO, R, R, R, 0, ND);
  359. LPC_P(e,6, R, CTOUT, UART1, EMC, GPIO, R, R, R, 0, ND);
  360. LPC_P(e,7, R, CTOUT, UART1, EMC, GPIO, R, R, R, 0, ND);
  361. LPC_P(e,8, R, CTOUT, UART1, EMC, GPIO, R, R, R, 0, ND);
  362. LPC_P(e,9, R, CTIN, UART1, EMC, GPIO, R, R, R, 0, ND);
  363. LPC_P(e,10, R, CTIN, UART1, EMC, GPIO, R, R, R, 0, ND);
  364. LPC_P(e,11, R, CTOUT, UART1, EMC, GPIO, R, R, R, 0, ND);
  365. LPC_P(e,12, R, CTOUT, UART1, EMC, GPIO, R, R, R, 0, ND);
  366. LPC_P(e,13, R, CTOUT, I2C1, EMC, GPIO, R, R, R, 0, ND);
  367. LPC_P(e,14, R, R, R, EMC, GPIO, R, R, R, 0, ND);
  368. LPC_P(e,15, R, CTOUT, I2C1, EMC, GPIO, R, R, R, 0, ND);
  369. LPC_P(f,0, SSP0, CLKIN, R, R, R, R, R, I2S1, 0, ND);
  370. LPC_P(f,1, R, R, SSP0, R, GPIO, R, SGPIO, R, 0, ND);
  371. LPC_P(f,2, R, UART3, SSP0, R, GPIO, R, SGPIO, R, 0, ND);
  372. LPC_P(f,3, R, UART3, SSP0, R, GPIO, R, SGPIO, R, 0, ND);
  373. LPC_P(f,4, SSP1, CLKIN, TRACE, R, R, R, I2S0_TX_MCLK,I2S0_RX_SCK, 0, ND);
  374. LPC_P(f,5, R, UART3, SSP1, TRACE, GPIO, R, SGPIO, R, ADC1|4, ND);
  375. LPC_P(f,6, R, UART3, SSP1, TRACE, GPIO, R, SGPIO, I2S1, ADC1|3, ND);
  376. LPC_P(f,7, R, UART3, SSP1, TRACE, GPIO, R, SGPIO, I2S1, ADC1|7, ND);
  377. LPC_P(f,8, R, UART0, CTIN, TRACE, GPIO, R, SGPIO, R, ADC0|2, ND);
  378. LPC_P(f,9, R, UART0, CTOUT, R, GPIO, R, SGPIO, R, ADC1|2, ND);
  379. LPC_P(f,10, R, UART0, R, R, GPIO, R, SDMMC, R, ADC0|5, ND);
  380. LPC_P(f,11, R, UART0, R, R, GPIO, R, SDMMC, R, ADC1|5, ND);
  381. /* Pin Offset FUNC0 FUNC1 FUNC2 FUNC3 FUNC4 FUNC5 FUNC6 FUNC7 ANALOG TYPE */
  382. LPC_N(clk0, 0xc00, EMC, CLKOUT, R, R, SDMMC, EMC_ALT, SSP1, ENET, 0, HS);
  383. LPC_N(clk1, 0xc04, EMC, CLKOUT, R, R, R, CGU_OUT, R, I2S1, 0, HS);
  384. LPC_N(clk2, 0xc08, EMC, CLKOUT, R, R, SDMMC, EMC_ALT,I2S0_TX_MCLK,I2S1, 0, HS);
  385. LPC_N(clk3, 0xc0c, EMC, CLKOUT, R, R, R, CGU_OUT, R, I2S1, 0, HS);
  386. LPC_N(usb1_dm, 0xc80, R, R, R, R, R, R, R, R, 0, USB1);
  387. LPC_N(usb1_dp, 0xc80, R, R, R, R, R, R, R, R, 0, USB1);
  388. LPC_N(i2c0_scl, 0xc84, R, R, R, R, R, R, R, R, 0, I2C0);
  389. LPC_N(i2c0_sda, 0xc84, R, R, R, R, R, R, R, R, 0, I2C0);
  390. #define LPC18XX_PIN_P(port, pin) { \
  391. .number = 0x##port * 32 + pin, \
  392. .name = "p"#port"_"#pin, \
  393. .drv_data = &lpc18xx_pin_p##port##_##pin \
  394. }
  395. /* Pin numbers for special pins */
  396. enum {
  397. PIN_CLK0 = 600,
  398. PIN_CLK1,
  399. PIN_CLK2,
  400. PIN_CLK3,
  401. PIN_USB1_DM,
  402. PIN_USB1_DP,
  403. PIN_I2C0_SCL,
  404. PIN_I2C0_SDA,
  405. };
  406. #define LPC18XX_PIN(pname, n) { \
  407. .number = n, \
  408. .name = #pname, \
  409. .drv_data = &lpc18xx_pin_##pname \
  410. }
  411. static const struct pinctrl_pin_desc lpc18xx_pins[] = {
  412. LPC18XX_PIN_P(0,0),
  413. LPC18XX_PIN_P(0,1),
  414. LPC18XX_PIN_P(1,0),
  415. LPC18XX_PIN_P(1,1),
  416. LPC18XX_PIN_P(1,2),
  417. LPC18XX_PIN_P(1,3),
  418. LPC18XX_PIN_P(1,4),
  419. LPC18XX_PIN_P(1,5),
  420. LPC18XX_PIN_P(1,6),
  421. LPC18XX_PIN_P(1,7),
  422. LPC18XX_PIN_P(1,8),
  423. LPC18XX_PIN_P(1,9),
  424. LPC18XX_PIN_P(1,10),
  425. LPC18XX_PIN_P(1,11),
  426. LPC18XX_PIN_P(1,12),
  427. LPC18XX_PIN_P(1,13),
  428. LPC18XX_PIN_P(1,14),
  429. LPC18XX_PIN_P(1,15),
  430. LPC18XX_PIN_P(1,16),
  431. LPC18XX_PIN_P(1,17),
  432. LPC18XX_PIN_P(1,18),
  433. LPC18XX_PIN_P(1,19),
  434. LPC18XX_PIN_P(1,20),
  435. LPC18XX_PIN_P(2,0),
  436. LPC18XX_PIN_P(2,1),
  437. LPC18XX_PIN_P(2,2),
  438. LPC18XX_PIN_P(2,3),
  439. LPC18XX_PIN_P(2,4),
  440. LPC18XX_PIN_P(2,5),
  441. LPC18XX_PIN_P(2,6),
  442. LPC18XX_PIN_P(2,7),
  443. LPC18XX_PIN_P(2,8),
  444. LPC18XX_PIN_P(2,9),
  445. LPC18XX_PIN_P(2,10),
  446. LPC18XX_PIN_P(2,11),
  447. LPC18XX_PIN_P(2,12),
  448. LPC18XX_PIN_P(2,13),
  449. LPC18XX_PIN_P(3,0),
  450. LPC18XX_PIN_P(3,1),
  451. LPC18XX_PIN_P(3,2),
  452. LPC18XX_PIN_P(3,3),
  453. LPC18XX_PIN_P(3,4),
  454. LPC18XX_PIN_P(3,5),
  455. LPC18XX_PIN_P(3,6),
  456. LPC18XX_PIN_P(3,7),
  457. LPC18XX_PIN_P(3,8),
  458. LPC18XX_PIN_P(4,0),
  459. LPC18XX_PIN_P(4,1),
  460. LPC18XX_PIN_P(4,2),
  461. LPC18XX_PIN_P(4,3),
  462. LPC18XX_PIN_P(4,4),
  463. LPC18XX_PIN_P(4,5),
  464. LPC18XX_PIN_P(4,6),
  465. LPC18XX_PIN_P(4,7),
  466. LPC18XX_PIN_P(4,8),
  467. LPC18XX_PIN_P(4,9),
  468. LPC18XX_PIN_P(4,10),
  469. LPC18XX_PIN_P(5,0),
  470. LPC18XX_PIN_P(5,1),
  471. LPC18XX_PIN_P(5,2),
  472. LPC18XX_PIN_P(5,3),
  473. LPC18XX_PIN_P(5,4),
  474. LPC18XX_PIN_P(5,5),
  475. LPC18XX_PIN_P(5,6),
  476. LPC18XX_PIN_P(5,7),
  477. LPC18XX_PIN_P(6,0),
  478. LPC18XX_PIN_P(6,1),
  479. LPC18XX_PIN_P(6,2),
  480. LPC18XX_PIN_P(6,3),
  481. LPC18XX_PIN_P(6,4),
  482. LPC18XX_PIN_P(6,5),
  483. LPC18XX_PIN_P(6,6),
  484. LPC18XX_PIN_P(6,7),
  485. LPC18XX_PIN_P(6,8),
  486. LPC18XX_PIN_P(6,9),
  487. LPC18XX_PIN_P(6,10),
  488. LPC18XX_PIN_P(6,11),
  489. LPC18XX_PIN_P(6,12),
  490. LPC18XX_PIN_P(7,0),
  491. LPC18XX_PIN_P(7,1),
  492. LPC18XX_PIN_P(7,2),
  493. LPC18XX_PIN_P(7,3),
  494. LPC18XX_PIN_P(7,4),
  495. LPC18XX_PIN_P(7,5),
  496. LPC18XX_PIN_P(7,6),
  497. LPC18XX_PIN_P(7,7),
  498. LPC18XX_PIN_P(8,0),
  499. LPC18XX_PIN_P(8,1),
  500. LPC18XX_PIN_P(8,2),
  501. LPC18XX_PIN_P(8,3),
  502. LPC18XX_PIN_P(8,4),
  503. LPC18XX_PIN_P(8,5),
  504. LPC18XX_PIN_P(8,6),
  505. LPC18XX_PIN_P(8,7),
  506. LPC18XX_PIN_P(8,8),
  507. LPC18XX_PIN_P(9,0),
  508. LPC18XX_PIN_P(9,1),
  509. LPC18XX_PIN_P(9,2),
  510. LPC18XX_PIN_P(9,3),
  511. LPC18XX_PIN_P(9,4),
  512. LPC18XX_PIN_P(9,5),
  513. LPC18XX_PIN_P(9,6),
  514. LPC18XX_PIN_P(a,0),
  515. LPC18XX_PIN_P(a,1),
  516. LPC18XX_PIN_P(a,2),
  517. LPC18XX_PIN_P(a,3),
  518. LPC18XX_PIN_P(a,4),
  519. LPC18XX_PIN_P(b,0),
  520. LPC18XX_PIN_P(b,1),
  521. LPC18XX_PIN_P(b,2),
  522. LPC18XX_PIN_P(b,3),
  523. LPC18XX_PIN_P(b,4),
  524. LPC18XX_PIN_P(b,5),
  525. LPC18XX_PIN_P(b,6),
  526. LPC18XX_PIN_P(c,0),
  527. LPC18XX_PIN_P(c,1),
  528. LPC18XX_PIN_P(c,2),
  529. LPC18XX_PIN_P(c,3),
  530. LPC18XX_PIN_P(c,4),
  531. LPC18XX_PIN_P(c,5),
  532. LPC18XX_PIN_P(c,6),
  533. LPC18XX_PIN_P(c,7),
  534. LPC18XX_PIN_P(c,8),
  535. LPC18XX_PIN_P(c,9),
  536. LPC18XX_PIN_P(c,10),
  537. LPC18XX_PIN_P(c,11),
  538. LPC18XX_PIN_P(c,12),
  539. LPC18XX_PIN_P(c,13),
  540. LPC18XX_PIN_P(c,14),
  541. LPC18XX_PIN_P(d,0),
  542. LPC18XX_PIN_P(d,1),
  543. LPC18XX_PIN_P(d,2),
  544. LPC18XX_PIN_P(d,3),
  545. LPC18XX_PIN_P(d,4),
  546. LPC18XX_PIN_P(d,5),
  547. LPC18XX_PIN_P(d,6),
  548. LPC18XX_PIN_P(d,7),
  549. LPC18XX_PIN_P(d,8),
  550. LPC18XX_PIN_P(d,9),
  551. LPC18XX_PIN_P(d,10),
  552. LPC18XX_PIN_P(d,11),
  553. LPC18XX_PIN_P(d,12),
  554. LPC18XX_PIN_P(d,13),
  555. LPC18XX_PIN_P(d,14),
  556. LPC18XX_PIN_P(d,15),
  557. LPC18XX_PIN_P(d,16),
  558. LPC18XX_PIN_P(e,0),
  559. LPC18XX_PIN_P(e,1),
  560. LPC18XX_PIN_P(e,2),
  561. LPC18XX_PIN_P(e,3),
  562. LPC18XX_PIN_P(e,4),
  563. LPC18XX_PIN_P(e,5),
  564. LPC18XX_PIN_P(e,6),
  565. LPC18XX_PIN_P(e,7),
  566. LPC18XX_PIN_P(e,8),
  567. LPC18XX_PIN_P(e,9),
  568. LPC18XX_PIN_P(e,10),
  569. LPC18XX_PIN_P(e,11),
  570. LPC18XX_PIN_P(e,12),
  571. LPC18XX_PIN_P(e,13),
  572. LPC18XX_PIN_P(e,14),
  573. LPC18XX_PIN_P(e,15),
  574. LPC18XX_PIN_P(f,0),
  575. LPC18XX_PIN_P(f,1),
  576. LPC18XX_PIN_P(f,2),
  577. LPC18XX_PIN_P(f,3),
  578. LPC18XX_PIN_P(f,4),
  579. LPC18XX_PIN_P(f,5),
  580. LPC18XX_PIN_P(f,6),
  581. LPC18XX_PIN_P(f,7),
  582. LPC18XX_PIN_P(f,8),
  583. LPC18XX_PIN_P(f,9),
  584. LPC18XX_PIN_P(f,10),
  585. LPC18XX_PIN_P(f,11),
  586. LPC18XX_PIN(clk0, PIN_CLK0),
  587. LPC18XX_PIN(clk1, PIN_CLK1),
  588. LPC18XX_PIN(clk2, PIN_CLK2),
  589. LPC18XX_PIN(clk3, PIN_CLK3),
  590. LPC18XX_PIN(usb1_dm, PIN_USB1_DM),
  591. LPC18XX_PIN(usb1_dp, PIN_USB1_DP),
  592. LPC18XX_PIN(i2c0_scl, PIN_I2C0_SCL),
  593. LPC18XX_PIN(i2c0_sda, PIN_I2C0_SDA),
  594. };
  595. static int lpc18xx_pconf_get_usb1(enum pin_config_param param, int *arg, u32 reg)
  596. {
  597. switch (param) {
  598. case PIN_CONFIG_LOW_POWER_MODE:
  599. if (reg & LPC18XX_SCU_USB1_EPWR)
  600. *arg = 0;
  601. else
  602. *arg = 1;
  603. break;
  604. case PIN_CONFIG_BIAS_DISABLE:
  605. if (reg & LPC18XX_SCU_USB1_EPD)
  606. return -EINVAL;
  607. break;
  608. case PIN_CONFIG_BIAS_PULL_DOWN:
  609. if (reg & LPC18XX_SCU_USB1_EPD)
  610. *arg = 1;
  611. else
  612. return -EINVAL;
  613. break;
  614. default:
  615. return -ENOTSUPP;
  616. }
  617. return 0;
  618. }
  619. static int lpc18xx_pconf_get_i2c0(enum pin_config_param param, int *arg, u32 reg,
  620. unsigned pin)
  621. {
  622. u8 shift;
  623. if (pin == PIN_I2C0_SCL)
  624. shift = LPC18XX_SCU_I2C0_SCL_SHIFT;
  625. else
  626. shift = LPC18XX_SCU_I2C0_SDA_SHIFT;
  627. switch (param) {
  628. case PIN_CONFIG_INPUT_ENABLE:
  629. if (reg & (LPC18XX_SCU_I2C0_EZI << shift))
  630. *arg = 1;
  631. else
  632. return -EINVAL;
  633. break;
  634. case PIN_CONFIG_SLEW_RATE:
  635. if (reg & (LPC18XX_SCU_I2C0_EHD << shift))
  636. *arg = 1;
  637. else
  638. *arg = 0;
  639. break;
  640. case PIN_CONFIG_INPUT_SCHMITT:
  641. if (reg & (LPC18XX_SCU_I2C0_EFP << shift))
  642. *arg = 3;
  643. else
  644. *arg = 50;
  645. break;
  646. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  647. if (reg & (LPC18XX_SCU_I2C0_ZIF << shift))
  648. return -EINVAL;
  649. else
  650. *arg = 1;
  651. break;
  652. default:
  653. return -ENOTSUPP;
  654. }
  655. return 0;
  656. }
  657. static int lpc18xx_pconf_get_pin(enum pin_config_param param, int *arg, u32 reg,
  658. struct lpc18xx_pin_caps *pin_cap)
  659. {
  660. switch (param) {
  661. case PIN_CONFIG_BIAS_DISABLE:
  662. if ((!(reg & LPC18XX_SCU_PIN_EPD)) && (reg & LPC18XX_SCU_PIN_EPUN))
  663. ;
  664. else
  665. return -EINVAL;
  666. break;
  667. case PIN_CONFIG_BIAS_PULL_UP:
  668. if (reg & LPC18XX_SCU_PIN_EPUN)
  669. return -EINVAL;
  670. else
  671. *arg = 1;
  672. break;
  673. case PIN_CONFIG_BIAS_PULL_DOWN:
  674. if (reg & LPC18XX_SCU_PIN_EPD)
  675. *arg = 1;
  676. else
  677. return -EINVAL;
  678. break;
  679. case PIN_CONFIG_INPUT_ENABLE:
  680. if (reg & LPC18XX_SCU_PIN_EZI)
  681. *arg = 1;
  682. else
  683. return -EINVAL;
  684. break;
  685. case PIN_CONFIG_SLEW_RATE:
  686. if (pin_cap->type == TYPE_HD)
  687. return -ENOTSUPP;
  688. if (reg & LPC18XX_SCU_PIN_EHS)
  689. *arg = 1;
  690. else
  691. *arg = 0;
  692. break;
  693. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  694. if (reg & LPC18XX_SCU_PIN_ZIF)
  695. return -EINVAL;
  696. else
  697. *arg = 1;
  698. break;
  699. case PIN_CONFIG_DRIVE_STRENGTH:
  700. if (pin_cap->type != TYPE_HD)
  701. return -ENOTSUPP;
  702. *arg = (reg & LPC18XX_SCU_PIN_EHD_MASK) >> LPC18XX_SCU_PIN_EHD_POS;
  703. switch (*arg) {
  704. case 3: *arg += 5;
  705. case 2: *arg += 5;
  706. case 1: *arg += 3;
  707. case 0: *arg += 4;
  708. }
  709. break;
  710. default:
  711. return -ENOTSUPP;
  712. }
  713. return 0;
  714. }
  715. static struct lpc18xx_pin_caps *lpc18xx_get_pin_caps(unsigned pin)
  716. {
  717. int i;
  718. for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
  719. if (lpc18xx_pins[i].number == pin)
  720. return lpc18xx_pins[i].drv_data;
  721. }
  722. return NULL;
  723. }
  724. static int lpc18xx_pconf_get(struct pinctrl_dev *pctldev, unsigned pin,
  725. unsigned long *config)
  726. {
  727. struct lpc18xx_scu_data *scu = pinctrl_dev_get_drvdata(pctldev);
  728. enum pin_config_param param = pinconf_to_config_param(*config);
  729. struct lpc18xx_pin_caps *pin_cap;
  730. int ret, arg = 0;
  731. u32 reg;
  732. pin_cap = lpc18xx_get_pin_caps(pin);
  733. if (!pin_cap)
  734. return -EINVAL;
  735. reg = readl(scu->base + pin_cap->offset);
  736. if (pin_cap->type == TYPE_I2C0)
  737. ret = lpc18xx_pconf_get_i2c0(param, &arg, reg, pin);
  738. else if (pin_cap->type == TYPE_USB1)
  739. ret = lpc18xx_pconf_get_usb1(param, &arg, reg);
  740. else
  741. ret = lpc18xx_pconf_get_pin(param, &arg, reg, pin_cap);
  742. if (ret < 0)
  743. return ret;
  744. *config = pinconf_to_config_packed(param, (u16)arg);
  745. return 0;
  746. }
  747. static int lpc18xx_pconf_set_usb1(struct pinctrl_dev *pctldev,
  748. enum pin_config_param param,
  749. u16 param_val, u32 *reg)
  750. {
  751. switch (param) {
  752. case PIN_CONFIG_LOW_POWER_MODE:
  753. if (param_val)
  754. *reg &= ~LPC18XX_SCU_USB1_EPWR;
  755. else
  756. *reg |= LPC18XX_SCU_USB1_EPWR;
  757. break;
  758. case PIN_CONFIG_BIAS_DISABLE:
  759. *reg &= ~LPC18XX_SCU_USB1_EPD;
  760. break;
  761. case PIN_CONFIG_BIAS_PULL_DOWN:
  762. *reg |= LPC18XX_SCU_USB1_EPD;
  763. break;
  764. default:
  765. dev_err(pctldev->dev, "Property not supported\n");
  766. return -ENOTSUPP;
  767. }
  768. return 0;
  769. }
  770. static int lpc18xx_pconf_set_i2c0(struct pinctrl_dev *pctldev,
  771. enum pin_config_param param,
  772. u16 param_val, u32 *reg,
  773. unsigned pin)
  774. {
  775. u8 shift;
  776. if (pin == PIN_I2C0_SCL)
  777. shift = LPC18XX_SCU_I2C0_SCL_SHIFT;
  778. else
  779. shift = LPC18XX_SCU_I2C0_SDA_SHIFT;
  780. switch (param) {
  781. case PIN_CONFIG_INPUT_ENABLE:
  782. if (param_val)
  783. *reg |= (LPC18XX_SCU_I2C0_EZI << shift);
  784. else
  785. *reg &= ~(LPC18XX_SCU_I2C0_EZI << shift);
  786. break;
  787. case PIN_CONFIG_SLEW_RATE:
  788. if (param_val)
  789. *reg |= (LPC18XX_SCU_I2C0_EHD << shift);
  790. else
  791. *reg &= ~(LPC18XX_SCU_I2C0_EHD << shift);
  792. break;
  793. case PIN_CONFIG_INPUT_SCHMITT:
  794. if (param_val == 3)
  795. *reg |= (LPC18XX_SCU_I2C0_EFP << shift);
  796. else if (param_val == 50)
  797. *reg &= ~(LPC18XX_SCU_I2C0_EFP << shift);
  798. else
  799. return -ENOTSUPP;
  800. break;
  801. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  802. if (param_val)
  803. *reg &= ~(LPC18XX_SCU_I2C0_ZIF << shift);
  804. else
  805. *reg |= (LPC18XX_SCU_I2C0_ZIF << shift);
  806. break;
  807. default:
  808. dev_err(pctldev->dev, "Property not supported\n");
  809. return -ENOTSUPP;
  810. }
  811. return 0;
  812. }
  813. static int lpc18xx_pconf_set_pin(struct pinctrl_dev *pctldev,
  814. enum pin_config_param param,
  815. u16 param_val, u32 *reg,
  816. struct lpc18xx_pin_caps *pin_cap)
  817. {
  818. switch (param) {
  819. case PIN_CONFIG_BIAS_DISABLE:
  820. *reg &= ~LPC18XX_SCU_PIN_EPD;
  821. *reg |= LPC18XX_SCU_PIN_EPUN;
  822. break;
  823. case PIN_CONFIG_BIAS_PULL_UP:
  824. *reg &= ~LPC18XX_SCU_PIN_EPUN;
  825. break;
  826. case PIN_CONFIG_BIAS_PULL_DOWN:
  827. *reg |= LPC18XX_SCU_PIN_EPD;
  828. break;
  829. case PIN_CONFIG_INPUT_ENABLE:
  830. if (param_val)
  831. *reg |= LPC18XX_SCU_PIN_EZI;
  832. else
  833. *reg &= ~LPC18XX_SCU_PIN_EZI;
  834. break;
  835. case PIN_CONFIG_SLEW_RATE:
  836. if (pin_cap->type == TYPE_HD) {
  837. dev_err(pctldev->dev, "Slew rate unsupported on high-drive pins\n");
  838. return -ENOTSUPP;
  839. }
  840. if (param_val == 0)
  841. *reg &= ~LPC18XX_SCU_PIN_EHS;
  842. else
  843. *reg |= LPC18XX_SCU_PIN_EHS;
  844. break;
  845. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  846. if (param_val)
  847. *reg &= ~LPC18XX_SCU_PIN_ZIF;
  848. else
  849. *reg |= LPC18XX_SCU_PIN_ZIF;
  850. break;
  851. case PIN_CONFIG_DRIVE_STRENGTH:
  852. if (pin_cap->type != TYPE_HD) {
  853. dev_err(pctldev->dev, "Drive strength available only on high-drive pins\n");
  854. return -ENOTSUPP;
  855. }
  856. *reg &= ~LPC18XX_SCU_PIN_EHD_MASK;
  857. switch (param_val) {
  858. case 20: param_val -= 5;
  859. case 14: param_val -= 5;
  860. case 8: param_val -= 3;
  861. case 4: param_val -= 4;
  862. break;
  863. default:
  864. dev_err(pctldev->dev, "Drive strength %u unsupported\n", param_val);
  865. return -ENOTSUPP;
  866. }
  867. *reg |= param_val << LPC18XX_SCU_PIN_EHD_POS;
  868. break;
  869. default:
  870. dev_err(pctldev->dev, "Property not supported\n");
  871. return -ENOTSUPP;
  872. }
  873. return 0;
  874. }
  875. static int lpc18xx_pconf_set(struct pinctrl_dev *pctldev, unsigned pin,
  876. unsigned long *configs, unsigned num_configs)
  877. {
  878. struct lpc18xx_scu_data *scu = pinctrl_dev_get_drvdata(pctldev);
  879. struct lpc18xx_pin_caps *pin_cap;
  880. enum pin_config_param param;
  881. u16 param_val;
  882. u32 reg;
  883. int ret;
  884. int i;
  885. pin_cap = lpc18xx_get_pin_caps(pin);
  886. if (!pin_cap)
  887. return -EINVAL;
  888. reg = readl(scu->base + pin_cap->offset);
  889. for (i = 0; i < num_configs; i++) {
  890. param = pinconf_to_config_param(configs[i]);
  891. param_val = pinconf_to_config_argument(configs[i]);
  892. if (pin_cap->type == TYPE_I2C0)
  893. ret = lpc18xx_pconf_set_i2c0(pctldev, param, param_val, &reg, pin);
  894. else if (pin_cap->type == TYPE_USB1)
  895. ret = lpc18xx_pconf_set_usb1(pctldev, param, param_val, &reg);
  896. else
  897. ret = lpc18xx_pconf_set_pin(pctldev, param, param_val, &reg, pin_cap);
  898. if (ret)
  899. return ret;
  900. }
  901. writel(reg, scu->base + pin_cap->offset);
  902. return 0;
  903. }
  904. static const struct pinconf_ops lpc18xx_pconf_ops = {
  905. .is_generic = true,
  906. .pin_config_get = lpc18xx_pconf_get,
  907. .pin_config_set = lpc18xx_pconf_set,
  908. };
  909. static int lpc18xx_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
  910. {
  911. return ARRAY_SIZE(lpc18xx_function_names);
  912. }
  913. static const char *lpc18xx_pmx_get_func_name(struct pinctrl_dev *pctldev,
  914. unsigned function)
  915. {
  916. return lpc18xx_function_names[function];
  917. }
  918. static int lpc18xx_pmx_get_func_groups(struct pinctrl_dev *pctldev,
  919. unsigned function,
  920. const char *const **groups,
  921. unsigned *const num_groups)
  922. {
  923. struct lpc18xx_scu_data *scu = pinctrl_dev_get_drvdata(pctldev);
  924. *groups = scu->func[function].groups;
  925. *num_groups = scu->func[function].ngroups;
  926. return 0;
  927. }
  928. static int lpc18xx_pmx_set(struct pinctrl_dev *pctldev, unsigned function,
  929. unsigned group)
  930. {
  931. struct lpc18xx_scu_data *scu = pinctrl_dev_get_drvdata(pctldev);
  932. struct lpc18xx_pin_caps *pin = lpc18xx_pins[group].drv_data;
  933. int func;
  934. u32 reg;
  935. /* Dedicated USB1 and I2C0 pins doesn't support muxing */
  936. if (pin->type == TYPE_USB1) {
  937. if (function == FUNC_USB1)
  938. return 0;
  939. goto fail;
  940. }
  941. if (pin->type == TYPE_I2C0) {
  942. if (function == FUNC_I2C0)
  943. return 0;
  944. goto fail;
  945. }
  946. if (function == FUNC_ADC && (pin->analog & LPC18XX_ANALOG_PIN)) {
  947. u32 offset;
  948. writel(LPC18XX_SCU_ANALOG_PIN_CFG, scu->base + pin->offset);
  949. if (LPC18XX_ANALOG_ADC(pin->analog) == 0)
  950. offset = LPC18XX_SCU_REG_ENAIO0;
  951. else
  952. offset = LPC18XX_SCU_REG_ENAIO1;
  953. reg = readl(scu->base + offset);
  954. reg |= pin->analog & LPC18XX_ANALOG_BIT_MASK;
  955. writel(reg, scu->base + offset);
  956. return 0;
  957. }
  958. if (function == FUNC_DAC && (pin->analog & LPC18XX_ANALOG_PIN)) {
  959. writel(LPC18XX_SCU_ANALOG_PIN_CFG, scu->base + pin->offset);
  960. reg = readl(scu->base + LPC18XX_SCU_REG_ENAIO2);
  961. reg |= LPC18XX_SCU_REG_ENAIO2_DAC;
  962. writel(reg, scu->base + LPC18XX_SCU_REG_ENAIO2);
  963. return 0;
  964. }
  965. for (func = 0; func < LPC18XX_SCU_FUNC_PER_PIN; func++) {
  966. if (function == pin->functions[func])
  967. break;
  968. }
  969. if (func >= LPC18XX_SCU_FUNC_PER_PIN)
  970. goto fail;
  971. reg = readl(scu->base + pin->offset);
  972. reg &= ~LPC18XX_SCU_PIN_MODE_MASK;
  973. writel(reg | func, scu->base + pin->offset);
  974. return 0;
  975. fail:
  976. dev_err(pctldev->dev, "Pin %s can't be %s\n", lpc18xx_pins[group].name,
  977. lpc18xx_function_names[function]);
  978. return -EINVAL;
  979. }
  980. static const struct pinmux_ops lpc18xx_pmx_ops = {
  981. .get_functions_count = lpc18xx_pmx_get_funcs_count,
  982. .get_function_name = lpc18xx_pmx_get_func_name,
  983. .get_function_groups = lpc18xx_pmx_get_func_groups,
  984. .set_mux = lpc18xx_pmx_set,
  985. };
  986. static int lpc18xx_pctl_get_groups_count(struct pinctrl_dev *pctldev)
  987. {
  988. return ARRAY_SIZE(lpc18xx_pins);
  989. }
  990. static const char *lpc18xx_pctl_get_group_name(struct pinctrl_dev *pctldev,
  991. unsigned group)
  992. {
  993. return lpc18xx_pins[group].name;
  994. }
  995. static int lpc18xx_pctl_get_group_pins(struct pinctrl_dev *pctldev,
  996. unsigned group,
  997. const unsigned **pins,
  998. unsigned *num_pins)
  999. {
  1000. *pins = &lpc18xx_pins[group].number;
  1001. *num_pins = 1;
  1002. return 0;
  1003. }
  1004. static const struct pinctrl_ops lpc18xx_pctl_ops = {
  1005. .get_groups_count = lpc18xx_pctl_get_groups_count,
  1006. .get_group_name = lpc18xx_pctl_get_group_name,
  1007. .get_group_pins = lpc18xx_pctl_get_group_pins,
  1008. .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
  1009. .dt_free_map = pinctrl_utils_dt_free_map,
  1010. };
  1011. static struct pinctrl_desc lpc18xx_scu_desc = {
  1012. .name = "lpc18xx/43xx-scu",
  1013. .pins = lpc18xx_pins,
  1014. .npins = ARRAY_SIZE(lpc18xx_pins),
  1015. .pctlops = &lpc18xx_pctl_ops,
  1016. .pmxops = &lpc18xx_pmx_ops,
  1017. .confops = &lpc18xx_pconf_ops,
  1018. .owner = THIS_MODULE,
  1019. };
  1020. static bool lpc18xx_valid_pin_function(unsigned pin, unsigned function)
  1021. {
  1022. struct lpc18xx_pin_caps *p = lpc18xx_pins[pin].drv_data;
  1023. int i;
  1024. if (function == FUNC_DAC && p->analog == DAC)
  1025. return true;
  1026. if (function == FUNC_ADC && p->analog)
  1027. return true;
  1028. if (function == FUNC_I2C0 && p->type == TYPE_I2C0)
  1029. return true;
  1030. if (function == FUNC_USB1 && p->type == TYPE_USB1)
  1031. return true;
  1032. for (i = 0; i < LPC18XX_SCU_FUNC_PER_PIN; i++) {
  1033. if (function == p->functions[i])
  1034. return true;
  1035. }
  1036. return false;
  1037. }
  1038. static int lpc18xx_create_group_func_map(struct device *dev,
  1039. struct lpc18xx_scu_data *scu)
  1040. {
  1041. u16 pins[ARRAY_SIZE(lpc18xx_pins)];
  1042. int func, ngroups, i;
  1043. for (func = 0; func < FUNC_MAX; ngroups = 0, func++) {
  1044. for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
  1045. if (lpc18xx_valid_pin_function(i, func))
  1046. pins[ngroups++] = i;
  1047. }
  1048. scu->func[func].ngroups = ngroups;
  1049. scu->func[func].groups = devm_kzalloc(dev, ngroups *
  1050. sizeof(char *), GFP_KERNEL);
  1051. if (!scu->func[func].groups)
  1052. return -ENOMEM;
  1053. for (i = 0; i < ngroups; i++)
  1054. scu->func[func].groups[i] = lpc18xx_pins[pins[i]].name;
  1055. }
  1056. return 0;
  1057. }
  1058. static int lpc18xx_scu_probe(struct platform_device *pdev)
  1059. {
  1060. struct lpc18xx_scu_data *scu;
  1061. struct resource *res;
  1062. int ret;
  1063. scu = devm_kzalloc(&pdev->dev, sizeof(*scu), GFP_KERNEL);
  1064. if (!scu)
  1065. return -ENOMEM;
  1066. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1067. scu->base = devm_ioremap_resource(&pdev->dev, res);
  1068. if (IS_ERR(scu->base))
  1069. return PTR_ERR(scu->base);
  1070. scu->clk = devm_clk_get(&pdev->dev, NULL);
  1071. if (IS_ERR(scu->clk)) {
  1072. dev_err(&pdev->dev, "Input clock not found.\n");
  1073. return PTR_ERR(scu->clk);
  1074. }
  1075. ret = lpc18xx_create_group_func_map(&pdev->dev, scu);
  1076. if (ret) {
  1077. dev_err(&pdev->dev, "Unable to create group func map.\n");
  1078. return ret;
  1079. }
  1080. ret = clk_prepare_enable(scu->clk);
  1081. if (ret) {
  1082. dev_err(&pdev->dev, "Unable to enable clock.\n");
  1083. return ret;
  1084. }
  1085. platform_set_drvdata(pdev, scu);
  1086. scu->pctl = pinctrl_register(&lpc18xx_scu_desc, &pdev->dev, scu);
  1087. if (IS_ERR(scu->pctl)) {
  1088. dev_err(&pdev->dev, "Could not register pinctrl driver\n");
  1089. clk_disable_unprepare(scu->clk);
  1090. return PTR_ERR(scu->pctl);
  1091. }
  1092. return 0;
  1093. }
  1094. static int lpc18xx_scu_remove(struct platform_device *pdev)
  1095. {
  1096. struct lpc18xx_scu_data *scu = platform_get_drvdata(pdev);
  1097. pinctrl_unregister(scu->pctl);
  1098. clk_disable_unprepare(scu->clk);
  1099. return 0;
  1100. }
  1101. static const struct of_device_id lpc18xx_scu_match[] = {
  1102. { .compatible = "nxp,lpc1850-scu" },
  1103. {},
  1104. };
  1105. MODULE_DEVICE_TABLE(of, lpc18xx_scu_match);
  1106. static struct platform_driver lpc18xx_scu_driver = {
  1107. .probe = lpc18xx_scu_probe,
  1108. .remove = lpc18xx_scu_remove,
  1109. .driver = {
  1110. .name = "lpc18xx-scu",
  1111. .of_match_table = lpc18xx_scu_match,
  1112. },
  1113. };
  1114. module_platform_driver(lpc18xx_scu_driver);
  1115. MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>");
  1116. MODULE_DESCRIPTION("Pinctrl driver for NXP LPC18xx/43xx SCU");
  1117. MODULE_LICENSE("GPL v2");