xref: /openbmc/linux/arch/m68k/mvme147/config.c (revision bc8419944f68161810702ea353aace17846829bc)
1 /*
2  *  arch/m68k/mvme147/config.c
3  *
4  *  Copyright (C) 1996 Dave Frascone [chaos@mindspring.com]
5  *  Cloned from        Richard Hirst [richard@sleepie.demon.co.uk]
6  *
7  * Based on:
8  *
9  *  Copyright (C) 1993 Hamish Macdonald
10  *
11  * This file is subject to the terms and conditions of the GNU General Public
12  * License.  See the file README.legal in the main directory of this archive
13  * for more details.
14  */
15 
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/mm.h>
19 #include <linux/tty.h>
20 #include <linux/clocksource.h>
21 #include <linux/console.h>
22 #include <linux/linkage.h>
23 #include <linux/init.h>
24 #include <linux/major.h>
25 #include <linux/rtc.h>
26 #include <linux/interrupt.h>
27 
28 #include <asm/bootinfo.h>
29 #include <asm/bootinfo-vme.h>
30 #include <asm/byteorder.h>
31 #include <asm/setup.h>
32 #include <asm/irq.h>
33 #include <asm/traps.h>
34 #include <asm/machdep.h>
35 #include <asm/mvme147hw.h>
36 
37 
38 static void mvme147_get_model(char *model);
39 extern void mvme147_sched_init(void);
40 extern int mvme147_hwclk (int, struct rtc_time *);
41 extern void mvme147_reset (void);
42 
43 
44 static int bcd2int (unsigned char b);
45 
46 
47 int __init mvme147_parse_bootinfo(const struct bi_record *bi)
48 {
49 	uint16_t tag = be16_to_cpu(bi->tag);
50 	if (tag == BI_VME_TYPE || tag == BI_VME_BRDINFO)
51 		return 0;
52 	else
53 		return 1;
54 }
55 
56 void mvme147_reset(void)
57 {
58 	pr_info("\r\n\nCalled mvme147_reset\r\n");
59 	m147_pcc->watchdog = 0x0a;	/* Clear timer */
60 	m147_pcc->watchdog = 0xa5;	/* Enable watchdog - 100ms to reset */
61 	while (1)
62 		;
63 }
64 
65 static void mvme147_get_model(char *model)
66 {
67 	sprintf(model, "Motorola MVME147");
68 }
69 
70 /*
71  * This function is called during kernel startup to initialize
72  * the mvme147 IRQ handling routines.
73  */
74 
75 void __init mvme147_init_IRQ(void)
76 {
77 	m68k_setup_user_interrupt(VEC_USER, 192);
78 }
79 
80 void __init config_mvme147(void)
81 {
82 	mach_sched_init		= mvme147_sched_init;
83 	mach_init_IRQ		= mvme147_init_IRQ;
84 	mach_hwclk		= mvme147_hwclk;
85 	mach_reset		= mvme147_reset;
86 	mach_get_model		= mvme147_get_model;
87 
88 	/* Board type is only set by newer versions of vmelilo/tftplilo */
89 	if (!vme_brdtype)
90 		vme_brdtype = VME_TYPE_MVME147;
91 }
92 
93 static u64 mvme147_read_clk(struct clocksource *cs);
94 
95 static struct clocksource mvme147_clk = {
96 	.name   = "pcc",
97 	.rating = 250,
98 	.read   = mvme147_read_clk,
99 	.mask   = CLOCKSOURCE_MASK(32),
100 	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
101 };
102 
103 static u32 clk_total;
104 
105 #define PCC_TIMER_CLOCK_FREQ 160000
106 #define PCC_TIMER_CYCLES     (PCC_TIMER_CLOCK_FREQ / HZ)
107 #define PCC_TIMER_PRELOAD    (0x10000 - PCC_TIMER_CYCLES)
108 
109 /* Using pcc tick timer 1 */
110 
111 static irqreturn_t mvme147_timer_int (int irq, void *dev_id)
112 {
113 	unsigned long flags;
114 
115 	local_irq_save(flags);
116 	m147_pcc->t1_cntrl = PCC_TIMER_CLR_OVF | PCC_TIMER_COC_EN |
117 			     PCC_TIMER_TIC_EN;
118 	m147_pcc->t1_int_cntrl = PCC_INT_ENAB | PCC_TIMER_INT_CLR |
119 				 PCC_LEVEL_TIMER1;
120 	clk_total += PCC_TIMER_CYCLES;
121 	legacy_timer_tick(1);
122 	local_irq_restore(flags);
123 
124 	return IRQ_HANDLED;
125 }
126 
127 
128 void mvme147_sched_init (void)
129 {
130 	if (request_irq(PCC_IRQ_TIMER1, mvme147_timer_int, IRQF_TIMER,
131 			"timer 1", NULL))
132 		pr_err("Couldn't register timer interrupt\n");
133 
134 	/* Init the clock with a value */
135 	/* The clock counter increments until 0xFFFF then reloads */
136 	m147_pcc->t1_preload = PCC_TIMER_PRELOAD;
137 	m147_pcc->t1_cntrl = PCC_TIMER_CLR_OVF | PCC_TIMER_COC_EN |
138 			     PCC_TIMER_TIC_EN;
139 	m147_pcc->t1_int_cntrl = PCC_INT_ENAB | PCC_TIMER_INT_CLR |
140 				 PCC_LEVEL_TIMER1;
141 
142 	clocksource_register_hz(&mvme147_clk, PCC_TIMER_CLOCK_FREQ);
143 }
144 
145 static u64 mvme147_read_clk(struct clocksource *cs)
146 {
147 	unsigned long flags;
148 	u8 overflow, tmp;
149 	u16 count;
150 	u32 ticks;
151 
152 	local_irq_save(flags);
153 	tmp = m147_pcc->t1_cntrl >> 4;
154 	count = m147_pcc->t1_count;
155 	overflow = m147_pcc->t1_cntrl >> 4;
156 	if (overflow != tmp)
157 		count = m147_pcc->t1_count;
158 	count -= PCC_TIMER_PRELOAD;
159 	ticks = count + overflow * PCC_TIMER_CYCLES;
160 	ticks += clk_total;
161 	local_irq_restore(flags);
162 
163 	return ticks;
164 }
165 
166 static int bcd2int (unsigned char b)
167 {
168 	return ((b>>4)*10 + (b&15));
169 }
170 
171 int mvme147_hwclk(int op, struct rtc_time *t)
172 {
173 	if (!op) {
174 		m147_rtc->ctrl = RTC_READ;
175 		t->tm_year = bcd2int (m147_rtc->bcd_year);
176 		t->tm_mon  = bcd2int(m147_rtc->bcd_mth) - 1;
177 		t->tm_mday = bcd2int (m147_rtc->bcd_dom);
178 		t->tm_hour = bcd2int (m147_rtc->bcd_hr);
179 		t->tm_min  = bcd2int (m147_rtc->bcd_min);
180 		t->tm_sec  = bcd2int (m147_rtc->bcd_sec);
181 		m147_rtc->ctrl = 0;
182 		if (t->tm_year < 70)
183 			t->tm_year += 100;
184 	} else {
185 		/* FIXME Setting the time is not yet supported */
186 		return -EOPNOTSUPP;
187 	}
188 	return 0;
189 }
190