Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Lorenz Brun and committed by
Alexandre Belloni
8eeb611b 770a54ac

+32
+32
drivers/rtc/rtc-s35390a.c
··· 18 18 #define S35390A_CMD_TIME1 2 19 19 #define S35390A_CMD_TIME2 3 20 20 #define S35390A_CMD_INT2_REG1 5 21 + #define S35390A_CMD_FREE_REG 7 21 22 22 23 #define S35390A_BYTE_YEAR 0 23 24 #define S35390A_BYTE_MONTH 1 ··· 417 416 .ioctl = s35390a_rtc_ioctl, 418 417 }; 419 418 419 + static int s35390a_nvmem_read(void *priv, unsigned int offset, void *val, 420 + size_t bytes) 421 + { 422 + struct s35390a *s35390a = priv; 423 + 424 + /* The offset is ignored because the NVMEM region is only 1 byte */ 425 + return s35390a_get_reg(s35390a, S35390A_CMD_FREE_REG, val, bytes); 426 + } 427 + 428 + static int s35390a_nvmem_write(void *priv, unsigned int offset, void *val, 429 + size_t bytes) 430 + { 431 + struct s35390a *s35390a = priv; 432 + 433 + return s35390a_set_reg(s35390a, S35390A_CMD_FREE_REG, val, bytes); 434 + } 435 + 420 436 static int s35390a_probe(struct i2c_client *client) 421 437 { 422 438 int err, err_read; ··· 442 424 struct rtc_device *rtc; 443 425 u8 buf, status1; 444 426 struct device *dev = &client->dev; 427 + struct nvmem_config nvmem_cfg = { 428 + .name = "s35390a_nvram", 429 + .type = NVMEM_TYPE_BATTERY_BACKED, 430 + .word_size = 1, 431 + .stride = 1, 432 + .size = 1, 433 + .reg_read = s35390a_nvmem_read, 434 + .reg_write = s35390a_nvmem_write, 435 + }; 445 436 446 437 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 447 438 return -ENODEV; ··· 516 489 517 490 if (status1 & S35390A_FLAG_INT2) 518 491 rtc_update_irq(rtc, 1, RTC_AF); 492 + 493 + nvmem_cfg.priv = s35390a; 494 + err = devm_rtc_nvmem_register(rtc, &nvmem_cfg); 495 + if (err) 496 + return err; 519 497 520 498 return devm_rtc_register_device(rtc); 521 499 }