drivers: spi: stm32: factor out completion routine

Polled and IRQ-driven SPI I/O share code for cleanup and completion,
which can now be factored into its own routine.

This keeps a single point of truth for common paths, which will allow
a subsequent bug fix to happen in one place, and help avoid future
regressions.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
This commit is contained in:
Marti Bolivar 2017-07-17 14:35:22 -04:00 committed by Anas Nashif
commit b13b2c591e

View file

@ -33,10 +33,6 @@
LL_SPI_SR_OVR | LL_SPI_SR_FRE)
#endif
#ifdef CONFIG_SPI_STM32_INTERRUPT
static void spi_stm32_transmit(SPI_TypeDef *spi, struct spi_stm32_data *data);
static void spi_stm32_receive(SPI_TypeDef *spi, struct spi_stm32_data *data);
static int spi_stm32_get_err(SPI_TypeDef *spi)
{
u32_t sr = LL_SPI_ReadReg(spi, SR);
@ -47,9 +43,11 @@ static int spi_stm32_get_err(SPI_TypeDef *spi)
static void spi_stm32_complete(struct spi_stm32_data *data, SPI_TypeDef *spi,
int status)
{
#ifdef CONFIG_SPI_STM32_INTERRUPT
LL_SPI_DisableIT_TXE(spi);
LL_SPI_DisableIT_RXNE(spi);
LL_SPI_DisableIT_ERR(spi);
#endif
spi_context_cs_control(&data->ctx, false);
@ -67,9 +65,15 @@ static void spi_stm32_complete(struct spi_stm32_data *data, SPI_TypeDef *spi,
LL_SPI_Disable(spi);
}
#ifdef CONFIG_SPI_STM32_INTERRUPT
spi_context_complete(&data->ctx, status);
#endif
}
#ifdef CONFIG_SPI_STM32_INTERRUPT
static void spi_stm32_transmit(SPI_TypeDef *spi, struct spi_stm32_data *data);
static void spi_stm32_receive(SPI_TypeDef *spi, struct spi_stm32_data *data);
static void spi_stm32_isr(void *arg)
{
struct device * const dev = (struct device *) arg;
@ -289,6 +293,7 @@ static int transceive(struct spi_config *config,
LL_SPI_Enable(spi);
/* This is turned off in spi_stm32_complete(). */
spi_context_cs_control(&data->ctx, true);
#ifdef CONFIG_SPI_STM32_INTERRUPT
@ -318,21 +323,7 @@ static int transceive(struct spi_config *config,
} while (spi_context_tx_on(&data->ctx) ||
spi_context_rx_on(&data->ctx));
spi_context_cs_control(&data->ctx, false);
#if defined(CONFIG_SOC_SERIES_STM32L4X) || defined(CONFIG_SOC_SERIES_STM32F3X)
/* Flush RX buffer */
while (LL_SPI_IsActiveFlag_RXNE(spi)) {
(void) LL_SPI_ReceiveData8(spi);
}
#endif
if (LL_SPI_GetMode(spi) == LL_SPI_MODE_MASTER) {
while (LL_SPI_IsActiveFlag_BSY(spi)) {
/* NOP */
}
LL_SPI_Disable(spi);
}
spi_stm32_complete(data, spi, ret);
#endif
spi_context_release(&data->ctx, 0);