Re: [PATCH v5 3/3] iio: proximity: Add a ChromeOS EC MKBP proximity driver
From: Stephen Boyd
Date: Wed Feb 10 2021 - 12:46:40 EST
Quoting Gwendal Grignou (2021-02-10 00:29:45)
> On Tue, Feb 9, 2021 at 6:51 PM Stephen Boyd <swboyd@xxxxxxxxxxxx> 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: