Re: [PATCH v5 1/3] hwmon: ina2xx: make shunt resistance configurable at run-time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Dec 11, 2014 at 11:26:07AM +0100, Bartosz Golaszewski wrote:
> 2014-12-10 19:31 GMT+01:00 Guenter Roeck <linux@xxxxxxxxxxxx>:
> > I don't really want it at all ;-). Seems to me all those options are broken
> > one way or another. The only real solution would be to re-instantiate the
> > driver if the chip was removed and re-inserted, and to provide parameters
> > either with platform data or with devicetree data.
> 
> I see your point, but as Benoit mentioned in one of the previous
> messages, in case of our platform it would be impossible to have an
> exhaustive list of possible shunt values.
> 
> > On a side note, data->rshunt is not really needed anymore with your current
> > code. The only reason for storing it in data is to use it in
> > ina2xx_calibration_val(), but you could as well pass it in as parameter
> > to that function. Even better would be to have a function such as
> > ina2xx_calibrate() and let it handle the write to the calibration register.
> > Also, I would suggest to move the above code into its own show function.
> > It is probably not a good idea to have a single function for all those
> > conversions in the first place, and converting from 'calibration' to
> > rshunt goes a bit beyond the original intent to convert from one representation
> > to the other.
> 
> I agree about having separate functions for this parameter and about
> not needing data->rshunt in my current code, but we still aren't clear
> about whether to read the value from the register or to store it in
> memory.
> 
Let's take the value from the register.

> > That still doesn't really solve the structural problem of having to deal with
> > an uninitialized chip which doesn't like to be uninitialized. But then on the
> > other side I guess that is really a problem with your platform, not a driver
> > problem.
> 
> This might be a stupid idea, but what about reading the calibration
> register first in ina2xx_update_device() and, in case it's value is 0
> (POR value according to the datasheet), reinitializing the chip?
> 
Not that stupid. Without programming the calibration register, the chip
will not report power and current. Expecting user space to "fix" the
situation if that happens seems to be at least as stupid as doing it in
the kernel (and, for example, the 'sensors' command won't be able to fix
it, nor any other program not running as root).

So it might make sense to move the chip initialization into an _init function,
call it from _probe, and call it from _update if, as you say, the calibration
register returns 0. The init function should initialize both the configuration
register and the calibration register. Make sure you update
data->reg[INA2XX_CALIBRATION] when you do that. In the latter case (update
function detects that chip is not initialized), you might also want to add
a dev_warn() as this is an unexpected situation.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
lm-sensors@xxxxxxxxxxxxxx
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors




[Index of Archives]     [Linux Kernel]     [Linux Hardware Monitoring]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux