summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2018-10-19 16:23:50 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-11-15 02:16:01 -0800
commit3b41a2b157de0a48160745d632163f7cc400c49b (patch)
treefefc319a4736bbc9564ac55b3fb2cdb51b5ae6b7
parent5b749cf03594ec652ad8b52e24a31db95b9d4634 (diff)
downloadchrome-ec-3b41a2b157de0a48160745d632163f7cc400c49b.tar.gz
dptf: Add support for DDPN
This change adds Device DPTF Profile Number(DDPN) to EC_ACPI_MEM_DEVICE_ORIENTATION field to indicate to host which DPTF profile should be loaded depending upon the device mode. This is done to de-couple DPTF table loading from tablet mode flag to allow different drivers within EC to set the profile number depending upon their design. In order to maintain backward compatibility, this change treats 0 as reserved to indicate to host that it should fall back to using tablet mode switch to decide which DPTF table to load. Additionally, it provides helper function to allow drivers to set the profile number that will be returned on host query for EC_ACPI_MEM_DEVICE_ORIENTATION. It also adds a new config option CONFIG_DPTF_MULTI_PROFILE that should be selected by the boards that support multiple DPTF profiles on the host side. CQ-DEPEND=CL:1295852 BUG=b:117844490 BRANCH=None TEST=make -j buildall Change-Id: Idfa0cfea48b9df346533342647258474fb63e86c Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://chromium-review.googlesource.com/1295851 Commit-Ready: Furquan Shaikh <furquan@chromium.org> Tested-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Duncan Laurie <dlaurie@google.com>
-rw-r--r--common/acpi.c51
-rw-r--r--include/acpi.h54
-rw-r--r--include/config.h15
-rw-r--r--include/ec_commands.h13
4 files changed, 130 insertions, 3 deletions
diff --git a/common/acpi.c b/common/acpi.c
index 3baad4dc4d..da6795acd9 100644
--- a/common/acpi.c
+++ b/common/acpi.c
@@ -37,6 +37,17 @@ static uint8_t __bss_slow acpi_mem_test;
#ifdef CONFIG_DPTF
static int __bss_slow dptf_temp_sensor_id; /* last sensor ID written */
static int __bss_slow dptf_temp_threshold; /* last threshold written */
+
+/*
+ * Current DPTF profile number.
+ * This is by default initialized to 1 if multi-profile DPTF is not supported.
+ * If multi-profile DPTF is supported, this is by default initialized to 2 under
+ * the assumption that profile #2 corresponds to lower thresholds and is a safer
+ * profile to use until board or some EC driver sets the appropriate profile for
+ * device mode.
+ */
+static int current_dptf_profile = DPTF_PROFILE_DEFAULT;
+
#endif
#ifdef CONFIG_USB_PORT_POWER_DUMB
@@ -81,6 +92,38 @@ static void acpi_disable_burst_deferred(void)
}
DECLARE_DEFERRED(acpi_disable_burst_deferred);
+#ifdef CONFIG_DPTF
+
+static int acpi_dptf_is_profile_valid(int n)
+{
+#ifdef CONFIG_DPTF_MULTI_PROFILE
+ if ((n < DPTF_PROFILE_VALID_FIRST) || (n > DPTF_PROFILE_VALID_LAST))
+ return EC_ERROR_INVAL;
+#else
+ if (n != DPTF_PROFILE_DEFAULT)
+ return EC_ERROR_INVAL;
+#endif
+
+ return EC_SUCCESS;
+}
+
+int acpi_dptf_set_profile_num(int n)
+{
+ int ret = acpi_dptf_is_profile_valid(n);
+
+ if (ret == EC_SUCCESS)
+ current_dptf_profile = n;
+
+ return ret;
+}
+
+int acpi_dptf_get_profile_num(void)
+{
+ return current_dptf_profile;
+}
+
+#endif
+
/* Read memmapped data, returns read data or 0xff on error. */
static int acpi_read(uint8_t addr)
{
@@ -178,7 +221,13 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
#endif
case EC_ACPI_MEM_DEVICE_ORIENTATION:
- result = tablet_get_mode();
+ result = tablet_get_mode() << EC_ACPI_MEM_TBMD_SHIFT;
+
+#ifdef CONFIG_DPTF
+ result |= (acpi_dptf_get_profile_num() &
+ EC_ACPI_MEM_DDPN_MASK)
+ << EC_ACPI_MEM_DDPN_SHIFT;
+#endif
break;
case EC_ACPI_MEM_DEVICE_FEATURES0:
diff --git a/include/acpi.h b/include/acpi.h
index 0ffc8d9f10..b966934d93 100644
--- a/include/acpi.h
+++ b/include/acpi.h
@@ -20,4 +20,58 @@
*/
int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *result);
+enum acpi_dptf_profile_num {
+ /*
+ * Value of 0 is reserved meaning the Device DPTF Profile Number in EC
+ * shared memory is invalid and host should fallback to using tablet
+ * mode switch to determine the DPTF table to load.
+ */
+ DPTF_PROFILE_INVALID = 0,
+
+#ifdef CONFIG_DPTF_MULTI_PROFILE
+ /*
+ * Set default profile value to 2 under the assumption that profile
+ * value of 1 means default high-power mode and value of 2 corresponds
+ * to a low-power mode. This value is used by ACPI routines to report
+ * back to host until appropriate EC driver updates the current profile
+ * number.
+ */
+ DPTF_PROFILE_DEFAULT = 2,
+#else
+ /* Default DPTF profile when multi-profile is not supported. */
+ DPTF_PROFILE_DEFAULT = 1,
+#endif
+
+ /* Range of valid values for DPTF profile number. */
+ DPTF_PROFILE_VALID_FIRST = 1,
+ DPTF_PROFILE_VALID_LAST = 7,
+
+ /* Standard convertible profiles */
+ DPTF_PROFILE_CLAMSHELL = 1,
+ DPTF_PROFILE_FLIPPED_360_MODE = 2,
+
+ /* Standard detachable profiles */
+ DPTF_PROFILE_BASE_ATTACHED = 1,
+ DPTF_PROFILE_BASE_DETACHED = 2,
+};
+
+/**
+ * Set current DPTF profile in EC shared memory.
+ *
+ * @param prof_num Profile number of current profile. Valid values are 1-7.
+ * See enum acpi_dptf_profile_num for standard profile
+ * numbers for convertibles/detachables.
+ * @return EC_SUCCESS if operation was successful, EC_ERROR* in
+ * case of error.
+ */
+int acpi_dptf_set_profile_num(int n);
+
+/**
+ * Get value of current DPTF profile.
+ *
+ * @return DPTF Profile number currently set to be shared with the
+ * host using EC shared memory.
+ */
+int acpi_dptf_get_profile_num(void);
+
#endif /* __CROS_EC_ACPI_H */
diff --git a/include/config.h b/include/config.h
index 4051703f99..7017a73a25 100644
--- a/include/config.h
+++ b/include/config.h
@@ -2986,6 +2986,17 @@
*/
#undef CONFIG_DPTF
+/*
+ * 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.
+ *
+ * This config can be used by any driver that does lid angle calculation or base
+ * state detection to determine if different profile numbers need to be
+ * indicated to the host.
+ */
+#undef CONFIG_DPTF_MULTI_PROFILE
+
/*****************************************************************************/
/* Touchpad config */
@@ -4120,5 +4131,9 @@
#define CONFIG_USB_PD_TCPM_ANX74XX
#endif
+#if defined(CONFIG_DPTF_MULTI_PROFILE) && !defined(CONFIG_DPTF)
+#error "CONFIG_DPTF_MULTI_PROFILE can be set only when CONFIG_DPTF is set."
+#endif /* CONFIG_DPTF_MULTI_PROFILE && !CONFIG_DPTF */
+
#endif /* __CROS_EC_CONFIG_H */
diff --git a/include/ec_commands.h b/include/ec_commands.h
index cb0bc9f62f..5508e448d3 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -328,10 +328,19 @@
/*
* Report device orientation
- * bit 0 device is tablet mode
+ * Bits Definition
+ * 3:1 Device DPTF Profile Number (DDPN)
+ * 0 = Reserved for backward compatibility (indicates no valid
+ * profile number. Host should fall back to using TBMD).
+ * 1..7 = DPTF Profile number to indicate to host which table needs
+ * to be loaded.
+ * 0 Tablet Mode Device Indicator (TBMD)
*/
#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
-#define EC_ACPI_MEM_DEVICE_TABLET_MODE 0x01
+#define EC_ACPI_MEM_TBMD_SHIFT 0
+#define EC_ACPI_MEM_TBMD_MASK 0x1
+#define EC_ACPI_MEM_DDPN_SHIFT 1
+#define EC_ACPI_MEM_DDPN_MASK 0x7
/*
* Report device features. Uses the same format as the host command, except: