gpio-config.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* linux/arch/arm/plat-s3c/gpio-config.c
  2. *
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * S3C series GPIO configuration core
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/gpio.h>
  17. #include <linux/io.h>
  18. #include <mach/gpio-core.h>
  19. #include <plat/gpio-cfg.h>
  20. #include <plat/gpio-cfg-helpers.h>
  21. int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
  22. {
  23. struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
  24. unsigned long flags;
  25. int offset;
  26. int ret;
  27. if (!chip)
  28. return -EINVAL;
  29. offset = pin - chip->chip.base;
  30. local_irq_save(flags);
  31. ret = s3c_gpio_do_setcfg(chip, offset, config);
  32. local_irq_restore(flags);
  33. return ret;
  34. }
  35. EXPORT_SYMBOL(s3c_gpio_cfgpin);
  36. int s3c_gpio_setpull(unsigned int pin, s3c_gpio_pull_t pull)
  37. {
  38. struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
  39. unsigned long flags;
  40. int offset, ret;
  41. if (!chip)
  42. return -EINVAL;
  43. offset = pin - chip->chip.base;
  44. local_irq_save(flags);
  45. ret = s3c_gpio_do_setpull(chip, offset, pull);
  46. local_irq_restore(flags);
  47. return ret;
  48. }
  49. EXPORT_SYMBOL(s3c_gpio_setpull);
  50. #ifdef CONFIG_S3C_GPIO_CFG_S3C24XX
  51. int s3c_gpio_setcfg_s3c24xx_banka(struct s3c_gpio_chip *chip,
  52. unsigned int off, unsigned int cfg)
  53. {
  54. void __iomem *reg = chip->base;
  55. unsigned int shift = off;
  56. u32 con;
  57. if (s3c_gpio_is_cfg_special(cfg)) {
  58. cfg &= 0xf;
  59. /* Map output to 0, and SFN2 to 1 */
  60. cfg -= 1;
  61. if (cfg > 1)
  62. return -EINVAL;
  63. cfg <<= shift;
  64. }
  65. con = __raw_readl(reg);
  66. con &= ~(0x1 << shift);
  67. con |= cfg;
  68. __raw_writel(con, reg);
  69. return 0;
  70. }
  71. int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip *chip,
  72. unsigned int off, unsigned int cfg)
  73. {
  74. void __iomem *reg = chip->base;
  75. unsigned int shift = off * 2;
  76. u32 con;
  77. if (s3c_gpio_is_cfg_special(cfg)) {
  78. cfg &= 0xf;
  79. if (cfg > 3)
  80. return -EINVAL;
  81. cfg <<= shift;
  82. }
  83. con = __raw_readl(reg);
  84. con &= ~(0x3 << shift);
  85. con |= cfg;
  86. __raw_writel(con, reg);
  87. return 0;
  88. }
  89. #endif
  90. #ifdef CONFIG_S3C_GPIO_CFG_S3C64XX
  91. int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
  92. unsigned int off, unsigned int cfg)
  93. {
  94. void __iomem *reg = chip->base;
  95. unsigned int shift = (off & 7) * 4;
  96. u32 con;
  97. if (off < 8 && chip->chip.ngpio > 8)
  98. reg -= 4;
  99. if (s3c_gpio_is_cfg_special(cfg)) {
  100. cfg &= 0xf;
  101. cfg <<= shift;
  102. }
  103. con = __raw_readl(reg);
  104. con &= ~(0xf << shift);
  105. con |= cfg;
  106. __raw_writel(con, reg);
  107. return 0;
  108. }
  109. #endif /* CONFIG_S3C_GPIO_CFG_S3C64XX */
  110. #ifdef CONFIG_S3C_GPIO_PULL_UPDOWN
  111. int s3c_gpio_setpull_updown(struct s3c_gpio_chip *chip,
  112. unsigned int off, s3c_gpio_pull_t pull)
  113. {
  114. void __iomem *reg = chip->base + 0x08;
  115. int shift = off * 2;
  116. u32 pup;
  117. pup = __raw_readl(reg);
  118. pup &= ~(3 << shift);
  119. pup |= pull << shift;
  120. __raw_writel(pup, reg);
  121. return 0;
  122. }
  123. s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip,
  124. unsigned int off)
  125. {
  126. void __iomem *reg = chip->base + 0x08;
  127. int shift = off * 2;
  128. u32 pup = __raw_readl(reg);
  129. pup >>= shift;
  130. pup &= 0x3;
  131. return (__force s3c_gpio_pull_t)pup;
  132. }
  133. #endif