summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/motion_lid.c70
-rw-r--r--include/config.h7
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.