All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/45] RTC: nvmem improvements
@ 2018-02-12 22:47 Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 01/45] rtc: documentation: correct nvmem date and version Alexandre Belloni
                   ` (44 more replies)
  0 siblings, 45 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

This series makes some change to the RTC nvmem API to simplify drivers
and clean the way the nvmem_config is used.

The main issue was the different lifecycle of the struct nvmem_config
(only needed at probe time) and rtc_device (needed for the lifetime of
the driver).

Then, it converts the remaining drivers (except ds1685) to the API. A
few other improvements are also made along the way.

Alexandre Belloni (45):
  rtc: documentation: correct nvmem date and version
  rtc: nvmem: pass nvmem_config to rtc_nvmem_register()
  rtc: nvmem: return error values
  rtc: nvmem: disallow registering nvmem more than once
  rtc: export rtc_nvmem_register() to drivers
  rtc: ds1305: call rtc_nvmem_register()
  rtc: ds1305: put ds1305_nvmem_cfg on the stack
  rtc: ds1307: call rtc_nvmem_register()
  rtc: ds1307: put struct nvmem_config on the stack
  rtc: ds1511: call rtc_nvmem_register()
  rtc: ds1511: put ds1511_nvmem_cfg on the stack
  rtc: m48t86: call rtc_nvmem_register()
  rtc: m48t86: put m48t86_nvmem_cfg on the stack
  rtc: omap: call rtc_nvmem_register()
  rtc: pcf85363: call rtc_nvmem_register()
  rtc: pcf85363: put struct nvmem_config on the stack
  rtc: rv8803: call rtc_nvmem_register()
  rtc: rv8803: put struct nvmem_config on the stack
  rtc: rv8803: fix possible race condition
  rtc: remove nvmem_config
  rtc: ds1343: simplify regmap initialization
  rtc: ds1343: switch to rtc_register_device
  rtc: ds1343: remove undocumented and useless sysfs files
  rtc: ds1343: use generic nvmem
  rtc: m48t59: switch to rtc_register_device
  rtc: m48t59: use generic nvmem
  rtc: sirfsoc: remove useless sirfsoc_rtc_ioctl
  rtc: ds1553: switch to rtc_register_device
  rtc: ds1553: use generic nvmem
  rtc: ds1553: make alarms useful
  rtc: cmos: fix possible race condition
  rtc: cmos: use generic nvmem
  rtc: ds1742: switch to rtc_register_device
  rtc: ds1742: use generic nvmem
  rtc: rp5c01: fix possible race condition
  rtc: rp5c01: use generic nvmem
  rtc: stk17ta8: make alarms useful
  rtc: stk17ta8: switch to rtc_register_device
  rtc: stk17ta8: fix possible race condition
  rtc: stk17ta8: use generic nvmem
  rtc: tx4939: remove arch/mips dependency
  rtc: tx4939: extend test coverage
  rtc: tx4939: switch to rtc_register_device
  rtc: tx4939: fix possible race condition
  rtc: tx4939: use generic nvmem

 Documentation/ABI/testing/sysfs-class-rtc |   4 +-
 drivers/rtc/Kconfig                       |   2 +-
 drivers/rtc/class.c                       |   2 -
 drivers/rtc/nvmem.c                       |  29 +++--
 drivers/rtc/rtc-cmos.c                    |  75 ++++++------
 drivers/rtc/rtc-core.h                    |   8 --
 drivers/rtc/rtc-ds1305.c                  |  21 ++--
 drivers/rtc/rtc-ds1307.c                  |  29 ++---
 drivers/rtc/rtc-ds1343.c                  | 183 +++++-------------------------
 drivers/rtc/rtc-ds1511.c                  |  22 ++--
 drivers/rtc/rtc-ds1553.c                  |  74 +++++-------
 drivers/rtc/rtc-ds1742.c                  |  73 ++++++------
 drivers/rtc/rtc-m48t59.c                  |  57 +++++-----
 drivers/rtc/rtc-m48t86.c                  |  23 ++--
 drivers/rtc/rtc-omap.c                    |   3 +-
 drivers/rtc/rtc-pcf85363.c                |  25 ++--
 drivers/rtc/rtc-rp5c01.c                  |  63 +++++-----
 drivers/rtc/rtc-rv8803.c                  |  33 +++---
 drivers/rtc/rtc-sirfsoc.c                 |  18 ---
 drivers/rtc/rtc-stk17ta8.c                |  70 +++++-------
 drivers/rtc/rtc-tx4939.c                  |  87 +++++++++-----
 include/linux/rtc.h                       |  14 ++-
 22 files changed, 380 insertions(+), 535 deletions(-)

-- 
2.16.1

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

* [PATCH 01/45] rtc: documentation: correct nvmem date and version
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 02/45] rtc: nvmem: pass nvmem_config to rtc_nvmem_register() Alexandre Belloni
                   ` (43 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

The nvmem interface appaeared in linux 4.13

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 Documentation/ABI/testing/sysfs-class-rtc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-class-rtc b/Documentation/ABI/testing/sysfs-class-rtc
index cf60412882f0..65270d95873c 100644
--- a/Documentation/ABI/testing/sysfs-class-rtc
+++ b/Documentation/ABI/testing/sysfs-class-rtc
@@ -58,8 +58,8 @@ Description:
 		(RO) RTC-provided time in 24-hour notation (hh:mm:ss)
 
 What:		/sys/class/rtc/rtcX/*/nvmem
-Date:		February 2016
-KernelVersion:	4.6
+Date:		July 2017
+KernelVersion:	4.13
 Contact:	linux-rtc@vger.kernel.org
 Description:
 		(RW) The non volatile storage exported as a raw file, as
-- 
2.16.1

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

* [PATCH 02/45] rtc: nvmem: pass nvmem_config to rtc_nvmem_register()
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 01/45] rtc: documentation: correct nvmem date and version Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 03/45] rtc: nvmem: return error values Alexandre Belloni
                   ` (42 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

To be able to remove nvmem_config from struct rtc_device, pass it as a
parameter to rtc_nvmem_register.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/class.c    |  2 +-
 drivers/rtc/nvmem.c    | 17 +++++++++--------
 drivers/rtc/rtc-core.h |  6 ++++--
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 722d683e0b0f..47c4aeed5106 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -453,7 +453,7 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc)
 
 	rtc_proc_add_device(rtc);
 
-	rtc_nvmem_register(rtc);
+	rtc_nvmem_register(rtc, rtc->nvmem_config);
 
 	rtc->registered = true;
 	dev_info(rtc->dev.parent, "registered as %s\n",
diff --git a/drivers/rtc/nvmem.c b/drivers/rtc/nvmem.c
index 8567b4ed9ac6..0a3522bcdd25 100644
--- a/drivers/rtc/nvmem.c
+++ b/drivers/rtc/nvmem.c
@@ -46,7 +46,7 @@ rtc_nvram_write(struct file *filp, struct kobject *kobj,
 	return nvmem_device_write(rtc->nvmem, off, count, buf);
 }
 
-static int rtc_nvram_register(struct rtc_device *rtc)
+static int rtc_nvram_register(struct rtc_device *rtc, size_t size)
 {
 	int err;
 
@@ -64,7 +64,7 @@ static int rtc_nvram_register(struct rtc_device *rtc)
 
 	rtc->nvram->read = rtc_nvram_read;
 	rtc->nvram->write = rtc_nvram_write;
-	rtc->nvram->size = rtc->nvmem_config->size;
+	rtc->nvram->size = size;
 
 	err = sysfs_create_bin_file(&rtc->dev.parent->kobj,
 				    rtc->nvram);
@@ -84,20 +84,21 @@ static void rtc_nvram_unregister(struct rtc_device *rtc)
 /*
  * New ABI, uses nvmem
  */
-void rtc_nvmem_register(struct rtc_device *rtc)
+void rtc_nvmem_register(struct rtc_device *rtc,
+			struct nvmem_config *nvmem_config)
 {
-	if (!rtc->nvmem_config)
+	if (!nvmem_config)
 		return;
 
-	rtc->nvmem_config->dev = &rtc->dev;
-	rtc->nvmem_config->owner = rtc->owner;
-	rtc->nvmem = nvmem_register(rtc->nvmem_config);
+	nvmem_config->dev = &rtc->dev;
+	nvmem_config->owner = rtc->owner;
+	rtc->nvmem = nvmem_register(nvmem_config);
 	if (IS_ERR_OR_NULL(rtc->nvmem))
 		return;
 
 	/* Register the old ABI */
 	if (rtc->nvram_old_abi)
-		rtc_nvram_register(rtc);
+		rtc_nvram_register(rtc, nvmem_config->size);
 }
 
 void rtc_nvmem_unregister(struct rtc_device *rtc)
diff --git a/drivers/rtc/rtc-core.h b/drivers/rtc/rtc-core.h
index 513b9bedd2c8..5f60e3b11cde 100644
--- a/drivers/rtc/rtc-core.h
+++ b/drivers/rtc/rtc-core.h
@@ -48,9 +48,11 @@ static inline const struct attribute_group **rtc_get_dev_attribute_groups(void)
 #endif
 
 #ifdef CONFIG_RTC_NVMEM
-void rtc_nvmem_register(struct rtc_device *rtc);
+void rtc_nvmem_register(struct rtc_device *rtc,
+			struct nvmem_config *nvmem_config);
 void rtc_nvmem_unregister(struct rtc_device *rtc);
 #else
-static inline void rtc_nvmem_register(struct rtc_device *rtc) {}
+static inline void rtc_nvmem_register(struct rtc_device *rtc,
+				      struct nvmem_config *nvmem_config) {}
 static inline void rtc_nvmem_unregister(struct rtc_device *rtc) {}
 #endif
-- 
2.16.1

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

* [PATCH 03/45] rtc: nvmem: return error values
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 01/45] rtc: documentation: correct nvmem date and version Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 02/45] rtc: nvmem: pass nvmem_config to rtc_nvmem_register() Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 04/45] rtc: nvmem: disallow registering nvmem more than once Alexandre Belloni
                   ` (41 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

In case of error, make rtc_nvmem_register() able to return an error value
to its caller.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/nvmem.c    | 10 ++++++----
 drivers/rtc/rtc-core.h | 11 +++++++----
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/rtc/nvmem.c b/drivers/rtc/nvmem.c
index 0a3522bcdd25..293df6db7c42 100644
--- a/drivers/rtc/nvmem.c
+++ b/drivers/rtc/nvmem.c
@@ -84,21 +84,23 @@ static void rtc_nvram_unregister(struct rtc_device *rtc)
 /*
  * New ABI, uses nvmem
  */
-void rtc_nvmem_register(struct rtc_device *rtc,
-			struct nvmem_config *nvmem_config)
+int rtc_nvmem_register(struct rtc_device *rtc,
+		       struct nvmem_config *nvmem_config)
 {
 	if (!nvmem_config)
-		return;
+		return -ENODEV;
 
 	nvmem_config->dev = &rtc->dev;
 	nvmem_config->owner = rtc->owner;
 	rtc->nvmem = nvmem_register(nvmem_config);
 	if (IS_ERR_OR_NULL(rtc->nvmem))
-		return;
+		return PTR_ERR(rtc->nvmem);
 
 	/* Register the old ABI */
 	if (rtc->nvram_old_abi)
 		rtc_nvram_register(rtc, nvmem_config->size);
+
+	return 0;
 }
 
 void rtc_nvmem_unregister(struct rtc_device *rtc)
diff --git a/drivers/rtc/rtc-core.h b/drivers/rtc/rtc-core.h
index 5f60e3b11cde..05a67837fd76 100644
--- a/drivers/rtc/rtc-core.h
+++ b/drivers/rtc/rtc-core.h
@@ -48,11 +48,14 @@ static inline const struct attribute_group **rtc_get_dev_attribute_groups(void)
 #endif
 
 #ifdef CONFIG_RTC_NVMEM
-void rtc_nvmem_register(struct rtc_device *rtc,
-			struct nvmem_config *nvmem_config);
+int rtc_nvmem_register(struct rtc_device *rtc,
+		       struct nvmem_config *nvmem_config);
 void rtc_nvmem_unregister(struct rtc_device *rtc);
 #else
-static inline void rtc_nvmem_register(struct rtc_device *rtc,
-				      struct nvmem_config *nvmem_config) {}
+static inline int rtc_nvmem_register(struct rtc_device *rtc,
+				     struct nvmem_config *nvmem_config)
+{
+	return -ENODEV;
+}
 static inline void rtc_nvmem_unregister(struct rtc_device *rtc) {}
 #endif
-- 
2.16.1

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

* [PATCH 04/45] rtc: nvmem: disallow registering nvmem more than once
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (2 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 03/45] rtc: nvmem: return error values Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 05/45] rtc: export rtc_nvmem_register() to drivers Alexandre Belloni
                   ` (40 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Make rtc_nvmem_register return -EBUSY when an nvmem is already registered
for that RTC.

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

diff --git a/drivers/rtc/nvmem.c b/drivers/rtc/nvmem.c
index 293df6db7c42..fd1c39a5ade5 100644
--- a/drivers/rtc/nvmem.c
+++ b/drivers/rtc/nvmem.c
@@ -87,6 +87,9 @@ static void rtc_nvram_unregister(struct rtc_device *rtc)
 int rtc_nvmem_register(struct rtc_device *rtc,
 		       struct nvmem_config *nvmem_config)
 {
+	if (!IS_ERR_OR_NULL(rtc->nvmem))
+		return -EBUSY;
+
 	if (!nvmem_config)
 		return -ENODEV;
 
-- 
2.16.1

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

* [PATCH 05/45] rtc: export rtc_nvmem_register() to drivers
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (3 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 04/45] rtc: nvmem: disallow registering nvmem more than once Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 06/45] rtc: ds1305: call rtc_nvmem_register() Alexandre Belloni
                   ` (39 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Export rtc_nvmem_register() so it can be called from drivers instead of
only the core.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/nvmem.c    |  3 +--
 drivers/rtc/rtc-core.h | 13 -------------
 include/linux/rtc.h    | 13 +++++++++++++
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/rtc/nvmem.c b/drivers/rtc/nvmem.c
index fd1c39a5ade5..3a02357eb783 100644
--- a/drivers/rtc/nvmem.c
+++ b/drivers/rtc/nvmem.c
@@ -14,8 +14,6 @@
 #include <linux/rtc.h>
 #include <linux/sysfs.h>
 
-#include "rtc-core.h"
-
 /*
  * Deprecated ABI compatibility, this should be removed at some point
  */
@@ -105,6 +103,7 @@ int rtc_nvmem_register(struct rtc_device *rtc,
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(rtc_nvmem_register);
 
 void rtc_nvmem_unregister(struct rtc_device *rtc)
 {
diff --git a/drivers/rtc/rtc-core.h b/drivers/rtc/rtc-core.h
index 05a67837fd76..0abf98983e13 100644
--- a/drivers/rtc/rtc-core.h
+++ b/drivers/rtc/rtc-core.h
@@ -46,16 +46,3 @@ static inline const struct attribute_group **rtc_get_dev_attribute_groups(void)
 	return NULL;
 }
 #endif
-
-#ifdef CONFIG_RTC_NVMEM
-int rtc_nvmem_register(struct rtc_device *rtc,
-		       struct nvmem_config *nvmem_config);
-void rtc_nvmem_unregister(struct rtc_device *rtc);
-#else
-static inline int rtc_nvmem_register(struct rtc_device *rtc,
-				     struct nvmem_config *nvmem_config)
-{
-	return -ENODEV;
-}
-static inline void rtc_nvmem_unregister(struct rtc_device *rtc) {}
-#endif
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index fc6c90b57be0..fbc92fff7c2e 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -271,4 +271,17 @@ extern int rtc_hctosys_ret;
 #define rtc_hctosys_ret -ENODEV
 #endif
 
+#ifdef CONFIG_RTC_NVMEM
+int rtc_nvmem_register(struct rtc_device *rtc,
+		       struct nvmem_config *nvmem_config);
+void rtc_nvmem_unregister(struct rtc_device *rtc);
+#else
+static inline int rtc_nvmem_register(struct rtc_device *rtc,
+				     struct nvmem_config *nvmem_config)
+{
+	return -ENODEV;
+}
+static inline void rtc_nvmem_unregister(struct rtc_device *rtc) {}
+#endif
+
 #endif /* _LINUX_RTC_H_ */
-- 
2.16.1

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

* [PATCH 06/45] rtc: ds1305: call rtc_nvmem_register()
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (4 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 05/45] rtc: export rtc_nvmem_register() to drivers Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 07/45] rtc: ds1305: put ds1305_nvmem_cfg on the stack Alexandre Belloni
                   ` (38 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

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

diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index d8df2e9e14ad..affa90da26f1 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -703,15 +703,15 @@ static int ds1305_probe(struct spi_device *spi)
 	ds1305->rtc->ops = &ds1305_ops;
 
 	ds1305_nvmem_cfg.priv = ds1305;
-	ds1305->rtc->nvmem_config = &ds1305_nvmem_cfg;
 	ds1305->rtc->nvram_old_abi = true;
-
 	status = rtc_register_device(ds1305->rtc);
 	if (status) {
 		dev_dbg(&spi->dev, "register rtc --> %d\n", status);
 		return status;
 	}
 
+	rtc_nvmem_register(ds1305->rtc, &ds1305_nvmem_cfg);
+
 	/* Maybe set up alarm IRQ; be ready to handle it triggering right
 	 * away.  NOTE that we don't share this.  The signal is active low,
 	 * and we can't ack it before a SPI message delay.  We temporarily
-- 
2.16.1

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

* [PATCH 07/45] rtc: ds1305: put ds1305_nvmem_cfg on the stack
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (5 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 06/45] rtc: ds1305: call rtc_nvmem_register() Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 08/45] rtc: ds1307: call rtc_nvmem_register() Alexandre Belloni
                   ` (37 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

This makes to code safer on system using two similar RTCs.

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

diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index affa90da26f1..3d2400a39da9 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -544,15 +544,6 @@ static int ds1305_nvram_write(void *priv, unsigned int off, void *buf,
 	return spi_sync(spi, &m);
 }
 
-static struct nvmem_config ds1305_nvmem_cfg = {
-	.name = "ds1305_nvram",
-	.word_size = 1,
-	.stride = 1,
-	.size = DS1305_NVRAM_LEN,
-	.reg_read = ds1305_nvram_read,
-	.reg_write = ds1305_nvram_write,
-};
-
 /*----------------------------------------------------------------------*/
 
 /*
@@ -566,6 +557,14 @@ static int ds1305_probe(struct spi_device *spi)
 	u8				addr, value;
 	struct ds1305_platform_data	*pdata = dev_get_platdata(&spi->dev);
 	bool				write_ctrl = false;
+	struct nvmem_config ds1305_nvmem_cfg = {
+		.name = "ds1305_nvram",
+		.word_size = 1,
+		.stride = 1,
+		.size = DS1305_NVRAM_LEN,
+		.reg_read = ds1305_nvram_read,
+		.reg_write = ds1305_nvram_write,
+	};
 
 	/* Sanity check board setup data.  This may be hooked up
 	 * in 3wire mode, but we don't care.  Note that unless
-- 
2.16.1

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

* [PATCH 08/45] rtc: ds1307: call rtc_nvmem_register()
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (6 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 07/45] rtc: ds1305: put ds1305_nvmem_cfg on the stack Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 09/45] rtc: ds1307: put struct nvmem_config on the stack Alexandre Belloni
                   ` (36 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

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

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 923dde912f60..c146411a2099 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -1696,6 +1696,11 @@ static int ds1307_probe(struct i2c_client *client,
 		}
 	}
 
+	ds1307->rtc->ops = chip->rtc_ops ?: &ds13xx_rtc_ops;
+	err = rtc_register_device(ds1307->rtc);
+	if (err)
+		return err;
+
 	if (chip->nvram_size) {
 		ds1307->nvmem_cfg.name = "ds1307_nvram";
 		ds1307->nvmem_cfg.word_size = 1;
@@ -1705,15 +1710,10 @@ static int ds1307_probe(struct i2c_client *client,
 		ds1307->nvmem_cfg.reg_write = ds1307_nvram_write;
 		ds1307->nvmem_cfg.priv = ds1307;
 
-		ds1307->rtc->nvmem_config = &ds1307->nvmem_cfg;
 		ds1307->rtc->nvram_old_abi = true;
+		rtc_nvmem_register(ds1307->rtc, &ds1307->nvmem_cfg);
 	}
 
-	ds1307->rtc->ops = chip->rtc_ops ?: &ds13xx_rtc_ops;
-	err = rtc_register_device(ds1307->rtc);
-	if (err)
-		return err;
-
 	ds1307_hwmon_register(ds1307);
 	ds1307_clks_register(ds1307);
 
-- 
2.16.1

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

* [PATCH 09/45] rtc: ds1307: put struct nvmem_config on the stack
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (7 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 08/45] rtc: ds1307: call rtc_nvmem_register() Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 10/45] rtc: ds1511: call rtc_nvmem_register() Alexandre Belloni
                   ` (35 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Avoid allocating memory for struct nvmem_config as it is only necessary at
the nvmem registration.

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

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index c146411a2099..4021d478b9f3 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -114,7 +114,6 @@ enum ds_type {
 #	define RX8025_BIT_XST		0x20
 
 struct ds1307 {
-	struct nvmem_config	nvmem_cfg;
 	enum ds_type		type;
 	unsigned long		flags;
 #define HAS_NVRAM	0		/* bit 0 == sysfs file active */
@@ -1702,16 +1701,18 @@ static int ds1307_probe(struct i2c_client *client,
 		return err;
 
 	if (chip->nvram_size) {
-		ds1307->nvmem_cfg.name = "ds1307_nvram";
-		ds1307->nvmem_cfg.word_size = 1;
-		ds1307->nvmem_cfg.stride = 1;
-		ds1307->nvmem_cfg.size = chip->nvram_size;
-		ds1307->nvmem_cfg.reg_read = ds1307_nvram_read;
-		ds1307->nvmem_cfg.reg_write = ds1307_nvram_write;
-		ds1307->nvmem_cfg.priv = ds1307;
+		struct nvmem_config nvmem_cfg = {
+			.name = "ds1307_nvram",
+			.word_size = 1,
+			.stride = 1,
+			.size = chip->nvram_size,
+			.reg_read = ds1307_nvram_read,
+			.reg_write = ds1307_nvram_write,
+			.priv = ds1307,
+		};
 
 		ds1307->rtc->nvram_old_abi = true;
-		rtc_nvmem_register(ds1307->rtc, &ds1307->nvmem_cfg);
+		rtc_nvmem_register(ds1307->rtc, &nvmem_cfg);
 	}
 
 	ds1307_hwmon_register(ds1307);
-- 
2.16.1

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

* [PATCH 10/45] rtc: ds1511: call rtc_nvmem_register()
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (8 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 09/45] rtc: ds1307: put struct nvmem_config on the stack Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 11/45] rtc: ds1511: put ds1511_nvmem_cfg on the stack Alexandre Belloni
                   ` (34 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

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

diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 1e95312a6f2e..b1e51a4c2908 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -479,13 +479,14 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
 	pdata->rtc->ops = &ds1511_rtc_ops;
 
 	ds1511_nvmem_cfg.priv = &pdev->dev;
-	pdata->rtc->nvmem_config = &ds1511_nvmem_cfg;
 	pdata->rtc->nvram_old_abi = true;
 
 	ret = rtc_register_device(pdata->rtc);
 	if (ret)
 		return ret;
 
+	rtc_nvmem_register(pdata->rtc, &ds1511_nvmem_cfg);
+
 	/*
 	 * if the platform has an interrupt in mind for this device,
 	 * then by all means, set it
-- 
2.16.1

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

* [PATCH 11/45] rtc: ds1511: put ds1511_nvmem_cfg on the stack
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (9 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 10/45] rtc: ds1511: call rtc_nvmem_register() Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 12/45] rtc: m48t86: call rtc_nvmem_register() Alexandre Belloni
                   ` (33 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Move ds1511_nvmem_cfg to the stack of ds1511_rtc_probe. This results in a
very small code size reduction and make it safer on systems with two
similar RTCs:

   text	   data	    bss	    dec	    hex	filename
   2128	    164	      4	   2296	    8f8	drivers/rtc/rtc-ds1511.o.before
   2175	    100	      4	   2279	    8e7	drivers/rtc/rtc-ds1511.o.after

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

diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index b1e51a4c2908..5f55214db9f8 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -422,20 +422,20 @@ static int ds1511_nvram_write(void *priv, unsigned int pos, void *buf,
 	return 0;
 }
 
-static struct nvmem_config ds1511_nvmem_cfg = {
-	.name = "ds1511_nvram",
-	.word_size = 1,
-	.stride = 1,
-	.size = DS1511_RAM_MAX,
-	.reg_read = ds1511_nvram_read,
-	.reg_write = ds1511_nvram_write,
-};
-
 static int ds1511_rtc_probe(struct platform_device *pdev)
 {
 	struct resource *res;
 	struct rtc_plat_data *pdata;
 	int ret = 0;
+	struct nvmem_config ds1511_nvmem_cfg = {
+		.name = "ds1511_nvram",
+		.word_size = 1,
+		.stride = 1,
+		.size = DS1511_RAM_MAX,
+		.reg_read = ds1511_nvram_read,
+		.reg_write = ds1511_nvram_write,
+		.priv = &pdev->dev,
+	};
 
 	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
@@ -478,7 +478,6 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
 
 	pdata->rtc->ops = &ds1511_rtc_ops;
 
-	ds1511_nvmem_cfg.priv = &pdev->dev;
 	pdata->rtc->nvram_old_abi = true;
 
 	ret = rtc_register_device(pdata->rtc);
-- 
2.16.1

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

* [PATCH 12/45] rtc: m48t86: call rtc_nvmem_register()
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (10 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 11/45] rtc: ds1511: put ds1511_nvmem_cfg on the stack Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 13/45] rtc: m48t86: put m48t86_nvmem_cfg on the stack Alexandre Belloni
                   ` (32 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

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

diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index d9aea9b6d9cd..3a48a7eb3e9c 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -266,13 +266,14 @@ static int m48t86_rtc_probe(struct platform_device *pdev)
 	info->rtc->ops = &m48t86_rtc_ops;
 
 	m48t86_nvmem_cfg.priv = &pdev->dev;
-	info->rtc->nvmem_config = &m48t86_nvmem_cfg;
 	info->rtc->nvram_old_abi = true;
 
 	err = rtc_register_device(info->rtc);
 	if (err)
 		return err;
 
+	rtc_nvmem_register(info->rtc, &m48t86_nvmem_cfg);
+
 	/* read battery status */
 	reg = m48t86_readb(&pdev->dev, M48T86_D);
 	dev_info(&pdev->dev, "battery %s\n",
-- 
2.16.1

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

* [PATCH 13/45] rtc: m48t86: put m48t86_nvmem_cfg on the stack
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (11 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 12/45] rtc: m48t86: call rtc_nvmem_register() Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 14/45] rtc: omap: call rtc_nvmem_register() Alexandre Belloni
                   ` (31 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Move m48t86_nvmem_cfg to the stack of m48t86_rtc_probe. This results in a
very small code size reduction and make it safer on systems with two
similar RTCs:

   text	   data	    bss	    dec	    hex	filename
   1733	    164	      0	   1897	    769	drivers/rtc/rtc-m48t86.o.before
   1793	    100	      0	   1893	    765	drivers/rtc/rtc-m48t86.o.after

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

diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 3a48a7eb3e9c..8d17be1e6650 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -218,21 +218,21 @@ static bool m48t86_verify_chip(struct platform_device *pdev)
 	return false;
 }
 
-static struct nvmem_config m48t86_nvmem_cfg = {
-	.name = "m48t86_nvram",
-	.word_size = 1,
-	.stride = 1,
-	.size = M48T86_NVRAM_LEN,
-	.reg_read = m48t86_nvram_read,
-	.reg_write = m48t86_nvram_write,
-};
-
 static int m48t86_rtc_probe(struct platform_device *pdev)
 {
 	struct m48t86_rtc_info *info;
 	struct resource *res;
 	unsigned char reg;
 	int err;
+	struct nvmem_config m48t86_nvmem_cfg = {
+		.name = "m48t86_nvram",
+		.word_size = 1,
+		.stride = 1,
+		.size = M48T86_NVRAM_LEN,
+		.reg_read = m48t86_nvram_read,
+		.reg_write = m48t86_nvram_write,
+		.priv = &pdev->dev,
+	};
 
 	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
 	if (!info)
@@ -264,8 +264,6 @@ static int m48t86_rtc_probe(struct platform_device *pdev)
 		return PTR_ERR(info->rtc);
 
 	info->rtc->ops = &m48t86_rtc_ops;
-
-	m48t86_nvmem_cfg.priv = &pdev->dev;
 	info->rtc->nvram_old_abi = true;
 
 	err = rtc_register_device(info->rtc);
-- 
2.16.1

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

* [PATCH 14/45] rtc: omap: call rtc_nvmem_register()
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (12 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 13/45] rtc: m48t86: put m48t86_nvmem_cfg on the stack Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 15/45] rtc: pcf85363: " Alexandre Belloni
                   ` (30 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

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

diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 09ef802d6e54..e53cb27f4118 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -850,7 +850,6 @@ static int omap_rtc_probe(struct platform_device *pdev)
 
 	rtc->rtc->ops = &omap_rtc_ops;
 	omap_rtc_nvmem_config.priv = rtc;
-	rtc->rtc->nvmem_config = &omap_rtc_nvmem_config;
 
 	/* handle periodic and alarm irqs */
 	ret = devm_request_irq(&pdev->dev, rtc->irq_timer, rtc_irq, 0,
@@ -886,6 +885,8 @@ static int omap_rtc_probe(struct platform_device *pdev)
 	if (ret)
 		goto err;
 
+	rtc_nvmem_register(rtc->rtc, &omap_rtc_nvmem_config);
+
 	return 0;
 
 err:
-- 
2.16.1

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

* [PATCH 15/45] rtc: pcf85363: call rtc_nvmem_register()
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (13 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 14/45] rtc: omap: call rtc_nvmem_register() Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 16/45] rtc: pcf85363: put struct nvmem_config on the stack Alexandre Belloni
                   ` (29 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

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

diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
index ea04e9f0930b..a1fe833d2431 100644
--- a/drivers/rtc/rtc-pcf85363.c
+++ b/drivers/rtc/rtc-pcf85363.c
@@ -164,6 +164,7 @@ static int pcf85363_probe(struct i2c_client *client,
 			  const struct i2c_device_id *id)
 {
 	struct pcf85363 *pcf85363;
+	int ret;
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
 		return -ENODEV;
@@ -193,10 +194,13 @@ static int pcf85363_probe(struct i2c_client *client,
 	pcf85363->nvmem_cfg.reg_read = pcf85363_nvram_read;
 	pcf85363->nvmem_cfg.reg_write = pcf85363_nvram_write;
 	pcf85363->nvmem_cfg.priv = pcf85363;
-	pcf85363->rtc->nvmem_config = &pcf85363->nvmem_cfg;
 	pcf85363->rtc->ops = &rtc_ops;
 
-	return rtc_register_device(pcf85363->rtc);
+	ret = rtc_register_device(pcf85363->rtc);
+
+	rtc_nvmem_register(pcf85363->rtc, &pcf85363->nvmem_cfg);
+
+	return ret;
 }
 
 static const struct of_device_id dev_ids[] = {
-- 
2.16.1

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

* [PATCH 16/45] rtc: pcf85363: put struct nvmem_config on the stack
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (14 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 15/45] rtc: pcf85363: " Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 17/45] rtc: rv8803: call rtc_nvmem_register() Alexandre Belloni
                   ` (28 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Avoid allocating memory for struct nvmem_config.

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

diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
index a1fe833d2431..64573cccf7fe 100644
--- a/drivers/rtc/rtc-pcf85363.c
+++ b/drivers/rtc/rtc-pcf85363.c
@@ -80,7 +80,6 @@ static struct i2c_driver pcf85363_driver;
 struct pcf85363 {
 	struct device		*dev;
 	struct rtc_device	*rtc;
-	struct nvmem_config	nvmem_cfg;
 	struct regmap		*regmap;
 };
 
@@ -164,6 +163,14 @@ static int pcf85363_probe(struct i2c_client *client,
 			  const struct i2c_device_id *id)
 {
 	struct pcf85363 *pcf85363;
+	struct nvmem_config nvmem_cfg = {
+		.name = "pcf85363-",
+		.word_size = 1,
+		.stride = 1,
+		.size = NVRAM_SIZE,
+		.reg_read = pcf85363_nvram_read,
+		.reg_write = pcf85363_nvram_write,
+	};
 	int ret;
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
@@ -187,18 +194,12 @@ static int pcf85363_probe(struct i2c_client *client,
 	if (IS_ERR(pcf85363->rtc))
 		return PTR_ERR(pcf85363->rtc);
 
-	pcf85363->nvmem_cfg.name = "pcf85363-";
-	pcf85363->nvmem_cfg.word_size = 1;
-	pcf85363->nvmem_cfg.stride = 1;
-	pcf85363->nvmem_cfg.size = NVRAM_SIZE;
-	pcf85363->nvmem_cfg.reg_read = pcf85363_nvram_read;
-	pcf85363->nvmem_cfg.reg_write = pcf85363_nvram_write;
-	pcf85363->nvmem_cfg.priv = pcf85363;
 	pcf85363->rtc->ops = &rtc_ops;
 
 	ret = rtc_register_device(pcf85363->rtc);
 
-	rtc_nvmem_register(pcf85363->rtc, &pcf85363->nvmem_cfg);
+	nvmem_cfg.priv = pcf85363;
+	rtc_nvmem_register(pcf85363->rtc, &nvmem_cfg);
 
 	return ret;
 }
-- 
2.16.1

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

* [PATCH 17/45] rtc: rv8803: call rtc_nvmem_register()
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (15 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 16/45] rtc: pcf85363: put struct nvmem_config on the stack Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 18/45] rtc: rv8803: put struct nvmem_config on the stack Alexandre Belloni
                   ` (27 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

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

diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c
index aae2576741a6..c10132d8cf2e 100644
--- a/drivers/rtc/rtc-rv8803.c
+++ b/drivers/rtc/rtc-rv8803.c
@@ -591,12 +591,13 @@ static int rv8803_probe(struct i2c_client *client,
 	rv8803->nvmem_cfg.priv = client;
 
 	rv8803->rtc->ops = &rv8803_rtc_ops;
-	rv8803->rtc->nvmem_config = &rv8803->nvmem_cfg;
 	rv8803->rtc->nvram_old_abi = true;
 	err = rtc_register_device(rv8803->rtc);
 	if (err)
 		return err;
 
+	rtc_nvmem_register(rv8803->rtc, &rv8803->nvmem_cfg);
+
 	err = rv8803_write_reg(rv8803->client, RV8803_EXT, RV8803_EXT_WADA);
 	if (err)
 		return err;
-- 
2.16.1

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

* [PATCH 18/45] rtc: rv8803: put struct nvmem_config on the stack
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (16 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 17/45] rtc: rv8803: call rtc_nvmem_register() Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 19/45] rtc: rv8803: fix possible race condition Alexandre Belloni
                   ` (26 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Avoid allocating memory for struct nvmem_config.

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

diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c
index c10132d8cf2e..6fb5041f750b 100644
--- a/drivers/rtc/rtc-rv8803.c
+++ b/drivers/rtc/rtc-rv8803.c
@@ -68,7 +68,6 @@ struct rv8803_data {
 	struct mutex flags_lock;
 	u8 ctrl;
 	enum rv8803_type type;
-	struct nvmem_config nvmem_cfg;
 };
 
 static int rv8803_read_reg(const struct i2c_client *client, u8 reg)
@@ -528,6 +527,15 @@ static int rv8803_probe(struct i2c_client *client,
 	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
 	struct rv8803_data *rv8803;
 	int err, flags;
+	struct nvmem_config nvmem_cfg = {
+		.name = "rv8803_nvram",
+		.word_size = 1,
+		.stride = 1,
+		.size = 1,
+		.reg_read = rv8803_nvram_read,
+		.reg_write = rv8803_nvram_write,
+		.priv = client,
+	};
 
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
 				     I2C_FUNC_SMBUS_I2C_BLOCK)) {
@@ -582,21 +590,13 @@ static int rv8803_probe(struct i2c_client *client,
 		}
 	}
 
-	rv8803->nvmem_cfg.name = "rv8803_nvram",
-	rv8803->nvmem_cfg.word_size = 1,
-	rv8803->nvmem_cfg.stride = 1,
-	rv8803->nvmem_cfg.size = 1,
-	rv8803->nvmem_cfg.reg_read = rv8803_nvram_read,
-	rv8803->nvmem_cfg.reg_write = rv8803_nvram_write,
-	rv8803->nvmem_cfg.priv = client;
-
 	rv8803->rtc->ops = &rv8803_rtc_ops;
 	rv8803->rtc->nvram_old_abi = true;
 	err = rtc_register_device(rv8803->rtc);
 	if (err)
 		return err;
 
-	rtc_nvmem_register(rv8803->rtc, &rv8803->nvmem_cfg);
+	rtc_nvmem_register(rv8803->rtc, &nvmem_cfg);
 
 	err = rv8803_write_reg(rv8803->client, RV8803_EXT, RV8803_EXT_WADA);
 	if (err)
-- 
2.16.1

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

* [PATCH 19/45] rtc: rv8803: fix possible race condition
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (17 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 18/45] rtc: rv8803: put struct nvmem_config on the stack Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 20/45] rtc: remove nvmem_config Alexandre Belloni
                   ` (25 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

The probe function is not allowed to fail after registering the RTC. Call
rtc_register_device() at the end.

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

diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c
index 6fb5041f750b..29fc3d210392 100644
--- a/drivers/rtc/rtc-rv8803.c
+++ b/drivers/rtc/rtc-rv8803.c
@@ -590,14 +590,6 @@ static int rv8803_probe(struct i2c_client *client,
 		}
 	}
 
-	rv8803->rtc->ops = &rv8803_rtc_ops;
-	rv8803->rtc->nvram_old_abi = true;
-	err = rtc_register_device(rv8803->rtc);
-	if (err)
-		return err;
-
-	rtc_nvmem_register(rv8803->rtc, &nvmem_cfg);
-
 	err = rv8803_write_reg(rv8803->client, RV8803_EXT, RV8803_EXT_WADA);
 	if (err)
 		return err;
@@ -608,6 +600,14 @@ static int rv8803_probe(struct i2c_client *client,
 		return err;
 	}
 
+	rv8803->rtc->ops = &rv8803_rtc_ops;
+	rv8803->rtc->nvram_old_abi = true;
+	err = rtc_register_device(rv8803->rtc);
+	if (err)
+		return err;
+
+	rtc_nvmem_register(rv8803->rtc, &nvmem_cfg);
+
 	rv8803->rtc->max_user_freq = 1;
 
 	return 0;
-- 
2.16.1

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

* [PATCH 20/45] rtc: remove nvmem_config
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (18 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 19/45] rtc: rv8803: fix possible race condition Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 21/45] rtc: ds1343: simplify regmap initialization Alexandre Belloni
                   ` (24 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Because nvmem_config is only used and copied at nvmem registration, remove
it from struct rtc_device.

All the rtc drivers using nvmem are now calling rtc_nvmem_register
directly.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/class.c | 2 --
 include/linux/rtc.h | 1 -
 2 files changed, 3 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 47c4aeed5106..999ed039da0d 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -453,8 +453,6 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc)
 
 	rtc_proc_add_device(rtc);
 
-	rtc_nvmem_register(rtc, rtc->nvmem_config);
-
 	rtc->registered = true;
 	dev_info(rtc->dev.parent, "registered as %s\n",
 		 dev_name(&rtc->dev));
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index fbc92fff7c2e..37b041f72f8d 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -145,7 +145,6 @@ struct rtc_device {
 
 	bool registered;
 
-	struct nvmem_config *nvmem_config;
 	struct nvmem_device *nvmem;
 	/* Old ABI support */
 	bool nvram_old_abi;
-- 
2.16.1

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

* [PATCH 21/45] rtc: ds1343: simplify regmap initialization
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (19 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 20/45] rtc: remove nvmem_config Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 22/45] rtc: ds1343: switch to rtc_register_device Alexandre Belloni
                   ` (23 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Avoid using memset as gcc can properly initialize structures.

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

diff --git a/drivers/rtc/rtc-ds1343.c b/drivers/rtc/rtc-ds1343.c
index 895fbeeb47fe..b5102cdd7f61 100644
--- a/drivers/rtc/rtc-ds1343.c
+++ b/drivers/rtc/rtc-ds1343.c
@@ -599,15 +599,11 @@ static const struct rtc_class_ops ds1343_rtc_ops = {
 static int ds1343_probe(struct spi_device *spi)
 {
 	struct ds1343_priv *priv;
-	struct regmap_config config;
+	struct regmap_config config = { .reg_bits = 8, .val_bits = 8,
+					.write_flag_mask = 0x80, };
 	unsigned int data;
 	int res;
 
-	memset(&config, 0, sizeof(config));
-	config.reg_bits = 8;
-	config.val_bits = 8;
-	config.write_flag_mask = 0x80;
-
 	priv = devm_kzalloc(&spi->dev, sizeof(struct ds1343_priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
-- 
2.16.1

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

* [PATCH 22/45] rtc: ds1343: switch to rtc_register_device
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (20 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 21/45] rtc: ds1343: simplify regmap initialization Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 23/45] rtc: ds1343: remove undocumented and useless sysfs files Alexandre Belloni
                   ` (22 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

This allows for future improvement of the driver.

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

diff --git a/drivers/rtc/rtc-ds1343.c b/drivers/rtc/rtc-ds1343.c
index b5102cdd7f61..a5a5a363c6e1 100644
--- a/drivers/rtc/rtc-ds1343.c
+++ b/drivers/rtc/rtc-ds1343.c
@@ -642,12 +642,15 @@ static int ds1343_probe(struct spi_device *spi)
 	data &= ~(DS1343_OSF | DS1343_IRQF1 | DS1343_IRQF0);
 	regmap_write(priv->map, DS1343_STATUS_REG, data);
 
-	priv->rtc = devm_rtc_device_register(&spi->dev, "ds1343",
-					&ds1343_rtc_ops, THIS_MODULE);
-	if (IS_ERR(priv->rtc)) {
-		dev_err(&spi->dev, "unable to register rtc ds1343\n");
+	priv->rtc = devm_rtc_allocate_device(&spi->dev);
+	if (IS_ERR(priv->rtc))
 		return PTR_ERR(priv->rtc);
-	}
+
+	priv->rtc->ops = &ds1343_rtc_ops;
+
+	res = rtc_register_device(priv->rtc);
+	if (res)
+		return res;
 
 	priv->irq = spi->irq;
 
-- 
2.16.1

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

* [PATCH 23/45] rtc: ds1343: remove undocumented and useless sysfs files
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (21 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 22/45] rtc: ds1343: switch to rtc_register_device Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 24/45] rtc: ds1343: use generic nvmem Alexandre Belloni
                   ` (21 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

A documented ABI already exists to get information about the alarm. It is
the only one that is used.

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

diff --git a/drivers/rtc/rtc-ds1343.c b/drivers/rtc/rtc-ds1343.c
index a5a5a363c6e1..67cae0dd8154 100644
--- a/drivers/rtc/rtc-ds1343.c
+++ b/drivers/rtc/rtc-ds1343.c
@@ -199,74 +199,6 @@ static struct bin_attribute nvram_attr = {
 	.size		= DS1343_NVRAM_LEN,
 };
 
-static ssize_t ds1343_show_alarmstatus(struct device *dev,
-				struct device_attribute *attr, char *buf)
-{
-	struct ds1343_priv *priv = dev_get_drvdata(dev);
-	int alarmstatus, data;
-
-	regmap_read(priv->map, DS1343_CONTROL_REG, &data);
-
-	alarmstatus = !!(data & DS1343_A0IE);
-
-	if (alarmstatus)
-		return sprintf(buf, "enabled\n");
-	else
-		return sprintf(buf, "disabled\n");
-}
-
-static DEVICE_ATTR(alarm_status, S_IRUGO, ds1343_show_alarmstatus, NULL);
-
-static ssize_t ds1343_show_alarmmode(struct device *dev,
-				struct device_attribute *attr, char *buf)
-{
-	struct ds1343_priv *priv = dev_get_drvdata(dev);
-	int alarm_mode, data;
-	char *alarm_str;
-
-	regmap_read(priv->map, DS1343_ALM0_SEC_REG, &data);
-	alarm_mode = (data & 0x80) >> 4;
-
-	regmap_read(priv->map, DS1343_ALM0_MIN_REG, &data);
-	alarm_mode |= (data & 0x80) >> 5;
-
-	regmap_read(priv->map, DS1343_ALM0_HOUR_REG, &data);
-	alarm_mode |= (data & 0x80) >> 6;
-
-	regmap_read(priv->map, DS1343_ALM0_DAY_REG, &data);
-	alarm_mode |= (data & 0x80) >> 7;
-
-	switch (alarm_mode) {
-	case 15:
-		alarm_str = "each second";
-		break;
-
-	case 7:
-		alarm_str = "seconds match";
-		break;
-
-	case 3:
-		alarm_str = "minutes and seconds match";
-		break;
-
-	case 1:
-		alarm_str = "hours, minutes and seconds match";
-		break;
-
-	case 0:
-		alarm_str = "day, hours, minutes and seconds match";
-		break;
-
-	default:
-		alarm_str = "invalid";
-		break;
-	}
-
-	return sprintf(buf, "%s\n", alarm_str);
-}
-
-static DEVICE_ATTR(alarm_mode, S_IRUGO, ds1343_show_alarmmode, NULL);
-
 static ssize_t ds1343_show_tricklecharger(struct device *dev,
 				struct device_attribute *attr, char *buf)
 {
@@ -313,7 +245,6 @@ static DEVICE_ATTR(trickle_charger, S_IRUGO, ds1343_show_tricklecharger, NULL);
 
 static int ds1343_sysfs_register(struct device *dev)
 {
-	struct ds1343_priv *priv = dev_get_drvdata(dev);
 	int err;
 
 	err = device_create_file(dev, &dev_attr_glitch_filter);
@@ -325,26 +256,9 @@ static int ds1343_sysfs_register(struct device *dev)
 		goto error1;
 
 	err = device_create_bin_file(dev, &nvram_attr);
-	if (err)
-		goto error2;
-
-	if (priv->irq <= 0)
-		return err;
-
-	err = device_create_file(dev, &dev_attr_alarm_mode);
-	if (err)
-		goto error3;
-
-	err = device_create_file(dev, &dev_attr_alarm_status);
 	if (!err)
-		return err;
-
-	device_remove_file(dev, &dev_attr_alarm_mode);
-
-error3:
-	device_remove_bin_file(dev, &nvram_attr);
+		return 0;
 
-error2:
 	device_remove_file(dev, &dev_attr_trickle_charger);
 
 error1:
@@ -355,17 +269,9 @@ static int ds1343_sysfs_register(struct device *dev)
 
 static void ds1343_sysfs_unregister(struct device *dev)
 {
-	struct ds1343_priv *priv = dev_get_drvdata(dev);
-
 	device_remove_file(dev, &dev_attr_glitch_filter);
 	device_remove_file(dev, &dev_attr_trickle_charger);
 	device_remove_bin_file(dev, &nvram_attr);
-
-	if (priv->irq <= 0)
-		return;
-
-	device_remove_file(dev, &dev_attr_alarm_status);
-	device_remove_file(dev, &dev_attr_alarm_mode);
 }
 
 static int ds1343_read_time(struct device *dev, struct rtc_time *dt)
-- 
2.16.1

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

* [PATCH 24/45] rtc: ds1343: use generic nvmem
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (22 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 23/45] rtc: ds1343: remove undocumented and useless sysfs files Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 25/45] rtc: m48t59: switch to rtc_register_device Alexandre Belloni
                   ` (20 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.

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

diff --git a/drivers/rtc/rtc-ds1343.c b/drivers/rtc/rtc-ds1343.c
index 67cae0dd8154..59d27db2fd37 100644
--- a/drivers/rtc/rtc-ds1343.c
+++ b/drivers/rtc/rtc-ds1343.c
@@ -153,52 +153,22 @@ static ssize_t ds1343_store_glitchfilter(struct device *dev,
 static DEVICE_ATTR(glitch_filter, S_IRUGO | S_IWUSR, ds1343_show_glitchfilter,
 			ds1343_store_glitchfilter);
 
-static ssize_t ds1343_nvram_write(struct file *filp, struct kobject *kobj,
-			struct bin_attribute *attr,
-			char *buf, loff_t off, size_t count)
+static int ds1343_nvram_write(void *priv, unsigned int off, void *val,
+			      size_t bytes)
 {
-	int ret;
-	unsigned char address;
-	struct device *dev = kobj_to_dev(kobj);
-	struct ds1343_priv *priv = dev_get_drvdata(dev);
-
-	address = DS1343_NVRAM + off;
+	struct ds1343_priv *ds1343 = priv;
 
-	ret = regmap_bulk_write(priv->map, address, buf, count);
-	if (ret < 0)
-		dev_err(&priv->spi->dev, "Error in nvram write %d", ret);
-
-	return (ret < 0) ? ret : count;
+	return regmap_bulk_write(ds1343->map, DS1343_NVRAM + off, val, bytes);
 }
 
-
-static ssize_t ds1343_nvram_read(struct file *filp, struct kobject *kobj,
-				struct bin_attribute *attr,
-				char *buf, loff_t off, size_t count)
+static int ds1343_nvram_read(void *priv, unsigned int off, void *val,
+			     size_t bytes)
 {
-	int ret;
-	unsigned char address;
-	struct device *dev = kobj_to_dev(kobj);
-	struct ds1343_priv *priv = dev_get_drvdata(dev);
-
-	address = DS1343_NVRAM + off;
+	struct ds1343_priv *ds1343 = priv;
 
-	ret = regmap_bulk_read(priv->map, address, buf, count);
-	if (ret < 0)
-		dev_err(&priv->spi->dev, "Error in nvram read %d\n", ret);
-
-	return (ret < 0) ? ret : count;
+	return regmap_bulk_read(ds1343->map, DS1343_NVRAM + off, val, bytes);
 }
 
-
-static struct bin_attribute nvram_attr = {
-	.attr.name	= "nvram",
-	.attr.mode	= S_IRUGO | S_IWUSR,
-	.read		= ds1343_nvram_read,
-	.write		= ds1343_nvram_write,
-	.size		= DS1343_NVRAM_LEN,
-};
-
 static ssize_t ds1343_show_tricklecharger(struct device *dev,
 				struct device_attribute *attr, char *buf)
 {
@@ -252,16 +222,9 @@ static int ds1343_sysfs_register(struct device *dev)
 		return err;
 
 	err = device_create_file(dev, &dev_attr_trickle_charger);
-	if (err)
-		goto error1;
-
-	err = device_create_bin_file(dev, &nvram_attr);
 	if (!err)
 		return 0;
 
-	device_remove_file(dev, &dev_attr_trickle_charger);
-
-error1:
 	device_remove_file(dev, &dev_attr_glitch_filter);
 
 	return err;
@@ -271,7 +234,6 @@ static void ds1343_sysfs_unregister(struct device *dev)
 {
 	device_remove_file(dev, &dev_attr_glitch_filter);
 	device_remove_file(dev, &dev_attr_trickle_charger);
-	device_remove_bin_file(dev, &nvram_attr);
 }
 
 static int ds1343_read_time(struct device *dev, struct rtc_time *dt)
@@ -509,6 +471,14 @@ static int ds1343_probe(struct spi_device *spi)
 					.write_flag_mask = 0x80, };
 	unsigned int data;
 	int res;
+	struct nvmem_config nvmem_cfg = {
+		.name = "ds1343-",
+		.word_size = 1,
+		.stride = 1,
+		.size = DS1343_NVRAM_LEN,
+		.reg_read = ds1343_nvram_read,
+		.reg_write = ds1343_nvram_write,
+	};
 
 	priv = devm_kzalloc(&spi->dev, sizeof(struct ds1343_priv), GFP_KERNEL);
 	if (!priv)
@@ -552,12 +522,16 @@ static int ds1343_probe(struct spi_device *spi)
 	if (IS_ERR(priv->rtc))
 		return PTR_ERR(priv->rtc);
 
+	priv->rtc->nvram_old_abi = true;
 	priv->rtc->ops = &ds1343_rtc_ops;
 
 	res = rtc_register_device(priv->rtc);
 	if (res)
 		return res;
 
+	nvmem_cfg.priv = priv;
+	rtc_nvmem_register(priv->rtc, &nvmem_cfg);
+
 	priv->irq = spi->irq;
 
 	if (priv->irq >= 0) {
-- 
2.16.1

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

* [PATCH 25/45] rtc: m48t59: switch to rtc_register_device
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (23 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 24/45] rtc: ds1343: use generic nvmem Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 26/45] rtc: m48t59: use generic nvmem Alexandre Belloni
                   ` (19 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

This allows for future improvement of the driver.

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

diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index d99a705bec07..e248e56ff8a1 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -480,11 +480,16 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
 	spin_lock_init(&m48t59->lock);
 	platform_set_drvdata(pdev, m48t59);
 
-	m48t59->rtc = devm_rtc_device_register(&pdev->dev, name, ops,
-						THIS_MODULE);
+	m48t59->rtc = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(m48t59->rtc))
 		return PTR_ERR(m48t59->rtc);
 
+	m48t59->rtc->ops = ops;
+
+	ret = rtc_register_device(m48t59->rtc);
+	if (ret)
+		return ret;
+
 	m48t59_nvram_attr.size = pdata->offset;
 
 	ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
-- 
2.16.1

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

* [PATCH 26/45] rtc: m48t59: use generic nvmem
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (24 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 25/45] rtc: m48t59: switch to rtc_register_device Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 27/45] rtc: sirfsoc: remove useless sirfsoc_rtc_ioctl Alexandre Belloni
                   ` (18 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.

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

diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index e248e56ff8a1..399fc4255d54 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -334,16 +334,16 @@ static const struct rtc_class_ops m48t02_rtc_ops = {
 	.set_time	= m48t59_rtc_set_time,
 };
 
-static ssize_t m48t59_nvram_read(struct file *filp, struct kobject *kobj,
-				struct bin_attribute *bin_attr,
-				char *buf, loff_t pos, size_t size)
+static int m48t59_nvram_read(void *priv, unsigned int offset, void *val,
+			     size_t size)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct platform_device *pdev = to_platform_device(dev);
+	struct platform_device *pdev = priv;
+	struct device *dev = &pdev->dev;
 	struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
 	struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
 	ssize_t cnt = 0;
 	unsigned long flags;
+	u8 *buf = val;
 
 	spin_lock_irqsave(&m48t59->lock, flags);
 
@@ -352,19 +352,19 @@ static ssize_t m48t59_nvram_read(struct file *filp, struct kobject *kobj,
 
 	spin_unlock_irqrestore(&m48t59->lock, flags);
 
-	return cnt;
+	return 0;
 }
 
-static ssize_t m48t59_nvram_write(struct file *filp, struct kobject *kobj,
-				struct bin_attribute *bin_attr,
-				char *buf, loff_t pos, size_t size)
+static int m48t59_nvram_write(void *priv, unsigned int offset, void *val,
+			      size_t size)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct platform_device *pdev = to_platform_device(dev);
+	struct platform_device *pdev = priv;
+	struct device *dev = &pdev->dev;
 	struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
 	struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
 	ssize_t cnt = 0;
 	unsigned long flags;
+	u8 *buf = val;
 
 	spin_lock_irqsave(&m48t59->lock, flags);
 
@@ -373,18 +373,9 @@ static ssize_t m48t59_nvram_write(struct file *filp, struct kobject *kobj,
 
 	spin_unlock_irqrestore(&m48t59->lock, flags);
 
-	return cnt;
+	return 0;
 }
 
-static struct bin_attribute m48t59_nvram_attr = {
-	.attr = {
-		.name = "nvram",
-		.mode = S_IRUGO | S_IWUSR,
-	},
-	.read = m48t59_nvram_read,
-	.write = m48t59_nvram_write,
-};
-
 static int m48t59_rtc_probe(struct platform_device *pdev)
 {
 	struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev);
@@ -393,6 +384,15 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
 	int ret = -ENOMEM;
 	char *name;
 	const struct rtc_class_ops *ops;
+	struct nvmem_config nvmem_cfg = {
+		.name = "m48t59-",
+		.word_size = 1,
+		.stride = 1,
+		.size = pdata->offset,
+		.reg_read = m48t59_nvram_read,
+		.reg_write = m48t59_nvram_write,
+		.priv = pdev,
+	};
 
 	/* This chip could be memory-mapped or I/O-mapped */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -484,24 +484,15 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
 	if (IS_ERR(m48t59->rtc))
 		return PTR_ERR(m48t59->rtc);
 
+	m48t59->rtc->nvram_old_abi = true;
 	m48t59->rtc->ops = ops;
 
 	ret = rtc_register_device(m48t59->rtc);
 	if (ret)
 		return ret;
 
-	m48t59_nvram_attr.size = pdata->offset;
+	rtc_nvmem_register(m48t59->rtc, &nvmem_cfg);
 
-	ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
-	if (ret)
-		return ret;
-
-	return 0;
-}
-
-static int m48t59_rtc_remove(struct platform_device *pdev)
-{
-	sysfs_remove_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
 	return 0;
 }
 
@@ -513,7 +504,6 @@ static struct platform_driver m48t59_rtc_driver = {
 		.name	= "rtc-m48t59",
 	},
 	.probe		= m48t59_rtc_probe,
-	.remove		= m48t59_rtc_remove,
 };
 
 module_platform_driver(m48t59_rtc_driver);
-- 
2.16.1

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

* [PATCH 27/45] rtc: sirfsoc: remove useless sirfsoc_rtc_ioctl
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (25 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 26/45] rtc: m48t59: use generic nvmem Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 28/45] rtc: ds1553: switch to rtc_register_device Alexandre Belloni
                   ` (17 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

sirfsoc_rtc_ioctl() doesn't implement any actual ioctl, remove it.

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

diff --git a/drivers/rtc/rtc-sirfsoc.c b/drivers/rtc/rtc-sirfsoc.c
index 7367f617145c..2a9e151cae99 100644
--- a/drivers/rtc/rtc-sirfsoc.c
+++ b/drivers/rtc/rtc-sirfsoc.c
@@ -204,23 +204,6 @@ static int sirfsoc_rtc_set_time(struct device *dev,
 	return 0;
 }
 
-static int sirfsoc_rtc_ioctl(struct device *dev, unsigned int cmd,
-		unsigned long arg)
-{
-	switch (cmd) {
-	case RTC_PIE_ON:
-	case RTC_PIE_OFF:
-	case RTC_UIE_ON:
-	case RTC_UIE_OFF:
-	case RTC_AIE_ON:
-	case RTC_AIE_OFF:
-		return 0;
-
-	default:
-		return -ENOIOCTLCMD;
-	}
-}
-
 static int sirfsoc_rtc_alarm_irq_enable(struct device *dev,
 		unsigned int enabled)
 {
@@ -250,7 +233,6 @@ static const struct rtc_class_ops sirfsoc_rtc_ops = {
 	.set_time = sirfsoc_rtc_set_time,
 	.read_alarm = sirfsoc_rtc_read_alarm,
 	.set_alarm = sirfsoc_rtc_set_alarm,
-	.ioctl = sirfsoc_rtc_ioctl,
 	.alarm_irq_enable = sirfsoc_rtc_alarm_irq_enable
 };
 
-- 
2.16.1

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

* [PATCH 28/45] rtc: ds1553: switch to rtc_register_device
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (26 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 27/45] rtc: sirfsoc: remove useless sirfsoc_rtc_ioctl Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 29/45] rtc: ds1553: use generic nvmem Alexandre Belloni
                   ` (16 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

This allows for future improvement of the driver.

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

diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 9961ec646fd2..59eab5eceafa 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -308,11 +308,16 @@ static int ds1553_rtc_probe(struct platform_device *pdev)
 	pdata->last_jiffies = jiffies;
 	platform_set_drvdata(pdev, pdata);
 
-	pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
-				  &ds1553_rtc_ops, THIS_MODULE);
+	pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(pdata->rtc))
 		return PTR_ERR(pdata->rtc);
 
+	pdata->rtc->ops = &ds1553_rtc_ops;
+
+	ret = rtc_register_device(pdata->rtc);
+	if (ret)
+		return ret;
+
 	if (pdata->irq > 0) {
 		writeb(0, ioaddr + RTC_INTERRUPTS);
 		if (devm_request_irq(&pdev->dev, pdata->irq,
-- 
2.16.1

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

* [PATCH 29/45] rtc: ds1553: use generic nvmem
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (27 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 28/45] rtc: ds1553: switch to rtc_register_device Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 30/45] rtc: ds1553: make alarms useful Alexandre Belloni
                   ` (15 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.

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

diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 59eab5eceafa..6205c28e0cdc 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -233,46 +233,32 @@ static const struct rtc_class_ops ds1553_rtc_ops = {
 	.alarm_irq_enable	= ds1553_rtc_alarm_irq_enable,
 };
 
-static ssize_t ds1553_nvram_read(struct file *filp, struct kobject *kobj,
-				 struct bin_attribute *bin_attr,
-				 char *buf, loff_t pos, size_t size)
+static int ds1553_nvram_read(void *priv, unsigned int pos, void *val,
+			     size_t bytes)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct platform_device *pdev = to_platform_device(dev);
+	struct platform_device *pdev = priv;
 	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 	void __iomem *ioaddr = pdata->ioaddr;
-	ssize_t count;
+	u8 *buf = val;
 
-	for (count = 0; count < size; count++)
+	for (; bytes; bytes--)
 		*buf++ = readb(ioaddr + pos++);
-	return count;
+	return 0;
 }
 
-static ssize_t ds1553_nvram_write(struct file *filp, struct kobject *kobj,
-				  struct bin_attribute *bin_attr,
-				  char *buf, loff_t pos, size_t size)
+static int ds1553_nvram_write(void *priv, unsigned int pos, void *val,
+			      size_t bytes)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct platform_device *pdev = to_platform_device(dev);
+	struct platform_device *pdev = priv;
 	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 	void __iomem *ioaddr = pdata->ioaddr;
-	ssize_t count;
+	u8 *buf = val;
 
-	for (count = 0; count < size; count++)
+	for (; bytes; bytes--)
 		writeb(*buf++, ioaddr + pos++);
-	return count;
+	return 0;
 }
 
-static struct bin_attribute ds1553_nvram_attr = {
-	.attr = {
-		.name = "nvram",
-		.mode = S_IRUGO | S_IWUSR,
-	},
-	.size = RTC_OFFSET,
-	.read = ds1553_nvram_read,
-	.write = ds1553_nvram_write,
-};
-
 static int ds1553_rtc_probe(struct platform_device *pdev)
 {
 	struct resource *res;
@@ -280,6 +266,15 @@ static int ds1553_rtc_probe(struct platform_device *pdev)
 	struct rtc_plat_data *pdata;
 	void __iomem *ioaddr;
 	int ret = 0;
+	struct nvmem_config nvmem_cfg = {
+		.name = "ds1553_nvram",
+		.word_size = 1,
+		.stride = 1,
+		.size = RTC_OFFSET,
+		.reg_read = ds1553_nvram_read,
+		.reg_write = ds1553_nvram_write,
+		.priv = pdev,
+	};
 
 	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
@@ -313,6 +308,7 @@ static int ds1553_rtc_probe(struct platform_device *pdev)
 		return PTR_ERR(pdata->rtc);
 
 	pdata->rtc->ops = &ds1553_rtc_ops;
+	pdata->rtc->nvram_old_abi = true;
 
 	ret = rtc_register_device(pdata->rtc);
 	if (ret)
@@ -328,10 +324,8 @@ static int ds1553_rtc_probe(struct platform_device *pdev)
 		}
 	}
 
-	ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr);
-	if (ret)
-		dev_err(&pdev->dev, "unable to create sysfs file: %s\n",
-			ds1553_nvram_attr.attr.name);
+	if (rtc_nvmem_register(pdata->rtc, &nvmem_cfg))
+		dev_err(&pdev->dev, "unable to register nvmem\n");
 
 	return 0;
 }
@@ -340,7 +334,6 @@ static int ds1553_rtc_remove(struct platform_device *pdev)
 {
 	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 
-	sysfs_remove_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr);
 	if (pdata->irq > 0)
 		writeb(0, pdata->ioaddr + RTC_INTERRUPTS);
 	return 0;
-- 
2.16.1

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

* [PATCH 30/45] rtc: ds1553: make alarms useful
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (28 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 29/45] rtc: ds1553: use generic nvmem Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 31/45] rtc: cmos: fix possible race condition Alexandre Belloni
                   ` (14 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Currently, the IRQs are disabled when the rtc driver is removed (e.g. when
shutting down the platform).
This means that the RTC will be unable to wakeup the platform.

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

diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 6205c28e0cdc..7334c824371a 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -330,21 +330,11 @@ static int ds1553_rtc_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int ds1553_rtc_remove(struct platform_device *pdev)
-{
-	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
-
-	if (pdata->irq > 0)
-		writeb(0, pdata->ioaddr + RTC_INTERRUPTS);
-	return 0;
-}
-
 /* work with hotplug and coldplug */
 MODULE_ALIAS("platform:rtc-ds1553");
 
 static struct platform_driver ds1553_rtc_driver = {
 	.probe		= ds1553_rtc_probe,
-	.remove		= ds1553_rtc_remove,
 	.driver		= {
 		.name	= "rtc-ds1553",
 	},
-- 
2.16.1

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

* [PATCH 31/45] rtc: cmos: fix possible race condition
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (29 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 30/45] rtc: ds1553: make alarms useful Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 32/45] rtc: cmos: use generic nvmem Alexandre Belloni
                   ` (13 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

The probe function is not allowed to fail after registering the RTC because
the following may happen:

CPU0:                                CPU1:
sys_load_module()
 do_init_module()
  do_one_initcall()
   cmos_do_probe()
    rtc_device_register()
     __register_chrdev()
     cdev->owner = struct module*
                                     open("/dev/rtc0")
    rtc_device_unregister()
  module_put()
  free_module()
   module_free(mod->module_core)
   /* struct module *module is now
      freed */
                                      chrdev_open()
                                       spin_lock(cdev_lock)
                                       cdev_get()
                                        try_module_get()
                                         module_is_live()
                                         /* dereferences already
                                            freed struct module* */

Switch to devm_rtc_allocate_device/rtc_register_device to register the rtc
as late as possible.

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

diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 9dca53df3584..e6393e784d0c 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -751,8 +751,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
 	cmos_rtc.dev = dev;
 	dev_set_drvdata(dev, &cmos_rtc);
 
-	cmos_rtc.rtc = rtc_device_register(driver_name, dev,
-				&cmos_rtc_ops, THIS_MODULE);
+	cmos_rtc.rtc = devm_rtc_allocate_device(dev);
 	if (IS_ERR(cmos_rtc.rtc)) {
 		retval = PTR_ERR(cmos_rtc.rtc);
 		goto cleanup0;
@@ -822,6 +821,11 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
 		goto cleanup2;
 	}
 
+	cmos_rtc.rtc->ops = &cmos_rtc_ops;
+	retval = rtc_register_device(cmos_rtc.rtc);
+	if (retval)
+		goto cleanup3;
+
 	dev_info(dev, "%s%s, %zd bytes nvram%s\n",
 		!is_valid_irq(rtc_irq) ? "no alarms" :
 			cmos_rtc.mon_alrm ? "alarms up to one year" :
@@ -833,12 +837,13 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
 
 	return 0;
 
+cleanup3:
+	sysfs_remove_bin_file(&dev->kobj, &nvram);
 cleanup2:
 	if (is_valid_irq(rtc_irq))
 		free_irq(rtc_irq, cmos_rtc.rtc);
 cleanup1:
 	cmos_rtc.dev = NULL;
-	rtc_device_unregister(cmos_rtc.rtc);
 cleanup0:
 	if (RTC_IOMAPPED)
 		release_region(ports->start, resource_size(ports));
@@ -869,7 +874,6 @@ static void cmos_do_remove(struct device *dev)
 		hpet_unregister_irq_handler(cmos_interrupt);
 	}
 
-	rtc_device_unregister(cmos->rtc);
 	cmos->rtc = NULL;
 
 	ports = cmos->iomem;
-- 
2.16.1

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

* [PATCH 32/45] rtc: cmos: use generic nvmem
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (30 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 31/45] rtc: cmos: fix possible race condition Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 33/45] rtc: ds1742: switch to rtc_register_device Alexandre Belloni
                   ` (12 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Instead of adding a binary sysfs attribute from the driver, use the
core to register an nvmem device. This allows to use the in-kernel
interface to access the nvram.

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

diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index e6393e784d0c..b8ec6009171a 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -541,11 +541,10 @@ static const struct rtc_class_ops cmos_rtc_ops = {
 
 #define NVRAM_OFFSET	(RTC_REG_D + 1)
 
-static ssize_t
-cmos_nvram_read(struct file *filp, struct kobject *kobj,
-		struct bin_attribute *attr,
-		char *buf, loff_t off, size_t count)
+static int cmos_nvram_read(void *priv, unsigned int off, void *val,
+			   size_t count)
 {
+	unsigned char *buf = val;
 	int	retval;
 
 	off += NVRAM_OFFSET;
@@ -563,16 +562,13 @@ cmos_nvram_read(struct file *filp, struct kobject *kobj,
 	return retval;
 }
 
-static ssize_t
-cmos_nvram_write(struct file *filp, struct kobject *kobj,
-		struct bin_attribute *attr,
-		char *buf, loff_t off, size_t count)
+static int cmos_nvram_write(void *priv, unsigned int off, void *val,
+			    size_t count)
 {
-	struct cmos_rtc	*cmos;
+	struct cmos_rtc	*cmos = priv;
+	unsigned char	*buf = val;
 	int		retval;
 
-	cmos = dev_get_drvdata(container_of(kobj, struct device, kobj));
-
 	/* NOTE:  on at least PCs and Ataris, the boot firmware uses a
 	 * checksum on part of the NVRAM data.  That's currently ignored
 	 * here.  If userspace is smart enough to know what fields of
@@ -598,17 +594,6 @@ cmos_nvram_write(struct file *filp, struct kobject *kobj,
 	return retval;
 }
 
-static struct bin_attribute nvram = {
-	.attr = {
-		.name	= "nvram",
-		.mode	= S_IRUGO | S_IWUSR,
-	},
-
-	.read	= cmos_nvram_read,
-	.write	= cmos_nvram_write,
-	/* size gets set up later */
-};
-
 /*----------------------------------------------------------------*/
 
 static struct cmos_rtc	cmos_rtc;
@@ -675,6 +660,14 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
 	unsigned char			rtc_control;
 	unsigned			address_space;
 	u32				flags = 0;
+	struct nvmem_config nvmem_cfg = {
+		.name = "cmos_nvram",
+		.word_size = 1,
+		.stride = 1,
+		.reg_read = cmos_nvram_read,
+		.reg_write = cmos_nvram_write,
+		.priv = &cmos_rtc,
+	};
 
 	/* there can be only one ... */
 	if (cmos_rtc.dev)
@@ -813,32 +806,28 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
 		}
 	}
 
-	/* export at least the first block of NVRAM */
-	nvram.size = address_space - NVRAM_OFFSET;
-	retval = sysfs_create_bin_file(&dev->kobj, &nvram);
-	if (retval < 0) {
-		dev_dbg(dev, "can't create nvram file? %d\n", retval);
-		goto cleanup2;
-	}
-
 	cmos_rtc.rtc->ops = &cmos_rtc_ops;
+	cmos_rtc.rtc->nvram_old_abi = true;
 	retval = rtc_register_device(cmos_rtc.rtc);
 	if (retval)
-		goto cleanup3;
+		goto cleanup2;
 
-	dev_info(dev, "%s%s, %zd bytes nvram%s\n",
-		!is_valid_irq(rtc_irq) ? "no alarms" :
-			cmos_rtc.mon_alrm ? "alarms up to one year" :
-			cmos_rtc.day_alrm ? "alarms up to one month" :
-			"alarms up to one day",
-		cmos_rtc.century ? ", y3k" : "",
-		nvram.size,
-		is_hpet_enabled() ? ", hpet irqs" : "");
+	/* export at least the first block of NVRAM */
+	nvmem_cfg.size = address_space - NVRAM_OFFSET;
+	if (rtc_nvmem_register(cmos_rtc.rtc, &nvmem_cfg))
+		dev_err(dev, "nvmem registration failed\n");
+
+	dev_info(dev, "%s%s, %d bytes nvram%s\n",
+		 !is_valid_irq(rtc_irq) ? "no alarms" :
+		 cmos_rtc.mon_alrm ? "alarms up to one year" :
+		 cmos_rtc.day_alrm ? "alarms up to one month" :
+		 "alarms up to one day",
+		 cmos_rtc.century ? ", y3k" : "",
+		 nvmem_cfg.size,
+		 is_hpet_enabled() ? ", hpet irqs" : "");
 
 	return 0;
 
-cleanup3:
-	sysfs_remove_bin_file(&dev->kobj, &nvram);
 cleanup2:
 	if (is_valid_irq(rtc_irq))
 		free_irq(rtc_irq, cmos_rtc.rtc);
@@ -867,8 +856,6 @@ static void cmos_do_remove(struct device *dev)
 
 	cmos_do_shutdown(cmos->irq);
 
-	sysfs_remove_bin_file(&dev->kobj, &nvram);
-
 	if (is_valid_irq(cmos->irq)) {
 		free_irq(cmos->irq, cmos->rtc);
 		hpet_unregister_irq_handler(cmos_interrupt);
-- 
2.16.1

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

* [PATCH 33/45] rtc: ds1742: switch to rtc_register_device
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (31 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 32/45] rtc: cmos: use generic nvmem Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 34/45] rtc: ds1742: use generic nvmem Alexandre Belloni
                   ` (11 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

This allows for future improvement of the driver.

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

diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 3abf1cbfb8ce..84e19fe2ca3b 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -196,11 +196,17 @@ static int ds1742_rtc_probe(struct platform_device *pdev)
 
 	pdata->last_jiffies = jiffies;
 	platform_set_drvdata(pdev, pdata);
-	rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
-				  &ds1742_rtc_ops, THIS_MODULE);
+
+	rtc = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(rtc))
 		return PTR_ERR(rtc);
 
+	rtc->ops = &ds1742_rtc_ops;
+
+	ret = rtc_register_device(rtc);
+	if (ret)
+		return ret;
+
 	ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
 	if (ret)
 		dev_err(&pdev->dev, "Unable to create sysfs entry: %s\n",
-- 
2.16.1

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

* [PATCH 34/45] rtc: ds1742: use generic nvmem
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (32 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 33/45] rtc: ds1742: switch to rtc_register_device Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 35/45] rtc: rp5c01: fix possible race condition Alexandre Belloni
                   ` (10 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.

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

diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 84e19fe2ca3b..52baf925a690 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -53,9 +53,7 @@
 struct rtc_plat_data {
 	void __iomem *ioaddr_nvram;
 	void __iomem *ioaddr_rtc;
-	size_t size_nvram;
 	unsigned long last_jiffies;
-	struct bin_attribute nvram_attr;
 };
 
 static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -122,34 +120,28 @@ static const struct rtc_class_ops ds1742_rtc_ops = {
 	.set_time	= ds1742_rtc_set_time,
 };
 
-static ssize_t ds1742_nvram_read(struct file *filp, struct kobject *kobj,
-				 struct bin_attribute *bin_attr,
-				 char *buf, loff_t pos, size_t size)
+static int ds1742_nvram_read(void *priv, unsigned int pos, void *val,
+			     size_t bytes)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct platform_device *pdev = to_platform_device(dev);
-	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
+	struct rtc_plat_data *pdata = priv;
 	void __iomem *ioaddr = pdata->ioaddr_nvram;
-	ssize_t count;
+	u8 *buf = val;
 
-	for (count = 0; count < size; count++)
+	for (; bytes; bytes--)
 		*buf++ = readb(ioaddr + pos++);
-	return count;
+	return 0;
 }
 
-static ssize_t ds1742_nvram_write(struct file *filp, struct kobject *kobj,
-				  struct bin_attribute *bin_attr,
-				  char *buf, loff_t pos, size_t size)
+static int ds1742_nvram_write(void *priv, unsigned int pos, void *val,
+			      size_t bytes)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct platform_device *pdev = to_platform_device(dev);
-	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
+	struct rtc_plat_data *pdata = priv;
 	void __iomem *ioaddr = pdata->ioaddr_nvram;
-	ssize_t count;
+	u8 *buf = val;
 
-	for (count = 0; count < size; count++)
+	for (; bytes; bytes--)
 		writeb(*buf++, ioaddr + pos++);
-	return count;
+	return 0;
 }
 
 static int ds1742_rtc_probe(struct platform_device *pdev)
@@ -160,6 +152,14 @@ static int ds1742_rtc_probe(struct platform_device *pdev)
 	struct rtc_plat_data *pdata;
 	void __iomem *ioaddr;
 	int ret = 0;
+	struct nvmem_config nvmem_cfg = {
+		.name = "ds1742_nvram",
+		.word_size = 1,
+		.stride = 1,
+		.reg_read = ds1742_nvram_read,
+		.reg_write = ds1742_nvram_write,
+	};
+
 
 	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
@@ -171,15 +171,10 @@ static int ds1742_rtc_probe(struct platform_device *pdev)
 		return PTR_ERR(ioaddr);
 
 	pdata->ioaddr_nvram = ioaddr;
-	pdata->size_nvram = resource_size(res) - RTC_SIZE;
-	pdata->ioaddr_rtc = ioaddr + pdata->size_nvram;
+	pdata->ioaddr_rtc = ioaddr + resource_size(res) - RTC_SIZE;
 
-	sysfs_bin_attr_init(&pdata->nvram_attr);
-	pdata->nvram_attr.attr.name = "nvram";
-	pdata->nvram_attr.attr.mode = S_IRUGO | S_IWUSR;
-	pdata->nvram_attr.read = ds1742_nvram_read;
-	pdata->nvram_attr.write = ds1742_nvram_write;
-	pdata->nvram_attr.size = pdata->size_nvram;
+	nvmem_cfg.size = resource_size(res) - RTC_SIZE;
+	nvmem_cfg.priv = pdata;
 
 	/* turn RTC on if it was not on */
 	ioaddr = pdata->ioaddr_rtc;
@@ -202,24 +197,15 @@ static int ds1742_rtc_probe(struct platform_device *pdev)
 		return PTR_ERR(rtc);
 
 	rtc->ops = &ds1742_rtc_ops;
+	rtc->nvram_old_abi = true;
 
 	ret = rtc_register_device(rtc);
 	if (ret)
 		return ret;
 
-	ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
-	if (ret)
-		dev_err(&pdev->dev, "Unable to create sysfs entry: %s\n",
-			pdata->nvram_attr.attr.name);
-
-	return 0;
-}
-
-static int ds1742_rtc_remove(struct platform_device *pdev)
-{
-	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
+	if (rtc_nvmem_register(rtc, &nvmem_cfg))
+		dev_err(&pdev->dev, "Unable to register nvmem\n");
 
-	sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
 	return 0;
 }
 
@@ -231,7 +217,6 @@ MODULE_DEVICE_TABLE(of, ds1742_rtc_of_match);
 
 static struct platform_driver ds1742_rtc_driver = {
 	.probe		= ds1742_rtc_probe,
-	.remove		= ds1742_rtc_remove,
 	.driver		= {
 		.name	= "rtc-ds1742",
 		.of_match_table = of_match_ptr(ds1742_rtc_of_match),
-- 
2.16.1

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

* [PATCH 35/45] rtc: rp5c01: fix possible race condition
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (33 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 34/45] rtc: ds1742: use generic nvmem Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 36/45] rtc: rp5c01: use generic nvmem Alexandre Belloni
                   ` (9 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

The probe function is not allowed to fail after registering the RTC because
the following may happen:

CPU0:                                CPU1:
sys_load_module()
 do_init_module()
  do_one_initcall()
   cmos_do_probe()
    rtc_device_register()
     __register_chrdev()
     cdev->owner = struct module*
                                     open("/dev/rtc0")
    rtc_device_unregister()
  module_put()
  free_module()
   module_free(mod->module_core)
   /* struct module *module is now
      freed */
                                      chrdev_open()
                                       spin_lock(cdev_lock)
                                       cdev_get()
                                        try_module_get()
                                         module_is_live()
                                         /* dereferences already
                                            freed struct module* */

Switch to devm_rtc_allocate_device/rtc_register_device to register the rtc
as late as possible.

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

diff --git a/drivers/rtc/rtc-rp5c01.c b/drivers/rtc/rtc-rp5c01.c
index 026035373ae6..38a12435b5a0 100644
--- a/drivers/rtc/rtc-rp5c01.c
+++ b/drivers/rtc/rtc-rp5c01.c
@@ -249,16 +249,24 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
 
 	platform_set_drvdata(dev, priv);
 
-	rtc = devm_rtc_device_register(&dev->dev, "rtc-rp5c01", &rp5c01_rtc_ops,
-				  THIS_MODULE);
+	rtc = devm_rtc_allocate_device(&dev->dev);
 	if (IS_ERR(rtc))
 		return PTR_ERR(rtc);
+
+	rtc->ops = &rp5c01_rtc_ops;
+
 	priv->rtc = rtc;
 
 	error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr);
 	if (error)
 		return error;
 
+	error = rtc_register_device(rtc);
+	if (error) {
+		sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr);
+		return error;
+	}
+
 	return 0;
 }
 
-- 
2.16.1

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

* [PATCH 36/45] rtc: rp5c01: use generic nvmem
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (34 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 35/45] rtc: rp5c01: fix possible race condition Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 37/45] rtc: stk17ta8: make alarms useful Alexandre Belloni
                   ` (8 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Instead of adding a binary sysfs attribute from the driver, use the core to
register an nvmem device.

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

diff --git a/drivers/rtc/rtc-rp5c01.c b/drivers/rtc/rtc-rp5c01.c
index 38a12435b5a0..2c0605132ac0 100644
--- a/drivers/rtc/rtc-rp5c01.c
+++ b/drivers/rtc/rtc-rp5c01.c
@@ -64,7 +64,6 @@ struct rp5c01_priv {
 	u32 __iomem *regs;
 	struct rtc_device *rtc;
 	spinlock_t lock;	/* against concurrent RTC/NVRAM access */
-	struct bin_attribute nvram_attr;
 };
 
 static inline unsigned int rp5c01_read(struct rp5c01_priv *priv,
@@ -160,17 +159,15 @@ static const struct rtc_class_ops rp5c01_rtc_ops = {
  * byte is stored in BLOCK10, the low nibble in BLOCK11.
  */
 
-static ssize_t rp5c01_nvram_read(struct file *filp, struct kobject *kobj,
-				 struct bin_attribute *bin_attr,
-				 char *buf, loff_t pos, size_t size)
+static int rp5c01_nvram_read(void *_priv, unsigned int pos, void *val,
+			     size_t bytes)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct rp5c01_priv *priv = dev_get_drvdata(dev);
-	ssize_t count;
+	struct rp5c01_priv *priv = _priv;
+	u8 *buf = val;
 
 	spin_lock_irq(&priv->lock);
 
-	for (count = 0; count < size; count++) {
+	for (; bytes; bytes--) {
 		u8 data;
 
 		rp5c01_write(priv,
@@ -187,20 +184,18 @@ static ssize_t rp5c01_nvram_read(struct file *filp, struct kobject *kobj,
 	}
 
 	spin_unlock_irq(&priv->lock);
-	return count;
+	return 0;
 }
 
-static ssize_t rp5c01_nvram_write(struct file *filp, struct kobject *kobj,
-				  struct bin_attribute *bin_attr,
-				  char *buf, loff_t pos, size_t size)
+static int rp5c01_nvram_write(void *_priv, unsigned int pos, void *val,
+			      size_t bytes)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct rp5c01_priv *priv = dev_get_drvdata(dev);
-	ssize_t count;
+	struct rp5c01_priv *priv = _priv;
+	u8 *buf = val;
 
 	spin_lock_irq(&priv->lock);
 
-	for (count = 0; count < size; count++) {
+	for (; bytes; bytes--) {
 		u8 data = *buf++;
 
 		rp5c01_write(priv,
@@ -216,7 +211,7 @@ static ssize_t rp5c01_nvram_write(struct file *filp, struct kobject *kobj,
 	}
 
 	spin_unlock_irq(&priv->lock);
-	return count;
+	return 0;
 }
 
 static int __init rp5c01_rtc_probe(struct platform_device *dev)
@@ -225,6 +220,14 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
 	struct rp5c01_priv *priv;
 	struct rtc_device *rtc;
 	int error;
+	struct nvmem_config nvmem_cfg = {
+		.name = "rp5c01_nvram",
+		.word_size = 1,
+		.stride = 1,
+		.size = RP5C01_MODE,
+		.reg_read = rp5c01_nvram_read,
+		.reg_write = rp5c01_nvram_write,
+	};
 
 	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
 	if (!res)
@@ -238,13 +241,6 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
 	if (!priv->regs)
 		return -ENOMEM;
 
-	sysfs_bin_attr_init(&priv->nvram_attr);
-	priv->nvram_attr.attr.name = "nvram";
-	priv->nvram_attr.attr.mode = S_IRUGO | S_IWUSR;
-	priv->nvram_attr.read = rp5c01_nvram_read;
-	priv->nvram_attr.write = rp5c01_nvram_write;
-	priv->nvram_attr.size = RP5C01_MODE;
-
 	spin_lock_init(&priv->lock);
 
 	platform_set_drvdata(dev, priv);
@@ -254,27 +250,17 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
 		return PTR_ERR(rtc);
 
 	rtc->ops = &rp5c01_rtc_ops;
+	rtc->nvram_old_abi = true;
 
 	priv->rtc = rtc;
 
-	error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr);
-	if (error)
-		return error;
-
 	error = rtc_register_device(rtc);
-	if (error) {
-		sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr);
+	if (error)
 		return error;
-	}
 
-	return 0;
-}
-
-static int __exit rp5c01_rtc_remove(struct platform_device *dev)
-{
-	struct rp5c01_priv *priv = platform_get_drvdata(dev);
+	nvmem_cfg.priv = priv;
+	rtc_nvmem_register(rtc, &nvmem_cfg);
 
-	sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr);
 	return 0;
 }
 
@@ -282,7 +268,6 @@ static struct platform_driver rp5c01_rtc_driver = {
 	.driver	= {
 		.name	= "rtc-rp5c01",
 	},
-	.remove	= __exit_p(rp5c01_rtc_remove),
 };
 
 module_platform_driver_probe(rp5c01_rtc_driver, rp5c01_rtc_probe);
-- 
2.16.1

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

* [PATCH 37/45] rtc: stk17ta8: make alarms useful
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (35 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 36/45] rtc: rp5c01: use generic nvmem Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 38/45] rtc: stk17ta8: switch to rtc_register_device Alexandre Belloni
                   ` (7 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Currently, the IRQs are disabled when the rtc driver is removed (e.g. when
shutting down the platform).
This means that the RTC will be unable to wakeup the platform.

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

diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index a456cb6177ea..39a80491e567 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -340,11 +340,8 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev)
 
 static int stk17ta8_rtc_remove(struct platform_device *pdev)
 {
-	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
-
 	sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
-	if (pdata->irq > 0)
-		writeb(0, pdata->ioaddr + RTC_INTERRUPTS);
+
 	return 0;
 }
 
-- 
2.16.1

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

* [PATCH 38/45] rtc: stk17ta8: switch to rtc_register_device
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (36 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 37/45] rtc: stk17ta8: make alarms useful Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 39/45] rtc: stk17ta8: fix possible race condition Alexandre Belloni
                   ` (6 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

This allows for future improvement of the driver.

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

diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index 39a80491e567..f936accf622f 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -328,11 +328,16 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev)
 		}
 	}
 
-	pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
-				  &stk17ta8_rtc_ops, THIS_MODULE);
+	pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(pdata->rtc))
 		return PTR_ERR(pdata->rtc);
 
+	pdata->rtc->ops = &stk17ta8_rtc_ops;
+
+	ret = rtc_register_device(pdata->rtc);
+	if (ret)
+		return ret;
+
 	ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
 
 	return ret;
-- 
2.16.1

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

* [PATCH 39/45] rtc: stk17ta8: fix possible race condition
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (37 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 38/45] rtc: stk17ta8: switch to rtc_register_device Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 40/45] rtc: stk17ta8: use generic nvmem Alexandre Belloni
                   ` (5 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

The probe function is not allowed to fail after registering the RTC. Call
rtc_register_device() at the end.

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

diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index f936accf622f..1d6febbe7d39 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -334,11 +334,11 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev)
 
 	pdata->rtc->ops = &stk17ta8_rtc_ops;
 
-	ret = rtc_register_device(pdata->rtc);
+	ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
 	if (ret)
 		return ret;
 
-	ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
+	ret = rtc_register_device(pdata->rtc);
 
 	return ret;
 }
-- 
2.16.1

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

* [PATCH 40/45] rtc: stk17ta8: use generic nvmem
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (38 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 39/45] rtc: stk17ta8: fix possible race condition Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 41/45] rtc: tx4939: remove arch/mips dependency Alexandre Belloni
                   ` (4 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Instead of adding a binary sysfs attribute from the driver, use the core to
register an nvmem device.

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

diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index 1d6febbe7d39..b670e44306a8 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -242,46 +242,30 @@ static const struct rtc_class_ops stk17ta8_rtc_ops = {
 	.alarm_irq_enable	= stk17ta8_rtc_alarm_irq_enable,
 };
 
-static ssize_t stk17ta8_nvram_read(struct file *filp, struct kobject *kobj,
-				 struct bin_attribute *attr, char *buf,
-				 loff_t pos, size_t size)
+static int stk17ta8_nvram_read(void *priv, unsigned int pos, void *val,
+			       size_t bytes)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct platform_device *pdev = to_platform_device(dev);
-	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
+	struct rtc_plat_data *pdata = priv;
 	void __iomem *ioaddr = pdata->ioaddr;
-	ssize_t count;
+	u8 *buf = val;
 
-	for (count = 0; count < size; count++)
+	for (; bytes; bytes--)
 		*buf++ = readb(ioaddr + pos++);
-	return count;
+	return 0;
 }
 
-static ssize_t stk17ta8_nvram_write(struct file *filp, struct kobject *kobj,
-				  struct bin_attribute *attr, char *buf,
-				  loff_t pos, size_t size)
+static int stk17ta8_nvram_write(void *priv, unsigned int pos, void *val,
+				size_t bytes)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct platform_device *pdev = to_platform_device(dev);
-	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
+	struct rtc_plat_data *pdata = priv;
 	void __iomem *ioaddr = pdata->ioaddr;
-	ssize_t count;
+	u8 *buf = val;
 
-	for (count = 0; count < size; count++)
+	for (; bytes; bytes--)
 		writeb(*buf++, ioaddr + pos++);
-	return count;
+	return 0;
 }
 
-static struct bin_attribute stk17ta8_nvram_attr = {
-	.attr = {
-		.name = "nvram",
-		.mode = S_IRUGO | S_IWUSR,
-	},
-	.size = RTC_OFFSET,
-	.read = stk17ta8_nvram_read,
-	.write = stk17ta8_nvram_write,
-};
-
 static int stk17ta8_rtc_probe(struct platform_device *pdev)
 {
 	struct resource *res;
@@ -290,6 +274,14 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev)
 	struct rtc_plat_data *pdata;
 	void __iomem *ioaddr;
 	int ret = 0;
+	struct nvmem_config nvmem_cfg = {
+		.name = "stk17ta8_nvram",
+		.word_size = 1,
+		.stride = 1,
+		.size = RTC_OFFSET,
+		.reg_read = stk17ta8_nvram_read,
+		.reg_write = stk17ta8_nvram_write,
+	};
 
 	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
@@ -333,29 +325,23 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev)
 		return PTR_ERR(pdata->rtc);
 
 	pdata->rtc->ops = &stk17ta8_rtc_ops;
+	pdata->rtc->nvram_old_abi = true;
 
-	ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
+	ret = rtc_register_device(pdata->rtc);
 	if (ret)
 		return ret;
 
-	ret = rtc_register_device(pdata->rtc);
+	nvmem_cfg.priv = pdata;
+	rtc_nvmem_register(pdata->rtc, &nvmem_cfg);
 
 	return ret;
 }
 
-static int stk17ta8_rtc_remove(struct platform_device *pdev)
-{
-	sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
-
-	return 0;
-}
-
 /* work with hotplug and coldplug */
 MODULE_ALIAS("platform:stk17ta8");
 
 static struct platform_driver stk17ta8_rtc_driver = {
 	.probe		= stk17ta8_rtc_probe,
-	.remove		= stk17ta8_rtc_remove,
 	.driver		= {
 		.name	= "stk17ta8",
 	},
-- 
2.16.1

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

* [PATCH 41/45] rtc: tx4939: remove arch/mips dependency
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (39 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 40/45] rtc: stk17ta8: use generic nvmem Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 42/45] rtc: tx4939: extend test coverage Alexandre Belloni
                   ` (3 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Copy RTC definitions from arch/mips/include/asm/txx9/tx4939.h to the RTC
driver so it doesn't depend on arch/mips anymore.

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

diff --git a/drivers/rtc/rtc-tx4939.c b/drivers/rtc/rtc-tx4939.c
index 560d9a5e0225..1f4013d8ae7b 100644
--- a/drivers/rtc/rtc-tx4939.c
+++ b/drivers/rtc/rtc-tx4939.c
@@ -14,7 +14,30 @@
 #include <linux/module.h>
 #include <linux/io.h>
 #include <linux/gfp.h>
-#include <asm/txx9/tx4939.h>
+
+#define TX4939_RTCCTL_ALME	0x00000080
+#define TX4939_RTCCTL_ALMD	0x00000040
+#define TX4939_RTCCTL_BUSY	0x00000020
+
+#define TX4939_RTCCTL_COMMAND	0x00000007
+#define TX4939_RTCCTL_COMMAND_NOP	0x00000000
+#define TX4939_RTCCTL_COMMAND_GETTIME	0x00000001
+#define TX4939_RTCCTL_COMMAND_SETTIME	0x00000002
+#define TX4939_RTCCTL_COMMAND_GETALARM	0x00000003
+#define TX4939_RTCCTL_COMMAND_SETALARM	0x00000004
+
+#define TX4939_RTCTBC_PM	0x00000080
+#define TX4939_RTCTBC_COMP	0x0000007f
+
+#define TX4939_RTC_REG_RAMSIZE	0x00000100
+#define TX4939_RTC_REG_RWBSIZE	0x00000006
+
+struct tx4939_rtc_reg {
+	__u32 ctl;
+	__u32 adr;
+	__u32 dat;
+	__u32 tbc;
+};
 
 struct tx4939rtc_plat_data {
 	struct rtc_device *rtc;
-- 
2.16.1

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

* [PATCH 42/45] rtc: tx4939: extend test coverage
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (40 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 41/45] rtc: tx4939: remove arch/mips dependency Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 43/45] rtc: tx4939: switch to rtc_register_device Alexandre Belloni
                   ` (2 subsequent siblings)
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

The rtc-tx4939 driver now compiles correctly on other architectures, add
COMPILE_TEST to improve code coverage.

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

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 8ab5f0a5d323..f6d7e490e714 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1512,7 +1512,7 @@ config RTC_DRV_STARFIRE
 
 config RTC_DRV_TX4939
 	tristate "TX4939 SoC"
-	depends on SOC_TX4939
+	depends on SOC_TX4939 || COMPILE_TEST
 	help
 	  Driver for the internal RTC (Realtime Clock) module found on
 	  Toshiba TX4939 SoC.
-- 
2.16.1

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

* [PATCH 43/45] rtc: tx4939: switch to rtc_register_device
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (41 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 42/45] rtc: tx4939: extend test coverage Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 44/45] rtc: tx4939: fix possible race condition Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 45/45] rtc: tx4939: use generic nvmem Alexandre Belloni
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

This allows for future improvement of the driver.

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

diff --git a/drivers/rtc/rtc-tx4939.c b/drivers/rtc/rtc-tx4939.c
index 1f4013d8ae7b..75c3887fbc6c 100644
--- a/drivers/rtc/rtc-tx4939.c
+++ b/drivers/rtc/rtc-tx4939.c
@@ -283,10 +283,16 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
 	if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt,
 			     0, pdev->name, &pdev->dev) < 0)
 		return -EBUSY;
-	rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
-				  &tx4939_rtc_ops, THIS_MODULE);
+	rtc = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(rtc))
 		return PTR_ERR(rtc);
+
+	rtc->ops = &tx4939_rtc_ops;
+
+	ret = rtc_register_device(rtc);
+	if (ret)
+		return ret;
+
 	pdata->rtc = rtc;
 	ret = sysfs_create_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
 
-- 
2.16.1

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

* [PATCH 44/45] rtc: tx4939: fix possible race condition
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (42 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 43/45] rtc: tx4939: switch to rtc_register_device Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  2018-02-12 22:47 ` [PATCH 45/45] rtc: tx4939: use generic nvmem Alexandre Belloni
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

The probe function is not allowed to fail after registering the RTC. Call
rtc_register_device() at the end.

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

diff --git a/drivers/rtc/rtc-tx4939.c b/drivers/rtc/rtc-tx4939.c
index 75c3887fbc6c..5a3a6b457b8f 100644
--- a/drivers/rtc/rtc-tx4939.c
+++ b/drivers/rtc/rtc-tx4939.c
@@ -289,12 +289,13 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
 
 	rtc->ops = &tx4939_rtc_ops;
 
-	ret = rtc_register_device(rtc);
+	ret = sysfs_create_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
 	if (ret)
 		return ret;
 
 	pdata->rtc = rtc;
-	ret = sysfs_create_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
+
+	ret = rtc_register_device(rtc);
 
 	return ret;
 }
