gpiolib.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* linux/arch/arm/plat-s3c24xx/gpiolib.c
  2. *
  3. * Copyright (c) 2008 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 <mach/gpio-core.h>
  22. #include <mach/hardware.h>
  23. #include <asm/irq.h>
  24. #include <plat/pm.h>
  25. #include <mach/regs-gpio.h>
  26. static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
  27. {
  28. return -EINVAL;
  29. }
  30. static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
  31. unsigned offset, int value)
  32. {
  33. struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
  34. void __iomem *base = ourchip->base;
  35. unsigned long flags;
  36. unsigned long dat;
  37. unsigned long con;
  38. local_irq_save(flags);
  39. con = __raw_readl(base + 0x00);
  40. dat = __raw_readl(base + 0x04);
  41. dat &= ~(1 << offset);
  42. if (value)
  43. dat |= 1 << offset;
  44. __raw_writel(dat, base + 0x04);
  45. con &= ~(1 << offset);
  46. __raw_writel(con, base + 0x00);
  47. __raw_writel(dat, base + 0x04);
  48. local_irq_restore(flags);
  49. return 0;
  50. }
  51. static int s3c24xx_gpiolib_bankf_toirq(struct gpio_chip *chip, unsigned offset)
  52. {
  53. if (offset < 4)
  54. return IRQ_EINT0 + offset;
  55. if (offset < 8)
  56. return IRQ_EINT4 + offset - 4;
  57. return -EINVAL;
  58. }
  59. static int s3c24xx_gpiolib_bankg_toirq(struct gpio_chip *chip, unsigned offset)
  60. {
  61. return IRQ_EINT8 + offset;
  62. }
  63. struct s3c_gpio_chip s3c24xx_gpios[] = {
  64. [0] = {
  65. .base = S3C2410_GPACON,
  66. .pm = __gpio_pm(&s3c_gpio_pm_1bit),
  67. .chip = {
  68. .base = S3C2410_GPA(0),
  69. .owner = THIS_MODULE,
  70. .label = "GPIOA",
  71. .ngpio = 24,
  72. .direction_input = s3c24xx_gpiolib_banka_input,
  73. .direction_output = s3c24xx_gpiolib_banka_output,
  74. },
  75. },
  76. [1] = {
  77. .base = S3C2410_GPBCON,
  78. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  79. .chip = {
  80. .base = S3C2410_GPB(0),
  81. .owner = THIS_MODULE,
  82. .label = "GPIOB",
  83. .ngpio = 16,
  84. },
  85. },
  86. [2] = {
  87. .base = S3C2410_GPCCON,
  88. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  89. .chip = {
  90. .base = S3C2410_GPC(0),
  91. .owner = THIS_MODULE,
  92. .label = "GPIOC",
  93. .ngpio = 16,
  94. },
  95. },
  96. [3] = {
  97. .base = S3C2410_GPDCON,
  98. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  99. .chip = {
  100. .base = S3C2410_GPD(0),
  101. .owner = THIS_MODULE,
  102. .label = "GPIOD",
  103. .ngpio = 16,
  104. },
  105. },
  106. [4] = {
  107. .base = S3C2410_GPECON,
  108. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  109. .chip = {
  110. .base = S3C2410_GPE(0),
  111. .label = "GPIOE",
  112. .owner = THIS_MODULE,
  113. .ngpio = 16,
  114. },
  115. },
  116. [5] = {
  117. .base = S3C2410_GPFCON,
  118. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  119. .chip = {
  120. .base = S3C2410_GPF(0),
  121. .owner = THIS_MODULE,
  122. .label = "GPIOF",
  123. .ngpio = 8,
  124. .to_irq = s3c24xx_gpiolib_bankf_toirq,
  125. },
  126. },
  127. [6] = {
  128. .base = S3C2410_GPGCON,
  129. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  130. .chip = {
  131. .base = S3C2410_GPG(0),
  132. .owner = THIS_MODULE,
  133. .label = "GPIOG",
  134. .ngpio = 16,
  135. .to_irq = s3c24xx_gpiolib_bankg_toirq,
  136. },
  137. }, {
  138. .base = S3C2410_GPHCON,
  139. .pm = __gpio_pm(&s3c_gpio_pm_2bit),
  140. .chip = {
  141. .base = S3C2410_GPH(0),
  142. .owner = THIS_MODULE,
  143. .label = "GPIOH",
  144. .ngpio = 11,
  145. },
  146. },
  147. };
  148. static __init int s3c24xx_gpiolib_init(void)
  149. {
  150. struct s3c_gpio_chip *chip = s3c24xx_gpios;
  151. int gpn;
  152. for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++)
  153. s3c_gpiolib_add(chip);
  154. return 0;
  155. }
  156. core_initcall(s3c24xx_gpiolib_init);