| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved. |
|---|
| 3 | 4 | * Copyright 2010 Orex Computed Radiography |
|---|
| 4 | 5 | */ |
|---|
| 5 | | - |
|---|
| 6 | | -/* |
|---|
| 7 | | - * The code contained herein is licensed under the GNU General Public |
|---|
| 8 | | - * License. You may obtain a copy of the GNU General Public License |
|---|
| 9 | | - * Version 2 or later at the following locations: |
|---|
| 10 | | - * |
|---|
| 11 | | - * http://www.opensource.org/licenses/gpl-license.html |
|---|
| 12 | | - * http://www.gnu.org/copyleft/gpl.html |
|---|
| 13 | | - */ |
|---|
| 14 | | - |
|---|
| 15 | | -/* based on rtc-mc13892.c */ |
|---|
| 16 | 6 | |
|---|
| 17 | 7 | /* |
|---|
| 18 | 8 | * This driver uses the 47-bit 32 kHz counter in the Freescale DryIce block |
|---|
| .. | .. |
|---|
| 105 | 95 | |
|---|
| 106 | 96 | /** |
|---|
| 107 | 97 | * struct imxdi_dev - private imxdi rtc data |
|---|
| 108 | | - * @pdev: pionter to platform dev |
|---|
| 98 | + * @pdev: pointer to platform dev |
|---|
| 109 | 99 | * @rtc: pointer to rtc struct |
|---|
| 110 | 100 | * @ioaddr: IO registers pointer |
|---|
| 111 | 101 | * @clk: input reference clock |
|---|
| .. | .. |
|---|
| 360 | 350 | * the tamper register is locked. We cannot disable the |
|---|
| 361 | 351 | * tamper detection. The TDCHL can only be reset by a |
|---|
| 362 | 352 | * DRYICE POR, but we cannot force a DRYICE POR in |
|---|
| 363 | | - * softwere because we are still in "FAILURE STATE". |
|---|
| 353 | + * software because we are still in "FAILURE STATE". |
|---|
| 364 | 354 | * We need a DRYICE POR via battery power cycling.... |
|---|
| 365 | 355 | */ |
|---|
| 366 | 356 | /* |
|---|
| .. | .. |
|---|
| 552 | 542 | unsigned long now; |
|---|
| 553 | 543 | |
|---|
| 554 | 544 | now = readl(imxdi->ioaddr + DTCMR); |
|---|
| 555 | | - rtc_time_to_tm(now, tm); |
|---|
| 545 | + rtc_time64_to_tm(now, tm); |
|---|
| 556 | 546 | |
|---|
| 557 | 547 | return 0; |
|---|
| 558 | 548 | } |
|---|
| .. | .. |
|---|
| 561 | 551 | * set the seconds portion of dryice time counter and clear the |
|---|
| 562 | 552 | * fractional part. |
|---|
| 563 | 553 | */ |
|---|
| 564 | | -static int dryice_rtc_set_mmss(struct device *dev, unsigned long secs) |
|---|
| 554 | +static int dryice_rtc_set_time(struct device *dev, struct rtc_time *tm) |
|---|
| 565 | 555 | { |
|---|
| 566 | 556 | struct imxdi_dev *imxdi = dev_get_drvdata(dev); |
|---|
| 567 | 557 | u32 dcr, dsr; |
|---|
| .. | .. |
|---|
| 588 | 578 | if (rc != 0) |
|---|
| 589 | 579 | return rc; |
|---|
| 590 | 580 | |
|---|
| 591 | | - rc = di_write_wait(imxdi, secs, DTCMR); |
|---|
| 581 | + rc = di_write_wait(imxdi, rtc_tm_to_time64(tm), DTCMR); |
|---|
| 592 | 582 | if (rc != 0) |
|---|
| 593 | 583 | return rc; |
|---|
| 594 | 584 | |
|---|
| .. | .. |
|---|
| 618 | 608 | u32 dcamr; |
|---|
| 619 | 609 | |
|---|
| 620 | 610 | dcamr = readl(imxdi->ioaddr + DCAMR); |
|---|
| 621 | | - rtc_time_to_tm(dcamr, &alarm->time); |
|---|
| 611 | + rtc_time64_to_tm(dcamr, &alarm->time); |
|---|
| 622 | 612 | |
|---|
| 623 | 613 | /* alarm is enabled if the interrupt is enabled */ |
|---|
| 624 | 614 | alarm->enabled = (readl(imxdi->ioaddr + DIER) & DIER_CAIE) != 0; |
|---|
| .. | .. |
|---|
| 640 | 630 | static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
|---|
| 641 | 631 | { |
|---|
| 642 | 632 | struct imxdi_dev *imxdi = dev_get_drvdata(dev); |
|---|
| 643 | | - unsigned long now; |
|---|
| 644 | | - unsigned long alarm_time; |
|---|
| 645 | 633 | int rc; |
|---|
| 646 | 634 | |
|---|
| 647 | | - rc = rtc_tm_to_time(&alarm->time, &alarm_time); |
|---|
| 648 | | - if (rc) |
|---|
| 649 | | - return rc; |
|---|
| 650 | | - |
|---|
| 651 | | - /* don't allow setting alarm in the past */ |
|---|
| 652 | | - now = readl(imxdi->ioaddr + DTCMR); |
|---|
| 653 | | - if (alarm_time < now) |
|---|
| 654 | | - return -EINVAL; |
|---|
| 655 | | - |
|---|
| 656 | 635 | /* write the new alarm time */ |
|---|
| 657 | | - rc = di_write_wait(imxdi, (u32)alarm_time, DCAMR); |
|---|
| 636 | + rc = di_write_wait(imxdi, rtc_tm_to_time64(&alarm->time), DCAMR); |
|---|
| 658 | 637 | if (rc) |
|---|
| 659 | 638 | return rc; |
|---|
| 660 | 639 | |
|---|
| .. | .. |
|---|
| 668 | 647 | |
|---|
| 669 | 648 | static const struct rtc_class_ops dryice_rtc_ops = { |
|---|
| 670 | 649 | .read_time = dryice_rtc_read_time, |
|---|
| 671 | | - .set_mmss = dryice_rtc_set_mmss, |
|---|
| 650 | + .set_time = dryice_rtc_set_time, |
|---|
| 672 | 651 | .alarm_irq_enable = dryice_rtc_alarm_irq_enable, |
|---|
| 673 | 652 | .read_alarm = dryice_rtc_read_alarm, |
|---|
| 674 | 653 | .set_alarm = dryice_rtc_set_alarm, |
|---|
| .. | .. |
|---|
| 761 | 740 | */ |
|---|
| 762 | 741 | static int __init dryice_rtc_probe(struct platform_device *pdev) |
|---|
| 763 | 742 | { |
|---|
| 764 | | - struct resource *res; |
|---|
| 765 | 743 | struct imxdi_dev *imxdi; |
|---|
| 766 | 744 | int norm_irq, sec_irq; |
|---|
| 767 | 745 | int rc; |
|---|
| .. | .. |
|---|
| 772 | 750 | |
|---|
| 773 | 751 | imxdi->pdev = pdev; |
|---|
| 774 | 752 | |
|---|
| 775 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 776 | | - imxdi->ioaddr = devm_ioremap_resource(&pdev->dev, res); |
|---|
| 753 | + imxdi->ioaddr = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 777 | 754 | if (IS_ERR(imxdi->ioaddr)) |
|---|
| 778 | 755 | return PTR_ERR(imxdi->ioaddr); |
|---|
| 779 | 756 | |
|---|
| .. | .. |
|---|
| 795 | 772 | INIT_WORK(&imxdi->work, dryice_work); |
|---|
| 796 | 773 | |
|---|
| 797 | 774 | mutex_init(&imxdi->write_mutex); |
|---|
| 775 | + |
|---|
| 776 | + imxdi->rtc = devm_rtc_allocate_device(&pdev->dev); |
|---|
| 777 | + if (IS_ERR(imxdi->rtc)) |
|---|
| 778 | + return PTR_ERR(imxdi->rtc); |
|---|
| 798 | 779 | |
|---|
| 799 | 780 | imxdi->clk = devm_clk_get(&pdev->dev, NULL); |
|---|
| 800 | 781 | if (IS_ERR(imxdi->clk)) |
|---|
| .. | .. |
|---|
| 829 | 810 | } |
|---|
| 830 | 811 | |
|---|
| 831 | 812 | platform_set_drvdata(pdev, imxdi); |
|---|
| 832 | | - imxdi->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, |
|---|
| 833 | | - &dryice_rtc_ops, THIS_MODULE); |
|---|
| 834 | | - if (IS_ERR(imxdi->rtc)) { |
|---|
| 835 | | - rc = PTR_ERR(imxdi->rtc); |
|---|
| 813 | + |
|---|
| 814 | + imxdi->rtc->ops = &dryice_rtc_ops; |
|---|
| 815 | + imxdi->rtc->range_max = U32_MAX; |
|---|
| 816 | + |
|---|
| 817 | + rc = rtc_register_device(imxdi->rtc); |
|---|
| 818 | + if (rc) |
|---|
| 836 | 819 | goto err; |
|---|
| 837 | | - } |
|---|
| 838 | 820 | |
|---|
| 839 | 821 | return 0; |
|---|
| 840 | 822 | |
|---|