drivers/gpio/gpio-ltc4283.c

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

File Facts

System
Linux kernel
Corpus path
drivers/gpio/gpio-ltc4283.c
Extension
.c
Size
5561 bytes
Lines
219
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 ltc4283_gpio {
	struct gpio_chip gpio_chip;
	struct regmap *regmap;
};

static int ltc4283_pgio_get_direction(const struct ltc4283_gpio *st, unsigned int off)
{
	unsigned int val;
	int ret;

	ret = regmap_read(st->regmap, LTC4283_PGIO_CONFIG, &val);
	if (ret)
		return ret;

	val = field_get(LTC4283_PGIO_CFG_MASK(off), val);
	if (val == LTC4283_PGIO_DIR_IN)
		return GPIO_LINE_DIRECTION_IN;

	return GPIO_LINE_DIRECTION_OUT;
}

static int ltc4283_gpio_get_direction(struct gpio_chip *gc, unsigned int off)
{
	struct ltc4283_gpio *st = gpiochip_get_data(gc);
	unsigned int val;
	int ret;

	if (off >= LTC4283_PGIOX_START_NR)
		return ltc4283_pgio_get_direction(st, off);

	ret = regmap_read(st->regmap, LTC4283_ADIO_CONFIG, &val);
	if (ret)
		return ret;

	if (val & LTC4283_ADIOX_CONFIG_MASK(off))
		return GPIO_LINE_DIRECTION_IN;

	return GPIO_LINE_DIRECTION_OUT;
}

static int ltc4283_gpio_direction_set(const struct ltc4283_gpio *st,
				      unsigned int off, bool input)
{
	if (off >= LTC4283_PGIOX_START_NR) {
		unsigned int val = LTC4283_PGIO_DIR_OUT;

		if (input)
			val = LTC4283_PGIO_DIR_IN;

		val = field_prep(LTC4283_PGIO_CFG_MASK(off), val);
		return regmap_update_bits(st->regmap, LTC4283_PGIO_CONFIG,
					  LTC4283_PGIO_CFG_MASK(off), val);
	}

	return regmap_update_bits(st->regmap, LTC4283_ADIO_CONFIG,
				  LTC4283_ADIOX_CONFIG_MASK(off),
				  field_prep(LTC4283_ADIOX_CONFIG_MASK(off), input));
}

static int __ltc4283_gpio_set_value(const struct ltc4283_gpio *st,
				    unsigned int off, int val)
{
	u32 reg = off < LTC4283_PGIOX_START_NR ? LTC4283_ADIO_CONFIG : LTC4283_PGIO_CONFIG_2;

	return regmap_update_bits(st->regmap, reg, BIT(off),
				  field_prep(BIT(off), !!val));
}

static int ltc4283_gpio_direction_input(struct gpio_chip *gc, unsigned int off)
{
	struct ltc4283_gpio *st = gpiochip_get_data(gc);

	return ltc4283_gpio_direction_set(st, off, true);
}

static int ltc4283_gpio_direction_output(struct gpio_chip *gc, unsigned int off, int val)
{
	struct ltc4283_gpio *st = gpiochip_get_data(gc);
	int ret;

	ret = ltc4283_gpio_direction_set(st, off, false);
	if (ret)
		return ret;

	return __ltc4283_gpio_set_value(st, off, val);
}

static int ltc4283_gpio_get_value(struct gpio_chip *gc, unsigned int off)
{
	struct ltc4283_gpio *st = gpiochip_get_data(gc);

Annotation

Implementation Notes