mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicolin Chen <nicoleotsuka@gmail.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: jdelvare@suse.com, linux-hwmon@vger.kernel.org,
	linux-kernel@vger.kernel.org, corbet@lwn.net,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH] hwmon: (ina3221) Add voltage conversion time settings
Date: Wed, 17 Apr 2019 11:39:50 -0700	[thread overview]
Message-ID: <20190417183949.GB5073@Asurada-Nvidia.nvidia.com> (raw)
In-Reply-To: <2a193494-a33e-dac0-456a-241d7b3e59ad@roeck-us.net>

On Wed, Apr 17, 2019 at 07:04:09AM -0700, Guenter Roeck wrote:
> > > I am not quite sure if this update_interval is the best way to
> > > implement the conversion time settings but I can't find another
> > > common approach. This implementation certainly has drawbacks:
> > >   1) It can't configure Bus and Shunt conversion times separately
> > >      (Not crucial for me at this point as I set them equally)
> > >   2) Users need to calculate for the settings of conversion time
> > >   3) The ABI defines update_interval in msec while the hardware
> > >      and datasheet does in usec, and that generates rounding diff
> > >   4) The update_interval value would be spontaneously modified
> > >      everytime number of samples or number of enabled channels
> > >      gets changed. This might confuses users who tries to have
> > >      a fixed update_interval other than really merely setting
> > >      conversion time.
> > > 
> > > I see IIO subsystem have something like IIO_CHAN_INFO_INT_TIME
> > > for conversion time setting exclusively. Do we have something
> > > similar under hwmon?
> > > 
> > 
> > No. I think what you have should be good enough for now.
> > Please see comments below.

OK. I will go ahead with this approach then.

> > > +        /* Update Bus-voltage conversion time */
> > > +        ret = regmap_update_bits(ina->regmap, INA3221_CONFIG,
> > > +                     INA3221_CONFIG_VBUS_CT_MASK,
> > > +                     idx << INA3221_CONFIG_VBUS_CT_SHIFT);
> > > +        if (ret)
> > > +            return ret;
> > > +
> > > +        /* Update Shunt-voltage conversion time */
> > > +        ret = regmap_update_bits(ina->regmap, INA3221_CONFIG,
> > > +                     INA3221_CONFIG_VSH_CT_MASK,
> > > +                     idx << INA3221_CONFIG_VSH_CT_SHIFT);
> > > +        if (ret)
> > > +            return ret;
> > 
> > It should be possible to update both conversion times with a single call,
> > since both calls touch only one register. Something like
> > 
> >          ret = regmap_update_bits(ina->regmap, INA3221_CONFIG
> >              INA3221_CONFIG_VBUS_CT_MASK | INA3221_CONFIG_VSH_CT_MASK,
> >              (idx << INA3221_CONFIG_VBUS_CT_SHIFT) | (idx << INA3221_CONFIG_VSH_CT_SHIFT));
> > 
> > Granted, that is a bit long, but it saves an extra i2c write operation.

Will merge them.

> Thinking about it ... does it even make sense to cache reg_config twice,
> or would it be better to just update the local copy and use regmap_write()
> to send it to the chip ?

I remember the reason of adding the read-back was to prevent race
condition. But now we have mutex protections for all sysfs nodes,
maybe it's not necessary anymore. I will read the code carefully
and see if it's safe to remove it -- will do in a separate patch.

Thanks
Nicolin

  reply	other threads:[~2019-04-17 18:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-16 23:55 Nicolin Chen
2019-04-17 13:46 ` Guenter Roeck
2019-04-17 14:04   ` Guenter Roeck
2019-04-17 18:39     ` Nicolin Chen [this message]
2019-04-17 19:48       ` Nicolin Chen
2019-04-17 20:12         ` Guenter Roeck
2019-04-17 21:10           ` Nicolin Chen

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=20190417183949.GB5073@Asurada-Nvidia.nvidia.com \
    --to=nicoleotsuka@gmail.com \
    --cc=corbet@lwn.net \
    --cc=jdelvare@suse.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /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

all inboxes | Powered by JetHome®