gpio-s5pc100.c 7.2 KB

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