Lines Matching +full:irq +full:- +full:syscfg

1 // SPDX-License-Identifier: GPL-2.0
139 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_wpr_unlock()
141 writel_relaxed(RTC_WPR_1ST_KEY, rtc->base + regs->wpr); in stm32_rtc_wpr_unlock()
142 writel_relaxed(RTC_WPR_2ND_KEY, rtc->base + regs->wpr); in stm32_rtc_wpr_unlock()
147 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_wpr_lock()
149 writel_relaxed(RTC_WPR_WRONG_KEY, rtc->base + regs->wpr); in stm32_rtc_wpr_lock()
154 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_enter_init_mode()
155 unsigned int isr = readl_relaxed(rtc->base + regs->isr); in stm32_rtc_enter_init_mode()
159 writel_relaxed(isr, rtc->base + regs->isr); in stm32_rtc_enter_init_mode()
167 return readl_relaxed_poll_timeout_atomic(rtc->base + regs->isr, isr, in stm32_rtc_enter_init_mode()
177 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_exit_init_mode()
178 unsigned int isr = readl_relaxed(rtc->base + regs->isr); in stm32_rtc_exit_init_mode()
181 writel_relaxed(isr, rtc->base + regs->isr); in stm32_rtc_exit_init_mode()
186 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_wait_sync()
187 unsigned int isr = readl_relaxed(rtc->base + regs->isr); in stm32_rtc_wait_sync()
190 writel_relaxed(isr, rtc->base + regs->isr); in stm32_rtc_wait_sync()
196 return readl_relaxed_poll_timeout_atomic(rtc->base + regs->isr, in stm32_rtc_wait_sync()
205 rtc->data->clear_events(rtc, flags); in stm32_rtc_clear_event_flags()
208 static irqreturn_t stm32_rtc_alarm_irq(int irq, void *dev_id) in stm32_rtc_alarm_irq() argument
211 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_alarm_irq()
212 const struct stm32_rtc_events *evts = &rtc->data->events; in stm32_rtc_alarm_irq()
215 rtc_lock(rtc->rtc_dev); in stm32_rtc_alarm_irq()
217 status = readl_relaxed(rtc->base + regs->sr); in stm32_rtc_alarm_irq()
218 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_alarm_irq()
220 if ((status & evts->alra) && in stm32_rtc_alarm_irq()
222 /* Alarm A flag - Alarm interrupt */ in stm32_rtc_alarm_irq()
223 dev_dbg(&rtc->rtc_dev->dev, "Alarm occurred\n"); in stm32_rtc_alarm_irq()
226 rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF); in stm32_rtc_alarm_irq()
229 stm32_rtc_clear_event_flags(rtc, evts->alra); in stm32_rtc_alarm_irq()
232 rtc_unlock(rtc->rtc_dev); in stm32_rtc_alarm_irq()
240 tm->tm_sec = bin2bcd(tm->tm_sec); in tm2bcd()
241 tm->tm_min = bin2bcd(tm->tm_min); in tm2bcd()
242 tm->tm_hour = bin2bcd(tm->tm_hour); in tm2bcd()
244 tm->tm_mday = bin2bcd(tm->tm_mday); in tm2bcd()
245 tm->tm_mon = bin2bcd(tm->tm_mon + 1); in tm2bcd()
246 tm->tm_year = bin2bcd(tm->tm_year - 100); in tm2bcd()
249 * - on kernel side, 0=Sunday...6=Saturday in tm2bcd()
250 * - on rtc side, 0=invalid,1=Monday...7=Sunday in tm2bcd()
252 tm->tm_wday = (!tm->tm_wday) ? 7 : tm->tm_wday; in tm2bcd()
258 tm->tm_sec = bcd2bin(tm->tm_sec); in bcd2tm()
259 tm->tm_min = bcd2bin(tm->tm_min); in bcd2tm()
260 tm->tm_hour = bcd2bin(tm->tm_hour); in bcd2tm()
262 tm->tm_mday = bcd2bin(tm->tm_mday); in bcd2tm()
263 tm->tm_mon = bcd2bin(tm->tm_mon) - 1; in bcd2tm()
264 tm->tm_year = bcd2bin(tm->tm_year) + 100; in bcd2tm()
267 * - on kernel side, 0=Sunday...6=Saturday in bcd2tm()
268 * - on rtc side, 0=invalid,1=Monday...7=Sunday in bcd2tm()
270 tm->tm_wday %= 7; in bcd2tm()
276 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_read_time()
280 tr = readl_relaxed(rtc->base + regs->tr); in stm32_rtc_read_time()
281 dr = readl_relaxed(rtc->base + regs->dr); in stm32_rtc_read_time()
283 tm->tm_sec = (tr & STM32_RTC_TR_SEC) >> STM32_RTC_TR_SEC_SHIFT; in stm32_rtc_read_time()
284 tm->tm_min = (tr & STM32_RTC_TR_MIN) >> STM32_RTC_TR_MIN_SHIFT; in stm32_rtc_read_time()
285 tm->tm_hour = (tr & STM32_RTC_TR_HOUR) >> STM32_RTC_TR_HOUR_SHIFT; in stm32_rtc_read_time()
287 tm->tm_mday = (dr & STM32_RTC_DR_DATE) >> STM32_RTC_DR_DATE_SHIFT; in stm32_rtc_read_time()
288 tm->tm_mon = (dr & STM32_RTC_DR_MONTH) >> STM32_RTC_DR_MONTH_SHIFT; in stm32_rtc_read_time()
289 tm->tm_year = (dr & STM32_RTC_DR_YEAR) >> STM32_RTC_DR_YEAR_SHIFT; in stm32_rtc_read_time()
290 tm->tm_wday = (dr & STM32_RTC_DR_WDAY) >> STM32_RTC_DR_WDAY_SHIFT; in stm32_rtc_read_time()
302 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_set_time()
309 tr = ((tm->tm_sec << STM32_RTC_TR_SEC_SHIFT) & STM32_RTC_TR_SEC) | in stm32_rtc_set_time()
310 ((tm->tm_min << STM32_RTC_TR_MIN_SHIFT) & STM32_RTC_TR_MIN) | in stm32_rtc_set_time()
311 ((tm->tm_hour << STM32_RTC_TR_HOUR_SHIFT) & STM32_RTC_TR_HOUR); in stm32_rtc_set_time()
314 dr = ((tm->tm_mday << STM32_RTC_DR_DATE_SHIFT) & STM32_RTC_DR_DATE) | in stm32_rtc_set_time()
315 ((tm->tm_mon << STM32_RTC_DR_MONTH_SHIFT) & STM32_RTC_DR_MONTH) | in stm32_rtc_set_time()
316 ((tm->tm_year << STM32_RTC_DR_YEAR_SHIFT) & STM32_RTC_DR_YEAR) | in stm32_rtc_set_time()
317 ((tm->tm_wday << STM32_RTC_DR_WDAY_SHIFT) & STM32_RTC_DR_WDAY); in stm32_rtc_set_time()
327 writel_relaxed(tr, rtc->base + regs->tr); in stm32_rtc_set_time()
328 writel_relaxed(dr, rtc->base + regs->dr); in stm32_rtc_set_time()
342 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_read_alarm()
343 const struct stm32_rtc_events *evts = &rtc->data->events; in stm32_rtc_read_alarm()
344 struct rtc_time *tm = &alrm->time; in stm32_rtc_read_alarm()
347 alrmar = readl_relaxed(rtc->base + regs->alrmar); in stm32_rtc_read_alarm()
348 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_read_alarm()
349 status = readl_relaxed(rtc->base + regs->sr); in stm32_rtc_read_alarm()
356 tm->tm_mday = -1; in stm32_rtc_read_alarm()
357 tm->tm_wday = -1; in stm32_rtc_read_alarm()
361 tm->tm_mday = -1; in stm32_rtc_read_alarm()
362 tm->tm_wday = (alrmar & STM32_RTC_ALRMXR_WDAY) >> in stm32_rtc_read_alarm()
364 tm->tm_wday %= 7; in stm32_rtc_read_alarm()
367 tm->tm_wday = -1; in stm32_rtc_read_alarm()
368 tm->tm_mday = (alrmar & STM32_RTC_ALRMXR_DATE) >> in stm32_rtc_read_alarm()
375 tm->tm_hour = -1; in stm32_rtc_read_alarm()
377 tm->tm_hour = (alrmar & STM32_RTC_ALRMXR_HOUR) >> in stm32_rtc_read_alarm()
380 tm->tm_hour += 12; in stm32_rtc_read_alarm()
385 tm->tm_min = -1; in stm32_rtc_read_alarm()
387 tm->tm_min = (alrmar & STM32_RTC_ALRMXR_MIN) >> in stm32_rtc_read_alarm()
393 tm->tm_sec = -1; in stm32_rtc_read_alarm()
395 tm->tm_sec = (alrmar & STM32_RTC_ALRMXR_SEC) >> in stm32_rtc_read_alarm()
401 alrm->enabled = (cr & STM32_RTC_CR_ALRAE) ? 1 : 0; in stm32_rtc_read_alarm()
402 alrm->pending = (status & evts->alra) ? 1 : 0; in stm32_rtc_read_alarm()
410 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_alarm_irq_enable()
411 const struct stm32_rtc_events *evts = &rtc->data->events; in stm32_rtc_alarm_irq_enable()
414 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_alarm_irq_enable()
423 writel_relaxed(cr, rtc->base + regs->cr); in stm32_rtc_alarm_irq_enable()
426 stm32_rtc_clear_event_flags(rtc, evts->alra); in stm32_rtc_alarm_irq_enable()
442 * Assuming current date is M-D-Y H:M:S. in stm32_rtc_valid_alrm()
445 * M-D-Y H:M:S < alarm <= (M+1)-D-Y H:M:S in stm32_rtc_valid_alrm()
463 - now.tm_mday in stm32_rtc_valid_alrm()
468 return rtc_tm_to_time64(tm) <= max_alarm_time64 ? 0 : -EINVAL; in stm32_rtc_valid_alrm()
474 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_set_alarm()
475 struct rtc_time *tm = &alrm->time; in stm32_rtc_set_alarm()
485 return -EINVAL; in stm32_rtc_set_alarm()
492 alrmar |= (tm->tm_mday << STM32_RTC_ALRMXR_DATE_SHIFT) & in stm32_rtc_set_alarm()
494 /* 24-hour format */ in stm32_rtc_set_alarm()
496 alrmar |= (tm->tm_hour << STM32_RTC_ALRMXR_HOUR_SHIFT) & in stm32_rtc_set_alarm()
498 alrmar |= (tm->tm_min << STM32_RTC_ALRMXR_MIN_SHIFT) & in stm32_rtc_set_alarm()
500 alrmar |= (tm->tm_sec << STM32_RTC_ALRMXR_SEC_SHIFT) & in stm32_rtc_set_alarm()
506 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_set_alarm()
508 writel_relaxed(cr, rtc->base + regs->cr); in stm32_rtc_set_alarm()
514 ret = readl_relaxed_poll_timeout_atomic(rtc->base + regs->isr, in stm32_rtc_set_alarm()
525 writel_relaxed(alrmar, rtc->base + regs->alrmar); in stm32_rtc_set_alarm()
527 stm32_rtc_alarm_irq_enable(dev, alrm->enabled); in stm32_rtc_set_alarm()
545 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_clear_events()
548 writel_relaxed(readl_relaxed(rtc->base + regs->isr) & ~flags, in stm32_rtc_clear_events()
549 rtc->base + regs->isr); in stm32_rtc_clear_events()
599 struct stm32_rtc_registers regs = rtc->data->regs; in stm32mp1_rtc_clear_events()
602 writel_relaxed(flags, rtc->base + regs.scr); in stm32mp1_rtc_clear_events()
628 { .compatible = "st,stm32-rtc", .data = &stm32_rtc_data },
629 { .compatible = "st,stm32h7-rtc", .data = &stm32h7_rtc_data },
630 { .compatible = "st,stm32mp1-rtc", .data = &stm32mp1_data },
638 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_init()
643 rate = clk_get_rate(rtc->rtc_ck); in stm32_rtc_init()
650 dev_err(&pdev->dev, "rtc_ck rate is too high: %dHz\n", rate); in stm32_rtc_init()
651 return -EINVAL; in stm32_rtc_init()
654 if (rtc->data->need_accuracy) { in stm32_rtc_init()
656 pred_s = (rate / (pred_a + 1)) - 1; in stm32_rtc_init()
662 for (pred_a = pred_a_max; pred_a + 1 > 0; pred_a--) { in stm32_rtc_init()
663 pred_s = (rate / (pred_a + 1)) - 1; in stm32_rtc_init()
676 pred_s = (rate / (pred_a + 1)) - 1; in stm32_rtc_init()
678 dev_warn(&pdev->dev, "rtc_ck is %s\n", in stm32_rtc_init()
683 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_init()
685 prer = readl_relaxed(rtc->base + regs->prer); in stm32_rtc_init()
701 dev_err(&pdev->dev, in stm32_rtc_init()
706 writel_relaxed(pred_s, rtc->base + regs->prer); in stm32_rtc_init()
707 writel_relaxed(pred_a | pred_s, rtc->base + regs->prer); in stm32_rtc_init()
711 writel_relaxed(cr, rtc->base + regs->cr); in stm32_rtc_init()
728 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); in stm32_rtc_probe()
730 return -ENOMEM; in stm32_rtc_probe()
732 rtc->base = devm_platform_ioremap_resource(pdev, 0); in stm32_rtc_probe()
733 if (IS_ERR(rtc->base)) in stm32_rtc_probe()
734 return PTR_ERR(rtc->base); in stm32_rtc_probe()
736 rtc->data = (struct stm32_rtc_data *) in stm32_rtc_probe()
737 of_device_get_match_data(&pdev->dev); in stm32_rtc_probe()
738 regs = &rtc->data->regs; in stm32_rtc_probe()
740 if (rtc->data->need_dbp) { in stm32_rtc_probe()
741 rtc->dbp = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, in stm32_rtc_probe()
742 "st,syscfg"); in stm32_rtc_probe()
743 if (IS_ERR(rtc->dbp)) { in stm32_rtc_probe()
744 dev_err(&pdev->dev, "no st,syscfg\n"); in stm32_rtc_probe()
745 return PTR_ERR(rtc->dbp); in stm32_rtc_probe()
748 ret = of_property_read_u32_index(pdev->dev.of_node, "st,syscfg", in stm32_rtc_probe()
749 1, &rtc->dbp_reg); in stm32_rtc_probe()
751 dev_err(&pdev->dev, "can't read DBP register offset\n"); in stm32_rtc_probe()
755 ret = of_property_read_u32_index(pdev->dev.of_node, "st,syscfg", in stm32_rtc_probe()
756 2, &rtc->dbp_mask); in stm32_rtc_probe()
758 dev_err(&pdev->dev, "can't read DBP register mask\n"); in stm32_rtc_probe()
763 if (!rtc->data->has_pclk) { in stm32_rtc_probe()
764 rtc->pclk = NULL; in stm32_rtc_probe()
765 rtc->rtc_ck = devm_clk_get(&pdev->dev, NULL); in stm32_rtc_probe()
767 rtc->pclk = devm_clk_get(&pdev->dev, "pclk"); in stm32_rtc_probe()
768 if (IS_ERR(rtc->pclk)) in stm32_rtc_probe()
769 return dev_err_probe(&pdev->dev, PTR_ERR(rtc->pclk), "no pclk clock"); in stm32_rtc_probe()
771 rtc->rtc_ck = devm_clk_get(&pdev->dev, "rtc_ck"); in stm32_rtc_probe()
773 if (IS_ERR(rtc->rtc_ck)) in stm32_rtc_probe()
774 return dev_err_probe(&pdev->dev, PTR_ERR(rtc->rtc_ck), "no rtc_ck clock"); in stm32_rtc_probe()
776 if (rtc->data->has_pclk) { in stm32_rtc_probe()
777 ret = clk_prepare_enable(rtc->pclk); in stm32_rtc_probe()
782 ret = clk_prepare_enable(rtc->rtc_ck); in stm32_rtc_probe()
786 if (rtc->data->need_dbp) in stm32_rtc_probe()
787 regmap_update_bits(rtc->dbp, rtc->dbp_reg, in stm32_rtc_probe()
788 rtc->dbp_mask, rtc->dbp_mask); in stm32_rtc_probe()
793 * power-on reset (no vbat, no power-supply). It is not reset if in stm32_rtc_probe()
802 rtc->irq_alarm = platform_get_irq(pdev, 0); in stm32_rtc_probe()
803 if (rtc->irq_alarm <= 0) { in stm32_rtc_probe()
804 ret = rtc->irq_alarm; in stm32_rtc_probe()
808 ret = device_init_wakeup(&pdev->dev, true); in stm32_rtc_probe()
812 ret = dev_pm_set_wake_irq(&pdev->dev, rtc->irq_alarm); in stm32_rtc_probe()
818 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name, in stm32_rtc_probe()
820 if (IS_ERR(rtc->rtc_dev)) { in stm32_rtc_probe()
821 ret = PTR_ERR(rtc->rtc_dev); in stm32_rtc_probe()
822 dev_err(&pdev->dev, "rtc device registration failed, err=%d\n", in stm32_rtc_probe()
828 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq_alarm, NULL, in stm32_rtc_probe()
830 pdev->name, rtc); in stm32_rtc_probe()
832 dev_err(&pdev->dev, "IRQ%d (alarm interrupt) already claimed\n", in stm32_rtc_probe()
833 rtc->irq_alarm); in stm32_rtc_probe()
841 if (!(readl_relaxed(rtc->base + regs->isr) & STM32_RTC_ISR_INITS)) in stm32_rtc_probe()
842 dev_warn(&pdev->dev, "Date/Time must be initialized\n"); in stm32_rtc_probe()
844 if (regs->verr != UNDEF_REG) { in stm32_rtc_probe()
845 u32 ver = readl_relaxed(rtc->base + regs->verr); in stm32_rtc_probe()
847 dev_info(&pdev->dev, "registered rev:%d.%d\n", in stm32_rtc_probe()
855 clk_disable_unprepare(rtc->rtc_ck); in stm32_rtc_probe()
857 if (rtc->data->has_pclk) in stm32_rtc_probe()
858 clk_disable_unprepare(rtc->pclk); in stm32_rtc_probe()
860 if (rtc->data->need_dbp) in stm32_rtc_probe()
861 regmap_update_bits(rtc->dbp, rtc->dbp_reg, rtc->dbp_mask, 0); in stm32_rtc_probe()
863 dev_pm_clear_wake_irq(&pdev->dev); in stm32_rtc_probe()
864 device_init_wakeup(&pdev->dev, false); in stm32_rtc_probe()
872 const struct stm32_rtc_registers *regs = &rtc->data->regs; in stm32_rtc_remove()
877 cr = readl_relaxed(rtc->base + regs->cr); in stm32_rtc_remove()
879 writel_relaxed(cr, rtc->base + regs->cr); in stm32_rtc_remove()
882 clk_disable_unprepare(rtc->rtc_ck); in stm32_rtc_remove()
883 if (rtc->data->has_pclk) in stm32_rtc_remove()
884 clk_disable_unprepare(rtc->pclk); in stm32_rtc_remove()
887 if (rtc->data->need_dbp) in stm32_rtc_remove()
888 regmap_update_bits(rtc->dbp, rtc->dbp_reg, rtc->dbp_mask, 0); in stm32_rtc_remove()
890 dev_pm_clear_wake_irq(&pdev->dev); in stm32_rtc_remove()
891 device_init_wakeup(&pdev->dev, false); in stm32_rtc_remove()
898 if (rtc->data->has_pclk) in stm32_rtc_suspend()
899 clk_disable_unprepare(rtc->pclk); in stm32_rtc_suspend()
909 if (rtc->data->has_pclk) { in stm32_rtc_resume()
910 ret = clk_prepare_enable(rtc->pclk); in stm32_rtc_resume()
917 if (rtc->data->has_pclk) in stm32_rtc_resume()
918 clk_disable_unprepare(rtc->pclk); in stm32_rtc_resume()