linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] powerpc: mac: fix rtc read functions
@ 2018-06-18 14:05 Arnd Bergmann
  2018-06-18 14:05 ` [PATCH 2/3] m68k: mac: use time64_t in RTC handling Arnd Bergmann
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Arnd Bergmann @ 2018-06-18 14:05 UTC (permalink / raw)
  To: Paul Mackerras, Michael Ellerman, Geert Uytterhoeven, Joshua Thompson
  Cc: Mathieu Malaterre, Benjamin Herrenschmidt, Greg Ungerer,
	linux-m68k, linuxppc-dev, linux-kernel, y2038, Meelis Roos,
	Arnd Bergmann

As Mathieu pointed out, my conversion to time64_t was incorrect and resulted
in negative times to be read from the RTC. The problem is that during the
conversion from a byte array to a time64_t, the 'unsigned char' variable
holding the top byte gets turned into a negative signed 32-bit integer
before being assigned to the 64-bit variable for any times after 1972.

This changes the logic to cast to an unsigned 32-bit number first for
the Macintosh time and then convert that to the Unix time, which then gives
us a time in the documented 1904..2040 year range. I decided not to use
the longer 1970..2106 range that other drivers use, for consistency with
the literal interpretation of the register, but that could be easily
changed if we decide we want to support any Mac after 2040.

Just to be on the safe side, I'm also adding a WARN_ON that will trigger
if either the year 2040 has come and is observed by this driver, or we
run into an RTC that got set back to a pre-1970 date for some reason
(the two are indistinguishable).

The same code exists in arch/m68k/ and is patched in an identical way now
in a separate patch.

Fixes: 5bfd643583b2 ("powerpc: use time64_t in read_persistent_clock")
Reported-by: Mathieu Malaterre <malat@debian.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/powerpc/platforms/powermac/time.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/platforms/powermac/time.c b/arch/powerpc/platforms/powermac/time.c
index 7c968e46736f..173a80630169 100644
--- a/arch/powerpc/platforms/powermac/time.c
+++ b/arch/powerpc/platforms/powermac/time.c
@@ -42,7 +42,11 @@
 #define DBG(x...)
 #endif
 
-/* Apparently the RTC stores seconds since 1 Jan 1904 */
+/*
+ * Offset between Unix time (1970-based) and Mac time (1904-based). Cuda and PMU
+ * times wrap in 2040. If we need to handle later times, the read_time functions
+ * need to be changed to interpret wrapped times as post-2040.
+ */
 #define RTC_OFFSET	2082844800
 
 /*
@@ -97,8 +101,11 @@ static time64_t cuda_get_time(void)
 	if (req.reply_len != 7)
 		printk(KERN_ERR "cuda_get_time: got %d byte reply\n",
 		       req.reply_len);
-	now = (req.reply[3] << 24) + (req.reply[4] << 16)
-		+ (req.reply[5] << 8) + req.reply[6];
+	now = (u32)((req.reply[3] << 24) + (req.reply[4] << 16) +
+		    (req.reply[5] << 8) + req.reply[6]);
+	/* it's either after year 2040, or the RTC has gone backwards */
+	WARN_ON(now < RTC_OFFSET);
+
 	return now - RTC_OFFSET;
 }
 
@@ -140,8 +147,12 @@ static time64_t pmu_get_time(void)
 	if (req.reply_len != 4)
 		printk(KERN_ERR "pmu_get_time: got %d byte reply from PMU\n",
 		       req.reply_len);
-	now = (req.reply[0] << 24) + (req.reply[1] << 16)
-		+ (req.reply[2] << 8) + req.reply[3];
+	now = (u32)((req.reply[0] << 24) + (req.reply[1] << 16)	+
+		    (req.reply[2] << 8) + req.reply[3]);
+
+	/* it's either after year 2040, or the RTC has gone backwards */
+	WARN_ON(now < RTC_OFFSET);
+
 	return now - RTC_OFFSET;
 }
 
-- 
2.9.0


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

* [PATCH 2/3] m68k: mac: use time64_t in RTC handling
  2018-06-18 14:05 [PATCH 1/3] powerpc: mac: fix rtc read functions Arnd Bergmann
@ 2018-06-18 14:05 ` Arnd Bergmann
  2018-06-18 16:55   ` kbuild test robot
  2018-06-18 14:05 ` [PATCH 3/3] m68k: remove unused set_clock_mmss() helpers Arnd Bergmann
  2018-06-18 19:10 ` [PATCH 1/3] powerpc: mac: fix rtc read functions Mathieu Malaterre
  2 siblings, 1 reply; 9+ messages in thread
From: Arnd Bergmann @ 2018-06-18 14:05 UTC (permalink / raw)
  To: Paul Mackerras, Michael Ellerman, Geert Uytterhoeven, Joshua Thompson
  Cc: Mathieu Malaterre, Benjamin Herrenschmidt, Greg Ungerer,
	linux-m68k, linuxppc-dev, linux-kernel, y2038, Meelis Roos,
	Arnd Bergmann

The real-time clock on m68k (and powerpc) mac systems uses an unsigned
32-bit value starting in 1904, which overflows in 2040, about two years
later than everyone else, but this gets wrapped around in the Linux
code in 2038 already because of the deprecated usage of time_t and/or
long in the conversion.

Getting rid of the deprecated interfaces makes it work until 2040 as
documented, and it could be easily extended by reinterpreting
the resulting time64_t as a positive number. For the moment, I'm
adding a WARN_ON() that triggers if we encounter a time before 1970
or after 2040 (the two are indistinguishable).

This brings it in line with the corresponding code that we have on
powerpc macintosh.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/m68k/mac/misc.c | 58 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 21 deletions(-)

diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index c68054361615..b399a0809e18 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -26,33 +26,40 @@
 
 #include <asm/machdep.h>
 
-/* Offset between Unix time (1970-based) and Mac time (1904-based) */
+/* Offset between Unix time (1970-based) and Mac time (1904-based). Cuda and PMU
+ * times wrap in 2040. If we need to handle later times, the read_time functions
+ * need to be changed to interpret wrapped times as post-2040. */
 
 #define RTC_OFFSET 2082844800
 
 static void (*rom_reset)(void);
 
 #ifdef CONFIG_ADB_CUDA
-static long cuda_read_time(void)
+static time64_t cuda_read_time(void)
 {
 	struct adb_request req;
-	long time;
+	time64_t time;
 
 	if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0)
 		return 0;
 	while (!req.complete)
 		cuda_poll();
 
-	time = (req.reply[3] << 24) | (req.reply[4] << 16) |
-	       (req.reply[5] << 8) | req.reply[6];
+	time = (u32)((req.reply[3] << 24( | (req.reply[4] << 16) |
+		     (req.reply[5] << 8) | req.reply[6]);
+
+	/* it's either after year 2040, or the RTC has gone backwards */
+	WARN_ON(time < RTC_OFFSET);
+
 	return time - RTC_OFFSET;
 }
 
-static void cuda_write_time(long data)
+static void cuda_write_time(time64_t data)
 {
 	struct adb_request req;
 
 	data += RTC_OFFSET;
+	data &= 0xffffffff;
 	if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME,
 			 (data >> 24) & 0xFF, (data >> 16) & 0xFF,
 			 (data >> 8) & 0xFF, data & 0xFF) < 0)
@@ -86,26 +93,29 @@ static void cuda_write_pram(int offset, __u8 data)
 #endif /* CONFIG_ADB_CUDA */
 
 #ifdef CONFIG_ADB_PMU68K
-static long pmu_read_time(void)
+static time64_t pmu_read_time(void)
 {
 	struct adb_request req;
-	long time;
+	time64_t time;
 
 	if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0)
 		return 0;
 	while (!req.complete)
 		pmu_poll();
 
-	time = (req.reply[1] << 24) | (req.reply[2] << 16) |
-	       (req.reply[3] << 8) | req.reply[4];
+	/* it's either after year 2040, or the RTC has gone backwards */
+	time = (u32)((req.reply[1] << 24) | (req.reply[2] << 16) |
+		     (req.reply[3] << 8) | req.reply[4]);
+
 	return time - RTC_OFFSET;
 }
 
-static void pmu_write_time(long data)
+static void pmu_write_time(time64_t data)
 {
 	struct adb_request req;
 
 	data += RTC_OFFSET;
+	data &= 0xffffffff;
 	if (pmu_request(&req, NULL, 5, PMU_SET_RTC,
 			(data >> 24) & 0xFF, (data >> 16) & 0xFF,
 			(data >> 8) & 0xFF, data & 0xFF) < 0)
@@ -269,8 +279,12 @@ static long via_read_time(void)
 		via_pram_command(0x89, &result.cdata[1]);
 		via_pram_command(0x8D, &result.cdata[0]);
 
-		if (result.idata == last_result.idata)
+		if (result.idata == last_result.idata) {
+			if (result.idata < RTC_OFFSET)
+				result.idata += 0x100000000ull;
+
 			return result.idata - RTC_OFFSET;
+		}
 
 		if (++count > 10)
 			break;
@@ -291,11 +305,11 @@ static long via_read_time(void)
  * is basically any machine with Mac II-style ADB.
  */
 
-static void via_write_time(long time)
+static void via_write_time(time64_t time)
 {
 	union {
 		__u8 cdata[4];
-		long idata;
+		__u32 idata;
 	} data;
 	__u8 temp;
 
@@ -585,12 +599,15 @@ void mac_reset(void)
  * This function translates seconds since 1970 into a proper date.
  *
  * Algorithm cribbed from glibc2.1, __offtime().
+ *
+ * This is roughly same as rtc_time64_to_tm(), which we should probably
+ * use here, but it's only available when CONFIG_RTC_LIB is enabled.
  */
 #define SECS_PER_MINUTE (60)
 #define SECS_PER_HOUR  (SECS_PER_MINUTE * 60)
 #define SECS_PER_DAY   (SECS_PER_HOUR * 24)
 
-static void unmktime(unsigned long time, long offset,
+static void unmktime(time64_t time, long offset,
 		     int *yearp, int *monp, int *dayp,
 		     int *hourp, int *minp, int *secp)
 {
@@ -602,11 +619,10 @@ static void unmktime(unsigned long time, long offset,
 		/* Leap years.  */
 		{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
 	};
-	long int days, rem, y, wday, yday;
+	int days, rem, y, wday, yday;
 	const unsigned short int *ip;
 
-	days = time / SECS_PER_DAY;
-	rem = time % SECS_PER_DAY;
+	days = div_u64_rem(time, SECS_PER_DAY, &rem);
 	rem += offset;
 	while (rem < 0) {
 		rem += SECS_PER_DAY;
@@ -657,7 +673,7 @@ static void unmktime(unsigned long time, long offset,
 
 int mac_hwclk(int op, struct rtc_time *t)
 {
-	unsigned long now;
+	time64_t now;
 
 	if (!op) { /* read */
 		switch (macintosh_config->adb_type) {
@@ -693,8 +709,8 @@ int mac_hwclk(int op, struct rtc_time *t)
 		         __func__, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
 		         t->tm_hour, t->tm_min, t->tm_sec);
 
-		now = mktime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
-			     t->tm_hour, t->tm_min, t->tm_sec);
+		now = mktime64(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
+			       t->tm_hour, t->tm_min, t->tm_sec);
 
 		switch (macintosh_config->adb_type) {
 		case MAC_ADB_IOP:
-- 
2.9.0


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

* [PATCH 3/3] m68k: remove unused set_clock_mmss() helpers
  2018-06-18 14:05 [PATCH 1/3] powerpc: mac: fix rtc read functions Arnd Bergmann
  2018-06-18 14:05 ` [PATCH 2/3] m68k: mac: use time64_t in RTC handling Arnd Bergmann
