drivers/gpio/gpio-adp5585.c

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

File Facts

System
Linux kernel
Corpus path
drivers/gpio/gpio-adp5585.c
Extension
.c
Size
16061 bytes
Lines
528
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 adp5585_gpio_chip {
	int (*bank)(unsigned int off);
	int (*bit)(unsigned int off);
	unsigned int debounce_dis_a;
	unsigned int rpull_cfg_a;
	unsigned int gpo_data_a;
	unsigned int gpo_out_a;
	unsigned int gpio_dir_a;
	unsigned int gpi_stat_a;
	unsigned int gpi_int_lvl_a;
	unsigned int gpi_ev_a;
	unsigned int gpi_ev_min;
	unsigned int gpi_ev_max;
	bool has_bias_hole;
};

struct adp5585_gpio_dev {
	struct gpio_chip gpio_chip;
	struct notifier_block nb;
	const struct adp5585_gpio_chip *info;
	struct regmap *regmap;
	unsigned long irq_mask;
	unsigned long irq_en;
	unsigned long irq_active_high;
	/* used for irqchip bus locking */
	struct mutex bus_lock;
};

static int adp5585_gpio_bank(unsigned int off)
{
	return ADP5585_BANK(off);
}

static int adp5585_gpio_bit(unsigned int off)
{
	return ADP5585_BIT(off);
}

static int adp5589_gpio_bank(unsigned int off)
{
	return ADP5589_BANK(off);
}

static int adp5589_gpio_bit(unsigned int off)
{
	return ADP5589_BIT(off);
}

static int adp5585_gpio_get_direction(struct gpio_chip *chip, unsigned int off)
{
	struct adp5585_gpio_dev *adp5585_gpio = gpiochip_get_data(chip);
	const struct adp5585_gpio_chip *info = adp5585_gpio->info;
	unsigned int val;

	regmap_read(adp5585_gpio->regmap, info->gpio_dir_a + info->bank(off), &val);

	return val & info->bit(off) ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
}

static int adp5585_gpio_direction_input(struct gpio_chip *chip, unsigned int off)
{
	struct adp5585_gpio_dev *adp5585_gpio = gpiochip_get_data(chip);
	const struct adp5585_gpio_chip *info = adp5585_gpio->info;

	return regmap_clear_bits(adp5585_gpio->regmap, info->gpio_dir_a + info->bank(off),
				 info->bit(off));
}

static int adp5585_gpio_direction_output(struct gpio_chip *chip, unsigned int off, int val)
{
	struct adp5585_gpio_dev *adp5585_gpio = gpiochip_get_data(chip);
	const struct adp5585_gpio_chip *info = adp5585_gpio->info;
	unsigned int bank = info->bank(off);
	unsigned int bit = info->bit(off);
	int ret;

	ret = regmap_update_bits(adp5585_gpio->regmap, info->gpo_data_a + bank,
				 bit, val ? bit : 0);
	if (ret)
		return ret;

	return regmap_set_bits(adp5585_gpio->regmap, info->gpio_dir_a + bank,
			       bit);
}

static int adp5585_gpio_get_value(struct gpio_chip *chip, unsigned int off)
{
	struct adp5585_gpio_dev *adp5585_gpio = gpiochip_get_data(chip);
	const struct adp5585_gpio_chip *info = adp5585_gpio->info;
	unsigned int bank = info->bank(off);

Annotation

Implementation Notes