Skip to content

Commit 8eeb611

Browse files
lorenzalexandrebelloni
authored andcommitted
rtc: s35390a: implement nvmem support
This RTC has one "free" register which can be used to store arbitrary data. Expose it as a nvmem resource in Linux. Signed-off-by: Lorenz Brun <lorenz@monogon.tech> Link: https://patch.msgid.link/20251223125728.346073-1-lorenz@monogon.tech Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 770a54a commit 8eeb611

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

drivers/rtc/rtc-s35390a.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define S35390A_CMD_TIME1 2
1919
#define S35390A_CMD_TIME2 3
2020
#define S35390A_CMD_INT2_REG1 5
21+
#define S35390A_CMD_FREE_REG 7
2122

2223
#define S35390A_BYTE_YEAR 0
2324
#define S35390A_BYTE_MONTH 1
@@ -416,6 +417,23 @@ static const struct rtc_class_ops s35390a_rtc_ops = {
416417
.ioctl = s35390a_rtc_ioctl,
417418
};
418419

420+
static int s35390a_nvmem_read(void *priv, unsigned int offset, void *val,
421+
size_t bytes)
422+
{
423+
struct s35390a *s35390a = priv;
424+
425+
/* The offset is ignored because the NVMEM region is only 1 byte */
426+
return s35390a_get_reg(s35390a, S35390A_CMD_FREE_REG, val, bytes);
427+
}
428+
429+
static int s35390a_nvmem_write(void *priv, unsigned int offset, void *val,
430+
size_t bytes)
431+
{
432+
struct s35390a *s35390a = priv;
433+
434+
return s35390a_set_reg(s35390a, S35390A_CMD_FREE_REG, val, bytes);
435+
}
436+
419437
static int s35390a_probe(struct i2c_client *client)
420438
{
421439
int err, err_read;
@@ -424,6 +442,15 @@ static int s35390a_probe(struct i2c_client *client)
424442
struct rtc_device *rtc;
425443
u8 buf, status1;
426444
struct device *dev = &client->dev;
445+
struct nvmem_config nvmem_cfg = {
446+
.name = "s35390a_nvram",
447+
.type = NVMEM_TYPE_BATTERY_BACKED,
448+
.word_size = 1,
449+
.stride = 1,
450+
.size = 1,
451+
.reg_read = s35390a_nvmem_read,
452+
.reg_write = s35390a_nvmem_write,
453+
};
427454

428455
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
429456
return -ENODEV;
@@ -490,6 +517,11 @@ static int s35390a_probe(struct i2c_client *client)
490517
if (status1 & S35390A_FLAG_INT2)
491518
rtc_update_irq(rtc, 1, RTC_AF);
492519

520+
nvmem_cfg.priv = s35390a;
521+
err = devm_rtc_nvmem_register(rtc, &nvmem_cfg);
522+
if (err)
523+
return err;
524+
493525
return devm_rtc_register_device(rtc);
494526
}
495527

0 commit comments

Comments
 (0)