@ 2018-06-18 14:05 ` Arnd Bergmann
  2018-06-19 13:07   ` Greg Ungerer
  2018-06-18 19:10 ` [PATCH 1/3] powerpc: mac: fix rtc read functions Mathieu Malaterre
  2 siblings, 1 reply; 9+ messages in thread
From: Arnd Bergmann @ 2018-06-18 14:05 UTC (permalink / raw)
  To: Paul Mackerras, Michael Ellerman, Geert Uytterhoeven, Joshua Thompson
  Cc: Mathieu Malaterre, Benjamin Herrenschmidt, Greg Ungerer,
	linux-m68k, linuxppc-dev, linux-kernel, y2038, Meelis Roos,
	Arnd Bergmann

Commit 397ac99c6cef ("m68k: remove dead timer code") removed set_rtc_mmss()
because it was unused in 2012. However, this was itself the only user of the
mach_set_clock_mmss() callback and the many implementations of that callback,
which are equally unused.

This removes all of those as well.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/m68k/apollo/config.c       |  8 ------
 arch/m68k/atari/config.c        |  5 ----
 arch/m68k/atari/time.c          | 63 -----------------------------------------
 arch/m68k/bvme6000/config.c     | 45 -----------------------------
 arch/m68k/include/asm/machdep.h |  1 -
 arch/m68k/kernel/setup_mm.c     |  1 -
 arch/m68k/kernel/setup_no.c     |  1 -
 arch/m68k/mac/config.c          |  2 --
 arch/m68k/mac/misc.c            | 16 -----------
 arch/m68k/mvme147/config.c      |  7 -----
 arch/m68k/mvme16x/config.c      |  8 ------
 arch/m68k/q40/config.c          | 30 --------------------
 12 files changed, 187 deletions(-)

diff --git a/arch/m68k/apollo/config.c b/arch/m68k/apollo/config.c
index b2a6bc63f8cd..aef8d42e078d 100644
--- a/arch/m68k/apollo/config.c
+++ b/arch/m68k/apollo/config.c
@@ -31,7 +31,6 @@ extern void dn_sched_init(irq_handler_t handler);
 extern void dn_init_IRQ(void);
 extern u32 dn_gettimeoffset(void);
 extern int dn_dummy_hwclk(int, struct rtc_time *);
-extern int dn_dummy_set_clock_mmss(unsigned long);
 extern void dn_dummy_reset(void);
 #ifdef CONFIG_HEARTBEAT
 static void dn_heartbeat(int on);
@@ -156,7 +155,6 @@ void __init config_apollo(void)
 	arch_gettimeoffset   = dn_gettimeoffset;
 	mach_max_dma_address = 0xffffffff;
 	mach_hwclk           = dn_dummy_hwclk; /* */
-	mach_set_clock_mmss  = dn_dummy_set_clock_mmss; /* */
 	mach_reset	     = dn_dummy_reset;  /* */
 #ifdef CONFIG_HEARTBEAT
 	mach_heartbeat = dn_heartbeat;
@@ -240,12 +238,6 @@ int dn_dummy_hwclk(int op, struct rtc_time *t) {
 
 }
 
-int dn_dummy_set_clock_mmss(unsigned long nowtime)
-{
-	pr_info("set_clock_mmss\n");
-	return 0;
-}
-
 void dn_dummy_reset(void) {
 
   dn_serial_print("The end !\n");
diff --git a/arch/m68k/atari/config.c b/arch/m68k/atari/config.c
index 565c6f06ab0b..bd96702a1ad0 100644
--- a/arch/m68k/atari/config.c
+++ b/arch/m68k/atari/config.c
@@ -81,9 +81,6 @@ extern void atari_sched_init(irq_handler_t);
 extern u32 atari_gettimeoffset(void);
 extern int atari_mste_hwclk (int, struct rtc_time *);
 extern int atari_tt_hwclk (int, struct rtc_time *);
-extern int atari_mste_set_clock_mmss (unsigned long);
-extern int atari_tt_set_clock_mmss (unsigned long);
-
 
 /* ++roman: This is a more elaborate test for an SCC chip, since the plain
  * Medusa board generates DTACK at the SCC's standard addresses, but a SCC
@@ -362,13 +359,11 @@ void __init config_atari(void)
 		ATARIHW_SET(TT_CLK);
 		pr_cont(" TT_CLK");
 		mach_hwclk = atari_tt_hwclk;
-		mach_set_clock_mmss = atari_tt_set_clock_mmss;
 	}
 	if (hwreg_present(&mste_rtc.sec_ones)) {
 		ATARIHW_SET(MSTE_CLK);
 		pr_cont(" MSTE_CLK");
 		mach_hwclk = atari_mste_hwclk;
-		mach_set_clock_mmss = atari_mste_set_clock_mmss;
 	}
 	if (!MACH_IS_MEDUSA && hwreg_present(&dma_wd.fdc_speed) &&
 	    hwreg_write(&dma_wd.fdc_speed, 0)) {
diff --git a/arch/m68k/atari/time.c b/arch/m68k/atari/time.c
index c549b48174ec..9cca64286464 100644
--- a/arch/m68k/atari/time.c
+++ b/arch/m68k/atari/time.c
@@ -285,69 +285,6 @@ int atari_tt_hwclk( int op, struct rtc_time *t )
     return( 0 );
 }
 
-
-int atari_mste_set_clock_mmss (unsigned long nowtime)
-{
-    short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
-    struct MSTE_RTC val;
-    unsigned char rtc_minutes;
-
-    mste_read(&val);
-    rtc_minutes= val.min_ones + val.min_tens * 10;
-    if ((rtc_minutes < real_minutes
-         ? real_minutes - rtc_minutes
-         : rtc_minutes - real_minutes) < 30)
-    {
-        val.sec_ones = real_seconds % 10;
-        val.sec_tens = real_seconds / 10;
-        val.min_ones = real_minutes % 10;
-        val.min_tens = real_minutes / 10;
-        mste_write(&val);
-    }
-    else
-        return -1;
-    return 0;
-}
-
-int atari_tt_set_clock_mmss (unsigned long nowtime)
-{
-    int retval = 0;
-    short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
-    unsigned char save_control, save_freq_select, rtc_minutes;
-
-    save_control = RTC_READ (RTC_CONTROL); /* tell the clock it's being set */
-    RTC_WRITE (RTC_CONTROL, save_control | RTC_SET);
-
-    save_freq_select = RTC_READ (RTC_FREQ_SELECT); /* stop and reset prescaler */
-    RTC_WRITE (RTC_FREQ_SELECT, save_freq_select | RTC_DIV_RESET2);
-
-    rtc_minutes = RTC_READ (RTC_MINUTES);
-    if (!(save_control & RTC_DM_BINARY))
-	rtc_minutes = bcd2bin(rtc_minutes);
-
-    /* Since we're only adjusting minutes and seconds, don't interfere
-       with hour overflow.  This avoids messing with unknown time zones
-       but requires your RTC not to be off by more than 30 minutes.  */
-    if ((rtc_minutes < real_minutes
-         ? real_minutes - rtc_minutes
-         : rtc_minutes - real_minutes) < 30)
-        {
-            if (!(save_control & RTC_DM_BINARY))
-                {
-		    real_seconds = bin2bcd(real_seconds);
-		    real_minutes = bin2bcd(real_minutes);
-                }
-            RTC_WRITE (RTC_SECONDS, real_seconds);
-            RTC_WRITE (RTC_MINUTES, real_minutes);
-        }
-    else
-        retval = -1;
-
-    RTC_WRITE (RTC_FREQ_SELECT, save_freq_select);
-    RTC_WRITE (RTC_CONTROL, save_control);
-    return retval;
-}
-
 /*
  * Local variables:
  *  c-indent-level: 4
diff --git a/arch/m68k/bvme6000/config.c b/arch/m68k/bvme6000/config.c
index 2cfff4765040..143ee9fa3893 100644
--- a/arch/m68k/bvme6000/config.c
+++ b/arch/m68k/bvme6000/config.c
@@ -41,7 +41,6 @@ static void bvme6000_get_model(char *model);
 extern void bvme6000_sched_init(irq_handler_t handler);
 extern u32 bvme6000_gettimeoffset(void);
 extern int bvme6000_hwclk (int, struct rtc_time *);
-extern int bvme6000_set_clock_mmss (unsigned long);
 extern void bvme6000_reset (void);
 void bvme6000_set_vectors (void);
 
@@ -113,7 +112,6 @@ void __init config_bvme6000(void)
     mach_init_IRQ        = bvme6000_init_IRQ;
     arch_gettimeoffset   = bvme6000_gettimeoffset;
     mach_hwclk           = bvme6000_hwclk;
-    mach_set_clock_mmss	 = bvme6000_set_clock_mmss;
     mach_reset		 = bvme6000_reset;
     mach_get_model       = bvme6000_get_model;
 
@@ -305,46 +303,3 @@ int bvme6000_hwclk(int op, struct rtc_time *t)
 
 	return 0;
 }
-
-/*
- * Set the minutes and seconds from seconds value 'nowtime'.  Fail if
- * clock is out by > 30 minutes.  Logic lifted from atari code.
- * Algorithm is to wait for the 10ms register to change, and then to
- * wait a short while, and then set it.
- */
-
-int bvme6000_set_clock_mmss (unsigned long nowtime)
-{
-	int retval = 0;
-	short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
-	unsigned char rtc_minutes, rtc_tenms;
-	volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
-	unsigned char msr = rtc->msr & 0xc0;
-	unsigned long flags;
-	volatile int i;
-
-	rtc->msr = 0;		/* Ensure clock accessible */
-	rtc_minutes = bcd2bin (rtc->bcd_min);
-
-	if ((rtc_minutes < real_minutes
-		? real_minutes - rtc_minutes
-			: rtc_minutes - real_minutes) < 30)
-	{
-		local_irq_save(flags);
-		rtc_tenms = rtc->bcd_tenms;
-		while (rtc_tenms == rtc->bcd_tenms)
-			;
-		for (i = 0; i < 1000; i++)
-			;
-		rtc->bcd_min = bin2bcd(real_minutes);
-		rtc->bcd_sec = bin2bcd(real_seconds);
-		local_irq_restore(flags);
-	}
-	else
-		retval = -1;
-
-	rtc->msr = msr;
-
-	return retval;
-}
-
diff --git a/arch/m68k/include/asm/machdep.h b/arch/m68k/include/asm/machdep.h
index 1605da48ebf2..49bd3266b4b1 100644
--- a/arch/m68k/include/asm/machdep.h
+++ b/arch/m68k/include/asm/machdep.h
@@ -22,7 +22,6 @@ extern int (*mach_hwclk)(int, struct rtc_time*);
 extern unsigned int (*mach_get_ss)(void);
 extern int (*mach_get_rtc_pll)(struct rtc_pll_info *);
 extern int (*mach_set_rtc_pll)(struct rtc_pll_info *);
-extern int (*mach_set_clock_mmss)(unsigned long);
 extern void (*mach_reset)( void );
 extern void (*mach_halt)( void );
 extern void (*mach_power_off)( void );
diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
index f35e3ebd6331..07244732eb41 100644
--- a/arch/m68k/kernel/setup_mm.c
+++ b/arch/m68k/kernel/setup_mm.c
@@ -88,7 +88,6 @@ void (*mach_get_hardware_list) (struct seq_file *m);
 /* machine dependent timer functions */
 int (*mach_hwclk) (int, struct rtc_time*);
 EXPORT_SYMBOL(mach_hwclk);
-int (*mach_set_clock_mmss) (unsigned long);
 unsigned int (*mach_get_ss)(void);
 int (*mach_get_rtc_pll)(struct rtc_pll_info *);
 int (*mach_set_rtc_pll)(struct rtc_pll_info *);
diff --git a/arch/m68k/kernel/setup_no.c b/arch/m68k/kernel/setup_no.c
index a98af1018201..3c53e4c366ac 100644
--- a/arch/m68k/kernel/setup_no.c
+++ b/arch/m68k/kernel/setup_no.c
@@ -51,7 +51,6 @@ char __initdata command_line[COMMAND_LINE_SIZE];
 
 /* machine dependent timer functions */
 void (*mach_sched_init)(irq_handler_t handler) __initdata = NULL;
-int (*mach_set_clock_mmss)(unsigned long);
 int (*mach_hwclk) (int, struct rtc_time*);
 
 /* machine dependent reboot functions */
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index e522307db47c..da1aeb966474 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -57,7 +57,6 @@ static unsigned long mac_orig_videoaddr;
 /* Mac specific timer functions */
 extern u32 mac_gettimeoffset(void);
 extern int mac_hwclk(int, struct rtc_time *);
-extern int mac_set_clock_mmss(unsigned long);
 extern void iop_preinit(void);
 extern void iop_init(void);
 extern void via_init(void);
@@ -158,7 +157,6 @@ void __init config_mac(void)
 	mach_get_model = mac_get_model;
 	arch_gettimeoffset = mac_gettimeoffset;
 	mach_hwclk = mac_hwclk;
-	mach_set_clock_mmss = mac_set_clock_mmss;
 	mach_reset = mac_reset;
 	mach_halt = mac_poweroff;
 	mach_power_off = mac_poweroff;
diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index b399a0809e18..b0dda5cb9e48 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -735,19 +735,3 @@ int mac_hwclk(int op, struct rtc_time *t)
 	}
 	return 0;
 }
-
-/*
- * Set minutes/seconds in the hardware clock
- */
-
-int mac_set_clock_mmss (unsigned long nowtime)
-{
-	struct rtc_time now;
-
-	mac_hwclk(0, &now);
-	now.tm_sec = nowtime % 60;
-	now.tm_min = (nowtime / 60) % 60;
-	mac_hwclk(1, &now);
-
-	return 0;
-}
diff --git a/arch/m68k/mvme147/config.c b/arch/m68k/mvme147/config.c
index f8a710fd84cd..adea549d240e 100644
--- a/arch/m68k/mvme147/config.c
+++ b/arch/m68k/mvme147/config.c
@@ -40,7 +40,6 @@ static void mvme147_get_model(char *model);
 extern void mvme147_sched_init(irq_handler_t handler);
 extern u32 mvme147_gettimeoffset(void);
 extern int mvme147_hwclk (int, struct rtc_time *);
-extern int mvme147_set_clock_mmss (unsigned long);
 extern void mvme147_reset (void);
 
 
@@ -92,7 +91,6 @@ void __init config_mvme147(void)
 	mach_init_IRQ		= mvme147_init_IRQ;
 	arch_gettimeoffset	= mvme147_gettimeoffset;
 	mach_hwclk		= mvme147_hwclk;
-	mach_set_clock_mmss	= mvme147_set_clock_mmss;
 	mach_reset		= mvme147_reset;
 	mach_get_model		= mvme147_get_model;
 
@@ -164,8 +162,3 @@ int mvme147_hwclk(int op, struct rtc_time *t)
 	}
 	return 0;
 }
-
-int mvme147_set_clock_mmss (unsigned long nowtime)
-{
-	return 0;
-}
diff --git a/arch/m68k/mvme16x/config.c b/arch/m68k/mvme16x/config.c
index 4ffd9ef98de4..6ee36a5b528d 100644
--- a/arch/m68k/mvme16x/config.c
+++ b/arch/m68k/mvme16x/config.c
@@ -46,7 +46,6 @@ static void mvme16x_get_model(char *model);
 extern void mvme16x_sched_init(irq_handler_t handler);
 extern u32 mvme16x_gettimeoffset(void);
 extern int mvme16x_hwclk (int, struct rtc_time *);
-extern int mvme16x_set_clock_mmss (unsigned long);
 extern void mvme16x_reset (void);
 
 int bcd2int (unsigned char b);
@@ -280,7 +279,6 @@ void __init config_mvme16x(void)
     mach_init_IRQ        = mvme16x_init_IRQ;
     arch_gettimeoffset   = mvme16x_gettimeoffset;
     mach_hwclk           = mvme16x_hwclk;
-    mach_set_clock_mmss	 = mvme16x_set_clock_mmss;
     mach_reset		 = mvme16x_reset;
     mach_get_model       = mvme16x_get_model;
     mach_get_hardware_list = mvme16x_get_hardware_list;
@@ -411,9 +409,3 @@ int mvme16x_hwclk(int op, struct rtc_time *t)
 	}
 	return 0;
 }
-
-int mvme16x_set_clock_mmss (unsigned long nowtime)
-{
-	return 0;
-}
-
diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c
index 71c0867ecf20..96810d91da2b 100644
--- a/arch/m68k/q40/config.c
+++ b/arch/m68k/q40/config.c
@@ -43,7 +43,6 @@ extern void q40_sched_init(irq_handler_t handler);
 static u32 q40_gettimeoffset(void);
 static int q40_hwclk(int, struct rtc_time *);
 static unsigned int q40_get_ss(void);
-static int q40_set_clock_mmss(unsigned long);
 static int q40_get_rtc_pll(struct rtc_pll_info *pll);
 static int q40_set_rtc_pll(struct rtc_pll_info *pll);
 
@@ -175,7 +174,6 @@ void __init config_q40(void)
 	mach_get_ss = q40_get_ss;
 	mach_get_rtc_pll = q40_get_rtc_pll;
 	mach_set_rtc_pll = q40_set_rtc_pll;
-	mach_set_clock_mmss = q40_set_clock_mmss;
 
 	mach_reset = q40_reset;
 	mach_get_model = q40_get_model;
@@ -267,34 +265,6 @@ static unsigned int q40_get_ss(void)
 	return bcd2bin(Q40_RTC_SECS);
 }
 
-/*
- * Set the minutes and seconds from seconds value 'nowtime'.  Fail if
- * clock is out by > 30 minutes.  Logic lifted from atari code.
- */
-
-static int q40_set_clock_mmss(unsigned long nowtime)
-{
-	int retval = 0;
-	short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
-
-	int rtc_minutes;
-
-	rtc_minutes = bcd2bin(Q40_RTC_MINS);
-
-	if ((rtc_minutes < real_minutes ?
-	     real_minutes - rtc_minutes :
-	     rtc_minutes - real_minutes) < 30) {
-		Q40_RTC_CTRL |= Q40_RTC_WRITE;
-		Q40_RTC_MINS = bin2bcd(real_minutes);
-		Q40_RTC_SECS = bin2bcd(real_seconds);
-		Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
-	} else
-		retval = -1;
-
-	return retval;
-}
-
-
 /* get and set PLL calibration of RTC clock */
 #define Q40_RTC_PLL_MASK ((1<<5)-1)
 #define Q40_RTC_PLL_SIGN (1<<5)
-- 
2.9.0


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

* Re: [PATCH 2/3] m68k: mac: use time64_t in RTC handling
  2018-06-18 14:05 ` [PATCH 2/3] m68k: mac: use time64_t in RTC handling Arnd Bergmann
