gpio-cfg-helpers.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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_setcfg_s3c24xx_a - S3C24XX style GPIO configuration (Bank A)
  50. * @chip: The gpio chip that is being configured.
  51. * @off: The offset for the GPIO being configured.
  52. * @cfg: The configuration value to set.
  53. *
  54. * This helper deal with the GPIO cases where the control register
  55. * has one bit of configuration for the gpio, where setting the bit
  56. * means the pin is in special function mode and unset means output.
  57. */
  58. extern int s3c_gpio_setcfg_s3c24xx_a(struct s3c_gpio_chip *chip,
  59. unsigned int off, unsigned int cfg);
  60. /**
  61. * s3c_gpio_setcfg_s3c64xx_4bit - S3C64XX 4bit single register GPIO config.
  62. * @chip: The gpio chip that is being configured.
  63. * @off: The offset for the GPIO being configured.
  64. * @cfg: The configuration value to set.
  65. *
  66. * This helper deal with the GPIO cases where the control register has 4 bits
  67. * of control per GPIO, generally in the form of:
  68. * 0000 = Input
  69. * 0001 = Output
  70. * others = Special functions (dependant on bank)
  71. *
  72. * Note, since the code to deal with the case where there are two control
  73. * registers instead of one, we do not have a seperate set of functions for
  74. * each case.
  75. */
  76. extern int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
  77. unsigned int off, unsigned int cfg);
  78. /* Pull-{up,down} resistor controls.
  79. *
  80. * S3C2410,S3C2440,S3C24A0 = Pull-UP,
  81. * S3C2412,S3C2413 = Pull-Down
  82. * S3C6400,S3C6410 = Pull-Both [None,Down,Up,Undef]
  83. * S3C2443 = Pull-Both [not same as S3C6400]
  84. */
  85. /**
  86. * s3c_gpio_setpull_1up() - Pull configuration for choice of up or none.
  87. * @chip: The gpio chip that is being configured.
  88. * @off: The offset for the GPIO being configured.
  89. * @param: pull: The pull mode being requested.
  90. *
  91. * This is a helper function for the case where we have GPIOs with one
  92. * bit configuring the presence of a pull-up resistor.
  93. */
  94. extern int s3c_gpio_setpull_1up(struct s3c_gpio_chip *chip,
  95. unsigned int off, s3c_gpio_pull_t pull);
  96. /**
  97. * s3c_gpio_setpull_1down() - Pull configuration for choice of down or none
  98. * @chip: The gpio chip that is being configured
  99. * @off: The offset for the GPIO being configured
  100. * @param: pull: The pull mode being requested
  101. *
  102. * This is a helper function for the case where we have GPIOs with one
  103. * bit configuring the presence of a pull-down resistor.
  104. */
  105. extern int s3c_gpio_setpull_1down(struct s3c_gpio_chip *chip,
  106. unsigned int off, s3c_gpio_pull_t pull);
  107. /**
  108. * s3c_gpio_setpull_upown() - Pull configuration for choice of up, down or none
  109. * @chip: The gpio chip that is being configured.
  110. * @off: The offset for the GPIO being configured.
  111. * @param: pull: The pull mode being requested.
  112. *
  113. * This is a helper function for the case where we have GPIOs with two
  114. * bits configuring the presence of a pull resistor, in the following
  115. * order:
  116. * 00 = No pull resistor connected
  117. * 01 = Pull-up resistor connected
  118. * 10 = Pull-down resistor connected
  119. */
  120. extern int s3c_gpio_setpull_updown(struct s3c_gpio_chip *chip,
  121. unsigned int off, s3c_gpio_pull_t pull);
  122. /**
  123. * s3c_gpio_getpull_updown() - Get configuration for choice of up, down or none
  124. * @chip: The gpio chip that the GPIO pin belongs to
  125. * @off: The offset to the pin to get the configuration of.
  126. *
  127. * This helper function reads the state of the pull-{up,down} resistor for the
  128. * given GPIO in the same case as s3c_gpio_setpull_upown.
  129. */
  130. extern s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip,
  131. unsigned int off);
  132. /**
  133. * s3c_gpio_setpull_s3c2443() - Pull configuration for s3c2443.
  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 two
  139. * bits configuring the presence of a pull resistor, in the following
  140. * order:
  141. * 00 = Pull-up resistor connected
  142. * 10 = Pull-down resistor connected
  143. * x1 = No pull up resistor
  144. */
  145. extern int s3c_gpio_setpull_s3c2443(struct s3c_gpio_chip *chip,
  146. unsigned int off, s3c_gpio_pull_t pull);
  147. /**
  148. * s3c_gpio_getpull_s3c2443() - Get configuration for s3c2443 pull resistors
  149. * @chip: The gpio chip that the GPIO pin belongs to.
  150. * @off: The offset to the pin to get the configuration of.
  151. *
  152. * This helper function reads the state of the pull-{up,down} resistor for the
  153. * given GPIO in the same case as s3c_gpio_setpull_upown.
  154. */
  155. extern s3c_gpio_pull_t s3c_gpio_getpull_s3c24xx(struct s3c_gpio_chip *chip,
  156. unsigned int off);
  157. #endif /* __PLAT_GPIO_CFG_HELPERS_H */