blob: aaf0793be076689f2b3202f9827a86ce016c7eef [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
Gregory Bean70816e22010-08-28 10:05:45 -07005Usage
6=====
7
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008To use gpiomux, do the following before the msmgpio gpiochips probe:
Gregory Bean70816e22010-08-28 10:05:45 -07009
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070010- 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
14Failing to finish these steps before the probe of msmgpio can result in calls
15from msmgpio to gpiomux to try and activate lines which have not yet
16been configured.
17
18A basic gpiomux setting is described by a gpiomux_setting structure.
19A gpiomux configuration is a group of those settings (one for each power
20state of the board) paired with a specific gpio, like so:
21
22struct 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 Bean70816e22010-08-28 10:05:45 -070036 },
37};
38
Gregory Bean70816e22010-08-28 10:05:45 -070039The effect of this configuration is as follows:
40
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041- 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 Bean70816e22010-08-28 10:05:45 -070046
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070047The reference count rises when msm_gpiomux_get() is called and falls
48when msm_gpiomux_put() is called. msmgpio has hooks to these functions
49in its gpiolib implementation. This means that when you call gpio_request()
50on an msmgpio, msm_gpiomux_get() is automatically called on your behalf.
51Similarly, when you call gpio_free(), msm_gpiomux_put() is called for you.
52This allows generic drivers to obtain low-level management of msmgpio lines
53without having to be aware of the gpiomux layer.
Gregory Bean70816e22010-08-28 10:05:45 -070054
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055Note that the .dir field is ignored if .func != GPIOMUX_FUNC_GPIO, since
56software control of gpios is allowed only in GPIO mode. By selecting any
57other .func, you assign the gpio to another piece of hardware and lose
58control of it from gpiolib. You can still reserve such gpios with gpio_request
59to prevent other modules from using them while they're in such a state,
60but other gpiolib functions will not behave as you expect if .func != GPIO.
Gregory Bean70816e22010-08-28 10:05:45 -070061
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070062If a configuration is omitted, nothing will happen at the relevant transitions.
63This allows for the creation of 'static configurations' which do not
64change as the line is requested and freed.
Gregory Bean70816e22010-08-28 10:05:45 -070065
66Static Configurations
67=====================
68
69To install a static configuration, which is applied at boot and does
70not change after that, install a configuration with a suspended component
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070071but no active component:
Gregory Bean70816e22010-08-28 10:05:45 -070072
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070073 .gpio = ...,
74 .settings = {
75 [GPIOMUX_SUSPENDED] = {
76 ...
77 },
Gregory Bean70816e22010-08-28 10:05:45 -070078 },
79
80The suspended setting is applied during boot, and the lack of any valid
81active setting prevents any other setting from being applied at runtime.
82If 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
84line at initialization to move the line into active mode. With the line
85held, it will never be re-suspended, and with no valid active configuration,
86no new configurations will be applied.
87
88But then, if having other subsystems grabbing for the line is truly a concern,
89it should be reserved with gpio_request instead, which carries an implicit
90msm_gpiomux_get.
91
92gpiomux and gpiolib
93===================
94
95It is expected that msm gpio_chips will call msm_gpiomux_get() and
96msm_gpiomux_put() from their request and free hooks, like this fictional
97example:
98
99static int request(struct gpio_chip *chip, unsigned offset)
100{
101 return msm_gpiomux_get(chip->base + offset);
102}
103
104static 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
113This 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
120This mechanism allows for "auto-request" of gpiomux lines via gpiolib
121when it is suitable. Drivers wishing more exact control are, of course,
122free to also use msm_gpiomux_set and msm_gpiomux_get.