From: Linus Walleij <linus.walleij@linaro.org>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "Jonathan Bakker" <xc-racer2@live.ca>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"Hartmut Knaack" <knaack.h@gmx.de>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Peter Meerwald-Stadler" <pmeerw@pmeerw.net>,
"linux-input@vger.kernel.org" <linux-input@vger.kernel.org>,
"Stephan Gerhold" <stephan@gerhold.net>,
"Minkyu Kang" <mk7.kang@samsung.com>,
"Paweł Chmiel" <pawel.mikolaj.chmiel@gmail.com>,
"Oskar Andero" <oskar.andero@gmail.com>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>
Subject: Re: [PATCH 2/2 v5] iio: light: Add a driver for Sharp GP2AP002x00F
Date: Sat, 8 Feb 2020 13:35:18 +0100 [thread overview]
Message-ID: <CACRpkdaWZ46j6M=TFsOEQvS1WOJyVkpXRdML585aKp+oCJVB_A@mail.gmail.com> (raw)
In-Reply-To: <20200202150843.762c6897@archlinux>
On Sun, Feb 2, 2020 at 4:08 PM Jonathan Cameron <jic23@kernel.org> wrote:
> On Sun, 26 Jan 2020 20:27:22 +0000 Jonathan Bakker <xc-racer2@live.ca> wrote:
> > - if (ch_type != IIO_CURRENT) {
> > + if (ch_type == IIO_VOLTAGE) {
> > + ret = device_property_read_u8(dev,
> > + "sharp,adc-adjustment-ratio", &val);
> > + if (ret) {
> > + dev_err(dev,
> > + "failed to obtain adc conversion\n");
> > + return -EINVAL;
> > + }
> > + gp2ap002->adc_adj = val;
> > + } else if (ch_type != IIO_CURRENT) {
> > dev_err(dev,
> > "wrong type of IIO channel specified for ALSOUT\n");
> > return -EINVAL;
> >
> > Alternatively, you could collect the resistor value, the ADC precision (this doesn't
> > appear to be queryable via the IIO layer), and the reference voltage level - but I'm
> > not sure how you'd do the inverse calculation in the kernel.
>
> An alternative to doing this is to represent the resistor circuit explicitly.
>
> You end up with a really small ADC driver that is a consumer of a voltage
> and provides a current channel. That has all the properties of the
> circuit via DT.
That is indeed a lot better, more modular and more reusable.
It also becomes its own node in the device tree with very
generic bindings for resistance and ADC bias/offset.
> In general I would prefer we handle this sort of conversion generically
> rather than bolting it into a light sensor driver like you are doing here,
> even if it comes at the cost of a bit more complexity.
Agreed.
There are however two improvements that can be done as separate
patches to the code in this driver, but preferably by someone with access
to the right hardware so they can verify the result.
The Google Android code pointed to by Mr. Bakker:
https://android.googlesource.com/device/samsung/crespo/+/2e0ab7265e3039fee787c2216e0c98d92ea0b49e%5E%21/#F0
+ // Convert adc value to lux assuming:
+ // I = 10 * log(Ev) uA
+ // R = 47kOhm
+ // Max adc value 4095 = 3.3V
+ // 1/4 of light reaches sensor
+ mPendingEvent.light = powf(10, event->value * (330.0f
/ 4095.0f / 47.0f)) * 4;
contains:
- A logarithmic formula based on the datasheet which we
don't have but presumably correct. A patch converting the
crude interpolated look-up table to proper floating point maths
expressing the curve would be much appreciated and cuts
down the size of the driver. This should be one simple
patch with nothing else needing to be changed. According
to the formula it should be lux = 10^(mA/10) which corresponds
to the values in the table. I verified the values with a spreadsheet,
then I sent a patch like this, please test!
- A device tree property to compensate for the attenuation by
the glass in front of the sensor. In the example the
attenuation is 75%, only 1/4 of the light actually hits the
sensor. I am uncertain about the physics of this, should
that really be expressed as fraction or percentage?
Should it rather be in dB? This should be another patch
adding the DT property and maths for the attenuation.
Yours,
Linus Walleij
prev parent reply other threads:[~2020-02-08 12:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-21 21:04 [PATCH 1/2 v5] iio: light: Add DT bindings for GP2AP002 Linus Walleij
2020-01-21 21:04 ` [PATCH 2/2 v5] iio: light: Add a driver for Sharp GP2AP002x00F Linus Walleij
2020-01-24 0:47 ` Jonathan Bakker
2020-01-26 15:16 ` Linus Walleij
2020-01-26 20:27 ` Jonathan Bakker
2020-02-02 15:08 ` Jonathan Cameron
2020-02-08 12:35 ` Linus Walleij [this message]
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='CACRpkdaWZ46j6M=TFsOEQvS1WOJyVkpXRdML585aKp+oCJVB_A@mail.gmail.com' \
--to=linus.walleij@linaro.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=mk7.kang@samsung.com \
--cc=oskar.andero@gmail.com \
--cc=pawel.mikolaj.chmiel@gmail.com \
--cc=pmeerw@pmeerw.net \
--cc=stephan@gerhold.net \
--cc=xc-racer2@live.ca \
/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).