Skip to content

Commit fadfd09

Browse files
rtc: pcf85063: add nvram support
The pcf85063 has one byte of nvram. Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 5b3a3ad commit fadfd09

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

drivers/rtc/rtc-pcf85063.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#define PCF85063_CTRL2_AF BIT(6)
3939
#define PCF85063_CTRL2_AIE BIT(7)
4040

41+
#define PCF85063_REG_RAM 0x03
42+
4143
#define PCF85063_REG_SC 0x04 /* datetime */
4244
#define PCF85063_REG_SC_OS 0x80
4345

@@ -236,6 +238,18 @@ static const struct rtc_class_ops pcf85063_rtc_ops_alarm = {
236238
.alarm_irq_enable = pcf85063_rtc_alarm_irq_enable,
237239
};
238240

241+
static int pcf85063_nvmem_read(void *priv, unsigned int offset,
242+
void *val, size_t bytes)
243+
{
244+
return regmap_read(priv, PCF85063_REG_RAM, val);
245+
}
246+
247+
static int pcf85063_nvmem_write(void *priv, unsigned int offset,
248+
void *val, size_t bytes)
249+
{
250+
return regmap_write(priv, PCF85063_REG_RAM, *(u8 *)val);
251+
}
252+
239253
static int pcf85063_load_capacitance(struct pcf85063 *pcf85063,
240254
const struct device_node *np,
241255
unsigned int force_cap)
@@ -298,6 +312,13 @@ static int pcf85063_probe(struct i2c_client *client)
298312
int err;
299313
const struct pcf85063_config *config = &pcf85063tp_config;
300314
const void *data = of_device_get_match_data(&client->dev);
315+
struct nvmem_config nvmem_cfg = {
316+
.name = "pcf85063_nvram",
317+
.reg_read = pcf85063_nvmem_read,
318+
.reg_write = pcf85063_nvmem_write,
319+
.type = NVMEM_TYPE_BATTERY_BACKED,
320+
.size = 1,
321+
};
301322

302323
dev_dbg(&client->dev, "%s\n", __func__);
303324

@@ -354,6 +375,9 @@ static int pcf85063_probe(struct i2c_client *client)
354375
}
355376
}
356377

378+
nvmem_cfg.priv = pcf85063->regmap;
379+
rtc_nvmem_register(pcf85063->rtc, &nvmem_cfg);
380+
357381
return rtc_register_device(pcf85063->rtc);
358382
}
359383

0 commit comments

Comments
 (0)