From: Olof Johansson <olof@lixom.net>
To: paulus@samba.org
Cc: linuxppc-dev@ozlabs.org, kimphill@freescale.com
Subject: [PATCH] generic RTC support for PPC
Date: Thu, 25 Jan 2007 01:37:54 -0600 [thread overview]
Message-ID: <20070125073754.GA10004@lixom.net> (raw)
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);
+
next reply other threads:[~2007-01-25 7:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-25 7:37 Olof Johansson [this message]
2007-01-30 5:17 ` [PATCH] generic RTC support for PPC 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: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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070125073754.GA10004@lixom.net \
--to=olof@lixom.net \
--cc=kimphill@freescale.com \
--cc=linuxppc-dev@ozlabs.org \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).