* [PATCH 2.6] enable genrtc for MIPS
@ 2004-01-30 18:39 Jun Sun
2004-01-30 19:13 ` Maciej W. Rozycki
0 siblings, 1 reply; 6+ messages in thread
From: Jun Sun @ 2004-01-30 18:39 UTC (permalink / raw)
To: linux-mips; +Cc: jsun
[-- Attachment #1: Type: text/plain, Size: 529 bytes --]
genrtc.c is like mips-rtc.c we have in 2.4, except it is shared by
other arches and has more capabilities (such as emulated alarms)
This patch implements the arch-specific code for genrtc based on
MIPS's rtc_get_time() and rtc_set_time(), which are now implemented
by every MIPS board. This essentially means with this patch
every MIPS machine now has a working genrtc for free.
Of course, individual board is still free to choose the old rtc.c
or implement some peculiar ones of its own - although I can't see why. :)
Jun
[-- Attachment #2: mips-genrtc.patch --]
[-- Type: text/plain, Size: 3543 bytes --]
diff -Nru linux/arch/mips/kernel/Makefile.orig linux/arch/mips/kernel/Makefile
--- linux/arch/mips/kernel/Makefile.orig Mon Jan 5 10:33:35 2004
+++ linux/arch/mips/kernel/Makefile Fri Jan 30 10:29:07 2004
@@ -51,6 +51,8 @@
obj-$(CONFIG_MIPS64) += cpu-bugs64.o
+obj-$(CONFIG_GEN_RTC) += genrtc.o
+
CFLAGS_cpu-bugs64.o = $(shell if $(CC) $(CFLAGS) -Wa,-mdaddi -c -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-DHAVE_AS_SET_DADDI"; fi)
EXTRA_AFLAGS := $(CFLAGS)
diff -Nru linux/arch/mips/kernel/genrtc.c.orig linux/arch/mips/kernel/genrtc.c
--- linux/arch/mips/kernel/genrtc.c.orig Thu Jan 29 16:35:28 2004
+++ linux/arch/mips/kernel/genrtc.c Thu Jan 29 17:22:56 2004
@@ -0,0 +1,65 @@
+/*
+ * A glue layer that provides RTC read/write to drivers/char/genrtc.c driver
+ * based on MIPS internal RTC routines. It does take care locking
+ * issues so that we are SMP/Preemption safe.
+ *
+ * Copyright (C) 2004 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * Please read the COPYING file for all license details.
+ */
+
+#include <linux/config.h>
+#include <linux/spinlock.h>
+
+#include <asm/rtc.h>
+#include <asm/time.h>
+
+static spinlock_t mips_rtc_lock = SPIN_LOCK_UNLOCKED;
+
+unsigned int get_rtc_time(struct rtc_time *time)
+{
+ unsigned long nowtime;
+
+ spin_lock(&mips_rtc_lock);
+ nowtime = rtc_get_time();
+ to_tm(nowtime, time);
+ time->tm_year -= 1900;
+ spin_unlock(&mips_rtc_lock);
+
+ return RTC_24H;
+}
+
+int set_rtc_time(struct rtc_time *time)
+{
+ unsigned long nowtime;
+ int ret;
+
+ spin_lock(&mips_rtc_lock);
+ nowtime = mktime(time->tm_year+1900, time->tm_mon+1,
+ time->tm_mday, time->tm_hour, time->tm_min,
+ time->tm_sec);
+ ret = rtc_set_time(nowtime);
+ spin_unlock(&mips_rtc_lock);
+
+ return ret;
+}
+
+unsigned int get_rtc_ss(void)
+{
+ struct rtc_time h;
+
+ get_rtc_time(&h);
+ return h.tm_sec;
+}
+
+int get_rtc_pll(struct rtc_pll_info *pll)
+{
+ return -EINVAL;
+}
+
+int set_rtc_pll(struct rtc_pll_info *pll)
+{
+ return -EINVAL;
+}
+
diff -Nru linux/include/asm-mips/rtc.h.orig linux/include/asm-mips/rtc.h
--- linux/include/asm-mips/rtc.h.orig Thu Oct 31 08:35:52 2002
+++ linux/include/asm-mips/rtc.h Thu Jan 29 16:35:14 2004
@@ -1,10 +1,37 @@
-#ifndef _I386_RTC_H
-#define _I386_RTC_H
-
/*
- * x86 uses the default access methods for the RTC.
+ * include/asm-mips/rtc.h
+ *
+ * (Really an interface for drivers/char/genrtc.c)
+ *
+ * Copyright (C) 2004 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * Please read the COPYING file for all license details.
*/
-#include <asm-generic/rtc.h>
+#ifndef _MIPS_RTC_H
+#define _MIPS_RTC_H
+
+#ifdef __KERNEL__
+
+#include <linux/rtc.h>
+
+#define RTC_PIE 0x40 /* periodic interrupt enable */
+#define RTC_AIE 0x20 /* alarm interrupt enable */
+#define RTC_UIE 0x10 /* update-finished interrupt enable */
+/* some dummy definitions */
+#define RTC_BATT_BAD 0x100 /* battery bad */
+#define RTC_SQWE 0x08 /* enable square-wave output */
+#define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */
+#define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */
+#define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */
+
+unsigned int get_rtc_time(struct rtc_time *time);
+int set_rtc_time(struct rtc_time *time);
+unsigned int get_rtc_ss(void);
+int get_rtc_pll(struct rtc_pll_info *pll);
+int set_rtc_pll(struct rtc_pll_info *pll);
+
+#endif
#endif
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 2.6] enable genrtc for MIPS
2004-01-30 18:39 [PATCH 2.6] enable genrtc for MIPS Jun Sun
@ 2004-01-30 19:13 ` Maciej W. Rozycki
2004-02-01 11:30 ` Atsushi Nemoto
0 siblings, 1 reply; 6+ messages in thread
From: Maciej W. Rozycki @ 2004-01-30 19:13 UTC (permalink / raw)
To: Jun Sun; +Cc: linux-mips
On Fri, 30 Jan 2004, Jun Sun wrote:
> Of course, individual board is still free to choose the old rtc.c
> or implement some peculiar ones of its own - although I can't see why. :)
s/old/full-featured/
--
+ Maciej W. Rozycki, Technical University of Gdansk, Poland +
+--------------------------------------------------------------+
+ e-mail: macro@ds2.pg.gda.pl, PGP key available +
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2.6] enable genrtc for MIPS
2004-01-30 19:13 ` Maciej W. Rozycki
@ 2004-02-01 11:30 ` Atsushi Nemoto
2004-02-01 12:04 ` Geert Uytterhoeven
2004-02-02 21:19 ` Jun Sun
0 siblings, 2 replies; 6+ messages in thread
From: Atsushi Nemoto @ 2004-02-01 11:30 UTC (permalink / raw)
To: macro; +Cc: jsun, linux-mips
>>>>> On Fri, 30 Jan 2004 20:13:38 +0100 (CET), "Maciej W. Rozycki" <macro@ds2.pg.gda.pl> said:
>> Of course, individual board is still free to choose the old rtc.c
>> or implement some peculiar ones of its own - although I can't see
>> why. :)
macro> s/old/full-featured/
No, I suppose s/rtc/mips-rtc/ is what the original patch means.
By the way, with this patch, individual board can not implement it's
own genrtc routines. How about making gen_rtc_time, etc. pointer to
functions to allow overrides?
I think implementing rtc_get_time (mips specific) with get_rtc_time
(genrtc) is more efficient than implementing get_rtc_time with
rtc_get_time for most RTC chips.
---
Atsushi Nemoto
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2.6] enable genrtc for MIPS
2004-02-01 11:30 ` Atsushi Nemoto
@ 2004-02-01 12:04 ` Geert Uytterhoeven
2004-02-02 21:19 ` Jun Sun
1 sibling, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2004-02-01 12:04 UTC (permalink / raw)
To: Atsushi Nemoto; +Cc: Maciej W. Rozycki, jsun, Linux/MIPS Development
On Sun, 1 Feb 2004, Atsushi Nemoto wrote:
> I think implementing rtc_get_time (mips specific) with get_rtc_time
> (genrtc) is more efficient than implementing get_rtc_time with
> rtc_get_time for most RTC chips.
Indeed, that's what I noticed a while ago, too.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 2.6] enable genrtc for MIPS
2004-02-01 11:30 ` Atsushi Nemoto
2004-02-01 12:04 ` Geert Uytterhoeven
@ 2004-02-02 21:19 ` Jun Sun
2004-02-03 1:30 ` Atsushi Nemoto
1 sibling, 1 reply; 6+ messages in thread
From: Jun Sun @ 2004-02-02 21:19 UTC (permalink / raw)
To: Atsushi Nemoto; +Cc: macro, linux-mips, jsun
On Sun, Feb 01, 2004 at 08:30:05PM +0900, Atsushi Nemoto wrote:
>
> By the way, with this patch, individual board can not implement it's
> own genrtc routines. How about making gen_rtc_time, etc. pointer to
> functions to allow overrides?
>
Is this necessary? How about letting us wait until there is a sensible
need?
> I think implementing rtc_get_time (mips specific) with get_rtc_time
> (genrtc) is more efficient than implementing get_rtc_time with
> rtc_get_time for most RTC chips.
>
If I understand you correctly, you like to have board rtc read routines to
return a rtc structure instead of the unsigned long integer.
There are actually boards which makes the current implementation more efficient.
See vr4181.
In general, however, this is not a bad idea, just involving a lot more
board level changes. I think it deserves another patch or even debate.
Jun
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2.6] enable genrtc for MIPS
2004-02-02 21:19 ` Jun Sun
@ 2004-02-03 1:30 ` Atsushi Nemoto
0 siblings, 0 replies; 6+ messages in thread
From: Atsushi Nemoto @ 2004-02-03 1:30 UTC (permalink / raw)
To: jsun; +Cc: macro, linux-mips
>>>>> On Mon, 2 Feb 2004 13:19:50 -0800, Jun Sun <jsun@mvista.com> said:
>> By the way, with this patch, individual board can not implement
>> it's own genrtc routines. How about making gen_rtc_time,
>> etc. pointer to functions to allow overrides?
jsun> Is this necessary? How about letting us wait until there is a
jsun> sensible need?
OK, we can wait. But still I suppose gen_rtc_time will become a
pointer sooner or later....
Anyway, I think using genrtc instead of mips-rtc is very good idea.
Thank you.
jsun> If I understand you correctly, you like to have board rtc read
jsun> routines to return a rtc structure instead of the unsigned long
jsun> integer.
jsun> There are actually boards which makes the current implementation
jsun> more efficient. See vr4181.
I see.
jsun> In general, however, this is not a bad idea, just involving a
jsun> lot more board level changes. I think it deserves another patch
jsun> or even debate.
Though I'm not have a real code yet, how about this idea?
1. Provide std_rtc_get_time (returns ulong) implemented with
get_rtc_time (returns rtc struct) pointer.
2. Provide std_get_rtc_time (returns rtc struct) implemented with
rtc_get_time returns ulong) pointer.
3. Each board implement its own rtc_get_time or get_rtc_time.
4. In generic time_init(), initialize rtc_get_time pointer or
get_rtc_time pointer with std_rtc_get_time or std_get_rtc_time if
they were NULL.
---
Atsushi Nemoto
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-02-03 1:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-30 18:39 [PATCH 2.6] enable genrtc for MIPS Jun Sun
2004-01-30 19:13 ` Maciej W. Rozycki
2004-02-01 11:30 ` Atsushi Nemoto
2004-02-01 12:04 ` Geert Uytterhoeven
2004-02-02 21:19 ` Jun Sun
2004-02-03 1:30 ` Atsushi Nemoto
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox