diff options
Diffstat (limited to 'drivers/misc')
| -rw-r--r-- | drivers/misc/cros_ec.c | 12 | ||||
| -rw-r--r-- | drivers/misc/cros_ec_spi.c | 24 | 
2 files changed, 36 insertions, 0 deletions
| diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index a7716b87f..5682d39ec 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -218,6 +218,11 @@ static int send_command_proto3(struct cros_ec_dev *dev,  		return in_bytes;  	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:  	/* TODO: support protocol 3 for LPC, I2C; for now fall through */  	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.  	 */ +	/* 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 */  	dev->protocol_version = 2;  	if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req), diff --git a/drivers/misc/cros_ec_spi.c b/drivers/misc/cros_ec_spi.c index ef7378260..7df709cc7 100644 --- a/drivers/misc/cros_ec_spi.c +++ b/drivers/misc/cros_ec_spi.c @@ -17,6 +17,30 @@  #include <cros_ec.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.   * |