From: Guenter Roeck <linux@roeck-us.net>
To: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Benoit Cousson <bcousson@baylibre.com>,
Patrick Titiano <ptitiano@baylibre.com>,
LM Sensors <lm-sensors@lm-sensors.org>
Subject: Re: [PATCH v5 1/3] hwmon: ina2xx: make shunt resistance configurable at run-time
Date: Thu, 11 Dec 2014 08:29:33 -0800 [thread overview]
Message-ID: <20141211162933.GA4769@roeck-us.net> (raw)
In-Reply-To: <CAMpxmJXVPbp+XJQ9oVpAB3ejRx7Czb0KTC0HtfL9zed4Z_rOQA@mail.gmail.com>
On Thu, Dec 11, 2014 at 11:26:07AM +0100, Bartosz Golaszewski wrote:
> 2014-12-10 19:31 GMT+01:00 Guenter Roeck <linux@roeck-us.net>:
> > 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
next prev parent reply other threads:[~2014-12-11 16:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-10 10:38 [PATCH v5 0/3] hwmon: ina2xx: new attributes Bartosz Golaszewski
2014-12-10 10:38 ` [PATCH v5 1/3] hwmon: ina2xx: make shunt resistance configurable at run-time Bartosz Golaszewski
2014-12-10 14:20 ` Guenter Roeck
2014-12-10 16:46 ` Bartosz Golaszewski
2014-12-10 18:31 ` Guenter Roeck
2014-12-11 10:26 ` Bartosz Golaszewski
2014-12-11 16:29 ` Guenter Roeck [this message]
2014-12-10 10:38 ` [PATCH v5 2/3] hwmon: ina2xx: allow to change the averaging rate " Bartosz Golaszewski
2014-12-10 10:38 ` [PATCH v5 3/3] hwmon: ina2xx: documentation update for new sysfs attributes Bartosz Golaszewski
2014-12-10 14:21 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141211162933.GA4769@roeck-us.net \
--to=linux@roeck-us.net \
--cc=bcousson@baylibre.com \
--cc=bgolaszewski@baylibre.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.org \
--cc=ptitiano@baylibre.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox