mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-12 19:04:59 +00:00
touchpad_st: Power off when USB is suspended without wake
When USB is suspended and disable remote wakeup (SUS0), we can stop touchpad scanning to save some power. This CL also stops sending empty touchpad HID events when there is no finger events nor button events. BRANCH=whiskers BUG=b:70482333 TEST=`st_tp_stop_scan` is called on USB suspend Signed-off-by: Wei-Han Chen <stimim@chromium.org> Change-Id: Iebf29d7371383b7493baa1059cfa8d56bbc2589c Reviewed-on: https://chromium-review.googlesource.com/1095119 Commit-Ready: Wei-Han Chen <stimim@chromium.org> Tested-by: Wei-Han Chen <stimim@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "touchpad.h"
|
||||
#include "touchpad_st.h"
|
||||
#include "update_fw.h"
|
||||
#include "usb_api.h"
|
||||
#include "usb_hid_touchpad.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -27,6 +28,9 @@
|
||||
#define CPRINTF(format, args...) cprintf(CC_TOUCHPAD, format, ## args)
|
||||
#define CPRINTS(format, args...) cprints(CC_TOUCHPAD, format, ## args)
|
||||
|
||||
#define TASK_EVENT_POWERON TASK_EVENT_CUSTOM(1)
|
||||
#define TASK_EVENT_POWEROFF TASK_EVENT_CUSTOM(2)
|
||||
|
||||
#define SPI (&(spi_devices[SPI_ST_TP_DEVICE_ID]))
|
||||
|
||||
BUILD_ASSERT(sizeof(struct st_tp_event_t) == 8);
|
||||
@@ -122,7 +126,7 @@ static int st_tp_parse_finger(struct usb_hid_touchpad_report *report,
|
||||
|
||||
static int st_tp_write_hid_report(void)
|
||||
{
|
||||
int ret, i, num_finger, num_events;
|
||||
int ret, i, num_finger, num_events, domeswitch_changed = 0;
|
||||
struct usb_hid_touchpad_report report;
|
||||
|
||||
ret = st_tp_read_host_buffer_header();
|
||||
@@ -138,6 +142,7 @@ static int st_tp_write_hid_report(void)
|
||||
(rx_buf.buffer_header.dome_switch_level ?
|
||||
0 : SYSTEM_STATE_DOME_SWITCH_LEVEL),
|
||||
SYSTEM_STATE_DOME_SWITCH_LEVEL);
|
||||
domeswitch_changed = 1;
|
||||
}
|
||||
|
||||
num_events = st_tp_read_all_events();
|
||||
@@ -162,6 +167,9 @@ static int st_tp_write_hid_report(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (!num_finger && !domeswitch_changed) /* nothing changed */
|
||||
return 0;
|
||||
|
||||
report.button = !!(system_state & SYSTEM_STATE_DOME_SWITCH_LEVEL);
|
||||
report.count = num_finger;
|
||||
report.timestamp = irq_ts / USB_HID_TOUCHPAD_TIMESTAMP_UNIT;
|
||||
@@ -790,16 +798,35 @@ void touchpad_interrupt(enum gpio_signal signal)
|
||||
|
||||
void touchpad_task(void *u)
|
||||
{
|
||||
uint32_t event;
|
||||
|
||||
st_tp_init();
|
||||
|
||||
while (1) {
|
||||
task_wait_event(-1);
|
||||
event = task_wait_event(-1);
|
||||
|
||||
while (!gpio_get_level(GPIO_TOUCHPAD_INT))
|
||||
st_tp_read_report();
|
||||
if (event & TASK_EVENT_WAKE)
|
||||
while (!gpio_get_level(GPIO_TOUCHPAD_INT))
|
||||
st_tp_read_report();
|
||||
|
||||
if (event & TASK_EVENT_POWERON)
|
||||
st_tp_start_scan();
|
||||
else if (event & TASK_EVENT_POWEROFF)
|
||||
st_tp_stop_scan();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_SUSPEND
|
||||
static void touchpad_usb_pm_change(void)
|
||||
{
|
||||
if (usb_is_suspended() && !usb_is_remote_wakeup_enabled())
|
||||
task_set_event(TASK_ID_TOUCHPAD, TASK_EVENT_POWEROFF, 0);
|
||||
else
|
||||
task_set_event(TASK_ID_TOUCHPAD, TASK_EVENT_POWERON, 0);
|
||||
}
|
||||
DECLARE_HOOK(HOOK_USB_PM_CHANGE, touchpad_usb_pm_change, HOOK_PRIO_DEFAULT);
|
||||
#endif
|
||||
|
||||
/* Debugging commands */
|
||||
static int command_touchpad_st(int argc, char **argv)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user