mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-06-06 23:01:36 +00:00
cros_ec: Clean up multiple EC protocol support
Version 1 protocols (without command version) were already no longer supported in cros_ec.c. This removes some dead code from the cros_ec_i2c driver. Version 2 protcols (with command version) are now called protocol_version=2, instead of cmd_version_is_supported=1. A subsequent change will introduce protocol version 3 for SPI. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Randall Spangler <rspangler@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
836bb6e827
commit
e8c1266236
4 changed files with 49 additions and 47 deletions
|
@ -501,18 +501,23 @@ static int cros_ec_check_version(struct cros_ec_dev *dev)
|
||||||
*
|
*
|
||||||
* So for now, just read all the data anyway.
|
* So for now, just read all the data anyway.
|
||||||
*/
|
*/
|
||||||
dev->cmd_version_is_supported = 1;
|
|
||||||
|
/* Try sending a version 2 packet */
|
||||||
|
dev->protocol_version = 2;
|
||||||
if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
|
if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
|
||||||
(uint8_t **)&resp, sizeof(*resp)) > 0) {
|
(uint8_t **)&resp, sizeof(*resp)) > 0) {
|
||||||
/* It appears to understand new version commands */
|
return 0;
|
||||||
dev->cmd_version_is_supported = 1;
|
|
||||||
} else {
|
|
||||||
printf("%s: ERROR: old EC interface not supported\n",
|
|
||||||
__func__);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
/*
|
||||||
|
* Fail if we're still here, since the EC doesn't understand any
|
||||||
|
* protcol version we speak. Version 1 interface without command
|
||||||
|
* version is no longer supported, and we don't know about any new
|
||||||
|
* protocol versions.
|
||||||
|
*/
|
||||||
|
dev->protocol_version = 0;
|
||||||
|
printf("%s: ERROR: old EC interface not supported\n", __func__);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cros_ec_test(struct cros_ec_dev *dev)
|
int cros_ec_test(struct cros_ec_dev *dev)
|
||||||
|
|
|
@ -35,7 +35,7 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
|
||||||
uint8_t *ptr;
|
uint8_t *ptr;
|
||||||
/* Receive input data, so that args will be dword aligned */
|
/* Receive input data, so that args will be dword aligned */
|
||||||
uint8_t *in_ptr;
|
uint8_t *in_ptr;
|
||||||
int ret;
|
int len, csum, ret;
|
||||||
|
|
||||||
old_bus = i2c_get_bus_num();
|
old_bus = i2c_get_bus_num();
|
||||||
|
|
||||||
|
@ -67,24 +67,24 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
|
||||||
* will be dword aligned.
|
* will be dword aligned.
|
||||||
*/
|
*/
|
||||||
in_ptr = dev->din + sizeof(int64_t);
|
in_ptr = dev->din + sizeof(int64_t);
|
||||||
if (!dev->cmd_version_is_supported) {
|
|
||||||
/* Send an old-style command */
|
if (dev->protocol_version != 2) {
|
||||||
*ptr++ = cmd;
|
/* Something we don't support */
|
||||||
out_bytes = dout_len + 1;
|
debug("%s: Protocol version %d unsupported\n",
|
||||||
in_bytes = din_len + 2;
|
__func__, dev->protocol_version);
|
||||||
in_ptr--; /* Expect just a status byte */
|
return -1;
|
||||||
} else {
|
|
||||||
*ptr++ = EC_CMD_VERSION0 + cmd_version;
|
|
||||||
*ptr++ = cmd;
|
|
||||||
*ptr++ = dout_len;
|
|
||||||
in_ptr -= 2; /* Expect status, length bytes */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*ptr++ = EC_CMD_VERSION0 + cmd_version;
|
||||||
|
*ptr++ = cmd;
|
||||||
|
*ptr++ = dout_len;
|
||||||
|
in_ptr -= 2; /* Expect status, length bytes */
|
||||||
|
|
||||||
memcpy(ptr, dout, dout_len);
|
memcpy(ptr, dout, dout_len);
|
||||||
ptr += dout_len;
|
ptr += dout_len;
|
||||||
|
|
||||||
if (dev->cmd_version_is_supported)
|
*ptr++ = (uint8_t)
|
||||||
*ptr++ = (uint8_t)
|
cros_ec_calc_checksum(dev->dout, dout_len + 3);
|
||||||
cros_ec_calc_checksum(dev->dout, dout_len + 3);
|
|
||||||
|
|
||||||
/* Set to the proper i2c bus */
|
/* Set to the proper i2c bus */
|
||||||
if (i2c_set_bus_num(dev->bus_num)) {
|
if (i2c_set_bus_num(dev->bus_num)) {
|
||||||
|
@ -121,26 +121,20 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
|
||||||
return -(int)*in_ptr;
|
return -(int)*in_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev->cmd_version_is_supported) {
|
len = in_ptr[1];
|
||||||
int len, csum;
|
if (len + 3 > sizeof(dev->din)) {
|
||||||
|
debug("%s: Received length %#02x too large\n",
|
||||||
len = in_ptr[1];
|
__func__, len);
|
||||||
if (len + 3 > sizeof(dev->din)) {
|
return -1;
|
||||||
debug("%s: Received length %#02x too large\n",
|
|
||||||
__func__, len);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
csum = cros_ec_calc_checksum(in_ptr, 2 + len);
|
|
||||||
if (csum != in_ptr[2 + len]) {
|
|
||||||
debug("%s: Invalid checksum rx %#02x, calced %#02x\n",
|
|
||||||
__func__, in_ptr[2 + din_len], csum);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
din_len = min(din_len, len);
|
|
||||||
cros_ec_dump_data("in", -1, in_ptr, din_len + 3);
|
|
||||||
} else {
|
|
||||||
cros_ec_dump_data("in (old)", -1, in_ptr, in_bytes);
|
|
||||||
}
|
}
|
||||||
|
csum = cros_ec_calc_checksum(in_ptr, 2 + len);
|
||||||
|
if (csum != in_ptr[2 + len]) {
|
||||||
|
debug("%s: Invalid checksum rx %#02x, calced %#02x\n",
|
||||||
|
__func__, in_ptr[2 + din_len], csum);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
din_len = min(din_len, len);
|
||||||
|
cros_ec_dump_data("in", -1, in_ptr, din_len + 3);
|
||||||
|
|
||||||
/* Return pointer to dword-aligned input data, if any */
|
/* Return pointer to dword-aligned input data, if any */
|
||||||
*dinp = dev->din + sizeof(int64_t);
|
*dinp = dev->din + sizeof(int64_t);
|
||||||
|
@ -178,7 +172,5 @@ int cros_ec_i2c_init(struct cros_ec_dev *dev, const void *blob)
|
||||||
{
|
{
|
||||||
i2c_init(dev->max_frequency, dev->addr);
|
i2c_init(dev->max_frequency, dev->addr);
|
||||||
|
|
||||||
dev->cmd_version_is_supported = 0;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,12 @@ int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
|
||||||
int csum, len;
|
int csum, len;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
|
if (dev->protocol_version != 2) {
|
||||||
|
debug("%s: Unsupported EC protcol version %d\n",
|
||||||
|
__func__, dev->protocol_version);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sanity-check input size to make sure it plus transaction overhead
|
* Sanity-check input size to make sure it plus transaction overhead
|
||||||
* fits in the internal device buffer.
|
* fits in the internal device buffer.
|
||||||
|
|
|
@ -33,7 +33,7 @@ struct cros_ec_dev {
|
||||||
unsigned int bus_num; /* Bus number (for I2C) */
|
unsigned int bus_num; /* Bus number (for I2C) */
|
||||||
unsigned int max_frequency; /* Maximum interface frequency */
|
unsigned int max_frequency; /* Maximum interface frequency */
|
||||||
struct fdt_gpio_state ec_int; /* GPIO used as EC interrupt line */
|
struct fdt_gpio_state ec_int; /* GPIO used as EC interrupt line */
|
||||||
int cmd_version_is_supported; /* Device supports command versions */
|
int protocol_version; /* Protocol version to use */
|
||||||
int optimise_flash_write; /* Don't write erased flash blocks */
|
int optimise_flash_write; /* Don't write erased flash blocks */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -260,8 +260,7 @@ int cros_ec_spi_decode_fdt(struct cros_ec_dev *dev, const void *blob);
|
||||||
* Check whether the LPC interface supports new-style commands.
|
* Check whether the LPC interface supports new-style commands.
|
||||||
*
|
*
|
||||||
* LPC has its own way of doing this, which involves checking LPC values
|
* LPC has its own way of doing this, which involves checking LPC values
|
||||||
* visible to the host. Do this, and update dev->cmd_version_is_supported
|
* visible to the host. Do this, and update dev->protocol_version accordingly.
|
||||||
* accordingly.
|
|
||||||
*
|
*
|
||||||
* @param dev CROS-EC device to check
|
* @param dev CROS-EC device to check
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue