10
10
#include <zephyr/drivers/clock_control/adi_max32_clock_control.h>
11
11
#include <zephyr/drivers/pinctrl.h>
12
12
#include <zephyr/irq.h>
13
+ #include <zephyr/logging/log.h>
13
14
14
15
#include <rtc.h>
15
16
#include <wrap_max32_lp.h>
17
+ #include <wrap_max32_rtc.h>
18
+
19
+ LOG_MODULE_REGISTER (max32_counter_rtc , CONFIG_COUNTER_LOG_LEVEL );
16
20
17
21
/* Resoultion is 1sec for time of day alarm*/
18
22
#define MAX32_RTC_COUNTER_FREQ 1
@@ -34,6 +38,7 @@ struct max32_rtc_config {
34
38
struct counter_config_info info ;
35
39
mxc_rtc_regs_t * regs ;
36
40
void (* irq_func )(void );
41
+ struct max32_perclk perclk ;
37
42
};
38
43
39
44
static int api_start (const struct device * dev )
@@ -207,10 +212,14 @@ static void rtc_max32_isr(const struct device *dev)
207
212
208
213
static int rtc_max32_init (const struct device * dev )
209
214
{
215
+ int ret ;
210
216
const struct max32_rtc_config * cfg = dev -> config ;
211
217
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
+ }
214
223
}
215
224
216
225
api_stop (dev );
@@ -252,6 +261,8 @@ static DEVICE_API(counter, counter_rtc_max32_driver_api) = {
252
261
}, \
253
262
.regs = (mxc_rtc_regs_t *)DT_INST_REG_ADDR(_num), \
254
263
.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), \
255
266
}; \
256
267
\
257
268
DEVICE_DT_INST_DEFINE(_num, &rtc_max32_init, NULL, &rtc_max32_data_##_num, \
0 commit comments