drivers/i2c/muxes/i2c-mux-ltc4306.c

Source file repositories/reference/linux-study-clean/drivers/i2c/muxes/i2c-mux-ltc4306.c

File Facts

System
Linux kernel
Corpus path
drivers/i2c/muxes/i2c-mux-ltc4306.c
Extension
.c
Size
7772 bytes
Lines
318
Domain
Driver Families
Bucket
drivers/i2c
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 chip_desc {
	u8 nchans;
	u8 num_gpios;
};

struct ltc4306 {
	struct regmap *regmap;
	struct gpio_chip gpiochip;
	const struct chip_desc *chip;
};

static const struct chip_desc chips[] = {
	[ltc_4305] = {
		.nchans = LTC4305_MAX_NCHANS,
	},
	[ltc_4306] = {
		.nchans = LTC4306_MAX_NCHANS,
		.num_gpios = 2,
	},
};

static bool ltc4306_is_volatile_reg(struct device *dev, unsigned int reg)
{
	return reg == LTC_REG_CONFIG;
}

static const struct regmap_config ltc4306_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.max_register = LTC_REG_SWITCH,
	.volatile_reg = ltc4306_is_volatile_reg,
	.cache_type = REGCACHE_FLAT,
};

static int ltc4306_gpio_get(struct gpio_chip *chip, unsigned int offset)
{
	struct ltc4306 *data = gpiochip_get_data(chip);
	unsigned int val;
	int ret;

	ret = regmap_read(data->regmap, LTC_REG_CONFIG, &val);
	if (ret < 0)
		return ret;

	return !!(val & BIT(1 - offset));
}

static int ltc4306_gpio_set(struct gpio_chip *chip, unsigned int offset,
			    int value)
{
	struct ltc4306 *data = gpiochip_get_data(chip);

	return regmap_update_bits(data->regmap, LTC_REG_CONFIG,
				  BIT(5 - offset), value ? BIT(5 - offset) : 0);
}

static int ltc4306_gpio_get_direction(struct gpio_chip *chip,
				      unsigned int offset)
{
	struct ltc4306 *data = gpiochip_get_data(chip);
	unsigned int val;
	int ret;

	ret = regmap_read(data->regmap, LTC_REG_MODE, &val);
	if (ret < 0)
		return ret;

	return !!(val & BIT(7 - offset));
}

static int ltc4306_gpio_direction_input(struct gpio_chip *chip,
					unsigned int offset)
{
	struct ltc4306 *data = gpiochip_get_data(chip);

	return regmap_update_bits(data->regmap, LTC_REG_MODE,
				  BIT(7 - offset), BIT(7 - offset));
}

static int ltc4306_gpio_direction_output(struct gpio_chip *chip,
					 unsigned int offset, int value)
{
	struct ltc4306 *data = gpiochip_get_data(chip);

	ltc4306_gpio_set(chip, offset, value);
	return regmap_update_bits(data->regmap, LTC_REG_MODE,
				  BIT(7 - offset), 0);
}

static int ltc4306_gpio_set_config(struct gpio_chip *chip,

Annotation

Implementation Notes