.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) ST-Ericsson SA 2010 |
---|
3 | 4 | * |
---|
4 | | - * License Terms: GNU General Public License, version 2 |
---|
5 | 5 | * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson |
---|
6 | 6 | */ |
---|
7 | 7 | |
---|
.. | .. |
---|
84 | 84 | if (ret < 0) |
---|
85 | 85 | return ret; |
---|
86 | 86 | |
---|
87 | | - return !(ret & mask); |
---|
| 87 | + if (ret & mask) |
---|
| 88 | + return GPIO_LINE_DIRECTION_OUT; |
---|
| 89 | + |
---|
| 90 | + return GPIO_LINE_DIRECTION_IN; |
---|
88 | 91 | } |
---|
89 | 92 | |
---|
90 | 93 | static int stmpe_gpio_direction_output(struct gpio_chip *chip, |
---|
.. | .. |
---|
305 | 308 | if (ret < 0) |
---|
306 | 309 | return; |
---|
307 | 310 | edge_det = !!(ret & mask); |
---|
308 | | - /* fall through */ |
---|
| 311 | + fallthrough; |
---|
309 | 312 | case STMPE1801: |
---|
310 | 313 | rise_reg = stmpe->regs[STMPE_IDX_GPRER_LSB + bank]; |
---|
311 | 314 | fall_reg = stmpe->regs[STMPE_IDX_GPFER_LSB + bank]; |
---|
.. | .. |
---|
318 | 321 | if (ret < 0) |
---|
319 | 322 | return; |
---|
320 | 323 | fall = !!(ret & mask); |
---|
321 | | - /* fall through */ |
---|
| 324 | + fallthrough; |
---|
322 | 325 | case STMPE801: |
---|
323 | 326 | case STMPE1600: |
---|
324 | 327 | irqen_reg = stmpe->regs[STMPE_IDX_IEGPIOR_LSB + bank]; |
---|
.. | .. |
---|
429 | 432 | return IRQ_HANDLED; |
---|
430 | 433 | } |
---|
431 | 434 | |
---|
| 435 | +static void stmpe_init_irq_valid_mask(struct gpio_chip *gc, |
---|
| 436 | + unsigned long *valid_mask, |
---|
| 437 | + unsigned int ngpios) |
---|
| 438 | +{ |
---|
| 439 | + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(gc); |
---|
| 440 | + int i; |
---|
| 441 | + |
---|
| 442 | + if (!stmpe_gpio->norequest_mask) |
---|
| 443 | + return; |
---|
| 444 | + |
---|
| 445 | + /* Forbid unused lines to be mapped as IRQs */ |
---|
| 446 | + for (i = 0; i < sizeof(u32); i++) { |
---|
| 447 | + if (stmpe_gpio->norequest_mask & BIT(i)) |
---|
| 448 | + clear_bit(i, valid_mask); |
---|
| 449 | + } |
---|
| 450 | +} |
---|
| 451 | + |
---|
432 | 452 | static int stmpe_gpio_probe(struct platform_device *pdev) |
---|
433 | 453 | { |
---|
434 | 454 | struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); |
---|
.. | .. |
---|
454 | 474 | stmpe_gpio->chip.parent = &pdev->dev; |
---|
455 | 475 | stmpe_gpio->chip.of_node = np; |
---|
456 | 476 | stmpe_gpio->chip.base = -1; |
---|
| 477 | + /* |
---|
| 478 | + * REVISIT: this makes sure the valid mask gets allocated and |
---|
| 479 | + * filled in when adding the gpio_chip, but the rest of the |
---|
| 480 | + * gpio_irqchip is still filled in using the old method |
---|
| 481 | + * in gpiochip_irqchip_add_nested() so clean this up once we |
---|
| 482 | + * get the gpio_irqchip to initialize while adding the |
---|
| 483 | + * gpio_chip also for threaded irqchips. |
---|
| 484 | + */ |
---|
| 485 | + stmpe_gpio->chip.irq.init_valid_mask = stmpe_init_irq_valid_mask; |
---|
457 | 486 | |
---|
458 | 487 | if (IS_ENABLED(CONFIG_DEBUG_FS)) |
---|
459 | 488 | stmpe_gpio->chip.dbg_show = stmpe_dbg_show; |
---|
460 | 489 | |
---|
461 | 490 | of_property_read_u32(np, "st,norequest-mask", |
---|
462 | 491 | &stmpe_gpio->norequest_mask); |
---|
463 | | - if (stmpe_gpio->norequest_mask) |
---|
464 | | - stmpe_gpio->chip.irq.need_valid_mask = true; |
---|
465 | 492 | |
---|
466 | 493 | irq = platform_get_irq(pdev, 0); |
---|
467 | 494 | if (irq < 0) |
---|
.. | .. |
---|
473 | 500 | if (ret) |
---|
474 | 501 | goto out_free; |
---|
475 | 502 | |
---|
476 | | - ret = gpiochip_add_data(&stmpe_gpio->chip, stmpe_gpio); |
---|
477 | | - if (ret) { |
---|
478 | | - dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); |
---|
479 | | - goto out_disable; |
---|
480 | | - } |
---|
481 | | - |
---|
482 | 503 | if (irq > 0) { |
---|
| 504 | + struct gpio_irq_chip *girq; |
---|
| 505 | + |
---|
483 | 506 | ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, |
---|
484 | 507 | stmpe_gpio_irq, IRQF_ONESHOT, |
---|
485 | 508 | "stmpe-gpio", stmpe_gpio); |
---|
.. | .. |
---|
487 | 510 | dev_err(&pdev->dev, "unable to get irq: %d\n", ret); |
---|
488 | 511 | goto out_disable; |
---|
489 | 512 | } |
---|
490 | | - if (stmpe_gpio->norequest_mask) { |
---|
491 | | - int i; |
---|
492 | 513 | |
---|
493 | | - /* Forbid unused lines to be mapped as IRQs */ |
---|
494 | | - for (i = 0; i < sizeof(u32); i++) |
---|
495 | | - if (stmpe_gpio->norequest_mask & BIT(i)) |
---|
496 | | - clear_bit(i, stmpe_gpio->chip.irq.valid_mask); |
---|
497 | | - } |
---|
498 | | - ret = gpiochip_irqchip_add_nested(&stmpe_gpio->chip, |
---|
499 | | - &stmpe_gpio_irq_chip, |
---|
500 | | - 0, |
---|
501 | | - handle_simple_irq, |
---|
502 | | - IRQ_TYPE_NONE); |
---|
503 | | - if (ret) { |
---|
504 | | - dev_err(&pdev->dev, |
---|
505 | | - "could not connect irqchip to gpiochip\n"); |
---|
506 | | - goto out_disable; |
---|
507 | | - } |
---|
| 514 | + girq = &stmpe_gpio->chip.irq; |
---|
| 515 | + girq->chip = &stmpe_gpio_irq_chip; |
---|
| 516 | + /* This will let us handle the parent IRQ in the driver */ |
---|
| 517 | + girq->parent_handler = NULL; |
---|
| 518 | + girq->num_parents = 0; |
---|
| 519 | + girq->parents = NULL; |
---|
| 520 | + girq->default_type = IRQ_TYPE_NONE; |
---|
| 521 | + girq->handler = handle_simple_irq; |
---|
| 522 | + girq->threaded = true; |
---|
| 523 | + } |
---|
508 | 524 | |
---|
509 | | - gpiochip_set_nested_irqchip(&stmpe_gpio->chip, |
---|
510 | | - &stmpe_gpio_irq_chip, |
---|
511 | | - irq); |
---|
| 525 | + ret = gpiochip_add_data(&stmpe_gpio->chip, stmpe_gpio); |
---|
| 526 | + if (ret) { |
---|
| 527 | + dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); |
---|
| 528 | + goto out_disable; |
---|
512 | 529 | } |
---|
513 | 530 | |
---|
514 | 531 | platform_set_drvdata(pdev, stmpe_gpio); |
---|