gpio-cfg.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * http://armlinux.simtec.co.uk/
  6. * Ben Dooks <[email protected]>
  7. *
  8. * S3C Platform - GPIO pin configuration
  9. */
  10. /* This file contains the necessary definitions to get the basic gpio
  11. * pin configuration done such as setting a pin to input or output or
  12. * changing the pull-{up,down} configurations.
  13. */
  14. /* Note, this interface is being added to the s3c64xx arch first and will
  15. * be added to the s3c24xx systems later.
  16. */
  17. #ifndef __PLAT_GPIO_CFG_H
  18. #define __PLAT_GPIO_CFG_H __FILE__
  19. #include <linux/types.h>
  20. typedef unsigned int __bitwise samsung_gpio_pull_t;
  21. /* forward declaration if gpio-core.h hasn't been included */
  22. struct samsung_gpio_chip;
  23. /**
  24. * struct samsung_gpio_cfg GPIO configuration
  25. * @cfg_eint: Configuration setting when used for external interrupt source
  26. * @get_pull: Read the current pull configuration for the GPIO
  27. * @set_pull: Set the current pull configuration for the GPIO
  28. * @set_config: Set the current configuration for the GPIO
  29. * @get_config: Read the current configuration for the GPIO
  30. *
  31. * Each chip can have more than one type of GPIO bank available and some
  32. * have different capabilites even when they have the same control register
  33. * layouts. Provide an point to vector control routine and provide any
  34. * per-bank configuration information that other systems such as the
  35. * external interrupt code will need.
  36. *
  37. * @sa samsung_gpio_cfgpin
  38. * @sa s3c_gpio_getcfg
  39. * @sa s3c_gpio_setpull
  40. * @sa s3c_gpio_getpull
  41. */
  42. struct samsung_gpio_cfg {
  43. unsigned int cfg_eint;
  44. samsung_gpio_pull_t (*get_pull)(struct samsung_gpio_chip *chip, unsigned offs);
  45. int (*set_pull)(struct samsung_gpio_chip *chip, unsigned offs,
  46. samsung_gpio_pull_t pull);
  47. unsigned (*get_config)(struct samsung_gpio_chip *chip, unsigned offs);
  48. int (*set_config)(struct samsung_gpio_chip *chip, unsigned offs,
  49. unsigned config);
  50. };
  51. #define S3C_GPIO_SPECIAL_MARK (0xfffffff0)
  52. #define S3C_GPIO_SPECIAL(x) (S3C_GPIO_SPECIAL_MARK | (x))
  53. /* Defines for generic pin configurations */
  54. #define S3C_GPIO_INPUT (S3C_GPIO_SPECIAL(0))
  55. #define S3C_GPIO_OUTPUT (S3C_GPIO_SPECIAL(1))
  56. #define S3C_GPIO_SFN(x) (S3C_GPIO_SPECIAL(x))
  57. #define samsung_gpio_is_cfg_special(_cfg) \
  58. (((_cfg) & S3C_GPIO_SPECIAL_MARK) == S3C_GPIO_SPECIAL_MARK)
  59. /**
  60. * s3c_gpio_cfgpin() - Change the GPIO function of a pin.
  61. * @pin pin The pin number to configure.
  62. * @to to The configuration for the pin's function.
  63. *
  64. * Configure which function is actually connected to the external
  65. * pin, such as an gpio input, output or some form of special function
  66. * connected to an internal peripheral block.
  67. *
  68. * The @to parameter can be one of the generic S3C_GPIO_INPUT, S3C_GPIO_OUTPUT
  69. * or S3C_GPIO_SFN() to indicate one of the possible values that the helper
  70. * will then generate the correct bit mask and shift for the configuration.
  71. *
  72. * If a bank of GPIOs all needs to be set to special-function 2, then
  73. * the following code will work:
  74. *
  75. * for (gpio = start; gpio < end; gpio++)
  76. * s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
  77. *
  78. * The @to parameter can also be a specific value already shifted to the
  79. * correct position in the control register, although these are discouraged
  80. * in newer kernels and are only being kept for compatibility.
  81. */
  82. extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);
  83. /**
  84. * s3c_gpio_getcfg - Read the current function for a GPIO pin
  85. * @pin: The pin to read the configuration value for.
  86. *
  87. * Read the configuration state of the given @pin, returning a value that
  88. * could be passed back to s3c_gpio_cfgpin().
  89. *
  90. * @sa s3c_gpio_cfgpin
  91. */
  92. extern unsigned s3c_gpio_getcfg(unsigned int pin);
  93. /**
  94. * s3c_gpio_cfgpin_range() - Change the GPIO function for configuring pin range
  95. * @start: The pin number to start at
  96. * @nr: The number of pins to configure from @start.
  97. * @cfg: The configuration for the pin's function
  98. *
  99. * Call s3c_gpio_cfgpin() for the @nr pins starting at @start.
  100. *
  101. * @sa s3c_gpio_cfgpin.
  102. */
  103. extern int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
  104. unsigned int cfg);
  105. /* Define values for the pull-{up,down} available for each gpio pin.
  106. *
  107. * These values control the state of the weak pull-{up,down} resistors
  108. * available on most pins on the S3C series. Not all chips support both
  109. * up or down settings, and it may be dependent on the chip that is being
  110. * used to whether the particular mode is available.
  111. */
  112. #define S3C_GPIO_PULL_NONE ((__force samsung_gpio_pull_t)0x00)
  113. #define S3C_GPIO_PULL_DOWN ((__force samsung_gpio_pull_t)0x01)
  114. #define S3C_GPIO_PULL_UP ((__force samsung_gpio_pull_t)0x02)
  115. /**
  116. * s3c_gpio_setpull() - set the state of a gpio pin pull resistor
  117. * @pin: The pin number to configure the pull resistor.
  118. * @pull: The configuration for the pull resistor.
  119. *
  120. * This function sets the state of the pull-{up,down} resistor for the
  121. * specified pin. It will return 0 if successful, or a negative error
  122. * code if the pin cannot support the requested pull setting.
  123. *
  124. * @pull is one of S3C_GPIO_PULL_NONE, S3C_GPIO_PULL_DOWN or S3C_GPIO_PULL_UP.
  125. */
  126. extern int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull);
  127. /**
  128. * s3c_gpio_getpull() - get the pull resistor state of a gpio pin
  129. * @pin: The pin number to get the settings for
  130. *
  131. * Read the pull resistor value for the specified pin.
  132. */
  133. extern samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin);
  134. /* configure `all` aspects of an gpio */
  135. /**
  136. * s3c_gpio_cfgall_range() - configure range of gpio functtion and pull.
  137. * @start: The gpio number to start at.
  138. * @nr: The number of gpio to configure from @start.
  139. * @cfg: The configuration to use
  140. * @pull: The pull setting to use.
  141. *
  142. * Run s3c_gpio_cfgpin() and s3c_gpio_setpull() over the gpio range starting
  143. * @gpio and running for @size.
  144. *
  145. * @sa s3c_gpio_cfgpin
  146. * @sa s3c_gpio_setpull
  147. * @sa s3c_gpio_cfgpin_range
  148. */
  149. extern int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
  150. unsigned int cfg, samsung_gpio_pull_t pull);
  151. static inline int s3c_gpio_cfgrange_nopull(unsigned int pin, unsigned int size,
  152. unsigned int cfg)
  153. {
  154. return s3c_gpio_cfgall_range(pin, size, cfg, S3C_GPIO_PULL_NONE);
  155. }
  156. #endif /* __PLAT_GPIO_CFG_H */