diff options
author | Chun-Ta Lin <itspeter@google.com> | 2017-09-13 20:13:44 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-09-14 22:25:02 -0700 |
commit | e18d9dd5300d5e1693ec3d4c72dd105efcff4393 (patch) | |
tree | f65e09e28867fe1113b460e870ccadb3575dec38 | |
parent | 4566523837774988a9862e07dd42c10c0e4284bc (diff) | |
download | chrome-ec-e18d9dd5300d5e1693ec3d4c72dd105efcff4393.tar.gz |
hammer: Support different IC types in touchpad FW update
Some Elan touchpad ICs have a different firmware sizes (48, 56, or 64
KB). We use CONFIG_TOUCHPAD_VIRTUAL_SIZE, set in the board file, to
determine the appropriate size, and, at runtime, we sanity check the
firmware size according to the IC type reported by the touchpad.
BRANCH=none
BUG=b:65188846
TEST=Manually modify the CONFIG_TOUCHPAD_VIRTUAL_SIZE in hammer,
executed and verified both (1) "EC_ERROR_UNKNOWN" returned
(2) ic_type shows 0x09 on EC console
TEST=Successfully flashing 48k firmware using CL:658920 on hammer and
56k firmware on staff. With success here, we specifically test
with different firmware version and make sure it reflected in
hammerd's touchpad info.
Change-Id: Ib30917d8376d4a2e8b6137daabad2341ac48d1f8
Signed-off-by: Chun-Ta Lin <itspeter@google.com>
Reviewed-on: https://chromium-review.googlesource.com/664937
Commit-Ready: Chun-ta Lin <itspeter@chromium.org>
Tested-by: Chun-ta Lin <itspeter@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
-rw-r--r-- | board/hammer/board.h | 18 | ||||
-rw-r--r-- | driver/touchpad_elan.c | 35 |
2 files changed, 38 insertions, 15 deletions
diff --git a/board/hammer/board.h b/board/hammer/board.h index a0028d22b0..5954b7b16d 100644 --- a/board/hammer/board.h +++ b/board/hammer/board.h @@ -141,19 +141,25 @@ #define CONFIG_USB_HID_KEYBOARD_BACKLIGHT #define CONFIG_USB_HID_TOUCHPAD +/* Virtual address for touchpad FW in USB updater. */ +#define CONFIG_TOUCHPAD_VIRTUAL_OFF 0x80000000 + +/* Touchpad firmware size and dimension difference */ #ifdef BOARD_STAFF /* TODO(b:38277869): Adjust values to match hardware. */ #define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_X 3214 #define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_Y 1840 #define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_X 1020 /* tenth of mm */ #define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_Y 584 /* tenth of mm */ +#define CONFIG_TOUCHPAD_VIRTUAL_SIZE (56*1024) #elif defined(BOARD_HAMMER) #define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_X 3207 #define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_Y 1783 #define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_X 1018 /* tenth of mm */ #define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_Y 566 /* tenth of mm */ +#define CONFIG_TOUCHPAD_VIRTUAL_SIZE (48*1024) #else -#error "No trackpad information for board." +#error "No touchpad information for board." #endif #define CONFIG_KEYBOARD_DEBUG @@ -175,20 +181,12 @@ /* Enable PWM */ #define CONFIG_PWM -/* Enable elan trackpad driver */ +/* Enable Elan touchpad driver */ #define CONFIG_TOUCHPAD #define CONFIG_TOUCHPAD_ELAN #define CONFIG_TOUCHPAD_I2C_PORT 0 #define CONFIG_TOUCHPAD_I2C_ADDR (0x15 << 1) -/* Virtual address for touchpad FW in USB updater. */ -#define CONFIG_TOUCHPAD_VIRTUAL_OFF 0x80000000 -/* TODO(itspeter): The CONFIG_TOUCHPAD_VIRTUAL_SIZE depends on IC. - * b/65188846 will address this separately. It will only works - * for this size as for now. - */ -#define CONFIG_TOUCHPAD_VIRTUAL_SIZE (48*1024) - #define CONFIG_CURVE25519 #define CONFIG_USB_PAIRING diff --git a/driver/touchpad_elan.c b/driver/touchpad_elan.c index 070602bf5b..3eae8f5c12 100644 --- a/driver/touchpad_elan.c +++ b/driver/touchpad_elan.c @@ -30,9 +30,11 @@ #define ETP_I2C_RESET 0x0100 #define ETP_I2C_WAKE_UP 0x0800 #define ETP_I2C_SLEEP 0x0801 + #define ETP_I2C_STAND_CMD 0x0005 #define ETP_I2C_UNIQUEID_CMD 0x0101 #define ETP_I2C_FW_VERSION_CMD 0x0102 +#define ETP_I2C_OSM_VERSION_CMD 0x0103 #define ETP_I2C_XY_TRACENUM_CMD 0x0105 #define ETP_I2C_MAX_X_AXIS_CMD 0x0106 #define ETP_I2C_MAX_Y_AXIS_CMD 0x0107 @@ -74,10 +76,9 @@ #define ETP_FW_IAP_INTF_ERR (1 << 4) #ifdef CONFIG_USB_UPDATE -/* TODO(b/65188846): The actual FW_PAGE_COUNT depends on IC. */ +/* The actual FW_SIZE depends on IC. */ +#define FW_SIZE CONFIG_TOUCHPAD_VIRTUAL_SIZE #define FW_PAGE_SIZE 64 -#define FW_PAGE_COUNT 768 -#define FW_SIZE (FW_PAGE_SIZE*FW_PAGE_COUNT) #endif struct { @@ -363,12 +364,28 @@ static int elan_in_main_mode(void) return val & ETP_I2C_MAIN_MODE_ON; } +static int elan_get_ic_page_count(void) +{ + uint16_t ic_type; + + elan_tp_read_cmd(ETP_I2C_OSM_VERSION_CMD, &ic_type); + CPRINTS("%s: ic_type:%04X.", __func__, ic_type); + switch (ic_type >> 8) { + case 0x09: + return 768; + case 0x0D: + return 896; + case 0x00: + return 1024; + } + return -1; +} + static int elan_prepare_for_update(void) { uint16_t rx_buf; int initial_mode; - /* TODO(itspeter): Let it work for different IC size. */ initial_mode = elan_in_main_mode(); if (!initial_mode) { CPRINTS("%s: In IAP mode, reset IC.", __func__); @@ -440,11 +457,19 @@ static int touchpad_update_page(const uint8_t *data) int touchpad_update_write(int offset, int size, const uint8_t *data) { static int iap_addr = -1; - int addr, rv; + int addr, rv, page_count; CPRINTS("%s %08x %d", __func__, offset, size); if (offset == 0) { + /* Verify the IC type is aligned with defined firmware size */ + page_count = elan_get_ic_page_count(); + if (FW_PAGE_SIZE * page_count != FW_SIZE) { + CPRINTS("%s: IC(%d*%d) size and FW_SIZE(%d) mismatch", + __func__, page_count, FW_PAGE_SIZE, FW_SIZE); + return EC_ERROR_UNKNOWN; + } + gpio_disable_interrupt(GPIO_TOUCHPAD_INT); CPRINTS("%s: prepare fw update.", __func__); rv = elan_prepare_for_update(); |