hc
2024-05-10 ee930fffee469d076998274a2ca55e13dc1efb67
kernel/drivers/rtc/rtc-sc27xx.c
....@@ -129,19 +129,6 @@
129129 SPRD_RTC_ALM_INT_MASK);
130130 }
131131
132
-static int sprd_rtc_disable_ints(struct sprd_rtc *rtc)
133
-{
134
- int ret;
135
-
136
- ret = regmap_update_bits(rtc->regmap, rtc->base + SPRD_RTC_INT_EN,
137
- SPRD_RTC_INT_MASK, 0);
138
- if (ret)
139
- return ret;
140
-
141
- return regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR,
142
- SPRD_RTC_INT_MASK);
143
-}
144
-
145132 static int sprd_rtc_lock_alarm(struct sprd_rtc *rtc, bool lock)
146133 {
147134 int ret;
....@@ -151,7 +138,7 @@
151138 if (ret)
152139 return ret;
153140
154
- val &= ~(SPRD_RTC_ALMLOCK_MASK | SPRD_RTC_POWEROFF_ALM_FLAG);
141
+ val &= ~SPRD_RTC_ALMLOCK_MASK;
155142 if (lock)
156143 val |= SPRD_RTC_ALM_LOCK;
157144 else
....@@ -172,7 +159,8 @@
172159 return ret;
173160 }
174161
175
- return 0;
162
+ return regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR,
163
+ SPRD_RTC_SPG_UPD_EN);
176164 }
177165
178166 static int sprd_rtc_get_secs(struct sprd_rtc *rtc, enum sprd_rtc_reg_types type,
....@@ -427,10 +415,14 @@
427415 u32 val;
428416
429417 /*
430
- * If aie_timer is enabled, we should get the normal alarm time.
418
+ * Before RTC device is registered, it will check to see if there is an
419
+ * alarm already set in RTC hardware, and we always read the normal
420
+ * alarm at this time.
421
+ *
422
+ * Or if aie_timer is enabled, we should get the normal alarm time.
431423 * Otherwise we should get auxiliary alarm time.
432424 */
433
- if (rtc->rtc && rtc->rtc->aie_timer.enabled == 0)
425
+ if (rtc->rtc && rtc->rtc->registered && rtc->rtc->aie_timer.enabled == 0)
434426 return sprd_rtc_read_aux_alarm(dev, alrm);
435427
436428 ret = sprd_rtc_get_secs(rtc, SPRD_RTC_ALARM, &secs);
....@@ -575,6 +567,32 @@
575567 return 0;
576568 }
577569
570
+static int sprd_rtc_check_alarm_int(struct sprd_rtc *rtc)
571
+{
572
+ u32 val;
573
+ int ret;
574
+
575
+ ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_SPG_VALUE, &val);
576
+ if (ret)
577
+ return ret;
578
+
579
+ /*
580
+ * The SPRD_RTC_INT_EN register is not put in always-power-on region
581
+ * supplied by VDDRTC, so we should check if we need enable the alarm
582
+ * interrupt when system booting.
583
+ *
584
+ * If we have set SPRD_RTC_POWEROFF_ALM_FLAG which is saved in
585
+ * always-power-on region, that means we have set one alarm last time,
586
+ * so we should enable the alarm interrupt to help RTC core to see if
587
+ * there is an alarm already set in RTC hardware.
588
+ */
589
+ if (!(val & SPRD_RTC_POWEROFF_ALM_FLAG))
590
+ return 0;
591
+
592
+ return regmap_update_bits(rtc->regmap, rtc->base + SPRD_RTC_INT_EN,
593
+ SPRD_RTC_ALARM_EN, SPRD_RTC_ALARM_EN);
594
+}
595
+
578596 static int sprd_rtc_probe(struct platform_device *pdev)
579597 {
580598 struct device_node *node = pdev->dev.of_node;
....@@ -596,10 +614,8 @@
596614 }
597615
598616 rtc->irq = platform_get_irq(pdev, 0);
599
- if (rtc->irq < 0) {
600
- dev_err(&pdev->dev, "failed to get RTC irq number\n");
617
+ if (rtc->irq < 0)
601618 return rtc->irq;
602
- }
603619
604620 rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
605621 if (IS_ERR(rtc->rtc))
....@@ -608,10 +624,10 @@
608624 rtc->dev = &pdev->dev;
609625 platform_set_drvdata(pdev, rtc);
610626
611
- /* clear all RTC interrupts and disable all RTC interrupts */
612
- ret = sprd_rtc_disable_ints(rtc);
627
+ /* check if we need set the alarm interrupt */
628
+ ret = sprd_rtc_check_alarm_int(rtc);
613629 if (ret) {
614
- dev_err(&pdev->dev, "failed to disable RTC interrupts\n");
630
+ dev_err(&pdev->dev, "failed to check RTC alarm interrupt\n");
615631 return ret;
616632 }
617633
....@@ -631,22 +647,17 @@
631647 return ret;
632648 }
633649
650
+ device_init_wakeup(&pdev->dev, 1);
651
+
634652 rtc->rtc->ops = &sprd_rtc_ops;
635653 rtc->rtc->range_min = 0;
636654 rtc->rtc->range_max = 5662310399LL;
637655 ret = rtc_register_device(rtc->rtc);
638656 if (ret) {
639
- dev_err(&pdev->dev, "failed to register rtc device\n");
657
+ device_init_wakeup(&pdev->dev, 0);
640658 return ret;
641659 }
642660
643
- device_init_wakeup(&pdev->dev, 1);
644
- return 0;
645
-}
646
-
647
-static int sprd_rtc_remove(struct platform_device *pdev)
648
-{
649
- device_init_wakeup(&pdev->dev, 0);
650661 return 0;
651662 }
652663
....@@ -662,7 +673,6 @@
662673 .of_match_table = sprd_rtc_of_match,
663674 },
664675 .probe = sprd_rtc_probe,
665
- .remove = sprd_rtc_remove,
666676 };
667677 module_platform_driver(sprd_rtc_driver);
668678