gpiolib.c 7.8 KB

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