gpio-cfg.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /* linux/arch/arm/plat-s3c/include/plat/gpio-cfg.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
  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 file contains the necessary definitions to get the basic gpio
  15. * pin configuration done such as setting a pin to input or output or
  16. * changing the pull-{up,down} configurations.
  17. */
  18. /* Note, this interface is being added to the s3c64xx arch first and will
  19. * be added to the s3c24xx systems later.
  20. */
  21. #ifndef __PLAT_GPIO_CFG_H
  22. #define __PLAT_GPIO_CFG_H __FILE__
  23. #include<linux/types.h>
  24. typedef unsigned int __bitwise__ samsung_gpio_pull_t;
  25. typedef unsigned int __bitwise__ s5p_gpio_drvstr_t;
  26. /* forward declaration if gpio-core.h hasn't been included */
  27. struct samsung_gpio_chip;
  28. /**
  29. * struct samsung_gpio_cfg GPIO configuration
  30. * @cfg_eint: Configuration setting when used for external interrupt source
  31. * @get_pull: Read the current pull configuration for the GPIO
  32. * @set_pull: Set the current pull configuraiton for the GPIO
  33. * @set_config: Set the current configuration for the GPIO
  34. * @get_config: Read the current configuration for the GPIO
  35. *
  36. * Each chip can have more than one type of GPIO bank available and some
  37. * have different capabilites even when they have the same control register
  38. * layouts. Provide an point to vector control routine and provide any
  39. * per-bank configuration information that other systems such as the
  40. * external interrupt code will need.
  41. *
  42. * @sa samsung_gpio_cfgpin
  43. * @sa s3c_gpio_getcfg
  44. * @sa s3c_gpio_setpull
  45. * @sa s3c_gpio_getpull
  46. */
  47. struct samsung_gpio_cfg {
  48. unsigned int cfg_eint;
  49. samsung_gpio_pull_t (*get_pull)(struct samsung_gpio_chip *chip, unsigned offs);
  50. int (*set_pull)(struct samsung_gpio_chip *chip, unsigned offs,
  51. samsung_gpio_pull_t pull);
  52. unsigned (*get_config)(struct samsung_gpio_chip *chip, unsigned offs);
  53. int (*set_config)(struct samsung_gpio_chip *chip, unsigned offs,
  54. unsigned config);
  55. };
  56. #define S3C_GPIO_SPECIAL_MARK (0xfffffff0)
  57. #define S3C_GPIO_SPECIAL(x) (S3C_GPIO_SPECIAL_MARK | (x))
  58. /* Defines for generic pin configurations */
  59. #define S3C_GPIO_INPUT (S3C_GPIO_SPECIAL(0))
  60. #define S3C_GPIO_OUTPUT (S3C_GPIO_SPECIAL(1))
  61. #define S3C_GPIO_SFN(x) (S3C_GPIO_SPECIAL(x))
  62. #define samsung_gpio_is_cfg_special(_cfg) \
  63. (((_cfg) & S3C_GPIO_SPECIAL_MARK) == S3C_GPIO_SPECIAL_MARK)
  64. /**
  65. * s3c_gpio_cfgpin() - Change the GPIO function of a pin.
  66. * @pin pin The pin number to configure.
  67. * @to to The configuration for the pin's function.
  68. *
  69. * Configure which function is actually connected to the external
  70. * pin, such as an gpio input, output or some form of special function
  71. * connected to an internal peripheral block.
  72. *
  73. * The @to parameter can be one of the generic S3C_GPIO_INPUT, S3C_GPIO_OUTPUT
  74. * or S3C_GPIO_SFN() to indicate one of the possible values that the helper
  75. * will then generate the correct bit mask and shift for the configuration.
  76. *
  77. * If a bank of GPIOs all needs to be set to special-function 2, then
  78. * the following code will work:
  79. *
  80. * for (gpio = start; gpio < end; gpio++)
  81. * s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
  82. *
  83. * The @to parameter can also be a specific value already shifted to the
  84. * correct position in the control register, although these are discouraged
  85. * in newer kernels and are only being kept for compatibility.
  86. */
  87. extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);
  88. /**
  89. * s3c_gpio_getcfg - Read the current function for a GPIO pin
  90. * @pin: The pin to read the configuration value for.
  91. *
  92. * Read the configuration state of the given @pin, returning a value that
  93. * could be passed back to s3c_gpio_cfgpin().
  94. *
  95. * @sa s3c_gpio_cfgpin
  96. */
  97. extern unsigned s3c_gpio_getcfg(unsigned int pin);
  98. /**
  99. * s3c_gpio_cfgpin_range() - Change the GPIO function for configuring pin range
  100. * @start: The pin number to start at
  101. * @nr: The number of pins to configure from @start.
  102. * @cfg: The configuration for the pin's function
  103. *
  104. * Call s3c_gpio_cfgpin() for the @nr pins starting at @start.
  105. *
  106. * @sa s3c_gpio_cfgpin.
  107. */
  108. extern int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
  109. unsigned int cfg);
  110. /* Define values for the pull-{up,down} available for each gpio pin.
  111. *
  112. * These values control the state of the weak pull-{up,down} resistors
  113. * available on most pins on the S3C series. Not all chips support both
  114. * up or down settings, and it may be dependent on the chip that is being
  115. * used to whether the particular mode is available.
  116. */
  117. #define S3C_GPIO_PULL_NONE ((__force samsung_gpio_pull_t)0x00)
  118. #define S3C_GPIO_PULL_DOWN ((__force samsung_gpio_pull_t)0x01)
  119. #define S3C_GPIO_PULL_UP ((__force samsung_gpio_pull_t)0x02)
  120. /**
  121. * s3c_gpio_setpull() - set the state of a gpio pin pull resistor
  122. * @pin: The pin number to configure the pull resistor.
  123. * @pull: The configuration for the pull resistor.
  124. *
  125. * This function sets the state of the pull-{up,down} resistor for the
  126. * specified pin. It will return 0 if successful, or a negative error
  127. * code if the pin cannot support the requested pull setting.
  128. *
  129. * @pull is one of S3C_GPIO_PULL_NONE, S3C_GPIO_PULL_DOWN or S3C_GPIO_PULL_UP.
  130. */
  131. extern int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull);
  132. /**
  133. * s3c_gpio_getpull() - get the pull resistor state of a gpio pin
  134. * @pin: The pin number to get the settings for
  135. *
  136. * Read the pull resistor value for the specified pin.
  137. */
  138. extern samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin);
  139. /* configure `all` aspects of an gpio */
  140. /**
  141. * s3c_gpio_cfgall_range() - configure range of gpio functtion and pull.
  142. * @start: The gpio number to start at.
  143. * @nr: The number of gpio to configure from @start.
  144. * @cfg: The configuration to use
  145. * @pull: The pull setting to use.
  146. *
  147. * Run s3c_gpio_cfgpin() and s3c_gpio_setpull() over the gpio range starting
  148. * @gpio and running for @size.
  149. *
  150. * @sa s3c_gpio_cfgpin
  151. * @sa s3c_gpio_setpull
  152. * @sa s3c_gpio_cfgpin_range
  153. */
  154. extern int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
  155. unsigned int cfg, samsung_gpio_pull_t pull);
  156. static inline int s3c_gpio_cfgrange_nopull(unsigned int pin, unsigned int size,
  157. unsigned int cfg)
  158. {
  159. return s3c_gpio_cfgall_range(pin, size, cfg, S3C_GPIO_PULL_NONE);
  160. }
  161. /* Define values for the drvstr available for each gpio pin.
  162. *
  163. * These values control the value of the output signal driver strength,
  164. * configurable on most pins on the S5P series.
  165. */
  166. #define S5P_GPIO_DRVSTR_LV1 ((__force s5p_gpio_drvstr_t)0x0)
  167. #define S5P_GPIO_DRVSTR_LV2 ((__force s5p_gpio_drvstr_t)0x2)
  168. #define S5P_GPIO_DRVSTR_LV3 ((__force s5p_gpio_drvstr_t)0x1)
  169. #define S5P_GPIO_DRVSTR_LV4 ((__force s5p_gpio_drvstr_t)0x3)
  170. /**
  171. * s5c_gpio_get_drvstr() - get the driver streght value of a gpio pin
  172. * @pin: The pin number to get the settings for
  173. *
  174. * Read the driver streght value for the specified pin.
  175. */
  176. extern s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin);
  177. /**
  178. * s3c_gpio_set_drvstr() - set the driver streght value of a gpio pin
  179. * @pin: The pin number to configure the driver streght value
  180. * @drvstr: The new value of the driver strength
  181. *
  182. * This function sets the driver strength value for the specified pin.
  183. * It will return 0 if successful, or a negative error code if the pin
  184. * cannot support the requested setting.
  185. */
  186. extern int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr);
  187. /**
  188. * s5p_register_gpio_interrupt() - register interrupt support for a gpio group
  189. * @pin: The pin number from the group to be registered
  190. *
  191. * This function registers gpio interrupt support for the group that the
  192. * specified pin belongs to.
  193. *
  194. * The total number of gpio pins is quite large ob s5p series. Registering
  195. * irq support for all of them would be a resource waste. Because of that the
  196. * interrupt support for standard gpio pins is registered dynamically.
  197. *
  198. * It will return the irq number of the interrupt that has been registered
  199. * or -ENOMEM if no more gpio interrupts can be registered. It is allowed
  200. * to call this function more than once for the same gpio group (the group
  201. * will be registered only once).
  202. */
  203. extern int s5p_register_gpio_interrupt(int pin);
  204. /** s5p_register_gpioint_bank() - add gpio bank for further gpio interrupt
  205. * registration (see s5p_register_gpio_interrupt function)
  206. * @chain_irq: chained irq number for the gpio int handler for this bank
  207. * @start: start gpio group number of this bank
  208. * @nr_groups: number of gpio groups handled by this bank
  209. *
  210. * This functions registers initial information about gpio banks that
  211. * can be later used by the s5p_register_gpio_interrupt() function to
  212. * enable support for gpio interrupt for particular gpio group.
  213. */
  214. #ifdef CONFIG_S5P_GPIO_INT
  215. extern int s5p_register_gpioint_bank(int chain_irq, int start, int nr_groups);
  216. #else
  217. #define s5p_register_gpioint_bank(chain_irq, start, nr_groups) do { } while (0)
  218. #endif
  219. #endif /* __PLAT_GPIO_CFG_H */