]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/misc/cros_ec_spi.c
cros_ec: spi: Add support for EC protocol version 3
[karo-tx-uboot.git] / drivers / misc / cros_ec_spi.c
index ef73782606e21301a14ba7ae5c500ef5c404db3a..7df709cc714b92a4d06a85cdea747d28cdb3f643 100644 (file)
 #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.
  *