@ 2018-06-18 16:55   ` kbuild test robot
  0 siblings, 0 replies; 9+ messages in thread
From: kbuild test robot @ 2018-06-18 16:55 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: kbuild-all, Paul Mackerras, Michael Ellerman, Geert Uytterhoeven,
	Joshua Thompson, Mathieu Malaterre, Benjamin Herrenschmidt,
	Greg Ungerer, linux-m68k, linuxppc-dev, linux-kernel, y2038,
	Meelis Roos, Arnd Bergmann

[-- Attachment #1: Type: text/plain, Size: 2508 bytes --]

Hi Arnd,

I love your patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.18-rc1 next-20180618]
[cannot apply to m68k/for-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Arnd-Bergmann/powerpc-mac-fix-rtc-read-functions/20180618-222412
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: m68k-multi_defconfig (attached as .config)
compiler: m68k-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.2.0 make.cross ARCH=m68k 

All errors (new ones prefixed by >>):

   arch/m68k/mac/misc.c: In function 'cuda_read_time':
>> arch/m68k/mac/misc.c:48:36: error: expected expression before '|' token
     time = (u32)((req.reply[3] << 24( | (req.reply[4] << 16) |
                                       ^
>> arch/m68k/mac/misc.c:48:32: error: called object is not a function or function pointer
     time = (u32)((req.reply[3] << 24( | (req.reply[4] << 16) |
                                   ^~
>> arch/m68k/mac/misc.c:49:43: error: expected ')' before ';' token
           (req.reply[5] << 8) | req.reply[6]);
                                              ^
   arch/m68k/mac/misc.c:55:1: error: expected ')' before '}' token
    }
    ^
>> arch/m68k/mac/misc.c:55:1: error: expected ';' before '}' token
   arch/m68k/mac/misc.c:55:1: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^

vim +48 arch/m68k/mac/misc.c

    36	
    37	#ifdef CONFIG_ADB_CUDA
    38	static time64_t cuda_read_time(void)
    39	{
    40		struct adb_request req;
    41		time64_t time;
    42	
    43		if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0)
    44			return 0;
    45		while (!req.complete)
    46			cuda_poll();
    47	
  > 48		time = (u32)((req.reply[3] << 24( | (req.reply[4] << 16) |
  > 49			     (req.reply[5] << 8) | req.reply[6]);
    50	
    51		/* it's either after year 2040, or the RTC has gone backwards */
    52		WARN_ON(time < RTC_OFFSET);
    53	
    54		return time - RTC_OFFSET;
  > 55	}
    56	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 13188 bytes --]

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

* Re: [PATCH 1/3] powerpc: mac: fix rtc read functions
  2018-06-18 14:05 [PATCH 1/3] powerpc: mac: fix rtc read functions Arnd Bergmann
  2018-06-18 14:05 ` [PATCH 2/3] m68k: mac: use time64_t in RTC handling Arnd Bergmann
  2018-06-18 14:05 ` [PATCH 3/3] m68k: remove unused set_clock_mmss() helpers Arnd Bergmann
@ 2018-06-18 19:10 ` Mathieu Malaterre
  2018-06-18 20:04   ` Andreas Schwab
  2 siblings, 1 reply; 9+ messages in thread
From: Mathieu Malaterre @ 2018-06-18 19:10 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Paul Mackerras, Michael Ellerman, Geert Uytterhoeven, funaho,
	Benjamin Herrenschmidt, gerg, linux-m68k, linuxppc-dev, LKML,
	y2038, Meelis Roos, Alexandre Belloni

On Mon, Jun 18, 2018 at 4:07 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> As Mathieu pointed out, my conversion to time64_t was incorrect and resulted
> in negative times to be read from the RTC. The problem is that during the
> conversion from a byte array to a time64_t, the 'unsigned char' variable
> holding the top byte gets turned into a negative signed 32-bit integer
> before being assigned to the 64-bit variable for any times after 1972.
>
> This changes the logic to cast to an unsigned 32-bit number first for
> the Macintosh time and then convert that to the Unix time, which then gives
> us a time in the documented 1904..2040 year range. I decided not to use
> the longer 1970..2106 range that other drivers use, for consistency with
> the literal interpretation of the register, but that could be easily
> changed if we decide we want to support any Mac after 2040.
>
> Just to be on the safe side, I'm also adding a WARN_ON that will trigger
> if either the year 2040 has come and is observed by this driver, or we
> run into an RTC that got set back to a pre-1970 date for some reason
> (the two are indistinguishable).
>
> The same code exists in arch/m68k/ and is patched in an identical way now
> in a separate patch.
>
> Fixes: 5bfd643583b2 ("powerpc: use time64_t in read_persistent_clock")
> Reported-by: Mathieu Malaterre <malat@debian.org>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  arch/powerpc/platforms/powermac/time.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/arch/powerpc/platforms/powermac/time.c b/arch/powerpc/platforms/powermac/time.c
> index 7c968e46736f..173a80630169 100644
> --- a/arch/powerpc/platforms/powermac/time.c
> +++ b/arch/powerpc/platforms/powermac/time.c
> @@ -42,7 +42,11 @@
>  #define DBG(x...)
>  #endif
>
> -/* Apparently the RTC stores seconds since 1 Jan 1904 */
> +/*
> + * Offset between Unix time (1970-based) and Mac time (1904-based). Cuda and PMU
> + * times wrap in 2040. If we need to handle later times, the read_time functions
> + * need to be changed to interpret wrapped times as post-2040.
> + */
>  #define RTC_OFFSET     2082844800
>
>  /*
> @@ -97,8 +101,11 @@ static time64_t cuda_get_time(void)
>         if (req.reply_len != 7)
>                 printk(KERN_ERR "cuda_get_time: got %d byte reply\n",
>                        req.reply_len);
> -       now = (req.reply[3] << 24) + (req.reply[4] << 16)
> -               + (req.reply[5] << 8) + req.reply[6];
> +       now = (u32)((req.reply[3] << 24) + (req.reply[4] << 16) +
> +                   (req.reply[5] << 8) + req.reply[6]);
> +       /* it's either after year 2040, or the RTC has gone backwards */
> +       WARN_ON(now < RTC_OFFSET);
> +
>         return now - RTC_OFFSET;
>  }
>
> @@ -140,8 +147,12 @@ static time64_t pmu_get_time(void)
>         if (req.reply_len != 4)
>                 printk(KERN_ERR "pmu_get_time: got %d byte reply from PMU\n",
>                        req.reply_len);
> -       now = (req.reply[0] << 24) + (req.reply[1] << 16)
> -               + (req.reply[2] << 8) + req.reply[3];
> +       now = (u32)((req.reply[0] << 24) + (req.reply[1] << 16) +
> +                   (req.reply[2] << 8) + req.reply[3]);
> +
> +       /* it's either after year 2040, or the RTC has gone backwards */
> +       WARN_ON(now < RTC_OFFSET);
> +
>         return now - RTC_OFFSET;
>  }

Sadly, trying again today does not work anymore. Adding some printk
just before WARN_ON:

+printk(KERN_ERR " rtc DBG pmu_get_time1: %lld %d %lld \n", now,
RTC_OFFSET, now - RTC_OFFSET );
+printk(KERN_ERR " rtc DBG pmu_get_time2: %x %x %x %x %d \n",
req.reply[0], req.reply[1], req.reply[2], req.reply[3] ,
req.reply_len);

leads to:

[    0.000000]  rtc DBG pmu_get_time1: 14096662 2082844800 -2068748138
[    0.000000]  rtc DBG pmu_get_time2: 0 d7 19 16 4
[    0.000000] WARNING: CPU: 0 PID: 0 at
../arch/powerpc/platforms/powermac/time.c:158 pmu_get_time+0x11c/0x16c
[    0.000000] Modules linked in:
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.17.0+ #8
[    0.000000] NIP:  c0035658 LR: c0035640 CTR: c00d4a5c
[    0.000000] REGS: c0cf7da0 TRAP: 0700   Not tainted  (4.17.0+)
[    0.000000] MSR:  00021032 <ME,IR,DR,RI>  CR: 84000848  XER: 00000000
[    0.000000]
               GPR00: c0035640 c0cf7e50 c0a41bd0 00000025 00000001
00000051 c0d56430 00000000
               GPR08: 00000051 00000001 c0aa4b38 00000004 24000842
00000000 ffbbf4c0 0013da1c
               GPR16: 0013da18 0013da20 00000000 00000000 00b81044
01696028 01697e02 40140000
               GPR24: 00000000 00d71000 c09debec dfff1120 000001a4
00d71916 ffffffff 84b16896
[    0.000000] NIP [c0035658] pmu_get_time+0x11c/0x16c
[    0.000000] LR [c0035640] pmu_get_time+0x104/0x16c
[    0.000000] Call Trace:
[    0.000000] [c0cf7e50] [c0035640] pmu_get_time+0x104/0x16c (unreliable)
[    0.000000] [c0cf7ed0] [c00113fc] read_persistent_clock64+0x78/0x1ac
[    0.000000] [c0cf7f30] [c09ad470] timekeeping_init+0x24/0x2f4
[    0.000000] [c0cf7fc0] [c09986f0] start_kernel+0x34c/0x490
[    0.000000] [c0cf7ff0] [00003444] 0x3444
[    0.000000] Instruction dump:
[    0.000000] 88e1002f 3863404c 88c1002e 88a1002d 8881002c 4809baf1
3d207c25 6129b07f
[    0.000000] 7f9d4840 39200001 409d0008 39200000 <0f090000> 4bffff20
3c60c0c1 7fe4fb78
[    0.000000] random: get_random_bytes called from
print_oops_end_marker+0x6c/0x90 with crng_init=0
[    0.000000] ---[ end trace 93a1b37c50fb7a33 ]---


and then later on :

[    5.535354]  rtc DBG pmu_get_time1: 14096667 2082844800 -2068748133
[    5.539988]  rtc DBG pmu_get_time2: 0 d7 19 1b 4
[    5.544477] WARNING: CPU: 0 PID: 1 at
../arch/powerpc/platforms/powermac/time.c:158 pmu_get_time+0x11c/0x16c
[    5.553536] Modules linked in:
[    5.558076] CPU: 0 PID: 1 Comm: swapper Tainted: G        W
4.17.0+ #8
[    5.562769] NIP:  c0035658 LR: c0035640 CTR: c00d4a5c
[    5.567437] REGS: df4e7a90 TRAP: 0700   Tainted: G        W
 (4.17.0+)
[    5.572201] MSR:  00029032 <EE,ME,IR,DR,RI>  CR: 88008288  XER: 00000000
[    5.577028]
               GPR00: c0035640 df4e7b40 df4e8000 00000025 00000001
00000344 00000400 00000000
               GPR08: 00000003 00000001 c0aa4b38 00000000 28008282
00000000 c09dfc4c c09dfc28
               GPR16: 00000690 c0aedae0 c0aee64c c0aecf50 00000054
c0ae7488 c0aea0f4 00000000
               GPR24: c0d70000 c0a85850 c086fc74 df4e7c5c df4e7ce8
00d7191b ffffffff 84b1689b
[    5.601871] NIP [c0035658] pmu_get_time+0x11c/0x16c
[    5.606952] LR [c0035640] pmu_get_time+0x104/0x16c
[    5.612042] Call Trace:
[    5.617079] [df4e7b40] [c0035640] pmu_get_time+0x104/0x16c (unreliable)
[    5.622297] [df4e7bc0] [c003572c] pmac_get_rtc_time+0x34/0x4c
[    5.627509] [df4e7bd0] [c001076c] rtc_generic_get_time+0x2c/0x40
[    5.632740] [df4e7be0] [c0611fb8] __rtc_read_time+0x70/0x13c
[    5.637977] [df4e7c00] [c06120f0] rtc_read_time+0x6c/0x130
[    5.643230] [df4e7c30] [c0613324] __rtc_read_alarm+0x34/0x684
[    5.648503] [df4e7ce0] [c060fe18] rtc_device_register+0x88/0x218
[    5.653804] [df4e7d40] [c061000c] devm_rtc_device_register+0x64/0xc4
[    5.659127] [df4e7d60] [c09d2630] generic_rtc_probe+0x50/0x78
[    5.664457] [df4e7d70] [c055eefc] platform_drv_probe+0xa8/0x128
[    5.669735] [df4e7d90] [c055a780] driver_probe_device+0x354/0x6fc
[    5.674905] [df4e7dd0] [c055acc8] __driver_attach+0x1a0/0x22c
[    5.679971] [df4e7df0] [c05565c8] bus_for_each_dev+0x84/0xdc
[    5.685017] [df4e7e20] [c0558e78] bus_add_driver+0x188/0x348
[    5.690021] [df4e7e40] [c055c20c] driver_register+0xa0/0x18c
[    5.694982] [df4e7e50] [c055f3a8] __platform_driver_probe+0x8c/0x198
[    5.699918] [df4e7e70] [c0005800] do_one_initcall+0x64/0x280
[    5.704726] [df4e7ee0] [c0998bd8] kernel_init_freeable+0x3a4/0x444
[    5.709433] [df4e7f30] [c00049f8] kernel_init+0x24/0x118
[    5.713995] [df4e7f40] [c001b1c4] ret_from_kernel_thread+0x14/0x1c
[    5.718536] Instruction dump:
[    5.723041] 88e1002f 3863404c 88c1002e 88a1002d 8881002c 4809baf1
3d207c25 6129b07f
[    5.727651] 7f9d4840 39200001 409d0008 39200000 <0f090000> 4bffff20
3c60c0c1 7fe4fb78
[    5.732196] ---[ end trace 93a1b37c50fb7a34 ]---
[    5.736768] ================================================================================
[    5.741519] UBSAN: Undefined behaviour in ../drivers/rtc/rtc-lib.c:87:22
[    5.746295] signed integer overflow:
[    5.751002] 1193026 * 3600 cannot be represented in type 'int'
[    5.755739] CPU: 0 PID: 1 Comm: swapper Tainted: G        W
4.17.0+ #8
[    5.760529] Call Trace:
[    5.765124] [df4e7b00] [c04817ec] ubsan_epilogue+0x18/0x4c (unreliable)
[    5.769871] [df4e7b10] [c048218c] handle_overflow+0xbc/0xdc
[    5.774580] [df4e7b90] [c060e27c] rtc_time64_to_tm+0x344/0x388
[    5.779264] [df4e7bd0] [c001076c] rtc_generic_get_time+0x2c/0x40
[    5.783841] [df4e7be0] [c0611fb8] __rtc_read_time+0x70/0x13c
[    5.788395] [df4e7c00] [c06120f0] rtc_read_time+0x6c/0x130
[    5.792929] [df4e7c30] [c0613324] __rtc_read_alarm+0x34/0x684
[    5.797415] [df4e7ce0] [c060fe18] rtc_device_register+0x88/0x218
[    5.801895] [df4e7d40] [c061000c] devm_rtc_device_register+0x64/0xc4
[    5.806395] [df4e7d60] [c09d2630] generic_rtc_probe+0x50/0x78
[    5.810889] [df4e7d70] [c055eefc] platform_drv_probe+0xa8/0x128
[    5.815405] [df4e7d90] [c055a780] driver_probe_device+0x354/0x6fc
[    5.819929] [df4e7dd0] [c055acc8] __driver_attach+0x1a0/0x22c
[    5.824440] [df4e7df0] [c05565c8] bus_for_each_dev+0x84/0xdc
[    5.828922] [df4e7e20] [c0558e78] bus_add_driver+0x188/0x348
[    5.833366] [df4e7e40] [c055c20c] driver_register+0xa0/0x18c
[    5.837789] [df4e7e50] [c055f3a8] __platform_driver_probe+0x8c/0x198
[    5.842244] [df4e7e70] [c0005800] do_one_initcall+0x64/0x280
[    5.846700] [df4e7ee0] [c0998bd8] kernel_init_freeable+0x3a4/0x444
[    5.851186] [df4e7f30] [c00049f8] kernel_init+0x24/0x118
[    5.855656] [df4e7f40] [c001b1c4] ret_from_kernel_thread+0x14/0x1c
[    5.860171] ================================================================================
[    5.864998] device: 'rtc0': device_add



> --
> 2.9.0
>

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

* Re: [PATCH 1/3] powerpc: mac: fix rtc read functions
  2018-06-18 19:10 ` [PATCH 1/3] powerpc: mac: fix rtc read functions Mathieu Malaterre
