From d2736a71fb342419ed7e548affe252e93e95196c Mon Sep 17 00:00:00 2001 From: Eric Yilun Lin Date: Thu, 24 Dec 2020 10:50:04 +0800 Subject: stm32/spi: disable DMA TX if it's not needed. This CL disable DMA TX when SPI NSS high, which means SPI client stops and won't receive any contents. Also, disable DMA on receiving SPI (spi_init) because there is no TX on SPI NSS just deasserted. BUG=b:156027159, b:173732816 TEST=run reboot test BRANCH=kukui Change-Id: Ia86a8728056f651db4b481eca4717b506f84498e Signed-off-by: Eric Yilun Lin Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2600811 Reviewed-by: Nicolas Boichat --- chip/stm32/spi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/chip/stm32/spi.c b/chip/stm32/spi.c index 4a36162f40..cee65a644c 100644 --- a/chip/stm32/spi.c +++ b/chip/stm32/spi.c @@ -315,6 +315,9 @@ static void setup_for_transaction(void) /* clear this as soon as possible */ setup_transaction_later = 0; + /* Stop sending DMA response before TX, if any */ + dma_disable(STM32_DMAC_SPI1_TX); + #ifndef CHIP_FAMILY_STM32H7 /* H7 is not ready to set status here */ /* Not ready to receive yet */ tx_status(EC_SPI_NOT_READY); @@ -323,9 +326,6 @@ static void setup_for_transaction(void) /* We are no longer actively processing a transaction */ state = SPI_STATE_PREPARE_RX; - /* Stop sending response, if any */ - dma_disable(STM32_DMAC_SPI1_TX); - /* * Read dummy bytes in case there are some pending; this prevents the * receive DMA from getting that byte right when we start it. @@ -477,6 +477,12 @@ void spi_event(enum gpio_signal signal) if (gpio_get_level(GPIO_SPI1_NSS)) { enable_sleep(SLEEP_MASK_SPI); + /* + * NSS is high (CS is deasserted), which means we can't + * do TX, disable DMA TX anyway. + */ + dma_get_channel(STM32_DMAC_SPI1_TX)->ccr &= ~STM32_DMA_CCR_TCIE; + /* * If the buffer is still used by the host command, postpone * the DMA rx setup. @@ -671,6 +677,9 @@ static void spi_init(void) STM32_RCC_APB2RSTR |= STM32_RCC_PB2_SPI1; STM32_RCC_APB2RSTR &= ~STM32_RCC_PB2_SPI1; + /* Reset the DMA TX. */ + dma_disable(STM32_DMAC_SPI1_TX); + /* Config SPI GPIO to high speed. This varies from board to board. */ board_set_stm32_spi_pin_speed(); -- cgit v1.2.1