From 7fdcb8bf869b59396b8e2c0844c31fefd4c22500 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Thu, 9 Nov 2017 16:35:53 -0800 Subject: [PATCH] usb_update: Add support for touchpad debugging feature We support touchpad-specific debugging feature over the USB update protocol. This will be used to fetch raw data from the sensor, without requiring to remove the write-protect screw. BRANCH=none BUG=b:63993891 TEST=./usb_updater2 -g 00 -d 18d1:502b Change-Id: I46dfd97aaa17b73a5893fe1e8c62327a302f829b Signed-off-by: Nicolas Boichat Reviewed-on: https://chromium-review.googlesource.com/763574 Reviewed-by: Chun-ta Lin Reviewed-by: Vincent Palatin --- common/usb_update.c | 25 +++++++++++++++++++++++++ driver/touchpad_elan.c | 7 +++++++ include/update_fw.h | 18 ++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/common/usb_update.c b/common/usb_update.c index c73459126c..a97541dd9c 100644 --- a/common/usb_update.c +++ b/common/usb_update.c @@ -326,6 +326,31 @@ static int try_vendor_command(struct consumer const *consumer, size_t count) &tp, response_size); return 1; } + case UPDATE_EXTRA_CMD_TOUCHPAD_DEBUG: { + uint8_t *data = NULL; + unsigned int write_count = 0; + + /* + * Let the touchpad driver decide what it wants to do + * with the payload data, and put the response in data. + */ + response = touchpad_debug(buffer + header_size, + data_count, &data, &write_count); + + /* + * On error, or if there is no data to write back, just + * write back response. + */ + if (response != EC_RES_SUCCESS || write_count == 0) + break; + + /* Check that we can write all the data to the queue. */ + if (write_count > queue_space(&update_to_usb)) + return EC_RES_BUSY; + + QUEUE_ADD_UNITS(&update_to_usb, data, write_count); + return 1; + } #endif default: response = EC_RES_INVALID_COMMAND; diff --git a/driver/touchpad_elan.c b/driver/touchpad_elan.c index 3eae8f5c12..f71bf3d09f 100644 --- a/driver/touchpad_elan.c +++ b/driver/touchpad_elan.c @@ -505,6 +505,13 @@ int touchpad_update_write(int offset, int size, const uint8_t *data) } return EC_SUCCESS; } + +/* TODO(b:63993891): Implement debugging mode for Elan touchpad. */ +int touchpad_debug(const uint8_t *param, unsigned int param_size, + uint8_t **data, unsigned int *data_size) +{ + return EC_RES_INVALID_COMMAND; +} #endif void elan_tp_interrupt(enum gpio_signal signal) diff --git a/include/update_fw.h b/include/update_fw.h index f31549e252..727a3012f5 100644 --- a/include/update_fw.h +++ b/include/update_fw.h @@ -165,6 +165,7 @@ enum update_extra_command { UPDATE_EXTRA_CMD_INJECT_ENTROPY = 5, UPDATE_EXTRA_CMD_PAIR_CHALLENGE = 6, UPDATE_EXTRA_CMD_TOUCHPAD_INFO = 7, + UPDATE_EXTRA_CMD_TOUCHPAD_DEBUG = 8, }; /* @@ -247,6 +248,23 @@ int touchpad_get_info(struct touchpad_info *tp); /* Touchpad FW update: Write a FW block. */ int touchpad_update_write(int offset, int size, const uint8_t *data); +/** + * Touchpad debugging interface, called whenever UPDATE_EXTRA_CMD_TOUCHPAD_DEBUG + * is received. Behaviour is touchpad-vendor dependent, with the following + * restrictions: data must be allocated statically, and must not be larger than + * 64 bytes. + * + * @param param Data passed as parameter to command. + * @param param_size Number of bytes passed as parameter. + * @param data Data to write back to host, needs to be allocated + * statically by touchpad handler. + * @param data_size Amount of data to write back to host (up to 64 bytes). + * + * @return EC_RES_SUCCESS on success, any other EC_RES_* status on error. + */ +int touchpad_debug(const uint8_t *param, unsigned int param_size, + uint8_t **data, unsigned int *data_size); + /* SHA256 hash of the touchpad firmware expected by this image. */ extern const uint8_t touchpad_fw_full_hash[32];