43 #define RTC_VERSION "1.07"
45 #include <linux/module.h>
46 #include <linux/sched.h>
47 #include <linux/errno.h>
49 #include <linux/fcntl.h>
51 #include <linux/rtc.h>
53 #include <linux/poll.h>
58 #include <asm/uaccess.h>
75 #define RTC_IS_OPEN 0x01
77 static unsigned char gen_rtc_status;
78 static unsigned long gen_rtc_irq_data;
81 static unsigned char days_in_mo[] =
82 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
84 static int irq_active;
86 #ifdef CONFIG_GEN_RTC_X
90 static unsigned int oldsecs;
92 static unsigned long tt_exp;
94 static void gen_rtc_timer(
unsigned long data);
96 static volatile int stask_active;
97 static volatile int ttask_active;
98 static int stop_rtc_timers;
101 static void gen_rtc_interrupt(
unsigned long arg);
109 unsigned int tmp = get_rtc_ss();
111 if (stop_rtc_timers) {
119 timer_task.function = gen_rtc_timer;
121 tt_exp=timer_task.expires;
126 gen_rtc_interrupt(0);
131 static void gen_rtc_timer(
unsigned long data)
133 lostint = get_rtc_ss() - oldsecs ;
135 lostint = 60 - lostint;
152 static void gen_rtc_interrupt(
unsigned long arg)
158 gen_rtc_irq_data += 0x100;
159 gen_rtc_irq_data &= ~0xff;
163 printk(
"genrtc: system delaying clock ticks?\n");
165 gen_rtc_irq_data += ((lostint-1)<<8);
176 size_t count, loff_t *ppos)
181 if (count !=
sizeof (
unsigned int) && count !=
sizeof (
unsigned long))
188 (data =
xchg(&gen_rtc_irq_data, 0)));
193 if (
sizeof (
int) !=
sizeof (
long) && count ==
sizeof (
unsigned int)) {
194 unsigned int uidata =
data;
195 retval =
put_user(uidata, (
unsigned int __user *)buf) ?:
196 sizeof(
unsigned int);
199 retval =
put_user(data, (
unsigned long __user *)buf) ?:
200 sizeof(
unsigned long);
206 static unsigned int gen_rtc_poll(
struct file *file,
209 poll_wait(file, &gen_rtc_wait, wait);
210 if (gen_rtc_irq_data != 0)
223 static inline void gen_clear_rtc_irq_bit(
unsigned char bit)
225 #ifdef CONFIG_GEN_RTC_X
234 spin_lock(&gen_rtc_lock);
236 spin_unlock(&gen_rtc_lock);
240 static inline int gen_set_rtc_irq_bit(
unsigned char bit)
242 #ifdef CONFIG_GEN_RTC_X
243 spin_lock(&gen_rtc_lock);
248 INIT_WORK(&genrtc_task, genrtc_troutine);
249 oldsecs = get_rtc_ss();
257 spin_unlock(&gen_rtc_lock);
258 gen_rtc_irq_data = 0;
265 static int gen_rtc_ioctl(
struct file *file,
266 unsigned int cmd,
unsigned long arg)
275 if (get_rtc_pll(&
pll))
285 return set_rtc_pll(&
pll);
288 gen_clear_rtc_irq_bit(
RTC_UIE);
292 return gen_set_rtc_irq_bit(
RTC_UIE);
296 memset(&wtime, 0,
sizeof(wtime));
304 unsigned char leap_yr;
312 year = wtime.tm_year + 1900;
313 leap_yr = ((!(year % 4) && (year % 100)) ||
316 if ((wtime.tm_mon < 0 || wtime.tm_mon > 11) || (wtime.tm_mday < 1))
319 if (wtime.tm_mday < 0 || wtime.tm_mday >
320 (days_in_mo[wtime.tm_mon] + ((wtime.tm_mon == 1) && leap_yr)))
323 if (wtime.tm_hour < 0 || wtime.tm_hour >= 24 ||
324 wtime.tm_min < 0 || wtime.tm_min >= 60 ||
325 wtime.tm_sec < 0 || wtime.tm_sec >= 60)
335 static long gen_rtc_unlocked_ioctl(
struct file *file,
unsigned int cmd,
341 ret = gen_rtc_ioctl(file, cmd, arg);
353 static int gen_rtc_open(
struct inode *
inode,
struct file *file)
362 gen_rtc_irq_data = 0;
369 static int gen_rtc_release(
struct inode *inode,
struct file *file)
383 #ifdef CONFIG_PROC_FS
389 static int gen_rtc_proc_output(
char *buf)
401 "rtc_time\t: %02d:%02d:%02d\n"
402 "rtc_date\t: %04d-%02d-%02d\n"
403 "rtc_epoch\t: %04u\n",
409 p +=
sprintf(p,
"alarm\t\t: ");
429 "square_wave\t: %s\n"
432 "periodic_IRQ\t: %s\n"
433 "periodic_freq\t: %ld\n"
434 "batt_status\t: %s\n",
437 (flags &
RTC_24H) ?
"yes" :
"no",
439 (flags &
RTC_AIE) ?
"yes" :
"no",
440 irq_active ?
"yes" :
"no",
441 (flags &
RTC_PIE) ?
"yes" :
"no",
444 if (!get_rtc_pll(&
pll))
446 "PLL adjustment\t: %d\n"
447 "PLL max +ve adjustment\t: %d\n"
448 "PLL max -ve adjustment\t: %d\n"
449 "PLL +ve adjustment factor\t: %d\n"
450 "PLL -ve adjustment factor\t: %d\n"
451 "PLL frequency\t: %ld\n",
462 int count,
int *eof,
void *data)
464 int len = gen_rtc_proc_output (page);
465 if (len <= off+count) *eof = 1;
468 if (len>count) len =
count;
473 static int __init gen_rtc_proc_init(
void)
477 r = create_proc_read_entry(
"driver/rtc", 0,
NULL, gen_rtc_read_proc,
NULL);
483 static inline int gen_rtc_proc_init(
void) {
return 0; }
493 #ifdef CONFIG_GEN_RTC_X
494 .read = gen_rtc_read,
495 .poll = gen_rtc_poll,
497 .unlocked_ioctl = gen_rtc_unlocked_ioctl,
498 .open = gen_rtc_open,
499 .release = gen_rtc_release,
507 .fops = &gen_rtc_fops,
510 static int __init rtc_generic_init(
void)
520 retval = gen_rtc_proc_init();
529 static void __exit rtc_generic_exit(
void)