@ 2018-06-18 20:04   ` Andreas Schwab
  2018-06-19  5:47     ` Mathieu Malaterre
  2018-06-19 10:18     ` Arnd Bergmann
  0 siblings, 2 replies; 9+ messages in thread
From: Andreas Schwab @ 2018-06-18 20:04 UTC (permalink / raw)
  To: Mathieu Malaterre
  Cc: Arnd Bergmann, Paul Mackerras, Michael Ellerman,
	Geert Uytterhoeven, funaho, Benjamin Herrenschmidt, gerg,
	linux-m68k, linuxppc-dev, LKML, y2038, Meelis Roos,
	Alexandre Belloni

On Jun 18 2018, Mathieu Malaterre <malat@debian.org> wrote:

> Sadly, trying again today does not work anymore. Adding some printk
> just before WARN_ON:
>
> +printk(KERN_ERR " rtc DBG pmu_get_time1: %lld %d %lld \n", now,
> RTC_OFFSET, now - RTC_OFFSET );
> +printk(KERN_ERR " rtc DBG pmu_get_time2: %x %x %x %x %d \n",
> req.reply[0], req.reply[1], req.reply[2], req.reply[3] ,
> req.reply_len);
>
> leads to:
>
> [    0.000000]  rtc DBG pmu_get_time1: 14096662 2082844800 -2068748138
> [    0.000000]  rtc DBG pmu_get_time2: 0 d7 19 16 4

A good value would have 0xd7 in the first byte.  The problem is that
pmu_set_rtc_time is also broken, and leads to an invalid time value
stored in the RTC.  Since pmu_request is a varargs function passing
values of type time64_t without casting won't work.

You need to reset your RTC before you can continue.

I think the right fix is to change nowtime in pmu_set_rtc_time and
cuda_set_rtc_time back to unsigned int (or to u32).

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

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

* Re: [PATCH 1/3] powerpc: mac: fix rtc read functions
  2018-06-18 20:04   ` Andreas Schwab
