summaryrefslogtreecommitdiff
path: root/chip/stm32/spi_master.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-07-30 16:07:39 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-08-01 02:50:29 +0000
commit8e9ccd8b0d44b013a6bc27827bec767567ff045a (patch)
tree7f36206a851a658723d6151929e9b5b08bd8d4f0 /chip/stm32/spi_master.c
parent2356870a224474adfb7162cc8ed0b1c3abbdb034 (diff)
downloadchrome-ec-8e9ccd8b0d44b013a6bc27827bec767567ff045a.tar.gz
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>
Diffstat (limited to 'chip/stm32/spi_master.c')
-rw-r--r--chip/stm32/spi_master.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/chip/stm32/spi_master.c b/chip/stm32/spi_master.c
index 26d279f19c..f8cebc295d 100644
--- a/chip/stm32/spi_master.c
+++ b/chip/stm32/spi_master.c
@@ -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;
}