Skip to content

Commit 1414fd4

Browse files
committed
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 <[email protected]>
1 parent 16f4d6c commit 1414fd4

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

drivers/serial/Kconfig.mcux_lpuart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@ config UART_MCUX_LPUART
88
depends on CLOCK_CONTROL
99
select SERIAL_HAS_DRIVER
1010
select SERIAL_SUPPORT_INTERRUPT
11-
select SERIAL_SUPPORT_ASYNC if $(dt_compat_any_has_prop,$(DT_COMPAT_NXP_LPUART),dmas)
12-
select DMA if UART_ASYNC_API
1311
select PINCTRL
1412
help
1513
Enable the MCUX LPUART driver.
1614

15+
if UART_MCUX_LPUART
16+
1717
config UART_MCUX_LPUART_ISR_SUPPORT
1818
bool
19-
depends on UART_MCUX_LPUART
2019
default y if UART_INTERRUPT_DRIVEN || PM || UART_ASYNC_API
2120
help
2221
Enable UART interrupt service routine.
22+
23+
config UART_NXP_LPUART_ASYNC_API_SUPPORT
24+
bool
25+
default y if $(dt_compat_any_has_prop,$(DT_COMPAT_NXP_LPUART),dmas)
26+
select SERIAL_SUPPORT_ASYNC
27+
select DMA if UART_ASYNC_API
28+
help
29+
Indicates if LPUART has async api support by having dmas enabled for it
30+
31+
endif

drivers/serial/uart_mcux_lpuart.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
#define DT_DRV_COMPAT nxp_lpuart
99

10+
#define LPUART_ASYNC_ENABLE \
11+
IS_ENABLED(CONFIG_UART_ASYNC_API) && IS_ENABLED(CONFIG_NXP_LPUART_ASYNC_API_SUPPORT)
12+
1013
#include <errno.h>
1114
#include <zephyr/device.h>
1215
#include <zephyr/drivers/uart.h>
@@ -15,7 +18,7 @@
1518
#include <zephyr/kernel.h>
1619
#include <zephyr/pm/policy.h>
1720
#include <zephyr/drivers/pinctrl.h>
18-
#ifdef CONFIG_UART_ASYNC_API
21+
#if LPUART_ASYNC_ENABLE
1922
#include <zephyr/drivers/dma.h>
2023
#endif
2124
#include <zephyr/logging/log.h>
@@ -40,21 +43,21 @@ LOG_MODULE_REGISTER(uart_mcux_lpuart, LOG_LEVEL_ERR);
4043
#define LPUART_HAS_MCR 1
4144
#endif
4245

43-
#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_INTERRUPT_DRIVEN)
46+
#if LPUART_ASYNC_ENABLE && defined(CONFIG_UART_INTERRUPT_DRIVEN)
4447
/* there are already going to be build errors, but at least this message will
4548
* be the first error from this driver making the reason clear
4649
*/
4750
BUILD_ASSERT(IS_ENABLED(CONFIG_UART_EXCLUSIVE_API_CALLBACKS), ""
4851
"LPUART must use exclusive api callbacks");
4952
#endif
5053

51-
#ifdef CONFIG_UART_ASYNC_API
54+
#if LPUART_ASYNC_ENABLE
5255
struct lpuart_dma_config {
5356
const struct device *dma_dev;
5457
const uint32_t dma_channel;
5558
struct dma_config dma_cfg;
5659
};
57-
#endif /* CONFIG_UART_ASYNC_API */
60+
#endif /* LPUART_ASYNC_ENABLE */
5861

