From 375db6e0804d46ebe2ac006b0f003fd6342564f3 Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Mon, 1 Mar 2021 10:44:54 +0100 Subject: [PATCH] drivers/spi: stm32 convert dma to new DT_DMA helper macros New DT_DMA helper macors are available to access DMA node identifier. Use them Signed-off-by: Erwan Gouriou --- drivers/spi/spi_ll_stm32.c | 31 +++++++++++++------------------ drivers/spi/spi_ll_stm32.h | 1 - 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/drivers/spi/spi_ll_stm32.c b/drivers/spi/spi_ll_stm32.c index 9424803d51..65aa029e40 100644 --- a/drivers/spi/spi_ll_stm32.c +++ b/drivers/spi/spi_ll_stm32.c @@ -768,8 +768,8 @@ static int spi_stm32_transceive(const struct device *dev, #ifdef CONFIG_SPI_STM32_DMA struct spi_stm32_data *data = DEV_DATA(dev); - if ((data->dma_tx.dma_name != NULL) - && (data->dma_rx.dma_name != NULL)) { + if ((data->dma_tx.dma_dev != NULL) + && (data->dma_rx.dma_dev != NULL)) { return transceive_dma(dev, config, tx_bufs, rx_bufs, false, NULL); } @@ -822,21 +822,16 @@ static int spi_stm32_init(const struct device *dev) #endif #ifdef CONFIG_SPI_STM32_DMA - if (data->dma_tx.dma_name != NULL) { - /* Get the binding to the DMA device */ - data->dma_tx.dma_dev = device_get_binding(data->dma_tx.dma_name); - if (!data->dma_tx.dma_dev) { - LOG_ERR("%s device not found", data->dma_tx.dma_name); - return -ENODEV; - } + if ((data->dma_rx.dma_dev != NULL) && + !device_is_ready(data->dma_rx.dma_dev)) { + LOG_ERR("%s device not ready", data->dma_rx.dma_dev->name); + return -ENODEV; } - if (data->dma_rx.dma_name != NULL) { - data->dma_rx.dma_dev = device_get_binding(data->dma_rx.dma_name); - if (!data->dma_rx.dma_dev) { - LOG_ERR("%s device not found", data->dma_rx.dma_name); - return -ENODEV; - } + if ((data->dma_tx.dma_dev != NULL) && + !device_is_ready(data->dma_tx.dma_dev)) { + LOG_ERR("%s device not ready", data->dma_tx.dma_dev->name); + return -ENODEV; } #endif /* CONFIG_SPI_STM32_DMA */ spi_context_unlock_unconditionally(&data->ctx); @@ -867,11 +862,13 @@ static void spi_stm32_irq_config_func_##id(const struct device *dev) \ DT_INST_DMAS_CELL_BY_NAME(id, dir, channel_config) #define DMA_FEATURES(id, dir) \ DT_INST_DMAS_CELL_BY_NAME(id, dir, features) +#define DMA_CTLR(id, dir) \ + DT_INST_DMAS_CTLR_BY_NAME(id, dir) #define SPI_DMA_CHANNEL_INIT(index, dir, dir_cap, src_dev, dest_dev) \ - .dma_name = DT_INST_DMAS_LABEL_BY_NAME(index, dir), \ .channel = \ DT_INST_DMAS_CELL_BY_NAME(index, dir, channel), \ + .dma_dev = DEVICE_DT_GET(DMA_CTLR(index, dir)), \ .dma_cfg = { \ .dma_slot = \ DT_INST_DMAS_CELL_BY_NAME(index, dir, slot), \ @@ -903,11 +900,9 @@ static void spi_stm32_irq_config_func_##id(const struct device *dev) \ (SPI_DMA_CHANNEL_INIT(id, dir, DIR, src, dest)),\ (NULL)) \ }, - #define SPI_DMA_STATUS_SEM(id) \ .status_sem = Z_SEM_INITIALIZER( \ spi_stm32_dev_data_##id.status_sem, 0, 1), - #else #define SPI_DMA_CHANNEL(id, dir, DIR, src, dest) #define SPI_DMA_STATUS_SEM(id) diff --git a/drivers/spi/spi_ll_stm32.h b/drivers/spi/spi_ll_stm32.h index eb37dc6e00..8639ef924f 100644 --- a/drivers/spi/spi_ll_stm32.h +++ b/drivers/spi/spi_ll_stm32.h @@ -30,7 +30,6 @@ struct spi_stm32_config { (SPI_STM32_DMA_RX_DONE_FLAG | SPI_STM32_DMA_TX_DONE_FLAG) struct stream { - const char *dma_name; const struct device *dma_dev; uint32_t channel; /* stores the channel for dma or mux */ struct dma_config dma_cfg;