sh: dreamcast: rtc: push down rtc class ops into driver
authorArnd Bergmann <arnd@arndb.de>
Wed, 24 Jan 2018 14:04:31 +0000 (15:04 +0100)
committerArnd Bergmann <arnd@arndb.de>
Tue, 18 Dec 2018 15:13:04 +0000 (16:13 +0100)
The SH RTC support has an extra level of indirection to provide
either the old read_persistent_clock/update_persistent_clock
interface or the rtc-generic device for hctosys/systohc.

Both do the same thing for dreamcast, so we can do away with the
abstraction and simply let the RTC core code to take care of it.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
arch/sh/boards/mach-dreamcast/Makefile
arch/sh/boards/mach-dreamcast/rtc.c
arch/sh/boards/mach-dreamcast/setup.c
arch/sh/configs/dreamcast_defconfig
arch/sh/include/mach-dreamcast/mach/sysasic.h

index 7b97546c7e5f4d58bda8f080e0910290a05a5112..62b024bc2a3ef59a8e1654387a7de853c394c506 100644 (file)
@@ -2,5 +2,5 @@
 # Makefile for the Sega Dreamcast specific parts of the kernel
 #
 
-obj-y   := setup.o irq.o rtc.o
-
+obj-y   := setup.o irq.o
+obj-$(CONFIG_RTC_DRV_GENERIC) += rtc.o
index 061d65714fcc2782ab0dae15daec9e33223d43c3..0eb12c45fa597174d48bace5151b4b9fe5bfa9ce 100644 (file)
@@ -11,8 +11,9 @@
  */
 
 #include <linux/time.h>
-#include <asm/rtc.h>
-#include <asm/io.h>
+#include <linux/rtc.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
 
 /* The AICA RTC has an Epoch of 1/1/1950, so we must subtract 20 years (in
    seconds) to get the standard Unix Epoch when getting the time, and add
 
 /**
  * aica_rtc_gettimeofday - Get the time from the AICA RTC
- * @ts: pointer to resulting timespec
+ * @dev: the RTC device (ignored)
+ * @tm: pointer to resulting RTC time structure
  *
  * Grabs the current RTC seconds counter and adjusts it to the Unix Epoch.
  */
-static void aica_rtc_gettimeofday(struct timespec *ts)
+static int aica_rtc_gettimeofday(struct device *dev, struct rtc_time *tm)
 {
        unsigned long val1, val2;
+       time64_t t;
 
        do {
                val1 = ((__raw_readl(AICA_RTC_SECS_H) & 0xffff) << 16) |
@@ -42,22 +45,26 @@ static void aica_rtc_gettimeofday(struct timespec *ts)
                        (__raw_readl(AICA_RTC_SECS_L) & 0xffff);
        } while (val1 != val2);
 
-       ts->tv_sec = val1 - TWENTY_YEARS;
+       /* normalize to 1970..2106 time range */
+       t = (u32)(val1 - TWENTY_YEARS);
 
-       /* Can't get nanoseconds with just a seconds counter. */
-       ts->tv_nsec = 0;
+       rtc_time64_to_tm(t, tm);
+
+       return 0;
 }
 
 /**
  * aica_rtc_settimeofday - Set the AICA RTC to the current time
- * @secs: contains the time_t to set
+ * @dev: the RTC device (ignored)
+ * @tm: pointer to new RTC time structure
  *
  * Adjusts the given @tv to the AICA Epoch and sets the RTC seconds counter.
  */
-static int aica_rtc_settimeofday(const time_t secs)
+static int aica_rtc_settimeofday(struct device *dev, struct rtc_time *tm)
 {
        unsigned long val1, val2;
-       unsigned long adj = secs + TWENTY_YEARS;
+       time64_t secs = rtc_tm_to_time64(tm);
+       u32 adj = secs + TWENTY_YEARS;
 
        do {
                __raw_writel((adj & 0xffff0000) >> 16, AICA_RTC_SECS_H);
@@ -73,9 +80,19 @@ static int aica_rtc_settimeofday(const time_t secs)
        return 0;
 }
 
-void aica_time_init(void)
+static const struct rtc_class_ops rtc_generic_ops = {
+       .read_time = aica_rtc_gettimeofday,
+       .set_time = aica_rtc_settimeofday,
+};
+
+static int __init aica_time_init(void)
 {
-       rtc_sh_get_time = aica_rtc_gettimeofday;
-       rtc_sh_set_time = aica_rtc_settimeofday;
-}
+       struct platform_device *pdev;
+
+       pdev = platform_device_register_data(NULL, "rtc-generic", -1,
+                                            &rtc_generic_ops,
+                                            sizeof(rtc_generic_ops));
 
+       return PTR_ERR_OR_ZERO(pdev);
+}
+arch_initcall(aica_time_init);
index ad1a4db72e0406308484ce7bebe6ad514433696b..672c2ad8f8d57866e04c946c3727fd9746ba6af4 100644 (file)
@@ -30,7 +30,6 @@
 
 static void __init dreamcast_setup(char **cmdline_p)
 {
-       board_time_init = aica_time_init;
 }
 
 static struct sh_machine_vector mv_dreamcast __initmv = {
index 3f08dc54480b8f9be93e4d24e645a05e0fac3930..1d27666c029f7efaaf42907799104f50611f5809 100644 (file)
@@ -70,3 +70,5 @@ CONFIG_PROC_KCORE=y
 CONFIG_TMPFS=y
 CONFIG_HUGETLBFS=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_GENERIC=y
index 58f710e1ebc2af30dc235cd4c17370798f986e23..59effd1ed3e138de548efb2ce38a56a60b691ffb 100644 (file)
@@ -42,7 +42,6 @@
 /* arch/sh/boards/mach-dreamcast/irq.c */
 extern int systemasic_irq_demux(int);
 extern void systemasic_irq_init(void);
-extern void aica_time_init(void);
 
 #endif /* __ASM_SH_DREAMCAST_SYSASIC_H */