mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-21 14:41:31 +00:00
cros_ec: spi: Add support for EC protocol version 3
Protocol version 3 will be attempted first; if the EC doesn't support it, u-boot will fall back to the old protocol version (2). 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
2d8ede58ca
commit
a607028331
3 changed files with 49 additions and 0 deletions
|
@ -218,6 +218,11 @@ static int send_command_proto3(struct cros_ec_dev *dev,
|
||||||
return in_bytes;
|
return in_bytes;
|
||||||
|
|
||||||
switch (dev->interface) {
|
switch (dev->interface) {
|
||||||
|
#ifdef CONFIG_CROS_EC_SPI
|
||||||
|
case CROS_EC_IF_SPI:
|
||||||
|
rv = cros_ec_spi_packet(dev, out_bytes, in_bytes);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
case CROS_EC_IF_NONE:
|
case CROS_EC_IF_NONE:
|
||||||
/* TODO: support protocol 3 for LPC, I2C; for now fall through */
|
/* TODO: support protocol 3 for LPC, I2C; for now fall through */
|
||||||
default:
|
default:
|
||||||
|
@ -665,6 +670,13 @@ 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Try sending a version 3 packet */
|
||||||
|
dev->protocol_version = 3;
|
||||||
|
if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
|
||||||
|
(uint8_t **)&resp, sizeof(*resp)) > 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Try sending a version 2 packet */
|
/* Try sending a version 2 packet */
|
||||||
dev->protocol_version = 2;
|
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),
|
||||||
|
|
|
@ -17,6 +17,30 @@
|
||||||
#include <cros_ec.h>
|
#include <cros_ec.h>
|
||||||
#include <spi.h>
|
#include <spi.h>
|
||||||
|
|
||||||
|
int cros_ec_spi_packet(struct cros_ec_dev *dev, int out_bytes, int in_bytes)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
/* Do the transfer */
|
||||||
|
if (spi_claim_bus(dev->spi)) {
|
||||||
|
debug("%s: Cannot claim SPI bus\n", __func__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = spi_xfer(dev->spi, max(out_bytes, in_bytes) * 8,
|
||||||
|
dev->dout, dev->din,
|
||||||
|
SPI_XFER_BEGIN | SPI_XFER_END);
|
||||||
|
|
||||||
|
spi_release_bus(dev->spi);
|
||||||
|
|
||||||
|
if (rv) {
|
||||||
|
debug("%s: Cannot complete SPI transfer\n", __func__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return in_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a command to a LPC CROS_EC device and return the reply.
|
* Send a command to a LPC CROS_EC device and return the reply.
|
||||||
*
|
*
|
||||||
|
|
|
@ -311,6 +311,19 @@ int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
|
||||||
const uint8_t *dout, int dout_len,
|
const uint8_t *dout, int dout_len,
|
||||||
uint8_t **dinp, int din_len);
|
uint8_t **dinp, int din_len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a packet to a CROS-EC device and return the response packet.
|
||||||
|
*
|
||||||
|
* Expects the request packet to be stored in dev->dout. Stores the response
|
||||||
|
* packet in dev->din.
|
||||||
|
*
|
||||||
|
* @param dev CROS-EC device
|
||||||
|
* @param out_bytes Size of request packet to output
|
||||||
|
* @param in_bytes Maximum size of response packet to receive
|
||||||
|
* @return number of bytes in response packet, or <0 on error
|
||||||
|
*/
|
||||||
|
int cros_ec_spi_packet(struct cros_ec_dev *dev, int out_bytes, int in_bytes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dump a block of data for a command.
|
* Dump a block of data for a command.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue