Skip to content

Commit f1f37ab

Browse files
author
Linus Walleij
committed
gpio: Retire the explicit gpio irqchip code
Now that all gpiolib irqchip users have been over to use the irqchip template, we can finally retire the old code path and leave just one way in to the irqchip: set up the template when registering the gpio_chip. For a while we had two code paths for this which was a bit confusing. This brings this work to a conclusion, there is now one way of doing this. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Cc: Thierry Reding <thierry.reding@gmail.com> Link: https://lore.kernel.org/r/20201019134046.65101-1-linus.walleij@linaro.org
1 parent 163d171 commit f1f37ab

4 files changed

Lines changed: 42 additions & 294 deletions

File tree

‎Documentation/driver-api/gpio/driver.rst‎

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ The preferred way to set up the helpers is to fill in the
416416
struct gpio_irq_chip inside struct gpio_chip before adding the gpio_chip.
417417
If you do this, the additional irq_chip will be set up by gpiolib at the
418418
same time as setting up the rest of the GPIO functionality. The following
419-
is a typical example of a cascaded interrupt handler using gpio_irq_chip:
419+
is a typical example of a chained cascaded interrupt handler using
420+
the gpio_irq_chip:
420421

421422
.. code-block:: c
422423
@@ -452,7 +453,46 @@ is a typical example of a cascaded interrupt handler using gpio_irq_chip:
452453
453454
return devm_gpiochip_add_data(dev, &g->gc, g);
454455
455-
The helper support using hierarchical interrupt controllers as well.
456+
The helper supports using threaded interrupts as well. Then you just request
457+
the interrupt separately and go with it:
458+
459+
.. code-block:: c
460+
461+
/* Typical state container with dynamic irqchip */
462+
struct my_gpio {
463+
struct gpio_chip gc;
464+
struct irq_chip irq;
465+
};
466+
467+
int irq; /* from platform etc */
468+
struct my_gpio *g;
469+
struct gpio_irq_chip *girq;
470+
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+
ret = devm_request_threaded_irq(dev, irq, NULL,
479+
irq_thread_fn, IRQF_ONESHOT, "my-chip", g);
480+
if (ret < 0)
481+
return ret;
482+
483+
/* Get a pointer to the gpio_irq_chip */
484+
girq = &g->gc.irq;
485+
girq->chip = &g->irq;
486+
/* This will let us handle the parent IRQ in the driver */
487+
girq->parent_handler = NULL;
488+
girq->num_parents = 0;
489+
girq->parents = NULL;
490+
girq->default_type = IRQ_TYPE_NONE;
491+
girq->handler = handle_bad_irq;
492+
493+
return devm_gpiochip_add_data(dev, &g->gc, g);
494+
495+
The helper supports using hierarchical interrupt controllers as well.
456496
In this case the typical set-up will look like this:
457497

458498
.. code-block:: c
@@ -493,25 +533,6 @@ the parent hardware irq from a child (i.e. this gpio chip) hardware irq.
493533
As always it is good to look at examples in the kernel tree for advice
494534
on how to find the required pieces.
495535

496-
The old way of adding irqchips to gpiochips after registration is also still
497-
available but we try to move away from this:
498-
499-
- DEPRECATED: gpiochip_irqchip_add(): adds a chained cascaded irqchip to a
500-
gpiochip. It will pass the struct gpio_chip* for the chip to all IRQ
501-
callbacks, so the callbacks need to embed the gpio_chip in its state
502-
container and obtain a pointer to the container using container_of().
503-
(See Documentation/driver-api/driver-model/design-patterns.rst)
504-
505-
- gpiochip_irqchip_add_nested(): adds a nested cascaded irqchip to a gpiochip,
506-
as discussed above regarding different types of cascaded irqchips. The
507-
cascaded irq has to be handled by a threaded interrupt handler.
508-
Apart from that it works exactly like the chained irqchip.
509-
510-
- gpiochip_set_nested_irqchip(): sets up a nested cascaded irq handler for a
511-
gpio_chip from a parent IRQ. As the parent IRQ has usually been
512-
explicitly requested by the driver, this does very little more than
513-
mark all the child IRQs as having the other IRQ as parent.
514-
515536
If there is a need to exclude certain GPIO lines from the IRQ domain handled by
516537
these helpers, we can set .irq.need_valid_mask of the gpiochip before
517538
devm_gpiochip_add_data() or gpiochip_add_data() is called. This allocates an

