Re: [PATCH v5 3/3] iio: proximity: Add a ChromeOS EC MKBP proximity driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 10, 2021 at 9:45 AM Stephen Boyd <swboyd@xxxxxxxxxxxx> wrote:
>
> 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?
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:




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux