diff options
author | Furquan Shaikh <furquan@google.com> | 2018-11-01 14:34:45 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-11-15 02:16:02 -0800 |
commit | 8c506ad9954b783a50d0785a117c28e3949c2695 (patch) | |
tree | d025a7042a3783e0a7e35888428a806442b9700c | |
parent | 3b41a2b157de0a48160745d632163f7cc400c49b (diff) | |
download | chrome-ec-8c506ad9954b783a50d0785a117c28e3949c2695.tar.gz |
motion_lid: Add support for setting DPTF profile based on lid angle
This change adds support in motion_lid driver to set DPTF profile
number based on the lid angle, only when:
1. CONFIG_DPTF_MULTI_PROFILE is selected by board
2. If board does not have a hall sensor to indicate completely flipped
mode. This is done by adding another new config option
CONFIG_DPTF_MOTION_LID_NO_HALL_SENSOR which will have to be selected
by boards to indicate to motion_lid driver to set DPTF profile
numbers.
BUG=b:117844490
CQ-DEPEND=CL:1295851
BRANCH=None
TEST=make -j buildall
Change-Id: If695429240e0645e3d19eeb9073bd00bac580705
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1295852
Commit-Ready: Furquan Shaikh <furquan@chromium.org>
Tested-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
-rw-r--r-- | common/motion_lid.c | 70 | ||||
-rw-r--r-- | include/config.h | 7 |
2 files changed, 76 insertions, 1 deletions
diff --git a/common/motion_lid.c b/common/motion_lid.c index cc7b098339..5d6f5ed8e7 100644 --- a/common/motion_lid.c +++ b/common/motion_lid.c @@ -5,6 +5,7 @@ /* Motion sense module to read from various motion sensors. */ +#include "acpi.h" #include "accelgyro.h" #include "chipset.h" #include "common.h" @@ -201,7 +202,68 @@ static int motion_lid_set_tablet_mode(int reliable) tablet_mode_debounce_cnt = TABLET_MODE_DEBOUNCE_COUNT; return reliable; } -#endif + +#endif /* CONFIG_LID_ANGLE_TABLET_MODE */ + +#if defined(CONFIG_DPTF_MULTI_PROFILE) && \ + defined(CONFIG_DPTF_MOTION_LID_NO_HALL_SENSOR) + +/* + * If CONFIG_DPTF_MULTI_PROFILE is defined by a board, then lid motion driver + * sets different profile numbers depending upon the current lid + * angle. Following profiles are currently supported by this driver: + * 1. Clamshell mode - DPTF_PROFILE_CLAMSHELL + * 2. 360-degree flipped mode - DPTF_PROFILE_FLIPPED_360_MODE + * + * 360-degree flipped mode is defined as the mode with base being behind the + * lid. We use 2 threshold to calculate this: + * + * 360-degree mode + * 1 | +-----<----+---------- + * | \/ /\ + * | | | + * 0 |------------------------>----+ + * +------------------+----------+----------+ lid angle + * 0 240 300 360 + */ +#define FLIPPED_360_ZONE_LID_ANGLE FLOAT_TO_FP(300) +#define CLAMSHELL_ZONE_LID_ANGLE FLOAT_TO_FP(240) + +/* + * Detection of DPTF profile is very similar to tablet mode detection using + * debounce counter. This is done to avoid any spurious changes in setting DPTF + * profile numbers. + */ +#define DPTF_MODE_DEBOUNCE_COUNT 3 + +static void motion_lid_set_dptf_profile(int reliable) +{ + static int debounce_cnt = DPTF_MODE_DEBOUNCE_COUNT; + int current_prof = acpi_dptf_get_profile_num(); + int new_prof = current_prof; + + if (reliable) { + if (last_lid_angle_fp > FLIPPED_360_ZONE_LID_ANGLE) + new_prof = DPTF_PROFILE_FLIPPED_360_MODE; + else if (last_lid_angle_fp < CLAMSHELL_ZONE_LID_ANGLE) + new_prof = DPTF_PROFILE_CLAMSHELL; + + if (current_prof != new_prof) { + if (debounce_cnt != 0) { + debounce_cnt--; + return; + } + + debounce_cnt = DPTF_MODE_DEBOUNCE_COUNT; + acpi_dptf_set_profile_num(new_prof); + return; + } + } + + debounce_cnt = DPTF_MODE_DEBOUNCE_COUNT; +} + +#endif /* CONFIG_DPTF_MULTI_PROFILE && CONFIG_DPTF_MOTION_LID_NO_HALL_SENSOR */ /** * Calculate the lid angle using two acceleration vectors, one recorded in @@ -397,6 +459,12 @@ static int calculate_lid_angle(const intv3_t base, const intv3_t lid, if (board_is_lid_angle_tablet_mode()) reliable = motion_lid_set_tablet_mode(reliable); + +#if defined(CONFIG_DPTF_MULTI_PROFILE) && \ + defined(CONFIG_DPTF_MOTION_LID_NO_HALL_SENSOR) + motion_lid_set_dptf_profile(reliable); +#endif /* CONFIG_DPTF_MULTI_PROFILE && CONFIG_DPTF_MOTION_LID_NO_HALL_SENSOR */ + #else /* CONFIG_LID_ANGLE_INVALID_CHECK */ *lid_angle = FP_TO_INT(lid_to_base_fp + FLOAT_TO_FP(0.5)); #endif diff --git a/include/config.h b/include/config.h index 7017a73a25..a4aecc1ffe 100644 --- a/include/config.h +++ b/include/config.h @@ -2987,6 +2987,13 @@ #undef CONFIG_DPTF /* + * If defined, this indicates to the motion lid driver that the board does not + * have any hall sensor and hence DPTF profile selection is required to be done + * based on lid angle. + */ +#undef CONFIG_DPTF_MOTION_LID_NO_HALL_SENSOR + +/* * If defined, device supports multiple DPTF profiles depending upon device mode * e.g. clamshell v/s 360-degree flipped mode or base detached v/s attached * mode. |