return ret < 0 ? ret : 0;
}
-static int ade7854_i2c_write_reg_8(struct device *dev,
- u16 reg_address,
- u8 val)
-{
- return ade7854_i2c_write_reg(dev, reg_address, val, 8);
-}
-
-static int ade7854_i2c_write_reg_16(struct device *dev,
- u16 reg_address,
- u16 val)
-{
- return ade7854_i2c_write_reg(dev, reg_address, val, 16);
-}
-
-static int ade7854_i2c_write_reg_24(struct device *dev,
- u16 reg_address,
- u32 val)
-{
- return ade7854_i2c_write_reg(dev, reg_address, val, 24);
-}
-
-static int ade7854_i2c_write_reg_32(struct device *dev,
- u16 reg_address,
- u32 val)
-{
- return ade7854_i2c_write_reg(dev, reg_address, val, 32);
-}
-
static int ade7854_i2c_read_reg_8(struct device *dev,
u16 reg_address,
u8 *val)
st->read_reg_16 = ade7854_i2c_read_reg_16;
st->read_reg_24 = ade7854_i2c_read_reg_24;
st->read_reg_32 = ade7854_i2c_read_reg_32;
- st->write_reg_8 = ade7854_i2c_write_reg_8;
- st->write_reg_16 = ade7854_i2c_write_reg_16;
- st->write_reg_24 = ade7854_i2c_write_reg_24;
- st->write_reg_32 = ade7854_i2c_write_reg_32;
+ st->write_reg = ade7854_i2c_write_reg;
st->i2c = client;
st->irq = client->irq;
return ret;
}
-static int ade7854_spi_write_reg_8(struct device *dev,
- u16 reg_address,
- u8 val)
-{
- return ade7854_spi_write_reg(dev, reg_address, val, 8);
-}
-
-static int ade7854_spi_write_reg_16(struct device *dev,
- u16 reg_address,
- u16 val)
-{
- return ade7854_spi_write_reg(dev, reg_address, val, 16);
-}
-
-static int ade7854_spi_write_reg_24(struct device *dev,
- u16 reg_address,
- u32 val)
-{
- return ade7854_spi_write_reg(dev, reg_address, val, 24);
-}
-
-static int ade7854_spi_write_reg_32(struct device *dev,
- u16 reg_address,
- u32 val)
-{
- return ade7854_spi_write_reg(dev, reg_address, val, 32);
-}
-
static int ade7854_spi_read_reg_8(struct device *dev,
u16 reg_address,
u8 *val)
st->read_reg_16 = ade7854_spi_read_reg_16;
st->read_reg_24 = ade7854_spi_read_reg_24;
st->read_reg_32 = ade7854_spi_read_reg_32;
- st->write_reg_8 = ade7854_spi_write_reg_8;
- st->write_reg_16 = ade7854_spi_write_reg_16;
- st->write_reg_24 = ade7854_spi_write_reg_24;
- st->write_reg_32 = ade7854_spi_write_reg_32;
+ st->write_reg = ade7854_spi_write_reg;
st->irq = spi->irq;
st->spi = spi;
ret = kstrtou8(buf, 10, &val);
if (ret)
goto error_ret;
- ret = st->write_reg_8(dev, this_attr->address, val);
+ ret = st->write_reg(dev, this_attr->address, val, 8);
error_ret:
return ret ? ret : len;
ret = kstrtou16(buf, 10, &val);
if (ret)
goto error_ret;
- ret = st->write_reg_16(dev, this_attr->address, val);
+ ret = st->write_reg(dev, this_attr->address, val, 16);
error_ret:
return ret ? ret : len;
ret = kstrtou32(buf, 10, &val);
if (ret)
goto error_ret;
- ret = st->write_reg_24(dev, this_attr->address, val);
+ ret = st->write_reg(dev, this_attr->address, val, 24);
error_ret:
return ret ? ret : len;
ret = kstrtou32(buf, 10, &val);
if (ret)
goto error_ret;
- ret = st->write_reg_32(dev, this_attr->address, val);
+ ret = st->write_reg(dev, this_attr->address, val, 32);
error_ret:
return ret ? ret : len;
st->read_reg_16(dev, ADE7854_CONFIG, &val);
val |= BIT(7); /* Software Chip Reset */
- return st->write_reg_16(dev, ADE7854_CONFIG, val);
+ return st->write_reg(dev, ADE7854_CONFIG, val, 16);
}
static IIO_DEV_ATTR_AIGAIN(0644,
else
irqen &= ~BIT(17);
- return st->write_reg_32(dev, ADE7854_MASK0, irqen);
+ return st->write_reg(dev, ADE7854_MASK0, irqen, 32);
}
static int ade7854_initial_setup(struct iio_dev *indio_dev)
/**
* struct ade7854_state - device instance specific data
- * @spi: actual spi_device
+ * @spi: actual spi_device
+ * @write_reg Wrapper function for I2C and SPI write
* @indio_dev: industrial I/O device structure
* @buf_lock: mutex to protect tx and rx
* @tx: transmit buffer
int (*read_reg_16)(struct device *dev, u16 reg_address, u16 *val);
int (*read_reg_24)(struct device *dev, u16 reg_address, u32 *val);
int (*read_reg_32)(struct device *dev, u16 reg_address, u32 *val);
- int (*write_reg_8)(struct device *dev, u16 reg_address, u8 val);
- int (*write_reg_16)(struct device *dev, u16 reg_address, u16 val);
- int (*write_reg_24)(struct device *dev, u16 reg_address, u32 val);
- int (*write_reg_32)(struct device *dev, u16 reg_address, u32 val);
+ int (*write_reg)(struct device *dev, u16 reg_address, u32 val,
+ int bits);
int irq;
struct mutex buf_lock;
u8 tx[ADE7854_MAX_TX] ____cacheline_aligned;