Commit 3a238fc7 authored by Rui Miguel Silva's avatar Rui Miguel Silva Committed by Greg Kroah-Hartman

greybus: spi: add inprogress bit to xfer_flags

When a SPI transfer needs to be split by more than one greybus spi
transfer operation, we need to indicate it so the controller can handle
the chip select lines correctly.

Add a new bit to indicate it, GB_SPI_XFER_INPROGRESS, and create an
helper function to calculate when the transfer is done. As we need this
information also in other places.
Signed-off-by: default avatarRui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 22e26a3a
......@@ -879,6 +879,7 @@ struct gb_spi_transfer {
__u8 xfer_flags;
#define GB_SPI_XFER_READ 0x01
#define GB_SPI_XFER_WRITE 0x02
#define GB_SPI_XFER_INPROGRESS 0x04
} __packed;
struct gb_spi_transfer_request {
......
......@@ -102,6 +102,17 @@ static void clean_xfer_state(struct gb_spilib *spi)
spi->op_timeout = 0;
}
static bool is_last_xfer_done(struct gb_spilib *spi)
{
struct spi_transfer *last_xfer = spi->last_xfer;
if ((spi->tx_xfer_offset + spi->last_xfer_size == last_xfer->len) ||
(spi->rx_xfer_offset + spi->last_xfer_size == last_xfer->len))
return true;
return false;
}
static int setup_next_xfer(struct gb_spilib *spi, struct spi_message *msg)
{
struct spi_transfer *last_xfer = spi->last_xfer;
......@@ -113,8 +124,7 @@ static int setup_next_xfer(struct gb_spilib *spi, struct spi_message *msg)
* if we transferred all content of the last transfer, reset values and
* check if this was the last transfer in the message
*/
if ((spi->tx_xfer_offset + spi->last_xfer_size == last_xfer->len) ||
(spi->rx_xfer_offset + spi->last_xfer_size == last_xfer->len)) {
if (is_last_xfer_done(spi)) {
spi->tx_xfer_offset = 0;
spi->rx_xfer_offset = 0;
spi->op_timeout = 0;
......@@ -265,6 +275,8 @@ static struct gb_operation *gb_spi_operation_create(struct gb_spilib *spi,
gb_xfer->xfer_flags |= GB_SPI_XFER_READ;
if (xfer == spi->last_xfer) {
if (!is_last_xfer_done(spi))
gb_xfer->xfer_flags |= GB_SPI_XFER_INPROGRESS;
msg->state = GB_SPI_STATE_OP_DONE;
continue;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment