From c9ea4bddbc45ef9b0104d5afc8a1d2a811cad372 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Fri, 10 Feb 2017 14:11:54 -0800 Subject: [PATCH] pdchipinfo: Increase compatibility of fw_version The firmware version formats may vary chip to chip. fw_version field is changed to a union of a 8 byte string and an 64-bit integer. BUG=chrome-os-partner:62383 BRANCH=none TEST=ectool pdchipinfo 0/1 on Electro Change-Id: Id51e66c44338a09ed897ee61f54cd6a394400e63 Signed-off-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/441270 --- common/usb_pd_protocol.c | 4 ++-- driver/tcpm/anx74xx.c | 2 -- driver/tcpm/tcpci.c | 23 ++++++++++++++--------- include/ec_commands.h | 9 ++++++--- util/ectool.c | 12 +++++++++++- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index c6d8712fa4..216886d0c7 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -1649,9 +1649,9 @@ void pd_task(void) if (!res) { struct ec_response_pd_chip_info *info; tcpm_get_chip_info(port, &info); - CPRINTS("TCPC p%d VID:0x%x PID:0x%x DID:0x%x FWV:0x%x", + CPRINTS("TCPC p%d VID:0x%x PID:0x%x DID:0x%x FWV:0x%lx", port, info->vendor_id, info->product_id, - info->device_id, info->fw_version); + info->device_id, info->fw_version_number); } #endif diff --git a/driver/tcpm/anx74xx.c b/driver/tcpm/anx74xx.c index 6311a53446..56728548c6 100644 --- a/driver/tcpm/anx74xx.c +++ b/driver/tcpm/anx74xx.c @@ -928,8 +928,6 @@ static int anx74xx_tcpm_init(int port) if (rv) return EC_ERROR_UNKNOWN; - tcpm_get_chip_info(port, NULL); - return EC_SUCCESS; } diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index ad50cdbb8d..be98248e1f 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -327,36 +327,39 @@ void tcpci_tcpc_alert(int port) int tcpci_get_chip_info(int port, struct ec_response_pd_chip_info **chip_info) { static struct ec_response_pd_chip_info info[CONFIG_USB_PD_PORT_COUNT]; + struct ec_response_pd_chip_info *i; int error; int val; if (port >= CONFIG_USB_PD_PORT_COUNT) return EC_ERROR_INVAL; + i = &info[port]; + /* If chip_info is NULL, chip info will be stored in cache and can be * read later by another call. */ if (chip_info) - *chip_info = &info[port]; + *chip_info = i; - if (info[port].vendor_id) + if (i->vendor_id) return EC_SUCCESS; error = tcpc_read16(port, TCPC_REG_VENDOR_ID, &val); if (error) return error; - info[port].vendor_id = val; + i->vendor_id = val; error = tcpc_read16(port, TCPC_REG_PRODUCT_ID, &val); if (error) return error; - info[port].product_id = val; + i->product_id = val; error = tcpc_read16(port, TCPC_REG_BCD_DEV, &val); if (error) return error; - info[port].device_id = val; + i->device_id = val; - switch(info[port].vendor_id) { + switch (i->vendor_id) { #ifdef CONFIG_USB_PD_TCPM_ANX74XX case ANX74XX_VENDOR_ID: error = anx74xx_tcpc_get_fw_version(port, &val); @@ -369,12 +372,14 @@ int tcpci_get_chip_info(int port, struct ec_response_pd_chip_info **chip_info) #endif default: /* Even if the chip doesn't implement get_fw_version, we - * return success. The version will be 0xffff. */ - return EC_SUCCESS; + * return success.*/ + val = -1; + error = EC_SUCCESS; } if (error) return error; - info[port].fw_version = val; + /* This may vary chip to chip. For now everything fits in this format */ + i->fw_version_number = val; return EC_SUCCESS; } diff --git a/include/ec_commands.h b/include/ec_commands.h index 1210d945cf..d2ef825130 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -3995,17 +3995,20 @@ struct __ec_align1 ec_response_usb_pd_mux_info { uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ }; -#define EC_CMD_PD_CHIP_INFO 0x011B +#define EC_CMD_PD_CHIP_INFO 0x011B struct __ec_align1 ec_params_pd_chip_info { - uint8_t port; /* USB-C port number */ + uint8_t port; /* USB-C port number */ }; struct __ec_align2 ec_response_pd_chip_info { uint16_t vendor_id; uint16_t product_id; uint16_t device_id; - uint16_t fw_version; + union { + uint8_t fw_version_string[8]; + uint64_t fw_version_number; + }; }; #endif /* !__ACPI__ */ diff --git a/util/ectool.c b/util/ectool.c index 5b14c78203..2c9bda2f8e 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -14,6 +14,7 @@ #include #include +#include "anx74xx.h" #include "battery.h" #include "comm-host.h" #include "compile_time_macros.h" @@ -24,6 +25,7 @@ #include "lock/gec_lock.h" #include "misc_util.h" #include "panic.h" +#include "ps8751.h" #include "usb_pd.h" /* Command line options */ @@ -6888,7 +6890,15 @@ int cmd_pd_chip_info(int argc, char *argv[]) printf("vendor_id: 0x%x\n", r.vendor_id); printf("product_id: 0x%x\n", r.product_id); printf("device_id: 0x%x\n", r.device_id); - printf("fw_version: 0x%x\n", r.fw_version); + + switch (r.vendor_id) { + case ANX74XX_VENDOR_ID: + case PS8751_VENDOR_ID: + printf("fw_version: 0x%" PRIx64 "\n", r.fw_version_number); + break; + default: + printf("fw_version: UNSUPPORTED\n"); + } return 0; }