Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions drivers/serial/Kconfig.mcux_lpuart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ config UART_MCUX_LPUART
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
39 changes: 21 additions & 18 deletions drivers/serial/uart_mcux_lpuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -40,21 +43,21 @@ LOG_MODULE_REGISTER(uart_mcux_lpuart, LOG_LEVEL_ERR);
#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
*/
BUILD_ASSERT(IS_ENABLED(CONFIG_UART_EXCLUSIVE_API_CALLBACKS), ""
"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;
Expand All @@ -72,13 +75,13 @@ struct mcux_lpuart_config {
#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;
Expand Down Expand Up @@ -126,7 +129,7 @@ struct mcux_lpuart_data {
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;
Expand Down Expand Up @@ -423,7 +426,7 @@ static void mcux_lpuart_irq_callback_set(const struct device *dev,
#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)) {
Expand Down Expand Up @@ -906,7 +909,7 @@ static void mcux_lpuart_async_tx_timeout(struct k_work *work)
(void)mcux_lpuart_tx_abort(dev);
}

#endif /* CONFIG_UART_ASYNC_API */
#endif /* LPUART_ASYNC_ENABLE */

#if CONFIG_UART_MCUX_LPUART_ISR_SUPPORT

Expand All @@ -925,7 +928,7 @@ static inline void mcux_lpuart_irq_driven_isr(const struct device *dev,
}
#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) {
Expand Down Expand Up @@ -960,15 +963,15 @@ static void mcux_lpuart_isr(const struct device *dev)
}
#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) {
mcux_lpuart_async_isr(data, config, status);
}
#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 */
}
Expand Down Expand Up @@ -1101,7 +1104,7 @@ static int mcux_lpuart_configure_basic(const struct device *dev, const struct ua
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;
Expand Down Expand Up @@ -1401,14 +1404,14 @@ static DEVICE_API(uart, mcux_lpuart_driver_api) = {
.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,
Expand Down Expand Up @@ -1451,7 +1454,7 @@ static DEVICE_API(uart, mcux_lpuart_driver_api) = {
#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 = \
Expand Down Expand Up @@ -1502,7 +1505,7 @@ static DEVICE_API(uart, mcux_lpuart_driver_api) = {
#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) \
Expand Down