gpio-lpc32xx.c 15 KB

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