File: /usr/src/linux/arch/m68k/mvme147/config.c

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 hwclk_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     
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     
74     int mvme147_kbdrate (struct kbd_repeat *k)
75     {
76     	return 0;
77     }
78     
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     
88     static void mvme147_get_model(char *model)
89     {
90     	sprintf(model, "Motorola MVME147");
91     }
92     
93     
94     static int mvme147_get_hardware_list(char *buffer)
95     {
96     	*buffer = '\0';
97     
98     	return 0;
99     }
100     
101     
102     void __init config_mvme147(void)
103     {
104     	mach_max_dma_address	= 0x01000000;
105     	mach_sched_init		= mvme147_sched_init;
106     	mach_keyb_init		= mvme147_keyb_init;
107     	mach_kbdrate		= mvme147_kbdrate;
108     	mach_init_IRQ		= mvme147_init_IRQ;
109     	mach_gettimeoffset	= mvme147_gettimeoffset;
110     	mach_gettod		= mvme147_gettod;
111     	mach_hwclk		= mvme147_hwclk;
112     	mach_set_clock_mmss	= mvme147_set_clock_mmss;
113     	mach_reset		= mvme147_reset;
114     	mach_free_irq		= mvme147_free_irq;
115     	mach_process_int	= mvme147_process_int;
116     	mach_get_irq_list	= mvme147_get_irq_list;
117     	mach_request_irq	= mvme147_request_irq;
118     	enable_irq		= mvme147_enable_irq;
119     	disable_irq		= mvme147_disable_irq;
120     	mach_get_model		= mvme147_get_model;
121     	mach_get_hardware_list	= mvme147_get_hardware_list;
122     
123     	/* Board type is only set by newer versions of vmelilo/tftplilo */
124     	if (!vme_brdtype)
125     		vme_brdtype = VME_TYPE_MVME147;
126     }
127     
128     
129     /* Using pcc tick timer 1 */
130     
131     static void mvme147_timer_int (int irq, void *dev_id, struct pt_regs *fp)
132     {
133     	m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR;  
134     	m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;   
135     	tick_handler(irq, dev_id, fp);
136     }
137     
138     
139     void mvme147_sched_init (void (*timer_routine)(int, void *, struct pt_regs *))
140     {
141     	tick_handler = timer_routine;
142     	request_irq (PCC_IRQ_TIMER1, mvme147_timer_int, 
143     		IRQ_FLG_REPLACE, "timer 1", NULL);
144     	
145     	/* Init the clock with a value */
146     	/* our clock goes off every 6.25us */
147     	m147_pcc->t1_preload = PCC_TIMER_PRELOAD;
148     	m147_pcc->t1_cntrl = 0x0;   	/* clear timer */
149     	m147_pcc->t1_cntrl = 0x3; 	/* start timer */
150     	m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR;  /* clear pending ints */
151     	m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;   
152     }
153     
154     /* This is always executed with interrupts disabled.  */
155     /* XXX There are race hazards in this code XXX */
156     unsigned long mvme147_gettimeoffset (void)
157     {
158     	volatile unsigned short *cp = (volatile unsigned short *)0xfffe1012;
159     	unsigned short n;
160     
161     	n = *cp;
162     	while (n != *cp)
163     		n = *cp;
164     
165     	n -= PCC_TIMER_PRELOAD;
166     	return (unsigned long)n * 25 / 4;
167     }
168     
169     extern void mvme147_gettod (int *year, int *mon, int *day, int *hour,
170                                int *min, int *sec)
171     {
172     	m147_rtc->ctrl = RTC_READ;
173     	*year = bcd2int (m147_rtc->bcd_year);
174     	*mon = bcd2int (m147_rtc->bcd_mth);
175     	*day = bcd2int (m147_rtc->bcd_dom);
176     	*hour = bcd2int (m147_rtc->bcd_hr);
177     	*min = bcd2int (m147_rtc->bcd_min);
178     	*sec = bcd2int (m147_rtc->bcd_sec);
179     	m147_rtc->ctrl = 0;
180     }
181     
182     static int bcd2int (unsigned char b)
183     {
184     	return ((b>>4)*10 + (b&15));
185     }
186     
187     int mvme147_hwclk(int op, struct hwclk_time *t)
188     {
189     	return 0;
190     }
191     
192     int mvme147_set_clock_mmss (unsigned long nowtime)
193     {
194     	return 0;
195     }
196     
197     int mvme147_keyb_init (void)
198     {
199     	return 0;
200     }
201     
202     /*-------------------  Serial console stuff ------------------------*/
203     
204     static void scc_delay (void)
205     {
206     	int n;
207     	volatile int trash;
208     
209     	for (n = 0; n < 20; n++)
210     		trash = n;
211     }
212     
213     static void scc_write (char ch)
214     {
215     	volatile char *p = (volatile char *)M147_SCC_A_ADDR;
216     
217     	do {
218     		scc_delay();
219     	}
220     	while (!(*p & 4));
221     	scc_delay();
222     	*p = 8;
223     	scc_delay();
224     	*p = ch;
225     }
226     
227     
228     void m147_scc_write (struct console *co, const char *str, unsigned count)
229     {
230     	unsigned long	flags;
231     
232     	save_flags(flags);
233     	cli();
234     
235     	while (count--)
236     	{
237     		if (*str == '\n')
238     			scc_write ('\r');
239     		scc_write (*str++);
240     	}
241     	restore_flags(flags);
242     }
243     
244     
245     static int m147_scc_wait_key (struct console *co)
246     {
247     	volatile unsigned char *p = (volatile char *)M147_SCC_A_ADDR;
248     	unsigned long	flags;
249     	int		c;
250     
251     	/* wait for rx buf filled */
252     	while ((*p & 0x01) == 0)
253     		;
254     
255     	save_flags(flags);
256     	cli();
257     
258     	*p = 8;
259     	scc_delay();
260     	c = *p;
261     
262     	restore_flags(flags);
263     	return c;
264     }
265     
266     
267     void mvme147_init_console_port (struct console *co, int cflag)
268     {
269     	co->write    = m147_scc_write;
270     	co->wait_key = m147_scc_wait_key;
271     }
272