summaryrefslogtreecommitdiff
path: root/chip/lm4
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2016-10-03 12:24:17 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-10-04 16:33:21 -0700
commit03857a3b350717d4b1c12d3aa61b51ea5e4cffcf (patch)
tree391254352285ec0e8d72b8b2caa288e35861dd3d /chip/lm4
parent9cd10a5a47544af10b0a4620130eaedd9c66eb42 (diff)
downloadchrome-ec-03857a3b350717d4b1c12d3aa61b51ea5e4cffcf.tar.gz
spi: Add lock around spi_transaction
spi_transaction() can be called from motionsense, hooks, hostcmd, console, and chipset tasks, so add a mutex to ensure an in-process transaction isn't preempted by another transaction. BUG=chrome-os-partner:57912 BRANCH=gru TEST=On kevin, run "while true; do ectool motionsense odr 0 0; sleep 1; ectool motionsense odr 0 1000000; sleep 1; done", verify watchdog crash not encountered after 20 minutes. Change-Id: I7ec495bab295dc03ce02372c20e5c7c5c196715d Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/391892 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit eabdea443775fab834aaabbb7afae871306c7530) Reviewed-on: https://chromium-review.googlesource.com/392226 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'chip/lm4')
-rw-r--r--chip/lm4/spi.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/chip/lm4/spi.c b/chip/lm4/spi.c
index 3fd3bc96de..0e43642bca 100644
--- a/chip/lm4/spi.c
+++ b/chip/lm4/spi.c
@@ -64,8 +64,10 @@ int spi_transaction(const struct spi_device_t *spi_device,
{
int totallen = txlen + rxlen;
int txcount = 0, rxcount = 0;
+ static struct mutex spi_mutex;
volatile uint32_t dummy __attribute__((unused));
+ mutex_lock(&spi_mutex);
/* Empty the receive FIFO */
while (LM4_SSI_SR(0) & LM4_SSI_SR_RNE)
dummy = LM4_SSI_DR(0);
@@ -104,6 +106,7 @@ int spi_transaction(const struct spi_device_t *spi_device,
/* End transaction */
gpio_set_level(spi_device->gpio_cs, 1);
+ mutex_unlock(&spi_mutex);
return EC_SUCCESS;
}