Skip to content

Commit 7130856

Browse files
3x380Valexandrebelloni
authored andcommitted
rtc: twl: add NVRAM support
Export SRAM using nvmem. Signed-off-by: Ladislav Michl <ladis@linux-mips.org> Reviewed-by: Tony Lindgren <tony@atomide.com> Link: https://lore.kernel.org/r/ZDf7qZTiml0ijD2g@lenoch Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 1e786b0 commit 7130856

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

drivers/rtc/rtc-twl.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,24 @@ static const struct rtc_class_ops twl_rtc_ops = {
487487
.alarm_irq_enable = twl_rtc_alarm_irq_enable,
488488
};
489489

490+
static int twl_nvram_read(void *priv, unsigned int offset, void *val,
491+
size_t bytes)
492+
{
493+
return twl_i2c_read((long)priv, val, offset, bytes);
494+
}
495+
496+
static int twl_nvram_write(void *priv, unsigned int offset, void *val,
497+
size_t bytes)
498+
{
499+
return twl_i2c_write((long)priv, val, offset, bytes);
500+
}
501+
490502
/*----------------------------------------------------------------------*/
491503

492504
static int twl_rtc_probe(struct platform_device *pdev)
493505
{
494506
struct twl_rtc *twl_rtc;
507+
struct nvmem_config nvmem_cfg;
495508
struct device_node *np = pdev->dev.of_node;
496509
int ret = -EINVAL;
497510
int irq = platform_get_irq(pdev, 0);
@@ -579,6 +592,30 @@ static int twl_rtc_probe(struct platform_device *pdev)
579592
return ret;
580593
}
581594

595+
memset(&nvmem_cfg, 0, sizeof(nvmem_cfg));
596+
nvmem_cfg.name = "twl-secured-";
597+
nvmem_cfg.type = NVMEM_TYPE_BATTERY_BACKED;
598+
nvmem_cfg.reg_read = twl_nvram_read,
599+
nvmem_cfg.reg_write = twl_nvram_write,
600+
nvmem_cfg.word_size = 1;
601+
nvmem_cfg.stride = 1;
602+
if (twl_class_is_4030()) {
603+
/* 20 bytes SECURED_REG area */
604+
nvmem_cfg.size = 20;
605+
nvmem_cfg.priv = (void *)TWL_MODULE_SECURED_REG;
606+
devm_rtc_nvmem_register(twl_rtc->rtc, &nvmem_cfg);
607+
/* 8 bytes BACKUP area */
608+
nvmem_cfg.name = "twl-backup-";
609+
nvmem_cfg.size = 8;
610+
nvmem_cfg.priv = (void *)TWL4030_MODULE_BACKUP;
611+
devm_rtc_nvmem_register(twl_rtc->rtc, &nvmem_cfg);
612+
} else {
613+
/* 8 bytes SECURED_REG area */
614+
nvmem_cfg.size = 8;
615+
nvmem_cfg.priv = (void *)TWL_MODULE_SECURED_REG;
616+
devm_rtc_nvmem_register(twl_rtc->rtc, &nvmem_cfg);
617+
}
618+
582619
return 0;
583620
}
584621

0 commit comments

Comments
 (0)