drivers/gpio/gpiolib.h

Source file repositories/reference/linux-study-clean/drivers/gpio/gpiolib.h

File Facts

System
Linux kernel
Corpus path
drivers/gpio/gpiolib.h
Extension
.h
Size
10912 bytes
Lines
311
Domain
Driver Families
Bucket
drivers/gpio
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct gpio_device {
	struct device		dev;
	struct cdev		chrdev;
	int			id;
	struct module		*owner;
	struct gpio_chip __rcu	*chip;
	struct gpio_desc	*descs;
	unsigned long		*valid_mask;
	struct srcu_struct	desc_srcu;
	unsigned int		base;
	u16			ngpio;
	bool			can_sleep;
	const char		*label;
	void			*data;
	struct list_head        list;
	struct raw_notifier_head line_state_notifier;
	rwlock_t		line_state_lock;
	struct workqueue_struct	*line_state_wq;
	struct blocking_notifier_head device_notifier;
	struct srcu_struct	srcu;

#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
};

static inline struct gpio_device *to_gpio_device(struct device *dev)
{
	return container_of(dev, struct gpio_device, dev);
}

/* GPIO suffixes used for ACPI and device tree lookup */
extern const char *const gpio_suffixes[];

#define for_each_gpio_property_name(propname, con_id)					\
	for (const char * const *__suffixes = gpio_suffixes;				\
	     *__suffixes && ({								\
		const char *__gs = *__suffixes;						\
											\
		if (con_id)								\
			snprintf(propname, sizeof(propname), "%s-%s", con_id, __gs);	\
		else									\
			strscpy(propname, __gs);					\
		1;									\
	     });									\
	     __suffixes++)

/**
 * 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
 * @gdev:		Parent GPIO device
 * @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.
 */
struct gpio_array {
	struct gpio_desc	**desc;
	unsigned int		size;
	struct gpio_device	*gdev;
	unsigned long		*get_mask;
	unsigned long		*set_mask;
	unsigned long		invert_mask[];
};

#define for_each_gpio_desc(gc, desc)					\
	for (unsigned int __i = 0;					\
	     __i < gc->ngpio && (desc = gpiochip_get_desc(gc, __i));	\
	     __i++)							\

#define for_each_gpio_desc_with_flag(gc, desc, flag)			\
	for_each_gpio_desc(gc, desc)					\
		if (!test_bit(flag, &desc->flags)) {} else

int gpiod_get_array_value_complex(bool raw, bool can_sleep,
				  unsigned int array_size,
				  struct gpio_desc **desc_array,
				  struct gpio_array *array_info,
				  unsigned long *value_bitmap);

Annotation

Implementation Notes