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/console.h>
21 #include <linux/linkage.h>
22 #include <linux/init.h>
23 #include <linux/major.h>
24
25 #include <asm/bootinfo.h>
26 #include <asm/system.h>
27 #include <asm/pgtable.h>
28 #include <asm/setup.h>
29 #include <asm/irq.h>
30 #include <asm/traps.h>
31 #include <asm/rtc.h>
32 #include <asm/machdep.h>
33 #include <asm/mvme147hw.h>
34
35
36 extern void mvme147_process_int (int level, struct pt_regs *regs);
37 extern void mvme147_init_IRQ (void);
38 extern void mvme147_free_irq (unsigned int, void *);
39 extern int mvme147_get_irq_list (char *);
40 extern void mvme147_enable_irq (unsigned int);
41 extern void mvme147_disable_irq (unsigned int);
42 static void mvme147_get_model(char *model);
43 static int mvme147_get_hardware_list(char *buffer);
44 extern int mvme147_request_irq (unsigned int irq, void (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *devname, void *dev_id);
45 extern void mvme147_sched_init(void (*handler)(int, void *, struct pt_regs *));
46 extern int mvme147_keyb_init(void);
47 extern int mvme147_kbdrate (struct kbd_repeat *);
48 extern unsigned long mvme147_gettimeoffset (void);
49 extern void mvme147_gettod (int *year, int *mon, int *day, int *hour,
50 int *min, int *sec);
51 extern int mvme147_hwclk (int, struct rtc_time *);
52 extern int mvme147_set_clock_mmss (unsigned long);
53 extern void mvme147_check_partition (struct gendisk *hd, unsigned int dev);
54 extern void mvme147_reset (void);
55 extern void mvme147_waitbut(void);
56
57
58 static int bcd2int (unsigned char b);
59
60 /* Save tick handler routine pointer, will point to do_timer() in
61 * kernel/sched.c, called via mvme147_process_int() */
62
63 void (*tick_handler)(int, void *, struct pt_regs *);
64
65
mvme147_parse_bootinfo(const struct bi_record * bi)66 int mvme147_parse_bootinfo(const struct bi_record *bi)
67 {
68 if (bi->tag == BI_VME_TYPE || bi->tag == BI_VME_BRDINFO)
69 return 0;
70 else
71 return 1;
72 }
73
mvme147_kbdrate(struct kbd_repeat * k)74 int mvme147_kbdrate (struct kbd_repeat *k)
75 {
76 return 0;
77 }
78
mvme147_reset()79 void mvme147_reset()
80 {
81 printk ("\r\n\nCalled mvme147_reset\r\n");
82 m147_pcc->watchdog = 0x0a; /* Clear timer */
83 m147_pcc->watchdog = 0xa5; /* Enable watchdog - 100ms to reset */
84 while (1)
85 ;
86 }
87
mvme147_get_model(char * model)88 static void mvme147_get_model(char *model)
89 {
90 sprintf(model, "Motorola MVME147");
91 }
92
93
mvme147_get_hardware_list(char * buffer)94 static int mvme147_get_hardware_list(char *buffer)
95 {
96 *buffer = '\0';
97
98 return 0;
99 }
100
101
config_mvme147(void)102 void __init config_mvme147(void)
103 {
104 mach_max_dma_address = 0x01000000;
105 mach_sched_init = mvme147_sched_init;
106 #ifdef CONFIG_VT
107 mach_keyb_init = mvme147_keyb_init;
108 mach_kbdrate = mvme147_kbdrate;
109 #endif
110 mach_init_IRQ = mvme147_init_IRQ;
111 mach_gettimeoffset = mvme147_gettimeoffset;
112 mach_gettod = mvme147_gettod;
113 mach_hwclk = mvme147_hwclk;
114 mach_set_clock_mmss = mvme147_set_clock_mmss;
115 mach_reset = mvme147_reset;
116 mach_free_irq = mvme147_free_irq;
117 mach_process_int = mvme147_process_int;
118 mach_get_irq_list = mvme147_get_irq_list;
119 mach_request_irq = mvme147_request_irq;
120 enable_irq = mvme147_enable_irq;
121 disable_irq = mvme147_disable_irq;
122 mach_get_model = mvme147_get_model;
123 mach_get_hardware_list = mvme147_get_hardware_list;
124
125 /* Board type is only set by newer versions of vmelilo/tftplilo */
126 if (!vme_brdtype)
127 vme_brdtype = VME_TYPE_MVME147;
128 }
129
130
131 /* Using pcc tick timer 1 */
132
mvme147_timer_int(int irq,void * dev_id,struct pt_regs * fp)133 static void mvme147_timer_int (int irq, void *dev_id, struct pt_regs *fp)
134 {
135 m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR;
136 m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;
137 tick_handler(irq, dev_id, fp);
138 }
139
140
mvme147_sched_init(void (* timer_routine)(int,void *,struct pt_regs *))141 void mvme147_sched_init (void (*timer_routine)(int, void *, struct pt_regs *))
142 {
143 tick_handler = timer_routine;
144 request_irq (PCC_IRQ_TIMER1, mvme147_timer_int,
145 IRQ_FLG_REPLACE, "timer 1", NULL);
146
147 /* Init the clock with a value */
148 /* our clock goes off every 6.25us */
149 m147_pcc->t1_preload = PCC_TIMER_PRELOAD;
150 m147_pcc->t1_cntrl = 0x0; /* clear timer */
151 m147_pcc->t1_cntrl = 0x3; /* start timer */
152 m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR; /* clear pending ints */
153 m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;
154 }
155
156 /* This is always executed with interrupts disabled. */
157 /* XXX There are race hazards in this code XXX */
mvme147_gettimeoffset(void)158 unsigned long mvme147_gettimeoffset (void)
159 {
160 volatile unsigned short *cp = (volatile unsigned short *)0xfffe1012;
161 unsigned short n;
162
163 n = *cp;
164 while (n != *cp)
165 n = *cp;
166
167 n -= PCC_TIMER_PRELOAD;
168 return (unsigned long)n * 25 / 4;
169 }
170
mvme147_gettod(int * year,int * mon,int * day,int * hour,int * min,int * sec)171 extern void mvme147_gettod (int *year, int *mon, int *day, int *hour,
172 int *min, int *sec)
173 {
174 m147_rtc->ctrl = RTC_READ;
175 *year = bcd2int (m147_rtc->bcd_year);
176 *mon = bcd2int (m147_rtc->bcd_mth);
177 *day = bcd2int (m147_rtc->bcd_dom);
178 *hour = bcd2int (m147_rtc->bcd_hr);
179 *min = bcd2int (m147_rtc->bcd_min);
180 *sec = bcd2int (m147_rtc->bcd_sec);
181 m147_rtc->ctrl = 0;
182 }
183
bcd2int(unsigned char b)184 static int bcd2int (unsigned char b)
185 {
186 return ((b>>4)*10 + (b&15));
187 }
188
mvme147_hwclk(int op,struct rtc_time * t)189 int mvme147_hwclk(int op, struct rtc_time *t)
190 {
191 return 0;
192 }
193
mvme147_set_clock_mmss(unsigned long nowtime)194 int mvme147_set_clock_mmss (unsigned long nowtime)
195 {
196 return 0;
197 }
198
mvme147_keyb_init(void)199 int mvme147_keyb_init (void)
200 {
201 return 0;
202 }
203
204 /*------------------- Serial console stuff ------------------------*/
205
scc_delay(void)206 static void scc_delay (void)
207 {
208 int n;
209 volatile int trash;
210
211 for (n = 0; n < 20; n++)
212 trash = n;
213 }
214
scc_write(char ch)215 static void scc_write (char ch)
216 {
217 volatile char *p = (volatile char *)M147_SCC_A_ADDR;
218
219 do {
220 scc_delay();
221 }
222 while (!(*p & 4));
223 scc_delay();
224 *p = 8;
225 scc_delay();
226 *p = ch;
227 }
228
229
m147_scc_write(struct console * co,const char * str,unsigned count)230 void m147_scc_write (struct console *co, const char *str, unsigned count)
231 {
232 unsigned long flags;
233
234 save_flags(flags);
235 cli();
236
237 while (count--)
238 {
239 if (*str == '\n')
240 scc_write ('\r');
241 scc_write (*str++);
242 }
243 restore_flags(flags);
244 }
245
mvme147_init_console_port(struct console * co,int cflag)246 void mvme147_init_console_port (struct console *co, int cflag)
247 {
248 co->write = m147_scc_write;
249 }
250