devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Pierre Bourdon (delroth)" <delroth@google.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-iio@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	devicetree <devicetree@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Daniel Baluta <daniel.baluta@gmail.com>
Subject: Re: [PATCH v2 1/2] iio: light: add driver for bh1730fvc chips
Date: Sat, 24 Feb 2018 12:41:17 +0000	[thread overview]
Message-ID: <20180224124117.115811e6@archlinux> (raw)
In-Reply-To: <CANEr7oVJosS5+XKqf+PBuwXG30cEqQFv_kvrgRdC=C+EvN67rg@mail.gmail.com>

On Thu, 22 Feb 2018 15:58:10 +0100
"Pierre Bourdon (delroth)" <delroth@google.com> wrote:

> Hi Andy,
> 
> Thanks for the review! Answers inline. I'll send a v3 when the two
> open questions are resolved.
> 
> On Wed, Feb 21, 2018 at 10:57 PM, Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Wed, Feb 21, 2018 at 9:45 PM, Pierre Bourdon <delroth@google.com> wrote:  
> >> Ambient light sensor that supports visible light and IR measurements and
> >> configurable gain/integration time.
> >>
> >> Changed in v2:
> >> * Split off DT documentation change into a separate commit.
> >> * Use i2c's probe_new.  
> >
> > Btw, how big the difference with existing drivers?  
> 
> See https://lkml.org/lkml/2018/2/21/982 . In retrospect, I should have
> added this to the commit message. It will be there in v3.
> 
> >> +       highest = max(visible, ir);
> >> +
> >> +       /*
> >> +        * If the read value is being clamped, assume the worst and go to the
> >> +        * lowest possible gain. The alternative is doing multiple
> >> +        * recalibrations, which would be slower and have the same effect.
> >> +        */
> >> +       if (highest == USHRT_MAX)
> >> +               highest *= 128;
> >> +       else
> >> +               highest = (highest * 128) / bh1730_gain_multiplier(bh1730);  
> >
> > In both cases you multiply.
> > Why not just
> >
> >      highest = max(visible, ir) * 128;
> >
> > if (highest < USHRT_MAX)
> > ...
> > ?  
> 
> You'd need < USHRT_MAX * 128 then. I refactored this a bit but
> differently. WDYT?
> 
>         if (highest == USHRT_MAX)
>                 gain = 1;
>         else
>                 gain = bh1730_gain_multiplier(bh1730);
> 
>         highest = (highest * BH1730_MAX_GAIN_MULTIPLIER) / gain;
> 
> >> +       millilux = (u64)USEC_PER_MSEC * (visible_coef * visible - ir_coef * ir);  
> >
> > I'm not sure I understand how time units is related to lux one.  
> 
> Now looks like this, which should match the units together better
> while keeping most multiplications before divisions (for accuracy).
> Not much better I can do here I think, for example the magic "103" is
> straight from the datasheet with no explanation.
> 
>         millilux = visible_coef * visible - ir_coef * ir;
>         millilux = (millilux * USEC_PER_MSEC) / itime_us;
>         millilux *= 103;
>         millilux /= bh1730_gain_multiplier(bh1730);
> 
> >> +       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*bh1730));
> >> +       if (!indio_dev)
> >> +               return -ENOMEM;
> >> +  
> >  
> >> +       indio_dev->dev.parent = &client->dev;  
> >
> > Strange, it's not done in IIO core... Jonathan, is it true that in
> > case of devm_iio_device_alloc() all drivers use supplied struct device
> > as a parent one?
> > If so, doesn't make sense to modify IIO core to do this?  
> 
> It doesn't seem like IIO core is doing it at this point. Should we
> just leave that as-is for now and get everything fixed in a future
> patch?

It's an interesting point - the bit that bothers me about rolling
that into the devm_iio_device_alloc is that it then
means that function is doing something a little non-obvious given
we don't have the relevant struct device available in the
iio_device_alloc call case.

However, we only have two iio_device_alloc calls left.
The dummy driver one doesn't have a parent (hardly surprising as
there is no hardware).

The other is harder to argue as it's inside the toshiba acpi
driver where reworking to make devm possible would be a major
job.

Hmm.  Will think about it...

> 
> >> +static int bh1730_remove(struct i2c_client *client)
> >> +{
> >> +       struct iio_dev *indio_dev = i2c_get_clientdata(client);
> >> +       struct bh1730_data *bh1730 = iio_priv(indio_dev);
> >> +  
> >  
> >> +       iio_device_unregister(indio_dev);  
> >
> > Hmm... Do you still need this even with devm IIO in ->probe()?  
> 
> I *think* so, but that's mostly because all the other IIO light
> drivers that I've looked at are doing it. Can someone who knows the
> IIO subsystem well weigh in?

Yes, it is absolutely needed.  This removes the userspace and core
kernel interfaces 'before' we turn the power off.  Without it there
are some obvious race conditions.  It's hard to query a sensor
which is powered down after all.

You could wrap up the power off call in devm magic, but that will
probably be more complex and error prone than doing it as we have
here.

In cases where there is no clean up to do in order we can
move to fully managed - this isn't one of those though.

Jonathan

> 
> Thanks!
> Best,
> 

  reply	other threads:[~2018-02-24 12:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180221125512.8265-1-delroth@google.com>
2018-02-21 19:45 ` [PATCH v2 1/2] iio: light: add driver for bh1730fvc chips Pierre Bourdon
2018-02-21 19:45   ` [PATCH v2 2/2] dt-bindings: iio: light: Add bh1730fvc bindings Pierre Bourdon
2018-02-21 21:57   ` [PATCH v2 1/2] iio: light: add driver for bh1730fvc chips Andy Shevchenko
2018-02-22 14:58     ` Pierre Bourdon (delroth)
2018-02-24 12:41       ` Jonathan Cameron [this message]
2018-02-24 12:53   ` Jonathan Cameron

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=20180224124117.115811e6@archlinux \
    --to=jic23@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=daniel.baluta@gmail.com \
    --cc=delroth@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).