diff options
author | Cyril Chemparathy <cyril@ti.com> | 2010-05-01 18:37:51 -0400 |
---|---|---|
committer | Kevin Hilman <khilman@deeprootsystems.com> | 2010-05-06 18:02:08 -0400 |
commit | ba4a984e838dfb1c46135ff8cadeea5f8ca5fd0a (patch) | |
tree | 1650621c7dbdfe8bcb3b9d9d2198715bc0d21043 /arch/arm | |
parent | 7a9978a1e2225507025a8b90b4289d506a416bd9 (diff) |
Davinci: gpio - minor cleanup
macroized repeated container_of()s to improve readability.
unified direction in/out functions.
Signed-off-by: Cyril Chemparathy <cyril@ti.com>
Tested-by: Sandeep Paulraj <s-paulraj@ti.com>
Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
Diffstat (limited to 'arch/arm')
-rw-r--r-- | arch/arm/mach-davinci/gpio.c | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/arch/arm/mach-davinci/gpio.c b/arch/arm/mach-davinci/gpio.c index 5476ad132044..93f7c686153a 100644 --- a/arch/arm/mach-davinci/gpio.c +++ b/arch/arm/mach-davinci/gpio.c | |||
@@ -28,6 +28,9 @@ struct davinci_gpio { | |||
28 | int irq_base; | 28 | int irq_base; |
29 | }; | 29 | }; |
30 | 30 | ||
31 | #define chip2controller(chip) \ | ||
32 | container_of(chip, struct davinci_gpio, chip) | ||
33 | |||
31 | static struct davinci_gpio chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)]; | 34 | static struct davinci_gpio chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)]; |
32 | 35 | ||
33 | /* create a non-inlined version */ | 36 | /* create a non-inlined version */ |
@@ -54,21 +57,39 @@ static int __init davinci_gpio_irq_setup(void); | |||
54 | * needed, and enable the GPIO clock. | 57 | * needed, and enable the GPIO clock. |
55 | */ | 58 | */ |
56 | 59 | ||
57 | static int davinci_direction_in(struct gpio_chip *chip, unsigned offset) | 60 | static inline int __davinci_direction(struct gpio_chip *chip, |
61 | unsigned offset, bool out, int value) | ||
58 | { | 62 | { |
59 | struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip); | 63 | struct davinci_gpio *d = chip2controller(chip); |
60 | struct gpio_controller __iomem *g = d->regs; | 64 | struct gpio_controller __iomem *g = d->regs; |
61 | u32 temp; | 65 | u32 temp; |
66 | u32 mask = 1 << offset; | ||
62 | 67 | ||
63 | spin_lock(&gpio_lock); | 68 | spin_lock(&gpio_lock); |
64 | temp = __raw_readl(&g->dir); | 69 | temp = __raw_readl(&g->dir); |
65 | temp |= (1 << offset); | 70 | if (out) { |
71 | temp &= ~mask; | ||
72 | __raw_writel(mask, value ? &g->set_data : &g->clr_data); | ||
73 | } else { | ||
74 | temp |= mask; | ||
75 | } | ||
66 | __raw_writel(temp, &g->dir); | 76 | __raw_writel(temp, &g->dir); |
67 | spin_unlock(&gpio_lock); | 77 | spin_unlock(&gpio_lock); |
68 | 78 | ||
69 | return 0; | 79 | return 0; |
70 | } | 80 | } |
71 | 81 | ||
82 | static int davinci_direction_in(struct gpio_chip *chip, unsigned offset) | ||
83 | { | ||
84 | return __davinci_direction(chip, offset, false, 0); | ||
85 | } | ||
86 | |||
87 | static int | ||
88 | davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value) | ||
89 | { | ||
90 | return __davinci_direction(chip, offset, true, value); | ||
91 | } | ||
92 | |||
72 | /* | 93 | /* |
73 | * Read the pin's value (works even if it's set up as output); | 94 | * Read the pin's value (works even if it's set up as output); |
74 | * returns zero/nonzero. | 95 | * returns zero/nonzero. |
@@ -78,36 +99,19 @@ static int davinci_direction_in(struct gpio_chip *chip, unsigned offset) | |||
78 | */ | 99 | */ |
79 | static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset) | 100 | static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset) |
80 | { | 101 | { |
81 | struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip); | 102 | struct davinci_gpio *d = chip2controller(chip); |
82 | struct gpio_controller __iomem *g = d->regs; | 103 | struct gpio_controller __iomem *g = d->regs; |
83 | 104 | ||
84 | return (1 << offset) & __raw_readl(&g->in_data); | 105 | return (1 << offset) & __raw_readl(&g->in_data); |
85 | } | 106 | } |
86 | 107 | ||
87 | static int | ||
88 | davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value) | ||
89 | { | ||
90 | struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip); | ||
91 | struct gpio_controller __iomem *g = d->regs; | ||
92 | u32 temp; | ||
93 | u32 mask = 1 << offset; | ||
94 | |||
95 | spin_lock(&gpio_lock); | ||
96 | temp = __raw_readl(&g->dir); | ||
97 | temp &= ~mask; | ||
98 | __raw_writel(mask, value ? &g->set_data : &g->clr_data); | ||
99 | __raw_writel(temp, &g->dir); | ||
100 | spin_unlock(&gpio_lock); | ||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | /* | 108 | /* |
105 | * Assuming the pin is muxed as a gpio output, set its output value. | 109 | * Assuming the pin is muxed as a gpio output, set its output value. |
106 | */ | 110 | */ |
107 | static void | 111 | static void |
108 | davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | 112 | davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
109 | { | 113 | { |
110 | struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip); | 114 | struct davinci_gpio *d = chip2controller(chip); |
111 | struct gpio_controller __iomem *g = d->regs; | 115 | struct gpio_controller __iomem *g = d->regs; |
112 | 116 | ||
113 | __raw_writel((1 << offset), value ? &g->set_data : &g->clr_data); | 117 | __raw_writel((1 << offset), value ? &g->set_data : &g->clr_data); |
@@ -262,7 +266,7 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc) | |||
262 | 266 | ||
263 | static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset) | 267 | static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset) |
264 | { | 268 | { |
265 | struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip); | 269 | struct davinci_gpio *d = chip2controller(chip); |
266 | 270 | ||
267 | if (d->irq_base >= 0) | 271 | if (d->irq_base >= 0) |
268 | return d->irq_base + offset; | 272 | return d->irq_base + offset; |