1 /* $Id: rtc.c,v 1.12 1998/05/08 21:04:35 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.rutgers.edu/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/malloc.h>
19 #include <linux/fcntl.h>
20 #include <linux/poll.h>
21 #include <linux/init.h>
22 #include <asm/mostek.h>
23 #include <asm/system.h>
24 #include <asm/uaccess.h>
27 static int rtc_busy
= 0;
29 /* Retrieve the current date and time from the real time clock. */
30 void get_rtc_time(struct rtc_time
*t
)
32 register struct mostek48t02
*regs
= mstk48t02_regs
;
37 regs
->creg
|= MSTK_CREG_READ
;
39 t
->sec
= MSTK_REG_SEC(regs
);
40 t
->min
= MSTK_REG_MIN(regs
);
41 t
->hour
= MSTK_REG_HOUR(regs
);
42 t
->dow
= MSTK_REG_DOW(regs
);
43 t
->dom
= MSTK_REG_DOM(regs
);
44 t
->month
= MSTK_REG_MONTH(regs
);
45 t
->year
= MSTK_CVT_YEAR( MSTK_REG_YEAR(regs
) );
47 regs
->creg
&= ~MSTK_CREG_READ
;
51 /* Set the current date and time inthe real time clock. */
52 void set_rtc_time(struct rtc_time
*t
)
54 register struct mostek48t02
*regs
= mstk48t02_regs
;
59 regs
->creg
|= MSTK_CREG_WRITE
;
61 MSTK_SET_REG_SEC(regs
,t
->sec
);
62 MSTK_SET_REG_MIN(regs
,t
->min
);
63 MSTK_SET_REG_HOUR(regs
,t
->hour
);
64 MSTK_SET_REG_DOW(regs
,t
->dow
);
65 MSTK_SET_REG_DOM(regs
,t
->dom
);
66 MSTK_SET_REG_MONTH(regs
,t
->month
);
67 MSTK_SET_REG_YEAR(regs
,t
->year
- MSTK_YEAR_ZERO
);
69 regs
->creg
&= ~MSTK_CREG_WRITE
;
73 static long long rtc_lseek(struct file
*file
, long long offset
, int origin
)
78 static int rtc_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
81 struct rtc_time rtc_tm
;
86 get_rtc_time(&rtc_tm
);
88 copy_to_user_ret((struct rtc_time
*)arg
, &rtc_tm
, sizeof(struct rtc_time
), -EFAULT
);
94 if (!capable(CAP_SYS_TIME
))
97 copy_from_user_ret(&rtc_tm
, (struct rtc_time
*)arg
, sizeof(struct rtc_time
), -EFAULT
);
99 set_rtc_time(&rtc_tm
);
108 static int rtc_open(struct inode
*inode
, struct file
*file
)
120 static int rtc_release(struct inode
*inode
, struct file
*file
)
127 static struct file_operations rtc_fops
= {
130 NULL
, /* rtc_write */
131 NULL
, /* rtc_readdir */
140 static struct miscdevice rtc_dev
= { RTC_MINOR
, "rtc", &rtc_fops
};
145 int init_module(void)
147 __initfunc(int rtc_init(void))
152 error
= misc_register(&rtc_dev
);
154 printk(KERN_ERR
"rtc: unable to get misc minor\n");
162 void cleanup_module(void)
164 misc_deregister(&rtc_dev
);