2 * Linux/PowerPC Real Time Clock Driver
5 * Linux/SPARC Real Time Clock Driver
6 * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
8 * This is a little driver that lets a user-level program access
9 * the PPC clocks chip. It is no use unless you
10 * use the modified clock utility.
12 * Get the modified clock utility from:
13 * ftp://vger.rutgers.edu/pub/linux/Sparc/userland/clock.c
16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/errno.h>
19 #include <linux/miscdevice.h>
20 #include <linux/slab.h>
21 #include <linux/fcntl.h>
22 #include <linux/poll.h>
23 #include <linux/init.h>
24 #include <linux/mc146818rtc.h>
25 #include <asm/system.h>
26 #include <asm/uaccess.h>
27 #include <asm/machdep.h>
31 static int rtc_busy = 0;
33 /* Retrieve the current date and time from the real time clock. */
34 void get_rtc_time(struct rtc_time *t)
36 unsigned long nowtime;
38 nowtime = (ppc_md.get_rtc_time)();
43 t->tm_mon -= 1; /* Make sure userland has a 0-based month */
46 /* Set the current date and time in the real time clock. */
47 void set_rtc_time(struct rtc_time *t)
49 unsigned long nowtime;
51 nowtime = mktime(t->tm_year+1900, t->tm_mon+1, t->tm_mday,
52 t->tm_hour, t->tm_min, t->tm_sec);
54 (ppc_md.set_rtc_time)(nowtime);
57 static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
60 struct rtc_time rtc_tm;
65 if (ppc_md.get_rtc_time)
67 memset(&rtc_tm, 0, sizeof(struct rtc_time));
68 get_rtc_time(&rtc_tm);
70 if (copy_to_user((struct rtc_time*)arg, &rtc_tm, sizeof(struct rtc_time)))
79 if (!capable(CAP_SYS_TIME))
82 if (ppc_md.set_rtc_time)
84 if (copy_from_user(&rtc_tm, (struct rtc_time*)arg, sizeof(struct rtc_time)))
87 set_rtc_time(&rtc_tm);
99 static int rtc_open(struct inode *inode, struct file *file)
111 static int rtc_release(struct inode *inode, struct file *file)
118 static struct file_operations rtc_fops = {
126 static struct miscdevice rtc_dev = { RTC_MINOR, "rtc", &rtc_fops };
130 static int __init rtc_init(void)
134 error = misc_register(&rtc_dev);
136 printk(KERN_ERR "rtc: unable to get misc minor\n");
143 static void __exit rtc_exit(void)
145 misc_deregister(&rtc_dev);
148 module_init(rtc_init);
149 module_exit(rtc_exit);
150 MODULE_LICENSE("GPL");