Skip to contentSkip to conversation

rtc: ds2404: set range

PATCH Superseded Alexandre Belloni 1 participant 6 messages Apr 19, 2019 Real time clock (RTC)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
author maintainer
#1 lore raw

PATCH 2/6 rtc: ds2404: switch to rtc_time64_to_tm

In reply to Alexandre Belloni

Call the 64bit version of rtc_time_to_tm now that the range is enforced by the core.

---
 drivers/rtc/rtc-ds2404.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-ds2404.c +1 -1
index 7b36c09bed10..17606e0fd28a 100644
@@ -206,7 +206,7 @@ static int ds2404_read_time(struct device *dev, struct rtc_time *dt)
 	ds2404_read_memory(dev, 0x203, 4, (u8 *)&time);
 	time = le32_to_cpu(time);
 
-	rtc_time_to_tm(time, dt);
+	rtc_time64_to_tm(time, dt);
 	return 0;
 }
 
Signature · 1 line
2.20.1
author maintainer
#2 lore raw

PATCH 3/6 rtc: ds2404: use .set_time

In reply to Alexandre Belloni

Use .set_time instead of the deprecated .set_mmss.

---
 drivers/rtc/rtc-ds2404.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/rtc/rtc-ds2404.c +3 -3
index 17606e0fd28a..3b12ec9e4c9d 100644
@@ -210,16 +210,16 @@ static int ds2404_read_time(struct device *dev, struct rtc_time *dt)
 	return 0;
 }
 
-static int ds2404_set_mmss(struct device *dev, unsigned long secs)
+static int ds2404_set_time(struct device *dev, struct rtc_time *dt)
 {
-	u32 time = cpu_to_le32(secs);
+	u32 time = cpu_to_le32(rtc_tm_to_time64(dt));
 	ds2404_write_memory(dev, 0x203, 4, (u8 *)&time);
 	return 0;
 }
 
 static const struct rtc_class_ops ds2404_rtc_ops = {
 	.read_time	= ds2404_read_time,
-	.set_mmss	= ds2404_set_mmss,
+	.set_time	= ds2404_set_time,
 };
 
 static int rtc_probe(struct platform_device *pdev)
Signature · 1 line
2.20.1
author maintainer
#3 lore raw

PATCH 4/6 rtc: ds2404: convert to SPDX identifier

In reply to Alexandre Belloni

Use SPDX-License-Identifier instead of a verbose license text.

---
 drivers/rtc/rtc-ds2404.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/rtc/rtc-ds2404.c +2 -8
index 3b12ec9e4c9d..89402ac11cfa 100644
@@ -1,11 +1,5 @@
-/*
- * Copyright (C) 2012 Sven Schnelle <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- */
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2012 Sven Schnelle <[email protected]>
 
 #include <linux/platform_device.h>
 #include <linux/module.h>
Signature · 1 line
2.20.1

Alexandre Belloni

author maintainer
#0 lore raw

PATCH 1/6 rtc: ds2404: set range

The real-time clock is a 5-byte binary counter. It is incremented 256 times per second. The least significant byte is a count of fractional seconds. The upper four bytes are a count of seconds. The realtime clock can accumulate 136 years of seconds before rolling over.

---
 drivers/rtc/rtc-ds2404.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/rtc/rtc-ds2404.c +9 -5
index b886b6a5c178..7b36c09bed10 100644
@@ -234,6 +234,10 @@ static int rtc_probe(struct platform_device *pdev)
 
 	chip->ops = &ds2404_gpio_ops;
 
+	chip->rtc = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(chip->rtc))
+		return PTR_ERR(chip->rtc);
+
 	retval = chip->ops->map_io(chip, pdev, pdata);
 	if (retval)
 		goto err_chip;
@@ -244,12 +248,12 @@ static int rtc_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, chip);
 
-	chip->rtc = devm_rtc_device_register(&pdev->dev, "ds2404",
-					&ds2404_rtc_ops, THIS_MODULE);
-	if (IS_ERR(chip->rtc)) {
-		retval = PTR_ERR(chip->rtc);
+	chip->rtc->ops = &ds2404_rtc_ops;
+	chip->rtc->range_max = U32_MAX;
+
+	retval = rtc_register_device(chip->rtc);
+	if (retval)
 		goto err_io;
-	}
 
 	ds2404_enable_osc(&pdev->dev);
 	return 0;
Signature · 1 line
2.20.1
author maintainer
#5 lore raw

PATCH 6/6 rtc: ds2404: simplify .probe and remove .remove

Use devm_add_action_or_reset to simplify .probe and remove .remove

---
 drivers/rtc/rtc-ds2404.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)
