Hello.
Cyril Chemparathy wrote:
macroized repeated container_of()s to improve readability.
unified direction in/out functions.
Signed-off-by: Cyril Chemparathy <cy...@ti.com>
Tested-by: Sandeep Paulraj <s-paul...@ti.com>
---
arch/arm/mach-davinci/gpio.c | 47 +++++++++++++++++++++--------------------
1 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/arch/arm/mach-davinci/gpio.c b/arch/arm/mach-davinci/gpio.c
index 5476ad1..bb55f41 100644
--- a/arch/arm/mach-davinci/gpio.c
+++ b/arch/arm/mach-davinci/gpio.c
[...]
@@ -54,21 +57,36 @@ static int __init davinci_gpio_irq_setup(void);
* needed, and enable the GPIO clock.
*/
-static int davinci_direction_in(struct gpio_chip *chip, unsigned offset)
+static inline int __davinci_direction(struct gpio_chip *chip,
+ unsigned offset, bool out)
{
- struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip);
+ struct davinci_gpio *d = chip2controller(chip);
struct gpio_controller __iomem *g = d->regs;
u32 temp;
spin_lock(&gpio_lock);
temp = __raw_readl(&g->dir);
- temp |= (1 << offset);
+ if (out)
+ temp &= ~(1 << offset);
+ else
+ temp |= (1 << offset);
__raw_writel(temp, &g->dir);
spin_unlock(&gpio_lock);
return 0;
}
+static int davinci_direction_in(struct gpio_chip *chip, unsigned offset)
+{
+ return __davinci_direction(chip, offset, false);
+}
+
+static int
+davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value)
+{
+ return __davinci_direction(chip, offset, true);
No, this ignores 'value'. The function should also program GPIO to
the value specified.
@@ -78,36 +96,19 @@ static int davinci_direction_in(struct gpio_chip *chip,
unsigned offset)
*/
static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset)
{
- struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip);
+ struct davinci_gpio *d = chip2controller(chip);
struct gpio_controller __iomem *g = d->regs;
return (1 << offset) & __raw_readl(&g->in_data);
}
-static int
-davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value)
-{
- struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip);
- struct gpio_controller __iomem *g = d->regs;
- u32 temp;
- u32 mask = 1 << offset;
-
- spin_lock(&gpio_lock);
- temp = __raw_readl(&g->dir);
- temp &= ~mask;
- __raw_writel(mask, value ? &g->set_data : &g->clr_data);
Here's what you've forgotten...
- __raw_writel(temp, &g->dir);
- spin_unlock(&gpio_lock);
- return 0;
-}
-
WBR, Sergei
_______________________________________________
Davinci-linux-open-source mailing list
Davinci-linux-open-source@linux.davincidsp.com
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source