gpiolib.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /* linux/arch/arm/mach-s5pv310/gpiolib.c
  2. *
  3. * Copyright (c) 2010 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * S5PV310 - GPIOlib support
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/irq.h>
  14. #include <linux/io.h>
  15. #include <linux/gpio.h>
  16. #include <mach/map.h>
  17. #include <plat/gpio-core.h>
  18. #include <plat/gpio-cfg.h>
  19. #include <plat/gpio-cfg-helpers.h>
  20. static struct s3c_gpio_cfg gpio_cfg = {
  21. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  22. .set_pull = s3c_gpio_setpull_updown,
  23. .get_pull = s3c_gpio_getpull_updown,
  24. };
  25. static struct s3c_gpio_cfg gpio_cfg_noint = {
  26. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  27. .set_pull = s3c_gpio_setpull_updown,
  28. .get_pull = s3c_gpio_getpull_updown,
  29. };
  30. /*
  31. * Following are the gpio banks in v310.
  32. *
  33. * The 'config' member when left to NULL, is initialized to the default
  34. * structure gpio_cfg in the init function below.
  35. *
  36. * The 'base' member is also initialized in the init function below.
  37. * Note: The initialization of 'base' member of s3c_gpio_chip structure
  38. * uses the above macro and depends on the banks being listed in order here.
  39. */
  40. static struct s3c_gpio_chip s5pv310_gpio_part1_4bit[] = {
  41. {
  42. .chip = {
  43. .base = S5PV310_GPA0(0),
  44. .ngpio = S5PV310_GPIO_A0_NR,
  45. .label = "GPA0",
  46. },
  47. }, {
  48. .chip = {
  49. .base = S5PV310_GPA1(0),
  50. .ngpio = S5PV310_GPIO_A1_NR,
  51. .label = "GPA1",
  52. },
  53. }, {
  54. .chip = {
  55. .base = S5PV310_GPB(0),
  56. .ngpio = S5PV310_GPIO_B_NR,
  57. .label = "GPB",
  58. },
  59. }, {
  60. .chip = {
  61. .base = S5PV310_GPC0(0),
  62. .ngpio = S5PV310_GPIO_C0_NR,
  63. .label = "GPC0",
  64. },
  65. }, {
  66. .chip = {
  67. .base = S5PV310_GPC1(0),
  68. .ngpio = S5PV310_GPIO_C1_NR,
  69. .label = "GPC1",
  70. },
  71. }, {
  72. .chip = {
  73. .base = S5PV310_GPD0(0),
  74. .ngpio = S5PV310_GPIO_D0_NR,
  75. .label = "GPD0",
  76. },
  77. }, {
  78. .chip = {
  79. .base = S5PV310_GPD1(0),
  80. .ngpio = S5PV310_GPIO_D1_NR,
  81. .label = "GPD1",
  82. },
  83. }, {
  84. .chip = {
  85. .base = S5PV310_GPE0(0),
  86. .ngpio = S5PV310_GPIO_E0_NR,
  87. .label = "GPE0",
  88. },
  89. }, {
  90. .chip = {
  91. .base = S5PV310_GPE1(0),
  92. .ngpio = S5PV310_GPIO_E1_NR,
  93. .label = "GPE1",
  94. },
  95. }, {
  96. .chip = {
  97. .base = S5PV310_GPE2(0),
  98. .ngpio = S5PV310_GPIO_E2_NR,
  99. .label = "GPE2",
  100. },
  101. }, {
  102. .chip = {
  103. .base = S5PV310_GPE3(0),
  104. .ngpio = S5PV310_GPIO_E3_NR,
  105. .label = "GPE3",
  106. },
  107. }, {
  108. .chip = {
  109. .base = S5PV310_GPE4(0),
  110. .ngpio = S5PV310_GPIO_E4_NR,
  111. .label = "GPE4",
  112. },
  113. }, {
  114. .chip = {
  115. .base = S5PV310_GPF0(0),
  116. .ngpio = S5PV310_GPIO_F0_NR,
  117. .label = "GPF0",
  118. },
  119. }, {
  120. .chip = {
  121. .base = S5PV310_GPF1(0),
  122. .ngpio = S5PV310_GPIO_F1_NR,
  123. .label = "GPF1",
  124. },
  125. }, {
  126. .chip = {
  127. .base = S5PV310_GPF2(0),
  128. .ngpio = S5PV310_GPIO_F2_NR,
  129. .label = "GPF2",
  130. },
  131. }, {
  132. .chip = {
  133. .base = S5PV310_GPF3(0),
  134. .ngpio = S5PV310_GPIO_F3_NR,
  135. .label = "GPF3",
  136. },
  137. },
  138. };
  139. static struct s3c_gpio_chip s5pv310_gpio_part2_4bit[] = {
  140. {
  141. .chip = {
  142. .base = S5PV310_GPJ0(0),
  143. .ngpio = S5PV310_GPIO_J0_NR,
  144. .label = "GPJ0",
  145. },
  146. }, {
  147. .chip = {
  148. .base = S5PV310_GPJ1(0),
  149. .ngpio = S5PV310_GPIO_J1_NR,
  150. .label = "GPJ1",
  151. },
  152. }, {
  153. .chip = {
  154. .base = S5PV310_GPK0(0),
  155. .ngpio = S5PV310_GPIO_K0_NR,
  156. .label = "GPK0",
  157. },
  158. }, {
  159. .chip = {
  160. .base = S5PV310_GPK1(0),
  161. .ngpio = S5PV310_GPIO_K1_NR,
  162. .label = "GPK1",
  163. },
  164. }, {
  165. .chip = {
  166. .base = S5PV310_GPK2(0),
  167. .ngpio = S5PV310_GPIO_K2_NR,
  168. .label = "GPK2",
  169. },
  170. }, {
  171. .chip = {
  172. .base = S5PV310_GPK3(0),
  173. .ngpio = S5PV310_GPIO_K3_NR,
  174. .label = "GPK3",
  175. },
  176. }, {
  177. .chip = {
  178. .base = S5PV310_GPL0(0),
  179. .ngpio = S5PV310_GPIO_L0_NR,
  180. .label = "GPL0",
  181. },
  182. }, {
  183. .chip = {
  184. .base = S5PV310_GPL1(0),
  185. .ngpio = S5PV310_GPIO_L1_NR,
  186. .label = "GPL1",
  187. },
  188. }, {
  189. .chip = {
  190. .base = S5PV310_GPL2(0),
  191. .ngpio = S5PV310_GPIO_L2_NR,
  192. .label = "GPL2",
  193. },
  194. }, {
  195. .base = (S5P_VA_GPIO2 + 0xC00),
  196. .config = &gpio_cfg_noint,
  197. .irq_base = IRQ_EINT(0),
  198. .chip = {
  199. .base = S5PV310_GPX0(0),
  200. .ngpio = S5PV310_GPIO_X0_NR,
  201. .label = "GPX0",
  202. .to_irq = samsung_gpiolib_to_irq,
  203. },
  204. }, {
  205. .base = (S5P_VA_GPIO2 + 0xC20),
  206. .config = &gpio_cfg_noint,
  207. .irq_base = IRQ_EINT(8),
  208. .chip = {
  209. .base = S5PV310_GPX1(0),
  210. .ngpio = S5PV310_GPIO_X1_NR,
  211. .label = "GPX1",
  212. .to_irq = samsung_gpiolib_to_irq,
  213. },
  214. }, {
  215. .base = (S5P_VA_GPIO2 + 0xC40),
  216. .config = &gpio_cfg_noint,
  217. .irq_base = IRQ_EINT(16),
  218. .chip = {
  219. .base = S5PV310_GPX2(0),
  220. .ngpio = S5PV310_GPIO_X2_NR,
  221. .label = "GPX2",
  222. .to_irq = samsung_gpiolib_to_irq,
  223. },
  224. }, {
  225. .base = (S5P_VA_GPIO2 + 0xC60),
  226. .config = &gpio_cfg_noint,
  227. .irq_base = IRQ_EINT(24),
  228. .chip = {
  229. .base = S5PV310_GPX3(0),
  230. .ngpio = S5PV310_GPIO_X3_NR,
  231. .label = "GPX3",
  232. .to_irq = samsung_gpiolib_to_irq,
  233. },
  234. },
  235. };
  236. static struct s3c_gpio_chip s5pv310_gpio_part3_4bit[] = {
  237. {
  238. .chip = {
  239. .base = S5PV310_GPZ(0),
  240. .ngpio = S5PV310_GPIO_Z_NR,
  241. .label = "GPZ",
  242. },
  243. },
  244. };
  245. static __init int s5pv310_gpiolib_init(void)
  246. {
  247. struct s3c_gpio_chip *chip;
  248. int i;
  249. int nr_chips;
  250. /* GPIO part 1 */
  251. chip = s5pv310_gpio_part1_4bit;
  252. nr_chips = ARRAY_SIZE(s5pv310_gpio_part1_4bit);
  253. for (i = 0; i < nr_chips; i++, chip++) {
  254. if (chip->config == NULL)
  255. chip->config = &gpio_cfg;
  256. if (chip->base == NULL)
  257. chip->base = S5P_VA_GPIO1 + (i) * 0x20;
  258. }
  259. samsung_gpiolib_add_4bit_chips(s5pv310_gpio_part1_4bit, nr_chips);
  260. /* GPIO part 2 */
  261. chip = s5pv310_gpio_part2_4bit;
  262. nr_chips = ARRAY_SIZE(s5pv310_gpio_part2_4bit);
  263. for (i = 0; i < nr_chips; i++, chip++) {
  264. if (chip->config == NULL)
  265. chip->config = &gpio_cfg;
  266. if (chip->base == NULL)
  267. chip->base = S5P_VA_GPIO2 + (i) * 0x20;
  268. }
  269. samsung_gpiolib_add_4bit_chips(s5pv310_gpio_part2_4bit, nr_chips);
  270. /* GPIO part 3 */
  271. chip = s5pv310_gpio_part3_4bit;
  272. nr_chips = ARRAY_SIZE(s5pv310_gpio_part3_4bit);
  273. for (i = 0; i < nr_chips; i++, chip++) {
  274. if (chip->config == NULL)
  275. chip->config = &gpio_cfg;
  276. if (chip->base == NULL)
  277. chip->base = S5P_VA_GPIO3 + (i) * 0x20;
  278. }
  279. samsung_gpiolib_add_4bit_chips(s5pv310_gpio_part3_4bit, nr_chips);
  280. return 0;
  281. }
  282. core_initcall(s5pv310_gpiolib_init);