Lines Matching refs:rtc
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()
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()
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()
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()
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()
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()
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()
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()
480 if (stm32_rtc_valid_alrm(rtc, tm) < 0) { 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()
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()
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()
664 stm32_rtc_wpr_unlock(rtc); in stm32_rtc_init()
666 ret = stm32_rtc_enter_init_mode(rtc); 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()
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()
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()
715 return PTR_ERR(rtc->dbp); in stm32_rtc_probe()
719 1, &rtc->dbp_reg); in stm32_rtc_probe()
726 2, &rtc->dbp_mask); 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()
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()
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()
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()
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()
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()
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()
808 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq_alarm, NULL, in stm32_rtc_probe()
810 pdev->name, rtc); 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()
825 u32 ver = readl_relaxed(rtc->base + regs->verr); 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()
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()
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()