@ 2018-06-19  5:47     ` Mathieu Malaterre
  2018-06-19 10:18     ` Arnd Bergmann
  1 sibling, 0 replies; 9+ messages in thread
From: Mathieu Malaterre @ 2018-06-19  5:47 UTC (permalink / raw)
  To: schwab
  Cc: Arnd Bergmann, Paul Mackerras, Michael Ellerman,
	Geert Uytterhoeven, funaho, Benjamin Herrenschmidt, gerg,
	linux-m68k, linuxppc-dev, LKML, y2038, Meelis Roos,
	Alexandre Belloni

On Mon, Jun 18, 2018 at 10:04 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Jun 18 2018, Mathieu Malaterre <malat@debian.org> wrote:
>
> > Sadly, trying again today does not work anymore. Adding some printk
> > just before WARN_ON:
> >
> > +printk(KERN_ERR " rtc DBG pmu_get_time1: %lld %d %lld \n", now,
> > RTC_OFFSET, now - RTC_OFFSET );
> > +printk(KERN_ERR " rtc DBG pmu_get_time2: %x %x %x %x %d \n",
> > req.reply[0], req.reply[1], req.reply[2], req.reply[3] ,
> > req.reply_len);
> >
> > leads to:
> >
> > [    0.000000]  rtc DBG pmu_get_time1: 14096662 2082844800 -2068748138
> > [    0.000000]  rtc DBG pmu_get_time2: 0 d7 19 16 4
>
> A good value would have 0xd7 in the first byte.  The problem is that
> pmu_set_rtc_time is also broken, and leads to an invalid time value
> stored in the RTC.  Since pmu_request is a varargs function passing
> values of type time64_t without casting won't work.
>
> You need to reset your RTC before you can continue.

