xref: /OK3568_Linux_fs/kernel/arch/m68k/sun3/intersil.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * arch/m68k/sun3/intersil.c
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * basic routines for accessing the intersil clock within the sun3 machines
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * started 11/12/1999 Sam Creasey
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
9*4882a593Smuzhiyun  * License.  See the file COPYING in the main directory of this archive
10*4882a593Smuzhiyun  * for more details.
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <linux/kernel.h>
14*4882a593Smuzhiyun #include <linux/rtc.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #include <asm/errno.h>
17*4882a593Smuzhiyun #include <asm/intersil.h>
18*4882a593Smuzhiyun #include <asm/machdep.h>
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /* bits to set for start/run of the intersil */
22*4882a593Smuzhiyun #define STOP_VAL (INTERSIL_STOP | INTERSIL_INT_ENABLE | INTERSIL_24H_MODE)
23*4882a593Smuzhiyun #define START_VAL (INTERSIL_RUN | INTERSIL_INT_ENABLE | INTERSIL_24H_MODE)
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /* get/set hwclock */
26*4882a593Smuzhiyun 
sun3_hwclk(int set,struct rtc_time * t)27*4882a593Smuzhiyun int sun3_hwclk(int set, struct rtc_time *t)
28*4882a593Smuzhiyun {
29*4882a593Smuzhiyun 	volatile struct intersil_dt *todintersil;
30*4882a593Smuzhiyun 	unsigned long flags;
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun         todintersil = (struct intersil_dt *) &intersil_clock->counter;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 	local_irq_save(flags);
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 	intersil_clock->cmd_reg = STOP_VAL;
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun 	/* set or read the clock */
39*4882a593Smuzhiyun 	if(set) {
40*4882a593Smuzhiyun 		todintersil->csec = 0;
41*4882a593Smuzhiyun 		todintersil->hour = t->tm_hour;
42*4882a593Smuzhiyun 		todintersil->minute = t->tm_min;
43*4882a593Smuzhiyun 		todintersil->second = t->tm_sec;
44*4882a593Smuzhiyun 		todintersil->month = t->tm_mon + 1;
45*4882a593Smuzhiyun 		todintersil->day = t->tm_mday;
46*4882a593Smuzhiyun 		todintersil->year = (t->tm_year - 68) % 100;
47*4882a593Smuzhiyun 		todintersil->weekday = t->tm_wday;
48*4882a593Smuzhiyun 	} else {
49*4882a593Smuzhiyun 		/* read clock */
50*4882a593Smuzhiyun 		t->tm_sec = todintersil->csec;
51*4882a593Smuzhiyun 		t->tm_hour = todintersil->hour;
52*4882a593Smuzhiyun 		t->tm_min = todintersil->minute;
53*4882a593Smuzhiyun 		t->tm_sec = todintersil->second;
54*4882a593Smuzhiyun 		t->tm_mon = todintersil->month - 1;
55*4882a593Smuzhiyun 		t->tm_mday = todintersil->day;
56*4882a593Smuzhiyun 		t->tm_year = todintersil->year + 68;
57*4882a593Smuzhiyun 		t->tm_wday = todintersil->weekday;
58*4882a593Smuzhiyun 		if (t->tm_year < 70)
59*4882a593Smuzhiyun 			t->tm_year += 100;
60*4882a593Smuzhiyun 	}
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun 	intersil_clock->cmd_reg = START_VAL;
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	local_irq_restore(flags);
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun 	return 0;
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun 
70