All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] generic RTC support for PPC
@ 2007-01-25  7:37 Olof Johansson
  2007-01-30  5:17 ` Tom Rini
  2007-02-06 11:08 ` Paul Mackerras
  0 siblings, 2 replies; 15+ messages in thread
From: Olof Johansson @ 2007-01-25  7:37 UTC (permalink / raw)
  To: paulus; +Cc: linuxppc-dev, kimphill

Make the PPC RTC functions use the generic RTC infrastructure if they
are not already defined (and an RTC is registered in the system).

This should make it possible to remove the hideous direct access used
in some of the 83xx platforms.


Signed-off-by: Olof Johansson <olof@lixom.net>

Index: powerpc/arch/powerpc/Kconfig
===================================================================
--- powerpc.orig/arch/powerpc/Kconfig
+++ powerpc/arch/powerpc/Kconfig
@@ -687,6 +687,12 @@ config TAU_AVERAGE
 
 	  If in doubt, say N here.
 
+config PPC_GENRTC
+	bool "Generic RTC support"
+	help
+	  Support for using regular RTC registered with the RTC framework
+	  as the main hardware clock on powerpc.
+
 endmenu
 
 source arch/powerpc/platforms/embedded6xx/Kconfig
Index: powerpc/arch/powerpc/sysdev/Makefile
===================================================================
--- powerpc.orig/arch/powerpc/sysdev/Makefile
+++ powerpc/arch/powerpc/sysdev/Makefile
@@ -22,4 +22,5 @@ endif
 ifeq ($(ARCH),powerpc)
 obj-$(CONFIG_MTD)		+= rom.o
 obj-$(CONFIG_CPM2)		+= cpm2_common.o cpm2_pic.o
+obj-$(CONFIG_PPC_GENRTC)	+= genrtc.o
 endif
Index: powerpc/arch/powerpc/sysdev/genrtc.c
===================================================================
--- /dev/null
+++ powerpc/arch/powerpc/sysdev/genrtc.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) Olof Johansson <olof@lixom.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <linux/time.h>
+#include <linux/device.h>
+#include <linux/rtc.h>
+
+#include <asm/machdep.h>
+#include <asm/time.h>
+
+static struct class_device *rtc_dev;
+
+static void genrtc_set_rtc_time_work(struct work_struct *work);
+
+static struct rtc_time delayed_tm;
+static struct workqueue_struct *rtc_workqueue;
+static DECLARE_WORK(rtc_work, genrtc_set_rtc_time_work);
+
+static void genrtc_set_rtc_time_work(struct work_struct *work)
+{
+	rtc_set_time(rtc_dev, &delayed_tm);
+}
+
+static int genrtc_set_rtc_time(struct rtc_time *tm)
+{
+	if (in_interrupt()) {
+		/* Can't access RTC with interrupts off, since some of
+		 * the drivers might sleep. Delay the setting with a
+		 * work queue.
+		 */
+		memcpy(&delayed_tm, tm, sizeof(struct rtc_time));
+		queue_work(rtc_workqueue, &rtc_work);
+		return 0;
+	} else
+		return rtc_set_time(rtc_dev, tm);
+}
+
+static void genrtc_get_rtc_time(struct rtc_time *tm)
+{
+	rtc_read_time(rtc_dev, tm);
+}
+
+static int __init genrtc_rtc_hookup(void)
+{
+	/* Don't init if the platform has already set up rtc functions. */
+	if (ppc_md.get_rtc_time || ppc_md.set_rtc_time)
+		return -1;
+
+	rtc_dev = rtc_class_open("rtc0");
+
+	if (!rtc_dev) {
+		printk("genrtc_rtc_hookup: Failed to open rtc0\n");
+		return -1;
+	}
+
+	ppc_md.get_rtc_time = genrtc_get_rtc_time;
+	ppc_md.set_rtc_time = genrtc_set_rtc_time;
+
+	return 0;
+}
+late_initcall(genrtc_rtc_hookup);
+

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

end of thread, other threads:[~2007-02-07  1:55 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-25  7:37 [PATCH] generic RTC support for PPC Olof Johansson
2007-01-30  5:17 ` Tom Rini
2007-01-30  6:37   ` Kumar Gala
2007-01-30 16:03     ` Olof Johansson
2007-01-30 18:53       ` Tom Rini
2007-01-30 19:25       ` Kim Phillips
2007-01-30 19:25         ` Kim Phillips
2007-01-30 19:55         ` David Brownell
2007-01-30 19:55           ` David Brownell
2007-02-06 11:08 ` Paul Mackerras
2007-02-06 14:40   ` Kumar Gala
2007-02-06 15:24     ` Olof Johansson
2007-02-06 16:16       ` Kumar Gala
2007-02-07  1:55         ` Kim Phillips
2007-02-06 15:16   ` Olof Johansson

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.