aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-vf610.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2015-08-27 08:13:46 -0400
committerLinus Walleij <linus.walleij@linaro.org>2015-10-02 07:19:32 -0400
commit2f930643c581f3fe45568f24a8aba93af46ff287 (patch)
tree8a10413474e997199675b039a0ba92d82495b0bd /drivers/gpio/gpio-vf610.c
parent218f1f8b50aef5438fd95a4e3d64549bf9c459c3 (diff)
gpio: vf610: use container_of() to get state container
The state container of the vf610 GPIO driver is sometimes extracted from the gpio_chip exploiting the fact that offsetof() the struct gpio_chip inside the struct vf610_gpio_port is 0, so the container_of() is in practice a noop. However if a member is added to struct vf610_gpio_port in front of struct gpio_chip, things will break. Using proper container_of() avoids this problem. Semantically this is a noop, the compiler will optimize it away, but syntactically it makes me happier. Also replace some explicit container_of() calls with the helper function. Acked-by: Stefan Agner <stefan@agner.ch> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-vf610.c')
-rw-r--r--drivers/gpio/gpio-vf610.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 069f9e4b7daa..e1a397121729 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -62,6 +62,11 @@ struct vf610_gpio_port {
62 62
63static struct irq_chip vf610_gpio_irq_chip; 63static struct irq_chip vf610_gpio_irq_chip;
64 64
65static struct vf610_gpio_port *to_vf610_gp(struct gpio_chip *gc)
66{
67 return container_of(gc, struct vf610_gpio_port, gc);
68}
69
65static const struct of_device_id vf610_gpio_dt_ids[] = { 70static const struct of_device_id vf610_gpio_dt_ids[] = {
66 { .compatible = "fsl,vf610-gpio" }, 71 { .compatible = "fsl,vf610-gpio" },
67 { /* sentinel */ } 72 { /* sentinel */ }
@@ -89,16 +94,14 @@ static void vf610_gpio_free(struct gpio_chip *chip, unsigned offset)
89 94
90static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio) 95static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio)
91{ 96{
92 struct vf610_gpio_port *port = 97 struct vf610_gpio_port *port = to_vf610_gp(gc);
93 container_of(gc, struct vf610_gpio_port, gc);
94 98
95 return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR) & BIT(gpio)); 99 return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR) & BIT(gpio));
96} 100}
97 101
98static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 102static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
99{ 103{
100 struct vf610_gpio_port *port = 104 struct vf610_gpio_port *port = to_vf610_gp(gc);
101 container_of(gc, struct vf610_gpio_port, gc);
102 unsigned long mask = BIT(gpio); 105 unsigned long mask = BIT(gpio);
103 106
104 if (val) 107 if (val)
@@ -122,7 +125,8 @@ static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
122 125
123static void vf610_gpio_irq_handler(struct irq_desc *desc) 126static void vf610_gpio_irq_handler(struct irq_desc *desc)
124{ 127{
125 struct vf610_gpio_port *port = irq_desc_get_handler_data(desc); 128 struct vf610_gpio_port *port =
129 to_vf610_gp(irq_desc_get_handler_data(desc));
126 struct irq_chip *chip = irq_desc_get_chip(desc); 130 struct irq_chip *chip = irq_desc_get_chip(desc);
127 int pin; 131 int pin;
128 unsigned long irq_isfr; 132 unsigned long irq_isfr;
@@ -142,7 +146,8 @@ static void vf610_gpio_irq_handler(struct irq_desc *desc)
142 146
143static void vf610_gpio_irq_ack(struct irq_data *d) 147static void vf610_gpio_irq_ack(struct irq_data *d)
144{ 148{
145 struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 149 struct vf610_gpio_port *port =
150 to_vf610_gp(irq_data_get_irq_chip_data(d));
146 int gpio = d->hwirq; 151 int gpio = d->hwirq;
147 152
148 vf610_gpio_writel(BIT(gpio), port->base + PORT_ISFR); 153 vf610_gpio_writel(BIT(gpio), port->base + PORT_ISFR);
@@ -150,7 +155,8 @@ static void vf610_gpio_irq_ack(struct irq_data *d)
150 155
151static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type) 156static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type)
152{ 157{
153 struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 158 struct vf610_gpio_port *port =
159 to_vf610_gp(irq_data_get_irq_chip_data(d));
154 u8 irqc; 160 u8 irqc;
155 161
156 switch (type) { 162 switch (type) {
@@ -185,7 +191,8 @@ static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type)
185 191
186static void vf610_gpio_irq_mask(struct irq_data *d) 192static void vf610_gpio_irq_mask(struct irq_data *d)
187{ 193{
188 struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 194 struct vf610_gpio_port *port =
195 to_vf610_gp(irq_data_get_irq_chip_data(d));
189 void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); 196 void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
190 197
191 vf610_gpio_writel(0, pcr_base); 198 vf610_gpio_writel(0, pcr_base);
@@ -193,7 +200,8 @@ static void vf610_gpio_irq_mask(struct irq_data *d)
193 200
194static void vf610_gpio_irq_unmask(struct irq_data *d) 201static void vf610_gpio_irq_unmask(struct irq_data *d)
195{ 202{
196 struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 203 struct vf610_gpio_port *port =
204 to_vf610_gp(irq_data_get_irq_chip_data(d));
197 void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); 205 void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
198 206
199 vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET, 207 vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET,
@@ -202,7 +210,8 @@ static void vf610_gpio_irq_unmask(struct irq_data *d)
202 210
203static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable) 211static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
204{ 212{
205 struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 213 struct vf610_gpio_port *port =
214 to_vf610_gp(irq_data_get_irq_chip_data(d));
206 215
207 if (enable) 216 if (enable)
208 enable_irq_wake(port->irq); 217 enable_irq_wake(port->irq);