Skip to content

Commit bb76044

Browse files
Martinhoff-makerfabiobaltieri
authored andcommitted
drivers: serial: silabs: Add new Kconfig symbol for async
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 <[email protected]>
1 parent c75fadb commit bb76044

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

drivers/serial/Kconfig.silabs_usart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ config UART_SILABS_USART
1515
select CLOCK_CONTROL
1616
help
1717
Enable the Silicon Labs usart driver.
18+
19+
if UART_SILABS_USART
20+
21+
config UART_SILABS_USART_ASYNC
22+
bool
23+
default y
24+
depends on DMA_SILABS_LDMA
25+
depends on UART_ASYNC_API
26+
help
27+
If 'y', Silabs usart driver will compile with support for UART async API.
28+
29+
endif

drivers/serial/uart_silabs_usart.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <zephyr/pm/device.h>
1717
#include <zephyr/pm/policy.h>
1818
#include <em_usart.h>
19-
#ifdef CONFIG_UART_ASYNC_API
19+
#ifdef CONFIG_UART_SILABS_USART_ASYNC
2020
#include <zephyr/drivers/dma.h>
2121
#include <zephyr/drivers/dma/dma_silabs_ldma.h>
2222
#endif
@@ -27,7 +27,7 @@ LOG_MODULE_REGISTER(uart_silabs_usart, CONFIG_UART_LOG_LEVEL);
2727
#define SILABS_USART_TIMEOUT_TO_TIMERCOUNTER(timeout, baudrate) \
2828
((timeout * NSEC_PER_USEC) / ((NSEC_PER_SEC / baudrate) * SILABS_USART_TIMER_COMPARE_VALUE))
2929

30-
#ifdef CONFIG_UART_ASYNC_API
30+
#ifdef CONFIG_UART_SILABS_USART_ASYNC
3131
struct uart_dma_channel {
3232
const struct device *dma_dev;
3333
uint32_t dma_channel;
@@ -64,7 +64,7 @@ struct uart_silabs_data {
6464
uart_irq_callback_user_data_t callback;
6565
void *cb_data;
6666
#endif
67-
#ifdef CONFIG_UART_ASYNC_API
67+
#ifdef CONFIG_UART_SILABS_USART_ASYNC
6868
const struct device *uart_dev;
6969
uart_callback_t async_cb;
7070
void *async_user_data;
@@ -303,7 +303,7 @@ static void uart_silabs_irq_callback_set(const struct device *dev, uart_irq_call
303303
}
304304
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
305305

306-
#ifdef CONFIG_UART_ASYNC_API
306+
#ifdef CONFIG_UART_SILABS_USART_ASYNC
307307
static inline void async_user_callback(struct uart_silabs_data *data, struct uart_event *event)
308308
{
309309
if (data->async_cb) {
@@ -741,15 +741,15 @@ static int uart_silabs_async_init(const struct device *dev)
741741

742742
return 0;
743743
}
744-
#endif /* CONFIG_UART_ASYNC_API */
744+
#endif /* CONFIG_UART_SILABS_USART_ASYNC */
745745

746746
static void uart_silabs_isr(const struct device *dev)
747747
{
748748
__maybe_unused struct uart_silabs_data *data = dev->data;
749749
const struct uart_silabs_config *config = dev->config;
750750
USART_TypeDef *usart = config->base;
751751
uint32_t flags = USART_IntGet(usart);
752-
#ifdef CONFIG_UART_ASYNC_API
752+
#ifdef CONFIG_UART_SILABS_USART_ASYNC
753753
struct dma_status stat;
754754
#endif
755755

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

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

815815
USART_IntClear(usart, USART_IF_TCMP2);
816816
}
817-
#endif /* CONFIG_UART_ASYNC_API */
817+
#endif /* CONFIG_UART_SILABS_USART_ASYNC */
818818
}
819819

820820
static inline USART_Parity_TypeDef uart_silabs_cfg2ll_parity(
@@ -971,7 +971,7 @@ static int uart_silabs_configure(const struct device *dev,
971971
USART_TypeDef *base = config->base;
972972
struct uart_silabs_data *data = dev->data;
973973

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

10281028
config->irq_config_func(dev);
10291029

1030-
#ifdef CONFIG_UART_ASYNC_API
1030+
#ifdef CONFIG_UART_SILABS_USART_ASYNC
10311031
err = uart_silabs_async_init(dev);
10321032
if (err < 0) {
10331033
return err;
@@ -1056,7 +1056,7 @@ static int uart_silabs_pm_action(const struct device *dev, enum pm_device_action
10561056

10571057
USART_Enable(config->base, usartEnable);
10581058
} else if (IS_ENABLED(CONFIG_PM_DEVICE) && (action == PM_DEVICE_ACTION_SUSPEND)) {
1059-
#ifdef CONFIG_UART_ASYNC_API
1059+
#ifdef CONFIG_UART_SILABS_USART_ASYNC
10601060
/* Entering suspend requires there to be no active asynchronous calls. */
10611061
__ASSERT_NO_MSG(!data->dma_rx.enabled);
10621062
__ASSERT_NO_MSG(!data->dma_tx.enabled);
@@ -1105,7 +1105,7 @@ static DEVICE_API(uart, uart_silabs_driver_api) = {
11051105
.irq_update = uart_silabs_irq_update,
11061106
.irq_callback_set = uart_silabs_irq_callback_set,
11071107
#endif
1108-
#ifdef CONFIG_UART_ASYNC_API
1108+
#ifdef CONFIG_UART_SILABS_USART_ASYNC
11091109
.callback_set = uart_silabs_async_callback_set,
11101110
.tx = uart_silabs_async_tx,
11111111
.tx_abort = uart_silabs_async_tx_abort,
@@ -1115,7 +1115,7 @@ static DEVICE_API(uart, uart_silabs_driver_api) = {
11151115
#endif
11161116
};
11171117

1118-
#ifdef CONFIG_UART_ASYNC_API
1118+
#ifdef CONFIG_UART_SILABS_USART_ASYNC
11191119

11201120
#define UART_DMA_CHANNEL_INIT(index, dir) \
11211121
.dma_##dir = { \

0 commit comments

Comments
 (0)