summaryrefslogtreecommitdiff
path: root/common/motion_sense.c
Commit message (Collapse)AuthorAgeFilesLines
* tablet_mode: Fix the race condition of setting the tablet modeWai-Hong Tam2021-07-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | There are 2 tablet mode triggers: * Lid: when the lid angle close to 360 degree, either detected by a GMR sensor or by the angle computed by 2 motion sensors. * Base: when the detachable base is detached. These 2 triggers set the tablet mode status, which as a boolean, resulting a race condition. This CL fixes the race condition. Each trigger updates its own bit. The final tablet mode status is the OR of all bits. BRANCH=Trogdor BUG=b:193873098 TEST=Attached the base, checked tablet_mode enabled; detached the base, checked tablet_mode disabled; flip base to 360 degree, checked tablet_mode disabled; move the base out of the lid, checked tablet_mode disabled. Change-Id: Ia9d9d2d66c194796c1039cc8b746c8d1f28a4496 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3044414 Reviewed-by: Ting Shen <phoenixshen@chromium.org>
* motion: check console task when availableTomasz Michalec2021-06-301-0/+4
| | | | | | | | | | | | | | | | motion_sense_init() checks if it was called in hooks task or console task context. In Zephyr console task is not available so TASK_ID_CONSOLE is not defined. Because of that HAS_TASK_CONSOLE is used to choose if check for hooks and console task or only for hooks task. BUG=none TEST=makeall BRANCH=none Signed-off-by: Tomasz Michalec <tm@semihalf.com> Change-Id: Ie51b043209d5228c074bbc9a693bf7b98cf2a598 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2933302 Reviewed-by: Keith Short <keithshort@chromium.org>
* common: body_detection: re-enable body_detection in S0Ching-Kang Yen2021-03-291-3/+16
| | | | | | | | | | | | | | | | | | | | The powerd will enable the body_detection once after rebooting, but not after resuming. Because we disable the body_detection in S3, we should re-enable the body_detection in S0. BRANCH=trogdor BUG=b:123434029 TEST=powerd_dbus_suspend; ectool motionsense list_activities; see if body_detection is enabled. TEST=make buildall; Signed-off-by: Ching-Kang Yen <chingkang@chromium.org> Change-Id: Idb06888d9b4ec0eca994201f7fbd646f37c2c371 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2752573 Commit-Queue: Ching-Kang Yen <chingkang@chromium.org> Tested-by: Ching-Kang Yen <chingkang@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* common: motion_sense: Prevent on/off body from waking up deviceGwendal Grignou2021-03-291-6/+8
| | | | | | | | | | | | | | | | | | | | Introduce a new flag: BYPASS_FIFO to raise an interrupt to the AP when an event is sent. It is not as strong as WAKEUP, as it does not wake up the AP. BYPASS_FIFO must be set when WAKEUP is set. It is applied to sync sensor as well as gesture/activity sensor. BUG=b:123434029 BRANCH=trogdor TEST=Compile Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: Id5aba71e6d11ef31f7fa2c67ba2e07178d088b1b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2780834 Reviewed-by: Ching-Kang Yen <chingkang@chromium.org> Tested-by: Ching-Kang Yen <chingkang@chromium.org> Commit-Queue: Ching-Kang Yen <chingkang@chromium.org>
* common: motion: fix races at shutdownGwendal Grignou2021-02-131-7/+10
| | | | | | | | | | | | | | | | | | | Do not use collection_rate blindly after a function may have slept: the HOOK task could have run suspend() or suspend() call and set it to 0. Fixes 104f5257 ("motion: Control on which task sensor setting functions are running on") [CL:2553347] BUG=b:176918310, b:170703322 BRANCH=kukui TEST=unit test. Change-Id: I9ef13ceca195db4b48866f1e53f9408fb2bbf595 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2616137 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* common: motion: move read fifo console commandGwendal Grignou2021-01-291-32/+0
| | | | | | | | | | | | | | Move command in _fifo.c, as the fifo data structure is a static in this file. BUG=none BRANCH=none TEST=Add CONFIG_CMD_ACCEL_FIFO to baseboard volteer, check it compiles. Change-Id: I6f9efafeaf450309ce48182396f3398fa4276d46 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2485909 Reviewed-by: Yuval Peress <peress@chromium.org>
* zephyr: add motion sense supportHyungwoo Yang2021-01-221-1/+13
| | | | | | | | | | | | | | | | | | | Add support for motion sense in zephyr. This change adds basic functions for motion sense task to do meaningful work. sensor_map.h included by board.h will be used to get board specific sensor configuration. BUG=b:173507858 BRANCH=none TEST=make buildall -j8 build volteer on zephyr Signed-off-by: Hyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com> Change-Id: I906316d2e97428cf46b9a15071666c8e3b039b18 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2638909 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org> Tested-by: Jack Rosenthal <jrosenth@chromium.org>
* task_set_event: remove the wait argumentDawid Niedzwiecki2020-12-141-5/+5
| | | | | | | | | | | | | | | | | | | | There is an option in the task_set_event function which force the calling task to wait for an event. However, the option is never used thus remove it. This also will help in the Zephyr migration process. BUG=b:172360521 BRANCH=none TEST=make buildall Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: Ic152fd3d6862d487bcc0024c48d136556c0b81bc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2521599 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
* ec_commands: add struct ec_response_activity_dataChing-Kang Yen2020-12-111-7/+12
| | | | | | | | | | | | | | Add struct ec_response_activity_data to handle activity data in include/ec_commands.h. BRANCH=None BUG=b:169374265 TEST=make buildall Signed-off-by: Ching-Kang Yen <chingkang@chromium.org> Change-Id: I5f40d45d656ae91acc6e9364261c548f302383ae Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2581708 Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* motion: Control on which task sensor setting functions are running onGwendal Grignou2020-12-011-31/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Analysis of motionsense shutdown revealed a race condition, as function that change sensor state can run on parallel tasks, namely CHIPSET and HOOK: motion_sense_shutdown (CHIPSET) ---> (motion_sense_switch_sensor_rate) suspend/resume (HOOK) ----> (motion_sense_switch_sensor_rate) motion_sense_process (MOTIONSENSE) ---> motion_sense_set_data_rate (ACTIVE) \-> motion_sense_set_motion_intervals /----------- motion_sense_init --\ | | motion_sense_switch_sensor_rate ---> motion_sense_set_data_rate (ACTIVE) | \----------- sensor->collection_rate = odr...; (ACTIVE) \------------> sensor->collection_rate = 0; (INACTIVE) \-----------> motion_sense_set_motion_intervals Running motion_sense_switch_sensor_rate() on HOOK task is necessary because on some platform, the power line may be already off, when the device is going to S5. - Always run motion_sense_switch_sensor_rate() on hook. - When changing ODR is needed (sensor active), schedule MOTIONSENSE task. The new sequencing is simplified: suspend/resume/shutdown (HOOK) ----> (motion_sense_switch_sensor_rate) /----------- motion_sense_init --\ | | motion_sense_switch_sensor_rate ---> schedule MOTIONSENSE. \------------> sensor->collection_rate = 0; (INACTIVE) motion_sense_process (MOTIONSENSE) ---> motion_sense_set_data_rate (ACTIVE) \-> motion_sense_set_motion_intervals BUG=b:170703322 BRANCH=kukui TEST=Check on Volteer the sequence at suspend/resume/shutdown. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: I0238cae9b4720e487a1e70788296a4db1b1e186b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2553347 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* motion_sense: Stop collection when sensor is powered downGwendal Grignou2020-12-011-5/+12
| | | | | | | | | | | | | | | | | Set collection_rate to 0 when sensor is not in initialized state anymore. It will prevent the motion_sense task to be neededlessly scheduled. Export wait_us to be tested. BUG=b:170703322 BRANCH=kukui TEST=unit test Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: I1dc4c7a07ff30fa10997ef87784114c725f100d5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2520297 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Chen-Tsung Hsieh <chentsung@chromium.org> Reviewed-by: Yuval Peress <peress@chromium.org>
* common: motion_sense: Add spoofing activityChing-Kang Yen2020-11-131-0/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | make spoof command able to spoof activity state: ectool motionsense spoof -- NUM activity ACT [EN] [0/1] This commit also remove unused parameter |sensor_num| from list_activities, set_activity, get_activity in ectool. BRANCH=None BUG=b:123434029 TEST=buildall TEST=ectool motionsense spoof 4 activity 4 1 0 ectool motionsense spoof 4 activity 4 ectool motionsense get_activity 4 ectool motionsense spoof 4 activity 4 1 1 ectool motionsense get_activity 4 ectool motionsense spoof 4 activity 4 0 ectool motionsense get_activity 4 ectool motionsense spoof 4 activity 4 1 ectool motionsense get_activity 4 Signed-off-by: Ching-Kang Yen <chingkang@chromium.org> Change-Id: I819c156ae7fe50c5cf6216d0f44012d192fb528e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2477393 Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* motion_sense: Make change in range permanentGwendal Grignou2020-11-121-13/+16
| | | | | | | | | | | | | | | | | | | | | | | | | When AP changes range, unlike offset or ODR, it was not surviving init() call. If the sensor is powered off in S3, at resume the range would be back to the default. To make it consistent with other attributes, remember range change until EC powers down. - remove get_range - add current_range to store the range currently used. This is modifiable by the AP - when the AP shutdown, revert current_range to default_range - Remove const attribute for sensor structure when init and set_range is called. BUG=chromium:1083791 BRANCH=none TEST=One eve branch, check range is preserved even after 'shutdown -h 0' Change-Id: Ia7126ac0cc9c3fef60b4464d95d6dd15e64b0fc4 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2215751 Reviewed-by: Yuval Peress <peress@chromium.org>
* Revert "motion_sense: set sensor data rate to 0, when sensors are being ↵Gwendal Grignou2020-11-061-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | powered off" We can not change the ODR when the sensors are marked as not active. They may not be powered on and can not be touched. This reverts commit 89b87b5004252bd6f6fa6c019a63a4a1dd157600. Reason for revert: <INSERT REASONING HERE> Original change's description: > motion_sense: set sensor data rate to 0, when sensors are being powered off > > when sensors are being powered off, we should set sensor data rate to 0, > to prevent the motion sense task from being unable to enter the idle > state because the collect rate is not equal to 0. > > BUG=b:170703322 > BRANCH=master > TEST=make buildall pass, and test cerise power consumption meet spec in > DC S5 state > > Signed-off-by: Mike Lee <mike5@huaqin.corp-partner.google.com> > Change-Id: Iae66f87aee1889b460fd598b1962be658c74ddab > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2505392 > Reviewed-by: Cheng-Hao Yang <chenghaoyang@chromium.org> > Reviewed-by: Ting Shen <phoenixshen@chromium.org> BRANCH=master BUG=b:170703322 TEST=compile Change-Id: Ieb8566614249fc2efdce5993291ceb98bab429f8 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2519428
* common: motion: add IF_ENABLED()Gwendal Grignou2020-11-061-237/+205
| | | | | | | | | | | | | | | Split some defines when necessary, add IF_ENABLED to common/motion_sense.c. Find small setting errors in some boards along the way. BUG=chromium:1140877 BRANCH=none TEST=buildall Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: I77ff528a16809088a986a2cc707aff8ae7df3906 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2488939 Reviewed-by: Ching-Kang Yen <chingkang@chromium.org>
* motion: Use empty CONFIG_ variable to use IS_ENABLED()Gwendal Grignou2020-11-061-2/+2
| | | | | | | | | | | | | | | | Split information in a boolean variable and another variable that contains a property. For instance, CONFIG_GESTURE_SENSOR_DOUBLE_TAP becomes: CONFIG_GESTURE_SENSOR_DOUBLE_TAP : boolean variable CONFIG_GESTURE_TAP_SENSOR : property that contains the sensor number. BUG=chromium:1140877 BRANCH=none TEST=buildall Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: I27ba462f8a12b14882104b9f983f2dc17f917314 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2488937
* motion: orientation: update interfaceGwendal Grignou2020-11-061-43/+15
| | | | | | | | | | | | | | Enabling orientation sensor would not compile anymore. Fix interface by replacing macros with functions. BUG=chromium:718919 BRANCH=none TEST=Compile when enabled on grunt and eve. Change-Id: Ic5d6992d040cde79ef3f691db494804e160b7650 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2491266 Reviewed-by: Ching-Kang Yen <chingkang@chromium.org>
* motion_sense: set sensor data rate to 0, when sensors are being powered offMike Lee2020-11-041-1/+3
| | | | | | | | | | | | | | | | | when sensors are being powered off, we should set sensor data rate to 0, to prevent the motion sense task from being unable to enter the idle state because the collect rate is not equal to 0. BUG=b:170703322 BRANCH=master TEST=make buildall pass, and test cerise power consumption meet spec in DC S5 state Signed-off-by: Mike Lee <mike5@huaqin.corp-partner.google.com> Change-Id: Iae66f87aee1889b460fd598b1962be658c74ddab Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2505392 Reviewed-by: Cheng-Hao Yang <chenghaoyang@chromium.org> Reviewed-by: Ting Shen <phoenixshen@chromium.org>
* Replace I2C_GET_ADDR with I2C_STRIP_FLAGSYuval Peress2020-11-021-1/+1
| | | | | | | | | | | | | | | | | The new I2C_STRIP_FLAGS macro was added to avoid conflict with Zephyr's macro. This CL performs the migration to that new API. BRANCH=none BUG=b:172067439 TEST=make runtests -j and built for various boards: eve, volteer, arcada_ish, atlas, hatch, kohaku, nocturne, samus, and scarlet Change-Id: I0583b647435db96ec268f186252b367bdc4118a6 Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2511097 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
* atomic: rename atomic_read_clear to atomic_clearDawid Niedzwiecki2020-11-021-2/+2
| | | | | | | | | | | | | | | | | Rename atomic_read_clear to atomic_clear to be consistent with the rest of the atomic functions, which return the previous value of the variable. BUG=b:169151160 BRANCH=none TEST=buildall Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I2588971bd7687879a28ec637cf5f6c3d27d393f4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2505143 Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* tree: Use new atomic_* implementationDawid Niedzwiecki2020-10-271-10/+7
| | | | | | | | | | | | | | | | | | | | | | | It is done as a part of porting to Zephyr. Since the implementation of atomic functions is done for all architectures use atomic_* instead of deprecated_atomic_*. Sometimes there was a compilation error "discards 'volatile' qualifier" due to dropping "volatile" in the argument of the functions, thus some pointers casts need to be made. It shouldn't cause any issues, because we are sure about generated asm (store operation will be performed). BUG=b:169151160 BRANCH=none TEST=buildall Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I98f590c323c3af52035e62825e8acfa358e0805a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2478949 Tested-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
* common: online_calibration: Fix compilation issueGwendal Grignou2020-10-201-3/+1
| | | | | | | | | | | | | | | | | - Fix compilation error: sizeof() of an input array was not calculated properly. - Fix calling convention: use sensor pointer instead of sensor number - Use common formula to calculate sensor number. BUG=none BRANCH=none TEST=compile, unittest, load on eve with online calibration added. Change-Id: I06ff30eb5710cbe8f91c939b2ccc084c20a37847 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2486304 Reviewed-by: Yuval Peress <peress@chromium.org>
* tree: rename atomic_* functions to deprecated_atomic_*Jack Rosenthal2020-09-291-8/+10
| | | | | | | | | | | | | | | | We will move to an API compatible with Zephyr's API. See the bug for complete rationale and plan. BUG=b:169151160 BRANCH=none TEST=buildall Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Id611f663446abf00b24298a669f2ae47fef7f632 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2427507 Tested-by: Dawid Niedźwiecki <dn@semihalf.com> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* common: implement body_detection state machineChing-Kang Yen2020-09-031-9/+66
| | | | | | | | | | | | | | | | | | | | | Implement body_detection state machine. Detect whether the user is close to the devices or not. Use the variance of acceleration from accelerometer to compute the motion confidence. If motion confidence is high enough, set the motion state to ON_BODY. If low enough, set it to OFF_BODY. Also, make gesture_cal() be called only when the gesture sensor data is updated. BRANCH=None BUG=b:123434029 TEST=make buildall, flash the ec, watch the ec console log Change-Id: If886b7f9fc505ef4db4d7abb08194b8f866121bb Signed-off-by: Ching-Kang Yen <chingkang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2230938 Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* motion_sense: use clamp functions in sending 32bit sensor valuesIkjoon Jang2020-09-021-13/+15
| | | | | | | | | | | | | | | | | | | Apply 32bit clamp functions in sending 32bit sensor values to host. Clamp functions explicitly clamp values into 16bit ec protocol regarding its sensor type. Clamp functions take its sensor type as an argument and clamp 32bit value into 0~65535 for light sensors and -32768 ~ 32767 for all other motion sensors. BUG=b:144002158 TEST=Reading illuminance values in kukui kernel BRANCH=none Signed-off-by: Ikjoon Jang <ikjn@chromium.org> Change-Id: I977114e26f28e7806c11b0a97c9edec7a84ea0dc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2328951 Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* motion_sense: hold 'ready_status' until next lid angle calculationInno.Park2020-05-291-3/+4
| | | | | | | | | | | | | | | | | | | | Current motionsense task clears the variable ready_status every event loop. In the case that all of two accels work on interrupt mode, no lid angle calculation until next polling event of the third sensor. So it might cause a tablet mode transition to take quite long. *delay = (TABLET_MODE_DEBOUNCE_COUNT + 1) x (collection_rate of the 3rd sensor) BUG=b:154299214 BRANCH=none TEST=build EC, flash 'ec.bin' and boot device. check a tablet mode transition time. Change-Id: I7882730df373dfb5164fb622fe939b6e70b738e0 Signed-off-by: Inno.Park <ih.yoo.park@samsung.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2217609 Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Bob Moragues <moragues@chromium.org>
* common: motion_sense: implement AP command to read dirty calibrationYuval Peress2020-03-111-0/+17
| | | | | | | | | | | | BRANCH=None BUG=b:138303429,chromium:1023858 TEST=buildall Change-Id: I857dbc0975a239a6d8419015d8b9e34415b477cf Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2044702 Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Commit-Queue: Gwendal Grignou <gwendal@chromium.org>
* ec_commands.h: add info_4 in sensor request structureGwendal Grignou2020-03-071-1/+1
| | | | | | | | | | | | | Fixes: 267da3cfc ("common: Add feature flag for online calibration") BUG=chromium:1023858 TEST=compile BRANCH=none Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: I7e7784e509062f28c8dc12d52fe8daed2ab73b23 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2084398 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* motion_sense: simple typo correction (CONIFG_ -> CONFIG)Jack Rosenthal2020-03-031-1/+1
| | | | | | | | | | | BUG=none TEST=none BRANCH=none Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: If62d1c4dc74000c1a4bd021c0c42e7bd2371ac81 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2083584 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* common: Migrate online calibration to own moduleYuval Peress2020-02-131-0/+2
| | | | | | | | | | | | | | | This change moves the code that handles caching the temperature (which is the first step in online calibration) into a new compilational unit. TEST=None BRANCH=None BUG=b:138303429,chromium:1023858 Change-Id: Ib1fe3d2234dc2436e2bbfd4febd22196e5cdafef Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1906340 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* common/motion_sense: finish change that change ODR in motion taskGwendal Grignou2020-01-131-0/+3
| | | | | | | | | | | | | | | Forgot to change odr_event_required in the console command accelrate. Fixup of crrev.com/c/1470772 BUG=b:111422556,chromium:562245,b:124085261 BRANCH=none TEST=Using accelrate ID ODR 1 change the ODR on sensor ID. Change-Id: I62b5d4b120e212ad74c976923270f29176266870 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1992840 Reviewed-by: Yuval Peress <peress@chromium.org>
* common: motion_sense_fifo: Read temperature on stageYuval Peress2020-01-111-1/+3
| | | | | | | | | | | | | | | | Assuming online calibration is enabled, and the driver implements the get_temp function. When a driver stages data, if this is the first staged sample, read the current internal sensor temperature and cache it (will later be used in commit_data()). BUG=b:138303429,chromium:1023858 BRANCH=None TEST=buildall Change-Id: I8e5404e628d3e8ded7c2d75b1b5cbac8166e97aa Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1867225 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* common: Add feature flag for online calibrationYuval Peress2019-12-191-5/+12
| | | | | | | | | | | | | | | This change adds a feature flag for online calibration. BUG=b:138303429,chromium:1023858 BRANCH=None TEST=buildall since flag is not yet used Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I3036371a7499bf0eaf0846ff07eec6e6ee18a391 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1834021 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Yuval Peress <peress@chromium.org> Tested-by: Yuval Peress <peress@chromium.org>
* Clean up double tap related definitionHeng-Ruey Hsu2019-11-131-4/+4
| | | | | | | | | | | | | | | | Fixes: commit 2f2a81079191ca "Add double tap and make motion sense wake up ap" CONFIG_GESTURE_DETECTION_MASK includes significant motion in activity list. We cannot use it for double tap. Add more flags to distinguish it. BUG=b:135575671 BRANCH=kukui TEST=AP can receive mkbp event when double tap is triggered Change-Id: I13776a01b14dc251396a615c8c97353f2d0477d4 Signed-off-by: Heng-Ruey Hsu <henryhsu@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1911263 Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* common: Refactor motion_sense_fifoYuval Peress2019-11-111-27/+17
| | | | | | | | | | | | | | | | | This change refactors the motion_sense_fifo to uniformly prefix all the functions to avoid collisions. It also adds several unit tests and fixes a few bugs with the fifo logic. BUG=b:137758297 BRANCH=kukui TEST=buildall TEST=run CTS on arcada, kohaku, and kukui TEST=boot kohaku (verify tablet mode works as expected) Change-Id: I6e8492ae5fa474d0aa870088ab56f76b220a73e3 Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1835221 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* Add double tap and make motion sense wake up apHeng-Ruey Hsu2019-11-111-1/+5
| | | | | | | | | | | | | | | Change to use CONFIG_GESTURE_DETECTION_MASK since CONFIG_GESTURE_SENSOR_BATTERY_TAP and CONFIG_GESTURE_SENSOR_DOUBLE_TAP both define it. BUG=b:135575671 BRANCH=none TEST=build pass. EC can receive double tap interrupt. Change-Id: I6eec40ef7405ec0653ff62dbce98f975cb19e332 Signed-off-by: Heng-Ruey Hsu <henryhsu@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1710210 Reviewed-by: Jett Rink <jettrink@chromium.org>
* common: motion_sense: Refactor common code out of event processYuval Peress2019-10-161-50/+48
| | | | | | | | | | | | | Refactor motion_sense_process to include less repeated code. TEST=buildall and run on Kohaku BUG=None BRANCH=None Change-Id: I2e5af84f20cc7e50d3ddfb39d661238643aa99b3 Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1856828 Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* Remove uses of %lEvan Green2019-10-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | This change removes uses of %l from the EC side of the EC codebase. This is done because the semantics of %l within printf have changed, and there are concerns that new calls to printf will be cherry-picked into old firmware branches without the printf changes. So, in preparation for disallowing %l in master, remove occurrences of %l. This change was done by manually fixing up anything found under the EC directory with the following regex: %[0-9*.-]*l[^l] Remember that anything on the host machine is fine as-is, since the host printf never changed. BUG=chromium:984041 TEST=make -j buildall BRANCH=None Change-Id: I2a97433ddab5bfb8a6031ca4ff1d3905289444e2 Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1834603 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* include: De-longify BIT() macroEvan Green2019-10-051-3/+3
| | | | | | | | | | | | | | | | | | | | | | | The BIT() macro was recently introduced to make things more comfortable to upstream Linux. However, there's no need for it to be a long. Change the macro back to being an int (int and long are the same on 32-bit platforms, which all of our ECs are), so that we can reduce the number of %l specifiers. The semantics of %l have changed, we are deprecating its use on master to reduce the risk that we accidentally cherry-pick one of those printfs to an old firmware branch. BUG=chromium:984041 TEST=make -j buildall BRANCH=None Change-Id: I95b9cd49895cc67998dcb1de9bab5b5591d93243 Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1834601 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: caveh jalali <caveh@chromium.org>
* printf: Fix formatting errorsEvan Green2019-10-051-3/+3
| | | | | | | | | | | | | | | | | | | This change fixes the printf formatting errors found by the compile-time prinf format checker. The errors fall into a few categories: 1. Incorrect size specifier (missing or extra l). 2. Missing or extra arguments. 3. Bad line splitting. BUG=chromium:984041 TEST=make -j buildall BRANCH=none Change-Id: I5618097a581210b9fcbfc81560dec050ae30b61c Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1819653 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* printf: Convert %T to %pTEvan Green2019-10-051-1/+2
| | | | | | | | | | | | | | | | | | | | | | In order to be more compliant to standards, and ultimately turn on compile-time printf format validation, switch the non-standard %T into %pT, which takes a pointer to a 64-bit timestamp as an argument. For convenience, define PRINTF_TIMESTAMP_NOW, which will use the current time as the timestamp value, rather than forcing everyone to pass a pointer to get_time().val. For a couple of instances, simply use CPRINTS instead. BUG=chromium:984041 TEST=make -j buildall BRANCH=None Cq-Depend:chrome-internal:1473305 Change-Id: I83e45b55a95ea27256dc147544ae3f7e39acc5dd Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704216 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* Revert "common: Refactor motion_sense_fifo"Scott Collyer2019-10-021-62/+76
| | | | | | | | | | | | | | | | | | | | | | This reverts commit 36b47ab3c06e477f5e95d6d9e84a5220248784e6. With this CL the lid angle calculation on hatch devices reports 500 which is what's used for can't caluclate a meaninfgul value. BUG=b:141840539 BRANCH=None TEST=On helios tested with this CL and saw that lid angle calculations returned 500 for lid angle. Then reverted the CL and verifed that lid angle calculations were correct. Used 'accelinfo on 10000' to check the EC reported lid angle. Change-Id: Id4e36219792d00357d2885e9944c58fe0e15c5ca Signed-off-by: Scott Collyer <scollyer@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1834705 Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Yuval Peress <peress@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org> Commit-Queue: Scott Collyer <scollyer@chromium.org>
* host_command: Change host command return value to enum ec_statusTom Hughes2019-10-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the host command handler callback function returns an int, it's easy to accidentally mix up the enum ec_error_list and enum ec_status types. The host commands always expect an enum ec_status type, so we change the return value to be of that explicit type. Compilation will then fail if you accidentally try to return an enum ec_error_list value. Ran the following commands and then manually fixed up a few remaining instances that were not caught: git grep --name-only 'static int .*(struct host_cmd_handler_args \*args)' |\ xargs sed -i 's#static int \(.*\)(struct host_cmd_handler_args \*args)#\ static enum ec_status \1(struct host_cmd_handler_args \*args)##' git grep --name-only 'int .*(struct host_cmd_handler_args \*args)' |\ xargs sed -i 's#int \(.*\)(struct host_cmd_handler_args \*args)#\ enum ec_status \1(struct host_cmd_handler_args \*args)##' BRANCH=none BUG=chromium:1004831 TEST=make buildall -j Cq-Depend: chrome-internal:1872675 Change-Id: Id93df9387ac53d016a1594dba86c6642babbfd1e Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1816865 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* common: Refactor motion_sense_fifoYuval Peress2019-09-271-76/+62
| | | | | | | | | | | | | | | This change refactors the motion_sense_fifo to uniformly prefix all the functions to avoid collisions. It also adds several unit tests and fixes a few bugs with the fifo logic. BUG=b:137758297 BRANCH=None TEST=buildall & run CTS on arcada Change-Id: I7aae45382b07d6c8858e07215c33e710c7ed27ec Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704166 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* config: Refactor CONFIG_ACCEL_FIFO to enable use of IS_ENABLEDYuval Peress2019-09-031-74/+77
| | | | | | | | | | | | | | | This change allows us to use the IS_ENABLED condition to replace the various ifdef guards around the CONFIG_ACCEL_FIFO BUG=b:137758297,chromium:981990 BRANCH=None TEST=buildall and CTS tests on Arcada Change-Id: I65d36bac19855e51c830a33e6f3812575e8d15d9 Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704164 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* common: Move fifo logic out of motion_sense.cYuval Peress2019-08-231-407/+2
| | | | | | | | | | | | | | | | | | | | This change is needed to allow better testing of the fifo behavior. Additionally, motion_sense_fifo.c will only be compiled if CONFIG_ACCEL_FIFO is defined. This behaviour requires a few small changes to several boards and baseboards to make sure that we only define CONFIG_ACCEL_FIFO when the MOTIONSENSE task is present (some times that may be only in one section RW or RO). BUG=b:137758297 BRANCH=None TEST=buildall and ran CTS on arcada Change-Id: I2f7e4e436ba9568a35b7a0b2c8d53a73f198ba73 Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704163 Reviewed-by: Alexandru M Stan <amstan@chromium.org> Commit-Queue: Alexandru M Stan <amstan@chromium.org>
* driver: Add support for calibration modeGwendal Grignou2019-07-241-5/+6
| | | | | | | | | | | | | | | | | For TCS3400, performing calibration is not just a one-shot event: The RBG sensor stays in calibration mode: returns raw value in R, G, B space. When out of calibration, it returns light information in X, Y and Z space. BUG=b:124512628 BRANCH=hatch,flapjack TEST=unit test Change-Id: I6766907054c8e79a3cbcb629ef91a0967ea0780a Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1702543 Reviewed-by: Nick Vaccaro <nvaccaro@google.com>
* Remove __7b, __8b and __7bfDenis Brockus2019-07-201-2/+2
| | | | | | | | | | | | | | | | | | | The extentions were added to make the compiler perform most of the verification that the conversion was being done correctly to remove 8bit addressing as the standard I2C/SPI address type. Now that the compiler has verified the code, the extra extentions are being removed BUG=chromium:971296 BRANCH=none TEST=make buildall -j TEST=verify sensor functionality on arcada_ish Change-Id: I36894f8bb9daefb5b31b5e91577708f6f9af2a4f Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704792 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* Use 7bit I2C/SPI slave addresses in ECDenis Brockus2019-07-191-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Opt for 7bit slave addresses in EC code. If 8bit is expected by a driver, make it local and show this in the naming. Use __7b, __7bf and __8b as name extensions for i2c/spi addresses used in the EC codebase. __7b indicates a 7bit address by itself. __7bf indicates a 7bit address with optional flags attached. __8b indicates a 8bit address by itself. Allow space for 10bit addresses, even though this is not currently being used by any of our attached devices. These extensions are for verification purposes only and will be removed in the last pass of this ticket. I want to make sure the variable names reflect the type to help eliminate future 7/8/7-flags confusion. BUG=chromium:971296 BRANCH=none TEST=make buildall -j Change-Id: I2fc3d1b52ce76184492b2aaff3060f486ca45f45 Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1699893 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* motionsense: remove panicJett Rink2019-06-271-3/+9
| | | | | | | | | | | | | | | | | Remove a panic that should never happen. If there was a bug to make the EC go down that code path, it seems better to log and error about motion sense than take down the entire system with an EC panic. BRANCH=none TEST=builds BUG=none Change-Id: I6231b0b2bf14f9bcb3701040d0844f765d5637ad Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1678254 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>