diff options
author | Mika Westerberg <mika.westerberg@linux.intel.com> | 2013-10-10 04:01:08 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2013-10-19 17:30:51 -0400 |
commit | 936e15dd2128eb5aa71251766f1176552b45f43c (patch) | |
tree | 43443f12206375f6a1503c0924c7864ada8c67a4 /drivers/gpio | |
parent | bae48da237fcedd7ad09569025483b988635efb7 (diff) |
gpiolib / ACPI: convert to gpiod interfaces
The new GPIO descriptor based interface is now preferred over the old
integer based one. This patch converts the ACPI GPIO helpers to use this
new interface internally. In addition to that provide compatibility
function acpi_get_gpio_by_index() that converts the returned GPIO
descriptor to an integer.
We also drop acpi_get_gpio() as it is not used anywhere outside
gpiolib-acpi and even there we use acpi_get_gpiod() instead.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/gpiolib-acpi.c | 51 |
1 files changed, 25 insertions, 26 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); |