Skip to content

Commit

Permalink
gpio/omap: auto request GPIO as input if used as IRQ via DT
Browse files Browse the repository at this point in the history
When an OMAP GPIO is used as an IRQ line, a call to gpio_request()
has to be made to initialize the OMAP GPIO bank before a driver
request the IRQ. Otherwise the call to request_irq() fails.

Drives should not be aware of this neither care wether an IRQ line
is a GPIO or not. They should just request the IRQ and this has to
be handled by the irq_chip driver.

With the current OMAP GPIO DT binding, if we define:

    gpio6: gpio@49058000 {
    	   compatible = "ti,omap3-gpio";
	   reg = <0x49058000 0x200>;
	   interrupts = <34>;
	   ti,hwmods = "gpio6";
	   gpio-controller;
	   #gpio-cells = <2>;
	   interrupt-controller;
	   #interrupt-cells = <2>;
    };

	   interrupt-parent = <&gpio6>;
           interrupts = <16 8>;

The GPIO is correctly mapped as an IRQ but a call to gpio_request()
is never made. Since a call to the custom IRQ domain .map function
handler is made for each GPIO used as an IRQ, the GPIO can be setup
and configured as input there automatically.

Changes since v3:
  - Use bank->chip.of_node instead of_have_populated_dt() to check
    DT or legacy boot as suggested by Jean-Christophe PLAGNIOL-VILLARD
  - Add a comment that this is just a temporary solution until and
    that it has to be removed once is handled by the IRQ core.

Changes since v2:
 - Only make the call to gpio_request_one() conditional in the DT
   case as suggested by Grant Likely.

Changes since v1:
  - Split the irq domain mapping function handler and the GPIO
    request in two different patches.

Signed-off-by: Javier Martinez Canillas <[email protected]>
Tested-by: Enric Balletbo i Serra <[email protected]>
Acked-by: Grant Likely <[email protected]>
Acked-by: Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
Acked-by: Santosh Shilimkar <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
  • Loading branch information
Javier Martinez Canillas authored and linusw committed Jul 20, 2013
1 parent 0e970ce commit b4419e1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions drivers/gpio/gpio-omap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,8 @@ static int omap_gpio_irq_map(struct irq_domain *d, unsigned int virq,
irq_hw_number_t hwirq)
{
struct gpio_bank *bank = d->host_data;
int gpio;
int ret;

if (!bank)
return -EINVAL;
Expand All @@ -1104,6 +1106,22 @@ static int omap_gpio_irq_map(struct irq_domain *d, unsigned int virq,
set_irq_flags(virq, IRQF_VALID);
}

/*
* REVISIT most GPIO IRQ chip drivers need to call
* gpio_request() before a GPIO line can be used as an
* IRQ. Ideally this should be handled by the IRQ core
* but until then this has to be done on a per driver
* basis. Remove this once this is managed by the core.
*/
if (bank->chip.of_node) {
gpio = irq_to_gpio(bank, hwirq);
ret = gpio_request_one(gpio, GPIOF_IN, NULL);
if (ret) {
dev_err(bank->dev, "Could not request GPIO%d\n", gpio);
return ret;
}
}

return 0;
}

Expand Down

0 comments on commit b4419e1

Please sign in to comment.