This patchset consist of some initial patches for heading
towards the regmap implementation and also the final patch
which enables the driver to use regmap API thus removing
the redundant and common code.
Changes in v4
-Rebase against iio's testing branch. Previous series
was rebased against greg's testing branch.
Changes in v3
-Fetch the changes from remote and rebase to have it in
the current working directory.
Changes in v2
-Change the val_bits to 8 and add two more patches
having a different change before the final implemetation
of regmap.
Shreeya Patel (3):
Staging: iio: adt7316: Remove irq from bus structure
Staging: iio: adt7316: Remove multi read and write functions
Staging: iio: adt7316: Add regmap support
drivers/staging/iio/addac/adt7316-i2c.c | 97 ++-------------
drivers/staging/iio/addac/adt7316-spi.c | 95 +++------------
drivers/staging/iio/addac/adt7316.c | 149 ++++++++++++------------
drivers/staging/iio/addac/adt7316.h | 15 +--
4 files changed, 104 insertions(+), 252 deletions(-)
--
2.17.1
interrupt request is not needed to be present in the bus
structure. It is a good option to pass it as a parameter
in the probe function instead of having it in the bus structure.
Signed-off-by: Shreeya Patel <[email protected]>
---
drivers/staging/iio/addac/adt7316-i2c.c | 3 +--
drivers/staging/iio/addac/adt7316-spi.c | 4 ++--
drivers/staging/iio/addac/adt7316.c | 15 +++++++--------
drivers/staging/iio/addac/adt7316.h | 3 +--
4 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/drivers/staging/iio/addac/adt7316-i2c.c b/drivers/staging/iio/addac/adt7316-i2c.c
index 0f26bc38edc6..9dfe3be21849 100644
--- a/drivers/staging/iio/addac/adt7316-i2c.c
+++ b/drivers/staging/iio/addac/adt7316-i2c.c
@@ -99,14 +99,13 @@ static int adt7316_i2c_probe(struct i2c_client *client,
{
struct adt7316_bus bus = {
.client = client,
- .irq = client->irq,
.read = adt7316_i2c_read,
.write = adt7316_i2c_write,
.multi_read = adt7316_i2c_multi_read,
.multi_write = adt7316_i2c_multi_write,
};
- return adt7316_probe(&client->dev, &bus, id->name);
+ return adt7316_probe(&client->dev, &bus, id->name, client->irq);
}
static const struct i2c_device_id adt7316_i2c_id[] = {
diff --git a/drivers/staging/iio/addac/adt7316-spi.c b/drivers/staging/iio/addac/adt7316-spi.c
index 8294b9c1e3c2..ec4848acec9f 100644
--- a/drivers/staging/iio/addac/adt7316-spi.c
+++ b/drivers/staging/iio/addac/adt7316-spi.c
@@ -93,7 +93,6 @@ static int adt7316_spi_probe(struct spi_device *spi_dev)
{
struct adt7316_bus bus = {
.client = spi_dev,
- .irq = spi_dev->irq,
.read = adt7316_spi_read,
.write = adt7316_spi_write,
.multi_read = adt7316_spi_multi_read,
@@ -112,7 +111,8 @@ static int adt7316_spi_probe(struct spi_device *spi_dev)
adt7316_spi_write(spi_dev, 0, 0);
adt7316_spi_write(spi_dev, 0, 0);
- return adt7316_probe(&spi_dev->dev, &bus, spi_dev->modalias);
+ return adt7316_probe(&spi_dev->dev, &bus, spi_dev->modalias,
+ spi_dev->irq);
}
static const struct spi_device_id adt7316_spi_id[] = {
diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c
index 6f7891b567b9..7c4f84822c18 100644
--- a/drivers/staging/iio/addac/adt7316.c
+++ b/drivers/staging/iio/addac/adt7316.c
@@ -1799,12 +1799,12 @@ static irqreturn_t adt7316_event_handler(int irq, void *private)
return IRQ_HANDLED;
}
-static int adt7316_setup_irq(struct iio_dev *indio_dev)
+static int adt7316_setup_irq(struct iio_dev *indio_dev, int irq)
{
struct adt7316_chip_info *chip = iio_priv(indio_dev);
int irq_type, ret;
- irq_type = irqd_get_trigger_type(irq_get_irq_data(chip->bus.irq));
+ irq_type = irqd_get_trigger_type(irq_get_irq_data(irq));
switch (irq_type) {
case IRQF_TRIGGER_HIGH:
@@ -1820,13 +1820,12 @@ static int adt7316_setup_irq(struct iio_dev *indio_dev)
break;
}
- ret = devm_request_threaded_irq(&indio_dev->dev, chip->bus.irq,
+ ret = devm_request_threaded_irq(&indio_dev->dev, irq,
NULL, adt7316_event_handler,
irq_type | IRQF_ONESHOT,
indio_dev->name, indio_dev);
if (ret) {
- dev_err(&indio_dev->dev, "failed to request irq %d\n",
- chip->bus.irq);
+ dev_err(&indio_dev->dev, "failed to request irq %d\n", irq);
return ret;
}
@@ -2126,7 +2125,7 @@ static const struct iio_info adt7516_info = {
* device probe and remove
*/
int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
- const char *name)
+ const char *name, int irq)
{
struct adt7316_chip_info *chip;
struct iio_dev *indio_dev;
@@ -2179,8 +2178,8 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
indio_dev->name = name;
indio_dev->modes = INDIO_DIRECT_MODE;
- if (chip->bus.irq > 0) {
- ret = adt7316_setup_irq(indio_dev);
+ if (irq > 0) {
+ ret = adt7316_setup_irq(indio_dev, irq);
if (ret)
return ret;
}
diff --git a/drivers/staging/iio/addac/adt7316.h b/drivers/staging/iio/addac/adt7316.h
index 84ca4f6c88f5..03d5300a98cd 100644
--- a/drivers/staging/iio/addac/adt7316.h
+++ b/drivers/staging/iio/addac/adt7316.h
@@ -16,7 +16,6 @@
struct adt7316_bus {
void *client;
- int irq;
int (*read)(void *client, u8 reg, u8 *data);
int (*write)(void *client, u8 reg, u8 val);
int (*multi_read)(void *client, u8 first_reg, u8 count, u8 *data);
@@ -30,6 +29,6 @@ extern const struct dev_pm_ops adt7316_pm_ops;
#define ADT7316_PM_OPS NULL
#endif
int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
- const char *name);
+ const char *name, int irq);
#endif
--
2.17.1
Currently, adt7316 doesn't use multi read and multi write
functions hence remove the redundant code and make the
necessary changes in the code.
Signed-off-by: Shreeya Patel <[email protected]>
---
drivers/staging/iio/addac/adt7316-i2c.c | 40 -------------------------
drivers/staging/iio/addac/adt7316-spi.c | 31 ++++---------------
drivers/staging/iio/addac/adt7316.h | 2 --
3 files changed, 6 insertions(+), 67 deletions(-)
diff --git a/drivers/staging/iio/addac/adt7316-i2c.c b/drivers/staging/iio/addac/adt7316-i2c.c
index 9dfe3be21849..167eafe3dd8c 100644
--- a/drivers/staging/iio/addac/adt7316-i2c.c
+++ b/drivers/staging/iio/addac/adt7316-i2c.c
@@ -52,44 +52,6 @@ static int adt7316_i2c_write(void *client, u8 reg, u8 data)
return ret;
}
-static int adt7316_i2c_multi_read(void *client, u8 reg, u8 count, u8 *data)
-{
- struct i2c_client *cl = client;
- int i, ret;
-
- if (count > ADT7316_REG_MAX_ADDR)
- count = ADT7316_REG_MAX_ADDR;
-
- for (i = 0; i < count; i++) {
- ret = adt7316_i2c_read(cl, reg, &data[i]);
- if (ret < 0) {
- dev_err(&cl->dev, "I2C multi read error\n");
- return ret;
- }
- }
-
- return 0;
-}
-
-static int adt7316_i2c_multi_write(void *client, u8 reg, u8 count, u8 *data)
-{
- struct i2c_client *cl = client;
- int i, ret;
-
- if (count > ADT7316_REG_MAX_ADDR)
- count = ADT7316_REG_MAX_ADDR;
-
- for (i = 0; i < count; i++) {
- ret = adt7316_i2c_write(cl, reg, data[i]);
- if (ret < 0) {
- dev_err(&cl->dev, "I2C multi write error\n");
- return ret;
- }
- }
-
- return 0;
-}
-
/*
* device probe and remove
*/
@@ -101,8 +63,6 @@ static int adt7316_i2c_probe(struct i2c_client *client,
.client = client,
.read = adt7316_i2c_read,
.write = adt7316_i2c_write,
- .multi_read = adt7316_i2c_multi_read,
- .multi_write = adt7316_i2c_multi_write,
};
return adt7316_probe(&client->dev, &bus, id->name, client->irq);
diff --git a/drivers/staging/iio/addac/adt7316-spi.c b/drivers/staging/iio/addac/adt7316-spi.c
index ec4848acec9f..06c943c2cc01 100644
--- a/drivers/staging/iio/addac/adt7316-spi.c
+++ b/drivers/staging/iio/addac/adt7316-spi.c
@@ -23,15 +23,12 @@
* adt7316 register access by SPI
*/
-static int adt7316_spi_multi_read(void *client, u8 reg, u8 count, u8 *data)
+static int adt7316_spi_read(void *client, u8 reg, u8 *data)
{
struct spi_device *spi_dev = client;
u8 cmd[2];
int ret;
- if (count > ADT7316_REG_MAX_ADDR)
- count = ADT7316_REG_MAX_ADDR;
-
cmd[0] = ADT7316_SPI_CMD_WRITE;
cmd[1] = reg;
@@ -43,7 +40,7 @@ static int adt7316_spi_multi_read(void *client, u8 reg, u8 count, u8 *data)
cmd[0] = ADT7316_SPI_CMD_READ;
- ret = spi_write_then_read(spi_dev, cmd, 1, data, count);
+ ret = spi_write_then_read(spi_dev, cmd, 1, data, 1);
if (ret < 0) {
dev_err(&spi_dev->dev, "SPI read data error\n");
return ret;
@@ -52,21 +49,17 @@ static int adt7316_spi_multi_read(void *client, u8 reg, u8 count, u8 *data)
return 0;
}
-static int adt7316_spi_multi_write(void *client, u8 reg, u8 count, u8 *data)
+static int adt7316_spi_write(void *client, u8 reg, u8 val)
{
struct spi_device *spi_dev = client;
u8 buf[ADT7316_REG_MAX_ADDR + 2];
- int i, ret;
-
- if (count > ADT7316_REG_MAX_ADDR)
- count = ADT7316_REG_MAX_ADDR;
+ int ret = 0;
buf[0] = ADT7316_SPI_CMD_WRITE;
buf[1] = reg;
- for (i = 0; i < count; i++)
- buf[i + 2] = data[i];
+ buf[2] = val;
- ret = spi_write(spi_dev, buf, count + 2);
+ ret = spi_write(spi_dev, buf, 3);
if (ret < 0) {
dev_err(&spi_dev->dev, "SPI write error\n");
return ret;
@@ -75,16 +68,6 @@ static int adt7316_spi_multi_write(void *client, u8 reg, u8 count, u8 *data)
return ret;
}
-static int adt7316_spi_read(void *client, u8 reg, u8 *data)
-{
- return adt7316_spi_multi_read(client, reg, 1, data);
-}
-
-static int adt7316_spi_write(void *client, u8 reg, u8 val)
-{
- return adt7316_spi_multi_write(client, reg, 1, &val);
-}
-
/*
* device probe and remove
*/
@@ -95,8 +78,6 @@ static int adt7316_spi_probe(struct spi_device *spi_dev)
.client = spi_dev,
.read = adt7316_spi_read,
.write = adt7316_spi_write,
- .multi_read = adt7316_spi_multi_read,
- .multi_write = adt7316_spi_multi_write,
};
/* don't exceed max specified SPI CLK frequency */
diff --git a/drivers/staging/iio/addac/adt7316.h b/drivers/staging/iio/addac/adt7316.h
index 03d5300a98cd..e9f288420234 100644
--- a/drivers/staging/iio/addac/adt7316.h
+++ b/drivers/staging/iio/addac/adt7316.h
@@ -18,8 +18,6 @@ struct adt7316_bus {
void *client;
int (*read)(void *client, u8 reg, u8 *data);
int (*write)(void *client, u8 reg, u8 val);
- int (*multi_read)(void *client, u8 first_reg, u8 count, u8 *data);
- int (*multi_write)(void *client, u8 first_reg, u8 count, u8 *data);
};
#ifdef CONFIG_PM_SLEEP
--
2.17.1
Both i2c and spi drivers have functions for reading and writing
to/from registers. Remove this redundant and common code by using
regmap API.
Signed-off-by: Shreeya Patel <[email protected]>
---
drivers/staging/iio/addac/adt7316-i2c.c | 56 +++-------
drivers/staging/iio/addac/adt7316-spi.c | 74 +++----------
drivers/staging/iio/addac/adt7316.c | 134 ++++++++++++------------
drivers/staging/iio/addac/adt7316.h | 10 +-
4 files changed, 95 insertions(+), 179 deletions(-)
diff --git a/drivers/staging/iio/addac/adt7316-i2c.c b/drivers/staging/iio/addac/adt7316-i2c.c
index 167eafe3dd8c..435b65845174 100644
--- a/drivers/staging/iio/addac/adt7316-i2c.c
+++ b/drivers/staging/iio/addac/adt7316-i2c.c
@@ -12,60 +12,28 @@
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/module.h>
+#include <linux/regmap.h>
#include "adt7316.h"
-/*
- * adt7316 register access by I2C
- */
-static int adt7316_i2c_read(void *client, u8 reg, u8 *data)
-{
- struct i2c_client *cl = client;
- int ret;
-
- ret = i2c_smbus_write_byte(cl, reg);
- if (ret < 0) {
- dev_err(&cl->dev, "I2C fail to select reg\n");
- return ret;
- }
-
- ret = i2c_smbus_read_byte(client);
- if (ret < 0) {
- dev_err(&cl->dev, "I2C read error\n");
- return ret;
- }
-
- *data = ret;
-
- return 0;
-}
-
-static int adt7316_i2c_write(void *client, u8 reg, u8 data)
-{
- struct i2c_client *cl = client;
- int ret;
-
- ret = i2c_smbus_write_byte_data(cl, reg, data);
- if (ret < 0)
- dev_err(&cl->dev, "I2C write error\n");
-
- return ret;
-}
-
/*
* device probe and remove
*/
-
static int adt7316_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
- struct adt7316_bus bus = {
- .client = client,
- .read = adt7316_i2c_read,
- .write = adt7316_i2c_write,
- };
+ struct regmap *regmap;
+
+ regmap = devm_regmap_init_i2c(client, &adt7316_regmap_config);
+
+ if (IS_ERR(regmap)) {
+ dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
+ PTR_ERR(regmap));
+ return PTR_ERR(regmap);
+ }
- return adt7316_probe(&client->dev, &bus, id->name, client->irq);
+ return adt7316_probe(&client->dev, regmap, id ? id->name : NULL,
+ client->irq);
}
static const struct i2c_device_id adt7316_i2c_id[] = {
diff --git a/drivers/staging/iio/addac/adt7316-spi.c b/drivers/staging/iio/addac/adt7316-spi.c
index 06c943c2cc01..203b5c3ada6e 100644
--- a/drivers/staging/iio/addac/adt7316-spi.c
+++ b/drivers/staging/iio/addac/adt7316-spi.c
@@ -11,74 +11,19 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
+#include <linux/regmap.h>
#include <linux/spi/spi.h>
#include "adt7316.h"
#define ADT7316_SPI_MAX_FREQ_HZ 5000000
-#define ADT7316_SPI_CMD_READ 0x91
-#define ADT7316_SPI_CMD_WRITE 0x90
-
-/*
- * adt7316 register access by SPI
- */
-
-static int adt7316_spi_read(void *client, u8 reg, u8 *data)
-{
- struct spi_device *spi_dev = client;
- u8 cmd[2];
- int ret;
-
- cmd[0] = ADT7316_SPI_CMD_WRITE;
- cmd[1] = reg;
-
- ret = spi_write(spi_dev, cmd, 2);
- if (ret < 0) {
- dev_err(&spi_dev->dev, "SPI fail to select reg\n");
- return ret;
- }
-
- cmd[0] = ADT7316_SPI_CMD_READ;
-
- ret = spi_write_then_read(spi_dev, cmd, 1, data, 1);
- if (ret < 0) {
- dev_err(&spi_dev->dev, "SPI read data error\n");
- return ret;
- }
-
- return 0;
-}
-
-static int adt7316_spi_write(void *client, u8 reg, u8 val)
-{
- struct spi_device *spi_dev = client;
- u8 buf[ADT7316_REG_MAX_ADDR + 2];
- int ret = 0;
-
- buf[0] = ADT7316_SPI_CMD_WRITE;
- buf[1] = reg;
- buf[2] = val;
-
- ret = spi_write(spi_dev, buf, 3);
- if (ret < 0) {
- dev_err(&spi_dev->dev, "SPI write error\n");
- return ret;
- }
-
- return ret;
-}
/*
* device probe and remove
*/
-
static int adt7316_spi_probe(struct spi_device *spi_dev)
{
- struct adt7316_bus bus = {
- .client = spi_dev,
- .read = adt7316_spi_read,
- .write = adt7316_spi_write,
- };
+ struct regmap *regmap;
/* don't exceed max specified SPI CLK frequency */
if (spi_dev->max_speed_hz > ADT7316_SPI_MAX_FREQ_HZ) {
@@ -87,12 +32,19 @@ static int adt7316_spi_probe(struct spi_device *spi_dev)
return -EINVAL;
}
+ regmap = devm_regmap_init_spi(spi_dev, &adt7316_regmap_config);
+ if (IS_ERR(regmap)) {
+ dev_err(&spi_dev->dev, "Error initializing spi regmap: %ld\n",
+ PTR_ERR(regmap));
+ return PTR_ERR(regmap);
+ }
+
/* switch from default I2C protocol to SPI protocol */
- adt7316_spi_write(spi_dev, 0, 0);
- adt7316_spi_write(spi_dev, 0, 0);
- adt7316_spi_write(spi_dev, 0, 0);
+ regmap_write(regmap, 0, 0);
+ regmap_write(regmap, 0, 0);
+ regmap_write(regmap, 0, 0);
- return adt7316_probe(&spi_dev->dev, &bus, spi_dev->modalias,
+ return adt7316_probe(&spi_dev->dev, regmap, spi_dev->modalias,
spi_dev->irq);
}
diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c
index 7c4f84822c18..922f827da8c4 100644
--- a/drivers/staging/iio/addac/adt7316.c
+++ b/drivers/staging/iio/addac/adt7316.c
@@ -17,6 +17,7 @@
#include <linux/list.h>
#include <linux/i2c.h>
#include <linux/rtc.h>
+#include <linux/regmap.h>
#include <linux/module.h>
#include <linux/iio/iio.h>
@@ -179,7 +180,7 @@
*/
struct adt7316_chip_info {
- struct adt7316_bus bus;
+ struct regmap *regmap;
struct gpio_desc *ldac_pin;
u16 int_mask; /* 0x2f */
u8 config1;
@@ -240,7 +241,7 @@ static ssize_t _adt7316_store_enabled(struct adt7316_chip_info *chip,
else
config1 = chip->config1 & ~ADT7316_EN;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG1, config1);
if (ret)
return -EIO;
@@ -304,7 +305,7 @@ static ssize_t adt7316_store_select_ex_temp(struct device *dev,
if (buf[0] == '1')
config1 |= ADT7516_SEL_EX_TEMP;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG1, config1);
if (ret)
return -EIO;
@@ -345,7 +346,7 @@ static ssize_t adt7316_store_mode(struct device *dev,
if (!memcmp(buf, "single_channel", 14))
config2 |= ADT7316_AD_SINGLE_CH_MODE;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG2, config2);
if (ret)
return -EIO;
@@ -438,7 +439,7 @@ static ssize_t adt7316_store_ad_channel(struct device *dev,
config2 |= data;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG2, config2);
if (ret)
return -EIO;
@@ -498,7 +499,7 @@ static ssize_t adt7316_store_disable_averaging(struct device *dev,
if (buf[0] == '1')
config2 |= ADT7316_DISABLE_AVERAGING;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG2, config2);
if (ret)
return -EIO;
@@ -537,7 +538,7 @@ static ssize_t adt7316_store_enable_smbus_timeout(struct device *dev,
if (buf[0] == '1')
config2 |= ADT7316_EN_SMBUS_TIMEOUT;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG2, config2);
if (ret)
return -EIO;
@@ -575,7 +576,7 @@ static ssize_t adt7316_store_powerdown(struct device *dev,
if (buf[0] == '1')
config1 |= ADT7316_PD;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG1, config1);
if (ret)
return -EIO;
@@ -613,7 +614,7 @@ static ssize_t adt7316_store_fast_ad_clock(struct device *dev,
if (buf[0] == '1')
config3 |= ADT7316_ADCLK_22_5;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG3, config3);
if (ret)
return -EIO;
@@ -659,7 +660,7 @@ static ssize_t adt7316_store_da_high_resolution(struct device *dev,
if (buf[0] == '1')
config3 |= ADT7316_DA_HIGH_RESOLUTION;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG3, config3);
if (ret)
return -EIO;
@@ -705,7 +706,7 @@ static ssize_t adt7316_store_AIN_internal_Vref(struct device *dev,
else
config3 = chip->config3 | ADT7516_AIN_IN_VREF;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG3, config3);
if (ret)
return -EIO;
@@ -744,7 +745,7 @@ static ssize_t adt7316_store_enable_prop_DACA(struct device *dev,
if (buf[0] == '1')
config3 |= ADT7316_EN_IN_TEMP_PROP_DACA;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG3, config3);
if (ret)
return -EIO;
@@ -783,7 +784,7 @@ static ssize_t adt7316_store_enable_prop_DACB(struct device *dev,
if (buf[0] == '1')
config3 |= ADT7316_EN_EX_TEMP_PROP_DACB;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG3, config3);
if (ret)
return -EIO;
@@ -826,7 +827,7 @@ static ssize_t adt7316_store_DAC_2Vref_ch_mask(struct device *dev,
dac_config = chip->dac_config & (~ADT7316_DA_2VREF_CH_MASK);
dac_config |= data;
- ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
+ ret = regmap_write(chip->regmap, ADT7316_DAC_CONFIG, dac_config);
if (ret)
return -EIO;
@@ -886,7 +887,7 @@ static ssize_t adt7316_store_DAC_update_mode(struct device *dev,
dac_config = chip->dac_config & (~ADT7316_DA_EN_MODE_MASK);
dac_config |= data << ADT7316_DA_EN_MODE_SHIFT;
- ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
+ ret = regmap_write(chip->regmap, ADT7316_DAC_CONFIG, dac_config);
if (ret)
return -EIO;
@@ -941,8 +942,8 @@ static ssize_t adt7316_store_update_DAC(struct device *dev,
ldac_config = chip->ldac_config & (~ADT7316_LDAC_EN_DA_MASK);
ldac_config |= data;
- ret = chip->bus.write(chip->bus.client, ADT7316_LDAC_CONFIG,
- ldac_config);
+ ret = regmap_write(chip->regmap, ADT7316_LDAC_CONFIG,
+ ldac_config);
if (ret)
return -EIO;
} else {
@@ -983,7 +984,7 @@ static ssize_t adt7316_store_DA_AB_Vref_bypass(struct device *dev,
if (buf[0] == '1')
dac_config |= ADT7316_VREF_BYPASS_DAC_AB;
- ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
+ ret = regmap_write(chip->regmap, ADT7316_DAC_CONFIG, dac_config);
if (ret)
return -EIO;
@@ -1022,7 +1023,7 @@ static ssize_t adt7316_store_DA_CD_Vref_bypass(struct device *dev,
if (buf[0] == '1')
dac_config |= ADT7316_VREF_BYPASS_DAC_CD;
- ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
+ ret = regmap_write(chip->regmap, ADT7316_DAC_CONFIG, dac_config);
if (ret)
return -EIO;
@@ -1082,8 +1083,7 @@ static ssize_t adt7316_store_DAC_internal_Vref(struct device *dev,
ldac_config = chip->ldac_config | ADT7316_DAC_IN_VREF;
}
- ret = chip->bus.write(chip->bus.client, ADT7316_LDAC_CONFIG,
- ldac_config);
+ ret = regmap_write(chip->regmap, ADT7316_LDAC_CONFIG, ldac_config);
if (ret)
return -EIO;
@@ -1101,7 +1101,7 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
int channel, char *buf)
{
u16 data;
- u8 msb, lsb;
+ unsigned int msb, lsb;
char sign = ' ';
int ret;
@@ -1111,13 +1111,12 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
switch (channel) {
case ADT7316_AD_SINGLE_CH_IN:
- ret = chip->bus.read(chip->bus.client,
- ADT7316_LSB_IN_TEMP_VDD, &lsb);
+ ret = regmap_read(chip->regmap, ADT7316_LSB_IN_TEMP_VDD, &lsb);
if (ret)
return -EIO;
- ret = chip->bus.read(chip->bus.client,
- ADT7316_AD_MSB_DATA_BASE + channel, &msb);
+ ret = regmap_read(chip->regmap,
+ ADT7316_AD_MSB_DATA_BASE + channel, &msb);
if (ret)
return -EIO;
@@ -1125,14 +1124,12 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
data |= lsb & ADT7316_LSB_IN_TEMP_MASK;
break;
case ADT7316_AD_SINGLE_CH_VDD:
- ret = chip->bus.read(chip->bus.client,
- ADT7316_LSB_IN_TEMP_VDD, &lsb);
+ ret = regmap_read(chip->regmap, ADT7316_LSB_IN_TEMP_VDD, &lsb);
if (ret)
return -EIO;
- ret = chip->bus.read(chip->bus.client,
-
- ADT7316_AD_MSB_DATA_BASE + channel, &msb);
+ ret = regmap_read(chip->regmap,
+ ADT7316_AD_MSB_DATA_BASE + channel, &msb);
if (ret)
return -EIO;
@@ -1140,13 +1137,12 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
data |= (lsb & ADT7316_LSB_VDD_MASK) >> ADT7316_LSB_VDD_OFFSET;
return sprintf(buf, "%d\n", data);
default: /* ex_temp and ain */
- ret = chip->bus.read(chip->bus.client,
- ADT7316_LSB_EX_TEMP_AIN, &lsb);
+ ret = regmap_read(chip->regmap, ADT7316_LSB_EX_TEMP_AIN, &lsb);
if (ret)
return -EIO;
- ret = chip->bus.read(chip->bus.client,
- ADT7316_AD_MSB_DATA_BASE + channel, &msb);
+ ret = regmap_read(chip->regmap,
+ ADT7316_AD_MSB_DATA_BASE + channel, &msb);
if (ret)
return -EIO;
@@ -1246,10 +1242,10 @@ static ssize_t adt7316_show_temp_offset(struct adt7316_chip_info *chip,
int offset_addr, char *buf)
{
int data;
- u8 val;
+ unsigned int val;
int ret;
- ret = chip->bus.read(chip->bus.client, offset_addr, &val);
+ ret = regmap_read(chip->regmap, offset_addr, &val);
if (ret)
return -EIO;
@@ -1278,7 +1274,7 @@ static ssize_t adt7316_store_temp_offset(struct adt7316_chip_info *chip,
val = (u8)data;
- ret = chip->bus.write(chip->bus.client, offset_addr, val);
+ ret = regmap_write(chip->regmap, offset_addr, val);
if (ret)
return -EIO;
@@ -1395,7 +1391,7 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip,
int channel, char *buf)
{
u16 data = 0;
- u8 msb, lsb, offset;
+ unsigned int msb, lsb, offset;
int ret;
if (channel >= ADT7316_DA_MSB_DATA_REGS ||
@@ -1408,14 +1404,14 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip,
offset = chip->dac_bits - 8;
if (chip->dac_bits > 8) {
- ret = chip->bus.read(chip->bus.client,
- ADT7316_DA_DATA_BASE + channel * 2, &lsb);
+ ret = regmap_read(chip->regmap,
+ ADT7316_DA_DATA_BASE + channel * 2, &lsb);
if (ret)
return -EIO;
}
- ret = chip->bus.read(chip->bus.client,
- ADT7316_DA_DATA_BASE + 1 + channel * 2, &msb);
+ ret = regmap_read(chip->regmap, ADT7316_DA_DATA_BASE + 1 + channel * 2,
+ &msb);
if (ret)
return -EIO;
@@ -1431,7 +1427,7 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip,
static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip,
int channel, const char *buf, size_t len)
{
- u8 msb, lsb, lsb_reg, offset;
+ unsigned int msb, lsb, lsb_reg, offset;
u16 data;
int ret;
@@ -1454,15 +1450,15 @@ static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip,
lsb_reg = lsb << ADT7316_DA_12_BIT_LSB_SHIFT;
else
lsb_reg = lsb << ADT7316_DA_10_BIT_LSB_SHIFT;
- ret = chip->bus.write(chip->bus.client,
- ADT7316_DA_DATA_BASE + channel * 2, lsb_reg);
+ ret = regmap_write(chip->regmap,
+ ADT7316_DA_DATA_BASE + channel * 2, lsb_reg);
if (ret)
return -EIO;
}
msb = data >> offset;
- ret = chip->bus.write(chip->bus.client,
- ADT7316_DA_DATA_BASE + 1 + channel * 2, msb);
+ ret = regmap_write(chip->regmap, ADT7316_DA_DATA_BASE + 1 + channel * 2,
+ msb);
if (ret)
return -EIO;
@@ -1571,10 +1567,10 @@ static ssize_t adt7316_show_device_id(struct device *dev,
{
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
- u8 id;
+ unsigned int id;
int ret;
- ret = chip->bus.read(chip->bus.client, ADT7316_DEVICE_ID, &id);
+ ret = regmap_read(chip->regmap, ADT7316_DEVICE_ID, &id);
if (ret)
return -EIO;
@@ -1589,10 +1585,10 @@ static ssize_t adt7316_show_manufactorer_id(struct device *dev,
{
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
- u8 id;
+ unsigned int id;
int ret;
- ret = chip->bus.read(chip->bus.client, ADT7316_MANUFACTURE_ID, &id);
+ ret = regmap_read(chip->regmap, ADT7316_MANUFACTURE_ID, &id);
if (ret)
return -EIO;
@@ -1608,10 +1604,10 @@ static ssize_t adt7316_show_device_rev(struct device *dev,
{
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
- u8 rev;
+ unsigned int rev;
int ret;
- ret = chip->bus.read(chip->bus.client, ADT7316_DEVICE_REV, &rev);
+ ret = regmap_read(chip->regmap, ADT7316_DEVICE_REV, &rev);
if (ret)
return -EIO;
@@ -1626,10 +1622,10 @@ static ssize_t adt7316_show_bus_type(struct device *dev,
{
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
- u8 stat;
+ unsigned int stat;
int ret;
- ret = chip->bus.read(chip->bus.client, ADT7316_SPI_LOCK_STAT, &stat);
+ ret = regmap_read(chip->regmap, ADT7316_SPI_LOCK_STAT, &stat);
if (ret)
return -EIO;
@@ -1732,11 +1728,11 @@ static irqreturn_t adt7316_event_handler(int irq, void *private)
{
struct iio_dev *indio_dev = private;
struct adt7316_chip_info *chip = iio_priv(indio_dev);
- u8 stat1, stat2;
+ unsigned int stat1, stat2;
int ret;
s64 time;
- ret = chip->bus.read(chip->bus.client, ADT7316_INT_STAT1, &stat1);
+ ret = regmap_read(chip->regmap, ADT7316_INT_STAT1, &stat1);
if (!ret) {
if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
stat1 &= 0x1F;
@@ -1785,7 +1781,7 @@ static irqreturn_t adt7316_event_handler(int irq, void *private)
IIO_EV_DIR_EITHER),
time);
}
- ret = chip->bus.read(chip->bus.client, ADT7316_INT_STAT2, &stat2);
+ ret = regmap_read(chip->regmap, ADT7316_INT_STAT2, &stat2);
if (!ret) {
if (stat2 & ADT7316_INT_MASK2_VDD)
iio_push_event(indio_dev,
@@ -1871,7 +1867,7 @@ static ssize_t adt7316_set_int_mask(struct device *dev,
else
mask = ADT7316_INT_MASK2_VDD; /* disable vdd int */
- ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK2, mask);
+ ret = regmap_write(chip->regmap, ADT7316_INT_MASK2, mask);
if (!ret) {
chip->int_mask &= ~ADT7316_VDD_INT_MASK;
chip->int_mask |= data & ADT7316_VDD_INT_MASK;
@@ -1885,7 +1881,7 @@ static ssize_t adt7316_set_int_mask(struct device *dev,
/* mask in reg is opposite, set 1 to disable */
mask = (~data) & ADT7316_TEMP_AIN_INT_MASK;
}
- ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK1, mask);
+ ret = regmap_write(chip->regmap, ADT7316_INT_MASK1, mask);
chip->int_mask = mask;
@@ -1899,7 +1895,7 @@ static inline ssize_t adt7316_show_ad_bound(struct device *dev,
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
- u8 val;
+ unsigned int val;
int data;
int ret;
@@ -1907,7 +1903,7 @@ static inline ssize_t adt7316_show_ad_bound(struct device *dev,
this_attr->address > ADT7316_EX_TEMP_LOW)
return -EPERM;
- ret = chip->bus.read(chip->bus.client, this_attr->address, &val);
+ ret = regmap_read(chip->regmap, this_attr->address, &val);
if (ret)
return -EIO;
@@ -1956,7 +1952,7 @@ static inline ssize_t adt7316_set_ad_bound(struct device *dev,
val = (u8)data;
- ret = chip->bus.write(chip->bus.client, this_attr->address, val);
+ ret = regmap_write(chip->regmap, this_attr->address, val);
if (ret)
return -EIO;
@@ -1987,7 +1983,7 @@ static ssize_t adt7316_set_int_enabled(struct device *dev,
if (buf[0] == '1')
config1 |= ADT7316_INT_EN;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG1, config1);
if (ret)
return -EIO;
@@ -2124,7 +2120,7 @@ static const struct iio_info adt7516_info = {
/*
* device probe and remove
*/
-int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
+int adt7316_probe(struct device *dev, struct regmap *regmap,
const char *name, int irq)
{
struct adt7316_chip_info *chip;
@@ -2138,7 +2134,7 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
/* this is only used for device removal purposes */
dev_set_drvdata(dev, indio_dev);
- chip->bus = *bus;
+ chip->regmap = regmap;
if (name[4] == '3')
chip->id = ID_ADT7316 + (name[6] - '6');
@@ -2184,11 +2180,11 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
return ret;
}
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, chip->config1);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG1, chip->config1);
if (ret)
return -EIO;
- ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, chip->config3);
+ ret = regmap_write(chip->regmap, ADT7316_CONFIG3, chip->config3);
if (ret)
return -EIO;
diff --git a/drivers/staging/iio/addac/adt7316.h b/drivers/staging/iio/addac/adt7316.h
index e9f288420234..0162d4026e88 100644
--- a/drivers/staging/iio/addac/adt7316.h
+++ b/drivers/staging/iio/addac/adt7316.h
@@ -11,13 +11,13 @@
#include <linux/types.h>
#include <linux/pm.h>
+#include <linux/regmap.h>
#define ADT7316_REG_MAX_ADDR 0x3F
-struct adt7316_bus {
- void *client;
- int (*read)(void *client, u8 reg, u8 *data);
- int (*write)(void *client, u8 reg, u8 val);
+static const struct regmap_config adt7316_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
};
#ifdef CONFIG_PM_SLEEP
@@ -26,7 +26,7 @@ extern const struct dev_pm_ops adt7316_pm_ops;
#else
#define ADT7316_PM_OPS NULL
#endif
-int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
+int adt7316_probe(struct device *dev, struct regmap *regmap,
const char *name, int irq);
#endif
--
2.17.1
On Sat, 26 Jan 2019 23:04:02 +0530
Shreeya Patel <[email protected]> wrote:
> Both i2c and spi drivers have functions for reading and writing
> to/from registers. Remove this redundant and common code by using
> regmap API.
>
> Signed-off-by: Shreeya Patel <[email protected]>
I hadn't previously looked closely at the spi side of things.
I'm afraid it is a long way from standard regmap style of spi.
It can be done through regmap, but only with custom handling.
This isn't too hard to do, take a look at how the code
deals with a standard spi regmap situation and modify it
to match yours. You basically just need the modified read
and write functions.
> ---
> drivers/staging/iio/addac/adt7316-i2c.c | 56 +++-------
> drivers/staging/iio/addac/adt7316-spi.c | 74 +++----------
> drivers/staging/iio/addac/adt7316.c | 134 ++++++++++++------------
> drivers/staging/iio/addac/adt7316.h | 10 +-
> 4 files changed, 95 insertions(+), 179 deletions(-)
>
> diff --git a/drivers/staging/iio/addac/adt7316-i2c.c b/drivers/staging/iio/addac/adt7316-i2c.c
> index 167eafe3dd8c..435b65845174 100644
> --- a/drivers/staging/iio/addac/adt7316-i2c.c
> +++ b/drivers/staging/iio/addac/adt7316-i2c.c
> @@ -12,60 +12,28 @@
> #include <linux/i2c.h>
> #include <linux/interrupt.h>
> #include <linux/module.h>
> +#include <linux/regmap.h>
>
> #include "adt7316.h"
>
> -/*
> - * adt7316 register access by I2C
> - */
> -static int adt7316_i2c_read(void *client, u8 reg, u8 *data)
> -{
> - struct i2c_client *cl = client;
> - int ret;
> -
> - ret = i2c_smbus_write_byte(cl, reg);
> - if (ret < 0) {
> - dev_err(&cl->dev, "I2C fail to select reg\n");
> - return ret;
> - }
> -
> - ret = i2c_smbus_read_byte(client);
> - if (ret < 0) {
> - dev_err(&cl->dev, "I2C read error\n");
> - return ret;
> - }
> -
> - *data = ret;
> -
> - return 0;
> -}
> -
> -static int adt7316_i2c_write(void *client, u8 reg, u8 data)
> -{
> - struct i2c_client *cl = client;
> - int ret;
> -
> - ret = i2c_smbus_write_byte_data(cl, reg, data);
> - if (ret < 0)
> - dev_err(&cl->dev, "I2C write error\n");
> -
> - return ret;
> -}
> -
> /*
> * device probe and remove
> */
> -
> static int adt7316_i2c_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> - struct adt7316_bus bus = {
> - .client = client,
> - .read = adt7316_i2c_read,
> - .write = adt7316_i2c_write,
> - };
> + struct regmap *regmap;
> +
> + regmap = devm_regmap_init_i2c(client, &adt7316_regmap_config);
> +
> + if (IS_ERR(regmap)) {
> + dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
> + PTR_ERR(regmap));
> + return PTR_ERR(regmap);
> + }
>
> - return adt7316_probe(&client->dev, &bus, id->name, client->irq);
> + return adt7316_probe(&client->dev, regmap, id ? id->name : NULL,
> + client->irq);
> }
>
> static const struct i2c_device_id adt7316_i2c_id[] = {
> diff --git a/drivers/staging/iio/addac/adt7316-spi.c b/drivers/staging/iio/addac/adt7316-spi.c
> index 06c943c2cc01..203b5c3ada6e 100644
> --- a/drivers/staging/iio/addac/adt7316-spi.c
> +++ b/drivers/staging/iio/addac/adt7316-spi.c
> @@ -11,74 +11,19 @@
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/interrupt.h>
> +#include <linux/regmap.h>
> #include <linux/spi/spi.h>
>
> #include "adt7316.h"
>
> #define ADT7316_SPI_MAX_FREQ_HZ 5000000
> -#define ADT7316_SPI_CMD_READ 0x91
> -#define ADT7316_SPI_CMD_WRITE 0x90
> -
> -/*
> - * adt7316 register access by SPI
> - */
> -
> -static int adt7316_spi_read(void *client, u8 reg, u8 *data)
> -{
> - struct spi_device *spi_dev = client;
> - u8 cmd[2];
> - int ret;
> -
> - cmd[0] = ADT7316_SPI_CMD_WRITE;
> - cmd[1] = reg;
> -
> - ret = spi_write(spi_dev, cmd, 2);
> - if (ret < 0) {
> - dev_err(&spi_dev->dev, "SPI fail to select reg\n");
> - return ret;
> - }
> -
> - cmd[0] = ADT7316_SPI_CMD_READ;
> -
> - ret = spi_write_then_read(spi_dev, cmd, 1, data, 1);
> - if (ret < 0) {
> - dev_err(&spi_dev->dev, "SPI read data error\n");
> - return ret;
> - }
This is very much non standard for regmap. You may need to define
your own entire regmap config for it. That may well still be
worth doing as you can take advantage of the caching etc that
regmap also gives, but it's not going to be totally trivial.
Take a look the other spi regmap options and you should see
this is not too hard to do.
The chip select has to deselect in the middle of the write sequence.
Figure 58 on the data sheet.
> -
> - return 0;
> -}
> -
> -static int adt7316_spi_write(void *client, u8 reg, u8 val)
> -{
> - struct spi_device *spi_dev = client;
> - u8 buf[ADT7316_REG_MAX_ADDR + 2];
> - int ret = 0;
> -
> - buf[0] = ADT7316_SPI_CMD_WRITE;
> - buf[1] = reg;
> - buf[2] = val;
This isn't a particularly standard regmap interface.
I'm fairly sure your config isn't equivalent to this.
You have reg_bits = 8 and val_bits = 8.
These result in an spi_write with the length of 2 and without the
CMD_WRITE bit being set.
So I think you need (you'll have to check)
static const struct regmap_config adt7316_regmap_config = {
.reg_bits = 16,
.val_bits = 8,
.write_flag_mask = ADT7316_SPI_CMD_WRITE,
.reg_format_endian = REGMAP_ENDIAN_BIG, /* I think.... - check this */
};
You will want to walk your way through the regmap code with the values you
put in the config and check it does the same thing as this original code.
> -
> - ret = spi_write(spi_dev, buf, 3);
> - if (ret < 0) {
> - dev_err(&spi_dev->dev, "SPI write error\n");
> - return ret;
> - }
> -
> - return ret;
> -}
>
> /*
> * device probe and remove
> */
> -
If I'm really nitpicking this whitespace change is unrelated
and shouldn't have been here. Not important though as obviously
trivial!
> static int adt7316_spi_probe(struct spi_device *spi_dev)
> {
> - struct adt7316_bus bus = {
> - .client = spi_dev,
> - .read = adt7316_spi_read,
> - .write = adt7316_spi_write,
> - };
> + struct regmap *regmap;
>
> /* don't exceed max specified SPI CLK frequency */
> if (spi_dev->max_speed_hz > ADT7316_SPI_MAX_FREQ_HZ) {
> @@ -87,12 +32,19 @@ static int adt7316_spi_probe(struct spi_device *spi_dev)
> return -EINVAL;
> }
>
> + regmap = devm_regmap_init_spi(spi_dev, &adt7316_regmap_config);
> + if (IS_ERR(regmap)) {
> + dev_err(&spi_dev->dev, "Error initializing spi regmap: %ld\n",
> + PTR_ERR(regmap));
> + return PTR_ERR(regmap);
> + }
> +
> /* switch from default I2C protocol to SPI protocol */
> - adt7316_spi_write(spi_dev, 0, 0);
> - adt7316_spi_write(spi_dev, 0, 0);
> - adt7316_spi_write(spi_dev, 0, 0);
> + regmap_write(regmap, 0, 0);
> + regmap_write(regmap, 0, 0);
> + regmap_write(regmap, 0, 0);
>
> - return adt7316_probe(&spi_dev->dev, &bus, spi_dev->modalias,
> + return adt7316_probe(&spi_dev->dev, regmap, spi_dev->modalias,
> spi_dev->irq);
> }
>
> diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c
> index 7c4f84822c18..922f827da8c4 100644
> --- a/drivers/staging/iio/addac/adt7316.c
> +++ b/drivers/staging/iio/addac/adt7316.c
> @@ -17,6 +17,7 @@
> #include <linux/list.h>
> #include <linux/i2c.h>
> #include <linux/rtc.h>
> +#include <linux/regmap.h>
> #include <linux/module.h>
>
> #include <linux/iio/iio.h>
> @@ -179,7 +180,7 @@
> */
>
> struct adt7316_chip_info {
> - struct adt7316_bus bus;
> + struct regmap *regmap;
> struct gpio_desc *ldac_pin;
> u16 int_mask; /* 0x2f */
> u8 config1;
> @@ -240,7 +241,7 @@ static ssize_t _adt7316_store_enabled(struct adt7316_chip_info *chip,
> else
> config1 = chip->config1 & ~ADT7316_EN;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG1, config1);
> if (ret)
> return -EIO;
>
> @@ -304,7 +305,7 @@ static ssize_t adt7316_store_select_ex_temp(struct device *dev,
> if (buf[0] == '1')
> config1 |= ADT7516_SEL_EX_TEMP;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG1, config1);
> if (ret)
> return -EIO;
>
> @@ -345,7 +346,7 @@ static ssize_t adt7316_store_mode(struct device *dev,
> if (!memcmp(buf, "single_channel", 14))
> config2 |= ADT7316_AD_SINGLE_CH_MODE;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG2, config2);
> if (ret)
> return -EIO;
>
> @@ -438,7 +439,7 @@ static ssize_t adt7316_store_ad_channel(struct device *dev,
>
> config2 |= data;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG2, config2);
> if (ret)
> return -EIO;
>
> @@ -498,7 +499,7 @@ static ssize_t adt7316_store_disable_averaging(struct device *dev,
> if (buf[0] == '1')
> config2 |= ADT7316_DISABLE_AVERAGING;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG2, config2);
> if (ret)
> return -EIO;
>
> @@ -537,7 +538,7 @@ static ssize_t adt7316_store_enable_smbus_timeout(struct device *dev,
> if (buf[0] == '1')
> config2 |= ADT7316_EN_SMBUS_TIMEOUT;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG2, config2);
> if (ret)
> return -EIO;
>
> @@ -575,7 +576,7 @@ static ssize_t adt7316_store_powerdown(struct device *dev,
> if (buf[0] == '1')
> config1 |= ADT7316_PD;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG1, config1);
> if (ret)
> return -EIO;
>
> @@ -613,7 +614,7 @@ static ssize_t adt7316_store_fast_ad_clock(struct device *dev,
> if (buf[0] == '1')
> config3 |= ADT7316_ADCLK_22_5;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG3, config3);
> if (ret)
> return -EIO;
>
> @@ -659,7 +660,7 @@ static ssize_t adt7316_store_da_high_resolution(struct device *dev,
> if (buf[0] == '1')
> config3 |= ADT7316_DA_HIGH_RESOLUTION;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG3, config3);
> if (ret)
> return -EIO;
>
> @@ -705,7 +706,7 @@ static ssize_t adt7316_store_AIN_internal_Vref(struct device *dev,
> else
> config3 = chip->config3 | ADT7516_AIN_IN_VREF;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG3, config3);
> if (ret)
> return -EIO;
>
> @@ -744,7 +745,7 @@ static ssize_t adt7316_store_enable_prop_DACA(struct device *dev,
> if (buf[0] == '1')
> config3 |= ADT7316_EN_IN_TEMP_PROP_DACA;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG3, config3);
> if (ret)
> return -EIO;
>
> @@ -783,7 +784,7 @@ static ssize_t adt7316_store_enable_prop_DACB(struct device *dev,
> if (buf[0] == '1')
> config3 |= ADT7316_EN_EX_TEMP_PROP_DACB;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG3, config3);
> if (ret)
> return -EIO;
>
> @@ -826,7 +827,7 @@ static ssize_t adt7316_store_DAC_2Vref_ch_mask(struct device *dev,
> dac_config = chip->dac_config & (~ADT7316_DA_2VREF_CH_MASK);
> dac_config |= data;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
> + ret = regmap_write(chip->regmap, ADT7316_DAC_CONFIG, dac_config);
> if (ret)
> return -EIO;
>
> @@ -886,7 +887,7 @@ static ssize_t adt7316_store_DAC_update_mode(struct device *dev,
> dac_config = chip->dac_config & (~ADT7316_DA_EN_MODE_MASK);
> dac_config |= data << ADT7316_DA_EN_MODE_SHIFT;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
> + ret = regmap_write(chip->regmap, ADT7316_DAC_CONFIG, dac_config);
> if (ret)
> return -EIO;
>
> @@ -941,8 +942,8 @@ static ssize_t adt7316_store_update_DAC(struct device *dev,
> ldac_config = chip->ldac_config & (~ADT7316_LDAC_EN_DA_MASK);
> ldac_config |= data;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_LDAC_CONFIG,
> - ldac_config);
> + ret = regmap_write(chip->regmap, ADT7316_LDAC_CONFIG,
> + ldac_config);
> if (ret)
> return -EIO;
> } else {
> @@ -983,7 +984,7 @@ static ssize_t adt7316_store_DA_AB_Vref_bypass(struct device *dev,
> if (buf[0] == '1')
> dac_config |= ADT7316_VREF_BYPASS_DAC_AB;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
> + ret = regmap_write(chip->regmap, ADT7316_DAC_CONFIG, dac_config);
> if (ret)
> return -EIO;
>
> @@ -1022,7 +1023,7 @@ static ssize_t adt7316_store_DA_CD_Vref_bypass(struct device *dev,
> if (buf[0] == '1')
> dac_config |= ADT7316_VREF_BYPASS_DAC_CD;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
> + ret = regmap_write(chip->regmap, ADT7316_DAC_CONFIG, dac_config);
> if (ret)
> return -EIO;
>
> @@ -1082,8 +1083,7 @@ static ssize_t adt7316_store_DAC_internal_Vref(struct device *dev,
> ldac_config = chip->ldac_config | ADT7316_DAC_IN_VREF;
> }
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_LDAC_CONFIG,
> - ldac_config);
> + ret = regmap_write(chip->regmap, ADT7316_LDAC_CONFIG, ldac_config);
> if (ret)
> return -EIO;
>
> @@ -1101,7 +1101,7 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
> int channel, char *buf)
> {
> u16 data;
> - u8 msb, lsb;
> + unsigned int msb, lsb;
> char sign = ' ';
> int ret;
>
> @@ -1111,13 +1111,12 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
>
> switch (channel) {
> case ADT7316_AD_SINGLE_CH_IN:
> - ret = chip->bus.read(chip->bus.client,
> - ADT7316_LSB_IN_TEMP_VDD, &lsb);
> + ret = regmap_read(chip->regmap, ADT7316_LSB_IN_TEMP_VDD, &lsb);
> if (ret)
> return -EIO;
>
> - ret = chip->bus.read(chip->bus.client,
> - ADT7316_AD_MSB_DATA_BASE + channel, &msb);
> + ret = regmap_read(chip->regmap,
> + ADT7316_AD_MSB_DATA_BASE + channel, &msb);
> if (ret)
> return -EIO;
>
> @@ -1125,14 +1124,12 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
> data |= lsb & ADT7316_LSB_IN_TEMP_MASK;
> break;
> case ADT7316_AD_SINGLE_CH_VDD:
> - ret = chip->bus.read(chip->bus.client,
> - ADT7316_LSB_IN_TEMP_VDD, &lsb);
> + ret = regmap_read(chip->regmap, ADT7316_LSB_IN_TEMP_VDD, &lsb);
> if (ret)
> return -EIO;
>
> - ret = chip->bus.read(chip->bus.client,
> -
> - ADT7316_AD_MSB_DATA_BASE + channel, &msb);
> + ret = regmap_read(chip->regmap,
> + ADT7316_AD_MSB_DATA_BASE + channel, &msb);
> if (ret)
> return -EIO;
>
> @@ -1140,13 +1137,12 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
> data |= (lsb & ADT7316_LSB_VDD_MASK) >> ADT7316_LSB_VDD_OFFSET;
> return sprintf(buf, "%d\n", data);
> default: /* ex_temp and ain */
> - ret = chip->bus.read(chip->bus.client,
> - ADT7316_LSB_EX_TEMP_AIN, &lsb);
> + ret = regmap_read(chip->regmap, ADT7316_LSB_EX_TEMP_AIN, &lsb);
> if (ret)
> return -EIO;
>
> - ret = chip->bus.read(chip->bus.client,
> - ADT7316_AD_MSB_DATA_BASE + channel, &msb);
> + ret = regmap_read(chip->regmap,
> + ADT7316_AD_MSB_DATA_BASE + channel, &msb);
> if (ret)
> return -EIO;
>
> @@ -1246,10 +1242,10 @@ static ssize_t adt7316_show_temp_offset(struct adt7316_chip_info *chip,
> int offset_addr, char *buf)
> {
> int data;
> - u8 val;
> + unsigned int val;
> int ret;
>
> - ret = chip->bus.read(chip->bus.client, offset_addr, &val);
> + ret = regmap_read(chip->regmap, offset_addr, &val);
> if (ret)
> return -EIO;
>
> @@ -1278,7 +1274,7 @@ static ssize_t adt7316_store_temp_offset(struct adt7316_chip_info *chip,
>
> val = (u8)data;
>
> - ret = chip->bus.write(chip->bus.client, offset_addr, val);
> + ret = regmap_write(chip->regmap, offset_addr, val);
> if (ret)
> return -EIO;
>
> @@ -1395,7 +1391,7 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip,
> int channel, char *buf)
> {
> u16 data = 0;
> - u8 msb, lsb, offset;
> + unsigned int msb, lsb, offset;
> int ret;
>
> if (channel >= ADT7316_DA_MSB_DATA_REGS ||
> @@ -1408,14 +1404,14 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip,
> offset = chip->dac_bits - 8;
>
> if (chip->dac_bits > 8) {
> - ret = chip->bus.read(chip->bus.client,
> - ADT7316_DA_DATA_BASE + channel * 2, &lsb);
> + ret = regmap_read(chip->regmap,
> + ADT7316_DA_DATA_BASE + channel * 2, &lsb);
> if (ret)
> return -EIO;
> }
>
> - ret = chip->bus.read(chip->bus.client,
> - ADT7316_DA_DATA_BASE + 1 + channel * 2, &msb);
> + ret = regmap_read(chip->regmap, ADT7316_DA_DATA_BASE + 1 + channel * 2,
> + &msb);
> if (ret)
> return -EIO;
>
> @@ -1431,7 +1427,7 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip,
> static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip,
> int channel, const char *buf, size_t len)
> {
> - u8 msb, lsb, lsb_reg, offset;
> + unsigned int msb, lsb, lsb_reg, offset;
> u16 data;
> int ret;
>
> @@ -1454,15 +1450,15 @@ static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip,
> lsb_reg = lsb << ADT7316_DA_12_BIT_LSB_SHIFT;
> else
> lsb_reg = lsb << ADT7316_DA_10_BIT_LSB_SHIFT;
> - ret = chip->bus.write(chip->bus.client,
> - ADT7316_DA_DATA_BASE + channel * 2, lsb_reg);
> + ret = regmap_write(chip->regmap,
> + ADT7316_DA_DATA_BASE + channel * 2, lsb_reg);
> if (ret)
> return -EIO;
> }
>
> msb = data >> offset;
> - ret = chip->bus.write(chip->bus.client,
> - ADT7316_DA_DATA_BASE + 1 + channel * 2, msb);
> + ret = regmap_write(chip->regmap, ADT7316_DA_DATA_BASE + 1 + channel * 2,
> + msb);
> if (ret)
> return -EIO;
>
> @@ -1571,10 +1567,10 @@ static ssize_t adt7316_show_device_id(struct device *dev,
> {
> struct iio_dev *dev_info = dev_to_iio_dev(dev);
> struct adt7316_chip_info *chip = iio_priv(dev_info);
> - u8 id;
> + unsigned int id;
> int ret;
>
> - ret = chip->bus.read(chip->bus.client, ADT7316_DEVICE_ID, &id);
> + ret = regmap_read(chip->regmap, ADT7316_DEVICE_ID, &id);
> if (ret)
> return -EIO;
>
> @@ -1589,10 +1585,10 @@ static ssize_t adt7316_show_manufactorer_id(struct device *dev,
> {
> struct iio_dev *dev_info = dev_to_iio_dev(dev);
> struct adt7316_chip_info *chip = iio_priv(dev_info);
> - u8 id;
> + unsigned int id;
> int ret;
>
> - ret = chip->bus.read(chip->bus.client, ADT7316_MANUFACTURE_ID, &id);
> + ret = regmap_read(chip->regmap, ADT7316_MANUFACTURE_ID, &id);
> if (ret)
> return -EIO;
>
> @@ -1608,10 +1604,10 @@ static ssize_t adt7316_show_device_rev(struct device *dev,
> {
> struct iio_dev *dev_info = dev_to_iio_dev(dev);
> struct adt7316_chip_info *chip = iio_priv(dev_info);
> - u8 rev;
> + unsigned int rev;
> int ret;
>
> - ret = chip->bus.read(chip->bus.client, ADT7316_DEVICE_REV, &rev);
> + ret = regmap_read(chip->regmap, ADT7316_DEVICE_REV, &rev);
> if (ret)
> return -EIO;
>
> @@ -1626,10 +1622,10 @@ static ssize_t adt7316_show_bus_type(struct device *dev,
> {
> struct iio_dev *dev_info = dev_to_iio_dev(dev);
> struct adt7316_chip_info *chip = iio_priv(dev_info);
> - u8 stat;
> + unsigned int stat;
> int ret;
>
> - ret = chip->bus.read(chip->bus.client, ADT7316_SPI_LOCK_STAT, &stat);
> + ret = regmap_read(chip->regmap, ADT7316_SPI_LOCK_STAT, &stat);
> if (ret)
> return -EIO;
>
> @@ -1732,11 +1728,11 @@ static irqreturn_t adt7316_event_handler(int irq, void *private)
> {
> struct iio_dev *indio_dev = private;
> struct adt7316_chip_info *chip = iio_priv(indio_dev);
> - u8 stat1, stat2;
> + unsigned int stat1, stat2;
> int ret;
> s64 time;
>
> - ret = chip->bus.read(chip->bus.client, ADT7316_INT_STAT1, &stat1);
> + ret = regmap_read(chip->regmap, ADT7316_INT_STAT1, &stat1);
> if (!ret) {
> if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
> stat1 &= 0x1F;
> @@ -1785,7 +1781,7 @@ static irqreturn_t adt7316_event_handler(int irq, void *private)
> IIO_EV_DIR_EITHER),
> time);
> }
> - ret = chip->bus.read(chip->bus.client, ADT7316_INT_STAT2, &stat2);
> + ret = regmap_read(chip->regmap, ADT7316_INT_STAT2, &stat2);
> if (!ret) {
> if (stat2 & ADT7316_INT_MASK2_VDD)
> iio_push_event(indio_dev,
> @@ -1871,7 +1867,7 @@ static ssize_t adt7316_set_int_mask(struct device *dev,
> else
> mask = ADT7316_INT_MASK2_VDD; /* disable vdd int */
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK2, mask);
> + ret = regmap_write(chip->regmap, ADT7316_INT_MASK2, mask);
> if (!ret) {
> chip->int_mask &= ~ADT7316_VDD_INT_MASK;
> chip->int_mask |= data & ADT7316_VDD_INT_MASK;
> @@ -1885,7 +1881,7 @@ static ssize_t adt7316_set_int_mask(struct device *dev,
> /* mask in reg is opposite, set 1 to disable */
> mask = (~data) & ADT7316_TEMP_AIN_INT_MASK;
> }
> - ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK1, mask);
> + ret = regmap_write(chip->regmap, ADT7316_INT_MASK1, mask);
>
> chip->int_mask = mask;
>
> @@ -1899,7 +1895,7 @@ static inline ssize_t adt7316_show_ad_bound(struct device *dev,
> struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
> struct iio_dev *dev_info = dev_to_iio_dev(dev);
> struct adt7316_chip_info *chip = iio_priv(dev_info);
> - u8 val;
> + unsigned int val;
> int data;
> int ret;
>
> @@ -1907,7 +1903,7 @@ static inline ssize_t adt7316_show_ad_bound(struct device *dev,
> this_attr->address > ADT7316_EX_TEMP_LOW)
> return -EPERM;
>
> - ret = chip->bus.read(chip->bus.client, this_attr->address, &val);
> + ret = regmap_read(chip->regmap, this_attr->address, &val);
> if (ret)
> return -EIO;
>
> @@ -1956,7 +1952,7 @@ static inline ssize_t adt7316_set_ad_bound(struct device *dev,
>
> val = (u8)data;
>
> - ret = chip->bus.write(chip->bus.client, this_attr->address, val);
> + ret = regmap_write(chip->regmap, this_attr->address, val);
> if (ret)
> return -EIO;
>
> @@ -1987,7 +1983,7 @@ static ssize_t adt7316_set_int_enabled(struct device *dev,
> if (buf[0] == '1')
> config1 |= ADT7316_INT_EN;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG1, config1);
> if (ret)
> return -EIO;
>
> @@ -2124,7 +2120,7 @@ static const struct iio_info adt7516_info = {
> /*
> * device probe and remove
> */
> -int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
> +int adt7316_probe(struct device *dev, struct regmap *regmap,
> const char *name, int irq)
> {
> struct adt7316_chip_info *chip;
> @@ -2138,7 +2134,7 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
> /* this is only used for device removal purposes */
> dev_set_drvdata(dev, indio_dev);
>
> - chip->bus = *bus;
> + chip->regmap = regmap;
>
> if (name[4] == '3')
> chip->id = ID_ADT7316 + (name[6] - '6');
> @@ -2184,11 +2180,11 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
> return ret;
> }
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, chip->config1);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG1, chip->config1);
> if (ret)
> return -EIO;
>
> - ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, chip->config3);
> + ret = regmap_write(chip->regmap, ADT7316_CONFIG3, chip->config3);
> if (ret)
> return -EIO;
>
> diff --git a/drivers/staging/iio/addac/adt7316.h b/drivers/staging/iio/addac/adt7316.h
> index e9f288420234..0162d4026e88 100644
> --- a/drivers/staging/iio/addac/adt7316.h
> +++ b/drivers/staging/iio/addac/adt7316.h
> @@ -11,13 +11,13 @@
>
> #include <linux/types.h>
> #include <linux/pm.h>
> +#include <linux/regmap.h>
>
> #define ADT7316_REG_MAX_ADDR 0x3F
>
> -struct adt7316_bus {
> - void *client;
> - int (*read)(void *client, u8 reg, u8 *data);
> - int (*write)(void *client, u8 reg, u8 val);
> +static const struct regmap_config adt7316_regmap_config = {
> + .reg_bits = 8,
> + .val_bits = 8,
> };
>
> #ifdef CONFIG_PM_SLEEP
> @@ -26,7 +26,7 @@ extern const struct dev_pm_ops adt7316_pm_ops;
> #else
> #define ADT7316_PM_OPS NULL
> #endif
> -int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
> +int adt7316_probe(struct device *dev, struct regmap *regmap,
> const char *name, int irq);
>
> #endif