iio: common: cros_ec_sensors: Expose cros_ec_sensors frequency range via iio sysfs

Embedded controller return minimum and maximum frequencies, unfortunately
we have no way to know the step for all available frequencies.
Even if not complete, we can return a list of known values using the
standard read_avail callback (IIO_CHAN_INFO_SAMP_FREQ) to provide them to
userland.

Now cros_ec_* sensors provides frequencies values in sysfs like this:
"0 min max". 0 is always true to disable the sensor.

Default frequencies are provided for earlier protocol.

Signed-off-by: Nick Vaccaro <nvaccaro@chromium.org>
Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
[rebased on top of iio/testing and solved conflicts]
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Fabien Lahoudere 2019-07-16 11:11:06 +02:00 committed by Jonathan Cameron
parent 9566cb1ddb
commit ae7b02ad2f
4 changed files with 92 additions and 0 deletions

View file

@ -73,6 +73,9 @@ struct cros_ec_sensors_core_state {
unsigned long scan_mask, s16 *data);
int curr_sampl_freq;
/* Table of known available frequencies : 0, Min and Max in mHz */
int frequencies[3];
};
/**
@ -153,6 +156,24 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask);
/**
* cros_ec_sensors_core_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
*/
int cros_ec_sensors_core_read_avail(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
const int **vals,
int *type,
int *length,
long mask);
/**
* cros_ec_sensors_core_write() - function to write a value to the sensor
* @st: pointer to state information for device