2014-01-08 10:40:54 +00:00
|
|
|
/*
|
|
|
|
* Internal GPIO functions.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013, Intel Corporation
|
|
|
|
* Author: 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GPIOLIB_H
|
|
|
|
#define GPIOLIB_H
|
|
|
|
|
2014-01-08 10:40:56 +00:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
|
2014-05-17 05:54:50 +00:00
|
|
|
enum of_gpio_flags;
|
|
|
|
|
2015-03-16 22:49:03 +00:00
|
|
|
struct acpi_device;
|
|
|
|
|
2014-01-08 10:40:56 +00:00
|
|
|
/**
|
|
|
|
* struct acpi_gpio_info - ACPI GPIO specific information
|
|
|
|
* @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
|
|
|
|
* @active_low: in case of @gpioint, the pin is active low
|
|
|
|
*/
|
|
|
|
struct acpi_gpio_info {
|
|
|
|
bool gpioint;
|
|
|
|
bool active_low;
|
|
|
|
};
|
|
|
|
|
2015-02-11 16:27:55 +00:00
|
|
|
/* gpio suffixes used for ACPI and device tree lookup */
|
|
|
|
static const char * const gpio_suffixes[] = { "gpios", "gpio" };
|
|
|
|
|
2014-01-08 10:40:54 +00:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
void acpi_gpiochip_add(struct gpio_chip *chip);
|
|
|
|
void acpi_gpiochip_remove(struct gpio_chip *chip);
|
2014-01-08 10:40:56 +00:00
|
|
|
|
2014-07-25 06:54:48 +00:00
|
|
|
void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
|
|
|
|
void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
|
|
|
|
|
gpio / ACPI: Add support for _DSD device properties
With release of ACPI 5.1 and _DSD method we can finally name GPIOs (and
other things as well) returned by _CRS. Previously we were only able to
use integer index to find the corresponding GPIO, which is pretty error
prone if the order changes.
With _DSD we can now query GPIOs using name instead of an integer index,
like the below example shows:
// Bluetooth device with reset and shutdown GPIOs
Device (BTH)
{
Name (_HID, ...)
Name (_CRS, ResourceTemplate ()
{
GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
"\\_SB.GPO0", 0, ResourceConsumer) {15}
GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
"\\_SB.GPO0", 0, ResourceConsumer) {27, 31}
})
Name (_DSD, Package ()
{
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package ()
{
Package () {"reset-gpio", Package() {^BTH, 1, 1, 0 }},
Package () {"shutdown-gpio", Package() {^BTH, 0, 0, 0 }},
}
})
}
The format of the supported GPIO property is:
Package () { "name", Package () { ref, index, pin, active_low }}
ref - The device that has _CRS containing GpioIo()/GpioInt() resources,
typically this is the device itself (BTH in our case).
index - Index of the GpioIo()/GpioInt() resource in _CRS starting from zero.
pin - Pin in the GpioIo()/GpioInt() resource. Typically this is zero.
active_low - If 1 the GPIO is marked as active_low.
Since ACPI GpioIo() resource does not have field saying whether it is
active low or high, the "active_low" argument can be used here. Setting
it to 1 marks the GPIO as active low.
In our Bluetooth example the "reset-gpio" refers to the second GpioIo()
resource, second pin in that resource with the GPIO number of 31.
This patch implements necessary support to gpiolib for extracting GPIOs
using _DSD device properties.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-10-29 14:41:01 +00:00
|
|
|
struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
|
|
|
|
const char *propname, int index,
|
2014-01-08 10:40:56 +00:00
|
|
|
struct acpi_gpio_info *info);
|
2015-08-27 02:42:33 +00:00
|
|
|
struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
|
|
|
|
const char *propname, int index,
|
|
|
|
struct acpi_gpio_info *info);
|
2015-02-11 16:27:58 +00:00
|
|
|
|
|
|
|
int acpi_gpio_count(struct device *dev, const char *con_id);
|
2015-11-11 19:45:30 +00:00
|
|
|
|
|
|
|
bool acpi_can_fallback_to_crs(struct acpi_device *adev, const char *con_id);
|
2014-01-08 10:40:54 +00:00
|
|
|
#else
|
|
|
|
static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
|
|
|
|
static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
|
2014-01-08 10:40:56 +00:00
|
|
|
|
2014-07-25 06:54:48 +00:00
|
|
|
static inline void
|
|
|
|
acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { }
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { }
|
|
|
|
|
2014-01-08 10:40:56 +00:00
|
|
|
static inline struct gpio_desc *
|
gpio / ACPI: Add support for _DSD device properties
With release of ACPI 5.1 and _DSD method we can finally name GPIOs (and
other things as well) returned by _CRS. Previously we were only able to
use integer index to find the corresponding GPIO, which is pretty error
prone if the order changes.
With _DSD we can now query GPIOs using name instead of an integer index,
like the below example shows:
// Bluetooth device with reset and shutdown GPIOs
Device (BTH)
{
Name (_HID, ...)
Name (_CRS, ResourceTemplate ()
{
GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
"\\_SB.GPO0", 0, ResourceConsumer) {15}
GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
"\\_SB.GPO0", 0, ResourceConsumer) {27, 31}
})
Name (_DSD, Package ()
{
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package ()
{
Package () {"reset-gpio", Package() {^BTH, 1, 1, 0 }},
Package () {"shutdown-gpio", Package() {^BTH, 0, 0, 0 }},
}
})
}
The format of the supported GPIO property is:
Package () { "name", Package () { ref, index, pin, active_low }}
ref - The device that has _CRS containing GpioIo()/GpioInt() resources,
typically this is the device itself (BTH in our case).
index - Index of the GpioIo()/GpioInt() resource in _CRS starting from zero.
pin - Pin in the GpioIo()/GpioInt() resource. Typically this is zero.
active_low - If 1 the GPIO is marked as active_low.
Since ACPI GpioIo() resource does not have field saying whether it is
active low or high, the "active_low" argument can be used here. Setting
it to 1 marks the GPIO as active low.
In our Bluetooth example the "reset-gpio" refers to the second GpioIo()
resource, second pin in that resource with the GPIO number of 31.
This patch implements necessary support to gpiolib for extracting GPIOs
using _DSD device properties.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-10-29 14:41:01 +00:00
|
|
|
acpi_get_gpiod_by_index(struct acpi_device *adev, const char *propname,
|
|
|
|
int index, struct acpi_gpio_info *info)
|
2014-01-08 10:40:56 +00:00
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
2015-08-27 02:42:33 +00:00
|
|
|
static inline struct gpio_desc *
|
|
|
|
acpi_node_get_gpiod(struct fwnode_handle *fwnode, const char *propname,
|
|
|
|
int index, struct acpi_gpio_info *info)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENXIO);
|
|
|
|
}
|
2015-02-11 16:27:58 +00:00
|
|
|
static inline int acpi_gpio_count(struct device *dev, const char *con_id)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2015-11-11 19:45:30 +00:00
|
|
|
|
|
|
|
static inline bool acpi_can_fallback_to_crs(struct acpi_device *adev,
|
|
|
|
const char *con_id)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-08 10:40:54 +00:00
|
|
|
#endif
|
|
|
|
|
2014-05-17 05:54:50 +00:00
|
|
|
struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
|
|
|
|
const char *list_name, int index, enum of_gpio_flags *flags);
|
|
|
|
|
2014-07-22 07:17:41 +00:00
|
|
|
struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, u16 hwnum);
|
|
|
|
|
2014-07-01 05:45:15 +00:00
|
|
|
extern struct spinlock gpio_lock;
|
|
|
|
extern struct list_head gpio_chips;
|
|
|
|
|
|
|
|
struct gpio_desc {
|
|
|
|
struct gpio_chip *chip;
|
|
|
|
unsigned long flags;
|
|
|
|
/* flag symbols are bit numbers */
|
|
|
|
#define FLAG_REQUESTED 0
|
|
|
|
#define FLAG_IS_OUT 1
|
|
|
|
#define FLAG_EXPORT 2 /* protected by sysfs_lock */
|
|
|
|
#define FLAG_SYSFS 3 /* exported via /sys/class/gpio/control */
|
|
|
|
#define FLAG_ACTIVE_LOW 6 /* value has active low */
|
|
|
|
#define FLAG_OPEN_DRAIN 7 /* Gpio is open drain type */
|
|
|
|
#define FLAG_OPEN_SOURCE 8 /* Gpio is open source type */
|
|
|
|
#define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */
|
2015-02-02 17:44:44 +00:00
|
|
|
#define FLAG_IS_HOGGED 11 /* GPIO is hogged */
|
2014-07-01 05:45:15 +00:00
|
|
|
|
2015-08-14 14:10:59 +00:00
|
|
|
/* Connection label */
|
2014-07-01 05:45:15 +00:00
|
|
|
const char *label;
|
2015-08-14 14:10:59 +00:00
|
|
|
/* Name of the GPIO */
|
|
|
|
const char *name;
|
2014-07-01 05:45:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int gpiod_request(struct gpio_desc *desc, const char *label);
|
|
|
|
void gpiod_free(struct gpio_desc *desc);
|
2015-02-02 17:44:44 +00:00
|
|
|
int gpiod_hog(struct gpio_desc *desc, const char *name,
|
|
|
|
unsigned long lflags, enum gpiod_flags dflags);
|
2014-07-01 05:45:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the GPIO number of the passed descriptor relative to its chip
|
|
|
|
*/
|
|
|
|
static int __maybe_unused gpio_chip_hwgpio(const struct gpio_desc *desc)
|
|
|
|
{
|
|
|
|
return desc - &desc->chip->desc[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* With descriptor prefix */
|
|
|
|
|
|
|
|
#define gpiod_emerg(desc, fmt, ...) \
|
|
|
|
pr_emerg("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\
|
|
|
|
##__VA_ARGS__)
|
|
|
|
#define gpiod_crit(desc, fmt, ...) \
|
|
|
|
pr_crit("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
|
|
|
|
##__VA_ARGS__)
|
|
|
|
#define gpiod_err(desc, fmt, ...) \
|
|
|
|
pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
|
|
|
|
##__VA_ARGS__)
|
|
|
|
#define gpiod_warn(desc, fmt, ...) \
|
|
|
|
pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
|
|
|
|
##__VA_ARGS__)
|
|
|
|
#define gpiod_info(desc, fmt, ...) \
|
|
|
|
pr_info("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
|
|
|
|
##__VA_ARGS__)
|
|
|
|
#define gpiod_dbg(desc, fmt, ...) \
|
|
|
|
pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\
|
|
|
|
##__VA_ARGS__)
|
|
|
|
|
|
|
|
/* With chip prefix */
|
|
|
|
|
|
|
|
#define chip_emerg(chip, fmt, ...) \
|
|
|
|
pr_emerg("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
|
|
|
|
#define chip_crit(chip, fmt, ...) \
|
|
|
|
pr_crit("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
|
|
|
|
#define chip_err(chip, fmt, ...) \
|
|
|
|
pr_err("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
|
|
|
|
#define chip_warn(chip, fmt, ...) \
|
|
|
|
pr_warn("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
|
|
|
|
#define chip_info(chip, fmt, ...) \
|
|
|
|
pr_info("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
|
|
|
|
#define chip_dbg(chip, fmt, ...) \
|
|
|
|
pr_debug("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#ifdef CONFIG_GPIO_SYSFS
|
|
|
|
|
2015-05-04 15:10:32 +00:00
|
|
|
int gpiochip_sysfs_register(struct gpio_chip *chip);
|
|
|
|
void gpiochip_sysfs_unregister(struct gpio_chip *chip);
|
2014-07-01 05:45:15 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2015-05-04 15:10:32 +00:00
|
|
|
static inline int gpiochip_sysfs_register(struct gpio_chip *chip)
|
2014-07-01 05:45:15 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-04 15:10:32 +00:00
|
|
|
static inline void gpiochip_sysfs_unregister(struct gpio_chip *chip)
|
2014-07-01 05:45:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_GPIO_SYSFS */
|
|
|
|
|
2014-01-08 10:40:54 +00:00
|
|
|
#endif /* GPIOLIB_H */
|