* [PATCH-vs-togreg v2 1/2] iio: ina2xx-adc: update the CALIB. register when RShunt changes
@ 2016-03-14 10:20 Marc Titinger
2016-03-20 11:24 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Marc Titinger @ 2016-03-14 10:20 UTC (permalink / raw)
To: jic23, knaack.h, lars, pmeerw; +Cc: afd, linux-iio, linux-kernel
The user (or an init script) may setup RShunt via sysfs after the
driver was initialized, for instance based on the EEPROM contents
of a modular probe. The calibration register must be set accordingly.
Signed-off-by: Marc Titinger <marc.titinger@baylibre.com>
---
v2 of http://www.spinics.net/lists/linux-iio/msg23402.html:
- remove unnecessary line insertions
- cleanup leftover unused variable (build warning)
- patch 2/2 is unchanged (see v1)
---
drivers/iio/adc/ina2xx-adc.c | 39 ++++++++++++++++++++++++---------------
1 file changed, 24 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
index 65909d5..4e56fe3 100644
--- a/drivers/iio/adc/ina2xx-adc.c
+++ b/drivers/iio/adc/ina2xx-adc.c
@@ -350,6 +350,23 @@ static ssize_t ina2xx_allow_async_readout_store(struct device *dev,
return len;
}
+/*
+ * Set current LSB to 1mA, shunt is in uOhms
+ * (equation 13 in datasheet). We hardcode a Current_LSB
+ * of 1.0 x10-6. The only remaining parameter is RShunt.
+ * There is no need to expose the CALIBRATION register
+ * to the user for now. But we need to reset this register
+ * if the user updates RShunt after driver init, e.g upon
+ * reading an EEPROM/Probe-type value.
+ */
+static int ina2xx_set_calibration(struct ina2xx_chip_info *chip)
+{
+ u16 regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor,
+ chip->shunt_resistor);
+
+ return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval);
+}
+
static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val)
{
if (val <= 0 || val > chip->config->calibration_factor)
@@ -385,6 +402,11 @@ static ssize_t ina2xx_shunt_resistor_store(struct device *dev,
if (ret)
return ret;
+ /* Update the Calibration register */
+ ret = ina2xx_set_calibration(chip);
+ if (ret)
+ return ret;
+
return len;
}
@@ -602,24 +624,11 @@ static const struct iio_info ina2xx_info = {
/* Initialize the configuration and calibration registers. */
static int ina2xx_init(struct ina2xx_chip_info *chip, unsigned int config)
{
- u16 regval;
- int ret;
-
- ret = regmap_write(chip->regmap, INA2XX_CONFIG, config);
+ int ret = regmap_write(chip->regmap, INA2XX_CONFIG, config);
if (ret)
return ret;
- /*
- * Set current LSB to 1mA, shunt is in uOhms
- * (equation 13 in datasheet). We hardcode a Current_LSB
- * of 1.0 x10-6. The only remaining parameter is RShunt.
- * There is no need to expose the CALIBRATION register
- * to the user for now.
- */
- regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor,
- chip->shunt_resistor);
-
- return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval);
+ return ina2xx_set_calibration(chip);
}
static int ina2xx_probe(struct i2c_client *client,
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH-vs-togreg v2 1/2] iio: ina2xx-adc: update the CALIB. register when RShunt changes
2016-03-14 10:20 [PATCH-vs-togreg v2 1/2] iio: ina2xx-adc: update the CALIB. register when RShunt changes Marc Titinger
@ 2016-03-20 11:24 ` Jonathan Cameron
2016-03-21 16:35 ` Marc Titinger
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2016-03-20 11:24 UTC (permalink / raw)
To: Marc Titinger, knaack.h, lars, pmeerw; +Cc: afd, linux-iio, linux-kernel
On 14/03/16 10:20, Marc Titinger wrote:
> The user (or an init script) may setup RShunt via sysfs after the
> driver was initialized, for instance based on the EEPROM contents
> of a modular probe. The calibration register must be set accordingly.
>
> Signed-off-by: Marc Titinger <marc.titinger@baylibre.com>
> ---
> v2 of http://www.spinics.net/lists/linux-iio/msg23402.html:
>
> - remove unnecessary line insertions
> - cleanup leftover unused variable (build warning)
> - patch 2/2 is unchanged (see v1)
Err, can't find it for some reason.
Anyhow, applied this one to the togreg branch of iio.git - pushed
out as testing for the autobuilders to play with it.
Thanks,
Jonathan
> ---
> drivers/iio/adc/ina2xx-adc.c | 39 ++++++++++++++++++++++++---------------
> 1 file changed, 24 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
> index 65909d5..4e56fe3 100644
> --- a/drivers/iio/adc/ina2xx-adc.c
> +++ b/drivers/iio/adc/ina2xx-adc.c
> @@ -350,6 +350,23 @@ static ssize_t ina2xx_allow_async_readout_store(struct device *dev,
> return len;
> }
>
> +/*
> + * Set current LSB to 1mA, shunt is in uOhms
> + * (equation 13 in datasheet). We hardcode a Current_LSB
> + * of 1.0 x10-6. The only remaining parameter is RShunt.
> + * There is no need to expose the CALIBRATION register
> + * to the user for now. But we need to reset this register
> + * if the user updates RShunt after driver init, e.g upon
> + * reading an EEPROM/Probe-type value.
> + */
> +static int ina2xx_set_calibration(struct ina2xx_chip_info *chip)
> +{
> + u16 regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor,
> + chip->shunt_resistor);
> +
> + return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval);
> +}
> +
> static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val)
> {
> if (val <= 0 || val > chip->config->calibration_factor)
> @@ -385,6 +402,11 @@ static ssize_t ina2xx_shunt_resistor_store(struct device *dev,
> if (ret)
> return ret;
>
> + /* Update the Calibration register */
> + ret = ina2xx_set_calibration(chip);
> + if (ret)
> + return ret;
> +
> return len;
> }
>
> @@ -602,24 +624,11 @@ static const struct iio_info ina2xx_info = {
> /* Initialize the configuration and calibration registers. */
> static int ina2xx_init(struct ina2xx_chip_info *chip, unsigned int config)
> {
> - u16 regval;
> - int ret;
> -
> - ret = regmap_write(chip->regmap, INA2XX_CONFIG, config);
> + int ret = regmap_write(chip->regmap, INA2XX_CONFIG, config);
> if (ret)
> return ret;
>
> - /*
> - * Set current LSB to 1mA, shunt is in uOhms
> - * (equation 13 in datasheet). We hardcode a Current_LSB
> - * of 1.0 x10-6. The only remaining parameter is RShunt.
> - * There is no need to expose the CALIBRATION register
> - * to the user for now.
> - */
> - regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor,
> - chip->shunt_resistor);
> -
> - return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval);
> + return ina2xx_set_calibration(chip);
> }
>
> static int ina2xx_probe(struct i2c_client *client,
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH-vs-togreg v2 1/2] iio: ina2xx-adc: update the CALIB. register when RShunt changes
2016-03-20 11:24 ` Jonathan Cameron
@ 2016-03-21 16:35 ` Marc Titinger
2016-03-28 15:09 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Marc Titinger @ 2016-03-21 16:35 UTC (permalink / raw)
To: Jonathan Cameron, knaack.h, lars, pmeerw; +Cc: afd, linux-iio, linux-kernel
On 20/03/2016 12:24, Jonathan Cameron wrote:
> On 14/03/16 10:20, Marc Titinger wrote:
>> The user (or an init script) may setup RShunt via sysfs after the
>> driver was initialized, for instance based on the EEPROM contents
>> of a modular probe. The calibration register must be set accordingly.
>>
>> Signed-off-by: Marc Titinger <marc.titinger@baylibre.com>
>> ---
>> v2 of http://www.spinics.net/lists/linux-iio/msg23402.html:
>>
>> - remove unnecessary line insertions
>> - cleanup leftover unused variable (build warning)
>> - patch 2/2 is unchanged (see v1)
> Err, can't find it for some reason.
sorry, it's here http://www.spinics.net/lists/linux-iio/msg23401.html
or here: pwclient get 8565821
BR,
Marc.
>
> Anyhow, applied this one to the togreg branch of iio.git - pushed
> out as testing for the autobuilders to play with it.
>
> Thanks,
>
> Jonathan
>> ---
>> drivers/iio/adc/ina2xx-adc.c | 39 ++++++++++++++++++++++++---------------
>> 1 file changed, 24 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
>> index 65909d5..4e56fe3 100644
>> --- a/drivers/iio/adc/ina2xx-adc.c
>> +++ b/drivers/iio/adc/ina2xx-adc.c
>> @@ -350,6 +350,23 @@ static ssize_t ina2xx_allow_async_readout_store(struct device *dev,
>> return len;
>> }
>>
>> +/*
>> + * Set current LSB to 1mA, shunt is in uOhms
>> + * (equation 13 in datasheet). We hardcode a Current_LSB
>> + * of 1.0 x10-6. The only remaining parameter is RShunt.
>> + * There is no need to expose the CALIBRATION register
>> + * to the user for now. But we need to reset this register
>> + * if the user updates RShunt after driver init, e.g upon
>> + * reading an EEPROM/Probe-type value.
>> + */
>> +static int ina2xx_set_calibration(struct ina2xx_chip_info *chip)
>> +{
>> + u16 regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor,
>> + chip->shunt_resistor);
>> +
>> + return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval);
>> +}
>> +
>> static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val)
>> {
>> if (val <= 0 || val > chip->config->calibration_factor)
>> @@ -385,6 +402,11 @@ static ssize_t ina2xx_shunt_resistor_store(struct device *dev,
>> if (ret)
>> return ret;
>>
>> + /* Update the Calibration register */
>> + ret = ina2xx_set_calibration(chip);
>> + if (ret)
>> + return ret;
>> +
>> return len;
>> }
>>
>> @@ -602,24 +624,11 @@ static const struct iio_info ina2xx_info = {
>> /* Initialize the configuration and calibration registers. */
>> static int ina2xx_init(struct ina2xx_chip_info *chip, unsigned int config)
>> {
>> - u16 regval;
>> - int ret;
>> -
>> - ret = regmap_write(chip->regmap, INA2XX_CONFIG, config);
>> + int ret = regmap_write(chip->regmap, INA2XX_CONFIG, config);
>> if (ret)
>> return ret;
>>
>> - /*
>> - * Set current LSB to 1mA, shunt is in uOhms
>> - * (equation 13 in datasheet). We hardcode a Current_LSB
>> - * of 1.0 x10-6. The only remaining parameter is RShunt.
>> - * There is no need to expose the CALIBRATION register
>> - * to the user for now.
>> - */
>> - regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor,
>> - chip->shunt_resistor);
>> -
>> - return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval);
>> + return ina2xx_set_calibration(chip);
>> }
>>
>> static int ina2xx_probe(struct i2c_client *client,
>>
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH-vs-togreg v2 1/2] iio: ina2xx-adc: update the CALIB. register when RShunt changes
2016-03-21 16:35 ` Marc Titinger
@ 2016-03-28 15:09 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2016-03-28 15:09 UTC (permalink / raw)
To: Marc Titinger, knaack.h, lars, pmeerw; +Cc: afd, linux-iio, linux-kernel
On 21/03/16 16:35, Marc Titinger wrote:
>
>
> On 20/03/2016 12:24, Jonathan Cameron wrote:
>> On 14/03/16 10:20, Marc Titinger wrote:
>>> The user (or an init script) may setup RShunt via sysfs after the
>>> driver was initialized, for instance based on the EEPROM contents
>>> of a modular probe. The calibration register must be set accordingly.
>>>
>>> Signed-off-by: Marc Titinger <marc.titinger@baylibre.com>
>>> ---
>>> v2 of http://www.spinics.net/lists/linux-iio/msg23402.html:
>>>
>>> - remove unnecessary line insertions
>>> - cleanup leftover unused variable (build warning)
>>> - patch 2/2 is unchanged (see v1)
>> Err, can't find it for some reason.
>
> sorry, it's here http://www.spinics.net/lists/linux-iio/msg23401.html
> or here: pwclient get 8565821
Meh, thunderbird was hiding it in completely the wrong thread.
Really should see about changing my email client one of these days.
Anyhow, applied that one now to the togreg branch of iio.git - pushed out
as testing.
thanks,
Jonathan
>
> BR,
> Marc.
>
>>
>> Anyhow, applied this one to the togreg branch of iio.git - pushed
>> out as testing for the autobuilders to play with it.
>>
>> Thanks,
>>
>> Jonathan
>>> ---
>>> drivers/iio/adc/ina2xx-adc.c | 39 ++++++++++++++++++++++++---------------
>>> 1 file changed, 24 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
>>> index 65909d5..4e56fe3 100644
>>> --- a/drivers/iio/adc/ina2xx-adc.c
>>> +++ b/drivers/iio/adc/ina2xx-adc.c
>>> @@ -350,6 +350,23 @@ static ssize_t ina2xx_allow_async_readout_store(struct device *dev,
>>> return len;
>>> }
>>>
>>> +/*
>>> + * Set current LSB to 1mA, shunt is in uOhms
>>> + * (equation 13 in datasheet). We hardcode a Current_LSB
>>> + * of 1.0 x10-6. The only remaining parameter is RShunt.
>>> + * There is no need to expose the CALIBRATION register
>>> + * to the user for now. But we need to reset this register
>>> + * if the user updates RShunt after driver init, e.g upon
>>> + * reading an EEPROM/Probe-type value.
>>> + */
>>> +static int ina2xx_set_calibration(struct ina2xx_chip_info *chip)
>>> +{
>>> + u16 regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor,
>>> + chip->shunt_resistor);
>>> +
>>> + return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval);
>>> +}
>>> +
>>> static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val)
>>> {
>>> if (val <= 0 || val > chip->config->calibration_factor)
>>> @@ -385,6 +402,11 @@ static ssize_t ina2xx_shunt_resistor_store(struct device *dev,
>>> if (ret)
>>> return ret;
>>>
>>> + /* Update the Calibration register */
>>> + ret = ina2xx_set_calibration(chip);
>>> + if (ret)
>>> + return ret;
>>> +
>>> return len;
>>> }
>>>
>>> @@ -602,24 +624,11 @@ static const struct iio_info ina2xx_info = {
>>> /* Initialize the configuration and calibration registers. */
>>> static int ina2xx_init(struct ina2xx_chip_info *chip, unsigned int config)
>>> {
>>> - u16 regval;
>>> - int ret;
>>> -
>>> - ret = regmap_write(chip->regmap, INA2XX_CONFIG, config);
>>> + int ret = regmap_write(chip->regmap, INA2XX_CONFIG, config);
>>> if (ret)
>>> return ret;
>>>
>>> - /*
>>> - * Set current LSB to 1mA, shunt is in uOhms
>>> - * (equation 13 in datasheet). We hardcode a Current_LSB
>>> - * of 1.0 x10-6. The only remaining parameter is RShunt.
>>> - * There is no need to expose the CALIBRATION register
>>> - * to the user for now.
>>> - */
>>> - regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor,
>>> - chip->shunt_resistor);
>>> -
>>> - return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval);
>>> + return ina2xx_set_calibration(chip);
>>> }
>>>
>>> static int ina2xx_probe(struct i2c_client *client,
>>>
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-03-28 15:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-14 10:20 [PATCH-vs-togreg v2 1/2] iio: ina2xx-adc: update the CALIB. register when RShunt changes Marc Titinger
2016-03-20 11:24 ` Jonathan Cameron
2016-03-21 16:35 ` Marc Titinger
2016-03-28 15:09 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).