include/linux/gpio/generic.h

Source file repositories/reference/linux-study-clean/include/linux/gpio/generic.h

File Facts

System
Linux kernel
Corpus path
include/linux/gpio/generic.h
Extension
.h
Size
7207 bytes
Lines
197
Domain
Core OS
Bucket
Core Kernel Interface
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct gpio_generic_chip_config {
	struct device *dev;
	unsigned long sz;
	void __iomem *dat;
	void __iomem *set;
	void __iomem *clr;
	void __iomem *dirout;
	void __iomem *dirin;
	unsigned long flags;
};

/**
 * struct gpio_generic_chip - Generic GPIO chip implementation.
 * @gc: The underlying struct gpio_chip object, implementing low-level GPIO
 *      chip routines.
 * @read_reg: reader function for generic GPIO
 * @write_reg: writer function for generic GPIO
 * @be_bits: if the generic GPIO has big endian bit order (bit 31 is
 *           representing line 0, bit 30 is line 1 ... bit 0 is line 31) this
 *           is set to true by the generic GPIO core. It is for internal
 *           housekeeping only.
 * @reg_dat: data (in) register for generic GPIO
 * @reg_set: output set register (out=high) for generic GPIO
 * @reg_clr: output clear register (out=low) for generic GPIO
 * @reg_dir_out: direction out setting register for generic GPIO
 * @reg_dir_in: direction in setting register for generic GPIO
 * @dir_unreadable: indicates that the direction register(s) cannot be read and
 *                  we need to rely on out internal state tracking.
 * @pinctrl: the generic GPIO uses a pin control backend.
 * @bits: number of register bits used for a generic GPIO
 *        i.e. <register width> * 8
 * @lock: used to lock chip->sdata. Also, this is needed to keep
 *        shadowed and real data registers writes together.
 * @sdata: shadowed data register for generic GPIO to clear/set bits safely.
 * @sdir: shadowed direction register for generic GPIO to clear/set direction
 *        safely. A "1" in this word means the line is set as output.
 */
struct gpio_generic_chip {
	struct gpio_chip gc;
	unsigned long (*read_reg)(void __iomem *reg);
	void (*write_reg)(void __iomem *reg, unsigned long data);
	bool be_bits;
	void __iomem *reg_dat;
	void __iomem *reg_set;
	void __iomem *reg_clr;
	void __iomem *reg_dir_out;
	void __iomem *reg_dir_in;
	bool dir_unreadable;
	bool pinctrl;
	int bits;
	raw_spinlock_t lock;
	unsigned long sdata;
	unsigned long sdir;
};

static inline struct gpio_generic_chip *
to_gpio_generic_chip(struct gpio_chip *gc)
{
	return container_of(gc, struct gpio_generic_chip, gc);
}

int gpio_generic_chip_init(struct gpio_generic_chip *chip,
			   const struct gpio_generic_chip_config *cfg);

/**
 * gpio_generic_chip_set() - Set the GPIO line value of the generic GPIO chip.
 * @chip: Generic GPIO chip to use.
 * @offset: Hardware offset of the line to set.
 * @value: New GPIO line value.
 *
 * Some modules using the generic GPIO chip, need to set line values in their
 * direction setters but they don't have access to the gpio-mmio symbols so
 * they use the function pointer in struct gpio_chip directly. This is not
 * optimal and can lead to crashes at run-time in some instances. This wrapper
 * provides a safe interface for users.
 *
 * Returns: 0 on success, negative error number of failure.
 */
static inline int
gpio_generic_chip_set(struct gpio_generic_chip *chip, unsigned int offset,
		      int value)
{
	if (WARN_ON(!chip->gc.set))
		return -EOPNOTSUPP;

	return chip->gc.set(&chip->gc, offset, value);
}

/**
 * gpio_generic_read_reg() - Read a register using the underlying callback.

Annotation

Implementation Notes