Skip to content

Commit b476fa7

Browse files
seankyerkartben
authored andcommitted
drivers: counter: counter_max32_wut: Fixed PM resume routine
Seperated SW and HW initialization code so timer is not wiped upon a PM resume event. Signed-off-by: Sean Kyer <Sean.Kyer@analog.com>
1 parent ee883a9 commit b476fa7

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

drivers/counter/counter_max32_wut.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,27 @@ static void counter_max32_wut_isr(const struct device *dev)
199199
MXC_WUT_ClearFlags(cfg->regs);
200200
}
201201

202+
static void counter_max32_wut_hw_init(const struct device *dev)
203+
{
204+
const struct max32_wut_config *cfg = dev->config;
205+
206+
Wrap_MXC_SYS_Select32KClockSource(cfg->clock_source);
207+
208+
cfg->irq_func(dev);
209+
210+
if (cfg->wakeup_source) {
211+
MXC_LP_EnableWUTAlarmWakeup();
212+
}
213+
}
214+
202215
static int counter_max32_wut_init(const struct device *dev)
203216
{
204217
const struct max32_wut_config *cfg = dev->config;
205218
uint8_t prescaler_lo, prescaler_hi;
206219
mxc_wut_pres_t pres;
207220
mxc_wut_cfg_t wut_cfg;
208221

209-
Wrap_MXC_SYS_Select32KClockSource(cfg->clock_source);
222+
counter_max32_wut_hw_init(dev);
210223

211224
prescaler_lo = FIELD_GET(GENMASK(2, 0), LOG2(cfg->prescaler));
212225
prescaler_hi = FIELD_GET(BIT(3), LOG2(cfg->prescaler));
@@ -222,30 +235,16 @@ static int counter_max32_wut_init(const struct device *dev)
222235

223236
MXC_WUT_SetCount(cfg->regs, 0);
224237

225-
cfg->irq_func(dev);
226-
227-
if (cfg->wakeup_source) {
228-
MXC_LP_EnableWUTAlarmWakeup();
229-
}
230-
231238
return 0;
232239
}
233240

234241
#ifdef CONFIG_PM_DEVICE
235242
static int counter_max32_wut_pm_action(const struct device *dev, enum pm_device_action action)
236243
{
237-
int ret;
238-
239244
switch (action) {
240245
case PM_DEVICE_ACTION_RESUME:
241-
242-
ret = counter_max32_wut_init(dev);
243-
if (ret != 0) {
244-
return ret;
245-
}
246-
246+
counter_max32_wut_hw_init(dev);
247247
break;
248-
249248
case PM_DEVICE_ACTION_SUSPEND:
250249
break;
251250
default:

0 commit comments

Comments
 (0)