aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-etraxfs.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2015-12-04 08:02:58 -0500
committerLinus Walleij <linus.walleij@linaro.org>2016-01-05 05:21:00 -0500
commit0f4630f3720e7e6e921bf525c8357fea7ef3dbab (patch)
tree61c1904593d1ee424464c2d57668ba0fd2fbcbb4 /drivers/gpio/gpio-etraxfs.c
parent3208b0f0c010b26e4d461a3bca59989d03ed9087 (diff)
gpio: generic: factor into gpio_chip struct
The separate struct bgpio_chip has been a pain to handle, both by being confusingly similar in name to struct gpio_chip and for being contained inside a struct so that struct gpio_chip is contained in a struct contained in a struct, making several steps of dereferencing necessary. Make things simpler: include the fields directly into <linux/gpio/driver.h>, #ifdef:ed for CONFIG_GENERIC_GPIO, and get rid of the <linux/basic_mmio_gpio.h> altogether. Prefix some of the member variables with bgpio_* and add proper kerneldoc while we're at it. Modify all users to handle the change and use a struct gpio_chip directly. And while we're at it: replace all container_of() dereferencing by gpiochip_get_data() and registering the gpio_chip with gpiochip_add_data(). Cc: arm@kernel.org Cc: Alexander Shiyan <shc_work@mail.ru> Cc: Shawn Guo <shawnguo@kernel.org> Cc: Sascha Hauer <kernel@pengutronix.de> Cc: Kukjin Kim <kgene@kernel.org> Cc: Alexandre Courbot <gnurou@gmail.com> Cc: Brian Norris <computersforpeace@gmail.com> Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: Sudeep Holla <sudeep.holla@arm.com> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Cc: Nicolas Pitre <nicolas.pitre@linaro.org> Cc: Olof Johansson <olof@lixom.net> Cc: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com> Cc: Rabin Vincent <rabin@rab.in> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-omap@vger.kernel.org Cc: linux-samsung-soc@vger.kernel.org Cc: bcm-kernel-feedback-list@broadcom.com Acked-by: Gregory Fong <gregory.0xf0@gmail.com> Acked-by: Liviu Dudau <Liviu.Dudau@arm.com> Acked-by: H Hartley Sweeten <hsweeten@visionengravers.com> Acked-by: Tony Lindgren <tony@atomide.com> Acked-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Acked-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-etraxfs.c')
-rw-r--r--drivers/gpio/gpio-etraxfs.c49
1 files changed, 21 insertions, 28 deletions
diff --git a/drivers/gpio/gpio-etraxfs.c b/drivers/gpio/gpio-etraxfs.c
index 5c15dd12172d..00b022c9acb3 100644
--- a/drivers/gpio/gpio-etraxfs.c
+++ b/drivers/gpio/gpio-etraxfs.c
@@ -1,12 +1,10 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/init.h> 2#include <linux/init.h>
3#include <linux/gpio.h>
4#include <linux/gpio/driver.h> 3#include <linux/gpio/driver.h>
5#include <linux/of_gpio.h> 4#include <linux/of_gpio.h>
6#include <linux/io.h> 5#include <linux/io.h>
7#include <linux/interrupt.h> 6#include <linux/interrupt.h>
8#include <linux/platform_device.h> 7#include <linux/platform_device.h>
9#include <linux/basic_mmio_gpio.h>
10 8
11#define ETRAX_FS_rw_pa_dout 0 9#define ETRAX_FS_rw_pa_dout 0
12#define ETRAX_FS_r_pa_din 4 10#define ETRAX_FS_r_pa_din 4
@@ -67,7 +65,7 @@ struct etraxfs_gpio_block {
67}; 65};
68 66
69struct etraxfs_gpio_chip { 67struct etraxfs_gpio_chip {
70 struct bgpio_chip bgc; 68 struct gpio_chip gc;
71 struct etraxfs_gpio_block *block; 69 struct etraxfs_gpio_block *block;
72}; 70};
73 71
@@ -176,11 +174,6 @@ static const struct etraxfs_gpio_info etraxfs_gpio_artpec3 = {
176 .rw_intr_pins = ARTPEC3_rw_intr_pins, 174 .rw_intr_pins = ARTPEC3_rw_intr_pins,
177}; 175};
178 176
179static struct etraxfs_gpio_chip *to_etraxfs(struct gpio_chip *gc)
180{
181 return container_of(gc, struct etraxfs_gpio_chip, bgc.gc);
182}
183
184static unsigned int etraxfs_gpio_chip_to_port(struct gpio_chip *gc) 177static unsigned int etraxfs_gpio_chip_to_port(struct gpio_chip *gc)
185{ 178{
186 return gc->label[0] - 'A'; 179 return gc->label[0] - 'A';
@@ -220,13 +213,13 @@ static unsigned int etraxfs_gpio_to_group_irq(unsigned int gpio)
220static unsigned int etraxfs_gpio_to_group_pin(struct etraxfs_gpio_chip *chip, 213static unsigned int etraxfs_gpio_to_group_pin(struct etraxfs_gpio_chip *chip,
221 unsigned int gpio) 214 unsigned int gpio)
222{ 215{
223 return 4 * etraxfs_gpio_chip_to_port(&chip->bgc.gc) + gpio / 8; 216 return 4 * etraxfs_gpio_chip_to_port(&chip->gc) + gpio / 8;
224} 217}
225 218
226static void etraxfs_gpio_irq_ack(struct irq_data *d) 219static void etraxfs_gpio_irq_ack(struct irq_data *d)
227{ 220{
228 struct etraxfs_gpio_chip *chip = 221 struct etraxfs_gpio_chip *chip =
229 to_etraxfs(irq_data_get_irq_chip_data(d)); 222 gpiochip_get_data(irq_data_get_irq_chip_data(d));
230 struct etraxfs_gpio_block *block = chip->block; 223 struct etraxfs_gpio_block *block = chip->block;
231 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 224 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
232 225
@@ -236,7 +229,7 @@ static void etraxfs_gpio_irq_ack(struct irq_data *d)
236static void etraxfs_gpio_irq_mask(struct irq_data *d) 229static void etraxfs_gpio_irq_mask(struct irq_data *d)
237{ 230{
238 struct etraxfs_gpio_chip *chip = 231 struct etraxfs_gpio_chip *chip =
239 to_etraxfs(irq_data_get_irq_chip_data(d)); 232 gpiochip_get_data(irq_data_get_irq_chip_data(d));
240 struct etraxfs_gpio_block *block = chip->block; 233 struct etraxfs_gpio_block *block = chip->block;
241 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 234 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
242 235
@@ -249,7 +242,7 @@ static void etraxfs_gpio_irq_mask(struct irq_data *d)
249static void etraxfs_gpio_irq_unmask(struct irq_data *d) 242static void etraxfs_gpio_irq_unmask(struct irq_data *d)
250{ 243{
251 struct etraxfs_gpio_chip *chip = 244 struct etraxfs_gpio_chip *chip =
252 to_etraxfs(irq_data_get_irq_chip_data(d)); 245 gpiochip_get_data(irq_data_get_irq_chip_data(d));
253 struct etraxfs_gpio_block *block = chip->block; 246 struct etraxfs_gpio_block *block = chip->block;
254 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 247 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
255 248
@@ -262,7 +255,7 @@ static void etraxfs_gpio_irq_unmask(struct irq_data *d)
262static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type) 255static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type)
263{ 256{
264 struct etraxfs_gpio_chip *chip = 257 struct etraxfs_gpio_chip *chip =
265 to_etraxfs(irq_data_get_irq_chip_data(d)); 258 gpiochip_get_data(irq_data_get_irq_chip_data(d));
266 struct etraxfs_gpio_block *block = chip->block; 259 struct etraxfs_gpio_block *block = chip->block;
267 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 260 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
268 u32 cfg; 261 u32 cfg;
@@ -299,7 +292,7 @@ static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type)
299static int etraxfs_gpio_irq_request_resources(struct irq_data *d) 292static int etraxfs_gpio_irq_request_resources(struct irq_data *d)
300{ 293{
301 struct etraxfs_gpio_chip *chip = 294 struct etraxfs_gpio_chip *chip =
302 to_etraxfs(irq_data_get_irq_chip_data(d)); 295 gpiochip_get_data(irq_data_get_irq_chip_data(d));
303 struct etraxfs_gpio_block *block = chip->block; 296 struct etraxfs_gpio_block *block = chip->block;
304 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 297 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
305 int ret = -EBUSY; 298 int ret = -EBUSY;
@@ -308,7 +301,7 @@ static int etraxfs_gpio_irq_request_resources(struct irq_data *d)
308 if (block->group[grpirq]) 301 if (block->group[grpirq])
309 goto out; 302 goto out;
310 303
311 ret = gpiochip_lock_as_irq(&chip->bgc.gc, d->hwirq); 304 ret = gpiochip_lock_as_irq(&chip->gc, d->hwirq);
312 if (ret) 305 if (ret)
313 goto out; 306 goto out;
314 307
@@ -330,13 +323,13 @@ out:
330static void etraxfs_gpio_irq_release_resources(struct irq_data *d) 323static void etraxfs_gpio_irq_release_resources(struct irq_data *d)
331{ 324{
332 struct etraxfs_gpio_chip *chip = 325 struct etraxfs_gpio_chip *chip =
333 to_etraxfs(irq_data_get_irq_chip_data(d)); 326 gpiochip_get_data(irq_data_get_irq_chip_data(d));
334 struct etraxfs_gpio_block *block = chip->block; 327 struct etraxfs_gpio_block *block = chip->block;
335 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 328 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
336 329
337 spin_lock(&block->lock); 330 spin_lock(&block->lock);
338 block->group[grpirq] = 0; 331 block->group[grpirq] = 0;
339 gpiochip_unlock_as_irq(&chip->bgc.gc, d->hwirq); 332 gpiochip_unlock_as_irq(&chip->gc, d->hwirq);
340 spin_unlock(&block->lock); 333 spin_unlock(&block->lock);
341} 334}
342 335
@@ -419,7 +412,7 @@ static int etraxfs_gpio_probe(struct platform_device *pdev)
419 412
420 for (i = 0; i < info->num_ports; i++) { 413 for (i = 0; i < info->num_ports; i++) {
421 struct etraxfs_gpio_chip *chip = &chips[i]; 414 struct etraxfs_gpio_chip *chip = &chips[i];
422 struct bgpio_chip *bgc = &chip->bgc; 415 struct gpio_chip *gc = &chip->gc;
423 const struct etraxfs_gpio_port *port = &info->ports[i]; 416 const struct etraxfs_gpio_port *port = &info->ports[i];
424 unsigned long flags = BGPIOF_READ_OUTPUT_REG_SET; 417 unsigned long flags = BGPIOF_READ_OUTPUT_REG_SET;
425 void __iomem *dat = regs + port->din; 418 void __iomem *dat = regs + port->din;
@@ -433,7 +426,7 @@ static int etraxfs_gpio_probe(struct platform_device *pdev)
433 flags = BGPIOF_NO_OUTPUT; 426 flags = BGPIOF_NO_OUTPUT;
434 } 427 }
435 428
436 ret = bgpio_init(bgc, dev, 4, 429 ret = bgpio_init(gc, dev, 4,
437 dat, set, NULL, dirout, NULL, 430 dat, set, NULL, dirout, NULL,
438 flags); 431 flags);
439 if (ret) { 432 if (ret) {
@@ -442,28 +435,28 @@ static int etraxfs_gpio_probe(struct platform_device *pdev)
442 continue; 435 continue;
443 } 436 }
444 437
445 bgc->gc.ngpio = port->ngpio; 438 gc->ngpio = port->ngpio;
446 bgc->gc.label = port->label; 439 gc->label = port->label;
447 440
448 bgc->gc.of_node = dev->of_node; 441 gc->of_node = dev->of_node;
449 bgc->gc.of_gpio_n_cells = 3; 442 gc->of_gpio_n_cells = 3;
450 bgc->gc.of_xlate = etraxfs_gpio_of_xlate; 443 gc->of_xlate = etraxfs_gpio_of_xlate;
451 444
452 ret = gpiochip_add(&bgc->gc); 445 ret = gpiochip_add_data(gc, chip);
453 if (ret) { 446 if (ret) {
454 dev_err(dev, "Unable to register port %s\n", 447 dev_err(dev, "Unable to register port %s\n",
455 bgc->gc.label); 448 gc->label);
456 continue; 449 continue;
457 } 450 }
458 451
459 if (i > 0 && !allportsirq) 452 if (i > 0 && !allportsirq)
460 continue; 453 continue;
461 454
462 ret = gpiochip_irqchip_add(&bgc->gc, &etraxfs_gpio_irq_chip, 0, 455 ret = gpiochip_irqchip_add(gc, &etraxfs_gpio_irq_chip, 0,
463 handle_level_irq, IRQ_TYPE_NONE); 456 handle_level_irq, IRQ_TYPE_NONE);
464 if (ret) { 457 if (ret) {
465 dev_err(dev, "Unable to add irqchip to port %s\n", 458 dev_err(dev, "Unable to add irqchip to port %s\n",
466 bgc->gc.label); 459 gc->label);
467 } 460 }
468 } 461 }
469 462