‎drivers/gpio/TODO‎

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -129,58 +129,9 @@ GPIOLIB irqchip
129129
The GPIOLIB irqchip is a helper irqchip for "simple cases" that should
130130
try to cover any generic kind of irqchip cascaded from a GPIO.
131131

132-
- Convert all the GPIOLIB_IRQCHIP users to pass an irqchip template,
133-
parent and flags before calling [devm_]gpiochip_add[_data]().
134-
Currently we set up the irqchip after setting up the gpiochip
135-
using gpiochip_irqchip_add() and gpiochip_set_[chained|nested]_irqchip().
136-
This is too complex, so convert all users over to just set up
137-
the irqchip before registering the gpio_chip, typical example:
138-
139-
/* Typical state container with dynamic irqchip */
140-
struct my_gpio {
141-
struct gpio_chip gc;
142-
struct irq_chip irq;
143-
};
144-
145-
int irq; /* from platform etc */
146-
struct my_gpio *g;
147-
struct gpio_irq_chip *girq;
148-
149-
/* Set up the irqchip dynamically */
150-
g->irq.name = "my_gpio_irq";
151-
g->irq.irq_ack = my_gpio_ack_irq;
152-
g->irq.irq_mask = my_gpio_mask_irq;
153-
g->irq.irq_unmask = my_gpio_unmask_irq;
154-
g->irq.irq_set_type = my_gpio_set_irq_type;
155-
156-
/* Get a pointer to the gpio_irq_chip */
157-
girq = &g->gc.irq;
158-
girq->chip = &g->irq;
159-
girq->parent_handler = ftgpio_gpio_irq_handler;
160-
girq->num_parents = 1;
161-
girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents),
162-
GFP_KERNEL);
163-
if (!girq->parents)
164-
return -ENOMEM;
165-
girq->default_type = IRQ_TYPE_NONE;
166-
girq->handler = handle_bad_irq;
167-
girq->parents[0] = irq;
168-
169-
When this is done, we will delete the old APIs for instatiating
170-
GPIOLIB_IRQCHIP and simplify the code.
171-
172132
- Look over and identify any remaining easily converted drivers and
173133
dry-code conversions to gpiolib irqchip for maintainers to test
174134

175-
- Drop gpiochip_set_chained_irqchip() when all the chained irqchips
176-
have been converted to the above infrastructure.
177-
178-
- Add more infrastructure to make it possible to also pass a threaded
179-
irqchip in struct gpio_irq_chip.
180-
181-
- Drop gpiochip_irqchip_add_nested() when all the chained irqchips
182-
have been converted to the above infrastructure.
183-
184135

185136
Increase integration with pin control
186137

‎drivers/gpio/gpiolib.c‎

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -924,67 +924,6 @@ bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc,
924924
}
925925
EXPORT_SYMBOL_GPL(gpiochip_irqchip_irq_valid);
926926

927-
/**
928-
* gpiochip_set_cascaded_irqchip() - connects a cascaded irqchip to a gpiochip
929-
* @gc: the gpiochip to set the irqchip chain to
930-
* @parent_irq: the irq number corresponding to the parent IRQ for this
931-
* cascaded irqchip
932-
* @parent_handler: the parent interrupt handler for the accumulated IRQ
933-
* coming out of the gpiochip. If the interrupt is nested rather than
934-
* cascaded, pass NULL in this handler argument
935-
*/
936-
static void gpiochip_set_cascaded_irqchip(struct gpio_chip *gc,
937-
unsigned int parent_irq,
938-
irq_flow_handler_t parent_handler)
939-
{
940-
struct gpio_irq_chip *girq = &gc->irq;
941-
struct device *dev = &gc->gpiodev->dev;
942-
943-
if (!girq->domain) {
944-
chip_err(gc, "called %s before setting up irqchip\n",
945-
__func__);
946-
return;
947-
}
948-
949-
if (parent_handler) {
950-
if (gc->can_sleep) {
951-
chip_err(gc,
952-
"you cannot have chained interrupts on a chip that may sleep\n");
953-
return;
954-
}
955-
girq->parents = devm_kcalloc(dev, 1,
956-
sizeof(*girq->parents),
957-
GFP_KERNEL);
958-
if (!girq->parents) {
959-
chip_err(gc, "out of memory allocating parent IRQ\n");
960-
return;
961-
}
962-
girq->parents[0] = parent_irq;
963-
girq->num_parents = 1;
964-
/*
965-
* The parent irqchip is already using the chip_data for this
966-
* irqchip, so our callbacks simply use the handler_data.
967-
*/
968-
irq_set_chained_handler_and_data(parent_irq, parent_handler,
969-
gc);
970-
}
971-
}
972-
973-
/**
974-
* gpiochip_set_nested_irqchip() - connects a nested irqchip to a gpiochip
975-
* @gc: the gpiochip to set the irqchip nested handler to
976-
* @irqchip: the irqchip to nest to the gpiochip
977-
* @parent_irq: the irq number corresponding to the parent IRQ for this
978-
* nested irqchip
979-
*/
980-
void gpiochip_set_nested_irqchip(struct gpio_chip *gc,
981-
struct irq_chip *irqchip,
982-
unsigned int parent_irq)
983-
{
984-
gpiochip_set_cascaded_irqchip(gc, parent_irq, NULL);
985-
}
986-
EXPORT_SYMBOL_GPL(gpiochip_set_nested_irqchip);
987-
988927
#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
989928

