Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio / ACPI: Move event handling registration to gpiolib irqchip helpers

Since now we have irqchip helpers that the GPIO chip drivers are supposed
to use if possible, we can move the registration of ACPI events to happen
in these helpers. This seems to be more natural place and might encourage
GPIO chip driver writers to take advantage of the irqchip helpers.

We make the functions available to GPIO chip drivers via private gpiolib.h,
just in case generic irqchip helpers are not suitable.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Mika Westerberg and committed by
Linus Walleij
afa82fab 7f87210e

+41 -10
+28 -10
drivers/gpio/gpiolib-acpi.c
··· 221 221 222 222 /** 223 223 * acpi_gpiochip_request_interrupts() - Register isr for gpio chip ACPI events 224 - * @acpi_gpio: ACPI GPIO chip 224 + * @chip: GPIO chip 225 225 * 226 226 * ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are 227 227 * handled by ACPI event methods which need to be called from the GPIO ··· 229 229 * gpio pins have acpi event methods and assigns interrupt handlers that calls 230 230 * the acpi event methods for those pins. 231 231 */ 232 - static void acpi_gpiochip_request_interrupts(struct acpi_gpio_chip *acpi_gpio) 232 + void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) 233 233 { 234 - struct gpio_chip *chip = acpi_gpio->chip; 234 + struct acpi_gpio_chip *acpi_gpio; 235 + acpi_handle handle; 236 + acpi_status status; 235 237 236 - if (!chip->to_irq) 238 + if (!chip->dev || !chip->to_irq) 239 + return; 240 + 241 + handle = ACPI_HANDLE(chip->dev); 242 + if (!handle) 243 + return; 244 + 245 + status = acpi_get_data(handle, acpi_gpio_chip_dh, (void **)&acpi_gpio); 246 + if (ACPI_FAILURE(status)) 237 247 return; 238 248 239 249 INIT_LIST_HEAD(&acpi_gpio->events); ··· 253 243 254 244 /** 255 245 * acpi_gpiochip_free_interrupts() - Free GPIO ACPI event interrupts. 256 - * @acpi_gpio: ACPI GPIO chip 246 + * @chip: GPIO chip 257 247 * 258 248 * Free interrupts associated with GPIO ACPI event method for the given 259 249 * GPIO chip. 260 250 */ 261 - static void acpi_gpiochip_free_interrupts(struct acpi_gpio_chip *acpi_gpio) 251 + void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) 262 252 { 253 + struct acpi_gpio_chip *acpi_gpio; 263 254 struct acpi_gpio_event *event, *ep; 264 - struct gpio_chip *chip = acpi_gpio->chip; 255 + acpi_handle handle; 256 + acpi_status status; 265 257 266 - if (!chip->to_irq) 258 + if (!chip->dev || !chip->to_irq) 259 + return; 260 + 261 + handle = ACPI_HANDLE(chip->dev); 262 + if (!handle) 263 + return; 264 + 265 + status = acpi_get_data(handle, acpi_gpio_chip_dh, (void **)&acpi_gpio); 266 + if (ACPI_FAILURE(status)) 267 267 return; 268 268 269 269 list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) { ··· 545 525 return; 546 526 } 547 527 548 - acpi_gpiochip_request_interrupts(acpi_gpio); 549 528 acpi_gpiochip_request_regions(acpi_gpio); 550 529 } 551 530 ··· 568 549 } 569 550 570 551 acpi_gpiochip_free_regions(acpi_gpio); 571 - acpi_gpiochip_free_interrupts(acpi_gpio); 572 552 573 553 acpi_detach_data(handle, acpi_gpio_chip_dh); 574 554 kfree(acpi_gpio);
+4
drivers/gpio/gpiolib.c
··· 519 519 { 520 520 unsigned int offset; 521 521 522 + acpi_gpiochip_free_interrupts(gpiochip); 523 + 522 524 /* Remove all IRQ mappings and delete the domain */ 523 525 if (gpiochip->irqdomain) { 524 526 for (offset = 0; offset < gpiochip->ngpio; offset++) ··· 613 611 */ 614 612 gpiochip->irq_base = irq_base; 615 613 } 614 + 615 + acpi_gpiochip_request_interrupts(gpiochip); 616 616 617 617 return 0; 618 618 }
+9
drivers/gpio/gpiolib.h
··· 31 31 void acpi_gpiochip_add(struct gpio_chip *chip); 32 32 void acpi_gpiochip_remove(struct gpio_chip *chip); 33 33 34 + void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); 35 + void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); 36 + 34 37 struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, 35 38 struct acpi_gpio_info *info); 36 39 #else 37 40 static inline void acpi_gpiochip_add(struct gpio_chip *chip) { } 38 41 static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { } 42 + 43 + static inline void 44 + acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { } 45 + 46 + static inline void 47 + acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { } 39 48 40 49 static inline struct gpio_desc * 41 50 acpi_get_gpiod_by_index(struct device *dev, int index,