X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fmisc%2Fcros_ec_spi.c;h=015333f139a209fd686a4ac173aba02baeeb1b33;hb=3cc83f9d08a80fddf4c1e8e766eff8273f30814c;hp=202acf258b8d75de6ed328bd346262f230716f7b;hpb=1a4596601fd395f3afb8f82f3f840c5e00bdd57a;p=u-boot diff --git a/drivers/misc/cros_ec_spi.c b/drivers/misc/cros_ec_spi.c index 202acf258b..015333f139 100644 --- a/drivers/misc/cros_ec_spi.c +++ b/drivers/misc/cros_ec_spi.c @@ -17,6 +17,30 @@ #include #include +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. * @@ -42,6 +66,12 @@ int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, int csum, len; 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 * fits in the internal device buffer. @@ -68,7 +98,7 @@ int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, } out = dev->dout; - out[0] = cmd_version; + out[0] = EC_CMD_VERSION0 + cmd_version; out[1] = cmd; out[2] = (uint8_t)dout_len; memcpy(out + 3, dout, dout_len); @@ -135,8 +165,7 @@ int cros_ec_spi_decode_fdt(struct cros_ec_dev *dev, const void *blob) */ int cros_ec_spi_init(struct cros_ec_dev *dev, const void *blob) { - dev->spi = spi_setup_slave_fdt(blob, dev->parent_node, - dev->cs, dev->max_frequency, 0); + dev->spi = spi_setup_slave_fdt(blob, dev->node, dev->parent_node); if (!dev->spi) { debug("%s: Could not setup SPI slave\n", __func__); return -1;