gpio-cfg-helpers.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 unsigned s3c_gpio_do_getcfg(struct s3c_gpio_chip *chip,
  29. unsigned int off)
  30. {
  31. return (chip->config->get_config)(chip, off);
  32. }
  33. static inline int s3c_gpio_do_setpull(struct s3c_gpio_chip *chip,
  34. unsigned int off, s3c_gpio_pull_t pull)
  35. {
  36. return (chip->config->set_pull)(chip, off, pull);
  37. }
  38. static inline s3c_gpio_pull_t s3c_gpio_do_getpull(struct s3c_gpio_chip *chip,
  39. unsigned int off)
  40. {
  41. return chip->config->get_pull(chip, off);
  42. }
  43. /**
  44. * s3c_gpio_setcfg_s3c24xx - S3C24XX style GPIO configuration.
  45. * @chip: The gpio chip that is being configured.
  46. * @off: The offset for the GPIO being configured.
  47. * @cfg: The configuration value to set.
  48. *
  49. * This helper deal with the GPIO cases where the control register
  50. * has two bits of configuration per gpio, which have the following
  51. * functions:
  52. * 00 = input
  53. * 01 = output
  54. * 1x = special function
  55. */
  56. extern int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip *chip,
  57. unsigned int off, unsigned int cfg);
  58. /**
  59. * s3c_gpio_getcfg_s3c24xx - S3C24XX style GPIO configuration read.
  60. * @chip: The gpio chip that is being configured.
  61. * @off: The offset for the GPIO being configured.
  62. *
  63. * The reverse of s3c_gpio_setcfg_s3c24xx(). Will return a value whicg
  64. * could be directly passed back to s3c_gpio_setcfg_s3c24xx(), from the
  65. * S3C_GPIO_SPECIAL() macro.
  66. */
  67. unsigned int s3c_gpio_getcfg_s3c24xx(struct s3c_gpio_chip *chip,
  68. unsigned int off);
  69. /**
  70. * s3c_gpio_setcfg_s3c24xx_a - S3C24XX style GPIO configuration (Bank A)
  71. * @chip: The gpio chip that is being configured.
  72. * @off: The offset for the GPIO being configured.
  73. * @cfg: The configuration value to set.
  74. *
  75. * This helper deal with the GPIO cases where the control register
  76. * has one bit of configuration for the gpio, where setting the bit
  77. * means the pin is in special function mode and unset means output.
  78. */
  79. extern int s3c_gpio_setcfg_s3c24xx_a(struct s3c_gpio_chip *chip,
  80. unsigned int off, unsigned int cfg);
  81. /**
  82. * s3c_gpio_getcfg_s3c24xx_a - S3C24XX style GPIO configuration read (Bank A)
  83. * @chip: The gpio chip that is being configured.
  84. * @off: The offset for the GPIO being configured.
  85. *
  86. * The reverse of s3c_gpio_setcfg_s3c24xx_a() turning an GPIO into a usable
  87. * GPIO configuration value.
  88. *
  89. * @sa s3c_gpio_getcfg_s3c24xx
  90. * @sa s3c_gpio_getcfg_s3c64xx_4bit
  91. */
  92. extern unsigned s3c_gpio_getcfg_s3c24xx_a(struct s3c_gpio_chip *chip,
  93. unsigned int off);
  94. /**
  95. * s3c_gpio_setcfg_s3c64xx_4bit - S3C64XX 4bit single register GPIO config.
  96. * @chip: The gpio chip that is being configured.
  97. * @off: The offset for the GPIO being configured.
  98. * @cfg: The configuration value to set.
  99. *
  100. * This helper deal with the GPIO cases where the control register has 4 bits
  101. * of control per GPIO, generally in the form of:
  102. * 0000 = Input
  103. * 0001 = Output
  104. * others = Special functions (dependant on bank)
  105. *
  106. * Note, since the code to deal with the case where there are two control
  107. * registers instead of one, we do not have a separate set of functions for
  108. * each case.
  109. */
  110. extern int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
  111. unsigned int off, unsigned int cfg);
  112. /**
  113. * s3c_gpio_getcfg_s3c64xx_4bit - S3C64XX 4bit single register GPIO config read.
  114. * @chip: The gpio chip that is being configured.
  115. * @off: The offset for the GPIO being configured.
  116. *
  117. * The reverse of s3c_gpio_setcfg_s3c64xx_4bit(), turning a gpio configuration
  118. * register setting into a value the software can use, such as could be passed
  119. * to s3c_gpio_setcfg_s3c64xx_4bit().
  120. *
  121. * @sa s3c_gpio_getcfg_s3c24xx
  122. */
  123. extern unsigned s3c_gpio_getcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
  124. unsigned int off);
  125. /* Pull-{up,down} resistor controls.
  126. *
  127. * S3C2410,S3C2440,S3C24A0 = Pull-UP,
  128. * S3C2412,S3C2413 = Pull-Down
  129. * S3C6400,S3C6410 = Pull-Both [None,Down,Up,Undef]
  130. * S3C2443 = Pull-Both [not same as S3C6400]
  131. */
  132. /**
  133. * s3c_gpio_setpull_1up() - Pull configuration for choice of up or none.
  134. * @chip: The gpio chip that is being configured.
  135. * @off: The offset for the GPIO being configured.
  136. * @param: pull: The pull mode being requested.
  137. *
  138. * This is a helper function for the case where we have GPIOs with one
  139. * bit configuring the presence of a pull-up resistor.
  140. */
  141. extern int s3c_gpio_setpull_1up(struct s3c_gpio_chip *chip,
  142. unsigned int off, s3c_gpio_pull_t pull);
  143. /**
  144. * s3c_gpio_setpull_1down() - Pull configuration for choice of down or none
  145. * @chip: The gpio chip that is being configured
  146. * @off: The offset for the GPIO being configured
  147. * @param: pull: The pull mode being requested
  148. *
  149. * This is a helper function for the case where we have GPIOs with one
  150. * bit configuring the presence of a pull-down resistor.
  151. */
  152. extern int s3c_gpio_setpull_1down(struct s3c_gpio_chip *chip,
  153. unsigned int off, s3c_gpio_pull_t pull);
  154. /**
  155. * s3c_gpio_setpull_upown() - Pull configuration for choice of up, down or none
  156. * @chip: The gpio chip that is being configured.
  157. * @off: The offset for the GPIO being configured.
  158. * @param: pull: The pull mode being requested.
  159. *
  160. * This is a helper function for the case where we have GPIOs with two
  161. * bits configuring the presence of a pull resistor, in the following
  162. * order:
  163. * 00 = No pull resistor connected
  164. * 01 = Pull-up resistor connected
  165. * 10 = Pull-down resistor connected
  166. */
  167. extern int s3c_gpio_setpull_updown(struct s3c_gpio_chip *chip,
  168. unsigned int off, s3c_gpio_pull_t pull);
  169. /**
  170. * s3c_gpio_getpull_updown() - Get configuration for choice of up, down 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,down} resistor for the
  175. * given GPIO in the same case as s3c_gpio_setpull_upown.
  176. */
  177. extern s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip,
  178. unsigned int off);
  179. /**
  180. * s3c_gpio_getpull_1up() - Get configuration for choice of up or none
  181. * @chip: The gpio chip that the GPIO pin belongs to
  182. * @off: The offset to the pin to get the configuration of.
  183. *
  184. * This helper function reads the state of the pull-up resistor for the
  185. * given GPIO in the same case as s3c_gpio_setpull_1up.
  186. */
  187. extern s3c_gpio_pull_t s3c_gpio_getpull_1up(struct s3c_gpio_chip *chip,
  188. unsigned int off);
  189. /**
  190. * s3c_gpio_getpull_1down() - Get configuration for choice of down or none
  191. * @chip: The gpio chip that the GPIO pin belongs to
  192. * @off: The offset to the pin to get the configuration of.
  193. *
  194. * This helper function reads the state of the pull-down resistor for the
  195. * given GPIO in the same case as s3c_gpio_setpull_1down.
  196. */
  197. extern s3c_gpio_pull_t s3c_gpio_getpull_1down(struct s3c_gpio_chip *chip,
  198. unsigned int off);
  199. /**
  200. * s3c_gpio_setpull_s3c2443() - Pull configuration for s3c2443.
  201. * @chip: The gpio chip that is being configured.
  202. * @off: The offset for the GPIO being configured.
  203. * @param: pull: The pull mode being requested.
  204. *
  205. * This is a helper function for the case where we have GPIOs with two
  206. * bits configuring the presence of a pull resistor, in the following
  207. * order:
  208. * 00 = Pull-up resistor connected
  209. * 10 = Pull-down resistor connected
  210. * x1 = No pull up resistor
  211. */
  212. extern int s3c_gpio_setpull_s3c2443(struct s3c_gpio_chip *chip,
  213. unsigned int off, s3c_gpio_pull_t pull);
  214. /**
  215. * s3c_gpio_getpull_s3c2443() - Get configuration for s3c2443 pull resistors
  216. * @chip: The gpio chip that the GPIO pin belongs to.
  217. * @off: The offset to the pin to get the configuration of.
  218. *
  219. * This helper function reads the state of the pull-{up,down} resistor for the
  220. * given GPIO in the same case as s3c_gpio_setpull_upown.
  221. */
  222. extern s3c_gpio_pull_t s3c_gpio_getpull_s3c24xx(struct s3c_gpio_chip *chip,
  223. unsigned int off);
  224. #endif /* __PLAT_GPIO_CFG_HELPERS_H */