Skip to content

Commit 581d6d8

Browse files
smaeulalexandrebelloni
authored andcommitted
rtc: sun6i: Add NVMEM provider
The sun6i RTC provides 32 bytes of general-purpose data registers. They can be used to save data in the always-on RTC power domain. The registers are writable via 32-bit MMIO accesses only. Expose them with a NVMEM provider so they can be used by other drivers. Signed-off-by: Samuel Holland <samuel@sholland.org> Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20220413231731.56709-1-samuel@sholland.org
1 parent 3123109 commit 581d6d8

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

drivers/rtc/rtc-sun6i.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
#define SUN6I_LOSC_OUT_GATING 0x0060
7272
#define SUN6I_LOSC_OUT_GATING_EN_OFFSET 0
7373

74+
/* General-purpose data */
75+
#define SUN6I_GP_DATA 0x0100
76+
#define SUN6I_GP_DATA_SIZE 0x20
77+
7478
/*
7579
* Get date values
7680
*/
@@ -662,6 +666,39 @@ static const struct rtc_class_ops sun6i_rtc_ops = {
662666
.alarm_irq_enable = sun6i_rtc_alarm_irq_enable
663667
};
664668

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+
665702
#ifdef CONFIG_PM_SLEEP
666703
/* Enable IRQ wake on suspend, to wake up from RTC. */
667704
static int sun6i_rtc_suspend(struct device *dev)
@@ -795,6 +832,11 @@ static int sun6i_rtc_probe(struct platform_device *pdev)
795832
if (ret)
796833
return ret;
797834

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+
798840
dev_info(&pdev->dev, "RTC enabled\n");
799841

800842
return 0;

0 commit comments

Comments
 (0)