gpio-config.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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/gpio.h>
  16. #include <linux/io.h>
  17. #include <mach/gpio-core.h>
  18. #include <plat/gpio-cfg.h>
  19. #include <plat/gpio-cfg-helpers.h>
  20. int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
  21. {
  22. struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
  23. unsigned long flags;
  24. int offset;
  25. int ret;
  26. if (!chip)
  27. return -EINVAL;
  28. offset = pin - chip->chip.base;
  29. local_irq_save(flags);
  30. ret = s3c_gpio_do_setcfg(chip, offset, config);
  31. local_irq_restore(flags);
  32. return ret;
  33. }
  34. int s3c_gpio_setpull(unsigned int pin, s3c_gpio_pull_t pull)
  35. {
  36. struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
  37. unsigned long flags;
  38. int offset, ret;
  39. if (!chip)
  40. return -EINVAL;
  41. offset = pin - chip->chip.base;
  42. local_irq_save(flags);
  43. ret = s3c_gpio_do_setpull(chip, offset, pull);
  44. local_irq_restore(flags);
  45. return ret;
  46. }
  47. #ifdef CONFIG_S3C_GPIO_CFG_S3C24XX
  48. int s3c_gpio_setcfg_s3c24xx_banka(struct s3c_gpio_chip *chip,
  49. unsigned int off, unsigned int cfg)
  50. {
  51. void __iomem *reg = chip->base;
  52. unsigned int shift = off;
  53. u32 con;
  54. if (s3c_gpio_is_cfg_special(cfg)) {
  55. cfg &= 0xf;
  56. /* Map output to 0, and SFN2 to 1 */
  57. cfg -= 1;
  58. if (cfg > 1)
  59. return -EINVAL;
  60. cfg <<= shift;
  61. }
  62. con = __raw_readl(reg);
  63. con &= ~(0x1 << shift);
  64. con |= cfg;
  65. __raw_writel(con, reg);
  66. return 0;
  67. }
  68. int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip *chip,
  69. unsigned int off, unsigned int cfg)
  70. {
  71. void __iomem *reg = chip->base;
  72. unsigned int shift = off * 2;
  73. u32 con;
  74. if (s3c_gpio_is_cfg_special(cfg)) {
  75. cfg &= 0xf;
  76. if (cfg > 3)
  77. return -EINVAL;
  78. cfg <<= shift;
  79. }
  80. con = __raw_readl(reg);
  81. con &= ~(0x3 << shift);
  82. con |= cfg;
  83. __raw_writel(con, reg);
  84. return 0;
  85. }
  86. #endif
  87. #ifdef CONFIG_S3C_GPIO_CFG_S3C64XX
  88. int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
  89. unsigned int off, unsigned int cfg)
  90. {
  91. void __iomem *reg = chip->base;
  92. unsigned int shift = (off & 7) * 4;
  93. u32 con;
  94. if (off < 8 && chip->chip.ngpio >= 8)
  95. reg -= 4;
  96. if (s3c_gpio_is_cfg_special(cfg)) {
  97. cfg &= 0xf;
  98. cfg <<= shift;
  99. }
  100. con = __raw_readl(reg);
  101. con &= ~(0xf << shift);
  102. con |= cfg;
  103. __raw_writel(con, reg);
  104. return 0;
  105. }
  106. #endif /* CONFIG_S3C_GPIO_CFG_S3C64XX */
  107. #ifdef CONFIG_S3C_GPIO_PULL_UPDOWN
  108. int s3c_gpio_setpull_updown(struct s3c_gpio_chip *chip,
  109. unsigned int off, s3c_gpio_pull_t pull)
  110. {
  111. void __iomem *reg = chip->base + 0x08;
  112. int shift = off * 2;
  113. u32 pup;
  114. pup = __raw_readl(reg);
  115. pup &= ~(3 << shift);
  116. pup |= pull << shift;
  117. __raw_writel(pup, reg);
  118. return 0;
  119. }
  120. s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip,
  121. unsigned int off)
  122. {
  123. void __iomem *reg = chip->base + 0x08;
  124. int shift = off * 2;
  125. u32 pup = __raw_readl(reg);
  126. pup >>= shift;
  127. pup &= 0x3;
  128. return (__force s3c_gpio_pull_t)pup;
  129. }
  130. #endif