hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpio-stmpe.c
....@@ -1,7 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) ST-Ericsson SA 2010
34 *
4
- * License Terms: GNU General Public License, version 2
55 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
66 */
77
....@@ -84,7 +84,10 @@
8484 if (ret < 0)
8585 return ret;
8686
87
- return !(ret & mask);
87
+ if (ret & mask)
88
+ return GPIO_LINE_DIRECTION_OUT;
89
+
90
+ return GPIO_LINE_DIRECTION_IN;
8891 }
8992
9093 static int stmpe_gpio_direction_output(struct gpio_chip *chip,
....@@ -305,7 +308,7 @@
305308 if (ret < 0)
306309 return;
307310 edge_det = !!(ret & mask);
308
- /* fall through */
311
+ fallthrough;
309312 case STMPE1801:
310313 rise_reg = stmpe->regs[STMPE_IDX_GPRER_LSB + bank];
311314 fall_reg = stmpe->regs[STMPE_IDX_GPFER_LSB + bank];
....@@ -318,7 +321,7 @@
318321 if (ret < 0)
319322 return;
320323 fall = !!(ret & mask);
321
- /* fall through */
324
+ fallthrough;
322325 case STMPE801:
323326 case STMPE1600:
324327 irqen_reg = stmpe->regs[STMPE_IDX_IEGPIOR_LSB + bank];
....@@ -429,6 +432,23 @@
429432 return IRQ_HANDLED;
430433 }
431434
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
+
432452 static int stmpe_gpio_probe(struct platform_device *pdev)
433453 {
434454 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
....@@ -454,14 +474,21 @@
454474 stmpe_gpio->chip.parent = &pdev->dev;
455475 stmpe_gpio->chip.of_node = np;
456476 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;
457486
458487 if (IS_ENABLED(CONFIG_DEBUG_FS))
459488 stmpe_gpio->chip.dbg_show = stmpe_dbg_show;
460489
461490 of_property_read_u32(np, "st,norequest-mask",
462491 &stmpe_gpio->norequest_mask);
463
- if (stmpe_gpio->norequest_mask)
464
- stmpe_gpio->chip.irq.need_valid_mask = true;
465492
466493 irq = platform_get_irq(pdev, 0);
467494 if (irq < 0)
....@@ -473,13 +500,9 @@
473500 if (ret)
474501 goto out_free;
475502
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
-
482503 if (irq > 0) {
504
+ struct gpio_irq_chip *girq;
505
+
483506 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
484507 stmpe_gpio_irq, IRQF_ONESHOT,
485508 "stmpe-gpio", stmpe_gpio);
....@@ -487,28 +510,22 @@
487510 dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
488511 goto out_disable;
489512 }
490
- if (stmpe_gpio->norequest_mask) {
491
- int i;
492513
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
+ }
508524
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;
512529 }
513530
514531 platform_set_drvdata(pdev, stmpe_gpio);