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 <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/441270
This commit is contained in:
Daisuke Nojiri
2017-02-10 14:11:54 -08:00
committed by chrome-bot
parent df2f085c16
commit c9ea4bddbc
5 changed files with 33 additions and 17 deletions

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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__ */

View File

@@ -14,6 +14,7 @@
#include <time.h>
#include <unistd.h>
#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;
}