diff options
-rw-r--r-- | drivers/gpio/gpiolib-acpi.c | 51 | ||||
-rw-r--r-- | include/linux/acpi_gpio.h | 29 |
2 files changed, 43 insertions, 37 deletions
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 1745ce5983d6..03187d0a3045 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c | |||
@@ -11,7 +11,7 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/errno.h> | 13 | #include <linux/errno.h> |
14 | #include <linux/gpio.h> | 14 | #include <linux/gpio/consumer.h> |
15 | #include <linux/export.h> | 15 | #include <linux/export.h> |
16 | #include <linux/acpi_gpio.h> | 16 | #include <linux/acpi_gpio.h> |
17 | #include <linux/acpi.h> | 17 | #include <linux/acpi.h> |
@@ -33,14 +33,15 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) | |||
33 | } | 33 | } |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * acpi_get_gpio() - Translate ACPI GPIO pin to GPIO number usable with GPIO API | 36 | * acpi_get_gpiod() - Translate ACPI GPIO pin to GPIO descriptor usable with GPIO API |
37 | * @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1") | 37 | * @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1") |
38 | * @pin: ACPI GPIO pin number (0-based, controller-relative) | 38 | * @pin: ACPI GPIO pin number (0-based, controller-relative) |
39 | * | 39 | * |
40 | * Returns GPIO number to use with Linux generic GPIO API, or errno error value | 40 | * Returns GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR |
41 | * error value | ||
41 | */ | 42 | */ |
42 | 43 | ||
43 | int acpi_get_gpio(char *path, int pin) | 44 | static struct gpio_desc *acpi_get_gpiod(char *path, int pin) |
44 | { | 45 | { |
45 | struct gpio_chip *chip; | 46 | struct gpio_chip *chip; |
46 | acpi_handle handle; | 47 | acpi_handle handle; |
@@ -48,18 +49,17 @@ int acpi_get_gpio(char *path, int pin) | |||
48 | 49 | ||
49 | status = acpi_get_handle(NULL, path, &handle); | 50 | status = acpi_get_handle(NULL, path, &handle); |
50 | if (ACPI_FAILURE(status)) | 51 | if (ACPI_FAILURE(status)) |
51 | return -ENODEV; | 52 | return ERR_PTR(-ENODEV); |
52 | 53 | ||
53 | chip = gpiochip_find(handle, acpi_gpiochip_find); | 54 | chip = gpiochip_find(handle, acpi_gpiochip_find); |
54 | if (!chip) | 55 | if (!chip) |
55 | return -ENODEV; | 56 | return ERR_PTR(-ENODEV); |
56 | 57 | ||
57 | if (!gpio_is_valid(chip->base + pin)) | 58 | if (pin < 0 || pin > chip->ngpio) |
58 | return -EINVAL; | 59 | return ERR_PTR(-EINVAL); |
59 | 60 | ||
60 | return chip->base + pin; | 61 | return gpio_to_desc(chip->base + pin); |
61 | } | 62 | } |
62 | EXPORT_SYMBOL_GPL(acpi_get_gpio); | ||
63 | 63 | ||
64 | static irqreturn_t acpi_gpio_irq_handler(int irq, void *data) | 64 | static irqreturn_t acpi_gpio_irq_handler(int irq, void *data) |
65 | { | 65 | { |
@@ -235,7 +235,7 @@ EXPORT_SYMBOL(acpi_gpiochip_free_interrupts); | |||
235 | struct acpi_gpio_lookup { | 235 | struct acpi_gpio_lookup { |
236 | struct acpi_gpio_info info; | 236 | struct acpi_gpio_info info; |
237 | int index; | 237 | int index; |
238 | int gpio; | 238 | struct gpio_desc *desc; |
239 | int n; | 239 | int n; |
240 | }; | 240 | }; |
241 | 241 | ||
@@ -246,11 +246,11 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data) | |||
246 | if (ares->type != ACPI_RESOURCE_TYPE_GPIO) | 246 | if (ares->type != ACPI_RESOURCE_TYPE_GPIO) |
247 | return 1; | 247 | return 1; |
248 | 248 | ||
249 | if (lookup->n++ == lookup->index && lookup->gpio < 0) { | 249 | if (lookup->n++ == lookup->index && !lookup->desc) { |
250 | const struct acpi_resource_gpio *agpio = &ares->data.gpio; | 250 | const struct acpi_resource_gpio *agpio = &ares->data.gpio; |
251 | 251 | ||
252 | lookup->gpio = acpi_get_gpio(agpio->resource_source.string_ptr, | 252 | lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr, |
253 | agpio->pin_table[0]); | 253 | agpio->pin_table[0]); |
254 | lookup->info.gpioint = | 254 | lookup->info.gpioint = |
255 | agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT; | 255 | agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT; |
256 | } | 256 | } |
@@ -259,24 +259,24 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data) | |||
259 | } | 259 | } |
260 | 260 | ||
261 | /** | 261 | /** |
262 | * acpi_get_gpio_by_index() - get a GPIO number from device resources | 262 | * acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources |
263 | * @dev: pointer to a device to get GPIO from | 263 | * @dev: pointer to a device to get GPIO from |
264 | * @index: index of GpioIo/GpioInt resource (starting from %0) | 264 | * @index: index of GpioIo/GpioInt resource (starting from %0) |
265 | * @info: info pointer to fill in (optional) | 265 | * @info: info pointer to fill in (optional) |
266 | * | 266 | * |
267 | * Function goes through ACPI resources for @dev and based on @index looks | 267 | * Function goes through ACPI resources for @dev and based on @index looks |
268 | * up a GpioIo/GpioInt resource, translates it to the Linux GPIO number, | 268 | * up a GpioIo/GpioInt resource, translates it to the Linux GPIO descriptor, |
269 | * and returns it. @index matches GpioIo/GpioInt resources only so if there | 269 | * and returns it. @index matches GpioIo/GpioInt resources only so if there |
270 | * are total %3 GPIO resources, the index goes from %0 to %2. | 270 | * are total %3 GPIO resources, the index goes from %0 to %2. |
271 | * | 271 | * |
272 | * If the GPIO cannot be translated or there is an error, negative errno is | 272 | * If the GPIO cannot be translated or there is an error an ERR_PTR is |
273 | * returned. | 273 | * returned. |
274 | * | 274 | * |
275 | * Note: if the GPIO resource has multiple entries in the pin list, this | 275 | * Note: if the GPIO resource has multiple entries in the pin list, this |
276 | * function only returns the first. | 276 | * function only returns the first. |
277 | */ | 277 | */ |
278 | int acpi_get_gpio_by_index(struct device *dev, int index, | 278 | struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, |
279 | struct acpi_gpio_info *info) | 279 | struct acpi_gpio_info *info) |
280 | { | 280 | { |
281 | struct acpi_gpio_lookup lookup; | 281 | struct acpi_gpio_lookup lookup; |
282 | struct list_head resource_list; | 282 | struct list_head resource_list; |
@@ -285,27 +285,26 @@ int acpi_get_gpio_by_index(struct device *dev, int index, | |||
285 | int ret; | 285 | int ret; |
286 | 286 | ||
287 | if (!dev) | 287 | if (!dev) |
288 | return -EINVAL; | 288 | return ERR_PTR(-EINVAL); |
289 | 289 | ||
290 | handle = ACPI_HANDLE(dev); | 290 | handle = ACPI_HANDLE(dev); |
291 | if (!handle || acpi_bus_get_device(handle, &adev)) | 291 | if (!handle || acpi_bus_get_device(handle, &adev)) |
292 | return -ENODEV; | 292 | return ERR_PTR(-ENODEV); |
293 | 293 | ||
294 | memset(&lookup, 0, sizeof(lookup)); | 294 | memset(&lookup, 0, sizeof(lookup)); |
295 | lookup.index = index; | 295 | lookup.index = index; |
296 | lookup.gpio = -ENODEV; | ||
297 | 296 | ||
298 | INIT_LIST_HEAD(&resource_list); | 297 | INIT_LIST_HEAD(&resource_list); |
299 | ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio, | 298 | ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio, |
300 | &lookup); | 299 | &lookup); |
301 | if (ret < 0) | 300 | if (ret < 0) |
302 | return ret; | 301 | return ERR_PTR(ret); |
303 | 302 | ||
304 | acpi_dev_free_resource_list(&resource_list); | 303 | acpi_dev_free_resource_list(&resource_list); |
305 | 304 | ||
306 | if (lookup.gpio >= 0 && info) | 305 | if (lookup.desc && info) |
307 | *info = lookup.info; | 306 | *info = lookup.info; |
308 | 307 | ||
309 | return lookup.gpio; | 308 | return lookup.desc ? lookup.desc : ERR_PTR(-ENODEV); |
310 | } | 309 | } |
311 | EXPORT_SYMBOL_GPL(acpi_get_gpio_by_index); | 310 | EXPORT_SYMBOL_GPL(acpi_get_gpiod_by_index); |
diff --git a/include/linux/acpi_gpio.h b/include/linux/acpi_gpio.h index 4c120a1e0ca3..b6ce601e55a2 100644 --- a/include/linux/acpi_gpio.h +++ b/include/linux/acpi_gpio.h | |||
@@ -2,8 +2,10 @@ | |||
2 | #define _LINUX_ACPI_GPIO_H_ | 2 | #define _LINUX_ACPI_GPIO_H_ |
3 | 3 | ||
4 | #include <linux/device.h> | 4 | #include <linux/device.h> |
5 | #include <linux/err.h> | ||
5 | #include <linux/errno.h> | 6 | #include <linux/errno.h> |
6 | #include <linux/gpio.h> | 7 | #include <linux/gpio.h> |
8 | #include <linux/gpio/consumer.h> | ||
7 | 9 | ||
8 | /** | 10 | /** |
9 | * struct acpi_gpio_info - ACPI GPIO specific information | 11 | * struct acpi_gpio_info - ACPI GPIO specific information |
@@ -15,23 +17,18 @@ struct acpi_gpio_info { | |||
15 | 17 | ||
16 | #ifdef CONFIG_GPIO_ACPI | 18 | #ifdef CONFIG_GPIO_ACPI |
17 | 19 | ||
18 | int acpi_get_gpio(char *path, int pin); | 20 | struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, |
19 | int acpi_get_gpio_by_index(struct device *dev, int index, | 21 | struct acpi_gpio_info *info); |
20 | struct acpi_gpio_info *info); | ||
21 | void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); | 22 | void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); |
22 | void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); | 23 | void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); |
23 | 24 | ||
24 | #else /* CONFIG_GPIO_ACPI */ | 25 | #else /* CONFIG_GPIO_ACPI */ |
25 | 26 | ||
26 | static inline int acpi_get_gpio(char *path, int pin) | 27 | static inline struct gpio_desc * |
28 | acpi_get_gpiod_by_index(struct device *dev, int index, | ||
29 | struct acpi_gpio_info *info) | ||
27 | { | 30 | { |
28 | return -ENODEV; | 31 | return ERR_PTR(-ENOSYS); |
29 | } | ||
30 | |||
31 | static inline int acpi_get_gpio_by_index(struct device *dev, int index, | ||
32 | struct acpi_gpio_info *info) | ||
33 | { | ||
34 | return -ENODEV; | ||
35 | } | 32 | } |
36 | 33 | ||
37 | static inline void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { } | 34 | static inline void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { } |
@@ -39,4 +36,14 @@ static inline void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { } | |||
39 | 36 | ||
40 | #endif /* CONFIG_GPIO_ACPI */ | 37 | #endif /* CONFIG_GPIO_ACPI */ |
41 | 38 | ||
39 | static inline int acpi_get_gpio_by_index(struct device *dev, int index, | ||
40 | struct acpi_gpio_info *info) | ||
41 | { | ||
42 | struct gpio_desc *desc = acpi_get_gpiod_by_index(dev, index, info); | ||
43 | |||
44 | if (IS_ERR(desc)) | ||
45 | return PTR_ERR(desc); | ||
46 | return desc_to_gpio(desc); | ||
47 | } | ||
48 | |||
42 | #endif /* _LINUX_ACPI_GPIO_H_ */ | 49 | #endif /* _LINUX_ACPI_GPIO_H_ */ |