-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* acpi-enumeration: spi / ACPI: add ACPI enumeration support gpio / ACPI: add ACPI support
- Loading branch information
Showing
5 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* ACPI helpers for GPIO API | ||
* | ||
* Copyright (C) 2012, Intel Corporation | ||
* Authors: Mathias Nyman <mathias.nyman@linux.intel.com> | ||
* Mika Westerberg <mika.westerberg@linux.intel.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
*/ | ||
|
||
#include <linux/errno.h> | ||
#include <linux/gpio.h> | ||
#include <linux/export.h> | ||
#include <linux/acpi_gpio.h> | ||
#include <linux/acpi.h> | ||
|
||
static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) | ||
{ | ||
if (!gc->dev) | ||
return false; | ||
|
||
return ACPI_HANDLE(gc->dev) == data; | ||
} | ||
|
||
/** | ||
* acpi_get_gpio() - Translate ACPI GPIO pin to GPIO number usable with GPIO API | ||
* @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1") | ||
* @pin: ACPI GPIO pin number (0-based, controller-relative) | ||
* | ||
* Returns GPIO number to use with Linux generic GPIO API, or errno error value | ||
*/ | ||
|
||
int acpi_get_gpio(char *path, int pin) | ||
{ | ||
struct gpio_chip *chip; | ||
acpi_handle handle; | ||
acpi_status status; | ||
|
||
status = acpi_get_handle(NULL, path, &handle); | ||
if (ACPI_FAILURE(status)) | ||
return -ENODEV; | ||
|
||
chip = gpiochip_find(handle, acpi_gpiochip_find); | ||
if (!chip) | ||
return -ENODEV; | ||
|
||
if (!gpio_is_valid(chip->base + pin)) | ||
return -EINVAL; | ||
|
||
return chip->base + pin; | ||
} | ||
EXPORT_SYMBOL_GPL(acpi_get_gpio); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef _LINUX_ACPI_GPIO_H_ | ||
#define _LINUX_ACPI_GPIO_H_ | ||
|
||
#include <linux/errno.h> | ||
|
||
#ifdef CONFIG_GPIO_ACPI | ||
|
||
int acpi_get_gpio(char *path, int pin); | ||
|
||
#else /* CONFIG_GPIO_ACPI */ | ||
|
||
static inline int acpi_get_gpio(char *path, int pin) | ||
{ | ||
return -ENODEV; | ||
} | ||
|
||
#endif /* CONFIG_GPIO_ACPI */ | ||
|
||
#endif /* _LINUX_ACPI_GPIO_H_ */ |