summaryrefslogtreecommitdiff
path: root/driver/accelgyro_bmi160.c
Commit message (Collapse)AuthorAgeFilesLines
* common: motion_sense: Spread timestamps in motion sense fifoYuval Peress2019-06-061-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes moves the specialized logic for timestamp spreading away from the accelgyro_lsm6dsm and into the main motion_sense loop. The motion_sense_fifo_add_data function was replaced by a stage equivalent, and a commit function was added. Similarly, internal static functions for motion_sense.c were renamed to use the stage terminology. The idea is: When a sensor is read, it might provide more than one measurement though the only known timestamp is the one that caused the interrupt. Staging this data allows us to use the same fifo queue space that the entries would consume eventually anyway without making the entries readable. Upon commit, the timestamp entries are spread if needed. Note that if tight timestamps are disabled, the commit becomes a simple tail move. BUG=chromium:966506 BRANCH=None TEST=Ran CTS on arcada. Change-Id: Ib7d0a75c9c56fc4e275aed794058a5eca58ff47f Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1637416 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* motionsense: Convert in_spoof_mode to a more generic flagsYuval Peress2019-05-231-1/+1
| | | | | | | | | | | | BUG=b:129159505 BRANCH=arcada TEST=I ran `make buildall` since this change isn't used yet it doesn't affect run-time behavior. Change-Id: I01857d679b800f9b53762c659ebd9a018cbf16db Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1612251 Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
* driver: bmi160: Check enable_fifo flags before processing FIFOGwendal Grignou2019-04-271-13/+13
| | | | | | | | | | | | | | | | | | | | If there is an interrupt pending after we suspend the BMI160, we will try to collect length from the FIFO, but the FIFO is suspended. Bring back enable_fifo flags check before processing the FIFO. It has been move after gathering the length in CL:1128555 BUG=b:127321764,b:131272795 BRANCH=master TEST=Using flip_flop.sh script at b/131272795#comment2 Check the messages "unexpected empty FIFO" disappear. Change-Id: Iaab1a7f3607b902acd92b75c926365d7eb09fd5e Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1585420 Reviewed-by: Enrico Granata <egranata@chromium.org> (cherry picked from commit d17cd2add14f1f1e32bd58d51d60a2c93f17f055) Reviewed-on: https://chromium-review.googlesource.com/1585471
* common: bit change 1 << constants with BIT(constants)Gwendal Grignou2019-03-261-2/+2
| | | | | | | | | | | | | | | | | Mechanical replacement of bit operation where operand is a constant. More bit operation exist, but prone to errors. Reveal a bug in npcx: chip/npcx/system-npcx7.c:114:54: error: conversion from 'long unsigned int' to 'uint8_t' {aka 'volatile unsigned char'} changes value from '16777215' to '255' [-Werror=overflow] BUG=None BRANCH=None TEST=None Change-Id: I006614026143fa180702ac0d1cc2ceb1b3c6eeb0 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1518660 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* motion: Define macros for custom eventsGwendal Grignou2019-03-201-2/+4
| | | | | | | | | | | | | | Define macros to define custom events used by sensor interrupt handlers. Remove CONFIG_ for activity events. BUG=none BRANCH=none TEST=compile, sensors work on eve. Change-Id: I08ef6ed2a004466ebc5f7650d6952a150b9de713 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1272189 Reviewed-by: Jett Rink <jettrink@chromium.org>
* driver: bmi160: Force calling irq_handler after mag initializationGwendal Grignou2019-02-281-0/+7
| | | | | | | | | | | | | | | | Without it, accelinit 3 lock the FIFO. BUG=chromium:917868 BRANCH=eve TEST=Check with ./mems_start_collection.sh fifo samples of the accelerometer are printed out after initalizing the magnetometer with accel_init 3. Change-Id: Iadab1b3ae506b3360ee8fe7663ee2c74e9f5bc18 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1390941 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Furquan Shaikh <furquan@chromium.org>
* driver: bmi160: Add temporary variable in decode_headerGwendal Grignou2019-02-281-7/+9
| | | | | | | | | | | | | | | | Use a single variable instead of (s+i) to point to the sensor we are working on. BUG=chromium:917868 BRANCH=eve TEST=With ./mems_start_collection.sh, check samples are collected. Change-Id: Ib05059bea776aec978a8feb350f2dacb8aae7311 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1390940 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Enrico Granata <egranata@chromium.org>
* FIXUP: sensor: Adjust max_frequency based on EC performanceGwendal Grignou2019-02-281-4/+2
| | | | | | | | | | | | | | | Remove unnecessary code, sensor maximal ODR is guaranteed to be smaller than EC support maximial ODR. BUG=b:118205424,b:118851581,chromium:615059 BRANCH=none TEST=Check the limits have not change and an error is reported when frequency is set to high in sysfs. Change-Id: Ia10bf2cc58c5609c4fded16a0bff3018916a2346 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1390937 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
* driver: bmi160: Add setting calibration scaleGwendal Grignou2019-02-271-8/+40
| | | | | | | | | | | | | | Implement get_scale, set_scale and apply the scale when normalizing. BUG=b:112957338 BRANCH=nocturne TEST=Check calibscale is taken into account on bmi160. Change-Id: I2c72053b026fe09798cd1009e77cc36c3c4fdac2 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1279186 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Enrico Granata <egranata@chromium.org>
* driver: bmi160: for reference, add for lis2mdl supportGwendal Grignou2019-02-111-0/+5
| | | | | | | | | | | | BUG=b:110143516,b:115587004 BRANCH=none TEST=compile Change-Id: I72953d1c279f739e15e5d14dab2d016e0900a532 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/1444094 Reviewed-by: Justin TerAvest <teravest@chromium.org> Tested-by: Justin TerAvest <teravest@chromium.org>
* config: Add magnetometer definitionsGwendal Grignou2019-02-081-1/+1
| | | | | | | | | | | | | | | | | | | Add all possible supported or soon-to-be supported configuration of magnetometer behind accelerometers. Use a more generic variable to indicate the i2c address of the secondary device. BUG=b:110143516,b:115587004 BRANCH=none TEST=compile Change-Id: Ic00c413f2ec5fa0e6bf1c98861daa02f00769a65 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1361989 Commit-Ready: Karthikeyan Ramasubramanian <kramasub@chromium.org> Tested-by: Justin TerAvest <teravest@chromium.org> Reviewed-by: Karthikeyan Ramasubramanian <kramasub@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* bmi160: exit IRQ loop if error during reg readJett Rink2018-12-141-2/+4
| | | | | | | | | | | | | | | | | | | | The IRQ handler for bmi160 continues to loop until all of the interrupt reasons are handled; however, if the read fails the interrupt variable will be in an unknown state. We can either return early if there was an error or we can set the interrupt variable to 0 before the read call. Either way the loop exits. BRANCH=none BUG=b:119093572 TEST=On Bobba360 with a solid repro case of the watchdog reset, this change avoids the watchdog reset. Change-Id: I482f074b6e9e7c183def8ce17157ed28ca96b1c9 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1378908 Reviewed-by: Alexandru M Stan <amstan@chromium.org> Reviewed-by: Enrico Granata <egranata@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* bmi160: do not overrun the amount of data read from the BMI FIFOEnrico Granata2018-12-131-8/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixes a race condition in the BMI160 driver w.r.t. reading from the FIFO. The previous code was reading the FIFO length, adding 1 byte to it and then reading that much data into a static buffer. This works well if no new samples are added to the FIFO between reading the length and reading the payload. But, if the BMI pushes a new sample in the FIFO, the read will not return an empty frame header, but instead fill in the first byte of the new sample, which is - however - incomplete and will be retransmitted. However, because the buffer we process is static, if things align just right, it is possible for that header to be parsed as a valid sample, since we do not clear the buffer and we assume the entire 64 bytes of it are valid and processable. Fix this issue by maintaining a pointer to the end of the read-in FIFO buffer and using that - instead of the static bp + sizeof - to calculate how much data we can actually process from the FIFO. BUG=b:120508077 BRANCH=poppy,octopus TEST=Starting from CL:1367013 and CL:1370689, adding an `msleep(2)` between reading last_interrupt_timestamp and calling load_fifo(), observe that the kernel sees more sensor events than should be present given the sample rate selected. Observe that some of those have repeated payload values. With this change, the number of samples seen at the kernel side is compatible with the chosen sample rate and no samples have incorrectly repeating payloads. It is possible to also make this more obvious by setting the buffer to contain an incorrect value before reading from the FIFO, and observing that no samples contain that incorrect value. Change-Id: I57124756d51b8acf04630020c1ffb934f471735f Signed-off-by: Enrico Granata <egranata@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1372027 Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Alexandru M Stan <amstan@chromium.org>
* bmi160: Keep timestamp and FIFO synchronizedEnrico Granata2018-12-121-8/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The BMI160 will clear the FIFO watermark/full interrupt when the FIFO crosses the threshold condition - which happens upon reading from it in load_fifo(). As a result of this, and the fact that the soft IRQ handler for the BMI160 tries to loop until it has finished serving all interrupt causes, there are possibilities for a race condition such as the following to occur: read timestamp, value is t0 read interrupt cause: it's a watermark interrupt load fifo(t0): this clears the interrupt, allowing a new one to happen read timestamp, value is still t0 a watermark interrupt happens at t1 read interrupt cause: watermark load fifo(t0) At this point, the fifo will process events at t1 as-if they had happened at t0, which is bad and causes incorrect timestamps on the AP side. This changes moves reading the timestamp value as close as possible to load_fifo, and in a relative order where a new watermark interrupt cannot happen, which ensures the timestamp and the FIFO data for it are synchronized BUG=b:120508077 TEST=on Bobba and Nocturne, observe that no events happen where an identical "a" time matches two distinct (b,c) times BRANCH=nocturne,bobba Change-Id: I454b257366bccf2b9e4d78df5dc005a8ad7313a0 Signed-off-by: Enrico Granata <egranata@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1367013 Reviewed-by: Alexandru M Stan <amstan@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* driver: bmi160: Read the FIFO more efficientlyGwendal Grignou2018-10-151-83/+108
| | | | | | | | | | | | | | | | | | | | Instead of blindy reading 64 bytes, even when only one sample is available, first read the amount of data in the FIFO: - if less than the buffer, just read that amount, and return when processed. - if more, read what the buffer can hold, return to be called again. by the interrupt routine. Return an error when we have to flush the FIFO when it looks incorrect. BUG=b:73557414,b:80284952 BRANCH=scarlet,poppy TEST=Check BMI160 is not stuck, run CtsHardwareTestCases suite. Check remaining failures are related to timestamp only. Change-Id: Ic2f48978f73f7aaf9996ec20d219a75dca5e5112 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1128555 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* FIXUP: driver: bmi160: harden interrupt and fifo processingGwendal Grignou2018-10-021-3/+2
| | | | | | | | | | | | | | | | | | | | | | | Actually 5ms is needed to reset interrupt of activity like significant motion. When processing FIFO, the interrupt will go down once the FIFO is processed, but for activity, there is no easy way for the bit to go down. See https://electronics.stackexchange.com/questions/299188/how-to-program-bmi160-inertial-measuremen-unit-to-latch-detection-flags BUG=b:73557414,b:80284952 BRANCH=scarlet,poppy,nocturne TEST=Without this change, the interrupt bitfield in the the interrupt routine never goes back to 0. Check the sensor is not getting stuck. Change-Id: I986547787183377938ab08afe52fb2871d5c7c71 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1205203 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit 61b1806c0db895487ee9e687f365d844f5931732) Reviewed-on: https://chromium-review.googlesource.com/1252449
* type: Rename vector_3_t to intv3_t.Yilun Lin2018-09-131-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Naming of many vector types and matrix types are not clear enough. For example, we have: vector_3_t, which is a vector of three int. vec3_t, which is a vector of three float. size4_t, which is a vector of four size_t. mat33_t, which is a 3x3 matrix of float. matrix_3x3_t, which is a 3x3 matrix of fixed point. Besides, we have types like int8_t, uint16_t types. To clearly distinguished types, the CL propose to, For vector types, naming should be `$type + 'v' + $num + '_t'`: vector_3_t becomes intv3_t vec3_t becomes floatv3_t vector 4 of uint16_t becomes uint16v4_t (which doesn't exist yet) For matrix types, naming should be `mat$N$N_` + $type + '_t', where $N is the matrix size: matrix_3x3_t becomes mat33_fp_t # fp: fixed point mat33_t becomes mat33_float_t TEST=make buildall -j BUG=b:114662791 Change-Id: I865aa3ecbab6cb97f8585a081a679adf00febe1d Signed-off-by: Yilun Lin <yllin@google.com> Reviewed-on: https://chromium-review.googlesource.com/1215442 Commit-Ready: Yilun Lin <yllin@chromium.org> Tested-by: Yilun Lin <yllin@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
* driver: accel: Prevent ODR from crashing the ECGwendal Grignou2018-09-051-23/+14
| | | | | | | | | | | | | | | | | | For accelerometers which are interrupt driven, setting ODR too high may exhaust the EC and trigger the watchdog timer. Use config variable to verify the ODR requested is not too big. Return an error when setting unsupported parameters. BUG=b:112672627 BRANCH=nocturne,eve TEST=Without this change, ectool motionsense odr 0 500000 crashes the EC Now, it returns EC result 3 (INVALID_PARAM) Change-Id: I64a4e522dcad450d619a7fc48a1330479f1cf81f Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1200068 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* bmi160: End IRQ handler if sensor isn't powered.Aseda Aboagye2018-08-221-1/+6
| | | | | | | | | | | | | | | | | | | It's possible for the interrupt to be triggered and then when the bottom half of the interrupt handler gets a chance to run, the sensor isn't powered anymore. This commit simply has the loop terminate early if the board indicates that the bus the sensor is on is no longer powered. BUG=b:111683988 BRANCH=nocturne TEST=Verify if IRQ handler is called when sensor is not powered, the irq_handler loop terminates. Change-Id: Iaf395902bb4b46a5b6d750c99767c4c36b1e7a99 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/1182879 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Alexandru M Stan <amstan@chromium.org>
* drivers: Refactor to use high-level i2c APIsJonathan Brandmeyer2018-08-091-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | Using the high-level APIs for block transfers eliminates some code duplication and error-prone manual locking sequences. - common/cbi: Block transfers - driver/accel_bma2x2: Block transfers - driver/accel_kionix: Block transfers - driver/accelgyro_bmi160: Block transfers - driver/accelgyro_lsm6ds0: Block transfers - driver/baro_bmp280: Block and byte transfers - driver/charger/rt946x: Block transfers - driver/gyro_l3gd20h: Block transfers - driver/stm_mems_common: Block transfers - driver/tcpm: Block transfers TEST=buildall; motionsense and PD testing on Grunt convertible which exercises the bma160, kionix and tcpcm drivers. BRANCH=none BUG=chromium:871851 Change-Id: I1732253a244c3343459265ce1e1e54488cee65b8 Signed-off-by: Jonathan Brandmeyer <jbrandmeyer@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1167958 Reviewed-by: Jett Rink <jettrink@chromium.org>
* driver: bmi160: Preserve the timestamp before releasing interruptGwendal Grignou2018-07-141-7/+13
| | | | | | | | | | | | | | | | | Collect timestamp before resetting the interrupt line: After reading, it is possible for the timestamp to change, before we can process the FIFO. BUG=b:67743747 BRANCH=scarlet TEST=CtsHardwareTestCases Change-Id: I283f8efb1098a38c76caf326b6416a386ab221cd Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1137438 Commit-Ready: Alexandru M Stan <amstan@chromium.org> Tested-by: Alexandru M Stan <amstan@chromium.org> Reviewed-by: Alexandru M Stan <amstan@chromium.org>
* driver: bmi160: harden interrupt and fifo processingGwendal Grignou2018-07-141-45/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | During cts test with CL:938146, the BMI160 would not send any interrupts and FIFO got un processed. - Latch IRQ events forever: the motion_sense task will kick in and read the interrupt source sometimes, even after 5ms. - Retest irq bits in irq_handler. If more events are posted, we will collect them right away, avoiding a task wake up round trip. We assume the BMI160 adds events too fast and force the motion task into a infinite loop. BUG=b:73557414,b:80284952 BRANCH=scarlet,poppy TEST=Without that code, BMI160 would get unprocessed: android.hardware.cts.SensorIntegrationTests#testSensorsWithSeveralClients fail: ... Iteration 0 failed: "WaitForEvents |i sensor='CrosEC Accelerometer', samplingPeriod=0us, maxReportLatency=0us | requested=100, received=0, With it, the 25 iterations pass. Change-Id: I0f94b811ac0dbf60dcfa24c899682a2b5eb69de7 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1128554 Commit-Ready: Alexandru M Stan <amstan@chromium.org> Tested-by: Alexandru M Stan <amstan@chromium.org> Reviewed-by: Alexandru M Stan <amstan@chromium.org>
* driver: bmi160: Rename secondary i2c access functionsGwendal Grignou2018-06-171-7/+8
| | | | | | | | | | | | | Make it more generic to support sensor other than BMI159. BUG=b:110143516 BRANCH=none TEST=compile Change-Id: I954df2e9301e05968930add396cd724ca0dfa262 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1101550 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* driver: bmi160: Rename secondary i2c device addressGwendal Grignou2018-06-151-1/+1
| | | | | | | | | | | | Make it more generic, to support other magnetometer. BUG=b:110143516 BRANCH=none TEST=Compile Change-Id: I94cbbe6daf598680a2decde12d703650dfb7c04c Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1101548
* BMI160: EVE TOT divide by 0 error at bootSam Hurst2018-05-241-0/+1
| | | | | | | | | | | | | | | | | | | The BMI160 driver's init function generates a divide by 0 error by calling config_interrupt before initializing the range defined in struct accelgyro_saved_data_t. The explicit error is generated by macro BMI160_TAP_TH that's called in config_interrupt. BUG=b:80237518 BRANCH=None TEST=`make -j buildall` EVE boots from TOT Signed-off-by: Sam Hurst <shurst@chromium.org> Change-Id: I8b7a4a7c63c973bcc639779ee54958f3702f1b36 Reviewed-on: https://chromium-review.googlesource.com/1071847 Commit-Ready: Sam Hurst <shurst@google.com> Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Duncan Laurie <dlaurie@google.com>
* sensor: bmi160/bma2x2: Fix the timeout value of compensation.Marco Chen2018-03-261-1/+1
| | | | | | | | | | | | | | | | | | | CL:957872 introduced "get_time().val + 400" as the deadline to perform compensation and the comment in bma2x2.c mentioned the deadline should be 400ms. But the unit of val in timestamp_t is microsecond not milisecond so only 400us is defined not 400ms. BRANCH=none BUG=b:76234078 BUG=b:76202592 TEST=test manually on the dut by performing calibrate. Change-Id: I7a834ef6dcb0772569d2c8d6c507803deb5d2fc1 Signed-off-by: Marco Chen <marcochen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/979512 Commit-Ready: Gwendal Grignou <gwendal@chromium.org> Tested-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* driver: bma2x2: Add perform_calibGwendal Grignou2018-03-161-4/+5
| | | | | | | | | | | | | | | | | | Add fast compensation automatic calibration, like bmi160. Use timestamp_expired for timeout measurement for both perform_calib functions. Remove driver offset field, remove private bma2x2 structure. BUG=b:73205042 BRANCH=master TEST=echo 1 > calibrate perform calibration. Reading in_accel_*_calibbias is within range. Check on Lami for both bma2x2 and bmi160. Change-Id: I3472865287fa4769a05e6f872b92d7c3f933cb4e Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/957872 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* driver: sensor: Remove set_resolution when NOOPGwendal Grignou2018-03-151-9/+0
| | | | | | | | | | | | | | set_resolution is only used for few sensors and is not exposed to the AP. Remove definition when sensors have a fixed resolution. BUG=none BRANCH=master TEST=compile, kevin has enough space for perform_calib. Change-Id: I8482387e135356467edaee44da3a0e47cf1db524 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/961222 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* motion: Lower jitter of Sensor->EC timestampAlexandru M Stan2018-03-141-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead getting the time for each sample in the task code, we should be getting it as soon as the sensor reported it added it to its fifo (so sensor just finished integration). Because of that each sensor should provide the time when it provides a sample, ideally from an accurate spot like an interrupt. Deprecate motion_sense_fifo_add_unit (without a timestamp) in favour of motion_sense_fifo_add_data (which adds the timestamps). Update all relevant sensors to use the new api. Note: for now I focused on the BMI160, where I actually made it get the time in the interrupt. The other sensors were made to use the new api, but still don't record the time in the right place (though it's not any worse than before). BUG=b:67743747 TEST=In the kernel, fifo_info->info.timestamp still has sane values. TEST=CTS should still pass BRANCH=master Change-Id: I9829343f8702e00cc19f9c88134fa1f258c9e1e9 Signed-off-by: Alexandru M Stan <amstan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/807331 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* motion: remove load_fifoGwendal Grignou2018-03-091-166/+179
| | | | | | | | | | | | | | | | | | | | | To prevent invalid timestamping, call load_fifo only when we get a FIFO interrupt. In consequence, remove load_fifo entry point and only process fifo inside the IRQ. Add helper function to know when we are in forced mode (the EC needs to periodically read sensor data or interrupt driven). BUG=b:73557414 BRANCH=master TEST=compile Change-Id: I959e476f3f7215be95424c07223f7421e8b13da1 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/938146 Commit-Ready: Alexandru M Stan <amstan@chromium.org> Tested-by: Alexandru M Stan <amstan@chromium.org> Reviewed-by: Alexandru M Stan <amstan@chromium.org>
* sensor: bmi160: Don't batch data on the sensorAlexandru M Stan2018-03-091-3/+2
| | | | | | | | | | | | | | | | | | | Set the sensor side fifo watermark to interrupt the EC as soon as there's any data in there, that way we get more frequent accelerometer interrupts (which is handy when you want to mark down the time of each sample accuratelly). BUG=b:67743747 TEST=Sensor should still be working normally, the ec will probably start recieving sensor interrupts (before this was probably not the case). BRANCH=master Change-Id: I726550e68447a74bbfed88b703d2f68b6967ac93 Signed-off-by: Alexandru M Stan <amstan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/956626 Commit-Ready: Gwendal Grignou <gwendal@chromium.org> Tested-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* motion_sense: Put set_range in common codeGwendal Grignou2017-11-171-3/+1
| | | | | | | | | | | | | | | | At the end of the sensor initialization, all _init sensor routines set the range to the default value from board.c file. Put all the code in a single place, move it from sensor_common.c to motion_sense.c. BUG=none BRANCH=none TEST=compile Change-Id: If89cf27c6438e0f215c193d68a480e027110174c Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/767610 Reviewed-by: Shawn N <shawnn@chromium.org>
* sensors: add bmi160 & kionix orientation driverNick Vaccaro2017-08-081-0/+49
| | | | | | | | | | | | | BRANCH=none BUG=chromium:718919 TEST=make buildall -j works, orientation works when enabled on gru and scarlet. Change-Id: I16dcfa5d9dea39c082d98190fa1bb6e496168b17 Signed-off-by: Nick Vaccaro <nvaccaro@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/540124 Tested-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* sensor: bmi160: Fix macro used to set double tap intersticeScott Collyer2017-05-311-1/+1
| | | | | | | | | | | | | | | | | The line to convert the desired double tap window time to its register value was using the incorrect macro. Have corrected this to use the intended one. BUG=b:62202895 BRANCH=none TEST=On Eve verified that double tap events are properly detected. Change-Id: I70d810c93a8e27a3f61f3175e1ea95d0e59554ac Signed-off-by: Scott Collyer <scollyer@google.com> Reviewed-on: https://chromium-review.googlesource.com/518522 Commit-Ready: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* console: Add non-verbose print config optionShawn Nematbakhsh2017-02-111-2/+2
| | | | | | | | | | | | | | | | | Shorten certain long prints and reduce the precision of timestamp prints when CONFIG_CONSOLE_VERBOSE is undef'd. BUG=chromium:688743 BRANCH=gru TEST=On kevin, cold reset the EC, boot to OS, and verify cros_ec.log contains all data since sysjump and is < 2K bytes (~1500 bytes). Change-Id: Ia9390867788d0ab3087f827b0296107b4e9d4bca Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/438932 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* driver: bmi160: Set odr to 0 at init.Gwendal Grignou2017-01-101-0/+6
| | | | | | | | | | | | | | | | | | | | | | | When we switch to a state where the sensor is not powered, we don't call set_data_rate(0), because we may trigger an i2c/spi access to a sensor already powered off. It has the side effect to leave data->odr to the last set sensor frequency. When we init the BMI160, it starts in suspend mode. We will set it to normal mode only if data->odr is 0. Therefore, we must set odr to 0 in the init routine. BUG=chrome-os-partner:61502 BRANCH=reef,kevin TEST=On reef, without this change. When going to S5 (shutdown -h 0) and power back up, sensor is stuck (on EC, accelread 1 reads old value). With this fix, sensor is active and working. This fix a regression due to CL:411964. Check others driver do not check odr for setting suspend/normal mode. Change-Id: Ibc7519d49e55a0b43b4c12ed545bd75ab0260766 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/426766 Reviewed-by: Aaron Durbin <adurbin@chromium.org>
* motion_sense: Add "spoof" modeAseda Aboagye2017-01-071-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds a "spoof" mode feature to the motionsense stack. It allows the user to arbitrarily set the outputs of the sensor in order to "spoof" the readings of the sensor. This can be useful in emulating tablet mode or device rotations. A command is available from the EC console named `accelspoof` and there is a corresponding motionsense command in ectool called `spoof`. The usage is as follows: - EC console > accelspoof [id] [on/off] [X Y Z] - ectool # ectool motionsense spoof -- [id] [0/1] [X Y Z] If on or off(or 0/1) is not specified, the current spoof mode status of the sensor is returned. If on is specified, but no components are provided, the sensor will lock the current values and provide those as the spoofed values. If the components are provided, those will be used as the spoofed values. BUG=chromium:675263 BRANCH=cyan,glados,gru,oak TEST=Flash a DUT with accels. From AP console, run `ectool motionsense lid_angle` in a loop, use 'accelspoof' EC console command to set spoofed values. Verify that the angle is fixed regardless of the actual angle of the DUT. TEST=Flash a DUT with accels. From AP console, use `ectool motionsense spoof` to spoof values and verify that `ectool motionsense` reflects the spoofed values. Test with both provided component values and no component values. Change-Id: Ie30688d22f38054e7243b1af493a3092b2cdfb72 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/421280 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* driver: Move sensor private struture definition to boards.Gwendal Grignou2016-12-281-4/+0
| | | | | | | | | | | | | | | | sensor private structure for bmi160 and bmp280 were defined in the drivers themselves. It worked because there was only one instance of each sensors on a board. However, this is an error it should be in board files, as it was done for other sensors like the kionix. BUG=none TEST=buildall. BRANCH=kevin,reef Change-Id: Ica3aba358d141a7df9a3e97251d4c1e520cbf2c8 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/424218 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* driver: bmi160: Add temperature sensorGwendal Grignou2016-12-121-0/+16
| | | | | | | | | | | | | | | | | | | | Allow BMI160 to report temperature like other device with a temperature sensor. Temparature is returned in K. Although BMI160 resolution is 9bits per degree, we round to the nearest degree. BUG=chrome-os-partner:58894 BRANCH=reef TEST=After enabling sensor on Reef, check we can measure the temperature with EC console commands temp or from user space with 'ectool temps 3' Check 'ectool tempsinfo 3' returns valid data: Sensor name: Gyro Sensor type: 1 Change-Id: Ib48f988e078cdee1dfbc05b23df806bd4eb09931 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/416297 Reviewed-by: Scott Collyer <scollyer@chromium.org>
* driver: bmi160: Remove unnecessary delayGwendal Grignou2016-11-211-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | Rereading the specification, remove delays when not needed: - When we move the sensor out of suspend, we need to wait before using it (BMI160 spec: 2.11.38 Register (0x7E) CMD) When we do a softreset, we need just need to wait 300us for the sensor to go in suspend, we will wait only when we change the rate and enable the sensor. - The timeout at fifo flush is not needed, it was added for debugging. - Remove unnecessary printf when initializing the magnetometer. BUG=chrome-os-partner:59188 BRANCH=glados, reef, strago TEST=On reef, check the EC boot faster: time spend initializing the sensors decreased from 240ms to 133ms Change-Id: Ia80232da42aa705df819a4988da483a344ffcbb4 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/411964 Commit-Ready: David Hendricks <dhendrix@chromium.org> Tested-by: David Hendricks <dhendrix@chromium.org> Reviewed-by: David Hendricks <dhendrix@chromium.org>
* Fix various misspellings in commentsMartin Roth2016-11-151-1/+1
| | | | | | | | | | | | | No functional changes. BUG=none BRANCH=none TEST=make buildall passes Change-Id: Ie852feb8e3951975d99dce5a49c17f5f0e8bc791 Signed-off-by: Martin Roth <martinroth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/403417 Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
* driver: sensor: Remove set_interruptGwendal Grignou2016-11-081-8/+0
| | | | | | | | | | | | | | Remove set_interrupt(), was always a noop. Unused, interrupt is done inside the init routine. BUG=none BRANCH=none TEST=buildall Change-Id: I0ff4843212ea8140be41dcd17af130991117e3da Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/407968 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* driver: bmi160: Autocalibrate Accelerometer properly.Gwendal Grignou2016-11-021-1/+6
| | | | | | | | | | | | | | | Take into account the rotation matrix to do calibration. In particular the Z axis: if board is upside down, we need to use MINUS_1G instead of PLUS_1G when setting online calibration. BRANCH=kevin BUG=none TEST=Before, calibration would not work on the Z axis. Change-Id: Ifaec331aac40a4be0e34fcab5dd3752d2d59b91f Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/405854 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* driver: bmi160: Fix logic issue when accelerometer is not first sensorGwendal Grignou2016-10-071-4/+2
| | | | | | | | | | | | | | BMI160 driver assumes accel, gyro, compass are next to each other. It was also assuming accel was sensor 0, which is wrong. BUG=none BRANCH=glados TEST=On Cave, check sensors 1 (accel) and 2 (gyro) are working properly. Change-Id: I37402e1d48070caaecbd7e32bbf53754616ee8cb Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/394067 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* driver: bmi160: Add config variable for INT2 settingGwendal Grignou2016-10-071-8/+10
| | | | | | | | | | | | | | BMI INT2 can be input or output. It is not used currently, but configure it properly nevertheless. BUG=none BRANCH=none TEST=On cave, (int2 is output), ensure FIFO headers are free of interrupt information. Change-Id: I9c058689a8676593aad542e33601cc11da105838 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/394066
* i2c: Add i2ctest console commandVijay Hiremath2016-09-231-2/+14
| | | | | | | | | | | | | | | | | | Added i2ctest console command to test the reliability of the I2C. By reading/writing to the known registers this tests provides the number of successful read and writes. BUG=chrome-os-partner:57487 TEST=Enabled the i2ctest config on Reef and tested the i2c read/writes. BRANCH=none Change-Id: I9e27ff96f2b85422933bc590d112a083990e2dfb Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/290427 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* driver: bmi160: Add support bmi168Wonjoon Lee2016-05-101-1/+1
| | | | | | | | | | | | BMI168 is twins sensor with BMI160. Adding chip ID. BUG=chrome-os-partner:52844 TEST="accelread 0" is working on kevin Change-Id: Iadb5aeb9bc7be7fb2c6bc23e48ea2510b4bf84df Signed-off-by: Wonjoon Lee <woojoo.lee@samsung.com> Reviewed-on: https://chromium-review.googlesource.com/341578 Reviewed-by: Shawn N <shawnn@chromium.org>
* driver/accelgyro_bmi160.c: fix the error handle in read()james_chao2016-05-061-1/+1
| | | | | | | | | | | | | | | | | The function raw_read_n() return the status, and then check it it should be saved to the variable ret. BUG=none BRANCH=tot TEST=make buildall -j Signed-off-by: james_chao <james_chao@asus.com> Change-Id: I4d2bd200fc49892ae95c63aaeca3af75f7338bec Reviewed-on: https://chromium-review.googlesource.com/342809 Commit-Ready: BoChao Jhan <james_chao@asus.com> Tested-by: BoChao Jhan <james_chao@asus.com> Reviewed-by: BoChao Jhan <james_chao@asus.com> Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
* sensor: update sensor driver to use I2C port from motion_sensor_tKevin K Wong2016-03-311-93/+104
| | | | | | | | | | | | | this allow motion sensor devices to be locate on different I2C port BUG=none BRANCH=none TEST=make buildall Change-Id: Ia7ba2f5729ebb19561768ec87fdb267e79aafb6a Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com> Reviewed-on: https://chromium-review.googlesource.com/334269 Reviewed-by: Shawn N <shawnn@chromium.org>
* common: spi: Add a delay after write commands.Gwendal Grignou2015-11-191-0/+6
| | | | | | | | | | | | | | | Some SPI slave devices need a delay to digest write commands. (BMI160). Add a 1ms delay in the write command. BRANCH=smaug BUG=none TEST=Check on the logic analyzer that there is ~1.5ms delay between back to back spixfer w ... commands. Change-Id: I7cc6ed0da9ae39550e58457b9431eb01b5ab36d8 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/305379 Reviewed-by: Alec Berg <alecaberg@chromium.org>