.. | .. |
---|
129 | 129 | SPRD_RTC_ALM_INT_MASK); |
---|
130 | 130 | } |
---|
131 | 131 | |
---|
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 | | - |
---|
145 | 132 | static int sprd_rtc_lock_alarm(struct sprd_rtc *rtc, bool lock) |
---|
146 | 133 | { |
---|
147 | 134 | int ret; |
---|
.. | .. |
---|
151 | 138 | if (ret) |
---|
152 | 139 | return ret; |
---|
153 | 140 | |
---|
154 | | - val &= ~(SPRD_RTC_ALMLOCK_MASK | SPRD_RTC_POWEROFF_ALM_FLAG); |
---|
| 141 | + val &= ~SPRD_RTC_ALMLOCK_MASK; |
---|
155 | 142 | if (lock) |
---|
156 | 143 | val |= SPRD_RTC_ALM_LOCK; |
---|
157 | 144 | else |
---|
.. | .. |
---|
172 | 159 | return ret; |
---|
173 | 160 | } |
---|
174 | 161 | |
---|
175 | | - return 0; |
---|
| 162 | + return regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, |
---|
| 163 | + SPRD_RTC_SPG_UPD_EN); |
---|
176 | 164 | } |
---|
177 | 165 | |
---|
178 | 166 | static int sprd_rtc_get_secs(struct sprd_rtc *rtc, enum sprd_rtc_reg_types type, |
---|
.. | .. |
---|
427 | 415 | u32 val; |
---|
428 | 416 | |
---|
429 | 417 | /* |
---|
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. |
---|
431 | 423 | * Otherwise we should get auxiliary alarm time. |
---|
432 | 424 | */ |
---|
433 | | - if (rtc->rtc && rtc->rtc->aie_timer.enabled == 0) |
---|
| 425 | + if (rtc->rtc && rtc->rtc->registered && rtc->rtc->aie_timer.enabled == 0) |
---|
434 | 426 | return sprd_rtc_read_aux_alarm(dev, alrm); |
---|
435 | 427 | |
---|
436 | 428 | ret = sprd_rtc_get_secs(rtc, SPRD_RTC_ALARM, &secs); |
---|
.. | .. |
---|
575 | 567 | return 0; |
---|
576 | 568 | } |
---|
577 | 569 | |
---|
| 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 | + |
---|
578 | 596 | static int sprd_rtc_probe(struct platform_device *pdev) |
---|
579 | 597 | { |
---|
580 | 598 | struct device_node *node = pdev->dev.of_node; |
---|
.. | .. |
---|
596 | 614 | } |
---|
597 | 615 | |
---|
598 | 616 | 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) |
---|
601 | 618 | return rtc->irq; |
---|
602 | | - } |
---|
603 | 619 | |
---|
604 | 620 | rtc->rtc = devm_rtc_allocate_device(&pdev->dev); |
---|
605 | 621 | if (IS_ERR(rtc->rtc)) |
---|
.. | .. |
---|
608 | 624 | rtc->dev = &pdev->dev; |
---|
609 | 625 | platform_set_drvdata(pdev, rtc); |
---|
610 | 626 | |
---|
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); |
---|
613 | 629 | 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"); |
---|
615 | 631 | return ret; |
---|
616 | 632 | } |
---|
617 | 633 | |
---|
.. | .. |
---|
631 | 647 | return ret; |
---|
632 | 648 | } |
---|
633 | 649 | |
---|
| 650 | + device_init_wakeup(&pdev->dev, 1); |
---|
| 651 | + |
---|
634 | 652 | rtc->rtc->ops = &sprd_rtc_ops; |
---|
635 | 653 | rtc->rtc->range_min = 0; |
---|
636 | 654 | rtc->rtc->range_max = 5662310399LL; |
---|
637 | 655 | ret = rtc_register_device(rtc->rtc); |
---|
638 | 656 | if (ret) { |
---|
639 | | - dev_err(&pdev->dev, "failed to register rtc device\n"); |
---|
| 657 | + device_init_wakeup(&pdev->dev, 0); |
---|
640 | 658 | return ret; |
---|
641 | 659 | } |
---|
642 | 660 | |
---|
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); |
---|
650 | 661 | return 0; |
---|
651 | 662 | } |
---|
652 | 663 | |
---|
.. | .. |
---|
662 | 673 | .of_match_table = sprd_rtc_of_match, |
---|
663 | 674 | }, |
---|
664 | 675 | .probe = sprd_rtc_probe, |
---|
665 | | - .remove = sprd_rtc_remove, |
---|
666 | 676 | }; |
---|
667 | 677 | module_platform_driver(sprd_rtc_driver); |
---|
668 | 678 | |
---|