gpio-cfg-helpers.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* linux/arch/arm/plat-s3c/include/plat/gpio-cfg-helper.h
  2. *
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * http://armlinux.simtec.co.uk/
  6. * Ben Dooks <ben@simtec.co.uk>
  7. *
  8. * S3C Platform - GPIO pin configuration helper definitions
  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. /* This is meant for core cpu support, machine or other driver files
  15. * should not be including this header.
  16. */
  17. #ifndef __PLAT_GPIO_CFG_HELPERS_H
  18. #define __PLAT_GPIO_CFG_HELPERS_H __FILE__
  19. /* As a note, all gpio configuration functions are entered exclusively, either
  20. * with the relevant lock held or the system prevented from doing anything else
  21. * by disabling interrupts.
  22. */
  23. static inline int s3c_gpio_do_setcfg(struct s3c_gpio_chip *chip,
  24. unsigned int off, unsigned int config)
  25. {
  26. return (chip->config->set_config)(chip, off, config);
  27. }
  28. static inline int s3c_gpio_do_setpull(struct s3c_gpio_chip *chip,
  29. unsigned int off, s3c_gpio_pull_t pull)
  30. {
  31. return (chip->config->set_pull)(chip, off, pull);
  32. }
  33. /**
  34. * s3c_gpio_setcfg_s3c24xx - S3C24XX style GPIO configuration.
  35. * @chip: The gpio chip that is being configured.
  36. * @off: The offset for the GPIO being configured.
  37. * @cfg: The configuration value to set.
  38. *
  39. * This helper deal with the GPIO cases where the control register
  40. * has two bits of configuration per gpio, which have the following
  41. * functions:
  42. * 00 = input
  43. * 01 = output
  44. * 1x = special function
  45. */
  46. extern int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip *chip,
  47. unsigned int off, unsigned int cfg);
  48. /**
  49. * s3c_gpio_getcfg_s3c24xx - S3C24XX style GPIO configuration read.
  50. * @chip: The gpio chip that is being configured.
  51. * @off: The offset for the GPIO being configured.
  52. *
  53. * The reverse of s3c_gpio_setcfg_s3c24xx(). Will return a value whicg
  54. * could be directly passed back to s3c_gpio_setcfg_s3c24xx(), from the
  55. * S3C_GPIO_SPECIAL() macro.
  56. */
  57. unsigned int s3c_gpio_getcfg_s3c24xx(struct s3c_gpio_chip *chip,
  58. unsigned int off);
  59. /**
  60. * s3c_gpio_setcfg_s3c24xx_a - S3C24XX style GPIO configuration (Bank A)
  61. * @chip: The gpio chip that is being configured.
  62. * @off: The offset for the GPIO being configured.
  63. * @cfg: The configuration value to set.
  64. *
  65. * This helper deal with the GPIO cases where the control register
  66. * has one bit of configuration for the gpio, where setting the bit
  67. * means the pin is in special function mode and unset means output.
  68. */
  69. extern int s3c_gpio_setcfg_s3c24xx_a(struct s3c_gpio_chip *chip,
  70. unsigned int off, unsigned int cfg);
  71. /**
  72. * s3c_gpio_getcfg_s3c24xx_a - S3C24XX style GPIO configuration read (Bank A)
  73. * @chip: The gpio chip that is being configured.
  74. * @off: The offset for the GPIO being configured.
  75. *
  76. * The reverse of s3c_gpio_setcfg_s3c24xx_a() turning an GPIO into a usable
  77. * GPIO configuration value.
  78. *
  79. * @sa s3c_gpio_getcfg_s3c24xx
  80. * @sa s3c_gpio_getcfg_s3c64xx_4bit
  81. */
  82. extern unsigned s3c_gpio_getcfg_s3c24xx_a(struct s3c_gpio_chip *chip,
  83. unsigned int off);
  84. /**
  85. * s3c_gpio_setcfg_s3c64xx_4bit - S3C64XX 4bit single register GPIO config.
  86. * @chip: The gpio chip that is being configured.
  87. * @off: The offset for the GPIO being configured.
  88. * @cfg: The configuration value to set.
  89. *
  90. * This helper deal with the GPIO cases where the control register has 4 bits
  91. * of control per GPIO, generally in the form of:
  92. * 0000 = Input
  93. * 0001 = Output
  94. * others = Special functions (dependant on bank)
  95. *
  96. * Note, since the code to deal with the case where there are two control
  97. * registers instead of one, we do not have a separate set of functions for
  98. * each case.
  99. */
  100. extern int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
  101. unsigned int off, unsigned int cfg);
  102. /**
  103. * s3c_gpio_getcfg_s3c64xx_4bit - S3C64XX 4bit single register GPIO config read.
  104. * @chip: The gpio chip that is being configured.
  105. * @off: The offset for the GPIO being configured.
  106. *
  107. * The reverse of s3c_gpio_setcfg_s3c64xx_4bit(), turning a gpio configuration
  108. * register setting into a value the software can use, such as could be passed
  109. * to s3c_gpio_setcfg_s3c64xx_4bit().
  110. *
  111. * @sa s3c_gpio_getcfg_s3c24xx
  112. */
  113. extern unsigned s3c_gpio_getcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
  114. unsigned int off);
  115. /* Pull-{up,down} resistor controls.
  116. *
  117. * S3C2410,S3C2440,S3C24A0 = Pull-UP,
  118. * S3C2412,S3C2413 = Pull-Down
  119. * S3C6400,S3C6410 = Pull-Both [None,Down,Up,Undef]
  120. * S3C2443 = Pull-Both [not same as S3C6400]
  121. */
  122. /**
  123. * s3c_gpio_setpull_1up() - Pull configuration for choice of up or none.
  124. * @chip: The gpio chip that is being configured.
  125. * @off: The offset for the GPIO being configured.
  126. * @param: pull: The pull mode being requested.
  127. *
  128. * This is a helper function for the case where we have GPIOs with one
  129. * bit configuring the presence of a pull-up resistor.
  130. */
  131. extern int s3c_gpio_setpull_1up(struct s3c_gpio_chip *chip,
  132. unsigned int off, s3c_gpio_pull_t pull);
  133. /**
  134. * s3c_gpio_setpull_1down() - Pull configuration for choice of down or none
  135. * @chip: The gpio chip that is being configured
  136. * @off: The offset for the GPIO being configured
  137. * @param: pull: The pull mode being requested
  138. *
  139. * This is a helper function for the case where we have GPIOs with one
  140. * bit configuring the presence of a pull-down resistor.
  141. */
  142. extern int s3c_gpio_setpull_1down(struct s3c_gpio_chip *chip,
  143. unsigned int off, s3c_gpio_pull_t pull);
  144. /**
  145. * s3c_gpio_setpull_upown() - Pull configuration for choice of up, down or none
  146. * @chip: The gpio chip that is being configured.
  147. * @off: The offset for the GPIO being configured.
  148. * @param: pull: The pull mode being requested.
  149. *
  150. * This is a helper function for the case where we have GPIOs with two
  151. * bits configuring the presence of a pull resistor, in the following
  152. * order:
  153. * 00 = No pull resistor connected
  154. * 01 = Pull-up resistor connected
  155. * 10 = Pull-down resistor connected
  156. */
  157. extern int s3c_gpio_setpull_updown(struct s3c_gpio_chip *chip,
  158. unsigned int off, s3c_gpio_pull_t pull);
  159. /**
  160. * s3c_gpio_getpull_updown() - Get configuration for choice of up, down or none
  161. * @chip: The gpio chip that the GPIO pin belongs to
  162. * @off: The offset to the pin to get the configuration of.
  163. *
  164. * This helper function reads the state of the pull-{up,down} resistor for the
  165. * given GPIO in the same case as s3c_gpio_setpull_upown.
  166. */
  167. extern s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip,
  168. unsigned int off);
  169. /**
  170. * s3c_gpio_getpull_1up() - Get configuration for choice of up or none
  171. * @chip: The gpio chip that the GPIO pin belongs to
  172. * @off: The offset to the pin to get the configuration of.
  173. *
  174. * This helper function reads the state of the pull-up resistor for the
  175. * given GPIO in the same case as s3c_gpio_setpull_1up.
  176. */
  177. extern s3c_gpio_pull_t s3c_gpio_getpull_1up(struct s3c_gpio_chip *chip,
  178. unsigned int off);
  179. /**
  180. * s3c_gpio_setpull_s3c2443() - Pull configuration for s3c2443.
  181. * @chip: The gpio chip that is being configured.
  182. * @off: The offset for the GPIO being configured.
  183. * @param: pull: The pull mode being requested.
  184. *
  185. * This is a helper function for the case where we have GPIOs with two
  186. * bits configuring the presence of a pull resistor, in the following
  187. * order:
  188. * 00 = Pull-up resistor connected
  189. * 10 = Pull-down resistor connected
  190. * x1 = No pull up resistor
  191. */
  192. extern int s3c_gpio_setpull_s3c2443(struct s3c_gpio_chip *chip,
  193. unsigned int off, s3c_gpio_pull_t pull);
  194. /**
  195. * s3c_gpio_getpull_s3c2443() - Get configuration for s3c2443 pull resistors
  196. * @chip: The gpio chip that the GPIO pin belongs to.
  197. * @off: The offset to the pin to get the configuration of.
  198. *
  199. * This helper function reads the state of the pull-{up,down} resistor for the
  200. * given GPIO in the same case as s3c_gpio_setpull_upown.
  201. */
  202. extern s3c_gpio_pull_t s3c_gpio_getpull_s3c24xx(struct s3c_gpio_chip *chip,
  203. unsigned int off);
  204. #endif /* __PLAT_GPIO_CFG_HELPERS_H */