From 4d6eb1bc01ddbc87bbd53a317cfddd78f9cce1b2 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Fri, 10 Feb 2017 15:54:08 -0800 Subject: [PATCH] pdchipinfo: Add option to force renewal This change adds an option to pdchipinfo command to force ec to get the version from the chip instead of the cache (if it's available). This option will be used after firmware update, which makes the cache value stale. BUG=chrome-os-partner:62383 BRANCH=none TEST=Run ectool as follows: localhost ~ # /tmp/ectool pdchipinfo 0 on vendor_id: 0xaaaa product_id: 0x3429 device_id: 0xad fw_version: 0x15 localhost ~ # /tmp/ectool pdchipinfo 1 on EC result 2 (ERROR) Change-Id: Icefe96d7fc1208b991a4caa13aaf4f04052edba7 Signed-off-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/441271 Reviewed-by: Vincent Palatin --- common/usb_pd_protocol.c | 4 ++-- driver/tcpm/tcpci.c | 8 +++++--- driver/tcpm/tcpci.h | 3 ++- driver/tcpm/tcpm.h | 4 ++-- include/ec_commands.h | 1 + include/usb_pd_tcpm.h | 4 +++- util/ectool.c | 14 ++++++++++++-- 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 216886d0c7..51133b741b 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -1648,7 +1648,7 @@ void pd_task(void) #ifndef CONFIG_USB_PD_TCPC if (!res) { struct ec_response_pd_chip_info *info; - tcpm_get_chip_info(port, &info); + tcpm_get_chip_info(port, 0, &info); 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_number); @@ -3725,7 +3725,7 @@ static int hc_remote_pd_chip_info(struct host_cmd_handler_args *args) if (p->port >= CONFIG_USB_PD_PORT_COUNT) return EC_RES_INVALID_PARAM; - if (tcpm_get_chip_info(p->port, &info)) + if (tcpm_get_chip_info(p->port, p->renew, &info)) return EC_RES_ERROR; memcpy(r, info, sizeof(*r)); diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index be98248e1f..cbbed9c05e 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -324,7 +324,8 @@ void tcpci_tcpc_alert(int port) * will be stored in cache, which can be accessed by tcpm_get_chip_info without * worrying about chip states. */ -int tcpci_get_chip_info(int port, struct ec_response_pd_chip_info **chip_info) +int tcpci_get_chip_info(int port, int renew, + 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; @@ -341,7 +342,8 @@ int tcpci_get_chip_info(int port, struct ec_response_pd_chip_info **chip_info) if (chip_info) *chip_info = i; - if (i->vendor_id) + /* If already populated and renewal is not asked, return cache value */ + if (i->vendor_id && !renew) return EC_SUCCESS; error = tcpc_read16(port, TCPC_REG_VENDOR_ID, &val); @@ -421,7 +423,7 @@ int tcpci_tcpm_init(int port) return error; /* Read chip info here when we know the chip is awake. */ - tcpm_get_chip_info(port, NULL); + tcpm_get_chip_info(port, 1, NULL); return EC_SUCCESS; } diff --git a/driver/tcpm/tcpci.h b/driver/tcpm/tcpci.h index a11050eaf0..ce1b082fca 100644 --- a/driver/tcpm/tcpci.h +++ b/driver/tcpm/tcpci.h @@ -137,6 +137,7 @@ int tcpci_tcpm_transmit(int port, enum tcpm_transmit_type type, int tcpci_tcpm_mux_init(int i2c_addr); int tcpci_tcpm_mux_set(int i2c_addr, mux_state_t mux_state); int tcpci_tcpm_mux_get(int i2c_addr, mux_state_t *mux_state); -int tcpci_get_chip_info(int port, struct ec_response_pd_chip_info **chip_info); +int tcpci_get_chip_info(int port, int renew, + struct ec_response_pd_chip_info **chip_info); #endif /* __CROS_EC_USB_PD_TCPM_TCPCI_H */ diff --git a/driver/tcpm/tcpm.h b/driver/tcpm/tcpm.h index 9f8e38cbfc..797a8c0dad 100644 --- a/driver/tcpm/tcpm.h +++ b/driver/tcpm/tcpm.h @@ -163,11 +163,11 @@ static inline int tcpc_i2c_write(const int port, const int addr, } #endif -static inline int tcpm_get_chip_info(int port, +static inline int tcpm_get_chip_info(int port, int renew, struct ec_response_pd_chip_info **info) { if (tcpc_config[port].drv->get_chip_info) - return tcpc_config[port].drv->get_chip_info(port, info); + return tcpc_config[port].drv->get_chip_info(port, renew, info); return EC_ERROR_UNIMPLEMENTED; } diff --git a/include/ec_commands.h b/include/ec_commands.h index d2ef825130..86fac1d45c 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -3999,6 +3999,7 @@ struct __ec_align1 ec_response_usb_pd_mux_info { struct __ec_align1 ec_params_pd_chip_info { uint8_t port; /* USB-C port number */ + uint8_t renew; /* Force renewal */ }; struct __ec_align2 ec_response_pd_chip_info { diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index d95d994184..c8526239d1 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -202,11 +202,13 @@ struct tcpm_drv { * Get firmware version. * * @param port Type-C port number + * @param renew Force renewal * @param info Pointer to pointer to PD chip info * * @return EC_SUCCESS or error */ - int (*get_chip_info)(int port, struct ec_response_pd_chip_info **info); + int (*get_chip_info)(int port, int renew, + struct ec_response_pd_chip_info **info); }; enum tcpc_alert_polarity { diff --git a/util/ectool.c b/util/ectool.c index 2c9bda2f8e..3375935d4b 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -6872,8 +6872,8 @@ int cmd_pd_chip_info(int argc, char *argv[]) char *e; int rv; - if (argc < 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); + if (argc < 2 || 3 < argc) { + fprintf(stderr, "Usage: %s [renew(on/off)]\n", argv[0]); return -1; } @@ -6883,6 +6883,16 @@ int cmd_pd_chip_info(int argc, char *argv[]) return -1; } + p.renew = 0; + if (argc == 3) { + int val; + if (!parse_bool(argv[2], &val)) { + fprintf(stderr, "invalid arg \"%s\"\n", argv[2]); + return -1; + } + p.renew = val; + } + rv = ec_command(EC_CMD_PD_CHIP_INFO, 0, &p, sizeof(p), &r, sizeof(r)); if (rv < 0) return rv;