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
)
24 return ACPI_HANDLE(gc
->dev
) == data
;
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
;
41 status
= acpi_get_handle(NULL
, path
, &handle
);
42 if (ACPI_FAILURE(status
))
45 chip
= gpiochip_find(handle
, acpi_gpiochip_find
);
49 if (!gpio_is_valid(chip
->base
+ pin
))
52 return chip
->base
+ pin
;
54 EXPORT_SYMBOL_GPL(acpi_get_gpio
);