drivers/rtc/rtc-ds2404.c +7 -18
index c6b73dcf9d62..1e9f429ada64 100644
@@ -72,7 +72,7 @@ static int ds2404_gpio_map(struct ds2404 *chip, struct platform_device *pdev,
 	return err;
 }
 
-static void ds2404_gpio_unmap(struct ds2404 *chip)
+static void ds2404_gpio_unmap(void *data)
 {
 	int i;
 
@@ -218,7 +218,11 @@ static int rtc_probe(struct platform_device *pdev)
 
 	retval = ds2404_gpio_map(chip, pdev, pdata);
 	if (retval)
-		goto err_chip;
+		return retval;
+
+	retval = devm_add_action_or_reset(&pdev->dev, ds2404_gpio_unmap, chip);
+	if (retval)
+		return retval;
 
 	dev_info(&pdev->dev, "using GPIOs RST:%d, CLK:%d, DQ:%d\n",
 		 chip->gpio[DS2404_RST].gpio, chip->gpio[DS2404_CLK].gpio,
@@ -231,29 +235,14 @@ static int rtc_probe(struct platform_device *pdev)
 
 	retval = rtc_register_device(chip->rtc);
 	if (retval)
-		goto err_io;
+		return retval;
 
 	ds2404_enable_osc(&pdev->dev);
 	return 0;
-
-err_io:
-	ds2404_gpio_unmap(chip);
-err_chip:
-	return retval;
-}
-
-static int rtc_remove(struct platform_device *dev)
-{
-	struct ds2404 *chip = platform_get_drvdata(dev);
-
-	ds2404_gpio_unmap(chip);
-
-	return 0;
 }
 
 static struct platform_driver rtc_device_driver = {
 	.probe	= rtc_probe,
-	.remove = rtc_remove,
 	.driver = {
 		.name	= "ds2404",
 	},
Signature · 1 line
2.20.1
author maintainer
#4 lore raw

PATCH 5/6 rtc: ds2404: remove ds2404_chip_ops

In reply to Alexandre Belloni

There is only one ds2404_chip_ops struct that is implemented, remove the unnecessary indirection.

---
 drivers/rtc/rtc-ds2404.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)
drivers/rtc/rtc-ds2404.c +3 -19
index 89402ac11cfa..c6b73dcf9d62 100644
@@ -23,14 +23,6 @@
 #define DS2404_COPY_SCRATCHPAD_CMD 0x55
 #define DS2404_READ_MEMORY_CMD 0xf0
 
-struct ds2404;
-
-struct ds2404_chip_ops {
-	int (*map_io)(struct ds2404 *chip, struct platform_device *pdev,
-		      struct ds2404_platform_data *pdata);
-	void (*unmap_io)(struct ds2404 *chip);
-};
-
 #define DS2404_RST	0
 #define DS2404_CLK	1
 #define DS2404_DQ	2
@@ -42,7 +34,6 @@ struct ds2404_gpio {
 
 struct ds2404 {
 	struct ds2404_gpio *gpio;
-	const struct ds2404_chip_ops *ops;
 	struct rtc_device *rtc;
 };
 
@@ -89,11 +80,6 @@ static void ds2404_gpio_unmap(struct ds2404 *chip)
 		gpio_free(ds2404_gpio[i].gpio);
 }
 
-static const struct ds2404_chip_ops ds2404_gpio_ops = {
-	.map_io		= ds2404_gpio_map,
-	.unmap_io	= ds2404_gpio_unmap,
-};
-
 static void ds2404_reset(struct device *dev)
 {
 	gpio_set_value(ds2404_gpio[DS2404_RST].gpio, 0);
@@ -226,13 +212,11 @@ static int rtc_probe(struct platform_device *pdev)
 	if (!chip)
 		return -ENOMEM;
 
-	chip->ops = &ds2404_gpio_ops;
-
 	chip->rtc = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(chip->rtc))
 		return PTR_ERR(chip->rtc);
 
-	retval = chip->ops->map_io(chip, pdev, pdata);
+	retval = ds2404_gpio_map(chip, pdev, pdata);
 	if (retval)
 		goto err_chip;
 
@@ -253,7 +237,7 @@ static int rtc_probe(struct platform_device *pdev)
 	return 0;
 
 err_io:
-	chip->ops->unmap_io(chip);
+	ds2404_gpio_unmap(chip);
 err_chip:
 	return retval;
 }
@@ -262,7 +246,7 @@ static int rtc_remove(struct platform_device *dev)
 {
 	struct ds2404 *chip = platform_get_drvdata(dev);
 
-	chip->ops->unmap_io(chip);
+	ds2404_gpio_unmap(chip);
 
 	return 0;
 }
Signature · 1 line
2.20.1