gpiolib.c 3.5 KB

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