gpio-s5pc100.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /* linux/arch/arm/mach-s5pc100/gpiolib.c
  2. *
  3. * Copyright (c) 2010 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * Copyright 2009 Samsung Electronics Co
  7. * Kyungmin Park <kyungmin.park@samsung.com>
  8. *
  9. * S5PC100 - GPIOlib support
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/irq.h>
  17. #include <linux/io.h>
  18. #include <linux/gpio.h>
  19. #include <mach/map.h>
  20. #include <mach/regs-gpio.h>
  21. #include <plat/gpio-core.h>
  22. #include <plat/gpio-cfg.h>
  23. #include <plat/gpio-cfg-helpers.h>
  24. /* S5PC100 GPIO bank summary:
  25. *
  26. * Bank GPIOs Style INT Type
  27. * A0 8 4Bit GPIO_INT0
  28. * A1 5 4Bit GPIO_INT1
  29. * B 8 4Bit GPIO_INT2
  30. * C 5 4Bit GPIO_INT3
  31. * D 7 4Bit GPIO_INT4
  32. * E0 8 4Bit GPIO_INT5
  33. * E1 6 4Bit GPIO_INT6
  34. * F0 8 4Bit GPIO_INT7
  35. * F1 8 4Bit GPIO_INT8
  36. * F2 8 4Bit GPIO_INT9
  37. * F3 4 4Bit GPIO_INT10
  38. * G0 8 4Bit GPIO_INT11
  39. * G1 3 4Bit GPIO_INT12
  40. * G2 7 4Bit GPIO_INT13
  41. * G3 7 4Bit GPIO_INT14
  42. * H0 8 4Bit WKUP_INT
  43. * H1 8 4Bit WKUP_INT
  44. * H2 8 4Bit WKUP_INT
  45. * H3 8 4Bit WKUP_INT
  46. * I 8 4Bit GPIO_INT15
  47. * J0 8 4Bit GPIO_INT16
  48. * J1 5 4Bit GPIO_INT17
  49. * J2 8 4Bit GPIO_INT18
  50. * J3 8 4Bit GPIO_INT19
  51. * J4 4 4Bit GPIO_INT20
  52. * K0 8 4Bit None
  53. * K1 6 4Bit None
  54. * K2 8 4Bit None
  55. * K3 8 4Bit None
  56. * L0 8 4Bit None
  57. * L1 8 4Bit None
  58. * L2 8 4Bit None
  59. * L3 8 4Bit None
  60. */
  61. static struct s3c_gpio_cfg gpio_cfg = {
  62. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  63. .set_pull = s3c_gpio_setpull_updown,
  64. .get_pull = s3c_gpio_getpull_updown,
  65. };
  66. static struct s3c_gpio_cfg gpio_cfg_eint = {
  67. .cfg_eint = 0xf,
  68. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  69. .set_pull = s3c_gpio_setpull_updown,
  70. .get_pull = s3c_gpio_getpull_updown,
  71. };
  72. static struct s3c_gpio_cfg gpio_cfg_noint = {
  73. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  74. .set_pull = s3c_gpio_setpull_updown,
  75. .get_pull = s3c_gpio_getpull_updown,
  76. };
  77. /*
  78. * GPIO bank's base address given the index of the bank in the
  79. * list of all gpio banks.
  80. */
  81. #define S5PC100_BANK_BASE(bank_nr) (S5P_VA_GPIO + ((bank_nr) * 0x20))
  82. /*
  83. * Following are the gpio banks in S5PC100.
  84. *
  85. * The 'config' member when left to NULL, is initialized to the default
  86. * structure gpio_cfg in the init function below.
  87. *
  88. * The 'base' member is also initialized in the init function below.
  89. * Note: The initialization of 'base' member of s3c_gpio_chip structure
  90. * uses the above macro and depends on the banks being listed in order here.
  91. */
  92. static struct s3c_gpio_chip s5pc100_gpio_chips[] = {
  93. {
  94. .chip = {
  95. .base = S5PC100_GPA0(0),
  96. .ngpio = S5PC100_GPIO_A0_NR,
  97. .label = "GPA0",
  98. },
  99. }, {
  100. .chip = {
  101. .base = S5PC100_GPA1(0),
  102. .ngpio = S5PC100_GPIO_A1_NR,
  103. .label = "GPA1",
  104. },
  105. }, {
  106. .chip = {
  107. .base = S5PC100_GPB(0),
  108. .ngpio = S5PC100_GPIO_B_NR,
  109. .label = "GPB",
  110. },
  111. }, {
  112. .chip = {
  113. .base = S5PC100_GPC(0),
  114. .ngpio = S5PC100_GPIO_C_NR,
  115. .label = "GPC",
  116. },
  117. }, {
  118. .chip = {
  119. .base = S5PC100_GPD(0),
  120. .ngpio = S5PC100_GPIO_D_NR,
  121. .label = "GPD",
  122. },
  123. }, {
  124. .chip = {
  125. .base = S5PC100_GPE0(0),
  126. .ngpio = S5PC100_GPIO_E0_NR,
  127. .label = "GPE0",
  128. },
  129. }, {
  130. .chip = {
  131. .base = S5PC100_GPE1(0),
  132. .ngpio = S5PC100_GPIO_E1_NR,
  133. .label = "GPE1",
  134. },
  135. }, {
  136. .chip = {
  137. .base = S5PC100_GPF0(0),
  138. .ngpio = S5PC100_GPIO_F0_NR,
  139. .label = "GPF0",
  140. },
  141. }, {
  142. .chip = {
  143. .base = S5PC100_GPF1(0),
  144. .ngpio = S5PC100_GPIO_F1_NR,
  145. .label = "GPF1",
  146. },
  147. }, {
  148. .chip = {
  149. .base = S5PC100_GPF2(0),
  150. .ngpio = S5PC100_GPIO_F2_NR,
  151. .label = "GPF2",
  152. },
  153. }, {
  154. .chip = {
  155. .base = S5PC100_GPF3(0),
  156. .ngpio = S5PC100_GPIO_F3_NR,
  157. .label = "GPF3",
  158. },
  159. }, {
  160. .chip = {
  161. .base = S5PC100_GPG0(0),
  162. .ngpio = S5PC100_GPIO_G0_NR,
  163. .label = "GPG0",
  164. },
  165. }, {
  166. .chip = {
  167. .base = S5PC100_GPG1(0),
  168. .ngpio = S5PC100_GPIO_G1_NR,
  169. .label = "GPG1",
  170. },
  171. }, {
  172. .chip = {
  173. .base = S5PC100_GPG2(0),
  174. .ngpio = S5PC100_GPIO_G2_NR,
  175. .label = "GPG2",
  176. },
  177. }, {
  178. .chip = {
  179. .base = S5PC100_GPG3(0),
  180. .ngpio = S5PC100_GPIO_G3_NR,
  181. .label = "GPG3",
  182. },
  183. }, {
  184. .chip = {
  185. .base = S5PC100_GPI(0),
  186. .ngpio = S5PC100_GPIO_I_NR,
  187. .label = "GPI",
  188. },
  189. }, {
  190. .chip = {
  191. .base = S5PC100_GPJ0(0),
  192. .ngpio = S5PC100_GPIO_J0_NR,
  193. .label = "GPJ0",
  194. },
  195. }, {
  196. .chip = {
  197. .base = S5PC100_GPJ1(0),
  198. .ngpio = S5PC100_GPIO_J1_NR,
  199. .label = "GPJ1",
  200. },
  201. }, {
  202. .chip = {
  203. .base = S5PC100_GPJ2(0),
  204. .ngpio = S5PC100_GPIO_J2_NR,
  205. .label = "GPJ2",
  206. },
  207. }, {
  208. .chip = {
  209. .base = S5PC100_GPJ3(0),
  210. .ngpio = S5PC100_GPIO_J3_NR,
  211. .label = "GPJ3",
  212. },
  213. }, {
  214. .chip = {
  215. .base = S5PC100_GPJ4(0),
  216. .ngpio = S5PC100_GPIO_J4_NR,
  217. .label = "GPJ4",
  218. },
  219. }, {
  220. .config = &gpio_cfg_noint,
  221. .chip = {
  222. .base = S5PC100_GPK0(0),
  223. .ngpio = S5PC100_GPIO_K0_NR,
  224. .label = "GPK0",
  225. },
  226. }, {
  227. .config = &gpio_cfg_noint,
  228. .chip = {
  229. .base = S5PC100_GPK1(0),
  230. .ngpio = S5PC100_GPIO_K1_NR,
  231. .label = "GPK1",
  232. },
  233. }, {
  234. .config = &gpio_cfg_noint,
  235. .chip = {
  236. .base = S5PC100_GPK2(0),
  237. .ngpio = S5PC100_GPIO_K2_NR,
  238. .label = "GPK2",
  239. },
  240. }, {
  241. .config = &gpio_cfg_noint,
  242. .chip = {
  243. .base = S5PC100_GPK3(0),
  244. .ngpio = S5PC100_GPIO_K3_NR,
  245. .label = "GPK3",
  246. },
  247. }, {
  248. .config = &gpio_cfg_noint,
  249. .chip = {
  250. .base = S5PC100_GPL0(0),
  251. .ngpio = S5PC100_GPIO_L0_NR,
  252. .label = "GPL0",
  253. },
  254. }, {
  255. .config = &gpio_cfg_noint,
  256. .chip = {
  257. .base = S5PC100_GPL1(0),
  258. .ngpio = S5PC100_GPIO_L1_NR,
  259. .label = "GPL1",
  260. },
  261. }, {
  262. .config = &gpio_cfg_noint,
  263. .chip = {
  264. .base = S5PC100_GPL2(0),
  265. .ngpio = S5PC100_GPIO_L2_NR,
  266. .label = "GPL2",
  267. },
  268. }, {
  269. .config = &gpio_cfg_noint,
  270. .chip = {
  271. .base = S5PC100_GPL3(0),
  272. .ngpio = S5PC100_GPIO_L3_NR,
  273. .label = "GPL3",
  274. },
  275. }, {
  276. .config = &gpio_cfg_noint,
  277. .chip = {
  278. .base = S5PC100_GPL4(0),
  279. .ngpio = S5PC100_GPIO_L4_NR,
  280. .label = "GPL4",
  281. },
  282. }, {
  283. .base = (S5P_VA_GPIO + 0xC00),
  284. .config = &gpio_cfg_eint,
  285. .irq_base = IRQ_EINT(0),
  286. .chip = {
  287. .base = S5PC100_GPH0(0),
  288. .ngpio = S5PC100_GPIO_H0_NR,
  289. .label = "GPH0",
  290. .to_irq = samsung_gpiolib_to_irq,
  291. },
  292. }, {
  293. .base = (S5P_VA_GPIO + 0xC20),
  294. .config = &gpio_cfg_eint,
  295. .irq_base = IRQ_EINT(8),
  296. .chip = {
  297. .base = S5PC100_GPH1(0),
  298. .ngpio = S5PC100_GPIO_H1_NR,
  299. .label = "GPH1",
  300. .to_irq = samsung_gpiolib_to_irq,
  301. },
  302. }, {
  303. .base = (S5P_VA_GPIO + 0xC40),
  304. .config = &gpio_cfg_eint,
  305. .irq_base = IRQ_EINT(16),
  306. .chip = {
  307. .base = S5PC100_GPH2(0),
  308. .ngpio = S5PC100_GPIO_H2_NR,
  309. .label = "GPH2",
  310. .to_irq = samsung_gpiolib_to_irq,
  311. },
  312. }, {
  313. .base = (S5P_VA_GPIO + 0xC60),
  314. .config = &gpio_cfg_eint,
  315. .irq_base = IRQ_EINT(24),
  316. .chip = {
  317. .base = S5PC100_GPH3(0),
  318. .ngpio = S5PC100_GPIO_H3_NR,
  319. .label = "GPH3",
  320. .to_irq = samsung_gpiolib_to_irq,
  321. },
  322. },
  323. };
  324. static __init int s5pc100_gpiolib_init(void)
  325. {
  326. struct s3c_gpio_chip *chip = s5pc100_gpio_chips;
  327. int nr_chips = ARRAY_SIZE(s5pc100_gpio_chips);
  328. int gpioint_group = 0;
  329. int i;
  330. for (i = 0; i < nr_chips; i++, chip++) {
  331. if (chip->config == NULL) {
  332. chip->config = &gpio_cfg;
  333. chip->group = gpioint_group++;
  334. }
  335. if (chip->base == NULL)
  336. chip->base = S5PC100_BANK_BASE(i);
  337. }
  338. samsung_gpiolib_add_4bit_chips(s5pc100_gpio_chips, nr_chips);
  339. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  340. return 0;
  341. }
  342. core_initcall(s5pc100_gpiolib_init);