* [parisc-linux] Generic RTC driver in 2.4.x?
@ 2002-12-24 13:55 ` Geert Uytterhoeven
0 siblings, 0 replies; 30+ messages in thread
From: Geert Uytterhoeven @ 2002-12-24 13:55 UTC (permalink / raw)
To: parisc-linux, Linux/PPC Development, Linux/m68k; +Cc: Linux Kernel Development
AFAIK the generic RTC driver is used on PA-RISC, PPC, and m68k.
Are you interested in a backport to 2.4.x?
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] 30+ messages in thread* Generic RTC driver in 2.4.x? @ 2002-12-24 13:55 ` Geert Uytterhoeven 0 siblings, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2002-12-24 13:55 UTC (permalink / raw) To: parisc-linux, Linux/PPC Development, Linux/m68k; +Cc: Linux Kernel Development AFAIK the generic RTC driver is used on PA-RISC, PPC, and m68k. Are you interested in a backport to 2.4.x? 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] 30+ messages in thread
* Re: [parisc-linux] Generic RTC driver in 2.4.x? 2002-12-24 13:55 ` Geert Uytterhoeven (?) @ 2002-12-24 23:51 ` Randolph Chung -1 siblings, 0 replies; 30+ messages in thread From: Randolph Chung @ 2002-12-24 23:51 UTC (permalink / raw) To: Geert Uytterhoeven Cc: parisc-linux, Linux/PPC Development, Linux/m68k, Linux Kernel Development > AFAIK the generic RTC driver is used on PA-RISC, PPC, and m68k. > > Are you interested in a backport to 2.4.x? On parisc we already have a version of the generic RTC driver in our 2.4 tree. If there's something more "official" or common we can adopt that version. randolph -- Randolph Chung Debian GNU/Linux Developer, hppa/ia64 ports http://www.tausq.org/ ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [parisc-linux] Generic RTC driver in 2.4.x? 2002-12-24 13:55 ` Geert Uytterhoeven (?) (?) @ 2002-12-24 23:51 ` Randolph Chung 2002-12-26 17:55 ` Tom Rini 2002-12-26 17:55 ` Tom Rini -1 siblings, 2 replies; 30+ messages in thread From: Randolph Chung @ 2002-12-24 23:51 UTC (permalink / raw) To: Geert Uytterhoeven Cc: parisc-linux, Linux/PPC Development, Linux/m68k, Linux Kernel Development > AFAIK the generic RTC driver is used on PA-RISC, PPC, and m68k. > > Are you interested in a backport to 2.4.x? On parisc we already have a version of the generic RTC driver in our 2.4 tree. If there's something more "official" or common we can adopt that version. randolph -- Randolph Chung Debian GNU/Linux Developer, hppa/ia64 ports http://www.tausq.org/ ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [parisc-linux] Generic RTC driver in 2.4.x? 2002-12-24 23:51 ` Randolph Chung @ 2002-12-26 17:55 ` Tom Rini 2002-12-28 22:37 ` Geert Uytterhoeven 2002-12-28 22:37 ` [parisc-linux] Generic RTC driver in 2.4.x? Geert Uytterhoeven 2002-12-26 17:55 ` Tom Rini 1 sibling, 2 replies; 30+ messages in thread From: Tom Rini @ 2002-12-26 17:55 UTC (permalink / raw) To: Randolph Chung Cc: Geert Uytterhoeven, parisc-linux, Linux/PPC Development, Linux/m68k, Linux Kernel Development On Tue, Dec 24, 2002 at 03:51:47PM -0800, Randolph Chung wrote: > > AFAIK the generic RTC driver is used on PA-RISC, PPC, and m68k. > > > > Are you interested in a backport to 2.4.x? > > On parisc we already have a version of the generic RTC driver in our > 2.4 tree. If there's something more "official" or common we can adopt > that version. Similarly, PPC has had it's own 'generic' RTC driver in the kernel for ages, so there's no pressing need, but if the 2.5 version makes its way back into 2.4 (as the 2.5 version has some minor changes needed for everyone which weren't in the 2.4 m68k version), we can easily switch to that version. -- Tom Rini (TR1265) http://gate.crashing.org/~trini/ ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [parisc-linux] Generic RTC driver in 2.4.x? 2002-12-26 17:55 ` Tom Rini @ 2002-12-28 22:37 ` Geert Uytterhoeven 2003-01-05 14:44 ` Geert Uytterhoeven 2003-01-05 14:44 ` Geert Uytterhoeven 2002-12-28 22:37 ` [parisc-linux] Generic RTC driver in 2.4.x? Geert Uytterhoeven 1 sibling, 2 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2002-12-28 22:37 UTC (permalink / raw) To: Tom Rini Cc: Randolph Chung, parisc-linux, Linux/PPC Development, Linux/m68k, Linux Kernel Development On Thu, 26 Dec 2002, Tom Rini wrote: > On Tue, Dec 24, 2002 at 03:51:47PM -0800, Randolph Chung wrote: > > > AFAIK the generic RTC driver is used on PA-RISC, PPC, and m68k. > > > > > > Are you interested in a backport to 2.4.x? > > > > On parisc we already have a version of the generic RTC driver in our > > 2.4 tree. If there's something more "official" or common we can adopt > > that version. > > Similarly, PPC has had it's own 'generic' RTC driver in the kernel for > ages, so there's no pressing need, but if the 2.5 version makes its way > back into 2.4 (as the 2.5 version has some minor changes needed for > everyone which weren't in the 2.4 m68k version), we can easily switch to > that version. I already merged some of your 2.5.x changes with the driver in the m68k 2.4.x tree. I'll do some more merges, and get back to you... 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] 30+ messages in thread
* Re: [parisc-linux] Generic RTC driver in 2.4.x? 2002-12-28 22:37 ` Geert Uytterhoeven @ 2003-01-05 14:44 ` Geert Uytterhoeven 2003-01-05 14:44 ` Geert Uytterhoeven 1 sibling, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2003-01-05 14:44 UTC (permalink / raw) To: Tom Rini Cc: Randolph Chung, parisc-linux, Linux/PPC Development, Linux/m68k, Linux Kernel Development On Sat, 28 Dec 2002, Geert Uytterhoeven wrote: > On Thu, 26 Dec 2002, Tom Rini wrote: > > On Tue, Dec 24, 2002 at 03:51:47PM -0800, Randolph Chung wrote: > > > > AFAIK the generic RTC driver is used on PA-RISC, PPC, and m68k. > > > > > > > > Are you interested in a backport to 2.4.x? > > > > > > On parisc we already have a version of the generic RTC driver in our > > > 2.4 tree. If there's something more "official" or common we can adopt > > > that version. > > > > Similarly, PPC has had it's own 'generic' RTC driver in the kernel for > > ages, so there's no pressing need, but if the 2.5 version makes its way > > back into 2.4 (as the 2.5 version has some minor changes needed for > > everyone which weren't in the 2.4 m68k version), we can easily switch to > > that version. > > I already merged some of your 2.5.x changes with the driver in the m68k 2.4.x > tree. > > I'll do some more merges, and get back to you... The following patch adds the generic RTC driver to 2.4.20 (applies fine to 2.4.21-pre2). This driver provides a /dev/rtc-compatible interface to the real time clock on machines without a PC-style RTC chip. It is used as the primary RTC driver on m68k, pa-risc, and ppc. This driver is already present in 2.5.x. Pa-risc and ppc people (any other users?), please send me your enhancements (or just ack if none are necessary), so I can send genrtc to Marcelo. Thanks! Documentation/Configure.help | 28 + arch/m68k/config.in | 5 arch/m68k/kernel/m68k_ksyms.c | 5 arch/m68k/kernel/setup.c | 3 arch/m68k/q40/config.c | 41 ++ drivers/char/Makefile | 1 include/asm-m68k/machdep.h | 4 include/asm-m68k/rtc.h | 44 ++ include/linux/rtc.h | 28 + linux-m68k-2.4.20/drivers/char/genrtc.c | 524 ++++++++++++++++++++++++++++++++ 10 files changed, 678 insertions, 5 deletions --- linux-2.4.20/Documentation/Configure.help Tue Oct 29 18:40:45 2002 +++ linux-m68k-2.4.20/Documentation/Configure.help Wed Oct 16 11:01:53 2002 @@ -18959,6 +18959,34 @@ The module is called rtc.o. If you want to compile it as a module, say M here and read <file:Documentation/modules.txt>. +Generic Real Time Clock Support +CONFIG_GEN_RTC + If you say Y here and create a character special file /dev/rtc with + major number 10 and minor number 135 using mknod ("man mknod"), you + will get access to the real time clock (or hardware clock) built + into your computer. + + In 2.4 and later kernels this is the only way to set and get rtc + time on m68k systems so it is highly recommended. + + It reports status information via the file /proc/driver/rtc and its + behaviour is set by various ioctls on /dev/rtc. If you enable the + "extended RTC operation" below it will also provide an emulation + for RTC_UIE which is required by some programs and may improve + precision in some cases. + + This driver is also available as a module ( = code which can be + inserted in and removed from the running kernel whenever you want). + The module is called genrtc.o. If you want to compile it as a module, + say M here and read <file:Documentation/modules.txt>. To load the + module automaticaly add 'alias char-major-10-135 genrtc' to your + /etc/modules.conf + +Extended RTC operation +CONFIG_GEN_RTC_X + Provides an emulation for RTC_UIE which is required by some programs + and may improve precision of the generic RTC support in some cases. + Tadpole ANA H8 Support CONFIG_H8 The Hitachi H8/337 is a microcontroller used to deal with the power --- linux-2.4.20/arch/m68k/config.in Fri Sep 13 10:14:59 2002 +++ linux-m68k-2.4.20/arch/m68k/config.in Tue Aug 13 09:14:30 2002 @@ -517,8 +517,11 @@ if [ "$CONFIG_SUN3" = "y" ]; then define_bool CONFIG_GEN_RTC y else - bool 'Generic /dev/rtc emulation' CONFIG_GEN_RTC + tristate 'Generic /dev/rtc emulation' CONFIG_GEN_RTC fi +fi +if [ "$CONFIG_GEN_RTC" != "n" ]; then + bool ' Extended RTC operation' CONFIG_GEN_RTC_X fi bool 'Unix98 PTY support' CONFIG_UNIX98_PTYS if [ "$CONFIG_UNIX98_PTYS" = "y" ]; then --- linux-2.4.20/arch/m68k/kernel/m68k_ksyms.c Thu Jan 4 22:00:55 2001 +++ linux-m68k-2.4.20/arch/m68k/kernel/m68k_ksyms.c Fri Mar 1 12:29:44 2002 @@ -18,6 +18,7 @@ #include <asm/checksum.h> #include <asm/hardirq.h> #include <asm/softirq.h> +#include <asm/rtc.h> asmlinkage long long __ashldi3 (long long, int); asmlinkage long long __ashrdi3 (long long, int); @@ -49,6 +50,10 @@ EXPORT_SYMBOL(kernel_set_cachemode); #endif /* !CONFIG_SUN3 */ EXPORT_SYMBOL(m68k_debug_device); +EXPORT_SYMBOL(mach_hwclk); +EXPORT_SYMBOL(mach_get_ss); +EXPORT_SYMBOL(mach_get_rtc_pll); +EXPORT_SYMBOL(mach_set_rtc_pll); EXPORT_SYMBOL(dump_fpu); EXPORT_SYMBOL(dump_thread); EXPORT_SYMBOL(strnlen); --- linux-2.4.20/arch/m68k/kernel/setup.c Fri Sep 13 10:15:01 2002 +++ linux-m68k-2.4.20/arch/m68k/kernel/setup.c Mon Sep 9 13:07:29 2002 @@ -90,6 +90,9 @@ void (*mach_gettod) (int*, int*, int*, int*, int*, int*); int (*mach_hwclk) (int, struct rtc_time*) = NULL; int (*mach_set_clock_mmss) (unsigned long) = NULL; +unsigned int (*mach_get_ss)(void) = NULL; +int (*mach_get_rtc_pll)(struct rtc_pll_info *) = NULL; +int (*mach_set_rtc_pll)(struct rtc_pll_info *) = NULL; void (*mach_reset)( void ); void (*mach_halt)( void ) = NULL; void (*mach_power_off)( void ) = NULL; --- linux-2.4.20/arch/m68k/q40/config.c Fri Sep 13 10:15:02 2002 +++ linux-m68k-2.4.20/arch/m68k/q40/config.c Mon Sep 9 13:07:29 2002 @@ -58,7 +58,10 @@ extern void q40_gettod (int *year, int *mon, int *day, int *hour, int *min, int *sec); extern int q40_hwclk (int, struct rtc_time *); +extern unsigned int q40_get_ss (void); extern 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); extern void q40_reset (void); void q40_halt(void); extern void q40_waitbut(void); @@ -196,6 +199,9 @@ mach_gettimeoffset = q40_gettimeoffset; mach_gettod = q40_gettod; mach_hwclk = q40_hwclk; + 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; @@ -331,6 +337,11 @@ return 0; } +unsigned int q40_get_ss() +{ + 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. @@ -362,3 +373,33 @@ 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) + +static int q40_get_rtc_pll(struct rtc_pll_info *pll) +{ + int tmp=Q40_RTC_CTRL; + pll->pll_value = tmp & Q40_RTC_PLL_MASK; + if (tmp & Q40_RTC_PLL_SIGN) + pll->pll_value = -pll->pll_value; + pll->pll_max=31; + pll->pll_min=-31; + pll->pll_posmult=512; + pll->pll_negmult=256; + pll->pll_clock=125829120; + return 0; + } + +static int q40_set_rtc_pll(struct rtc_pll_info *pll) +{ + if (!pll->pll_ctrl){ + /* the docs are a bit unclear so I am doublesetting RTC_WRITE here ... */ + int tmp=(pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) | Q40_RTC_WRITE; + Q40_RTC_CTRL |= Q40_RTC_WRITE; + Q40_RTC_CTRL = tmp; + Q40_RTC_CTRL &= ~(Q40_RTC_WRITE); + return 0; + } else return -EINVAL; +} --- linux-2.4.20/drivers/char/Makefile Wed Nov 27 11:02:06 2002 +++ linux-m68k-2.4.20/drivers/char/Makefile Tue Nov 26 13:24:32 2002 @@ -222,6 +222,7 @@ obj-$(CONFIG_PC110_PAD) += pc110pad.o obj-$(CONFIG_MK712_MOUSE) += mk712.o obj-$(CONFIG_RTC) += rtc.o +obj-$(CONFIG_GEN_RTC) += genrtc.o obj-$(CONFIG_EFI_RTC) += efirtc.o ifeq ($(CONFIG_PPC),) obj-$(CONFIG_NVRAM) += nvram.o --- /dev/null Mon Mar 18 12:17:27 2002 +++ linux-m68k-2.4.20/drivers/char/genrtc.c Sun Jan 5 15:24:28 2003 @@ -0,0 +1,524 @@ +/* + * Real Time Clock interface for q40 and other m68k machines + * emulate some RTC irq capabilities in software + * + * Copyright (C) 1999 Richard Zidlicky + * + * based on Paul Gortmaker's rtc.c device and + * Sam Creasey Generic rtc driver + * + * This driver allows use of the real time clock (built into + * nearly all computers) from user space. It exports the /dev/rtc + * interface supporting various ioctl() and also the /proc/dev/rtc + * pseudo-file for status information. + * + * The ioctls can be used to set the interrupt behaviour where + * supported. + * + * The /dev/rtc interface will block on reads until an interrupt + * has been received. If a RTC interrupt has already happened, + * it will output an unsigned long and then block. The output value + * contains the interrupt status in the low byte and the number of + * interrupts since the last read in the remaining high bytes. The + * /dev/rtc interface can also be used with the select(2) call. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + + * 1.01 fix for 2.3.X rz@linux-m68k.org + * 1.02 merged with code from genrtc.c rz@linux-m68k.org + * 1.03 make it more portable zippel@linux-m68k.org + * 1.04 removed useless timer code rz@linux-m68k.org + * 1.05 portable RTC_UIE emulation rz@linux-m68k.org + * 1.06 set_rtc_time can return an error trini@kernel.crashing.org + */ + +#define RTC_VERSION "1.06" + +#include <linux/module.h> +#include <linux/config.h> +#include <linux/errno.h> +#include <linux/miscdevice.h> +#include <linux/fcntl.h> + +#include <linux/rtc.h> +#include <linux/init.h> +#include <linux/poll.h> +#include <linux/proc_fs.h> + +#include <asm/uaccess.h> +#include <asm/system.h> +#include <asm/rtc.h> + +/* + * We sponge a minor off of the misc major. No need slurping + * up another valuable major dev number for this. If you add + * an ioctl, make sure you don't conflict with SPARC's RTC + * ioctls. + */ + +static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); + +static int gen_rtc_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg); + +/* + * Bits in gen_rtc_status. + */ + +#define RTC_IS_OPEN 0x01 /* means /dev/rtc is in use */ + +unsigned char gen_rtc_status; /* bitmapped status byte. */ +unsigned long gen_rtc_irq_data; /* our output to the world */ + +/* months start at 0 now */ +unsigned char days_in_mo[] = +{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +static int irq_active; + +#ifdef CONFIG_GEN_RTC_X +struct tq_struct genrtc_task; +static struct timer_list timer_task; + +static unsigned int oldsecs; +static int lostint; +static int tt_exp; + +void gen_rtc_timer(unsigned long data); + +static volatile int stask_active; /* schedule_task */ +static volatile int ttask_active; /* timer_task */ +static int stop_rtc_timers; /* don't requeue tasks */ +static spinlock_t gen_rtc_lock = SPIN_LOCK_UNLOCKED; + +/* + * Routine to poll RTC seconds field for change as often as posible, + * after first RTC_UIE use timer to reduce polling + */ +void genrtc_troutine(void *data) +{ + unsigned int tmp = get_rtc_ss(); + + if (stop_rtc_timers) { + stask_active = 0; + return; + } + + if (oldsecs != tmp){ + oldsecs = tmp; + + timer_task.function = gen_rtc_timer; + timer_task.expires = jiffies + HZ - (HZ/10); + tt_exp=timer_task.expires; + ttask_active=1; + stask_active=0; + add_timer(&timer_task); + + gen_rtc_interrupt(0); + } else if (schedule_task(&genrtc_task) == 0) + stask_active = 0; +} + +void gen_rtc_timer(unsigned long data) +{ + lostint = get_rtc_ss() - oldsecs ; + if (lostint<0) + lostint = 60 - lostint; + if (time_after(jiffies, tt_exp)) + printk(KERN_INFO "genrtc: timer task delayed by %ld jiffies\n", + jiffies-tt_exp); + ttask_active=0; + stask_active=1; + if ((schedule_task(&genrtc_task) == 0)) + stask_active = 0; +} + +/* + * call gen_rtc_interrupt function to signal an RTC_UIE, + * arg is unused. + * Could be invoked either from a real interrupt handler or + * from some routine that periodically (eg 100HZ) monitors + * whether RTC_SECS changed + */ +void gen_rtc_interrupt(unsigned long arg) +{ + /* We store the status in the low byte and the number of + * interrupts received since the last read in the remainder + * of rtc_irq_data. */ + + gen_rtc_irq_data += 0x100; + gen_rtc_irq_data &= ~0xff; + gen_rtc_irq_data |= RTC_UIE; + + if (lostint){ + printk("genrtc: system delaying clock ticks?\n"); + /* increment count so that userspace knows something is wrong */ + gen_rtc_irq_data += ((lostint-1)<<8); + lostint = 0; + } + + wake_up_interruptible(&gen_rtc_wait); +} + +/* + * Now all the various file operations that we export. + */ +static ssize_t gen_rtc_read(struct file *file, char *buf, + size_t count, loff_t *ppos) +{ + DECLARE_WAITQUEUE(wait, current); + unsigned long data; + ssize_t retval; + + if (count != sizeof (unsigned int) && count != sizeof (unsigned long)) + return -EINVAL; + + if (file->f_flags & O_NONBLOCK && !gen_rtc_irq_data) + return -EAGAIN; + + add_wait_queue(&gen_rtc_wait, &wait); + retval = -ERESTARTSYS; + + while (1) { + set_current_state(TASK_INTERRUPTIBLE); + data = xchg(&gen_rtc_irq_data, 0); + if (data) + break; + if (signal_pending(current)) + goto out; + schedule(); + } + + /* first test allows optimizer to nuke this case for 32-bit machines */ + if (sizeof (int) != sizeof (long) && count == sizeof (unsigned int)) { + unsigned int uidata = data; + retval = put_user(uidata, (unsigned long *)buf); + } + else { + retval = put_user(data, (unsigned long *)buf); + } + if (!retval) + retval = sizeof(unsigned long); + out: + current->state = TASK_RUNNING; + remove_wait_queue(&gen_rtc_wait, &wait); + + return retval; +} + +static unsigned int gen_rtc_poll(struct file *file, + struct poll_table_struct *wait) +{ + poll_wait(file, &gen_rtc_wait, wait); + if (gen_rtc_irq_data != 0) + return POLLIN | POLLRDNORM; + return 0; +} + +#endif + +/* + * Used to disable/enable interrupts, only RTC_UIE supported + * We also clear out any old irq data after an ioctl() that + * meddles with the interrupt enable/disable bits. + */ + +static inline void gen_clear_rtc_irq_bit(unsigned char bit) +{ +#ifdef CONFIG_GEN_RTC_X + stop_rtc_timers = 1; + if (ttask_active){ + del_timer_sync(&timer_task); + ttask_active = 0; + } + while (stask_active) + schedule(); + + spin_lock(&gen_rtc_lock); + irq_active = 0; + spin_unlock(&gen_rtc_lock); +#endif +} + +static inline int gen_set_rtc_irq_bit(unsigned char bit) +{ +#ifdef CONFIG_GEN_RTC_X + spin_lock(&gen_rtc_lock); + if ( !irq_active ) { + irq_active = 1; + stop_rtc_timers = 0; + lostint = 0; + genrtc_task.routine = genrtc_troutine; + oldsecs = get_rtc_ss(); + init_timer(&timer_task); + + stask_active = 1; + if (schedule_task(&genrtc_task) == 0){ + stask_active = 0; + } + } + spin_unlock(&gen_rtc_lock); + gen_rtc_irq_data = 0; + return 0; +#else + return -EINVAL; +#endif +} + +static int gen_rtc_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) +{ + struct rtc_time wtime; + struct rtc_pll_info pll; + + switch (cmd) { + + case RTC_PLL_GET: + if (get_rtc_pll(&pll)) + return -EINVAL; + else + return copy_to_user((void *)arg, &pll, sizeof pll) ? -EFAULT : 0; + + case RTC_PLL_SET: + if (!capable(CAP_SYS_TIME)) + return -EACCES; + if (copy_from_user(&pll, (struct rtc_pll_info*)arg, + sizeof(pll))) + return -EFAULT; + return set_rtc_pll(&pll); + + case RTC_UIE_OFF: /* disable ints from RTC updates. */ + gen_clear_rtc_irq_bit(RTC_UIE); + return 0; + + case RTC_UIE_ON: /* enable ints for RTC updates. */ + return gen_set_rtc_irq_bit(RTC_UIE); + + case RTC_RD_TIME: /* Read the time/date from RTC */ + /* this doesn't get week-day, who cares */ + memset(&wtime, 0, sizeof(wtime)); + get_rtc_time(&wtime); + + return copy_to_user((void *)arg, &wtime, sizeof(wtime)) ? -EFAULT : 0; + + case RTC_SET_TIME: /* Set the RTC */ + { + int year; + unsigned char leap_yr; + + if (!capable(CAP_SYS_TIME)) + return -EACCES; + + if (copy_from_user(&wtime, (struct rtc_time *)arg, + sizeof(wtime))) + return -EFAULT; + + year = wtime.tm_year + 1900; + leap_yr = ((!(year % 4) && (year % 100)) || + !(year % 400)); + + if ((wtime.tm_mon < 0 || wtime.tm_mon > 11) || (wtime.tm_mday < 1)) + return -EINVAL; + + if (wtime.tm_mday < 0 || wtime.tm_mday > + (days_in_mo[wtime.tm_mon] + ((wtime.tm_mon == 1) && leap_yr))) + return -EINVAL; + + if (wtime.tm_hour < 0 || wtime.tm_hour >= 24 || + wtime.tm_min < 0 || wtime.tm_min >= 60 || + wtime.tm_sec < 0 || wtime.tm_sec >= 60) + return -EINVAL; + + return set_rtc_time(&wtime); + } + } + + return -EINVAL; +} + +/* + * We enforce only one user at a time here with the open/close. + * Also clear the previous interrupt data on an open, and clean + * up things on a close. + */ + +static int gen_rtc_open(struct inode *inode, struct file *file) +{ + if (gen_rtc_status & RTC_IS_OPEN) + return -EBUSY; + + MOD_INC_USE_COUNT; + + gen_rtc_status |= RTC_IS_OPEN; + gen_rtc_irq_data = 0; + irq_active = 0; + + return 0; +} + +static int gen_rtc_release(struct inode *inode, struct file *file) +{ + /* + * Turn off all interrupts once the device is no longer + * in use and clear the data. + */ + + gen_clear_rtc_irq_bit(RTC_PIE|RTC_AIE|RTC_UIE); + + gen_rtc_status &= ~RTC_IS_OPEN; + MOD_DEC_USE_COUNT; + + return 0; +} + +static int gen_rtc_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data); + + +/* + * The various file operations we support. + */ + +static struct file_operations gen_rtc_fops = { + owner: THIS_MODULE, +#ifdef CONFIG_GEN_RTC_X + read: gen_rtc_read, + poll: gen_rtc_poll, +#endif + ioctl: gen_rtc_ioctl, + open: gen_rtc_open, + release: gen_rtc_release +}; + +static struct miscdevice rtc_gen_dev = +{ + RTC_MINOR, + "rtc", + &gen_rtc_fops +}; + +int __init rtc_generic_init(void) +{ + + printk(KERN_INFO "Generic RTC Driver v%s\n", RTC_VERSION); + + misc_register(&rtc_gen_dev); + create_proc_read_entry ("driver/rtc", 0, 0, gen_rtc_read_proc, NULL); + + return 0; +} + +static void __exit rtc_generic_exit(void) +{ + remove_proc_entry ("driver/rtc", NULL); + misc_deregister(&rtc_gen_dev); +} + +module_init(rtc_generic_init); +module_exit(rtc_generic_exit); +EXPORT_NO_SYMBOLS; + + +/* + * Info exported via "/proc/rtc". + */ + +int gen_rtc_proc_output(char *buf) +{ + char *p; + struct rtc_time tm; + unsigned tmp; + struct rtc_pll_info pll; + + p = buf; + + get_rtc_time(&tm); + + p += sprintf(p, + "rtc_time\t: %02d:%02d:%02d\n" + "rtc_date\t: %04d-%02d-%02d\n" + "rtc_epoch\t: %04u\n", + tm.tm_hour, tm.tm_min, tm.tm_sec, + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, 1900); + + tm.tm_hour=0;tm.tm_min=0;tm.tm_sec=0; + + p += sprintf(p, "alarm\t\t: "); + if (tm.tm_hour <= 24) + p += sprintf(p, "%02d:", tm.tm_hour); + else + p += sprintf(p, "**:"); + + if (tm.tm_min <= 59) + p += sprintf(p, "%02d:", tm.tm_min); + else + p += sprintf(p, "**:"); + + if (tm.tm_sec <= 59) + p += sprintf(p, "%02d\n", tm.tm_sec); + else + p += sprintf(p, "**\n"); + + tmp= RTC_24H ; + p += sprintf(p, + "DST_enable\t: %s\n" + "BCD\t\t: %s\n" + "24hr\t\t: %s\n" + "square_wave\t: %s\n" + "alarm_IRQ\t: %s\n" + "update_IRQ\t: %s\n" + "periodic_IRQ\t: %s\n" + "periodic_freq\t: %ld\n" + "batt_status\t: %s\n", + (tmp & RTC_DST_EN) ? "yes" : "no", + (tmp & RTC_DM_BINARY) ? "no" : "yes", + (tmp & RTC_24H) ? "yes" : "no", + (tmp & RTC_SQWE) ? "yes" : "no", + (tmp & RTC_AIE) ? "yes" : "no", + irq_active ? "yes" : "no", + (tmp & RTC_PIE) ? "yes" : "no", + 0L /* freq */, + "okay" ); + if (!get_rtc_pll(&pll)) + p += sprintf(p, + "PLL adjustment\t: %d\n" + "PLL max +ve adjustment\t: %d\n" + "PLL max -ve adjustment\t: %d\n" + "PLL +ve adjustment factor\t: %d\n" + "PLL -ve adjustment factor\t: %d\n" + "PLL frequency\t: %ld\n", + pll.pll_value, + pll.pll_max, + pll.pll_min, + pll.pll_posmult, + pll.pll_negmult, + pll.pll_clock); + return p - buf; +} + +static int gen_rtc_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + int len = gen_rtc_proc_output (page); + if (len <= off+count) *eof = 1; + *start = page + off; + len -= off; + if (len>count) len = count; + if (len<0) len = 0; + return len; +} + + +MODULE_AUTHOR("Richard Zidlicky"); +MODULE_LICENSE("GPL"); + +/* + * Local variables: + * compile-command: "m68k-linux-gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -ffixed-a2 -c -o genrtc.o genrtc.c" + * End: + */ + --- linux-2.4.20/include/asm-m68k/machdep.h Wed May 29 10:14:12 2002 +++ linux-m68k-2.4.20/include/asm-m68k/machdep.h Mon Sep 9 13:07:29 2002 @@ -5,6 +5,7 @@ struct kbd_repeat; struct mktime; struct rtc_time; +struct rtc_pll_info; struct gendisk; struct buffer_head; @@ -29,6 +30,9 @@ extern void (*mach_gettod)(int *year, int *mon, int *day, int *hour, int *min, int *sec); 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 ); --- linux-2.4.20/include/asm-m68k/rtc.h Wed May 29 10:14:13 2002 +++ linux-m68k-2.4.20/include/asm-m68k/rtc.h Sun Jan 5 15:24:28 2003 @@ -13,9 +13,8 @@ #ifdef __KERNEL__ -#include <linux/config.h> #include <linux/rtc.h> -#include <linux/delay.h> +#include <asm/errno.h> #include <asm/machdep.h> #define RTC_PIE 0x40 /* periodic interrupt enable */ @@ -30,7 +29,48 @@ #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 */ +static inline void get_rtc_time(struct rtc_time *time) +{ + /* + * Only the values that we read from the RTC are set. We leave + * tm_wday, tm_yday and tm_isdst untouched. Even though the + * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated + * by the RTC when initially set to a non-zero value. + */ + mach_hwclk(0, time); +} +static inline int set_rtc_time(struct rtc_time *time) +{ + return mach_hwclk(1, time); +} + +static inline unsigned int get_rtc_ss(void) +{ + if (mach_get_ss) + return mach_get_ss(); + else{ + struct rtc_time h; + + get_rtc_time(&h); + return h.tm_sec; + } +} + +static inline int get_rtc_pll(struct rtc_pll_info *pll) +{ + if (mach_get_rtc_pll) + return mach_get_rtc_pll(pll); + else + return -EINVAL; +} +static inline int set_rtc_pll(struct rtc_pll_info *pll) +{ + if (mach_set_rtc_pll) + return mach_set_rtc_pll(pll); + else + return -EINVAL; +} #endif /* __KERNEL__ */ #endif /* _ASM__RTC_H */ --- linux-2.4.20/include/linux/rtc.h Mon Feb 19 09:47:19 2001 +++ linux-m68k-2.4.20/include/linux/rtc.h Sun Jan 5 15:24:28 2003 @@ -39,10 +39,32 @@ struct rtc_time time; /* time the alarm is set to */ }; +/* + * Data structure to control PLL correction some better RTC feature + * pll_value is used to get or set current value of correction, + * the rest of the struct is used to query HW capabilities. + * This is modeled after the RTC used in Q40/Q60 computers but + * should be sufficiently flexible for other devices + * + * +ve pll_value means clock will run faster by + * pll_value*pll_posmult/pll_clock + * -ve pll_value means clock will run slower by + * pll_value*pll_negmult/pll_clock + */ + +struct rtc_pll_info { + int pll_ctrl; /* placeholder for fancier control */ + int pll_value; /* get/set correction value */ + int pll_max; /* max +ve (faster) adjustment value */ + int pll_min; /* max -ve (slower) adjustment value */ + int pll_posmult; /* factor for +ve corection */ + int pll_negmult; /* factor for -ve corection */ + long pll_clock; /* base PLL frequency */ +}; /* - * ioctl calls that are permitted to the /dev/rtc interface, if - * CONFIG_RTC/CONFIG_EFI_RTC was enabled. + * ioctl calls that are permitted to the /dev/rtc interface, if + * any of the RTC drivers are enabled. */ #define RTC_AIE_ON _IO('p', 0x01) /* Alarm int. enable on */ @@ -66,4 +88,6 @@ #define RTC_WKALM_SET _IOW('p', 0x0f, struct rtc_wkalrm)/* Set wakeup alarm*/ #define RTC_WKALM_RD _IOR('p', 0x10, struct rtc_wkalrm)/* Get wakeup alarm*/ +#define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info) /* Get PLL correction */ +#define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info) /* Set PLL correction */ #endif /* _LINUX_RTC_H_ */ 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] 30+ messages in thread
* Re: [parisc-linux] Generic RTC driver in 2.4.x? 2002-12-28 22:37 ` Geert Uytterhoeven 2003-01-05 14:44 ` Geert Uytterhoeven @ 2003-01-05 14:44 ` Geert Uytterhoeven 2003-01-10 20:05 ` Geert Uytterhoeven 2003-01-10 20:05 ` [parisc-linux] " Geert Uytterhoeven 1 sibling, 2 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2003-01-05 14:44 UTC (permalink / raw) To: Tom Rini Cc: Randolph Chung, parisc-linux, Linux/PPC Development, Linux/m68k, Linux Kernel Development On Sat, 28 Dec 2002, Geert Uytterhoeven wrote: > On Thu, 26 Dec 2002, Tom Rini wrote: > > On Tue, Dec 24, 2002 at 03:51:47PM -0800, Randolph Chung wrote: > > > > AFAIK the generic RTC driver is used on PA-RISC, PPC, and m68k. > > > > > > > > Are you interested in a backport to 2.4.x? > > > > > > On parisc we already have a version of the generic RTC driver in our > > > 2.4 tree. If there's something more "official" or common we can adopt > > > that version. > > > > Similarly, PPC has had it's own 'generic' RTC driver in the kernel for > > ages, so there's no pressing need, but if the 2.5 version makes its way > > back into 2.4 (as the 2.5 version has some minor changes needed for > > everyone which weren't in the 2.4 m68k version), we can easily switch to > > that version. > > I already merged some of your 2.5.x changes with the driver in the m68k 2.4.x > tree. > > I'll do some more merges, and get back to you... The following patch adds the generic RTC driver to 2.4.20 (applies fine to 2.4.21-pre2). This driver provides a /dev/rtc-compatible interface to the real time clock on machines without a PC-style RTC chip. It is used as the primary RTC driver on m68k, pa-risc, and ppc. This driver is already present in 2.5.x. Pa-risc and ppc people (any other users?), please send me your enhancements (or just ack if none are necessary), so I can send genrtc to Marcelo. Thanks! Documentation/Configure.help | 28 + arch/m68k/config.in | 5 arch/m68k/kernel/m68k_ksyms.c | 5 arch/m68k/kernel/setup.c | 3 arch/m68k/q40/config.c | 41 ++ drivers/char/Makefile | 1 include/asm-m68k/machdep.h | 4 include/asm-m68k/rtc.h | 44 ++ include/linux/rtc.h | 28 + linux-m68k-2.4.20/drivers/char/genrtc.c | 524 ++++++++++++++++++++++++++++++++ 10 files changed, 678 insertions, 5 deletions --- linux-2.4.20/Documentation/Configure.help Tue Oct 29 18:40:45 2002 +++ linux-m68k-2.4.20/Documentation/Configure.help Wed Oct 16 11:01:53 2002 @@ -18959,6 +18959,34 @@ The module is called rtc.o. If you want to compile it as a module, say M here and read <file:Documentation/modules.txt>. +Generic Real Time Clock Support +CONFIG_GEN_RTC + If you say Y here and create a character special file /dev/rtc with + major number 10 and minor number 135 using mknod ("man mknod"), you + will get access to the real time clock (or hardware clock) built + into your computer. + + In 2.4 and later kernels this is the only way to set and get rtc + time on m68k systems so it is highly recommended. + + It reports status information via the file /proc/driver/rtc and its + behaviour is set by various ioctls on /dev/rtc. If you enable the + "extended RTC operation" below it will also provide an emulation + for RTC_UIE which is required by some programs and may improve + precision in some cases. + + This driver is also available as a module ( = code which can be + inserted in and removed from the running kernel whenever you want). + The module is called genrtc.o. If you want to compile it as a module, + say M here and read <file:Documentation/modules.txt>. To load the + module automaticaly add 'alias char-major-10-135 genrtc' to your + /etc/modules.conf + +Extended RTC operation +CONFIG_GEN_RTC_X + Provides an emulation for RTC_UIE which is required by some programs + and may improve precision of the generic RTC support in some cases. + Tadpole ANA H8 Support CONFIG_H8 The Hitachi H8/337 is a microcontroller used to deal with the power --- linux-2.4.20/arch/m68k/config.in Fri Sep 13 10:14:59 2002 +++ linux-m68k-2.4.20/arch/m68k/config.in Tue Aug 13 09:14:30 2002 @@ -517,8 +517,11 @@ if [ "$CONFIG_SUN3" = "y" ]; then define_bool CONFIG_GEN_RTC y else - bool 'Generic /dev/rtc emulation' CONFIG_GEN_RTC + tristate 'Generic /dev/rtc emulation' CONFIG_GEN_RTC fi +fi +if [ "$CONFIG_GEN_RTC" != "n" ]; then + bool ' Extended RTC operation' CONFIG_GEN_RTC_X fi bool 'Unix98 PTY support' CONFIG_UNIX98_PTYS if [ "$CONFIG_UNIX98_PTYS" = "y" ]; then --- linux-2.4.20/arch/m68k/kernel/m68k_ksyms.c Thu Jan 4 22:00:55 2001 +++ linux-m68k-2.4.20/arch/m68k/kernel/m68k_ksyms.c Fri Mar 1 12:29:44 2002 @@ -18,6 +18,7 @@ #include <asm/checksum.h> #include <asm/hardirq.h> #include <asm/softirq.h> +#include <asm/rtc.h> asmlinkage long long __ashldi3 (long long, int); asmlinkage long long __ashrdi3 (long long, int); @@ -49,6 +50,10 @@ EXPORT_SYMBOL(kernel_set_cachemode); #endif /* !CONFIG_SUN3 */ EXPORT_SYMBOL(m68k_debug_device); +EXPORT_SYMBOL(mach_hwclk); +EXPORT_SYMBOL(mach_get_ss); +EXPORT_SYMBOL(mach_get_rtc_pll); +EXPORT_SYMBOL(mach_set_rtc_pll); EXPORT_SYMBOL(dump_fpu); EXPORT_SYMBOL(dump_thread); EXPORT_SYMBOL(strnlen); --- linux-2.4.20/arch/m68k/kernel/setup.c Fri Sep 13 10:15:01 2002 +++ linux-m68k-2.4.20/arch/m68k/kernel/setup.c Mon Sep 9 13:07:29 2002 @@ -90,6 +90,9 @@ void (*mach_gettod) (int*, int*, int*, int*, int*, int*); int (*mach_hwclk) (int, struct rtc_time*) = NULL; int (*mach_set_clock_mmss) (unsigned long) = NULL; +unsigned int (*mach_get_ss)(void) = NULL; +int (*mach_get_rtc_pll)(struct rtc_pll_info *) = NULL; +int (*mach_set_rtc_pll)(struct rtc_pll_info *) = NULL; void (*mach_reset)( void ); void (*mach_halt)( void ) = NULL; void (*mach_power_off)( void ) = NULL; --- linux-2.4.20/arch/m68k/q40/config.c Fri Sep 13 10:15:02 2002 +++ linux-m68k-2.4.20/arch/m68k/q40/config.c Mon Sep 9 13:07:29 2002 @@ -58,7 +58,10 @@ extern void q40_gettod (int *year, int *mon, int *day, int *hour, int *min, int *sec); extern int q40_hwclk (int, struct rtc_time *); +extern unsigned int q40_get_ss (void); extern 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); extern void q40_reset (void); void q40_halt(void); extern void q40_waitbut(void); @@ -196,6 +199,9 @@ mach_gettimeoffset = q40_gettimeoffset; mach_gettod = q40_gettod; mach_hwclk = q40_hwclk; + 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; @@ -331,6 +337,11 @@ return 0; } +unsigned int q40_get_ss() +{ + 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. @@ -362,3 +373,33 @@ 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) + +static int q40_get_rtc_pll(struct rtc_pll_info *pll) +{ + int tmp=Q40_RTC_CTRL; + pll->pll_value = tmp & Q40_RTC_PLL_MASK; + if (tmp & Q40_RTC_PLL_SIGN) + pll->pll_value = -pll->pll_value; + pll->pll_max=31; + pll->pll_min=-31; + pll->pll_posmult=512; + pll->pll_negmult=256; + pll->pll_clock=125829120; + return 0; + } + +static int q40_set_rtc_pll(struct rtc_pll_info *pll) +{ + if (!pll->pll_ctrl){ + /* the docs are a bit unclear so I am doublesetting RTC_WRITE here ... */ + int tmp=(pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) | Q40_RTC_WRITE; + Q40_RTC_CTRL |= Q40_RTC_WRITE; + Q40_RTC_CTRL = tmp; + Q40_RTC_CTRL &= ~(Q40_RTC_WRITE); + return 0; + } else return -EINVAL; +} --- linux-2.4.20/drivers/char/Makefile Wed Nov 27 11:02:06 2002 +++ linux-m68k-2.4.20/drivers/char/Makefile Tue Nov 26 13:24:32 2002 @@ -222,6 +222,7 @@ obj-$(CONFIG_PC110_PAD) += pc110pad.o obj-$(CONFIG_MK712_MOUSE) += mk712.o obj-$(CONFIG_RTC) += rtc.o +obj-$(CONFIG_GEN_RTC) += genrtc.o obj-$(CONFIG_EFI_RTC) += efirtc.o ifeq ($(CONFIG_PPC),) obj-$(CONFIG_NVRAM) += nvram.o --- /dev/null Mon Mar 18 12:17:27 2002 +++ linux-m68k-2.4.20/drivers/char/genrtc.c Sun Jan 5 15:24:28 2003 @@ -0,0 +1,524 @@ +/* + * Real Time Clock interface for q40 and other m68k machines + * emulate some RTC irq capabilities in software + * + * Copyright (C) 1999 Richard Zidlicky + * + * based on Paul Gortmaker's rtc.c device and + * Sam Creasey Generic rtc driver + * + * This driver allows use of the real time clock (built into + * nearly all computers) from user space. It exports the /dev/rtc + * interface supporting various ioctl() and also the /proc/dev/rtc + * pseudo-file for status information. + * + * The ioctls can be used to set the interrupt behaviour where + * supported. + * + * The /dev/rtc interface will block on reads until an interrupt + * has been received. If a RTC interrupt has already happened, + * it will output an unsigned long and then block. The output value + * contains the interrupt status in the low byte and the number of + * interrupts since the last read in the remaining high bytes. The + * /dev/rtc interface can also be used with the select(2) call. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + + * 1.01 fix for 2.3.X rz@linux-m68k.org + * 1.02 merged with code from genrtc.c rz@linux-m68k.org + * 1.03 make it more portable zippel@linux-m68k.org + * 1.04 removed useless timer code rz@linux-m68k.org + * 1.05 portable RTC_UIE emulation rz@linux-m68k.org + * 1.06 set_rtc_time can return an error trini@kernel.crashing.org + */ + +#define RTC_VERSION "1.06" + +#include <linux/module.h> +#include <linux/config.h> +#include <linux/errno.h> +#include <linux/miscdevice.h> +#include <linux/fcntl.h> + +#include <linux/rtc.h> +#include <linux/init.h> +#include <linux/poll.h> +#include <linux/proc_fs.h> + +#include <asm/uaccess.h> +#include <asm/system.h> +#include <asm/rtc.h> + +/* + * We sponge a minor off of the misc major. No need slurping + * up another valuable major dev number for this. If you add + * an ioctl, make sure you don't conflict with SPARC's RTC + * ioctls. + */ + +static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); + +static int gen_rtc_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg); + +/* + * Bits in gen_rtc_status. + */ + +#define RTC_IS_OPEN 0x01 /* means /dev/rtc is in use */ + +unsigned char gen_rtc_status; /* bitmapped status byte. */ +unsigned long gen_rtc_irq_data; /* our output to the world */ + +/* months start at 0 now */ +unsigned char days_in_mo[] = +{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +static int irq_active; + +#ifdef CONFIG_GEN_RTC_X +struct tq_struct genrtc_task; +static struct timer_list timer_task; + +static unsigned int oldsecs; +static int lostint; +static int tt_exp; + +void gen_rtc_timer(unsigned long data); + +static volatile int stask_active; /* schedule_task */ +static volatile int ttask_active; /* timer_task */ +static int stop_rtc_timers; /* don't requeue tasks */ +static spinlock_t gen_rtc_lock = SPIN_LOCK_UNLOCKED; + +/* + * Routine to poll RTC seconds field for change as often as posible, + * after first RTC_UIE use timer to reduce polling + */ +void genrtc_troutine(void *data) +{ + unsigned int tmp = get_rtc_ss(); + + if (stop_rtc_timers) { + stask_active = 0; + return; + } + + if (oldsecs != tmp){ + oldsecs = tmp; + + timer_task.function = gen_rtc_timer; + timer_task.expires = jiffies + HZ - (HZ/10); + tt_exp=timer_task.expires; + ttask_active=1; + stask_active=0; + add_timer(&timer_task); + + gen_rtc_interrupt(0); + } else if (schedule_task(&genrtc_task) == 0) + stask_active = 0; +} + +void gen_rtc_timer(unsigned long data) +{ + lostint = get_rtc_ss() - oldsecs ; + if (lostint<0) + lostint = 60 - lostint; + if (time_after(jiffies, tt_exp)) + printk(KERN_INFO "genrtc: timer task delayed by %ld jiffies\n", + jiffies-tt_exp); + ttask_active=0; + stask_active=1; + if ((schedule_task(&genrtc_task) == 0)) + stask_active = 0; +} + +/* + * call gen_rtc_interrupt function to signal an RTC_UIE, + * arg is unused. + * Could be invoked either from a real interrupt handler or + * from some routine that periodically (eg 100HZ) monitors + * whether RTC_SECS changed + */ +void gen_rtc_interrupt(unsigned long arg) +{ + /* We store the status in the low byte and the number of + * interrupts received since the last read in the remainder + * of rtc_irq_data. */ + + gen_rtc_irq_data += 0x100; + gen_rtc_irq_data &= ~0xff; + gen_rtc_irq_data |= RTC_UIE; + + if (lostint){ + printk("genrtc: system delaying clock ticks?\n"); + /* increment count so that userspace knows something is wrong */ + gen_rtc_irq_data += ((lostint-1)<<8); + lostint = 0; + } + + wake_up_interruptible(&gen_rtc_wait); +} + +/* + * Now all the various file operations that we export. + */ +static ssize_t gen_rtc_read(struct file *file, char *buf, + size_t count, loff_t *ppos) +{ + DECLARE_WAITQUEUE(wait, current); + unsigned long data; + ssize_t retval; + + if (count != sizeof (unsigned int) && count != sizeof (unsigned long)) + return -EINVAL; + + if (file->f_flags & O_NONBLOCK && !gen_rtc_irq_data) + return -EAGAIN; + + add_wait_queue(&gen_rtc_wait, &wait); + retval = -ERESTARTSYS; + + while (1) { + set_current_state(TASK_INTERRUPTIBLE); + data = xchg(&gen_rtc_irq_data, 0); + if (data) + break; + if (signal_pending(current)) + goto out; + schedule(); + } + + /* first test allows optimizer to nuke this case for 32-bit machines */ + if (sizeof (int) != sizeof (long) && count == sizeof (unsigned int)) { + unsigned int uidata = data; + retval = put_user(uidata, (unsigned long *)buf); + } + else { + retval = put_user(data, (unsigned long *)buf); + } + if (!retval) + retval = sizeof(unsigned long); + out: + current->state = TASK_RUNNING; + remove_wait_queue(&gen_rtc_wait, &wait); + + return retval; +} + +static unsigned int gen_rtc_poll(struct file *file, + struct poll_table_struct *wait) +{ + poll_wait(file, &gen_rtc_wait, wait); + if (gen_rtc_irq_data != 0) + return POLLIN | POLLRDNORM; + return 0; +} + +#endif + +/* + * Used to disable/enable interrupts, only RTC_UIE supported + * We also clear out any old irq data after an ioctl() that + * meddles with the interrupt enable/disable bits. + */ + +static inline void gen_clear_rtc_irq_bit(unsigned char bit) +{ +#ifdef CONFIG_GEN_RTC_X + stop_rtc_timers = 1; + if (ttask_active){ + del_timer_sync(&timer_task); + ttask_active = 0; + } + while (stask_active) + schedule(); + + spin_lock(&gen_rtc_lock); + irq_active = 0; + spin_unlock(&gen_rtc_lock); +#endif +} + +static inline int gen_set_rtc_irq_bit(unsigned char bit) +{ +#ifdef CONFIG_GEN_RTC_X + spin_lock(&gen_rtc_lock); + if ( !irq_active ) { + irq_active = 1; + stop_rtc_timers = 0; + lostint = 0; + genrtc_task.routine = genrtc_troutine; + oldsecs = get_rtc_ss(); + init_timer(&timer_task); + + stask_active = 1; + if (schedule_task(&genrtc_task) == 0){ + stask_active = 0; + } + } + spin_unlock(&gen_rtc_lock); + gen_rtc_irq_data = 0; + return 0; +#else + return -EINVAL; +#endif +} + +static int gen_rtc_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) +{ + struct rtc_time wtime; + struct rtc_pll_info pll; + + switch (cmd) { + + case RTC_PLL_GET: + if (get_rtc_pll(&pll)) + return -EINVAL; + else + return copy_to_user((void *)arg, &pll, sizeof pll) ? -EFAULT : 0; + + case RTC_PLL_SET: + if (!capable(CAP_SYS_TIME)) + return -EACCES; + if (copy_from_user(&pll, (struct rtc_pll_info*)arg, + sizeof(pll))) + return -EFAULT; + return set_rtc_pll(&pll); + + case RTC_UIE_OFF: /* disable ints from RTC updates. */ + gen_clear_rtc_irq_bit(RTC_UIE); + return 0; + + case RTC_UIE_ON: /* enable ints for RTC updates. */ + return gen_set_rtc_irq_bit(RTC_UIE); + + case RTC_RD_TIME: /* Read the time/date from RTC */ + /* this doesn't get week-day, who cares */ + memset(&wtime, 0, sizeof(wtime)); + get_rtc_time(&wtime); + + return copy_to_user((void *)arg, &wtime, sizeof(wtime)) ? -EFAULT : 0; + + case RTC_SET_TIME: /* Set the RTC */ + { + int year; + unsigned char leap_yr; + + if (!capable(CAP_SYS_TIME)) + return -EACCES; + + if (copy_from_user(&wtime, (struct rtc_time *)arg, + sizeof(wtime))) + return -EFAULT; + + year = wtime.tm_year + 1900; + leap_yr = ((!(year % 4) && (year % 100)) || + !(year % 400)); + + if ((wtime.tm_mon < 0 || wtime.tm_mon > 11) || (wtime.tm_mday < 1)) + return -EINVAL; + + if (wtime.tm_mday < 0 || wtime.tm_mday > + (days_in_mo[wtime.tm_mon] + ((wtime.tm_mon == 1) && leap_yr))) + return -EINVAL; + + if (wtime.tm_hour < 0 || wtime.tm_hour >= 24 || + wtime.tm_min < 0 || wtime.tm_min >= 60 || + wtime.tm_sec < 0 || wtime.tm_sec >= 60) + return -EINVAL; + + return set_rtc_time(&wtime); + } + } + + return -EINVAL; +} + +/* + * We enforce only one user at a time here with the open/close. + * Also clear the previous interrupt data on an open, and clean + * up things on a close. + */ + +static int gen_rtc_open(struct inode *inode, struct file *file) +{ + if (gen_rtc_status & RTC_IS_OPEN) + return -EBUSY; + + MOD_INC_USE_COUNT; + + gen_rtc_status |= RTC_IS_OPEN; + gen_rtc_irq_data = 0; + irq_active = 0; + + return 0; +} + +static int gen_rtc_release(struct inode *inode, struct file *file) +{ + /* + * Turn off all interrupts once the device is no longer + * in use and clear the data. + */ + + gen_clear_rtc_irq_bit(RTC_PIE|RTC_AIE|RTC_UIE); + + gen_rtc_status &= ~RTC_IS_OPEN; + MOD_DEC_USE_COUNT; + + return 0; +} + +static int gen_rtc_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data); + + +/* + * The various file operations we support. + */ + +static struct file_operations gen_rtc_fops = { + owner: THIS_MODULE, +#ifdef CONFIG_GEN_RTC_X + read: gen_rtc_read, + poll: gen_rtc_poll, +#endif + ioctl: gen_rtc_ioctl, + open: gen_rtc_open, + release: gen_rtc_release +}; + +static struct miscdevice rtc_gen_dev = +{ + RTC_MINOR, + "rtc", + &gen_rtc_fops +}; + +int __init rtc_generic_init(void) +{ + + printk(KERN_INFO "Generic RTC Driver v%s\n", RTC_VERSION); + + misc_register(&rtc_gen_dev); + create_proc_read_entry ("driver/rtc", 0, 0, gen_rtc_read_proc, NULL); + + return 0; +} + +static void __exit rtc_generic_exit(void) +{ + remove_proc_entry ("driver/rtc", NULL); + misc_deregister(&rtc_gen_dev); +} + +module_init(rtc_generic_init); +module_exit(rtc_generic_exit); +EXPORT_NO_SYMBOLS; + + +/* + * Info exported via "/proc/rtc". + */ + +int gen_rtc_proc_output(char *buf) +{ + char *p; + struct rtc_time tm; + unsigned tmp; + struct rtc_pll_info pll; + + p = buf; + + get_rtc_time(&tm); + + p += sprintf(p, + "rtc_time\t: %02d:%02d:%02d\n" + "rtc_date\t: %04d-%02d-%02d\n" + "rtc_epoch\t: %04u\n", + tm.tm_hour, tm.tm_min, tm.tm_sec, + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, 1900); + + tm.tm_hour=0;tm.tm_min=0;tm.tm_sec=0; + + p += sprintf(p, "alarm\t\t: "); + if (tm.tm_hour <= 24) + p += sprintf(p, "%02d:", tm.tm_hour); + else + p += sprintf(p, "**:"); + + if (tm.tm_min <= 59) + p += sprintf(p, "%02d:", tm.tm_min); + else + p += sprintf(p, "**:"); + + if (tm.tm_sec <= 59) + p += sprintf(p, "%02d\n", tm.tm_sec); + else + p += sprintf(p, "**\n"); + + tmp= RTC_24H ; + p += sprintf(p, + "DST_enable\t: %s\n" + "BCD\t\t: %s\n" + "24hr\t\t: %s\n" + "square_wave\t: %s\n" + "alarm_IRQ\t: %s\n" + "update_IRQ\t: %s\n" + "periodic_IRQ\t: %s\n" + "periodic_freq\t: %ld\n" + "batt_status\t: %s\n", + (tmp & RTC_DST_EN) ? "yes" : "no", + (tmp & RTC_DM_BINARY) ? "no" : "yes", + (tmp & RTC_24H) ? "yes" : "no", + (tmp & RTC_SQWE) ? "yes" : "no", + (tmp & RTC_AIE) ? "yes" : "no", + irq_active ? "yes" : "no", + (tmp & RTC_PIE) ? "yes" : "no", + 0L /* freq */, + "okay" ); + if (!get_rtc_pll(&pll)) + p += sprintf(p, + "PLL adjustment\t: %d\n" + "PLL max +ve adjustment\t: %d\n" + "PLL max -ve adjustment\t: %d\n" + "PLL +ve adjustment factor\t: %d\n" + "PLL -ve adjustment factor\t: %d\n" + "PLL frequency\t: %ld\n", + pll.pll_value, + pll.pll_max, + pll.pll_min, + pll.pll_posmult, + pll.pll_negmult, + pll.pll_clock); + return p - buf; +} + +static int gen_rtc_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + int len = gen_rtc_proc_output (page); + if (len <= off+count) *eof = 1; + *start = page + off; + len -= off; + if (len>count) len = count; + if (len<0) len = 0; + return len; +} + + +MODULE_AUTHOR("Richard Zidlicky"); +MODULE_LICENSE("GPL"); + +/* + * Local variables: + * compile-command: "m68k-linux-gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -ffixed-a2 -c -o genrtc.o genrtc.c" + * End: + */ + --- linux-2.4.20/include/asm-m68k/machdep.h Wed May 29 10:14:12 2002 +++ linux-m68k-2.4.20/include/asm-m68k/machdep.h Mon Sep 9 13:07:29 2002 @@ -5,6 +5,7 @@ struct kbd_repeat; struct mktime; struct rtc_time; +struct rtc_pll_info; struct gendisk; struct buffer_head; @@ -29,6 +30,9 @@ extern void (*mach_gettod)(int *year, int *mon, int *day, int *hour, int *min, int *sec); 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 ); --- linux-2.4.20/include/asm-m68k/rtc.h Wed May 29 10:14:13 2002 +++ linux-m68k-2.4.20/include/asm-m68k/rtc.h Sun Jan 5 15:24:28 2003 @@ -13,9 +13,8 @@ #ifdef __KERNEL__ -#include <linux/config.h> #include <linux/rtc.h> -#include <linux/delay.h> +#include <asm/errno.h> #include <asm/machdep.h> #define RTC_PIE 0x40 /* periodic interrupt enable */ @@ -30,7 +29,48 @@ #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 */ +static inline void get_rtc_time(struct rtc_time *time) +{ + /* + * Only the values that we read from the RTC are set. We leave + * tm_wday, tm_yday and tm_isdst untouched. Even though the + * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated + * by the RTC when initially set to a non-zero value. + */ + mach_hwclk(0, time); +} +static inline int set_rtc_time(struct rtc_time *time) +{ + return mach_hwclk(1, time); +} + +static inline unsigned int get_rtc_ss(void) +{ + if (mach_get_ss) + return mach_get_ss(); + else{ + struct rtc_time h; + + get_rtc_time(&h); + return h.tm_sec; + } +} + +static inline int get_rtc_pll(struct rtc_pll_info *pll) +{ + if (mach_get_rtc_pll) + return mach_get_rtc_pll(pll); + else + return -EINVAL; +} +static inline int set_rtc_pll(struct rtc_pll_info *pll) +{ + if (mach_set_rtc_pll) + return mach_set_rtc_pll(pll); + else + return -EINVAL; +} #endif /* __KERNEL__ */ #endif /* _ASM__RTC_H */ --- linux-2.4.20/include/linux/rtc.h Mon Feb 19 09:47:19 2001 +++ linux-m68k-2.4.20/include/linux/rtc.h Sun Jan 5 15:24:28 2003 @@ -39,10 +39,32 @@ struct rtc_time time; /* time the alarm is set to */ }; +/* + * Data structure to control PLL correction some better RTC feature + * pll_value is used to get or set current value of correction, + * the rest of the struct is used to query HW capabilities. + * This is modeled after the RTC used in Q40/Q60 computers but + * should be sufficiently flexible for other devices + * + * +ve pll_value means clock will run faster by + * pll_value*pll_posmult/pll_clock + * -ve pll_value means clock will run slower by + * pll_value*pll_negmult/pll_clock + */ + +struct rtc_pll_info { + int pll_ctrl; /* placeholder for fancier control */ + int pll_value; /* get/set correction value */ + int pll_max; /* max +ve (faster) adjustment value */ + int pll_min; /* max -ve (slower) adjustment value */ + int pll_posmult; /* factor for +ve corection */ + int pll_negmult; /* factor for -ve corection */ + long pll_clock; /* base PLL frequency */ +}; /* - * ioctl calls that are permitted to the /dev/rtc interface, if - * CONFIG_RTC/CONFIG_EFI_RTC was enabled. + * ioctl calls that are permitted to the /dev/rtc interface, if + * any of the RTC drivers are enabled. */ #define RTC_AIE_ON _IO('p', 0x01) /* Alarm int. enable on */ @@ -66,4 +88,6 @@ #define RTC_WKALM_SET _IOW('p', 0x0f, struct rtc_wkalrm)/* Set wakeup alarm*/ #define RTC_WKALM_RD _IOR('p', 0x10, struct rtc_wkalrm)/* Get wakeup alarm*/ +#define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info) /* Get PLL correction */ +#define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info) /* Set PLL correction */ #endif /* _LINUX_RTC_H_ */ 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] 30+ messages in thread
* [parisc-linux] Generic RTC driver in 2.4.x 2003-01-05 14:44 ` Geert Uytterhoeven @ 2003-01-10 20:05 ` Geert Uytterhoeven 2003-01-10 20:05 ` [parisc-linux] " Geert Uytterhoeven 1 sibling, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2003-01-10 20:05 UTC (permalink / raw) To: Alan Cox, parisc-linux, Linux/PPC Development Cc: Linux Kernel Development, Linux/m68k Unfortunately I didn't receive any feedback from the pa-risc and ppc people after my previous posting last Sunday. Alan, I'm explicitly sending it to you for inclusion in your ac tree. I intend to send it to Marcelo after the weekend. Changes since last Sunday: - fix spelling of `automatically' (from Geoffrey Lee <glee@gnupilgrims.org>) - misc_register() and create_proc_read_entry() can fail (from mikal@stillhq.com in 2.5.x) - create_proc_read_entry() depends on CONFIG_PROC_FS (from mikal@stillhq.com in 2.5.x) The following patch adds the generic RTC driver to 2.4.20 (applies fine to 2.4.21-pre3). This driver provides a /dev/rtc-compatible interface to the real time clock on machines without a PC-style RTC chip. It is used as the primary RTC driver on m68k, pa-risc, and ppc. This driver is already present in 2.5.x. Pa-risc and ppc people (any other users?), please send me your enhancements (or just ack if none are necessary), so I can send genrtc to Marcelo. Thanks! Documentation/Configure.help | 28 ++ arch/m68k/config.in | 5 arch/m68k/kernel/m68k_ksyms.c | 5 arch/m68k/kernel/setup.c | 3 arch/m68k/q40/config.c | 41 +++ drivers/char/Makefile | 1 drivers/char/genrtc.c | 533 ++++++++++++++++++++++++++++++++++++++++++ include/asm-m68k/machdep.h | 4 include/asm-m68k/rtc.h | 44 +++ include/linux/rtc.h | 28 ++ 10 files changed, 687 insertions(+), 5 deletions(-) --- linux-2.4.20/Documentation/Configure.help Tue Oct 29 18:40:45 2002 +++ linux-genrtc-2.4.20/Documentation/Configure.help Fri Jan 10 20:54:52 2003 @@ -18959,6 +18959,34 @@ The module is called rtc.o. If you want to compile it as a module, say M here and read <file:Documentation/modules.txt>. +Generic Real Time Clock Support +CONFIG_GEN_RTC + If you say Y here and create a character special file /dev/rtc with + major number 10 and minor number 135 using mknod ("man mknod"), you + will get access to the real time clock (or hardware clock) built + into your computer. + + In 2.4 and later kernels this is the only way to set and get rtc + time on m68k systems so it is highly recommended. + + It reports status information via the file /proc/driver/rtc and its + behaviour is set by various ioctls on /dev/rtc. If you enable the + "extended RTC operation" below it will also provide an emulation + for RTC_UIE which is required by some programs and may improve + precision in some cases. + + This driver is also available as a module ( = code which can be + inserted in and removed from the running kernel whenever you want). + The module is called genrtc.o. If you want to compile it as a module, + say M here and read <file:Documentation/modules.txt>. To load the + module automatically add 'alias char-major-10-135 genrtc' to your + /etc/modules.conf + +Extended RTC operation +CONFIG_GEN_RTC_X + Provides an emulation for RTC_UIE which is required by some programs + and may improve precision of the generic RTC support in some cases. + Tadpole ANA H8 Support CONFIG_H8 The Hitachi H8/337 is a microcontroller used to deal with the power --- linux-2.4.20/arch/m68k/config.in Fri Sep 13 10:14:59 2002 +++ linux-genrtc-2.4.20/arch/m68k/config.in Fri Jan 10 20:54:25 2003 @@ -517,8 +517,11 @@ if [ "$CONFIG_SUN3" = "y" ]; then define_bool CONFIG_GEN_RTC y else - bool 'Generic /dev/rtc emulation' CONFIG_GEN_RTC + tristate 'Generic /dev/rtc emulation' CONFIG_GEN_RTC fi +fi +if [ "$CONFIG_GEN_RTC" != "n" ]; then + bool ' Extended RTC operation' CONFIG_GEN_RTC_X fi bool 'Unix98 PTY support' CONFIG_UNIX98_PTYS if [ "$CONFIG_UNIX98_PTYS" = "y" ]; then --- linux-2.4.20/arch/m68k/kernel/m68k_ksyms.c Thu Jan 4 22:00:55 2001 +++ linux-genrtc-2.4.20/arch/m68k/kernel/m68k_ksyms.c Fri Jan 10 20:54:25 2003 @@ -18,6 +18,7 @@ #include <asm/checksum.h> #include <asm/hardirq.h> #include <asm/softirq.h> +#include <asm/rtc.h> asmlinkage long long __ashldi3 (long long, int); asmlinkage long long __ashrdi3 (long long, int); @@ -49,6 +50,10 @@ EXPORT_SYMBOL(kernel_set_cachemode); #endif /* !CONFIG_SUN3 */ EXPORT_SYMBOL(m68k_debug_device); +EXPORT_SYMBOL(mach_hwclk); +EXPORT_SYMBOL(mach_get_ss); +EXPORT_SYMBOL(mach_get_rtc_pll); +EXPORT_SYMBOL(mach_set_rtc_pll); EXPORT_SYMBOL(dump_fpu); EXPORT_SYMBOL(dump_thread); EXPORT_SYMBOL(strnlen); --- linux-2.4.20/arch/m68k/kernel/setup.c Fri Sep 13 10:15:01 2002 +++ linux-genrtc-2.4.20/arch/m68k/kernel/setup.c Fri Jan 10 20:54:25 2003 @@ -90,6 +90,9 @@ void (*mach_gettod) (int*, int*, int*, int*, int*, int*); int (*mach_hwclk) (int, struct rtc_time*) = NULL; int (*mach_set_clock_mmss) (unsigned long) = NULL; +unsigned int (*mach_get_ss)(void) = NULL; +int (*mach_get_rtc_pll)(struct rtc_pll_info *) = NULL; +int (*mach_set_rtc_pll)(struct rtc_pll_info *) = NULL; void (*mach_reset)( void ); void (*mach_halt)( void ) = NULL; void (*mach_power_off)( void ) = NULL; --- linux-2.4.20/arch/m68k/q40/config.c Fri Sep 13 10:15:02 2002 +++ linux-genrtc-2.4.20/arch/m68k/q40/config.c Fri Jan 10 20:54:25 2003 @@ -58,7 +58,10 @@ extern void q40_gettod (int *year, int *mon, int *day, int *hour, int *min, int *sec); extern int q40_hwclk (int, struct rtc_time *); +extern unsigned int q40_get_ss (void); extern 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); extern void q40_reset (void); void q40_halt(void); extern void q40_waitbut(void); @@ -196,6 +199,9 @@ mach_gettimeoffset = q40_gettimeoffset; mach_gettod = q40_gettod; mach_hwclk = q40_hwclk; + 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; @@ -331,6 +337,11 @@ return 0; } +unsigned int q40_get_ss() +{ + 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. @@ -362,3 +373,33 @@ 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) + +static int q40_get_rtc_pll(struct rtc_pll_info *pll) +{ + int tmp=Q40_RTC_CTRL; + pll->pll_value = tmp & Q40_RTC_PLL_MASK; + if (tmp & Q40_RTC_PLL_SIGN) + pll->pll_value = -pll->pll_value; + pll->pll_max=31; + pll->pll_min=-31; + pll->pll_posmult=512; + pll->pll_negmult=256; + pll->pll_clock=125829120; + return 0; + } + +static int q40_set_rtc_pll(struct rtc_pll_info *pll) +{ + if (!pll->pll_ctrl){ + /* the docs are a bit unclear so I am doublesetting RTC_WRITE here ... */ + int tmp=(pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) | Q40_RTC_WRITE; + Q40_RTC_CTRL |= Q40_RTC_WRITE; + Q40_RTC_CTRL = tmp; + Q40_RTC_CTRL &= ~(Q40_RTC_WRITE); + return 0; + } else return -EINVAL; +} --- linux-2.4.20/drivers/char/Makefile Wed Nov 27 11:02:06 2002 +++ linux-genrtc-2.4.20/drivers/char/Makefile Fri Jan 10 20:54:25 2003 @@ -222,6 +222,7 @@ obj-$(CONFIG_PC110_PAD) += pc110pad.o obj-$(CONFIG_MK712_MOUSE) += mk712.o obj-$(CONFIG_RTC) += rtc.o +obj-$(CONFIG_GEN_RTC) += genrtc.o obj-$(CONFIG_EFI_RTC) += efirtc.o ifeq ($(CONFIG_PPC),) obj-$(CONFIG_NVRAM) += nvram.o --- linux-2.4.20/drivers/char/genrtc.c Thu Jan 1 01:00:00 1970 +++ linux-genrtc-2.4.20/drivers/char/genrtc.c Fri Jan 10 20:54:52 2003 @@ -0,0 +1,533 @@ +/* + * Real Time Clock interface for q40 and other m68k machines + * emulate some RTC irq capabilities in software + * + * Copyright (C) 1999 Richard Zidlicky + * + * based on Paul Gortmaker's rtc.c device and + * Sam Creasey Generic rtc driver + * + * This driver allows use of the real time clock (built into + * nearly all computers) from user space. It exports the /dev/rtc + * interface supporting various ioctl() and also the /proc/dev/rtc + * pseudo-file for status information. + * + * The ioctls can be used to set the interrupt behaviour where + * supported. + * + * The /dev/rtc interface will block on reads until an interrupt + * has been received. If a RTC interrupt has already happened, + * it will output an unsigned long and then block. The output value + * contains the interrupt status in the low byte and the number of + * interrupts since the last read in the remaining high bytes. The + * /dev/rtc interface can also be used with the select(2) call. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + + * 1.01 fix for 2.3.X rz@linux-m68k.org + * 1.02 merged with code from genrtc.c rz@linux-m68k.org + * 1.03 make it more portable zippel@linux-m68k.org + * 1.04 removed useless timer code rz@linux-m68k.org + * 1.05 portable RTC_UIE emulation rz@linux-m68k.org + * 1.06 set_rtc_time can return an error trini@kernel.crashing.org + */ + +#define RTC_VERSION "1.06" + +#include <linux/module.h> +#include <linux/config.h> +#include <linux/errno.h> +#include <linux/miscdevice.h> +#include <linux/fcntl.h> + +#include <linux/rtc.h> +#include <linux/init.h> +#include <linux/poll.h> +#include <linux/proc_fs.h> + +#include <asm/uaccess.h> +#include <asm/system.h> +#include <asm/rtc.h> + +/* + * We sponge a minor off of the misc major. No need slurping + * up another valuable major dev number for this. If you add + * an ioctl, make sure you don't conflict with SPARC's RTC + * ioctls. + */ + +static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); + +static int gen_rtc_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg); + +/* + * Bits in gen_rtc_status. + */ + +#define RTC_IS_OPEN 0x01 /* means /dev/rtc is in use */ + +unsigned char gen_rtc_status; /* bitmapped status byte. */ +unsigned long gen_rtc_irq_data; /* our output to the world */ + +/* months start at 0 now */ +unsigned char days_in_mo[] = +{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +static int irq_active; + +#ifdef CONFIG_GEN_RTC_X +struct tq_struct genrtc_task; +static struct timer_list timer_task; + +static unsigned int oldsecs; +static int lostint; +static int tt_exp; + +void gen_rtc_timer(unsigned long data); + +static volatile int stask_active; /* schedule_task */ +static volatile int ttask_active; /* timer_task */ +static int stop_rtc_timers; /* don't requeue tasks */ +static spinlock_t gen_rtc_lock = SPIN_LOCK_UNLOCKED; + +/* + * Routine to poll RTC seconds field for change as often as posible, + * after first RTC_UIE use timer to reduce polling + */ +void genrtc_troutine(void *data) +{ + unsigned int tmp = get_rtc_ss(); + + if (stop_rtc_timers) { + stask_active = 0; + return; + } + + if (oldsecs != tmp){ + oldsecs = tmp; + + timer_task.function = gen_rtc_timer; + timer_task.expires = jiffies + HZ - (HZ/10); + tt_exp=timer_task.expires; + ttask_active=1; + stask_active=0; + add_timer(&timer_task); + + gen_rtc_interrupt(0); + } else if (schedule_task(&genrtc_task) == 0) + stask_active = 0; +} + +void gen_rtc_timer(unsigned long data) +{ + lostint = get_rtc_ss() - oldsecs ; + if (lostint<0) + lostint = 60 - lostint; + if (time_after(jiffies, tt_exp)) + printk(KERN_INFO "genrtc: timer task delayed by %ld jiffies\n", + jiffies-tt_exp); + ttask_active=0; + stask_active=1; + if ((schedule_task(&genrtc_task) == 0)) + stask_active = 0; +} + +/* + * call gen_rtc_interrupt function to signal an RTC_UIE, + * arg is unused. + * Could be invoked either from a real interrupt handler or + * from some routine that periodically (eg 100HZ) monitors + * whether RTC_SECS changed + */ +void gen_rtc_interrupt(unsigned long arg) +{ + /* We store the status in the low byte and the number of + * interrupts received since the last read in the remainder + * of rtc_irq_data. */ + + gen_rtc_irq_data += 0x100; + gen_rtc_irq_data &= ~0xff; + gen_rtc_irq_data |= RTC_UIE; + + if (lostint){ + printk("genrtc: system delaying clock ticks?\n"); + /* increment count so that userspace knows something is wrong */ + gen_rtc_irq_data += ((lostint-1)<<8); + lostint = 0; + } + + wake_up_interruptible(&gen_rtc_wait); +} + +/* + * Now all the various file operations that we export. + */ +static ssize_t gen_rtc_read(struct file *file, char *buf, + size_t count, loff_t *ppos) +{ + DECLARE_WAITQUEUE(wait, current); + unsigned long data; + ssize_t retval; + + if (count != sizeof (unsigned int) && count != sizeof (unsigned long)) + return -EINVAL; + + if (file->f_flags & O_NONBLOCK && !gen_rtc_irq_data) + return -EAGAIN; + + add_wait_queue(&gen_rtc_wait, &wait); + retval = -ERESTARTSYS; + + while (1) { + set_current_state(TASK_INTERRUPTIBLE); + data = xchg(&gen_rtc_irq_data, 0); + if (data) + break; + if (signal_pending(current)) + goto out; + schedule(); + } + + /* first test allows optimizer to nuke this case for 32-bit machines */ + if (sizeof (int) != sizeof (long) && count == sizeof (unsigned int)) { + unsigned int uidata = data; + retval = put_user(uidata, (unsigned long *)buf); + } + else { + retval = put_user(data, (unsigned long *)buf); + } + if (!retval) + retval = sizeof(unsigned long); + out: + current->state = TASK_RUNNING; + remove_wait_queue(&gen_rtc_wait, &wait); + + return retval; +} + +static unsigned int gen_rtc_poll(struct file *file, + struct poll_table_struct *wait) +{ + poll_wait(file, &gen_rtc_wait, wait); + if (gen_rtc_irq_data != 0) + return POLLIN | POLLRDNORM; + return 0; +} + +#endif + +/* + * Used to disable/enable interrupts, only RTC_UIE supported + * We also clear out any old irq data after an ioctl() that + * meddles with the interrupt enable/disable bits. + */ + +static inline void gen_clear_rtc_irq_bit(unsigned char bit) +{ +#ifdef CONFIG_GEN_RTC_X + stop_rtc_timers = 1; + if (ttask_active){ + del_timer_sync(&timer_task); + ttask_active = 0; + } + while (stask_active) + schedule(); + + spin_lock(&gen_rtc_lock); + irq_active = 0; + spin_unlock(&gen_rtc_lock); +#endif +} + +static inline int gen_set_rtc_irq_bit(unsigned char bit) +{ +#ifdef CONFIG_GEN_RTC_X + spin_lock(&gen_rtc_lock); + if ( !irq_active ) { + irq_active = 1; + stop_rtc_timers = 0; + lostint = 0; + genrtc_task.routine = genrtc_troutine; + oldsecs = get_rtc_ss(); + init_timer(&timer_task); + + stask_active = 1; + if (schedule_task(&genrtc_task) == 0){ + stask_active = 0; + } + } + spin_unlock(&gen_rtc_lock); + gen_rtc_irq_data = 0; + return 0; +#else + return -EINVAL; +#endif +} + +static int gen_rtc_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) +{ + struct rtc_time wtime; + struct rtc_pll_info pll; + + switch (cmd) { + + case RTC_PLL_GET: + if (get_rtc_pll(&pll)) + return -EINVAL; + else + return copy_to_user((void *)arg, &pll, sizeof pll) ? -EFAULT : 0; + + case RTC_PLL_SET: + if (!capable(CAP_SYS_TIME)) + return -EACCES; + if (copy_from_user(&pll, (struct rtc_pll_info*)arg, + sizeof(pll))) + return -EFAULT; + return set_rtc_pll(&pll); + + case RTC_UIE_OFF: /* disable ints from RTC updates. */ + gen_clear_rtc_irq_bit(RTC_UIE); + return 0; + + case RTC_UIE_ON: /* enable ints for RTC updates. */ + return gen_set_rtc_irq_bit(RTC_UIE); + + case RTC_RD_TIME: /* Read the time/date from RTC */ + /* this doesn't get week-day, who cares */ + memset(&wtime, 0, sizeof(wtime)); + get_rtc_time(&wtime); + + return copy_to_user((void *)arg, &wtime, sizeof(wtime)) ? -EFAULT : 0; + + case RTC_SET_TIME: /* Set the RTC */ + { + int year; + unsigned char leap_yr; + + if (!capable(CAP_SYS_TIME)) + return -EACCES; + + if (copy_from_user(&wtime, (struct rtc_time *)arg, + sizeof(wtime))) + return -EFAULT; + + year = wtime.tm_year + 1900; + leap_yr = ((!(year % 4) && (year % 100)) || + !(year % 400)); + + if ((wtime.tm_mon < 0 || wtime.tm_mon > 11) || (wtime.tm_mday < 1)) + return -EINVAL; + + if (wtime.tm_mday < 0 || wtime.tm_mday > + (days_in_mo[wtime.tm_mon] + ((wtime.tm_mon == 1) && leap_yr))) + return -EINVAL; + + if (wtime.tm_hour < 0 || wtime.tm_hour >= 24 || + wtime.tm_min < 0 || wtime.tm_min >= 60 || + wtime.tm_sec < 0 || wtime.tm_sec >= 60) + return -EINVAL; + + return set_rtc_time(&wtime); + } + } + + return -EINVAL; +} + +/* + * We enforce only one user at a time here with the open/close. + * Also clear the previous interrupt data on an open, and clean + * up things on a close. + */ + +static int gen_rtc_open(struct inode *inode, struct file *file) +{ + if (gen_rtc_status & RTC_IS_OPEN) + return -EBUSY; + + MOD_INC_USE_COUNT; + + gen_rtc_status |= RTC_IS_OPEN; + gen_rtc_irq_data = 0; + irq_active = 0; + + return 0; +} + +static int gen_rtc_release(struct inode *inode, struct file *file) +{ + /* + * Turn off all interrupts once the device is no longer + * in use and clear the data. + */ + + gen_clear_rtc_irq_bit(RTC_PIE|RTC_AIE|RTC_UIE); + + gen_rtc_status &= ~RTC_IS_OPEN; + MOD_DEC_USE_COUNT; + + return 0; +} + +static int gen_rtc_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data); + + +/* + * The various file operations we support. + */ + +static struct file_operations gen_rtc_fops = { + owner: THIS_MODULE, +#ifdef CONFIG_GEN_RTC_X + read: gen_rtc_read, + poll: gen_rtc_poll, +#endif + ioctl: gen_rtc_ioctl, + open: gen_rtc_open, + release: gen_rtc_release +}; + +static struct miscdevice rtc_gen_dev = +{ + RTC_MINOR, + "rtc", + &gen_rtc_fops +}; + +int __init rtc_generic_init(void) +{ + int retval; + + printk(KERN_INFO "Generic RTC Driver v%s\n", RTC_VERSION); + + retval = misc_register(&rtc_gen_dev); + if(retval < 0) + return retval; + +#ifdef CONFIG_PROC_FS + if((create_proc_read_entry ("driver/rtc", 0, 0, gen_rtc_read_proc, NULL)) == NULL){ + misc_deregister(&rtc_gen_dev); + return -ENOMEM; + } +#endif + + return 0; +} + +static void __exit rtc_generic_exit(void) +{ + remove_proc_entry ("driver/rtc", NULL); + misc_deregister(&rtc_gen_dev); +} + +module_init(rtc_generic_init); +module_exit(rtc_generic_exit); +EXPORT_NO_SYMBOLS; + + +/* + * Info exported via "/proc/rtc". + */ + +int gen_rtc_proc_output(char *buf) +{ + char *p; + struct rtc_time tm; + unsigned tmp; + struct rtc_pll_info pll; + + p = buf; + + get_rtc_time(&tm); + + p += sprintf(p, + "rtc_time\t: %02d:%02d:%02d\n" + "rtc_date\t: %04d-%02d-%02d\n" + "rtc_epoch\t: %04u\n", + tm.tm_hour, tm.tm_min, tm.tm_sec, + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, 1900); + + tm.tm_hour=0;tm.tm_min=0;tm.tm_sec=0; + + p += sprintf(p, "alarm\t\t: "); + if (tm.tm_hour <= 24) + p += sprintf(p, "%02d:", tm.tm_hour); + else + p += sprintf(p, "**:"); + + if (tm.tm_min <= 59) + p += sprintf(p, "%02d:", tm.tm_min); + else + p += sprintf(p, "**:"); + + if (tm.tm_sec <= 59) + p += sprintf(p, "%02d\n", tm.tm_sec); + else + p += sprintf(p, "**\n"); + + tmp= RTC_24H ; + p += sprintf(p, + "DST_enable\t: %s\n" + "BCD\t\t: %s\n" + "24hr\t\t: %s\n" + "square_wave\t: %s\n" + "alarm_IRQ\t: %s\n" + "update_IRQ\t: %s\n" + "periodic_IRQ\t: %s\n" + "periodic_freq\t: %ld\n" + "batt_status\t: %s\n", + (tmp & RTC_DST_EN) ? "yes" : "no", + (tmp & RTC_DM_BINARY) ? "no" : "yes", + (tmp & RTC_24H) ? "yes" : "no", + (tmp & RTC_SQWE) ? "yes" : "no", + (tmp & RTC_AIE) ? "yes" : "no", + irq_active ? "yes" : "no", + (tmp & RTC_PIE) ? "yes" : "no", + 0L /* freq */, + "okay" ); + if (!get_rtc_pll(&pll)) + p += sprintf(p, + "PLL adjustment\t: %d\n" + "PLL max +ve adjustment\t: %d\n" + "PLL max -ve adjustment\t: %d\n" + "PLL +ve adjustment factor\t: %d\n" + "PLL -ve adjustment factor\t: %d\n" + "PLL frequency\t: %ld\n", + pll.pll_value, + pll.pll_max, + pll.pll_min, + pll.pll_posmult, + pll.pll_negmult, + pll.pll_clock); + return p - buf; +} + +static int gen_rtc_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + int len = gen_rtc_proc_output (page); + if (len <= off+count) *eof = 1; + *start = page + off; + len -= off; + if (len>count) len = count; + if (len<0) len = 0; + return len; +} + + +MODULE_AUTHOR("Richard Zidlicky"); +MODULE_LICENSE("GPL"); + +/* + * Local variables: + * compile-command: "m68k-linux-gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -ffixed-a2 -c -o genrtc.o genrtc.c" + * End: + */ + --- linux-2.4.20/include/asm-m68k/machdep.h Wed May 29 10:14:12 2002 +++ linux-genrtc-2.4.20/include/asm-m68k/machdep.h Fri Jan 10 20:54:25 2003 @@ -5,6 +5,7 @@ struct kbd_repeat; struct mktime; struct rtc_time; +struct rtc_pll_info; struct gendisk; struct buffer_head; @@ -29,6 +30,9 @@ extern void (*mach_gettod)(int *year, int *mon, int *day, int *hour, int *min, int *sec); 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 ); --- linux-2.4.20/include/asm-m68k/rtc.h Wed May 29 10:14:13 2002 +++ linux-genrtc-2.4.20/include/asm-m68k/rtc.h Fri Jan 10 20:54:25 2003 @@ -13,9 +13,8 @@ #ifdef __KERNEL__ -#include <linux/config.h> #include <linux/rtc.h> -#include <linux/delay.h> +#include <asm/errno.h> #include <asm/machdep.h> #define RTC_PIE 0x40 /* periodic interrupt enable */ @@ -30,7 +29,48 @@ #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 */ +static inline void get_rtc_time(struct rtc_time *time) +{ + /* + * Only the values that we read from the RTC are set. We leave + * tm_wday, tm_yday and tm_isdst untouched. Even though the + * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated + * by the RTC when initially set to a non-zero value. + */ + mach_hwclk(0, time); +} +static inline int set_rtc_time(struct rtc_time *time) +{ + return mach_hwclk(1, time); +} + +static inline unsigned int get_rtc_ss(void) +{ + if (mach_get_ss) + return mach_get_ss(); + else{ + struct rtc_time h; + + get_rtc_time(&h); + return h.tm_sec; + } +} + +static inline int get_rtc_pll(struct rtc_pll_info *pll) +{ + if (mach_get_rtc_pll) + return mach_get_rtc_pll(pll); + else + return -EINVAL; +} +static inline int set_rtc_pll(struct rtc_pll_info *pll) +{ + if (mach_set_rtc_pll) + return mach_set_rtc_pll(pll); + else + return -EINVAL; +} #endif /* __KERNEL__ */ #endif /* _ASM__RTC_H */ --- linux-2.4.20/include/linux/rtc.h Mon Feb 19 09:47:19 2001 +++ linux-genrtc-2.4.20/include/linux/rtc.h Fri Jan 10 20:54:25 2003 @@ -39,10 +39,32 @@ struct rtc_time time; /* time the alarm is set to */ }; +/* + * Data structure to control PLL correction some better RTC feature + * pll_value is used to get or set current value of correction, + * the rest of the struct is used to query HW capabilities. + * This is modeled after the RTC used in Q40/Q60 computers but + * should be sufficiently flexible for other devices + * + * +ve pll_value means clock will run faster by + * pll_value*pll_posmult/pll_clock + * -ve pll_value means clock will run slower by + * pll_value*pll_negmult/pll_clock + */ + +struct rtc_pll_info { + int pll_ctrl; /* placeholder for fancier control */ + int pll_value; /* get/set correction value */ + int pll_max; /* max +ve (faster) adjustment value */ + int pll_min; /* max -ve (slower) adjustment value */ + int pll_posmult; /* factor for +ve corection */ + int pll_negmult; /* factor for -ve corection */ + long pll_clock; /* base PLL frequency */ +}; /* - * ioctl calls that are permitted to the /dev/rtc interface, if - * CONFIG_RTC/CONFIG_EFI_RTC was enabled. + * ioctl calls that are permitted to the /dev/rtc interface, if + * any of the RTC drivers are enabled. */ #define RTC_AIE_ON _IO('p', 0x01) /* Alarm int. enable on */ @@ -66,4 +88,6 @@ #define RTC_WKALM_SET _IOW('p', 0x0f, struct rtc_wkalrm)/* Set wakeup alarm*/ #define RTC_WKALM_RD _IOR('p', 0x10, struct rtc_wkalrm)/* Get wakeup alarm*/ +#define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info) /* Get PLL correction */ +#define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info) /* Set PLL correction */ #endif /* _LINUX_RTC_H_ */ 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] 30+ messages in thread
* Generic RTC driver in 2.4.x @ 2003-01-10 20:05 ` Geert Uytterhoeven 0 siblings, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2003-01-10 20:05 UTC (permalink / raw) To: Alan Cox, parisc-linux, Linux/PPC Development Cc: Linux Kernel Development, Linux/m68k Unfortunately I didn't receive any feedback from the pa-risc and ppc people after my previous posting last Sunday. Alan, I'm explicitly sending it to you for inclusion in your ac tree. I intend to send it to Marcelo after the weekend. Changes since last Sunday: - fix spelling of `automatically' (from Geoffrey Lee <glee@gnupilgrims.org>) - misc_register() and create_proc_read_entry() can fail (from mikal@stillhq.com in 2.5.x) - create_proc_read_entry() depends on CONFIG_PROC_FS (from mikal@stillhq.com in 2.5.x) The following patch adds the generic RTC driver to 2.4.20 (applies fine to 2.4.21-pre3). This driver provides a /dev/rtc-compatible interface to the real time clock on machines without a PC-style RTC chip. It is used as the primary RTC driver on m68k, pa-risc, and ppc. This driver is already present in 2.5.x. Pa-risc and ppc people (any other users?), please send me your enhancements (or just ack if none are necessary), so I can send genrtc to Marcelo. Thanks! Documentation/Configure.help | 28 ++ arch/m68k/config.in | 5 arch/m68k/kernel/m68k_ksyms.c | 5 arch/m68k/kernel/setup.c | 3 arch/m68k/q40/config.c | 41 +++ drivers/char/Makefile | 1 drivers/char/genrtc.c | 533 ++++++++++++++++++++++++++++++++++++++++++ include/asm-m68k/machdep.h | 4 include/asm-m68k/rtc.h | 44 +++ include/linux/rtc.h | 28 ++ 10 files changed, 687 insertions(+), 5 deletions(-) --- linux-2.4.20/Documentation/Configure.help Tue Oct 29 18:40:45 2002 +++ linux-genrtc-2.4.20/Documentation/Configure.help Fri Jan 10 20:54:52 2003 @@ -18959,6 +18959,34 @@ The module is called rtc.o. If you want to compile it as a module, say M here and read <file:Documentation/modules.txt>. +Generic Real Time Clock Support +CONFIG_GEN_RTC + If you say Y here and create a character special file /dev/rtc with + major number 10 and minor number 135 using mknod ("man mknod"), you + will get access to the real time clock (or hardware clock) built + into your computer. + + In 2.4 and later kernels this is the only way to set and get rtc + time on m68k systems so it is highly recommended. + + It reports status information via the file /proc/driver/rtc and its + behaviour is set by various ioctls on /dev/rtc. If you enable the + "extended RTC operation" below it will also provide an emulation + for RTC_UIE which is required by some programs and may improve + precision in some cases. + + This driver is also available as a module ( = code which can be + inserted in and removed from the running kernel whenever you want). + The module is called genrtc.o. If you want to compile it as a module, + say M here and read <file:Documentation/modules.txt>. To load the + module automatically add 'alias char-major-10-135 genrtc' to your + /etc/modules.conf + +Extended RTC operation +CONFIG_GEN_RTC_X + Provides an emulation for RTC_UIE which is required by some programs + and may improve precision of the generic RTC support in some cases. + Tadpole ANA H8 Support CONFIG_H8 The Hitachi H8/337 is a microcontroller used to deal with the power --- linux-2.4.20/arch/m68k/config.in Fri Sep 13 10:14:59 2002 +++ linux-genrtc-2.4.20/arch/m68k/config.in Fri Jan 10 20:54:25 2003 @@ -517,8 +517,11 @@ if [ "$CONFIG_SUN3" = "y" ]; then define_bool CONFIG_GEN_RTC y else - bool 'Generic /dev/rtc emulation' CONFIG_GEN_RTC + tristate 'Generic /dev/rtc emulation' CONFIG_GEN_RTC fi +fi +if [ "$CONFIG_GEN_RTC" != "n" ]; then + bool ' Extended RTC operation' CONFIG_GEN_RTC_X fi bool 'Unix98 PTY support' CONFIG_UNIX98_PTYS if [ "$CONFIG_UNIX98_PTYS" = "y" ]; then --- linux-2.4.20/arch/m68k/kernel/m68k_ksyms.c Thu Jan 4 22:00:55 2001 +++ linux-genrtc-2.4.20/arch/m68k/kernel/m68k_ksyms.c Fri Jan 10 20:54:25 2003 @@ -18,6 +18,7 @@ #include <asm/checksum.h> #include <asm/hardirq.h> #include <asm/softirq.h> +#include <asm/rtc.h> asmlinkage long long __ashldi3 (long long, int); asmlinkage long long __ashrdi3 (long long, int); @@ -49,6 +50,10 @@ EXPORT_SYMBOL(kernel_set_cachemode); #endif /* !CONFIG_SUN3 */ EXPORT_SYMBOL(m68k_debug_device); +EXPORT_SYMBOL(mach_hwclk); +EXPORT_SYMBOL(mach_get_ss); +EXPORT_SYMBOL(mach_get_rtc_pll); +EXPORT_SYMBOL(mach_set_rtc_pll); EXPORT_SYMBOL(dump_fpu); EXPORT_SYMBOL(dump_thread); EXPORT_SYMBOL(strnlen); --- linux-2.4.20/arch/m68k/kernel/setup.c Fri Sep 13 10:15:01 2002 +++ linux-genrtc-2.4.20/arch/m68k/kernel/setup.c Fri Jan 10 20:54:25 2003 @@ -90,6 +90,9 @@ void (*mach_gettod) (int*, int*, int*, int*, int*, int*); int (*mach_hwclk) (int, struct rtc_time*) = NULL; int (*mach_set_clock_mmss) (unsigned long) = NULL; +unsigned int (*mach_get_ss)(void) = NULL; +int (*mach_get_rtc_pll)(struct rtc_pll_info *) = NULL; +int (*mach_set_rtc_pll)(struct rtc_pll_info *) = NULL; void (*mach_reset)( void ); void (*mach_halt)( void ) = NULL; void (*mach_power_off)( void ) = NULL; --- linux-2.4.20/arch/m68k/q40/config.c Fri Sep 13 10:15:02 2002 +++ linux-genrtc-2.4.20/arch/m68k/q40/config.c Fri Jan 10 20:54:25 2003 @@ -58,7 +58,10 @@ extern void q40_gettod (int *year, int *mon, int *day, int *hour, int *min, int *sec); extern int q40_hwclk (int, struct rtc_time *); +extern unsigned int q40_get_ss (void); extern 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); extern void q40_reset (void); void q40_halt(void); extern void q40_waitbut(void); @@ -196,6 +199,9 @@ mach_gettimeoffset = q40_gettimeoffset; mach_gettod = q40_gettod; mach_hwclk = q40_hwclk; + 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; @@ -331,6 +337,11 @@ return 0; } +unsigned int q40_get_ss() +{ + 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. @@ -362,3 +373,33 @@ 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) + +static int q40_get_rtc_pll(struct rtc_pll_info *pll) +{ + int tmp=Q40_RTC_CTRL; + pll->pll_value = tmp & Q40_RTC_PLL_MASK; + if (tmp & Q40_RTC_PLL_SIGN) + pll->pll_value = -pll->pll_value; + pll->pll_max=31; + pll->pll_min=-31; + pll->pll_posmult=512; + pll->pll_negmult=256; + pll->pll_clock=125829120; + return 0; + } + +static int q40_set_rtc_pll(struct rtc_pll_info *pll) +{ + if (!pll->pll_ctrl){ + /* the docs are a bit unclear so I am doublesetting RTC_WRITE here ... */ + int tmp=(pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) | Q40_RTC_WRITE; + Q40_RTC_CTRL |= Q40_RTC_WRITE; + Q40_RTC_CTRL = tmp; + Q40_RTC_CTRL &= ~(Q40_RTC_WRITE); + return 0; + } else return -EINVAL; +} --- linux-2.4.20/drivers/char/Makefile Wed Nov 27 11:02:06 2002 +++ linux-genrtc-2.4.20/drivers/char/Makefile Fri Jan 10 20:54:25 2003 @@ -222,6 +222,7 @@ obj-$(CONFIG_PC110_PAD) += pc110pad.o obj-$(CONFIG_MK712_MOUSE) += mk712.o obj-$(CONFIG_RTC) += rtc.o +obj-$(CONFIG_GEN_RTC) += genrtc.o obj-$(CONFIG_EFI_RTC) += efirtc.o ifeq ($(CONFIG_PPC),) obj-$(CONFIG_NVRAM) += nvram.o --- linux-2.4.20/drivers/char/genrtc.c Thu Jan 1 01:00:00 1970 +++ linux-genrtc-2.4.20/drivers/char/genrtc.c Fri Jan 10 20:54:52 2003 @@ -0,0 +1,533 @@ +/* + * Real Time Clock interface for q40 and other m68k machines + * emulate some RTC irq capabilities in software + * + * Copyright (C) 1999 Richard Zidlicky + * + * based on Paul Gortmaker's rtc.c device and + * Sam Creasey Generic rtc driver + * + * This driver allows use of the real time clock (built into + * nearly all computers) from user space. It exports the /dev/rtc + * interface supporting various ioctl() and also the /proc/dev/rtc + * pseudo-file for status information. + * + * The ioctls can be used to set the interrupt behaviour where + * supported. + * + * The /dev/rtc interface will block on reads until an interrupt + * has been received. If a RTC interrupt has already happened, + * it will output an unsigned long and then block. The output value + * contains the interrupt status in the low byte and the number of + * interrupts since the last read in the remaining high bytes. The + * /dev/rtc interface can also be used with the select(2) call. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + + * 1.01 fix for 2.3.X rz@linux-m68k.org + * 1.02 merged with code from genrtc.c rz@linux-m68k.org + * 1.03 make it more portable zippel@linux-m68k.org + * 1.04 removed useless timer code rz@linux-m68k.org + * 1.05 portable RTC_UIE emulation rz@linux-m68k.org + * 1.06 set_rtc_time can return an error trini@kernel.crashing.org + */ + +#define RTC_VERSION "1.06" + +#include <linux/module.h> +#include <linux/config.h> +#include <linux/errno.h> +#include <linux/miscdevice.h> +#include <linux/fcntl.h> + +#include <linux/rtc.h> +#include <linux/init.h> +#include <linux/poll.h> +#include <linux/proc_fs.h> + +#include <asm/uaccess.h> +#include <asm/system.h> +#include <asm/rtc.h> + +/* + * We sponge a minor off of the misc major. No need slurping + * up another valuable major dev number for this. If you add + * an ioctl, make sure you don't conflict with SPARC's RTC + * ioctls. + */ + +static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); + +static int gen_rtc_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg); + +/* + * Bits in gen_rtc_status. + */ + +#define RTC_IS_OPEN 0x01 /* means /dev/rtc is in use */ + +unsigned char gen_rtc_status; /* bitmapped status byte. */ +unsigned long gen_rtc_irq_data; /* our output to the world */ + +/* months start at 0 now */ +unsigned char days_in_mo[] = +{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +static int irq_active; + +#ifdef CONFIG_GEN_RTC_X +struct tq_struct genrtc_task; +static struct timer_list timer_task; + +static unsigned int oldsecs; +static int lostint; +static int tt_exp; + +void gen_rtc_timer(unsigned long data); + +static volatile int stask_active; /* schedule_task */ +static volatile int ttask_active; /* timer_task */ +static int stop_rtc_timers; /* don't requeue tasks */ +static spinlock_t gen_rtc_lock = SPIN_LOCK_UNLOCKED; + +/* + * Routine to poll RTC seconds field for change as often as posible, + * after first RTC_UIE use timer to reduce polling + */ +void genrtc_troutine(void *data) +{ + unsigned int tmp = get_rtc_ss(); + + if (stop_rtc_timers) { + stask_active = 0; + return; + } + + if (oldsecs != tmp){ + oldsecs = tmp; + + timer_task.function = gen_rtc_timer; + timer_task.expires = jiffies + HZ - (HZ/10); + tt_exp=timer_task.expires; + ttask_active=1; + stask_active=0; + add_timer(&timer_task); + + gen_rtc_interrupt(0); + } else if (schedule_task(&genrtc_task) == 0) + stask_active = 0; +} + +void gen_rtc_timer(unsigned long data) +{ + lostint = get_rtc_ss() - oldsecs ; + if (lostint<0) + lostint = 60 - lostint; + if (time_after(jiffies, tt_exp)) + printk(KERN_INFO "genrtc: timer task delayed by %ld jiffies\n", + jiffies-tt_exp); + ttask_active=0; + stask_active=1; + if ((schedule_task(&genrtc_task) == 0)) + stask_active = 0; +} + +/* + * call gen_rtc_interrupt function to signal an RTC_UIE, + * arg is unused. + * Could be invoked either from a real interrupt handler or + * from some routine that periodically (eg 100HZ) monitors + * whether RTC_SECS changed + */ +void gen_rtc_interrupt(unsigned long arg) +{ + /* We store the status in the low byte and the number of + * interrupts received since the last read in the remainder + * of rtc_irq_data. */ + + gen_rtc_irq_data += 0x100; + gen_rtc_irq_data &= ~0xff; + gen_rtc_irq_data |= RTC_UIE; + + if (lostint){ + printk("genrtc: system delaying clock ticks?\n"); + /* increment count so that userspace knows something is wrong */ + gen_rtc_irq_data += ((lostint-1)<<8); + lostint = 0; + } + + wake_up_interruptible(&gen_rtc_wait); +} + +/* + * Now all the various file operations that we export. + */ +static ssize_t gen_rtc_read(struct file *file, char *buf, + size_t count, loff_t *ppos) +{ + DECLARE_WAITQUEUE(wait, current); + unsigned long data; + ssize_t retval; + + if (count != sizeof (unsigned int) && count != sizeof (unsigned long)) + return -EINVAL; + + if (file->f_flags & O_NONBLOCK && !gen_rtc_irq_data) + return -EAGAIN; + + add_wait_queue(&gen_rtc_wait, &wait); + retval = -ERESTARTSYS; + + while (1) { + set_current_state(TASK_INTERRUPTIBLE); + data = xchg(&gen_rtc_irq_data, 0); + if (data) + break; + if (signal_pending(current)) + goto out; + schedule(); + } + + /* first test allows optimizer to nuke this case for 32-bit machines */ + if (sizeof (int) != sizeof (long) && count == sizeof (unsigned int)) { + unsigned int uidata = data; + retval = put_user(uidata, (unsigned long *)buf); + } + else { + retval = put_user(data, (unsigned long *)buf); + } + if (!retval) + retval = sizeof(unsigned long); + out: + current->state = TASK_RUNNING; + remove_wait_queue(&gen_rtc_wait, &wait); + + return retval; +} + +static unsigned int gen_rtc_poll(struct file *file, + struct poll_table_struct *wait) +{ + poll_wait(file, &gen_rtc_wait, wait); + if (gen_rtc_irq_data != 0) + return POLLIN | POLLRDNORM; + return 0; +} + +#endif + +/* + * Used to disable/enable interrupts, only RTC_UIE supported + * We also clear out any old irq data after an ioctl() that + * meddles with the interrupt enable/disable bits. + */ + +static inline void gen_clear_rtc_irq_bit(unsigned char bit) +{ +#ifdef CONFIG_GEN_RTC_X + stop_rtc_timers = 1; + if (ttask_active){ + del_timer_sync(&timer_task); + ttask_active = 0; + } + while (stask_active) + schedule(); + + spin_lock(&gen_rtc_lock); + irq_active = 0; + spin_unlock(&gen_rtc_lock); +#endif +} + +static inline int gen_set_rtc_irq_bit(unsigned char bit) +{ +#ifdef CONFIG_GEN_RTC_X + spin_lock(&gen_rtc_lock); + if ( !irq_active ) { + irq_active = 1; + stop_rtc_timers = 0; + lostint = 0; + genrtc_task.routine = genrtc_troutine; + oldsecs = get_rtc_ss(); + init_timer(&timer_task); + + stask_active = 1; + if (schedule_task(&genrtc_task) == 0){ + stask_active = 0; + } + } + spin_unlock(&gen_rtc_lock); + gen_rtc_irq_data = 0; + return 0; +#else + return -EINVAL; +#endif +} + +static int gen_rtc_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) +{ + struct rtc_time wtime; + struct rtc_pll_info pll; + + switch (cmd) { + + case RTC_PLL_GET: + if (get_rtc_pll(&pll)) + return -EINVAL; + else + return copy_to_user((void *)arg, &pll, sizeof pll) ? -EFAULT : 0; + + case RTC_PLL_SET: + if (!capable(CAP_SYS_TIME)) + return -EACCES; + if (copy_from_user(&pll, (struct rtc_pll_info*)arg, + sizeof(pll))) + return -EFAULT; + return set_rtc_pll(&pll); + + case RTC_UIE_OFF: /* disable ints from RTC updates. */ + gen_clear_rtc_irq_bit(RTC_UIE); + return 0; + + case RTC_UIE_ON: /* enable ints for RTC updates. */ + return gen_set_rtc_irq_bit(RTC_UIE); + + case RTC_RD_TIME: /* Read the time/date from RTC */ + /* this doesn't get week-day, who cares */ + memset(&wtime, 0, sizeof(wtime)); + get_rtc_time(&wtime); + + return copy_to_user((void *)arg, &wtime, sizeof(wtime)) ? -EFAULT : 0; + + case RTC_SET_TIME: /* Set the RTC */ + { + int year; + unsigned char leap_yr; + + if (!capable(CAP_SYS_TIME)) + return -EACCES; + + if (copy_from_user(&wtime, (struct rtc_time *)arg, + sizeof(wtime))) + return -EFAULT; + + year = wtime.tm_year + 1900; + leap_yr = ((!(year % 4) && (year % 100)) || + !(year % 400)); + + if ((wtime.tm_mon < 0 || wtime.tm_mon > 11) || (wtime.tm_mday < 1)) + return -EINVAL; + + if (wtime.tm_mday < 0 || wtime.tm_mday > + (days_in_mo[wtime.tm_mon] + ((wtime.tm_mon == 1) && leap_yr))) + return -EINVAL; + + if (wtime.tm_hour < 0 || wtime.tm_hour >= 24 || + wtime.tm_min < 0 || wtime.tm_min >= 60 || + wtime.tm_sec < 0 || wtime.tm_sec >= 60) + return -EINVAL; + + return set_rtc_time(&wtime); + } + } + + return -EINVAL; +} + +/* + * We enforce only one user at a time here with the open/close. + * Also clear the previous interrupt data on an open, and clean + * up things on a close. + */ + +static int gen_rtc_open(struct inode *inode, struct file *file) +{ + if (gen_rtc_status & RTC_IS_OPEN) + return -EBUSY; + + MOD_INC_USE_COUNT; + + gen_rtc_status |= RTC_IS_OPEN; + gen_rtc_irq_data = 0; + irq_active = 0; + + return 0; +} + +static int gen_rtc_release(struct inode *inode, struct file *file) +{ + /* + * Turn off all interrupts once the device is no longer + * in use and clear the data. + */ + + gen_clear_rtc_irq_bit(RTC_PIE|RTC_AIE|RTC_UIE); + + gen_rtc_status &= ~RTC_IS_OPEN; + MOD_DEC_USE_COUNT; + + return 0; +} + +static int gen_rtc_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data); + + +/* + * The various file operations we support. + */ + +static struct file_operations gen_rtc_fops = { + owner: THIS_MODULE, +#ifdef CONFIG_GEN_RTC_X + read: gen_rtc_read, + poll: gen_rtc_poll, +#endif + ioctl: gen_rtc_ioctl, + open: gen_rtc_open, + release: gen_rtc_release +}; + +static struct miscdevice rtc_gen_dev = +{ + RTC_MINOR, + "rtc", + &gen_rtc_fops +}; + +int __init rtc_generic_init(void) +{ + int retval; + + printk(KERN_INFO "Generic RTC Driver v%s\n", RTC_VERSION); + + retval = misc_register(&rtc_gen_dev); + if(retval < 0) + return retval; + +#ifdef CONFIG_PROC_FS + if((create_proc_read_entry ("driver/rtc", 0, 0, gen_rtc_read_proc, NULL)) == NULL){ + misc_deregister(&rtc_gen_dev); + return -ENOMEM; + } +#endif + + return 0; +} + +static void __exit rtc_generic_exit(void) +{ + remove_proc_entry ("driver/rtc", NULL); + misc_deregister(&rtc_gen_dev); +} + +module_init(rtc_generic_init); +module_exit(rtc_generic_exit); +EXPORT_NO_SYMBOLS; + + +/* + * Info exported via "/proc/rtc". + */ + +int gen_rtc_proc_output(char *buf) +{ + char *p; + struct rtc_time tm; + unsigned tmp; + struct rtc_pll_info pll; + + p = buf; + + get_rtc_time(&tm); + + p += sprintf(p, + "rtc_time\t: %02d:%02d:%02d\n" + "rtc_date\t: %04d-%02d-%02d\n" + "rtc_epoch\t: %04u\n", + tm.tm_hour, tm.tm_min, tm.tm_sec, + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, 1900); + + tm.tm_hour=0;tm.tm_min=0;tm.tm_sec=0; + + p += sprintf(p, "alarm\t\t: "); + if (tm.tm_hour <= 24) + p += sprintf(p, "%02d:", tm.tm_hour); + else + p += sprintf(p, "**:"); + + if (tm.tm_min <= 59) + p += sprintf(p, "%02d:", tm.tm_min); + else + p += sprintf(p, "**:"); + + if (tm.tm_sec <= 59) + p += sprintf(p, "%02d\n", tm.tm_sec); + else + p += sprintf(p, "**\n"); + + tmp= RTC_24H ; + p += sprintf(p, + "DST_enable\t: %s\n" + "BCD\t\t: %s\n" + "24hr\t\t: %s\n" + "square_wave\t: %s\n" + "alarm_IRQ\t: %s\n" + "update_IRQ\t: %s\n" + "periodic_IRQ\t: %s\n" + "periodic_freq\t: %ld\n" + "batt_status\t: %s\n", + (tmp & RTC_DST_EN) ? "yes" : "no", + (tmp & RTC_DM_BINARY) ? "no" : "yes", + (tmp & RTC_24H) ? "yes" : "no", + (tmp & RTC_SQWE) ? "yes" : "no", + (tmp & RTC_AIE) ? "yes" : "no", + irq_active ? "yes" : "no", + (tmp & RTC_PIE) ? "yes" : "no", + 0L /* freq */, + "okay" ); + if (!get_rtc_pll(&pll)) + p += sprintf(p, + "PLL adjustment\t: %d\n" + "PLL max +ve adjustment\t: %d\n" + "PLL max -ve adjustment\t: %d\n" + "PLL +ve adjustment factor\t: %d\n" + "PLL -ve adjustment factor\t: %d\n" + "PLL frequency\t: %ld\n", + pll.pll_value, + pll.pll_max, + pll.pll_min, + pll.pll_posmult, + pll.pll_negmult, + pll.pll_clock); + return p - buf; +} + +static int gen_rtc_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + int len = gen_rtc_proc_output (page); + if (len <= off+count) *eof = 1; + *start = page + off; + len -= off; + if (len>count) len = count; + if (len<0) len = 0; + return len; +} + + +MODULE_AUTHOR("Richard Zidlicky"); +MODULE_LICENSE("GPL"); + +/* + * Local variables: + * compile-command: "m68k-linux-gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -ffixed-a2 -c -o genrtc.o genrtc.c" + * End: + */ + --- linux-2.4.20/include/asm-m68k/machdep.h Wed May 29 10:14:12 2002 +++ linux-genrtc-2.4.20/include/asm-m68k/machdep.h Fri Jan 10 20:54:25 2003 @@ -5,6 +5,7 @@ struct kbd_repeat; struct mktime; struct rtc_time; +struct rtc_pll_info; struct gendisk; struct buffer_head; @@ -29,6 +30,9 @@ extern void (*mach_gettod)(int *year, int *mon, int *day, int *hour, int *min, int *sec); 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 ); --- linux-2.4.20/include/asm-m68k/rtc.h Wed May 29 10:14:13 2002 +++ linux-genrtc-2.4.20/include/asm-m68k/rtc.h Fri Jan 10 20:54:25 2003 @@ -13,9 +13,8 @@ #ifdef __KERNEL__ -#include <linux/config.h> #include <linux/rtc.h> -#include <linux/delay.h> +#include <asm/errno.h> #include <asm/machdep.h> #define RTC_PIE 0x40 /* periodic interrupt enable */ @@ -30,7 +29,48 @@ #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 */ +static inline void get_rtc_time(struct rtc_time *time) +{ + /* + * Only the values that we read from the RTC are set. We leave + * tm_wday, tm_yday and tm_isdst untouched. Even though the + * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated + * by the RTC when initially set to a non-zero value. + */ + mach_hwclk(0, time); +} +static inline int set_rtc_time(struct rtc_time *time) +{ + return mach_hwclk(1, time); +} + +static inline unsigned int get_rtc_ss(void) +{ + if (mach_get_ss) + return mach_get_ss(); + else{ + struct rtc_time h; + + get_rtc_time(&h); + return h.tm_sec; + } +} + +static inline int get_rtc_pll(struct rtc_pll_info *pll) +{ + if (mach_get_rtc_pll) + return mach_get_rtc_pll(pll); + else + return -EINVAL; +} +static inline int set_rtc_pll(struct rtc_pll_info *pll) +{ + if (mach_set_rtc_pll) + return mach_set_rtc_pll(pll); + else + return -EINVAL; +} #endif /* __KERNEL__ */ #endif /* _ASM__RTC_H */ --- linux-2.4.20/include/linux/rtc.h Mon Feb 19 09:47:19 2001 +++ linux-genrtc-2.4.20/include/linux/rtc.h Fri Jan 10 20:54:25 2003 @@ -39,10 +39,32 @@ struct rtc_time time; /* time the alarm is set to */ }; +/* + * Data structure to control PLL correction some better RTC feature + * pll_value is used to get or set current value of correction, + * the rest of the struct is used to query HW capabilities. + * This is modeled after the RTC used in Q40/Q60 computers but + * should be sufficiently flexible for other devices + * + * +ve pll_value means clock will run faster by + * pll_value*pll_posmult/pll_clock + * -ve pll_value means clock will run slower by + * pll_value*pll_negmult/pll_clock + */ + +struct rtc_pll_info { + int pll_ctrl; /* placeholder for fancier control */ + int pll_value; /* get/set correction value */ + int pll_max; /* max +ve (faster) adjustment value */ + int pll_min; /* max -ve (slower) adjustment value */ + int pll_posmult; /* factor for +ve corection */ + int pll_negmult; /* factor for -ve corection */ + long pll_clock; /* base PLL frequency */ +}; /* - * ioctl calls that are permitted to the /dev/rtc interface, if - * CONFIG_RTC/CONFIG_EFI_RTC was enabled. + * ioctl calls that are permitted to the /dev/rtc interface, if + * any of the RTC drivers are enabled. */ #define RTC_AIE_ON _IO('p', 0x01) /* Alarm int. enable on */ @@ -66,4 +88,6 @@ #define RTC_WKALM_SET _IOW('p', 0x0f, struct rtc_wkalrm)/* Set wakeup alarm*/ #define RTC_WKALM_RD _IOR('p', 0x10, struct rtc_wkalrm)/* Get wakeup alarm*/ +#define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info) /* Get PLL correction */ +#define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info) /* Set PLL correction */ #endif /* _LINUX_RTC_H_ */ 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] 30+ messages in thread
* [parisc-linux] Re: Generic RTC driver in 2.4.x 2003-01-10 20:05 ` Geert Uytterhoeven (?) @ 2003-01-11 19:50 ` Helge Deller 2003-01-12 11:33 ` Geert Uytterhoeven 2003-01-12 11:33 ` Geert Uytterhoeven -1 siblings, 2 replies; 30+ messages in thread From: Helge Deller @ 2003-01-11 19:50 UTC (permalink / raw) To: Geert Uytterhoeven, Alan Cox, parisc-linux; +Cc: Linux/m68k [-- Attachment #1: Type: text/plain, Size: 662 bytes --] On Friday 10 January 2003 21:05, Geert Uytterhoeven wrote: > Unfortunately I didn't receive any feedback from the pa-risc and ppc people > after my previous posting last Sunday. Hi Geert, It took me some time, but here are the PA-RISC specific patches vs. your latest genrtc driver. Please consider applying, Helge ChangeLog: - small indenting fixes, - new driver version number - more "static" functions - C99 named initializers - added RTC_BATT_BAD capatibility flag (for the procfs-interface), - get_rtc_time() now returns the "capatibilities" value (e.g. RTC_BATT_BAD | RTC_24H) [this means, the m86k get_rtc_time() function has to return a value too. [-- Attachment #2: genrtc.patch --] [-- Type: text/plain, Size: 8911 bytes --] --- ./drivers/char/genrtc.c.geert Sat Jan 11 18:14:50 2003 +++ ./drivers/char/genrtc.c Sat Jan 11 20:36:28 2003 @@ -1,5 +1,8 @@ /* - * Real Time Clock interface for q40 and other m68k machines + * Real Time Clock interface for + * - q40 and other m68k machines, + * - HP PARISC machines + * - PowerPC machines * emulate some RTC irq capabilities in software * * Copyright (C) 1999 Richard Zidlicky @@ -13,7 +16,7 @@ * pseudo-file for status information. * * The ioctls can be used to set the interrupt behaviour where - * supported. + * supported. * * The /dev/rtc interface will block on reads until an interrupt * has been received. If a RTC interrupt has already happened, @@ -34,9 +37,10 @@ * 1.04 removed useless timer code rz@linux-m68k.org * 1.05 portable RTC_UIE emulation rz@linux-m68k.org * 1.06 set_rtc_time can return an error trini@kernel.crashing.org + * 1.07 ported to HP PARISC (hppa) Helge Deller <deller@gmx.de> */ -#define RTC_VERSION "1.06" +#define RTC_VERSION "1.07" #include <linux/module.h> #include <linux/config.h> @@ -71,11 +75,11 @@ #define RTC_IS_OPEN 0x01 /* means /dev/rtc is in use */ -unsigned char gen_rtc_status; /* bitmapped status byte. */ -unsigned long gen_rtc_irq_data; /* our output to the world */ +static unsigned char gen_rtc_status; /* bitmapped status byte. */ +static unsigned long gen_rtc_irq_data; /* our output to the world */ /* months start at 0 now */ -unsigned char days_in_mo[] = +static unsigned char days_in_mo[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; static int irq_active; @@ -88,7 +92,7 @@ static int lostint; static int tt_exp; -void gen_rtc_timer(unsigned long data); +static void gen_rtc_timer(unsigned long data); static volatile int stask_active; /* schedule_task */ static volatile int ttask_active; /* timer_task */ @@ -99,7 +103,7 @@ * Routine to poll RTC seconds field for change as often as posible, * after first RTC_UIE use timer to reduce polling */ -void genrtc_troutine(void *data) +static void genrtc_troutine(void *data) { unsigned int tmp = get_rtc_ss(); @@ -123,7 +127,7 @@ stask_active = 0; } -void gen_rtc_timer(unsigned long data) +static void gen_rtc_timer(unsigned long data) { lostint = get_rtc_ss() - oldsecs ; if (lostint<0) @@ -144,7 +148,7 @@ * from some routine that periodically (eg 100HZ) monitors * whether RTC_SECS changed */ -void gen_rtc_interrupt(unsigned long arg) +static void gen_rtc_interrupt(unsigned long arg) { /* We store the status in the low byte and the number of * interrupts received since the last read in the remainder @@ -384,24 +388,24 @@ */ static struct file_operations gen_rtc_fops = { - owner: THIS_MODULE, + .owner = THIS_MODULE, #ifdef CONFIG_GEN_RTC_X - read: gen_rtc_read, - poll: gen_rtc_poll, + .read = gen_rtc_read, + .poll = gen_rtc_poll, #endif - ioctl: gen_rtc_ioctl, - open: gen_rtc_open, - release: gen_rtc_release + .ioctl = gen_rtc_ioctl, + .open = gen_rtc_open, + .release = gen_rtc_release, }; static struct miscdevice rtc_gen_dev = { - RTC_MINOR, - "rtc", - &gen_rtc_fops + .minor = RTC_MINOR, + .name = "rtc", + .fops = &gen_rtc_fops, }; -int __init rtc_generic_init(void) +static int __init rtc_generic_init(void) { int retval; @@ -436,16 +440,18 @@ * Info exported via "/proc/rtc". */ -int gen_rtc_proc_output(char *buf) +#ifdef CONFIG_PROC_FS + +static int gen_rtc_proc_output(char *buf) { char *p; struct rtc_time tm; - unsigned tmp; + unsigned flags; struct rtc_pll_info pll; p = buf; - get_rtc_time(&tm); + flags = get_rtc_time(&tm); p += sprintf(p, "rtc_time\t: %02d:%02d:%02d\n" @@ -454,7 +460,7 @@ tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, 1900); - tm.tm_hour=0;tm.tm_min=0;tm.tm_sec=0; + tm.tm_hour = tm.tm_min = tm.tm_sec = 0; p += sprintf(p, "alarm\t\t: "); if (tm.tm_hour <= 24) @@ -472,7 +478,6 @@ else p += sprintf(p, "**\n"); - tmp= RTC_24H ; p += sprintf(p, "DST_enable\t: %s\n" "BCD\t\t: %s\n" @@ -483,15 +488,15 @@ "periodic_IRQ\t: %s\n" "periodic_freq\t: %ld\n" "batt_status\t: %s\n", - (tmp & RTC_DST_EN) ? "yes" : "no", - (tmp & RTC_DM_BINARY) ? "no" : "yes", - (tmp & RTC_24H) ? "yes" : "no", - (tmp & RTC_SQWE) ? "yes" : "no", - (tmp & RTC_AIE) ? "yes" : "no", + (flags & RTC_DST_EN) ? "yes" : "no", + (flags & RTC_DM_BINARY) ? "no" : "yes", + (flags & RTC_24H) ? "yes" : "no", + (flags & RTC_SQWE) ? "yes" : "no", + (flags & RTC_AIE) ? "yes" : "no", irq_active ? "yes" : "no", - (tmp & RTC_PIE) ? "yes" : "no", + (flags & RTC_PIE) ? "yes" : "no", 0L /* freq */, - "okay" ); + (flags & RTC_BATT_BAD) ? "bad" : "okay"); if (!get_rtc_pll(&pll)) p += sprintf(p, "PLL adjustment\t: %d\n" @@ -506,7 +511,7 @@ pll.pll_posmult, pll.pll_negmult, pll.pll_clock); - return p - buf; + return p - buf; } static int gen_rtc_read_proc(char *page, char **start, off_t off, @@ -521,6 +526,8 @@ return len; } +#endif /* CONFIG_PROC_FS */ + MODULE_AUTHOR("Richard Zidlicky"); MODULE_LICENSE("GPL"); --- ./include/asm-parisc/rtc.h.geert Sat Jan 11 18:21:25 2003 +++ ./include/asm-parisc/rtc.h Sat Jan 11 20:40:41 2003 @@ -0,0 +1,131 @@ +/* include/asm-parisc/rtc.h */ + +#ifndef _ASM_RTC_H +#define _ASM_RTC_H + +#ifdef __KERNEL__ + +#include <linux/rtc.h> +#include <asm/errno.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 0x10 /* 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 */ + + +/* constants for calculation */ +#define SECS_PER_HOUR (60 * 60) +#define SECS_PER_DAY (SECS_PER_HOUR * 24) + +#define __isleap(year) \ + ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) + + +/* How many days come before each month (0-12). */ +static const unsigned short int __mon_yday[2][13] = +{ + /* Normal years. */ + { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, + /* Leap years. */ + { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } +}; + +static inline unsigned get_rtc_time(struct rtc_time *wtime) +{ + /* + * Only the values that we read from the RTC are set. We leave + * tm_wday, tm_yday and tm_isdst untouched. Even though the + * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated + * by the RTC when initially set to a non-zero value. + */ + + struct pdc_tod tod_data; + long int days, rem, y; + const unsigned short int *ip; + + if (pdc_tod_read(&tod_data) < 0) + return (RTC_24H | RTC_BATT_BAD); + + + // most of the remainder of this function is: + // Copyright (C) 1991, 1993, 1997, 1998 Free Software Foundation, Inc. + // This was originally a part of the GNU C Library. + // It is distributed under the GPL, and was swiped from offtime.c + + + days = tod_data.tod_sec / SECS_PER_DAY; + rem = tod_data.tod_sec % SECS_PER_DAY; + + wtime->tm_hour = rem / SECS_PER_HOUR; + rem %= SECS_PER_HOUR; + wtime->tm_min = rem / 60; + wtime->tm_sec = rem % 60; + + y = 1970; + +#define DIV(a, b) ((a) / (b) - ((a) % (b) < 0)) +#define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) + + while (days < 0 || days >= (__isleap (y) ? 366 : 365)) + { + /* Guess a corrected year, assuming 365 days per year. */ + long int yg = y + days / 365 - (days % 365 < 0); + + /* Adjust DAYS and Y to match the guessed year. */ + days -= ((yg - y) * 365 + + LEAPS_THRU_END_OF (yg - 1) + - LEAPS_THRU_END_OF (y - 1)); + y = yg; + } + wtime->tm_year = y - 1900; +#undef DIV +#undef LEAPS_THRU_END_OF + + ip = __mon_yday[__isleap(y)]; + for (y = 11; days < (long int) ip[y]; --y) + continue; + days -= ip[y]; + wtime->tm_mon = y; + wtime->tm_mday = days + 1; + + return (RTC_24H); +} + +static inline int set_rtc_time(struct rtc_time *wtime) +{ + u_int32_t secs; + + secs = mktime(wtime->tm_year + 1900, wtime->tm_mon + 1, wtime->tm_mday, + wtime->tm_hour, wtime->tm_min, wtime->tm_sec); + + if (pdc_tod_set(secs, 0) < 0) + return -EINVAL; + else + return 0; +} + +static inline unsigned int get_rtc_ss(void) +{ + return -EINVAL; +} + +static inline int get_rtc_pll(struct rtc_pll_info *pll) +{ + return -EINVAL; +} +static inline int set_rtc_pll(struct rtc_pll_info *pll) +{ + return -EINVAL; +} + +#endif /* __KERNEL__ */ + +#endif /* _ASM__RTC_H */ + ^ permalink raw reply [flat|nested] 30+ messages in thread
* [parisc-linux] Re: Generic RTC driver in 2.4.x 2003-01-11 19:50 ` [parisc-linux] " Helge Deller @ 2003-01-12 11:33 ` Geert Uytterhoeven 2003-01-12 11:33 ` Geert Uytterhoeven 1 sibling, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2003-01-12 11:33 UTC (permalink / raw) To: Helge Deller; +Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux/m68k On Sat, 11 Jan 2003, Helge Deller wrote: > On Friday 10 January 2003 21:05, Geert Uytterhoeven wrote: > > Unfortunately I didn't receive any feedback from the pa-risc and ppc people > > after my previous posting last Sunday. > > It took me some time, but here are the PA-RISC specific patches vs. your > latest genrtc driver. > > Please consider applying, Thanks! Applied. I made some more changes afterwards: - Remove unnecessary forward declaration of gen_rtc_ioctl() - Add forward declaration for gen_rtc_interrupt() - Remove obsolete extern declaration for gen_rtc_interrupt() on m68k - Change `unsigned' to `unsigned int' - Change value of RTC_BATT_BAD to 0x100 (0x10 conflicted with RTC_UIE, and 0x01 is already used in <linux/mc146818rtc.h>) - Update m68k get_rtc_time() to return flags BTW, perhaps we should move the global RTC_* definitions in <asm/rtc.h> to <linux/genrtc.h>, or merge them with the ones in <linux/mc146818rtc.h> and move them to <linux/rtc.h>? --- linux-genrtc-parisc-2.4.20/drivers/char/genrtc.c Sun Jan 12 12:01:23 2003 +++ linux-m68k-2.4.20/drivers/char/genrtc.c Sun Jan 12 12:18:21 2003 @@ -66,8 +66,8 @@ static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); -static int gen_rtc_ioctl(struct inode *inode, struct file *file, - unsigned int cmd, unsigned long arg); +static void gen_rtc_interrupt(unsigned long arg); + /* * Bits in gen_rtc_status. @@ -446,7 +446,7 @@ { char *p; struct rtc_time tm; - unsigned flags; + unsigned int flags; struct rtc_pll_info pll; p = buf; --- linux-genrtc-parisc-2.4.20/include/asm-parisc/rtc.h Sun Jan 12 12:01:23 2003 +++ linux-m68k-2.4.20/include/asm-parisc/rtc.h Sun Jan 12 11:05:53 2003 @@ -12,8 +12,9 @@ #define RTC_AIE 0x20 /* alarm interrupt enable */ #define RTC_UIE 0x10 /* update-finished interrupt enable */ +#define RTC_BATT_BAD 0x100 /* battery bad */ + /* some dummy definitions */ -#define RTC_BATT_BAD 0x10 /* 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 */ @@ -37,7 +38,7 @@ { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } }; -static inline unsigned get_rtc_time(struct rtc_time *wtime) +static inline unsigned int get_rtc_time(struct rtc_time *wtime) { /* * Only the values that we read from the RTC are set. We leave --- linux-genrtc-parisc-2.4.20/include/asm-m68k/rtc.h Fri Jan 10 20:54:25 2003 +++ linux-m68k-2.4.20/include/asm-m68k/rtc.h Sun Jan 12 12:18:29 2003 @@ -21,15 +21,14 @@ #define RTC_AIE 0x20 /* alarm interrupt enable */ #define RTC_UIE 0x10 /* update-finished interrupt enable */ -extern void gen_rtc_interrupt(unsigned long); - /* 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 */ -static inline void get_rtc_time(struct rtc_time *time) +static inline unsigned int get_rtc_time(struct rtc_time *time) { /* * Only the values that we read from the RTC are set. We leave @@ -38,6 +37,7 @@ * by the RTC when initially set to a non-zero value. */ mach_hwclk(0, time); + return RTC_24H; } static inline int set_rtc_time(struct rtc_time *time) 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] 30+ messages in thread
* [parisc-linux] Re: Generic RTC driver in 2.4.x 2003-01-11 19:50 ` [parisc-linux] " Helge Deller @ 2003-01-12 11:33 ` Geert Uytterhoeven 2003-01-12 11:33 ` Geert Uytterhoeven 1 sibling, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2003-01-12 11:33 UTC (permalink / raw) To: Helge Deller; +Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux/m68k On Sat, 11 Jan 2003, Helge Deller wrote: > On Friday 10 January 2003 21:05, Geert Uytterhoeven wrote: > > Unfortunately I didn't receive any feedback from the pa-risc and ppc people > > after my previous posting last Sunday. > > It took me some time, but here are the PA-RISC specific patches vs. your > latest genrtc driver. > > Please consider applying, Thanks! Applied. I made some more changes afterwards: - Remove unnecessary forward declaration of gen_rtc_ioctl() - Add forward declaration for gen_rtc_interrupt() - Remove obsolete extern declaration for gen_rtc_interrupt() on m68k - Change `unsigned' to `unsigned int' - Change value of RTC_BATT_BAD to 0x100 (0x10 conflicted with RTC_UIE, and 0x01 is already used in <linux/mc146818rtc.h>) - Update m68k get_rtc_time() to return flags BTW, perhaps we should move the global RTC_* definitions in <asm/rtc.h> to <linux/genrtc.h>, or merge them with the ones in <linux/mc146818rtc.h> and move them to <linux/rtc.h>? --- linux-genrtc-parisc-2.4.20/drivers/char/genrtc.c Sun Jan 12 12:01:23 2003 +++ linux-m68k-2.4.20/drivers/char/genrtc.c Sun Jan 12 12:18:21 2003 @@ -66,8 +66,8 @@ static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); -static int gen_rtc_ioctl(struct inode *inode, struct file *file, - unsigned int cmd, unsigned long arg); +static void gen_rtc_interrupt(unsigned long arg); + /* * Bits in gen_rtc_status. @@ -446,7 +446,7 @@ { char *p; struct rtc_time tm; - unsigned flags; + unsigned int flags; struct rtc_pll_info pll; p = buf; --- linux-genrtc-parisc-2.4.20/include/asm-parisc/rtc.h Sun Jan 12 12:01:23 2003 +++ linux-m68k-2.4.20/include/asm-parisc/rtc.h Sun Jan 12 11:05:53 2003 @@ -12,8 +12,9 @@ #define RTC_AIE 0x20 /* alarm interrupt enable */ #define RTC_UIE 0x10 /* update-finished interrupt enable */ +#define RTC_BATT_BAD 0x100 /* battery bad */ + /* some dummy definitions */ -#define RTC_BATT_BAD 0x10 /* 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 */ @@ -37,7 +38,7 @@ { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } }; -static inline unsigned get_rtc_time(struct rtc_time *wtime) +static inline unsigned int get_rtc_time(struct rtc_time *wtime) { /* * Only the values that we read from the RTC are set. We leave --- linux-genrtc-parisc-2.4.20/include/asm-m68k/rtc.h Fri Jan 10 20:54:25 2003 +++ linux-m68k-2.4.20/include/asm-m68k/rtc.h Sun Jan 12 12:18:29 2003 @@ -21,15 +21,14 @@ #define RTC_AIE 0x20 /* alarm interrupt enable */ #define RTC_UIE 0x10 /* update-finished interrupt enable */ -extern void gen_rtc_interrupt(unsigned long); - /* 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 */ -static inline void get_rtc_time(struct rtc_time *time) +static inline unsigned int get_rtc_time(struct rtc_time *time) { /* * Only the values that we read from the RTC are set. We leave @@ -38,6 +37,7 @@ * by the RTC when initially set to a non-zero value. */ mach_hwclk(0, time); + return RTC_24H; } static inline int set_rtc_time(struct rtc_time *time) 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] 30+ messages in thread
* Re: Generic RTC driver in 2.4.x @ 2003-01-12 11:33 ` Geert Uytterhoeven 0 siblings, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2003-01-12 11:33 UTC (permalink / raw) To: Helge Deller; +Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux/m68k On Sat, 11 Jan 2003, Helge Deller wrote: > On Friday 10 January 2003 21:05, Geert Uytterhoeven wrote: > > Unfortunately I didn't receive any feedback from the pa-risc and ppc people > > after my previous posting last Sunday. > > It took me some time, but here are the PA-RISC specific patches vs. your > latest genrtc driver. > > Please consider applying, Thanks! Applied. I made some more changes afterwards: - Remove unnecessary forward declaration of gen_rtc_ioctl() - Add forward declaration for gen_rtc_interrupt() - Remove obsolete extern declaration for gen_rtc_interrupt() on m68k - Change `unsigned' to `unsigned int' - Change value of RTC_BATT_BAD to 0x100 (0x10 conflicted with RTC_UIE, and 0x01 is already used in <linux/mc146818rtc.h>) - Update m68k get_rtc_time() to return flags BTW, perhaps we should move the global RTC_* definitions in <asm/rtc.h> to <linux/genrtc.h>, or merge them with the ones in <linux/mc146818rtc.h> and move them to <linux/rtc.h>? --- linux-genrtc-parisc-2.4.20/drivers/char/genrtc.c Sun Jan 12 12:01:23 2003 +++ linux-m68k-2.4.20/drivers/char/genrtc.c Sun Jan 12 12:18:21 2003 @@ -66,8 +66,8 @@ static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); -static int gen_rtc_ioctl(struct inode *inode, struct file *file, - unsigned int cmd, unsigned long arg); +static void gen_rtc_interrupt(unsigned long arg); + /* * Bits in gen_rtc_status. @@ -446,7 +446,7 @@ { char *p; struct rtc_time tm; - unsigned flags; + unsigned int flags; struct rtc_pll_info pll; p = buf; --- linux-genrtc-parisc-2.4.20/include/asm-parisc/rtc.h Sun Jan 12 12:01:23 2003 +++ linux-m68k-2.4.20/include/asm-parisc/rtc.h Sun Jan 12 11:05:53 2003 @@ -12,8 +12,9 @@ #define RTC_AIE 0x20 /* alarm interrupt enable */ #define RTC_UIE 0x10 /* update-finished interrupt enable */ +#define RTC_BATT_BAD 0x100 /* battery bad */ + /* some dummy definitions */ -#define RTC_BATT_BAD 0x10 /* 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 */ @@ -37,7 +38,7 @@ { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } }; -static inline unsigned get_rtc_time(struct rtc_time *wtime) +static inline unsigned int get_rtc_time(struct rtc_time *wtime) { /* * Only the values that we read from the RTC are set. We leave --- linux-genrtc-parisc-2.4.20/include/asm-m68k/rtc.h Fri Jan 10 20:54:25 2003 +++ linux-m68k-2.4.20/include/asm-m68k/rtc.h Sun Jan 12 12:18:29 2003 @@ -21,15 +21,14 @@ #define RTC_AIE 0x20 /* alarm interrupt enable */ #define RTC_UIE 0x10 /* update-finished interrupt enable */ -extern void gen_rtc_interrupt(unsigned long); - /* 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 */ -static inline void get_rtc_time(struct rtc_time *time) +static inline unsigned int get_rtc_time(struct rtc_time *time) { /* * Only the values that we read from the RTC are set. We leave @@ -38,6 +37,7 @@ * by the RTC when initially set to a non-zero value. */ mach_hwclk(0, time); + return RTC_24H; } static inline int set_rtc_time(struct rtc_time *time) 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 ** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/ ^ permalink raw reply [flat|nested] 30+ messages in thread
* [parisc-linux] Re: Generic RTC driver in 2.4.x 2003-01-12 11:33 ` Geert Uytterhoeven @ 2003-01-12 12:35 ` Helge Deller -1 siblings, 0 replies; 30+ messages in thread From: Helge Deller @ 2003-01-12 12:35 UTC (permalink / raw) To: Geert Uytterhoeven Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux/m68k [-- Attachment #1: Type: text/plain, Size: 868 bytes --] On Sunday 12 January 2003 12:33, Geert Uytterhoeven wrote: > I made some more changes afterwards: > - Add forward declaration for gen_rtc_interrupt() This one should be moved inside the #ifdef CONFIG_GEN_RTC_X section to avoid "genrtc.c:69: warning: `gen_rtc_interrupt' declared `static' but never defined" warnings. Please see attached patch. Or, you could just move the declaration of gen_rtc_interrupt() above the one from genrtc_troutine(), in which case we wouldn't need the forward declaration at all. > BTW, perhaps we should move the global RTC_* definitions in <asm/rtc.h> to > <linux/genrtc.h>, or merge them with the ones in <linux/mc146818rtc.h> and > move them to <linux/rtc.h>? IMHO leaving them architecture specific in <asm/rtc.h> seems best to me, and it leaves the most possibilities to make them later more dependend on the hardware. Helge [-- Attachment #2: diff --] [-- Type: text/plain, Size: 574 bytes --] --- ./genrtc.c.geert Sun Jan 12 13:16:40 2003 +++ ./genrtc.c Sun Jan 12 13:15:18 2003 @@ -66,9 +66,6 @@ static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); -static void gen_rtc_interrupt(unsigned long arg); - - /* * Bits in gen_rtc_status. */ @@ -99,6 +96,8 @@ static int stop_rtc_timers; /* don't requeue tasks */ static spinlock_t gen_rtc_lock = SPIN_LOCK_UNLOCKED; +static void gen_rtc_interrupt(unsigned long arg); + /* * Routine to poll RTC seconds field for change as often as posible, * after first RTC_UIE use timer to reduce polling ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Generic RTC driver in 2.4.x @ 2003-01-12 12:35 ` Helge Deller 0 siblings, 0 replies; 30+ messages in thread From: Helge Deller @ 2003-01-12 12:35 UTC (permalink / raw) To: Geert Uytterhoeven Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux/m68k [-- Attachment #1: Type: text/plain, Size: 867 bytes --] On Sunday 12 January 2003 12:33, Geert Uytterhoeven wrote: > I made some more changes afterwards: > - Add forward declaration for gen_rtc_interrupt() This one should be moved inside the #ifdef CONFIG_GEN_RTC_X section to avoid "genrtc.c:69: warning: `gen_rtc_interrupt' declared `static' but never defined" warnings. Please see attached patch. Or, you could just move the declaration of gen_rtc_interrupt() above the one from genrtc_troutine(), in which case we wouldn't need the forward declaration at all. > BTW, perhaps we should move the global RTC_* definitions in <asm/rtc.h> to > <linux/genrtc.h>, or merge them with the ones in <linux/mc146818rtc.h> and > move them to <linux/rtc.h>? IMHO leaving them architecture specific in <asm/rtc.h> seems best to me, and it leaves the most possibilities to make them later more dependend on the hardware. Helge [-- Attachment #2: diff --] [-- Type: text/plain, Size: 571 bytes --] --- ./genrtc.c.geert Sun Jan 12 13:16:40 2003 +++ ./genrtc.c Sun Jan 12 13:15:18 2003 @@ -66,9 +66,6 @@ static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); -static void gen_rtc_interrupt(unsigned long arg); - - /* * Bits in gen_rtc_status. */ @@ -99,6 +96,8 @@ static int stop_rtc_timers; /* don't requeue tasks */ static spinlock_t gen_rtc_lock = SPIN_LOCK_UNLOCKED; +static void gen_rtc_interrupt(unsigned long arg); + /* * Routine to poll RTC seconds field for change as often as posible, * after first RTC_UIE use timer to reduce polling ^ permalink raw reply [flat|nested] 30+ messages in thread
* [parisc-linux] Re: Generic RTC driver in 2.4.x 2003-01-12 12:35 ` Helge Deller @ 2003-01-12 21:49 ` Richard Zidlicky -1 siblings, 0 replies; 30+ messages in thread From: Richard Zidlicky @ 2003-01-12 21:49 UTC (permalink / raw) To: Helge Deller Cc: Geert Uytterhoeven, Alan Cox, parisc-linux, Linux/PPC Development, Linux/m68k On Sun, Jan 12, 2003 at 01:35:33PM +0100, Helge Deller wrote: > > BTW, perhaps we should move the global RTC_* definitions in <asm/rtc.h> to > > <linux/genrtc.h>, or merge them with the ones in <linux/mc146818rtc.h> and > > move them to <linux/rtc.h>? > > IMHO leaving them architecture specific in <asm/rtc.h> seems best to me, and it > leaves the most possibilities to make them later more dependend on the hardware. in genrtc the RTC_* defs should be used only for interface definition, unlike rtc.c where they are 1:1 with some obscure bits in the rtc chip and also happen to be the interface.. It would make sense to merge them into <linux/rtc.h>, whether it is a good idea to do it in 2.4 is another question. Stuff that is really hw dependent should use different naming (and stay in asm/rtc.h of course). Richard ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Generic RTC driver in 2.4.x @ 2003-01-12 21:49 ` Richard Zidlicky 0 siblings, 0 replies; 30+ messages in thread From: Richard Zidlicky @ 2003-01-12 21:49 UTC (permalink / raw) To: Helge Deller Cc: Geert Uytterhoeven, Alan Cox, parisc-linux, Linux/PPC Development, Linux/m68k On Sun, Jan 12, 2003 at 01:35:33PM +0100, Helge Deller wrote: > > BTW, perhaps we should move the global RTC_* definitions in <asm/rtc.h> to > > <linux/genrtc.h>, or merge them with the ones in <linux/mc146818rtc.h> and > > move them to <linux/rtc.h>? > > IMHO leaving them architecture specific in <asm/rtc.h> seems best to me, and it > leaves the most possibilities to make them later more dependend on the hardware. in genrtc the RTC_* defs should be used only for interface definition, unlike rtc.c where they are 1:1 with some obscure bits in the rtc chip and also happen to be the interface.. It would make sense to merge them into <linux/rtc.h>, whether it is a good idea to do it in 2.4 is another question. Stuff that is really hw dependent should use different naming (and stay in asm/rtc.h of course). Richard ** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/ ^ permalink raw reply [flat|nested] 30+ messages in thread
* [parisc-linux] Re: Generic RTC driver in 2.4.x 2003-01-12 12:35 ` Helge Deller (?) (?) @ 2003-01-12 21:49 ` Richard Zidlicky -1 siblings, 0 replies; 30+ messages in thread From: Richard Zidlicky @ 2003-01-12 21:49 UTC (permalink / raw) To: Helge Deller Cc: Geert Uytterhoeven, Alan Cox, parisc-linux, Linux/PPC Development, Linux/m68k On Sun, Jan 12, 2003 at 01:35:33PM +0100, Helge Deller wrote: > > BTW, perhaps we should move the global RTC_* definitions in <asm/rtc.h> to > > <linux/genrtc.h>, or merge them with the ones in <linux/mc146818rtc.h> and > > move them to <linux/rtc.h>? > > IMHO leaving them architecture specific in <asm/rtc.h> seems best to me, and it > leaves the most possibilities to make them later more dependend on the hardware. in genrtc the RTC_* defs should be used only for interface definition, unlike rtc.c where they are 1:1 with some obscure bits in the rtc chip and also happen to be the interface.. It would make sense to merge them into <linux/rtc.h>, whether it is a good idea to do it in 2.4 is another question. Stuff that is really hw dependent should use different naming (and stay in asm/rtc.h of course). Richard ^ permalink raw reply [flat|nested] 30+ messages in thread
* [parisc-linux] Re: Generic RTC driver in 2.4.x 2003-01-12 11:33 ` Geert Uytterhoeven (?) (?) @ 2003-01-12 12:35 ` Helge Deller -1 siblings, 0 replies; 30+ messages in thread From: Helge Deller @ 2003-01-12 12:35 UTC (permalink / raw) To: Geert Uytterhoeven Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux/m68k [-- Attachment #1: Type: text/plain, Size: 868 bytes --] On Sunday 12 January 2003 12:33, Geert Uytterhoeven wrote: > I made some more changes afterwards: > - Add forward declaration for gen_rtc_interrupt() This one should be moved inside the #ifdef CONFIG_GEN_RTC_X section to avoid "genrtc.c:69: warning: `gen_rtc_interrupt' declared `static' but never defined" warnings. Please see attached patch. Or, you could just move the declaration of gen_rtc_interrupt() above the one from genrtc_troutine(), in which case we wouldn't need the forward declaration at all. > BTW, perhaps we should move the global RTC_* definitions in <asm/rtc.h> to > <linux/genrtc.h>, or merge them with the ones in <linux/mc146818rtc.h> and > move them to <linux/rtc.h>? IMHO leaving them architecture specific in <asm/rtc.h> seems best to me, and it leaves the most possibilities to make them later more dependend on the hardware. Helge [-- Attachment #2: diff --] [-- Type: text/plain, Size: 207 bytes --] --- ./genrtc.c.geert Sun Jan 12 13:16:40 2003 +++ ./genrtc.c Sun Jan 12 13:15:18 2003 @@ -66,9 +66,6 @@ static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); -static void gen_rtc_interrupt(unsigned long arg); - ^ permalink raw reply [flat|nested] 30+ messages in thread
* [parisc-linux] Re: Generic RTC driver in 2.4.x 2003-01-10 20:05 ` Geert Uytterhoeven @ 2003-01-30 18:03 ` Tom Rini -1 siblings, 0 replies; 30+ messages in thread From: Tom Rini @ 2003-01-30 18:03 UTC (permalink / raw) To: Geert Uytterhoeven Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux Kernel Development, Linux/m68k On Fri, Jan 10, 2003 at 09:05:55PM +0100, Geert Uytterhoeven wrote: > Unfortunately I didn't receive any feedback from the pa-risc and ppc people > after my previous posting last Sunday. [snip] > Pa-risc and ppc people (any other users?), please send me your enhancements (or > just ack if none are necessary), so I can send genrtc to Marcelo. Sorry I haven't spoken up before this, A simple cp of include/asm-ppc/rtc.h (and then throwing the question someplace) compiles a kernel correctly, and from what I recall of getting it to work in 2.5, at that point it was all good anyhow. So this is fine for PPC32 as is. -- Tom Rini (TR1265) http://gate.crashing.org/~trini/ ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Generic RTC driver in 2.4.x @ 2003-01-30 18:03 ` Tom Rini 0 siblings, 0 replies; 30+ messages in thread From: Tom Rini @ 2003-01-30 18:03 UTC (permalink / raw) To: Geert Uytterhoeven Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux Kernel Development, Linux/m68k On Fri, Jan 10, 2003 at 09:05:55PM +0100, Geert Uytterhoeven wrote: > Unfortunately I didn't receive any feedback from the pa-risc and ppc people > after my previous posting last Sunday. [snip] > Pa-risc and ppc people (any other users?), please send me your enhancements (or > just ack if none are necessary), so I can send genrtc to Marcelo. Sorry I haven't spoken up before this, A simple cp of include/asm-ppc/rtc.h (and then throwing the question someplace) compiles a kernel correctly, and from what I recall of getting it to work in 2.5, at that point it was all good anyhow. So this is fine for PPC32 as is. -- Tom Rini (TR1265) http://gate.crashing.org/~trini/ ^ permalink raw reply [flat|nested] 30+ messages in thread
* [parisc-linux] Re: Generic RTC driver in 2.4.x 2003-01-30 18:03 ` Tom Rini (?) @ 2003-01-31 17:43 ` Geert Uytterhoeven -1 siblings, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2003-01-31 17:43 UTC (permalink / raw) To: Tom Rini Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux Kernel Development, Linux/m68k On Thu, 30 Jan 2003, Tom Rini wrote: > On Fri, Jan 10, 2003 at 09:05:55PM +0100, Geert Uytterhoeven wrote: > > Unfortunately I didn't receive any feedback from the pa-risc and ppc people > > after my previous posting last Sunday. > [snip] > > Pa-risc and ppc people (any other users?), please send me your enhancements (or > > just ack if none are necessary), so I can send genrtc to Marcelo. > > Sorry I haven't spoken up before this, A simple cp of > include/asm-ppc/rtc.h (and then throwing the question > someplace) compiles a kernel correctly, and from what I recall of > getting it to work in 2.5, at that point it was all good anyhow. So > this is fine for PPC32 as is. Note that in the mean time genrtc has changed, so I'd prefer you to at least sent me your include/asm-ppc/rtc.h and a patch to add the question on PPC, _after_ you have test-compiled the latest version. I'll send it to you in a separate mail. 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] 30+ messages in thread
* [parisc-linux] Re: Generic RTC driver in 2.4.x 2003-01-30 18:03 ` Tom Rini @ 2003-01-31 17:43 ` Geert Uytterhoeven -1 siblings, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2003-01-31 17:43 UTC (permalink / raw) To: Tom Rini Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux Kernel Development, Linux/m68k On Thu, 30 Jan 2003, Tom Rini wrote: > On Fri, Jan 10, 2003 at 09:05:55PM +0100, Geert Uytterhoeven wrote: > > Unfortunately I didn't receive any feedback from the pa-risc and ppc people > > after my previous posting last Sunday. > [snip] > > Pa-risc and ppc people (any other users?), please send me your enhancements (or > > just ack if none are necessary), so I can send genrtc to Marcelo. > > Sorry I haven't spoken up before this, A simple cp of > include/asm-ppc/rtc.h (and then throwing the question > someplace) compiles a kernel correctly, and from what I recall of > getting it to work in 2.5, at that point it was all good anyhow. So > this is fine for PPC32 as is. Note that in the mean time genrtc has changed, so I'd prefer you to at least sent me your include/asm-ppc/rtc.h and a patch to add the question on PPC, _after_ you have test-compiled the latest version. I'll send it to you in a separate mail. 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] 30+ messages in thread
* Re: Generic RTC driver in 2.4.x @ 2003-01-31 17:43 ` Geert Uytterhoeven 0 siblings, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2003-01-31 17:43 UTC (permalink / raw) To: Tom Rini Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux Kernel Development, Linux/m68k On Thu, 30 Jan 2003, Tom Rini wrote: > On Fri, Jan 10, 2003 at 09:05:55PM +0100, Geert Uytterhoeven wrote: > > Unfortunately I didn't receive any feedback from the pa-risc and ppc people > > after my previous posting last Sunday. > [snip] > > Pa-risc and ppc people (any other users?), please send me your enhancements (or > > just ack if none are necessary), so I can send genrtc to Marcelo. > > Sorry I haven't spoken up before this, A simple cp of > include/asm-ppc/rtc.h (and then throwing the question > someplace) compiles a kernel correctly, and from what I recall of > getting it to work in 2.5, at that point it was all good anyhow. So > this is fine for PPC32 as is. Note that in the mean time genrtc has changed, so I'd prefer you to at least sent me your include/asm-ppc/rtc.h and a patch to add the question on PPC, _after_ you have test-compiled the latest version. I'll send it to you in a separate mail. 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] 30+ messages in thread
* [parisc-linux] Re: Generic RTC driver in 2.4.x 2003-01-10 20:05 ` Geert Uytterhoeven ` (2 preceding siblings ...) (?) @ 2003-01-30 18:03 ` Tom Rini -1 siblings, 0 replies; 30+ messages in thread From: Tom Rini @ 2003-01-30 18:03 UTC (permalink / raw) To: Geert Uytterhoeven Cc: Alan Cox, parisc-linux, Linux/PPC Development, Linux Kernel Development, Linux/m68k On Fri, Jan 10, 2003 at 09:05:55PM +0100, Geert Uytterhoeven wrote: > Unfortunately I didn't receive any feedback from the pa-risc and ppc people > after my previous posting last Sunday. [snip] > Pa-risc and ppc people (any other users?), please send me your enhancements (or > just ack if none are necessary), so I can send genrtc to Marcelo. Sorry I haven't spoken up before this, A simple cp of include/asm-ppc/rtc.h (and then throwing the question someplace) compiles a kernel correctly, and from what I recall of getting it to work in 2.5, at that point it was all good anyhow. So this is fine for PPC32 as is. -- Tom Rini (TR1265) http://gate.crashing.org/~trini/ ^ permalink raw reply [flat|nested] 30+ messages in thread
* [parisc-linux] Generic RTC driver in 2.4.x 2003-01-05 14:44 ` Geert Uytterhoeven 2003-01-10 20:05 ` Geert Uytterhoeven @ 2003-01-10 20:05 ` Geert Uytterhoeven 1 sibling, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2003-01-10 20:05 UTC (permalink / raw) To: Alan Cox, parisc-linux, Linux/PPC Development Cc: Linux Kernel Development, Linux/m68k Unfortunately I didn't receive any feedback from the pa-risc and ppc people after my previous posting last Sunday. Alan, I'm explicitly sending it to you for inclusion in your ac tree. I intend to send it to Marcelo after the weekend. Changes since last Sunday: - fix spelling of `automatically' (from Geoffrey Lee <glee@gnupilgrims.org>) - misc_register() and create_proc_read_entry() can fail (from mikal@stillhq.com in 2.5.x) - create_proc_read_entry() depends on CONFIG_PROC_FS (from mikal@stillhq.com in 2.5.x) The following patch adds the generic RTC driver to 2.4.20 (applies fine to 2.4.21-pre3). This driver provides a /dev/rtc-compatible interface to the real time clock on machines without a PC-style RTC chip. It is used as the primary RTC driver on m68k, pa-risc, and ppc. This driver is already present in 2.5.x. Pa-risc and ppc people (any other users?), please send me your enhancements (or just ack if none are necessary), so I can send genrtc to Marcelo. Thanks! Documentation/Configure.help | 28 ++ arch/m68k/config.in | 5 arch/m68k/kernel/m68k_ksyms.c | 5 arch/m68k/kernel/setup.c | 3 arch/m68k/q40/config.c | 41 +++ drivers/char/Makefile | 1 drivers/char/genrtc.c | 533 ++++++++++++++++++++++++++++++++++++++++++ include/asm-m68k/machdep.h | 4 include/asm-m68k/rtc.h | 44 +++ include/linux/rtc.h | 28 ++ 10 files changed, 687 insertions(+), 5 deletions(-) --- linux-2.4.20/Documentation/Configure.help Tue Oct 29 18:40:45 2002 +++ linux-genrtc-2.4.20/Documentation/Configure.help Fri Jan 10 20:54:52 2003 @@ -18959,6 +18959,34 @@ The module is called rtc.o. If you want to compile it as a module, say M here and read <file:Documentation/modules.txt>. +Generic Real Time Clock Support +CONFIG_GEN_RTC + If you say Y here and create a character special file /dev/rtc with + major number 10 and minor number 135 using mknod ("man mknod"), you + will get access to the real time clock (or hardware clock) built + into your computer. + + In 2.4 and later kernels this is the only way to set and get rtc + time on m68k systems so it is highly recommended. + + It reports status information via the file /proc/driver/rtc and its + behaviour is set by various ioctls on /dev/rtc. If you enable the + "extended RTC operation" below it will also provide an emulation + for RTC_UIE which is required by some programs and may improve + precision in some cases. + + This driver is also available as a module ( = code which can be + inserted in and removed from the running kernel whenever you want). + The module is called genrtc.o. If you want to compile it as a module, + say M here and read <file:Documentation/modules.txt>. To load the + module automatically add 'alias char-major-10-135 genrtc' to your + /etc/modules.conf + +Extended RTC operation +CONFIG_GEN_RTC_X + Provides an emulation for RTC_UIE which is required by some programs + and may improve precision of the generic RTC support in some cases. + Tadpole ANA H8 Support CONFIG_H8 The Hitachi H8/337 is a microcontroller used to deal with the power --- linux-2.4.20/arch/m68k/config.in Fri Sep 13 10:14:59 2002 +++ linux-genrtc-2.4.20/arch/m68k/config.in Fri Jan 10 20:54:25 2003 @@ -517,8 +517,11 @@ if [ "$CONFIG_SUN3" = "y" ]; then define_bool CONFIG_GEN_RTC y else - bool 'Generic /dev/rtc emulation' CONFIG_GEN_RTC + tristate 'Generic /dev/rtc emulation' CONFIG_GEN_RTC fi +fi +if [ "$CONFIG_GEN_RTC" != "n" ]; then + bool ' Extended RTC operation' CONFIG_GEN_RTC_X fi bool 'Unix98 PTY support' CONFIG_UNIX98_PTYS if [ "$CONFIG_UNIX98_PTYS" = "y" ]; then --- linux-2.4.20/arch/m68k/kernel/m68k_ksyms.c Thu Jan 4 22:00:55 2001 +++ linux-genrtc-2.4.20/arch/m68k/kernel/m68k_ksyms.c Fri Jan 10 20:54:25 2003 @@ -18,6 +18,7 @@ #include <asm/checksum.h> #include <asm/hardirq.h> #include <asm/softirq.h> +#include <asm/rtc.h> asmlinkage long long __ashldi3 (long long, int); asmlinkage long long __ashrdi3 (long long, int); @@ -49,6 +50,10 @@ EXPORT_SYMBOL(kernel_set_cachemode); #endif /* !CONFIG_SUN3 */ EXPORT_SYMBOL(m68k_debug_device); +EXPORT_SYMBOL(mach_hwclk); +EXPORT_SYMBOL(mach_get_ss); +EXPORT_SYMBOL(mach_get_rtc_pll); +EXPORT_SYMBOL(mach_set_rtc_pll); EXPORT_SYMBOL(dump_fpu); EXPORT_SYMBOL(dump_thread); EXPORT_SYMBOL(strnlen); --- linux-2.4.20/arch/m68k/kernel/setup.c Fri Sep 13 10:15:01 2002 +++ linux-genrtc-2.4.20/arch/m68k/kernel/setup.c Fri Jan 10 20:54:25 2003 @@ -90,6 +90,9 @@ void (*mach_gettod) (int*, int*, int*, int*, int*, int*); int (*mach_hwclk) (int, struct rtc_time*) = NULL; int (*mach_set_clock_mmss) (unsigned long) = NULL; +unsigned int (*mach_get_ss)(void) = NULL; +int (*mach_get_rtc_pll)(struct rtc_pll_info *) = NULL; +int (*mach_set_rtc_pll)(struct rtc_pll_info *) = NULL; void (*mach_reset)( void ); void (*mach_halt)( void ) = NULL; void (*mach_power_off)( void ) = NULL; --- linux-2.4.20/arch/m68k/q40/config.c Fri Sep 13 10:15:02 2002 +++ linux-genrtc-2.4.20/arch/m68k/q40/config.c Fri Jan 10 20:54:25 2003 @@ -58,7 +58,10 @@ extern void q40_gettod (int *year, int *mon, int *day, int *hour, int *min, int *sec); extern int q40_hwclk (int, struct rtc_time *); +extern unsigned int q40_get_ss (void); extern 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); extern void q40_reset (void); void q40_halt(void); extern void q40_waitbut(void); @@ -196,6 +199,9 @@ mach_gettimeoffset = q40_gettimeoffset; mach_gettod = q40_gettod; mach_hwclk = q40_hwclk; + 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; @@ -331,6 +337,11 @@ return 0; } +unsigned int q40_get_ss() +{ + 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. @@ -362,3 +373,33 @@ 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) + +static int q40_get_rtc_pll(struct rtc_pll_info *pll) +{ + int tmp=Q40_RTC_CTRL; + pll->pll_value = tmp & Q40_RTC_PLL_MASK; + if (tmp & Q40_RTC_PLL_SIGN) + pll->pll_value = -pll->pll_value; + pll->pll_max=31; + pll->pll_min=-31; + pll->pll_posmult=512; + pll->pll_negmult=256; + pll->pll_clock=125829120; + return 0; + } + +static int q40_set_rtc_pll(struct rtc_pll_info *pll) +{ + if (!pll->pll_ctrl){ + /* the docs are a bit unclear so I am doublesetting RTC_WRITE here ... */ + int tmp=(pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) | Q40_RTC_WRITE; + Q40_RTC_CTRL |= Q40_RTC_WRITE; + Q40_RTC_CTRL = tmp; + Q40_RTC_CTRL &= ~(Q40_RTC_WRITE); + return 0; + } else return -EINVAL; +} --- linux-2.4.20/drivers/char/Makefile Wed Nov 27 11:02:06 2002 +++ linux-genrtc-2.4.20/drivers/char/Makefile Fri Jan 10 20:54:25 2003 @@ -222,6 +222,7 @@ obj-$(CONFIG_PC110_PAD) += pc110pad.o obj-$(CONFIG_MK712_MOUSE) += mk712.o obj-$(CONFIG_RTC) += rtc.o +obj-$(CONFIG_GEN_RTC) += genrtc.o obj-$(CONFIG_EFI_RTC) += efirtc.o ifeq ($(CONFIG_PPC),) obj-$(CONFIG_NVRAM) += nvram.o --- linux-2.4.20/drivers/char/genrtc.c Thu Jan 1 01:00:00 1970 +++ linux-genrtc-2.4.20/drivers/char/genrtc.c Fri Jan 10 20:54:52 2003 @@ -0,0 +1,533 @@ +/* + * Real Time Clock interface for q40 and other m68k machines + * emulate some RTC irq capabilities in software + * + * Copyright (C) 1999 Richard Zidlicky + * + * based on Paul Gortmaker's rtc.c device and + * Sam Creasey Generic rtc driver + * + * This driver allows use of the real time clock (built into + * nearly all computers) from user space. It exports the /dev/rtc + * interface supporting various ioctl() and also the /proc/dev/rtc + * pseudo-file for status information. + * + * The ioctls can be used to set the interrupt behaviour where + * supported. + * + * The /dev/rtc interface will block on reads until an interrupt + * has been received. If a RTC interrupt has already happened, + * it will output an unsigned long and then block. The output value + * contains the interrupt status in the low byte and the number of + * interrupts since the last read in the remaining high bytes. The + * /dev/rtc interface can also be used with the select(2) call. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + + * 1.01 fix for 2.3.X rz@linux-m68k.org + * 1.02 merged with code from genrtc.c rz@linux-m68k.org + * 1.03 make it more portable zippel@linux-m68k.org + * 1.04 removed useless timer code rz@linux-m68k.org + * 1.05 portable RTC_UIE emulation rz@linux-m68k.org + * 1.06 set_rtc_time can return an error trini@kernel.crashing.org + */ + +#define RTC_VERSION "1.06" + +#include <linux/module.h> +#include <linux/config.h> +#include <linux/errno.h> +#include <linux/miscdevice.h> +#include <linux/fcntl.h> + +#include <linux/rtc.h> +#include <linux/init.h> +#include <linux/poll.h> +#include <linux/proc_fs.h> + +#include <asm/uaccess.h> +#include <asm/system.h> +#include <asm/rtc.h> + +/* + * We sponge a minor off of the misc major. No need slurping + * up another valuable major dev number for this. If you add + * an ioctl, make sure you don't conflict with SPARC's RTC + * ioctls. + */ + +static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); + +static int gen_rtc_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg); + +/* + * Bits in gen_rtc_status. + */ + +#define RTC_IS_OPEN 0x01 /* means /dev/rtc is in use */ + +unsigned char gen_rtc_status; /* bitmapped status byte. */ +unsigned long gen_rtc_irq_data; /* our output to the world */ + +/* months start at 0 now */ +unsigned char days_in_mo[] = +{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +static int irq_active; + +#ifdef CONFIG_GEN_RTC_X +struct tq_struct genrtc_task; +static struct timer_list timer_task; + +static unsigned int oldsecs; +static int lostint; +static int tt_exp; + +void gen_rtc_timer(unsigned long data); + +static volatile int stask_active; /* schedule_task */ +static volatile int ttask_active; /* timer_task */ +static int stop_rtc_timers; /* don't requeue tasks */ +static spinlock_t gen_rtc_lock = SPIN_LOCK_UNLOCKED; + +/* + * Routine to poll RTC seconds field for change as often as posible, + * after first RTC_UIE use timer to reduce polling + */ +void genrtc_troutine(void *data) +{ + unsigned int tmp = get_rtc_ss(); + + if (stop_rtc_timers) { + stask_active = 0; + return; + } + + if (oldsecs != tmp){ + oldsecs = tmp; + + timer_task.function = gen_rtc_timer; + timer_task.expires = jiffies + HZ - (HZ/10); + tt_exp=timer_task.expires; + ttask_active=1; + stask_active=0; + add_timer(&timer_task); + + gen_rtc_interrupt(0); + } else if (schedule_task(&genrtc_task) == 0) + stask_active = 0; +} + +void gen_rtc_timer(unsigned long data) +{ + lostint = get_rtc_ss() - oldsecs ; + if (lostint<0) + lostint = 60 - lostint; + if (time_after(jiffies, tt_exp)) + printk(KERN_INFO "genrtc: timer task delayed by %ld jiffies\n", + jiffies-tt_exp); + ttask_active=0; + stask_active=1; + if ((schedule_task(&genrtc_task) == 0)) + stask_active = 0; +} + +/* + * call gen_rtc_interrupt function to signal an RTC_UIE, + * arg is unused. + * Could be invoked either from a real interrupt handler or + * from some routine that periodically (eg 100HZ) monitors + * whether RTC_SECS changed + */ +void gen_rtc_interrupt(unsigned long arg) +{ + /* We store the status in the low byte and the number of + * interrupts received since the last read in the remainder + * of rtc_irq_data. */ + + gen_rtc_irq_data += 0x100; + gen_rtc_irq_data &= ~0xff; + gen_rtc_irq_data |= RTC_UIE; + + if (lostint){ + printk("genrtc: system delaying clock ticks?\n"); + /* increment count so that userspace knows something is wrong */ + gen_rtc_irq_data += ((lostint-1)<<8); + lostint = 0; + } + + wake_up_interruptible(&gen_rtc_wait); +} + +/* + * Now all the various file operations that we export. + */ +static ssize_t gen_rtc_read(struct file *file, char *buf, + size_t count, loff_t *ppos) +{ + DECLARE_WAITQUEUE(wait, current); + unsigned long data; + ssize_t retval; + + if (count != sizeof (unsigned int) && count != sizeof (unsigned long)) + return -EINVAL; + + if (file->f_flags & O_NONBLOCK && !gen_rtc_irq_data) + return -EAGAIN; + + add_wait_queue(&gen_rtc_wait, &wait); + retval = -ERESTARTSYS; + + while (1) { + set_current_state(TASK_INTERRUPTIBLE); + data = xchg(&gen_rtc_irq_data, 0); + if (data) + break; + if (signal_pending(current)) + goto out; + schedule(); + } + + /* first test allows optimizer to nuke this case for 32-bit machines */ + if (sizeof (int) != sizeof (long) && count == sizeof (unsigned int)) { + unsigned int uidata = data; + retval = put_user(uidata, (unsigned long *)buf); + } + else { + retval = put_user(data, (unsigned long *)buf); + } + if (!retval) + retval = sizeof(unsigned long); + out: + current->state = TASK_RUNNING; + remove_wait_queue(&gen_rtc_wait, &wait); + + return retval; +} + +static unsigned int gen_rtc_poll(struct file *file, + struct poll_table_struct *wait) +{ + poll_wait(file, &gen_rtc_wait, wait); + if (gen_rtc_irq_data != 0) + return POLLIN | POLLRDNORM; + return 0; +} + +#endif + +/* + * Used to disable/enable interrupts, only RTC_UIE supported + * We also clear out any old irq data after an ioctl() that + * meddles with the interrupt enable/disable bits. + */ + +static inline void gen_clear_rtc_irq_bit(unsigned char bit) +{ +#ifdef CONFIG_GEN_RTC_X + stop_rtc_timers = 1; + if (ttask_active){ + del_timer_sync(&timer_task); + ttask_active = 0; + } + while (stask_active) + schedule(); + + spin_lock(&gen_rtc_lock); + irq_active = 0; + spin_unlock(&gen_rtc_lock); +#endif +} + +static inline int gen_set_rtc_irq_bit(unsigned char bit) +{ +#ifdef CONFIG_GEN_RTC_X + spin_lock(&gen_rtc_lock); + if ( !irq_active ) { + irq_active = 1; + stop_rtc_timers = 0; + lostint = 0; + genrtc_task.routine = genrtc_troutine; + oldsecs = get_rtc_ss(); + init_timer(&timer_task); + + stask_active = 1; + if (schedule_task(&genrtc_task) == 0){ + stask_active = 0; + } + } + spin_unlock(&gen_rtc_lock); + gen_rtc_irq_data = 0; + return 0; +#else + return -EINVAL; +#endif +} + +static int gen_rtc_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) +{ + struct rtc_time wtime; + struct rtc_pll_info pll; + + switch (cmd) { + + case RTC_PLL_GET: + if (get_rtc_pll(&pll)) + return -EINVAL; + else + return copy_to_user((void *)arg, &pll, sizeof pll) ? -EFAULT : 0; + + case RTC_PLL_SET: + if (!capable(CAP_SYS_TIME)) + return -EACCES; + if (copy_from_user(&pll, (struct rtc_pll_info*)arg, + sizeof(pll))) + return -EFAULT; + return set_rtc_pll(&pll); + + case RTC_UIE_OFF: /* disable ints from RTC updates. */ + gen_clear_rtc_irq_bit(RTC_UIE); + return 0; + + case RTC_UIE_ON: /* enable ints for RTC updates. */ + return gen_set_rtc_irq_bit(RTC_UIE); + + case RTC_RD_TIME: /* Read the time/date from RTC */ + /* this doesn't get week-day, who cares */ + memset(&wtime, 0, sizeof(wtime)); + get_rtc_time(&wtime); + + return copy_to_user((void *)arg, &wtime, sizeof(wtime)) ? -EFAULT : 0; + + case RTC_SET_TIME: /* Set the RTC */ + { + int year; + unsigned char leap_yr; + + if (!capable(CAP_SYS_TIME)) + return -EACCES; + + if (copy_from_user(&wtime, (struct rtc_time *)arg, + sizeof(wtime))) + return -EFAULT; + + year = wtime.tm_year + 1900; + leap_yr = ((!(year % 4) && (year % 100)) || + !(year % 400)); + + if ((wtime.tm_mon < 0 || wtime.tm_mon > 11) || (wtime.tm_mday < 1)) + return -EINVAL; + + if (wtime.tm_mday < 0 || wtime.tm_mday > + (days_in_mo[wtime.tm_mon] + ((wtime.tm_mon == 1) && leap_yr))) + return -EINVAL; + + if (wtime.tm_hour < 0 || wtime.tm_hour >= 24 || + wtime.tm_min < 0 || wtime.tm_min >= 60 || + wtime.tm_sec < 0 || wtime.tm_sec >= 60) + return -EINVAL; + + return set_rtc_time(&wtime); + } + } + + return -EINVAL; +} + +/* + * We enforce only one user at a time here with the open/close. + * Also clear the previous interrupt data on an open, and clean + * up things on a close. + */ + +static int gen_rtc_open(struct inode *inode, struct file *file) +{ + if (gen_rtc_status & RTC_IS_OPEN) + return -EBUSY; + + MOD_INC_USE_COUNT; + + gen_rtc_status |= RTC_IS_OPEN; + gen_rtc_irq_data = 0; + irq_active = 0; + + return 0; +} + +static int gen_rtc_release(struct inode *inode, struct file *file) +{ + /* + * Turn off all interrupts once the device is no longer + * in use and clear the data. + */ + + gen_clear_rtc_irq_bit(RTC_PIE|RTC_AIE|RTC_UIE); + + gen_rtc_status &= ~RTC_IS_OPEN; + MOD_DEC_USE_COUNT; + + return 0; +} + +static int gen_rtc_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data); + + +/* + * The various file operations we support. + */ + +static struct file_operations gen_rtc_fops = { + owner: THIS_MODULE, +#ifdef CONFIG_GEN_RTC_X + read: gen_rtc_read, + poll: gen_rtc_poll, +#endif + ioctl: gen_rtc_ioctl, + open: gen_rtc_open, + release: gen_rtc_release +}; + +static struct miscdevice rtc_gen_dev = +{ + RTC_MINOR, + "rtc", + &gen_rtc_fops +}; + +int __init rtc_generic_init(void) +{ + int retval; + + printk(KERN_INFO "Generic RTC Driver v%s\n", RTC_VERSION); + + retval = misc_register(&rtc_gen_dev); + if(retval < 0) + return retval; + +#ifdef CONFIG_PROC_FS + if((create_proc_read_entry ("driver/rtc", 0, 0, gen_rtc_read_proc, NULL)) == NULL){ + misc_deregister(&rtc_gen_dev); + return -ENOMEM; + } +#endif + + return 0; +} + +static void __exit rtc_generic_exit(void) +{ + remove_proc_entry ("driver/rtc", NULL); + misc_deregister(&rtc_gen_dev); +} + +module_init(rtc_generic_init); +module_exit(rtc_generic_exit); +EXPORT_NO_SYMBOLS; + + +/* + * Info exported via "/proc/rtc". + */ + +int gen_rtc_proc_output(char *buf) +{ + char *p; + struct rtc_time tm; + unsigned tmp; + struct rtc_pll_info pll; + + p = buf; + + get_rtc_time(&tm); + + p += sprintf(p, + "rtc_time\t: %02d:%02d:%02d\n" + "rtc_date\t: %04d-%02d-%02d\n" + "rtc_epoch\t: %04u\n", + tm.tm_hour, tm.tm_min, tm.tm_sec, + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, 1900); + + tm.tm_hour=0;tm.tm_min=0;tm.tm_sec=0; + + p += sprintf(p, "alarm\t\t: "); + if (tm.tm_hour <= 24) + p += sprintf(p, "%02d:", tm.tm_hour); + else + p += sprintf(p, "**:"); + + if (tm.tm_min <= 59) + p += sprintf(p, "%02d:", tm.tm_min); + else + p += sprintf(p, "**:"); + + if (tm.tm_sec <= 59) + p += sprintf(p, "%02d\n", tm.tm_sec); + else + p += sprintf(p, "**\n"); + + tmp= RTC_24H ; + p += sprintf(p, + "DST_enable\t: %s\n" + "BCD\t\t: %s\n" + "24hr\t\t: %s\n" + "square_wave\t: %s\n" + "alarm_IRQ\t: %s\n" + "update_IRQ\t: %s\n" + "periodic_IRQ\t: %s\n" + "periodic_freq\t: %ld\n" + "batt_status\t: %s\n", + (tmp & RTC_DST_EN) ? "yes" : "no", + (tmp & RTC_DM_BINARY) ? "no" : "yes", + (tmp & RTC_24H) ? "yes" : "no", + (tmp & RTC_SQWE) ? "yes" : "no", + (tmp & RTC_AIE) ? "yes" : "no", + irq_active ? "yes" : "no", + (tmp & RTC_PIE) ? "yes" : "no", + 0L /* freq */, + "okay" ); + if (!get_rtc_pll(&pll)) + p += sprintf(p, + "PLL adjustment\t: %d\n" + "PLL max +ve adjustment\t: %d\n" + "PLL max -ve adjustment\t: %d\n" + "PLL +ve adjustment factor\t: %d\n" + "PLL -ve adjustment factor\t: %d\n" + "PLL frequency\t: %ld\n", + pll.pll_value, + pll.pll_max, + pll.pll_min, + pll.pll_posmult, + pll.pll_negmult, + pll.pll_clock); + return p - buf; +} + +static int gen_rtc_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + int len = gen_rtc_proc_output (page); + if (len <= off+count) *eof = 1; + *start = page + off; + len -= off; + if (len>count) len = count; + if (len<0) len = 0; + return len; +} + + +MODULE_AUTHOR("Richard Zidlicky"); +MODULE_LICENSE("GPL"); + +/* + * Local variables: + * compile-command: "m68k-linux-gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -ffixed-a2 -c -o genrtc.o genrtc.c" + * End: + */ + --- linux-2.4.20/include/asm-m68k/machdep.h Wed May 29 10:14:12 2002 +++ linux-genrtc-2.4.20/include/asm-m68k/machdep.h Fri Jan 10 20:54:25 2003 @@ -5,6 +5,7 @@ struct kbd_repeat; struct mktime; struct rtc_time; +struct rtc_pll_info; struct gendisk; struct buffer_head; @@ -29,6 +30,9 @@ extern void (*mach_gettod)(int *year, int *mon, int *day, int *hour, int *min, int *sec); 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 ); --- linux-2.4.20/include/asm-m68k/rtc.h Wed May 29 10:14:13 2002 +++ linux-genrtc-2.4.20/include/asm-m68k/rtc.h Fri Jan 10 20:54:25 2003 @@ -13,9 +13,8 @@ #ifdef __KERNEL__ -#include <linux/config.h> #include <linux/rtc.h> -#include <linux/delay.h> +#include <asm/errno.h> #include <asm/machdep.h> #define RTC_PIE 0x40 /* periodic interrupt enable */ @@ -30,7 +29,48 @@ #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 */ +static inline void get_rtc_time(struct rtc_time *time) +{ + /* + * Only the values that we read from the RTC are set. We leave + * tm_wday, tm_yday and tm_isdst untouched. Even though the + * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated + * by the RTC when initially set to a non-zero value. + */ + mach_hwclk(0, time); +} +static inline int set_rtc_time(struct rtc_time *time) +{ + return mach_hwclk(1, time); +} + +static inline unsigned int get_rtc_ss(void) +{ + if (mach_get_ss) + return mach_get_ss(); + else{ + struct rtc_time h; + + get_rtc_time(&h); + return h.tm_sec; + } +} + +static inline int get_rtc_pll(struct rtc_pll_info *pll) +{ + if (mach_get_rtc_pll) + return mach_get_rtc_pll(pll); + else + return -EINVAL; +} +static inline int set_rtc_pll(struct rtc_pll_info *pll) +{ + if (mach_set_rtc_pll) + return mach_set_rtc_pll(pll); + else + return -EINVAL; +} #endif /* __KERNEL__ */ #endif /* _ASM__RTC_H */ --- linux-2.4.20/include/linux/rtc.h Mon Feb 19 09:47:19 2001 +++ linux-genrtc-2.4.20/include/linux/rtc.h Fri Jan 10 20:54:25 2003 @@ -39,10 +39,32 @@ struct rtc_time time; /* time the alarm is set to */ }; +/* + * Data structure to control PLL correction some better RTC feature + * pll_value is used to get or set current value of correction, + * the rest of the struct is used to query HW capabilities. + * This is modeled after the RTC used in Q40/Q60 computers but + * should be sufficiently flexible for other devices + * + * +ve pll_value means clock will run faster by + * pll_value*pll_posmult/pll_clock + * -ve pll_value means clock will run slower by + * pll_value*pll_negmult/pll_clock + */ + +struct rtc_pll_info { + int pll_ctrl; /* placeholder for fancier control */ + int pll_value; /* get/set correction value */ + int pll_max; /* max +ve (faster) adjustment value */ + int pll_min; /* max -ve (slower) adjustment value */ + int pll_posmult; /* factor for +ve corection */ + int pll_negmult; /* factor for -ve corection */ + long pll_clock; /* base PLL frequency */ +}; /* - * ioctl calls that are permitted to the /dev/rtc interface, if - * CONFIG_RTC/CONFIG_EFI_RTC was enabled. + * ioctl calls that are permitted to the /dev/rtc interface, if + * any of the RTC drivers are enabled. */ #define RTC_AIE_ON _IO('p', 0x01) /* Alarm int. enable on */ @@ -66,4 +88,6 @@ #define RTC_WKALM_SET _IOW('p', 0x0f, struct rtc_wkalrm)/* Set wakeup alarm*/ #define RTC_WKALM_RD _IOR('p', 0x10, struct rtc_wkalrm)/* Get wakeup alarm*/ +#define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info) /* Get PLL correction */ +#define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info) /* Set PLL correction */ #endif /* _LINUX_RTC_H_ */ 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] 30+ messages in thread
* Re: [parisc-linux] Generic RTC driver in 2.4.x? 2002-12-26 17:55 ` Tom Rini 2002-12-28 22:37 ` Geert Uytterhoeven @ 2002-12-28 22:37 ` Geert Uytterhoeven 1 sibling, 0 replies; 30+ messages in thread From: Geert Uytterhoeven @ 2002-12-28 22:37 UTC (permalink / raw) To: Tom Rini Cc: Randolph Chung, parisc-linux, Linux/PPC Development, Linux/m68k, Linux Kernel Development On Thu, 26 Dec 2002, Tom Rini wrote: > On Tue, Dec 24, 2002 at 03:51:47PM -0800, Randolph Chung wrote: > > > AFAIK the generic RTC driver is used on PA-RISC, PPC, and m68k. > > > > > > Are you interested in a backport to 2.4.x? > > > > On parisc we already have a version of the generic RTC driver in our > > 2.4 tree. If there's something more "official" or common we can adopt > > that version. > > Similarly, PPC has had it's own 'generic' RTC driver in the kernel for > ages, so there's no pressing need, but if the 2.5 version makes its way > back into 2.4 (as the 2.5 version has some minor changes needed for > everyone which weren't in the 2.4 m68k version), we can easily switch to > that version. I already merged some of your 2.5.x changes with the driver in the m68k 2.4.x tree. I'll do some more merges, and get back to you... 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] 30+ messages in thread
* Re: [parisc-linux] Generic RTC driver in 2.4.x? 2002-12-24 23:51 ` Randolph Chung 2002-12-26 17:55 ` Tom Rini @ 2002-12-26 17:55 ` Tom Rini 1 sibling, 0 replies; 30+ messages in thread From: Tom Rini @ 2002-12-26 17:55 UTC (permalink / raw) To: Randolph Chung Cc: Geert Uytterhoeven, parisc-linux, Linux/PPC Development, Linux/m68k, Linux Kernel Development On Tue, Dec 24, 2002 at 03:51:47PM -0800, Randolph Chung wrote: > > AFAIK the generic RTC driver is used on PA-RISC, PPC, and m68k. > > > > Are you interested in a backport to 2.4.x? > > On parisc we already have a version of the generic RTC driver in our > 2.4 tree. If there's something more "official" or common we can adopt > that version. Similarly, PPC has had it's own 'generic' RTC driver in the kernel for ages, so there's no pressing need, but if the 2.5 version makes its way back into 2.4 (as the 2.5 version has some minor changes needed for everyone which weren't in the 2.4 m68k version), we can easily switch to that version. -- Tom Rini (TR1265) http://gate.crashing.org/~trini/ ^ permalink raw reply [flat|nested] 30+ messages in thread
* [parisc-linux] Generic RTC driver in 2.4.x?
@ 2002-12-24 13:55 Geert Uytterhoeven
0 siblings, 0 replies; 30+ messages in thread
From: Geert Uytterhoeven @ 2002-12-24 13:55 UTC (permalink / raw)
To: parisc-linux, Linux/PPC Development, Linux/m68k; +Cc: Linux Kernel Development
AFAIK the generic RTC driver is used on PA-RISC, PPC, and m68k.
Are you interested in a backport to 2.4.x?
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] 30+ messages in threadend of thread, other threads:[~2003-01-31 17:44 UTC | newest] Thread overview: 30+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2002-12-24 13:55 [parisc-linux] Generic RTC driver in 2.4.x? Geert Uytterhoeven 2002-12-24 13:55 ` Geert Uytterhoeven 2002-12-24 23:51 ` [parisc-linux] " Randolph Chung 2002-12-24 23:51 ` Randolph Chung 2002-12-26 17:55 ` Tom Rini 2002-12-28 22:37 ` Geert Uytterhoeven 2003-01-05 14:44 ` Geert Uytterhoeven 2003-01-05 14:44 ` Geert Uytterhoeven 2003-01-10 20:05 ` [parisc-linux] Generic RTC driver in 2.4.x Geert Uytterhoeven 2003-01-10 20:05 ` Geert Uytterhoeven 2003-01-11 19:50 ` [parisc-linux] " Helge Deller 2003-01-12 11:33 ` Geert Uytterhoeven 2003-01-12 11:33 ` Geert Uytterhoeven 2003-01-12 11:33 ` Geert Uytterhoeven 2003-01-12 12:35 ` [parisc-linux] " Helge Deller 2003-01-12 12:35 ` Helge Deller 2003-01-12 21:49 ` [parisc-linux] " Richard Zidlicky 2003-01-12 21:49 ` Richard Zidlicky 2003-01-12 21:49 ` [parisc-linux] " Richard Zidlicky 2003-01-12 12:35 ` Helge Deller 2003-01-30 18:03 ` Tom Rini 2003-01-30 18:03 ` Tom Rini 2003-01-31 17:43 ` [parisc-linux] " Geert Uytterhoeven 2003-01-31 17:43 ` Geert Uytterhoeven 2003-01-31 17:43 ` Geert Uytterhoeven 2003-01-30 18:03 ` [parisc-linux] " Tom Rini 2003-01-10 20:05 ` [parisc-linux] " Geert Uytterhoeven 2002-12-28 22:37 ` [parisc-linux] Generic RTC driver in 2.4.x? Geert Uytterhoeven 2002-12-26 17:55 ` Tom Rini -- strict thread matches above, loose matches on Subject: below -- 2002-12-24 13:55 Geert Uytterhoeven
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.