blob: 67a81620adf67d7830a5037d21a47ad48e2acdfc [file] [log] [blame]
Gregory Bean70816e22010-08-28 10:05:45 -07001This document provides an overview of the msm_gpiomux interface, which
2is used to provide gpio pin multiplexing and configuration on mach-msm
3targets.
4
5History
6=======
7
8The first-generation API for gpio configuration & multiplexing on msm
9is the function gpio_tlmm_config(). This function has a few notable
10shortcomings, which led to its deprecation and replacement by gpiomux:
11
12The 'disable' parameter: Setting the second parameter to
13gpio_tlmm_config to GPIO_CFG_DISABLE tells the peripheral
14processor in charge of the subsystem to perform a look-up into a
15low-power table and apply the low-power/sleep setting for the pin.
16As the msm family evolved this became problematic. Not all pins
17have sleep settings, not all peripheral processors will accept requests
18to apply said sleep settings, and not all msm targets have their gpio
19subsystems managed by a peripheral processor. In order to get consistent
20behavior on all targets, drivers are forced to ignore this parameter,
21rendering it useless.
22
23The 'direction' flag: for all mux-settings other than raw-gpio (0),
24the output-enable bit of a gpio is hard-wired to a known
25input (usually VDD or ground). For those settings, the direction flag
26is meaningless at best, and deceptive at worst. In addition, using the
27direction flag to change output-enable (OE) directly can cause trouble in
28gpiolib, which has no visibility into gpio direction changes made
29in this way. Direction control in gpio mode should be made through gpiolib.
30
31Key Features of gpiomux
32=======================
33
34- A consistent interface across all generations of msm. Drivers can expect
35the same results on every target.
36- gpiomux plays nicely with gpiolib. Functions that should belong to gpiolib
37are left to gpiolib and not duplicated here. gpiomux is written with the
38intent that gpio_chips will call gpiomux reference-counting methods
39from their request() and free() hooks, providing full integration.
40- Tabular configuration. Instead of having to call gpio_tlmm_config
41hundreds of times, gpio configuration is placed in a single table.
42- Per-gpio sleep. Each gpio is individually reference counted, allowing only
43those lines which are in use to be put in high-power states.
44- 0 means 'do nothing': all flags are designed so that the default memset-zero
45equates to a sensible default of 'no configuration', preventing users
46from having to provide hundreds of 'no-op' configs for unused or
47unwanted lines.
48
49Usage
50=====
51
52To use gpiomux, provide configuration information for relevant gpio lines
53in the msm_gpiomux_configs table. Since a 0 equates to "unconfigured",
54only those lines to be managed by gpiomux need to be specified. Here
55is a completely fictional example:
56
57struct msm_gpiomux_config msm_gpiomux_configs[GPIOMUX_NGPIOS] = {
58 [12] = {
59 .active = GPIOMUX_VALID | GPIOMUX_DRV_8MA | GPIOMUX_FUNC_1,
60 .suspended = GPIOMUX_VALID | GPIOMUX_PULL_DOWN,
61 },
62 [34] = {
63 .suspended = GPIOMUX_VALID | GPIOMUX_PULL_DOWN,
64 },
65};
66
67To indicate that a gpio is in use, call msm_gpiomux_get() to increase
68its reference count. To decrease the reference count, call msm_gpiomux_put().
69
70The effect of this configuration is as follows:
71
72When the system boots, gpios 12 and 34 will be initialized with their
73'suspended' configurations. All other gpios, which were left unconfigured,
74will not be touched.
75
76When msm_gpiomux_get() is called on gpio 12 to raise its reference count
77above 0, its active configuration will be applied. Since no other gpio
78line has a valid active configuration, msm_gpiomux_get() will have no
79effect on any other line.
80
81When msm_gpiomux_put() is called on gpio 12 or 34 to drop their reference
82count to 0, their suspended configurations will be applied.
83Since no other gpio line has a valid suspended configuration, no other
84gpio line will be effected by msm_gpiomux_put(). Since gpio 34 has no valid
85active configuration, this is effectively a no-op for gpio 34 as well,
86with one small caveat, see the section "About Output-Enable Settings".
87
88All of the GPIOMUX_VALID flags may seem like unnecessary overhead, but
89they address some important issues. As unused entries (all those
90except 12 and 34) are zero-filled, gpiomux needs a way to distinguish
91the used fields from the unused. In addition, the all-zero pattern
92is a valid configuration! Therefore, gpiomux defines an additional bit
93which is used to indicate when a field is used. This has the pleasant
94side-effect of allowing calls to msm_gpiomux_write to use '0' to indicate
95that a value should not be changed:
96
97 msm_gpiomux_write(0, GPIOMUX_VALID, 0);
98
99replaces the active configuration of gpio 0 with an all-zero configuration,
100but leaves the suspended configuration as it was.
101
102Static Configurations
103=====================
104
105To install a static configuration, which is applied at boot and does
106not change after that, install a configuration with a suspended component
107but no active component, as in the previous example:
108
109 [34] = {
110 .suspended = GPIOMUX_VALID | GPIOMUX_PULL_DOWN,
111 },
112
113The suspended setting is applied during boot, and the lack of any valid
114active setting prevents any other setting from being applied at runtime.
115If other subsystems attempting to access the line is a concern, one could
116*really* anchor the configuration down by calling msm_gpiomux_get on the
117line at initialization to move the line into active mode. With the line
118held, it will never be re-suspended, and with no valid active configuration,
119no new configurations will be applied.
120
121But then, if having other subsystems grabbing for the line is truly a concern,
122it should be reserved with gpio_request instead, which carries an implicit
123msm_gpiomux_get.
124
125gpiomux and gpiolib
126===================
127
128It is expected that msm gpio_chips will call msm_gpiomux_get() and
129msm_gpiomux_put() from their request and free hooks, like this fictional
130example:
131
132static int request(struct gpio_chip *chip, unsigned offset)
133{
134 return msm_gpiomux_get(chip->base + offset);
135}
136
137static void free(struct gpio_chip *chip, unsigned offset)
138{
139 msm_gpiomux_put(chip->base + offset);
140}
141
142 ...somewhere in a gpio_chip declaration...
143 .request = request,
144 .free = free,
145
146This provides important functionality:
147- It guarantees that a gpio line will have its 'active' config applied
148 when the line is requested, and will not be suspended while the line
149 remains requested; and
150- It guarantees that gpio-direction settings from gpiolib behave sensibly.
151 See "About Output-Enable Settings."
152
153This mechanism allows for "auto-request" of gpiomux lines via gpiolib
154when it is suitable. Drivers wishing more exact control are, of course,
155free to also use msm_gpiomux_set and msm_gpiomux_get.
156
157About Output-Enable Settings
158============================
159
160Some msm targets do not have the ability to query the current gpio
161configuration setting. This means that changes made to the output-enable
162(OE) bit by gpiolib cannot be consistently detected and preserved by gpiomux.
163Therefore, when gpiomux applies a configuration setting, any direction
164settings which may have been applied by gpiolib are lost and the default
165input settings are re-applied.
166
167For this reason, drivers should not assume that gpio direction settings
168continue to hold if they free and then re-request a gpio. This seems like
169common sense - after all, anybody could have obtained the line in the
170meantime - but it needs saying.
171
172This also means that calls to msm_gpiomux_write will reset the OE bit,
173which means that if the gpio line is held by a client of gpiolib and
174msm_gpiomux_write is called, the direction setting has been lost and
175gpiolib's internal state has been broken.
176Release gpio lines before reconfiguring them.