s3c2410-gpio.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* linux/arch/arm/mach-s3c2410/gpio.c
  2. *
  3. * Copyright (c) 2004-2006 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C2410 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. * Changelog
  23. * 15-Jan-2006 LCVR Splitted from gpio.c
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/init.h>
  27. #include <linux/module.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/ioport.h>
  30. #include <asm/hardware.h>
  31. #include <asm/irq.h>
  32. #include <asm/io.h>
  33. #include <asm/arch/regs-gpio.h>
  34. int s3c2410_gpio_irqfilter(unsigned int pin, unsigned int on,
  35. unsigned int config)
  36. {
  37. void __iomem *reg = S3C2410_EINFLT0;
  38. unsigned long flags;
  39. unsigned long val;
  40. if (pin < S3C2410_GPG8 || pin > S3C2410_GPG15)
  41. return -1;
  42. config &= 0xff;
  43. pin -= S3C2410_GPG8_EINT16;
  44. reg += pin & ~3;
  45. local_irq_save(flags);
  46. /* update filter width and clock source */
  47. val = __raw_readl(reg);
  48. val &= ~(0xff << ((pin & 3) * 8));
  49. val |= config << ((pin & 3) * 8);
  50. __raw_writel(val, reg);
  51. /* update filter enable */
  52. val = __raw_readl(S3C2410_EXTINT2);
  53. val &= ~(1 << ((pin * 4) + 3));
  54. val |= on << ((pin * 4) + 3);
  55. __raw_writel(val, S3C2410_EXTINT2);
  56. local_irq_restore(flags);
  57. return 0;
  58. }
  59. EXPORT_SYMBOL(s3c2410_gpio_irqfilter);
  60. int s3c2410_gpio_getirq(unsigned int pin)
  61. {
  62. if (pin < S3C2410_GPF0 || pin > S3C2410_GPG15_EINT23)
  63. return -1; /* not valid interrupts */
  64. if (pin < S3C2410_GPG0 && pin > S3C2410_GPF7)
  65. return -1; /* not valid pin */
  66. if (pin < S3C2410_GPF4)
  67. return (pin - S3C2410_GPF0) + IRQ_EINT0;
  68. if (pin < S3C2410_GPG0)
  69. return (pin - S3C2410_GPF4) + IRQ_EINT4;
  70. return (pin - S3C2410_GPG0) + IRQ_EINT8;
  71. }
  72. EXPORT_SYMBOL(s3c2410_gpio_getirq);