iio:ad5064: Report scale as fractional value
Subsystems (7)
PATCH 1/25 iio:ad5064: Report scale as fractional value
Move the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/ad5064.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/dac/ad5064.c +3 -4
@@ -239,10 +239,9 @@ static int ad5064_read_raw(struct iio_dev *indio_dev,if (scale_uv <0 )return scale_uv; - scale_uv = (scale_uv *100 ) >> chan->scan_type.realbits; - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = scale_uv /1000 ; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;default :break ; }
Signature · 1 line
1.8.0
PATCH 2/25 iio:ad5360: Report scale as fractional value
Move the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/ad5360.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/dac/ad5360.c +5 -6
@@ -379,15 +379,14 @@ static int ad5360_read_raw(struct iio_dev *indio_dev, *val = ret >> chan->scan_type.shift;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : -/* vout = 4 * vref * dac_code */ - scale_uv =ad5360_get_channel_vref (st, chan->channel) *4 *100 ; + scale_uv =ad5360_get_channel_vref (st, chan->channel);if (scale_uv <0 )return scale_uv; - scale_uv >>= (chan->scan_type.realbits); - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; +/* vout = 4 * vref * dac_code */ + *val = scale_uv *4 /1000 ; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_CALIBBIAS : ret =ad5360_read (indio_dev,AD5360_READBACK_OFFSET , chan->address);
Signature · 1 line
1.8.0
Re: [PATCH 02/25] iio:ad5360: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
Thanks
Quoted 30 lines
--- drivers/iio/dac/ad5360.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/iio/dac/ad5360.c +5
-6@@ -379,15 +379,14 @@ static int ad5360_read_raw(struct iio_dev *indio_dev, *val = ret >> chan->scan_type.shift;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : -/* vout = 4 * vref * dac_code */ - scale_uv =ad5360_get_channel_vref (st, chan->channel) *4 *100 ; + scale_uv =ad5360_get_channel_vref (st, chan->channel);if (scale_uv <0 )return scale_uv; - scale_uv >>= (chan->scan_type.realbits); - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; +/* vout = 4 * vref * dac_code */ + *val = scale_uv *4 /1000 ; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_CALIBBIAS : ret =ad5360_read (indio_dev,AD5360_READBACK_OFFSET , chan->address);
PATCH 3/25 iio:ad5380: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/ad5380.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-)
drivers/iio/dac/ad5380.c +19 -21
@@ -204,7 +204,6 @@ static int ad5380_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long info) { struct ad5380_state *st = iio_priv(indio_dev); -unsigned long scale_uv;int ret;switch (info) {
@@ -225,10 +224,9 @@ static int ad5380_read_raw(struct iio_dev *indio_dev, val -= (1 << chan->scan_type.realbits) /2 ;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = ((2 * st->vref) >> chan->scan_type.realbits) *100 ; - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val =2 * st->vref; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;default :break ; }
@@ -271,72 +269,72 @@ static const struct ad5380_chip_info ad5380_chip_info_tbl[] = { [ID_AD5380_3 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =40 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5380_5 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =40 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5381_3 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =16 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5381_5 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =16 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5382_3 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =32 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5382_5 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =32 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5383_3 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =32 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5383_5 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =32 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5390_3 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =16 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5390_5 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =16 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5391_3 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =16 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5391_5 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =16 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5392_3 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =8 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5392_5 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =8 , - .int_vref =2500000 , + .int_vref =2500 , }, };
@@ -395,7 +393,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,return ret; } -if (st->chip_info->int_vref ==2500000 ) +if (st->chip_info->int_vref ==2500 ) ctrl |=AD5380_CTRL_INT_VREF_2V5 ; st->vref_reg =devm_regulator_get (dev,"vref" );
@@ -411,7 +409,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,if (ret <0 ) goto error_disable_reg; - st->vref = ret; + st->vref = ret /1000 ; }else { st->vref = st->chip_info->int_vref; ctrl |=AD5380_CTRL_INT_VREF_EN ;
Signature · 1 line
1.8.0
Re: [PATCH 03/25] iio:ad5380: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
Thanks
Quoted 136 lines
--- drivers/iio/dac/ad5380.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-)drivers/iio/dac/ad5380.c +19
-21@@ -204,7 +204,6 @@ static int ad5380_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long info) { struct ad5380_state *st = iio_priv(indio_dev); -unsigned long scale_uv;int ret;switch (info) {@@ -225,10 +224,9 @@ static int ad5380_read_raw(struct iio_dev *indio_dev, val -= (1 << chan->scan_type.realbits) /2 ;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = ((2 * st->vref) >> chan->scan_type.realbits) *100 ; - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val =2 * st->vref; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;default :break ; }@@ -271,72 +269,72 @@ static const struct ad5380_chip_info ad5380_chip_info_tbl[] = { [ID_AD5380_3 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =40 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5380_5 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =40 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5381_3 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =16 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5381_5 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =16 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5382_3 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =32 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5382_5 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =32 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5383_3 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =32 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5383_5 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =32 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5390_3 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =16 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5390_5 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =16 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5391_3 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =16 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5391_5 ] = { .channel_template =AD5380_CHANNEL (12 ), .num_channels =16 , - .int_vref =2500000 , + .int_vref =2500 , }, [ID_AD5392_3 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =8 , - .int_vref =1250000 , + .int_vref =1250 , }, [ID_AD5392_5 ] = { .channel_template =AD5380_CHANNEL (14 ), .num_channels =8 , - .int_vref =2500000 , + .int_vref =2500 , }, };@@ -395,7 +393,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,return ret; } -if (st->chip_info->int_vref ==2500000 ) +if (st->chip_info->int_vref ==2500 ) ctrl |=AD5380_CTRL_INT_VREF_2V5 ; st->vref_reg =devm_regulator_get (dev,"vref" );@@ -411,7 +409,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,if (ret <0 ) goto error_disable_reg; - st->vref = ret; + st->vref = ret /1000 ; }else { st->vref = st->chip_info->int_vref; ctrl |=AD5380_CTRL_INT_VREF_EN ;
PATCH 4/25 iio:ad5421: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/ad5421.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/iio/dac/ad5421.c +5 -11
@@ -281,18 +281,11 @@ static inline unsigned int ad5421_get_offset(struct ad5421_state *st)return (min * (1 <<16 )) / (max - min); } -static inline unsigned int ad5421_get_scale (struct ad5421_state *st) -{ -unsigned int min, max; - -ad5421_get_current_min_max (st, &min, &max); -return ((max - min) *1000 ) / (1 <<16 ); -} -static int ad5421_read_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2,long m) {struct ad5421_state *st =iio_priv (indio_dev); +unsigned int min, max;int ret;if (chan->type !=IIO_CURRENT )
@@ -306,9 +299,10 @@ static int ad5421_read_raw(struct iio_dev *indio_dev, *val = ret;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - *val =0 ; - *val2 =ad5421_get_scale (st); -return IIO_VAL_INT_PLUS_MICRO ; +ad5421_get_current_min_max (st, &min, &max); + *val = max - min; + *val2 = (1 <<16 ) *1000 ; +return IIO_VAL_FRACTIONAL ;case IIO_CHAN_INFO_OFFSET : *val =ad5421_get_offset (st);return IIO_VAL_INT ;
Signature · 1 line
1.8.0
Re: [PATCH 04/25] iio:ad5421: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
Thanks
Quoted 43 lines
--- drivers/iio/dac/ad5421.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)drivers/iio/dac/ad5421.c +5
-11@@ -281,18 +281,11 @@ static inline unsigned int ad5421_get_offset(struct ad5421_state *st)return (min * (1 <<16 )) / (max - min); } -static inline unsigned int ad5421_get_scale (struct ad5421_state *st) -{ -unsigned int min, max; - -ad5421_get_current_min_max (st, &min, &max); -return ((max - min) *1000 ) / (1 <<16 ); -} -static int ad5421_read_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2,long m) {struct ad5421_state *st =iio_priv (indio_dev); +unsigned int min, max;int ret;if (chan->type !=IIO_CURRENT )@@ -306,9 +299,10 @@ static int ad5421_read_raw(struct iio_dev *indio_dev, *val = ret;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - *val =0 ; - *val2 =ad5421_get_scale (st); -return IIO_VAL_INT_PLUS_MICRO ; +ad5421_get_current_min_max (st, &min, &max); + *val = max - min; + *val2 = (1 <<16 ) *1000 ; +return IIO_VAL_FRACTIONAL ;case IIO_CHAN_INFO_OFFSET : *val =ad5421_get_offset (st);return IIO_VAL_INT ;
PATCH 5/25 iio:ad5446: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/ad5446.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/iio/dac/ad5446.c +3 -6
@@ -163,18 +163,15 @@ static int ad5446_read_raw(struct iio_dev *indio_dev, long m) {struct ad5446_state *st =iio_priv (indio_dev); -unsigned long scale_uv;switch (m) {case IIO_CHAN_INFO_RAW : *val = st->cached_val;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->vref_mv *1000 ) >> chan->scan_type.realbits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; - + *val = st->vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
Signature · 1 line
1.8.0
Re: [PATCH 05/25] iio:ad5446: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
Thanks,
Quoted 31 lines
--- drivers/iio/dac/ad5446.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/iio/dac/ad5446.c +3
-6@@ -163,18 +163,15 @@ static int ad5446_read_raw(struct iio_dev *indio_dev, long m) {struct ad5446_state *st =iio_priv (indio_dev); -unsigned long scale_uv;switch (m) {case IIO_CHAN_INFO_RAW : *val = st->cached_val;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->vref_mv *1000 ) >> chan->scan_type.realbits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; - + *val = st->vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
PATCH 6/25 iio:ad5504: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/ad5504.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/iio/dac/ad5504.c +3 -6
@@ -100,7 +100,6 @@ static int ad5504_read_raw(struct iio_dev *indio_dev, long m) {struct ad5504_state *st =iio_priv (indio_dev); -unsigned long scale_uv;int ret;switch (m) {
@@ -113,11 +112,9 @@ static int ad5504_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->vref_mv *1000 ) >> chan->scan_type.realbits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; - + *val = st->vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
Signature · 1 line
1.8.0
Re: [PATCH 06/25] iio:ad5504: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
Thanks,
Quoted 32 lines
--- drivers/iio/dac/ad5504.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/iio/dac/ad5504.c +3
-6@@ -100,7 +100,6 @@ static int ad5504_read_raw(struct iio_dev *indio_dev, long m) {struct ad5504_state *st =iio_priv (indio_dev); -unsigned long scale_uv;int ret;switch (m) {@@ -113,11 +112,9 @@ static int ad5504_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->vref_mv *1000 ) >> chan->scan_type.realbits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; - + *val = st->vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
PATCH 7/25 iio:ad5624r: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/ad5624r_spi.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/iio/dac/ad5624r_spi.c +3 -6
@@ -50,15 +50,12 @@ static int ad5624r_read_raw(struct iio_dev *indio_dev, long m) {struct ad5624r_state *st =iio_priv (indio_dev); -unsigned long scale_uv;switch (m) {case IIO_CHAN_INFO_SCALE : - scale_uv = (st->vref_mv *1000 ) >> chan->scan_type.realbits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; - + *val = st->vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
Signature · 1 line
1.8.0
Re: [PATCH 07/25] iio:ad5624r: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
Thanks,
Quoted 28 lines
--- drivers/iio/dac/ad5624r_spi.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/iio/dac/ad5624r_spi.c +3
-6@@ -50,15 +50,12 @@ static int ad5624r_read_raw(struct iio_dev *indio_dev, long m) {struct ad5624r_state *st =iio_priv (indio_dev); -unsigned long scale_uv;switch (m) {case IIO_CHAN_INFO_SCALE : - scale_uv = (st->vref_mv *1000 ) >> chan->scan_type.realbits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; - + *val = st->vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
PATCH 8/25 iio:ad5686: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/ad5686.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/iio/dac/ad5686.c +3 -7
@@ -201,7 +201,6 @@ static int ad5686_read_raw(struct iio_dev *indio_dev, long m) {struct ad5686_state *st =iio_priv (indio_dev); -unsigned long scale_uv;int ret;switch (m) {
@@ -214,12 +213,9 @@ static int ad5686_read_raw(struct iio_dev *indio_dev, *val = ret;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->vref_mv *100000 ) - >> (chan->scan_type.realbits); - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; - + *val = st->vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
Signature · 1 line
1.8.0
Re: [PATCH 08/25] iio:ad5686: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied
Quoted 33 lines
--- drivers/iio/dac/ad5686.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/iio/dac/ad5686.c +3
-7@@ -201,7 +201,6 @@ static int ad5686_read_raw(struct iio_dev *indio_dev, long m) {struct ad5686_state *st =iio_priv (indio_dev); -unsigned long scale_uv;int ret;switch (m) {@@ -214,12 +213,9 @@ static int ad5686_read_raw(struct iio_dev *indio_dev, *val = ret;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->vref_mv *100000 ) - >> (chan->scan_type.realbits); - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; - + *val = st->vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
PATCH 9/25 iio:ad5755: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/ad5755.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/iio/dac/ad5755.c +5 -12
@@ -253,15 +253,6 @@ static inline int ad5755_get_offset(struct ad5755_state *st,return (min * (1 << chan->scan_type.realbits)) / (max - min); } -static inline int ad5755_get_scale (struct ad5755_state *st, -struct iio_chan_spec const *chan) -{ -int min, max; - -ad5755_get_min_max (st, chan, &min, &max); -return ((max - min) *1000000000ULL ) >> chan->scan_type.realbits; -} -static int ad5755_chan_reg_info (struct ad5755_state *st,struct iio_chan_spec const *chan,long info,bool write,unsigned int *reg,unsigned int *shift,unsigned int *offset)
@@ -303,13 +294,15 @@ static int ad5755_read_raw(struct iio_dev *indio_dev, {struct ad5755_state *st =iio_priv (indio_dev);unsigned int reg, shift, offset; +int min, max;int ret;switch (info) {case IIO_CHAN_INFO_SCALE : - *val =0 ; - *val2 =ad5755_get_scale (st, chan); -return IIO_VAL_INT_PLUS_NANO ; +ad5755_get_min_max (st, chan, &min, &max); + *val = max - min; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_OFFSET : *val =ad5755_get_offset (st, chan);return IIO_VAL_INT ;
Signature · 1 line
1.8.0
Re: [PATCH 09/25] iio:ad5755: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied.
Quoted 44 lines
--- drivers/iio/dac/ad5755.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)drivers/iio/dac/ad5755.c +5
-12@@ -253,15 +253,6 @@ static inline int ad5755_get_offset(struct ad5755_state *st,return (min * (1 << chan->scan_type.realbits)) / (max - min); } -static inline int ad5755_get_scale (struct ad5755_state *st, -struct iio_chan_spec const *chan) -{ -int min, max; - -ad5755_get_min_max (st, chan, &min, &max); -return ((max - min) *1000000000ULL ) >> chan->scan_type.realbits; -} -static int ad5755_chan_reg_info (struct ad5755_state *st,struct iio_chan_spec const *chan,long info,bool write,unsigned int *reg,unsigned int *shift,unsigned int *offset)@@ -303,13 +294,15 @@ static int ad5755_read_raw(struct iio_dev *indio_dev, {struct ad5755_state *st =iio_priv (indio_dev);unsigned int reg, shift, offset; +int min, max;int ret;switch (info) {case IIO_CHAN_INFO_SCALE : - *val =0 ; - *val2 =ad5755_get_scale (st, chan); -return IIO_VAL_INT_PLUS_NANO ; +ad5755_get_min_max (st, chan, &min, &max); + *val = max - min; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_OFFSET : *val =ad5755_get_offset (st, chan);return IIO_VAL_INT ;
PATCH 10/25 iio:ad5764: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
Also fix a off by one error in the comment describing the transfer function.
--- drivers/iio/dac/ad5764.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/dac/ad5764.c +4 -6
@@ -217,7 +217,6 @@ static int ad5764_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long info) { struct ad5764_state *st = iio_priv(indio_dev); -unsigned long scale_uv;unsigned int reg;int vref;int ret;
@@ -245,15 +244,14 @@ static int ad5764_read_raw(struct iio_dev *indio_dev, *val =sign_extend32 (*val,5 );return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : -/* vout = 4 * vref + ((dac_code / 65535) - 0.5) */ +/* vout = 4 * vref + ((dac_code / 65536) - 0.5) */ vref =ad5764_get_channel_vref (st, chan->channel);if (vref <0 )return vref; - scale_uv = (vref *4 *100 ) >> chan->scan_type.realbits; - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = vref *4 /1000 ; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_OFFSET : *val = -(1 << chan->scan_type.realbits) /2 ;return IIO_VAL_INT ;
Signature · 1 line
1.8.0
Re: [PATCH 10/25] iio:ad5764: Report scale as fractional value
Quoted 5 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Also fix a off by one error in the comment describing the transfer function.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
Thanks
Quoted 37 lines
--- drivers/iio/dac/ad5764.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/iio/dac/ad5764.c +4
-6@@ -217,7 +217,6 @@ static int ad5764_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long info) { struct ad5764_state *st = iio_priv(indio_dev); -unsigned long scale_uv;unsigned int reg;int vref;int ret;@@ -245,15 +244,14 @@ static int ad5764_read_raw(struct iio_dev *indio_dev, *val =sign_extend32 (*val,5 );return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : -/* vout = 4 * vref + ((dac_code / 65535) - 0.5) */ +/* vout = 4 * vref + ((dac_code / 65536) - 0.5) */ vref =ad5764_get_channel_vref (st, chan->channel);if (vref <0 )return vref; - scale_uv = (vref *4 *100 ) >> chan->scan_type.realbits; - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = vref *4 /1000 ; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_OFFSET : *val = -(1 << chan->scan_type.realbits) /2 ;return IIO_VAL_INT ;
PATCH 11/25 iio:ad5791: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/ad5791.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/dac/ad5791.c +3 -3
@@ -270,9 +270,9 @@ static int ad5791_read_raw(struct iio_dev *indio_dev, *val >>= chan->scan_type.shift;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - *val =0 ; - *val2 = (((u64 )st->vref_mv) *1000000ULL ) >> chan->scan_type.realbits; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->vref_mv; + *val2 = (1 << chan->scan_type.realbits) -1 ; +return IIO_VAL_FRACTIONAL ;case IIO_CHAN_INFO_OFFSET : val64 = (((u64 )st->vref_neg_mv) << chan->scan_type.realbits);do_div (val64, st->vref_mv);
Signature · 1 line
1.8.0
Re: [PATCH 11/25] iio:ad5791: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
The minus 1 in here had me confused for a bit, but that is indeed the transfer function given in the datasheet.
Applied to the togreg branch of iio.git
Thanks,
Quoted 22 lines
--- drivers/iio/dac/ad5791.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/iio/dac/ad5791.c +3
-3@@ -270,9 +270,9 @@ static int ad5791_read_raw(struct iio_dev *indio_dev, *val >>= chan->scan_type.shift;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - *val =0 ; - *val2 = (((u64 )st->vref_mv) *1000000ULL ) >> chan->scan_type.realbits; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->vref_mv; + *val2 = (1 << chan->scan_type.realbits) -1 ; +return IIO_VAL_FRACTIONAL ;case IIO_CHAN_INFO_OFFSET : val64 = (((u64 )st->vref_neg_mv) << chan->scan_type.realbits);do_div (val64, st->vref_mv);
PATCH 12/25 iio:max517: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/max517.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/dac/max517.c +3 -5
@@ -82,15 +82,13 @@ static int max517_read_raw(struct iio_dev *indio_dev, long m) {struct max517_data *data =iio_priv (indio_dev); -unsigned int scale_uv;switch (m) {case IIO_CHAN_INFO_SCALE :/* Corresponds to Vref / 2^(bits) */ - scale_uv = (data->vref_mv[chan->channel] *1000 ) >>8 ; - *val = scale_uv /1000000 ; - *val2 = scale_uv %1000000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = data->vref_mv[chan->channel]; + *val2 =8 ; +return IIO_VAL_FRACTIONAL_LOG2 ;default :break ; }
Signature · 1 line
1.8.0
Re: [PATCH 12/25] iio:max517: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
This one should have had a cc for Roland so I've added it now.
Roland, shout if you have any comments on this! Whilst it is my tree I'll probably not send another pull request to Greg until the weekend.
Thanks,
Jonathan
Quoted 28 lines
--- drivers/iio/dac/max517.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/iio/dac/max517.c +3
-5@@ -82,15 +82,13 @@ static int max517_read_raw(struct iio_dev *indio_dev, long m) {struct max517_data *data =iio_priv (indio_dev); -unsigned int scale_uv;switch (m) {case IIO_CHAN_INFO_SCALE :/* Corresponds to Vref / 2^(bits) */ - scale_uv = (data->vref_mv[chan->channel] *1000 ) >>8 ; - *val = scale_uv /1000000 ; - *val2 = scale_uv %1000000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = data->vref_mv[chan->channel]; + *val2 =8 ; +return IIO_VAL_FRACTIONAL_LOG2 ;default :break ; }
PATCH 13/25 iio:mcp4725: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/dac/mcp4725.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/dac/mcp4725.c +3 -5
@@ -239,17 +239,15 @@ static int mcp4725_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct mcp4725_data *data = iio_priv(indio_dev); -unsigned long scale_uv;switch (mask) {case IIO_CHAN_INFO_RAW : *val = data->dac_value;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (data->vref_mv *1000 ) >>12 ; - *val = scale_uv /1000000 ; - *val2 = scale_uv %1000000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = data->vref_mv; + *val2 =12 ; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
Signature · 1 line
1.8.0
PATCH 14/25 iio:ad7266: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/adc/ad7266.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/iio/adc/ad7266.c +10 -11
@@ -27,7 +27,7 @@struct ad7266_state {struct spi_device *spi;struct regulator *reg; -unsigned long vref_uv; +unsigned long vref_mv;struct spi_transfer single_xfer[3 ];struct spi_message single_msg;
@@ -156,7 +156,7 @@ static int ad7266_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long m) { struct ad7266_state *st = iio_priv(indio_dev); -unsigned long scale_uv; +unsigned long scale_mv;int ret;switch (m) {
@@ -174,16 +174,15 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->vref_uv *100 ); + scale_mv = st->vref_mv;if (st->mode ==AD7266_MODE_DIFF ) - scale_uv *=2 ; + scale_mv *=2 ;if (st->range ==AD7266_RANGE_2VREF ) - scale_uv *=2 ; + scale_mv *=2 ; - scale_uv >>= chan->scan_type.realbits; - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = scale_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_OFFSET :if (st->range ==AD7266_RANGE_2VREF && st->mode !=AD7266_MODE_DIFF )
@@ -414,10 +413,10 @@ static int ad7266_probe(struct spi_device *spi)if (ret <0 ) goto error_disable_reg; - st->vref_uv = ret; + st->vref_mv = ret /1000 ; }else {/* Use internal reference */ - st->vref_uv =2500000 ; + st->vref_mv =2500 ; }if (pdata) {
Signature · 1 line
1.8.0
Re: [PATCH 14/25] iio:ad7266: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
Thanks
Quoted 63 lines
--- drivers/iio/adc/ad7266.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)drivers/iio/adc/ad7266.c +10
-11@@ -27,7 +27,7 @@struct ad7266_state {struct spi_device *spi;struct regulator *reg; -unsigned long vref_uv; +unsigned long vref_mv;struct spi_transfer single_xfer[3 ];struct spi_message single_msg;@@ -156,7 +156,7 @@ static int ad7266_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long m) { struct ad7266_state *st = iio_priv(indio_dev); -unsigned long scale_uv; +unsigned long scale_mv;int ret;switch (m) {@@ -174,16 +174,15 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->vref_uv *100 ); + scale_mv = st->vref_mv;if (st->mode ==AD7266_MODE_DIFF ) - scale_uv *=2 ; + scale_mv *=2 ;if (st->range ==AD7266_RANGE_2VREF ) - scale_uv *=2 ; + scale_mv *=2 ; - scale_uv >>= chan->scan_type.realbits; - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = scale_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_OFFSET :if (st->range ==AD7266_RANGE_2VREF && st->mode !=AD7266_MODE_DIFF )@@ -414,10 +413,10 @@ static int ad7266_probe(struct spi_device *spi)if (ret <0 ) goto error_disable_reg; - st->vref_uv = ret; + st->vref_mv = ret /1000 ; }else {/* Use internal reference */ - st->vref_uv =2500000 ; + st->vref_mv =2500 ; }if (pdata) {
PATCH 15/25 iio:ad7476: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/adc/ad7476.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/adc/ad7476.c +3 -4
@@ -127,10 +127,9 @@ static int ad7476_read_raw(struct iio_dev *indio_dev, }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 ; + *val = scale_uv /1000 ; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
Signature · 1 line
1.8.0
Re: [PATCH 15/25] iio:ad7476: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
Thanks,
Quoted 23 lines
--- drivers/iio/adc/ad7476.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/iio/adc/ad7476.c +3
-4@@ -127,10 +127,9 @@ static int ad7476_read_raw(struct iio_dev *indio_dev, }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 ; + *val = scale_uv /1000 ; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
PATCH 16/25 iio:ad7791: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/adc/ad7791.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/iio/adc/ad7791.c +10 -8
@@ -202,7 +202,6 @@ static int ad7791_read_raw(struct iio_dev *indio_dev, {struct ad7791_state *st =iio_priv (indio_dev);bool unipolar = !!(st->mode &AD7791_MODE_UNIPOLAR ); -unsigned long long scale_pv;switch (info) {case IIO_CHAN_INFO_RAW :
@@ -220,23 +219,26 @@ static int ad7791_read_raw(struct iio_dev *indio_dev,case IIO_CHAN_INFO_SCALE :/* The monitor channel uses an internal reference. */ if (chan->address ==AD7791_CH_AVDD_MONITOR ) { - scale_pv =5850000000000ULL ; +/* +* The signal is attenuated by a factor of 5 and +* compared against a 1.17V internal reference. +*/ + *val =1170 *5 ; }else {int voltage_uv; voltage_uv =regulator_get_voltage (st->reg);if (voltage_uv <0 )return voltage_uv; - scale_pv = (unsigned long long )voltage_uv *1000000 ; + + *val = voltage_uv /1000 ; }if (unipolar) - scale_pv >>= chan->scan_type.realbits; + *val2 = chan->scan_type.realbits;else - scale_pv >>= chan->scan_type.realbits -1 ; - *val2 =do_div (scale_pv,1000000000 ); - *val = scale_pv; + *val2 = chan->scan_type.realbits -1 ; -return IIO_VAL_INT_PLUS_NANO ; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ;
Signature · 1 line
1.8.0
Re: [PATCH 16/25] iio:ad7791: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Nice cleanup in this one.
Applied to the togreg branch of iio.git
Thanks,
Quoted 51 lines
--- drivers/iio/adc/ad7791.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)drivers/iio/adc/ad7791.c +10
-8@@ -202,7 +202,6 @@ static int ad7791_read_raw(struct iio_dev *indio_dev, {struct ad7791_state *st =iio_priv (indio_dev);bool unipolar = !!(st->mode &AD7791_MODE_UNIPOLAR ); -unsigned long long scale_pv;switch (info) {case IIO_CHAN_INFO_RAW :@@ -220,23 +219,26 @@ static int ad7791_read_raw(struct iio_dev *indio_dev,case IIO_CHAN_INFO_SCALE :/* The monitor channel uses an internal reference. */ if (chan->address ==AD7791_CH_AVDD_MONITOR ) { - scale_pv =5850000000000ULL ; +/* +* The signal is attenuated by a factor of 5 and +* compared against a 1.17V internal reference. +*/ + *val =1170 *5 ; }else {int voltage_uv; voltage_uv =regulator_get_voltage (st->reg);if (voltage_uv <0 )return voltage_uv; - scale_pv = (unsigned long long )voltage_uv *1000000 ; + + *val = voltage_uv /1000 ; }if (unipolar) - scale_pv >>= chan->scan_type.realbits; + *val2 = chan->scan_type.realbits;else - scale_pv >>= chan->scan_type.realbits -1 ; - *val2 =do_div (scale_pv,1000000000 ); - *val = scale_pv; + *val2 = chan->scan_type.realbits -1 ; -return IIO_VAL_INT_PLUS_NANO ; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ;
PATCH 17/25 iio:at91: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/adc/at91_adc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/at91_adc.c +3 -3
@@ -366,9 +366,9 @@ static int at91_adc_read_raw(struct iio_dev *idev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - *val = (st->vref_mv *1000 ) >> chan->scan_type.realbits; - *val2 =0 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;default :break ; }
Signature · 1 line
1.8.0
Re: [PATCH 17/25] iio:at91: Report scale as fractional value
Quoted 4 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>Cc Josh Wu <[email protected]>
Applied to the togreg branch of iio.git
Thanks,
Quoted 22 lines
--- drivers/iio/adc/at91_adc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/iio/adc/at91_adc.c +3
-3@@ -366,9 +366,9 @@ static int at91_adc_read_raw(struct iio_dev *idev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - *val = (st->vref_mv *1000 ) >> chan->scan_type.realbits; - *val2 =0 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;default :break ; }
PATCH 18/25 iio:max1363: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/iio/adc/max1363.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/adc/max1363.c +3 -5
@@ -397,7 +397,6 @@ static int max1363_read_raw(struct iio_dev *indio_dev, {struct max1363_state *st =iio_priv (indio_dev);int ret; -unsigned long scale_uv;switch (m) {case IIO_CHAN_INFO_RAW :
@@ -406,10 +405,9 @@ static int max1363_read_raw(struct iio_dev *indio_dev,return ret;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = st->vref_uv >> st->chip_info->bits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->vref_uv /1000 ; + *val2 = st->chip_info->bits; +return IIO_VAL_FRACTIONAL_LOG2 ;default :return -EINVAL ; }
Signature · 1 line
1.8.0
Re: [PATCH 18/25] iio:max1363: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
Thanks,
Quoted 31 lines
--- drivers/iio/adc/max1363.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/iio/adc/max1363.c +3
-5@@ -397,7 +397,6 @@ static int max1363_read_raw(struct iio_dev *indio_dev, {struct max1363_state *st =iio_priv (indio_dev);int ret; -unsigned long scale_uv;switch (m) {case IIO_CHAN_INFO_RAW :@@ -406,10 +405,9 @@ static int max1363_read_raw(struct iio_dev *indio_dev,return ret;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = st->vref_uv >> st->chip_info->bits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->vref_uv /1000 ; + *val2 = st->chip_info->bits; +return IIO_VAL_FRACTIONAL_LOG2 ;default :return -EINVAL ; }
PATCH 19/25 staging:iio:ad7280a: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/staging/iio/adc/ad7280a.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/iio/adc/ad7280a.c +4 -6
@@ -783,7 +783,6 @@ static int ad7280_read_raw(struct iio_dev *indio_dev, long m) {struct ad7280_state *st =iio_priv (indio_dev); -unsigned int scale_uv;int ret;switch (m) {
@@ -804,13 +803,12 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE :if ((chan->address &0xFF ) <=AD7280A_CELL_VOLTAGE_6 ) - scale_uv = (4000 *1000 ) >>AD7280A_BITS ; + *val =4000 ;else - scale_uv = (5000 *1000 ) >>AD7280A_BITS ; + *val =5000 ; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val2 =AD7280A_BITS ; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
Signature · 1 line
1.8.0
Re: [PATCH 19/25] staging:iio:ad7280a: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied
Quoted 35 lines
--- drivers/staging/iio/adc/ad7280a.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/staging/iio/adc/ad7280a.c +4
-6@@ -783,7 +783,6 @@ static int ad7280_read_raw(struct iio_dev *indio_dev, long m) {struct ad7280_state *st =iio_priv (indio_dev); -unsigned int scale_uv;int ret;switch (m) {@@ -804,13 +803,12 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE :if ((chan->address &0xFF ) <=AD7280A_CELL_VOLTAGE_6 ) - scale_uv = (4000 *1000 ) >>AD7280A_BITS ; + *val =4000 ;else - scale_uv = (5000 *1000 ) >>AD7280A_BITS ; + *val =5000 ; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val2 =AD7280A_BITS ; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
PATCH 20/25 staging:iio:ad7606: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/staging/iio/adc/ad7606_core.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/staging/iio/adc/ad7606_core.c +3 -6
@@ -85,7 +85,6 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, {int ret;struct ad7606_state *st =iio_priv (indio_dev); -unsigned int scale_uv;switch (m) {case IIO_CHAN_INFO_RAW :
@@ -101,11 +100,9 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, *val = (short ) ret;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->range *1000 *2 ) - >> st->chip_info->channels[0 ].scan_type.realbits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->range *2 ; + *val2 = st->chip_info->channels[0 ].scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
Signature · 1 line
1.8.0
Re: [PATCH 20/25] staging:iio:ad7606: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied.
Quoted 32 lines
--- drivers/staging/iio/adc/ad7606_core.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/staging/iio/adc/ad7606_core.c +3
-6@@ -85,7 +85,6 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, {int ret;struct ad7606_state *st =iio_priv (indio_dev); -unsigned int scale_uv;switch (m) {case IIO_CHAN_INFO_RAW :@@ -101,11 +100,9 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, *val = (short ) ret;return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->range *1000 *2 ) - >> st->chip_info->channels[0 ].scan_type.realbits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->range *2 ; + *val2 = st->chip_info->channels[0 ].scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
PATCH 21/25 staging:iio:ad7780: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/staging/iio/adc/ad7780.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/staging/iio/adc/ad7780.c +3 -6
@@ -90,17 +90,14 @@ static int ad7780_read_raw(struct iio_dev *indio_dev, long m) {struct ad7780_state *st =iio_priv (indio_dev); -unsigned long scale_uv;switch (m) {case IIO_CHAN_INFO_RAW :return ad_sigma_delta_single_conversion (indio_dev, chan, val);case IIO_CHAN_INFO_SCALE : - scale_uv = (st->int_vref_mv *100000 * st->gain) - >> (chan->scan_type.realbits -1 ); - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->int_vref_mv * st->gain; + *val2 = chan->scan_type.realbits -1 ; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_OFFSET : *val -= (1 << (chan->scan_type.realbits -1 ));return IIO_VAL_INT ;
Signature · 1 line
1.8.0
Re: [PATCH 21/25] staging:iio:ad7780: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
applied
Quoted 30 lines
--- drivers/staging/iio/adc/ad7780.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/staging/iio/adc/ad7780.c +3
-6@@ -90,17 +90,14 @@ static int ad7780_read_raw(struct iio_dev *indio_dev, long m) {struct ad7780_state *st =iio_priv (indio_dev); -unsigned long scale_uv;switch (m) {case IIO_CHAN_INFO_RAW :return ad_sigma_delta_single_conversion (indio_dev, chan, val);case IIO_CHAN_INFO_SCALE : - scale_uv = (st->int_vref_mv *100000 * st->gain) - >> (chan->scan_type.realbits -1 ); - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->int_vref_mv * st->gain; + *val2 = chan->scan_type.realbits -1 ; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_OFFSET : *val -= (1 << (chan->scan_type.realbits -1 ));return IIO_VAL_INT ;
PATCH 22/25 staging:iio:ad799x: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/staging/iio/adc/ad799x_core.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/iio/adc/ad799x_core.c +3 -5
@@ -163,7 +163,6 @@ static int ad799x_read_raw(struct iio_dev *indio_dev, {int ret;struct ad799x_state *st =iio_priv (indio_dev); -unsigned int scale_uv;switch (m) {case IIO_CHAN_INFO_RAW :
@@ -180,10 +179,9 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,RES_MASK (chan->scan_type.realbits);return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->int_vref_mv *1000 ) >> chan->scan_type.realbits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->int_vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
Signature · 1 line
1.8.0
Re: [PATCH 22/25] staging:iio:ad799x: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied
Quoted 31 lines
--- drivers/staging/iio/adc/ad799x_core.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/staging/iio/adc/ad799x_core.c +3
-5@@ -163,7 +163,6 @@ static int ad799x_read_raw(struct iio_dev *indio_dev, {int ret;struct ad799x_state *st =iio_priv (indio_dev); -unsigned int scale_uv;switch (m) {case IIO_CHAN_INFO_RAW :@@ -180,10 +179,9 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,RES_MASK (chan->scan_type.realbits);return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_uv = (st->int_vref_mv *1000 ) >> chan->scan_type.realbits; - *val = scale_uv /1000 ; - *val2 = (scale_uv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = st->int_vref_mv; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ; }
PATCH 23/25 staging:iio:ad7746: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/staging/iio/cdc/ad7746.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/staging/iio/cdc/ad7746.c +7 -6
@@ -656,20 +656,21 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,switch (chan->type) {case IIO_CAPACITANCE :/* 8.192pf / 2^24 */ - *val2 =488 ; *val =0 ; + *val2 =488 ; + ret =IIO_VAL_INT_PLUS_NANO ;break ;case IIO_VOLTAGE :/* 1170mV / 2^23 */ - *val2 =139475 ; - *val =0 ; + *val =1170 ; + *val2 =23 ; + ret =IIO_VAL_FRACTIONAL_LOG2 ;break ;default : - ret = -EINVAL ; - goto out; + ret = -EINVAL ; +break ; } - ret =IIO_VAL_INT_PLUS_NANO ;break ;default : ret = -EINVAL ;
Signature · 1 line
1.8.0
Re: [PATCH 23/25] staging:iio:ad7746: Report scale as fractional value
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Should probably mention the tidying up in the commit message, but it is trivial so I won't bother changing it ;)
Applied to the togreg branch of iio.git
Thanks
Quoted 37 lines
--- drivers/staging/iio/cdc/ad7746.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/staging/iio/cdc/ad7746.c +7
-6@@ -656,20 +656,21 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,switch (chan->type) {case IIO_CAPACITANCE :/* 8.192pf / 2^24 */ - *val2 =488 ; *val =0 ; + *val2 =488 ; + ret =IIO_VAL_INT_PLUS_NANO ;break ;case IIO_VOLTAGE :/* 1170mV / 2^23 */ - *val2 =139475 ; - *val =0 ; + *val =1170 ; + *val2 =23 ; + ret =IIO_VAL_FRACTIONAL_LOG2 ;break ;default : - ret = -EINVAL ; - goto out; + ret = -EINVAL ; +break ; } - ret =IIO_VAL_INT_PLUS_NANO ;break ;default : ret = -EINVAL ;
PATCH 24/25 staging:iio:spear_adc: Report scale as fractional value
In reply to Lars-Peter ClausenMove the complexity of calculating the fixed point scale to the core.
--- drivers/staging/iio/adc/spear_adc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/iio/adc/spear_adc.c +3 -4
@@ -168,10 +168,9 @@ static int spear_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_mv = (info->vref_external *1000 ) >>DATA_BITS ; - *val = scale_mv /1000 ; - *val2 = (scale_mv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = info->vref_external; + *val2 =DATA_BITS ; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ;
Signature · 1 line
1.8.0
Re: [PATCH 24/25] staging:iio:spear_adc: Report scale as fractional value
Quoted 4 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>Cc Stefan Roese <[email protected]>
Applied to the togreg branch of iio.git
Thanks
Quoted 23 lines
--- drivers/staging/iio/adc/spear_adc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/staging/iio/adc/spear_adc.c +3
-4@@ -168,10 +168,9 @@ static int spear_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : - scale_mv = (info->vref_external *1000 ) >>DATA_BITS ; - *val = scale_mv /1000 ; - *val2 = (scale_mv %1000 ) *1000 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = info->vref_external; + *val2 =DATA_BITS ; +return IIO_VAL_FRACTIONAL_LOG2 ; }return -EINVAL ;
PATCH 25/25 iio: Update unit of the voltage scale in the documentation
In reply to Lars-Peter ClausenThe documentation says that the result of raw * scale should be in microvolts, but in reallity all drivers actually report the scale so that the result is in millivolts. So update the documentation to match reallity.
--- Documentation/ABI/testing/sysfs-bus-iio | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-bus-iio +2 -2
@@ -79,7 +79,7 @@ Description: correspond to externally available input one of the named versions may be used. The number must always be specified and unique to allow association with event codes. Units after - application of scale and offset are microvolts. + application of scale and offset are millivolts. What: /sys/bus/iio/devices/iio:deviceX/in_voltageY-voltageZ_raw KernelVersion: 2.6.35
@@ -90,7 +90,7 @@ Description: physically equivalent inputs when non differential readings are separately available. In differential only parts, then all that is required is a consistent labeling. Units after application - of scale and offset are microvolts. + of scale and offset are millivolts. What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceY_raw KernelVersion: 3.2
Signature · 1 line
1.8.0
Jonathan Cameron
maintainerRe: [PATCH 25/25] iio: Update unit of the voltage scale in the documentation
Quoted 5 lines · Lars-Peter Clausen
The documentation says that the result of raw * scale should be in microvolts, but in reallity all drivers actually report the scale so that the result is in millivolts. So update the documentation to match reallity.
Signed-off-by Lars-Peter Clausen <[email protected]>
I've no idea how we ended up with this being wrong, but it does indeed need fixing!
Anyhow, applied to the togreg branch of iio.git
Thanks for a nice focussed, easy to review series,
Jonathan
Quoted 27 lines
--- Documentation/ABI/testing/sysfs-bus-iio | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Documentation/ABI/testing/sysfs-bus-iio +2
-2@@ -79,7 +79,7 @@ Description: correspond to externally available input one of the named versions may be used. The number must always be specified and unique to allow association with event codes. Units after - application of scale and offset are microvolts. + application of scale and offset are millivolts. What: /sys/bus/iio/devices/iio:deviceX/in_voltageY-voltageZ_raw KernelVersion: 2.6.35@@ -90,7 +90,7 @@ Description: physically equivalent inputs when non differential readings are separately available. In differential only parts, then all that is required is a consistent labeling. Units after application - of scale and offset are microvolts. + of scale and offset are millivolts. What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceY_raw KernelVersion: 3.2
Quoted 3 lines · Lars-Peter Clausen
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git
Thanks
Quoted 23 lines
--- drivers/iio/dac/ad5064.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/iio/dac/ad5064.c +3
-4@@ -239,10 +239,9 @@ static int ad5064_read_raw(struct iio_dev *indio_dev,if (scale_uv <0 )return scale_uv; - scale_uv = (scale_uv *100 ) >> chan->scan_type.realbits; - *val = scale_uv /100000 ; - *val2 = (scale_uv %100000 ) *10 ; -return IIO_VAL_INT_PLUS_MICRO ; + *val = scale_uv /1000 ; + *val2 = chan->scan_type.realbits; +return IIO_VAL_FRACTIONAL_LOG2 ;default :break ; }