Commit 8ea0fa7c authored by Rodrigo Siqueira's avatar Rodrigo Siqueira Committed by Jonathan Cameron

staging:iio:ade7854: Remove read_reg_* duplications

The original code had a read function per data size; after updates, all
read functions tasks were centralized in a single function, but the old
signature was kept to maintain the module working without problems. This
patch removes a set of duplications associated with read_reg_*, and
update the areas that calling the old interface by the new one.
Signed-off-by: default avatarRodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent e6182b2d
...@@ -110,34 +110,6 @@ static int ade7854_i2c_read_reg(struct device *dev, ...@@ -110,34 +110,6 @@ static int ade7854_i2c_read_reg(struct device *dev,
return ret; return ret;
} }
static int ade7854_i2c_read_reg_8(struct device *dev,
u16 reg_address,
u8 *val)
{
return ade7854_i2c_read_reg(dev, reg_address, (u32 *)val, 8);
}
static int ade7854_i2c_read_reg_16(struct device *dev,
u16 reg_address,
u16 *val)
{
return ade7854_i2c_read_reg(dev, reg_address, (u32 *)val, 16);
}
static int ade7854_i2c_read_reg_24(struct device *dev,
u16 reg_address,
u32 *val)
{
return ade7854_i2c_read_reg(dev, reg_address, (u32 *)val, 24);
}
static int ade7854_i2c_read_reg_32(struct device *dev,
u16 reg_address,
u32 *val)
{
return ade7854_i2c_read_reg(dev, reg_address, (u32 *)val, 32);
}
static int ade7854_i2c_probe(struct i2c_client *client, static int ade7854_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
...@@ -149,10 +121,7 @@ static int ade7854_i2c_probe(struct i2c_client *client, ...@@ -149,10 +121,7 @@ static int ade7854_i2c_probe(struct i2c_client *client,
return -ENOMEM; return -ENOMEM;
st = iio_priv(indio_dev); st = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev); i2c_set_clientdata(client, indio_dev);
st->read_reg_8 = ade7854_i2c_read_reg_8; st->read_reg = ade7854_i2c_read_reg;
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 = ade7854_i2c_write_reg; st->write_reg = ade7854_i2c_write_reg;
st->i2c = client; st->i2c = client;
st->irq = client->irq; st->irq = client->irq;
......
...@@ -94,7 +94,7 @@ static int ade7854_spi_read_reg(struct device *dev, ...@@ -94,7 +94,7 @@ static int ade7854_spi_read_reg(struct device *dev,
st->tx[2] = reg_address & 0xFF; st->tx[2] = reg_address & 0xFF;
ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
if (ret) { if (ret < 0) {
dev_err(&st->spi->dev, "problem when reading register 0x%02X", dev_err(&st->spi->dev, "problem when reading register 0x%02X",
reg_address); reg_address);
goto unlock; goto unlock;
...@@ -120,34 +120,6 @@ static int ade7854_spi_read_reg(struct device *dev, ...@@ -120,34 +120,6 @@ static int ade7854_spi_read_reg(struct device *dev,
return ret; return ret;
} }
static int ade7854_spi_read_reg_8(struct device *dev,
u16 reg_address,
u8 *val)
{
return ade7854_spi_read_reg(dev, reg_address, (u32 *)val, 8);
}
static int ade7854_spi_read_reg_16(struct device *dev,
u16 reg_address,
u16 *val)
{
return ade7854_spi_read_reg(dev, reg_address, (u32 *)val, 16);
}
static int ade7854_spi_read_reg_24(struct device *dev,
u16 reg_address,
u32 *val)
{
return ade7854_spi_read_reg(dev, reg_address, (u32 *)val, 24);
}
static int ade7854_spi_read_reg_32(struct device *dev,
u16 reg_address,
u32 *val)
{
return ade7854_spi_read_reg(dev, reg_address, (u32 *)val, 32);
}
static int ade7854_spi_probe(struct spi_device *spi) static int ade7854_spi_probe(struct spi_device *spi)
{ {
struct ade7854_state *st; struct ade7854_state *st;
...@@ -158,10 +130,7 @@ static int ade7854_spi_probe(struct spi_device *spi) ...@@ -158,10 +130,7 @@ static int ade7854_spi_probe(struct spi_device *spi)
return -ENOMEM; return -ENOMEM;
st = iio_priv(indio_dev); st = iio_priv(indio_dev);
spi_set_drvdata(spi, indio_dev); spi_set_drvdata(spi, indio_dev);
st->read_reg_8 = ade7854_spi_read_reg_8; st->read_reg = ade7854_spi_read_reg;
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 = ade7854_spi_write_reg; st->write_reg = ade7854_spi_write_reg;
st->irq = spi->irq; st->irq = spi->irq;
st->spi = spi; st->spi = spi;
......
...@@ -27,12 +27,12 @@ static ssize_t ade7854_read_8bit(struct device *dev, ...@@ -27,12 +27,12 @@ static ssize_t ade7854_read_8bit(struct device *dev,
char *buf) char *buf)
{ {
int ret; int ret;
u8 val = 0; u32 val = 0;
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ade7854_state *st = iio_priv(indio_dev); struct ade7854_state *st = iio_priv(indio_dev);
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
ret = st->read_reg_8(dev, this_attr->address, &val); ret = st->read_reg(dev, this_attr->address, &val, 8);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -44,12 +44,12 @@ static ssize_t ade7854_read_16bit(struct device *dev, ...@@ -44,12 +44,12 @@ static ssize_t ade7854_read_16bit(struct device *dev,
char *buf) char *buf)
{ {
int ret; int ret;
u16 val = 0; u32 val = 0;
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ade7854_state *st = iio_priv(indio_dev); struct ade7854_state *st = iio_priv(indio_dev);
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
ret = st->read_reg_16(dev, this_attr->address, &val); ret = st->read_reg(dev, this_attr->address, &val, 16);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -66,7 +66,7 @@ static ssize_t ade7854_read_24bit(struct device *dev, ...@@ -66,7 +66,7 @@ static ssize_t ade7854_read_24bit(struct device *dev,
struct ade7854_state *st = iio_priv(indio_dev); struct ade7854_state *st = iio_priv(indio_dev);
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
ret = st->read_reg_24(dev, this_attr->address, &val); ret = st->read_reg(dev, this_attr->address, &val, 24);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -83,7 +83,7 @@ static ssize_t ade7854_read_32bit(struct device *dev, ...@@ -83,7 +83,7 @@ static ssize_t ade7854_read_32bit(struct device *dev,
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ade7854_state *st = iio_priv(indio_dev); struct ade7854_state *st = iio_priv(indio_dev);
ret = st->read_reg_32(dev, this_attr->address, &val); ret = st->read_reg(dev, this_attr->address, &val, 32);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -178,9 +178,9 @@ static int ade7854_reset(struct device *dev) ...@@ -178,9 +178,9 @@ static int ade7854_reset(struct device *dev)
{ {
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ade7854_state *st = iio_priv(indio_dev); struct ade7854_state *st = iio_priv(indio_dev);
u16 val; u32 val;
st->read_reg_16(dev, ADE7854_CONFIG, &val); st->read_reg(dev, ADE7854_CONFIG, &val, 16);
val |= BIT(7); /* Software Chip Reset */ val |= BIT(7); /* Software Chip Reset */
return st->write_reg(dev, ADE7854_CONFIG, val, 16); return st->write_reg(dev, ADE7854_CONFIG, val, 16);
...@@ -415,7 +415,7 @@ static int ade7854_set_irq(struct device *dev, bool enable) ...@@ -415,7 +415,7 @@ static int ade7854_set_irq(struct device *dev, bool enable)
int ret; int ret;
u32 irqen; u32 irqen;
ret = st->read_reg_32(dev, ADE7854_MASK0, &irqen); ret = st->read_reg(dev, ADE7854_MASK0, &irqen, 32);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -146,6 +146,7 @@ ...@@ -146,6 +146,7 @@
/** /**
* struct ade7854_state - device instance specific data * struct ade7854_state - device instance specific data
* @spi: actual spi_device * @spi: actual spi_device
* @read_reg Wrapper function for I2C and SPI read
* @write_reg Wrapper function for I2C and SPI write * @write_reg Wrapper function for I2C and SPI write
* @indio_dev: industrial I/O device structure * @indio_dev: industrial I/O device structure
* @buf_lock: mutex to protect tx and rx * @buf_lock: mutex to protect tx and rx
...@@ -155,10 +156,8 @@ ...@@ -155,10 +156,8 @@
struct ade7854_state { struct ade7854_state {
struct spi_device *spi; struct spi_device *spi;
struct i2c_client *i2c; struct i2c_client *i2c;
int (*read_reg_8)(struct device *dev, u16 reg_address, u8 *val); int (*read_reg)(struct device *dev, u16 reg_address, u32 *val,
int (*read_reg_16)(struct device *dev, u16 reg_address, u16 *val); int bits);
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)(struct device *dev, u16 reg_address, u32 val, int (*write_reg)(struct device *dev, u16 reg_address, u32 val,
int bits); int bits);
int irq; int irq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment