gpio-cfg-helpers.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * http://armlinux.simtec.co.uk/
  6. * Ben Dooks <[email protected]>
  7. *
  8. * Samsung Platform - GPIO pin configuration helper definitions
  9. */
  10. /* This is meant for core cpu support, machine or other driver files
  11. * should not be including this header.
  12. */
  13. #ifndef __PLAT_GPIO_CFG_HELPERS_H
  14. #define __PLAT_GPIO_CFG_HELPERS_H __FILE__
  15. /* As a note, all gpio configuration functions are entered exclusively, either
  16. * with the relevant lock held or the system prevented from doing anything else
  17. * by disabling interrupts.
  18. */
  19. static inline int samsung_gpio_do_setcfg(struct samsung_gpio_chip *chip,
  20. unsigned int off, unsigned int config)
  21. {
  22. return (chip->config->set_config)(chip, off, config);
  23. }
  24. static inline unsigned samsung_gpio_do_getcfg(struct samsung_gpio_chip *chip,
  25. unsigned int off)
  26. {
  27. return (chip->config->get_config)(chip, off);
  28. }
  29. static inline int samsung_gpio_do_setpull(struct samsung_gpio_chip *chip,
  30. unsigned int off, samsung_gpio_pull_t pull)
  31. {
  32. return (chip->config->set_pull)(chip, off, pull);
  33. }
  34. static inline samsung_gpio_pull_t samsung_gpio_do_getpull(struct samsung_gpio_chip *chip,
  35. unsigned int off)
  36. {
  37. return chip->config->get_pull(chip, off);
  38. }
  39. /* Pull-{up,down} resistor controls.
  40. *
  41. * S3C2410,S3C2440 = Pull-UP,
  42. * S3C2412,S3C2413 = Pull-Down
  43. * S3C6400,S3C6410 = Pull-Both [None,Down,Up,Undef]
  44. * S3C2443 = Pull-Both [not same as S3C6400]
  45. */
  46. /**
  47. * s3c24xx_gpio_setpull_1up() - Pull configuration for choice of up or none.
  48. * @chip: The gpio chip that is being configured.
  49. * @off: The offset for the GPIO being configured.
  50. * @param: pull: The pull mode being requested.
  51. *
  52. * This is a helper function for the case where we have GPIOs with one
  53. * bit configuring the presence of a pull-up resistor.
  54. */
  55. extern int s3c24xx_gpio_setpull_1up(struct samsung_gpio_chip *chip,
  56. unsigned int off, samsung_gpio_pull_t pull);
  57. /**
  58. * s3c24xx_gpio_setpull_1down() - Pull configuration for choice of down or none
  59. * @chip: The gpio chip that is being configured
  60. * @off: The offset for the GPIO being configured
  61. * @param: pull: The pull mode being requested
  62. *
  63. * This is a helper function for the case where we have GPIOs with one
  64. * bit configuring the presence of a pull-down resistor.
  65. */
  66. extern int s3c24xx_gpio_setpull_1down(struct samsung_gpio_chip *chip,
  67. unsigned int off, samsung_gpio_pull_t pull);
  68. /**
  69. * samsung_gpio_setpull_upown() - Pull configuration for choice of up,
  70. * down or none
  71. *
  72. * @chip: The gpio chip that is being configured.
  73. * @off: The offset for the GPIO being configured.
  74. * @param: pull: The pull mode being requested.
  75. *
  76. * This is a helper function for the case where we have GPIOs with two
  77. * bits configuring the presence of a pull resistor, in the following
  78. * order:
  79. * 00 = No pull resistor connected
  80. * 01 = Pull-up resistor connected
  81. * 10 = Pull-down resistor connected
  82. */
  83. extern int samsung_gpio_setpull_updown(struct samsung_gpio_chip *chip,
  84. unsigned int off, samsung_gpio_pull_t pull);
  85. /**
  86. * samsung_gpio_getpull_updown() - Get configuration for choice of up,
  87. * down or none
  88. *
  89. * @chip: The gpio chip that the GPIO pin belongs to
  90. * @off: The offset to the pin to get the configuration of.
  91. *
  92. * This helper function reads the state of the pull-{up,down} resistor
  93. * for the given GPIO in the same case as samsung_gpio_setpull_upown.
  94. */
  95. extern samsung_gpio_pull_t samsung_gpio_getpull_updown(struct samsung_gpio_chip *chip,
  96. unsigned int off);
  97. /**
  98. * s3c24xx_gpio_getpull_1up() - Get configuration for choice of up or none
  99. * @chip: The gpio chip that the GPIO pin belongs to
  100. * @off: The offset to the pin to get the configuration of.
  101. *
  102. * This helper function reads the state of the pull-up resistor for the
  103. * given GPIO in the same case as s3c24xx_gpio_setpull_1up.
  104. */
  105. extern samsung_gpio_pull_t s3c24xx_gpio_getpull_1up(struct samsung_gpio_chip *chip,
  106. unsigned int off);
  107. /**
  108. * s3c24xx_gpio_getpull_1down() - Get configuration for choice of down or none
  109. * @chip: The gpio chip that the GPIO pin belongs to
  110. * @off: The offset to the pin to get the configuration of.
  111. *
  112. * This helper function reads the state of the pull-down resistor for the
  113. * given GPIO in the same case as s3c24xx_gpio_setpull_1down.
  114. */
  115. extern samsung_gpio_pull_t s3c24xx_gpio_getpull_1down(struct samsung_gpio_chip *chip,
  116. unsigned int off);
  117. /**
  118. * s3c2443_gpio_setpull() - Pull configuration for s3c2443.
  119. * @chip: The gpio chip that is being configured.
  120. * @off: The offset for the GPIO being configured.
  121. * @param: pull: The pull mode being requested.
  122. *
  123. * This is a helper function for the case where we have GPIOs with two
  124. * bits configuring the presence of a pull resistor, in the following
  125. * order:
  126. * 00 = Pull-up resistor connected
  127. * 10 = Pull-down resistor connected
  128. * x1 = No pull up resistor
  129. */
  130. extern int s3c2443_gpio_setpull(struct samsung_gpio_chip *chip,
  131. unsigned int off, samsung_gpio_pull_t pull);
  132. /**
  133. * s3c2443_gpio_getpull() - Get configuration for s3c2443 pull resistors
  134. * @chip: The gpio chip that the GPIO pin belongs to.
  135. * @off: The offset to the pin to get the configuration of.
  136. *
  137. * This helper function reads the state of the pull-{up,down} resistor for the
  138. * given GPIO in the same case as samsung_gpio_setpull_upown.
  139. */
  140. extern samsung_gpio_pull_t s3c2443_gpio_getpull(struct samsung_gpio_chip *chip,
  141. unsigned int off);
  142. #endif /* __PLAT_GPIO_CFG_HELPERS_H */