gpiolib.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. struct s3c_gpio_chip s3c24xx_gpios[] = {
  50. [0] = {
  51. .base = S3C24XX_GPIO_BASE(S3C2410_GPA0),
  52. .chip = {
  53. .base = S3C2410_GPA0,
  54. .owner = THIS_MODULE,
  55. .label = "GPIOA",
  56. .ngpio = 24,
  57. .direction_input = s3c24xx_gpiolib_banka_input,
  58. .direction_output = s3c24xx_gpiolib_banka_output,
  59. },
  60. },
  61. [1] = {
  62. .base = S3C24XX_GPIO_BASE(S3C2410_GPB0),
  63. .chip = {
  64. .base = S3C2410_GPB0,
  65. .owner = THIS_MODULE,
  66. .label = "GPIOB",
  67. .ngpio = 16,
  68. },
  69. },
  70. [2] = {
  71. .base = S3C24XX_GPIO_BASE(S3C2410_GPC0),
  72. .chip = {
  73. .base = S3C2410_GPC0,
  74. .owner = THIS_MODULE,
  75. .label = "GPIOC",
  76. .ngpio = 16,
  77. },
  78. },
  79. [3] = {
  80. .base = S3C24XX_GPIO_BASE(S3C2410_GPD0),
  81. .chip = {
  82. .base = S3C2410_GPD0,
  83. .owner = THIS_MODULE,
  84. .label = "GPIOD",
  85. .ngpio = 16,
  86. },
  87. },
  88. [4] = {
  89. .base = S3C24XX_GPIO_BASE(S3C2410_GPE0),
  90. .chip = {
  91. .base = S3C2410_GPE0,
  92. .label = "GPIOE",
  93. .owner = THIS_MODULE,
  94. .ngpio = 16,
  95. },
  96. },
  97. [5] = {
  98. .base = S3C24XX_GPIO_BASE(S3C2410_GPF0),
  99. .chip = {
  100. .base = S3C2410_GPF0,
  101. .owner = THIS_MODULE,
  102. .label = "GPIOF",
  103. .ngpio = 8,
  104. },
  105. },
  106. [6] = {
  107. .base = S3C24XX_GPIO_BASE(S3C2410_GPG0),
  108. .chip = {
  109. .base = S3C2410_GPG0,
  110. .owner = THIS_MODULE,
  111. .label = "GPIOG",
  112. .ngpio = 10,
  113. },
  114. },
  115. };
  116. static __init int s3c24xx_gpiolib_init(void)
  117. {
  118. struct s3c_gpio_chip *chip = s3c24xx_gpios;
  119. int gpn;
  120. for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++)
  121. s3c_gpiolib_add(chip);
  122. return 0;
  123. }
  124. arch_initcall(s3c24xx_gpiolib_init);