11
11
#include <zephyr/drivers/counter.h>
12
12
#include <zephyr/irq.h>
13
13
#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
14
20
15
21
struct mcux_lptmr_config {
16
22
struct counter_config_info info ;
@@ -22,6 +28,9 @@ struct mcux_lptmr_config {
22
28
lptmr_pin_select_t pin ;
23
29
lptmr_pin_polarity_t polarity ;
24
30
void (* irq_config_func )(const struct device * dev );
31
+ #if defined(CONFIG_PM ) || defined(CONFIG_POWEROFF )
32
+ bool wakeup_source ;
33
+ #endif
25
34
};
26
35
27
36
struct mcux_lptmr_data {
@@ -106,6 +115,13 @@ static uint32_t mcux_lptmr_get_top_value(const struct device *dev)
106
115
return (config -> base -> CMR & LPTMR_CMR_COMPARE_MASK ) + 1U ;
107
116
}
108
117
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
+
109
125
static void mcux_lptmr_isr (const struct device * dev )
110
126
{
111
127
const struct mcux_lptmr_config * config = dev -> config ;
@@ -141,6 +157,20 @@ static int mcux_lptmr_init(const struct device *dev)
141
157
142
158
LPTMR_SetTimerPeriod (config -> base , config -> info .max_top_value );
143
159
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
144
174
config -> irq_config_func (dev );
145
175
146
176
return 0 ;
@@ -153,8 +183,16 @@ static DEVICE_API(counter, mcux_lptmr_driver_api) = {
153
183
.set_top_value = mcux_lptmr_set_top_value ,
154
184
.get_pending_int = mcux_lptmr_get_pending_int ,
155
185
.get_top_value = mcux_lptmr_get_top_value ,
186
+ .get_freq = mcux_lptmr_get_freq ,
156
187
};
157
188
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
+
158
196
#define COUNTER_MCUX_LPTMR_DEVICE_INIT (n ) \
159
197
static void mcux_lptmr_irq_config_##n(const struct device *dev) \
160
198
{ \
@@ -193,6 +231,7 @@ static DEVICE_API(counter, mcux_lptmr_driver_api) = {
193
231
.prescaler_glitch = DT_INST_PROP(n, prescale_glitch_filter) + \
194
232
DT_INST_PROP(n, timer_mode_sel) - 1, \
195
233
.irq_config_func = mcux_lptmr_irq_config_##n, \
234
+ LPTMR_ENABLED_WAKEUP_FUNCTION(n) \
196
235
}; \
197
236
\
198
237
DEVICE_DT_INST_DEFINE(n, &mcux_lptmr_init, NULL, \
0 commit comments