stm32: spi: Add lock around spi_transaction

Like the implementation for mec1322, add a lock around spi_transaction.
It prevents 2 tasks from accessing a given bus at the same time.

BRANCH=smaug
TEST=Check the BMI160 FIFO corruption disappeared in SPI mode.
BUG=None

Change-Id: I9e8a9e39ca96ea56692e3125930ab05ae6ef143f
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/289856
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Gwendal Grignou
2015-07-30 16:07:39 -07:00
committed by ChromeOS Commit Bot
parent 2356870a22
commit 8e9ccd8b0d

View File

@@ -11,6 +11,7 @@
#include "gpio.h"
#include "shared_mem.h"
#include "spi.h"
#include "task.h"
#include "timer.h"
#include "util.h"
@@ -22,6 +23,8 @@ static stm32_spi_regs_t *SPI_REGS[] = {
#endif
};
static struct mutex spi_mutex[ARRAY_SIZE(SPI_REGS)];
#define SPI_TRANSACTION_TIMEOUT_USEC (800 * MSEC)
/* Default DMA channel options */
@@ -245,9 +248,12 @@ int spi_transaction(const struct spi_device_t *spi_device,
uint8_t *rxdata, int rxlen)
{
int rv;
int port = spi_device->port;
mutex_lock(spi_mutex + port);
rv = spi_transaction_async(spi_device, txdata, txlen, rxdata, rxlen);
rv |= spi_transaction_flush(spi_device);
mutex_unlock(spi_mutex + port);
return rv;
}