7e0eed9235
Usually, we want to operate only on "available" device nodes ("available" means "status is okay and a matching binding is found"), but that's not true in all cases. Sometimes we want to operate on special nodes without matching bindings, such as those describing memory. To handle the distinction, change various additional devicetree APIs making it clear that they operate only on available device nodes, adjusting gen_defines and devicetree.h implementation details accordingly: - emit macros for all existing nodes in gen_defines.py, regardless of status or matching binding - rename DT_NUM_INST to DT_NUM_INST_STATUS_OKAY - rename DT_NODE_HAS_COMPAT to DT_NODE_HAS_COMPAT_STATUS_OKAY - rename DT_INST_FOREACH to DT_INST_FOREACH_STATUS_OKAY - rename DT_ANY_INST_ON_BUS to DT_ANY_INST_ON_BUS_STATUS_OKAY - rewrite DT_HAS_NODE_STATUS_OKAY in terms of a new DT_NODE_HAS_STATUS - resurrect DT_HAS_NODE in the form of DT_NODE_EXISTS - remove DT_COMPAT_ON_BUS as a public API - use the new default_prop_types edtlib parameter Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
185 lines
3.9 KiB
C
185 lines
3.9 KiB
C
/*
|
|
* Copyright (c) 2016 BayLibre, SAS
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#ifndef ZEPHYR_DRIVERS_SPI_SPI_LL_STM32_H_
|
|
#define ZEPHYR_DRIVERS_SPI_SPI_LL_STM32_H_
|
|
|
|
#include "spi_context.h"
|
|
|
|
typedef void (*irq_config_func_t)(struct device *port);
|
|
|
|
struct spi_stm32_config {
|
|
struct stm32_pclken pclken;
|
|
SPI_TypeDef *spi;
|
|
#ifdef CONFIG_SPI_STM32_INTERRUPT
|
|
irq_config_func_t irq_config;
|
|
#endif
|
|
};
|
|
|
|
#ifdef CONFIG_SPI_STM32_DMA
|
|
struct stream {
|
|
const char *dma_name;
|
|
u32_t channel; /* stores the channel for dma or mux */
|
|
struct dma_config dma_cfg;
|
|
u8_t priority;
|
|
bool src_addr_increment;
|
|
bool dst_addr_increment;
|
|
bool transfer_complete;
|
|
int fifo_threshold;
|
|
};
|
|
#endif
|
|
|
|
struct spi_stm32_data {
|
|
struct spi_context ctx;
|
|
#ifdef CONFIG_SPI_STM32_DMA
|
|
struct device *dev_dma_tx;
|
|
struct device *dev_dma_rx;
|
|
struct stream dma_rx;
|
|
struct stream dma_tx;
|
|
size_t dma_segment_len;
|
|
#endif
|
|
};
|
|
|
|
static inline u32_t ll_func_tx_is_empty(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
return LL_SPI_IsActiveFlag_TXP(spi);
|
|
#else
|
|
return LL_SPI_IsActiveFlag_TXE(spi);
|
|
#endif
|
|
}
|
|
|
|
static inline u32_t ll_func_rx_is_not_empty(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
return LL_SPI_IsActiveFlag_RXP(spi);
|
|
#else
|
|
return LL_SPI_IsActiveFlag_RXNE(spi);
|
|
#endif
|
|
}
|
|
|
|
static inline void ll_func_enable_int_tx_empty(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
LL_SPI_EnableIT_TXP(spi);
|
|
#else
|
|
LL_SPI_EnableIT_TXE(spi);
|
|
#endif
|
|
}
|
|
|
|
static inline void ll_func_enable_int_rx_not_empty(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
LL_SPI_EnableIT_RXP(spi);
|
|
#else
|
|
LL_SPI_EnableIT_RXNE(spi);
|
|
#endif
|
|
}
|
|
|
|
static inline void ll_func_enable_int_errors(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
LL_SPI_EnableIT_UDR(spi);
|
|
LL_SPI_EnableIT_OVR(spi);
|
|
LL_SPI_EnableIT_CRCERR(spi);
|
|
LL_SPI_EnableIT_FRE(spi);
|
|
LL_SPI_EnableIT_MODF(spi);
|
|
#else
|
|
LL_SPI_EnableIT_ERR(spi);
|
|
#endif
|
|
}
|
|
|
|
static inline void ll_func_disable_int_tx_empty(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
LL_SPI_DisableIT_TXP(spi);
|
|
#else
|
|
LL_SPI_DisableIT_TXE(spi);
|
|
#endif
|
|
}
|
|
|
|
static inline void ll_func_disable_int_rx_not_empty(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
LL_SPI_DisableIT_RXP(spi);
|
|
#else
|
|
LL_SPI_DisableIT_RXNE(spi);
|
|
#endif
|
|
}
|
|
|
|
static inline void ll_func_disable_int_errors(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
LL_SPI_DisableIT_UDR(spi);
|
|
LL_SPI_DisableIT_OVR(spi);
|
|
LL_SPI_DisableIT_CRCERR(spi);
|
|
LL_SPI_DisableIT_FRE(spi);
|
|
LL_SPI_DisableIT_MODF(spi);
|
|
#else
|
|
LL_SPI_DisableIT_ERR(spi);
|
|
#endif
|
|
}
|
|
|
|
static inline u32_t ll_func_spi_is_busy(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
return (!LL_SPI_IsActiveFlag_MODF(spi) &&
|
|
!LL_SPI_IsActiveFlag_TXC(spi));
|
|
#else
|
|
return LL_SPI_IsActiveFlag_BSY(spi);
|
|
#endif
|
|
}
|
|
|
|
/* Header is compiled first, this switch avoid the compiler to lookup for
|
|
* non-existing LL FIFO functions for SoC without SPI FIFO
|
|
*/
|
|
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_spi_fifo)
|
|
static inline void ll_func_set_fifo_threshold_8bit(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
LL_SPI_SetFIFOThreshold(spi, LL_SPI_FIFO_TH_01DATA);
|
|
#else
|
|
LL_SPI_SetRxFIFOThreshold(spi, LL_SPI_RX_FIFO_TH_QUARTER);
|
|
#endif
|
|
}
|
|
|
|
static inline void ll_func_set_fifo_threshold_16bit(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
LL_SPI_SetFIFOThreshold(spi, LL_SPI_FIFO_TH_02DATA);
|
|
#else
|
|
LL_SPI_SetRxFIFOThreshold(spi, LL_SPI_RX_FIFO_TH_HALF);
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
static inline void ll_func_disable_spi(SPI_TypeDef *spi)
|
|
{
|
|
#ifdef CONFIG_SOC_SERIES_STM32MP1X
|
|
if (LL_SPI_IsActiveMasterTransfer(spi)) {
|
|
LL_SPI_SuspendMasterTransfer(spi);
|
|
while (LL_SPI_IsActiveMasterTransfer(spi)) {
|
|
/* NOP */
|
|
}
|
|
}
|
|
|
|
LL_SPI_Disable(spi);
|
|
while (LL_SPI_IsEnabled(spi)) {
|
|
/* NOP */
|
|
}
|
|
|
|
/* Flush RX buffer */
|
|
while (LL_SPI_IsActiveFlag_RXP(spi)) {
|
|
(void)LL_SPI_ReceiveData8(spi);
|
|
}
|
|
LL_SPI_ClearFlag_SUSP(spi);
|
|
#else
|
|
LL_SPI_Disable(spi);
|
|
#endif
|
|
}
|
|
|
|
#endif /* ZEPHYR_DRIVERS_SPI_SPI_LL_STM32_H_ */
|