From 5b6fadc10d3be7120a808928f11389a6151944d2 Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Fri, 8 Mar 2024 12:22:00 -0600 Subject: [PATCH] drivers: mipi_dbi: mipi_dbi_spi: do not take spinlock Taking a spinlock will result in interrupts being blocked in the MIPI DBI driver, which is not desired behavior while issuing SPI transfers, since the driver may use interrupts to drive the transfer Fixes #68815 Signed-off-by: Daniel DeGrasse --- drivers/mipi_dbi/mipi_dbi_spi.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/mipi_dbi/mipi_dbi_spi.c b/drivers/mipi_dbi/mipi_dbi_spi.c index 87456868e0d01a..846158efee65ae 100644 --- a/drivers/mipi_dbi/mipi_dbi_spi.c +++ b/drivers/mipi_dbi/mipi_dbi_spi.c @@ -25,7 +25,7 @@ struct mipi_dbi_spi_config { struct mipi_dbi_spi_data { /* Used for 3 wire mode */ uint16_t spi_byte; - struct k_spinlock lock; + struct k_mutex lock; }; /* Expands to 1 if the node does not have the `write-only` property */ @@ -58,7 +58,11 @@ static int mipi_dbi_spi_write_helper(const struct device *dev, .count = 1, }; int ret = 0; - k_spinlock_key_t spinlock_key = k_spin_lock(&data->lock); + + ret = k_mutex_lock(&data->lock, K_FOREVER); + if (ret < 0) { + return ret; + } if (dbi_config->mode == MIPI_DBI_MODE_SPI_3WIRE && IS_ENABLED(CONFIG_MIPI_DBI_SPI_3WIRE)) { @@ -124,7 +128,7 @@ static int mipi_dbi_spi_write_helper(const struct device *dev, ret = -ENOTSUP; } out: - k_spin_unlock(&data->lock, spinlock_key); + k_mutex_unlock(&data->lock); return ret; } @@ -164,9 +168,12 @@ static int mipi_dbi_spi_command_read(const struct device *dev, .count = 1, }; int ret = 0; - k_spinlock_key_t spinlock_key = k_spin_lock(&data->lock); struct spi_config tmp_config; + ret = k_mutex_lock(&data->lock, K_FOREVER); + if (ret < 0) { + return ret; + } memcpy(&tmp_config, &dbi_config->config, sizeof(tmp_config)); if (dbi_config->mode == MIPI_DBI_MODE_SPI_3WIRE && IS_ENABLED(CONFIG_MIPI_DBI_SPI_3WIRE)) { @@ -231,7 +238,7 @@ static int mipi_dbi_spi_command_read(const struct device *dev, } out: spi_release(config->spi_dev, &tmp_config); - k_spin_unlock(&data->lock, spinlock_key); + k_mutex_unlock(&data->lock); return ret; } @@ -262,6 +269,7 @@ static int mipi_dbi_spi_reset(const struct device *dev, uint32_t delay) static int mipi_dbi_spi_init(const struct device *dev) { const struct mipi_dbi_spi_config *config = dev->config; + struct mipi_dbi_spi_data *data = dev->data; int ret; if (!device_is_ready(config->spi_dev)) { @@ -291,6 +299,8 @@ static int mipi_dbi_spi_init(const struct device *dev) } } + k_mutex_init(&data->lock); + return 0; }