Lines Matching +full:device +full:- +full:id
2 * Copyright 2021-23, NXP
4 * SPDX-License-Identifier: Apache-2.0
26 const struct device *rtc_dev;
27 void (*irq_config_func)(const struct device *dev);
28 /* Device defined as wake-up source */
33 static int mcux_lpc_rtc_highres_start(const struct device *dev);
36 static void mcux_lpc_rtc_isr(const struct device *dev) in mcux_lpc_rtc_isr()
38 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_isr()
41 struct mcux_lpc_rtc_data *data = dev->data; in mcux_lpc_rtc_isr()
43 uint32_t current = RTC_GetSecondsTimerCount(config->base); in mcux_lpc_rtc_isr()
47 if ((RTC_GetStatusFlags(config->base) & RTC_CTRL_ALARM1HZ_MASK) && in mcux_lpc_rtc_isr()
48 (data->alarm_callback)) { in mcux_lpc_rtc_isr()
49 cb = data->alarm_callback; in mcux_lpc_rtc_isr()
50 data->alarm_callback = NULL; in mcux_lpc_rtc_isr()
51 cb(dev, 0, current, data->alarm_user_data); in mcux_lpc_rtc_isr()
54 if (data->top_callback) { in mcux_lpc_rtc_isr()
55 data->top_callback(dev, data->top_user_data); in mcux_lpc_rtc_isr()
64 if (RTC_GetStatusFlags(config->base) & RTC_CTRL_ALARM1HZ_MASK) { in mcux_lpc_rtc_isr()
65 RTC_ClearStatusFlags(config->base, kRTC_AlarmFlag); in mcux_lpc_rtc_isr()
69 if (RTC_GetStatusFlags(config->base) & RTC_CTRL_WAKE1KHZ_MASK) { in mcux_lpc_rtc_isr()
70 RTC_ClearStatusFlags(config->base, kRTC_WakeupFlag); in mcux_lpc_rtc_isr()
72 if (config->base->CTRL & RTC_CTRL_RTC1KHZ_EN_MASK) { in mcux_lpc_rtc_isr()
83 static int mcux_lpc_rtc_start(const struct device *dev) in mcux_lpc_rtc_start()
85 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_start()
89 RTC_EnableTimer(config->base, true); in mcux_lpc_rtc_start()
94 static int mcux_lpc_rtc_stop(const struct device *dev) in mcux_lpc_rtc_stop()
96 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_stop()
100 RTC_EnableTimer(config->base, false); in mcux_lpc_rtc_stop()
103 RTC_SetSecondsTimerMatch(config->base, 0); in mcux_lpc_rtc_stop()
108 static uint32_t mcux_lpc_rtc_read(const struct device *dev) in mcux_lpc_rtc_read()
110 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_read()
114 uint32_t ticks = RTC_GetSecondsTimerCount(config->base); in mcux_lpc_rtc_read()
119 static int mcux_lpc_rtc_get_value(const struct device *dev, uint32_t *ticks) in mcux_lpc_rtc_get_value()
125 static int mcux_lpc_rtc_set_alarm(const struct device *dev, uint8_t chan_id, in mcux_lpc_rtc_set_alarm()
128 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_set_alarm()
131 struct mcux_lpc_rtc_data *data = dev->data; in mcux_lpc_rtc_set_alarm()
133 uint32_t ticks = alarm_cfg->ticks; in mcux_lpc_rtc_set_alarm()
139 LOG_ERR("Invalid channel id"); in mcux_lpc_rtc_set_alarm()
140 return -EINVAL; in mcux_lpc_rtc_set_alarm()
143 if (data->alarm_callback != NULL) { in mcux_lpc_rtc_set_alarm()
144 return -EBUSY; in mcux_lpc_rtc_set_alarm()
147 if ((alarm_cfg->flags & COUNTER_ALARM_CFG_ABSOLUTE) == 0) { in mcux_lpc_rtc_set_alarm()
153 return -EINVAL; in mcux_lpc_rtc_set_alarm()
156 data->alarm_callback = alarm_cfg->callback; in mcux_lpc_rtc_set_alarm()
157 data->alarm_user_data = alarm_cfg->user_data; in mcux_lpc_rtc_set_alarm()
159 RTC_SetSecondsTimerMatch(config->base, ticks); in mcux_lpc_rtc_set_alarm()
165 static int mcux_lpc_rtc_cancel_alarm(const struct device *dev, uint8_t chan_id) in mcux_lpc_rtc_cancel_alarm()
167 struct mcux_lpc_rtc_data *data = dev->data; in mcux_lpc_rtc_cancel_alarm()
170 LOG_ERR("Invalid channel id"); in mcux_lpc_rtc_cancel_alarm()
171 return -EINVAL; in mcux_lpc_rtc_cancel_alarm()
174 data->alarm_callback = NULL; in mcux_lpc_rtc_cancel_alarm()
179 static int mcux_lpc_rtc_set_top_value(const struct device *dev, in mcux_lpc_rtc_set_top_value()
182 return -ENOTSUP; in mcux_lpc_rtc_set_top_value()
185 static uint32_t mcux_lpc_rtc_get_pending_int(const struct device *dev) in mcux_lpc_rtc_get_pending_int()
187 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_get_pending_int()
191 return RTC_GetStatusFlags(config->base) & RTC_CTRL_ALARM1HZ_MASK; in mcux_lpc_rtc_get_pending_int()
194 static uint32_t mcux_lpc_rtc_get_top_value(const struct device *dev) in mcux_lpc_rtc_get_top_value()
196 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_get_top_value()
198 return info->max_top_value; in mcux_lpc_rtc_get_top_value()
201 static int mcux_lpc_rtc_init(const struct device *dev) in mcux_lpc_rtc_init()
203 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_init()
207 RTC_Init(config->base); in mcux_lpc_rtc_init()
210 RTC_Reset(config->base); in mcux_lpc_rtc_init()
212 config->irq_config_func(dev); in mcux_lpc_rtc_init()
214 if (config->wakeup_source) { in mcux_lpc_rtc_init()
216 RTC_EnableAlarmTimerInterruptFromDPD(config->base, true); in mcux_lpc_rtc_init()
233 #define COUNTER_LPC_RTC_DEVICE(id) \ argument
234 static void mcux_lpc_rtc_irq_config_##id(const struct device *dev); \
235 static const struct mcux_lpc_rtc_config mcux_lpc_rtc_config_##id = { \
236 .base = (RTC_Type *)DT_INST_REG_ADDR(id), \
237 .irq_config_func = mcux_lpc_rtc_irq_config_##id, \
238 .rtc_dev = DEVICE_DT_GET_OR_NULL(DT_INST_CHILD(id, rtc_highres)), \
245 .wakeup_source = DT_INST_PROP(id, wakeup_source) \
247 static struct mcux_lpc_rtc_data mcux_lpc_rtc_data_##id; \
248 DEVICE_DT_INST_DEFINE(id, &mcux_lpc_rtc_init, NULL, \
249 &mcux_lpc_rtc_data_##id, &mcux_lpc_rtc_config_##id.info, \
252 static void mcux_lpc_rtc_irq_config_##id(const struct device *dev) \
254 IRQ_CONNECT(DT_INST_IRQN(id), \
255 DT_INST_IRQ(id, priority), \
256 mcux_lpc_rtc_isr, DEVICE_DT_INST_GET(id), 0); \
257 irq_enable(DT_INST_IRQN(id)); \
258 if (DT_INST_PROP(id, wakeup_source)) { \
259 EnableDeepSleepIRQ(DT_INST_IRQN(id)); \
271 static int mcux_lpc_rtc_highres_start(const struct device *dev) in DT_INST_FOREACH_STATUS_OKAY()
273 const struct counter_config_info *info = dev->config; in DT_INST_FOREACH_STATUS_OKAY()
276 struct mcux_lpc_rtc_data *data = dev->data; in DT_INST_FOREACH_STATUS_OKAY()
278 if (config->rtc_dev) { in DT_INST_FOREACH_STATUS_OKAY()
280 if ((config->base->CTRL & RTC_CTRL_RTC_EN_MASK) == 0) { in DT_INST_FOREACH_STATUS_OKAY()
285 return -EINVAL; in DT_INST_FOREACH_STATUS_OKAY()
288 if ((config->base->CTRL & RTC_CTRL_RTC_EN_MASK) == 0) { in DT_INST_FOREACH_STATUS_OKAY()
289 RTC_EnableTimer(config->base, true); in DT_INST_FOREACH_STATUS_OKAY()
293 if (data->value == 0) { in DT_INST_FOREACH_STATUS_OKAY()
295 RTC_SetWakeupCount(config->base, counter_get_top_value(dev)); in DT_INST_FOREACH_STATUS_OKAY()
297 RTC_SetWakeupCount(config->base, data->value); in DT_INST_FOREACH_STATUS_OKAY()
303 static int mcux_lpc_rtc_highres_stop(const struct device *dev) in mcux_lpc_rtc_highres_stop()
305 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_highres_stop()
309 config->base->CTRL &= ~RTC_CTRL_RTC1KHZ_EN_MASK; in mcux_lpc_rtc_highres_stop()
311 if (config->rtc_dev == NULL) { in mcux_lpc_rtc_highres_stop()
313 RTC_EnableTimer(config->base, false); in mcux_lpc_rtc_highres_stop()
319 static uint32_t mcux_lpc_rtc_highres_read(const struct device *dev) in mcux_lpc_rtc_highres_read()
321 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_highres_read()
325 uint32_t ticks = RTC_GetWakeupCount(config->base); in mcux_lpc_rtc_highres_read()
330 static int mcux_lpc_rtc_highres_set_alarm(const struct device *dev, uint8_t chan_id, in mcux_lpc_rtc_highres_set_alarm()
333 return -ENOTSUP; in mcux_lpc_rtc_highres_set_alarm()
336 static int mcux_lpc_rtc_highres_cancel_alarm(const struct device *dev, uint8_t chan_id) in mcux_lpc_rtc_highres_cancel_alarm()
338 return -ENOTSUP; in mcux_lpc_rtc_highres_cancel_alarm()
342 static int mcux_lpc_rtc_highres_get_value(const struct device *dev, uint32_t *ticks) in mcux_lpc_rtc_highres_get_value()
348 static int mcux_lpc_rtc_highres_set_top_value(const struct device *dev, in mcux_lpc_rtc_highres_set_top_value()
351 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_highres_set_top_value()
354 struct mcux_lpc_rtc_data *data = dev->data; in mcux_lpc_rtc_highres_set_top_value()
356 if (cfg->flags & COUNTER_TOP_CFG_DONT_RESET) { in mcux_lpc_rtc_highres_set_top_value()
357 return -ENOTSUP; in mcux_lpc_rtc_highres_set_top_value()
360 data->value = cfg->ticks; in mcux_lpc_rtc_highres_set_top_value()
361 data->top_callback = cfg->callback; in mcux_lpc_rtc_highres_set_top_value()
362 data->top_user_data = cfg->user_data; in mcux_lpc_rtc_highres_set_top_value()
364 if (config->base->CTRL & RTC_CTRL_RTC1KHZ_EN_MASK) { in mcux_lpc_rtc_highres_set_top_value()
371 static uint32_t mcux_lpc_rtc_highres_get_pending_int(const struct device *dev) in mcux_lpc_rtc_highres_get_pending_int()
373 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_highres_get_pending_int()
377 return RTC_GetStatusFlags(config->base) & RTC_CTRL_WAKE1KHZ_MASK; in mcux_lpc_rtc_highres_get_pending_int()
380 static uint32_t mcux_lpc_rtc_highres_get_top_value(const struct device *dev) in mcux_lpc_rtc_highres_get_top_value()
382 struct mcux_lpc_rtc_data *data = dev->data; in mcux_lpc_rtc_highres_get_top_value()
383 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_highres_get_top_value()
385 if (data->value == 0) { in mcux_lpc_rtc_highres_get_top_value()
386 return info->max_top_value; in mcux_lpc_rtc_highres_get_top_value()
388 return data->value; in mcux_lpc_rtc_highres_get_top_value()
392 static int mcux_lpc_rtc_highres_init(const struct device *dev) in mcux_lpc_rtc_highres_init()
394 const struct counter_config_info *info = dev->config; in mcux_lpc_rtc_highres_init()
399 if (config->rtc_dev == NULL) { in mcux_lpc_rtc_highres_init()
400 RTC_Init(config->base); in mcux_lpc_rtc_highres_init()
403 RTC_Reset(config->base); in mcux_lpc_rtc_highres_init()
405 config->irq_config_func(dev); in mcux_lpc_rtc_highres_init()
408 if (config->wakeup_source) { in mcux_lpc_rtc_highres_init()
410 RTC_EnableWakeUpTimerInterruptFromDPD(config->base, true); in mcux_lpc_rtc_highres_init()
439 #define COUNTER_LPC_RTC_HIGHRES_DEVICE(id) \ argument
440 static void mcux_lpc_rtc_highres_irq_config_##id(const struct device *dev); \
441 static const struct mcux_lpc_rtc_config mcux_lpc_rtc_highres_config_##id = { \
442 .base = (RTC_Type *)DT_REG_ADDR(DT_INST_PARENT(id)), \
443 .rtc_dev = DEVICE_DT_GET_OR_NULL(DT_INST_PARENT(id)), \
444 .irq_config_func = mcux_lpc_rtc_highres_irq_config_##id, \
450 .wakeup_source = DT_INST_PROP(id, wakeup_source) \
452 static struct mcux_lpc_rtc_data mcux_lpc_rtc_highres_data_##id; \
453 DEVICE_DT_INST_DEFINE(id, &mcux_lpc_rtc_highres_init, NULL, \
454 &mcux_lpc_rtc_highres_data_##id, \
455 &mcux_lpc_rtc_highres_config_##id.info, \
458 static void mcux_lpc_rtc_highres_irq_config_##id(const struct device *dev) \
461 (), (COUNTER_LPC_RTC_HIGHRES_IRQ_INIT(id));) \