staging:iio:ad7476: Fix off by one error for channel shift
Subsystems (5)
PATCH v2 1/10 staging:iio:ad7476: Fix off by one error for channel shift
The datasheet is a bit confusing about this. It says that a dataword has 4 leading zeros, but the first zero is already put on the bus when CS is pulled low and the second zero is put on the bus on the first leading edge of SCLK, so when the first bit is sampled on the first trailing edge it will sample what the datasheet refers to as the second leading zero. Subsequently we only see 3 leading zeros in the 16 bit dataword and the result we get is shifted to the left by one bit. Fix this by adjusting the channel shift by 1.
--- drivers/staging/iio/adc/ad7476_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/adc/ad7476_core.c +1 -1
@@ -76,7 +76,7 @@ static int ad7476_read_raw(struct iio_dev *indio_dev, .sign = 'u', \ .realbits = bits, \ .storagebits = 16, \ - .shift = 12 - bits, \ + .shift = 13 - bits, \ }, \ }
Signature · 1 line
1.7.10.4
PATCH v2 2/10 staging:iio:ad7476: Remove duplicated chip info entries
Some of the parts supported by this driver are software compatible. The difference between them is only in the operating voltage range. So we do not need extra chip info entries for them.
--- drivers/staging/iio/adc/ad7476.h | 4 ---- drivers/staging/iio/adc/ad7476_core.c | 30 +++++++----------------------- 2 files changed, 7 insertions(+), 27 deletions(-)
drivers/staging/iio/adc/ad7476.h +0 -4
@@ -41,10 +41,6 @@ enum ad7476_supported_device_ids {ID_AD7466 ,ID_AD7467 ,ID_AD7468 , -ID_AD7475 , -ID_AD7476 , -ID_AD7477 , -ID_AD7478 , ID_AD7495 };
drivers/staging/iio/adc/ad7476_core.c +7 -23
@@ -93,22 +93,6 @@ static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { .channel[0] = AD7476_CHAN(8), .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), }, - [ID_AD7475] = { - .channel[0] = AD7476_CHAN(12), - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), - }, - [ID_AD7476] = { - .channel[0] = AD7476_CHAN(12), - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), - }, - [ID_AD7477] = { - .channel[0] = AD7476_CHAN(10), - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), - }, - [ID_AD7478] = { - .channel[0] = AD7476_CHAN(8), - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), - }, [ID_AD7495] = { .channel[0] = AD7476_CHAN(12), .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
@@ -216,13 +200,13 @@ static const struct spi_device_id ad7476_id[] = { {"ad7466", ID_AD7466}, {"ad7467", ID_AD7467}, {"ad7468", ID_AD7468}, - {"ad7475", ID_AD7475}, - {"ad7476", ID_AD7476}, - {"ad7476a", ID_AD7476}, - {"ad7477", ID_AD7477}, - {"ad7477a", ID_AD7477}, - {"ad7478", ID_AD7478}, - {"ad7478a", ID_AD7478}, + {"ad7475", ID_AD7466}, + {"ad7476", ID_AD7466}, + {"ad7476a", ID_AD7466}, + {"ad7477", ID_AD7467}, + {"ad7477a", ID_AD7467}, + {"ad7478", ID_AD7468}, + {"ad7478a", ID_AD7468}, {"ad7495", ID_AD7495}, {} };
Signature · 1 line
1.7.10.4
PATCH v2 3/10 staging:iio:ad7476: Avoid alloc/free for each sample in buffered mode
In reply to Lars-Peter ClausenThe ad7476 driver has only support for 1 channel ADCs. So the upper limit for the buffer size is the size of one sample plus the size of the timestamp. Preallocate a buffer large enough to hold this to avoid having to allocate and free a new buffer for each sample being captured.
---
Changes since v1:
Use the same prepared spi message as for single transfers in the trigger handler.
--- drivers/staging/iio/adc/ad7476.h | 5 ++++- drivers/staging/iio/adc/ad7476_ring.c | 14 +++----------- 2 files changed, 7 insertions(+), 12 deletions(-)
drivers/staging/iio/adc/ad7476.h +4 -1
@@ -33,8 +33,11 @@ struct ad7476_state {/* * DMA (thus cache coherency maintenance) requires the * transfer buffers to live in their own cache lines. +* Make the buffer large enough for one 16 bit sample and one 64 bit +* aligned 64 bit timestamp. */ -unsigned char data[2 ]____cacheline_aligned ; +unsigned char data[ALIGN (2 ,sizeof (s64)) +sizeof (s64)] +____cacheline_aligned ; };enum ad7476_supported_device_ids {
drivers/staging/iio/adc/ad7476_ring.c +3 -11
@@ -26,28 +26,20 @@ static irqreturn_t ad7476_trigger_handler(int irq, void *p)struct iio_dev *indio_dev = pf->indio_dev;struct ad7476_state *st =iio_priv (indio_dev);s64 time_ns; -__u8 *rxbuf;int b_sent; - rxbuf =kzalloc (indio_dev->scan_bytes,GFP_KERNEL ); -if (rxbuf ==NULL ) - goto done; - - b_sent =spi_read (st->spi, rxbuf, - st->chip_info->channel[0 ].scan_type.storagebits /8 ); + b_sent =spi_sync (st->spi, &st->msg);if (b_sent <0 ) goto done; time_ns =iio_get_time_ns ();if (indio_dev->scan_timestamp) -memcpy (rxbuf + indio_dev->scan_bytes -sizeof (s64), - &time_ns,sizeof (time_ns)); + ((s64 *)st->data)[1 ] = time_ns; -iio_push_to_buffer (indio_dev->buffer, rxbuf); +iio_push_to_buffer (indio_dev->buffer, st->data); done:iio_trigger_notify_done (indio_dev->trig); -kfree (rxbuf);return IRQ_HANDLED ; }
Signature · 1 line
1.7.10.4
PATCH v2 4/10 staging:iio:ad7476: Rework reference voltage handling
In reply to Lars-Peter ClausenSlightly rework the reference voltage handling for the ad7476 driver. Now the only way to specify a external reference voltage is to use the regulator API, previously it was possible to use either platform_data or the regulator API. The new way is more consistent with what other drivers do.
Also do not ignore errors when requesting the regulator, since this will cope very poorly with e.g. deferred probing.
----
Changes since v1:
* Fix regulator error handling
--- drivers/staging/iio/adc/ad7476.h | 11 +------ drivers/staging/iio/adc/ad7476_core.c | 58 +++++++++++++++------------------ 2 files changed, 27 insertions(+), 42 deletions(-)
drivers/staging/iio/adc/ad7476.h +1 -10
@@ -10,16 +10,8 @@#define RES_MASK (bits) ((1 << (bits)) - 1) -/* -* TODO: struct ad7476_platform_data needs to go into include/linux/iio -*/ - -struct ad7476_platform_data { -u16 vref_mv; -}; -struct ad7476_chip_info { -u16 int_vref_mv; +unsigned int int_vref_uv;struct iio_chan_spec channel[2 ]; };
@@ -27,7 +19,6 @@ struct ad7476_state {struct spi_device *spi;const struct ad7476_chip_info *chip_info;struct regulator *reg; -u16 int_vref_mv;struct spi_transfer xfer;struct spi_message msg;/*
drivers/staging/iio/adc/ad7476_core.c +26 -32
106 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Jonathan Cameron
maintainerRe: [PATCH v2 04/10] staging:iio:ad7476: Rework reference voltage handling
Quoted 5 lines · Lars-Peter Clausen
Slightly rework the reference voltage handling for the ad7476 driver. Now the only way to specify a external reference voltage is to use the regulator API, previously it was possible to use either
platform_dataor the regulator API. The new way is more consistent with what other drivers do.
Quoted 8 lines
Also do not ignore errors when requesting the regulator, since this will cope very poorly with e.g. deferred probing.
Signed-off-by Lars-Peter Clausen <[email protected]>----
Changes since v1:
* Fix regulator error handling
Not right yet. If the regulator_get fails you will leak the iio_device
I've fixed up, could you take a look at what I ended up with just to be sure I haven't made mistakes. It was one of those clasic cases where a one line change made for some nasty merging...
Anyhow, I've pushed the slightly amended versions out to iio.git togreg branch.
Quoted 153 lines
--- drivers/staging/iio/adc/ad7476.h | 11 +------ drivers/staging/iio/adc/ad7476_core.c | 58 +++++++++++++++------------------ 2 files changed, 27 insertions(+), 42 deletions(-)drivers/staging/iio/adc/ad7476.h +1
-10@@ -10,16 +10,8 @@#define RES_MASK (bits) ((1 << (bits)) - 1) -/* -* TODO: struct ad7476_platform_data needs to go into include/linux/iio -*/ - -struct ad7476_platform_data { -u16 vref_mv; -}; -struct ad7476_chip_info { -u16 int_vref_mv; +unsigned int int_vref_uv;struct iio_chan_spec channel[2 ]; };@@ -27,7 +19,6 @@ struct ad7476_state {struct spi_device *spi;const struct ad7476_chip_info *chip_info;struct regulator *reg; -u16 int_vref_mv;struct spi_transfer xfer;struct spi_message msg;/* drivers/staging/iio/adc/ad7476_core.c +26
-32@@ -40,7 +40,7 @@ static int ad7476_read_raw(struct iio_dev *indio_dev, {int ret;struct ad7476_state *st =iio_priv (indio_dev); -unsigned int scale_uv; +int scale_uv;switch (m) {case IIO_CHAN_INFO_RAW :@@ -57,10 +57,16 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,RES_MASK (st->chip_info->channel[0 ].scan_type.realbits);return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->int_vref_mv *1000 ) - >> st->chip_info->channel[0 ].scan_type.realbits; - *val = scale_uv/1000 ; - *val2 = (scale_uv%1000 )*1000 ; +if (!st->chip_info->int_vref_uv) { + scale_uv =regulator_get_voltage (st->reg); +if (scale_uv <0 ) +return scale_uv; + }else { + scale_uv = st->chip_info->int_vref_uv; + } + scale_uv >>= chan->scan_type.realbits; + *val = scale_uv /1000 ; + *val2 = (scale_uv %1000 ) *1000 ;return IIO_VAL_INT_PLUS_MICRO ; }return -EINVAL ;@@ -96,7 +102,7 @@ static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { [ID_AD7495 ] = { .channel[0 ] =AD7476_CHAN (12 ), .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), - .int_vref_mv =2500 , + .int_vref_uv =2500000 , }, };@@ -107,10 +113,9 @@ static const struct iio_info ad7476_info = {static int __devinit ad7476_probe (struct spi_device *spi) { -struct ad7476_platform_data *pdata = spi->dev.platform_data;struct ad7476_state *st;struct iio_dev *indio_dev; -int ret, voltage_uv =0 ; +int ret; indio_dev =iio_device_alloc (sizeof (*st));if (indio_dev ==NULL ) {@@ -118,25 +123,18 @@ static int __devinit ad7476_probe(struct spi_device *spi) goto error_ret; } st =iio_priv (indio_dev); - st->reg =regulator_get (&spi->dev,"vcc" ); -if (!IS_ERR (st->reg)) { - ret =regulator_enable (st->reg); -if (ret) - goto error_put_reg; - - voltage_uv =regulator_get_voltage (st->reg); - } st->chip_info = &ad7476_chip_info_tbl[spi_get_device_id (spi)->driver_data]; -if (st->chip_info->int_vref_mv) - st->int_vref_mv = st->chip_info->int_vref_mv; -else if (pdata && pdata->vref_mv) - st->int_vref_mv = pdata->vref_mv; -else if (voltage_uv) - st->int_vref_mv = voltage_uv /1000 ; -else -dev_warn (&spi->dev,"reference voltage unspecified\n" ); + st->reg =regulator_get (&spi->dev,"vcc" ); +if (IS_ERR (st->reg)) { + ret =PTR_ERR (st->reg); + goto error_ret; + } + + ret =regulator_enable (st->reg); +if (ret) + goto error_put_reg;spi_set_drvdata (spi, indio_dev);@@ -169,11 +167,9 @@ static int __devinit ad7476_probe(struct spi_device *spi) error_ring_unregister:ad7476_ring_cleanup (indio_dev); error_disable_reg: -if (!IS_ERR (st->reg)) -regulator_disable (st->reg); +regulator_disable (st->reg); error_put_reg: -if (!IS_ERR (st->reg)) -regulator_put (st->reg); +regulator_put (st->reg);iio_device_free (indio_dev); error_ret:@@ -187,10 +183,8 @@ static int __devexit ad7476_remove(struct spi_device *spi)iio_device_unregister (indio_dev);ad7476_ring_cleanup (indio_dev); -if (!IS_ERR (st->reg)) { -regulator_disable (st->reg); -regulator_put (st->reg); - } +regulator_disable (st->reg); +regulator_put (st->reg);iio_device_free (indio_dev);return 0 ;
Re: [PATCH v2 04/10] staging:iio:ad7476: Rework reference voltage handling
Quoted 15 lines · Jonathan Cameron
Quoted 5 lines · Lars-Peter Clausen
Slightly rework the reference voltage handling for the ad7476 driver. Now the only way to specify a external reference voltage is to use the regulator API, previously it was possible to use either
platform_dataor the regulator API. The new way is more consistent with what other drivers do.Quoted 8 lines
Also do not ignore errors when requesting the regulator, since this will cope very poorly with e.g. deferred probing.
Signed-off-by Lars-Peter Clausen <[email protected]>----
Changes since v1:
* Fix regulator error handling
Quoted 7 lines
Not right yet. If the
regulator_getfails you will leak theiio_deviceI've fixed up, could you take a look at what I ended up with just to be sure I haven't made mistakes. It was one of those clasic cases where a one line change made for some nasty merging...
Anyhow, I've pushed the slightly amended versions out to iio.git togreg branch.
Thanks, looks good. Except for the commit message, which has the changelog between my and your Signed-off-by.
Quoted 154 lines
Quoted 154 lines
--- drivers/staging/iio/adc/ad7476.h | 11 +------ drivers/staging/iio/adc/ad7476_core.c | 58 +++++++++++++++------------------ 2 files changed, 27 insertions(+), 42 deletions(-)drivers/staging/iio/adc/ad7476.h +1
-10@@ -10,16 +10,8 @@#define RES_MASK (bits) ((1 << (bits)) - 1) -/* -* TODO: struct ad7476_platform_data needs to go into include/linux/iio -*/ - -struct ad7476_platform_data { -u16 vref_mv; -}; -struct ad7476_chip_info { -u16 int_vref_mv; +unsigned int int_vref_uv;struct iio_chan_spec channel[2 ]; };@@ -27,7 +19,6 @@ struct ad7476_state {struct spi_device *spi;const struct ad7476_chip_info *chip_info;struct regulator *reg; -u16 int_vref_mv;struct spi_transfer xfer;struct spi_message msg;/* drivers/staging/iio/adc/ad7476_core.c +26
-32@@ -40,7 +40,7 @@ static int ad7476_read_raw(struct iio_dev *indio_dev, {int ret;struct ad7476_state *st =iio_priv (indio_dev); -unsigned int scale_uv; +int scale_uv;switch (m) {case IIO_CHAN_INFO_RAW :@@ -57,10 +57,16 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,RES_MASK (st->chip_info->channel[0 ].scan_type.realbits);return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->int_vref_mv *1000 ) - >> st->chip_info->channel[0 ].scan_type.realbits; - *val = scale_uv/1000 ; - *val2 = (scale_uv%1000 )*1000 ; +if (!st->chip_info->int_vref_uv) { + scale_uv =regulator_get_voltage (st->reg); +if (scale_uv <0 ) +return scale_uv; + }else { + scale_uv = st->chip_info->int_vref_uv; + } + scale_uv >>= chan->scan_type.realbits; + *val = scale_uv /1000 ; + *val2 = (scale_uv %1000 ) *1000 ;return IIO_VAL_INT_PLUS_MICRO ; }return -EINVAL ;@@ -96,7 +102,7 @@ static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { [ID_AD7495 ] = { .channel[0 ] =AD7476_CHAN (12 ), .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), - .int_vref_mv =2500 , + .int_vref_uv =2500000 , }, };@@ -107,10 +113,9 @@ static const struct iio_info ad7476_info = {static int __devinit ad7476_probe (struct spi_device *spi) { -struct ad7476_platform_data *pdata = spi->dev.platform_data;struct ad7476_state *st;struct iio_dev *indio_dev; -int ret, voltage_uv =0 ; +int ret; indio_dev =iio_device_alloc (sizeof (*st));if (indio_dev ==NULL ) {@@ -118,25 +123,18 @@ static int __devinit ad7476_probe(struct spi_device *spi) goto error_ret; } st =iio_priv (indio_dev); - st->reg =regulator_get (&spi->dev,"vcc" ); -if (!IS_ERR (st->reg)) { - ret =regulator_enable (st->reg); -if (ret) - goto error_put_reg; - - voltage_uv =regulator_get_voltage (st->reg); - } st->chip_info = &ad7476_chip_info_tbl[spi_get_device_id (spi)->driver_data]; -if (st->chip_info->int_vref_mv) - st->int_vref_mv = st->chip_info->int_vref_mv; -else if (pdata && pdata->vref_mv) - st->int_vref_mv = pdata->vref_mv; -else if (voltage_uv) - st->int_vref_mv = voltage_uv /1000 ; -else -dev_warn (&spi->dev,"reference voltage unspecified\n" ); + st->reg =regulator_get (&spi->dev,"vcc" ); +if (IS_ERR (st->reg)) { + ret =PTR_ERR (st->reg); + goto error_ret; + } + + ret =regulator_enable (st->reg); +if (ret) + goto error_put_reg;spi_set_drvdata (spi, indio_dev);@@ -169,11 +167,9 @@ static int __devinit ad7476_probe(struct spi_device *spi) error_ring_unregister:ad7476_ring_cleanup (indio_dev); error_disable_reg: -if (!IS_ERR (st->reg)) -regulator_disable (st->reg); +regulator_disable (st->reg); error_put_reg: -if (!IS_ERR (st->reg)) -regulator_put (st->reg); +regulator_put (st->reg);iio_device_free (indio_dev); error_ret:@@ -187,10 +183,8 @@ static int __devexit ad7476_remove(struct spi_device *spi)iio_device_unregister (indio_dev);ad7476_ring_cleanup (indio_dev); -if (!IS_ERR (st->reg)) { -regulator_disable (st->reg); -regulator_put (st->reg); - } +regulator_disable (st->reg); +regulator_put (st->reg);iio_device_free (indio_dev);return 0 ;
Jonathan Cameron
maintainerRe: [PATCH v2 04/10] staging:iio:ad7476: Rework reference voltage handling
Quoted 18 lines · Lars-Peter Clausen
Quoted 17 lines · Jonathan Cameron
Quoted 5 lines · Lars-Peter Clausen
Slightly rework the reference voltage handling for the ad7476 driver. Now the only way to specify a external reference voltage is to use the regulator API, previously it was possible to use either
platform_dataor the regulator API. The new way is more consistent with what other drivers do.Quoted 8 lines
Also do not ignore errors when requesting the regulator, since this will cope very poorly with e.g. deferred probing.
Signed-off-by Lars-Peter Clausen <[email protected]>----
Changes since v1:
* Fix regulator error handlingNot right yet. If the
regulator_getfails you will leak theiio_device
Quoted 8 lines
Quoted 5 lines
I've fixed up, could you take a look at what I ended up with just to be sure I haven't made mistakes. It was one of those clasic cases where a one line change made for some nasty merging...
Anyhow, I've pushed the slightly amended versions out to iio.git togreg branch.
Thanks, looks good. Except for the commit message, which has the changelog between my and your Signed-off-by.
oops. Will fix that up before pushing out.
*hopes no one is mad enough to base their trees off mine given how often I rebase*
Quoted 161 lines
Quoted 153 lines
Quoted 153 lines
--- drivers/staging/iio/adc/ad7476.h | 11 +------ drivers/staging/iio/adc/ad7476_core.c | 58 +++++++++++++++------------------ 2 files changed, 27 insertions(+), 42 deletions(-)drivers/staging/iio/adc/ad7476.h +1
-10@@ -10,16 +10,8 @@#define RES_MASK (bits) ((1 << (bits)) - 1) -/* -* TODO: struct ad7476_platform_data needs to go into include/linux/iio -*/ - -struct ad7476_platform_data { -u16 vref_mv; -}; -struct ad7476_chip_info { -u16 int_vref_mv; +unsigned int int_vref_uv;struct iio_chan_spec channel[2 ]; };@@ -27,7 +19,6 @@ struct ad7476_state {struct spi_device *spi;const struct ad7476_chip_info *chip_info;struct regulator *reg; -u16 int_vref_mv;struct spi_transfer xfer;struct spi_message msg;/* drivers/staging/iio/adc/ad7476_core.c +26
-32@@ -40,7 +40,7 @@ static int ad7476_read_raw(struct iio_dev *indio_dev, {int ret;struct ad7476_state *st =iio_priv (indio_dev); -unsigned int scale_uv; +int scale_uv;switch (m) {case IIO_CHAN_INFO_RAW :@@ -57,10 +57,16 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,RES_MASK (st->chip_info->channel[0 ].scan_type.realbits);return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->int_vref_mv *1000 ) - >> st->chip_info->channel[0 ].scan_type.realbits; - *val = scale_uv/1000 ; - *val2 = (scale_uv%1000 )*1000 ; +if (!st->chip_info->int_vref_uv) { + scale_uv =regulator_get_voltage (st->reg); +if (scale_uv <0 ) +return scale_uv; + }else { + scale_uv = st->chip_info->int_vref_uv; + } + scale_uv >>= chan->scan_type.realbits; + *val = scale_uv /1000 ; + *val2 = (scale_uv %1000 ) *1000 ;return IIO_VAL_INT_PLUS_MICRO ; }return -EINVAL ;@@ -96,7 +102,7 @@ static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { [ID_AD7495 ] = { .channel[0 ] =AD7476_CHAN (12 ), .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), - .int_vref_mv =2500 , + .int_vref_uv =2500000 , }, };@@ -107,10 +113,9 @@ static const struct iio_info ad7476_info = {static int __devinit ad7476_probe (struct spi_device *spi) { -struct ad7476_platform_data *pdata = spi->dev.platform_data;struct ad7476_state *st;struct iio_dev *indio_dev; -int ret, voltage_uv =0 ; +int ret; indio_dev =iio_device_alloc (sizeof (*st));if (indio_dev ==NULL ) {@@ -118,25 +123,18 @@ static int __devinit ad7476_probe(struct spi_device *spi) goto error_ret; } st =iio_priv (indio_dev); - st->reg =regulator_get (&spi->dev,"vcc" ); -if (!IS_ERR (st->reg)) { - ret =regulator_enable (st->reg); -if (ret) - goto error_put_reg; - - voltage_uv =regulator_get_voltage (st->reg); - } st->chip_info = &ad7476_chip_info_tbl[spi_get_device_id (spi)->driver_data]; -if (st->chip_info->int_vref_mv) - st->int_vref_mv = st->chip_info->int_vref_mv; -else if (pdata && pdata->vref_mv) - st->int_vref_mv = pdata->vref_mv; -else if (voltage_uv) - st->int_vref_mv = voltage_uv /1000 ; -else -dev_warn (&spi->dev,"reference voltage unspecified\n" ); + st->reg =regulator_get (&spi->dev,"vcc" ); +if (IS_ERR (st->reg)) { + ret =PTR_ERR (st->reg); + goto error_ret; + } + + ret =regulator_enable (st->reg); +if (ret) + goto error_put_reg;spi_set_drvdata (spi, indio_dev);@@ -169,11 +167,9 @@ static int __devinit ad7476_probe(struct spi_device *spi) error_ring_unregister:ad7476_ring_cleanup (indio_dev); error_disable_reg: -if (!IS_ERR (st->reg)) -regulator_disable (st->reg); +regulator_disable (st->reg); error_put_reg: -if (!IS_ERR (st->reg)) -regulator_put (st->reg); +regulator_put (st->reg);iio_device_free (indio_dev); error_ret:@@ -187,10 +183,8 @@ static int __devexit ad7476_remove(struct spi_device *spi)iio_device_unregister (indio_dev);ad7476_ring_cleanup (indio_dev); -if (!IS_ERR (st->reg)) { -regulator_disable (st->reg); -regulator_put (st->reg); - } +regulator_disable (st->reg); +regulator_put (st->reg);iio_device_free (indio_dev);Quoted 2 lines
drivers/staging/iio/adc/ad7476_core.c static int __devexit ad7476_remove(struct spi_device *spi) · line 190
Quoted 2 lines
drivers/staging/iio/adc/ad7476_core.c +0
-0return 0 ;--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 5/10 staging:iio:ad7476: Squash driver into a single file.
In reply to Lars-Peter ClausenAfter the recent cleanups the buffer support is just a single 23 line function. This does not really justify a file on its own, so move it to the main driver file. And with only one source file left the header file containing the device state struct becomes superflousious so move the content of the header file to the main driver source file as well.
---
Changes since v1:
Since the driver selects buffer support there is no need to #ifdef guard the buffer code in this driver. So build it unconditionally, this gets rid of another couple of boilterplate code.
--- drivers/staging/iio/adc/Makefile | 2 - drivers/staging/iio/adc/ad7476.c | 277 +++++++++++++++++++++++++++++++++ drivers/staging/iio/adc/ad7476.h | 56 ------- drivers/staging/iio/adc/ad7476_core.c | 222 -------------------------- drivers/staging/iio/adc/ad7476_ring.c | 56 ------- 5 files changed, 277 insertions(+), 336 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7476.c delete mode 100644 drivers/staging/iio/adc/ad7476.h delete mode 100644 drivers/staging/iio/adc/ad7476_core.c delete mode 100644 drivers/staging/iio/adc/ad7476_ring.c
drivers/staging/iio/adc/Makefile +0 -2
@@ -17,8 +17,6 @@ ad799x-y := ad799x_core.o ad799x-$(CONFIG_AD799X_RING_BUFFER) += ad799x_ring.o obj-$(CONFIG_AD799X) += ad799x.o -ad7476-y := ad7476_core.o -ad7476-$(CONFIG_IIO_BUFFER) += ad7476_ring.o obj-$(CONFIG_AD7476) += ad7476.o ad7887-y := ad7887_core.o
drivers/staging/iio/adc/ad7476.c new file +277 -0
277 lines not on this page · raw message
drivers/staging/iio/adc/ad7476.h deleted +0 -56
56 lines not on this page · raw message
drivers/staging/iio/adc/ad7476_core.c deleted +0 -222
222 lines not on this page · raw message
drivers/staging/iio/adc/ad7476_ring.c deleted +0 -56
56 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v2 6/10 staging:iio:ad7476: Use be16_to_cpup instead of open-coding it
In reply to Lars-Peter Clausen--- drivers/staging/iio/adc/ad7476.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/adc/ad7476.c +1 -1
@@ -83,7 +83,7 @@ static int ad7476_scan_direct(struct ad7476_state *st)if (ret)return ret; -return (st->data[0 ] <<8 ) | st->data[1 ]; +return be16_to_cpup ((__be16 *)st->data); } static int ad7476_read_raw(struct iio_dev *indio_dev,
Signature · 1 line
1.7.10.4
PATCH v2 7/10 iio: Move ad7476 driver out of staging
In reply to Lars-Peter ClausenThe ad7476 driver is a driver for simple single channel ADCs. The driver does not export any experimental or custom ABI files nor do the static code check tools report any issues, so move the driver out of staging.
--- drivers/iio/adc/Kconfig | 14 ++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ad7476.c | 277 ++++++++++++++++++++++++++++++++++++++ drivers/staging/iio/adc/Kconfig | 14 -- drivers/staging/iio/adc/Makefile | 2 - drivers/staging/iio/adc/ad7476.c | 277 -------------------------------------- 6 files changed, 292 insertions(+), 293 deletions(-) create mode 100644 drivers/iio/adc/ad7476.c delete mode 100644 drivers/staging/iio/adc/ad7476.c
drivers/iio/adc/Kconfig +14 -0
@@ -18,6 +18,20 @@ config AD7266 Say yes here to build support for Analog Devices AD7265 and AD7266 ADCs. +config AD7476 + tristate "Analog Devices AD7475/6/7/8 AD7466/7/8 and AD7495 ADC driver" + depends on SPI + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + Say yes here to build support for Analog Devices + AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, AD7495 + SPI analog to digital converters (ADC). + If unsure, say N (but it's safe to say "Y"). + + To compile this driver as a module, choose M here: the + module will be called ad7476. + config AT91_ADC tristate "Atmel AT91 ADC" depends on ARCH_AT91
drivers/iio/adc/Makefile +1 -0
@@ -4,4 +4,5 @@ obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o obj-$(CONFIG_AD7266) += ad7266.o +obj-$(CONFIG_AD7476) += ad7476.o obj-$(CONFIG_AT91_ADC) += at91_adc.o
drivers/iio/adc/ad7476.c new file +277 -0
277 lines not on this page · raw message
drivers/staging/iio/adc/Kconfig +0 -14
@@ -68,20 +68,6 @@ config AD799X_RING_BUFFER Say yes here to include ring buffer support in the AD799X ADC driver. -config AD7476 - tristate "Analog Devices AD7475/6/7/8 AD7466/7/8 and AD7495 ADC driver" - depends on SPI - select IIO_BUFFER - select IIO_TRIGGERED_BUFFER - help - Say yes here to build support for Analog Devices - AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, AD7495 - SPI analog to digital converters (ADC). - If unsure, say N (but it's safe to say "Y"). - - To compile this driver as a module, choose M here: the - module will be called ad7476. - config AD7887 tristate "Analog Devices AD7887 ADC driver" depends on SPI
drivers/staging/iio/adc/Makefile +0 -2
@@ -17,8 +17,6 @@ ad799x-y := ad799x_core.o ad799x-$(CONFIG_AD799X_RING_BUFFER) += ad799x_ring.o obj-$(CONFIG_AD799X) += ad799x.o -obj-$(CONFIG_AD7476) += ad7476.o - ad7887-y := ad7887_core.o ad7887-$(CONFIG_IIO_BUFFER) += ad7887_ring.o obj-$(CONFIG_AD7887) += ad7887.o
drivers/staging/iio/adc/ad7476.c deleted +0 -277
277 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v2 8/10 iio:ad7476: Add ad7910/ad7920 device table entries
In reply to Lars-Peter ClausenThe ad7910/ad7920 are software compatible to the ad7467/ad7466.
--- drivers/iio/adc/Kconfig | 9 +++++---- drivers/iio/adc/ad7476.c | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/iio/adc/Kconfig +5 -4
@@ -19,14 +19,15 @@ config AD7266 ADCs. config AD7476 - tristate "Analog Devices AD7475/6/7/8 AD7466/7/8 and AD7495 ADC driver" + tristate "Analog Devices AD7476 and similar 1-channel ADCs driver" depends on SPI select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - Say yes here to build support for Analog Devices - AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, AD7495 - SPI analog to digital converters (ADC). + Say yes here to build support for Analog Devices AD7475, AD7476, AD7477, + AD7478, AD7466, AD7467, AD7468, AD7495, AD7910, AD7920 SPI analog to + digital converters (ADC). + If unsure, say N (but it's safe to say "Y"). To compile this driver as a module, choose M here: the
drivers/iio/adc/ad7476.c +3 -1
@@ -257,6 +257,8 @@ static const struct spi_device_id ad7476_id[] = { {"ad7478", ID_AD7468}, {"ad7478a", ID_AD7468}, {"ad7495", ID_AD7495}, + {"ad7910", ID_AD7467}, + {"ad7920", ID_AD7466}, {} };MODULE_DEVICE_TABLE (spi, ad7476_id);
@@ -273,5 +275,5 @@ static struct spi_driver ad7476_driver = {module_spi_driver (ad7476_driver);MODULE_AUTHOR ("Michael Hennerich <[email protected]>" ); -MODULE_DESCRIPTION ("Analog Devices AD7475/6/7/8(A) AD7466/7/8 ADC" ); +MODULE_DESCRIPTION ("Analog Devices AD7476 and similar 1-channel ADCs" );MODULE_LICENSE ("GPL v2" );
Signature · 1 line
1.7.10.4
PATCH v2 9/10 iio:ad7476: Add ad7940 support
In reply to Lars-Peter ClausenThe AD7940 is a single channel 14 bit ADC similar to the ADCs already supported by the ad7476 driver, but it does have a different shift factor.
--- drivers/iio/adc/Kconfig | 4 ++-- drivers/iio/adc/ad7476.c | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-)
drivers/iio/adc/Kconfig +2 -2
@@ -25,8 +25,8 @@ config AD7476 select IIO_TRIGGERED_BUFFER help Say yes here to build support for Analog Devices AD7475, AD7476, AD7477, - AD7478, AD7466, AD7467, AD7468, AD7495, AD7910, AD7920 SPI analog to - digital converters (ADC). + AD7478, AD7466, AD7467, AD7468, AD7495, AD7910, AD7920, AD7920 SPI analog + to digital converters (ADC). If unsure, say N (but it's safe to say "Y").
drivers/iio/adc/ad7476.c +14 -4
@@ -48,7 +48,8 @@ enum ad7476_supported_device_ids {ID_AD7466 ,ID_AD7467 ,ID_AD7468 , - ID_AD7495 +ID_AD7495 , + ID_AD7940, };static irqreturn_t ad7476_trigger_handler (int irq,void *p)
@@ -126,7 +127,7 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,return -EINVAL ; } -#define AD7476_CHAN (bits) \ +#define _AD7476_CHAN (bits, _shift) \ { \ .type = IIO_VOLTAGE, \ .indexed = 1, \
@@ -134,12 +135,16 @@ static int ad7476_read_raw(struct iio_dev *indio_dev, IIO_CHAN_INFO_SCALE_SHARED_BIT, \ .scan_type = { \ .sign = 'u', \ - .realbits = bits, \ + .realbits = (bits), \ .storagebits = 16, \ - .shift = 13 - bits, \ + .shift = (_shift), \ + .endianness = IIO_BE, \ }, \ } +#define AD7476_CHAN (bits) _AD7476_CHAN((bits), 13 - (bits)) +#define AD7940_CHAN (bits) _AD7476_CHAN((bits), 15 - (bits)) +static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { [ID_AD7466 ] = { .channel[0 ] =AD7476_CHAN (12 ),
@@ -158,6 +163,10 @@ static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), .int_vref_uv = 2500000, }, + [ID_AD7940] = { + .channel[0] = AD7940_CHAN(14), + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), + }, }; static const struct iio_info ad7476_info = {
@@ -259,6 +268,7 @@ static const struct spi_device_id ad7476_id[] = { {"ad7495", ID_AD7495}, {"ad7910", ID_AD7467}, {"ad7920", ID_AD7466}, + {"ad7940", ID_AD7940}, {} };MODULE_DEVICE_TABLE (spi, ad7476_id);
Signature · 1 line
1.7.10.4
PATCH v2 10/10 iio:ad7476: Add support for ad7274/ad7275/ad7276/ad7277/ad7278
In reply to Lars-Peter ClausenThe ad7276/ad7277/ad7278 are similar to the ad7476/ad7477/ad7478 but have the same number of leading zeros as the ad7940. The ad7274/ad7275 have a extra pin for VREF where as for the ad7276/ad7277/ad7278 VREF is taken from VDD, but otherwise they are compatible to the ad7276/ad7277.
--- drivers/iio/adc/Kconfig | 6 +++--- drivers/iio/adc/ad7476.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-)
drivers/iio/adc/Kconfig +3 -3
@@ -24,9 +24,9 @@ config AD7476 select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - Say yes here to build support for Analog Devices AD7475, AD7476, AD7477, - AD7478, AD7466, AD7467, AD7468, AD7495, AD7910, AD7920, AD7920 SPI analog - to digital converters (ADC). + Say yes here to build support for Analog Devices AD7274, AD7275, AD7276, + AD7277, AD7278, AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, + AD7495, AD7910, AD7920, AD7920 SPI analog to digital converters (ADC). If unsure, say N (but it's safe to say "Y").
drivers/iio/adc/ad7476.c +20 -0
@@ -45,6 +45,9 @@ struct ad7476_state { };enum ad7476_supported_device_ids { +ID_AD7276 , +ID_AD7277 , +ID_AD7278 ,ID_AD7466 ,ID_AD7467 ,ID_AD7468 ,
@@ -146,6 +149,18 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,#define AD7940_CHAN (bits) _AD7476_CHAN((bits), 15 - (bits))static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { + [ID_AD7276 ] = { + .channel[0 ] =AD7940_CHAN (12 ), + .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), + }, + [ID_AD7277 ] = { + .channel[0 ] =AD7940_CHAN (10 ), + .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), + }, + [ID_AD7278 ] = { + .channel[0 ] =AD7940_CHAN (8 ), + .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), + }, [ID_AD7466 ] = { .channel[0 ] =AD7476_CHAN (12 ), .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ),
@@ -255,6 +270,11 @@ static int __devexit ad7476_remove(struct spi_device *spi) }static const struct spi_device_id ad7476_id[] = { + {"ad7274" ,ID_AD7276 }, + {"ad7275" ,ID_AD7277 }, + {"ad7276" ,ID_AD7276 }, + {"ad7277" ,ID_AD7277 }, + {"ad7278" ,ID_AD7278 }, {"ad7466" ,ID_AD7466 }, {"ad7467" ,ID_AD7467 }, {"ad7468" ,ID_AD7468 },
Signature · 1 line
1.7.10.4
PATCH v3 10/10 iio:ad7476: Add support for ad7273/ad7274/ad7276/ad7277/ad7278
The ad7276/ad7277/ad7278 are similar to the ad7476/ad7477/ad7478 but have the same number of leading zeros as the ad7940. The ad7273/ad7274 have a extra pin for VREF where as for the ad7276/ad7277/ad7278 VREF is taken from VDD, but otherwise they are compatible to the ad7276/ad7277.
---
Changes since v2:
Fixup part numbers. It's actually ad7273/ad7274 instead of ad7274/ad7275 --- drivers/iio/adc/Kconfig | 6 +++--- drivers/iio/adc/ad7476.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-)
drivers/iio/adc/Kconfig +3 -3
@@ -24,9 +24,9 @@ config AD7476 select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - Say yes here to build support for Analog Devices AD7475, AD7476, AD7477, - AD7478, AD7466, AD7467, AD7468, AD7495, AD7910, AD7920, AD7920 SPI analog - to digital converters (ADC). + Say yes here to build support for Analog Devices AD7274, AD7275, AD7276, + AD7277, AD7278, AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, + AD7495, AD7910, AD7920, AD7920 SPI analog to digital converters (ADC). If unsure, say N (but it's safe to say "Y").
drivers/iio/adc/ad7476.c +20 -0
@@ -45,6 +45,9 @@ struct ad7476_state { };enum ad7476_supported_device_ids { +ID_AD7276 , +ID_AD7277 , +ID_AD7278 ,ID_AD7466 ,ID_AD7467 ,ID_AD7468 ,
@@ -146,6 +149,18 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,#define AD7940_CHAN (bits) _AD7476_CHAN((bits), 15 - (bits))static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { + [ID_AD7276 ] = { + .channel[0 ] =AD7940_CHAN (12 ), + .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), + }, + [ID_AD7277 ] = { + .channel[0 ] =AD7940_CHAN (10 ), + .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), + }, + [ID_AD7278 ] = { + .channel[0 ] =AD7940_CHAN (8 ), + .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), + }, [ID_AD7466 ] = { .channel[0 ] =AD7476_CHAN (12 ), .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ),
@@ -255,6 +270,11 @@ static int __devexit ad7476_remove(struct spi_device *spi) }static const struct spi_device_id ad7476_id[] = { + {"ad7273" ,ID_AD7277 }, + {"ad7274" ,ID_AD7276 }, + {"ad7276" ,ID_AD7276 }, + {"ad7277" ,ID_AD7277 }, + {"ad7278" ,ID_AD7278 }, {"ad7466" ,ID_AD7466 }, {"ad7467" ,ID_AD7467 }, {"ad7468" ,ID_AD7468 },
Signature · 1 line
1.7.10.4
PATCH v4 10/10 iio:ad7476: Add support for ad7273/ad7274/ad7276/ad7277/ad7278
The ad7276/ad7277/ad7278 are similar to the ad7476/ad7477/ad7478 but have the same number of leading zeros as the ad7940. The ad7273/ad7274 have a extra pin for VREF where as for the ad7276/ad7277/ad7278 VREF is taken from VDD, but otherwise they are compatible to the ad7276/ad7277.
---
Changes since v3:
Forgot the Kconfig entry in the previous fixup...
Changes since v2:
Fixup part numbers. It's actually ad7273/ad7274 instead of ad7274/ad7275 --- drivers/iio/adc/Kconfig | 6 +++--- drivers/iio/adc/ad7476.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-)
drivers/iio/adc/Kconfig +3 -3
@@ -24,9 +24,9 @@ config AD7476 select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - Say yes here to build support for Analog Devices AD7475, AD7476, AD7477, - AD7478, AD7466, AD7467, AD7468, AD7495, AD7910, AD7920, AD7920 SPI analog - to digital converters (ADC). + Say yes here to build support for Analog Devices AD7273, AD7274, AD7276, + AD7277, AD7278, AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, + AD7495, AD7910, AD7920, AD7920 SPI analog to digital converters (ADC). If unsure, say N (but it's safe to say "Y").
drivers/iio/adc/ad7476.c +20 -0
@@ -45,6 +45,9 @@ struct ad7476_state { };enum ad7476_supported_device_ids { +ID_AD7276 , +ID_AD7277 , +ID_AD7278 ,ID_AD7466 ,ID_AD7467 ,ID_AD7468 ,
@@ -146,6 +149,18 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,#define AD7940_CHAN (bits) _AD7476_CHAN((bits), 15 - (bits))static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { + [ID_AD7276 ] = { + .channel[0 ] =AD7940_CHAN (12 ), + .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), + }, + [ID_AD7277 ] = { + .channel[0 ] =AD7940_CHAN (10 ), + .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), + }, + [ID_AD7278 ] = { + .channel[0 ] =AD7940_CHAN (8 ), + .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ), + }, [ID_AD7466 ] = { .channel[0 ] =AD7476_CHAN (12 ), .channel[1 ] =IIO_CHAN_SOFT_TIMESTAMP (1 ),
@@ -255,6 +270,11 @@ static int __devexit ad7476_remove(struct spi_device *spi) }static const struct spi_device_id ad7476_id[] = { + {"ad7273" ,ID_AD7277 }, + {"ad7274" ,ID_AD7276 }, + {"ad7276" ,ID_AD7276 }, + {"ad7277" ,ID_AD7277 }, + {"ad7278" ,ID_AD7278 }, {"ad7466" ,ID_AD7466 }, {"ad7467" ,ID_AD7467 }, {"ad7468" ,ID_AD7468 },
Signature · 1 line
1.7.10.4