gpio-cfg-helpers.h 8.1 KB

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