From 9d8f28dd760f4f0e68ed3746bb9e50dc31687859 Mon Sep 17 00:00:00 2001 From: Ting Shen Date: Mon, 29 Mar 2021 07:37:06 +0000 Subject: Revert "touchpad_elan: implement sleep mode" This reverts commit 1e86df339d40526911ebea45530b20c36be47a5d. Reason for revert: b/176137996#comment65 Original change's description: > touchpad_elan: implement sleep mode > > Implement sleep mode to save S3 power. After this patch, the touchpad > enters sleep mode when suspend with lid opened. > > Also did some refactor but the logic doesn't change > > BUG=b:176137996 > TEST=tested following scenarios: > 1) suspend when lid open > 2) lid close > 3) hammer reboot > verify that power/sleep state are configured correctly > BRANCH=trogdor > > Signed-off-by: Ting Shen > Change-Id: I0742460ef5d3ec34c6bf16ee4a02a87966069087 > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2752530 > Reviewed-by: Nicolas Boichat > Commit-Queue: Ting Shen > Tested-by: Ting Shen Bug: b:176137996 Change-Id: I0be526ee74b127b7a3ef901b885d825f2356d0c0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2789781 Auto-Submit: Ting Shen Reviewed-by: Ting Shen Commit-Queue: Ting Shen Commit-Queue: Rubber Stamper Tested-by: Ting Shen Bot-Commit: Rubber Stamper --- driver/touchpad_elan.c | 65 +++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 41 deletions(-) (limited to 'driver') diff --git a/driver/touchpad_elan.c b/driver/touchpad_elan.c index 1501e1fb67..d2e28d53a6 100644 --- a/driver/touchpad_elan.c +++ b/driver/touchpad_elan.c @@ -141,18 +141,18 @@ static int elan_tp_write_cmd(uint16_t reg, uint16_t val) buf, sizeof(buf), NULL, 0); } -static bool elan_tp_power = true; -static bool elan_tp_sleep; +/* Power is on by default. */ +static int elan_tp_power = 1; -static int elan_tp_power_enable(bool enable) +static int elan_tp_set_power(int enable) { int rv; uint16_t val; - if (elan_tp_power == enable) + if ((enable && elan_tp_power) || (!enable && !elan_tp_power)) return EC_SUCCESS; - CPRINTS("tp power: %d", enable); + CPRINTS("elan TP power %s", enable ? "on" : "off"); rv = elan_tp_read_cmd(ETP_I2C_POWER_CMD, &val); if (rv) @@ -170,19 +170,6 @@ out: return rv; } -static int elan_tp_sleep_enable(bool sleep) -{ - if (elan_tp_sleep == sleep) - return EC_SUCCESS; - - CPRINTS("tp sleep: %d", sleep); - - elan_tp_sleep = sleep; - - return elan_tp_write_cmd(ETP_I2C_STAND_CMD, - sleep ? ETP_I2C_SLEEP : ETP_I2C_WAKE_UP); -} - static int finger_status[ETP_MAX_FINGERS] = {0}; /* @@ -431,8 +418,6 @@ static void elan_tp_init(void) gpio_enable_interrupt(GPIO_TOUCHPAD_INT); out: - elan_tp_power = true; - elan_tp_sleep = false; CPRINTS("%s:%d", __func__, rv); return; @@ -803,23 +788,24 @@ void touchpad_interrupt(enum gpio_signal signal) /* Make a decision on touchpad power, based on USB and tablet mode status. */ static void touchpad_power_control(void) { - if (IS_ENABLED(CONFIG_TABLET_MODE) && tablet_get_mode()) { - /* power off */ - elan_tp_power_enable(false); - } else if (IS_ENABLED(CONFIG_USB_SUSPEND) && usb_is_suspended()) { - if (usb_is_remote_wakeup_enabled()) { - /* sleep */ - elan_tp_power_enable(true); - elan_tp_sleep_enable(true); - } else { - /* power off */ - elan_tp_power_enable(false); - } - } else { - /* power on */ - elan_tp_power_enable(true); - elan_tp_sleep_enable(false); - } + static int enabled = 1; + int enable = 1; + +#ifdef CONFIG_USB_SUSPEND + enable = enable && + (!usb_is_suspended() || usb_is_remote_wakeup_enabled()); +#endif + +#ifdef CONFIG_TABLET_MODE + enable = enable && !tablet_get_mode(); +#endif + + if (enabled == enable) + return; + + elan_tp_set_power(enable); + + enabled = enable; } void touchpad_task(void *u) @@ -832,11 +818,8 @@ void touchpad_task(void *u) while (1) { event = task_wait_event(-1); - if (event & TASK_EVENT_WAKE) { - elan_tp_power_enable(true); - elan_tp_sleep_enable(false); + if (event & TASK_EVENT_WAKE) elan_tp_read_report_retry(); - } if (event & TASK_EVENT_POWER) touchpad_power_control(); -- cgit v1.2.1