|
71 | 71 | #define SUN6I_LOSC_OUT_GATING 0x0060
|
72 | 72 | #define SUN6I_LOSC_OUT_GATING_EN_OFFSET 0
|
73 | 73 |
|
| 74 | +/* General-purpose data */ |
| 75 | +#define SUN6I_GP_DATA 0x0100 |
| 76 | +#define SUN6I_GP_DATA_SIZE 0x20 |
| 77 | + |
74 | 78 | /*
|
75 | 79 | * Get date values
|
76 | 80 | */
|
@@ -662,6 +666,39 @@ static const struct rtc_class_ops sun6i_rtc_ops = {
|
662 | 666 | .alarm_irq_enable = sun6i_rtc_alarm_irq_enable
|
663 | 667 | };
|
664 | 668 |
|
| 669 | +static int sun6i_rtc_nvmem_read(void *priv, unsigned int offset, void *_val, size_t bytes) |
| 670 | +{ |
| 671 | + struct sun6i_rtc_dev *chip = priv; |
| 672 | + u32 *val = _val; |
| 673 | + int i; |
| 674 | + |
| 675 | + for (i = 0; i < bytes / 4; ++i) |
| 676 | + val[i] = readl(chip->base + SUN6I_GP_DATA + offset + 4 * i); |
| 677 | + |
| 678 | + return 0; |
| 679 | +} |
| 680 | + |
| 681 | +static int sun6i_rtc_nvmem_write(void *priv, unsigned int offset, void *_val, size_t bytes) |
| 682 | +{ |
| 683 | + struct sun6i_rtc_dev *chip = priv; |
| 684 | + u32 *val = _val; |
| 685 | + int i; |
| 686 | + |
| 687 | + for (i = 0; i < bytes / 4; ++i) |
| 688 | + writel(val[i], chip->base + SUN6I_GP_DATA + offset + 4 * i); |
| 689 | + |
| 690 | + return 0; |
| 691 | +} |
| 692 | + |
| 693 | +static struct nvmem_config sun6i_rtc_nvmem_cfg = { |
| 694 | + .type = NVMEM_TYPE_BATTERY_BACKED, |
| 695 | + .reg_read = sun6i_rtc_nvmem_read, |
| 696 | + .reg_write = sun6i_rtc_nvmem_write, |
| 697 | + .size = SUN6I_GP_DATA_SIZE, |
| 698 | + .word_size = 4, |
| 699 | + .stride = 4, |
| 700 | +}; |
| 701 | + |
665 | 702 | #ifdef CONFIG_PM_SLEEP
|
666 | 703 | /* Enable IRQ wake on suspend, to wake up from RTC. */
|
667 | 704 | static int sun6i_rtc_suspend(struct device *dev)
|
@@ -795,6 +832,11 @@ static int sun6i_rtc_probe(struct platform_device *pdev)
|
795 | 832 | if (ret)
|
796 | 833 | return ret;
|
797 | 834 |
|
| 835 | + sun6i_rtc_nvmem_cfg.priv = chip; |
| 836 | + ret = devm_rtc_nvmem_register(chip->rtc, &sun6i_rtc_nvmem_cfg); |
| 837 | + if (ret) |
| 838 | + return ret; |
| 839 | + |
798 | 840 | dev_info(&pdev->dev, "RTC enabled\n");
|
799 | 841 |
|
800 | 842 | return 0;
|
|
0 commit comments