Cros EC sensor hub FIFO support
Subsystems (3)
v7 cover Cros EC sensor hub FIFO support
This patchset adds a sensorhub driver for spreading sensor events coming from the Embedded controller sensor FIFO:
+---------------+ +--------------+ +----
| cros_ec_accel | | cros_ec_gyro | | ...
+---------------+ +--------------+ +----
id:0 \ id:1 | / id:..
+------------------------------+
| cros-ec-sensorhub |
+------------------------------+
| cros_ec_dev |
+------------------------------+
| cros_ec_i2c, cros_ec_lpc, .. |
+------------------------------+
|EC
When new sensors events are present, the EC raises and interrupt, sensorhub reads the FIFO and uses the 'id' field to spread the event to the proper IIO sensors. This stack is similar to the HID sensor input stack.
The patch set allows the host to receive MEMS sensor sample asynchronously from ChromeOS Emebedded Controller (EC).
Given the EC and the host are not synchronized, the timestamp generated by the EC drifts and the AP interrupt latency adds variable delay.
When events arrive, the driver stores the time of the interrupt and use that information to convert the timestamp from the EC time domain to the AP time domain. To prevent the errors from the interrupt time variation, a median filter smooth the timestamp generation and prevents timestamps to go in the past.
When a batch of sensor events arrives, the sensor hub ring code spreads the timestamps.
The buffer interaface is presentid through the IIO ABI.
And extra parameter - flush - (presents on HID and ST sensor hub implementation) force the EC to send accumulated events in its queue, without waiting for buffer hwfifo_timeout to expire.
To access sensor data, we can use iio_readdev like:
iio_readdev -T 10000 -s 4 -b 2 iio:device4
When FIFO is not supported by the EC, a trigger is present in the directory. After registering a trigger, setting sampling_frequency, the latest data collected by the sensor will be retrieved by the host when the trigger expires.
When cros_ec_accel_legacy driver is used, no FIFO is supported and the sampling frequency for the accelerometers is hard coded at 10Hz.
Gwendal Grignou (12):
platform: chrome: sensorhub: Add the number of sensors in sensorhub
platform: chrome: sensorhub: Add FIFO support
platform: chrome: sensorhub: Add code to spread timestmap
platform: chrome: sensorhub: Add median filter
iio: cros_ec: Move function description to .c file
iio: expose iio_device_set_clock
iio: cros_ec: Register to cros_ec_sensorhub when EC supports FIFO
iio: cros_ec: Remove pm function
iio: cros_ec: Expose hwfifo_timeout
iio: cros_ec: Report hwfifo_watermark_max
iio: cros_ec: Use Hertz as unit for sampling frequency
iio: cros_ec: flush as hwfifo attribute
drivers/iio/accel/cros_ec_accel_legacy.c | 8 +- .../cros_ec_sensors/cros_ec_lid_angle.c | 3 +- .../common/cros_ec_sensors/cros_ec_sensors.c | 13 +- .../cros_ec_sensors/cros_ec_sensors_core.c | 403 +++++-- drivers/iio/industrialio-core.c | 8 +- drivers/iio/light/cros_ec_light_prox.c | 15 +- drivers/iio/pressure/cros_ec_baro.c | 14 +- drivers/platform/chrome/Makefile | 4 +- drivers/platform/chrome/cros_ec_sensorhub.c | 111 +- .../platform/chrome/cros_ec_sensorhub_ring.c | 1046 +++++++++++++++++ .../linux/iio/common/cros_ec_sensors_core.h | 104 +- include/linux/iio/iio.h | 2 + .../linux/platform_data/cros_ec_sensorhub.h | 163 +++ 13 files changed, 1655 insertions(+), 239 deletions(-) create mode 100644 drivers/platform/chrome/cros_ec_sensorhub_ring.c
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v7 1/12 platform: chrome: sensorhub: Add the number of sensors in sensorhub
To better manage resources, store the number of sensors reported by the EC.
---
New in v7
drivers/platform/chrome/cros_ec_sensorhub.c | 4 +++- include/linux/platform_data/cros_ec_sensorhub.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_sensorhub.c +3 -1
@@ -65,6 +65,7 @@ static int cros_ec_sensorhub_register(struct device *dev,return sensor_num; } + sensorhub->sensor_num = sensor_num;if (sensor_num ==0 ) {dev_err (dev,"Zero sensors reported.\n" );return -EINVAL ;
@@ -172,7 +173,8 @@ static int cros_ec_sensorhub_probe(struct platform_device *pdev)* If the device has sensors but does not claim to * be a sensor hub, we are in legacy mode. */ -for (i =0 ; i <2 ; i++) { + data->sensor_num =2 ; +for (i =0 ; i < data->sensor_num; i++) { ret =cros_ec_sensorhub_allocate_sensor (dev,"cros-ec-accel-legacy" , i);if (ret)
include/linux/platform_data/cros_ec_sensorhub.h +2 -0
@@ -22,9 +22,11 @@ struct cros_ec_sensor_platform {* struct cros_ec_sensorhub - Sensor Hub device data. * * @ec: Embedded Controller where the hub is located. +* @sensor_num: Number of MEMS sensors present in the EC. */ struct cros_ec_sensorhub {struct cros_ec_dev *ec; +int sensor_num; };#endif /* __LINUX_PLATFORM_DATA_CROS_EC_SENSORHUB_H */
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v7 2/12 platform: chrome: sensorhub: Add FIFO support
In reply to Gwendal Grignoucros_ec_sensorhub registers a listener and query motion sense FIFO, spread to iio sensors registers.
To test, we can use libiio:
iiod&iio_readdev -u ip:localhost -T 10000 -s 25 -b 16 cros-ec-gyro | od -x
---
Changes in v7:
- Use the number of sensors present to create the right number of callback slots and to collect the right amount of FIFO information when sensor events are lost.
- Report the number of lost events for sensors that lost all their events.
Changes in v6:
- Unify function naming in cros_ec_sensorhub: cros_ec_sensorhub_ring_...
- Kernel module name is now cros-ec-sensorhub
- Remove unneceassary warning messages.
Changes in v5:
- Use a goto in cros_ec_sensorhub_ring_handler to centralize error handling
- Use devm_add_action_or_reset to not need a .remove entry point for cros_sensor_hub.
- Fix logic error in cros_ec_sensorhub_register_push_data.
- Update kernel_doc documentation.
- Remve the need for comments in variable declaration section. Changes in v4:
- Keep defining cros_ec_sensorhub in kernel-doc format
- Fix logic error when checking if sensor index outside array.
- Check patch with --strict option
Use sizeof(*obj) instead of sizeof(struct ...obj) Alignement
Use uX instead of uintX_t
Use !ptr instead of ptr != NULL
Changes in v3:
- Do not use ret !=
- Simplfy errpr handling by removing a goto
- Fix doxygen comments
- Replace suspend/resume entry points with regular driver entry point; There was an issue in the past where the sensor stack was preventing device to suspend, but the proper fix has been implemented in cros_ec code (6ad16b78a039b "platform/chrome: don't reportEC_MKBP_EVENT_SENSOR_FIFO as wakeup")
- Reduce mutex scope by checking return code outside of it. Changes in v2:
- Do not register a .remove routinge in plaform_driver. A devm_action_add is added later patch IIO driver register their
callback.
- Remove double lines, add lines before return calls.
- Handle FLUSH flag from EC.
- Use ktime_t for most timestamp measurements.
- Add doxygen comments
- Cleanup timestamp collection when processing FIFO.
- Rename fifo_toggle to fifo_enable
drivers/platform/chrome/Makefile | 4 +- drivers/platform/chrome/cros_ec_sensorhub.c | 107 +++-- .../platform/chrome/cros_ec_sensorhub_ring.c | 439 ++++++++++++++++++ .../linux/platform_data/cros_ec_sensorhub.h | 76 +++ 4 files changed, 598 insertions(+), 28 deletions(-) create mode 100644 drivers/platform/chrome/cros_ec_sensorhub_ring.c
drivers/platform/chrome/Makefile +3 -1
@@ -20,7 +20,9 @@ obj-$(CONFIG_CROS_EC_CHARDEV) += cros_ec_chardev.o obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o obj-$(CONFIG_CROS_EC_VBC) += cros_ec_vbc.o obj-$(CONFIG_CROS_EC_DEBUGFS) += cros_ec_debugfs.o -obj-$(CONFIG_CROS_EC_SENSORHUB) += cros_ec_sensorhub.o +obj-$(CONFIG_CROS_EC_SENSORHUB) += cros-ec-sensorhub.o +cros-ec-sensorhub-objs := cros_ec_sensorhub.o +cros-ec-sensorhub-objs += cros_ec_sensorhub_ring.o obj-$(CONFIG_CROS_EC_SYSFS) += cros_ec_sysfs.o obj-$(CONFIG_CROS_USBPD_LOGGER) += cros_usbpd_logger.o obj-$(CONFIG_CROS_USBPD_NOTIFY) += cros_usbpd_notify.o
drivers/platform/chrome/cros_ec_sensorhub.c +80 -27
175 lines not on this page · raw message
drivers/platform/chrome/cros_ec_sensorhub_ring.c new file +439 -0
439 lines not on this page · raw message
include/linux/platform_data/cros_ec_sensorhub.h +76 -0
99 lines not on this page · raw message
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
kbuild test robot
build botRe: [PATCH v7 02/12] platform: chrome: sensorhub: Add FIFO support
Thank you for the patch! Perhaps something to improve:
Hi Gwendal,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on chrome-platform-linux/for-next]
[also build test WARNING on linus/master linux/master v5.6] [cannot apply to iio/togreg]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Gwendal-Grignou/Cros-EC-sensor-hub-FIFO-support/20200328-063655 base: https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next config: x86_64-randconfig-a002-20200329 (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project dd030036f0a2ace74d0bd2242cfdbcf726ef565d)
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag
All warnings (new ones prefixed by >>):
>> drivers/platform/chrome/cros_ec_sensorhub_ring.o: warning: objtool: __llvm_gcov_writeout()+0x14: call without frame pointer save/setup >> drivers/platform/chrome/cros_ec_sensorhub_ring.o: warning: objtool: __llvm_gcov_flush()+0x0: call without frame pointer save/setup
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v7 02/12] platform: chrome: sensorhub: Add FIFO support
Quoted 12 lines · kbuild test robot
Hi Gwendal,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on chrome-platform-linux/for-next]
[also build test WARNING on linus/master linux/master v5.6] [cannot apply to iio/togreg]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
Quoted 3 lines
url: https://github.com/0day-ci/linux/commits/Gwendal-Grignou/Cros-EC-sensor-hub-FIFO-support/20200328-063655 base: https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next config: x86_64-randconfig-a002-20200329 (attached as .config)
Looks like a randconfig build enabled gcov; maybe we have an issue with objtool here to resolve?
Quoted 23 lines
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project
dd030036f0a2ace74d0bd2242cfdbcf726ef565d) reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER=clang make.cross ARCH=x86_64If you fix the issue, kindly add following tag
Reported-by kbuild test robot <[email protected]>All warnings (new ones prefixed by >>):
Quoted 2 lines
Quoted 2 lines
drivers/platform/chrome/cros_ec_sensorhub_ring.o: warning: objtool: __llvm_gcov_writeout()+0x14: call without frame pointer save/setupdrivers/platform/chrome/cros_ec_sensorhub_ring.o: warning: objtool: __llvm_gcov_flush()+0x0: call without frame pointer save/setup---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe(a)googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/202003301529.ukpsA1aF%25lkp%40intel.com.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Re: [PATCH v7 02/12] platform: chrome: sensorhub: Add FIFO support
Quoted 14 lines · Nick Desaulniers
Quoted 12 lines · kbuild test robot
Hi Gwendal,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on chrome-platform-linux/for-next]
[also build test WARNING on linus/master linux/master v5.6] [cannot apply to iio/togreg]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
Quoted 6 lines
Quoted 3 lines
url: https://github.com/0day-ci/linux/commits/Gwendal-Grignou/Cros-EC-sensor-hub-FIFO-support/20200328-063655 base: https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next config: x86_64-randconfig-a002-20200329 (attached as .config)Looks like a randconfig build enabled gcov; maybe we have an issue with objtool here to resolve?
Will track here: https://github.com/ClangBuiltLinux/linux/issues/955
Quoted 30 lines
Quoted 16 lines
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project
dd030036f0a2ace74d0bd2242cfdbcf726ef565d) reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER=clang make.cross ARCH=x86_64If you fix the issue, kindly add following tag
Reported-by kbuild test robot <[email protected]>All warnings (new ones prefixed by >>):
Quoted 2 lines
Quoted 2 lines
drivers/platform/chrome/cros_ec_sensorhub_ring.o: warning: objtool: __llvm_gcov_writeout()+0x14: call without frame pointer save/setupdrivers/platform/chrome/cros_ec_sensorhub_ring.o: warning: objtool: __llvm_gcov_flush()+0x0: call without frame pointer save/setupQuoted 8 lines
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe(a)googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/202003301529.ukpsA1aF%25lkp%40intel.com.--
Thanks,
~Nick Desaulniers
Signature · 2 lines
Thanks, ~Nick Desaulniers
PATCH v7 3/12 platform: chrome: sensorhub: Add code to spread timestmap
In reply to Gwendal GrignouEC FIFO can send sensor events in batch. Spread them based on previous (TSa) and currnet timestamp (TSb)
EC FIFO iio events
+-----------+ | TSa | +-----------+ +---------------------------------------+ | event 1 | | event 1 | TSb - (TSb - TSa)/n * (n-1) | +-----------+ +---------------------------------------+ | event 2 | | event 2 | TSb - (TSb - TSa)/n * (n-2) | +-----------+ +---------------------------------------+ | ... | ------> | .... | | +-----------+ +---------------------------------------+ | event n-1 | | event 2 | TSb - (TSb - TSa)/n | +-----------+ +---------------------------------------+ | event n | | event 2 | TSb | +-----------+ +---------------------------------------+ | TSb | +-----------+
---
Changes in v7:
- Use the number of sensors present to limit the scan of sensr mask. fifo_info is now a separate structure.
Changes in v6:
Comment fixes
Changes in v5:
Added ack.
Changes in v4:
- Check patch with --strict option
Alignement
No changes in v3.
Changes in v2:
- Use CROS_EC_SENSOR_LAST_TS instead of LAST_TS to avoid name colisions.
.../platform/chrome/cros_ec_sensorhub_ring.c | 117 ++++++++++++++++-- 1 file changed, 109 insertions(+), 8 deletions(-)
drivers/platform/chrome/cros_ec_sensorhub_ring.c +109 -8
@@ -190,6 +190,101 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,return true; } +/* +* cros_ec_sensor_ring_spread_add: Calculate proper timestamps then add to +* ringbuffer. +* +* If there is a sample with a proper timestamp +* +* timestamp | count +* ----------------- +* older_unprocess_out --> TS1 | 1 +* TS1 | 2 +* out --> TS1 | 3 +* next_out --> TS2 | +* +* We spread time for the samples [older_unprocess_out .. out] +* between TS1 and TS2: [TS1+1/4, TS1+2/4, TS1+3/4, TS2]. +* +* If we reach the end of the samples, we compare with the +* current timestamp: +* +* older_unprocess_out --> TS1 | 1 +* TS1 | 2 +* out --> TS1 | 3 +* +* We know have [TS1+1/3, TS1+2/3, current timestamp] +*/ +static void cros_ec_sensor_ring_spread_add (struct cros_ec_sensorhub *sensorhub, +unsigned long sensor_mask, +s64 current_timestamp, +struct cros_ec_sensors_ring_sample + *last_out) +{ +struct cros_ec_sensors_ring_sample *out; +int i; + +for_each_set_bit (i, &sensor_mask, sensorhub->sensor_num) { +s64 older_timestamp; +s64 timestamp; +struct cros_ec_sensors_ring_sample *older_unprocess_out = + sensorhub->ring; +struct cros_ec_sensors_ring_sample *next_out; +int count =1 ; + +for (out = sensorhub->ring; out < last_out; out = next_out) { +s64 time_period; + + next_out = out +1 ; +if (out->sensor_id != i) +continue ; + +/* Timestamp to start with */ + older_timestamp = out->timestamp; + +/* Find next sample. */ +while (next_out < last_out && next_out->sensor_id != i) + next_out++; + +if (next_out >= last_out) { + timestamp = current_timestamp; + }else { + timestamp = next_out->timestamp; +if (timestamp == older_timestamp) { + count++; +continue ; + } + } + +/* +* The next sample has a new timestamp, spread the +* unprocessed samples. +*/ +if (next_out < last_out) + count++; + time_period =div_s64 (timestamp - older_timestamp, + count); + +for (; older_unprocess_out <= out; + older_unprocess_out++) { +if (older_unprocess_out->sensor_id != i) +continue ; + older_timestamp += time_period; + older_unprocess_out->timestamp = + older_timestamp; + } + count =1 ; +/* The next_out sample has a valid timestamp, skip. */ + next_out++; + older_unprocess_out = next_out; + } + } + +/* Push the event into the kfifo */ +for (out = sensorhub->ring; out < last_out; out++) +cros_sensorhub_send_sample (sensorhub, out); +} +/** * cros_ec_sensorhub_ring_handler() - The trigger handler function *
@@ -204,6 +299,7 @@ static void cros_ec_sensorhub_ring_handler(struct cros_ec_sensorhub *sensorhub)struct cros_ec_dev *ec = sensorhub->ec;ktime_t fifo_timestamp, current_timestamp;int i, j, number_data, ret; +unsigned long sensor_mask =0 ;struct ec_response_motion_sensor_data *in;struct cros_ec_sensors_ring_sample *out, *last_out;
@@ -289,8 +385,10 @@ static void cros_ec_sensorhub_ring_handler(struct cros_ec_sensorhub *sensorhub) sensorhub, fifo_info, fifo_timestamp, ¤t_timestamp, - in, out)) + in, out)) { + sensor_mask |=BIT (in->sensor_num); out++; + } } }mutex_unlock (&sensorhub->cmd_lock);
@@ -301,10 +399,10 @@ static void cros_ec_sensorhub_ring_handler(struct cros_ec_sensorhub *sensorhub) goto ring_handler_end;/* -* Check if current_timestamp is ahead of the last sample. -* Normally, the EC appends a timestamp after the last sample, but if -* the AP is slow to respond to the IRQ, the EC may have added new -* samples. Use the FIFO info timestamp as last timestamp then. +* Check if current_timestamp is ahead of the last sample. Normally, +* the EC appends a timestamp after the last sample, but if the AP +* is slow to respond to the IRQ, the EC may have added new samples. +* Use the FIFO info timestamp as last timestamp then. */ if ((last_out -1 )->timestamp == current_timestamp) current_timestamp = fifo_timestamp;
@@ -319,9 +417,12 @@ static void cros_ec_sensorhub_ring_handler(struct cros_ec_sensorhub *sensorhub) fifo_info->total_lost); } -/* Push the event into the FIFO. */ -for (out = sensorhub->ring; out < last_out; out++) -cros_sensorhub_send_sample (sensorhub, out); +/* +* Spread samples in case of batching, then add them to the +* ringbuffer. +*/ +cros_ec_sensor_ring_spread_add (sensorhub, sensor_mask, + current_timestamp, last_out); ring_handler_end: sensorhub->fifo_timestamp[CROS_EC_SENSOR_LAST_TS ] = current_timestamp;
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v7 4/12 platform: chrome: sensorhub: Add median filter
In reply to Gwendal GrignouEvents are timestamped in EC time space, their timestamps need to be converted in host time space.
The assumption is the time delta between when the interrupt is sent by the EC and when it is receive by the host is a [small] constant. This is not always true, even with hard-wired interrupt. To mitigate worst offenders, add a median filter to weed out bigger than expected delays.
---
Changes in v7:
- Use the number of sensors present to create the right number of per sensor batch information.
Changes in v6:
- No changes.
Changes in v5:
- Enforce kernel-doc function naming.
- Added ack.
- Fix spelling
- Add ratelimiting for an error message.
- Remove unrelated code changes (line, kernel-doc) Changes in v4:
- Keep defining cros_ec_sensorhub in kernel-doc format
- Check patch with --strict option
Use BIT()
Add spaces around '-'
Alignement
Changes in v3:
- Fix doxygen code.
Changes in v2:
- Move some #define in .c to prevent name collisions.
- Add proper doxygen comments.
- Use /* instead of //
.../platform/chrome/cros_ec_sensorhub_ring.c | 560 +++++++++++++++++- .../linux/platform_data/cros_ec_sensorhub.h | 93 ++- 2 files changed, 622 insertions(+), 31 deletions(-)
drivers/platform/chrome/cros_ec_sensorhub_ring.c +533 -27
@@ -17,6 +17,21 @@#include <linux/sort.h> #include <linux/slab.h> +/* Precision of fixed point for the m values from the filter */ +#define M_PRECISION BIT(23) + +/* Only activate the filter once we have at least this many elements. */ +#define TS_HISTORY_THRESHOLD 8 + +/* +* If we don't have any history entries for this long, empty the filter to +* make sure there are no big discontinuities. +*/ +#define TS_HISTORY_BORED_US 500000 + +/* To measure by how much the filter is overshooting, if it happens. */ +#define FUTURE_TS_ANALYTICS_COUNT_MAX 100 +static inline int cros_sensorhub_send_sample (struct cros_ec_sensorhub *sensorhub,struct cros_ec_sensors_ring_sample *sample)
@@ -92,9 +107,13 @@ EXPORT_SYMBOL_GPL(cros_ec_sensorhub_unregister_push_data);int cros_ec_sensorhub_ring_fifo_enable (struct cros_ec_sensorhub *sensorhub,bool on) { -int ret; +int ret, i;mutex_lock (&sensorhub->cmd_lock); +if (sensorhub->tight_timestamps) +for (i =0 ; i < sensorhub->sensor_num; i++) + sensorhub->batch_state[i].last_len =0 ; + sensorhub->params->cmd =MOTIONSENSE_CMD_FIFO_INT_ENABLE ; sensorhub->params->fifo_int_enable.enable = on;
@@ -111,8 +130,245 @@ int cros_ec_sensorhub_ring_fifo_enable(struct cros_ec_sensorhub *sensorhub,return ret; } +static int cros_ec_sensor_ring_median_cmp (const void *pv1,const void *pv2) +{ +s64 v1 = *(s64 *)pv1; +s64 v2 = *(s64 *)pv2; + +if (v1 > v2) +return 1 ; +else if (v1 < v2) +return -1 ; +else +return 0 ; +} + +/* +* cros_ec_sensor_ring_median: Gets median of an array of numbers +* +* For now it's implemented using an inefficient > O(n) sort then return +* the middle element. A more optimal method would be something like +* quickselect, but given that n = 64 we can probably live with it in the +* name of clarity. +* +* Warning: the input array gets modified (sorted)! +*/ +static s64 cros_ec_sensor_ring_median (s64 *array,size_t length) +{ +sort (array, length,sizeof (s64), cros_ec_sensor_ring_median_cmp,NULL ); +return array[length /2 ]; +} + +/* +* IRQ Timestamp Filtering +* +* Lower down in cros_ec_sensor_ring_process_event(), for each sensor event +* we have to calculate it's timestamp in the AP timebase. There are 3 time +* points: +* a - EC timebase, sensor event +* b - EC timebase, IRQ +* c - AP timebase, IRQ +* a' - what we want: sensor even in AP timebase +* +* While a and b are recorded at accurate times (due to the EC real time +* nature); c is pretty untrustworthy, even though it's recorded the +* first thing in ec_irq_handler(). There is a very good change we'll get +* added lantency due to: +* other irqs +* ddrfreq +* cpuidle +* +* Normally a' = c - b + a, but if we do that naive math any jitter in c +* will get coupled in a', which we don't want. We want a function +* a' = cros_ec_sensor_ring_ts_filter(a) which will filter out outliers in c. +* +* Think of a graph of AP time(b) on the y axis vs EC time(c) on the x axis. +* The slope of the line won't be exactly 1, there will be some clock drift +* between the 2 chips for various reasons (mechanical stress, temperature, +* voltage). We need to extrapolate values for a future x, without trusting +* recent y values too much. +* +* We use a median filter for the slope, then another median filter for the +* y-intercept to calculate this function: +* dx[n] = x[n-1] - x[n] +* dy[n] = x[n-1] - x[n] +* m[n] = dy[n] / dx[n] +* median_m = median(m[n-k:n]) +* error[i] = y[n-i] - median_m * x[n-i] +* median_error = median(error[:k]) +* predicted_y = median_m * x + median_error +* +* Implementation differences from above: +* - Redefined y to be actually c - b, this gives us a lot more precision +* to do the math. (c-b)/b variations are more obvious than c/b variations. +* - Since we don't have floating point, any operations involving slope are +* done using fixed point math (*M_PRECISION) +* - Since x and y grow with time, we keep zeroing the graph (relative to +* the last sample), this way math involving *x[n-i] will not overflow +* - EC timestamps are kept in us, it improves the slope calculation precision +*/ + +/** +* cros_ec_sensor_ring_ts_filter_update() - Update filter history. +* +* @state: Filter information. +* @b: IRQ timestamp, EC timebase (us) +* @c: IRQ timestamp, AP timebase (ns) +* +* Given a new IRQ timestamp pair (EC and AP timebases), add it to the filter +* history. +*/ +static void +cros_ec_sensor_ring_ts_filter_update (struct cros_ec_sensors_ts_filter_state + *state, +s64 b,s64 c) +{ +s64 x, y; +s64 dx, dy; +s64 m;/* stored as *M_PRECISION */ +s64 *m_history_copy = state->temp_buf; +s64 *error = state->temp_buf; +int i; + +/* we trust b the most, that'll be our independent variable */ + x = b; +/* y is the offset between AP and EC times, in ns */ + y = c - b *1000 ; + + dx = (state->x_history[0 ] + state->x_offset) - x; +if (dx ==0 ) +return ;/* we already have this irq in the history */ + dy = (state->y_history[0 ] + state->y_offset) - y; + m =div64_s64 (dy *M_PRECISION , dx); + +/* Empty filter if we haven't seen any action in a while. */ +if (-dx >TS_HISTORY_BORED_US ) + state->history_len =0 ; + +/* Move everything over, also update offset to all absolute coords .*/ +for (i = state->history_len -1 ; i >=1 ; i--) { + state->x_history[i] = state->x_history[i -1 ] + dx; + state->y_history[i] = state->y_history[i -1 ] + dy; + + state->m_history[i] = state->m_history[i -1 ]; +/* +* Also use the same loop to copy m_history for future +* median extraction. +*/ + m_history_copy[i] = state->m_history[i -1 ]; + } + +/* Store the x and y, but remember offset is actually last sample. */ + state->x_offset = x; + state->y_offset = y; + state->x_history[0 ] =0 ; + state->y_history[0 ] =0 ; + + state->m_history[0 ] = m; + m_history_copy[0 ] = m; + +if (state->history_len <CROS_EC_SENSORHUB_TS_HISTORY_SIZE ) + state->history_len++; + +/* Precalculate things for the filter. */ +if (state->history_len >TS_HISTORY_THRESHOLD ) { + state->median_m = +cros_ec_sensor_ring_median (m_history_copy, + state->history_len -1 ); + +/* +* Calculate y-intercepts as if m_median is the slope and +* points in the history are on the line. median_error will +* still be in the offset coordinate system. +*/ +for (i =0 ; i < state->history_len; i++) + error[i] = state->y_history[i] - +div_s64 (state->median_m * state->x_history[i], +M_PRECISION ); + state->median_error = +cros_ec_sensor_ring_median (error, state->history_len); + }else { + state->median_m =0 ; + state->median_error =0 ; + } +} + +/** +* cros_ec_sensor_ring_ts_filter() - Translate EC timebase timestamp to AP +* timebase +* +* @state: filter information. +* @x: any ec timestamp (us): +* +* cros_ec_sensor_ring_ts_filter(a) => a' event timestamp, AP timebase +* cros_ec_sensor_ring_ts_filter(b) => calculated timestamp when the EC IRQ +* should have happened on the AP, with low jitter +* +* Note: The filter will only activate once state->history_len goes +* over TS_HISTORY_THRESHOLD. Otherwise it'll just do the naive c - b + a +* transform. +* +* How to derive the formula, starting from: +* f(x) = median_m * x + median_error +* That's the calculated AP - EC offset (at the x point in time) +* Undo the coordinate system transform: +* f(x) = median_m * (x - x_offset) + median_error + y_offset +* Remember to undo the "y = c - b * 1000" modification: +* f(x) = median_m * (x - x_offset) + median_error + y_offset + x * 1000 +* +* Return: timestamp in AP timebase (ns) +*/ +static s64 +cros_ec_sensor_ring_ts_filter (struct cros_ec_sensors_ts_filter_state *state, +s64 x) +{ +return div_s64 (state->median_m * (x - state->x_offset),M_PRECISION ) + + state->median_error + state->y_offset + x *1000 ; +} + +/* +* Since a and b were originally 32 bit values from the EC, +* they overflow relatively often, casting is not enough, so we need to +* add an offset. +*/ +static void +cros_ec_sensor_ring_fix_overflow (s64 *ts, +const s64 overflow_period, +struct cros_ec_sensors_ec_overflow_state + *state) +{ +s64 adjust; + + *ts += state->offset; +if (abs (state->last - *ts) > (overflow_period /2 )) { + adjust = state->last > *ts ? overflow_period : -overflow_period; + state->offset += adjust; + *ts += adjust; + } + state->last = *ts; +} + +static void +cros_ec_sensor_ring_check_for_past_timestamp (struct cros_ec_sensorhub + *sensorhub, +struct cros_ec_sensors_ring_sample + *sample) +{ +const u8 sensor_id = sample->sensor_id; + +/* If this event is earlier than one we saw before... */ +if (sensorhub->batch_state[sensor_id].newest_sensor_event > + sample->timestamp) +/* mark it for spreading. */ + sample->timestamp = + sensorhub->batch_state[sensor_id].last_ts; +else + sensorhub->batch_state[sensor_id].newest_sensor_event = + sample->timestamp; +} +/** -* cros_ec_sensor_ring_process_event() - process one EC FIFO event +* cros_ec_sensor_ring_process_event() - Process one EC FIFO event * * @sensorhub: Sensor Hub object. * @fifo_info: FIFO information from the EC (includes b point, EC timebase).
@@ -142,28 +398,57 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub, (MOTIONSENSE_SENSOR_FLAG_ODR |MOTIONSENSE_SENSOR_FLAG_FLUSH );if (in->flags &MOTIONSENSE_SENSOR_FLAG_TIMESTAMP && !async_flags) { -s64 new_timestamp; +s64 a = in->timestamp; +s64 b = fifo_info->timestamp; +s64 c = fifo_timestamp; + +cros_ec_sensor_ring_fix_overflow (&a,1LL <<32 , + &sensorhub->overflow_a); +cros_ec_sensor_ring_fix_overflow (&b,1LL <<32 , + &sensorhub->overflow_b); + +if (sensorhub->tight_timestamps) { +cros_ec_sensor_ring_ts_filter_update ( + &sensorhub->filter, b, c); + *current_timestamp =cros_ec_sensor_ring_ts_filter ( + &sensorhub->filter, a); + }else { +s64 new_timestamp; -/* -* Disable filtering since we might add more jitter -* if b is in a random point in time. -*/ - new_timestamp = fifo_timestamp - - fifo_info->timestamp *1000 + - in->timestamp *1000 ; +/* +* Disable filtering since we might add more jitter +* if b is in a random point in time. +*/ + new_timestamp = fifo_timestamp - + fifo_info->timestamp *1000 + + in->timestamp *1000 ; +/* +* The timestamp can be stale if we had to use the fifo +* info timestamp. +*/ +if (new_timestamp - *current_timestamp >0 ) + *current_timestamp = new_timestamp; + } + } +if (in->flags &MOTIONSENSE_SENSOR_FLAG_ODR ) { +if (sensorhub->tight_timestamps) { + sensorhub->batch_state[in->sensor_num].last_len =0 ; + sensorhub->batch_state[in->sensor_num].penul_len =0 ; + }/* -* The timestamp can be stale if we had to use the fifo -* info timestamp. +* ODR change is only useful for the sensor_ring, it does not +* convey information to clients. */ -if (new_timestamp - *current_timestamp >0 ) - *current_timestamp = new_timestamp; +return false; }if (in->flags &MOTIONSENSE_SENSOR_FLAG_FLUSH ) { out->sensor_id = in->sensor_num; out->timestamp = *current_timestamp; out->flag = in->flags; +if (sensorhub->tight_timestamps) + sensorhub->batch_state[out->sensor_id].last_len =0 ;/* * No other payload information provided with * flush ack.
@@ -177,22 +462,221 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,/* Regular sample */ out->sensor_id = in->sensor_num; -if (*current_timestamp - now >0 ) -/* If the timestamp is in the future. */ +if (*current_timestamp - now >0 ) { +/* +* This fix is needed to overcome the timestamp filter putting +* events in the future. +*/ + sensorhub->future_timestamp_total_ns += + *current_timestamp - now; +if (++sensorhub->future_timestamp_count == +FUTURE_TS_ANALYTICS_COUNT_MAX ) { +s64 avg =div_s64 (sensorhub->future_timestamp_total_ns, + sensorhub->future_timestamp_count); +dev_warn_ratelimited (sensorhub->dev, +"100 timestamps in the future, %lldns shaved on average\n" , + avg); + sensorhub->future_timestamp_count =0 ; + sensorhub->future_timestamp_total_ns =0 ; + } out->timestamp = now; -else + }else { out->timestamp = *current_timestamp; + } out->flag = in->flags;for (axis =0 ; axis <3 ; axis++) out->vector[axis] = in->data[axis]; +if (sensorhub->tight_timestamps) +cros_ec_sensor_ring_check_for_past_timestamp (sensorhub, out);return true; }/* * cros_ec_sensor_ring_spread_add: Calculate proper timestamps then add to -* ringbuffer. +* ringbuffer. +* +* This is the new spreading code, assumes every sample's timestamp +* preceeds the sample. Run if tight_timestamps == true. +* +* Sometimes the EC receives only one interrupt (hence timestamp) for +* a batch of samples. Only the first sample will have the correct +* timestamp. So we must interpolate the other samples. +* We use the previous batch timestamp and our current batch timestamp +* as a way to calculate period, then spread the samples evenly. +* +* s0 int, 0ms +* s1 int, 10ms +* s2 int, 20ms +* 30ms point goes by, no interrupt, previous one is still asserted +* downloading s2 and s3 +* s3 sample, 20ms (incorrect timestamp) +* s4 int, 40ms +* +* The batches are [(s0), (s1), (s2, s3), (s4)]. Since the 3rd batch +* has 2 samples in them, we adjust the timestamp of s3. +* s2 - s1 = 10ms, so s3 must be s2 + 10ms => 20ms. If s1 would have +* been part of a bigger batch things would have gotten a little +* more complicated. +* +* Note: we also assume another sensor sample doesn't break up a batch +* in 2 or more partitions. Example, there can't ever be a sync sensor +* in between S2 and S3. This simplifies the following code. +*/ +static void +cros_ec_sensor_ring_spread_add (struct cros_ec_sensorhub *sensorhub, +unsigned long sensor_mask, +struct cros_ec_sensors_ring_sample *last_out) +{ +struct cros_ec_sensors_ring_sample *batch_start, *next_batch_start; +int id; + +for_each_set_bit (id, &sensor_mask, sensorhub->sensor_num) { +for (batch_start = sensorhub->ring; batch_start < last_out; + batch_start = next_batch_start) { +/* +* For each batch (where all samples have the same +* timestamp). +*/ +int batch_len, sample_idx; +struct cros_ec_sensors_ring_sample *batch_end = + batch_start; +struct cros_ec_sensors_ring_sample *s; +s64 batch_timestamp = batch_start->timestamp; +s64 sample_period; + +/* +* Skip over batches that start with the sensor types +* we're not looking at right now. +*/ +if (batch_start->sensor_id != id) { + next_batch_start = batch_start +1 ; +continue ; + } + +/* +* Do not start a batch +* from a flush, as it happens asynchronously to the +* regular flow of events. +*/ +if (batch_start->flag &MOTIONSENSE_SENSOR_FLAG_FLUSH ) { +cros_sensorhub_send_sample (sensorhub, + batch_start); + next_batch_start = batch_start +1 ; +continue ; + } + +if (batch_start->timestamp <= + sensorhub->batch_state[id].last_ts) { + batch_timestamp = + sensorhub->batch_state[id].last_ts; + batch_len = sensorhub->batch_state[id].last_len; + + sample_idx = batch_len; + + sensorhub->batch_state[id].last_ts = + sensorhub->batch_state[id].penul_ts; + sensorhub->batch_state[id].last_len = + sensorhub->batch_state[id].penul_len; + }else { +/* +* Push first sample in the batch to the, +* kifo, it's guaranteed to be correct, the +* rest will follow later on. +*/ + sample_idx =1 ; + batch_len =1 ; +cros_sensorhub_send_sample (sensorhub, + batch_start); + batch_start++; + } + +/* Find all samples have the same timestamp. */ +for (s = batch_start; s < last_out; s++) { +if (s->sensor_id != id) +/* +* Skip over other sensor types that +* are interleaved, don't count them. +*/ +continue ; +if (s->timestamp != batch_timestamp) +/* we discovered the next batch */ +break ; +if (s->flag &MOTIONSENSE_SENSOR_FLAG_FLUSH ) +/* break on flush packets */ +break ; + batch_end = s; + batch_len++; + } + +if (batch_len ==1 ) + goto done_with_this_batch; + +/* Can we calculate period? */ +if (sensorhub->batch_state[id].last_len ==0 ) { +dev_warn (sensorhub->dev,"Sensor %d: lost %d samples when spreading\n" , + id, batch_len -1 ); + goto done_with_this_batch; +/* +* Note: we're dropping the rest of the samples +* in this batch since we have no idea where +* they're supposed to go without a period +* calculation. +*/ + } + + sample_period =div_s64 (batch_timestamp - + sensorhub->batch_state[id].last_ts, + sensorhub->batch_state[id].last_len); +dev_dbg (sensorhub->dev, +"Adjusting %d samples, sensor %d last_batch @%lld (%d samples) batch_timestamp=%lld => period=%lld\n" , + batch_len, id, + sensorhub->batch_state[id].last_ts, + sensorhub->batch_state[id].last_len, + batch_timestamp, + sample_period); + +/* +* Adjust timestamps of the samples then push them to +* kfifo. +*/ +for (s = batch_start; s <= batch_end; s++) { +if (s->sensor_id != id) +/* +* Skip over other sensor types that +* are interleaved, don't change them. +*/ +continue ; + + s->timestamp = batch_timestamp + + sample_period * sample_idx; + sample_idx++; + +cros_sensorhub_send_sample (sensorhub, s); + } + +done_with_this_batch: + sensorhub->batch_state[id].penul_ts = + sensorhub->batch_state[id].last_ts; + sensorhub->batch_state[id].penul_len = + sensorhub->batch_state[id].last_len; + + sensorhub->batch_state[id].last_ts = + batch_timestamp; + sensorhub->batch_state[id].last_len = batch_len; + + next_batch_start = batch_end +1 ; + } + } +} + +/* +* cros_ec_sensor_ring_spread_add_legacy: Calculate proper timestamps then +* add to ringbuffer (legacy). +* +* Note: This assumes we're running old firmware, where every sample's timestamp +* is after the sample. Run if tight_timestamps == false. * * If there is a sample with a proper timestamp *
@@ -215,11 +699,12 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,* * We know have [TS1+1/3, TS1+2/3, current timestamp] */ -static void cros_ec_sensor_ring_spread_add (struct cros_ec_sensorhub *sensorhub, -unsigned long sensor_mask, -s64 current_timestamp, -struct cros_ec_sensors_ring_sample - *last_out) +static void +cros_ec_sensor_ring_spread_add_legacy (struct cros_ec_sensorhub *sensorhub, +unsigned long sensor_mask, +s64 current_timestamp, +struct cros_ec_sensors_ring_sample + *last_out) {struct cros_ec_sensors_ring_sample *out;int i;
@@ -404,25 +889,34 @@ static void cros_ec_sensorhub_ring_handler(struct cros_ec_sensorhub *sensorhub)* is slow to respond to the IRQ, the EC may have added new samples. * Use the FIFO info timestamp as last timestamp then. */ -if ((last_out -1 )->timestamp == current_timestamp) +if (!sensorhub->tight_timestamps && + (last_out -1 )->timestamp == current_timestamp) current_timestamp = fifo_timestamp;/* Warn on lost samples. */ if (fifo_info->total_lost)for (i =0 ; i < sensorhub->sensor_num; i++) { -if (fifo_info->lost[i]) +if (fifo_info->lost[i]) {dev_warn_ratelimited (sensorhub->dev,"Sensor %d: lost: %d out of %d\n" , i, fifo_info->lost[i], fifo_info->total_lost); +if (sensorhub->tight_timestamps) + sensorhub->batch_state[i].last_len =0 ; + } }/* * Spread samples in case of batching, then add them to the * ringbuffer. */ -cros_ec_sensor_ring_spread_add (sensorhub, sensor_mask, - current_timestamp, last_out); +if (sensorhub->tight_timestamps) +cros_ec_sensor_ring_spread_add (sensorhub, sensor_mask, + last_out); +else +cros_ec_sensor_ring_spread_add_legacy (sensorhub, sensor_mask, + current_timestamp, + last_out); ring_handler_end: sensorhub->fifo_timestamp[CROS_EC_SENSOR_LAST_TS ] = current_timestamp;
@@ -517,6 +1011,18 @@ int cros_ec_sensorhub_ring_add(struct cros_ec_sensorhub *sensorhub) sensorhub->fifo_timestamp[CROS_EC_SENSOR_LAST_TS ] =cros_ec_get_time_ns (); + sensorhub->tight_timestamps =cros_ec_check_features ( + ec,EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS ); + +if (sensorhub->tight_timestamps) { + sensorhub->batch_state =devm_kcalloc (sensorhub->dev, + sensorhub->sensor_num, +sizeof (*sensorhub->batch_state), +GFP_KERNEL ); +if (!sensorhub->batch_state) +return -ENOMEM ; + } +/* Register the notifier that will act as a top half interrupt. */ sensorhub->notifier.notifier_call = cros_ec_sensorhub_event; ret = blocking_notifier_chain_register(&ec->ec_dev->event_notifier,
include/linux/platform_data/cros_ec_sensorhub.h +89 -4
112 lines not on this page · raw message
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v7 5/12 iio: cros_ec: Move function description to .c file
In reply to Gwendal GrignouTo prevent comment rot, move function description to cros_ec_sensors_core.c.
---
No changes in v6 and v7.
Changes in v5:
Added ack.
No changes in v4.
Changes in v3:
fix spelling.
New in v2.
.../cros_ec_sensors/cros_ec_sensors_core.c | 69 ++++++++++++++++ .../linux/iio/common/cros_ec_sensors_core.h | 80 ------------------- 2 files changed, 69 insertions(+), 80 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +69 -0
@@ -82,6 +82,14 @@ static void get_default_min_max_freq(enum motionsensor_type type, } } +/** +* cros_ec_sensors_core_init() - basic initialization of the core structure +* @pdev: platform device created for the sensors +* @indio_dev: iio device structure of the device +* @physical_device: true if the device refers to a physical device +* +* Return: 0 on success, -errno on failure. +*/ int cros_ec_sensors_core_init (struct platform_device *pdev,struct iio_dev *indio_dev,bool physical_device)
@@ -159,6 +167,16 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, }EXPORT_SYMBOL_GPL (cros_ec_sensors_core_init); +/** +* cros_ec_motion_send_host_cmd() - send motion sense host command +* @state: pointer to state information for device +* @opt_length: optional length to reduce the response size, useful on the data +* path. Otherwise, the maximal allowed response size is used +* +* When called, the sub-command is assumed to be set in param->cmd. +* +* Return: 0 on success, -errno on failure. +*/ int cros_ec_motion_send_host_cmd (struct cros_ec_sensors_core_state *state,u16 opt_length) {
@@ -421,6 +439,14 @@ int cros_ec_sensors_read_lpc(struct iio_dev *indio_dev, }EXPORT_SYMBOL_GPL (cros_ec_sensors_read_lpc); +/** +* cros_ec_sensors_read_cmd() - retrieve data using the EC command protocol +* @indio_dev: pointer to IIO device +* @scan_mask: bitmap of the sensor indices to scan +* @data: location to store data +* +* Return: 0 on success, -errno on failure. +*/ int cros_ec_sensors_read_cmd (struct iio_dev *indio_dev,unsigned long scan_mask,s16 *data) {
@@ -445,6 +471,18 @@ int cros_ec_sensors_read_cmd(struct iio_dev *indio_dev, }EXPORT_SYMBOL_GPL (cros_ec_sensors_read_cmd); +/** +* cros_ec_sensors_capture() - the trigger handler function +* @irq: the interrupt number. +* @p: a pointer to the poll function. +* +* On a trigger event occurring, if the pollfunc is attached then this +* handler is called as a threaded interrupt (and hence may sleep). It +* is responsible for grabbing data from the device and pushing it into +* the associated buffer. +* +* Return: IRQ_HANDLED +*/ irqreturn_t cros_ec_sensors_capture (int irq,void *p) {struct iio_poll_func *pf = p;
@@ -480,6 +518,16 @@ irqreturn_t cros_ec_sensors_capture(int irq, void *p) }EXPORT_SYMBOL_GPL (cros_ec_sensors_capture); +/** +* cros_ec_sensors_core_read() - function to request a value from the sensor +* @st: pointer to state information for device +* @chan: channel specification structure table +* @val: will contain one element making up the returned value +* @val2: will contain another element making up the returned value +* @mask: specifies which values to be requested +* +* Return: the type of value returned by the device +*/ 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)
@@ -520,6 +568,17 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st, }EXPORT_SYMBOL_GPL (cros_ec_sensors_core_read); +/** +* 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,
@@ -541,6 +600,16 @@ int cros_ec_sensors_core_read_avail(struct iio_dev *indio_dev, }EXPORT_SYMBOL_GPL (cros_ec_sensors_core_read_avail); +/** +* cros_ec_sensors_core_write() - function to write a value to the sensor +* @st: pointer to state information for device +* @chan: channel specification structure table +* @val: first part of value to write +* @val2: second part of value to write +* @mask: specifies which values to write +* +* Return: the type of value returned by the device +*/ 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)
include/linux/iio/common/cros_ec_sensors_core.h +0 -80
111 lines not on this page · raw message
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v7 6/12 iio: expose iio_device_set_clock
In reply to Gwendal GrignouSome IIO devices may want to override the default (realtime) to another clock source by default.
It can beneficial when timestamps coming from the hardware or underlying drivers are already in that format.
It can always be overridden by attribute current_timestamp_clock.
---
No changes in v6 and v7.
Changes in v5:
- New in v5.
drivers/iio/industrialio-core.c | 8 +++++++- include/linux/iio/iio.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/iio/industrialio-core.c +7 -1
@@ -189,7 +189,12 @@ ssize_t iio_read_const_attr(struct device *dev, }EXPORT_SYMBOL (iio_read_const_attr); -static int iio_device_set_clock (struct iio_dev *indio_dev,clockid_t clock_id) +/** +* iio_device_set_clock() - Set current timestamping clock for the device +* @indio_dev: IIO device structure containing the device +* @clock_id: timestamping clock posix identifier to set. +*/ +int iio_device_set_clock (struct iio_dev *indio_dev,clockid_t clock_id) {int ret;const struct iio_event_interface *ev_int = indio_dev->event_interface;
@@ -207,6 +212,7 @@ static int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)return 0 ; } +EXPORT_SYMBOL (iio_device_set_clock);/** * iio_get_time_ns() - utility function to get a time stamp for events etc
include/linux/iio/iio.h +2 -0
@@ -627,6 +627,8 @@ static inline clockid_t iio_device_get_clock(const struct iio_dev *indio_dev)return indio_dev->clock_id; } +int iio_device_set_clock (struct iio_dev *indio_dev,clockid_t clock_id); +/** * dev_to_iio_dev() - Get IIO device struct from a device struct * @dev: The device embedded in the IIO device
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v7 7/12 iio: cros_ec: Register to cros_ec_sensorhub when EC supports FIFO
In reply to Gwendal GrignouWhen EC supports FIFO, each IIO device registers a callback, to put samples in the buffer when they arrives from the FIFO.
When no FIFO, the user space app needs to call trigger_new, or better register a high precision timer.
---
No changes in v7
Changes in v6:
- Revert code from v2 that allow trigger in FIFO mode. It was causing a crash when events would flow from hardware FIFO in but no triggers were setup.
Creating a triggered buffers and a hardware interrupt trigger from the sensorhub and having to connect the trigger to sensor before use was not practical.
Changes in v5:
- Revert modes setting that were removed by mistake
- Remove unnecessary check when receving events from callback
- Set clock_id to boottime by default, as it is what sensorhub_ring is using.
- Update commit messages reference to time domain: trigger and hub generated events are always in the same time domain.
Changes in v4:
- Fix a logic error when the sensor is not "physical", for instance lig
angle: core_init() would return !0 even if there was no error.
- Check patch with --strict option
Use sizeof(*obj) instead of sizeof(struct ...obj) Alignement
Change in v3:
- Remove double line
- Fix indentation
- Add code to support iio clock_id setting. Optimized for CLOCK_BOOTTIME.
Change in v2 from "Use triggered buffer only when EC does not support FIFO":
- Keep trigger all the time.
- Add devm_add_action to cleanup callback registration.
- EC that "reports" legacy sensors do not have FIFO.
- Use iiio_is_buffer_enabled instead of checking the scan_mask before sending samples to buffer.
- Add empty lines for visibility.
drivers/iio/accel/cros_ec_accel_legacy.c | 8 +- .../cros_ec_sensors/cros_ec_lid_angle.c | 2 +- .../common/cros_ec_sensors/cros_ec_sensors.c | 9 +- .../cros_ec_sensors/cros_ec_sensors_core.c | 101 +++++++++++++++++- drivers/iio/light/cros_ec_light_prox.c | 9 +- drivers/iio/pressure/cros_ec_baro.c | 9 +- .../linux/iio/common/cros_ec_sensors_core.h | 10 +- 7 files changed, 119 insertions(+), 29 deletions(-)
drivers/iio/accel/cros_ec_accel_legacy.c +2 -6
@@ -170,7 +170,8 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)if (!indio_dev)return -ENOMEM ; - ret =cros_ec_sensors_core_init (pdev, indio_dev, true); + ret =cros_ec_sensors_core_init (pdev, indio_dev, true, + cros_ec_sensors_capture,NULL );if (ret)return ret;
@@ -190,11 +191,6 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev) state->sign[CROS_EC_SENSOR_Z ] =-1 ; } - ret =devm_iio_triggered_buffer_setup (dev, indio_dev,NULL , - cros_ec_sensors_capture,NULL ); -if (ret) -return ret; -return devm_iio_device_register (dev, indio_dev); }
drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c +1 -1
@@ -97,7 +97,7 @@ static int cros_ec_lid_angle_probe(struct platform_device *pdev)if (!indio_dev)return -ENOMEM ; - ret =cros_ec_sensors_core_init (pdev, indio_dev, false); + ret =cros_ec_sensors_core_init (pdev, indio_dev, false,NULL ,NULL );if (ret)return ret;
drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +3 -6
@@ -230,7 +230,9 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)if (!indio_dev)return -ENOMEM ; - ret =cros_ec_sensors_core_init (pdev, indio_dev, true); + ret =cros_ec_sensors_core_init (pdev, indio_dev, true, + cros_ec_sensors_capture, + cros_ec_sensors_push_data);if (ret)return ret;
@@ -292,11 +294,6 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)else state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd; - ret =devm_iio_triggered_buffer_setup (dev, indio_dev,NULL , - cros_ec_sensors_capture,NULL ); -if (ret) -return ret; -return devm_iio_device_register (dev, indio_dev); }
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +98 -3
135 lines not on this page · raw message
drivers/iio/light/cros_ec_light_prox.c +3 -6
@@ -177,7 +177,9 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev)if (!indio_dev)return -ENOMEM ; - ret =cros_ec_sensors_core_init (pdev, indio_dev, true); + ret =cros_ec_sensors_core_init (pdev, indio_dev, true, + cros_ec_sensors_capture, + cros_ec_sensors_push_data);if (ret)return ret;
@@ -236,11 +238,6 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev) state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd; - ret =devm_iio_triggered_buffer_setup (dev, indio_dev,NULL , - cros_ec_sensors_capture,NULL ); -if (ret) -return ret; -return devm_iio_device_register (dev, indio_dev); }
drivers/iio/pressure/cros_ec_baro.c +3 -6
@@ -134,7 +134,9 @@ static int cros_ec_baro_probe(struct platform_device *pdev)if (!indio_dev)return -ENOMEM ; - ret =cros_ec_sensors_core_init (pdev, indio_dev, true); + ret =cros_ec_sensors_core_init (pdev, indio_dev, true, + cros_ec_sensors_capture, + cros_ec_sensors_push_data);if (ret)return ret;
@@ -182,11 +184,6 @@ static int cros_ec_baro_probe(struct platform_device *pdev) state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd; - ret =devm_iio_triggered_buffer_setup (dev, indio_dev,NULL , - cros_ec_sensors_capture,NULL ); -if (ret) -return ret; -return devm_iio_device_register (dev, indio_dev); }
include/linux/iio/common/cros_ec_sensors_core.h +9 -1
@@ -12,6 +12,7 @@#include <linux/irqreturn.h> #include <linux/platform_data/cros_ec_commands.h> #include <linux/platform_data/cros_ec_proto.h> +#include <linux/platform_data/cros_ec_sensorhub.h> enum {CROS_EC_SENSOR_X ,
@@ -32,6 +33,8 @@ enum {/* Minimum sampling period to use when device is suspending */ #define CROS_EC_MIN_SUSPEND_SAMPLING_FREQUENCY 1000/* 1 second */ +typedef irqreturn_t (*cros_ec_sensors_capture_t )(int irq,void *p); +/** * struct cros_ec_sensors_core_state - state data for EC sensors IIO driver * @ec: cros EC device structure
@@ -87,9 +90,14 @@ int cros_ec_sensors_read_cmd(struct iio_dev *indio_dev, unsigned long scan_mask,struct platform_device ;int cros_ec_sensors_core_init (struct platform_device *pdev, -struct iio_dev *indio_dev,bool physical_device); +struct iio_dev *indio_dev,bool physical_device, +cros_ec_sensors_capture_t trigger_capture, +cros_ec_sensorhub_push_data_cb_t push_data);irqreturn_t cros_ec_sensors_capture (int irq,void *p); +int cros_ec_sensors_push_data (struct iio_dev *indio_dev, +s16 *data, +s64 timestamp);int cros_ec_motion_send_host_cmd (struct cros_ec_sensors_core_state *st,u16 opt_length);
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v7 8/12 iio: cros_ec: Remove pm function
In reply to Gwendal GrignouSince cros_ec_sensorhub is shutting down the FIFO when the device suspends, no need to slow down the EC sampling period rate. It was necesseary to do that before command CMD_FIFO_INT_ENABLE was introduced, but now all supported chromebooks have it.
---
No changes in v6 and v7.
Changes in v5:
Added ack.
No changes in v4, v3.
New in v2.
.../cros_ec_sensors/cros_ec_lid_angle.c | 1 - .../common/cros_ec_sensors/cros_ec_sensors.c | 1 - .../cros_ec_sensors/cros_ec_sensors_core.c | 47 ------------------- drivers/iio/light/cros_ec_light_prox.c | 1 - .../linux/iio/common/cros_ec_sensors_core.h | 5 -- 5 files changed, 55 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c +0 -1
@@ -127,7 +127,6 @@ MODULE_DEVICE_TABLE(platform, cros_ec_lid_angle_ids);static struct platform_driver cros_ec_lid_angle_platform_driver = { .driver = { .name =DRV_NAME , - .pm = &cros_ec_sensors_pm_ops, }, .probe = cros_ec_lid_angle_probe, .id_table = cros_ec_lid_angle_ids,
drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +0 -1
@@ -314,7 +314,6 @@ MODULE_DEVICE_TABLE(platform, cros_ec_sensors_ids);static struct platform_driver cros_ec_sensors_platform_driver = { .driver = { .name ="cros-ec-sensors" , - .pm = &cros_ec_sensors_pm_ops, }, .probe = cros_ec_sensors_probe, .id_table = cros_ec_sensors_ids,
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +0 -47
52 lines not on this page · raw message
drivers/iio/light/cros_ec_light_prox.c +0 -1
@@ -255,7 +255,6 @@ MODULE_DEVICE_TABLE(platform, cros_ec_light_prox_ids);static struct platform_driver cros_ec_light_prox_platform_driver = { .driver = { .name ="cros-ec-light-prox" , - .pm = &cros_ec_sensors_pm_ops, }, .probe = cros_ec_light_prox_probe, .id_table = cros_ec_light_prox_ids,
include/linux/iio/common/cros_ec_sensors_core.h +0 -5
@@ -30,9 +30,6 @@ enum {*/ #define CROS_EC_SAMPLE_SIZE (sizeof(s64) * 2) -/* Minimum sampling period to use when device is suspending */ -#define CROS_EC_MIN_SUSPEND_SAMPLING_FREQUENCY 1000/* 1 second */ -typedef irqreturn_t (*cros_ec_sensors_capture_t )(int irq,void *p);/**
@@ -117,8 +114,6 @@ 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); -extern const struct dev_pm_ops cros_ec_sensors_pm_ops; -/* List of extended channel specification for all sensors */ extern const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[];
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v7 9/12 iio: cros_ec: Expose hwfifo_timeout
In reply to Gwendal GrignouExpose EC minimal interrupt period through buffer/hwfifo_timeout:
- Maximal timeout is limited to 65s.
- When timeout for all sensors is set to 0, EC will not send events, even if the sensor sampling rate is greater than 0.
Rename frequency to sampling_frequency to match IIO ABI.
---
No changes in v6 and v7.
Changes in v5:
Added ack.
Changes in v4:
- Check patch with --strict option
Alignement
No changes in v3.
Changes in v2:
- Register fifo_attributes in sensors drivers that previously advertise that feature.
.../common/cros_ec_sensors/cros_ec_sensors.c | 3 +- .../cros_ec_sensors/cros_ec_sensors_core.c | 95 ++++++++++++++----- drivers/iio/light/cros_ec_light_prox.c | 5 +- drivers/iio/pressure/cros_ec_baro.c | 5 +- .../linux/iio/common/cros_ec_sensors_core.h | 4 +- 5 files changed, 82 insertions(+), 30 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +2 -1
@@ -236,6 +236,8 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)if (ret)return ret; +iio_buffer_set_attrs (indio_dev->buffer, cros_ec_sensor_fifo_attributes); + indio_dev->info = &ec_sensors_info; state =iio_priv (indio_dev); for (channel = state->channels, i = CROS_EC_SENSOR_X;
@@ -247,7 +249,6 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)BIT (IIO_CHAN_INFO_CALIBSCALE ); channel->info_mask_shared_by_all =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 );
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +73 -22
125 lines not on this page · raw message
drivers/iio/light/cros_ec_light_prox.c +3 -2
@@ -183,6 +183,8 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev)if (ret)return ret; +iio_buffer_set_attrs (indio_dev->buffer, cros_ec_sensor_fifo_attributes); + indio_dev->info = &cros_ec_light_prox_info; state =iio_priv (indio_dev); state->core.type = state->core.resp->info.type;
@@ -191,8 +193,7 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev)/* Common part */ channel->info_mask_shared_by_all = -BIT (IIO_CHAN_INFO_SAMP_FREQ ) | -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 ;
drivers/iio/pressure/cros_ec_baro.c +3 -2
@@ -140,6 +140,8 @@ static int cros_ec_baro_probe(struct platform_device *pdev)if (ret)return ret; +iio_buffer_set_attrs (indio_dev->buffer, cros_ec_sensor_fifo_attributes); + indio_dev->info = &cros_ec_baro_info; state =iio_priv (indio_dev); state->core.type = state->core.resp->info.type;
@@ -149,8 +151,7 @@ static int cros_ec_baro_probe(struct platform_device *pdev) channel->info_mask_separate =BIT (IIO_CHAN_INFO_RAW ); channel->info_mask_shared_by_all =BIT (IIO_CHAN_INFO_SCALE ) | -BIT (IIO_CHAN_INFO_SAMP_FREQ ) | -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 ;
include/linux/iio/common/cros_ec_sensors_core.h +1 -3
@@ -50,7 +50,6 @@ typedef irqreturn_t (*cros_ec_sensors_capture_t)(int irq, void *p);* the timestamp. The timestamp is always last and * is always 8-byte aligned. * @read_ec_sensors_data: function used for accessing sensors values -* @cuur_sampl_freq: current sampling period */ struct cros_ec_sensors_core_state {struct cros_ec_device *ec;
@@ -73,8 +72,6 @@ struct cros_ec_sensors_core_state {int (*read_ec_sensors_data)(struct iio_dev *indio_dev,unsigned long scan_mask,s16 *data); -int curr_sampl_freq; -/* Table of known available frequencies : 0, Min and Max in mHz */ int frequencies[3 ]; };
@@ -116,5 +113,6 @@ int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st,/* List of extended channel specification for all sensors */ extern const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[]; +extern const struct attribute *cros_ec_sensor_fifo_attributes[];#endif /* __CROS_EC_SENSORS_CORE_H */
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v7 10/12 iio: cros_ec: Report hwfifo_watermark_max
In reply to Gwendal GrignouReport the maximum amount of sample the EC can hold.
This is not tunable, but can be useful for application to find out the maximum amount of time it can sleep when hwfifo_timeout is set to a large number.
---
No changes in v6 and v7.
Changes in v5:
Added ack.
Changes in v4:
- Check patch with --strict option
Alignement
No changes in v3.
Changes in v2:
- Remove double lines, add line before return for visibility.
.../cros_ec_sensors/cros_ec_sensors_core.c | 33 +++++++++++++++++-- .../linux/iio/common/cros_ec_sensors_core.h | 3 ++ 2 files changed, 34 insertions(+), 2 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +31 -2
@@ -22,6 +22,12 @@#include <linux/platform_data/cros_ec_sensorhub.h> #include <linux/platform_device.h> +/* +* Hard coded to the first device to support sensor fifo. The EC has a 2048 +* byte fifo and will trigger an interrupt when fifo is 2/3 full. +*/ +#define CROS_EC_FIFO_SIZE (2048 * 2 / 3) +static char *cros_ec_loc[] = { [MOTIONSENSE_LOC_BASE ] ="base" , [MOTIONSENSE_LOC_LID ] ="lid" ,
@@ -55,8 +61,15 @@ static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev,static void get_default_min_max_freq (enum motionsensor_type type,u32 *min_freq, -u32 *max_freq) +u32 *max_freq, +u32 *max_fifo_events) { +/* +* We don't know fifo size, set to size previously used by older +* hardware. +*/ + *max_fifo_events =CROS_EC_FIFO_SIZE ; +switch (type) {case MOTIONSENSE_TYPE_ACCEL :case MOTIONSENSE_TYPE_GYRO :
@@ -149,8 +162,21 @@ static IIO_DEVICE_ATTR(hwfifo_timeout, 0644, cros_ec_sensor_get_report_latency, cros_ec_sensor_set_report_latency, 0); +static ssize_t hwfifo_watermark_max_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); + +return sprintf (buf,"%d\n" , st->fifo_max_event_count); +} + +static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0); +const struct attribute *cros_ec_sensor_fifo_attributes[] = { &iio_dev_attr_hwfifo_timeout.dev_attr.attr, + &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,NULL , };EXPORT_SYMBOL_GPL (cros_ec_sensor_fifo_attributes);
@@ -279,12 +305,15 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,if (state->msg->version <3 ) {get_default_min_max_freq (state->resp->info.type, &state->frequencies[1 ], - &state->frequencies[2 ]); + &state->frequencies[2 ], + &state->fifo_max_event_count); }else { state->frequencies[1 ] = state->resp->info_3.min_frequency; state->frequencies[2 ] = state->resp->info_3.max_frequency; + state->fifo_max_event_count = + state->resp->info_3.fifo_max_event_count; }if (cros_ec_check_features (ec,EC_FEATURE_MOTION_SENSE_FIFO )) {
include/linux/iio/common/cros_ec_sensors_core.h +3 -0
@@ -50,6 +50,7 @@ typedef irqreturn_t (*cros_ec_sensors_capture_t)(int irq, void *p);* the timestamp. The timestamp is always last and * is always 8-byte aligned. * @read_ec_sensors_data: function used for accessing sensors values +* @fifo_max_event_count: Size of the EC sensor FIFO */ struct cros_ec_sensors_core_state {struct cros_ec_device *ec;
@@ -72,6 +73,8 @@ struct cros_ec_sensors_core_state {int (*read_ec_sensors_data)(struct iio_dev *indio_dev,unsigned long scan_mask,s16 *data); +u32 fifo_max_event_count; +/* Table of known available frequencies : 0, Min and Max in mHz */ int frequencies[3 ]; };
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v7 11/12 iio: cros_ec: Use Hertz as unit for sampling frequency
In reply to Gwendal GrignouTo be compliant with other sensors, set and get sensor sampling frequency in Hz, not mHz.
cros_ec_sensors frequency range via iio sysfs")
---
No changes in v6 and v7.
Changes in v5:
Added ack.
Changes in v4:
- Check patch with --strict option
Alignement
No changes in v3.
No changes in v2.
.../cros_ec_sensors/cros_ec_sensors_core.c | 32 +++++++++++-------- .../linux/iio/common/cros_ec_sensors_core.h | 6 ++-- 2 files changed, 22 insertions(+), 16 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +19 -13
@@ -253,6 +253,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,struct cros_ec_dev *ec = sensor_hub->ec;struct cros_ec_sensor_platform *sensor_platform =dev_get_platdata (dev);u32 ver_mask; +int frequencies[ARRAY_SIZE (state->frequencies) /2 ] = {0 };int ret, i;platform_set_drvdata (pdev, indio_dev);
@@ -301,20 +302,22 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, state->calib[i].scale =MOTION_SENSE_DEFAULT_SCALE ;/* 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 ], + &frequencies[1 ], + &frequencies[2 ], &state->fifo_max_event_count); }else { - state->frequencies[1 ] = - state->resp->info_3.min_frequency; - state->frequencies[2 ] = - state->resp->info_3.max_frequency; + frequencies[1 ] = state->resp->info_3.min_frequency; + frequencies[2 ] = state->resp->info_3.max_frequency; state->fifo_max_event_count = state->resp->info_3.fifo_max_event_count; } +for (i =0 ; i <ARRAY_SIZE (frequencies); i++) { + state->frequencies[2 * i] = frequencies[i] /1000 ; + state->frequencies[2 * i +1 ] = + (frequencies[i] %1000 ) *1000 ; + }if (cros_ec_check_features (ec,EC_FEATURE_MOTION_SENSE_FIFO )) {/*
@@ -728,7 +731,7 @@ 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) { - int ret; + int ret, frequency;switch (mask) {case IIO_CHAN_INFO_SAMP_FREQ :
@@ -740,8 +743,10 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st,if (ret)break ; - *val = st->resp->sensor_odr.ret; - ret =IIO_VAL_INT ; + frequency = st->resp->sensor_odr.ret; + *val = frequency /1000 ; + *val2 = (frequency %1000 ) *1000 ; + ret =IIO_VAL_INT_PLUS_MICRO ;break ;default : ret = -EINVAL ;
@@ -776,7 +781,7 @@ int cros_ec_sensors_core_read_avail(struct iio_dev *indio_dev,case IIO_CHAN_INFO_SAMP_FREQ : *length =ARRAY_SIZE (state->frequencies); *vals = (const int *)&state->frequencies; - *type =IIO_VAL_INT ; + *type =IIO_VAL_INT_PLUS_MICRO ;return IIO_AVAIL_LIST ; }
@@ -798,12 +803,13 @@ 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) { - int ret; + int ret, frequency;switch (mask) {case IIO_CHAN_INFO_SAMP_FREQ : + frequency = val *1000 + val2 /1000 ; st->param.cmd =MOTIONSENSE_CMD_SENSOR_ODR ; - st->param.sensor_odr.data = val; + st->param.sensor_odr.data = frequency;/* Always roundup, so caller gets at least what it asks for. */ st->param.sensor_odr.roundup =1 ;
include/linux/iio/common/cros_ec_sensors_core.h +3 -3
@@ -51,6 +51,8 @@ typedef irqreturn_t (*cros_ec_sensors_capture_t)(int irq, void *p);* is always 8-byte aligned. * @read_ec_sensors_data: function used for accessing sensors values * @fifo_max_event_count: Size of the EC sensor FIFO +* @frequencies: Table of known available frequencies: +* 0, Min and Max in mHz */ struct cros_ec_sensors_core_state {struct cros_ec_device *ec;
@@ -74,9 +76,7 @@ struct cros_ec_sensors_core_state { unsigned long scan_mask, s16 *data);u32 fifo_max_event_count; - -/* Table of known available frequencies : 0, Min and Max in mHz */ -int frequencies[3 ]; +int frequencies[6 ]; }; int cros_ec_sensors_read_lpc(struct iio_dev *indio_dev, unsigned long scan_mask,
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v7 12/12 iio: cros_ec: flush as hwfifo attribute
In reply to Gwendal GrignouAdd buffer/hwfifo_flush. It is not part of the ABI, but it follows ST and HID lead: Tells the sensor hub to send to the host all pending sensor events.
---
No changes in v7.
New in v6.
.../cros_ec_sensors/cros_ec_sensors_core.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +28 -0
@@ -113,6 +113,33 @@ static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st,return ret; } +static ssize_t cros_ec_sensors_flush (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); +int ret =0 ; +bool flush; + + ret =strtobool (buf, &flush); +if (ret <0 ) +return ret; +if (!flush) +return -EINVAL ; + +mutex_lock (&st->cmd_lock); + st->param.cmd =MOTIONSENSE_CMD_FIFO_FLUSH ; + ret =cros_ec_motion_send_host_cmd (st,0 ); +if (ret !=0 ) +dev_warn (&indio_dev->dev,"Unable to flush sensor\n" ); +mutex_unlock (&st->cmd_lock); +return ret ? ret : len; +} + +static IIO_DEVICE_ATTR(hwfifo_flush, 0644, NULL, + cros_ec_sensors_flush, 0); +static ssize_t cros_ec_sensor_set_report_latency (struct device *dev,struct device_attribute *attr,const char *buf,size_t len)
@@ -175,6 +202,7 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev, static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);const struct attribute *cros_ec_sensor_fifo_attributes[] = { + &iio_dev_attr_hwfifo_flush.dev_attr.attr, &iio_dev_attr_hwfifo_timeout.dev_attr.attr, &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,NULL ,
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
Re: [PATCH v7 12/12] iio: cros_ec: flush as hwfifo attribute
Hi Jonathan and Gwendal,
Quoted 5 lines · Gwendal Grignou
Add buffer/hwfifo_flush. It is not part of the ABI, but it follows ST and HID lead: Tells the sensor hub to send to the host all pending sensor events.
Signed-off-by Gwendal Grignou <[email protected]>
I need an Ack from Jonathan to pick this.
Jonathan, once you are fine with it, do you mind if I take the full series through the platform chrome tree?
Thanks,
Enric
Quoted 54 lines
---
No changes in v7.
New in v6..../cros_ec_sensors/cros_ec_sensors_core.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +28
-0@@ -113,6 +113,33 @@ static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st,return ret; } +static ssize_t cros_ec_sensors_flush (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); +int ret =0 ; +bool flush; + + ret =strtobool (buf, &flush); +if (ret <0 ) +return ret; +if (!flush) +return -EINVAL ; + +mutex_lock (&st->cmd_lock); + st->param.cmd =MOTIONSENSE_CMD_FIFO_FLUSH ; + ret =cros_ec_motion_send_host_cmd (st,0 ); +if (ret !=0 ) +dev_warn (&indio_dev->dev,"Unable to flush sensor\n" ); +mutex_unlock (&st->cmd_lock); +return ret ? ret : len; +} + +static IIO_DEVICE_ATTR(hwfifo_flush, 0644, NULL, + cros_ec_sensors_flush, 0); +static ssize_t cros_ec_sensor_set_report_latency (struct device *dev,struct device_attribute *attr,const char *buf,size_t len)@@ -175,6 +202,7 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev, static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);const struct attribute *cros_ec_sensor_fifo_attributes[] = { + &iio_dev_attr_hwfifo_flush.dev_attr.attr, &iio_dev_attr_hwfifo_timeout.dev_attr.attr, &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,NULL ,
Jonathan Cameron
maintainerRe: [PATCH v7 12/12] iio: cros_ec: flush as hwfifo attribute
Quoted 7 lines · On Sat, 28 Mar 2020 10:14:23 +0100 Enric Balletbo i Serra…
Hi Jonathan and Gwendal,
Quoted 4 lines · Gwendal Grignou
Add buffer/hwfifo_flush. It is not part of the ABI, but it follows ST and HID lead: Tells the sensor hub to send to the host all pending sensor events.
Quoted 6 lines
Quoted 1 line
Signed-off-by Gwendal Grignou <[email protected]>I need an Ack from Jonathan to pick this.
Jonathan, once you are fine with it, do you mind if I take the full series through the platform chrome tree?
Once 12 is sorted (or if you want to take up to 11 thats fine) then sure happy for you to take them.
Thanks,
Jonathan
Quoted 59 lines
Thanks,
EnricQuoted 54 lines
---
No changes in v7.
New in v6..../cros_ec_sensors/cros_ec_sensors_core.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +28
-0@@ -113,6 +113,33 @@ static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st,return ret; } +static ssize_t cros_ec_sensors_flush (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); +int ret =0 ; +bool flush; + + ret =strtobool (buf, &flush); +if (ret <0 ) +return ret; +if (!flush) +return -EINVAL ; + +mutex_lock (&st->cmd_lock); + st->param.cmd =MOTIONSENSE_CMD_FIFO_FLUSH ; + ret =cros_ec_motion_send_host_cmd (st,0 ); +if (ret !=0 ) +dev_warn (&indio_dev->dev,"Unable to flush sensor\n" ); +mutex_unlock (&st->cmd_lock); +return ret ? ret : len; +} + +static IIO_DEVICE_ATTR(hwfifo_flush, 0644, NULL, + cros_ec_sensors_flush, 0); +static ssize_t cros_ec_sensor_set_report_latency (struct device *dev,struct device_attribute *attr,const char *buf,size_t len)@@ -175,6 +202,7 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev, static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);const struct attribute *cros_ec_sensor_fifo_attributes[] = { + &iio_dev_attr_hwfifo_flush.dev_attr.attr, &iio_dev_attr_hwfifo_timeout.dev_attr.attr, &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,NULL ,
Re: [PATCH v7 12/12] iio: cros_ec: flush as hwfifo attribute
In reply to Gwendal GrignouQuoted 5 lines · On Fri, 27 Mar 2020 15:34:43 -0700 Gwendal Grignou <[email protected]> wrote:
Add buffer/hwfifo_flush. It is not part of the ABI, but it follows ST and HID lead: Tells the sensor hub to send to the host all pending sensor events.
Signed-off-by Gwendal Grignou <[email protected]>
Unless I'm missing something there aren't any other drivers providing an explicit flush attribute. The nearest equivalent is the flush callback which reads out stuff that is in a fifo to be read, but which hasn't yet reached a watermark to trigger normal readback.
Can we do something similar here?
If not this needs ABI documentation in Documentation/ABI/testing/... I'm not keen on it in becoming general ABI unless I'm missing a strong argument in favour of it.
Jonathan
Quoted 53 lines
---
No changes in v7.
New in v6..../cros_ec_sensors/cros_ec_sensors_core.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +28
-0@@ -113,6 +113,33 @@ static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st,return ret; } +static ssize_t cros_ec_sensors_flush (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); +int ret =0 ; +bool flush; + + ret =strtobool (buf, &flush); +if (ret <0 ) +return ret; +if (!flush) +return -EINVAL ; + +mutex_lock (&st->cmd_lock); + st->param.cmd =MOTIONSENSE_CMD_FIFO_FLUSH ; + ret =cros_ec_motion_send_host_cmd (st,0 ); +if (ret !=0 ) +dev_warn (&indio_dev->dev,"Unable to flush sensor\n" ); +mutex_unlock (&st->cmd_lock); +return ret ? ret : len; +} + +static IIO_DEVICE_ATTR(hwfifo_flush, 0644, NULL, + cros_ec_sensors_flush, 0); +static ssize_t cros_ec_sensor_set_report_latency (struct device *dev,struct device_attribute *attr,const char *buf,size_t len)@@ -175,6 +202,7 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev, static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);const struct attribute *cros_ec_sensor_fifo_attributes[] = { + &iio_dev_attr_hwfifo_flush.dev_attr.attr, &iio_dev_attr_hwfifo_timeout.dev_attr.attr, &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,NULL ,
Re: [PATCH v7 12/12] iio: cros_ec: flush as hwfifo attribute
Quoted 4 lines · Jonathan Cameron
On Fri, 27 Mar 2020 15:34:43 -0700
Gwendal Grignou <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines
Add buffer/hwfifo_flush. It is not part of the ABI, but it follows ST and HID lead: Tells the sensor hub to send to the host all pending sensor events.
Signed-off-by Gwendal Grignou <[email protected]>Unless I'm missing something there aren't any other drivers providing an explicit flush attribute.
The flush attribute comes from a requirement from Android to ask the sensorhub to flush the samples still in its FIFO queue. (see
https://source.android.com/devices/sensors/hal-interface#flush_sensor)
It has been implemented in the ST Android HAL, which expects a hw_fifo_flush attribute.:
https://github.com/STMicroelectronics/STMems_Android_Sensor_HAL_IIO/blob/STMems_Android_Sensor_HAL_IIO/src/utils.cpp#L31
But I misread kernel ST code; as you said, the request to flush appends only when the buffer is enabled/disabled or the sensor suspended, it is not exposed to user space.
For Bosh sensor : there is a patch that was proposed a while back:
"http://lkml.iu.edu/hypermail/linux/kernel/1504.3/03270.html", but it never reached mainline.
For HID, the attribute is defined in the HID specification (31C) :
https://www.usb.org/sites/default/files/hutrr59_-_usages_for_wearables_0.pdf
but I could not find a publicly available proposed change request that uses it.
Anyhow, it was a mistake to put this patch in the current patch set. I need it on chromebook for supporting Android, but it should be discussed more widely to have it part of the ABI, or define a better solution.
Quoted 11 lines
The nearest equivalent is the flush
callback which reads out stuff that is in a fifo to be read, but which hasn't yet reached a watermark to trigger normal readback.Can we do something similar here?
If not this needs ABI documentation in
Documentation/ABI/testing/... I'm not keen on it in becoming general ABI unless I'm missing a strong argument in favour of it.Jonathan
Thank you for your support,
Gwendal.
Quoted 56 lines
Quoted 55 lines
---
No changes in v7.
New in v6..../cros_ec_sensors/cros_ec_sensors_core.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +28
-0@@ -113,6 +113,33 @@ static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st,return ret; } +static ssize_t cros_ec_sensors_flush (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); +int ret =0 ; +bool flush; + + ret =strtobool (buf, &flush); +if (ret <0 ) +return ret; +if (!flush) +return -EINVAL ; + +mutex_lock (&st->cmd_lock); + st->param.cmd =MOTIONSENSE_CMD_FIFO_FLUSH ; + ret =cros_ec_motion_send_host_cmd (st,0 ); +if (ret !=0 ) +dev_warn (&indio_dev->dev,"Unable to flush sensor\n" ); +mutex_unlock (&st->cmd_lock); +return ret ? ret : len; +} + +static IIO_DEVICE_ATTR(hwfifo_flush, 0644, NULL, + cros_ec_sensors_flush, 0); +static ssize_t cros_ec_sensor_set_report_latency (struct device *dev,struct device_attribute *attr,const char *buf,size_t len)@@ -175,6 +202,7 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev, static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);const struct attribute *cros_ec_sensor_fifo_attributes[] = { + &iio_dev_attr_hwfifo_flush.dev_attr.attr, &iio_dev_attr_hwfifo_timeout.dev_attr.attr, &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,NULL ,
Jonathan Cameron
maintainerRe: [PATCH v7 12/12] iio: cros_ec: flush as hwfifo attribute
Quoted 44 lines · On Sat, 28 Mar 2020 17:33:48 -0700 Gwendal Grignou <[email protected]> wrote:
Quoted 4 lines · Jonathan Cameron
On Fri, 27 Mar 2020 15:34:43 -0700
Gwendal Grignou <[email protected]> wrote:Quoted 8 lines
Quoted 5 lines
Add buffer/hwfifo_flush. It is not part of the ABI, but it follows ST and HID lead: Tells the sensor hub to send to the host all pending sensor events.
Signed-off-by Gwendal Grignou <[email protected]>Unless I'm missing something there aren't any other drivers providing an explicit flush attribute.
The flush attribute comes from a requirement from Android to ask the sensorhub to flush the samples still in its FIFO queue. (see
https://source.android.com/devices/sensors/hal-interface#flush_sensor)
It has been implemented in the ST Android HAL, which expects ahw_fifo_flushattribute.:
https://github.com/STMicroelectronics/STMems_Android_Sensor_HAL_IIO/blob/STMems_Android_Sensor_HAL_IIO/src/utils.cpp#L31But I misread kernel ST code; as you said, the request to flush appends only when the buffer is enabled/disabled or the sensor suspended, it is not exposed to user space.
For Bosh sensor : there is a patch that was proposed a while back:
"http://lkml.iu.edu/hypermail/linux/kernel/1504.3/03270.html", but it never reached mainline.For HID, the attribute is defined in the HID specification (31C) :
https://www.usb.org/sites/default/files/hutrr59_-_usages_for_wearables_0.pdf
but I could not find a publicly available proposed change request that uses it.Anyhow, it was a mistake to put this patch in the current patch set. I need it on chromebook for supporting Android, but it should be discussed more widely to have it part of the ABI, or define a better solution.
Quoted 6 lines
The nearest equivalent is the flush
callback which reads out stuff that is in a fifo to be read, but which hasn't yet reached a watermark to trigger normal readback.Can we do something similar here?
Quoted 7 lines
Quoted 5 lines
If not this needs ABI documentation in
Documentation/ABI/testing/... I'm not keen on it in becoming general ABI unless I'm missing a strong argument in favour of it.Jonathan
Thank you for your support,
Gwendal.
Agreed, lets separate this one out for now.
So Enric, please pick up patches 1-11 and we can revisit this one as a separate series.
Thanks!
Jonathan
Quoted 56 lines
Quoted 56 lines
Quoted 55 lines
---
No changes in v7.
New in v6..../cros_ec_sensors/cros_ec_sensors_core.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +28
-0@@ -113,6 +113,33 @@ static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st,return ret; } +static ssize_t cros_ec_sensors_flush (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); +int ret =0 ; +bool flush; + + ret =strtobool (buf, &flush); +if (ret <0 ) +return ret; +if (!flush) +return -EINVAL ; + +mutex_lock (&st->cmd_lock); + st->param.cmd =MOTIONSENSE_CMD_FIFO_FLUSH ; + ret =cros_ec_motion_send_host_cmd (st,0 ); +if (ret !=0 ) +dev_warn (&indio_dev->dev,"Unable to flush sensor\n" ); +mutex_unlock (&st->cmd_lock); +return ret ? ret : len; +} + +static IIO_DEVICE_ATTR(hwfifo_flush, 0644, NULL, + cros_ec_sensors_flush, 0); +static ssize_t cros_ec_sensor_set_report_latency (struct device *dev,struct device_attribute *attr,const char *buf,size_t len)@@ -175,6 +202,7 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev, static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);const struct attribute *cros_ec_sensor_fifo_attributes[] = { + &iio_dev_attr_hwfifo_flush.dev_attr.attr, &iio_dev_attr_hwfifo_timeout.dev_attr.attr, &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,NULL ,
Re: [PATCH v7 12/12] iio: cros_ec: flush as hwfifo attribute
In reply to Gwendal GrignouQuoted 4 lines · Gwendal Grignou
Add buffer/hwfifo_flush. It is not part of the ABI, but it follows ST and HID lead: Tells the sensor hub to send to the host all pending sensor events.
I see where discussion is going, but nevertheless some comments below that you will not make same mistakes in the future.
...
Quoted 1 line
+ int ret = 0;
Useless assignment.
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st, · line 125
Quoted 4 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +3
-0+bool flush; + + ret =strtobool (buf, &flush);
kstrtobool()
Quoted 1 line
+ if (ret < 0)
Positive error codes? I'm not sure it returns a such. So ' < 0' part is redundant.
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st, · line 129
Quoted 4 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +3
-0+return ret; +if (!flush) +return -EINVAL ;
This I didn't get, you have accept only true as input? It's really strange.
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st, · line 134
Quoted 3 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +2
-0+ ret =cros_ec_motion_send_host_cmd (st,0 ); +if (ret !=0 )
Similar to above ' != 0' part is redundant.
Quoted 1 line
+
dev_warn(&indio_dev->dev, "Unable to flush sensor\n");
...
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st, · line 141
Quoted 2 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +2
-0+static IIO_DEVICE_ATTR(hwfifo_flush, 0644, NULL, + cros_ec_sensors_flush, 0);
IIO_DEVICE_ATTR_RW() ?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Enric Balletbo i Serra
AppliedHi Gwendal,
Quoted 67 lines · Gwendal Grignou
This patchset adds a sensorhub driver for spreading sensor events coming from the Embedded controller sensor FIFO:
+---------------+ +--------------+ +---- | cros_ec_accel | | cros_ec_gyro | | ... +---------------+ +--------------+ +---- id:0 \ id:1 | / id:.. +------------------------------+ | cros-ec-sensorhub | +------------------------------+ | cros_ec_dev | +------------------------------+ | cros_ec_i2c, cros_ec_lpc, .. | +------------------------------+ |EC
When new sensors events are present, the EC raises and interrupt, sensorhub reads the FIFO and uses the 'id' field to spread the event to the proper IIO sensors. This stack is similar to the HID sensor input stack.
The patch set allows the host to receive MEMS sensor sample asynchronously from ChromeOS Emebedded Controller (EC).
Given the EC and the host are not synchronized, the timestamp generated by the EC drifts and the AP interrupt latency adds variable delay.
When events arrive, the driver stores the time of the interrupt and use that information to convert the timestamp from the EC time domain to the AP time domain. To prevent the errors from the interrupt time variation, a median filter smooth the timestamp generation and prevents timestamps to go in the past.
When a batch of sensor events arrives, the sensor hub ring code spreads the timestamps.
The buffer interaface is presentid through the IIO ABI.
And extra parameter - flush - (presents on HID and ST sensor hub implementation) force the EC to send accumulated events in its queue, without waiting for bufferhwfifo_timeoutto expire.To access sensor data, we can use
iio_readdevlike:
iio_readdev-T 10000 -s 4 -b 2 iio:device4When FIFO is not supported by the EC, a trigger is present in the directory. After registering a trigger, setting
sampling_frequency, the latest data collected by the sensor will be retrieved by the host when the trigger expires.When
cros_ec_accel_legacydriver is used, no FIFO is supported and the sampling frequency for the accelerometers is hard coded at 10Hz.Gwendal Grignou (12):
platform: chrome: sensorhub: Add the number of sensors in sensorhub
platform: chrome: sensorhub: Add FIFO support
platform: chrome: sensorhub: Add code to spread timestmap
platform: chrome: sensorhub: Add median filter
iio:cros_ec: Move function description to .c file
iio: exposeiio_device_set_clock
iio:cros_ec: Register tocros_ec_sensorhubwhen EC supports FIFO
iio:cros_ec: Remove pm function
iio:cros_ec: Exposehwfifo_timeout
iio:cros_ec: Reporthwfifo_watermark_max
iio:cros_ec: Use Hertz as unit for sampling frequency
iio:cros_ec: flush as hwfifo attribute
Quoted 16 lines
drivers/iio/accel/cros_ec_accel_legacy.c | 8 +- .../cros_ec_sensors/cros_ec_lid_angle.c | 3 +- .../common/cros_ec_sensors/cros_ec_sensors.c | 13 +- .../cros_ec_sensors/cros_ec_sensors_core.c | 403 +++++-- drivers/iio/industrialio-core.c | 8 +- drivers/iio/light/cros_ec_light_prox.c | 15 +- drivers/iio/pressure/cros_ec_baro.c | 14 +- drivers/platform/chrome/Makefile | 4 +- drivers/platform/chrome/cros_ec_sensorhub.c | 111 +- .../platform/chrome/cros_ec_sensorhub_ring.c | 1046 +++++++++++++++++ .../linux/iio/common/cros_ec_sensors_core.h | 104 +- include/linux/iio/iio.h | 2 + .../linux/platform_data/cros_ec_sensorhub.h | 163 +++ 13 files changed, 1655 insertions(+), 239 deletions(-) create mode 100644 drivers/platform/chrome/cros_ec_sensorhub_ring.c
Queued patches from 0 to 11 to for-next. Patch 12 needs some rework.
Thanks,
Enric