-- 
2.16.1

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

* [PATCH 45/45] rtc: tx4939: use generic nvmem
  2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
                   ` (43 preceding siblings ...)
  2018-02-12 22:47 ` [PATCH 44/45] rtc: tx4939: fix possible race condition Alexandre Belloni
@ 2018-02-12 22:47 ` Alexandre Belloni
  44 siblings, 0 replies; 46+ messages in thread
From: Alexandre Belloni @ 2018-02-12 22:47 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

Instead of adding a binary sysfs attribute from the driver, use the core to
register an nvmem device.

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

diff --git a/drivers/rtc/rtc-tx4939.c b/drivers/rtc/rtc-tx4939.c
index 5a3a6b457b8f..feededce3ded 100644
--- a/drivers/rtc/rtc-tx4939.c
+++ b/drivers/rtc/rtc-tx4939.c
@@ -212,58 +212,52 @@ static const struct rtc_class_ops tx4939_rtc_ops = {
 	.alarm_irq_enable	= tx4939_rtc_alarm_irq_enable,
 };
 
-static ssize_t tx4939_rtc_nvram_read(struct file *filp, struct kobject *kobj,
-				     struct bin_attribute *bin_attr,
-				     char *buf, loff_t pos, size_t size)
+static int tx4939_nvram_read(void *priv, unsigned int pos, void *val,
+			     size_t bytes)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev);
+	struct tx4939rtc_plat_data *pdata = priv;
 	struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
-	ssize_t count;
+	u8 *buf = val;
 
 	spin_lock_irq(&pdata->lock);
-	for (count = 0; count < size; count++) {
+	for (; bytes; bytes--) {
 		__raw_writel(pos++, &rtcreg->adr);
 		*buf++ = __raw_readl(&rtcreg->dat);
 	}
 	spin_unlock_irq(&pdata->lock);
-	return count;
+	return 0;
 }
 
-static ssize_t tx4939_rtc_nvram_write(struct file *filp, struct kobject *kobj,
-				      struct bin_attribute *bin_attr,
-				      char *buf, loff_t pos, size_t size)
+static int tx4939_nvram_write(void *priv, unsigned int pos, void *val,
+			      size_t bytes)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev);
+	struct tx4939rtc_plat_data *pdata = priv;
 	struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
-	ssize_t count;
+	u8 *buf = val;
 
 	spin_lock_irq(&pdata->lock);
-	for (count = 0; count < size; count++) {
+	for (; bytes; bytes--) {
 		__raw_writel(pos++, &rtcreg->adr);
 		__raw_writel(*buf++, &rtcreg->dat);
 	}
 	spin_unlock_irq(&pdata->lock);
-	return count;
+	return 0;
 }
 
-static struct bin_attribute tx4939_rtc_nvram_attr = {
-	.attr = {
-		.name = "nvram",
-		.mode = S_IRUGO | S_IWUSR,
-	},
-	.size = TX4939_RTC_REG_RAMSIZE,
-	.read = tx4939_rtc_nvram_read,
-	.write = tx4939_rtc_nvram_write,
-};
-
 static int __init tx4939_rtc_probe(struct platform_device *pdev)
 {
 	struct rtc_device *rtc;
 	struct tx4939rtc_plat_data *pdata;
 	struct resource *res;
 	int irq, ret;
+	struct nvmem_config nvmem_cfg = {
+		.name = "rv8803_nvram",
+		.word_size = 4,
+		.stride = 4,
+		.size = TX4939_RTC_REG_RAMSIZE,
+		.reg_read = tx4939_nvram_read,
+		.reg_write = tx4939_nvram_write,
+	};
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
@@ -288,14 +282,16 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
 		return PTR_ERR(rtc);
 
 	rtc->ops = &tx4939_rtc_ops;
-
-	ret = sysfs_create_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
-	if (ret)
-		return ret;
+	rtc->nvram_old_abi = true;
 
 	pdata->rtc = rtc;
 
 	ret = rtc_register_device(rtc);
+	if (ret)
+		return ret;
+
+	nvmem_cfg.priv = pdata;
+	ret = rtc_nvmem_register(rtc, &nvmem_cfg);
 
 	return ret;
 }
@@ -304,7 +300,6 @@ static int __exit tx4939_rtc_remove(struct platform_device *pdev)
 {
 	struct tx4939rtc_plat_data *pdata = platform_get_drvdata(pdev);
 
-	sysfs_remove_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
 	spin_lock_irq(&pdata->lock);
 	tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);
 	spin_unlock_irq(&pdata->lock);
-- 
2.16.1

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

end of thread, other threads:[~2018-02-12 22:59 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
2018-02-12 22:47 ` [PATCH 01/45] rtc: documentation: correct nvmem date and version Alexandre Belloni
2018-02-12 22:47 ` [PATCH 02/45] rtc: nvmem: pass nvmem_config to rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 03/45] rtc: nvmem: return error values Alexandre Belloni
2018-02-12 22:47 ` [PATCH 04/45] rtc: nvmem: disallow registering nvmem more than once Alexandre Belloni
2018-02-12 22:47 ` [PATCH 05/45] rtc: export rtc_nvmem_register() to drivers Alexandre Belloni
2018-02-12 22:47 ` [PATCH 06/45] rtc: ds1305: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 07/45] rtc: ds1305: put ds1305_nvmem_cfg on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 08/45] rtc: ds1307: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 09/45] rtc: ds1307: put struct nvmem_config on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 10/45] rtc: ds1511: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 11/45] rtc: ds1511: put ds1511_nvmem_cfg on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 12/45] rtc: m48t86: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 13/45] rtc: m48t86: put m48t86_nvmem_cfg on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 14/45] rtc: omap: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 15/45] rtc: pcf85363: " Alexandre Belloni
2018-02-12 22:47 ` [PATCH 16/45] rtc: pcf85363: put struct nvmem_config on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 17/45] rtc: rv8803: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 18/45] rtc: rv8803: put struct nvmem_config on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 19/45] rtc: rv8803: fix possible race condition Alexandre Belloni
2018-02-12 22:47 ` [PATCH 20/45] rtc: remove nvmem_config Alexandre Belloni
2018-02-12 22:47 ` [PATCH 21/45] rtc: ds1343: simplify regmap initialization Alexandre Belloni
2018-02-12 22:47 ` [PATCH 22/45] rtc: ds1343: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 23/45] rtc: ds1343: remove undocumented and useless sysfs files Alexandre Belloni
2018-02-12 22:47 ` [PATCH 24/45] rtc: ds1343: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 25/45] rtc: m48t59: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 26/45] rtc: m48t59: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 27/45] rtc: sirfsoc: remove useless sirfsoc_rtc_ioctl Alexandre Belloni
2018-02-12 22:47 ` [PATCH 28/45] rtc: ds1553: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 29/45] rtc: ds1553: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 30/45] rtc: ds1553: make alarms useful Alexandre Belloni
2018-02-12 22:47 ` [PATCH 31/45] rtc: cmos: fix possible race condition Alexandre Belloni
2018-02-12 22:47 ` [PATCH 32/45] rtc: cmos: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 33/45] rtc: ds1742: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 34/45] rtc: ds1742: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 35/45] rtc: rp5c01: fix possible race condition Alexandre Belloni
2018-02-12 22:47 ` [PATCH 36/45] rtc: rp5c01: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 37/45] rtc: stk17ta8: make alarms useful Alexandre Belloni
2018-02-12 22:47 ` [PATCH 38/45] rtc: stk17ta8: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 39/45] rtc: stk17ta8: fix possible race condition Alexandre Belloni
2018-02-12 22:47 ` [PATCH 40/45] rtc: stk17ta8: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 41/45] rtc: tx4939: remove arch/mips dependency Alexandre Belloni
2018-02-12 22:47 ` [PATCH 42/45] rtc: tx4939: extend test coverage Alexandre Belloni
2018-02-12 22:47 ` [PATCH 43/45] rtc: tx4939: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 44/45] rtc: tx4939: fix possible race condition Alexandre Belloni
2018-02-12 22:47 ` [PATCH 45/45] rtc: tx4939: use generic nvmem 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.