Lines Matching +full:stm32mp1 +full:- +full:rtc

1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/rtc.h>
89 /* Max STM32 RTC register offset is 0x3FC */
114 void (*clear_events)(struct stm32_rtc *rtc, unsigned int flags);
133 static void stm32_rtc_wpr_unlock(struct stm32_rtc *rtc) in stm32_rtc_wpr_unlock() argument
135 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_wpr_unlock()
137 writel_relaxed(RTC_WPR_1ST_KEY, rtc->base + regs->wpr); in stm32_rtc_wpr_unlock()
138 writel_relaxed(RTC_WPR_2ND_KEY, rtc->base + regs->wpr); in stm32_rtc_wpr_unlock()
141 static void stm32_rtc_wpr_lock(struct stm32_rtc *rtc) in stm32_rtc_wpr_lock() argument
143 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_wpr_lock()
145 writel_relaxed(RTC_WPR_WRONG_KEY, rtc->base + regs->wpr); in stm32_rtc_wpr_lock()
148 static int stm32_rtc_enter_init_mode(struct stm32_rtc *rtc) in stm32_rtc_enter_init_mode() argument
150 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_enter_init_mode()
151 unsigned int isr = readl_relaxed(rtc->base + regs->isr); in stm32_rtc_enter_init_mode()
155 writel_relaxed(isr, rtc->base + regs->isr); in stm32_rtc_enter_init_mode()
164 rtc->base + regs->isr, in stm32_rtc_enter_init_mode()
172 static void stm32_rtc_exit_init_mode(struct stm32_rtc *rtc) in stm32_rtc_exit_init_mode() argument
174 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_exit_init_mode()
175 unsigned int isr = readl_relaxed(rtc->base + regs->isr); in stm32_rtc_exit_init_mode()
178 writel_relaxed(isr, rtc->base + regs->isr); in stm32_rtc_exit_init_mode()
181 static int stm32_rtc_wait_sync(struct stm32_rtc *rtc) in stm32_rtc_wait_sync() argument
183 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_wait_sync()
184 unsigned int isr = readl_relaxed(rtc->base + regs->isr); in stm32_rtc_wait_sync()
187 writel_relaxed(isr, rtc->base + regs->isr); in stm32_rtc_wait_sync()
193 return readl_relaxed_poll_timeout_atomic(rtc->base + regs->isr, in stm32_rtc_wait_sync()
199 static void stm32_rtc_clear_event_flags(struct stm32_rtc *rtc, in stm32_rtc_clear_event_flags() argument
202 rtc->data->clear_events(rtc, flags); in stm32_rtc_clear_event_flags()
207 struct stm32_rtc *rtc = (struct stm32_rtc *)dev_id; in stm32_rtc_alarm_irq() local
208 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_alarm_irq()
209 const struct stm32_rtc_events *evts = &rtc->data->events; in stm32_rtc_alarm_irq()
212 rtc_lock(rtc->rtc_dev); in stm32_rtc_alarm_irq()
214 status = readl_relaxed(rtc->base + regs->sr); in stm32_rtc_alarm_irq()
215 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_alarm_irq()
217 if ((status & evts->alra) && in stm32_rtc_alarm_irq()
219 /* Alarm A flag - Alarm interrupt */ in stm32_rtc_alarm_irq()
220 dev_dbg(&rtc->rtc_dev->dev, "Alarm occurred\n"); in stm32_rtc_alarm_irq()
223 rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF); in stm32_rtc_alarm_irq()
226 stm32_rtc_clear_event_flags(rtc, evts->alra); in stm32_rtc_alarm_irq()
229 rtc_unlock(rtc->rtc_dev); in stm32_rtc_alarm_irq()
237 tm->tm_sec = bin2bcd(tm->tm_sec); in tm2bcd()
238 tm->tm_min = bin2bcd(tm->tm_min); in tm2bcd()
239 tm->tm_hour = bin2bcd(tm->tm_hour); in tm2bcd()
241 tm->tm_mday = bin2bcd(tm->tm_mday); in tm2bcd()
242 tm->tm_mon = bin2bcd(tm->tm_mon + 1); in tm2bcd()
243 tm->tm_year = bin2bcd(tm->tm_year - 100); in tm2bcd()
246 * - on kernel side, 0=Sunday...6=Saturday in tm2bcd()
247 * - on rtc side, 0=invalid,1=Monday...7=Sunday in tm2bcd()
249 tm->tm_wday = (!tm->tm_wday) ? 7 : tm->tm_wday; in tm2bcd()
255 tm->tm_sec = bcd2bin(tm->tm_sec); in bcd2tm()
256 tm->tm_min = bcd2bin(tm->tm_min); in bcd2tm()
257 tm->tm_hour = bcd2bin(tm->tm_hour); in bcd2tm()
259 tm->tm_mday = bcd2bin(tm->tm_mday); in bcd2tm()
260 tm->tm_mon = bcd2bin(tm->tm_mon) - 1; in bcd2tm()
261 tm->tm_year = bcd2bin(tm->tm_year) + 100; in bcd2tm()
264 * - on kernel side, 0=Sunday...6=Saturday in bcd2tm()
265 * - on rtc side, 0=invalid,1=Monday...7=Sunday in bcd2tm()
267 tm->tm_wday %= 7; in bcd2tm()
272 struct stm32_rtc *rtc = dev_get_drvdata(dev); in stm32_rtc_read_time() local
273 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_read_time()
277 tr = readl_relaxed(rtc->base + regs->tr); in stm32_rtc_read_time()
278 dr = readl_relaxed(rtc->base + regs->dr); in stm32_rtc_read_time()
280 tm->tm_sec = (tr & STM32_RTC_TR_SEC) >> STM32_RTC_TR_SEC_SHIFT; in stm32_rtc_read_time()
281 tm->tm_min = (tr & STM32_RTC_TR_MIN) >> STM32_RTC_TR_MIN_SHIFT; in stm32_rtc_read_time()
282 tm->tm_hour = (tr & STM32_RTC_TR_HOUR) >> STM32_RTC_TR_HOUR_SHIFT; in stm32_rtc_read_time()
284 tm->tm_mday = (dr & STM32_RTC_DR_DATE) >> STM32_RTC_DR_DATE_SHIFT; in stm32_rtc_read_time()
285 tm->tm_mon = (dr & STM32_RTC_DR_MONTH) >> STM32_RTC_DR_MONTH_SHIFT; in stm32_rtc_read_time()
286 tm->tm_year = (dr & STM32_RTC_DR_YEAR) >> STM32_RTC_DR_YEAR_SHIFT; in stm32_rtc_read_time()
287 tm->tm_wday = (dr & STM32_RTC_DR_WDAY) >> STM32_RTC_DR_WDAY_SHIFT; in stm32_rtc_read_time()
298 struct stm32_rtc *rtc = dev_get_drvdata(dev); in stm32_rtc_set_time() local
299 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_set_time()
306 tr = ((tm->tm_sec << STM32_RTC_TR_SEC_SHIFT) & STM32_RTC_TR_SEC) | in stm32_rtc_set_time()
307 ((tm->tm_min << STM32_RTC_TR_MIN_SHIFT) & STM32_RTC_TR_MIN) | in stm32_rtc_set_time()
308 ((tm->tm_hour << STM32_RTC_TR_HOUR_SHIFT) & STM32_RTC_TR_HOUR); in stm32_rtc_set_time()
311 dr = ((tm->tm_mday << STM32_RTC_DR_DATE_SHIFT) & STM32_RTC_DR_DATE) | in stm32_rtc_set_time()
312 ((tm->tm_mon << STM32_RTC_DR_MONTH_SHIFT) & STM32_RTC_DR_MONTH) | in stm32_rtc_set_time()
313 ((tm->tm_year << STM32_RTC_DR_YEAR_SHIFT) & STM32_RTC_DR_YEAR) | in stm32_rtc_set_time()
314 ((tm->tm_wday << STM32_RTC_DR_WDAY_SHIFT) & STM32_RTC_DR_WDAY); in stm32_rtc_set_time()
316 stm32_rtc_wpr_unlock(rtc); in stm32_rtc_set_time()
318 ret = stm32_rtc_enter_init_mode(rtc); in stm32_rtc_set_time()
324 writel_relaxed(tr, rtc->base + regs->tr); in stm32_rtc_set_time()
325 writel_relaxed(dr, rtc->base + regs->dr); in stm32_rtc_set_time()
327 stm32_rtc_exit_init_mode(rtc); in stm32_rtc_set_time()
329 ret = stm32_rtc_wait_sync(rtc); in stm32_rtc_set_time()
331 stm32_rtc_wpr_lock(rtc); in stm32_rtc_set_time()
338 struct stm32_rtc *rtc = dev_get_drvdata(dev); in stm32_rtc_read_alarm() local
339 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_read_alarm()
340 const struct stm32_rtc_events *evts = &rtc->data->events; in stm32_rtc_read_alarm()
341 struct rtc_time *tm = &alrm->time; in stm32_rtc_read_alarm()
344 alrmar = readl_relaxed(rtc->base + regs->alrmar); in stm32_rtc_read_alarm()
345 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_read_alarm()
346 status = readl_relaxed(rtc->base + regs->sr); in stm32_rtc_read_alarm()
353 tm->tm_mday = -1; in stm32_rtc_read_alarm()
354 tm->tm_wday = -1; in stm32_rtc_read_alarm()
358 tm->tm_mday = -1; in stm32_rtc_read_alarm()
359 tm->tm_wday = (alrmar & STM32_RTC_ALRMXR_WDAY) >> in stm32_rtc_read_alarm()
361 tm->tm_wday %= 7; in stm32_rtc_read_alarm()
364 tm->tm_wday = -1; in stm32_rtc_read_alarm()
365 tm->tm_mday = (alrmar & STM32_RTC_ALRMXR_DATE) >> in stm32_rtc_read_alarm()
372 tm->tm_hour = -1; in stm32_rtc_read_alarm()
374 tm->tm_hour = (alrmar & STM32_RTC_ALRMXR_HOUR) >> in stm32_rtc_read_alarm()
377 tm->tm_hour += 12; in stm32_rtc_read_alarm()
382 tm->tm_min = -1; in stm32_rtc_read_alarm()
384 tm->tm_min = (alrmar & STM32_RTC_ALRMXR_MIN) >> in stm32_rtc_read_alarm()
390 tm->tm_sec = -1; in stm32_rtc_read_alarm()
392 tm->tm_sec = (alrmar & STM32_RTC_ALRMXR_SEC) >> in stm32_rtc_read_alarm()
398 alrm->enabled = (cr & STM32_RTC_CR_ALRAE) ? 1 : 0; in stm32_rtc_read_alarm()
399 alrm->pending = (status & evts->alra) ? 1 : 0; in stm32_rtc_read_alarm()
406 struct stm32_rtc *rtc = dev_get_drvdata(dev); in stm32_rtc_alarm_irq_enable() local
407 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_alarm_irq_enable()
408 const struct stm32_rtc_events *evts = &rtc->data->events; in stm32_rtc_alarm_irq_enable()
411 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_alarm_irq_enable()
413 stm32_rtc_wpr_unlock(rtc); in stm32_rtc_alarm_irq_enable()
420 writel_relaxed(cr, rtc->base + regs->cr); in stm32_rtc_alarm_irq_enable()
423 stm32_rtc_clear_event_flags(rtc, evts->alra); in stm32_rtc_alarm_irq_enable()
425 stm32_rtc_wpr_lock(rtc); in stm32_rtc_alarm_irq_enable()
430 static int stm32_rtc_valid_alrm(struct stm32_rtc *rtc, struct rtc_time *tm) in stm32_rtc_valid_alrm() argument
432 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_valid_alrm()
434 unsigned int dr = readl_relaxed(rtc->base + regs->dr); in stm32_rtc_valid_alrm()
435 unsigned int tr = readl_relaxed(rtc->base + regs->tr); in stm32_rtc_valid_alrm()
445 * Assuming current date is M-D-Y H:M:S. in stm32_rtc_valid_alrm()
446 * RTC alarm can't be set on a specific month and year. in stm32_rtc_valid_alrm()
448 * M-D-Y H:M:S < alarm <= (M+1)-D-Y H:M:S in stm32_rtc_valid_alrm()
451 if ((((tm->tm_year > cur_year) && in stm32_rtc_valid_alrm()
452 (tm->tm_mon == 0x1) && (cur_mon == 0x12)) || in stm32_rtc_valid_alrm()
453 ((tm->tm_year == cur_year) && in stm32_rtc_valid_alrm()
454 (tm->tm_mon <= cur_mon + 1))) && in stm32_rtc_valid_alrm()
455 ((tm->tm_mday > cur_day) || in stm32_rtc_valid_alrm()
456 ((tm->tm_mday == cur_day) && in stm32_rtc_valid_alrm()
457 ((tm->tm_hour > cur_hour) || in stm32_rtc_valid_alrm()
458 ((tm->tm_hour == cur_hour) && (tm->tm_min > cur_min)) || in stm32_rtc_valid_alrm()
459 ((tm->tm_hour == cur_hour) && (tm->tm_min == cur_min) && in stm32_rtc_valid_alrm()
460 (tm->tm_sec >= cur_sec)))))) in stm32_rtc_valid_alrm()
463 return -EINVAL; in stm32_rtc_valid_alrm()
468 struct stm32_rtc *rtc = dev_get_drvdata(dev); in stm32_rtc_set_alarm() local
469 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_set_alarm()
470 struct rtc_time *tm = &alrm->time; in stm32_rtc_set_alarm()
477 * RTC alarm can't be set on a specific date, unless this date is in stm32_rtc_set_alarm()
480 if (stm32_rtc_valid_alrm(rtc, tm) < 0) { in stm32_rtc_set_alarm()
482 return -EINVAL; in stm32_rtc_set_alarm()
486 /* tm_year and tm_mon are not used because not supported by RTC */ in stm32_rtc_set_alarm()
487 alrmar |= (tm->tm_mday << STM32_RTC_ALRMXR_DATE_SHIFT) & in stm32_rtc_set_alarm()
489 /* 24-hour format */ in stm32_rtc_set_alarm()
491 alrmar |= (tm->tm_hour << STM32_RTC_ALRMXR_HOUR_SHIFT) & in stm32_rtc_set_alarm()
493 alrmar |= (tm->tm_min << STM32_RTC_ALRMXR_MIN_SHIFT) & in stm32_rtc_set_alarm()
495 alrmar |= (tm->tm_sec << STM32_RTC_ALRMXR_SEC_SHIFT) & in stm32_rtc_set_alarm()
498 stm32_rtc_wpr_unlock(rtc); in stm32_rtc_set_alarm()
501 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_set_alarm()
503 writel_relaxed(cr, rtc->base + regs->cr); in stm32_rtc_set_alarm()
509 ret = readl_relaxed_poll_timeout_atomic(rtc->base + regs->isr, in stm32_rtc_set_alarm()
520 writel_relaxed(alrmar, rtc->base + regs->alrmar); in stm32_rtc_set_alarm()
522 stm32_rtc_alarm_irq_enable(dev, alrm->enabled); in stm32_rtc_set_alarm()
524 stm32_rtc_wpr_lock(rtc); in stm32_rtc_set_alarm()
537 static void stm32_rtc_clear_events(struct stm32_rtc *rtc, in stm32_rtc_clear_events() argument
540 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_clear_events()
543 writel_relaxed(readl_relaxed(rtc->base + regs->isr) & ~flags, in stm32_rtc_clear_events()
544 rtc->base + regs->isr); in stm32_rtc_clear_events()
591 static void stm32mp1_rtc_clear_events(struct stm32_rtc *rtc, in stm32mp1_rtc_clear_events() argument
594 struct stm32_rtc_registers regs = rtc->data->regs; in stm32mp1_rtc_clear_events()
597 writel_relaxed(flags, rtc->base + regs.scr); in stm32mp1_rtc_clear_events()
608 .isr = 0x0C, /* named RTC_ICSR on stm32mp1 */
623 { .compatible = "st,stm32-rtc", .data = &stm32_rtc_data },
624 { .compatible = "st,stm32h7-rtc", .data = &stm32h7_rtc_data },
625 { .compatible = "st,stm32mp1-rtc", .data = &stm32mp1_data },
631 struct stm32_rtc *rtc) in stm32_rtc_init() argument
633 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_init()
638 rate = clk_get_rate(rtc->rtc_ck); in stm32_rtc_init()
644 for (pred_a = pred_a_max; pred_a + 1 > 0; pred_a--) { in stm32_rtc_init()
645 pred_s = (rate / (pred_a + 1)) - 1; in stm32_rtc_init()
652 * Can't find a 1Hz, so give priority to RTC power consumption in stm32_rtc_init()
657 pred_s = (rate / (pred_a + 1)) - 1; in stm32_rtc_init()
659 dev_warn(&pdev->dev, "rtc_ck is %s\n", in stm32_rtc_init()
664 stm32_rtc_wpr_unlock(rtc); in stm32_rtc_init()
666 ret = stm32_rtc_enter_init_mode(rtc); in stm32_rtc_init()
668 dev_err(&pdev->dev, in stm32_rtc_init()
674 writel_relaxed(prer, rtc->base + regs->prer); in stm32_rtc_init()
676 writel_relaxed(prer, rtc->base + regs->prer); in stm32_rtc_init()
679 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_init()
681 writel_relaxed(cr, rtc->base + regs->cr); in stm32_rtc_init()
683 stm32_rtc_exit_init_mode(rtc); in stm32_rtc_init()
685 ret = stm32_rtc_wait_sync(rtc); in stm32_rtc_init()
687 stm32_rtc_wpr_lock(rtc); in stm32_rtc_init()
694 struct stm32_rtc *rtc; in stm32_rtc_probe() local
698 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); in stm32_rtc_probe()
699 if (!rtc) in stm32_rtc_probe()
700 return -ENOMEM; in stm32_rtc_probe()
702 rtc->base = devm_platform_ioremap_resource(pdev, 0); in stm32_rtc_probe()
703 if (IS_ERR(rtc->base)) in stm32_rtc_probe()
704 return PTR_ERR(rtc->base); in stm32_rtc_probe()
706 rtc->data = (struct stm32_rtc_data *) in stm32_rtc_probe()
707 of_device_get_match_data(&pdev->dev); in stm32_rtc_probe()
708 regs = &rtc->data->regs; in stm32_rtc_probe()
710 if (rtc->data->need_dbp) { in stm32_rtc_probe()
711 rtc->dbp = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, in stm32_rtc_probe()
713 if (IS_ERR(rtc->dbp)) { in stm32_rtc_probe()
714 dev_err(&pdev->dev, "no st,syscfg\n"); in stm32_rtc_probe()
715 return PTR_ERR(rtc->dbp); in stm32_rtc_probe()
718 ret = of_property_read_u32_index(pdev->dev.of_node, "st,syscfg", in stm32_rtc_probe()
719 1, &rtc->dbp_reg); in stm32_rtc_probe()
721 dev_err(&pdev->dev, "can't read DBP register offset\n"); in stm32_rtc_probe()
725 ret = of_property_read_u32_index(pdev->dev.of_node, "st,syscfg", in stm32_rtc_probe()
726 2, &rtc->dbp_mask); in stm32_rtc_probe()
728 dev_err(&pdev->dev, "can't read DBP register mask\n"); in stm32_rtc_probe()
733 if (!rtc->data->has_pclk) { in stm32_rtc_probe()
734 rtc->pclk = NULL; in stm32_rtc_probe()
735 rtc->rtc_ck = devm_clk_get(&pdev->dev, NULL); in stm32_rtc_probe()
737 rtc->pclk = devm_clk_get(&pdev->dev, "pclk"); in stm32_rtc_probe()
738 if (IS_ERR(rtc->pclk)) { in stm32_rtc_probe()
739 dev_err(&pdev->dev, "no pclk clock"); in stm32_rtc_probe()
740 return PTR_ERR(rtc->pclk); in stm32_rtc_probe()
742 rtc->rtc_ck = devm_clk_get(&pdev->dev, "rtc_ck"); in stm32_rtc_probe()
744 if (IS_ERR(rtc->rtc_ck)) { in stm32_rtc_probe()
745 dev_err(&pdev->dev, "no rtc_ck clock"); in stm32_rtc_probe()
746 return PTR_ERR(rtc->rtc_ck); in stm32_rtc_probe()
749 if (rtc->data->has_pclk) { in stm32_rtc_probe()
750 ret = clk_prepare_enable(rtc->pclk); in stm32_rtc_probe()
755 ret = clk_prepare_enable(rtc->rtc_ck); in stm32_rtc_probe()
759 if (rtc->data->need_dbp) in stm32_rtc_probe()
760 regmap_update_bits(rtc->dbp, rtc->dbp_reg, in stm32_rtc_probe()
761 rtc->dbp_mask, rtc->dbp_mask); in stm32_rtc_probe()
766 * power-on reset (no vbat, no power-supply). It is not reset if in stm32_rtc_probe()
767 * rtc_ck parent clock has changed (so RTC prescalers need to be in stm32_rtc_probe()
768 * changed). That's why we cannot rely on this flag to know if RTC in stm32_rtc_probe()
771 ret = stm32_rtc_init(pdev, rtc); in stm32_rtc_probe()
775 rtc->irq_alarm = platform_get_irq(pdev, 0); in stm32_rtc_probe()
776 if (rtc->irq_alarm <= 0) { in stm32_rtc_probe()
777 ret = rtc->irq_alarm; in stm32_rtc_probe()
781 ret = device_init_wakeup(&pdev->dev, true); in stm32_rtc_probe()
782 if (rtc->data->has_wakeirq) { in stm32_rtc_probe()
783 rtc->wakeirq_alarm = platform_get_irq(pdev, 1); in stm32_rtc_probe()
784 if (rtc->wakeirq_alarm > 0) { in stm32_rtc_probe()
785 ret = dev_pm_set_dedicated_wake_irq(&pdev->dev, in stm32_rtc_probe()
786 rtc->wakeirq_alarm); in stm32_rtc_probe()
788 ret = rtc->wakeirq_alarm; in stm32_rtc_probe()
789 if (rtc->wakeirq_alarm == -EPROBE_DEFER) in stm32_rtc_probe()
794 dev_warn(&pdev->dev, "alarm can't wake up the system: %d", ret); in stm32_rtc_probe()
796 platform_set_drvdata(pdev, rtc); in stm32_rtc_probe()
798 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name, in stm32_rtc_probe()
800 if (IS_ERR(rtc->rtc_dev)) { in stm32_rtc_probe()
801 ret = PTR_ERR(rtc->rtc_dev); in stm32_rtc_probe()
802 dev_err(&pdev->dev, "rtc device registration failed, err=%d\n", in stm32_rtc_probe()
807 /* Handle RTC alarm interrupts */ in stm32_rtc_probe()
808 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq_alarm, NULL, in stm32_rtc_probe()
810 pdev->name, rtc); in stm32_rtc_probe()
812 dev_err(&pdev->dev, "IRQ%d (alarm interrupt) already claimed\n", in stm32_rtc_probe()
813 rtc->irq_alarm); in stm32_rtc_probe()
821 if (!(readl_relaxed(rtc->base + regs->isr) & STM32_RTC_ISR_INITS)) in stm32_rtc_probe()
822 dev_warn(&pdev->dev, "Date/Time must be initialized\n"); in stm32_rtc_probe()
824 if (regs->verr != UNDEF_REG) { in stm32_rtc_probe()
825 u32 ver = readl_relaxed(rtc->base + regs->verr); in stm32_rtc_probe()
827 dev_info(&pdev->dev, "registered rev:%d.%d\n", in stm32_rtc_probe()
835 clk_disable_unprepare(rtc->rtc_ck); in stm32_rtc_probe()
837 if (rtc->data->has_pclk) in stm32_rtc_probe()
838 clk_disable_unprepare(rtc->pclk); in stm32_rtc_probe()
840 if (rtc->data->need_dbp) in stm32_rtc_probe()
841 regmap_update_bits(rtc->dbp, rtc->dbp_reg, rtc->dbp_mask, 0); in stm32_rtc_probe()
843 dev_pm_clear_wake_irq(&pdev->dev); in stm32_rtc_probe()
844 device_init_wakeup(&pdev->dev, false); in stm32_rtc_probe()
851 struct stm32_rtc *rtc = platform_get_drvdata(pdev); in stm32_rtc_remove() local
852 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_remove()
856 stm32_rtc_wpr_unlock(rtc); in stm32_rtc_remove()
857 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_remove()
859 writel_relaxed(cr, rtc->base + regs->cr); in stm32_rtc_remove()
860 stm32_rtc_wpr_lock(rtc); in stm32_rtc_remove()
862 clk_disable_unprepare(rtc->rtc_ck); in stm32_rtc_remove()
863 if (rtc->data->has_pclk) in stm32_rtc_remove()
864 clk_disable_unprepare(rtc->pclk); in stm32_rtc_remove()
867 if (rtc->data->need_dbp) in stm32_rtc_remove()
868 regmap_update_bits(rtc->dbp, rtc->dbp_reg, rtc->dbp_mask, 0); in stm32_rtc_remove()
870 dev_pm_clear_wake_irq(&pdev->dev); in stm32_rtc_remove()
871 device_init_wakeup(&pdev->dev, false); in stm32_rtc_remove()
879 struct stm32_rtc *rtc = dev_get_drvdata(dev); in stm32_rtc_suspend() local
881 if (rtc->data->has_pclk) in stm32_rtc_suspend()
882 clk_disable_unprepare(rtc->pclk); in stm32_rtc_suspend()
885 return enable_irq_wake(rtc->irq_alarm); in stm32_rtc_suspend()
892 struct stm32_rtc *rtc = dev_get_drvdata(dev); in stm32_rtc_resume() local
895 if (rtc->data->has_pclk) { in stm32_rtc_resume()
896 ret = clk_prepare_enable(rtc->pclk); in stm32_rtc_resume()
901 ret = stm32_rtc_wait_sync(rtc); in stm32_rtc_resume()
903 if (rtc->data->has_pclk) in stm32_rtc_resume()
904 clk_disable_unprepare(rtc->pclk); in stm32_rtc_resume()
909 return disable_irq_wake(rtc->irq_alarm); in stm32_rtc_resume()