aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-ds3232.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-05-09 17:46:33 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-05-09 17:46:33 -0400
commit8e4ff713ce313dcabbb60e6ede1ffc193e67631f (patch)
tree8efdfe4925570ec8608d40e229ed01a5432d901e /drivers/rtc/rtc-ds3232.c
parent45182e4e1f8ac04708ca7508c51d9103f07d81ab (diff)
parentdacb6a4035a010e41abaf81c1cfe2beadfb05ec8 (diff)
Merge tag 'rtc-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni: "A huge series from me this cycle. I went through many drivers to set the date and time range supported by the RTC which helps solving HW limitation when the time comes (as early as next year for some). This time, I focused on drivers using .set_mms and .set_mmss64, allowing me to remove those callbacks. About a third of the patches got reviews, I actually own the RTCs and I tested another third and the remaining one are unlikely to cause any issues. Other than that, a single new driver and the usual fixes here and there. Summary: Subsystem: - set_mmss and set_mmss64 rtc_ops removal - Fix timestamp value for RTC_TIMESTAMP_BEGIN_1900 - Use SPDX identifier for the core - validate upper bound of tm->tm_year New driver: - Aspeed BMC SoC RTC Drivers: - abx80x: use rtc_add_group - ds3232: nvram support - pcf85063: add alarm, nvram, offset correction and microcrystal rv8263 support - x1205: add of_match_table - Use set_time instead of set_mms/set_mmss64 for: ab3100, coh901331, digicolor, ds1672, ds2404, ep93xx, imxdi, jz4740, lpc32xx, mc13xxx, mxc, pcap, stmp3xxx, test, wm831x, xgene. - Set RTC range for: ab3100, at91sam9, coh901331, da9063, digicolor, dm355evm, ds1672, ds2404, ep39xx, goldfish, imxdi, jz4740, lpc32xx, mc13xxx, mv, mxc, omap, pcap, pcf85063, pcf85363, ps3, sh, stmp3xxx, sun4v, tegra, wm831x, xgene. - Switch to rtc_time64_to_tm/rtc_tm_to_time64 for the driver that properly set the RTC range. - Use dev_get_drvdata instead of multiple indirections" * tag 'rtc-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (177 commits) rtc: snvs: Use __maybe_unused instead of #if CONFIG_PM_SLEEP rtc: imxdi: remove unused variable rtc: drop set_mms and set_mmss64 rtc: pcap: convert to SPDX identifier rtc: pcap: use .set_time rtc: pcap: switch to rtc_time64_to_tm/rtc_tm_to_time64 rtc: pcap: set range rtc: digicolor: convert to SPDX identifier rtc: digicolor: use .set_time rtc: digicolor: set range rtc: digicolor: fix possible race condition rtc: jz4740: convert to SPDX identifier rtc: jz4740: rework invalid time detection rtc: jz4740: use dev_pm_set_wake_irq() to simplify code rtc: jz4740: use .set_time rtc: jz4740: remove useless check rtc: jz4740: switch to rtc_time64_to_tm/rtc_tm_to_time64 rtc: jz4740: set range rtc: 88pm860x: prevent use-after-free on device remove rtc: Use dev_get_drvdata() ...
Diffstat (limited to 'drivers/rtc/rtc-ds3232.c')
-rw-r--r--drivers/rtc/rtc-ds3232.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
index 7184e5145f12..1e9312f96021 100644
--- a/drivers/rtc/rtc-ds3232.c
+++ b/drivers/rtc/rtc-ds3232.c
@@ -48,6 +48,10 @@
48# define DS3232_REG_SR_A1F 0x01 48# define DS3232_REG_SR_A1F 0x01
49 49
50#define DS3232_REG_TEMPERATURE 0x11 50#define DS3232_REG_TEMPERATURE 0x11
51#define DS3232_REG_SRAM_START 0x14
52#define DS3232_REG_SRAM_END 0xFF
53
54#define DS3232_REG_SRAM_SIZE 236
51 55
52struct ds3232 { 56struct ds3232 {
53 struct device *dev; 57 struct device *dev;
@@ -461,11 +465,39 @@ static const struct rtc_class_ops ds3232_rtc_ops = {
461 .alarm_irq_enable = ds3232_alarm_irq_enable, 465 .alarm_irq_enable = ds3232_alarm_irq_enable,
462}; 466};
463 467
468static int ds3232_nvmem_read(void *priv, unsigned int offset, void *val,
469 size_t bytes)
470{
471 struct regmap *ds3232_regmap = (struct regmap *)priv;
472
473 return regmap_bulk_read(ds3232_regmap, DS3232_REG_SRAM_START + offset,
474 val, bytes);
475}
476
477static int ds3232_nvmem_write(void *priv, unsigned int offset, void *val,
478 size_t bytes)
479{
480 struct regmap *ds3232_regmap = (struct regmap *)priv;
481
482 return regmap_bulk_write(ds3232_regmap, DS3232_REG_SRAM_START + offset,
483 val, bytes);
484}
485
464static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq, 486static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
465 const char *name) 487 const char *name)
466{ 488{
467 struct ds3232 *ds3232; 489 struct ds3232 *ds3232;
468 int ret; 490 int ret;
491 struct nvmem_config nvmem_cfg = {
492 .name = "ds3232_sram",
493 .stride = 1,
494 .size = DS3232_REG_SRAM_SIZE,
495 .word_size = 1,
496 .reg_read = ds3232_nvmem_read,
497 .reg_write = ds3232_nvmem_write,
498 .priv = regmap,
499 .type = NVMEM_TYPE_BATTERY_BACKED
500 };
469 501
470 ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL); 502 ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL);
471 if (!ds3232) 503 if (!ds3232)
@@ -490,6 +522,10 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
490 if (IS_ERR(ds3232->rtc)) 522 if (IS_ERR(ds3232->rtc))
491 return PTR_ERR(ds3232->rtc); 523 return PTR_ERR(ds3232->rtc);
492 524
525 ret = rtc_nvmem_register(ds3232->rtc, &nvmem_cfg);
526 if(ret)
527 return ret;
528
493 if (ds3232->irq > 0) { 529 if (ds3232->irq > 0) {
494 ret = devm_request_threaded_irq(dev, ds3232->irq, NULL, 530 ret = devm_request_threaded_irq(dev, ds3232->irq, NULL,
495 ds3232_irq, 531 ds3232_irq,
@@ -542,7 +578,7 @@ static int ds3232_i2c_probe(struct i2c_client *client,
542 static const struct regmap_config config = { 578 static const struct regmap_config config = {
543 .reg_bits = 8, 579 .reg_bits = 8,
544 .val_bits = 8, 580 .val_bits = 8,
545 .max_register = 0x13, 581 .max_register = DS3232_REG_SRAM_END,
546 }; 582 };
547 583
548 regmap = devm_regmap_init_i2c(client, &config); 584 regmap = devm_regmap_init_i2c(client, &config);
@@ -609,7 +645,7 @@ static int ds3234_probe(struct spi_device *spi)
609 static const struct regmap_config config = { 645 static const struct regmap_config config = {
610 .reg_bits = 8, 646 .reg_bits = 8,
611 .val_bits = 8, 647 .val_bits = 8,
612 .max_register = 0x13, 648 .max_register = DS3232_REG_SRAM_END,
613 .write_flag_mask = 0x80, 649 .write_flag_mask = 0x80,
614 }; 650 };
615 struct regmap *regmap; 651 struct regmap *regmap;