linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Boyd <swboyd@chromium.org>
To: Gwendal Grignou <gwendal@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: Wed, 10 Feb 2021 09:45:27 -0800	[thread overview]
Message-ID: <161297912701.418021.12174983952645253802@swboyd.mtv.corp.google.com> (raw)
In-Reply-To: <CAPUE2utey1os_CmYxHdmObCSPZWFGrLCVfP24wuZj_iQDNqQ5Q@mail.gmail.com>

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? What happens to events that happen
across suspend/resume? We drop them? Or we need to inject the last state
if it's different into IIO with the time of 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	other threads:[~2021-02-10 17:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10  2:51 [PATCHv5 0/3] iio: Add a ChromeOS EC MKBP proximity driver 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 [this message]
2021-02-12 19:22       ` Gwendal Grignou

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=161297912701.418021.12174983952645253802@swboyd.mtv.corp.google.com \
    --to=swboyd@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=gwendal@chromium.org \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.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).