rtc: parisc: provide rtc_class_ops directly
authorArnd Bergmann <arnd@arndb.de>
Mon, 30 May 2016 18:57:55 +0000 (20:57 +0200)
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>
Fri, 3 Jun 2016 22:23:04 +0000 (00:23 +0200)
The rtc-generic driver provides an architecture specific
wrapper on top of the generic rtc_class_ops abstraction,
and on pa-risc, that is implemented using an open-coded
version of rtc_time_to_tm/rtc_tm_to_time.

This changes the parisc rtc-generic device to provide its
rtc_class_ops directly, using the normal helper functions,
which makes this y2038 safe (on 32-bit) and simplifies
the implementation.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
arch/parisc/kernel/time.c
drivers/rtc/rtc-generic.c

index 58dd6801f5bece511f16603b7db47906637582b0..744878789752bb06db3f9467d138c9df5ec00a76 100644 (file)
@@ -12,6 +12,7 @@
  */
 #include <linux/errno.h>
 #include <linux/module.h>
+#include <linux/rtc.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
 #include <linux/param.h>
@@ -248,14 +249,47 @@ void __init start_cpu_itimer(void)
        per_cpu(cpu_data, cpu).it_value = next_tick;
 }
 
+#if IS_ENABLED(CONFIG_RTC_DRV_GENERIC)
+static int rtc_generic_get_time(struct device *dev, struct rtc_time *tm)
+{
+       struct pdc_tod tod_data;
+
+       memset(tm, 0, sizeof(*tm));
+       if (pdc_tod_read(&tod_data) < 0)
+               return -EOPNOTSUPP;
+
+       /* we treat tod_sec as unsigned, so this can work until year 2106 */
+       rtc_time64_to_tm(tod_data.tod_sec, tm);
+       return rtc_valid_tm(tm);
+}
+
+static int rtc_generic_set_time(struct device *dev, struct rtc_time *tm)
+{
+       time64_t secs = rtc_tm_to_time64(tm);
+
+       if (pdc_tod_set(secs, 0) < 0)
+               return -EOPNOTSUPP;
+
+       return 0;
+}
+
+static const struct rtc_class_ops rtc_generic_ops = {
+       .read_time = rtc_generic_get_time,
+       .set_time = rtc_generic_set_time,
+};
+
 static int __init rtc_init(void)
 {
        struct platform_device *pdev;
 
-       pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0);
+       pdev = platform_device_register_data(NULL, "rtc-generic", -1,
+                                            &rtc_generic_ops,
+                                            sizeof(rtc_generic_ops));
+
        return PTR_ERR_OR_ZERO(pdev);
 }
 device_initcall(rtc_init);
+#endif
 
 void read_persistent_clock(struct timespec *ts)
 {
index 3958e87a05fa66bf10ee5e95dc794221bda22093..92b5e02a37506ab6fc72aa076891a2046bd9839e 100644 (file)
@@ -9,8 +9,7 @@
 #include <linux/platform_device.h>
 #include <linux/rtc.h>
 
-#if defined(CONFIG_M68K) || defined(CONFIG_PARISC) || \
-    defined(CONFIG_PPC)
+#if defined(CONFIG_M68K) || defined(CONFIG_PPC)
 #include <asm/rtc.h>
 
 static int generic_get_time(struct device *dev, struct rtc_time *tm)