Skip to content

Commit

Permalink
gliolib: set hooks in gpiochip_set_irq_hooks()
Browse files Browse the repository at this point in the history
Centralize setting the irq_request/release_resources callbacks
in one function since we'll be adding more callbacks to that.

Also fix the removal of the callback overrides: this should
only be done if we actually installed our own callback there.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Hans Verkuil authored and Linus Walleij committed Sep 10, 2018
1 parent 4e6b823 commit ca620f2
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,17 @@ static void gpiochip_irq_relres(struct irq_data *d)
gpiochip_relres_irq(chip, d->hwirq);
}

static void gpiochip_set_irq_hooks(struct gpio_chip *gpiochip)
{
struct irq_chip *irqchip = gpiochip->irq.chip;

if (!irqchip->irq_request_resources &&
!irqchip->irq_release_resources) {
irqchip->irq_request_resources = gpiochip_irq_reqres;
irqchip->irq_release_resources = gpiochip_irq_relres;
}
}

/**
* gpiochip_add_irqchip() - adds an IRQ chip to a GPIO chip
* @gpiochip: the GPIO chip to add the IRQ chip to
Expand Down Expand Up @@ -1884,16 +1895,6 @@ static int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
if (!gpiochip->irq.domain)
return -EINVAL;

/*
* It is possible for a driver to override this, but only if the
* alternative functions are both implemented.
*/
if (!irqchip->irq_request_resources &&
!irqchip->irq_release_resources) {
irqchip->irq_request_resources = gpiochip_irq_reqres;
irqchip->irq_release_resources = gpiochip_irq_relres;
}

if (gpiochip->irq.parent_handler) {
void *data = gpiochip->irq.parent_handler_data ?: gpiochip;

Expand All @@ -1909,6 +1910,8 @@ static int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
}
}

gpiochip_set_irq_hooks(gpiochip);

acpi_gpiochip_request_interrupts(gpiochip);

return 0;
Expand All @@ -1922,11 +1925,12 @@ static int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
*/
static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
{
struct irq_chip *irqchip = gpiochip->irq.chip;
unsigned int offset;

acpi_gpiochip_free_interrupts(gpiochip);

if (gpiochip->irq.chip && gpiochip->irq.parent_handler) {
if (irqchip && gpiochip->irq.parent_handler) {
struct gpio_irq_chip *irq = &gpiochip->irq;
unsigned int i;

Expand All @@ -1950,11 +1954,12 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
irq_domain_remove(gpiochip->irq.domain);
}

if (gpiochip->irq.chip) {
gpiochip->irq.chip->irq_request_resources = NULL;
gpiochip->irq.chip->irq_release_resources = NULL;
gpiochip->irq.chip = NULL;
if (irqchip &&
irqchip->irq_request_resources == gpiochip_irq_reqres) {
irqchip->irq_request_resources = NULL;
irqchip->irq_release_resources = NULL;
}
gpiochip->irq.chip = NULL;

gpiochip_irqchip_free_valid_mask(gpiochip);
}
Expand Down Expand Up @@ -2043,15 +2048,7 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip,
return -EINVAL;
}

/*
* It is possible for a driver to override this, but only if the
* alternative functions are both implemented.
*/
if (!irqchip->irq_request_resources &&
!irqchip->irq_release_resources) {
irqchip->irq_request_resources = gpiochip_irq_reqres;
irqchip->irq_release_resources = gpiochip_irq_relres;
}
gpiochip_set_irq_hooks(gpiochip);

acpi_gpiochip_request_interrupts(gpiochip);

Expand Down

0 comments on commit ca620f2

Please sign in to comment.