Re: [PATCH] iio: cros_ec_accel_legacy: Add Read Only frequency entries

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

 



On Fri, Jul 3, 2020 at 2:29 AM Enric Balletbo i Serra
<enric.balletbo@xxxxxxxxxxxxx> wrote:
>
> Hi Gwendal,
>
> Thank you for the patch.
>
> On 2/7/20 0:10, Gwendal Grignou wrote:
> > Report to user space that 10Hz is the sampling frequency of
> > the accelerometers in legacy mode, and it can not be changed.
> >
> > Signed-off-by: Gwendal Grignou <gwendal@xxxxxxxxxxxx>
> > ---
> >  drivers/iio/accel/cros_ec_accel_legacy.c | 52 +++++++++++++++++++++++-
> >  1 file changed, 51 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/accel/cros_ec_accel_legacy.c b/drivers/iio/accel/cros_ec_accel_legacy.c
> > index 2532b9ad33842..e924183089368 100644
> > --- a/drivers/iio/accel/cros_ec_accel_legacy.c
> > +++ b/drivers/iio/accel/cros_ec_accel_legacy.c
> > @@ -33,6 +33,11 @@
> >   */
> >  #define ACCEL_LEGACY_NSCALE 9586168
> >
> > +/*
> > + * Sensor frequency is hard-coded to 10Hz.
> > + */
> > +#define ACCEL_LEGACY_FREQ 10
> > +
> >  static int cros_ec_accel_legacy_read_cmd(struct iio_dev *indio_dev,
> >                                 unsigned long scan_mask, s16 *data)
> >  {
> > @@ -96,6 +101,11 @@ static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
> >               *val = 0;
> >               ret = IIO_VAL_INT;
> >               break;
> > +     case IIO_CHAN_INFO_SAMP_FREQ:
> > +             *val = ACCEL_LEGACY_FREQ;
> > +             *val2 = 0;
> > +             ret = IIO_VAL_INT_PLUS_MICRO;
> > +             break;
> >       default:
> >               ret = cros_ec_sensors_core_read(st, chan, val, val2,
> >                               mask);
> > @@ -120,9 +130,41 @@ static int cros_ec_accel_legacy_write(struct iio_dev *indio_dev,
> >       return -EINVAL;
> >  }
> >
> > +/**
> > + * cros_ec_accel_legacy_read_avail() - get available values
> > + * @indio_dev:               pointer to state information for device
> > + * @chan:    channel specification structure table
> > + * @vals:    list of available values
> > + * @type:    type of data returned
> > + * @length:  number of data returned in the array
> > + * @mask:    specifies which values to be requested
> > + *
> > + * Return:   an error code, IIO_AVAIL_RANGE or IIO_AVAIL_LIST
>
> That's not really true, you're returning a list or an error code.
>
> > + */
> > +static int cros_ec_accel_legacy_read_avail(struct iio_dev *indio_dev,
> > +                                        struct iio_chan_spec const *chan,
> > +                                        const int **vals,
> > +                                        int *type,
> > +                                        int *length,
> > +                                        long mask)
> > +{
> > +     struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
> > +
> > +     switch (mask) {
> > +     case IIO_CHAN_INFO_SAMP_FREQ:
> > +             *length = 2;
> > +             *vals = (const int *)&state->frequencies;
>
> I am wondering if you shouldn't just
>
> static const int cros_ec_legacy_sample_freqs[] = { 10, 0 };
>
>     *length = ARRAY_SIZE(cros_ec_legacy_sample_freqs);
>     *vals = cros_ec_legacy_sample_freqs;
>
Will do.
> > +             *type = IIO_VAL_INT_PLUS_MICRO;
> > +             return IIO_AVAIL_LIST;
> > +     }
> > +
> > +     return -EINVAL;
> > +}
> > +
> >  static const struct iio_info cros_ec_accel_legacy_info = {
> >       .read_raw = &cros_ec_accel_legacy_read,
> >       .write_raw = &cros_ec_accel_legacy_write,
> > +     .read_avail = &cros_ec_accel_legacy_read_avail,
> >  };
> >
> >  /*
> > @@ -142,7 +184,11 @@ static const struct iio_info cros_ec_accel_legacy_info = {
> >               .info_mask_separate =                                   \
> >                       BIT(IIO_CHAN_INFO_RAW) |                        \
> >                       BIT(IIO_CHAN_INFO_CALIBBIAS),                   \
> > -             .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE),    \
> > +             .info_mask_shared_by_all =                              \
> > +                     BIT(IIO_CHAN_INFO_SCALE) |                      \
> > +                     BIT(IIO_CHAN_INFO_SAMP_FREQ),                   \
> > +             .info_mask_shared_by_all_available =                    \
> > +                     BIT(IIO_CHAN_INFO_SAMP_FREQ),                   \
> >               .ext_info = cros_ec_sensors_ext_info,                   \
> >               .scan_type = {                                          \
> >                       .sign = 's',                                    \
> > @@ -191,6 +237,10 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
> >               state->sign[CROS_EC_SENSOR_Z] = -1;
> >       }
> >
> > +     /* Frequency can not be changed on glimmer and is set to 10Hz. */
> > +     state->frequencies[0] = ACCEL_LEGACY_FREQ;
>
> If cannot be changed ...
>
> > +     state->frequencies[1] = 0;
>
> Why there are two values? 10Hz and 0Hz?
I returned a single IIO_VAL_INT_PLUS_MICRO, (10.000), I describe the
frequency with 2 ints.
>
> > +
> >       return devm_iio_device_register(dev, indio_dev);
> >  }
> >
> >



[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