gpiolib.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. #if 0
  60. static int s5pc100_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset)
  61. {
  62. return S3C_IRQ_GPIO(chip->base + offset);
  63. }
  64. static int s5pc100_gpiolib_to_eint(struct gpio_chip *chip, unsigned int offset)
  65. {
  66. int base;
  67. base = chip->base - S5PC100_GPH0(0);
  68. if (base == 0)
  69. return IRQ_EINT(offset);
  70. base = chip->base - S5PC100_GPH1(0);
  71. if (base == 0)
  72. return IRQ_EINT(8 + offset);
  73. base = chip->base - S5PC100_GPH2(0);
  74. if (base == 0)
  75. return IRQ_EINT(16 + offset);
  76. base = chip->base - S5PC100_GPH3(0);
  77. if (base == 0)
  78. return IRQ_EINT(24 + offset);
  79. return -EINVAL;
  80. }
  81. #endif
  82. static struct s3c_gpio_cfg gpio_cfg = {
  83. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  84. .set_pull = s3c_gpio_setpull_updown,
  85. .get_pull = s3c_gpio_getpull_updown,
  86. };
  87. static struct s3c_gpio_cfg gpio_cfg_eint = {
  88. .cfg_eint = 0xf,
  89. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  90. .set_pull = s3c_gpio_setpull_updown,
  91. .get_pull = s3c_gpio_getpull_updown,
  92. };
  93. static struct s3c_gpio_cfg gpio_cfg_noint = {
  94. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  95. .set_pull = s3c_gpio_setpull_updown,
  96. .get_pull = s3c_gpio_getpull_updown,
  97. };
  98. static struct s3c_gpio_chip s5pc100_gpio_chips[] = {
  99. {
  100. .base = S5PC100_GPA0_BASE,
  101. .config = &gpio_cfg,
  102. .chip = {
  103. .base = S5PC100_GPA0(0),
  104. .ngpio = S5PC100_GPIO_A0_NR,
  105. .label = "GPA0",
  106. },
  107. }, {
  108. .base = S5PC100_GPA1_BASE,
  109. .config = &gpio_cfg,
  110. .chip = {
  111. .base = S5PC100_GPA1(0),
  112. .ngpio = S5PC100_GPIO_A1_NR,
  113. .label = "GPA1",
  114. },
  115. }, {
  116. .base = S5PC100_GPB_BASE,
  117. .config = &gpio_cfg,
  118. .chip = {
  119. .base = S5PC100_GPB(0),
  120. .ngpio = S5PC100_GPIO_B_NR,
  121. .label = "GPB",
  122. },
  123. }, {
  124. .base = S5PC100_GPC_BASE,
  125. .config = &gpio_cfg,
  126. .chip = {
  127. .base = S5PC100_GPC(0),
  128. .ngpio = S5PC100_GPIO_C_NR,
  129. .label = "GPC",
  130. },
  131. }, {
  132. .base = S5PC100_GPD_BASE,
  133. .config = &gpio_cfg,
  134. .chip = {
  135. .base = S5PC100_GPD(0),
  136. .ngpio = S5PC100_GPIO_D_NR,
  137. .label = "GPD",
  138. },
  139. }, {
  140. .base = S5PC100_GPE0_BASE,
  141. .config = &gpio_cfg,
  142. .chip = {
  143. .base = S5PC100_GPE0(0),
  144. .ngpio = S5PC100_GPIO_E0_NR,
  145. .label = "GPE0",
  146. },
  147. }, {
  148. .base = S5PC100_GPE1_BASE,
  149. .config = &gpio_cfg,
  150. .chip = {
  151. .base = S5PC100_GPE1(0),
  152. .ngpio = S5PC100_GPIO_E1_NR,
  153. .label = "GPE1",
  154. },
  155. }, {
  156. .base = S5PC100_GPF0_BASE,
  157. .config = &gpio_cfg,
  158. .chip = {
  159. .base = S5PC100_GPF0(0),
  160. .ngpio = S5PC100_GPIO_F0_NR,
  161. .label = "GPF0",
  162. },
  163. }, {
  164. .base = S5PC100_GPF1_BASE,
  165. .config = &gpio_cfg,
  166. .chip = {
  167. .base = S5PC100_GPF1(0),
  168. .ngpio = S5PC100_GPIO_F1_NR,
  169. .label = "GPF1",
  170. },
  171. }, {
  172. .base = S5PC100_GPF2_BASE,
  173. .config = &gpio_cfg,
  174. .chip = {
  175. .base = S5PC100_GPF2(0),
  176. .ngpio = S5PC100_GPIO_F2_NR,
  177. .label = "GPF2",
  178. },
  179. }, {
  180. .base = S5PC100_GPF3_BASE,
  181. .config = &gpio_cfg,
  182. .chip = {
  183. .base = S5PC100_GPF3(0),
  184. .ngpio = S5PC100_GPIO_F3_NR,
  185. .label = "GPF3",
  186. },
  187. }, {
  188. .base = S5PC100_GPG0_BASE,
  189. .config = &gpio_cfg,
  190. .chip = {
  191. .base = S5PC100_GPG0(0),
  192. .ngpio = S5PC100_GPIO_G0_NR,
  193. .label = "GPG0",
  194. },
  195. }, {
  196. .base = S5PC100_GPG1_BASE,
  197. .config = &gpio_cfg,
  198. .chip = {
  199. .base = S5PC100_GPG1(0),
  200. .ngpio = S5PC100_GPIO_G1_NR,
  201. .label = "GPG1",
  202. },
  203. }, {
  204. .base = S5PC100_GPG2_BASE,
  205. .config = &gpio_cfg,
  206. .chip = {
  207. .base = S5PC100_GPG2(0),
  208. .ngpio = S5PC100_GPIO_G2_NR,
  209. .label = "GPG2",
  210. },
  211. }, {
  212. .base = S5PC100_GPG3_BASE,
  213. .config = &gpio_cfg,
  214. .chip = {
  215. .base = S5PC100_GPG3(0),
  216. .ngpio = S5PC100_GPIO_G3_NR,
  217. .label = "GPG3",
  218. },
  219. }, {
  220. .base = S5PC100_GPH0_BASE,
  221. .config = &gpio_cfg_eint,
  222. .chip = {
  223. .base = S5PC100_GPH0(0),
  224. .ngpio = S5PC100_GPIO_H0_NR,
  225. .label = "GPH0",
  226. },
  227. }, {
  228. .base = S5PC100_GPH1_BASE,
  229. .config = &gpio_cfg_eint,
  230. .chip = {
  231. .base = S5PC100_GPH1(0),
  232. .ngpio = S5PC100_GPIO_H1_NR,
  233. .label = "GPH1",
  234. },
  235. }, {
  236. .base = S5PC100_GPH2_BASE,
  237. .config = &gpio_cfg_eint,
  238. .chip = {
  239. .base = S5PC100_GPH2(0),
  240. .ngpio = S5PC100_GPIO_H2_NR,
  241. .label = "GPH2",
  242. },
  243. }, {
  244. .base = S5PC100_GPH3_BASE,
  245. .config = &gpio_cfg_eint,
  246. .chip = {
  247. .base = S5PC100_GPH3(0),
  248. .ngpio = S5PC100_GPIO_H3_NR,
  249. .label = "GPH3",
  250. },
  251. }, {
  252. .base = S5PC100_GPI_BASE,
  253. .config = &gpio_cfg,
  254. .chip = {
  255. .base = S5PC100_GPI(0),
  256. .ngpio = S5PC100_GPIO_I_NR,
  257. .label = "GPI",
  258. },
  259. }, {
  260. .base = S5PC100_GPJ0_BASE,
  261. .config = &gpio_cfg,
  262. .chip = {
  263. .base = S5PC100_GPJ0(0),
  264. .ngpio = S5PC100_GPIO_J0_NR,
  265. .label = "GPJ0",
  266. },
  267. }, {
  268. .base = S5PC100_GPJ1_BASE,
  269. .config = &gpio_cfg,
  270. .chip = {
  271. .base = S5PC100_GPJ1(0),
  272. .ngpio = S5PC100_GPIO_J1_NR,
  273. .label = "GPJ1",
  274. },
  275. }, {
  276. .base = S5PC100_GPJ2_BASE,
  277. .config = &gpio_cfg,
  278. .chip = {
  279. .base = S5PC100_GPJ2(0),
  280. .ngpio = S5PC100_GPIO_J2_NR,
  281. .label = "GPJ2",
  282. },
  283. }, {
  284. .base = S5PC100_GPJ3_BASE,
  285. .config = &gpio_cfg,
  286. .chip = {
  287. .base = S5PC100_GPJ3(0),
  288. .ngpio = S5PC100_GPIO_J3_NR,
  289. .label = "GPJ3",
  290. },
  291. }, {
  292. .base = S5PC100_GPJ4_BASE,
  293. .config = &gpio_cfg,
  294. .chip = {
  295. .base = S5PC100_GPJ4(0),
  296. .ngpio = S5PC100_GPIO_J4_NR,
  297. .label = "GPJ4",
  298. },
  299. }, {
  300. .base = S5PC100_GPK0_BASE,
  301. .config = &gpio_cfg_noint,
  302. .chip = {
  303. .base = S5PC100_GPK0(0),
  304. .ngpio = S5PC100_GPIO_K0_NR,
  305. .label = "GPK0",
  306. },
  307. }, {
  308. .base = S5PC100_GPK1_BASE,
  309. .config = &gpio_cfg_noint,
  310. .chip = {
  311. .base = S5PC100_GPK1(0),
  312. .ngpio = S5PC100_GPIO_K1_NR,
  313. .label = "GPK1",
  314. },
  315. }, {
  316. .base = S5PC100_GPK2_BASE,
  317. .config = &gpio_cfg_noint,
  318. .chip = {
  319. .base = S5PC100_GPK2(0),
  320. .ngpio = S5PC100_GPIO_K2_NR,
  321. .label = "GPK2",
  322. },
  323. }, {
  324. .base = S5PC100_GPK3_BASE,
  325. .config = &gpio_cfg_noint,
  326. .chip = {
  327. .base = S5PC100_GPK3(0),
  328. .ngpio = S5PC100_GPIO_K3_NR,
  329. .label = "GPK3",
  330. },
  331. }, {
  332. .base = S5PC100_GPL0_BASE,
  333. .config = &gpio_cfg_noint,
  334. .chip = {
  335. .base = S5PC100_GPL0(0),
  336. .ngpio = S5PC100_GPIO_L0_NR,
  337. .label = "GPL0",
  338. },
  339. }, {
  340. .base = S5PC100_GPL1_BASE,
  341. .config = &gpio_cfg_noint,
  342. .chip = {
  343. .base = S5PC100_GPL1(0),
  344. .ngpio = S5PC100_GPIO_L1_NR,
  345. .label = "GPL1",
  346. },
  347. }, {
  348. .base = S5PC100_GPL2_BASE,
  349. .config = &gpio_cfg_noint,
  350. .chip = {
  351. .base = S5PC100_GPL2(0),
  352. .ngpio = S5PC100_GPIO_L2_NR,
  353. .label = "GPL2",
  354. },
  355. }, {
  356. .base = S5PC100_GPL3_BASE,
  357. .config = &gpio_cfg_noint,
  358. .chip = {
  359. .base = S5PC100_GPL3(0),
  360. .ngpio = S5PC100_GPIO_L3_NR,
  361. .label = "GPL3",
  362. },
  363. }, {
  364. .base = S5PC100_GPL4_BASE,
  365. .config = &gpio_cfg_noint,
  366. .chip = {
  367. .base = S5PC100_GPL4(0),
  368. .ngpio = S5PC100_GPIO_L4_NR,
  369. .label = "GPL4",
  370. },
  371. },
  372. };
  373. /* FIXME move from irq-gpio.c */
  374. extern struct irq_chip s5pc100_gpioint;
  375. extern void s5pc100_irq_gpioint_handler(unsigned int irq, struct irq_desc *desc);
  376. static __init void s5pc100_gpiolib_link(struct s3c_gpio_chip *chip)
  377. {
  378. /* Interrupt */
  379. if (chip->config == &gpio_cfg) {
  380. int i, irq;
  381. chip->chip.to_irq = s5pc100_gpiolib_to_irq;
  382. for (i = 0; i < chip->chip.ngpio; i++) {
  383. irq = S3C_IRQ_GPIO_BASE + chip->chip.base + i;
  384. set_irq_chip(irq, &s5pc100_gpioint);
  385. set_irq_data(irq, &chip->chip);
  386. set_irq_handler(irq, handle_level_irq);
  387. set_irq_flags(irq, IRQF_VALID);
  388. }
  389. } else if (chip->config == &gpio_cfg_eint) {
  390. chip->chip.to_irq = s5pc100_gpiolib_to_eint;
  391. }
  392. }
  393. static __init int s5pc100_gpiolib_init(void)
  394. {
  395. struct s3c_gpio_chip *chip;
  396. int nr_chips;
  397. chip = s5pc100_gpio_chips;
  398. nr_chips = ARRAY_SIZE(s5pc100_gpio_chips);
  399. for (; nr_chips > 0; nr_chips--, chip++)
  400. s5pc100_gpiolib_link(chip);
  401. samsung_gpiolib_add_4bit_chips(s5pc100_gpio_chips,
  402. ARRAY_SIZE(s5pc100_gpio_chips));
  403. /* Interrupt */
  404. set_irq_chained_handler(IRQ_GPIOINT, s5pc100_irq_gpioint_handler);
  405. return 0;
  406. }
  407. core_initcall(s5pc100_gpiolib_init);