gpiolib.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. 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. 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. int s3c64xx_gpio2int_gpn(struct gpio_chip *chip, unsigned pin)
  184. {
  185. return IRQ_EINT(0) + pin;
  186. }
  187. static struct s3c_gpio_chip gpio_2bit[] = {
  188. {
  189. .base = S3C64XX_GPF_BASE,
  190. .config = &gpio_2bit_cfg_eint11,
  191. .chip = {
  192. .base = S3C64XX_GPF(0),
  193. .ngpio = S3C64XX_GPIO_F_NR,
  194. .label = "GPF",
  195. },
  196. }, {
  197. .base = S3C64XX_GPI_BASE,
  198. .config = &gpio_2bit_cfg_noint,
  199. .chip = {
  200. .base = S3C64XX_GPI(0),
  201. .ngpio = S3C64XX_GPIO_I_NR,
  202. .label = "GPI",
  203. },
  204. }, {
  205. .base = S3C64XX_GPJ_BASE,
  206. .config = &gpio_2bit_cfg_noint,
  207. .chip = {
  208. .base = S3C64XX_GPJ(0),
  209. .ngpio = S3C64XX_GPIO_J_NR,
  210. .label = "GPJ",
  211. },
  212. }, {
  213. .base = S3C64XX_GPN_BASE,
  214. .config = &gpio_2bit_cfg_eint10,
  215. .chip = {
  216. .base = S3C64XX_GPN(0),
  217. .ngpio = S3C64XX_GPIO_N_NR,
  218. .label = "GPN",
  219. .to_irq = s3c64xx_gpio2int_gpn,
  220. },
  221. }, {
  222. .base = S3C64XX_GPO_BASE,
  223. .config = &gpio_2bit_cfg_eint11,
  224. .chip = {
  225. .base = S3C64XX_GPO(0),
  226. .ngpio = S3C64XX_GPIO_O_NR,
  227. .label = "GPO",
  228. },
  229. }, {
  230. .base = S3C64XX_GPP_BASE,
  231. .config = &gpio_2bit_cfg_eint11,
  232. .chip = {
  233. .base = S3C64XX_GPP(0),
  234. .ngpio = S3C64XX_GPIO_P_NR,
  235. .label = "GPP",
  236. },
  237. }, {
  238. .base = S3C64XX_GPQ_BASE,
  239. .config = &gpio_2bit_cfg_eint11,
  240. .chip = {
  241. .base = S3C64XX_GPQ(0),
  242. .ngpio = S3C64XX_GPIO_Q_NR,
  243. .label = "GPQ",
  244. },
  245. },
  246. };
  247. static __init void s3c64xx_gpiolib_add_2bit(struct s3c_gpio_chip *chip)
  248. {
  249. chip->pm = __gpio_pm(&s3c_gpio_pm_2bit);
  250. }
  251. static __init void s3c64xx_gpiolib_add(struct s3c_gpio_chip *chips,
  252. int nr_chips,
  253. void (*fn)(struct s3c_gpio_chip *))
  254. {
  255. for (; nr_chips > 0; nr_chips--, chips++) {
  256. if (fn)
  257. (fn)(chips);
  258. s3c_gpiolib_add(chips);
  259. }
  260. }
  261. static __init int s3c64xx_gpiolib_init(void)
  262. {
  263. s3c64xx_gpiolib_add(gpio_4bit, ARRAY_SIZE(gpio_4bit),
  264. samsung_gpiolib_add_4bit);
  265. s3c64xx_gpiolib_add(gpio_4bit2, ARRAY_SIZE(gpio_4bit2),
  266. samsung_gpiolib_add_4bit2);
  267. s3c64xx_gpiolib_add(gpio_2bit, ARRAY_SIZE(gpio_2bit),
  268. s3c64xx_gpiolib_add_2bit);
  269. return 0;
  270. }
  271. core_initcall(s3c64xx_gpiolib_init);