summaryrefslogtreecommitdiff
path: root/driver/touchpad_st.c
diff options
context:
space:
mode:
authorWei-Han Chen <stimim@google.com>2018-09-25 14:55:32 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-09-26 10:32:07 -0700
commit997916e9343581b88cc875d4c072ccf88756a565 (patch)
tree1a81954f22aac1bb6dfce59536f4a2a3365e7ac9 /driver/touchpad_st.c
parent81851d0e69e89ff158427e91ded5dd88ac1a2e9e (diff)
downloadchrome-ec-997916e9343581b88cc875d4c072ccf88756a565.tar.gz
touchpad_st: integrate power control and system state
Previously, there was a static variable "enabled" in touchpad_power_control(). Logically, this value should be same as "SYSTEM_STATE_ACTIVE_MODE" in system_state. And, because system_state will be reset after touchpad reset, to make sure everything line up, we should get "enabled" from system_state instead. Also, when touchpad is being reset due to errors, power control should not enable / disable scanning. BRANCH=nocturne BUG=None TEST=manual on whiskers Signed-off-by: Wei-Han Chen <stimim@chromium.org> Change-Id: I5485422759c68769e9ad249a2903f3f796b5b068 Reviewed-on: https://chromium-review.googlesource.com/1242576 Commit-Ready: Wei-Han Chen <stimim@chromium.org> Tested-by: Wei-Han Chen <stimim@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'driver/touchpad_st.c')
-rw-r--r--driver/touchpad_st.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/driver/touchpad_st.c b/driver/touchpad_st.c
index ddef727fe9..cde1a07edb 100644
--- a/driver/touchpad_st.c
+++ b/driver/touchpad_st.c
@@ -45,6 +45,7 @@ static int st_tp_send_ack(void);
static int st_tp_start_scan(void);
static int st_tp_stop_scan(void);
static int st_tp_update_system_state(int new_state, int mask);
+static void touchpad_power_control(void);
/* Global variables */
/*
@@ -66,6 +67,8 @@ static int tp_control;
#define TP_CONTROL_SHALL_HALT (1 << 0)
#define TP_CONTROL_SHALL_RESET (1 << 1)
#define TP_CONTROL_SHALL_INITIALIZE (1 << 2)
+#define TP_CONTROL_RESETTING (1 << 3)
+#define TP_CONTROL_INITIALIZING (1 << 4)
/*
* Number of times we have reset the touchpad because of errors.
@@ -731,6 +734,8 @@ static int st_tp_reset(void)
/* Initialize the controller ICs after reset */
static void st_tp_init(void)
{
+ tp_control = TP_CONTROL_RESETTING;
+
if (st_tp_reset())
return;
/*
@@ -740,9 +745,9 @@ static void st_tp_init(void)
st_tp_read_system_info(0);
system_state = 0;
- tp_control &= ~TP_CONTROL_SHALL_RESET;
+ tp_control &= ~TP_CONTROL_RESETTING;
- st_tp_start_scan();
+ touchpad_power_control();
}
DECLARE_DEFERRED(st_tp_init);
@@ -955,11 +960,10 @@ static int st_tp_write_flash(int offset, int size, const uint8_t *data)
return EC_SUCCESS;
}
-static int st_tp_check_command_echo(const uint8_t *cmd,
- const size_t len)
+static int st_tp_check_command_echo(const uint8_t *cmd, const size_t len)
{
int num_events, i;
- num_events = st_tp_read_all_events(0);
+ num_events = st_tp_read_all_events(1);
if (num_events < 0)
return -num_events;
@@ -969,7 +973,7 @@ static int st_tp_check_command_echo(const uint8_t *cmd,
if (e->evt_id == ST_TP_EVENT_ID_STATUS_REPORT &&
e->report.report_type == ST_TP_STATUS_CMD_ECHO &&
memcmp(e->report.info, cmd, MIN(4, len)) == 0)
- return 0;
+ return EC_SUCCESS;
}
return -EC_ERROR_BUSY;
}
@@ -985,7 +989,7 @@ static void st_tp_full_initialize_end(void)
ret = st_tp_check_command_echo(tx_buf, sizeof(tx_buf));
if (ret == EC_SUCCESS) {
CPRINTS("Full panel initialization completed.");
- tp_control &= ~TP_CONTROL_SHALL_INITIALIZE;
+ tp_control &= ~TP_CONTROL_INITIALIZING;
st_tp_init();
} else if (ret == -EC_ERROR_BUSY) {
hook_call_deferred(&st_tp_full_initialize_end_data, 100 * MSEC);
@@ -998,6 +1002,10 @@ static void st_tp_full_initialize_start(void)
{
uint8_t tx_buf[] = { ST_TP_CMD_WRITE_SYSTEM_COMMAND, 0x00, 0x03 };
+ if (tp_control == TP_CONTROL_INITIALIZING)
+ return;
+
+ tp_control = TP_CONTROL_INITIALIZING;
st_tp_stop_scan();
if (st_tp_reset())
return;
@@ -1116,20 +1124,29 @@ void touchpad_interrupt(enum gpio_signal signal)
task_wake(TASK_ID_TOUCHPAD);
}
-/* Make a decision on touchpad power, based on USB and tablet mode status. */
-static void touchpad_power_control(void)
+static int touchpad_should_enable(void)
{
- static int enabled = 1;
- int enable = 1;
+ /* touchpad is not ready. */
+ if (tp_control)
+ return 0;
#ifdef CONFIG_USB_SUSPEND
- enable = enable &&
- (!usb_is_suspended() || usb_is_remote_wakeup_enabled());
+ if (usb_is_suspended() && !usb_is_remote_wakeup_enabled())
+ return 0;
#endif
#ifdef CONFIG_TABLET_MODE
- enable = enable && !tablet_get_mode();
+ if (tablet_get_mode())
+ return 0;
#endif
+ return 1;
+}
+
+/* Make a decision on touchpad power, based on USB and tablet mode status. */
+static void touchpad_power_control(void)
+{
+ const int enabled = !!(system_state & SYSTEM_STATE_ACTIVE_MODE);
+ int enable = touchpad_should_enable();
if (enabled == enable)
return;
@@ -1138,8 +1155,6 @@ static void touchpad_power_control(void)
st_tp_start_scan();
else
st_tp_stop_scan();
-
- enabled = enable;
}
void touchpad_task(void *u)