]>
git.ipfire.org Git - people/ms/linux.git/blob - drivers/sbus/char/rtc.c
1 /* $Id: rtc.c,v 1.28 2001/10/08 22:19:51 davem Exp $
3 * Linux/SPARC Real Time Clock Driver
4 * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
6 * This is a little driver that lets a user-level program access
7 * the SPARC Mostek real time clock chip. It is no use unless you
8 * use the modified clock utility.
10 * Get the modified clock utility from:
11 * ftp://vger.kernel.org/pub/linux/Sparc/userland/clock.c
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/errno.h>
17 #include <linux/miscdevice.h>
18 #include <linux/slab.h>
19 #include <linux/fcntl.h>
20 #include <linux/poll.h>
21 #include <linux/init.h>
22 #include <linux/smp_lock.h>
24 #include <asm/mostek.h>
25 #include <asm/system.h>
26 #include <asm/uaccess.h>
29 static int rtc_busy
= 0;
31 /* Retrieve the current date and time from the real time clock. */
32 static void get_rtc_time(struct rtc_time
*t
)
34 void * __iomem regs
= mstk48t02_regs
;
37 spin_lock_irq(&mostek_lock
);
39 tmp
= mostek_read(regs
+ MOSTEK_CREG
);
40 tmp
|= MSTK_CREG_READ
;
41 mostek_write(regs
+ MOSTEK_CREG
, tmp
);
43 t
->sec
= MSTK_REG_SEC(regs
);
44 t
->min
= MSTK_REG_MIN(regs
);
45 t
->hour
= MSTK_REG_HOUR(regs
);
46 t
->dow
= MSTK_REG_DOW(regs
);
47 t
->dom
= MSTK_REG_DOM(regs
);
48 t
->month
= MSTK_REG_MONTH(regs
);
49 t
->year
= MSTK_CVT_YEAR( MSTK_REG_YEAR(regs
) );
51 tmp
= mostek_read(regs
+ MOSTEK_CREG
);
52 tmp
&= ~MSTK_CREG_READ
;
53 mostek_write(regs
+ MOSTEK_CREG
, tmp
);
55 spin_unlock_irq(&mostek_lock
);
58 /* Set the current date and time inthe real time clock. */
59 void set_rtc_time(struct rtc_time
*t
)
61 void * __iomem regs
= mstk48t02_regs
;
64 spin_lock_irq(&mostek_lock
);
66 tmp
= mostek_read(regs
+ MOSTEK_CREG
);
67 tmp
|= MSTK_CREG_WRITE
;
68 mostek_write(regs
+ MOSTEK_CREG
, tmp
);
70 MSTK_SET_REG_SEC(regs
,t
->sec
);
71 MSTK_SET_REG_MIN(regs
,t
->min
);
72 MSTK_SET_REG_HOUR(regs
,t
->hour
);
73 MSTK_SET_REG_DOW(regs
,t
->dow
);
74 MSTK_SET_REG_DOM(regs
,t
->dom
);
75 MSTK_SET_REG_MONTH(regs
,t
->month
);
76 MSTK_SET_REG_YEAR(regs
,t
->year
- MSTK_YEAR_ZERO
);
78 tmp
= mostek_read(regs
+ MOSTEK_CREG
);
79 tmp
&= ~MSTK_CREG_WRITE
;
80 mostek_write(regs
+ MOSTEK_CREG
, tmp
);
82 spin_unlock_irq(&mostek_lock
);
85 static int rtc_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
88 struct rtc_time rtc_tm
;
89 void __user
*argp
= (void __user
*)arg
;
94 memset(&rtc_tm
, 0, sizeof(struct rtc_time
));
95 get_rtc_time(&rtc_tm
);
97 if (copy_to_user(argp
, &rtc_tm
, sizeof(struct rtc_time
)))
104 if (!capable(CAP_SYS_TIME
))
107 if (copy_from_user(&rtc_tm
, argp
, sizeof(struct rtc_time
)))
110 set_rtc_time(&rtc_tm
);
119 static int rtc_open(struct inode
*inode
, struct file
*file
)
123 spin_lock_irq(&mostek_lock
);
130 spin_unlock_irq(&mostek_lock
);
135 static int rtc_release(struct inode
*inode
, struct file
*file
)
142 static struct file_operations rtc_fops
= {
143 .owner
= THIS_MODULE
,
147 .release
= rtc_release
,
150 static struct miscdevice rtc_dev
= { RTC_MINOR
, "rtc", &rtc_fops
};
152 static int __init
rtc_sun_init(void)
156 /* It is possible we are being driven by some other RTC chip
157 * and thus another RTC driver is handling things.
159 if (mstk48t02_regs
== 0)
162 error
= misc_register(&rtc_dev
);
164 printk(KERN_ERR
"rtc: unable to get misc minor for Mostek\n");
171 static void __exit
rtc_sun_cleanup(void)
173 misc_deregister(&rtc_dev
);
176 module_init(rtc_sun_init
);
177 module_exit(rtc_sun_cleanup
);
178 MODULE_LICENSE("GPL");