staging:iio:adxrs450: Don't split string across multiple lines
[linux-2.6/btrfs-unstable.git] / drivers / gpio / gpiolib-acpi.c
blobcbad6e908d30e1d093d651232d425d3976d45864
1 /*
2 * ACPI helpers for GPIO API
4 * Copyright (C) 2012, Intel Corporation
5 * Authors: Mathias Nyman <mathias.nyman@linux.intel.com>
6 * Mika Westerberg <mika.westerberg@linux.intel.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/errno.h>
14 #include <linux/gpio.h>
15 #include <linux/export.h>
16 #include <linux/acpi_gpio.h>
17 #include <linux/acpi.h>
19 static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
21 if (!gc->dev)
22 return false;
24 return ACPI_HANDLE(gc->dev) == data;
27 /**
28 * acpi_get_gpio() - Translate ACPI GPIO pin to GPIO number usable with GPIO API
29 * @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
30 * @pin: ACPI GPIO pin number (0-based, controller-relative)
32 * Returns GPIO number to use with Linux generic GPIO API, or errno error value
35 int acpi_get_gpio(char *path, int pin)
37 struct gpio_chip *chip;
38 acpi_handle handle;
39 acpi_status status;
41 status = acpi_get_handle(NULL, path, &handle);
42 if (ACPI_FAILURE(status))
43 return -ENODEV;
45 chip = gpiochip_find(handle, acpi_gpiochip_find);
46 if (!chip)
47 return -ENODEV;
49 if (!gpio_is_valid(chip->base + pin))
50 return -EINVAL;
52 return chip->base + pin;
54 EXPORT_SYMBOL_GPL(acpi_get_gpio);