All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] rtc: ds2404: set range
@ 2019-04-19  8:24 Alexandre Belloni
  2019-04-19  8:24 ` [PATCH 2/6] rtc: ds2404: switch to rtc_time64_to_tm Alexandre Belloni
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Alexandre Belloni @ 2019-04-19  8:24 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

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.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-ds2404.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index b886b6a5c178..7b36c09bed10 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/6] rtc: ds2404: switch to rtc_time64_to_tm
  2019-04-19  8:24 [PATCH 1/6] rtc: ds2404: set range Alexandre Belloni
@ 2019-04-19  8:24 ` Alexandre Belloni
  2019-04-19  8:24 ` [PATCH 3/6] rtc: ds2404: use .set_time Alexandre Belloni
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2019-04-19  8:24 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

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

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-ds2404.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index 7b36c09bed10..17606e0fd28a 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -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;
 }
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/6] rtc: ds2404: use .set_time
  2019-04-19  8:24 [PATCH 1/6] rtc: ds2404: set range Alexandre Belloni
  2019-04-19  8:24 ` [PATCH 2/6] rtc: ds2404: switch to rtc_time64_to_tm Alexandre Belloni
@ 2019-04-19  8:24 ` Alexandre Belloni
  2019-04-19  8:24 ` [PATCH 4/6] rtc: ds2404: convert to SPDX identifier Alexandre Belloni
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2019-04-19  8:24 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Use .set_time instead of the deprecated .set_mmss.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-ds2404.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index 17606e0fd28a..3b12ec9e4c9d 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -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)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/6] rtc: ds2404: convert to SPDX identifier
  2019-04-19  8:24 [PATCH 1/6] rtc: ds2404: set range Alexandre Belloni
  2019-04-19  8:24 ` [PATCH 2/6] rtc: ds2404: switch to rtc_time64_to_tm Alexandre Belloni
  2019-04-19  8:24 ` [PATCH 3/6] rtc: ds2404: use .set_time Alexandre Belloni
@ 2019-04-19  8:24 ` Alexandre Belloni
  2019-04-19  8:25 ` [PATCH 5/6] rtc: ds2404: remove ds2404_chip_ops Alexandre Belloni
  2019-04-19  8:25 ` [PATCH 6/6] rtc: ds2404: simplify .probe and remove .remove Alexandre Belloni
  4 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2019-04-19  8:24 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

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

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-ds2404.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index 3b12ec9e4c9d..89402ac11cfa 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -1,11 +1,5 @@
-/*
- * Copyright (C) 2012 Sven Schnelle <svens@stackframe.org>
- *
- * 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 <svens@stackframe.org>
 
 #include <linux/platform_device.h>
 #include <linux/module.h>
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/6] rtc: ds2404: remove ds2404_chip_ops
  2019-04-19  8:24 [PATCH 1/6] rtc: ds2404: set range Alexandre Belloni
                   ` (2 preceding siblings ...)
  2019-04-19  8:24 ` [PATCH 4/6] rtc: ds2404: convert to SPDX identifier Alexandre Belloni
@ 2019-04-19  8:25 ` Alexandre Belloni
  2019-04-19  8:25 ` [PATCH 6/6] rtc: ds2404: simplify .probe and remove .remove Alexandre Belloni
  4 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2019-04-19  8:25 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

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

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-ds2404.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index 89402ac11cfa..c6b73dcf9d62 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -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;
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 6/6] rtc: ds2404: simplify .probe and remove .remove
  2019-04-19  8:24 [PATCH 1/6] rtc: ds2404: set range Alexandre Belloni
                   ` (3 preceding siblings ...)
  2019-04-19  8:25 ` [PATCH 5/6] rtc: ds2404: remove ds2404_chip_ops Alexandre Belloni
@ 2019-04-19  8:25 ` Alexandre Belloni
  4 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2019-04-19  8:25 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Use devm_add_action_or_reset to simplify .probe and remove .remove

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-ds2404.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index c6b73dcf9d62..1e9f429ada64 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -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",
 	},
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-04-19 20:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-19  8:24 [PATCH 1/6] rtc: ds2404: set range Alexandre Belloni
2019-04-19  8:24 ` [PATCH 2/6] rtc: ds2404: switch to rtc_time64_to_tm Alexandre Belloni
2019-04-19  8:24 ` [PATCH 3/6] rtc: ds2404: use .set_time Alexandre Belloni
2019-04-19  8:24 ` [PATCH 4/6] rtc: ds2404: convert to SPDX identifier Alexandre Belloni
2019-04-19  8:25 ` [PATCH 5/6] rtc: ds2404: remove ds2404_chip_ops Alexandre Belloni
2019-04-19  8:25 ` [PATCH 6/6] rtc: ds2404: simplify .probe and remove .remove Alexandre Belloni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.