5962
struct mcux_lpuart_config {
6063
LPUART_Type *base;
@@ -72,13 +75,13 @@ struct mcux_lpuart_config {
7275
#ifdef CONFIG_UART_MCUX_LPUART_ISR_SUPPORT
7376
void (*irq_config_func)(const struct device *dev);
7477
#endif
75-
#ifdef CONFIG_UART_ASYNC_API
78+
#if LPUART_ASYNC_ENABLE
7679
const struct lpuart_dma_config rx_dma_config;
7780
const struct lpuart_dma_config tx_dma_config;
78-
#endif /* CONFIG_UART_ASYNC_API */
81+
#endif /* LPUART_ASYNC_ENABLE */
7982
};
8083

81-
#ifdef CONFIG_UART_ASYNC_API
84+
#if LPUART_ASYNC_ENABLE
8285
struct mcux_lpuart_rx_dma_params {
8386
struct dma_block_config active_dma_block;
8487
uint8_t *buf;
@@ -126,7 +129,7 @@ struct mcux_lpuart_data {
126129
bool tx_poll_stream_on;
127130
bool tx_int_stream_on;
128131
#endif /* CONFIG_PM */
129-
#ifdef CONFIG_UART_ASYNC_API
132+
#if LPUART_ASYNC_ENABLE
130133
struct mcux_lpuart_async_data async;
131134
#endif
132135
struct uart_config uart_config;
@@ -423,7 +426,7 @@ static void mcux_lpuart_irq_callback_set(const struct device *dev,
423426
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
424427

425428

426-
#ifdef CONFIG_UART_ASYNC_API
429+
#if LPUART_ASYNC_ENABLE
427430
static inline void async_timer_start(struct k_work_delayable *work, size_t timeout_us)
428431
{
429432
if ((timeout_us != SYS_FOREVER_US) && (timeout_us != 0)) {
@@ -906,7 +909,7 @@ static void mcux_lpuart_async_tx_timeout(struct k_work *work)
906909
(void)mcux_lpuart_tx_abort(dev);
907910
}
908911

909-
#endif /* CONFIG_UART_ASYNC_API */
912+
#endif /* LPUART_ASYNC_ENABLE */
910913

911914
#if CONFIG_UART_MCUX_LPUART_ISR_SUPPORT
912915

@@ -925,7 +928,7 @@ static inline void mcux_lpuart_irq_driven_isr(const struct device *dev,
925928
}
926929
#endif
927930

928-
#ifdef CONFIG_UART_ASYNC_API
931+
#if LPUART_ASYNC_ENABLE
929932
static inline void mcux_lpuart_async_isr(struct mcux_lpuart_data *data,
930933
const struct mcux_lpuart_config *config,
931934
const uint32_t status) {
@@ -960,15 +963,15 @@ static void mcux_lpuart_isr(const struct device *dev)
960963
}
961964
#endif /* CONFIG_PM */
962965

963-
#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_INTERRUPT_DRIVEN)
966+
#if LPUART_ASYNC_ENABLE && defined(CONFIG_UART_INTERRUPT_DRIVEN)
964967
if (data->api_type == LPUART_IRQ_DRIVEN) {
965968
mcux_lpuart_irq_driven_isr(dev, data, config, status);
966969
} else if (data->api_type == LPUART_ASYNC) {
967970
mcux_lpuart_async_isr(data, config, status);
968971
}
969972
#elif defined(CONFIG_UART_INTERRUPT_DRIVEN)
970973
mcux_lpuart_irq_driven_isr(dev, data, config, status);
971-
#elif defined(CONFIG_UART_ASYNC_API)
974+
#elif LPUART_ASYNC_ENABLE
972975
mcux_lpuart_async_isr(data, config, status);
973976
#endif /* API */
974977
}
@@ -1101,7 +1104,7 @@ static int mcux_lpuart_configure_basic(const struct device *dev, const struct ua
11011104
return 0;
11021105
}
11031106

1104-
#ifdef CONFIG_UART_ASYNC_API
1107+
#if LPUART_ASYNC_ENABLE
11051108
static int mcux_lpuart_configure_async(const struct device *dev)
11061109
{
11071110
const struct mcux_lpuart_config *config = dev->config;
@@ -1401,14 +1404,14 @@ static DEVICE_API(uart, mcux_lpuart_driver_api) = {
14011404
.irq_update = mcux_lpuart_irq_update,
14021405
.irq_callback_set = mcux_lpuart_irq_callback_set,
14031406
#endif
1404-
#ifdef CONFIG_UART_ASYNC_API
1407+
#if LPUART_ASYNC_ENABLE
14051408
.callback_set = mcux_lpuart_callback_set,
14061409
.tx = mcux_lpuart_tx,
14071410
.tx_abort = mcux_lpuart_tx_abort,
14081411
.rx_enable = mcux_lpuart_rx_enable,
14091412
.rx_buf_rsp = mcux_lpuart_rx_buf_rsp,
14101413
.rx_disable = mcux_lpuart_rx_disable,
1411-
#endif /* CONFIG_UART_ASYNC_API */
1414+
#endif /* LPUART_ASYNC_ENABLE */
14121415
#ifdef CONFIG_UART_LINE_CTRL
14131416
.line_ctrl_set = mcux_lpuart_line_ctrl_set,
14141417
.line_ctrl_get = mcux_lpuart_line_ctrl_get,
@@ -1451,7 +1454,7 @@ static DEVICE_API(uart, mcux_lpuart_driver_api) = {
14511454
#define MCUX_LPUART_IRQ_DEFINE(n)
14521455
#endif /* CONFIG_UART_MCUX_LPUART_ISR_SUPPORT */
14531456

1454-
#ifdef CONFIG_UART_ASYNC_API
1457+
#if LPUART_ASYNC_ENABLE
14551458
#define TX_DMA_CONFIG(id) \
14561459
.tx_dma_config = { \
14571460
.dma_dev = \
@@ -1502,7 +1505,7 @@ static DEVICE_API(uart, mcux_lpuart_driver_api) = {
15021505
#else
15031506
#define RX_DMA_CONFIG(n)
15041507
#define TX_DMA_CONFIG(n)
1505-
#endif /* CONFIG_UART_ASYNC_API */
1508+
#endif /* LPUART_ASYNC_ENABLE */
15061509

15071510
#define FLOW_CONTROL(n) \
15081511
DT_INST_PROP(n, hw_flow_control) \

0 commit comments

Comments
 (0)