drivers/gpio/gpio-dwapb.c

Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-dwapb.c

File Facts

System
Linux kernel
Corpus path
drivers/gpio/gpio-dwapb.c
Extension
.c
Size
21655 bytes
Lines
850
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 dwapb_port_property {
	struct fwnode_handle *fwnode;
	unsigned int idx;
	unsigned int ngpio;
	unsigned int gpio_base;
	int irq[DWAPB_MAX_GPIOS];
};

struct dwapb_platform_data {
	unsigned int nports;
	struct dwapb_port_property properties[] __counted_by(nports);
};

/* Store GPIO context across system-wide suspend/resume transitions */
struct dwapb_context {
	u32 data;
	u32 dir;
	u32 ext;
	u32 int_en;
	u32 int_mask;
	u32 int_type;
	u32 int_pol;
	u32 int_deb;
	u32 wake_en;
};

struct dwapb_gpio_port_irqchip {
	unsigned int		nr_irqs;
	unsigned int		irq[DWAPB_MAX_GPIOS];
};

struct dwapb_gpio_port {
	struct gpio_generic_chip chip;
	struct dwapb_gpio_port_irqchip *pirq;
	struct dwapb_gpio	*gpio;
	struct dwapb_context	*ctx;
	unsigned int		idx;
};

static inline struct dwapb_gpio *to_dwapb_gpio(struct gpio_chip *gc)
{
	return container_of(to_gpio_generic_chip(gc),
			    struct dwapb_gpio_port, chip)->gpio;
}

struct dwapb_gpio {
	struct	device		*dev;
	void __iomem		*regs;
	unsigned int		nr_ports;
	unsigned int		flags;
	struct reset_control	*rst;
	struct clk_bulk_data	clks[DWAPB_NR_CLOCKS];
	struct dwapb_gpio_port	ports[] __counted_by(nr_ports);
};

static inline u32 gpio_reg_v2_convert(unsigned int offset)
{
	switch (offset) {
	case GPIO_INTMASK:
		return GPIO_INTMASK_V2;
	case GPIO_INTTYPE_LEVEL:
		return GPIO_INTTYPE_LEVEL_V2;
	case GPIO_INT_POLARITY:
		return GPIO_INT_POLARITY_V2;
	case GPIO_INTSTATUS:
		return GPIO_INTSTATUS_V2;
	case GPIO_PORTA_EOI:
		return GPIO_PORTA_EOI_V2;
	}

	return offset;
}

static inline u32 gpio_reg_convert(struct dwapb_gpio *gpio, unsigned int offset)
{
	if ((gpio->flags & GPIO_REG_OFFSET_MASK) == GPIO_REG_OFFSET_V2)
		return gpio_reg_v2_convert(offset);

	return offset;
}

static inline u32 dwapb_read(struct dwapb_gpio *gpio, unsigned int offset)
{
	struct gpio_generic_chip *chip = &gpio->ports[0].chip;
	void __iomem *reg_base = gpio->regs;

	return gpio_generic_read_reg(chip, reg_base + gpio_reg_convert(gpio, offset));
}

static inline void dwapb_write(struct dwapb_gpio *gpio, unsigned int offset,

Annotation

Implementation Notes