Skip to content

Commit cb0f951

Browse files
ttmutfabiobaltieri
authored andcommitted
drivers: counter: max32_rtc: Add clock source selection support
Add clock source selection support by applying changes introduced in 41a0ba7. Signed-off-by: Tahsin Mutlugun <[email protected]>
1 parent 25ebec2 commit cb0f951

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/counter/counter_max32_rtc.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
#include <zephyr/drivers/clock_control/adi_max32_clock_control.h>
1111
#include <zephyr/drivers/pinctrl.h>
1212
#include <zephyr/irq.h>
13+
#include <zephyr/logging/log.h>
1314

1415
#include <rtc.h>
1516
#include <wrap_max32_lp.h>
17+
#include <wrap_max32_rtc.h>
18+
19+
LOG_MODULE_REGISTER(max32_counter_rtc, CONFIG_COUNTER_LOG_LEVEL);
1620

1721
/* Resoultion is 1sec for time of day alarm*/
1822
#define MAX32_RTC_COUNTER_FREQ 1
@@ -34,6 +38,7 @@ struct max32_rtc_config {
3438
struct counter_config_info info;
3539
mxc_rtc_regs_t *regs;
3640
void (*irq_func)(void);
41+
struct max32_perclk perclk;
3742
};
3843

3944
static int api_start(const struct device *dev)
@@ -207,10 +212,14 @@ static void rtc_max32_isr(const struct device *dev)
207212

208213
static int rtc_max32_init(const struct device *dev)
209214
{
215+
int ret;
210216
const struct max32_rtc_config *cfg = dev->config;
211217

212-
while (MXC_RTC_Init(0, 0) == E_BUSY) {
213-
;
218+
while ((ret = Wrap_MXC_RTC_Init(0, 0, cfg->perclk.clk_src)) != E_SUCCESS) {
219+
if (ret < 0) {
220+
LOG_ERR("RTC does not support this clock source.");
221+
return -ENOTSUP;
222+
}
214223
}
215224

216225
api_stop(dev);
@@ -252,6 +261,8 @@ static DEVICE_API(counter, counter_rtc_max32_driver_api) = {
252261
}, \
253262
.regs = (mxc_rtc_regs_t *)DT_INST_REG_ADDR(_num), \
254263
.irq_func = max32_rtc_irq_init_##_num, \
264+
.perclk.clk_src = \
265+
DT_INST_PROP_OR(_num, clock_source, ADI_MAX32_PRPH_CLK_SRC_ERTCO), \
255266
}; \
256267
\
257268
DEVICE_DT_INST_DEFINE(_num, &rtc_max32_init, NULL, &rtc_max32_data_##_num, \

0 commit comments

Comments
 (0)