gpiolib.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. };
  73. struct s3c_gpio_chip s3c24xx_gpios[] = {
  74. [0] = {
  75. .base = S3C2410_GPACON,
  76. .pm = __gpio_pm(&s3c_gpio_pm_1bit),
  77. .config = &s3c24xx_gpiocfg_banka,
  78. .chip = {
  79. .base = S3C2410_GPA(0),
  80. .owner = THIS_MODULE,
  81. .label = "GPIOA",
  82. .ngpio = 24,
  83. .direction_input = s3c24xx_gpiolib_banka_input,
  84. .direction_output = s3c24xx_gpiolib_banka_output,
  85. },
  86. },
  87. [1] = {
  88. .base = S3C2410_GPBCON,
  89. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  90. .chip = {
  91. .base = S3C2410_GPB(0),
  92. .owner = THIS_MODULE,
  93. .label = "GPIOB",
  94. .ngpio = 16,
  95. },
  96. },
  97. [2] = {
  98. .base = S3C2410_GPCCON,
  99. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  100. .chip = {
  101. .base = S3C2410_GPC(0),
  102. .owner = THIS_MODULE,
  103. .label = "GPIOC",
  104. .ngpio = 16,
  105. },
  106. },
  107. [3] = {
  108. .base = S3C2410_GPDCON,
  109. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  110. .chip = {
  111. .base = S3C2410_GPD(0),
  112. .owner = THIS_MODULE,
  113. .label = "GPIOD",
  114. .ngpio = 16,
  115. },
  116. },
  117. [4] = {
  118. .base = S3C2410_GPECON,
  119. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  120. .chip = {
  121. .base = S3C2410_GPE(0),
  122. .label = "GPIOE",
  123. .owner = THIS_MODULE,
  124. .ngpio = 16,
  125. },
  126. },
  127. [5] = {
  128. .base = S3C2410_GPFCON,
  129. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  130. .chip = {
  131. .base = S3C2410_GPF(0),
  132. .owner = THIS_MODULE,
  133. .label = "GPIOF",
  134. .ngpio = 8,
  135. .to_irq = s3c24xx_gpiolib_bankf_toirq,
  136. },
  137. },
  138. [6] = {
  139. .base = S3C2410_GPGCON,
  140. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  141. .chip = {
  142. .base = S3C2410_GPG(0),
  143. .owner = THIS_MODULE,
  144. .label = "GPIOG",
  145. .ngpio = 16,
  146. .to_irq = s3c24xx_gpiolib_bankg_toirq,
  147. },
  148. }, {
  149. .base = S3C2410_GPHCON,
  150. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  151. .chip = {
  152. .base = S3C2410_GPH(0),
  153. .owner = THIS_MODULE,
  154. .label = "GPIOH",
  155. .ngpio = 11,
  156. },
  157. },
  158. /* GPIOS for the S3C2443 and later devices. */
  159. {
  160. .base = S3C2440_GPJCON,
  161. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  162. .chip = {
  163. .base = S3C2410_GPJ(0),
  164. .owner = THIS_MODULE,
  165. .label = "GPIOJ",
  166. .ngpio = 16,
  167. },
  168. }, {
  169. .base = S3C2443_GPKCON,
  170. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  171. .chip = {
  172. .base = S3C2410_GPK(0),
  173. .owner = THIS_MODULE,
  174. .label = "GPIOK",
  175. .ngpio = 16,
  176. },
  177. }, {
  178. .base = S3C2443_GPLCON,
  179. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  180. .chip = {
  181. .base = S3C2410_GPL(0),
  182. .owner = THIS_MODULE,
  183. .label = "GPIOL",
  184. .ngpio = 15,
  185. },
  186. }, {
  187. .base = S3C2443_GPMCON,
  188. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  189. .chip = {
  190. .base = S3C2410_GPM(0),
  191. .owner = THIS_MODULE,
  192. .label = "GPIOM",
  193. .ngpio = 2,
  194. },
  195. },
  196. };
  197. static __init int s3c24xx_gpiolib_init(void)
  198. {
  199. struct s3c_gpio_chip *chip = s3c24xx_gpios;
  200. int gpn;
  201. for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++) {
  202. if (!chip->config)
  203. chip->config = &s3c24xx_gpiocfg_default;
  204. s3c_gpiolib_add(chip);
  205. }
  206. return 0;
  207. }
  208. core_initcall(s3c24xx_gpiolib_init);