Indeed that was silly, I was not paying attention. I'll try again tonight.

> I think the right fix is to change nowtime in pmu_set_rtc_time and
> cuda_set_rtc_time back to unsigned int (or to u32).
>
> Andreas.
>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."

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

* Re: [PATCH 1/3] powerpc: mac: fix rtc read functions
  2018-06-18 20:04   ` Andreas Schwab
  2018-06-19  5:47     ` Mathieu Malaterre
@ 2018-06-19 10:18     ` Arnd Bergmann
  1 sibling, 0 replies; 9+ messages in thread
From: Arnd Bergmann @ 2018-06-19 10:18 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Mathieu Malaterre, Paul Mackerras, Michael Ellerman,
	Geert Uytterhoeven, funaho, Benjamin Herrenschmidt, Greg Ungerer,
	linux-m68k, linuxppc-dev, LKML, y2038 Mailman List, Meelis Roos,
	Alexandre Belloni

On Mon, Jun 18, 2018 at 10:04 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> On Jun 18 2018, Mathieu Malaterre <malat@debian.org> wrote:
>
>> Sadly, trying again today does not work anymore. Adding some printk
>> just before WARN_ON:
>>
>> +printk(KERN_ERR " rtc DBG pmu_get_time1: %lld %d %lld \n", now,
>> RTC_OFFSET, now - RTC_OFFSET );
>> +printk(KERN_ERR " rtc DBG pmu_get_time2: %x %x %x %x %d \n",
>> req.reply[0], req.reply[1], req.reply[2], req.reply[3] ,
>> req.reply_len);
>>
>> leads to:
>>
>> [    0.000000]  rtc DBG pmu_get_time1: 14096662 2082844800 -2068748138
>> [    0.000000]  rtc DBG pmu_get_time2: 0 d7 19 16 4
>
> A good value would have 0xd7 in the first byte.  The problem is that
> pmu_set_rtc_time is also broken, and leads to an invalid time value
> stored in the RTC.  Since pmu_request is a varargs function passing
> values of type time64_t without casting won't work.
>
> You need to reset your RTC before you can continue.
>
> I think the right fix is to change nowtime in pmu_set_rtc_time and
> cuda_set_rtc_time back to unsigned int (or to u32).

Thanks for the additional analysis. I'll do it like you suggest and send
an updated patch.

       Arnd

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

* Re: [PATCH 3/3] m68k: remove unused set_clock_mmss() helpers
  2018-06-18 14:05 ` [PATCH 3/3] m68k: remove unused set_clock_mmss() helpers Arnd Bergmann
