Skip to content

Commit

Permalink
drivers: serial: silabs: Add new Kconfig symbol for async
Browse files Browse the repository at this point in the history
Add a new Kconfig symbol (UART_SILABS_USART_ASYNC) to enable the async
API for the Silabs USART driver.
It is needed because the symbol (UART_ASYNC_API) is shared between uart
driver. In the case that you have multiple UART drivers enabled,
condition to enable async API for different uart driver may differ.

Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
  • Loading branch information
Martinhoff-maker authored and fabiobaltieri committed Feb 20, 2025
1 parent c75fadb commit bb76044
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
12 changes: 12 additions & 0 deletions drivers/serial/Kconfig.silabs_usart
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ config UART_SILABS_USART
select CLOCK_CONTROL
help
Enable the Silicon Labs usart driver.

if UART_SILABS_USART

config UART_SILABS_USART_ASYNC
bool
default y
depends on DMA_SILABS_LDMA
depends on UART_ASYNC_API
help
If 'y', Silabs usart driver will compile with support for UART async API.

endif
26 changes: 13 additions & 13 deletions drivers/serial/uart_silabs_usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <zephyr/pm/device.h>
#include <zephyr/pm/policy.h>
#include <em_usart.h>
#ifdef CONFIG_UART_ASYNC_API
#ifdef CONFIG_UART_SILABS_USART_ASYNC
#include <zephyr/drivers/dma.h>
#include <zephyr/drivers/dma/dma_silabs_ldma.h>
#endif
Expand All @@ -27,7 +27,7 @@ LOG_MODULE_REGISTER(uart_silabs_usart, CONFIG_UART_LOG_LEVEL);
#define SILABS_USART_TIMEOUT_TO_TIMERCOUNTER(timeout, baudrate) \
((timeout * NSEC_PER_USEC) / ((NSEC_PER_SEC / baudrate) * SILABS_USART_TIMER_COMPARE_VALUE))

#ifdef CONFIG_UART_ASYNC_API
#ifdef CONFIG_UART_SILABS_USART_ASYNC
struct uart_dma_channel {
const struct device *dma_dev;
uint32_t dma_channel;
Expand Down Expand Up @@ -64,7 +64,7 @@ struct uart_silabs_data {
uart_irq_callback_user_data_t callback;
void *cb_data;
#endif
#ifdef CONFIG_UART_ASYNC_API
#ifdef CONFIG_UART_SILABS_USART_ASYNC
const struct device *uart_dev;
uart_callback_t async_cb;
void *async_user_data;
Expand Down Expand Up @@ -303,7 +303,7 @@ static void uart_silabs_irq_callback_set(const struct device *dev, uart_irq_call
}
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

#ifdef CONFIG_UART_ASYNC_API
#ifdef CONFIG_UART_SILABS_USART_ASYNC
static inline void async_user_callback(struct uart_silabs_data *data, struct uart_event *event)
{
if (data->async_cb) {
Expand Down Expand Up @@ -741,15 +741,15 @@ static int uart_silabs_async_init(const struct device *dev)

return 0;
}
#endif /* CONFIG_UART_ASYNC_API */
#endif /* CONFIG_UART_SILABS_USART_ASYNC */

static void uart_silabs_isr(const struct device *dev)
{
__maybe_unused struct uart_silabs_data *data = dev->data;
const struct uart_silabs_config *config = dev->config;
USART_TypeDef *usart = config->base;
uint32_t flags = USART_IntGet(usart);
#ifdef CONFIG_UART_ASYNC_API
#ifdef CONFIG_UART_SILABS_USART_ASYNC
struct dma_status stat;
#endif

Expand All @@ -764,7 +764,7 @@ static void uart_silabs_isr(const struct device *dev)
data->callback(dev, data->cb_data);
}
#endif
#ifdef CONFIG_UART_ASYNC_API
#ifdef CONFIG_UART_SILABS_USART_ASYNC
if (flags & USART_IF_TCMP1) {

data->dma_rx.timeout_cnt++;
Expand Down Expand Up @@ -814,7 +814,7 @@ static void uart_silabs_isr(const struct device *dev)

USART_IntClear(usart, USART_IF_TCMP2);
}
#endif /* CONFIG_UART_ASYNC_API */
#endif /* CONFIG_UART_SILABS_USART_ASYNC */
}

static inline USART_Parity_TypeDef uart_silabs_cfg2ll_parity(
Expand Down Expand Up @@ -971,7 +971,7 @@ static int uart_silabs_configure(const struct device *dev,
USART_TypeDef *base = config->base;
struct uart_silabs_data *data = dev->data;

#ifdef CONFIG_UART_ASYNC_API
#ifdef CONFIG_UART_SILABS_USART_ASYNC
if (data->dma_rx.enabled || data->dma_tx.enabled) {
return -EBUSY;
}
Expand Down Expand Up @@ -1027,7 +1027,7 @@ static int uart_silabs_init(const struct device *dev)

config->irq_config_func(dev);

#ifdef CONFIG_UART_ASYNC_API
#ifdef CONFIG_UART_SILABS_USART_ASYNC
err = uart_silabs_async_init(dev);
if (err < 0) {
return err;
Expand Down Expand Up @@ -1056,7 +1056,7 @@ static int uart_silabs_pm_action(const struct device *dev, enum pm_device_action

USART_Enable(config->base, usartEnable);
} else if (IS_ENABLED(CONFIG_PM_DEVICE) && (action == PM_DEVICE_ACTION_SUSPEND)) {
#ifdef CONFIG_UART_ASYNC_API
#ifdef CONFIG_UART_SILABS_USART_ASYNC
/* Entering suspend requires there to be no active asynchronous calls. */
__ASSERT_NO_MSG(!data->dma_rx.enabled);
__ASSERT_NO_MSG(!data->dma_tx.enabled);
Expand Down Expand Up @@ -1105,7 +1105,7 @@ static DEVICE_API(uart, uart_silabs_driver_api) = {
.irq_update = uart_silabs_irq_update,
.irq_callback_set = uart_silabs_irq_callback_set,
#endif
#ifdef CONFIG_UART_ASYNC_API
#ifdef CONFIG_UART_SILABS_USART_ASYNC
.callback_set = uart_silabs_async_callback_set,
.tx = uart_silabs_async_tx,
.tx_abort = uart_silabs_async_tx_abort,
Expand All @@ -1115,7 +1115,7 @@ static DEVICE_API(uart, uart_silabs_driver_api) = {
#endif
};

#ifdef CONFIG_UART_ASYNC_API
#ifdef CONFIG_UART_SILABS_USART_ASYNC

#define UART_DMA_CHANNEL_INIT(index, dir) \
.dma_##dir = { \
Expand Down

0 comments on commit bb76044

Please sign in to comment.