gpio-lpc32xx.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. * GPIO driver for LPC32xx SoC
  3. *
  4. * Author: Kevin Wells <kevin.wells@nxp.com>
  5. *
  6. * Copyright (C) 2010 NXP Semiconductors
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/io.h>
  21. #include <linux/errno.h>
  22. #include <linux/gpio.h>
  23. #include <linux/of.h>
  24. #include <linux/of_gpio.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/module.h>
  27. #include <linux/platform_data/gpio-lpc32xx.h>
  28. #include <mach/hardware.h>
  29. #include <mach/platform.h>
  30. #include <mach/irqs.h>
  31. #define LPC32XX_GPIO_P3_INP_STATE _GPREG(0x000)
  32. #define LPC32XX_GPIO_P3_OUTP_SET _GPREG(0x004)
  33. #define LPC32XX_GPIO_P3_OUTP_CLR _GPREG(0x008)
  34. #define LPC32XX_GPIO_P3_OUTP_STATE _GPREG(0x00C)
  35. #define LPC32XX_GPIO_P2_DIR_SET _GPREG(0x010)
  36. #define LPC32XX_GPIO_P2_DIR_CLR _GPREG(0x014)
  37. #define LPC32XX_GPIO_P2_DIR_STATE _GPREG(0x018)
  38. #define LPC32XX_GPIO_P2_INP_STATE _GPREG(0x01C)
  39. #define LPC32XX_GPIO_P2_OUTP_SET _GPREG(0x020)
  40. #define LPC32XX_GPIO_P2_OUTP_CLR _GPREG(0x024)
  41. #define LPC32XX_GPIO_P2_MUX_SET _GPREG(0x028)
  42. #define LPC32XX_GPIO_P2_MUX_CLR _GPREG(0x02C)
  43. #define LPC32XX_GPIO_P2_MUX_STATE _GPREG(0x030)
  44. #define LPC32XX_GPIO_P0_INP_STATE _GPREG(0x040)
  45. #define LPC32XX_GPIO_P0_OUTP_SET _GPREG(0x044)
  46. #define LPC32XX_GPIO_P0_OUTP_CLR _GPREG(0x048)
  47. #define LPC32XX_GPIO_P0_OUTP_STATE _GPREG(0x04C)
  48. #define LPC32XX_GPIO_P0_DIR_SET _GPREG(0x050)
  49. #define LPC32XX_GPIO_P0_DIR_CLR _GPREG(0x054)
  50. #define LPC32XX_GPIO_P0_DIR_STATE _GPREG(0x058)
  51. #define LPC32XX_GPIO_P1_INP_STATE _GPREG(0x060)
  52. #define LPC32XX_GPIO_P1_OUTP_SET _GPREG(0x064)
  53. #define LPC32XX_GPIO_P1_OUTP_CLR _GPREG(0x068)
  54. #define LPC32XX_GPIO_P1_OUTP_STATE _GPREG(0x06C)
  55. #define LPC32XX_GPIO_P1_DIR_SET _GPREG(0x070)
  56. #define LPC32XX_GPIO_P1_DIR_CLR _GPREG(0x074)
  57. #define LPC32XX_GPIO_P1_DIR_STATE _GPREG(0x078)
  58. #define GPIO012_PIN_TO_BIT(x) (1 << (x))
  59. #define GPIO3_PIN_TO_BIT(x) (1 << ((x) + 25))
  60. #define GPO3_PIN_TO_BIT(x) (1 << (x))
  61. #define GPIO012_PIN_IN_SEL(x, y) (((x) >> (y)) & 1)
  62. #define GPIO3_PIN_IN_SHIFT(x) ((x) == 5 ? 24 : 10 + (x))
  63. #define GPIO3_PIN_IN_SEL(x, y) (((x) >> GPIO3_PIN_IN_SHIFT(y)) & 1)
  64. #define GPIO3_PIN5_IN_SEL(x) (((x) >> 24) & 1)
  65. #define GPI3_PIN_IN_SEL(x, y) (((x) >> (y)) & 1)
  66. #define GPO3_PIN_IN_SEL(x, y) (((x) >> (y)) & 1)
  67. struct gpio_regs {
  68. void __iomem *inp_state;
  69. void __iomem *outp_state;
  70. void __iomem *outp_set;
  71. void __iomem *outp_clr;
  72. void __iomem *dir_set;
  73. void __iomem *dir_clr;
  74. };
  75. /*
  76. * GPIO names
  77. */
  78. static const char *gpio_p0_names[LPC32XX_GPIO_P0_MAX] = {
  79. "p0.0", "p0.1", "p0.2", "p0.3",
  80. "p0.4", "p0.5", "p0.6", "p0.7"
  81. };
  82. static const char *gpio_p1_names[LPC32XX_GPIO_P1_MAX] = {
  83. "p1.0", "p1.1", "p1.2", "p1.3",
  84. "p1.4", "p1.5", "p1.6", "p1.7",
  85. "p1.8", "p1.9", "p1.10", "p1.11",
  86. "p1.12", "p1.13", "p1.14", "p1.15",
  87. "p1.16", "p1.17", "p1.18", "p1.19",
  88. "p1.20", "p1.21", "p1.22", "p1.23",
  89. };
  90. static const char *gpio_p2_names[LPC32XX_GPIO_P2_MAX] = {
  91. "p2.0", "p2.1", "p2.2", "p2.3",
  92. "p2.4", "p2.5", "p2.6", "p2.7",
  93. "p2.8", "p2.9", "p2.10", "p2.11",
  94. "p2.12"
  95. };
  96. static const char *gpio_p3_names[LPC32XX_GPIO_P3_MAX] = {
  97. "gpio00", "gpio01", "gpio02", "gpio03",
  98. "gpio04", "gpio05"
  99. };
  100. static const char *gpi_p3_names[LPC32XX_GPI_P3_MAX] = {
  101. "gpi00", "gpi01", "gpi02", "gpi03",
  102. "gpi04", "gpi05", "gpi06", "gpi07",
  103. "gpi08", "gpi09", NULL, NULL,
  104. NULL, NULL, NULL, "gpi15",
  105. "gpi16", "gpi17", "gpi18", "gpi19",
  106. "gpi20", "gpi21", "gpi22", "gpi23",
  107. "gpi24", "gpi25", "gpi26", "gpi27",
  108. "gpi28"
  109. };
  110. static const char *gpo_p3_names[LPC32XX_GPO_P3_MAX] = {
  111. "gpo00", "gpo01", "gpo02", "gpo03",
  112. "gpo04", "gpo05", "gpo06", "gpo07",
  113. "gpo08", "gpo09", "gpo10", "gpo11",
  114. "gpo12", "gpo13", "gpo14", "gpo15",
  115. "gpo16", "gpo17", "gpo18", "gpo19",
  116. "gpo20", "gpo21", "gpo22", "gpo23"
  117. };
  118. static struct gpio_regs gpio_grp_regs_p0 = {
  119. .inp_state = LPC32XX_GPIO_P0_INP_STATE,
  120. .outp_set = LPC32XX_GPIO_P0_OUTP_SET,
  121. .outp_clr = LPC32XX_GPIO_P0_OUTP_CLR,
  122. .dir_set = LPC32XX_GPIO_P0_DIR_SET,
  123. .dir_clr = LPC32XX_GPIO_P0_DIR_CLR,
  124. };
  125. static struct gpio_regs gpio_grp_regs_p1 = {
  126. .inp_state = LPC32XX_GPIO_P1_INP_STATE,
  127. .outp_set = LPC32XX_GPIO_P1_OUTP_SET,
  128. .outp_clr = LPC32XX_GPIO_P1_OUTP_CLR,
  129. .dir_set = LPC32XX_GPIO_P1_DIR_SET,
  130. .dir_clr = LPC32XX_GPIO_P1_DIR_CLR,
  131. };
  132. static struct gpio_regs gpio_grp_regs_p2 = {
  133. .inp_state = LPC32XX_GPIO_P2_INP_STATE,
  134. .outp_set = LPC32XX_GPIO_P2_OUTP_SET,
  135. .outp_clr = LPC32XX_GPIO_P2_OUTP_CLR,
  136. .dir_set = LPC32XX_GPIO_P2_DIR_SET,
  137. .dir_clr = LPC32XX_GPIO_P2_DIR_CLR,
  138. };
  139. static struct gpio_regs gpio_grp_regs_p3 = {
  140. .inp_state = LPC32XX_GPIO_P3_INP_STATE,
  141. .outp_state = LPC32XX_GPIO_P3_OUTP_STATE,
  142. .outp_set = LPC32XX_GPIO_P3_OUTP_SET,
  143. .outp_clr = LPC32XX_GPIO_P3_OUTP_CLR,
  144. .dir_set = LPC32XX_GPIO_P2_DIR_SET,
  145. .dir_clr = LPC32XX_GPIO_P2_DIR_CLR,
  146. };
  147. struct lpc32xx_gpio_chip {
  148. struct gpio_chip chip;
  149. struct gpio_regs *gpio_grp;
  150. };
  151. static void __set_gpio_dir_p012(struct lpc32xx_gpio_chip *group,
  152. unsigned pin, int input)
  153. {
  154. if (input)
  155. __raw_writel(GPIO012_PIN_TO_BIT(pin),
  156. group->gpio_grp->dir_clr);
  157. else
  158. __raw_writel(GPIO012_PIN_TO_BIT(pin),
  159. group->gpio_grp->dir_set);
  160. }
  161. static void __set_gpio_dir_p3(struct lpc32xx_gpio_chip *group,
  162. unsigned pin, int input)
  163. {
  164. u32 u = GPIO3_PIN_TO_BIT(pin);
  165. if (input)
  166. __raw_writel(u, group->gpio_grp->dir_clr);
  167. else
  168. __raw_writel(u, group->gpio_grp->dir_set);
  169. }
  170. static void __set_gpio_level_p012(struct lpc32xx_gpio_chip *group,
  171. unsigned pin, int high)
  172. {
  173. if (high)
  174. __raw_writel(GPIO012_PIN_TO_BIT(pin),
  175. group->gpio_grp->outp_set);
  176. else
  177. __raw_writel(GPIO012_PIN_TO_BIT(pin),
  178. group->gpio_grp->outp_clr);
  179. }
  180. static void __set_gpio_level_p3(struct lpc32xx_gpio_chip *group,
  181. unsigned pin, int high)
  182. {
  183. u32 u = GPIO3_PIN_TO_BIT(pin);
  184. if (high)
  185. __raw_writel(u, group->gpio_grp->outp_set);
  186. else
  187. __raw_writel(u, group->gpio_grp->outp_clr);
  188. }
  189. static void __set_gpo_level_p3(struct lpc32xx_gpio_chip *group,
  190. unsigned pin, int high)
  191. {
  192. if (high)
  193. __raw_writel(GPO3_PIN_TO_BIT(pin), group->gpio_grp->outp_set);
  194. else
  195. __raw_writel(GPO3_PIN_TO_BIT(pin), group->gpio_grp->outp_clr);
  196. }
  197. static int __get_gpio_state_p012(struct lpc32xx_gpio_chip *group,
  198. unsigned pin)
  199. {
  200. return GPIO012_PIN_IN_SEL(__raw_readl(group->gpio_grp->inp_state),
  201. pin);
  202. }
  203. static int __get_gpio_state_p3(struct lpc32xx_gpio_chip *group,
  204. unsigned pin)
  205. {
  206. int state = __raw_readl(group->gpio_grp->inp_state);
  207. /*
  208. * P3 GPIO pin input mapping is not contiguous, GPIOP3-0..4 is mapped
  209. * to bits 10..14, while GPIOP3-5 is mapped to bit 24.
  210. */
  211. return GPIO3_PIN_IN_SEL(state, pin);
  212. }
  213. static int __get_gpi_state_p3(struct lpc32xx_gpio_chip *group,
  214. unsigned pin)
  215. {
  216. return GPI3_PIN_IN_SEL(__raw_readl(group->gpio_grp->inp_state), pin);
  217. }
  218. static int __get_gpo_state_p3(struct lpc32xx_gpio_chip *group,
  219. unsigned pin)
  220. {
  221. return GPO3_PIN_IN_SEL(__raw_readl(group->gpio_grp->outp_state), pin);
  222. }
  223. /*
  224. * GPIO primitives.
  225. */
  226. static int lpc32xx_gpio_dir_input_p012(struct gpio_chip *chip,
  227. unsigned pin)
  228. {
  229. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  230. __set_gpio_dir_p012(group, pin, 1);
  231. return 0;
  232. }
  233. static int lpc32xx_gpio_dir_input_p3(struct gpio_chip *chip,
  234. unsigned pin)
  235. {
  236. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  237. __set_gpio_dir_p3(group, pin, 1);
  238. return 0;
  239. }
  240. static int lpc32xx_gpio_dir_in_always(struct gpio_chip *chip,
  241. unsigned pin)
  242. {
  243. return 0;
  244. }
  245. static int lpc32xx_gpio_get_value_p012(struct gpio_chip *chip, unsigned pin)
  246. {
  247. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  248. return !!__get_gpio_state_p012(group, pin);
  249. }
  250. static int lpc32xx_gpio_get_value_p3(struct gpio_chip *chip, unsigned pin)
  251. {
  252. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  253. return !!__get_gpio_state_p3(group, pin);
  254. }
  255. static int lpc32xx_gpi_get_value(struct gpio_chip *chip, unsigned pin)
  256. {
  257. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  258. return !!__get_gpi_state_p3(group, pin);
  259. }
  260. static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin,
  261. int value)
  262. {
  263. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  264. __set_gpio_level_p012(group, pin, value);
  265. __set_gpio_dir_p012(group, pin, 0);
  266. return 0;
  267. }
  268. static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin,
  269. int value)
  270. {
  271. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  272. __set_gpio_level_p3(group, pin, value);
  273. __set_gpio_dir_p3(group, pin, 0);
  274. return 0;
  275. }
  276. static int lpc32xx_gpio_dir_out_always(struct gpio_chip *chip, unsigned pin,
  277. int value)
  278. {
  279. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  280. __set_gpo_level_p3(group, pin, value);
  281. return 0;
  282. }
  283. static void lpc32xx_gpio_set_value_p012(struct gpio_chip *chip, unsigned pin,
  284. int value)
  285. {
  286. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  287. __set_gpio_level_p012(group, pin, value);
  288. }
  289. static void lpc32xx_gpio_set_value_p3(struct gpio_chip *chip, unsigned pin,
  290. int value)
  291. {
  292. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  293. __set_gpio_level_p3(group, pin, value);
  294. }
  295. static void lpc32xx_gpo_set_value(struct gpio_chip *chip, unsigned pin,
  296. int value)
  297. {
  298. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  299. __set_gpo_level_p3(group, pin, value);
  300. }
  301. static int lpc32xx_gpo_get_value(struct gpio_chip *chip, unsigned pin)
  302. {
  303. struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
  304. return !!__get_gpo_state_p3(group, pin);
  305. }
  306. static int lpc32xx_gpio_request(struct gpio_chip *chip, unsigned pin)
  307. {
  308. if (pin < chip->ngpio)
  309. return 0;
  310. return -EINVAL;
  311. }
  312. static int lpc32xx_gpio_to_irq_p01(struct gpio_chip *chip, unsigned offset)
  313. {
  314. return IRQ_LPC32XX_P0_P1_IRQ;
  315. }
  316. static const char lpc32xx_gpio_to_irq_gpio_p3_table[] = {
  317. IRQ_LPC32XX_GPIO_00,
  318. IRQ_LPC32XX_GPIO_01,
  319. IRQ_LPC32XX_GPIO_02,
  320. IRQ_LPC32XX_GPIO_03,
  321. IRQ_LPC32XX_GPIO_04,
  322. IRQ_LPC32XX_GPIO_05,
  323. };
  324. static int lpc32xx_gpio_to_irq_gpio_p3(struct gpio_chip *chip, unsigned offset)
  325. {
  326. if (offset < ARRAY_SIZE(lpc32xx_gpio_to_irq_gpio_p3_table))
  327. return lpc32xx_gpio_to_irq_gpio_p3_table[offset];
  328. return -ENXIO;
  329. }
  330. static const char lpc32xx_gpio_to_irq_gpi_p3_table[] = {
  331. IRQ_LPC32XX_GPI_00,
  332. IRQ_LPC32XX_GPI_01,
  333. IRQ_LPC32XX_GPI_02,
  334. IRQ_LPC32XX_GPI_03,
  335. IRQ_LPC32XX_GPI_04,
  336. IRQ_LPC32XX_GPI_05,
  337. IRQ_LPC32XX_GPI_06,
  338. IRQ_LPC32XX_GPI_07,
  339. IRQ_LPC32XX_GPI_08,
  340. IRQ_LPC32XX_GPI_09,
  341. -ENXIO, /* 10 */
  342. -ENXIO, /* 11 */
  343. -ENXIO, /* 12 */
  344. -ENXIO, /* 13 */
  345. -ENXIO, /* 14 */
  346. -ENXIO, /* 15 */
  347. -ENXIO, /* 16 */
  348. -ENXIO, /* 17 */
  349. -ENXIO, /* 18 */
  350. IRQ_LPC32XX_GPI_19,
  351. -ENXIO, /* 20 */
  352. -ENXIO, /* 21 */
  353. -ENXIO, /* 22 */
  354. -ENXIO, /* 23 */
  355. -ENXIO, /* 24 */
  356. -ENXIO, /* 25 */
  357. -ENXIO, /* 26 */
  358. -ENXIO, /* 27 */
  359. IRQ_LPC32XX_GPI_28,
  360. };
  361. static int lpc32xx_gpio_to_irq_gpi_p3(struct gpio_chip *chip, unsigned offset)
  362. {
  363. if (offset < ARRAY_SIZE(lpc32xx_gpio_to_irq_gpi_p3_table))
  364. return lpc32xx_gpio_to_irq_gpi_p3_table[offset];
  365. return -ENXIO;
  366. }
  367. static struct lpc32xx_gpio_chip lpc32xx_gpiochip[] = {
  368. {
  369. .chip = {
  370. .label = "gpio_p0",
  371. .direction_input = lpc32xx_gpio_dir_input_p012,
  372. .get = lpc32xx_gpio_get_value_p012,
  373. .direction_output = lpc32xx_gpio_dir_output_p012,
  374. .set = lpc32xx_gpio_set_value_p012,
  375. .request = lpc32xx_gpio_request,
  376. .to_irq = lpc32xx_gpio_to_irq_p01,
  377. .base = LPC32XX_GPIO_P0_GRP,
  378. .ngpio = LPC32XX_GPIO_P0_MAX,
  379. .names = gpio_p0_names,
  380. .can_sleep = false,
  381. },
  382. .gpio_grp = &gpio_grp_regs_p0,
  383. },
  384. {
  385. .chip = {
  386. .label = "gpio_p1",
  387. .direction_input = lpc32xx_gpio_dir_input_p012,
  388. .get = lpc32xx_gpio_get_value_p012,
  389. .direction_output = lpc32xx_gpio_dir_output_p012,
  390. .set = lpc32xx_gpio_set_value_p012,
  391. .request = lpc32xx_gpio_request,
  392. .to_irq = lpc32xx_gpio_to_irq_p01,
  393. .base = LPC32XX_GPIO_P1_GRP,
  394. .ngpio = LPC32XX_GPIO_P1_MAX,
  395. .names = gpio_p1_names,
  396. .can_sleep = false,
  397. },
  398. .gpio_grp = &gpio_grp_regs_p1,
  399. },
  400. {
  401. .chip = {
  402. .label = "gpio_p2",
  403. .direction_input = lpc32xx_gpio_dir_input_p012,
  404. .get = lpc32xx_gpio_get_value_p012,
  405. .direction_output = lpc32xx_gpio_dir_output_p012,
  406. .set = lpc32xx_gpio_set_value_p012,
  407. .request = lpc32xx_gpio_request,
  408. .base = LPC32XX_GPIO_P2_GRP,
  409. .ngpio = LPC32XX_GPIO_P2_MAX,
  410. .names = gpio_p2_names,
  411. .can_sleep = false,
  412. },
  413. .gpio_grp = &gpio_grp_regs_p2,
  414. },
  415. {
  416. .chip = {
  417. .label = "gpio_p3",
  418. .direction_input = lpc32xx_gpio_dir_input_p3,
  419. .get = lpc32xx_gpio_get_value_p3,
  420. .direction_output = lpc32xx_gpio_dir_output_p3,
  421. .set = lpc32xx_gpio_set_value_p3,
  422. .request = lpc32xx_gpio_request,
  423. .to_irq = lpc32xx_gpio_to_irq_gpio_p3,
  424. .base = LPC32XX_GPIO_P3_GRP,
  425. .ngpio = LPC32XX_GPIO_P3_MAX,
  426. .names = gpio_p3_names,
  427. .can_sleep = false,
  428. },
  429. .gpio_grp = &gpio_grp_regs_p3,
  430. },
  431. {
  432. .chip = {
  433. .label = "gpi_p3",
  434. .direction_input = lpc32xx_gpio_dir_in_always,
  435. .get = lpc32xx_gpi_get_value,
  436. .request = lpc32xx_gpio_request,
  437. .to_irq = lpc32xx_gpio_to_irq_gpi_p3,
  438. .base = LPC32XX_GPI_P3_GRP,
  439. .ngpio = LPC32XX_GPI_P3_MAX,
  440. .names = gpi_p3_names,
  441. .can_sleep = false,
  442. },
  443. .gpio_grp = &gpio_grp_regs_p3,
  444. },
  445. {
  446. .chip = {
  447. .label = "gpo_p3",
  448. .direction_output = lpc32xx_gpio_dir_out_always,
  449. .set = lpc32xx_gpo_set_value,
  450. .get = lpc32xx_gpo_get_value,
  451. .request = lpc32xx_gpio_request,
  452. .base = LPC32XX_GPO_P3_GRP,
  453. .ngpio = LPC32XX_GPO_P3_MAX,
  454. .names = gpo_p3_names,
  455. .can_sleep = false,
  456. },
  457. .gpio_grp = &gpio_grp_regs_p3,
  458. },
  459. };
  460. static int lpc32xx_of_xlate(struct gpio_chip *gc,
  461. const struct of_phandle_args *gpiospec, u32 *flags)
  462. {
  463. /* Is this the correct bank? */
  464. u32 bank = gpiospec->args[0];
  465. if ((bank >= ARRAY_SIZE(lpc32xx_gpiochip) ||
  466. (gc != &lpc32xx_gpiochip[bank].chip)))
  467. return -EINVAL;
  468. if (flags)
  469. *flags = gpiospec->args[2];
  470. return gpiospec->args[1];
  471. }
  472. static int lpc32xx_gpio_probe(struct platform_device *pdev)
  473. {
  474. int i;
  475. for (i = 0; i < ARRAY_SIZE(lpc32xx_gpiochip); i++) {
  476. if (pdev->dev.of_node) {
  477. lpc32xx_gpiochip[i].chip.of_xlate = lpc32xx_of_xlate;
  478. lpc32xx_gpiochip[i].chip.of_gpio_n_cells = 3;
  479. lpc32xx_gpiochip[i].chip.of_node = pdev->dev.of_node;
  480. }
  481. devm_gpiochip_add_data(&pdev->dev, &lpc32xx_gpiochip[i].chip,
  482. &lpc32xx_gpiochip[i]);
  483. }
  484. return 0;
  485. }
  486. #ifdef CONFIG_OF
  487. static const struct of_device_id lpc32xx_gpio_of_match[] = {
  488. { .compatible = "nxp,lpc3220-gpio", },
  489. { },
  490. };
  491. #endif
  492. static struct platform_driver lpc32xx_gpio_driver = {
  493. .driver = {
  494. .name = "lpc32xx-gpio",
  495. .of_match_table = of_match_ptr(lpc32xx_gpio_of_match),
  496. },
  497. .probe = lpc32xx_gpio_probe,
  498. };
  499. module_platform_driver(lpc32xx_gpio_driver);