patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / arch / m68k / q40 / config.c
1 /*
2  *  arch/m68k/q40/config.c
3  *
4  *  Copyright (C) 1999 Richard Zidlicky
5  *
6  * originally based on:
7  *
8  *  linux/bvme/config.c
9  *
10  * This file is subject to the terms and conditions of the GNU General Public
11  * License.  See the file README.legal in the main directory of this archive
12  * for more details.
13  */
14
15 #include <linux/config.h>
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 #include <linux/serial_reg.h>
25 #include <linux/rtc.h>
26 #include <linux/vt_kern.h>
27
28 #include <asm/io.h>
29 #include <asm/rtc.h>
30 #include <asm/bootinfo.h>
31 #include <asm/system.h>
32 #include <asm/pgtable.h>
33 #include <asm/setup.h>
34 #include <asm/irq.h>
35 #include <asm/traps.h>
36 #include <asm/rtc.h>
37 #include <asm/machdep.h>
38 #include <asm/q40_master.h>
39
40 extern void floppy_setup(char *str, int *ints);
41
42 extern irqreturn_t q40_process_int (int level, struct pt_regs *regs);
43 extern irqreturn_t (*q40_default_handler[]) (int, void *, struct pt_regs *);  /* added just for debugging */
44 extern void q40_init_IRQ (void);
45 extern void q40_free_irq (unsigned int, void *);
46 extern int  show_q40_interrupts (struct seq_file *, void *);
47 extern void q40_enable_irq (unsigned int);
48 extern void q40_disable_irq (unsigned int);
49 static void q40_get_model(char *model);
50 static int  q40_get_hardware_list(char *buffer);
51 extern int  q40_request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *devname, void *dev_id);
52 extern void q40_sched_init(irqreturn_t (*handler)(int, void *, struct pt_regs *));
53
54 extern unsigned long q40_gettimeoffset (void);
55 extern int q40_hwclk (int, struct rtc_time *);
56 extern unsigned int q40_get_ss (void);
57 extern int q40_set_clock_mmss (unsigned long);
58 static int q40_get_rtc_pll(struct rtc_pll_info *pll);
59 static int q40_set_rtc_pll(struct rtc_pll_info *pll);
60 extern void q40_reset (void);
61 void q40_halt(void);
62 extern void q40_waitbut(void);
63 void q40_set_vectors (void);
64
65 extern void q40_mksound(unsigned int /*freq*/, unsigned int /*ticks*/ );
66
67 extern char *saved_command_line;
68 extern char m68k_debug_device[];
69 static void q40_mem_console_write(struct console *co, const char *b,
70                                     unsigned int count);
71
72 extern int ql_ticks;
73
74 static struct console q40_console_driver = {
75         .name =         "debug",
76         .flags =        CON_PRINTBUFFER,
77         .index =        -1,
78 };
79
80
81 /* early debugging function:*/
82 extern char *q40_mem_cptr; /*=(char *)0xff020000;*/
83 static int _cpleft;
84
85 static void q40_mem_console_write(struct console *co, const char *s,
86                                   unsigned int count)
87 {
88   char *p=(char *)s;
89
90   if (count<_cpleft)
91     while (count-- >0){
92       *q40_mem_cptr=*p++;
93       q40_mem_cptr+=4;
94       _cpleft--;
95     }
96 }
97 #if 0
98 void printq40(char *str)
99 {
100   int l=strlen(str);
101   char *p=q40_mem_cptr;
102
103   while (l-- >0 && _cpleft-- >0)
104     {
105       *p=*str++;
106       p+=4;
107     }
108   q40_mem_cptr=p;
109 }
110 #endif
111
112 static int halted=0;
113
114 #ifdef CONFIG_HEARTBEAT
115 static void q40_heartbeat(int on)
116 {
117   if (halted) return;
118
119   if (on)
120     Q40_LED_ON();
121   else
122     Q40_LED_OFF();
123 }
124 #endif
125
126 void q40_reset()
127 {
128         halted=1;
129         printk ("\n\n*******************************************\n"
130                 "Called q40_reset : press the RESET button!! \n"
131                 "*******************************************\n");
132         Q40_LED_ON();
133         while(1) ;
134 }
135 void q40_halt()
136 {
137         halted=1;
138         printk ("\n\n*******************\n"
139                     "  Called q40_halt\n"
140                     "*******************\n");
141         Q40_LED_ON();
142         while(1) ;
143 }
144
145 static void q40_get_model(char *model)
146 {
147     sprintf(model, "Q40");
148 }
149
150 /* No hardware options on Q40? */
151
152 static int q40_get_hardware_list(char *buffer)
153 {
154     *buffer = '\0';
155     return 0;
156 }
157
158 static unsigned int serports[]={0x3f8,0x2f8,0x3e8,0x2e8,0};
159 void q40_disable_irqs(void)
160 {
161   unsigned i,j;
162
163   j=0;
164   while((i=serports[j++])) outb(0,i+UART_IER);
165   master_outb(0,EXT_ENABLE_REG);
166   master_outb(0,KEY_IRQ_ENABLE_REG);
167 }
168
169 void __init config_q40(void)
170 {
171     mach_sched_init      = q40_sched_init;
172
173     mach_init_IRQ        = q40_init_IRQ;
174     mach_gettimeoffset   = q40_gettimeoffset;
175     mach_hwclk           = q40_hwclk;
176     mach_get_ss          = q40_get_ss;
177     mach_get_rtc_pll     = q40_get_rtc_pll;
178     mach_set_rtc_pll     = q40_set_rtc_pll;
179     mach_set_clock_mmss  = q40_set_clock_mmss;
180
181     mach_reset           = q40_reset;
182     mach_free_irq        = q40_free_irq;
183     mach_process_int     = q40_process_int;
184     mach_get_irq_list    = show_q40_interrupts;
185     mach_request_irq     = q40_request_irq;
186     enable_irq           = q40_enable_irq;
187     disable_irq          = q40_disable_irq;
188     mach_default_handler = &q40_default_handler;
189     mach_get_model       = q40_get_model;
190     mach_get_hardware_list = q40_get_hardware_list;
191
192 #if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
193     mach_beep            = q40_mksound;
194 #endif
195 #ifdef CONFIG_HEARTBEAT
196     mach_heartbeat = q40_heartbeat;
197 #endif
198     mach_halt = q40_halt;
199 #ifdef CONFIG_DUMMY_CONSOLE
200     conswitchp = &dummy_con;
201 #endif
202
203     /* disable a few things that SMSQ might have left enabled */
204     q40_disable_irqs();
205
206     /* no DMA at all, but ide-scsi requires it.. make sure
207      * all physical RAM fits into the boundary - otherwise
208      * allocator may play costly and useless tricks */
209     mach_max_dma_address = 1024*1024*1024;
210
211     /* useful for early debugging stages - writes kernel messages into SRAM */
212     if (!strncmp( m68k_debug_device,"mem",3 ))
213       {
214         /*printk("using NVRAM debug, q40_mem_cptr=%p\n",q40_mem_cptr);*/
215         _cpleft=2000-((long)q40_mem_cptr-0xff020000)/4;
216         q40_console_driver.write = q40_mem_console_write;
217         register_console(&q40_console_driver);
218       }
219 }
220
221
222 int q40_parse_bootinfo(const struct bi_record *rec)
223 {
224   return 1;
225 }
226
227
228 static inline unsigned char bcd2bin (unsigned char b)
229 {
230         return ((b>>4)*10 + (b&15));
231 }
232
233 static inline unsigned char bin2bcd (unsigned char b)
234 {
235         return (((b/10)*16) + (b%10));
236 }
237
238
239 unsigned long q40_gettimeoffset (void)
240 {
241     return 5000*(ql_ticks!=0);
242 }
243
244
245 /*
246  * Looks like op is non-zero for setting the clock, and zero for
247  * reading the clock.
248  *
249  *  struct hwclk_time {
250  *         unsigned        sec;       0..59
251  *         unsigned        min;       0..59
252  *         unsigned        hour;      0..23
253  *         unsigned        day;       1..31
254  *         unsigned        mon;       0..11
255  *         unsigned        year;      00...
256  *         int             wday;      0..6, 0 is Sunday, -1 means unknown/don't set
257  * };
258  */
259
260 int q40_hwclk(int op, struct rtc_time *t)
261 {
262         if (op)
263         {       /* Write.... */
264                 Q40_RTC_CTRL |= Q40_RTC_WRITE;
265
266                 Q40_RTC_SECS = bin2bcd(t->tm_sec);
267                 Q40_RTC_MINS = bin2bcd(t->tm_min);
268                 Q40_RTC_HOUR = bin2bcd(t->tm_hour);
269                 Q40_RTC_DATE = bin2bcd(t->tm_mday);
270                 Q40_RTC_MNTH = bin2bcd(t->tm_mon + 1);
271                 Q40_RTC_YEAR = bin2bcd(t->tm_year%100);
272                 if (t->tm_wday >= 0)
273                         Q40_RTC_DOW = bin2bcd(t->tm_wday+1);
274
275                 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
276         }
277         else
278         {       /* Read....  */
279           Q40_RTC_CTRL |= Q40_RTC_READ;
280
281           t->tm_year = bcd2bin (Q40_RTC_YEAR);
282           t->tm_mon  = bcd2bin (Q40_RTC_MNTH)-1;
283           t->tm_mday = bcd2bin (Q40_RTC_DATE);
284           t->tm_hour = bcd2bin (Q40_RTC_HOUR);
285           t->tm_min  = bcd2bin (Q40_RTC_MINS);
286           t->tm_sec  = bcd2bin (Q40_RTC_SECS);
287
288           Q40_RTC_CTRL &= ~(Q40_RTC_READ);
289
290           if (t->tm_year < 70)
291             t->tm_year += 100;
292           t->tm_wday = bcd2bin(Q40_RTC_DOW)-1;
293
294         }
295
296         return 0;
297 }
298
299 unsigned int q40_get_ss()
300 {
301         return bcd2bin(Q40_RTC_SECS);
302 }
303
304 /*
305  * Set the minutes and seconds from seconds value 'nowtime'.  Fail if
306  * clock is out by > 30 minutes.  Logic lifted from atari code.
307  */
308
309 int q40_set_clock_mmss (unsigned long nowtime)
310 {
311         int retval = 0;
312         short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
313
314         int rtc_minutes;
315
316
317         rtc_minutes = bcd2bin (Q40_RTC_MINS);
318
319         if ((rtc_minutes < real_minutes
320                 ? real_minutes - rtc_minutes
321                         : rtc_minutes - real_minutes) < 30)
322         {
323                 Q40_RTC_CTRL |= Q40_RTC_WRITE;
324                 Q40_RTC_MINS = bin2bcd(real_minutes);
325                 Q40_RTC_SECS = bin2bcd(real_seconds);
326                 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
327         }
328         else
329                 retval = -1;
330
331
332         return retval;
333 }
334
335
336 /* get and set PLL calibration of RTC clock */
337 #define Q40_RTC_PLL_MASK ((1<<5)-1)
338 #define Q40_RTC_PLL_SIGN (1<<5)
339
340 static int q40_get_rtc_pll(struct rtc_pll_info *pll)
341 {
342         int tmp=Q40_RTC_CTRL;
343         pll->pll_value = tmp & Q40_RTC_PLL_MASK;
344         if (tmp & Q40_RTC_PLL_SIGN)
345                 pll->pll_value = -pll->pll_value;
346         pll->pll_max=31;
347         pll->pll_min=-31;
348         pll->pll_posmult=512;
349         pll->pll_negmult=256;
350         pll->pll_clock=125829120;
351         return 0;
352 }
353
354 static int q40_set_rtc_pll(struct rtc_pll_info *pll)
355 {
356         if (!pll->pll_ctrl){
357                 /* the docs are a bit unclear so I am doublesetting */
358                 /* RTC_WRITE here ... */
359                 int tmp = (pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) |
360                           Q40_RTC_WRITE;
361                 Q40_RTC_CTRL |= Q40_RTC_WRITE;
362                 Q40_RTC_CTRL = tmp;
363                 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
364                 return 0;
365         } else
366                 return -EINVAL;
367 }