Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
From: Gwendal Grignou <gwendal@chromium.org>
To: Stephen Boyd <swboyd@chromium.org>
Cc: Jonathan Cameron <jic23@kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Benson Leung <bleung@chromium.org>,
	Guenter Roeck <groeck@chromium.org>,
	Douglas Anderson <dianders@chromium.org>,
	Enric Balletbo i Serra <enric.balletbo@collabora.com>
Subject: Re: [PATCH v5 3/3] iio: proximity: Add a ChromeOS EC MKBP proximity driver
Date: Fri, 12 Feb 2021 11:22:37 -0800
Message-ID: <CAPUE2uvGaO_qpfg2S4vmcLto65eTzngbhL-pVcXKuS48r8zghQ@mail.gmail.com> (raw)
In-Reply-To: <161297912701.418021.12174983952645253802@swboyd.mtv.corp.google.com>

On Wed, Feb 10, 2021 at 9:45 AM Stephen Boyd <swboyd@chromium.org> wrote:
>
> Quoting Gwendal Grignou (2021-02-10 00:29:45)
> > On Tue, Feb 9, 2021 at 6:51 PM Stephen Boyd <swboyd@chromium.org> wrote:
> > > +       if (event_type == EC_MKBP_EVENT_SWITCH) {
> > > +               data = container_of(nb, struct cros_ec_mkbp_proximity_data,
> > > +                                   notifier);
> > > +               indio_dev = data->indio_dev;
> > > +
> > > +               mutex_lock(&data->lock);
> > > +               if (data->enabled) {
> > > +                       timestamp = ktime_to_ns(ec->last_event_time);
> > Note to self, ktime_to_ns is a noop, but make code cleaner: need to
> > change other access to ec->last_event_time.
> >
> > > +                       if (iio_device_get_clock(indio_dev) != CLOCK_BOOTTIME)
> > > +                               timestamp = iio_get_time_ns(indio_dev);
> > > +                       state = cros_ec_mkbp_proximity_parse_state(switches);
> >
> > There can be several switches in the EC (lid open, tablet mode, ...),
> > so you can get a switch event even when the proximity switch did not
> > trigger.
> > You can keep the current state and push an iio event only when there
> > is a change. See cbas_ec_notify().
> >
>
> Ah ok. So we'll have to save a state tracking variable and poll the bit
> once at boot and then at resume time?
Required at boot: There is provision in the EC to report switch events
at init mkbp_report_switch_on_init(), but that's only useful when EC
reboots or transitions from RO to RW while AP is up.
No need to peek at resume time: the EC will send a switch event if the
mask has changed during suspend: when the AP is sleeping, EC just put
the event in a FIFO. But looking at the code, the FIFO can get full,
so if no switch events can be added, we lose them - see
mkbp_fifo_add()).
Then cros_ec_report_events_during_suspend() will gather these events.
> What happens to events that happen across suspend/resume? We drop them?
We should not drop them: if the user gets close while the device is
suspended and she resumes it, we should be able to send that info to
the user space.
EV stores switches values in a single field |mkbp_switch_state|, so 2
events that nullify themselves during suspend will be ignored.
> Or we need to inject the last state
> if it's different into IIO with the time of resume?
The notifier routine will be called. Looking at the code, the ec
last_event_time is not updated, I need to fix cros_ec_resume().
>
> > > +                       dir = state ? IIO_EV_DIR_FALLING : IIO_EV_DIR_RISING;
> > > +
> > > +                       ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0,
> > > +                                                 IIO_EV_TYPE_THRESH, dir);
> > > +                       iio_push_event(indio_dev, ev, timestamp);
> > > +               }
> > > +               mutex_unlock(&data->lock);
> > > +       }
> > > +
> > > +       return NOTIFY_OK;
> > > +}
> > > +
> > > +static int cros_ec_mkbp_proximity_read_raw(struct iio_dev *indio_dev,
> > > +                          const struct iio_chan_spec *chan, int *val,
> > > +                          int *val2, long mask)
> > > +{
> > > +       struct cros_ec_mkbp_proximity_data *data = iio_priv(indio_dev);
> > > +       struct cros_ec_device *ec = data->ec;
> > > +
> > > +       if (chan->type != IIO_PROXIMITY)
> > > +               return -EINVAL;
> > > +
> > > +       switch (mask) {
> >
> > A switch is not necessary here.
>
> Ok.
>
> > > +       case IIO_CHAN_INFO_RAW:

      reply index

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10  2:51 [PATCHv5 0/3] iio: " Stephen Boyd
2021-02-10  2:51 ` [PATCH v5 1/3] platform/chrome: cros_ec: Add SW_FRONT_PROXIMITY MKBP define Stephen Boyd
2021-02-10  2:51 ` [PATCH v5 2/3] dt-bindings: iio: Add cros ec proximity yaml doc Stephen Boyd
2021-02-10 18:44   ` Rob Herring
2021-02-10  2:51 ` [PATCH v5 3/3] iio: proximity: Add a ChromeOS EC MKBP proximity driver Stephen Boyd
2021-02-10  8:29   ` Gwendal Grignou
2021-02-10 17:45     ` Stephen Boyd
2021-02-12 19:22       ` Gwendal Grignou [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=CAPUE2uvGaO_qpfg2S4vmcLto65eTzngbhL-pVcXKuS48r8zghQ@mail.gmail.com \
    --to=gwendal@chromium.org \
    --cc=bleung@chromium.org \
    --cc=dianders@chromium.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=enric.balletbo@collabora.com \
    --cc=groeck@chromium.org \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=swboyd@chromium.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

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org
	public-inbox-index linux-iio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git