IIO-onwards: ADC: AD7887: Convert to new channel registration method.
Subsystems (4)
[email protected]
maintainerPATCH 1/2 IIO-onwards: ADC: AD7887: Convert to new channel registration method.
From: Michael Hennerich <[email protected]>
Convert to new channel registration method
Update / change license copyright header
Add missing call to iio_trigger_notify_done()
--- drivers/staging/iio/adc/ad7887.h | 14 ++-- drivers/staging/iio/adc/ad7887_core.c | 123 ++++++++++++++------------------- drivers/staging/iio/adc/ad7887_ring.c | 71 +++----------------- 3 files changed, 69 insertions(+), 139 deletions(-)
drivers/staging/iio/adc/ad7887.h +8 -6
@@ -48,12 +48,15 @@ struct ad7887_platform_data {bool use_onchip_ref; }; +/** +* struct ad7887_chip_info - chip specifc information +* @int_vref_mv: the internal reference voltage +* @channel: channel specification +*/ +struct ad7887_chip_info { -u8 bits;/* number of ADC bits */ -u8 storagebits;/* number of bits read from the ADC */ -u8 left_shift;/* number of bits the sample must be shifted */ -char sign;/* [s]igned or [u]nsigned */ -u16 int_vref_mv;/* internal reference voltage */ +u16 int_vref_mv; +struct iio_chan_spec channel[3 ]; };struct ad7887_state {
@@ -63,7 +66,6 @@ struct ad7887_state {struct regulator *reg;size_t d_size;u16 int_vref_mv; -bool en_dual;struct spi_transfer xfer[4 ];struct spi_message msg[3 ];struct spi_message *ring_msg;
drivers/staging/iio/adc/ad7887_core.c +52 -71
179 lines not on this page · raw message
drivers/staging/iio/adc/ad7887_ring.c +9 -62
111 lines not on this page · raw message
Signature · 1 line
1.6.0.2
[email protected]
maintainerPATCH 2/2 IIO-onwards: ADC: AD7887: Use private data space from iio_allocate_device
From: Michael Hennerich <[email protected]>
--- drivers/staging/iio/adc/ad7887.h | 1 - drivers/staging/iio/adc/ad7887_core.c | 80 +++++++++++++++------------------ drivers/staging/iio/adc/ad7887_ring.c | 2 +- 3 files changed, 37 insertions(+), 46 deletions(-)
drivers/staging/iio/adc/ad7887.h +0 -1
@@ -60,7 +60,6 @@ struct ad7887_chip_info { };struct ad7887_state { -struct iio_dev *indio_dev;struct spi_device *spi;const struct ad7887_chip_info *chip_info;struct regulator *reg;
drivers/staging/iio/adc/ad7887_core.c +36 -44
136 lines not on this page · raw message
drivers/staging/iio/adc/ad7887_ring.c +1 -1
@@ -27,7 +27,7 @@int ad7887_scan_from_ring (struct ad7887_state *st,long mask) { -struct iio_ring_buffer *ring = st->indio_dev->ring; +struct iio_ring_buffer *ring =iio_priv_to_dev (st)->ring;int count =0 , ret;u16 *ring_data;
Signature · 1 line
1.6.0.2
Re: [PATCH 2/2] IIO-onwards: ADC: AD7887: Use private data space from iio_allocate_device
Quoted 2 lines · On 04/18/11 14:03, [email protected] wrote:
From: Michael Hennerich <[email protected]>
Will put this one after the other in iio-onwards.
Quoted 1 line
Signed-off-by Michael Hennerich <[email protected]>
Thanks for doing these.
Quoted 175 lines
--- drivers/staging/iio/adc/ad7887.h | 1 - drivers/staging/iio/adc/ad7887_core.c | 80 +++++++++++++++------------------ drivers/staging/iio/adc/ad7887_ring.c | 2 +- 3 files changed, 37 insertions(+), 46 deletions(-)drivers/staging/iio/adc/ad7887.h +0
-1@@ -60,7 +60,6 @@ struct ad7887_chip_info { };struct ad7887_state { -struct iio_dev *indio_dev;struct spi_device *spi;const struct ad7887_chip_info *chip_info;struct regulator *reg;drivers/staging/iio/adc/ad7887_core.c +36
-44@@ -90,13 +90,13 @@ static int __devinit ad7887_probe(struct spi_device *spi) {struct ad7887_platform_data *pdata = spi->dev.platform_data;struct ad7887_state *st; -int ret, voltage_uv =0 ; +int ret, voltage_uv =0 , regdone =0 ; +struct iio_dev *indio_dev =iio_allocate_device (sizeof (*st)); - st =kzalloc (sizeof (*st),GFP_KERNEL ); -if (st ==NULL ) { - ret = -ENOMEM ; - goto error_ret; - } +if (indio_dev ==NULL ) +return -ENOMEM ; + + st =iio_priv (indio_dev); st->reg =regulator_get (&spi->dev,"vcc" );if (!IS_ERR (st->reg)) {@@ -110,26 +110,16 @@ static int __devinit ad7887_probe(struct spi_device *spi) st->chip_info = &ad7887_chip_info_tbl[spi_get_device_id (spi)->driver_data]; -spi_set_drvdata (spi, st); - +spi_set_drvdata (spi, indio_dev); st->spi = spi; - st->indio_dev =iio_allocate_device (0 ); -if (st->indio_dev ==NULL ) { - ret = -ENOMEM ; - goto error_disable_reg; - } -/* Estabilish that the iio_dev is a child of the spi device */ - st->indio_dev->dev.parent = &spi->dev; - st->indio_dev->name =spi_get_device_id (spi)->name; - st->indio_dev->dev_data = (void *)(st); - st->indio_dev->channels = st->chip_info->channel; - st->indio_dev->num_channels =3 ; - st->indio_dev->read_raw = &ad7887_read_raw; - - st->indio_dev->driver_module =THIS_MODULE ; - st->indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->dev.parent = &spi->dev; + indio_dev->name =spi_get_device_id (spi)->name; + indio_dev->dev_data = (void *)(st); + indio_dev->read_raw = &ad7887_read_raw; + indio_dev->driver_module =THIS_MODULE ; + indio_dev->modes =INDIO_DIRECT_MODE ;/* Setup default message */ @@ -180,8 +170,8 @@ static int __devinit ad7887_probe(struct spi_device *spi)else dev_warn (&spi->dev,"reference voltage unspecified\n" ); - st->indio_dev->channels = st->chip_info->channel; - st->indio_dev->num_channels =3 ; + indio_dev->channels = st->chip_info->channel; + indio_dev->num_channels =3 ; }else {if (pdata && pdata->vref_mv) st->int_vref_mv = pdata->vref_mv;@@ -190,53 +180,55 @@ static int __devinit ad7887_probe(struct spi_device *spi)else dev_warn (&spi->dev,"reference voltage unspecified\n" ); - st->indio_dev->channels = &st->chip_info->channel[1 ]; - st->indio_dev->num_channels =2 ; + indio_dev->channels = &st->chip_info->channel[1 ]; + indio_dev->num_channels =2 ; } - ret =ad7887_register_ring_funcs_and_init (st->indio_dev); + ret =ad7887_register_ring_funcs_and_init (indio_dev);if (ret) - goto error_free_device; + goto error_disable_reg; - ret =iio_device_register (st->indio_dev); + ret =iio_device_register (indio_dev);if (ret) - goto error_free_device; + goto error_disable_reg; + regdone =1 ; - ret =iio_ring_buffer_register_ex (st->indio_dev->ring,0 , - st->indio_dev->channels, - st->indio_dev->num_channels); + ret =iio_ring_buffer_register_ex (indio_dev->ring,0 , + indio_dev->channels, + indio_dev->num_channels);if (ret) goto error_cleanup_ring;return 0 ; error_cleanup_ring: -ad7887_ring_cleanup (st->indio_dev); -iio_device_unregister (st->indio_dev); -error_free_device: -iio_free_device (st->indio_dev); +ad7887_ring_cleanup (indio_dev); error_disable_reg:if (!IS_ERR (st->reg))regulator_disable (st->reg); error_put_reg:if (!IS_ERR (st->reg))regulator_put (st->reg); -kfree (st); -error_ret: +if (regdone) +iio_device_unregister (indio_dev); +else +iio_free_device (indio_dev); +return ret; }static int ad7887_remove (struct spi_device *spi) { -struct ad7887_state *st =spi_get_drvdata (spi); -struct iio_dev *indio_dev = st->indio_dev; +struct iio_dev *indio_dev =spi_get_drvdata (spi); +struct ad7887_state *st =iio_priv (indio_dev); +iio_ring_buffer_unregister (indio_dev->ring);ad7887_ring_cleanup (indio_dev); -iio_device_unregister (indio_dev);if (!IS_ERR (st->reg)) {regulator_disable (st->reg);regulator_put (st->reg); } -kfree (st); +iio_device_unregister (indio_dev); +return 0 ; }drivers/staging/iio/adc/ad7887_ring.c +1
-1@@ -27,7 +27,7 @@int ad7887_scan_from_ring (struct ad7887_state *st,long mask) { -struct iio_ring_buffer *ring = st->indio_dev->ring; +struct iio_ring_buffer *ring =iio_priv_to_dev (st)->ring;int count =0 , ret;u16 *ring_data;
Quoted 5 lines · On 04/18/11 14:03, [email protected] wrote:
From: Michael Hennerich <[email protected]>
Convert to new channel registration method
Update / change license copyright header
Add missing call toiio_trigger_notify_done()
Looks good. I wonder if it would make more sense to have the channel definitions external to the chip_info structure (have a pointer and size parameter in there.) That would allow the driver to handle devices with different numbers of channels. Right now it's irrelevant though and can be easily enough fixed when/if it becomes an issue.
Thanks,
Will slot this one into relevant spot in iio-onwards.
Quoted 2 lines
Signed-off-by Michael Hennerich <[email protected]>
Quoted 5 lines
--- drivers/staging/iio/adc/ad7887.h | 14 ++-- drivers/staging/iio/adc/ad7887_core.c | 123 ++++++++++++++------------------- drivers/staging/iio/adc/ad7887_ring.c | 71 +++----------------- 3 files changed, 69 insertions(+), 139 deletions(-)