pinctrl-lpc18xx.c 42 KB

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