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