iio: [v2] add support for Analog Devices ad7194 a/d converter
Subsystems (4)
PATCH 1/1 iio: [v2] add support for Analog Devices ad7194 a/d converter
This uses the iio sysfs interface, and inculdes gain
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7194.c | 393 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 401 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7194.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -17,6 +17,13 @@ config AD7152 Say yes here to build support for Analog Devices capacitive sensors. (ad7152, ad7153) Provides direct access via sysfs. +config AD7194 + tristate "Analog Devices AD7194 ADC driver" + depends on SPI + help + Say yes here to build support for Analog Devices ad7194. + Provides direct access via sysfs. + config AD7291 tristate "Analog Devices AD7291 temperature sensor driver" depends on I2C
drivers/staging/iio/adc/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_AD7298) += ad7298.o obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7152) += ad7152.o +obj-$(CONFIG_AD7194) += ad7194.o obj-$(CONFIG_AD7291) += ad7291.o obj-$(CONFIG_AD7314) += ad7314.o obj-$(CONFIG_AD7745) += ad7745.o
drivers/staging/iio/adc/ad7194.c new file +393 -0
393 lines not on this page · raw message
Signature · 1 line
1.6.2.5
OK, so this used the iio_chan_spec now. I just did 1 attribute for the gain instead of 1 / channel. It's always set before the query anyway so there's no reason for it to be per channel.
thanks,
Paul
Quoted 1 line · Paul Thomas
This uses the iio sysfs interface, and inculdes gain
includes
Couple of left over bits from chan_spec conversion that need cleaning up and a that gain attribute wants to be done via the scale_shared chan_info element instead.
Some other nitpicks inline. Mostly looks good though so shouldn't take much time to clean up.
Thanks,
Jonathan
Quoted 72 lines
Signed-off-by Paul Thomas <[email protected]>--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7194.c | 393 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 401 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7194.cdrivers/staging/iio/adc/Kconfig +7
-0@@ -17,6 +17,13 @@ config AD7152 Say yes here to build support for Analog Devices capacitive sensors. (ad7152, ad7153) Provides direct access via sysfs. +config AD7194 + tristate "Analog Devices AD7194 ADC driver" + depends on SPI + help + Say yes here to build support for Analog Devices ad7194. + Provides direct access via sysfs. + config AD7291 tristate "Analog Devices AD7291 temperature sensor driver" depends on I2Cdrivers/staging/iio/adc/Makefile +1
-0@@ -31,6 +31,7 @@ obj-$(CONFIG_AD7298) += ad7298.o obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7152) += ad7152.o +obj-$(CONFIG_AD7194) += ad7194.o obj-$(CONFIG_AD7291) += ad7291.o obj-$(CONFIG_AD7314) += ad7314.o obj-$(CONFIG_AD7745) += ad7745.odrivers/staging/iio/adc/ad7194.c new file +27
-0@@ -0,0 +1,393 @@ +/* +* ad7194 - driver for Analog Devices AD7194 A/D converter +* +* Copyright (c) 2011 Paul Thomas <[email protected]> +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 or +* later as publishhed by the Free Software Foundation. +* +* You need to have something like this in struct spi_board_info +* { +* .modalias = "ad7194", +* .max_speed_hz = 2*1000*1000, +* .chip_select = 0, +* .bus_num = 1, +* }, +* +* There is 1 universial gain that is used for each read. +*/ + +/*From Table 15 in the datasheet*/ +/*Register addresses*/
drivers/staging/iio/adc/ad7194.c line 37
Quoted 10 lines
drivers/staging/iio/adc/ad7194.c new file +10
-0+#define REG_STATUS 0 +#define REG_MODE 1 +#define REG_CONF 2 +#define REG_DATA 3 +#define REG_ID 4 +#define REG_GPOCON 5 +#define REG_OFFSET 6 +#define REG_FS 7 + +/*From Table 15 in the datasheet*/
What are these bp, bm and gc suffixes for?
Quoted 21 lines
drivers/staging/iio/adc/ad7194.c new file +21
-0+#define COMM_ADDR_bp 3 +#define COMM_READ_bm (1 << 6) + +#define CONF_CHOP_bm (1 << 23) +#define CONF_PSEUDO_bm (1 << 18) +#define CONF_BUF_bm (1 << 4) +#define CONF_CHAN_NEG_bp 8 +#define CONF_CHAN_POS_bp 12 + + +#define MODE_MD_SINGLE_gc (0x01 << 21) +#define MODE_MD_ZS_CAL_gc (0x04 << 21) +#define MODE_MD_FS_CAL_gc (0x05 << 21) +#define MODE_CLK_INTTRI_gc (0x02 << 18) +/*Table 8 in the datasheet provides options for the Filter Word*/ +#define MODE_FILTER_WORD 1 +#define SETTLE_MS 2 + +#include <linux/device.h> +#include <linux/module.h> +#include <linux/init.h>
drivers/staging/iio/adc/ad7194.c line 68
Quoted 10 lines
drivers/staging/iio/adc/ad7194.c new file +10
-0+#include <linux/spi/spi.h> +#include <linux/err.h> +#include <linux/mutex.h> +#include <linux/delay.h> + +#include "../iio.h" +#include "../sysfs.h" + +#define DEVICE_NAME "ad7194" +#define NUM_CHANNELS 16
Not used so drop.
Quoted 4 lines
drivers/staging/iio/adc/ad7194.c new file +4
-0+ +const uint8_t gains[8 ] = {1 ,0 ,0 ,8 ,16 ,32 ,64 ,128 }; + +struct ad7194_state {
drivers/staging/iio/adc/ad7194.c line 82
Quoted 10 lines
drivers/staging/iio/adc/ad7194.c new file +10
-0+struct spi_device *spi_dev; +struct iio_dev *indio_dev; +uint8_t gain; +struct mutex lock; +}; + +static ssize_t show_gain (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev);
Inconsistent naming. Pick either dev_info of indio_dev (yes, I'm the fool who put both of these in the same driver first, but no need to copy me ;)
drivers/staging/iio/adc/ad7194.c line 83
Quoted 1 line
drivers/staging/iio/adc/ad7194.c new file +1
-0+struct ad7194_state *st = dev_info->dev_data;
dev_data just got dropped entirely (when Greg merges patches I sent him on Friday.) It's been deprecated for a while and I got the final tested by last week on a tricky conversion so it's gone now. As you are using a size in iio_allocate_device just use
struct ad7194_state *st = iio_priv(dev_info);
everywhere you have a dev_info->dev_data.
Also gain is handled by the iio_chan_spec and read_raw. There is a shared version that covers what you are doing here. Also attribute is in_scale for this. Note this will involve some conversions as the scale value should be what you multiply the raw reading by to get an output in millivolts.
drivers/staging/iio/adc/ad7194.c line 95
Quoted 12 lines
drivers/staging/iio/adc/ad7194.c new file +12
-0+ +return sprintf (buf,"%d\n" , gains[st->gain]); +} + +static ssize_t set_gain (struct device *dev, +struct device_attribute *attr,const char *buf,size_t count) +{ +uint8_t gain_real, i; +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7194_state *st = dev_info->dev_data; + + gain_real =simple_strtol (buf,NULL ,10 );
simple_strtol was always dubious, now it's deprecated as well. kstrtou8 is a better choice.
drivers/staging/iio/adc/ad7194.c line 98
Quoted 3 lines
drivers/staging/iio/adc/ad7194.c new file +3
-0+if (gain_real ==0 ) +return -EPERM ; +for (i =0 ; i <8 ; i++) {
Check patch should I think have moaned about extra brackets for the for loop.
Quoted 44 lines
drivers/staging/iio/adc/ad7194.c new file +44
-0+if (gains[i] == gain_real) { + st->gain = i; +return count; + } + } +return -EPERM ; +} + +static inline int ad7194_read_reg8 (struct spi_device *spi, +int reg,uint8_t *val) +{ +int ret; +uint8_t tx[1 ], rx[1 ]; + + tx[0 ] = (COMM_READ_bm | (reg << COMM_ADDR_bp)); + + ret =spi_write_then_read (spi, tx,1 , rx,1 ); + *val = rx[0 ]; +return ret; +} + +static inline int ad7194_read_reg24 (struct spi_device *spi, +int reg,uint32_t *val) +{ +int ret; +uint8_t tx[1 ], rx[3 ]; + + tx[0 ] = (COMM_READ_bm | (reg << COMM_ADDR_bp)); + + ret =spi_write_then_read (spi, tx,1 , rx,3 ); + *val = (rx[0 ] <<16 ) + (rx[1 ] <<8 ) + rx[2 ]; +return ret; +} + +static inline int ad7194_write_reg24 (struct spi_device *spi, +int reg,uint32_t *val) +{ +uint8_t *tx; + tx =kmalloc (4 ,GFP_KERNEL ); + + tx[0 ] = (reg << COMM_ADDR_bp); + tx[1 ] = (*val >>16 ) &0xff ; + tx[2 ] = (*val >>8 ) &0xff ; + tx[3 ] = (*val >>0 ) &0xff ;
drivers/staging/iio/adc/ad7194.c line 152
Quoted 10 lines
drivers/staging/iio/adc/ad7194.c new file +10
-0+ +return spi_write (spi, tx,4 ); +} + +static ssize_t show_voltage (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val, +int *val2, +long m) +{
In kernel stuff, so u32, u8, s32 as types please. Actually that's true everywhere, I just happened to notice it here ;)
Quoted 31 lines
drivers/staging/iio/adc/ad7194.c new file +31
-0+uint32_t conf, mode, myval, sign; +uint8_t status; +int32_t whole, fract; +int ret; + +struct ad7194_state *st =iio_priv (indio_dev); +struct spi_device *spi = st->spi_dev; + +if (chan->type ==IIO_IN_DIFF ) + conf = CONF_CHOP_bm | CONF_BUF_bm | + ((chan->channel -1 ) << CONF_CHAN_POS_bp) | + ((chan->channel2 -1 ) << CONF_CHAN_NEG_bp) | st->gain; +else + conf = CONF_CHOP_bm | CONF_BUF_bm | CONF_PSEUDO_bm | + ((chan->channel -1 ) << CONF_CHAN_POS_bp) | st->gain; + + ret =mutex_lock_interruptible (&st->lock); +if (ret !=0 ) +return ret; + + ret =ad7194_write_reg24 (spi,REG_CONF , &conf); +if (ret !=0 ) + goto out; + + mode = MODE_MD_SINGLE_gc | MODE_CLK_INTTRI_gc |MODE_FILTER_WORD ; + ret =ad7194_write_reg24 (spi,REG_MODE , &mode); +if (ret !=0 ) + goto out; + +msleep_interruptible (SETTLE_MS ); +
drivers/staging/iio/adc/ad7194.c line 193
Quoted 10 lines
drivers/staging/iio/adc/ad7194.c new file +10
-0+ ret =ad7194_read_reg8 (spi,REG_STATUS , &status); +if (ret !=0 ) + goto out; + status = (status >>6 ) &0x01 ; + + ret =ad7194_read_reg24 (spi,REG_DATA , &myval); +if (ret !=0 ) + goto out; + + sign = (myval &0x800000 ) >>23 ;
(no need for the right shift though irrelevant given next suggestion - 0x800000000 = true).
drivers/staging/iio/adc/ad7194.c line 197
Quoted 4 lines
drivers/staging/iio/adc/ad7194.c new file +4
-0+if (sign) + fract = (myval &0x7fffff ); +else + fract =0x7fffff - (myval &0x7fffff );
There are cleaner options for sign extension.
Classic trick would be something like:
fract = (s32)((myval & 0xffffff << 8) >> 8;
drivers/staging/iio/adc/ad7194.c line 203
Quoted 6 lines
drivers/staging/iio/adc/ad7194.c new file +6
-0+ fract = ((int64_t )fract*4095000 ) >>23 ; + fract = fract / gains[st->gain]; + whole = fract /1000000 ; + fract = fract %1000000 ; + +if (status ==0 ) {
better for program flow to do the status check much earlier.
Quoted 9 lines
drivers/staging/iio/adc/ad7194.c new file +9
-0+mutex_unlock (&st->lock); +if (sign) { + *val = whole; + *val2 = fract; + }else { + *val = whole; + *val2 = -fract; + } +return IIO_VAL_INT_PLUS_MICRO ;
drivers/staging/iio/adc/ad7194.c line 222
Quoted 10 lines
drivers/staging/iio/adc/ad7194.c new file +10
-0+ }else { + ret = -EAGAIN ; + goto out; + } + +out: +mutex_unlock (&st->lock); +return ret; +} +
Couple of things here some of which you had no way of knowing about!
a) I'm trying to clear out that IIO_CHAN macro. Arnd warned me when I introduced it and he was right. It's a maintenance nightmare. Hence please use explicit asignment of the elements. A local macro will help with this. Note scan type is currently irrelevant as you don't support buffering so we'll add it if anyone ever needs it. Same is true of scan_index and you don't use address anywhere either. So we don't need to set that many elements.
#define AD7194_CHAN_S(index)\
{\
.type = IIO_IN,\
.indexed = 1,\
.channel = index,\
.info_mask = (1 << IIO_CHAN_INFO_SCALE_SHARED),\ \\note this is your 'gain' equivalent.
}#define AD7194_CHAN_D(index1, index2) \
{\
.type = IIO_DIFF,\
.indexed = 1,\
.channel = index1,\
.channel2 = index2,\
.info_mask = (1 << IIO_CHAN_INFO_SCALE_SHARED),\ \\note we don't support sharing gainacross channel types so will have two attributes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FF ,0 ,1 ,0 ,NULL ,8 ,7 ,0 , +23 ,23 ,IIO_ST ('s' ,24 ,32 ,0 ),0 ), +IIO_CHAN (IIO_IN_DIFF ,0 ,1 ,0 ,NULL ,9 ,10 ,0 , +24 ,24 ,IIO_ST ('s' ,24 ,32 ,0 ),0 ), +IIO_CHAN (IIO_IN_DIFF ,0 ,1 ,0 ,NULL ,10 ,9 ,0 , +25 ,25 ,IIO_ST ('s' ,24 ,32 ,0 ),0 ), +IIO_CHAN (IIO_IN_DIFF ,0 ,1 ,0 ,NULL ,11 ,12 ,0 , +26 ,26 ,IIO_ST ('s' ,24 ,32 ,0 ),0 ), +IIO_CHAN (IIO_IN_DIFF ,0 ,1 ,0 ,NULL ,12 ,11 ,0 , +27 ,27 ,IIO_ST ('s' ,24 ,32 ,0 ),0 ), +IIO_CHAN (IIO_IN_DIFF ,0 ,1 ,0 ,NULL ,13 ,14 ,0 , +28 ,28 ,IIO_ST ('s' ,24 ,32 ,0 ),0 ), +IIO_CHAN (IIO_IN_DIFF ,0 ,1 ,0 ,NULL ,14 ,13 ,0 , +29 ,29 ,IIO_ST ('s' ,24 ,32 ,0 ),0 ), +IIO_CHAN (IIO_IN_DIFF ,0 ,1 ,0 ,NULL ,15 ,16 ,0 , +30 ,30 ,IIO_ST ('s' ,24 ,32 ,0 ),0 ), +IIO_CHAN (IIO_IN_DIFF ,0 ,1 ,0 ,NULL ,16 ,15 ,0 , +31 ,31 ,IIO_ST ('s' ,24 ,32 ,0 ),0 ), +}; + +static IIO_DEVICE_ATTR(gain, S_IWUSR | S_IRUGO, show_gain, set_gain, -1); + +static struct attribute *ad7194_attributes[] = { + &iio_dev_attr_gain.dev_attr.attr, +NULL , +}; + +static const struct attribute_group ad7194_attribute_group = { + .attrs = ad7194_attributes, +}; + +static const struct iio_info ad7194_info = { + .attrs = &ad7194_attribute_group, + .read_raw = &show_voltage, + .driver_module =THIS_MODULE ,
drivers/staging/iio/adc/ad7194.c line 314
Quoted 10 lines
drivers/staging/iio/adc/ad7194.c new file +10
-0+}; + +static int __devinit ad7194_probe (struct spi_device *spi) +{ +int ret; +struct ad7194_state *st; +struct iio_dev *indio_dev; + +/* Configure the SPI bus */ + spi->mode = (SPI_MODE_0 );
Again, please run checkpatch over this, those brackets will cause a warning.
drivers/staging/iio/adc/ad7194.c line 315
Quoted 1 line
drivers/staging/iio/adc/ad7194.c new file +1
-0+ spi->bits_per_word =8 ;
Should be the default, but feel free to make sure!
drivers/staging/iio/adc/ad7194.c line 325
Quoted 11 lines
drivers/staging/iio/adc/ad7194.c new file +10
-0+spi_setup (spi); + + indio_dev =iio_allocate_device (sizeof (struct ad7194_state )); +if (indio_dev ==NULL ) { + ret = -ENOMEM ; + goto exit; + } + st =iio_priv (indio_dev); + +dev_set_drvdata (&spi->dev, st);
Don't think this line does anything (fairly sure the spi_set_drvdata will overwrite it in a mo).
drivers/staging/iio/adc/ad7194.c line 328
Quoted 3 lines
drivers/staging/iio/adc/ad7194.c new file +3
-0+ + st->spi_dev = spi; +
Why do we have two iio_allocate_devices? One is plenty. (I'm guessing this is dead code).
Quoted 4 lines
drivers/staging/iio/adc/ad7194.c new file +4
-0+ st->indio_dev =iio_allocate_device (0 ); +if (st->indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_free;
drivers/staging/iio/adc/ad7194.c line 342
Quoted 10 lines
drivers/staging/iio/adc/ad7194.c new file +10
-0+ } + +spi_set_drvdata (spi, indio_dev); + st->spi_dev = spi; + +mutex_init (&st->lock); + indio_dev->name ="ad7194" ; + indio_dev->dev.parent = &spi->dev; + indio_dev->info = &ad7194_info; + indio_dev->dev_data = (void *)st;
Gone.
drivers/staging/iio/adc/ad7194.c line 354
Quoted 12 lines
drivers/staging/iio/adc/ad7194.c new file +12
-0+ indio_dev->channels = ad7194_channels; + indio_dev->num_channels =ARRAY_SIZE (ad7194_channels); + + ret =iio_device_register (indio_dev); +if (ret) + goto error_free_dev; + +return 0 ; + +error_free_dev: +iio_free_device (st->indio_dev); +error_free:
Check this error path. st is never explicitly allocated.
drivers/staging/iio/adc/ad7194.c line 361
Quoted 7 lines
drivers/staging/iio/adc/ad7194.c new file +7
-0+kfree (st); +exit: +return ret; +} + +static int __devexit ad7194_remove(struct spi_device *spi) +{
roll into one line.
iio_device_unregister(spi_get_drvdata(spi));
drivers/staging/iio/adc/ad7194.c line 369
Quoted 8 lines
drivers/staging/iio/adc/ad7194.c new file +8
-0+struct iio_dev *indio_dev =spi_get_drvdata (spi); +iio_device_unregister (indio_dev); +return 0 ; +} + +static struct spi_driver ad7194_driver = { + .driver = { + .name =DEVICE_NAME ,
DEVICE_NAME is only used here, so I'd just put "ad7194" here directly and get rid of the define.
drivers/staging/iio/adc/ad7194.c line 370
Quoted 1 line
drivers/staging/iio/adc/ad7194.c new file +1
-0+ .bus = &spi_bus_type,
I'm fairly sure spi_register_driver will set the bus type anyway so don't need this here.
Quoted 8 lines
drivers/staging/iio/adc/ad7194.c new file +8
-0+ .owner = THIS_MODULE, + }, + + .probe = ad7194_probe, + .remove = __devexit_p(ad7194_remove), +}; + +static int __init ad7194_init (void )
drivers/staging/iio/adc/ad7194.c line 388
Quoted 10 lines
drivers/staging/iio/adc/ad7194.c new file +10
-0+{ +return spi_register_driver (&ad7194_driver); +} + +static void __exit ad7194_exit(void) +{ +spi_unregister_driver (&ad7194_driver); +} + +module_init (ad7194_init);
Convention puts these directly under the functions rather than in a block on their own down here.
Quoted 5 lines
drivers/staging/iio/adc/ad7194.c new file +5
-0+module_exit (ad7194_exit); + +MODULE_AUTHOR ("Paul Thomas <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices AD7194 A/D driver" ); +MODULE_LICENSE ("GPL" );
Quoted 7 lines · Jonathan Cameron
Quoted 1 line · Paul Thomas
This uses the iio sysfs interface, and inculdes gain
includes
Couple of left over bits from
chan_specconversion that need cleaning up and a that gain attribute wants to be done via thescale_sharedchan_infoelement instead.
OK, most of that makes sense. I might have more questions latter, but one question for now. You say to use the scale_shared for the gain (can you point do a good example of this?) I just want to make sure we're on the same page as to what the gain is doing. It's really just setting the range of the voltage input I scale the result back down to volts. So if the input voltage is 0.2V you get 0.2V Whether you set the gain to 1 or 8
thanks,
Paul
Quoted 8 lines · Paul Thomas
Quoted 7 lines · Jonathan Cameron
Quoted 1 line · Paul Thomas
This uses the iio sysfs interface, and inculdes gain
includes
Couple of left over bits from
chan_specconversion that need cleaning up and a that gain attribute wants to be done via thescale_sharedchan_infoelement instead.
Quoted 7 lines
OK, most of that makes sense. I might have more questions latter, but one question for now. You say to use the
scale_sharedfor the gain (can you point do a good example of this?) I just want to make sure we're on the same page as to what the gain is doing. It's really just setting the range of the voltage input I scale the result back down to volts. So if the input voltage is 0.2V you get 0.2V Whether you set the gain to 1 or 8
Ah, I missed that. In that case, given it's internal only, it should be IIO_CHAN_INFO_CALIBSCALE_SHARED and you should be setting processed_val in iio_chan_spec structures and scaling to millivolts not volts (we may change everything to volts but haven't done it yet).
For a device like this we tend to leave things raw and use the scale attribute to tell userspace enough to know how to convert it to SI units. Doesn't matter so much with devices only being accessed over sysfs (hence fine here) but you don't want to waste time with conversions when pushing to a buffer.
Jonathan
Quoted 2 lines · Jonathan Cameron
Quoted 1 line · Paul Thomas
On Mon, Aug 15, 2011 at 2:52 AM, Jonathan Cameron <[email protected]> wrot=
e:
Quoted 14 lines
Quoted 7 lines
Quoted 7 lines · Paul Thomas
Quoted 1 line
This uses the iio sysfs interface, and inculdes gain
includes
Couple of left over bits from
chan_specconversion that need cleaning up and a that gain attribute wants to be done via thescale_sharedchan_infoelement instead.Quoted 7 lines
OK, most of that makes sense. I might have more questions latter, but one question for now. You say to use the
scale_sharedfor the gain (can you point do a good example of this?) =A0I just want to make sure we're on the same page as to what the gain is doing. It's really just setting the range of the voltage input I scale the result back down to volts. So if the input voltage is 0.2V you get 0.2V Whether you set the gain to 1 or 8
Quoted 2 lines
Ah, I missed that. In that case, given it's internal only, it should be
IIO_CHAN_INFO_CALIBSCALE_SHAREDand you should be setting processed_va=
l
Quoted 4 lines
in
iio_chan_specstructures and scaling to millivolts not volts (we may change everything to volts but haven't done it yet).For a device like this we tend to leave things raw and use the scale attr=
ibute
Quoted 1 line
to tell userspace enough to know how to convert it to SI units. =A0Doesn'=
t
Quoted 1 line
matter so much with devices only being accessed over sysfs (hence fine he=
re)
Quoted 1 line
but you don't want to waste time with conversions when pushing to a buffe=
r.
Quoted 3 lines
Jonathan
OK, but isn't this just about what the best way to report the values? What should the knob/hook from userspace be to set the gain/range?
thanks,
Paul
Quoted 27 lines · Paul Thomas
Quoted 26 lines · Jonathan Cameron
Quoted 8 lines · Paul Thomas
Quoted 7 lines · Jonathan Cameron
Quoted 1 line · Paul Thomas
This uses the iio sysfs interface, and inculdes gain
includes
Couple of left over bits from
chan_specconversion that need cleaning up and a that gain attribute wants to be done via thescale_sharedchan_infoelement instead.Quoted 7 lines
OK, most of that makes sense. I might have more questions latter, but one question for now. You say to use the
scale_sharedfor the gain (can you point do a good example of this?) I just want to make sure we're on the same page as to what the gain is doing. It's really just setting the range of the voltage input I scale the result back down to volts. So if the input voltage is 0.2V you get 0.2V Whether you set the gain to 1 or 8Ah, I missed that. In that case, given it's internal only, it should be
IIO_CHAN_INFO_CALIBSCALE_SHAREDand you should be settingprocessed_valiniio_chan_specstructures and scaling to millivolts not volts (we may change everything to volts but haven't done it yet).For a device like this we tend to leave things raw and use the scale attribute to tell userspace enough to know how to convert it to SI units. Doesn't matter so much with devices only being accessed over sysfs (hence fine here) but you don't want to waste time with conversions when pushing to a buffer.
Quoted 5 lines
Quoted 2 lines
Jonathan
OK, but isn't this just about what the best way to report the values? What should the knob/hook from userspace be to set the gain/range?
Two ways of doing this:
1) If reporting _raw values, the calibscale and calibbias are controls for an offset and scale applied inside the hardware. Here, control is done via scale and offset (as userspace has to apply these later anyway). There has been some debate about range and it is in the abi, but hasn't been added to chan_spec stuff yet.
2) If reporting _input (processed values) as you are here, then it looks to userspace as if hardware has already applied these values - hence conventionally we have been using calibscale and calibbias under that condition. Only place this really happened before is in the light sensors. There the transform is so hideous, it's not practical to tell userspace what it is, hence processing is done internally and calibscale is actually a software knob.
So given your current situation, either use the range attribute (and add it to the chan spec core stuff) or use calibscale.
Sorry for the slow reply,
Jonathan