Expose cros_ec_sensors frequency range via iio sysfs
Subsystems (2)
v4 cover Expose cros_ec_sensors frequency range via iio sysfs
Chromebooks EC sensors must expose a range of frequencies for each sensors using the standard ABI sampling_frquency_available.
This patch needs https://lkml.org/lkml/2019/7/2/345
Changes since v3:
- Split patch 6
- Drop clean up patches
- Fix minor changes
Changes since v2:
- use read_avail callback
- rework core functions to avoid code duplication
Changes since v1:
- Add a cover letter
- Add Nick Vaccaro SoB to patch 1
- Drop fifo size related code
Fabien Lahoudere (1):
iio: common: cros_ec_sensors: Expose cros_ec_sensors frequency range
via iio sysfs
.../common/cros_ec_sensors/cros_ec_sensors.c | 3 + .../cros_ec_sensors/cros_ec_sensors_core.c | 65 +++++++++++++++++++ drivers/iio/light/cros_ec_light_prox.c | 3 + .../linux/iio/common/cros_ec_sensors_core.h | 21 ++++++ 4 files changed, 92 insertions(+)
Signature · 1 line
2.19.2
PATCH v4 1/1 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.
--- .../common/cros_ec_sensors/cros_ec_sensors.c | 3 + .../cros_ec_sensors/cros_ec_sensors_core.c | 65 +++++++++++++++++++ drivers/iio/light/cros_ec_light_prox.c | 3 + .../linux/iio/common/cros_ec_sensors_core.h | 21 ++++++ 4 files changed, 92 insertions(+)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +3 -0
@@ -175,6 +175,7 @@ static int cros_ec_sensors_write(struct iio_dev *indio_dev,static const struct iio_info ec_sensors_info = { .read_raw = &cros_ec_sensors_read, .write_raw = &cros_ec_sensors_write, + .read_avail = &cros_ec_sensors_core_read_avail, };static int cros_ec_sensors_probe (struct platform_device *pdev)
@@ -211,6 +212,8 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)BIT (IIO_CHAN_INFO_SCALE ) |BIT (IIO_CHAN_INFO_FREQUENCY ) |BIT (IIO_CHAN_INFO_SAMP_FREQ ); + channel->info_mask_shared_by_all_available = +BIT (IIO_CHAN_INFO_SAMP_FREQ ); channel->scan_type.realbits =CROS_EC_SENSOR_BITS ; channel->scan_type.storagebits =CROS_EC_SENSOR_BITS ; channel->scan_index = i;
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +65 -0
83 lines not on this page · raw message
drivers/iio/light/cros_ec_light_prox.c +3 -0
@@ -164,6 +164,7 @@ static int cros_ec_light_prox_write(struct iio_dev *indio_dev,static const struct iio_info cros_ec_light_prox_info = { .read_raw = &cros_ec_light_prox_read, .write_raw = &cros_ec_light_prox_write, + .read_avail = &cros_ec_sensors_core_read_avail, };static int cros_ec_light_prox_probe (struct platform_device *pdev)
@@ -198,6 +199,8 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev) channel->info_mask_shared_by_all =BIT (IIO_CHAN_INFO_SAMP_FREQ ) |BIT (IIO_CHAN_INFO_FREQUENCY ); + channel->info_mask_shared_by_all_available = +BIT (IIO_CHAN_INFO_SAMP_FREQ ); channel->scan_type.realbits =CROS_EC_SENSOR_BITS ; channel->scan_type.storagebits =CROS_EC_SENSOR_BITS ; channel->scan_type.shift =0 ;
include/linux/iio/common/cros_ec_sensors_core.h +21 -0
@@ -70,6 +70,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 ]; };/**
@@ -150,6 +153,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
Signature · 1 line
2.19.2
Re: [PATCH v4 1/1] iio: common: cros_ec_sensors: Expose cros_ec_sensors frequency range via iio sysfs
Quoted 6 lines · On Tue, 9 Jul 2019 13:53:45 +0200 Fabien Lahoudere…
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_availcallback (IIO_CHAN_INFO_SAMP_FREQ) to provide them to userland.
Quoted 7 lines
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 <[email protected]>Signed-off-by Fabien Lahoudere <[email protected]>
There is some trailing whitespace in here, and with the high level of other work going on in this driver a lot of fuzz.
So with the whitespace fixed,
Quoted 178 lines
--- .../common/cros_ec_sensors/cros_ec_sensors.c | 3 + .../cros_ec_sensors/cros_ec_sensors_core.c | 65 +++++++++++++++++++ drivers/iio/light/cros_ec_light_prox.c | 3 + .../linux/iio/common/cros_ec_sensors_core.h | 21 ++++++ 4 files changed, 92 insertions(+)drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +3
-0@@ -175,6 +175,7 @@ static int cros_ec_sensors_write(struct iio_dev *indio_dev,static const struct iio_info ec_sensors_info = { .read_raw = &cros_ec_sensors_read, .write_raw = &cros_ec_sensors_write, + .read_avail = &cros_ec_sensors_core_read_avail, };static int cros_ec_sensors_probe (struct platform_device *pdev)@@ -211,6 +212,8 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)BIT (IIO_CHAN_INFO_SCALE ) |BIT (IIO_CHAN_INFO_FREQUENCY ) |BIT (IIO_CHAN_INFO_SAMP_FREQ ); + channel->info_mask_shared_by_all_available = +BIT (IIO_CHAN_INFO_SAMP_FREQ ); channel->scan_type.realbits =CROS_EC_SENSOR_BITS ; channel->scan_type.storagebits =CROS_EC_SENSOR_BITS ; channel->scan_index = i;drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +65
-0@@ -50,6 +50,37 @@ static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev,return ret; } +static void get_default_min_max_freq (enum motionsensor_type type, +u32 *min_freq, +u32 *max_freq) +{ +switch (type) { +case MOTIONSENSE_TYPE_ACCEL : +case MOTIONSENSE_TYPE_GYRO : + *min_freq =12500 ; + *max_freq =100000 ; +break ; +case MOTIONSENSE_TYPE_MAG : + *min_freq =5000 ; + *max_freq =25000 ; +break ; +case MOTIONSENSE_TYPE_PROX : +case MOTIONSENSE_TYPE_LIGHT : + *min_freq =100 ; + *max_freq =50000 ; +break ; +case MOTIONSENSE_TYPE_BARO : + *min_freq =250 ; + *max_freq =20000 ; +break ; +case MOTIONSENSE_TYPE_ACTIVITY : +default : + *min_freq =0 ; + *max_freq =0 ; +break ; + } +} +int cros_ec_sensors_core_init (struct platform_device *pdev,struct iio_dev *indio_dev,bool physical_device)@@ -100,6 +131,19 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, } state->type = state->resp->info.type; state->loc = state->resp->info.location; + +/* 0 is a correct value used to stop the device */ + state->frequencies[0 ] =0 ; +if (state->msg->version <3 ) { +get_default_min_max_freq (state->resp->info.type, + &state->frequencies[1 ], + &state->frequencies[2 ]); + }else { + state->frequencies[1 ] = + state->resp->info_3.min_frequency; + state->frequencies[2 ] = + state->resp->info_3.max_frequency; + } }return 0 ;@@ -461,6 +505,27 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st, }EXPORT_SYMBOL_GPL (cros_ec_sensors_core_read); +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) +{ +struct cros_ec_sensors_core_state *state =iio_priv (indio_dev); + +switch (mask) { +case IIO_CHAN_INFO_SAMP_FREQ : + *length =ARRAY_SIZE (state->frequencies); + *vals = (const int *)&state->frequencies; + *type =IIO_VAL_INT ; +return IIO_AVAIL_LIST ; + } + +return -EINVAL ; +} +EXPORT_SYMBOL_GPL (cros_ec_sensors_core_read_avail); +int cros_ec_sensors_core_write (struct cros_ec_sensors_core_state *st,struct iio_chan_spec const *chan,int val,int val2,long mask)drivers/iio/light/cros_ec_light_prox.c +3
-0@@ -164,6 +164,7 @@ static int cros_ec_light_prox_write(struct iio_dev *indio_dev,static const struct iio_info cros_ec_light_prox_info = { .read_raw = &cros_ec_light_prox_read, .write_raw = &cros_ec_light_prox_write, + .read_avail = &cros_ec_sensors_core_read_avail, };static int cros_ec_light_prox_probe (struct platform_device *pdev)@@ -198,6 +199,8 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev) channel->info_mask_shared_by_all =BIT (IIO_CHAN_INFO_SAMP_FREQ ) |BIT (IIO_CHAN_INFO_FREQUENCY ); + channel->info_mask_shared_by_all_available = +BIT (IIO_CHAN_INFO_SAMP_FREQ ); channel->scan_type.realbits =CROS_EC_SENSOR_BITS ; channel->scan_type.storagebits =CROS_EC_SENSOR_BITS ; channel->scan_type.shift =0 ;include/linux/iio/common/cros_ec_sensors_core.h +21
-0@@ -70,6 +70,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 ]; };/** @@ -150,6 +153,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
Re: [PATCH v4 1/1] iio: common: cros_ec_sensors: Expose cros_ec_sensors frequency range via iio sysfs
Quoted 16 lines · Jonathan Cameron
Quoted 13 lines · On Tue, 9 Jul 2019 13:53:45 +0200 Fabien Lahoudere…
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
standardread_availcallback (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.
Quoted 7 lines
Quoted 4 lines
Default frequencies are provided for earlier protocol.
Signed-off-by Nick Vaccaro <[email protected]>Signed-off-by Fabien Lahoudere <[email protected]>There is some trailing whitespace in here, and with the high level of other work going on in this driver a lot of fuzz.
Sorry for that, I will fix it quickly.
Thanks for reviewing
Quoted 201 lines
So with the whitespace fixed,
Acked-by Jonathan Cameron <[email protected]>Quoted 199 lines
--- .../common/cros_ec_sensors/cros_ec_sensors.c | 3 + .../cros_ec_sensors/cros_ec_sensors_core.c | 65 +++++++++++++++++++ drivers/iio/light/cros_ec_light_prox.c | 3 + .../linux/iio/common/cros_ec_sensors_core.h | 21 ++++++ 4 files changed, 92 insertions(+)drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +1
-0@@ -175,6 +175,7 @@ static int cros_ec_sensors_write(struct iio_dev *indio_dev, static const struct iio_info ec_sensors_info = { .read_raw = &cros_ec_sensors_read, .write_raw = &cros_ec_sensors_write, + .read_avail = &cros_ec_sensors_core_read_avail, };static int
cros_ec_sensors_probe(struct platform_device *pdev)drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +2
-0@@ -211,6 +212,8 @@ static int cros_ec_sensors_probe(struct platform_device *pdev) BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_FREQUENCY) | BIT(IIO_CHAN_INFO_SAMP_FREQ); + channel->info_mask_shared_by_all_available = + BIT(IIO_CHAN_INFO_SAMP_FREQ); channel->scan_type.realbits = CROS_EC_SENSOR_BITS; channel->scan_type.storagebits = CROS_EC_SENSOR_BITS;
channel->scan_index= i;
diff --gita/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.cb/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.cindex 81111af8a167..805652250960 100644drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +31
-0@@ -50,6 +50,37 @@ static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev, return ret; } +static void get_default_min_max_freq (enum motionsensor_type type, +u32 *min_freq, +u32 *max_freq) +{ +switch (type) { +case MOTIONSENSE_TYPE_ACCEL : +case MOTIONSENSE_TYPE_GYRO : + *min_freq =12500 ; + *max_freq =100000 ; +break ; +case MOTIONSENSE_TYPE_MAG : + *min_freq =5000 ; + *max_freq =25000 ; +break ; +case MOTIONSENSE_TYPE_PROX : +case MOTIONSENSE_TYPE_LIGHT : + *min_freq =100 ; + *max_freq =50000 ; +break ; +case MOTIONSENSE_TYPE_BARO : + *min_freq =250 ; + *max_freq =20000 ; +break ; +case MOTIONSENSE_TYPE_ACTIVITY : +default : + *min_freq =0 ; + *max_freq =0 ; +break ; + } +} + int cros_ec_sensors_core_init(struct platform_device *pdev, struct iio_dev *indio_dev,drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +7
-0bool physical_device)@@ -100,6 +131,19 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, } state->type = state->resp->info.type; state->loc = state->resp->info.location; + +/* 0 is a correct value used to stop the device */ + state->frequencies[0 ] =0 ; +if (state->msg->version <3 ) { + get_default_min_max_freq(state->resp- >info.type, + &state- >frequencies[1], + &state-Quoted 1 line
frequencies[2]);
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +27
-0+ }else { + state->frequencies[1 ] = + state->resp->info_3.min_frequency; + state->frequencies[2 ] = + state->resp->info_3.max_frequency; + } }return 0 ;@@ -461,6 +505,27 @@ int cros_ec_sensors_core_read(structcros_ec_sensors_core_state *st, }EXPORT_SYMBOL_GPL (cros_ec_sensors_core_read ); +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) +{ +struct cros_ec_sensors_core_state *state =iio_priv (indio_dev); + +switch (mask) { +case IIO_CHAN_INFO_SAMP_FREQ : + *length =ARRAY_SIZE (state->frequencies); + *vals = (const int *)&state->frequencies; + *type =IIO_VAL_INT ; +return IIO_AVAIL_LIST ; + } + +return -EINVAL ; +} +EXPORT_SYMBOL_GPL (cros_ec_sensors_core_read_avail); + int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st,drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +0
-0struct iio_chan_spec const *chan, int val, int val2, long mask)drivers/iio/light/cros_ec_light_prox.c +1
-0@@ -164,6 +164,7 @@ static int cros_ec_light_prox_write(struct iio_dev *indio_dev, static const struct iio_info cros_ec_light_prox_info = { .read_raw = &cros_ec_light_prox_read, .write_raw = &cros_ec_light_prox_write, + .read_avail = &cros_ec_sensors_core_read_avail, };static int
cros_ec_light_prox_probe(struct platform_device *pdev)drivers/iio/light/cros_ec_light_prox.c +2
-0@@ -198,6 +199,8 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev) channel->info_mask_shared_by_all =BIT (IIO_CHAN_INFO_SAMP_FREQ ) |BIT (IIO_CHAN_INFO_FREQUENCY ); + channel->info_mask_shared_by_all_available = +BIT (IIO_CHAN_INFO_SAMP_FREQ ); channel->scan_type.realbits =CROS_EC_SENSOR_BITS ; channel->scan_type.storagebits =CROS_EC_SENSOR_BITS ;drivers/iio/light/cros_ec_light_prox.c +0
-0channel->scan_type.shift =0 ;include/linux/iio/common/cros_ec_sensors_core.h +3
-0@@ -70,6 +70,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 ]; };/**
include/linux/iio/common/cros_ec_sensors_core.h +18
-0@@ -150,6 +153,24 @@ int cros_ec_sensors_core_read(structcros_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