Skip to content
Merged
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
34 changes: 30 additions & 4 deletions drivers/serial/uart_mcux.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <zephyr/drivers/clock_control.h>
#include <fsl_uart.h>
#include <soc.h>
#include <zephyr/pm/device.h>
#ifdef CONFIG_PINCTRL
#include <zephyr/drivers/pinctrl.h>
#endif
Expand Down Expand Up @@ -209,15 +210,17 @@ static void uart_mcux_irq_tx_enable(const struct device *dev)
{
const struct uart_mcux_config *config = dev->config;
uint32_t mask = kUART_TxDataRegEmptyInterruptEnable;

config->base->C2 |= UART_C2_TE_MASK;
pm_device_busy_set(dev);
UART_EnableInterrupts(config->base, mask);
}

static void uart_mcux_irq_tx_disable(const struct device *dev)
{
const struct uart_mcux_config *config = dev->config;
uint32_t mask = kUART_TxDataRegEmptyInterruptEnable;

config->base->C2 &= ~UART_C2_TE_MASK;
pm_device_busy_clear(dev);
UART_DisableInterrupts(config->base, mask);
}

Expand Down Expand Up @@ -315,7 +318,6 @@ static void uart_mcux_irq_callback_set(const struct device *dev,
static void uart_mcux_isr(const struct device *dev)
{
struct uart_mcux_data *data = dev->data;

if (data->callback) {
data->callback(dev, data->cb_data);
}
Expand Down Expand Up @@ -349,6 +351,29 @@ static int uart_mcux_init(const struct device *dev)
return 0;
}

#ifdef CONFIG_PM_DEVICE
static int uart_mcux_pm_action(const struct device *dev, enum pm_device_action action)
{
const struct uart_mcux_config *config = dev->config;

switch (action) {
case PM_DEVICE_ACTION_RESUME:
clock_control_on(config->clock_dev, config->clock_subsys);
break;
case PM_DEVICE_ACTION_SUSPEND:
clock_control_off(config->clock_dev, config->clock_subsys);
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmahadevan108 can you check it please ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor issue, please fix the indentation of the break commands

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this bit keeps the UART clock running during low power modes. Should this be something the user gets to decide through a device tree property?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another point is that we don't need to clear and enable this bit in suspend and resume. This is a one time operation where the user decides if the UART clock should be active in low power modes.

case PM_DEVICE_ACTION_TURN_OFF:
return 0;
case PM_DEVICE_ACTION_TURN_ON:
return 0;
default:
return -ENOTSUP;
}
return 0;
}
#endif /*CONFIG_PM_DEVICE*/

static const struct uart_driver_api uart_mcux_driver_api = {
.poll_in = uart_mcux_poll_in,
.poll_out = uart_mcux_poll_out,
Expand Down Expand Up @@ -434,10 +459,11 @@ static const struct uart_mcux_config uart_mcux_##n##_config = { \
}; \
\
static const struct uart_mcux_config uart_mcux_##n##_config; \
PM_DEVICE_DT_INST_DEFINE(n, uart_mcux_pm_action);\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, "" identation.

\
DEVICE_DT_INST_DEFINE(n, \
&uart_mcux_init, \
NULL, \
PM_DEVICE_DT_INST_GET(n), \
&uart_mcux_##n##_data, \
&uart_mcux_##n##_config, \
PRE_KERNEL_1, \
Expand Down