~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/macintosh/rtc.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Linux/PowerPC Real Time Clock Driver
  3  *
  4  * heavily based on:
  5  * Linux/SPARC Real Time Clock Driver
  6  * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
  7  *
  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.
 11  *
 12  * Get the modified clock utility from:
 13  *   ftp://vger.rutgers.edu/pub/linux/Sparc/userland/clock.c
 14  */
 15 
 16 #include <linux/module.h>
 17 #include <linux/types.h>
 18 #include <linux/errno.h>
 19 #include <linux/miscdevice.h>
 20 #include <linux/malloc.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>
 28 
 29 #include <asm/time.h>
 30 
 31 static int rtc_busy = 0;
 32 
 33 /* Retrieve the current date and time from the real time clock. */
 34 void get_rtc_time(struct rtc_time *t)
 35 {
 36         unsigned long nowtime;
 37     
 38         nowtime = (ppc_md.get_rtc_time)();
 39 
 40         to_tm(nowtime, t);
 41 
 42         t->tm_year -= 1900;
 43         t->tm_mon -= 1;
 44         t->tm_wday -= 1;
 45 }
 46 
 47 /* Set the current date and time in the real time clock. */
 48 void set_rtc_time(struct rtc_time *t)
 49 {
 50         unsigned long nowtime;
 51 
 52         printk(KERN_INFO "rtc.c:set_rtc_time: %04d-%02d-%02d %02d:%02d:%02d.\n", t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
 53 
 54         nowtime = mktime(t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
 55 
 56         printk(KERN_INFO "rtc.c:set_rtc_time: set rtc time to %ld seconds.\n", nowtime);
 57 
 58         (ppc_md.set_rtc_time)(nowtime);
 59 }
 60 
 61 static loff_t rtc_lseek(struct file *file, loff_t offset, int origin)
 62 {
 63         return -ESPIPE;
 64 }
 65 
 66 static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 67         unsigned long arg)
 68 {
 69         struct rtc_time rtc_tm;
 70 
 71         switch (cmd)
 72         {
 73         case RTC_RD_TIME:
 74                 if (ppc_md.get_rtc_time)
 75                 {
 76                         get_rtc_time(&rtc_tm);
 77 
 78                         if (copy_to_user((struct rtc_time*)arg, &rtc_tm, sizeof(struct rtc_time)))
 79                                 return -EFAULT;
 80 
 81                         return 0;
 82                 }
 83                 else
 84                         return -EINVAL;
 85 
 86         case RTC_SET_TIME:
 87                 if (!capable(CAP_SYS_TIME))
 88                         return -EPERM;
 89 
 90                 if (ppc_md.set_rtc_time)
 91                 {
 92                         if (copy_from_user(&rtc_tm, (struct rtc_time*)arg, sizeof(struct rtc_time)))
 93                                 return -EFAULT;
 94 
 95                         set_rtc_time(&rtc_tm);
 96 
 97                         return 0;
 98                 }
 99                 else
100                         return -EINVAL;
101 
102         default:
103                 return -EINVAL;
104         }
105 }
106 
107 static int rtc_open(struct inode *inode, struct file *file)
108 {
109         if (rtc_busy)
110                 return -EBUSY;
111 
112         rtc_busy = 1;
113 
114         MOD_INC_USE_COUNT;
115 
116         return 0;
117 }
118 
119 static int rtc_release(struct inode *inode, struct file *file)
120 {
121         MOD_DEC_USE_COUNT;
122         rtc_busy = 0;
123         return 0;
124 }
125 
126 static struct file_operations rtc_fops = {
127         owner:          THIS_MODULE,
128         llseek:         rtc_lseek,
129         ioctl:          rtc_ioctl,
130         open:           rtc_open,
131         release:        rtc_release
132 };
133 
134 static struct miscdevice rtc_dev = { RTC_MINOR, "rtc", &rtc_fops };
135 
136 EXPORT_NO_SYMBOLS;
137 
138 static int __init rtc_init(void)
139 {
140         int error;
141 
142         error = misc_register(&rtc_dev);
143         if (error) {
144                 printk(KERN_ERR "rtc: unable to get misc minor\n");
145                 return error;
146         }
147 
148         return 0;
149 }
150 
151 static void __exit rtc_exit(void)
152 {
153         misc_deregister(&rtc_dev);
154 }
155 
156 module_init(rtc_init);
157 module_exit(rtc_exit);
158 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.