@@ -417,30 +417,66 @@ struct gpio_irq_chip inside struct gpio_chip before adding the gpio_chip.
417
417
If you do this, the additional irq_chip will be set up by gpiolib at the
418
418
same time as setting up the rest of the GPIO functionality. The following
419
419
is a typical example of a chained cascaded interrupt handler using
420
- the gpio_irq_chip:
420
+ the gpio_irq_chip. Note how the mask/unmask (or disable/enable) functions
421
+ call into the core gpiolib code:
421
422
422
423
.. code-block :: c
423
424
424
- /* Typical state container with dynamic irqchip */
425
+ /* Typical state container */
425
426
struct my_gpio {
426
427
struct gpio_chip gc;
427
- struct irq_chip irq;
428
+ };
429
+
430
+ static void my_gpio_mask_irq(struct irq_data *d)
431
+ {
432
+ struct gpio_chip *gc = irq_desc_get_handler_data(d);
433
+
434
+ /*
435
+ * Perform any necessary action to mask the interrupt,
436
+ * and then call into the core code to synchronise the
437
+ * state.
438
+ */
439
+
440
+ gpiochip_disable_irq(gc, d->hwirq);
441
+ }
442
+
443
+ static void my_gpio_unmask_irq(struct irq_data *d)
444
+ {
445
+ struct gpio_chip *gc = irq_desc_get_handler_data(d);
446
+
447
+ gpiochip_enable_irq(gc, d->hwirq);
448
+
449
+ /*
450
+ * Perform any necessary action to unmask the interrupt,
451
+ * after having called into the core code to synchronise
452
+ * the state.
453
+ */
454
+ }
455
+
456
+ /*
457
+ * Statically populate the irqchip. Note that it is made const
458
+ * (further indicated by the IRQCHIP_IMMUTABLE flag), and that
459
+ * the GPIOCHIP_IRQ_RESOURCE_HELPER macro adds some extra
460
+ * callbacks to the structure.
461
+ */
462
+ static const struct irq_chip my_gpio_irq_chip = {
463
+ .name = "my_gpio_irq",
464
+ .irq_ack = my_gpio_ack_irq,
465
+ .irq_mask = my_gpio_mask_irq,
466
+ .irq_unmask = my_gpio_unmask_irq,
467
+ .irq_set_type = my_gpio_set_irq_type,
468
+ .flags = IRQCHIP_IMMUTABLE,
469
+ /* Provide the gpio resource callbacks */
470
+ GPIOCHIP_IRQ_RESOURCE_HELPERS,
428
471
};
429
472
430
473
int irq; /* from platform etc */
431
474
struct my_gpio *g;
432
475
struct gpio_irq_chip *girq;
433
476
434
- /* Set up the irqchip dynamically */
435
- g->irq.name = "my_gpio_irq";
436
- g->irq.irq_ack = my_gpio_ack_irq;
437
- g->irq.irq_mask = my_gpio_mask_irq;
438
- g->irq.irq_unmask = my_gpio_unmask_irq;
439
- g->irq.irq_set_type = my_gpio_set_irq_type;
440
-
441
477
/* Get a pointer to the gpio_irq_chip */
442
478
girq = &g->gc.irq;
443
- girq->chip = &g->irq ;
479
+ gpio_irq_chip_set_chip( girq, &my_gpio_irq_chip) ;
444
480
girq->parent_handler = ftgpio_gpio_irq_handler;
445
481
girq->num_parents = 1;
446
482
girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents),
@@ -458,31 +494,66 @@ the interrupt separately and go with it:
458
494
459
495
.. code-block :: c
460
496
461
- /* Typical state container with dynamic irqchip */
497
+ /* Typical state container */
462
498
struct my_gpio {
463
499
struct gpio_chip gc;
464
- struct irq_chip irq;
500
+ };
501
+
502
+ static void my_gpio_mask_irq(struct irq_data *d)
503
+ {
504
+ struct gpio_chip *gc = irq_desc_get_handler_data(d);
505
+
506
+ /*
507
+ * Perform any necessary action to mask the interrupt,
508
+ * and then call into the core code to synchronise the
509
+ * state.
510
+ */
511
+
512
+ gpiochip_disable_irq(gc, d->hwirq);
513
+ }
514
+
515
+ static void my_gpio_unmask_irq(struct irq_data *d)
516
+ {
517
+ struct gpio_chip *gc = irq_desc_get_handler_data(d);
518
+
519
+ gpiochip_enable_irq(gc, d->hwirq);
520
+
521
+ /*
522
+ * Perform any necessary action to unmask the interrupt,
523
+ * after having called into the core code to synchronise
524
+ * the state.
525
+ */
526
+ }
527
+
528
+ /*
529
+ * Statically populate the irqchip. Note that it is made const
530
+ * (further indicated by the IRQCHIP_IMMUTABLE flag), and that
531
+ * the GPIOCHIP_IRQ_RESOURCE_HELPER macro adds some extra
532
+ * callbacks to the structure.
533
+ */
534
+ static const struct irq_chip my_gpio_irq_chip = {
535
+ .name = "my_gpio_irq",
536
+ .irq_ack = my_gpio_ack_irq,
537
+ .irq_mask = my_gpio_mask_irq,
538
+ .irq_unmask = my_gpio_unmask_irq,
539
+ .irq_set_type = my_gpio_set_irq_type,
540
+ .flags = IRQCHIP_IMMUTABLE,
541
+ /* Provide the gpio resource callbacks */
542
+ GPIOCHIP_IRQ_RESOURCE_HELPERS,
465
543
};
466
544
467
545
int irq; /* from platform etc */
468
546
struct my_gpio *g;
469
547
struct gpio_irq_chip *girq;
470
548
471
- /* Set up the irqchip dynamically */
472
- g->irq.name = "my_gpio_irq";
473
- g->irq.irq_ack = my_gpio_ack_irq;
474
- g->irq.irq_mask = my_gpio_mask_irq;
475
- g->irq.irq_unmask = my_gpio_unmask_irq;
476
- g->irq.irq_set_type = my_gpio_set_irq_type;
477
-
478
549
ret = devm_request_threaded_irq(dev, irq, NULL,
479
550
irq_thread_fn, IRQF_ONESHOT, "my-chip", g);
480
551
if (ret < 0)
481
552
return ret;
482
553
483
554
/* Get a pointer to the gpio_irq_chip */
484
555
girq = &g->gc.irq;
485
- girq->chip = &g->irq ;
556
+ gpio_irq_chip_set_chip( girq, &my_gpio_irq_chip) ;
486
557
/* This will let us handle the parent IRQ in the driver */
487
558
girq->parent_handler = NULL;
488
559
girq->num_parents = 0;
@@ -500,24 +571,61 @@ In this case the typical set-up will look like this:
500
571
/* Typical state container with dynamic irqchip */
501
572
struct my_gpio {
502
573
struct gpio_chip gc;
503
- struct irq_chip irq;
504
574
struct fwnode_handle *fwnode;
505
575
};
506
576
507
- int irq; /* from platform etc */
577
+ static void my_gpio_mask_irq(struct irq_data *d)
578
+ {
579
+ struct gpio_chip *gc = irq_desc_get_handler_data(d);
580
+
581
+ /*
582
+ * Perform any necessary action to mask the interrupt,
583
+ * and then call into the core code to synchronise the
584
+ * state.
585
+ */
586
+
587
+ gpiochip_disable_irq(gc, d->hwirq);
588
+ irq_mask_mask_parent(d);
589
+ }
590
+
591
+ static void my_gpio_unmask_irq(struct irq_data *d)
592
+ {
593
+ struct gpio_chip *gc = irq_desc_get_handler_data(d);
594
+
595
+ gpiochip_enable_irq(gc, d->hwirq);
596
+
597
+ /*
598
+ * Perform any necessary action to unmask the interrupt,
599
+ * after having called into the core code to synchronise
600
+ * the state.
601
+ */
602
+
603
+ irq_mask_unmask_parent(d);
604
+ }
605
+
606
+ /*
607
+ * Statically populate the irqchip. Note that it is made const
608
+ * (further indicated by the IRQCHIP_IMMUTABLE flag), and that
609
+ * the GPIOCHIP_IRQ_RESOURCE_HELPER macro adds some extra
610
+ * callbacks to the structure.
611
+ */
612
+ static const struct irq_chip my_gpio_irq_chip = {
613
+ .name = "my_gpio_irq",
614
+ .irq_ack = my_gpio_ack_irq,
615
+ .irq_mask = my_gpio_mask_irq,
616
+ .irq_unmask = my_gpio_unmask_irq,
617
+ .irq_set_type = my_gpio_set_irq_type,
618
+ .flags = IRQCHIP_IMMUTABLE,
619
+ /* Provide the gpio resource callbacks */
620
+ GPIOCHIP_IRQ_RESOURCE_HELPERS,
621
+ };
622
+
508
623
struct my_gpio *g;
509
624
struct gpio_irq_chip *girq;
510
625
511
- /* Set up the irqchip dynamically */
512
- g->irq.name = "my_gpio_irq";
513
- g->irq.irq_ack = my_gpio_ack_irq;
514
- g->irq.irq_mask = my_gpio_mask_irq;
515
- g->irq.irq_unmask = my_gpio_unmask_irq;
516
- g->irq.irq_set_type = my_gpio_set_irq_type;
517
-
518
626
/* Get a pointer to the gpio_irq_chip */
519
627
girq = &g->gc.irq;
520
- girq->chip = &g->irq ;
628
+ gpio_irq_chip_set_chip( girq, &my_gpio_irq_chip) ;
521
629
girq->default_type = IRQ_TYPE_NONE;
522
630
girq->handler = handle_bad_irq;
523
631
girq->fwnode = g->fwnode;
@@ -605,8 +713,9 @@ When implementing an irqchip inside a GPIO driver, these two functions should
605
713
typically be called in the .irq_disable() and .irq_enable() callbacks from the
606
714
irqchip.
607
715
608
- When using the gpiolib irqchip helpers, these callbacks are automatically
609
- assigned.
716
+ When IRQCHIP_IMMUTABLE is not advertised by the irqchip, these callbacks
717
+ are automatically assigned. This behaviour is deprecated and on its way
718
+ to be removed from the kernel.
610
719
611
720
612
721
Real-Time compliance for GPIO IRQ chips
0 commit comments