adt7316 regmap implementation
Subsystems (4)
v3 cover adt7316 regmap implementation
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 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 | 147 ++++++++++++------------ drivers/staging/iio/addac/adt7316.h | 15 +-- 4 files changed, 103 insertions(+), 251 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/3 Staging: iio: adt7316: Remove irq from bus structure
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.
--- 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(-)
drivers/staging/iio/addac/adt7316-i2c.c +1 -2
@@ -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[] = {
drivers/staging/iio/addac/adt7316-spi.c +2 -2
@@ -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[] = {
drivers/staging/iio/addac/adt7316.c +7 -8
@@ -1809,12 +1809,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 :
@@ -1830,13 +1830,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; }
@@ -2136,7 +2135,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;
@@ -2182,8 +2181,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; }
drivers/staging/iio/addac/adt7316.h +1 -2
@@ -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
Signature · 1 line
2.17.1
PATCH v3 2/3 Staging: iio: adt7316: Remove multi read and write functions
In reply to Shreeya PatelCurrently, adt7316 doesn't use multi read and multi write functions hence remove the redundant code and make the necessary changes in the code.
--- 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(-)
drivers/staging/iio/addac/adt7316-i2c.c +0 -40
@@ -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 =0 ; - -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 =0 ; - -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);
drivers/staging/iio/addac/adt7316-spi.c +6 -25
@@ -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 =0 ; -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 =0 ; - -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 */
drivers/staging/iio/addac/adt7316.h +0 -2
@@ -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
Signature · 1 line
2.17.1
PATCH v3 3/3 Staging: iio: adt7316: Add regmap support
In reply to Shreeya PatelBoth i2c and spi drivers have functions for reading and writing to/from registers. Remove this redundant and common code by using regmap API.
--- drivers/staging/iio/addac/adt7316-i2c.c | 56 +++------- drivers/staging/iio/addac/adt7316-spi.c | 74 +++---------- drivers/staging/iio/addac/adt7316.c | 132 ++++++++++++------------ drivers/staging/iio/addac/adt7316.h | 10 +- 4 files changed, 94 insertions(+), 178 deletions(-)
drivers/staging/iio/addac/adt7316-i2c.c +12 -44
@@ -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 =0 ; - - 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[] = {
drivers/staging/iio/addac/adt7316-spi.c +13 -61
99 lines not on this page · raw message
drivers/staging/iio/addac/adt7316.c +64 -68
430 lines not on this page · raw message
drivers/staging/iio/addac/adt7316.h +5 -5
@@ -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
Signature · 1 line
2.17.1
Quoted 19 lines · Shreeya Patel
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 v3
-Fetch the changes from remote and rebase to have it in
the current working directory.Changes in v2
-Change theval_bitsto 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
Quoted 9 lines
drivers/staging/iio/addac/adt7316-i2c.c | 97 ++-------------- drivers/staging/iio/addac/adt7316-spi.c | 95 +++------------ drivers/staging/iio/addac/adt7316.c | 147 ++++++++++++------------ drivers/staging/iio/addac/adt7316.h | 15 +-- 4 files changed, 103 insertions(+), 251 deletions(-)Signature · 1 line
2.17.1
The series doesn't apply to the current iio testing branch. If there's any value in a quick sanity testing, I can do that after a rebase. I wasn't planning to test everything the patch touches, but thought I could at least test a few register reads and writes to make sure we haven't missed anything obvious in the regmap implementation.
Jeremy
Quoted 31 lines · Jeremy Fertic
Quoted 19 lines · Shreeya Patel
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 v3
-Fetch the changes from remote and rebase to have it in
the current working directory.Changes in v2
-Change theval_bitsto 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 supportQuoted 10 lines
drivers/staging/iio/addac/adt7316-i2c.c | 97 ++-------------- drivers/staging/iio/addac/adt7316-spi.c | 95 +++------------ drivers/staging/iio/addac/adt7316.c | 147 ++++++++++++------ ------ drivers/staging/iio/addac/adt7316.h | 15 +-- 4 files changed, 103 insertions(+), 251 deletions(-)Signature · 1 line
2.17.1
Quoted 8 lines
The series doesn't apply to the current iio testing branch. If there's any
value in a quick sanity testing, I can do that after a rebase. I wasn't
planning to test everything the patch touches, but thought I could at least test a few register reads and writes to make sure we haven't missed
anything obvious in the regmap implementation.
Hi Jeremy,
Is it still not applying? Jonathan told me that v2 of this series wasn't applying so I rebased for this series.
I hope I didn't mess things up while rebasing :(
Thanks
Quoted 3 lines
Jeremy
Quoted 42 lines · Shreeya Patel
Quoted 31 lines · Jeremy Fertic
Quoted 19 lines · Shreeya Patel
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 v3
-Fetch the changes from remote and rebase to have it in
the current working directory.Changes in v2
-Change theval_bitsto 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 supportQuoted 10 lines
drivers/staging/iio/addac/adt7316-i2c.c | 97 ++-------------- drivers/staging/iio/addac/adt7316-spi.c | 95 +++------------ drivers/staging/iio/addac/adt7316.c | 147 ++++++++++++------ ------ drivers/staging/iio/addac/adt7316.h | 15 +-- 4 files changed, 103 insertions(+), 251 deletions(-)Signature · 1 line
2.17.1Quoted 9 lines
The series doesn't apply to the current iio testing branch. If there's any
value in a quick sanity testing, I can do that after a rebase. I wasn't
planning to test everything the patch touches, but thought I could at
least test a few register reads and writes to make sure we haven't missed
anything obvious in the regmap implementation.
Quoted 8 lines
Hi Jeremy,
Is it still not applying? Jonathan told me that v2 of this series wasn't applying so I rebased for this series.
I hope I didn't mess things up while rebasing :(
Thanks
Yes it is my mistake. I've rebased against greg's staging tree. I will soon send a v4 for the series.
Thanks
Quoted 6 lines
Quoted 4 lines
Jeremy