xref: /openbmc/linux/arch/m68k/sun3x/time.c (revision 9f380456)
1 /*
2  *  linux/arch/m68k/sun3x/time.c
3  *
4  *  Sun3x-specific time handling
5  */
6 
7 #include <linux/types.h>
8 #include <linux/kd.h>
9 #include <linux/init.h>
10 #include <linux/sched.h>
11 #include <linux/kernel_stat.h>
12 #include <linux/interrupt.h>
13 #include <linux/rtc.h>
14 #include <linux/bcd.h>
15 
16 #include <asm/irq.h>
17 #include <asm/io.h>
18 #include <asm/traps.h>
19 #include <asm/sun3x.h>
20 #include <asm/sun3ints.h>
21 #include <asm/rtc.h>
22 
23 #include "time.h"
24 
25 #define M_CONTROL 0xf8
26 #define M_SEC     0xf9
27 #define M_MIN     0xfa
28 #define M_HOUR    0xfb
29 #define M_DAY     0xfc
30 #define M_DATE    0xfd
31 #define M_MONTH   0xfe
32 #define M_YEAR    0xff
33 
34 #define C_WRITE   0x80
35 #define C_READ    0x40
36 #define C_SIGN    0x20
37 #define C_CALIB   0x1f
38 
39 int sun3x_hwclk(int set, struct rtc_time *t)
40 {
41 	volatile struct mostek_dt *h =
42 		(struct mostek_dt *)(SUN3X_EEPROM+M_CONTROL);
43 	unsigned long flags;
44 
45 	local_irq_save(flags);
46 
47 	if(set) {
48 		h->csr |= C_WRITE;
49 		h->sec = bin2bcd(t->tm_sec);
50 		h->min = bin2bcd(t->tm_min);
51 		h->hour = bin2bcd(t->tm_hour);
52 		h->wday = bin2bcd(t->tm_wday);
53 		h->mday = bin2bcd(t->tm_mday);
54 		h->month = bin2bcd(t->tm_mon);
55 		h->year = bin2bcd(t->tm_year);
56 		h->csr &= ~C_WRITE;
57 	} else {
58 		h->csr |= C_READ;
59 		t->tm_sec = bcd2bin(h->sec);
60 		t->tm_min = bcd2bin(h->min);
61 		t->tm_hour = bcd2bin(h->hour);
62 		t->tm_wday = bcd2bin(h->wday);
63 		t->tm_mday = bcd2bin(h->mday);
64 		t->tm_mon = bcd2bin(h->month);
65 		t->tm_year = bcd2bin(h->year);
66 		h->csr &= ~C_READ;
67 	}
68 
69 	local_irq_restore(flags);
70 
71 	return 0;
72 }
73 /* Not much we can do here */
74 unsigned long sun3x_gettimeoffset (void)
75 {
76     return 0L;
77 }
78 
79 #if 0
80 static void sun3x_timer_tick(int irq, void *dev_id, struct pt_regs *regs)
81 {
82     void (*vector)(int, void *, struct pt_regs *) = dev_id;
83 
84     /* Clear the pending interrupt - pulse the enable line low */
85     disable_irq(5);
86     enable_irq(5);
87 
88     vector(irq, NULL, regs);
89 }
90 #endif
91 
92 void __init sun3x_sched_init(irq_handler_t vector)
93 {
94 
95 	sun3_disable_interrupts();
96 
97 
98     /* Pulse enable low to get the clock started */
99 	sun3_disable_irq(5);
100 	sun3_enable_irq(5);
101 	sun3_enable_interrupts();
102 }
103