Skip to contentSkip to conversation

MIPS: IP32: Add platform data hooks to use DS1685 driver

PATCH In review Joshua Kinard 2 participants 3 messages Feb 27, 2015 – Apr 1, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 MIPS: IP32: Add platform data hooks to use DS1685 driver

From: Joshua Kinard <[email protected]>

This modifies the IP32 (SGI O2) platform and reset code to utilize the new rtc-ds1685 driver. The old mc146818rtc.h header is removed and ip32_defconfig is updated as well.

---
 arch/mips/configs/ip32_defconfig              |    3
 arch/mips/include/asm/mach-ip32/mc146818rtc.h |   36 ----
 arch/mips/sgi-ip32/ip32-platform.c            |   52 +++++-
 arch/mips/sgi-ip32/ip32-reset.c               |  132 ++++------------
 4 files changed, 85 insertions(+), 138 deletions(-)

Ralf,
This is a re-spin due to the recent commit efc46d13 in ip32-reset.c ("Use
__noreturn instead of open coded attributes in declarations."). Those declarations are removed by this patch, since the poweroff mechanism of the rtc-ds1685 driver is used instead on SGI O2. rtc-ds1685 is in linux-next now, so this one can be added at your convenience.

linux-mips-ip32-use-rtc-ds1685.patch

arch/mips/configs/ip32_defconfig +2 -1
index 70ffe9b..fe48220 100644
@@ -105,7 +105,8 @@ CONFIG_RTC_CLASS=y
 # CONFIG_RTC_HCTOSYS is not set
 # CONFIG_RTC_INTF_SYSFS is not set
 # CONFIG_RTC_INTF_PROC is not set
-CONFIG_RTC_DRV_CMOS=y
+CONFIG_RTC_DRV_DS1685_FAMILY=y
+CONFIG_RTC_DRV_DS1685=y
 CONFIG_EXT2_FS=y
 CONFIG_EXT2_FS_XATTR=y
 CONFIG_EXT2_FS_POSIX_ACL=y
arch/mips/include/asm/mach-ip32/mc146818rtc.h deleted +0 -36
deleted file mode 100644
index 6b6bab4..0000000
@@ -1,36 +0,0 @@
-/*
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file "COPYING" in the main directory of this archive
- * for more details.
- *
- * Copyright (C) 1998, 2001, 03 by Ralf Baechle
- * Copyright (C) 2000 Harald Koerfgen
- *
- * RTC routines for IP32 style attached Dallas chip.
- */
-#ifndef __ASM_MACH_IP32_MC146818RTC_H
-#define __ASM_MACH_IP32_MC146818RTC_H
-
-#include <asm/ip32/mace.h>
-
-#define RTC_PORT(x)	(0x70 + (x))
-
-static unsigned char CMOS_READ(unsigned long addr)
-{
-	return mace->isa.rtc[addr << 8];
-}
-
-static inline void CMOS_WRITE(unsigned char data, unsigned long addr)
-{
-	mace->isa.rtc[addr << 8] = data;
-}
-
-/*
- * FIXME: Do it right. For now just assume that no one lives in 20th century
- * and no O2 user in 22th century ;-)
- */
-#define mc146818_decode_year(year) ((year) + 2000)
-
-#define RTC_ALWAYS_BCD	0
-
-#endif /* __ASM_MACH_IP32_MC146818RTC_H */
arch/mips/sgi-ip32/ip32-platform.c +43 -9

75 lines not on this page · raw message

arch/mips/sgi-ip32/ip32-reset.c +40 -92

189 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · Joshua Kinard

This modifies the IP32 (SGI O2) platform and reset code to utilize the new rtc-ds1685 driver. The old mc146818rtc.h header is removed and ip32_defconfig is updated as well.

In general - good cleanup. But:

Quoted 3 lines

index 511e9ff..ec9eb7f 100644

arch/mips/sgi-ip32/ip32-platform.c +0 -0

[...]

arch/mips/sgi-ip32/ip32-platform.c static __init int sgio2btns_devinit(void) · line 145

Quoted 4 lines

MODULE_AUTHOR("Ralf Baechle <[email protected]>"); MODULE_LICENSE("GPL");

arch/mips/sgi-ip32/ip32-platform.c +1 -1
-MODULE_DESCRIPTION("8250 UART probe driver for SGI IP32 aka O2");
+MODULE_DESCRIPTION("IP32 platform setup for SGI IP32 aka O2");

This isn't even a kernel module so I've just nuked all these MODULE_* calls.

Quoted 4 lines
arch/mips/sgi-ip32/ip32-reset.c +0 -0
index 44b3470..ef21706 100644

[...]

Quoted 6 lines
arch/mips/sgi-ip32/ip32-reset.c +1 -4
-static void ip32_machine_restart(char *cmd)
+static __noreturn void ip32_poweroff(void *data)
 {
-	crime->control = CRIME_CONTROL_HARD_RESET;
-	while (1);
-}

arch/mips/sgi-ip32/ip32-reset.c line 53

Quoted 10 lines
arch/mips/sgi-ip32/ip32-reset.c +10 -0
+	void (*poweroff_func)(struct platform_device *) =
+		symbol_get(ds1685_rtc_poweroff);
+
+#ifdef CONFIG_MODULES
+	/* If the first __symbol_get failed, our module wasn't loaded. */
+	if (!poweroff_func) {
+		request_module("rtc-ds1685");
+		poweroff_func = symbol_get(ds1685_rtc_poweroff);
+	}
+#endif

symbol_get() calls are high on my list of items that indicate a piece of code is probably ill-structured.

While RTCs often deal with power the RTC really only wants to deal with time and so power stuff should rather go elsewhere. I suggest to take a look at drivers/power/reset/. A small driver there could set pm_power_off approriately. drivers/power/reset/restart-poweroff.c is a very compact example.

arch/mips/sgi-ip32/ip32-reset.c static void blink_timeout(unsigned long data) · line 101

Quoted 2 lines
arch/mips/sgi-ip32/ip32-reset.c +1 -1
-	shuting_down = 1;
+	shutting_down = 1;

I'm amazed nobody of the church of speel patchology has caught this earlier.

arch/mips/sgi-ip32/ip32-reset.c static __init int ip32_reboot_setup(void) · line 144

Quoted 6 lines
arch/mips/sgi-ip32/ip32-reset.c +1 -1
@@ -190,15 +141,12 @@ static __init int ip32_reboot_setup(void)
 
 	_machine_restart = ip32_machine_restart;
 	_machine_halt = ip32_machine_halt;
-	pm_power_off = ip32_machine_power_off;
+	pm_power_off = ip32_machine_halt;

So halt and power_off no do the same?

Ralf

Signature · 9 lines
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#2 lore raw
Quoted 12 lines · Ralf Baechle
Quoted 3 lines · Joshua Kinard

This modifies the IP32 (SGI O2) platform and reset code to utilize the new rtc-ds1685 driver. The old mc146818rtc.h header is removed and ip32_defconfig is updated as well.

In general - good cleanup. But:

Quoted 3 lines

index 511e9ff..ec9eb7f 100644

arch/mips/sgi-ip32/ip32-platform.c +0 -0

[...]

Quoted 7 lines

arch/mips/sgi-ip32/ip32-platform.c static __init int sgio2btns_devinit(void) · line 145

Quoted 4 lines

MODULE_AUTHOR("Ralf Baechle <[email protected]>"); MODULE_LICENSE("GPL");

arch/mips/sgi-ip32/ip32-platform.c +1 -1
-MODULE_DESCRIPTION("8250 UART probe driver for SGI IP32 aka O2");
+MODULE_DESCRIPTION("IP32 platform setup for SGI IP32 aka O2");

This isn't even a kernel module so I've just nuked all these MODULE_* calls.

Works for me, thanks!

Quoted 16 lines
Quoted 4 lines
arch/mips/sgi-ip32/ip32-reset.c +0 -0
index 44b3470..ef21706 100644

[...]

Quoted 11 lines
arch/mips/sgi-ip32/ip32-reset.c +6 -4
-static void ip32_machine_restart(char *cmd)
+static __noreturn void ip32_poweroff(void *data)
 {
-	crime->control = CRIME_CONTROL_HARD_RESET;
-	while (1);
-}
+	void (*poweroff_func)(struct platform_device *) =
+		symbol_get(ds1685_rtc_poweroff);
+
+#ifdef CONFIG_MODULES
+	/* If the first __symbol_get failed, our module wasn't loaded. */
Quoted 8 lines

arch/mips/sgi-ip32/ip32-reset.c line 53

Quoted 5 lines
arch/mips/sgi-ip32/ip32-reset.c +5 -0
+	if (!poweroff_func) {
+		request_module("rtc-ds1685");
+		poweroff_func = symbol_get(ds1685_rtc_poweroff);
+	}
+#endif

symbol_get() calls are high on my list of items that indicate a piece of code is probably ill-structured.

That was the only function I could find that would attempt to fetch the ds1685_rtc_poweroff() function from kernel memory and return an indication of success or failure that could be checked. If there's a better way to do that, I'll be happy to re-write that section. I looked through the docs back then and couldn't find another way that worked with and without modules.

Quoted 5 lines

While RTCs often deal with power the RTC really only wants to deal with time and so power stuff should rather go elsewhere. I suggest to take a look at drivers/power/reset/. A small driver there could set pm_power_off approriately. drivers/power/reset/restart-poweroff.c is a very compact example.

Except this code is in a file called "ip32-reset.c", and the original code there did the exact same thing -- powered off the machine. The ds1685_rtc_poweroff() function is defined in the core DS1685 driver (drivers/rtc/rtc-ds1685.c) that got added to linux-next a few weeks ago (no one had any complaints about that). This code just checks to see if the RTC driver is loaded and then calls that function to power the machine down.

IP30 uses a similar setup as well, since both machines share the same RTC chip/family.

Quoted 9 lines

arch/mips/sgi-ip32/ip32-reset.c static __init int ip32_reboot_setup(void) · line 144

Quoted 6 lines
arch/mips/sgi-ip32/ip32-reset.c +1 -1
@@ -190,15 +141,12 @@ static __init int ip32_reboot_setup(void)
 
 	_machine_restart = ip32_machine_restart;
 	_machine_halt = ip32_machine_halt;
-	pm_power_off = ip32_machine_power_off;
+	pm_power_off = ip32_machine_halt;

So halt and power_off no do the same?

They always did. This is the original ip32_machine_halt function:

static inline void ip32_machine_halt(void)

{
       ip32_machine_power_off();
}

I just got rid of the added level of misdirection and set both _machine_halt and pm_power_off to call the same function (especially since there's no sleeping these kinds of machines -- maybe hibernate, but that'll still properly poweroff). Seemed the logical thing to do. In either case, it'll lead to the RTC driver handling the poweroff routine, which seems to be the only way SGI designed these machines to power off. I'll wager the ARCS firmware internally does the same thing.

Signature · 20 lines
Joshua Kinard
Gentoo/MIPS
[email protected]
4096R/D25D95E3 2011-03-28

"The past tempts us, the present confuses us, the future frightens us.  And our
lives slip away, moment by moment, lost in that vast, terrible in-between."

--Emperor Turhan, Centauri Republic

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.