diff options
author | Andrew McRae <amcrae@google.com> | 2022-12-15 21:16:00 +1100 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-02-13 22:42:50 +0000 |
commit | f975d4f4f5614cbc3b0f2f4e43b476abb1c163c1 (patch) | |
tree | 947e9679c2506f67ae15aeb324734c1720d47920 | |
parent | fee6bafd64b4d80e9fc7d2123a6adbb47533d8a3 (diff) | |
download | chrome-ec-f975d4f4f5614cbc3b0f2f4e43b476abb1c163c1.tar.gz |
keyboard: Wake up key scanner only if there are changesfirmware-guybrush-14500.B-main
When enabling or disabling the key scanning,
wake up the key scanning task only if there has been
a change to the disable mask.
Sources such as lid angle calculations were calling
keyboard_scan_enable() continually because of the
sensor polling, which was unnecessarily waking up
the task (once awake, the task would scan the matrix
for maybe 100ms before switching back to interrupt detection).
BUG=b:262685673 b:253069581
TEST=Confirm on Nereid that task is not awoken
BRANCH=none
Change-Id: I4a069c67b244a9fc0a40d1af18f491dac3b6d024
Signed-off-by: Andrew McRae <amcrae@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4110251
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
(cherry picked from commit 37c75ac808dc857dc87a44b34419af590c7f8416)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4235982
Commit-Queue: Chris Gerber <gerb@google.com>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Tested-by: Boris Mittelberg <bmbm@google.com>
-rw-r--r-- | common/keyboard_scan.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/common/keyboard_scan.c b/common/keyboard_scan.c index 8ec7d5d3d2..7bebac8481 100644 --- a/common/keyboard_scan.c +++ b/common/keyboard_scan.c @@ -6,6 +6,7 @@ /* Keyboard scanner module for Chrome EC */ #include "adc.h" +#include "atomic_bit.h" #include "chipset.h" #include "clock.h" #include "common.h" @@ -139,16 +140,21 @@ static int keyboard_scan_is_enabled(void) void keyboard_scan_enable(int enable, enum kb_scan_disable_masks mask) { + atomic_val_t old; /* Access atomically */ if (enable) { - atomic_clear_bits((atomic_t *)&disable_scanning_mask, mask); + old = atomic_clear_bits((atomic_t *)&disable_scanning_mask, + mask); } else { - atomic_or((atomic_t *)&disable_scanning_mask, mask); + old = atomic_or((atomic_t *)&disable_scanning_mask, mask); clear_typematic_key(); } - /* Let the task figure things out */ - task_wake(TASK_ID_KEYSCAN); + /* Using atomic_get() causes build errors on some archs */ + if (old != disable_scanning_mask) { + /* If the mask has changed, let the task figure things out */ + task_wake(TASK_ID_KEYSCAN); + } } /** |