Skip to content

Commit 8ac0a67

Browse files
tsi-chungkartben
authored andcommitted
Counter_mcux_ctimer: Adds PM low-power recovery support
Enables Sleep mode (PM3) in RW61x for Ctimer. Signed-off-by: Tsi-Chung Liew <[email protected]>
1 parent 222e0fc commit 8ac0a67

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

drivers/counter/counter_mcux_ctimer.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <zephyr/drivers/clock_control.h>
1212
#include <zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h>
1313
#include <zephyr/irq.h>
14+
#include <zephyr/pm/device.h>
1415

1516
LOG_MODULE_REGISTER(mcux_ctimer, CONFIG_COUNTER_LOG_LEVEL);
1617

@@ -248,7 +249,7 @@ static void mcux_lpc_ctimer_isr(const struct device *dev)
248249
#endif
249250
}
250251

251-
static int mcux_lpc_ctimer_init(const struct device *dev)
252+
static int mcux_lpc_ctimer_init_common(const struct device *dev)
252253
{
253254
const struct mcux_lpc_ctimer_config *config = dev->config;
254255
struct mcux_lpc_ctimer_data *data = dev->data;
@@ -277,6 +278,32 @@ static int mcux_lpc_ctimer_init(const struct device *dev)
277278
return 0;
278279
}
279280

281+
static int mcux_lpc_ctimer_pm_action(const struct device *dev, enum pm_device_action action)
282+
{
283+
switch (action) {
284+
case PM_DEVICE_ACTION_RESUME:
285+
break;
286+
case PM_DEVICE_ACTION_SUSPEND:
287+
break;
288+
case PM_DEVICE_ACTION_TURN_OFF:
289+
break;
290+
case PM_DEVICE_ACTION_TURN_ON:
291+
mcux_lpc_ctimer_init_common(dev);
292+
break;
293+
default:
294+
return -ENOTSUP;
295+
}
296+
return 0;
297+
}
298+
299+
static int mcux_lpc_ctimer_init(const struct device *dev)
300+
{
301+
/* Rest of the init is done from the PM_DEVICE_TURN_ON action
302+
* which is invoked by pm_device_driver_init().
303+
*/
304+
return pm_device_driver_init(dev, mcux_lpc_ctimer_pm_action);
305+
}
306+
280307
static DEVICE_API(counter, mcux_ctimer_driver_api) = {
281308
.start = mcux_lpc_ctimer_start,
282309
.stop = mcux_lpc_ctimer_stop,
@@ -306,8 +333,10 @@ static DEVICE_API(counter, mcux_ctimer_driver_api) = {
306333
.prescale = DT_INST_PROP(id, prescale), \
307334
.irq_config_func = mcux_lpc_ctimer_irq_config_##id, \
308335
}; \
336+
PM_DEVICE_DT_INST_DEFINE(id, mcux_lpc_ctimer_pm_action); \
309337
static struct mcux_lpc_ctimer_data mcux_lpc_ctimer_data_##id; \
310-
DEVICE_DT_INST_DEFINE(id, &mcux_lpc_ctimer_init, NULL, &mcux_lpc_ctimer_data_##id, \
338+
DEVICE_DT_INST_DEFINE(id, &mcux_lpc_ctimer_init, PM_DEVICE_DT_INST_GET(id), \
339+
&mcux_lpc_ctimer_data_##id, \
311340
&mcux_lpc_ctimer_config_##id, POST_KERNEL, \
312341
CONFIG_COUNTER_INIT_PRIORITY, &mcux_ctimer_driver_api); \
313342
static void mcux_lpc_ctimer_irq_config_##id(const struct device *dev) \

0 commit comments

Comments
 (0)