@ 2018-06-19 13:07   ` Greg Ungerer
  0 siblings, 0 replies; 9+ messages in thread
From: Greg Ungerer @ 2018-06-19 13:07 UTC (permalink / raw)
  To: Arnd Bergmann, Paul Mackerras, Michael Ellerman,
	Geert Uytterhoeven, Joshua Thompson
  Cc: Mathieu Malaterre, Benjamin Herrenschmidt, linux-m68k,
	linuxppc-dev, linux-kernel, y2038, Meelis Roos

Hi Arnd,

On 19/06/18 00:05, Arnd Bergmann wrote:
> Commit 397ac99c6cef ("m68k: remove dead timer code") removed set_rtc_mmss()
> because it was unused in 2012. However, this was itself the only user of the
> mach_set_clock_mmss() callback and the many implementations of that callback,
> which are equally unused.
> 
> This removes all of those as well.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

This looks good to me:

Acked-by: Greg Ungerer <gerg@linux-m68k.org>

Regards
Greg


> ---
>   arch/m68k/apollo/config.c       |  8 ------
>   arch/m68k/atari/config.c        |  5 ----
>   arch/m68k/atari/time.c          | 63 -----------------------------------------
>   arch/m68k/bvme6000/config.c     | 45 -----------------------------
>   arch/m68k/include/asm/machdep.h |  1 -
>   arch/m68k/kernel/setup_mm.c     |  1 -
>   arch/m68k/kernel/setup_no.c     |  1 -
>   arch/m68k/mac/config.c          |  2 --
>   arch/m68k/mac/misc.c            | 16 -----------
>   arch/m68k/mvme147/config.c      |  7 -----
>   arch/m68k/mvme16x/config.c      |  8 ------
>   arch/m68k/q40/config.c          | 30 --------------------
>   12 files changed, 187 deletions(-)
> 
> diff --git a/arch/m68k/apollo/config.c b/arch/m68k/apollo/config.c
> index b2a6bc63f8cd..aef8d42e078d 100644
> --- a/arch/m68k/apollo/config.c
> +++ b/arch/m68k/apollo/config.c
> @@ -31,7 +31,6 @@ extern void dn_sched_init(irq_handler_t handler);
>   extern void dn_init_IRQ(void);
>   extern u32 dn_gettimeoffset(void);
>   extern int dn_dummy_hwclk(int, struct rtc_time *);
> -extern int dn_dummy_set_clock_mmss(unsigned long);
>   extern void dn_dummy_reset(void);
>   #ifdef CONFIG_HEARTBEAT
>   static void dn_heartbeat(int on);
> @@ -156,7 +155,6 @@ void __init config_apollo(void)
>   	arch_gettimeoffset   = dn_gettimeoffset;
>   	mach_max_dma_address = 0xffffffff;
>   	mach_hwclk           = dn_dummy_hwclk; /* */
> -	mach_set_clock_mmss  = dn_dummy_set_clock_mmss; /* */
>   	mach_reset	     = dn_dummy_reset;  /* */
>   #ifdef CONFIG_HEARTBEAT
>   	mach_heartbeat = dn_heartbeat;
> @@ -240,12 +238,6 @@ int dn_dummy_hwclk(int op, struct rtc_time *t) {
>   
>   }
>   
> -int dn_dummy_set_clock_mmss(unsigned long nowtime)
> -{
> -	pr_info("set_clock_mmss\n");
> -	return 0;
> -}
> -
>   void dn_dummy_reset(void) {
>   
>     dn_serial_print("The end !\n");
> diff --git a/arch/m68k/atari/config.c b/arch/m68k/atari/config.c
> index 565c6f06ab0b..bd96702a1ad0 100644
> --- a/arch/m68k/atari/config.c
> +++ b/arch/m68k/atari/config.c
> @@ -81,9 +81,6 @@ extern void atari_sched_init(irq_handler_t);
>   extern u32 atari_gettimeoffset(void);
>   extern int atari_mste_hwclk (int, struct rtc_time *);
>   extern int atari_tt_hwclk (int, struct rtc_time *);
> -extern int atari_mste_set_clock_mmss (unsigned long);
> -extern int atari_tt_set_clock_mmss (unsigned long);
> -
>   
>   /* ++roman: This is a more elaborate test for an SCC chip, since the plain
>    * Medusa board generates DTACK at the SCC's standard addresses, but a SCC
> @@ -362,13 +359,11 @@ void __init config_atari(void)
>   		ATARIHW_SET(TT_CLK);
>   		pr_cont(" TT_CLK");
>   		mach_hwclk = atari_tt_hwclk;
> -		mach_set_clock_mmss = atari_tt_set_clock_mmss;
>   	}
>   	if (hwreg_present(&mste_rtc.sec_ones)) {
>   		ATARIHW_SET(MSTE_CLK);
>   		pr_cont(" MSTE_CLK");
>   		mach_hwclk = atari_mste_hwclk;
> -		mach_set_clock_mmss = atari_mste_set_clock_mmss;
>   	}
>   	if (!MACH_IS_MEDUSA && hwreg_present(&dma_wd.fdc_speed) &&
>   	    hwreg_write(&dma_wd.fdc_speed, 0)) {
> diff --git a/arch/m68k/atari/time.c b/arch/m68k/atari/time.c
> index c549b48174ec..9cca64286464 100644
> --- a/arch/m68k/atari/time.c
> +++ b/arch/m68k/atari/time.c
> @@ -285,69 +285,6 @@ int atari_tt_hwclk( int op, struct rtc_time *t )
>       return( 0 );
>   }
>   
> -
> -int atari_mste_set_clock_mmss (unsigned long nowtime)
> -{
> -    short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
> -    struct MSTE_RTC val;
> -    unsigned char rtc_minutes;
> -
> -    mste_read(&val);
> -    rtc_minutes= val.min_ones + val.min_tens * 10;
> -    if ((rtc_minutes < real_minutes
> -         ? real_minutes - rtc_minutes
> -         : rtc_minutes - real_minutes) < 30)
> -    {
> -        val.sec_ones = real_seconds % 10;
> -        val.sec_tens = real_seconds / 10;
> -        val.min_ones = real_minutes % 10;
> -        val.min_tens = real_minutes / 10;
> -        mste_write(&val);
> -    }
> -    else
> -        return -1;
> -    return 0;
> -}
> -
> -int atari_tt_set_clock_mmss (unsigned long nowtime)
> -{
> -    int retval = 0;
> -    short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
> -    unsigned char save_control, save_freq_select, rtc_minutes;
> -
> -    save_control = RTC_READ (RTC_CONTROL); /* tell the clock it's being set */
> -    RTC_WRITE (RTC_CONTROL, save_control | RTC_SET);
> -
> -    save_freq_select = RTC_READ (RTC_FREQ_SELECT); /* stop and reset prescaler */
> -    RTC_WRITE (RTC_FREQ_SELECT, save_freq_select | RTC_DIV_RESET2);
> -
> -    rtc_minutes = RTC_READ (RTC_MINUTES);
> -    if (!(save_control & RTC_DM_BINARY))
> -	rtc_minutes = bcd2bin(rtc_minutes);
> -
> -    /* Since we're only adjusting minutes and seconds, don't interfere
> -       with hour overflow.  This avoids messing with unknown time zones
> -       but requires your RTC not to be off by more than 30 minutes.  */
> -    if ((rtc_minutes < real_minutes
> -         ? real_minutes - rtc_minutes
> -         : rtc_minutes - real_minutes) < 30)
> -        {
> -            if (!(save_control & RTC_DM_BINARY))
> -                {
> -		    real_seconds = bin2bcd(real_seconds);
> -		    real_minutes = bin2bcd(real_minutes);
> -                }
> -            RTC_WRITE (RTC_SECONDS, real_seconds);
> -            RTC_WRITE (RTC_MINUTES, real_minutes);
> -        }
> -    else
> -        retval = -1;
> -
> -    RTC_WRITE (RTC_FREQ_SELECT, save_freq_select);
> -    RTC_WRITE (RTC_CONTROL, save_control);
> -    return retval;
> -}
> -
>   /*
>    * Local variables:
>    *  c-indent-level: 4
> diff --git a/arch/m68k/bvme6000/config.c b/arch/m68k/bvme6000/config.c
> index 2cfff4765040..143ee9fa3893 100644
> --- a/arch/m68k/bvme6000/config.c
> +++ b/arch/m68k/bvme6000/config.c
> @@ -41,7 +41,6 @@ static void bvme6000_get_model(char *model);
>   extern void bvme6000_sched_init(irq_handler_t handler);
>   extern u32 bvme6000_gettimeoffset(void);
>   extern int bvme6000_hwclk (int, struct rtc_time *);
> -extern int bvme6000_set_clock_mmss (unsigned long);
>   extern void bvme6000_reset (void);
>   void bvme6000_set_vectors (void);
>   
> @@ -113,7 +112,6 @@ void __init config_bvme6000(void)
>       mach_init_IRQ        = bvme6000_init_IRQ;
>       arch_gettimeoffset   = bvme6000_gettimeoffset;
>       mach_hwclk           = bvme6000_hwclk;
> -    mach_set_clock_mmss	 = bvme6000_set_clock_mmss;
>       mach_reset		 = bvme6000_reset;
>       mach_get_model       = bvme6000_get_model;
>   
> @@ -305,46 +303,3 @@ int bvme6000_hwclk(int op, struct rtc_time *t)
>   
>   	return 0;
>   }
> -
> -/*
> - * Set the minutes and seconds from seconds value 'nowtime'.  Fail if
> - * clock is out by > 30 minutes.  Logic lifted from atari code.
> - * Algorithm is to wait for the 10ms register to change, and then to
> - * wait a short while, and then set it.
> - */
> -
> -int bvme6000_set_clock_mmss (unsigned long nowtime)
> -{
> -	int retval = 0;
> -	short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
> -	unsigned char rtc_minutes, rtc_tenms;
> -	volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
> -	unsigned char msr = rtc->msr & 0xc0;
> -	unsigned long flags;
> -	volatile int i;
> -
> -	rtc->msr = 0;		/* Ensure clock accessible */
> -	rtc_minutes = bcd2bin (rtc->bcd_min);
> -
> -	if ((rtc_minutes < real_minutes
> -		? real_minutes - rtc_minutes
> -			: rtc_minutes - real_minutes) < 30)
> -	{
> -		local_irq_save(flags);
> -		rtc_tenms = rtc->bcd_tenms;
> -		while (rtc_tenms == rtc->bcd_tenms)
> -			;
> -		for (i = 0; i < 1000; i++)
> -			;
> -		rtc->bcd_min = bin2bcd(real_minutes);
> -		rtc->bcd_sec = bin2bcd(real_seconds);
> -		local_irq_restore(flags);
> -	}
> -	else
> -		retval = -1;
> -
> -	rtc->msr = msr;
> -
> -	return retval;
> -}
> -
> diff --git a/arch/m68k/include/asm/machdep.h b/arch/m68k/include/asm/machdep.h
> index 1605da48ebf2..49bd3266b4b1 100644
> --- a/arch/m68k/include/asm/machdep.h
> +++ b/arch/m68k/include/asm/machdep.h
> @@ -22,7 +22,6 @@ extern int (*mach_hwclk)(int, struct rtc_time*);
>   extern unsigned int (*mach_get_ss)(void);
>   extern int (*mach_get_rtc_pll)(struct rtc_pll_info *);
>   extern int (*mach_set_rtc_pll)(struct rtc_pll_info *);
> -extern int (*mach_set_clock_mmss)(unsigned long);
>   extern void (*mach_reset)( void );
>   extern void (*mach_halt)( void );
>   extern void (*mach_power_off)( void );
> diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
> index f35e3ebd6331..07244732eb41 100644
> --- a/arch/m68k/kernel/setup_mm.c
> +++ b/arch/m68k/kernel/setup_mm.c
> @@ -88,7 +88,6 @@ void (*mach_get_hardware_list) (struct seq_file *m);
>   /* machine dependent timer functions */
>   int (*mach_hwclk) (int, struct rtc_time*);
>   EXPORT_SYMBOL(mach_hwclk);
> -int (*mach_set_clock_mmss) (unsigned long);
>   unsigned int (*mach_get_ss)(void);
>   int (*mach_get_rtc_pll)(struct rtc_pll_info *);
>   int (*mach_set_rtc_pll)(struct rtc_pll_info *);
> diff --git a/arch/m68k/kernel/setup_no.c b/arch/m68k/kernel/setup_no.c
> index a98af1018201..3c53e4c366ac 100644
> --- a/arch/m68k/kernel/setup_no.c
> +++ b/arch/m68k/kernel/setup_no.c
> @@ -51,7 +51,6 @@ char __initdata command_line[COMMAND_LINE_SIZE];
>   
>   /* machine dependent timer functions */
>   void (*mach_sched_init)(irq_handler_t handler) __initdata = NULL;
> -int (*mach_set_clock_mmss)(unsigned long);
>   int (*mach_hwclk) (int, struct rtc_time*);
>   
>   /* machine dependent reboot functions */
> diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
> index e522307db47c..da1aeb966474 100644
> --- a/arch/m68k/mac/config.c
> +++ b/arch/m68k/mac/config.c
> @@ -57,7 +57,6 @@ static unsigned long mac_orig_videoaddr;
>   /* Mac specific timer functions */
>   extern u32 mac_gettimeoffset(void);
>   extern int mac_hwclk(int, struct rtc_time *);
> -extern int mac_set_clock_mmss(unsigned long);
>   extern void iop_preinit(void);
>   extern void iop_init(void);
>   extern void via_init(void);
> @@ -158,7 +157,6 @@ void __init config_mac(void)
>   	mach_get_model = mac_get_model;
>   	arch_gettimeoffset = mac_gettimeoffset;
>   	mach_hwclk = mac_hwclk;
> -	mach_set_clock_mmss = mac_set_clock_mmss;
>   	mach_reset = mac_reset;
>   	mach_halt = mac_poweroff;
>   	mach_power_off = mac_poweroff;
> diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
> index b399a0809e18..b0dda5cb9e48 100644
> --- a/arch/m68k/mac/misc.c
> +++ b/arch/m68k/mac/misc.c
> @@ -735,19 +735,3 @@ int mac_hwclk(int op, struct rtc_time *t)
>   	}
>   	return 0;
>   }
> -
> -/*
> - * Set minutes/seconds in the hardware clock
> - */
> -
> -int mac_set_clock_mmss (unsigned long nowtime)
> -{
> -	struct rtc_time now;
> -
> -	mac_hwclk(0, &now);
> -	now.tm_sec = nowtime % 60;
> -	now.tm_min = (nowtime / 60) % 60;
> -	mac_hwclk(1, &now);
> -
> -	return 0;
> -}
> diff --git a/arch/m68k/mvme147/config.c b/arch/m68k/mvme147/config.c
> index f8a710fd84cd..adea549d240e 100644
> --- a/arch/m68k/mvme147/config.c
> +++ b/arch/m68k/mvme147/config.c
> @@ -40,7 +40,6 @@ static void mvme147_get_model(char *model);
>   extern void mvme147_sched_init(irq_handler_t handler);
>   extern u32 mvme147_gettimeoffset(void);
>   extern int mvme147_hwclk (int, struct rtc_time *);
> -extern int mvme147_set_clock_mmss (unsigned long);
>   extern void mvme147_reset (void);
>   
>   
> @@ -92,7 +91,6 @@ void __init config_mvme147(void)
>   	mach_init_IRQ		= mvme147_init_IRQ;
>   	arch_gettimeoffset	= mvme147_gettimeoffset;
>   	mach_hwclk		= mvme147_hwclk;
> -	mach_set_clock_mmss	= mvme147_set_clock_mmss;
>   	mach_reset		= mvme147_reset;
>   	mach_get_model		= mvme147_get_model;
>   
> @@ -164,8 +162,3 @@ int mvme147_hwclk(int op, struct rtc_time *t)
>   	}
>   	return 0;
>   }
> -
> -int mvme147_set_clock_mmss (unsigned long nowtime)
> -{
> -	return 0;
> -}
> diff --git a/arch/m68k/mvme16x/config.c b/arch/m68k/mvme16x/config.c
> index 4ffd9ef98de4..6ee36a5b528d 100644
> --- a/arch/m68k/mvme16x/config.c
> +++ b/arch/m68k/mvme16x/config.c
> @@ -46,7 +46,6 @@ static void mvme16x_get_model(char *model);
>   extern void mvme16x_sched_init(irq_handler_t handler);
>   extern u32 mvme16x_gettimeoffset(void);
>   extern int mvme16x_hwclk (int, struct rtc_time *);
> -extern int mvme16x_set_clock_mmss (unsigned long);
>   extern void mvme16x_reset (void);
>   
>   int bcd2int (unsigned char b);
> @@ -280,7 +279,6 @@ void __init config_mvme16x(void)
>       mach_init_IRQ        = mvme16x_init_IRQ;
>       arch_gettimeoffset   = mvme16x_gettimeoffset;
>       mach_hwclk           = mvme16x_hwclk;
> -    mach_set_clock_mmss	 = mvme16x_set_clock_mmss;
>       mach_reset		 = mvme16x_reset;
>       mach_get_model       = mvme16x_get_model;
>       mach_get_hardware_list = mvme16x_get_hardware_list;
> @@ -411,9 +409,3 @@ int mvme16x_hwclk(int op, struct rtc_time *t)
>   	}
>   	return 0;
>   }
> -
> -int mvme16x_set_clock_mmss (unsigned long nowtime)
> -{
> -	return 0;
> -}
> -
> diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c
> index 71c0867ecf20..96810d91da2b 100644
> --- a/arch/m68k/q40/config.c
> +++ b/arch/m68k/q40/config.c
> @@ -43,7 +43,6 @@ extern void q40_sched_init(irq_handler_t handler);
>   static u32 q40_gettimeoffset(void);
>   static int q40_hwclk(int, struct rtc_time *);
>   static unsigned int q40_get_ss(void);
> -static int q40_set_clock_mmss(unsigned long);
>   static int q40_get_rtc_pll(struct rtc_pll_info *pll);
>   static int q40_set_rtc_pll(struct rtc_pll_info *pll);
>   
> @@ -175,7 +174,6 @@ void __init config_q40(void)
>   	mach_get_ss = q40_get_ss;
>   	mach_get_rtc_pll = q40_get_rtc_pll;
>   	mach_set_rtc_pll = q40_set_rtc_pll;
> -	mach_set_clock_mmss = q40_set_clock_mmss;
>   
>   	mach_reset = q40_reset;
>   	mach_get_model = q40_get_model;
> @@ -267,34 +265,6 @@ static unsigned int q40_get_ss(void)
>   	return bcd2bin(Q40_RTC_SECS);
>   }
>   
> -/*
> - * Set the minutes and seconds from seconds value 'nowtime'.  Fail if
> - * clock is out by > 30 minutes.  Logic lifted from atari code.
> - */
> -
> -static int q40_set_clock_mmss(unsigned long nowtime)
> -{
> -	int retval = 0;
> -	short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
> -
> -	int rtc_minutes;
> -
> -	rtc_minutes = bcd2bin(Q40_RTC_MINS);
> -
> -	if ((rtc_minutes < real_minutes ?
> -	     real_minutes - rtc_minutes :
> -	     rtc_minutes - real_minutes) < 30) {
> -		Q40_RTC_CTRL |= Q40_RTC_WRITE;
> -		Q40_RTC_MINS = bin2bcd(real_minutes);
> -		Q40_RTC_SECS = bin2bcd(real_seconds);
> -		Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
> -	} else
> -		retval = -1;
> -
> -	return retval;
> -}
> -
> -
>   /* get and set PLL calibration of RTC clock */
>   #define Q40_RTC_PLL_MASK ((1<<5)-1)
>   #define Q40_RTC_PLL_SIGN (1<<5)
> 

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

end of thread, other threads:[~2018-06-19 13:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-18 14:05 [PATCH 1/3] powerpc: mac: fix rtc read functions Arnd Bergmann
2018-06-18 14:05 ` [PATCH 2/3] m68k: mac: use time64_t in RTC handling Arnd Bergmann
2018-06-18 16:55   ` kbuild test robot
2018-06-18 14:05 ` [PATCH 3/3] m68k: remove unused set_clock_mmss() helpers Arnd Bergmann
2018-06-19 13:07   ` Greg Ungerer
2018-06-18 19:10 ` [PATCH 1/3] powerpc: mac: fix rtc read functions Mathieu Malaterre
2018-06-18 20:04   ` Andreas Schwab
2018-06-19  5:47     ` Mathieu Malaterre
2018-06-19 10:18     ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).