summaryrefslogtreecommitdiff
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
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>
-rw-r--r--chip/it83xx/spi.c3
-rw-r--r--chip/lm4/spi.c3
-rw-r--r--chip/npcx/spi.c3
3 files changed, 9 insertions, 0 deletions
diff --git a/chip/it83xx/spi.c b/chip/it83xx/spi.c
index 8e8ebf47d6..1337f7ccac 100644
--- a/chip/it83xx/spi.c
+++ b/chip/it83xx/spi.c
@@ -109,7 +109,9 @@ int spi_transaction(const struct spi_device_t *spi_device,
{
int idx;
uint8_t port = spi_device->port;
+ static struct mutex spi_mutex;
+ mutex_lock(&spi_mutex);
/* bit[0]: Write cycle */
IT83XX_SSPI_SPICTRL2 &= ~0x04;
for (idx = 0x00; idx < txlen; idx++) {
@@ -135,6 +137,7 @@ int spi_transaction(const struct spi_device_t *spi_device,
}
sspi_transmission_end();
+ mutex_unlock(&spi_mutex);
return EC_SUCCESS;
}
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;
}
diff --git a/chip/npcx/spi.c b/chip/npcx/spi.c
index 790f4c1e47..3079c05b1a 100644
--- a/chip/npcx/spi.c
+++ b/chip/npcx/spi.c
@@ -131,7 +131,9 @@ int spi_transaction(const struct spi_device_t *spi_device,
{
int i = 0;
enum gpio_signal gpio = spi_device->gpio_cs;
+ static struct mutex spi_lock;
+ mutex_lock(&spi_lock);
/* Make sure CS# is a GPIO output mode. */
gpio_set_flags(gpio, GPIO_OUTPUT);
/* Make sure CS# is deselected */
@@ -174,6 +176,7 @@ int spi_transaction(const struct spi_device_t *spi_device,
}
/* Deassert CS# (high) to end transaction */
gpio_set_level(gpio, 1);
+ mutex_unlock(&spi_lock);
return EC_SUCCESS;
}