Source
x
MODULE_DESCRIPTION("Linear Technology LTC4306, LTC4305 I2C mux/switch driver");
// SPDX-License-Identifier: GPL-2.0-only
/*
* Linear Technology LTC4306 and LTC4305 I2C multiplexer/switch
*
* Copyright (C) 2017 Analog Devices Inc.
*
* Based on: i2c-mux-pca954x.c
*
* Datasheet: http://cds.linear.com/docs/en/datasheet/4306.pdf
*/
enum ltc_type {
ltc_4305,
ltc_4306,
};
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) ? true : false;
}
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 void ltc4306_gpio_set(struct gpio_chip *chip, unsigned int offset,
int value)
{
struct ltc4306 *data = gpiochip_get_data(chip);