gpiolib.c 3.2 KB

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