gpiolib.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /*
  2. * arch/arm/plat-s5pc100/gpiolib.c
  3. *
  4. * Copyright 2009 Samsung Electronics Co
  5. * Kyungmin Park <kyungmin.park@samsung.com>
  6. *
  7. * S5PC100 - GPIOlib support
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/irq.h>
  15. #include <linux/io.h>
  16. #include <linux/gpio.h>
  17. #include <mach/map.h>
  18. #include <mach/regs-gpio.h>
  19. #include <plat/gpio-core.h>
  20. #include <plat/gpio-cfg.h>
  21. #include <plat/gpio-cfg-helpers.h>
  22. /* S5PC100 GPIO bank summary:
  23. *
  24. * Bank GPIOs Style INT Type
  25. * A0 8 4Bit GPIO_INT0
  26. * A1 5 4Bit GPIO_INT1
  27. * B 8 4Bit GPIO_INT2
  28. * C 5 4Bit GPIO_INT3
  29. * D 7 4Bit GPIO_INT4
  30. * E0 8 4Bit GPIO_INT5
  31. * E1 6 4Bit GPIO_INT6
  32. * F0 8 4Bit GPIO_INT7
  33. * F1 8 4Bit GPIO_INT8
  34. * F2 8 4Bit GPIO_INT9
  35. * F3 4 4Bit GPIO_INT10
  36. * G0 8 4Bit GPIO_INT11
  37. * G1 3 4Bit GPIO_INT12
  38. * G2 7 4Bit GPIO_INT13
  39. * G3 7 4Bit GPIO_INT14
  40. * H0 8 4Bit WKUP_INT
  41. * H1 8 4Bit WKUP_INT
  42. * H2 8 4Bit WKUP_INT
  43. * H3 8 4Bit WKUP_INT
  44. * I 8 4Bit GPIO_INT15
  45. * J0 8 4Bit GPIO_INT16
  46. * J1 5 4Bit GPIO_INT17
  47. * J2 8 4Bit GPIO_INT18
  48. * J3 8 4Bit GPIO_INT19
  49. * J4 4 4Bit GPIO_INT20
  50. * K0 8 4Bit None
  51. * K1 6 4Bit None
  52. * K2 8 4Bit None
  53. * K3 8 4Bit None
  54. * L0 8 4Bit None
  55. * L1 8 4Bit None
  56. * L2 8 4Bit None
  57. * L3 8 4Bit None
  58. */
  59. static int s5pc100_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset)
  60. {
  61. return S3C_IRQ_GPIO(chip->base + offset);
  62. }
  63. static int s5pc100_gpiolib_to_eint(struct gpio_chip *chip, unsigned int offset)
  64. {
  65. int base;
  66. base = chip->base - S5PC100_GPH0(0);
  67. if (base == 0)
  68. return IRQ_EINT(offset);
  69. base = chip->base - S5PC100_GPH1(0);
  70. if (base == 0)
  71. return IRQ_EINT(8 + offset);
  72. base = chip->base - S5PC100_GPH2(0);
  73. if (base == 0)
  74. return IRQ_EINT(16 + offset);
  75. base = chip->base - S5PC100_GPH3(0);
  76. if (base == 0)
  77. return IRQ_EINT(24 + offset);
  78. return -EINVAL;
  79. }
  80. static struct s3c_gpio_cfg gpio_cfg = {
  81. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  82. .set_pull = s3c_gpio_setpull_updown,
  83. .get_pull = s3c_gpio_getpull_updown,
  84. };
  85. static struct s3c_gpio_cfg gpio_cfg_eint = {
  86. .cfg_eint = 0xf,
  87. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  88. .set_pull = s3c_gpio_setpull_updown,
  89. .get_pull = s3c_gpio_getpull_updown,
  90. };
  91. static struct s3c_gpio_cfg gpio_cfg_noint = {
  92. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  93. .set_pull = s3c_gpio_setpull_updown,
  94. .get_pull = s3c_gpio_getpull_updown,
  95. };
  96. static struct s3c_gpio_chip s5pc100_gpio_chips[] = {
  97. {
  98. .base = S5PC100_GPA0_BASE,
  99. .config = &gpio_cfg,
  100. .chip = {
  101. .base = S5PC100_GPA0(0),
  102. .ngpio = S5PC100_GPIO_A0_NR,
  103. .label = "GPA0",
  104. },
  105. }, {
  106. .base = S5PC100_GPA1_BASE,
  107. .config = &gpio_cfg,
  108. .chip = {
  109. .base = S5PC100_GPA1(0),
  110. .ngpio = S5PC100_GPIO_A1_NR,
  111. .label = "GPA1",
  112. },
  113. }, {
  114. .base = S5PC100_GPB_BASE,
  115. .config = &gpio_cfg,
  116. .chip = {
  117. .base = S5PC100_GPB(0),
  118. .ngpio = S5PC100_GPIO_B_NR,
  119. .label = "GPB",
  120. },
  121. }, {
  122. .base = S5PC100_GPC_BASE,
  123. .config = &gpio_cfg,
  124. .chip = {
  125. .base = S5PC100_GPC(0),
  126. .ngpio = S5PC100_GPIO_C_NR,
  127. .label = "GPC",
  128. },
  129. }, {
  130. .base = S5PC100_GPD_BASE,
  131. .config = &gpio_cfg,
  132. .chip = {
  133. .base = S5PC100_GPD(0),
  134. .ngpio = S5PC100_GPIO_D_NR,
  135. .label = "GPD",
  136. },
  137. }, {
  138. .base = S5PC100_GPE0_BASE,
  139. .config = &gpio_cfg,
  140. .chip = {
  141. .base = S5PC100_GPE0(0),
  142. .ngpio = S5PC100_GPIO_E0_NR,
  143. .label = "GPE0",
  144. },
  145. }, {
  146. .base = S5PC100_GPE1_BASE,
  147. .config = &gpio_cfg,
  148. .chip = {
  149. .base = S5PC100_GPE1(0),
  150. .ngpio = S5PC100_GPIO_E1_NR,
  151. .label = "GPE1",
  152. },
  153. }, {
  154. .base = S5PC100_GPF0_BASE,
  155. .config = &gpio_cfg,
  156. .chip = {
  157. .base = S5PC100_GPF0(0),
  158. .ngpio = S5PC100_GPIO_F0_NR,
  159. .label = "GPF0",
  160. },
  161. }, {
  162. .base = S5PC100_GPF1_BASE,
  163. .config = &gpio_cfg,
  164. .chip = {
  165. .base = S5PC100_GPF1(0),
  166. .ngpio = S5PC100_GPIO_F1_NR,
  167. .label = "GPF1",
  168. },
  169. }, {
  170. .base = S5PC100_GPF2_BASE,
  171. .config = &gpio_cfg,
  172. .chip = {
  173. .base = S5PC100_GPF2(0),
  174. .ngpio = S5PC100_GPIO_F2_NR,
  175. .label = "GPF2",
  176. },
  177. }, {
  178. .base = S5PC100_GPF3_BASE,
  179. .config = &gpio_cfg,
  180. .chip = {
  181. .base = S5PC100_GPF3(0),
  182. .ngpio = S5PC100_GPIO_F3_NR,
  183. .label = "GPF3",
  184. },
  185. }, {
  186. .base = S5PC100_GPG0_BASE,
  187. .config = &gpio_cfg,
  188. .chip = {
  189. .base = S5PC100_GPG0(0),
  190. .ngpio = S5PC100_GPIO_G0_NR,
  191. .label = "GPG0",
  192. },
  193. }, {
  194. .base = S5PC100_GPG1_BASE,
  195. .config = &gpio_cfg,
  196. .chip = {
  197. .base = S5PC100_GPG1(0),
  198. .ngpio = S5PC100_GPIO_G1_NR,
  199. .label = "GPG1",
  200. },
  201. }, {
  202. .base = S5PC100_GPG2_BASE,
  203. .config = &gpio_cfg,
  204. .chip = {
  205. .base = S5PC100_GPG2(0),
  206. .ngpio = S5PC100_GPIO_G2_NR,
  207. .label = "GPG2",
  208. },
  209. }, {
  210. .base = S5PC100_GPG3_BASE,
  211. .config = &gpio_cfg,
  212. .chip = {
  213. .base = S5PC100_GPG3(0),
  214. .ngpio = S5PC100_GPIO_G3_NR,
  215. .label = "GPG3",
  216. },
  217. }, {
  218. .base = S5PC100_GPH0_BASE,
  219. .config = &gpio_cfg_eint,
  220. .chip = {
  221. .base = S5PC100_GPH0(0),
  222. .ngpio = S5PC100_GPIO_H0_NR,
  223. .label = "GPH0",
  224. },
  225. }, {
  226. .base = S5PC100_GPH1_BASE,
  227. .config = &gpio_cfg_eint,
  228. .chip = {
  229. .base = S5PC100_GPH1(0),
  230. .ngpio = S5PC100_GPIO_H1_NR,
  231. .label = "GPH1",
  232. },
  233. }, {
  234. .base = S5PC100_GPH2_BASE,
  235. .config = &gpio_cfg_eint,
  236. .chip = {
  237. .base = S5PC100_GPH2(0),
  238. .ngpio = S5PC100_GPIO_H2_NR,
  239. .label = "GPH2",
  240. },
  241. }, {
  242. .base = S5PC100_GPH3_BASE,
  243. .config = &gpio_cfg_eint,
  244. .chip = {
  245. .base = S5PC100_GPH3(0),
  246. .ngpio = S5PC100_GPIO_H3_NR,
  247. .label = "GPH3",
  248. },
  249. }, {
  250. .base = S5PC100_GPI_BASE,
  251. .config = &gpio_cfg,
  252. .chip = {
  253. .base = S5PC100_GPI(0),
  254. .ngpio = S5PC100_GPIO_I_NR,
  255. .label = "GPI",
  256. },
  257. }, {
  258. .base = S5PC100_GPJ0_BASE,
  259. .config = &gpio_cfg,
  260. .chip = {
  261. .base = S5PC100_GPJ0(0),
  262. .ngpio = S5PC100_GPIO_J0_NR,
  263. .label = "GPJ0",
  264. },
  265. }, {
  266. .base = S5PC100_GPJ1_BASE,
  267. .config = &gpio_cfg,
  268. .chip = {
  269. .base = S5PC100_GPJ1(0),
  270. .ngpio = S5PC100_GPIO_J1_NR,
  271. .label = "GPJ1",
  272. },
  273. }, {
  274. .base = S5PC100_GPJ2_BASE,
  275. .config = &gpio_cfg,
  276. .chip = {
  277. .base = S5PC100_GPJ2(0),
  278. .ngpio = S5PC100_GPIO_J2_NR,
  279. .label = "GPJ2",
  280. },
  281. }, {
  282. .base = S5PC100_GPJ3_BASE,
  283. .config = &gpio_cfg,
  284. .chip = {
  285. .base = S5PC100_GPJ3(0),
  286. .ngpio = S5PC100_GPIO_J3_NR,
  287. .label = "GPJ3",
  288. },
  289. }, {
  290. .base = S5PC100_GPJ4_BASE,
  291. .config = &gpio_cfg,
  292. .chip = {
  293. .base = S5PC100_GPJ4(0),
  294. .ngpio = S5PC100_GPIO_J4_NR,
  295. .label = "GPJ4",
  296. },
  297. }, {
  298. .base = S5PC100_GPK0_BASE,
  299. .config = &gpio_cfg_noint,
  300. .chip = {
  301. .base = S5PC100_GPK0(0),
  302. .ngpio = S5PC100_GPIO_K0_NR,
  303. .label = "GPK0",
  304. },
  305. }, {
  306. .base = S5PC100_GPK1_BASE,
  307. .config = &gpio_cfg_noint,
  308. .chip = {
  309. .base = S5PC100_GPK1(0),
  310. .ngpio = S5PC100_GPIO_K1_NR,
  311. .label = "GPK1",
  312. },
  313. }, {
  314. .base = S5PC100_GPK2_BASE,
  315. .config = &gpio_cfg_noint,
  316. .chip = {
  317. .base = S5PC100_GPK2(0),
  318. .ngpio = S5PC100_GPIO_K2_NR,
  319. .label = "GPK2",
  320. },
  321. }, {
  322. .base = S5PC100_GPK3_BASE,
  323. .config = &gpio_cfg_noint,
  324. .chip = {
  325. .base = S5PC100_GPK3(0),
  326. .ngpio = S5PC100_GPIO_K3_NR,
  327. .label = "GPK3",
  328. },
  329. }, {
  330. .base = S5PC100_GPL0_BASE,
  331. .config = &gpio_cfg_noint,
  332. .chip = {
  333. .base = S5PC100_GPL0(0),
  334. .ngpio = S5PC100_GPIO_L0_NR,
  335. .label = "GPL0",
  336. },
  337. }, {
  338. .base = S5PC100_GPL1_BASE,
  339. .config = &gpio_cfg_noint,
  340. .chip = {
  341. .base = S5PC100_GPL1(0),
  342. .ngpio = S5PC100_GPIO_L1_NR,
  343. .label = "GPL1",
  344. },
  345. }, {
  346. .base = S5PC100_GPL2_BASE,
  347. .config = &gpio_cfg_noint,
  348. .chip = {
  349. .base = S5PC100_GPL2(0),
  350. .ngpio = S5PC100_GPIO_L2_NR,
  351. .label = "GPL2",
  352. },
  353. }, {
  354. .base = S5PC100_GPL3_BASE,
  355. .config = &gpio_cfg_noint,
  356. .chip = {
  357. .base = S5PC100_GPL3(0),
  358. .ngpio = S5PC100_GPIO_L3_NR,
  359. .label = "GPL3",
  360. },
  361. }, {
  362. .base = S5PC100_GPL4_BASE,
  363. .config = &gpio_cfg_noint,
  364. .chip = {
  365. .base = S5PC100_GPL4(0),
  366. .ngpio = S5PC100_GPIO_L4_NR,
  367. .label = "GPL4",
  368. },
  369. },
  370. };
  371. /* FIXME move from irq-gpio.c */
  372. extern struct irq_chip s5pc100_gpioint;
  373. extern void s5pc100_irq_gpioint_handler(unsigned int irq, struct irq_desc *desc);
  374. static __init void s5pc100_gpiolib_link(struct s3c_gpio_chip *chip)
  375. {
  376. /* Interrupt */
  377. if (chip->config == &gpio_cfg) {
  378. int i, irq;
  379. chip->chip.to_irq = s5pc100_gpiolib_to_irq;
  380. for (i = 0; i < chip->chip.ngpio; i++) {
  381. irq = S3C_IRQ_GPIO_BASE + chip->chip.base + i;
  382. set_irq_chip(irq, &s5pc100_gpioint);
  383. set_irq_data(irq, &chip->chip);
  384. set_irq_handler(irq, handle_level_irq);
  385. set_irq_flags(irq, IRQF_VALID);
  386. }
  387. } else if (chip->config == &gpio_cfg_eint) {
  388. chip->chip.to_irq = s5pc100_gpiolib_to_eint;
  389. }
  390. }
  391. static __init int s5pc100_gpiolib_init(void)
  392. {
  393. struct s3c_gpio_chip *chip;
  394. int nr_chips;
  395. chip = s5pc100_gpio_chips;
  396. nr_chips = ARRAY_SIZE(s5pc100_gpio_chips);
  397. for (; nr_chips > 0; nr_chips--, chip++)
  398. s5pc100_gpiolib_link(chip);
  399. samsung_gpiolib_add_4bit_chips(s5pc100_gpio_chips,
  400. ARRAY_SIZE(s5pc100_gpio_chips));
  401. /* Interrupt */
  402. set_irq_chained_handler(IRQ_GPIOINT, s5pc100_irq_gpioint_handler);
  403. return 0;
  404. }
  405. core_initcall(s5pc100_gpiolib_init);