drivers: uart_mcux_lpuart: Handle multiple uart case
Handle the case where there are multiple different kinds of UART on one
platform, the other UART driver select SERIAL_SUPPORT_ASYNC but LPUART
did not, causing build error in LPUART driver. Shield LPUART driver from
this case by introducing driver config to indicate that in fact LPUART
is the one enabling ASYNC.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
diff --git a/drivers/serial/Kconfig.mcux_lpuart b/drivers/serial/Kconfig.mcux_lpuart
index b59578a..f95ab24 100644
--- a/drivers/serial/Kconfig.mcux_lpuart
+++ b/drivers/serial/Kconfig.mcux_lpuart
@@ -8,15 +8,24 @@
depends on CLOCK_CONTROL
select SERIAL_HAS_DRIVER
select SERIAL_SUPPORT_INTERRUPT
- select SERIAL_SUPPORT_ASYNC if $(dt_compat_any_has_prop,$(DT_COMPAT_NXP_LPUART),dmas)
- select DMA if UART_ASYNC_API
select PINCTRL
help
Enable the MCUX LPUART driver.
+if UART_MCUX_LPUART
+
config UART_MCUX_LPUART_ISR_SUPPORT
bool
- depends on UART_MCUX_LPUART
default y if UART_INTERRUPT_DRIVEN || PM || UART_ASYNC_API
help
Enable UART interrupt service routine.
+
+config UART_NXP_LPUART_ASYNC_API_SUPPORT
+ bool
+ default y if $(dt_compat_any_has_prop,$(DT_COMPAT_NXP_LPUART),dmas)
+ select SERIAL_SUPPORT_ASYNC
+ select DMA if UART_ASYNC_API
+ help
+ Indicates if LPUART has async api support by having dmas enabled for it
+
+endif
diff --git a/drivers/serial/uart_mcux_lpuart.c b/drivers/serial/uart_mcux_lpuart.c
index 7faf225..6768567 100644
--- a/drivers/serial/uart_mcux_lpuart.c
+++ b/drivers/serial/uart_mcux_lpuart.c
@@ -7,6 +7,9 @@
#define DT_DRV_COMPAT nxp_lpuart
+#define LPUART_ASYNC_ENABLE \
+ IS_ENABLED(CONFIG_UART_ASYNC_API) && IS_ENABLED(CONFIG_UART_NXP_LPUART_ASYNC_API_SUPPORT)
+
#include <errno.h>
#include <zephyr/device.h>
#include <zephyr/drivers/uart.h>
@@ -15,7 +18,7 @@
#include <zephyr/kernel.h>
#include <zephyr/pm/policy.h>
#include <zephyr/drivers/pinctrl.h>
-#ifdef CONFIG_UART_ASYNC_API
+#if LPUART_ASYNC_ENABLE
#include <zephyr/drivers/dma.h>
#endif
#include <zephyr/logging/log.h>
@@ -40,7 +43,7 @@
#define LPUART_HAS_MCR 1
#endif
-#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_INTERRUPT_DRIVEN)
+#if LPUART_ASYNC_ENABLE && defined(CONFIG_UART_INTERRUPT_DRIVEN)
/* there are already going to be build errors, but at least this message will
* be the first error from this driver making the reason clear
*/
@@ -48,13 +51,13 @@
"LPUART must use exclusive api callbacks");
#endif
-#ifdef CONFIG_UART_ASYNC_API
+#if LPUART_ASYNC_ENABLE
struct lpuart_dma_config {
const struct device *dma_dev;
const uint32_t dma_channel;
struct dma_config dma_cfg;
};
-#endif /* CONFIG_UART_ASYNC_API */
+#endif /* LPUART_ASYNC_ENABLE */
struct mcux_lpuart_config {
LPUART_Type *base;
@@ -72,13 +75,13 @@
#ifdef CONFIG_UART_MCUX_LPUART_ISR_SUPPORT
void (*irq_config_func)(const struct device *dev);
#endif
-#ifdef CONFIG_UART_ASYNC_API
+#if LPUART_ASYNC_ENABLE
const struct lpuart_dma_config rx_dma_config;
const struct lpuart_dma_config tx_dma_config;
-#endif /* CONFIG_UART_ASYNC_API */
+#endif /* LPUART_ASYNC_ENABLE */
};
-#ifdef CONFIG_UART_ASYNC_API
+#if LPUART_ASYNC_ENABLE
struct mcux_lpuart_rx_dma_params {
struct dma_block_config active_dma_block;
uint8_t *buf;
@@ -126,7 +129,7 @@
bool tx_poll_stream_on;
bool tx_int_stream_on;
#endif /* CONFIG_PM */
-#ifdef CONFIG_UART_ASYNC_API
+#if LPUART_ASYNC_ENABLE
struct mcux_lpuart_async_data async;
#endif
struct uart_config uart_config;
@@ -423,7 +426,7 @@
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
-#ifdef CONFIG_UART_ASYNC_API
+#if LPUART_ASYNC_ENABLE
static inline void async_timer_start(struct k_work_delayable *work, size_t timeout_us)
{
if ((timeout_us != SYS_FOREVER_US) && (timeout_us != 0)) {
@@ -906,7 +909,7 @@
(void)mcux_lpuart_tx_abort(dev);
}
-#endif /* CONFIG_UART_ASYNC_API */
+#endif /* LPUART_ASYNC_ENABLE */
#if CONFIG_UART_MCUX_LPUART_ISR_SUPPORT
@@ -925,7 +928,7 @@
}
#endif
-#ifdef CONFIG_UART_ASYNC_API
+#if LPUART_ASYNC_ENABLE
static inline void mcux_lpuart_async_isr(struct mcux_lpuart_data *data,
const struct mcux_lpuart_config *config,
const uint32_t status) {
@@ -960,7 +963,7 @@
}
#endif /* CONFIG_PM */
-#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_INTERRUPT_DRIVEN)
+#if LPUART_ASYNC_ENABLE && defined(CONFIG_UART_INTERRUPT_DRIVEN)
if (data->api_type == LPUART_IRQ_DRIVEN) {
mcux_lpuart_irq_driven_isr(dev, data, config, status);
} else if (data->api_type == LPUART_ASYNC) {
@@ -968,7 +971,7 @@
}
#elif defined(CONFIG_UART_INTERRUPT_DRIVEN)
mcux_lpuart_irq_driven_isr(dev, data, config, status);
-#elif defined(CONFIG_UART_ASYNC_API)
+#elif LPUART_ASYNC_ENABLE
mcux_lpuart_async_isr(data, config, status);
#endif /* API */
}
@@ -1101,7 +1104,7 @@
return 0;
}
-#ifdef CONFIG_UART_ASYNC_API
+#if LPUART_ASYNC_ENABLE
static int mcux_lpuart_configure_async(const struct device *dev)
{
const struct mcux_lpuart_config *config = dev->config;
@@ -1401,14 +1404,14 @@
.irq_update = mcux_lpuart_irq_update,
.irq_callback_set = mcux_lpuart_irq_callback_set,
#endif
-#ifdef CONFIG_UART_ASYNC_API
+#if LPUART_ASYNC_ENABLE
.callback_set = mcux_lpuart_callback_set,
.tx = mcux_lpuart_tx,
.tx_abort = mcux_lpuart_tx_abort,
.rx_enable = mcux_lpuart_rx_enable,
.rx_buf_rsp = mcux_lpuart_rx_buf_rsp,
.rx_disable = mcux_lpuart_rx_disable,
-#endif /* CONFIG_UART_ASYNC_API */
+#endif /* LPUART_ASYNC_ENABLE */
#ifdef CONFIG_UART_LINE_CTRL
.line_ctrl_set = mcux_lpuart_line_ctrl_set,
.line_ctrl_get = mcux_lpuart_line_ctrl_get,
@@ -1451,7 +1454,7 @@
#define MCUX_LPUART_IRQ_DEFINE(n)
#endif /* CONFIG_UART_MCUX_LPUART_ISR_SUPPORT */
-#ifdef CONFIG_UART_ASYNC_API
+#if LPUART_ASYNC_ENABLE
#define TX_DMA_CONFIG(id) \
.tx_dma_config = { \
.dma_dev = \
@@ -1502,7 +1505,7 @@
#else
#define RX_DMA_CONFIG(n)
#define TX_DMA_CONFIG(n)
-#endif /* CONFIG_UART_ASYNC_API */
+#endif /* LPUART_ASYNC_ENABLE */
#define FLOW_CONTROL(n) \
DT_INST_PROP(n, hw_flow_control) \