gpio.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* linux/arch/arm/plat-s3c24xx/gpio.c
  2. *
  3. * Copyright (c) 2004-2010 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/gpio.h>
  28. #include <linux/io.h>
  29. #include <mach/hardware.h>
  30. #include <mach/gpio-fns.h>
  31. #include <asm/irq.h>
  32. #include <mach/regs-gpio.h>
  33. #include <plat/gpio-core.h>
  34. /* gpiolib wrappers until these are totally eliminated */
  35. void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
  36. {
  37. int ret;
  38. WARN_ON(to); /* should be none of these left */
  39. if (!to) {
  40. /* if pull is enabled, try first with up, and if that
  41. * fails, try using down */
  42. ret = s3c_gpio_setpull(pin, S3C_GPIO_PULL_UP);
  43. if (ret)
  44. s3c_gpio_setpull(pin, S3C_GPIO_PULL_DOWN);
  45. } else {
  46. s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
  47. }
  48. }
  49. EXPORT_SYMBOL(s3c2410_gpio_pullup);
  50. void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
  51. {
  52. /* do this via gpiolib until all users removed */
  53. gpio_request(pin, "temporary");
  54. gpio_set_value(pin, to);
  55. gpio_free(pin);
  56. }
  57. EXPORT_SYMBOL(s3c2410_gpio_setpin);
  58. unsigned int s3c2410_gpio_getpin(unsigned int pin)
  59. {
  60. struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
  61. unsigned long offs = pin - chip->chip.base;
  62. return __raw_readl(chip->base + 0x04) & (1<< offs);
  63. }
  64. EXPORT_SYMBOL(s3c2410_gpio_getpin);
  65. unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
  66. {
  67. unsigned long flags;
  68. unsigned long misccr;
  69. local_irq_save(flags);
  70. misccr = __raw_readl(S3C24XX_MISCCR);
  71. misccr &= ~clear;
  72. misccr ^= change;
  73. __raw_writel(misccr, S3C24XX_MISCCR);
  74. local_irq_restore(flags);
  75. return misccr;
  76. }
  77. EXPORT_SYMBOL(s3c2410_modify_misccr);