* [PATCH v3] iio: cros_ec_accel_legacy: Add Read Only frequency entries
@ 2020-07-09 18:09 Gwendal Grignou
2020-07-10 8:21 ` Enric Balletbo i Serra
0 siblings, 1 reply; 3+ messages in thread
From: Gwendal Grignou @ 2020-07-09 18:09 UTC (permalink / raw)
To: jic23, bleung, enric.balletbo; +Cc: lars, linux-iio, Gwendal Grignou
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@chromium.org>
---
Changes since v2:
- fix compilation warning
Changes since v1:
- Use a static array to store the single frequency allowed.
drivers/iio/accel/cros_ec_accel_legacy.c | 46 +++++++++++++++++++++++-
1 file changed, 45 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..b6f3471b62dcf 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.
+ */
+static const int cros_ec_legacy_sample_freq[] = { 10, 0 };
+
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 = cros_ec_legacy_sample_freq[0];
+ *val2 = cros_ec_legacy_sample_freq[1];
+ ret = IIO_VAL_INT_PLUS_MICRO;
+ break;
default:
ret = cros_ec_sensors_core_read(st, chan, val, val2,
mask);
@@ -120,9 +130,39 @@ 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 or IIO_AVAIL_LIST
+ */
+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)
+{
+ switch (mask) {
+ case IIO_CHAN_INFO_SAMP_FREQ:
+ *length = ARRAY_SIZE(cros_ec_legacy_sample_freq);
+ *vals = cros_ec_legacy_sample_freq;
+ *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 +182,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', \
--
2.27.0.383.g050319c2ae-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] iio: cros_ec_accel_legacy: Add Read Only frequency entries
2020-07-09 18:09 [PATCH v3] iio: cros_ec_accel_legacy: Add Read Only frequency entries Gwendal Grignou
@ 2020-07-10 8:21 ` Enric Balletbo i Serra
2020-07-12 11:07 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Enric Balletbo i Serra @ 2020-07-10 8:21 UTC (permalink / raw)
To: Gwendal Grignou, jic23, bleung; +Cc: lars, linux-iio
Hi Gwendal,
On 9/7/20 20:09, 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@chromium.org>
Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> ---
> Changes since v2:
> - fix compilation warning
> Changes since v1:
> - Use a static array to store the single frequency allowed.
>
> drivers/iio/accel/cros_ec_accel_legacy.c | 46 +++++++++++++++++++++++-
> 1 file changed, 45 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..b6f3471b62dcf 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.
> + */
> +static const int cros_ec_legacy_sample_freq[] = { 10, 0 };
> +
> 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 = cros_ec_legacy_sample_freq[0];
> + *val2 = cros_ec_legacy_sample_freq[1];
> + ret = IIO_VAL_INT_PLUS_MICRO;
> + break;
> default:
> ret = cros_ec_sensors_core_read(st, chan, val, val2,
> mask);
> @@ -120,9 +130,39 @@ 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 or IIO_AVAIL_LIST
> + */
> +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)
> +{
> + switch (mask) {
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + *length = ARRAY_SIZE(cros_ec_legacy_sample_freq);
> + *vals = cros_ec_legacy_sample_freq;
> + *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 +182,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', \
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] iio: cros_ec_accel_legacy: Add Read Only frequency entries
2020-07-10 8:21 ` Enric Balletbo i Serra
@ 2020-07-12 11:07 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2020-07-12 11:07 UTC (permalink / raw)
To: Enric Balletbo i Serra; +Cc: Gwendal Grignou, bleung, lars, linux-iio
On Fri, 10 Jul 2020 10:21:47 +0200
Enric Balletbo i Serra <enric.balletbo@collabora.com> wrote:
> Hi Gwendal,
>
> On 9/7/20 20:09, 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@chromium.org>
>
> Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
I'm fairly sure you could have just used IIO_VAL_INT as the return
value given the micro part is 0. Doesn't make any practical difference
though so applied to the togreg branch of iio.git and pushed out as
testing for the autobuilders to play with it!
Thanks,
Jonathan
>
> > ---
> > Changes since v2:
> > - fix compilation warning
> > Changes since v1:
> > - Use a static array to store the single frequency allowed.
> >
> > drivers/iio/accel/cros_ec_accel_legacy.c | 46 +++++++++++++++++++++++-
> > 1 file changed, 45 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..b6f3471b62dcf 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.
> > + */
> > +static const int cros_ec_legacy_sample_freq[] = { 10, 0 };
> > +
> > 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 = cros_ec_legacy_sample_freq[0];
> > + *val2 = cros_ec_legacy_sample_freq[1];
> > + ret = IIO_VAL_INT_PLUS_MICRO;
> > + break;
> > default:
> > ret = cros_ec_sensors_core_read(st, chan, val, val2,
> > mask);
> > @@ -120,9 +130,39 @@ 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 or IIO_AVAIL_LIST
> > + */
> > +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)
> > +{
> > + switch (mask) {
> > + case IIO_CHAN_INFO_SAMP_FREQ:
> > + *length = ARRAY_SIZE(cros_ec_legacy_sample_freq);
> > + *vals = cros_ec_legacy_sample_freq;
> > + *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 +182,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', \
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-12 11:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-09 18:09 [PATCH v3] iio: cros_ec_accel_legacy: Add Read Only frequency entries Gwendal Grignou
2020-07-10 8:21 ` Enric Balletbo i Serra
2020-07-12 11:07 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox