gpiolib.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /* arch/arm/plat-s3c64xx/gpiolib.c
  2. *
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * S3C64XX - GPIOlib support
  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 <plat/gpio-core.h>
  20. #include <plat/gpio-cfg.h>
  21. #include <plat/gpio-cfg-helpers.h>
  22. #include <mach/regs-gpio.h>
  23. /* GPIO bank summary:
  24. *
  25. * Bank GPIOs Style SlpCon ExtInt Group
  26. * A 8 4Bit Yes 1
  27. * B 7 4Bit Yes 1
  28. * C 8 4Bit Yes 2
  29. * D 5 4Bit Yes 3
  30. * E 5 4Bit Yes None
  31. * F 16 2Bit Yes 4 [1]
  32. * G 7 4Bit Yes 5
  33. * H 10 4Bit[2] Yes 6
  34. * I 16 2Bit Yes None
  35. * J 12 2Bit Yes None
  36. * K 16 4Bit[2] No None
  37. * L 15 4Bit[2] No None
  38. * M 6 4Bit No IRQ_EINT
  39. * N 16 2Bit No IRQ_EINT
  40. * O 16 2Bit Yes 7
  41. * P 15 2Bit Yes 8
  42. * Q 9 2Bit Yes 9
  43. *
  44. * [1] BANKF pins 14,15 do not form part of the external interrupt sources
  45. * [2] BANK has two control registers, GPxCON0 and GPxCON1
  46. */
  47. static struct s3c_gpio_cfg gpio_4bit_cfg_noint = {
  48. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  49. .get_config = s3c_gpio_getcfg_s3c64xx_4bit,
  50. .set_pull = s3c_gpio_setpull_updown,
  51. .get_pull = s3c_gpio_getpull_updown,
  52. };
  53. static struct s3c_gpio_cfg gpio_4bit_cfg_eint0111 = {
  54. .cfg_eint = 7,
  55. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  56. .get_config = s3c_gpio_getcfg_s3c64xx_4bit,
  57. .set_pull = s3c_gpio_setpull_updown,
  58. .get_pull = s3c_gpio_getpull_updown,
  59. };
  60. static struct s3c_gpio_cfg gpio_4bit_cfg_eint0011 = {
  61. .cfg_eint = 3,
  62. .get_config = s3c_gpio_getcfg_s3c64xx_4bit,
  63. .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
  64. .set_pull = s3c_gpio_setpull_updown,
  65. .get_pull = s3c_gpio_getpull_updown,
  66. };
  67. static int s3c64xx_gpio2int_gpm(struct gpio_chip *chip, unsigned pin)
  68. {
  69. return pin < 5 ? IRQ_EINT(23) + pin : -ENXIO;
  70. }
  71. static struct s3c_gpio_chip gpio_4bit[] = {
  72. {
  73. .base = S3C64XX_GPA_BASE,
  74. .config = &gpio_4bit_cfg_eint0111,
  75. .chip = {
  76. .base = S3C64XX_GPA(0),
  77. .ngpio = S3C64XX_GPIO_A_NR,
  78. .label = "GPA",
  79. },
  80. }, {
  81. .base = S3C64XX_GPB_BASE,
  82. .config = &gpio_4bit_cfg_eint0111,
  83. .chip = {
  84. .base = S3C64XX_GPB(0),
  85. .ngpio = S3C64XX_GPIO_B_NR,
  86. .label = "GPB",
  87. },
  88. }, {
  89. .base = S3C64XX_GPC_BASE,
  90. .config = &gpio_4bit_cfg_eint0111,
  91. .chip = {
  92. .base = S3C64XX_GPC(0),
  93. .ngpio = S3C64XX_GPIO_C_NR,
  94. .label = "GPC",
  95. },
  96. }, {
  97. .base = S3C64XX_GPD_BASE,
  98. .config = &gpio_4bit_cfg_eint0111,
  99. .chip = {
  100. .base = S3C64XX_GPD(0),
  101. .ngpio = S3C64XX_GPIO_D_NR,
  102. .label = "GPD",
  103. },
  104. }, {
  105. .base = S3C64XX_GPE_BASE,
  106. .config = &gpio_4bit_cfg_noint,
  107. .chip = {
  108. .base = S3C64XX_GPE(0),
  109. .ngpio = S3C64XX_GPIO_E_NR,
  110. .label = "GPE",
  111. },
  112. }, {
  113. .base = S3C64XX_GPG_BASE,
  114. .config = &gpio_4bit_cfg_eint0111,
  115. .chip = {
  116. .base = S3C64XX_GPG(0),
  117. .ngpio = S3C64XX_GPIO_G_NR,
  118. .label = "GPG",
  119. },
  120. }, {
  121. .base = S3C64XX_GPM_BASE,
  122. .config = &gpio_4bit_cfg_eint0011,
  123. .chip = {
  124. .base = S3C64XX_GPM(0),
  125. .ngpio = S3C64XX_GPIO_M_NR,
  126. .label = "GPM",
  127. .to_irq = s3c64xx_gpio2int_gpm,
  128. },
  129. },
  130. };
  131. static int s3c64xx_gpio2int_gpl(struct gpio_chip *chip, unsigned pin)
  132. {
  133. return pin >= 8 ? IRQ_EINT(16) + pin - 8 : -ENXIO;
  134. }
  135. static struct s3c_gpio_chip gpio_4bit2[] = {
  136. {
  137. .base = S3C64XX_GPH_BASE + 0x4,
  138. .config = &gpio_4bit_cfg_eint0111,
  139. .chip = {
  140. .base = S3C64XX_GPH(0),
  141. .ngpio = S3C64XX_GPIO_H_NR,
  142. .label = "GPH",
  143. },
  144. }, {
  145. .base = S3C64XX_GPK_BASE + 0x4,
  146. .config = &gpio_4bit_cfg_noint,
  147. .chip = {
  148. .base = S3C64XX_GPK(0),
  149. .ngpio = S3C64XX_GPIO_K_NR,
  150. .label = "GPK",
  151. },
  152. }, {
  153. .base = S3C64XX_GPL_BASE + 0x4,
  154. .config = &gpio_4bit_cfg_eint0011,
  155. .chip = {
  156. .base = S3C64XX_GPL(0),
  157. .ngpio = S3C64XX_GPIO_L_NR,
  158. .label = "GPL",
  159. .to_irq = s3c64xx_gpio2int_gpl,
  160. },
  161. },
  162. };
  163. static struct s3c_gpio_cfg gpio_2bit_cfg_noint = {
  164. .set_config = s3c_gpio_setcfg_s3c24xx,
  165. .get_config = s3c_gpio_getcfg_s3c24xx,
  166. .set_pull = s3c_gpio_setpull_updown,
  167. .get_pull = s3c_gpio_getpull_updown,
  168. };
  169. static struct s3c_gpio_cfg gpio_2bit_cfg_eint10 = {
  170. .cfg_eint = 2,
  171. .set_config = s3c_gpio_setcfg_s3c24xx,
  172. .get_config = s3c_gpio_getcfg_s3c24xx,
  173. .set_pull = s3c_gpio_setpull_updown,
  174. .get_pull = s3c_gpio_getpull_updown,
  175. };
  176. static struct s3c_gpio_cfg gpio_2bit_cfg_eint11 = {
  177. .cfg_eint = 3,
  178. .set_config = s3c_gpio_setcfg_s3c24xx,
  179. .get_config = s3c_gpio_getcfg_s3c24xx,
  180. .set_pull = s3c_gpio_setpull_updown,
  181. .get_pull = s3c_gpio_getpull_updown,
  182. };
  183. static struct s3c_gpio_chip gpio_2bit[] = {
  184. {
  185. .base = S3C64XX_GPF_BASE,
  186. .config = &gpio_2bit_cfg_eint11,
  187. .chip = {
  188. .base = S3C64XX_GPF(0),
  189. .ngpio = S3C64XX_GPIO_F_NR,
  190. .label = "GPF",
  191. },
  192. }, {
  193. .base = S3C64XX_GPI_BASE,
  194. .config = &gpio_2bit_cfg_noint,
  195. .chip = {
  196. .base = S3C64XX_GPI(0),
  197. .ngpio = S3C64XX_GPIO_I_NR,
  198. .label = "GPI",
  199. },
  200. }, {
  201. .base = S3C64XX_GPJ_BASE,
  202. .config = &gpio_2bit_cfg_noint,
  203. .chip = {
  204. .base = S3C64XX_GPJ(0),
  205. .ngpio = S3C64XX_GPIO_J_NR,
  206. .label = "GPJ",
  207. },
  208. }, {
  209. .base = S3C64XX_GPN_BASE,
  210. .irq_base = IRQ_EINT(0),
  211. .config = &gpio_2bit_cfg_eint10,
  212. .chip = {
  213. .base = S3C64XX_GPN(0),
  214. .ngpio = S3C64XX_GPIO_N_NR,
  215. .label = "GPN",
  216. .to_irq = samsung_gpiolib_to_irq,
  217. },
  218. }, {
  219. .base = S3C64XX_GPO_BASE,
  220. .config = &gpio_2bit_cfg_eint11,
  221. .chip = {
  222. .base = S3C64XX_GPO(0),
  223. .ngpio = S3C64XX_GPIO_O_NR,
  224. .label = "GPO",
  225. },
  226. }, {
  227. .base = S3C64XX_GPP_BASE,
  228. .config = &gpio_2bit_cfg_eint11,
  229. .chip = {
  230. .base = S3C64XX_GPP(0),
  231. .ngpio = S3C64XX_GPIO_P_NR,
  232. .label = "GPP",
  233. },
  234. }, {
  235. .base = S3C64XX_GPQ_BASE,
  236. .config = &gpio_2bit_cfg_eint11,
  237. .chip = {
  238. .base = S3C64XX_GPQ(0),
  239. .ngpio = S3C64XX_GPIO_Q_NR,
  240. .label = "GPQ",
  241. },
  242. },
  243. };
  244. static __init void s3c64xx_gpiolib_add_2bit(struct s3c_gpio_chip *chip)
  245. {
  246. chip->pm = __gpio_pm(&s3c_gpio_pm_2bit);
  247. }
  248. static __init void s3c64xx_gpiolib_add(struct s3c_gpio_chip *chips,
  249. int nr_chips,
  250. void (*fn)(struct s3c_gpio_chip *))
  251. {
  252. for (; nr_chips > 0; nr_chips--, chips++) {
  253. if (fn)
  254. (fn)(chips);
  255. s3c_gpiolib_add(chips);
  256. }
  257. }
  258. static __init int s3c64xx_gpiolib_init(void)
  259. {
  260. s3c64xx_gpiolib_add(gpio_4bit, ARRAY_SIZE(gpio_4bit),
  261. samsung_gpiolib_add_4bit);
  262. s3c64xx_gpiolib_add(gpio_4bit2, ARRAY_SIZE(gpio_4bit2),
  263. samsung_gpiolib_add_4bit2);
  264. s3c64xx_gpiolib_add(gpio_2bit, ARRAY_SIZE(gpio_2bit),
  265. s3c64xx_gpiolib_add_2bit);
  266. return 0;
  267. }
  268. core_initcall(s3c64xx_gpiolib_init);