gpiolib.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* linux/arch/arm/plat-s3c24xx/gpiolib.c
  2. *
  3. * Copyright (c) 2008-2010 Simtec Electronics
  4. * http://armlinux.simtec.co.uk/
  5. * Ben Dooks <ben@simtec.co.uk>
  6. *
  7. * S3C24XX GPIOlib support
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/sysdev.h>
  18. #include <linux/ioport.h>
  19. #include <linux/io.h>
  20. #include <linux/gpio.h>
  21. #include <plat/gpio-core.h>
  22. #include <plat/gpio-cfg.h>
  23. #include <plat/gpio-cfg-helpers.h>
  24. #include <mach/hardware.h>
  25. #include <asm/irq.h>
  26. #include <plat/pm.h>
  27. #include <mach/regs-gpio.h>
  28. static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
  29. {
  30. return -EINVAL;
  31. }
  32. static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
  33. unsigned offset, int value)
  34. {
  35. struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
  36. void __iomem *base = ourchip->base;
  37. unsigned long flags;
  38. unsigned long dat;
  39. unsigned long con;
  40. local_irq_save(flags);
  41. con = __raw_readl(base + 0x00);
  42. dat = __raw_readl(base + 0x04);
  43. dat &= ~(1 << offset);
  44. if (value)
  45. dat |= 1 << offset;
  46. __raw_writel(dat, base + 0x04);
  47. con &= ~(1 << offset);
  48. __raw_writel(con, base + 0x00);
  49. __raw_writel(dat, base + 0x04);
  50. local_irq_restore(flags);
  51. return 0;
  52. }
  53. static int s3c24xx_gpiolib_bankf_toirq(struct gpio_chip *chip, unsigned offset)
  54. {
  55. if (offset < 4)
  56. return IRQ_EINT0 + offset;
  57. if (offset < 8)
  58. return IRQ_EINT4 + offset - 4;
  59. return -EINVAL;
  60. }
  61. static int s3c24xx_gpiolib_bankg_toirq(struct gpio_chip *chip, unsigned offset)
  62. {
  63. return IRQ_EINT8 + offset;
  64. }
  65. static struct s3c_gpio_cfg s3c24xx_gpiocfg_banka = {
  66. .set_config = s3c_gpio_setcfg_s3c24xx_a,
  67. .get_config = s3c_gpio_getcfg_s3c24xx_a,
  68. };
  69. struct s3c_gpio_cfg s3c24xx_gpiocfg_default = {
  70. .set_config = s3c_gpio_setcfg_s3c24xx,
  71. .get_config = s3c_gpio_getcfg_s3c24xx,
  72. .set_pull = s3c_gpio_setpull_1up,
  73. .get_pull = s3c_gpio_getpull_1up,
  74. };
  75. struct s3c_gpio_chip s3c24xx_gpios[] = {
  76. [0] = {
  77. .base = S3C2410_GPACON,
  78. .pm = __gpio_pm(&s3c_gpio_pm_1bit),
  79. .config = &s3c24xx_gpiocfg_banka,
  80. .chip = {
  81. .base = S3C2410_GPA(0),
  82. .owner = THIS_MODULE,
  83. .label = "GPIOA",
  84. .ngpio = 24,
  85. .direction_input = s3c24xx_gpiolib_banka_input,
  86. .direction_output = s3c24xx_gpiolib_banka_output,
  87. },
  88. },
  89. [1] = {
  90. .base = S3C2410_GPBCON,
  91. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  92. .chip = {
  93. .base = S3C2410_GPB(0),
  94. .owner = THIS_MODULE,
  95. .label = "GPIOB",
  96. .ngpio = 16,
  97. },
  98. },
  99. [2] = {
  100. .base = S3C2410_GPCCON,
  101. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  102. .chip = {
  103. .base = S3C2410_GPC(0),
  104. .owner = THIS_MODULE,
  105. .label = "GPIOC",
  106. .ngpio = 16,
  107. },
  108. },
  109. [3] = {
  110. .base = S3C2410_GPDCON,
  111. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  112. .chip = {
  113. .base = S3C2410_GPD(0),
  114. .owner = THIS_MODULE,
  115. .label = "GPIOD",
  116. .ngpio = 16,
  117. },
  118. },
  119. [4] = {
  120. .base = S3C2410_GPECON,
  121. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  122. .chip = {
  123. .base = S3C2410_GPE(0),
  124. .label = "GPIOE",
  125. .owner = THIS_MODULE,
  126. .ngpio = 16,
  127. },
  128. },
  129. [5] = {
  130. .base = S3C2410_GPFCON,
  131. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  132. .chip = {
  133. .base = S3C2410_GPF(0),
  134. .owner = THIS_MODULE,
  135. .label = "GPIOF",
  136. .ngpio = 8,
  137. .to_irq = s3c24xx_gpiolib_bankf_toirq,
  138. },
  139. },
  140. [6] = {
  141. .base = S3C2410_GPGCON,
  142. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  143. .chip = {
  144. .base = S3C2410_GPG(0),
  145. .owner = THIS_MODULE,
  146. .label = "GPIOG",
  147. .ngpio = 16,
  148. .to_irq = s3c24xx_gpiolib_bankg_toirq,
  149. },
  150. }, {
  151. .base = S3C2410_GPHCON,
  152. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  153. .chip = {
  154. .base = S3C2410_GPH(0),
  155. .owner = THIS_MODULE,
  156. .label = "GPIOH",
  157. .ngpio = 11,
  158. },
  159. },
  160. /* GPIOS for the S3C2443 and later devices. */
  161. {
  162. .base = S3C2440_GPJCON,
  163. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  164. .chip = {
  165. .base = S3C2410_GPJ(0),
  166. .owner = THIS_MODULE,
  167. .label = "GPIOJ",
  168. .ngpio = 16,
  169. },
  170. }, {
  171. .base = S3C2443_GPKCON,
  172. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  173. .chip = {
  174. .base = S3C2410_GPK(0),
  175. .owner = THIS_MODULE,
  176. .label = "GPIOK",
  177. .ngpio = 16,
  178. },
  179. }, {
  180. .base = S3C2443_GPLCON,
  181. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  182. .chip = {
  183. .base = S3C2410_GPL(0),
  184. .owner = THIS_MODULE,
  185. .label = "GPIOL",
  186. .ngpio = 15,
  187. },
  188. }, {
  189. .base = S3C2443_GPMCON,
  190. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  191. .chip = {
  192. .base = S3C2410_GPM(0),
  193. .owner = THIS_MODULE,
  194. .label = "GPIOM",
  195. .ngpio = 2,
  196. },
  197. },
  198. };
  199. static __init int s3c24xx_gpiolib_init(void)
  200. {
  201. struct s3c_gpio_chip *chip = s3c24xx_gpios;
  202. int gpn;
  203. for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++) {
  204. if (!chip->config)
  205. chip->config = &s3c24xx_gpiocfg_default;
  206. s3c_gpiolib_add(chip);
  207. }
  208. return 0;
  209. }
  210. core_initcall(s3c24xx_gpiolib_init);