linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Jonathan Bakker <xc-racer2@live.ca>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"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: Sun, 26 Jan 2020 16:16:59 +0100	[thread overview]
Message-ID: <CACRpkdYMxXL6oY0eA+5EYOUTZ_opAtiT-6THfc9dwy_9Ufq8MQ@mail.gmail.com> (raw)
In-Reply-To: <BYAPR10MB3479CEEA65545B8422C77091A30E0@BYAPR10MB3479.namprd10.prod.outlook.com>

On Fri, Jan 24, 2020 at 1:47 AM Jonathan Bakker <xc-racer2@live.ca> wrote:

> Thanks for the driver, I've tested it on a first-gen Galaxy S
> device with a GP2AP002A00F.  I have a few comments that I've put inline
> based on my experiences.

Thanks a lot!

> Both shortly after probe (when runtime pm timeout occurs?) and after
> manually disabling the proximity event, this
> irq handler is called.  Since the chip is in low power state, it obviously
> fails to read the proximity value and write to the OCON register below, eg
>
> [    7.215875] gp2ap002 11-0044: error reading proximity
> [    8.105878] gp2ap002 11-0044: error setting up VOUT control 1
>
> Can we do something like disable_irq() in the runtime pm function to prevent
> this?

I added that in v6, I hope this solves your problem.

> The gp2ap002s00f_regmap_i2c_read function works on the gp2ap002a00f as well,
> so this can be simplified/dropped.

Fixed this too in v6.

> > +             if (ch_type != IIO_CURRENT) {
> > +                     dev_err(dev,
> > +                             "wrong type of IIO channel specified for ALSOUT\n");
> > +                     return -EINVAL;
> > +             }
>
> This enforces a current ADC, while several devices besides mine (eg Galaxy Nexus)
> use a resistor and a voltage ADC.  For this case, could we add a device property such as
> sharp,adc-adjustment-ratio to convert from the raw ADC values to a "current" that
> could be used in the lookup table?  So the "current" would be the raw ADC divided
> by that special value.
>
> Instructions for converting the ADC back to the current can be found eg at
> https://android.googlesource.com/device/samsung/crespo/+/2e0ab7265e3039fee787c2216e0c98d92ea0b49e%5E%21/#F0

I'd like to keep that as a future enhancement unless someone is very eager
to get it and has a device they can test it on. Otherwise it will be
just dry-coding
on my part.

I think the property we would add in the device tree in that case should
be the resistance value. This is based on the following assumption
which is indeed a bit of speculation since there is no proper datasheet
for the light sensor part of the component:

- The light sensor part is simply a photodiode
- This emits a nonlinear current in relation to how many
  photons hit the photodiode in a time interval, the relationship
  is described in the curren->lux table we have
- Some vendors do not have any current ADC, so they connect
  this to a resistor, and measure the voltage over the
  resistor because the have a voltage ADC

Since current is linear to the voltage over the resistor, we should
include the resistance in the device tree, then using that the
corresponding current can be calculated and we use the same
look-up table to find the lux. Probably each system may need
to also subtract some bias voltage or so.

But we definately need something to test on to do this right.

Yours,
Linus Walleij

  reply	other threads:[~2020-01-26 15:17 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 [this message]
2020-01-26 20:27       ` Jonathan Bakker
2020-02-02 15:08         ` Jonathan Cameron
2020-02-08 12:35           ` Linus Walleij

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=CACRpkdYMxXL6oY0eA+5EYOUTZ_opAtiT-6THfc9dwy_9Ufq8MQ@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).