990929
/**
@@ -1635,98 +1574,6 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gc)
16351574
gpiochip_irqchip_free_valid_mask(gc);
16361575
}
16371576

1638-
/**
1639-
* gpiochip_irqchip_add_key() - adds an irqchip to a gpiochip
1640-
* @gc: the gpiochip to add the irqchip to
1641-
* @irqchip: the irqchip to add to the gpiochip
1642-
* @first_irq: if not dynamically assigned, the base (first) IRQ to
1643-
* allocate gpiochip irqs from
1644-
* @handler: the irq handler to use (often a predefined irq core function)
1645-
* @type: the default type for IRQs on this irqchip, pass IRQ_TYPE_NONE
1646-
* to have the core avoid setting up any default type in the hardware.
1647-
* @threaded: whether this irqchip uses a nested thread handler
1648-
* @lock_key: lockdep class for IRQ lock
1649-
* @request_key: lockdep class for IRQ request
1650-
*
1651-
* This function closely associates a certain irqchip with a certain
1652-
* gpiochip, providing an irq domain to translate the local IRQs to
1653-
* global irqs in the gpiolib core, and making sure that the gpiochip
1654-
* is passed as chip data to all related functions. Driver callbacks
1655-
* need to use gpiochip_get_data() to get their local state containers back
1656-
* from the gpiochip passed as chip data. An irqdomain will be stored
1657-
* in the gpiochip that shall be used by the driver to handle IRQ number
1658-
* translation. The gpiochip will need to be initialized and registered
1659-
* before calling this function.
1660-
*
1661-
* This function will handle two cell:ed simple IRQs and assumes all
1662-
* the pins on the gpiochip can generate a unique IRQ. Everything else
1663-
* need to be open coded.
1664-
*/
1665-
int gpiochip_irqchip_add_key(struct gpio_chip *gc,
1666-
struct irq_chip *irqchip,
1667-
unsigned int first_irq,
1668-
irq_flow_handler_t handler,
1669-
unsigned int type,
1670-
bool threaded,
1671-
struct lock_class_key *lock_key,
1672-
struct lock_class_key *request_key)
1673-
{
1674-
struct device_node *of_node;
1675-
1676-
if (!gc || !irqchip)
1677-
return -EINVAL;
1678-
1679-
if (!gc->parent) {
1680-
chip_err(gc, "missing gpiochip .dev parent pointer\n");
1681-
return -EINVAL;
1682-
}
1683-
gc->irq.threaded = threaded;
1684-
of_node = gc->parent->of_node;
1685-
#ifdef CONFIG_OF_GPIO
1686-
/*
1687-
* If the gpiochip has an assigned OF node this takes precedence
1688-
* FIXME: get rid of this and use gc->parent->of_node
1689-
* everywhere
1690-
*/
1691-
if (gc->of_node)
1692-
of_node = gc->of_node;
1693-
#endif
1694-
/*
1695-
* Specifying a default trigger is a terrible idea if DT or ACPI is
1696-
* used to configure the interrupts, as you may end-up with
1697-
* conflicting triggers. Tell the user, and reset to NONE.
1698-
*/
1699-
if (WARN(of_node && type != IRQ_TYPE_NONE,
1700-
"%pOF: Ignoring %d default trigger\n", of_node, type))
1701-
type = IRQ_TYPE_NONE;
1702-
if (has_acpi_companion(gc->parent) && type != IRQ_TYPE_NONE) {
1703-
acpi_handle_warn(ACPI_HANDLE(gc->parent),
1704-
"Ignoring %d default trigger\n", type);
1705-
type = IRQ_TYPE_NONE;
1706-
}
1707-
1708-
gc->irq.chip = irqchip;
1709-
gc->irq.handler = handler;
1710-
gc->irq.default_type = type;
1711-
gc->to_irq = gpiochip_to_irq;
1712-
gc->irq.lock_key = lock_key;
1713-
gc->irq.request_key = request_key;
1714-
gc->irq.domain = irq_domain_add_simple(of_node,
1715-
gc->ngpio, first_irq,
1716-
&gpiochip_domain_ops, gc);
1717-
if (!gc->irq.domain) {
1718-
gc->irq.chip = NULL;
1719-
return -EINVAL;
1720-
}
1721-
1722-
gpiochip_set_irq_hooks(gc);
1723-
1724-
acpi_gpiochip_request_interrupts(gc);
1725-
1726-
return 0;
1727-
}
1728-
EXPORT_SYMBOL_GPL(gpiochip_irqchip_add_key);
1729-
17301577
/**
17311578
* gpiochip_irqchip_add_domain() - adds an irqdomain to a gpiochip
17321579
* @gc: the gpiochip to add the irqchip to

‎include/linux/gpio/driver.h‎

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -621,83 +621,12 @@ int gpiochip_irq_domain_activate(struct irq_domain *domain,
621621
void gpiochip_irq_domain_deactivate(struct irq_domain *domain,
622622
struct irq_data *data);
623623

624-
void gpiochip_set_nested_irqchip(struct gpio_chip *gc,
625-
struct irq_chip *irqchip,
626-
unsigned int parent_irq);
627-
628-
int gpiochip_irqchip_add_key(struct gpio_chip *gc,
629-
struct irq_chip *irqchip,
630-
unsigned int first_irq,
631-
irq_flow_handler_t handler,
632-
unsigned int type,
633-
bool threaded,
634-
struct lock_class_key *lock_key,
635-
struct lock_class_key *request_key);
636-
637624
bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc,
638625
unsigned int offset);
639626

640627
int gpiochip_irqchip_add_domain(struct gpio_chip *gc,
641628
struct irq_domain *domain);
642629

643-
#ifdef CONFIG_LOCKDEP
644-
645-
/*
646-
* Lockdep requires that each irqchip instance be created with a
647-
* unique key so as to avoid unnecessary warnings. This upfront
648-
* boilerplate static inlines provides such a key for each
649-
* unique instance.
650-
*/
651-
static inline int gpiochip_irqchip_add(struct gpio_chip *gc,
652-
struct irq_chip *irqchip,
653-
unsigned int first_irq,
654-
irq_flow_handler_t handler,
655-
unsigned int type)
656-
{
657-
static struct lock_class_key lock_key;
658-
static struct lock_class_key request_key;
659-
660-
return gpiochip_irqchip_add_key(gc, irqchip, first_irq,
661-
handler, type, false,
662-
&lock_key, &request_key);
663-
}
664-
665-
static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gc,
666-
struct irq_chip *irqchip,
667-
unsigned int first_irq,
668-
irq_flow_handler_t handler,
669-
unsigned int type)
670-
{
671-
672-
static struct lock_class_key lock_key;
673-
static struct lock_class_key request_key;
674-
675-
return gpiochip_irqchip_add_key(gc, irqchip, first_irq,
676-
handler, type, true,
677-
&lock_key, &request_key);
678-
}
679-
#else /* ! CONFIG_LOCKDEP */
680-
static inline int gpiochip_irqchip_add(struct gpio_chip *gc,
681-
struct irq_chip *irqchip,
682-
unsigned int first_irq,
683-
irq_flow_handler_t handler,
684-
unsigned int type)
685-
{
686-
return gpiochip_irqchip_add_key(gc, irqchip, first_irq,
687-
handler, type, false, NULL, NULL);
688-
}
689-
690-
static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gc,
691-
struct irq_chip *irqchip,
692-
unsigned int first_irq,
693-
irq_flow_handler_t handler,
694-
unsigned int type)
695-
{
696-
return gpiochip_irqchip_add_key(gc, irqchip, first_irq,
697-
handler, type, true, NULL, NULL);
698-
}
699-
#endif /* CONFIG_LOCKDEP */
700-
701630
int gpiochip_generic_request(struct gpio_chip *gc, unsigned int offset);
702631
void gpiochip_generic_free(struct gpio_chip *gc, unsigned int offset);
703632
int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset,

0 commit comments

Comments
 (0)