aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-omap.c
diff options
context:
space:
mode:
authorTarun Kanti DebBarma <tarun.kanti@ti.com>2012-02-27 01:16:09 -0500
committerTarun Kanti DebBarma <tarun.kanti@ti.com>2012-03-21 00:51:24 -0400
commit7fcca715de3438b8fc3c8a144702f3a95c8ff63c (patch)
treeaef934198309bad7f0fca3a392e8360185d40e7d /drivers/gpio/gpio-omap.c
parent2a900eb74c123a21054836ab2c63d6ff46f854c6 (diff)
gpio/omap: fix redundant decoding of gpio offset
In gpio_get(), _get_gpio_datain() and _get_gpio_dataout() get rid of un-necessary operation to compute gpio mask. The gpio offset passed to gpio_get() is sufficient to do that. Here is Russell's original comment: Can someone explain to me this: static int _get_gpio_datain(struct gpio_bank *bank, int gpio) { void __iomem *reg = bank->base + bank->regs->datain; return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0; } static int gpio_get(struct gpio_chip *chip, unsigned offset) { struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); void __iomem *reg = bank->base; int gpio = chip->base + offset; u32 mask = GPIO_BIT(bank, gpio); if (gpio_is_input(bank, mask)) return _get_gpio_datain(bank, gpio); else return _get_gpio_dataout(bank, gpio); } Given that bank->width on OMAP is either 32 or 16, and GPIO numbers for any GPIO chip are always aligned to 32 or 16, why does this code bother adding the chips base gpio number and then modulo the width? Surely this means if - for argument sake - you registered a GPIO chip with 8 lines followed by one with 16 lines, GPIO0..7 would be chip 0 bit 0..7, GPIO8..15 would be chip 1 bit 8..15, GPIO16..23 would be chip 1 bit 0..7. However, if you registered a GPIO chip with 16 lines first, it would mean GPIO0..15 would be chip 0 bit 0..15, and GPIO16..31 would be chip 1 bit 0..15. Surely this kind of behaviour is not intended? Is there a reason why the bitmask can't just be (1 << offset) where offset is passed into these functions as GPIO number - chip->base ? Reported-by: Russell King - ARM Linux <linux@arm.linux.org.uk> Signed-off-by: Tarun Kanti DebBarma <tarun.kanti@ti.com> Reviewed-by: Santosh Shilimkar <santosh.shilimkar@ti.com> Reviewed-by: Kevin Hilman <khilman@ti.com> Signed-off-by: Kevin Hilman <khilman@ti.com>
Diffstat (limited to 'drivers/gpio/gpio-omap.c')
-rw-r--r--drivers/gpio/gpio-omap.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index 6c17e5812312..1adc2ec1e383 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -147,18 +147,18 @@ static void _set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, int enable)
147 bank->context.dataout = l; 147 bank->context.dataout = l;
148} 148}
149 149
150static int _get_gpio_datain(struct gpio_bank *bank, int gpio) 150static int _get_gpio_datain(struct gpio_bank *bank, int offset)
151{ 151{
152 void __iomem *reg = bank->base + bank->regs->datain; 152 void __iomem *reg = bank->base + bank->regs->datain;
153 153
154 return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0; 154 return (__raw_readl(reg) & (1 << offset)) != 0;
155} 155}
156 156
157static int _get_gpio_dataout(struct gpio_bank *bank, int gpio) 157static int _get_gpio_dataout(struct gpio_bank *bank, int offset)
158{ 158{
159 void __iomem *reg = bank->base + bank->regs->dataout; 159 void __iomem *reg = bank->base + bank->regs->dataout;
160 160
161 return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0; 161 return (__raw_readl(reg) & (1 << offset)) != 0;
162} 162}
163 163
164static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) 164static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
@@ -865,19 +865,15 @@ static int gpio_is_input(struct gpio_bank *bank, int mask)
865static int gpio_get(struct gpio_chip *chip, unsigned offset) 865static int gpio_get(struct gpio_chip *chip, unsigned offset)
866{ 866{
867 struct gpio_bank *bank; 867 struct gpio_bank *bank;
868 void __iomem *reg;
869 int gpio;
870 u32 mask; 868 u32 mask;
871 869
872 gpio = chip->base + offset;
873 bank = container_of(chip, struct gpio_bank, chip); 870 bank = container_of(chip, struct gpio_bank, chip);
874 reg = bank->base; 871 mask = (1 << offset);
875 mask = GPIO_BIT(bank, gpio);
876 872
877 if (gpio_is_input(bank, mask)) 873 if (gpio_is_input(bank, mask))
878 return _get_gpio_datain(bank, gpio); 874 return _get_gpio_datain(bank, offset);
879 else 875 else
880 return _get_gpio_dataout(bank, gpio); 876 return _get_gpio_dataout(bank, offset);
881} 877}
882 878
883static int gpio_output(struct gpio_chip *chip, unsigned offset, int value) 879static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)