gpiolib.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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_eint(struct gpio_chip *chip, unsigned int offset)
  60. {
  61. int base;
  62. base = chip->base - S5PC100_GPH0(0);
  63. if (base == 0)
  64. return IRQ_EINT(offset);
  65. base = chip->base - S5PC100_GPH1(0);
  66. if (base == 0)
  67. return IRQ_EINT(8 + offset);
  68. base = chip->base - S5PC100_GPH2(0);
  69. if (base == 0)
  70. return IRQ_EINT(16 + offset);
  71. base = chip->base - S5PC100_GPH3(0);
  72. if (base == 0)
  73. return IRQ_EINT(24 + offset);
  74. return -EINVAL;
  75. }
  76. static struct s3c_gpio_cfg gpio_cfg = {
  77. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  78. .set_pull = s3c_gpio_setpull_updown,
  79. .get_pull = s3c_gpio_getpull_updown,
  80. };
  81. static struct s3c_gpio_cfg gpio_cfg_eint = {
  82. .cfg_eint = 0xf,
  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_noint = {
  88. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  89. .set_pull = s3c_gpio_setpull_updown,
  90. .get_pull = s3c_gpio_getpull_updown,
  91. };
  92. static struct s3c_gpio_chip s5pc100_gpio_chips[] = {
  93. {
  94. .base = S5PC100_GPA0_BASE,
  95. .config = &gpio_cfg,
  96. .chip = {
  97. .base = S5PC100_GPA0(0),
  98. .ngpio = S5PC100_GPIO_A0_NR,
  99. .label = "GPA0",
  100. },
  101. }, {
  102. .base = S5PC100_GPA1_BASE,
  103. .config = &gpio_cfg,
  104. .chip = {
  105. .base = S5PC100_GPA1(0),
  106. .ngpio = S5PC100_GPIO_A1_NR,
  107. .label = "GPA1",
  108. },
  109. }, {
  110. .base = S5PC100_GPB_BASE,
  111. .config = &gpio_cfg,
  112. .chip = {
  113. .base = S5PC100_GPB(0),
  114. .ngpio = S5PC100_GPIO_B_NR,
  115. .label = "GPB",
  116. },
  117. }, {
  118. .base = S5PC100_GPC_BASE,
  119. .config = &gpio_cfg,
  120. .chip = {
  121. .base = S5PC100_GPC(0),
  122. .ngpio = S5PC100_GPIO_C_NR,
  123. .label = "GPC",
  124. },
  125. }, {
  126. .base = S5PC100_GPD_BASE,
  127. .config = &gpio_cfg,
  128. .chip = {
  129. .base = S5PC100_GPD(0),
  130. .ngpio = S5PC100_GPIO_D_NR,
  131. .label = "GPD",
  132. },
  133. }, {
  134. .base = S5PC100_GPE0_BASE,
  135. .config = &gpio_cfg,
  136. .chip = {
  137. .base = S5PC100_GPE0(0),
  138. .ngpio = S5PC100_GPIO_E0_NR,
  139. .label = "GPE0",
  140. },
  141. }, {
  142. .base = S5PC100_GPE1_BASE,
  143. .config = &gpio_cfg,
  144. .chip = {
  145. .base = S5PC100_GPE1(0),
  146. .ngpio = S5PC100_GPIO_E1_NR,
  147. .label = "GPE1",
  148. },
  149. }, {
  150. .base = S5PC100_GPF0_BASE,
  151. .config = &gpio_cfg,
  152. .chip = {
  153. .base = S5PC100_GPF0(0),
  154. .ngpio = S5PC100_GPIO_F0_NR,
  155. .label = "GPF0",
  156. },
  157. }, {
  158. .base = S5PC100_GPF1_BASE,
  159. .config = &gpio_cfg,
  160. .chip = {
  161. .base = S5PC100_GPF1(0),
  162. .ngpio = S5PC100_GPIO_F1_NR,
  163. .label = "GPF1",
  164. },
  165. }, {
  166. .base = S5PC100_GPF2_BASE,
  167. .config = &gpio_cfg,
  168. .chip = {
  169. .base = S5PC100_GPF2(0),
  170. .ngpio = S5PC100_GPIO_F2_NR,
  171. .label = "GPF2",
  172. },
  173. }, {
  174. .base = S5PC100_GPF3_BASE,
  175. .config = &gpio_cfg,
  176. .chip = {
  177. .base = S5PC100_GPF3(0),
  178. .ngpio = S5PC100_GPIO_F3_NR,
  179. .label = "GPF3",
  180. },
  181. }, {
  182. .base = S5PC100_GPG0_BASE,
  183. .config = &gpio_cfg,
  184. .chip = {
  185. .base = S5PC100_GPG0(0),
  186. .ngpio = S5PC100_GPIO_G0_NR,
  187. .label = "GPG0",
  188. },
  189. }, {
  190. .base = S5PC100_GPG1_BASE,
  191. .config = &gpio_cfg,
  192. .chip = {
  193. .base = S5PC100_GPG1(0),
  194. .ngpio = S5PC100_GPIO_G1_NR,
  195. .label = "GPG1",
  196. },
  197. }, {
  198. .base = S5PC100_GPG2_BASE,
  199. .config = &gpio_cfg,
  200. .chip = {
  201. .base = S5PC100_GPG2(0),
  202. .ngpio = S5PC100_GPIO_G2_NR,
  203. .label = "GPG2",
  204. },
  205. }, {
  206. .base = S5PC100_GPG3_BASE,
  207. .config = &gpio_cfg,
  208. .chip = {
  209. .base = S5PC100_GPG3(0),
  210. .ngpio = S5PC100_GPIO_G3_NR,
  211. .label = "GPG3",
  212. },
  213. }, {
  214. .base = S5PC100_GPH0_BASE,
  215. .config = &gpio_cfg_eint,
  216. .chip = {
  217. .base = S5PC100_GPH0(0),
  218. .ngpio = S5PC100_GPIO_H0_NR,
  219. .label = "GPH0",
  220. .to_irq = s5pc100_gpiolib_to_eint,
  221. },
  222. }, {
  223. .base = S5PC100_GPH1_BASE,
  224. .config = &gpio_cfg_eint,
  225. .chip = {
  226. .base = S5PC100_GPH1(0),
  227. .ngpio = S5PC100_GPIO_H1_NR,
  228. .label = "GPH1",
  229. .to_irq = s5pc100_gpiolib_to_eint,
  230. },
  231. }, {
  232. .base = S5PC100_GPH2_BASE,
  233. .config = &gpio_cfg_eint,
  234. .chip = {
  235. .base = S5PC100_GPH2(0),
  236. .ngpio = S5PC100_GPIO_H2_NR,
  237. .label = "GPH2",
  238. .to_irq = s5pc100_gpiolib_to_eint,
  239. },
  240. }, {
  241. .base = S5PC100_GPH3_BASE,
  242. .config = &gpio_cfg_eint,
  243. .chip = {
  244. .base = S5PC100_GPH3(0),
  245. .ngpio = S5PC100_GPIO_H3_NR,
  246. .label = "GPH3",
  247. .to_irq = s5pc100_gpiolib_to_eint,
  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. static __init int s5pc100_gpiolib_init(void)
  372. {
  373. struct s3c_gpio_chip *chip;
  374. int nr_chips;
  375. int gpioint_group = 0;
  376. chip = s5pc100_gpio_chips;
  377. nr_chips = ARRAY_SIZE(s5pc100_gpio_chips);
  378. for (; nr_chips > 0; nr_chips--, chip++) {
  379. if (chip->config == &gpio_cfg) {
  380. /* gpio interrupts */
  381. chip->group = gpioint_group++;
  382. }
  383. }
  384. samsung_gpiolib_add_4bit_chips(s5pc100_gpio_chips,
  385. ARRAY_SIZE(s5pc100_gpio_chips));
  386. return 0;
  387. }
  388. core_initcall(s5pc100_gpiolib_init);