gpio.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* linux/arch/arm/plat-s3c24xx/gpio.c
  2. *
  3. * Copyright (c) 2004-2005 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C24XX GPIO support
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/module.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/ioport.h>
  27. #include <linux/io.h>
  28. #include <mach/hardware.h>
  29. #include <mach/gpio-fns.h>
  30. #include <asm/irq.h>
  31. #include <mach/regs-gpio.h>
  32. unsigned int s3c2410_gpio_getcfg(unsigned int pin)
  33. {
  34. void __iomem *base = S3C24XX_GPIO_BASE(pin);
  35. unsigned long val = __raw_readl(base);
  36. if (pin < S3C2410_GPIO_BANKB) {
  37. val >>= S3C2410_GPIO_OFFSET(pin);
  38. val &= 1;
  39. val += 1;
  40. } else {
  41. val >>= S3C2410_GPIO_OFFSET(pin)*2;
  42. val &= 3;
  43. }
  44. return val | S3C2410_GPIO_INPUT;
  45. }
  46. EXPORT_SYMBOL(s3c2410_gpio_getcfg);
  47. void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
  48. {
  49. void __iomem *base = S3C24XX_GPIO_BASE(pin);
  50. unsigned long offs = S3C2410_GPIO_OFFSET(pin);
  51. unsigned long flags;
  52. unsigned long up;
  53. if (pin < S3C2410_GPIO_BANKB)
  54. return;
  55. local_irq_save(flags);
  56. up = __raw_readl(base + 0x08);
  57. up &= ~(1L << offs);
  58. up |= to << offs;
  59. __raw_writel(up, base + 0x08);
  60. local_irq_restore(flags);
  61. }
  62. EXPORT_SYMBOL(s3c2410_gpio_pullup);
  63. void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
  64. {
  65. void __iomem *base = S3C24XX_GPIO_BASE(pin);
  66. unsigned long offs = S3C2410_GPIO_OFFSET(pin);
  67. unsigned long flags;
  68. unsigned long dat;
  69. local_irq_save(flags);
  70. dat = __raw_readl(base + 0x04);
  71. dat &= ~(1 << offs);
  72. dat |= to << offs;
  73. __raw_writel(dat, base + 0x04);
  74. local_irq_restore(flags);
  75. }
  76. EXPORT_SYMBOL(s3c2410_gpio_setpin);
  77. unsigned int s3c2410_gpio_getpin(unsigned int pin)
  78. {
  79. void __iomem *base = S3C24XX_GPIO_BASE(pin);
  80. unsigned long offs = S3C2410_GPIO_OFFSET(pin);
  81. return __raw_readl(base + 0x04) & (1<< offs);
  82. }
  83. EXPORT_SYMBOL(s3c2410_gpio_getpin);
  84. unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
  85. {
  86. unsigned long flags;
  87. unsigned long misccr;
  88. local_irq_save(flags);
  89. misccr = __raw_readl(S3C24XX_MISCCR);
  90. misccr &= ~clear;
  91. misccr ^= change;
  92. __raw_writel(misccr, S3C24XX_MISCCR);
  93. local_irq_restore(flags);
  94. return misccr;
  95. }
  96. EXPORT_SYMBOL(s3c2410_modify_misccr);
  97. int s3c2410_gpio_getirq(unsigned int pin)
  98. {
  99. if (pin < S3C2410_GPF(0) || pin > S3C2410_GPG(15))
  100. return -EINVAL; /* not valid interrupts */
  101. if (pin < S3C2410_GPG(0) && pin > S3C2410_GPF(7))
  102. return -EINVAL; /* not valid pin */
  103. if (pin < S3C2410_GPF(4))
  104. return (pin - S3C2410_GPF(0)) + IRQ_EINT0;
  105. if (pin < S3C2410_GPG(0))
  106. return (pin - S3C2410_GPF(4)) + IRQ_EINT4;
  107. return (pin - S3C2410_GPG(0)) + IRQ_EINT8;
  108. }
  109. EXPORT_SYMBOL(s3c2410_gpio_getirq);