gpio: handle also nested irqchips in the chained handler set-up

To unify how we connect cascaded IRQ chips to parent IRQs, if
NULL us passed as handler to the gpiochip_set_chained_irqchip()
function, assume the chips is nested rather than chained, and
we still get the parent set up correctly by way of this function
call.

Alter the drivers for tc3589x and stmpe to use this to set up
their chained handlers as a demonstration of the usage.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
Linus Walleij 2014-09-26 14:19:52 +02:00
parent 83141a7719
commit 3f97d5fcf9
4 changed files with 38 additions and 22 deletions

View File

@ -124,7 +124,8 @@ symbol:
* gpiochip_set_chained_irqchip(): sets up a chained irq handler for a * gpiochip_set_chained_irqchip(): sets up a chained irq handler for a
gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler
data. (Notice handler data, since the irqchip data is likely used by the data. (Notice handler data, since the irqchip data is likely used by the
parent irqchip!) This is for the chained type of chip. parent irqchip!) This is for the chained type of chip. This is also used
to set up a nested irqchip if NULL is passed as handler.
To use the helpers please keep the following in mind: To use the helpers please keep the following in mind:

View File

@ -308,6 +308,12 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
if (ret) if (ret)
goto out_free; goto out_free;
ret = gpiochip_add(&stmpe_gpio->chip);
if (ret) {
dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
goto out_disable;
}
if (irq > 0) { if (irq > 0) {
ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
stmpe_gpio_irq, IRQF_ONESHOT, stmpe_gpio_irq, IRQF_ONESHOT,
@ -324,14 +330,13 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
if (ret) { if (ret) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"could not connect irqchip to gpiochip\n"); "could not connect irqchip to gpiochip\n");
return ret; goto out_disable;
} }
}
ret = gpiochip_add(&stmpe_gpio->chip); gpiochip_set_chained_irqchip(&stmpe_gpio->chip,
if (ret) { &stmpe_gpio_irq_chip,
dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); irq,
goto out_disable; NULL);
} }
if (pdata && pdata->setup) if (pdata && pdata->setup)
@ -343,6 +348,7 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
out_disable: out_disable:
stmpe_disable(stmpe, STMPE_BLOCK_GPIO); stmpe_disable(stmpe, STMPE_BLOCK_GPIO);
gpiochip_remove(&stmpe_gpio->chip);
out_free: out_free:
kfree(stmpe_gpio); kfree(stmpe_gpio);
return ret; return ret;

View File

@ -300,6 +300,11 @@ static int tc3589x_gpio_probe(struct platform_device *pdev)
return ret; return ret;
} }
gpiochip_set_chained_irqchip(&tc3589x_gpio->chip,
&tc3589x_gpio_irq_chip,
irq,
NULL);
if (pdata && pdata->setup) if (pdata && pdata->setup)
pdata->setup(tc3589x, tc3589x_gpio->chip.base); pdata->setup(tc3589x, tc3589x_gpio->chip.base);

View File

@ -385,13 +385,14 @@ static struct gpio_chip *find_chip_by_name(const char *name)
*/ */
/** /**
* gpiochip_add_chained_irqchip() - adds a chained irqchip to a gpiochip * gpiochip_set_chained_irqchip() - sets a chained irqchip to a gpiochip
* @gpiochip: the gpiochip to add the irqchip to * @gpiochip: the gpiochip to set the irqchip chain to
* @irqchip: the irqchip to add to the gpiochip * @irqchip: the irqchip to chain to the gpiochip
* @parent_irq: the irq number corresponding to the parent IRQ for this * @parent_irq: the irq number corresponding to the parent IRQ for this
* chained irqchip * chained irqchip
* @parent_handler: the parent interrupt handler for the accumulated IRQ * @parent_handler: the parent interrupt handler for the accumulated IRQ
* coming out of the gpiochip * coming out of the gpiochip. If the interrupt is nested rather than
* cascaded, pass NULL in this handler argument
*/ */
void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
struct irq_chip *irqchip, struct irq_chip *irqchip,
@ -400,23 +401,26 @@ void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
{ {
unsigned int offset; unsigned int offset;
if (gpiochip->can_sleep) {
chip_err(gpiochip, "you cannot have chained interrupts on a chip that may sleep\n");
return;
}
if (!gpiochip->irqdomain) { if (!gpiochip->irqdomain) {
chip_err(gpiochip, "called %s before setting up irqchip\n", chip_err(gpiochip, "called %s before setting up irqchip\n",
__func__); __func__);
return; return;
} }
irq_set_chained_handler(parent_irq, parent_handler); if (parent_handler) {
if (gpiochip->can_sleep) {
/* chip_err(gpiochip,
* The parent irqchip is already using the chip_data for this "you cannot have chained interrupts on a "
* irqchip, so our callbacks simply use the handler_data. "chip that may sleep\n");
*/ return;
irq_set_handler_data(parent_irq, gpiochip); }
irq_set_chained_handler(parent_irq, parent_handler);
/*
* The parent irqchip is already using the chip_data for this
* irqchip, so our callbacks simply use the handler_data.
*/
irq_set_handler_data(parent_irq, gpiochip);
}
/* Set the parent IRQ for all affected IRQs */ /* Set the parent IRQ for all affected IRQs */
for (offset = 0; offset < gpiochip->ngpio; offset++) for (offset = 0; offset < gpiochip->ngpio; offset++)