Skip to content

Commit

Permalink
spi: spi-mem: Claim SPI bus before spi mem access
Browse files Browse the repository at this point in the history
It is necessary to call spi_claim_bus() before starting any SPI
transactions and this restriction would also apply when calling spi-mem
operations. Therefore claim and release bus before requesting transfer
via exec_op.

Signed-off-by: Vignesh R <[email protected]>
Tested-by: Simon Goldschmidt <[email protected]>
Tested-by: Stefan Roese <[email protected]>
Tested-by: Horatiu Vultur <[email protected]>
Reviewed-by: Jagan Teki <[email protected]>
Tested-by: Jagan Teki <[email protected]> #zynq-microzed
  • Loading branch information
r-vignesh authored and openedev committed Feb 7, 2019
1 parent 12563f7 commit 7609448
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions drivers/spi/spi-mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)
if (!spi_mem_supports_op(slave, op))
return -ENOTSUPP;

ret = spi_claim_bus(slave);
if (ret < 0)
return ret;

if (ops->mem_ops) {
#ifndef __UBOOT__
/*
Expand All @@ -232,6 +236,7 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)
mutex_lock(&ctlr->io_mutex);
#endif
ret = ops->mem_ops->exec_op(slave, op);

#ifndef __UBOOT__
mutex_unlock(&ctlr->io_mutex);
mutex_unlock(&ctlr->bus_lock_mutex);
Expand All @@ -245,8 +250,10 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)
* read path) and expect the core to use the regular SPI
* interface in other cases.
*/
if (!ret || ret != -ENOTSUPP)
if (!ret || ret != -ENOTSUPP) {
spi_release_bus(slave);
return ret;
}
}

#ifndef __UBOOT__
Expand Down Expand Up @@ -333,10 +340,6 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)
op_len = sizeof(op->cmd.opcode) + op->addr.nbytes + op->dummy.nbytes;
op_buf = calloc(1, op_len);

ret = spi_claim_bus(slave);
if (ret < 0)
return ret;

op_buf[pos++] = op->cmd.opcode;

if (op->addr.nbytes) {
Expand Down

0 comments on commit 7609448

Please sign in to comment.