linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: "Stephan Gerhold" <stephan@gerhold.net>,
	"Jonathan Cameron" <jic23@kernel.org>,
	linux-iio <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" <linux-input@vger.kernel.org>,
	"Minkyu Kang" <mk7.kang@samsung.com>,
	"Paweł Chmiel" <pawel.mikolaj.chmiel@gmail.com>,
	"Jonathan Bakker" <xc-racer2@live.ca>,
	"Oskar Andero" <oskar.andero@gmail.com>,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>
Subject: Re: [PATCH 2/2 v4] iio: light: Add a driver for Sharp GP2AP002x00F
Date: Fri, 17 Jan 2020 17:53:07 +0000	[thread overview]
Message-ID: <20200117175307.00000c8c@Huawei.com> (raw)
In-Reply-To: <CACRpkdbDEhCu8LVBT_xjuar1UgCPALJg0V12varZjG-eGqj=2Q@mail.gmail.com>

On Mon, 13 Jan 2020 22:02:00 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> On Sun, Jan 12, 2020 at 5:54 PM Stephan Gerhold <stephan@gerhold.net> wrote:
> 
> > It seems to work fine on samsung,golden with gp2ap002s00f.
> > There are interrupts being sent when something moves in front of the
> > sensor and iio-event-monitor looks good too:
> >
> > Tested-by: Stephan Gerhold <stephan@gerhold.net>  
> 
> Thanks! I think I'm up at v7 or something on this driver
> and now it looks good.
> 
> > Out of curiosity: I'm not so familiar with the IIO subsystem,
> > is it intended that the sensor is active the whole time?
> > Wouldn't it be better to activate it only when something is reading
> > /dev/iio:device2?  
> 
> IMO the best way to power manage an IIO sensor is like I do in
> drivers/iio/gyro/mpu3050-core.c
> 
> Of course I think it is excellent code since I wrote it. Beware
> of hubris in the driver.
> 
> The idea is to take the runtime pm handle on the device
> whenever in use (reading values from the hardware or
> using the trigger), and then use autosuspend to completely
> shut it down (including regulators) when not in use. If the power-up
> time for the sensor is long, then the autosuspend timeout
> should be proportionally longer, like a magnitude or two above.
> 
> With the proximity events I have this problem that I don't know
> in the driver if someone had opened the file to read events
> or not, only the core knows, I think. I just emit my events
> and be happy.
> 
> Jonathan: is there a way for the driver to know if someone
> is listening on the event interface?

Hmm. Normally we'd do it on someone actually enabling the events on
the basis I'd expect userspace to open the file then enable the events.

Nothing stops us doing it on file open I guess, but not sure what the
real world benefit would be.

> 
> > There is one problem I noticed, although I'm not sure if it is a problem
> > in this driver. Reading one of the files in the sysfs results in:
> >
> > $ cat /sys/bus/iio/devices/iio\:device2/events/in_proximity_thresh_either_en
> > Segmentation fault  
> 
> That looks like an ordinary bug, but that seems to be for the
> core? Hm...
Ah.. Seems I missed that you have the driver set event spec for enable, but
didn't actually provide the callback function.   + we clearly don't sanity
check that one.  Hence IIO core could do with hardening but driver is
buggy as well.

+static const struct iio_event_spec gp2ap002_events[] = {
+	{
+		.type = IIO_EV_TYPE_THRESH,
+		.dir = IIO_EV_DIR_EITHER,
+		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
+	},
+};

Means you must supply read_event_config in iio_info.
It's a bit odd if you don't also supply write event config for that
matter though that wasn't the bug here. It would cause a similar
bug if you wrote the sysfs file though :)

Kind of also explains why my logic about enabling the event
doesn't apply currently.

Good find from Stephan on both fronts.

Jonathan

> 
> Yours,
> Linus Walleij



  reply	other threads:[~2020-01-17 17:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-12 11:13 [PATCH 1/2 v4] iio: light: Add DT bindings for GP2AP002 Linus Walleij
2020-01-12 11:13 ` [PATCH 2/2 v4] iio: light: Add a driver for Sharp GP2AP002x00F Linus Walleij
2020-01-12 16:54   ` Stephan Gerhold
2020-01-13 21:02     ` Linus Walleij
2020-01-17 17:53       ` Jonathan Cameron [this message]
2020-01-13 22:52 ` [PATCH 1/2 v4] iio: light: Add DT bindings for GP2AP002 Rob Herring

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=20200117175307.00000c8c@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --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).