gpiomux.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. This document provides an overview of the msm_gpiomux interface, which
  2. is used to provide gpio pin multiplexing and configuration on mach-msm
  3. targets.
  4. Usage
  5. =====
  6. To use gpiomux, do the following before the msmgpio gpiochips probe:
  7. - Call msm_gpiomux_init to allocate needed resources.
  8. - Install one or more sets of gpiomux configuration data via
  9. msm_gpiomux_install and/or msm_gpiomux_write.
  10. Failing to finish these steps before the probe of msmgpio can result in calls
  11. from msmgpio to gpiomux to try and activate lines which have not yet
  12. been configured.
  13. A basic gpiomux setting is described by a gpiomux_setting structure.
  14. A gpiomux configuration is a group of those settings (one for each power
  15. state of the board) paired with a specific gpio, like so:
  16. struct msm_gpiomux_config gpio123_config __initdata = {
  17. .gpio = 123,
  18. .settings = {
  19. [GPIOMUX_ACTIVE] = {
  20. .func = GPIOMUX_FUNC_GPIO,
  21. .drv = GPIOMUX_DRV_2MA,
  22. .pull = GPIOMUX_PULL_NONE,
  23. .dir = GPIOMUX_OUT_HIGH,
  24. },
  25. [GPIOMUX_SUSPENDED] = {
  26. .func = GPIOMUX_FUNC_3,
  27. .drv = GPIOMUX_DRV_8MA,
  28. .pull = GPIOMUX_PULL_DOWN,
  29. },
  30. },
  31. };
  32. The effect of this configuration is as follows:
  33. - When the system boots, gpio 123 will be put into the SUSPENDED setting.
  34. - When the reference count for gpio 123 rises above 0, the ACTIVE setting
  35. will be applied.
  36. - When the reference count falls back to 0, the SUSPENDED setting will be
  37. reapplied.
  38. The reference count rises when msm_gpiomux_get() is called and falls
  39. when msm_gpiomux_put() is called. msmgpio has hooks to these functions
  40. in its gpiolib implementation. This means that when you call gpio_request()
  41. on an msmgpio, msm_gpiomux_get() is automatically called on your behalf.
  42. Similarly, when you call gpio_free(), msm_gpiomux_put() is called for you.
  43. This allows generic drivers to obtain low-level management of msmgpio lines
  44. without having to be aware of the gpiomux layer.
  45. Note that the .dir field is ignored if .func != GPIOMUX_FUNC_GPIO, since
  46. software control of gpios is allowed only in GPIO mode. By selecting any
  47. other .func, you assign the gpio to another piece of hardware and lose
  48. control of it from gpiolib. You can still reserve such gpios with gpio_request
  49. to prevent other modules from using them while they're in such a state,
  50. but other gpiolib functions will not behave as you expect if .func != GPIO.
  51. If a configuration is omitted, nothing will happen at the relevant transitions.
  52. This allows for the creation of 'static configurations' which do not
  53. change as the line is requested and freed.
  54. Static Configurations
  55. =====================
  56. To install a static configuration, which is applied at boot and does
  57. not change after that, install a configuration with a suspended component
  58. but no active component:
  59. .gpio = ...,
  60. .settings = {
  61. [GPIOMUX_SUSPENDED] = {
  62. ...
  63. },
  64. },
  65. The suspended setting is applied during boot, and the lack of any valid
  66. active setting prevents any other setting from being applied at runtime.
  67. If other subsystems attempting to access the line is a concern, one could
  68. *really* anchor the configuration down by calling msm_gpiomux_get on the
  69. line at initialization to move the line into active mode. With the line
  70. held, it will never be re-suspended, and with no valid active configuration,
  71. no new configurations will be applied.
  72. But then, if having other subsystems grabbing for the line is truly a concern,
  73. it should be reserved with gpio_request instead, which carries an implicit
  74. msm_gpiomux_get.
  75. gpiomux and gpiolib
  76. ===================
  77. It is expected that msm gpio_chips will call msm_gpiomux_get() and
  78. msm_gpiomux_put() from their request and free hooks, like this fictional
  79. example:
  80. static int request(struct gpio_chip *chip, unsigned offset)
  81. {
  82. return msm_gpiomux_get(chip->base + offset);
  83. }
  84. static void free(struct gpio_chip *chip, unsigned offset)
  85. {
  86. msm_gpiomux_put(chip->base + offset);
  87. }
  88. ...somewhere in a gpio_chip declaration...
  89. .request = request,
  90. .free = free,
  91. This provides important functionality:
  92. - It guarantees that a gpio line will have its 'active' config applied
  93. when the line is requested, and will not be suspended while the line
  94. remains requested; and
  95. - It guarantees that gpio-direction settings from gpiolib behave sensibly.
  96. See "About Output-Enable Settings."
  97. This mechanism allows for "auto-request" of gpiomux lines via gpiolib
  98. when it is suitable. Drivers wishing more exact control are, of course,
  99. free to also use msm_gpiomux_set and msm_gpiomux_get.