gpiolib.c 4.8 KB

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