| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * RTC client/driver for the Maxim/Dallas DS3232/DS3234 Real-Time Clock |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2009-2011 Freescale Semiconductor. |
|---|
| 5 | 6 | * Author: Jack Lan <jack.lan@freescale.com> |
|---|
| 6 | 7 | * Copyright (C) 2008 MIMOMax Wireless Ltd. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 9 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 10 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 11 | | - * option) any later version. |
|---|
| 12 | 8 | */ |
|---|
| 13 | 9 | |
|---|
| 14 | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| .. | .. |
|---|
| 48 | 44 | # define DS3232_REG_SR_A1F 0x01 |
|---|
| 49 | 45 | |
|---|
| 50 | 46 | #define DS3232_REG_TEMPERATURE 0x11 |
|---|
| 47 | +#define DS3232_REG_SRAM_START 0x14 |
|---|
| 48 | +#define DS3232_REG_SRAM_END 0xFF |
|---|
| 49 | + |
|---|
| 50 | +#define DS3232_REG_SRAM_SIZE 236 |
|---|
| 51 | 51 | |
|---|
| 52 | 52 | struct ds3232 { |
|---|
| 53 | 53 | struct device *dev; |
|---|
| .. | .. |
|---|
| 461 | 461 | .alarm_irq_enable = ds3232_alarm_irq_enable, |
|---|
| 462 | 462 | }; |
|---|
| 463 | 463 | |
|---|
| 464 | +static int ds3232_nvmem_read(void *priv, unsigned int offset, void *val, |
|---|
| 465 | + size_t bytes) |
|---|
| 466 | +{ |
|---|
| 467 | + struct regmap *ds3232_regmap = (struct regmap *)priv; |
|---|
| 468 | + |
|---|
| 469 | + return regmap_bulk_read(ds3232_regmap, DS3232_REG_SRAM_START + offset, |
|---|
| 470 | + val, bytes); |
|---|
| 471 | +} |
|---|
| 472 | + |
|---|
| 473 | +static int ds3232_nvmem_write(void *priv, unsigned int offset, void *val, |
|---|
| 474 | + size_t bytes) |
|---|
| 475 | +{ |
|---|
| 476 | + struct regmap *ds3232_regmap = (struct regmap *)priv; |
|---|
| 477 | + |
|---|
| 478 | + return regmap_bulk_write(ds3232_regmap, DS3232_REG_SRAM_START + offset, |
|---|
| 479 | + val, bytes); |
|---|
| 480 | +} |
|---|
| 481 | + |
|---|
| 464 | 482 | static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq, |
|---|
| 465 | 483 | const char *name) |
|---|
| 466 | 484 | { |
|---|
| 467 | 485 | struct ds3232 *ds3232; |
|---|
| 468 | 486 | int ret; |
|---|
| 487 | + struct nvmem_config nvmem_cfg = { |
|---|
| 488 | + .name = "ds3232_sram", |
|---|
| 489 | + .stride = 1, |
|---|
| 490 | + .size = DS3232_REG_SRAM_SIZE, |
|---|
| 491 | + .word_size = 1, |
|---|
| 492 | + .reg_read = ds3232_nvmem_read, |
|---|
| 493 | + .reg_write = ds3232_nvmem_write, |
|---|
| 494 | + .priv = regmap, |
|---|
| 495 | + .type = NVMEM_TYPE_BATTERY_BACKED |
|---|
| 496 | + }; |
|---|
| 469 | 497 | |
|---|
| 470 | 498 | ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL); |
|---|
| 471 | 499 | if (!ds3232) |
|---|
| .. | .. |
|---|
| 489 | 517 | THIS_MODULE); |
|---|
| 490 | 518 | if (IS_ERR(ds3232->rtc)) |
|---|
| 491 | 519 | return PTR_ERR(ds3232->rtc); |
|---|
| 520 | + |
|---|
| 521 | + ret = rtc_nvmem_register(ds3232->rtc, &nvmem_cfg); |
|---|
| 522 | + if(ret) |
|---|
| 523 | + return ret; |
|---|
| 492 | 524 | |
|---|
| 493 | 525 | if (ds3232->irq > 0) { |
|---|
| 494 | 526 | ret = devm_request_threaded_irq(dev, ds3232->irq, NULL, |
|---|
| .. | .. |
|---|
| 542 | 574 | static const struct regmap_config config = { |
|---|
| 543 | 575 | .reg_bits = 8, |
|---|
| 544 | 576 | .val_bits = 8, |
|---|
| 545 | | - .max_register = 0x13, |
|---|
| 577 | + .max_register = DS3232_REG_SRAM_END, |
|---|
| 546 | 578 | }; |
|---|
| 547 | 579 | |
|---|
| 548 | 580 | regmap = devm_regmap_init_i2c(client, &config); |
|---|
| .. | .. |
|---|
| 609 | 641 | static const struct regmap_config config = { |
|---|
| 610 | 642 | .reg_bits = 8, |
|---|
| 611 | 643 | .val_bits = 8, |
|---|
| 612 | | - .max_register = 0x13, |
|---|
| 644 | + .max_register = DS3232_REG_SRAM_END, |
|---|
| 613 | 645 | .write_flag_mask = 0x80, |
|---|
| 614 | 646 | }; |
|---|
| 615 | 647 | struct regmap *regmap; |
|---|