aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-sx150x.c
diff options
context:
space:
mode:
authorWei Chen <Wei.Chen@csr.com>2014-12-04 07:12:08 -0500
committerLinus Walleij <linus.walleij@linaro.org>2015-01-15 11:23:12 -0500
commit093e9435483c8ad630a1432bfdcc10efe1c08a64 (patch)
tree41bb517ce7389f15668a42b6786af984b41ab366 /drivers/gpio/gpio-sx150x.c
parent3c01b9a896c9c592d9edc7439d5e5cf6c411d014 (diff)
gpio: sx150x: move to irqdomain framework for sx150x driver
The sx150x gpio driver used a loop to set liner irq map for gpio pins. Now we use the irq domain to rebuild this irq mappig and make sure the codes are still compatible to old users. this patch also adds IRQF_ONESHOT flag to fix the IRQ flooding issues. Signed-off-by: Wei Chen <Wei.Chen@csr.com> Signed-off-by: Barry Song <Baohua.Song@csr.com> [Make Kconfig select GPIOLIB_IRQCHIP] Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-sx150x.c')
-rw-r--r--drivers/gpio/gpio-sx150x.c72
1 files changed, 18 insertions, 54 deletions
diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index bce6c6108f20..0bc61c2bd079 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -293,27 +293,11 @@ static int sx150x_gpio_direction_output(struct gpio_chip *gc,
293 return status; 293 return status;
294} 294}
295 295
296static int sx150x_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
297{
298 struct sx150x_chip *chip;
299
300 chip = container_of(gc, struct sx150x_chip, gpio_chip);
301
302 if (offset >= chip->dev_cfg->ngpios)
303 return -EINVAL;
304
305 if (chip->irq_base < 0)
306 return -EINVAL;
307
308 return chip->irq_base + offset;
309}
310
311static void sx150x_irq_mask(struct irq_data *d) 296static void sx150x_irq_mask(struct irq_data *d)
312{ 297{
313 struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 298 struct sx150x_chip *chip = irq_data_get_irq_chip_data(d);
314 unsigned n; 299 unsigned n = d->hwirq;
315 300
316 n = d->irq - chip->irq_base;
317 chip->irq_masked |= (1 << n); 301 chip->irq_masked |= (1 << n);
318 chip->irq_update = n; 302 chip->irq_update = n;
319} 303}
@@ -321,9 +305,8 @@ static void sx150x_irq_mask(struct irq_data *d)
321static void sx150x_irq_unmask(struct irq_data *d) 305static void sx150x_irq_unmask(struct irq_data *d)
322{ 306{
323 struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 307 struct sx150x_chip *chip = irq_data_get_irq_chip_data(d);
324 unsigned n; 308 unsigned n = d->hwirq;
325 309
326 n = d->irq - chip->irq_base;
327 chip->irq_masked &= ~(1 << n); 310 chip->irq_masked &= ~(1 << n);
328 chip->irq_update = n; 311 chip->irq_update = n;
329} 312}
@@ -336,7 +319,7 @@ static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type)
336 if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) 319 if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
337 return -EINVAL; 320 return -EINVAL;
338 321
339 n = d->irq - chip->irq_base; 322 n = d->hwirq;
340 323
341 if (flow_type & IRQ_TYPE_EDGE_RISING) 324 if (flow_type & IRQ_TYPE_EDGE_RISING)
342 val |= 0x1; 325 val |= 0x1;
@@ -371,7 +354,9 @@ static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id)
371 val); 354 val);
372 for (n = 0; n < 8; ++n) { 355 for (n = 0; n < 8; ++n) {
373 if (val & (1 << n)) { 356 if (val & (1 << n)) {
374 sub_irq = chip->irq_base + (i * 8) + n; 357 sub_irq = irq_find_mapping(
358 chip->gpio_chip.irqdomain,
359 (i * 8) + n);
375 handle_nested_irq(sub_irq); 360 handle_nested_irq(sub_irq);
376 ++nhandled; 361 ++nhandled;
377 } 362 }
@@ -428,12 +413,12 @@ static void sx150x_init_chip(struct sx150x_chip *chip,
428 413
429 chip->client = client; 414 chip->client = client;
430 chip->dev_cfg = &sx150x_devices[driver_data]; 415 chip->dev_cfg = &sx150x_devices[driver_data];
416 chip->gpio_chip.dev = &client->dev;
431 chip->gpio_chip.label = client->name; 417 chip->gpio_chip.label = client->name;
432 chip->gpio_chip.direction_input = sx150x_gpio_direction_input; 418 chip->gpio_chip.direction_input = sx150x_gpio_direction_input;
433 chip->gpio_chip.direction_output = sx150x_gpio_direction_output; 419 chip->gpio_chip.direction_output = sx150x_gpio_direction_output;
434 chip->gpio_chip.get = sx150x_gpio_get; 420 chip->gpio_chip.get = sx150x_gpio_get;
435 chip->gpio_chip.set = sx150x_gpio_set; 421 chip->gpio_chip.set = sx150x_gpio_set;
436 chip->gpio_chip.to_irq = sx150x_gpio_to_irq;
437 chip->gpio_chip.base = pdata->gpio_base; 422 chip->gpio_chip.base = pdata->gpio_base;
438 chip->gpio_chip.can_sleep = true; 423 chip->gpio_chip.can_sleep = true;
439 chip->gpio_chip.ngpio = chip->dev_cfg->ngpios; 424 chip->gpio_chip.ngpio = chip->dev_cfg->ngpios;
@@ -529,31 +514,24 @@ static int sx150x_install_irq_chip(struct sx150x_chip *chip,
529 int irq_base) 514 int irq_base)
530{ 515{
531 int err; 516 int err;
532 unsigned n;
533 unsigned irq;
534 517
535 chip->irq_summary = irq_summary; 518 chip->irq_summary = irq_summary;
536 chip->irq_base = irq_base; 519 chip->irq_base = irq_base;
537 520
538 for (n = 0; n < chip->dev_cfg->ngpios; ++n) { 521 /* Add gpio chip to irq subsystem */
539 irq = irq_base + n; 522 err = gpiochip_irqchip_add(&chip->gpio_chip,
540 irq_set_chip_data(irq, chip); 523 &chip->irq_chip, chip->irq_base,
541 irq_set_chip_and_handler(irq, &chip->irq_chip, handle_edge_irq); 524 handle_edge_irq, IRQ_TYPE_EDGE_BOTH);
542 irq_set_nested_thread(irq, 1); 525 if (err) {
543#ifdef CONFIG_ARM 526 dev_err(&chip->client->dev,
544 set_irq_flags(irq, IRQF_VALID); 527 "could not connect irqchip to gpiochip\n");
545#else 528 return err;
546 irq_set_noprobe(irq);
547#endif
548 } 529 }
549 530
550 err = devm_request_threaded_irq(&chip->client->dev, 531 err = devm_request_threaded_irq(&chip->client->dev,
551 irq_summary, 532 irq_summary, NULL, sx150x_irq_thread_fn,
552 NULL, 533 IRQF_ONESHOT | IRQF_SHARED | IRQF_TRIGGER_FALLING,
553 sx150x_irq_thread_fn, 534 chip->irq_chip.name, chip);
554 IRQF_SHARED | IRQF_TRIGGER_FALLING,
555 chip->irq_chip.name,
556 chip);
557 if (err < 0) { 535 if (err < 0) {
558 chip->irq_summary = -1; 536 chip->irq_summary = -1;
559 chip->irq_base = -1; 537 chip->irq_base = -1;
@@ -562,17 +540,6 @@ static int sx150x_install_irq_chip(struct sx150x_chip *chip,
562 return err; 540 return err;
563} 541}
564 542
565static void sx150x_remove_irq_chip(struct sx150x_chip *chip)
566{
567 unsigned n;
568 unsigned irq;
569
570 for (n = 0; n < chip->dev_cfg->ngpios; ++n) {
571 irq = chip->irq_base + n;
572 irq_set_chip_and_handler(irq, NULL, NULL);
573 }
574}
575
576static int sx150x_probe(struct i2c_client *client, 543static int sx150x_probe(struct i2c_client *client,
577 const struct i2c_device_id *id) 544 const struct i2c_device_id *id)
578{ 545{
@@ -626,9 +593,6 @@ static int sx150x_remove(struct i2c_client *client)
626 chip = i2c_get_clientdata(client); 593 chip = i2c_get_clientdata(client);
627 gpiochip_remove(&chip->gpio_chip); 594 gpiochip_remove(&chip->gpio_chip);
628 595
629 if (chip->irq_summary >= 0)
630 sx150x_remove_irq_chip(chip);
631
632 return 0; 596 return 0;
633} 597}
634 598