Path: blob/master/Documentation/arm/msm/gpiomux.txt
10823 views
This document provides an overview of the msm_gpiomux interface, which1is used to provide gpio pin multiplexing and configuration on mach-msm2targets.34History5=======67The first-generation API for gpio configuration & multiplexing on msm8is the function gpio_tlmm_config(). This function has a few notable9shortcomings, which led to its deprecation and replacement by gpiomux:1011The 'disable' parameter: Setting the second parameter to12gpio_tlmm_config to GPIO_CFG_DISABLE tells the peripheral13processor in charge of the subsystem to perform a look-up into a14low-power table and apply the low-power/sleep setting for the pin.15As the msm family evolved this became problematic. Not all pins16have sleep settings, not all peripheral processors will accept requests17to apply said sleep settings, and not all msm targets have their gpio18subsystems managed by a peripheral processor. In order to get consistent19behavior on all targets, drivers are forced to ignore this parameter,20rendering it useless.2122The 'direction' flag: for all mux-settings other than raw-gpio (0),23the output-enable bit of a gpio is hard-wired to a known24input (usually VDD or ground). For those settings, the direction flag25is meaningless at best, and deceptive at worst. In addition, using the26direction flag to change output-enable (OE) directly can cause trouble in27gpiolib, which has no visibility into gpio direction changes made28in this way. Direction control in gpio mode should be made through gpiolib.2930Key Features of gpiomux31=======================3233- A consistent interface across all generations of msm. Drivers can expect34the same results on every target.35- gpiomux plays nicely with gpiolib. Functions that should belong to gpiolib36are left to gpiolib and not duplicated here. gpiomux is written with the37intent that gpio_chips will call gpiomux reference-counting methods38from their request() and free() hooks, providing full integration.39- Tabular configuration. Instead of having to call gpio_tlmm_config40hundreds of times, gpio configuration is placed in a single table.41- Per-gpio sleep. Each gpio is individually reference counted, allowing only42those lines which are in use to be put in high-power states.43- 0 means 'do nothing': all flags are designed so that the default memset-zero44equates to a sensible default of 'no configuration', preventing users45from having to provide hundreds of 'no-op' configs for unused or46unwanted lines.4748Usage49=====5051To use gpiomux, provide configuration information for relevant gpio lines52in the msm_gpiomux_configs table. Since a 0 equates to "unconfigured",53only those lines to be managed by gpiomux need to be specified. Here54is a completely fictional example:5556struct msm_gpiomux_config msm_gpiomux_configs[GPIOMUX_NGPIOS] = {57[12] = {58.active = GPIOMUX_VALID | GPIOMUX_DRV_8MA | GPIOMUX_FUNC_1,59.suspended = GPIOMUX_VALID | GPIOMUX_PULL_DOWN,60},61[34] = {62.suspended = GPIOMUX_VALID | GPIOMUX_PULL_DOWN,63},64};6566To indicate that a gpio is in use, call msm_gpiomux_get() to increase67its reference count. To decrease the reference count, call msm_gpiomux_put().6869The effect of this configuration is as follows:7071When the system boots, gpios 12 and 34 will be initialized with their72'suspended' configurations. All other gpios, which were left unconfigured,73will not be touched.7475When msm_gpiomux_get() is called on gpio 12 to raise its reference count76above 0, its active configuration will be applied. Since no other gpio77line has a valid active configuration, msm_gpiomux_get() will have no78effect on any other line.7980When msm_gpiomux_put() is called on gpio 12 or 34 to drop their reference81count to 0, their suspended configurations will be applied.82Since no other gpio line has a valid suspended configuration, no other83gpio line will be effected by msm_gpiomux_put(). Since gpio 34 has no valid84active configuration, this is effectively a no-op for gpio 34 as well,85with one small caveat, see the section "About Output-Enable Settings".8687All of the GPIOMUX_VALID flags may seem like unnecessary overhead, but88they address some important issues. As unused entries (all those89except 12 and 34) are zero-filled, gpiomux needs a way to distinguish90the used fields from the unused. In addition, the all-zero pattern91is a valid configuration! Therefore, gpiomux defines an additional bit92which is used to indicate when a field is used. This has the pleasant93side-effect of allowing calls to msm_gpiomux_write to use '0' to indicate94that a value should not be changed:9596msm_gpiomux_write(0, GPIOMUX_VALID, 0);9798replaces the active configuration of gpio 0 with an all-zero configuration,99but leaves the suspended configuration as it was.100101Static Configurations102=====================103104To install a static configuration, which is applied at boot and does105not change after that, install a configuration with a suspended component106but no active component, as in the previous example:107108[34] = {109.suspended = GPIOMUX_VALID | GPIOMUX_PULL_DOWN,110},111112The suspended setting is applied during boot, and the lack of any valid113active setting prevents any other setting from being applied at runtime.114If other subsystems attempting to access the line is a concern, one could115*really* anchor the configuration down by calling msm_gpiomux_get on the116line at initialization to move the line into active mode. With the line117held, it will never be re-suspended, and with no valid active configuration,118no new configurations will be applied.119120But then, if having other subsystems grabbing for the line is truly a concern,121it should be reserved with gpio_request instead, which carries an implicit122msm_gpiomux_get.123124gpiomux and gpiolib125===================126127It is expected that msm gpio_chips will call msm_gpiomux_get() and128msm_gpiomux_put() from their request and free hooks, like this fictional129example:130131static int request(struct gpio_chip *chip, unsigned offset)132{133return msm_gpiomux_get(chip->base + offset);134}135136static void free(struct gpio_chip *chip, unsigned offset)137{138msm_gpiomux_put(chip->base + offset);139}140141...somewhere in a gpio_chip declaration...142.request = request,143.free = free,144145This provides important functionality:146- It guarantees that a gpio line will have its 'active' config applied147when the line is requested, and will not be suspended while the line148remains requested; and149- It guarantees that gpio-direction settings from gpiolib behave sensibly.150See "About Output-Enable Settings."151152This mechanism allows for "auto-request" of gpiomux lines via gpiolib153when it is suitable. Drivers wishing more exact control are, of course,154free to also use msm_gpiomux_set and msm_gpiomux_get.155156About Output-Enable Settings157============================158159Some msm targets do not have the ability to query the current gpio160configuration setting. This means that changes made to the output-enable161(OE) bit by gpiolib cannot be consistently detected and preserved by gpiomux.162Therefore, when gpiomux applies a configuration setting, any direction163settings which may have been applied by gpiolib are lost and the default164input settings are re-applied.165166For this reason, drivers should not assume that gpio direction settings167continue to hold if they free and then re-request a gpio. This seems like168common sense - after all, anybody could have obtained the line in the169meantime - but it needs saying.170171This also means that calls to msm_gpiomux_write will reset the OE bit,172which means that if the gpio line is held by a client of gpiolib and173msm_gpiomux_write is called, the direction setting has been lost and174gpiolib's internal state has been broken.175Release gpio lines before reconfiguring them.176177178