Skip to content

Commit 664e3e5

Browse files
westeriLinus Walleij
authored andcommitted
gpio / ACPI: register to ACPI events automatically
Instead of asking each driver to register to ACPI events we can just call acpi_gpiochip_register_interrupts() for each chip that has an ACPI handle. The function checks chip->to_irq and if it is set to NULL (a GPIO driver that doesn't do interrupts) the function does nothing. We also add the a new header drivers/gpio/gpiolib.h that is used for functions internal to gpiolib and add ACPI GPIO chip registering functions to that header. Once that is done we can remove call to acpi_gpiochip_register_interrupts() from its only user, pinctrl-baytrail.c Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 8787565 commit 664e3e5

5 files changed

Lines changed: 39 additions & 14 deletions

File tree

‎drivers/gpio/gpiolib-acpi.c‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void acpi_gpio_evt_dh(acpi_handle handle, void *data)
9494
* gpio pins have acpi event methods and assigns interrupt handlers that calls
9595
* the acpi event methods for those pins.
9696
*/
97-
void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
97+
static void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
9898
{
9999
struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
100100
struct acpi_resource *res;
@@ -192,7 +192,6 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
192192
irq);
193193
}
194194
}
195-
EXPORT_SYMBOL(acpi_gpiochip_request_interrupts);
196195

197196
/**
198197
* acpi_gpiochip_free_interrupts() - Free GPIO _EVT ACPI event interrupts.
@@ -203,7 +202,7 @@ EXPORT_SYMBOL(acpi_gpiochip_request_interrupts);
203202
* The remaining ACPI event interrupts associated with the chip are freed
204203
* automatically.
205204
*/
206-
void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
205+
static void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
207206
{
208207
acpi_handle handle;
209208
acpi_status status;
@@ -230,7 +229,6 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
230229
acpi_detach_data(handle, acpi_gpio_evt_dh);
231230
kfree(evt_pins);
232231
}
233-
EXPORT_SYMBOL(acpi_gpiochip_free_interrupts);
234232

235233
struct acpi_gpio_lookup {
236234
struct acpi_gpio_info info;
@@ -310,3 +308,13 @@ struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
310308
return lookup.desc ? lookup.desc : ERR_PTR(-ENOENT);
311309
}
312310
EXPORT_SYMBOL_GPL(acpi_get_gpiod_by_index);
311+
312+
void acpi_gpiochip_add(struct gpio_chip *chip)
313+
{
314+
acpi_gpiochip_request_interrupts(chip);
315+
}
316+
317+
void acpi_gpiochip_remove(struct gpio_chip *chip)
318+
{
319+
acpi_gpiochip_free_interrupts(chip);
320+
}

‎drivers/gpio/gpiolib.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <linux/acpi.h>
1717
#include <linux/gpio/driver.h>
1818

19+
#include "gpiolib.h"
20+
1921
#define CREATE_TRACE_POINTS
2022
#include <trace/events/gpio.h>
2123

@@ -1226,6 +1228,7 @@ int gpiochip_add(struct gpio_chip *chip)
12261228
#endif
12271229

12281230
of_gpiochip_add(chip);
1231+
acpi_gpiochip_add(chip);
12291232

12301233
if (status)
12311234
goto fail;
@@ -1267,6 +1270,7 @@ int gpiochip_remove(struct gpio_chip *chip)
12671270

12681271
gpiochip_remove_pin_ranges(chip);
12691272
of_gpiochip_remove(chip);
1273+
acpi_gpiochip_remove(chip);
12701274

12711275
for (id = 0; id < chip->ngpio; id++) {
12721276
if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) {

‎drivers/gpio/gpiolib.h‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Internal GPIO functions.
3+
*
4+
* Copyright (C) 2013, Intel Corporation
5+
* Author: Mika Westerberg <mika.westerberg@linux.intel.com>
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License version 2 as
9+
* published by the Free Software Foundation.
10+
*/
11+
12+
#ifndef GPIOLIB_H
13+
#define GPIOLIB_H
14+
15+
#ifdef CONFIG_ACPI
16+
void acpi_gpiochip_add(struct gpio_chip *chip);
17+
void acpi_gpiochip_remove(struct gpio_chip *chip);
18+
#else
19+
static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
20+
static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
21+
#endif
22+
23+
#endif /* GPIOLIB_H */

‎drivers/pinctrl/pinctrl-baytrail.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <linux/gpio.h>
3030
#include <linux/irqdomain.h>
3131
#include <linux/acpi.h>
32-
#include <linux/acpi_gpio.h>
3332
#include <linux/platform_device.h>
3433
#include <linux/seq_file.h>
3534
#include <linux/io.h>
@@ -485,9 +484,6 @@ static int byt_gpio_probe(struct platform_device *pdev)
485484

486485
irq_set_handler_data(hwirq, vg);
487486
irq_set_chained_handler(hwirq, byt_gpio_irq_handler);
488-
489-
/* Register interrupt handlers for gpio signaled acpi events */
490-
acpi_gpiochip_request_interrupts(gc);
491487
}
492488

493489
pm_runtime_enable(dev);

‎include/linux/acpi_gpio.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ struct acpi_gpio_info {
2121

2222
struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
2323
struct acpi_gpio_info *info);
24-
void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
25-
void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
26-
2724
#else /* CONFIG_GPIO_ACPI */
2825

2926
static inline struct gpio_desc *
@@ -33,9 +30,6 @@ acpi_get_gpiod_by_index(struct device *dev, int index,
3330
return ERR_PTR(-ENOSYS);
3431
}
3532

36-
static inline void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { }
37-
static inline void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { }
38-
3933
#endif /* CONFIG_GPIO_ACPI */
4034

4135
static inline int acpi_get_gpio_by_index(struct device *dev, int index,

0 commit comments

Comments
 (0)