gpio-exynos4.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * EXYNOS4 - GPIOlib support
  3. *
  4. * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/irq.h>
  13. #include <linux/io.h>
  14. #include <linux/gpio.h>
  15. #include <mach/map.h>
  16. #include <plat/gpio-core.h>
  17. #include <plat/gpio-cfg.h>
  18. #include <plat/gpio-cfg-helpers.h>
  19. int s3c_gpio_setpull_exynos4(struct s3c_gpio_chip *chip,
  20. unsigned int off, s3c_gpio_pull_t pull)
  21. {
  22. if (pull == S3C_GPIO_PULL_UP)
  23. pull = 3;
  24. return s3c_gpio_setpull_updown(chip, off, pull);
  25. }
  26. s3c_gpio_pull_t s3c_gpio_getpull_exynos4(struct s3c_gpio_chip *chip,
  27. unsigned int off)
  28. {
  29. s3c_gpio_pull_t pull;
  30. pull = s3c_gpio_getpull_updown(chip, off);
  31. if (pull == 3)
  32. pull = S3C_GPIO_PULL_UP;
  33. return pull;
  34. }
  35. static struct s3c_gpio_cfg gpio_cfg = {
  36. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  37. .set_pull = s3c_gpio_setpull_exynos4,
  38. .get_pull = s3c_gpio_getpull_exynos4,
  39. };
  40. static struct s3c_gpio_cfg gpio_cfg_noint = {
  41. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  42. .set_pull = s3c_gpio_setpull_exynos4,
  43. .get_pull = s3c_gpio_getpull_exynos4,
  44. };
  45. /*
  46. * Following are the gpio banks in v310.
  47. *
  48. * The 'config' member when left to NULL, is initialized to the default
  49. * structure gpio_cfg in the init function below.
  50. *
  51. * The 'base' member is also initialized in the init function below.
  52. * Note: The initialization of 'base' member of s3c_gpio_chip structure
  53. * uses the above macro and depends on the banks being listed in order here.
  54. */
  55. static struct s3c_gpio_chip exynos4_gpio_part1_4bit[] = {
  56. {
  57. .chip = {
  58. .base = EXYNOS4_GPA0(0),
  59. .ngpio = EXYNOS4_GPIO_A0_NR,
  60. .label = "GPA0",
  61. },
  62. }, {
  63. .chip = {
  64. .base = EXYNOS4_GPA1(0),
  65. .ngpio = EXYNOS4_GPIO_A1_NR,
  66. .label = "GPA1",
  67. },
  68. }, {
  69. .chip = {
  70. .base = EXYNOS4_GPB(0),
  71. .ngpio = EXYNOS4_GPIO_B_NR,
  72. .label = "GPB",
  73. },
  74. }, {
  75. .chip = {
  76. .base = EXYNOS4_GPC0(0),
  77. .ngpio = EXYNOS4_GPIO_C0_NR,
  78. .label = "GPC0",
  79. },
  80. }, {
  81. .chip = {
  82. .base = EXYNOS4_GPC1(0),
  83. .ngpio = EXYNOS4_GPIO_C1_NR,
  84. .label = "GPC1",
  85. },
  86. }, {
  87. .chip = {
  88. .base = EXYNOS4_GPD0(0),
  89. .ngpio = EXYNOS4_GPIO_D0_NR,
  90. .label = "GPD0",
  91. },
  92. }, {
  93. .chip = {
  94. .base = EXYNOS4_GPD1(0),
  95. .ngpio = EXYNOS4_GPIO_D1_NR,
  96. .label = "GPD1",
  97. },
  98. }, {
  99. .chip = {
  100. .base = EXYNOS4_GPE0(0),
  101. .ngpio = EXYNOS4_GPIO_E0_NR,
  102. .label = "GPE0",
  103. },
  104. }, {
  105. .chip = {
  106. .base = EXYNOS4_GPE1(0),
  107. .ngpio = EXYNOS4_GPIO_E1_NR,
  108. .label = "GPE1",
  109. },
  110. }, {
  111. .chip = {
  112. .base = EXYNOS4_GPE2(0),
  113. .ngpio = EXYNOS4_GPIO_E2_NR,
  114. .label = "GPE2",
  115. },
  116. }, {
  117. .chip = {
  118. .base = EXYNOS4_GPE3(0),
  119. .ngpio = EXYNOS4_GPIO_E3_NR,
  120. .label = "GPE3",
  121. },
  122. }, {
  123. .chip = {
  124. .base = EXYNOS4_GPE4(0),
  125. .ngpio = EXYNOS4_GPIO_E4_NR,
  126. .label = "GPE4",
  127. },
  128. }, {
  129. .chip = {
  130. .base = EXYNOS4_GPF0(0),
  131. .ngpio = EXYNOS4_GPIO_F0_NR,
  132. .label = "GPF0",
  133. },
  134. }, {
  135. .chip = {
  136. .base = EXYNOS4_GPF1(0),
  137. .ngpio = EXYNOS4_GPIO_F1_NR,
  138. .label = "GPF1",
  139. },
  140. }, {
  141. .chip = {
  142. .base = EXYNOS4_GPF2(0),
  143. .ngpio = EXYNOS4_GPIO_F2_NR,
  144. .label = "GPF2",
  145. },
  146. }, {
  147. .chip = {
  148. .base = EXYNOS4_GPF3(0),
  149. .ngpio = EXYNOS4_GPIO_F3_NR,
  150. .label = "GPF3",
  151. },
  152. },
  153. };
  154. static struct s3c_gpio_chip exynos4_gpio_part2_4bit[] = {
  155. {
  156. .chip = {
  157. .base = EXYNOS4_GPJ0(0),
  158. .ngpio = EXYNOS4_GPIO_J0_NR,
  159. .label = "GPJ0",
  160. },
  161. }, {
  162. .chip = {
  163. .base = EXYNOS4_GPJ1(0),
  164. .ngpio = EXYNOS4_GPIO_J1_NR,
  165. .label = "GPJ1",
  166. },
  167. }, {
  168. .chip = {
  169. .base = EXYNOS4_GPK0(0),
  170. .ngpio = EXYNOS4_GPIO_K0_NR,
  171. .label = "GPK0",
  172. },
  173. }, {
  174. .chip = {
  175. .base = EXYNOS4_GPK1(0),
  176. .ngpio = EXYNOS4_GPIO_K1_NR,
  177. .label = "GPK1",
  178. },
  179. }, {
  180. .chip = {
  181. .base = EXYNOS4_GPK2(0),
  182. .ngpio = EXYNOS4_GPIO_K2_NR,
  183. .label = "GPK2",
  184. },
  185. }, {
  186. .chip = {
  187. .base = EXYNOS4_GPK3(0),
  188. .ngpio = EXYNOS4_GPIO_K3_NR,
  189. .label = "GPK3",
  190. },
  191. }, {
  192. .chip = {
  193. .base = EXYNOS4_GPL0(0),
  194. .ngpio = EXYNOS4_GPIO_L0_NR,
  195. .label = "GPL0",
  196. },
  197. }, {
  198. .chip = {
  199. .base = EXYNOS4_GPL1(0),
  200. .ngpio = EXYNOS4_GPIO_L1_NR,
  201. .label = "GPL1",
  202. },
  203. }, {
  204. .chip = {
  205. .base = EXYNOS4_GPL2(0),
  206. .ngpio = EXYNOS4_GPIO_L2_NR,
  207. .label = "GPL2",
  208. },
  209. }, {
  210. .config = &gpio_cfg_noint,
  211. .chip = {
  212. .base = EXYNOS4_GPY0(0),
  213. .ngpio = EXYNOS4_GPIO_Y0_NR,
  214. .label = "GPY0",
  215. },
  216. }, {
  217. .config = &gpio_cfg_noint,
  218. .chip = {
  219. .base = EXYNOS4_GPY1(0),
  220. .ngpio = EXYNOS4_GPIO_Y1_NR,
  221. .label = "GPY1",
  222. },
  223. }, {
  224. .config = &gpio_cfg_noint,
  225. .chip = {
  226. .base = EXYNOS4_GPY2(0),
  227. .ngpio = EXYNOS4_GPIO_Y2_NR,
  228. .label = "GPY2",
  229. },
  230. }, {
  231. .config = &gpio_cfg_noint,
  232. .chip = {
  233. .base = EXYNOS4_GPY3(0),
  234. .ngpio = EXYNOS4_GPIO_Y3_NR,
  235. .label = "GPY3",
  236. },
  237. }, {
  238. .config = &gpio_cfg_noint,
  239. .chip = {
  240. .base = EXYNOS4_GPY4(0),
  241. .ngpio = EXYNOS4_GPIO_Y4_NR,
  242. .label = "GPY4",
  243. },
  244. }, {
  245. .config = &gpio_cfg_noint,
  246. .chip = {
  247. .base = EXYNOS4_GPY5(0),
  248. .ngpio = EXYNOS4_GPIO_Y5_NR,
  249. .label = "GPY5",
  250. },
  251. }, {
  252. .config = &gpio_cfg_noint,
  253. .chip = {
  254. .base = EXYNOS4_GPY6(0),
  255. .ngpio = EXYNOS4_GPIO_Y6_NR,
  256. .label = "GPY6",
  257. },
  258. }, {
  259. .base = (S5P_VA_GPIO2 + 0xC00),
  260. .config = &gpio_cfg_noint,
  261. .irq_base = IRQ_EINT(0),
  262. .chip = {
  263. .base = EXYNOS4_GPX0(0),
  264. .ngpio = EXYNOS4_GPIO_X0_NR,
  265. .label = "GPX0",
  266. .to_irq = samsung_gpiolib_to_irq,
  267. },
  268. }, {
  269. .base = (S5P_VA_GPIO2 + 0xC20),
  270. .config = &gpio_cfg_noint,
  271. .irq_base = IRQ_EINT(8),
  272. .chip = {
  273. .base = EXYNOS4_GPX1(0),
  274. .ngpio = EXYNOS4_GPIO_X1_NR,
  275. .label = "GPX1",
  276. .to_irq = samsung_gpiolib_to_irq,
  277. },
  278. }, {
  279. .base = (S5P_VA_GPIO2 + 0xC40),
  280. .config = &gpio_cfg_noint,
  281. .irq_base = IRQ_EINT(16),
  282. .chip = {
  283. .base = EXYNOS4_GPX2(0),
  284. .ngpio = EXYNOS4_GPIO_X2_NR,
  285. .label = "GPX2",
  286. .to_irq = samsung_gpiolib_to_irq,
  287. },
  288. }, {
  289. .base = (S5P_VA_GPIO2 + 0xC60),
  290. .config = &gpio_cfg_noint,
  291. .irq_base = IRQ_EINT(24),
  292. .chip = {
  293. .base = EXYNOS4_GPX3(0),
  294. .ngpio = EXYNOS4_GPIO_X3_NR,
  295. .label = "GPX3",
  296. .to_irq = samsung_gpiolib_to_irq,
  297. },
  298. },
  299. };
  300. static struct s3c_gpio_chip exynos4_gpio_part3_4bit[] = {
  301. {
  302. .chip = {
  303. .base = EXYNOS4_GPZ(0),
  304. .ngpio = EXYNOS4_GPIO_Z_NR,
  305. .label = "GPZ",
  306. },
  307. },
  308. };
  309. static __init int exynos4_gpiolib_init(void)
  310. {
  311. struct s3c_gpio_chip *chip;
  312. int i;
  313. int group = 0;
  314. int nr_chips;
  315. /* GPIO part 1 */
  316. chip = exynos4_gpio_part1_4bit;
  317. nr_chips = ARRAY_SIZE(exynos4_gpio_part1_4bit);
  318. for (i = 0; i < nr_chips; i++, chip++) {
  319. if (chip->config == NULL) {
  320. chip->config = &gpio_cfg;
  321. /* Assign the GPIO interrupt group */
  322. chip->group = group++;
  323. }
  324. if (chip->base == NULL)
  325. chip->base = S5P_VA_GPIO1 + (i) * 0x20;
  326. }
  327. samsung_gpiolib_add_4bit_chips(exynos4_gpio_part1_4bit, nr_chips);
  328. /* GPIO part 2 */
  329. chip = exynos4_gpio_part2_4bit;
  330. nr_chips = ARRAY_SIZE(exynos4_gpio_part2_4bit);
  331. for (i = 0; i < nr_chips; i++, chip++) {
  332. if (chip->config == NULL) {
  333. chip->config = &gpio_cfg;
  334. /* Assign the GPIO interrupt group */
  335. chip->group = group++;
  336. }
  337. if (chip->base == NULL)
  338. chip->base = S5P_VA_GPIO2 + (i) * 0x20;
  339. }
  340. samsung_gpiolib_add_4bit_chips(exynos4_gpio_part2_4bit, nr_chips);
  341. /* GPIO part 3 */
  342. chip = exynos4_gpio_part3_4bit;
  343. nr_chips = ARRAY_SIZE(exynos4_gpio_part3_4bit);
  344. for (i = 0; i < nr_chips; i++, chip++) {
  345. if (chip->config == NULL) {
  346. chip->config = &gpio_cfg;
  347. /* Assign the GPIO interrupt group */
  348. chip->group = group++;
  349. }
  350. if (chip->base == NULL)
  351. chip->base = S5P_VA_GPIO3 + (i) * 0x20;
  352. }
  353. samsung_gpiolib_add_4bit_chips(exynos4_gpio_part3_4bit, nr_chips);
  354. s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS);
  355. s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS);
  356. return 0;
  357. }
  358. core_initcall(exynos4_gpiolib_init);