Commit 7130856f authored by Ladislav Michl's avatar Ladislav Michl Committed by Alexandre Belloni

rtc: twl: add NVRAM support

Export SRAM using nvmem.
Signed-off-by: default avatarLadislav Michl <ladis@linux-mips.org>
Reviewed-by: default avatarTony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/ZDf7qZTiml0ijD2g@lenochSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 1e786b03
...@@ -487,11 +487,24 @@ static const struct rtc_class_ops twl_rtc_ops = { ...@@ -487,11 +487,24 @@ static const struct rtc_class_ops twl_rtc_ops = {
.alarm_irq_enable = twl_rtc_alarm_irq_enable, .alarm_irq_enable = twl_rtc_alarm_irq_enable,
}; };
static int twl_nvram_read(void *priv, unsigned int offset, void *val,
size_t bytes)
{
return twl_i2c_read((long)priv, val, offset, bytes);
}
static int twl_nvram_write(void *priv, unsigned int offset, void *val,
size_t bytes)
{
return twl_i2c_write((long)priv, val, offset, bytes);
}
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
static int twl_rtc_probe(struct platform_device *pdev) static int twl_rtc_probe(struct platform_device *pdev)
{ {
struct twl_rtc *twl_rtc; struct twl_rtc *twl_rtc;
struct nvmem_config nvmem_cfg;
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
int ret = -EINVAL; int ret = -EINVAL;
int irq = platform_get_irq(pdev, 0); int irq = platform_get_irq(pdev, 0);
...@@ -579,6 +592,30 @@ static int twl_rtc_probe(struct platform_device *pdev) ...@@ -579,6 +592,30 @@ static int twl_rtc_probe(struct platform_device *pdev)
return ret; return ret;
} }
memset(&nvmem_cfg, 0, sizeof(nvmem_cfg));
nvmem_cfg.name = "twl-secured-";
nvmem_cfg.type = NVMEM_TYPE_BATTERY_BACKED;
nvmem_cfg.reg_read = twl_nvram_read,
nvmem_cfg.reg_write = twl_nvram_write,
nvmem_cfg.word_size = 1;
nvmem_cfg.stride = 1;
if (twl_class_is_4030()) {
/* 20 bytes SECURED_REG area */
nvmem_cfg.size = 20;
nvmem_cfg.priv = (void *)TWL_MODULE_SECURED_REG;
devm_rtc_nvmem_register(twl_rtc->rtc, &nvmem_cfg);
/* 8 bytes BACKUP area */
nvmem_cfg.name = "twl-backup-";
nvmem_cfg.size = 8;
nvmem_cfg.priv = (void *)TWL4030_MODULE_BACKUP;
devm_rtc_nvmem_register(twl_rtc->rtc, &nvmem_cfg);
} else {
/* 8 bytes SECURED_REG area */
nvmem_cfg.size = 8;
nvmem_cfg.priv = (void *)TWL_MODULE_SECURED_REG;
devm_rtc_nvmem_register(twl_rtc->rtc, &nvmem_cfg);
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment