gpio.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
  33. {
  34. void __iomem *base = S3C24XX_GPIO_BASE(pin);
  35. unsigned long offs = S3C2410_GPIO_OFFSET(pin);
  36. unsigned long flags;
  37. unsigned long up;
  38. if (pin < S3C2410_GPIO_BANKB)
  39. return;
  40. local_irq_save(flags);
  41. up = __raw_readl(base + 0x08);
  42. up &= ~(1L << offs);
  43. up |= to << offs;
  44. __raw_writel(up, base + 0x08);
  45. local_irq_restore(flags);
  46. }
  47. EXPORT_SYMBOL(s3c2410_gpio_pullup);
  48. void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
  49. {
  50. void __iomem *base = S3C24XX_GPIO_BASE(pin);
  51. unsigned long offs = S3C2410_GPIO_OFFSET(pin);
  52. unsigned long flags;
  53. unsigned long dat;
  54. local_irq_save(flags);
  55. dat = __raw_readl(base + 0x04);
  56. dat &= ~(1 << offs);
  57. dat |= to << offs;
  58. __raw_writel(dat, base + 0x04);
  59. local_irq_restore(flags);
  60. }
  61. EXPORT_SYMBOL(s3c2410_gpio_setpin);
  62. unsigned int s3c2410_gpio_getpin(unsigned int pin)
  63. {
  64. void __iomem *base = S3C24XX_GPIO_BASE(pin);
  65. unsigned long offs = S3C2410_GPIO_OFFSET(pin);
  66. return __raw_readl(base + 0x04) & (1<< offs);
  67. }
  68. EXPORT_SYMBOL(s3c2410_gpio_getpin);
  69. unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
  70. {
  71. unsigned long flags;
  72. unsigned long misccr;
  73. local_irq_save(flags);
  74. misccr = __raw_readl(S3C24XX_MISCCR);
  75. misccr &= ~clear;
  76. misccr ^= change;
  77. __raw_writel(misccr, S3C24XX_MISCCR);
  78. local_irq_restore(flags);
  79. return misccr;
  80. }
  81. EXPORT_SYMBOL(s3c2410_modify_misccr);