msm: gpiomux: Improve gpiomux interface design.
PATCH 1/2 msm: gpiomux: Improve gpiomux interface design.
Fix the gpiomux interface by:
- collapsing redundant abstractions into shared common ones
- disconnecting gpiomux abstractions from particular MSM implementations
- moving platform-specific details out of the common abstraction
- moving implementation complexity out of the interface and back into the implementation, where it should have been in the first place
- allowing for the future extension of the set of power states
- disambiguating 'settings' and 'configurations'.
- improving the initialization sequence to provide more flexibility
- not forcing lines to reset to input mode at power transitions
--- arch/arm/mach-msm/gpio.c | 17 ++++ arch/arm/mach-msm/gpio.h | 28 +++++++ arch/arm/mach-msm/gpiomux-7x30.c | 69 +++++++++++++---- arch/arm/mach-msm/gpiomux-8x50.c | 43 +++++++++-- arch/arm/mach-msm/gpiomux-8x60.c | 9 ++- arch/arm/mach-msm/gpiomux-v1.c | 24 +++++- arch/arm/mach-msm/gpiomux-v1.h | 67 ----------------- arch/arm/mach-msm/gpiomux-v2.c | 17 ++++- arch/arm/mach-msm/gpiomux-v2.h | 61 --------------- arch/arm/mach-msm/gpiomux.c | 121 ++++++++++++++++++++++-------- arch/arm/mach-msm/gpiomux.h | 152 +++++++++++++++++++++++++++----------- 11 files changed, 378 insertions(+), 230 deletions(-) create mode 100644 arch/arm/mach-msm/gpio.h delete mode 100644 arch/arm/mach-msm/gpiomux-v1.h delete mode 100644 arch/arm/mach-msm/gpiomux-v2.h
arch/arm/mach-msm/gpio.c +17 -0
@@ -374,3 +374,20 @@ static int __init msm_init_gpio(void) }postcore_initcall (msm_init_gpio); + +/* Locate the GPIO_OUT register for the given GPIO and return its address +* and the bit position of the gpio's bit within the register. +* +* This function is used by gpiomux-v1 in order to support output transitions. +*/ +void msm_gpio_find_out (const unsigned gpio,void __iomem **out, +unsigned *offset) +{ +struct msm_gpio_chip *msm_chip = msm_gpio_chips; + +while (gpio >= msm_chip->chip.base + msm_chip->chip.ngpio) + ++msm_chip; + + *out = msm_chip->regs.out; + *offset = gpio - msm_chip->chip.base; +}
arch/arm/mach-msm/gpio.h new file +28 -0
@@ -0,0 +1,28 @@ +/* Copyright (c) 2010, Code Aurora Forum. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA. +*/ +#ifndef _ARCH_ARM_MACH_MSM_GPIO_H_ +#define _ARCH_ARM_MACH_MSM_GPIO_H_ + +/* Locate the GPIO_OUT register for the given GPIO and return its address +* and the bit position of the gpio's bit within the register. +* +* This function is used by gpiomux-v1 in order to support output transitions. +*/ +void msm_gpio_find_out (const unsigned gpio,void __iomem **out, +unsigned *offset); + +#endif
arch/arm/mach-msm/gpiomux-7x30.c +54 -15
79 lines not on this page · raw message
arch/arm/mach-msm/gpiomux-8x50.c +36 -7
51 lines not on this page · raw message
arch/arm/mach-msm/gpiomux-8x60.c +8 -1
@@ -14,6 +14,13 @@* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ +#include <linux/module.h> +#include <mach/irqs.h> +#include <asm/mach-types.h> #include "gpiomux.h" -struct msm_gpiomux_config msm_gpiomux_configs[GPIOMUX_NGPIOS ] = {}; +static int __init gpiomux_init (void ) +{ +return msm_gpiomux_init (NR_GPIO_IRQS ); +} +postcore_initcall (gpiomux_init);
arch/arm/mach-msm/gpiomux-v1.c +21 -3
@@ -14,17 +14,35 @@* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ +#include <linux/bitops.h> #include <linux/kernel.h> +#include <linux/io.h> #include "gpiomux.h" #include "proc_comm.h" +#include "gpio.h" -void __msm_gpiomux_write (unsigned gpio,gpiomux_config_t val) +void __msm_gpiomux_write (unsigned gpio,struct gpiomux_setting val) { -unsigned tlmm_config = (val & ~GPIOMUX_CTL_MASK ) | - ((gpio &0x3ff ) <<4 ); +unsigned tlmm_config;unsigned tlmm_disable =0 ; +void __iomem *out_reg; +unsigned offset; +uint32_t bits;int rc; + tlmm_config = (val.drv <<17 ) | + (val.pull <<15 ) | + ((gpio &0x3ff ) <<4 ) | + val.func; +if (val.func ==GPIOMUX_FUNC_GPIO ) { + tlmm_config |= (val.dir >GPIOMUX_IN ?BIT (14 ) :0 ); +msm_gpio_find_out (gpio, &out_reg, &offset); + bits =readl (out_reg); +if (val.dir ==GPIOMUX_OUT_HIGH ) +writel (bits |BIT (offset), out_reg); +else +writel (bits & ~BIT (offset), out_reg); + } rc =msm_proc_comm (PCOM_RPC_GPIO_TLMM_CONFIG_EX , &tlmm_config, &tlmm_disable);if (rc)
arch/arm/mach-msm/gpiomux-v1.h deleted +0 -67
67 lines not on this page · raw message
arch/arm/mach-msm/gpiomux-v2.c +14 -3
@@ -14,12 +14,23 @@* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ +#include <linux/bitops.h> #include <linux/io.h> #include <mach/msm_iomap.h> #include "gpiomux.h" -void __msm_gpiomux_write (unsigned gpio,gpiomux_config_t val) +#define GPIO_CFG (n) (MSM_TLMM_BASE + 0x1000 + (0x10 * n)) +#define GPIO_IN_OUT (n) (MSM_TLMM_BASE + 0x1004 + (0x10 * n)) + +void __msm_gpiomux_write (unsigned gpio,struct gpiomux_setting val) { -writel (val & ~GPIOMUX_CTL_MASK , -MSM_TLMM_BASE +0x1000 + (0x10 * gpio)); +uint32_t bits; + + bits = (val.drv <<6 ) | (val.func <<2 ) | val.pull; +if (val.func ==GPIOMUX_FUNC_GPIO ) { + bits |= val.dir >GPIOMUX_IN ?BIT (9 ) :0 ; +writel (val.dir ==GPIOMUX_OUT_HIGH ?BIT (1 ) :0 , +GPIO_IN_OUT (gpio)); + } +writel (bits,GPIO_CFG (gpio)); }
arch/arm/mach-msm/gpiomux-v2.h deleted +0 -61
61 lines not on this page · raw message
arch/arm/mach-msm/gpiomux.c +90 -31
171 lines not on this page · raw message
arch/arm/mach-msm/gpiomux.h +110 -42
194 lines not on this page · raw message
Signature · 5 lines
1.7.0.4 -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 2/2 msm: documentation: Update gpiomux documentation.
Bring gpiomux documentation up-to-date with the current API.
--- Documentation/arm/msm/gpiomux.txt | 170 +++++++++++++------------------------ 1 files changed, 58 insertions(+), 112 deletions(-)
Documentation/arm/msm/gpiomux.txt +58 -112
@@ -2,112 +2,79 @@ This document provides an overview of the msm_gpiomux interface, which is used to provide gpio pin multiplexing and configuration on mach-msm targets. -History -======= - -The first-generation API for gpio configuration & multiplexing on msm -is the function gpio_tlmm_config(). This function has a few notable -shortcomings, which led to its deprecation and replacement by gpiomux: - -The 'disable' parameter: Setting the second parameter to -gpio_tlmm_config to GPIO_CFG_DISABLE tells the peripheral -processor in charge of the subsystem to perform a look-up into a -low-power table and apply the low-power/sleep setting for the pin. -As the msm family evolved this became problematic. Not all pins -have sleep settings, not all peripheral processors will accept requests -to apply said sleep settings, and not all msm targets have their gpio -subsystems managed by a peripheral processor. In order to get consistent -behavior on all targets, drivers are forced to ignore this parameter, -rendering it useless. - -The 'direction' flag: for all mux-settings other than raw-gpio (0), -the output-enable bit of a gpio is hard-wired to a known -input (usually VDD or ground). For those settings, the direction flag -is meaningless at best, and deceptive at worst. In addition, using the -direction flag to change output-enable (OE) directly can cause trouble in -gpiolib, which has no visibility into gpio direction changes made -in this way. Direction control in gpio mode should be made through gpiolib. - -Key Features of gpiomux -======================= - -- A consistent interface across all generations of msm. Drivers can expect -the same results on every target. -- gpiomux plays nicely with gpiolib. Functions that should belong to gpiolib -are left to gpiolib and not duplicated here. gpiomux is written with the -intent that gpio_chips will call gpiomux reference-counting methods -from their request() and free() hooks, providing full integration. -- Tabular configuration. Instead of having to call gpio_tlmm_config -hundreds of times, gpio configuration is placed in a single table. -- Per-gpio sleep. Each gpio is individually reference counted, allowing only -those lines which are in use to be put in high-power states. -- 0 means 'do nothing': all flags are designed so that the default memset-zero -equates to a sensible default of 'no configuration', preventing users -from having to provide hundreds of 'no-op' configs for unused or -unwanted lines. - Usage ===== -To use gpiomux, provide configuration information for relevant gpio lines -in the msm_gpiomux_configs table. Since a 0 equates to "unconfigured", -only those lines to be managed by gpiomux need to be specified. Here -is a completely fictional example: - -struct msm_gpiomux_config msm_gpiomux_configs[GPIOMUX_NGPIOS] = { - [12] = { - .active = GPIOMUX_VALID | GPIOMUX_DRV_8MA | GPIOMUX_FUNC_1, - .suspended = GPIOMUX_VALID | GPIOMUX_PULL_DOWN, - }, - [34] = { - .suspended = GPIOMUX_VALID | GPIOMUX_PULL_DOWN, +To use gpiomux, do the following before the msmgpio gpiochips probe: + +- Call msm_gpiomux_init to allocate needed resources. +- Install one or more sets of gpiomux configuration data via + msm_gpiomux_install and/or msm_gpiomux_write. + +Failing to finish these steps before the probe of msmgpio can result in calls +from msmgpio to gpiomux to try and activate lines which have not yet +been configured. + +A basic gpiomux setting is described by a gpiomux_setting structure. +A gpiomux configuration is a group of those settings (one for each power +state of the board) paired with a specific gpio, like so: + +struct msm_gpiomux_config gpio123_config __initdata = { + .gpio = 123, + .settings = { + [GPIOMUX_ACTIVE] = { + .func = GPIOMUX_FUNC_GPIO, + .drv = GPIOMUX_DRV_2MA, + .pull = GPIOMUX_PULL_NONE, + .dir = GPIOMUX_OUT_HIGH, + }, + [GPIOMUX_SUSPENDED] = { + .func = GPIOMUX_FUNC_3, + .drv = GPIOMUX_DRV_8MA, + .pull = GPIOMUX_PULL_DOWN, + }, }, }; -To indicate that a gpio is in use, call msm_gpiomux_get() to increase -its reference count. To decrease the reference count, call msm_gpiomux_put(). - The effect of this configuration is as follows: -When the system boots, gpios 12 and 34 will be initialized with their -'suspended' configurations. All other gpios, which were left unconfigured, -will not be touched. - -When msm_gpiomux_get() is called on gpio 12 to raise its reference count -above 0, its active configuration will be applied. Since no other gpio -line has a valid active configuration, msm_gpiomux_get() will have no -effect on any other line. - -When msm_gpiomux_put() is called on gpio 12 or 34 to drop their reference -count to 0, their suspended configurations will be applied. -Since no other gpio line has a valid suspended configuration, no other -gpio line will be effected by msm_gpiomux_put(). Since gpio 34 has no valid -active configuration, this is effectively a no-op for gpio 34 as well, -with one small caveat, see the section "About Output-Enable Settings". - -All of the GPIOMUX_VALID flags may seem like unnecessary overhead, but -they address some important issues. As unused entries (all those -except 12 and 34) are zero-filled, gpiomux needs a way to distinguish -the used fields from the unused. In addition, the all-zero pattern -is a valid configuration! Therefore, gpiomux defines an additional bit -which is used to indicate when a field is used. This has the pleasant -side-effect of allowing calls to msm_gpiomux_write to use '0' to indicate -that a value should not be changed: - - msm_gpiomux_write(0, GPIOMUX_VALID, 0); - -replaces the active configuration of gpio 0 with an all-zero configuration, -but leaves the suspended configuration as it was. +- When the system boots, gpio 123 will be put into the SUSPENDED setting. +- When the reference count for gpio 123 rises above 0, the ACTIVE setting + will be applied. +- When the reference count falls back to 0, the SUSPENDED setting will be + reapplied. + +The reference count rises when msm_gpiomux_get() is called and falls +when msm_gpiomux_put() is called. msmgpio has hooks to these functions +in its gpiolib implementation. This means that when you call gpio_request() +on an msmgpio, msm_gpiomux_get() is automatically called on your behalf. +Similarly, when you call gpio_free(), msm_gpiomux_put() is called for you. +This allows generic drivers to obtain low-level management of msmgpio lines +without having to be aware of the gpiomux layer. + +Note that the .dir field is ignored if .func != GPIOMUX_FUNC_GPIO, since +software control of gpios is allowed only in GPIO mode. By selecting any +other .func, you assign the gpio to another piece of hardware and lose +control of it from gpiolib. You can still reserve such gpios with gpio_request +to prevent other modules from using them while they're in such a state, +but other gpiolib functions will not behave as you expect if .func != GPIO. + +If a configuration is omitted, nothing will happen at the relevant transitions. +This allows for the creation of 'static configurations' which do not +change as the line is requested and freed. Static Configurations ===================== To install a static configuration, which is applied at boot and does not change after that, install a configuration with a suspended component -but no active component, as in the previous example: +but no active component: - [34] = { - .suspended = GPIOMUX_VALID | GPIOMUX_PULL_DOWN, + .gpio = ..., + .settings = { + [GPIOMUX_SUSPENDED] = { + ... + }, }, The suspended setting is applied during boot, and the lack of any valid
@@ -153,24 +120,3 @@ This provides important functionality: This mechanism allows for "auto-request" of gpiomux lines via gpiolib when it is suitable. Drivers wishing more exact control are, of course, free to also use msm_gpiomux_set and msm_gpiomux_get. - -About Output-Enable Settings -============================ - -Some msm targets do not have the ability to query the current gpio -configuration setting. This means that changes made to the output-enable -(OE) bit by gpiolib cannot be consistently detected and preserved by gpiomux. -Therefore, when gpiomux applies a configuration setting, any direction -settings which may have been applied by gpiolib are lost and the default -input settings are re-applied. - -For this reason, drivers should not assume that gpio direction settings -continue to hold if they free and then re-request a gpio. This seems like -common sense - after all, anybody could have obtained the line in the -meantime - but it needs saying. - -This also means that calls to msm_gpiomux_write will reset the OE bit, -which means that if the gpio line is held by a client of gpiolib and -msm_gpiomux_write is called, the direction setting has been lost and -gpiolib's internal state has been broken. -Release gpio lines before reconfiguring them.
Signature · 5 lines
1.7.0.4 -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 1/2 msm: gpiomux: Improve gpiomux interface design.
In reply to Gregory BeanQuoted 10 lines · Gregory Bean
Fix the gpiomux interface by:
- collapsing redundant abstractions into shared common ones
- disconnecting gpiomux abstractions from particular MSM implementations
- moving platform-specific details out of the common abstraction
- moving implementation complexity out of the interface and back into the implementation, where it should have been in the first place
- allowing for the future extension of the set of power states
- disambiguating 'settings' and 'configurations'.
- improving the initialization sequence to provide more flexibility
- not forcing lines to reset to input mode at power transitions
Your doing too much in too large a patch. Could you break this up into multiple patches?
Daniel
Signature · 3 lines
Sent by an consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.