gpiolib.c 4.7 KB

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