Skip to content

Commit 2c03fb2

Browse files
committed
drivers: counter/lptmr: Enable lptmr wakeup feature
1. Enable lptmr wakeup feature 2. Enable lptmr get_freq function Signed-off-by: Zhaoxiang Jin <[email protected]>
1 parent bd6d7b6 commit 2c03fb2

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

drivers/counter/Kconfig.mcux_lptmr

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@
33
# Copyright (c) 2020 Vestas Wind Systems A/S
44
# SPDX-License-Identifier: Apache-2.0
55

6-
config COUNTER_MCUX_LPTMR
7-
bool "MCUX LPTMR driver"
8-
default y
9-
depends on DT_HAS_NXP_LPTMR_ENABLED
10-
help
11-
Enable support for the MCUX Low Power Timer (LPTMR).
6+
if MCUX_HW_HAS_LPTMR0
7+
mcux_hw_lptmr_index = 0
8+
rsource "Kconfig.mcux_lptmr_instance"
9+
endif
10+
11+
if MCUX_HW_HAS_LPTMR1
12+
mcux_hw_lptmr_index = 1
13+
rsource "Kconfig.mcux_lptmr_instance"
14+
endif
15+
16+
if MCUX_HW_HAS_LPTMR2
17+
mcux_hw_lptmr_index = 2
18+
rsource "Kconfig.mcux_lptmr_instance"
19+
endif
20+
21+
if MCUX_HW_HAS_LPTMR3
22+
mcux_hw_lptmr_index = 3
23+
rsource "Kconfig.mcux_lptmr_instance"
24+
endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# MCUXpresso SDK Low Power Timer (LPTMR)
2+
3+
# Copyright (c) 2020 Vestas Wind Systems A/S
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
config COUNTER_MCUX_LPTMR
7+
bool "MCUX LPTMR driver"
8+
default y
9+
depends on DT_HAS_NXP_LPTMR_ENABLED
10+
help
11+
Enable support for the MCUX Low Power Timer (LPTMR).
12+
13+
if PM || POWEROFF
14+
15+
# Only include following kconfig option when the lptmr
16+
# works as a wakeup source.
17+
config COUNTER_MCUX_LPTMR_WAKEUP_SOURCE_INDEX
18+
int "Index in wakeup unit when LPTMR is used as a wakeup source"
19+
default 6 if SOC_FAMILY_MCXN || SOC_FAMILY_MCXA
20+
default 0 if SOC_FAMILY_MCXW
21+
depends on ($(dt_nodelabel_bool_prop,lptmr$(mcux_hw_lptmr_index),wakeup-source))
22+
23+
endif

drivers/counter/counter_mcux_lptmr.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
#include <zephyr/drivers/counter.h>
1212
#include <zephyr/irq.h>
1313
#include <fsl_lptmr.h>
14+
#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF)
15+
#if defined(CONFIG_SOC_FAMILY_MCXN) || defined(CONFIG_SOC_FAMILY_MCXA) || \
16+
defined(CONFIG_SOC_FAMILY_MCXW)
17+
#include <fsl_wuu.h>
18+
#endif
19+
#endif
1420

1521
struct mcux_lptmr_config {
1622
struct counter_config_info info;
@@ -22,6 +28,9 @@ struct mcux_lptmr_config {
2228
lptmr_pin_select_t pin;
2329
lptmr_pin_polarity_t polarity;
2430
void (*irq_config_func)(const struct device *dev);
31+
#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF)
32+
bool wakeup_source;
33+
#endif
2534
};
2635

2736
struct mcux_lptmr_data {
@@ -106,6 +115,13 @@ static uint32_t mcux_lptmr_get_top_value(const struct device *dev)
106115
return (config->base->CMR & LPTMR_CMR_COMPARE_MASK) + 1U;
107116
}
108117

118+
static uint32_t mcux_lptmr_get_freq(const struct device *dev)
119+
{
120+
const struct mcux_lptmr_config *config = dev->config;
121+
122+
return config->info.freq;
123+
}
124+
109125
static void mcux_lptmr_isr(const struct device *dev)
110126
{
111127
const struct mcux_lptmr_config *config = dev->config;
@@ -141,6 +157,20 @@ static int mcux_lptmr_init(const struct device *dev)
141157

142158
LPTMR_SetTimerPeriod(config->base, config->info.max_top_value);
143159

160+
#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF)
161+
#if defined(CONFIG_SOC_FAMILY_MCXN) || defined(CONFIG_SOC_FAMILY_MCXA) || \
162+
defined(CONFIG_SOC_FAMILY_MCXW)
163+
if (config->wakeup_source) {
164+
WUU_SetInternalWakeUpModulesConfig(WUU0,
165+
CONFIG_COUNTER_MCUX_LPTMR_WAKEUP_SOURCE_INDEX,
166+
kWUU_InternalModuleInterrupt);
167+
}
168+
#elif
169+
/* Other platforms may also use lptmr as the wakeup source, but the wakeup source
170+
* management is not done using WUU.
171+
*/
172+
#endif
173+
#endif
144174
config->irq_config_func(dev);
145175

146176
return 0;
@@ -153,8 +183,16 @@ static DEVICE_API(counter, mcux_lptmr_driver_api) = {
153183
.set_top_value = mcux_lptmr_set_top_value,
154184
.get_pending_int = mcux_lptmr_get_pending_int,
155185
.get_top_value = mcux_lptmr_get_top_value,
186+
.get_freq = mcux_lptmr_get_freq,
156187
};
157188

189+
#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF)
190+
#define LPTMR_ENABLED_WAKEUP_FUNCTION(inst) \
191+
.wakeup_source = DT_INST_PROP_OR(inst, wakeup_source, 0),
192+
#else
193+
#define LPTMR_ENABLED_WAKEUP_FUNCTION(inst)
194+
#endif
195+
158196
#define COUNTER_MCUX_LPTMR_DEVICE_INIT(n) \
159197
static void mcux_lptmr_irq_config_##n(const struct device *dev) \
160198
{ \
@@ -193,6 +231,7 @@ static DEVICE_API(counter, mcux_lptmr_driver_api) = {
193231
.prescaler_glitch = DT_INST_PROP(n, prescale_glitch_filter) + \
194232
DT_INST_PROP(n, timer_mode_sel) - 1, \
195233
.irq_config_func = mcux_lptmr_irq_config_##n, \
234+
LPTMR_ENABLED_WAKEUP_FUNCTION(n) \
196235
}; \
197236
\
198237
DEVICE_DT_INST_DEFINE(n, &mcux_lptmr_init, NULL, \

0 commit comments

Comments
 (0)