2018-09-25 07:08:48 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2014-01-08 10:40:54 +00:00
|
|
|
/*
|
|
|
|
* Internal GPIO functions.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013, Intel Corporation
|
|
|
|
* Author: Mika Westerberg <mika.westerberg@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GPIOLIB_H
|
|
|
|
#define GPIOLIB_H
|
|
|
|
|
2023-07-12 09:59:55 +00:00
|
|
|
#include <linux/cdev.h>
|
2014-01-08 10:40:56 +00:00
|
|
|
#include <linux/device.h>
|
2023-07-12 09:59:55 +00:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/gpio/consumer.h> /* for enum gpiod_flags */
|
|
|
|
#include <linux/gpio/driver.h>
|
2015-10-20 09:10:38 +00:00
|
|
|
#include <linux/module.h>
|
2023-07-05 07:42:19 +00:00
|
|
|
#include <linux/notifier.h>
|
2024-01-05 14:46:27 +00:00
|
|
|
#include <linux/srcu.h>
|
2014-01-08 10:40:56 +00:00
|
|
|
|
2019-11-27 08:42:47 +00:00
|
|
|
#define GPIOCHIP_NAME "gpiochip"
|
|
|
|
|
2015-10-20 09:10:38 +00:00
|
|
|
/**
|
|
|
|
* struct gpio_device - internal state container for GPIO devices
|
|
|
|
* @dev: the GPIO device struct
|
gpio: add a userspace chardev ABI for GPIOs
A new chardev that is to be used for userspace GPIO access is
added in this patch. It is intended to gradually replace the
horribly broken sysfs ABI.
Using a chardev has many upsides:
- All operations are per-gpiochip, which is the actual
device underlying the GPIOs, making us tie in to the
kernel device model properly.
- Hotpluggable GPIO controllers can come and go, as this
kind of problem has been know to userspace for character
devices since ages, and if a gpiochip handle is held in
userspace we know we will break something, whereas the
sysfs is stateless.
- The one-value-per-file rule of sysfs is really hard to
maintain when you want to twist more than one knob at a time,
for example have in-kernel APIs to switch several GPIO
lines at the same time, and this will be possible to do
with a single ioctl() from userspace, saving a lot of
context switching.
We also need to add a new bus type for GPIO. This is
necessary for example for userspace coldplug, where sysfs is
traversed to find the boot-time device nodes and create the
character devices in /dev.
This new chardev ABI is *non* *optional* and can be counted
on to be present in the future, emphasizing the preference
of this ABI.
The ABI only implements one single ioctl() to get the name
and number of GPIO lines of a chip. Even this is debatable:
see it as a minimal example for review. This ABI shall be
ruthlessly reviewed and etched in stone.
The old /sys/class/gpio is still optional to compile in,
but will be deprecated.
Unique device IDs are created using IDR, which is overkill
and insanely scalable, but also well tested.
Cc: Johan Hovold <johan@kernel.org>
Cc: Michael Welling <mwelling@ieee.org>
Cc: Markus Pargmann <mpa@pengutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2015-10-21 13:29:53 +00:00
|
|
|
* @chrdev: character device for the GPIO device
|
2022-11-28 19:00:54 +00:00
|
|
|
* @id: numerical ID number for the GPIO chip
|
2016-02-09 12:21:06 +00:00
|
|
|
* @mockdev: class device used by the deprecated sysfs interface (may be
|
|
|
|
* NULL)
|
2015-10-20 09:10:38 +00:00
|
|
|
* @owner: helps prevent removal of modules exporting active GPIOs
|
|
|
|
* @chip: pointer to the corresponding gpiochip, holding static
|
|
|
|
* data for this device
|
2016-02-09 12:51:59 +00:00
|
|
|
* @descs: array of ngpio descriptors.
|
gpio: reflect base and ngpio into gpio_device
Some information about the GPIO chip need to stay around also
after the gpio_chip has been removed and only the gpio_device
persist. The base and ngpio are such things, for example we
don't want a new chip arriving to overlap the number space
of a dangling gpio_device, and the chardev may still query
the device for the number of lines etc.
Note that the code that assigns base and insert gpio_device
into the global list no longer check for a missing gpio_chip:
we respect the number space allocated by any other gpio_device.
As a consequence of the gdev being referenced directly from
the gpio_desc, we need to verify it differently from all
in-kernel API calls that fall through to direct queries to
the gpio_chip vtable: we first check that desc is !NULL, then
that desc->gdev is !NULL, then, if desc->gdev->chip is NULL,
we *BAIL OUT* without any error, so as to manage the case
where operations are requested on a device that is gone.
These checks were non-uniform and partly missing in the past:
so to simplify: create the macros VALIDATE_DESC() that will
return -EINVAL if the desc or desc->gdev is missing and just
0 if the chip is gone, and conversely VALIDATE_DESC_VOID()
for the case where the function does not return an error.
By using these macros, we get warning messages about missing
gdev with reference to the right function in the kernel log.
Despite the macro business this simplifies the code and make
it more readable than if we copy/paste the same descriptor
checking code into all code ABI call sites (IMHO).
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2016-02-10 09:57:36 +00:00
|
|
|
* @ngpio: the number of GPIO lines on this GPIO device, equal to the size
|
|
|
|
* of the @descs array.
|
2024-01-27 21:14:15 +00:00
|
|
|
* @can_sleep: indicate whether the GPIO chip driver's callbacks can sleep
|
|
|
|
* implying that they cannot be used from atomic context
|
gpio: reflect base and ngpio into gpio_device
Some information about the GPIO chip need to stay around also
after the gpio_chip has been removed and only the gpio_device
persist. The base and ngpio are such things, for example we
don't want a new chip arriving to overlap the number space
of a dangling gpio_device, and the chardev may still query
the device for the number of lines etc.
Note that the code that assigns base and insert gpio_device
into the global list no longer check for a missing gpio_chip:
we respect the number space allocated by any other gpio_device.
As a consequence of the gdev being referenced directly from
the gpio_desc, we need to verify it differently from all
in-kernel API calls that fall through to direct queries to
the gpio_chip vtable: we first check that desc is !NULL, then
that desc->gdev is !NULL, then, if desc->gdev->chip is NULL,
we *BAIL OUT* without any error, so as to manage the case
where operations are requested on a device that is gone.
These checks were non-uniform and partly missing in the past:
so to simplify: create the macros VALIDATE_DESC() that will
return -EINVAL if the desc or desc->gdev is missing and just
0 if the chip is gone, and conversely VALIDATE_DESC_VOID()
for the case where the function does not return an error.
By using these macros, we get warning messages about missing
gdev with reference to the right function in the kernel log.
Despite the macro business this simplifies the code and make
it more readable than if we copy/paste the same descriptor
checking code into all code ABI call sites (IMHO).
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2016-02-10 09:57:36 +00:00
|
|
|
* @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned
|
|
|
|
* at device creation time.
|
2016-02-12 13:48:23 +00:00
|
|
|
* @label: a descriptive name for the GPIO device, such as the part number
|
|
|
|
* or name of the IP component in a System on Chip.
|
2016-02-11 10:37:48 +00:00
|
|
|
* @data: per-instance data assigned by the driver
|
2015-10-20 09:10:38 +00:00
|
|
|
* @list: links gpio_device:s together for traversal
|
2023-08-17 08:52:28 +00:00
|
|
|
* @line_state_notifier: used to notify subscribers about lines being
|
|
|
|
* requested, released or reconfigured
|
2023-08-17 11:59:05 +00:00
|
|
|
* @device_notifier: used to notify character device wait queues about the GPIO
|
|
|
|
* device being unregistered
|
2024-01-05 19:42:44 +00:00
|
|
|
* @srcu: protects the pointer to the underlying GPIO chip
|
2022-02-08 10:48:31 +00:00
|
|
|
* @pin_ranges: range of pins served by the GPIO driver
|
2015-10-20 09:10:38 +00:00
|
|
|
*
|
|
|
|
* This state container holds most of the runtime variable data
|
|
|
|
* for a GPIO device and can hold references and live on after the
|
|
|
|
* GPIO chip has been removed, if it is still being used from
|
|
|
|
* userspace.
|
|
|
|
*/
|
|
|
|
struct gpio_device {
|
|
|
|
struct device dev;
|
gpio: add a userspace chardev ABI for GPIOs
A new chardev that is to be used for userspace GPIO access is
added in this patch. It is intended to gradually replace the
horribly broken sysfs ABI.
Using a chardev has many upsides:
- All operations are per-gpiochip, which is the actual
device underlying the GPIOs, making us tie in to the
kernel device model properly.
- Hotpluggable GPIO controllers can come and go, as this
kind of problem has been know to userspace for character
devices since ages, and if a gpiochip handle is held in
userspace we know we will break something, whereas the
sysfs is stateless.
- The one-value-per-file rule of sysfs is really hard to
maintain when you want to twist more than one knob at a time,
for example have in-kernel APIs to switch several GPIO
lines at the same time, and this will be possible to do
with a single ioctl() from userspace, saving a lot of
context switching.
We also need to add a new bus type for GPIO. This is
necessary for example for userspace coldplug, where sysfs is
traversed to find the boot-time device nodes and create the
character devices in /dev.
This new chardev ABI is *non* *optional* and can be counted
on to be present in the future, emphasizing the preference
of this ABI.
The ABI only implements one single ioctl() to get the name
and number of GPIO lines of a chip. Even this is debatable:
see it as a minimal example for review. This ABI shall be
ruthlessly reviewed and etched in stone.
The old /sys/class/gpio is still optional to compile in,
but will be deprecated.
Unique device IDs are created using IDR, which is overkill
and insanely scalable, but also well tested.
Cc: Johan Hovold <johan@kernel.org>
Cc: Michael Welling <mwelling@ieee.org>
Cc: Markus Pargmann <mpa@pengutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2015-10-21 13:29:53 +00:00
|
|
|
struct cdev chrdev;
|
2022-11-28 19:00:54 +00:00
|
|
|
int id;
|
2016-02-09 12:21:06 +00:00
|
|
|
struct device *mockdev;
|
2015-10-20 09:10:38 +00:00
|
|
|
struct module *owner;
|
2024-01-23 11:01:10 +00:00
|
|
|
struct gpio_chip __rcu *chip;
|
2016-02-09 12:51:59 +00:00
|
|
|
struct gpio_desc *descs;
|
2024-02-21 21:31:56 +00:00
|
|
|
unsigned int base;
|
gpio: reflect base and ngpio into gpio_device
Some information about the GPIO chip need to stay around also
after the gpio_chip has been removed and only the gpio_device
persist. The base and ngpio are such things, for example we
don't want a new chip arriving to overlap the number space
of a dangling gpio_device, and the chardev may still query
the device for the number of lines etc.
Note that the code that assigns base and insert gpio_device
into the global list no longer check for a missing gpio_chip:
we respect the number space allocated by any other gpio_device.
As a consequence of the gdev being referenced directly from
the gpio_desc, we need to verify it differently from all
in-kernel API calls that fall through to direct queries to
the gpio_chip vtable: we first check that desc is !NULL, then
that desc->gdev is !NULL, then, if desc->gdev->chip is NULL,
we *BAIL OUT* without any error, so as to manage the case
where operations are requested on a device that is gone.
These checks were non-uniform and partly missing in the past:
so to simplify: create the macros VALIDATE_DESC() that will
return -EINVAL if the desc or desc->gdev is missing and just
0 if the chip is gone, and conversely VALIDATE_DESC_VOID()
for the case where the function does not return an error.
By using these macros, we get warning messages about missing
gdev with reference to the right function in the kernel log.
Despite the macro business this simplifies the code and make
it more readable than if we copy/paste the same descriptor
checking code into all code ABI call sites (IMHO).
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2016-02-10 09:57:36 +00:00
|
|
|
u16 ngpio;
|
2024-01-27 21:14:15 +00:00
|
|
|
bool can_sleep;
|
2017-12-13 11:25:19 +00:00
|
|
|
const char *label;
|
2016-02-11 10:37:48 +00:00
|
|
|
void *data;
|
2015-10-20 09:10:38 +00:00
|
|
|
struct list_head list;
|
2023-08-17 08:52:28 +00:00
|
|
|
struct blocking_notifier_head line_state_notifier;
|
2023-08-17 11:59:05 +00:00
|
|
|
struct blocking_notifier_head device_notifier;
|
2024-01-05 19:42:44 +00:00
|
|
|
struct srcu_struct srcu;
|
2016-02-11 10:03:06 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_PINCTRL
|
|
|
|
/*
|
|
|
|
* If CONFIG_PINCTRL is enabled, then gpio controllers can optionally
|
|
|
|
* describe the actual pin range which they serve in an SoC. This
|
|
|
|
* information would be used by pinctrl subsystem to configure
|
|
|
|
* corresponding pins for gpio usage.
|
|
|
|
*/
|
|
|
|
struct list_head pin_ranges;
|
|
|
|
#endif
|
2015-10-20 09:10:38 +00:00
|
|
|
};
|
|
|
|
|
2022-11-28 19:00:54 +00:00
|
|
|
static inline struct gpio_device *to_gpio_device(struct device *dev)
|
|
|
|
{
|
|
|
|
return container_of(dev, struct gpio_device, dev);
|
|
|
|
}
|
|
|
|
|
2015-02-11 16:27:55 +00:00
|
|
|
/* gpio suffixes used for ACPI and device tree lookup */
|
2018-07-09 18:47:27 +00:00
|
|
|
static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" };
|
2015-02-11 16:27:55 +00:00
|
|
|
|
2022-02-08 10:48:31 +00:00
|
|
|
/**
|
|
|
|
* struct gpio_array - Opaque descriptor for a structure of GPIO array attributes
|
|
|
|
*
|
|
|
|
* @desc: Array of pointers to the GPIO descriptors
|
|
|
|
* @size: Number of elements in desc
|
|
|
|
* @chip: Parent GPIO chip
|
|
|
|
* @get_mask: Get mask used in fastpath
|
|
|
|
* @set_mask: Set mask used in fastpath
|
|
|
|
* @invert_mask: Invert mask used in fastpath
|
|
|
|
*
|
|
|
|
* This structure is attached to struct gpiod_descs obtained from
|
|
|
|
* gpiod_get_array() and can be passed back to get/set array functions in order
|
|
|
|
* to activate fast processing path if applicable.
|
|
|
|
*/
|
2018-09-05 21:50:06 +00:00
|
|
|
struct gpio_array {
|
|
|
|
struct gpio_desc **desc;
|
|
|
|
unsigned int size;
|
|
|
|
struct gpio_chip *chip;
|
|
|
|
unsigned long *get_mask;
|
|
|
|
unsigned long *set_mask;
|
|
|
|
unsigned long invert_mask[];
|
|
|
|
};
|
|
|
|
|
2022-04-08 18:18:51 +00:00
|
|
|
#define for_each_gpio_desc(gc, desc) \
|
2022-04-08 18:18:50 +00:00
|
|
|
for (unsigned int __i = 0; \
|
|
|
|
__i < gc->ngpio && (desc = gpiochip_get_desc(gc, __i)); \
|
|
|
|
__i++) \
|
2022-04-08 18:18:51 +00:00
|
|
|
|
|
|
|
#define for_each_gpio_desc_with_flag(gc, desc, flag) \
|
|
|
|
for_each_gpio_desc(gc, desc) \
|
2022-02-01 15:27:56 +00:00
|
|
|
if (!test_bit(flag, &desc->flags)) {} else
|
|
|
|
|
2017-10-12 10:40:10 +00:00
|
|
|
int gpiod_get_array_value_complex(bool raw, bool can_sleep,
|
|
|
|
unsigned int array_size,
|
|
|
|
struct gpio_desc **desc_array,
|
2018-09-05 21:50:07 +00:00
|
|
|
struct gpio_array *array_info,
|
2018-09-05 21:50:05 +00:00
|
|
|
unsigned long *value_bitmap);
|
2018-05-21 17:57:07 +00:00
|
|
|
int gpiod_set_array_value_complex(bool raw, bool can_sleep,
|
2018-09-27 11:38:10 +00:00
|
|
|
unsigned int array_size,
|
|
|
|
struct gpio_desc **desc_array,
|
|
|
|
struct gpio_array *array_info,
|
|
|
|
unsigned long *value_bitmap);
|
2014-07-22 07:17:41 +00:00
|
|
|
|
2023-09-03 19:06:57 +00:00
|
|
|
int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
|
|
|
|
|
2023-08-21 14:18:27 +00:00
|
|
|
void gpiod_line_state_notify(struct gpio_desc *desc, unsigned long action);
|
2022-02-08 10:48:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct gpio_desc - Opaque descriptor for a GPIO
|
|
|
|
*
|
|
|
|
* @gdev: Pointer to the parent GPIO device
|
|
|
|
* @flags: Binary descriptor flags
|
|
|
|
* @label: Name of the consumer
|
|
|
|
* @name: Line name
|
|
|
|
* @hog: Pointer to the device node that hogs this line (if any)
|
2024-01-05 14:46:27 +00:00
|
|
|
* @srcu: SRCU struct protecting the label pointer.
|
2022-02-08 10:48:31 +00:00
|
|
|
*
|
|
|
|
* These are obtained using gpiod_get() and are preferable to the old
|
|
|
|
* integer-based handles.
|
|
|
|
*
|
|
|
|
* Contrary to integers, a pointer to a &struct gpio_desc is guaranteed to be
|
|
|
|
* valid until the GPIO is released.
|
|
|
|
*/
|
2014-07-01 05:45:15 +00:00
|
|
|
struct gpio_desc {
|
gpio: reflect base and ngpio into gpio_device
Some information about the GPIO chip need to stay around also
after the gpio_chip has been removed and only the gpio_device
persist. The base and ngpio are such things, for example we
don't want a new chip arriving to overlap the number space
of a dangling gpio_device, and the chardev may still query
the device for the number of lines etc.
Note that the code that assigns base and insert gpio_device
into the global list no longer check for a missing gpio_chip:
we respect the number space allocated by any other gpio_device.
As a consequence of the gdev being referenced directly from
the gpio_desc, we need to verify it differently from all
in-kernel API calls that fall through to direct queries to
the gpio_chip vtable: we first check that desc is !NULL, then
that desc->gdev is !NULL, then, if desc->gdev->chip is NULL,
we *BAIL OUT* without any error, so as to manage the case
where operations are requested on a device that is gone.
These checks were non-uniform and partly missing in the past:
so to simplify: create the macros VALIDATE_DESC() that will
return -EINVAL if the desc or desc->gdev is missing and just
0 if the chip is gone, and conversely VALIDATE_DESC_VOID()
for the case where the function does not return an error.
By using these macros, we get warning messages about missing
gdev with reference to the right function in the kernel log.
Despite the macro business this simplifies the code and make
it more readable than if we copy/paste the same descriptor
checking code into all code ABI call sites (IMHO).
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2016-02-10 09:57:36 +00:00
|
|
|
struct gpio_device *gdev;
|
2014-07-01 05:45:15 +00:00
|
|
|
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 */
|
2018-09-08 09:23:16 +00:00
|
|
|
#define FLAG_IRQ_IS_ENABLED 10 /* GPIO is connected to an enabled IRQ */
|
2015-02-02 17:44:44 +00:00
|
|
|
#define FLAG_IS_HOGGED 11 /* GPIO is hogged */
|
2017-11-30 03:55:24 +00:00
|
|
|
#define FLAG_TRANSITORY 12 /* GPIO may lose value in sleep or reset */
|
2019-02-07 16:28:58 +00:00
|
|
|
#define FLAG_PULL_UP 13 /* GPIO has pull up enabled */
|
|
|
|
#define FLAG_PULL_DOWN 14 /* GPIO has pull down enabled */
|
2019-11-05 02:04:25 +00:00
|
|
|
#define FLAG_BIAS_DISABLE 15 /* GPIO has pull disabled */
|
2020-09-28 00:27:56 +00:00
|
|
|
#define FLAG_EDGE_RISING 16 /* GPIO CDEV detects rising edge events */
|
|
|
|
#define FLAG_EDGE_FALLING 17 /* GPIO CDEV detects falling edge events */
|
2020-10-14 23:11:56 +00:00
|
|
|
#define FLAG_EVENT_CLOCK_REALTIME 18 /* GPIO CDEV reports REALTIME timestamps in events */
|
2022-04-22 20:52:16 +00:00
|
|
|
#define FLAG_EVENT_CLOCK_HTE 19 /* GPIO CDEV reports hardware timestamps in events */
|
2014-07-01 05:45:15 +00:00
|
|
|
|
2015-08-14 14:10:59 +00:00
|
|
|
/* Connection label */
|
2024-01-05 16:08:36 +00:00
|
|
|
const char __rcu *label;
|
2015-08-14 14:10:59 +00:00
|
|
|
/* Name of the GPIO */
|
|
|
|
const char *name;
|
2020-02-20 13:01:49 +00:00
|
|
|
#ifdef CONFIG_OF_DYNAMIC
|
|
|
|
struct device_node *hog;
|
|
|
|
#endif
|
2024-01-05 14:46:27 +00:00
|
|
|
struct srcu_struct srcu;
|
2014-07-01 05:45:15 +00:00
|
|
|
};
|
|
|
|
|
2020-10-21 14:25:28 +00:00
|
|
|
#define gpiod_not_found(desc) (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT)
|
|
|
|
|
2024-01-23 11:01:10 +00:00
|
|
|
struct gpio_chip_guard {
|
|
|
|
struct gpio_device *gdev;
|
|
|
|
struct gpio_chip *gc;
|
|
|
|
int idx;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_CLASS(gpio_chip_guard,
|
|
|
|
struct gpio_chip_guard,
|
|
|
|
srcu_read_unlock(&_T.gdev->srcu, _T.idx),
|
|
|
|
({
|
|
|
|
struct gpio_chip_guard _guard;
|
|
|
|
|
|
|
|
_guard.gdev = desc->gdev;
|
|
|
|
_guard.idx = srcu_read_lock(&_guard.gdev->srcu);
|
2024-02-14 08:44:18 +00:00
|
|
|
_guard.gc = srcu_dereference(_guard.gdev->chip,
|
|
|
|
&_guard.gdev->srcu);
|
2024-01-23 11:01:10 +00:00
|
|
|
|
|
|
|
_guard;
|
|
|
|
}),
|
|
|
|
struct gpio_desc *desc)
|
|
|
|
|
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);
|
2022-02-01 15:27:55 +00:00
|
|
|
|
|
|
|
static inline int gpiod_request_user(struct gpio_desc *desc, const char *label)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = gpiod_request(desc, label);
|
|
|
|
if (ret == -EPROBE_DEFER)
|
|
|
|
ret = -ENODEV;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-02-23 06:52:53 +00:00
|
|
|
struct gpio_desc *gpiod_find_and_request(struct device *consumer,
|
|
|
|
struct fwnode_handle *fwnode,
|
|
|
|
const char *con_id,
|
|
|
|
unsigned int idx,
|
|
|
|
enum gpiod_flags flags,
|
|
|
|
const char *label,
|
|
|
|
bool platform_lookup_allowed);
|
|
|
|
|
2017-05-23 17:03:16 +00:00
|
|
|
int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
|
|
|
|
unsigned long lflags, enum gpiod_flags dflags);
|
2020-11-09 20:53:23 +00:00
|
|
|
int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce);
|
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);
|
2023-07-11 15:12:48 +00:00
|
|
|
int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev);
|
2024-01-29 09:11:41 +00:00
|
|
|
const char *gpiod_get_label(struct gpio_desc *desc);
|
2014-07-01 05:45:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the GPIO number of the passed descriptor relative to its chip
|
|
|
|
*/
|
2017-07-11 14:41:43 +00:00
|
|
|
static inline int gpio_chip_hwgpio(const struct gpio_desc *desc)
|
2014-07-01 05:45:15 +00:00
|
|
|
{
|
gpio: reflect base and ngpio into gpio_device
Some information about the GPIO chip need to stay around also
after the gpio_chip has been removed and only the gpio_device
persist. The base and ngpio are such things, for example we
don't want a new chip arriving to overlap the number space
of a dangling gpio_device, and the chardev may still query
the device for the number of lines etc.
Note that the code that assigns base and insert gpio_device
into the global list no longer check for a missing gpio_chip:
we respect the number space allocated by any other gpio_device.
As a consequence of the gdev being referenced directly from
the gpio_desc, we need to verify it differently from all
in-kernel API calls that fall through to direct queries to
the gpio_chip vtable: we first check that desc is !NULL, then
that desc->gdev is !NULL, then, if desc->gdev->chip is NULL,
we *BAIL OUT* without any error, so as to manage the case
where operations are requested on a device that is gone.
These checks were non-uniform and partly missing in the past:
so to simplify: create the macros VALIDATE_DESC() that will
return -EINVAL if the desc or desc->gdev is missing and just
0 if the chip is gone, and conversely VALIDATE_DESC_VOID()
for the case where the function does not return an error.
By using these macros, we get warning messages about missing
gdev with reference to the right function in the kernel log.
Despite the macro business this simplifies the code and make
it more readable than if we copy/paste the same descriptor
checking code into all code ABI call sites (IMHO).
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2016-02-10 09:57:36 +00:00
|
|
|
return desc - &desc->gdev->descs[0];
|
2014-07-01 05:45:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* With descriptor prefix */
|
|
|
|
|
2024-01-05 16:08:36 +00:00
|
|
|
#define gpiod_err(desc, fmt, ...) \
|
|
|
|
do { \
|
|
|
|
scoped_guard(srcu, &desc->srcu) { \
|
|
|
|
pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), \
|
|
|
|
gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define gpiod_warn(desc, fmt, ...) \
|
|
|
|
do { \
|
|
|
|
scoped_guard(srcu, &desc->srcu) { \
|
|
|
|
pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), \
|
|
|
|
gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define gpiod_dbg(desc, fmt, ...) \
|
|
|
|
do { \
|
|
|
|
scoped_guard(srcu, &desc->srcu) { \
|
|
|
|
pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), \
|
|
|
|
gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2014-07-01 05:45:15 +00:00
|
|
|
|
|
|
|
/* With chip prefix */
|
|
|
|
|
2020-04-24 14:15:17 +00:00
|
|
|
#define chip_err(gc, fmt, ...) \
|
|
|
|
dev_err(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)
|
|
|
|
#define chip_warn(gc, fmt, ...) \
|
|
|
|
dev_warn(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)
|
|
|
|
#define chip_info(gc, fmt, ...) \
|
|
|
|
dev_info(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)
|
|
|
|
#define chip_dbg(gc, fmt, ...) \
|
|
|
|
dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)
|
2014-07-01 05:45:15 +00:00
|
|
|
|
2014-01-08 10:40:54 +00:00
|
|
|
#endif /* GPIOLIB_H */
|