port enough sendpoint support for DSM-G600 from D-Link 2.4.21-pre4
[linux-2.4.git] / arch / ppc / platforms / gemini_setup.c
1 /*
2  *  arch/ppc/platforms/setup.c
3  *
4  *  Copyright (C) 1995 Linus Torvalds
5  *  Adapted from 'alpha' version by Gary Thomas
6  *  Modified by Cort Dougan (cort@cs.nmt.edu)
7  *  Synergy Microsystems board support by Dan Cox (dan@synergymicro.com)
8  *
9  */
10
11 #include <linux/config.h>
12 #include <linux/stddef.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/errno.h>
16 #include <linux/reboot.h>
17 #include <linux/pci.h>
18 #include <linux/time.h>
19 #include <linux/kdev_t.h>
20 #include <linux/types.h>
21 #include <linux/major.h>
22 #include <linux/blk.h>
23 #include <linux/console.h>
24 #include <linux/irq.h>
25 #include <linux/seq_file.h>
26
27 #include <asm/system.h>
28 #include <asm/pgtable.h>
29 #include <asm/page.h>
30 #include <asm/dma.h>
31 #include <asm/io.h>
32 #include <asm/m48t35.h>
33 #include <platforms/gemini.h>
34 #include <asm/time.h>
35 #include <asm/open_pic.h>
36 #include <asm/bootinfo.h>
37 #include <asm/hardirq.h> /* for heartbeat */
38
39 void gemini_find_bridges(void);
40 static int gemini_get_clock_speed(void);
41 extern void gemini_pcibios_fixup(void);
42
43 static char *gemini_board_families[] = {
44   "VGM", "VSS", "KGM", "VGR", "VCM", "VCS", "KCM", "VCR"
45 };
46 static int gemini_board_count = sizeof(gemini_board_families) /
47                                  sizeof(gemini_board_families[0]);
48
49 static unsigned int cpu_7xx[16] = {
50         0, 15, 14, 0, 0, 13, 5, 9, 6, 11, 8, 10, 16, 12, 7, 0
51 };
52 static unsigned int cpu_6xx[16] = {
53         0, 0, 14, 0, 0, 13, 5, 9, 6, 11, 8, 10, 0, 12, 7, 0
54 };
55
56 /*
57  * prom_init is the Gemini version of prom.c:prom_init.  We only need
58  * the BSS clearing code, so I copied that out of prom.c.  This is a
59  * lot simpler than hacking prom.c so it will build with Gemini. -VAL
60  */
61
62 #define PTRRELOC(x)     ((typeof(x))((unsigned long)(x) + offset))
63
64 unsigned long
65 prom_init(void)
66 {
67         unsigned long offset = reloc_offset();
68         unsigned long phys;
69         extern char __bss_start, _end;
70
71         /* First zero the BSS -- use memset, some arches don't have
72          * caches on yet */
73         memset_io(PTRRELOC(&__bss_start),0 , &_end - &__bss_start);
74
75         /* Default */
76         phys = offset + KERNELBASE;
77
78         gemini_prom_init();
79
80         return phys;
81 }
82
83 int
84 gemini_show_cpuinfo(struct seq_file *m)
85 {
86         unsigned char reg, rev;
87         char *family;
88         unsigned int type;
89
90         reg = readb(GEMINI_FEAT);
91         family = gemini_board_families[((reg>>4) & 0xf)];
92         if (((reg>>4) & 0xf) > gemini_board_count)
93                 printk(KERN_ERR "cpuinfo(): unable to determine board family\n");
94
95         reg = readb(GEMINI_BREV);
96         type = (reg>>4) & 0xf;
97         rev = reg & 0xf;
98
99         reg = readb(GEMINI_BECO);
100
101         seq_printf(m, "machine\t\t: Gemini %s%d, rev %c, eco %d\n",
102                    family, type, (rev + 'A'), (reg & 0xf));
103
104         seq_printf(m, "board\t\t: Gemini %s", family);
105         if (type > 9)
106                 seq_printf(m, "%c", (type - 10) + 'A');
107         else
108                 seq_printf(m, "%d", type);
109
110         seq_printf(m, ", rev %c, eco %d\n", (rev + 'A'), (reg & 0xf));
111
112         seq_printf(m, "clock\t\t: %dMhz\n", gemini_get_clock_speed());
113
114         return 0;
115 }
116
117 static u_char gemini_openpic_initsenses[] = {
118         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 0 */
119         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 1 */
120         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 2 */
121         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 3 */
122         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* IRQ 4 */
123         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* IRQ 5 */
124         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 6 */
125         /* remainder are level-triggered */
126 };
127
128 #define GEMINI_MPIC_ADDR (0xfcfc0000)
129 #define GEMINI_MPIC_PCI_CFG (0x80005800)
130
131 void __init gemini_openpic_init(void)
132 {
133
134         OpenPIC_Addr = (volatile struct OpenPIC *)
135                 grackle_read(GEMINI_MPIC_PCI_CFG + 0x10);
136         OpenPIC_InitSenses = gemini_openpic_initsenses;
137         OpenPIC_NumInitSenses = sizeof( gemini_openpic_initsenses );
138
139         ioremap( GEMINI_MPIC_ADDR, OPENPIC_SIZE);
140 }
141
142
143 extern unsigned long loops_per_jiffy;
144 extern int root_mountflags;
145 extern char cmd_line[];
146
147 void
148 gemini_heartbeat(void)
149 {
150         static unsigned long led = GEMINI_LEDBASE+(4*8);
151         static char direction = 8;
152
153         /* We only want to do this on 1 CPU */
154         if (smp_processor_id()) {
155                 static short ratelimit;
156                 if (!ratelimit++)
157                         printk(KERN_ERR "%s: unexpected heartbeat on cpu %d\n",
158                                         __FUNCTION__, smp_processor_id());
159                 return;
160         }
161         *(char *)led = 0;
162         if ( (led + direction) > (GEMINI_LEDBASE+(7*8)) ||
163              (led + direction) < (GEMINI_LEDBASE+(4*8)) )
164                 direction *= -1;
165         led += direction;
166         *(char *)led = 0xff;
167 }
168
169 void __init gemini_setup_arch(void)
170 {
171         extern char cmd_line[];
172
173
174         loops_per_jiffy = 50000000/HZ;
175
176 #ifdef CONFIG_BLK_DEV_INITRD
177         /* bootable off CDROM */
178         if (initrd_start)
179                 ROOT_DEV = MKDEV(SCSI_CDROM_MAJOR, 0);
180         else
181 #endif
182                 ROOT_DEV = to_kdev_t(0x0801);
183
184         /* nothing but serial consoles... */
185         sprintf(cmd_line, "%s console=ttyS0", cmd_line);
186
187         printk("Boot arguments: %s\n", cmd_line);
188
189         ppc_md.heartbeat = gemini_heartbeat;
190         /* only run on cpu 0 */
191         heartbeat_reset(0) = HZ/8;
192         heartbeat_count(0) = 1;
193
194         /* Lookup PCI hosts */
195         gemini_find_bridges();
196         /* take special pains to map the MPIC, since it isn't mapped yet */
197         gemini_openpic_init();
198         /* start the L2 */
199         gemini_init_l2();
200 }
201
202
203 int
204 gemini_get_clock_speed(void)
205 {
206         unsigned long hid1, pvr;
207         int clock;
208
209         pvr = mfspr(PVR);
210         hid1 = (mfspr(HID1) >> 28) & 0xf;
211         if (PVR_VER(pvr) == 8 ||
212             PVR_VER(pvr) == 12)
213                 hid1 = cpu_7xx[hid1];
214         else
215                 hid1 = cpu_6xx[hid1];
216
217         switch((readb(GEMINI_BSTAT) & 0xc) >> 2) {
218
219         case 0:
220         default:
221                 clock = (hid1*100)/3;
222                 break;
223
224         case 1:
225                 clock = (hid1*125)/3;
226                 break;
227
228         case 2:
229                 clock = (hid1*50);
230                 break;
231         }
232
233         return clock;
234 }
235
236 void __init gemini_init_l2(void)
237 {
238         unsigned char reg, brev, fam, creg;
239         unsigned long cache;
240         unsigned long pvr;
241
242         reg = readb(GEMINI_L2CFG);
243         brev = readb(GEMINI_BREV);
244         fam = readb(GEMINI_FEAT);
245         pvr = mfspr(PVR);
246
247         switch(PVR_VER(pvr)) {
248
249         case 8:
250                 if (reg & 0xc0)
251                         cache = (((reg >> 6) & 0x3) << 28);
252                 else
253                         cache = 0x3 << 28;
254
255 #ifdef CONFIG_SMP
256                 /* Pre-3.0 processor revs had snooping errata.  Leave
257                    their L2's disabled with SMP. -- Dan */
258                 if (PVR_CFG(pvr) < 3) {
259                         printk("Pre-3.0 750; L2 left disabled!\n");
260                         return;
261                 }
262 #endif /* CONFIG_SMP */
263
264                 /* Special case: VGM5-B's came before L2 ratios were set on
265                    the board.  Processor speed shouldn't be too high, so
266                    set L2 ratio to 1:1.5.  */
267                 if ((brev == 0x51) && ((fam & 0xa0) >> 4) == 0)
268                         reg |= 1;
269
270                 /* determine best cache ratio based upon what the board
271                    tells us (which sometimes _may_ not be true) and
272                    the processor speed. */
273                 else {
274                         if (gemini_get_clock_speed() > 250)
275                                 reg = 2;
276                 }
277                 break;
278         case 12:
279         {
280                 static unsigned long l2_size_val = 0;
281
282                 if (!l2_size_val)
283                         l2_size_val = _get_L2CR();
284                 cache = l2_size_val;
285                 break;
286         }
287         case 4:
288         case 9:
289                 creg = readb(GEMINI_CPUSTAT);
290                 if (((creg & 0xc) >> 2) != 1)
291                         printk("Dual-604 boards don't support the use of L2\n");
292                 else
293                         writeb(1, GEMINI_L2CFG);
294                 return;
295         default:
296                 printk("Unknown processor; L2 left disabled\n");
297                 return;
298         }
299
300         cache |= ((1<<reg) << 25);
301         cache |= (L2CR_L2RAM_MASK|L2CR_L2CTL|L2CR_L2DO);
302         _set_L2CR(0);
303         _set_L2CR(cache | L2CR_L2E);
304
305 }
306
307 void
308 gemini_restart(char *cmd)
309 {
310         __cli();
311         /* make a clean restart, not via the MPIC */
312         _gemini_reboot();
313         for(;;);
314 }
315
316 void
317 gemini_power_off(void)
318 {
319         for(;;);
320 }
321
322 void
323 gemini_halt(void)
324 {
325         gemini_restart(NULL);
326 }
327
328 void __init gemini_init_IRQ(void)
329 {
330         /* gemini has no 8259 */
331         openpic_init(0);
332 }
333
334 #define gemini_rtc_read(x)       (readb(GEMINI_RTC+(x)))
335 #define gemini_rtc_write(val,x)  (writeb((val),(GEMINI_RTC+(x))))
336
337 /* ensure that the RTC is up and running */
338 long __init gemini_time_init(void)
339 {
340         unsigned char reg;
341
342         reg = gemini_rtc_read(M48T35_RTC_CONTROL);
343
344         if ( reg & M48T35_RTC_STOPPED ) {
345                 printk(KERN_INFO "M48T35 real-time-clock was stopped. Now starting...\n");
346                 gemini_rtc_write((reg & ~(M48T35_RTC_STOPPED)), M48T35_RTC_CONTROL);
347                 gemini_rtc_write((reg | M48T35_RTC_SET), M48T35_RTC_CONTROL);
348         }
349         return 0;
350 }
351
352 #undef DEBUG_RTC
353
354 unsigned long
355 gemini_get_rtc_time(void)
356 {
357         unsigned int year, mon, day, hour, min, sec;
358         unsigned char reg;
359
360         reg = gemini_rtc_read(M48T35_RTC_CONTROL);
361         gemini_rtc_write((reg|M48T35_RTC_READ), M48T35_RTC_CONTROL);
362 #ifdef DEBUG_RTC
363         printk("get rtc: reg = %x\n", reg);
364 #endif
365
366         do {
367                 sec = gemini_rtc_read(M48T35_RTC_SECONDS);
368                 min = gemini_rtc_read(M48T35_RTC_MINUTES);
369                 hour = gemini_rtc_read(M48T35_RTC_HOURS);
370                 day = gemini_rtc_read(M48T35_RTC_DOM);
371                 mon = gemini_rtc_read(M48T35_RTC_MONTH);
372                 year = gemini_rtc_read(M48T35_RTC_YEAR);
373         } while( sec != gemini_rtc_read(M48T35_RTC_SECONDS));
374 #ifdef DEBUG_RTC
375         printk("get rtc: sec=%x, min=%x, hour=%x, day=%x, mon=%x, year=%x\n",
376                sec, min, hour, day, mon, year);
377 #endif
378
379         gemini_rtc_write(reg, M48T35_RTC_CONTROL);
380
381         BCD_TO_BIN(sec);
382         BCD_TO_BIN(min);
383         BCD_TO_BIN(hour);
384         BCD_TO_BIN(day);
385         BCD_TO_BIN(mon);
386         BCD_TO_BIN(year);
387
388         if ((year += 1900) < 1970)
389                 year += 100;
390 #ifdef DEBUG_RTC
391         printk("get rtc: sec=%x, min=%x, hour=%x, day=%x, mon=%x, year=%x\n",
392                sec, min, hour, day, mon, year);
393 #endif
394
395         return mktime( year, mon, day, hour, min, sec );
396 }
397
398
399 int
400 gemini_set_rtc_time( unsigned long now )
401 {
402         unsigned char reg;
403         struct rtc_time tm;
404
405         to_tm( now, &tm );
406
407         reg = gemini_rtc_read(M48T35_RTC_CONTROL);
408 #if DEBUG_RTC
409         printk("set rtc: reg = %x\n", reg);
410 #endif
411
412         gemini_rtc_write((reg|M48T35_RTC_SET), M48T35_RTC_CONTROL);
413 #if DEBUG_RTC
414         printk("set rtc: tm vals - sec=%x, min=%x, hour=%x, mon=%x, mday=%x, year=%x\n",
415                tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mon, tm.tm_mday, tm.tm_year);
416 #endif
417
418         tm.tm_year -= 1900;
419         BIN_TO_BCD(tm.tm_sec);
420         BIN_TO_BCD(tm.tm_min);
421         BIN_TO_BCD(tm.tm_hour);
422         BIN_TO_BCD(tm.tm_mon);
423         BIN_TO_BCD(tm.tm_mday);
424         BIN_TO_BCD(tm.tm_year);
425 #ifdef DEBUG_RTC
426         printk("set rtc: tm vals - sec=%x, min=%x, hour=%x, mon=%x, mday=%x, year=%x\n",
427                tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mon, tm.tm_mday, tm.tm_year);
428 #endif
429
430         gemini_rtc_write(tm.tm_sec, M48T35_RTC_SECONDS);
431         gemini_rtc_write(tm.tm_min, M48T35_RTC_MINUTES);
432         gemini_rtc_write(tm.tm_hour, M48T35_RTC_HOURS);
433         gemini_rtc_write(tm.tm_mday, M48T35_RTC_DOM);
434         gemini_rtc_write(tm.tm_mon, M48T35_RTC_MONTH);
435         gemini_rtc_write(tm.tm_year, M48T35_RTC_YEAR);
436
437         /* done writing */
438         gemini_rtc_write(reg, M48T35_RTC_CONTROL);
439
440         if ((time_state == TIME_ERROR) || (time_state == TIME_BAD))
441                 time_state = TIME_OK;
442
443         return 0;
444 }
445
446 /*  use the RTC to determine the decrementer count */
447 void __init gemini_calibrate_decr(void)
448 {
449         int freq, divisor;
450         unsigned char reg;
451
452         /* determine processor bus speed */
453         reg = readb(GEMINI_BSTAT);
454
455         switch(((reg & 0x0c)>>2)&0x3) {
456         case 0:
457         default:
458                 freq = 66667;
459                 break;
460         case 1:
461                 freq = 83000;
462                 break;
463         case 2:
464                 freq = 100000;
465                 break;
466         }
467
468         freq *= 1000;
469         divisor = 4;
470         tb_ticks_per_jiffy = freq / HZ / divisor;
471         tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);
472 }
473
474 unsigned long __init gemini_find_end_of_memory(void)
475 {
476         unsigned long total;
477         unsigned char reg;
478
479         reg = readb(GEMINI_MEMCFG);
480         total = ((1<<((reg & 0x7) - 1)) *
481                  (8<<((reg >> 3) & 0x7)));
482         total *= (1024*1024);
483         return total;
484 }
485
486 static void __init
487 gemini_map_io(void)
488 {
489         io_block_mapping(0xf0000000, 0xf0000000, 0x10000000, _PAGE_IO);
490         io_block_mapping(0x80000000, 0x80000000, 0x10000000, _PAGE_IO);
491 }
492
493 #ifdef CONFIG_SMP
494 static int
495 smp_gemini_probe(void)
496 {
497         int i, nr;
498
499         nr = (readb(GEMINI_CPUSTAT) & GEMINI_CPU_COUNT_MASK) >> 2;
500         if (nr == 0)
501                 nr = 4;
502
503         if (nr > 1) {
504                 openpic_request_IPIs();
505                 for (i = 1; i < nr; ++i)
506                         smp_hw_index[i] = i;
507         }
508
509         return nr;
510 }
511
512 static void
513 smp_gemini_kick_cpu(int nr)
514 {
515         openpic_reset_processor_phys(1 << nr);
516         openpic_reset_processor_phys(0);
517 }
518
519 static void
520 smp_gemini_setup_cpu(int cpu_nr)
521 {
522         if (OpenPIC_Addr)
523                 do_openpic_setup_cpu();
524         if (cpu_nr > 0)
525                 gemini_init_l2();
526 }
527
528 static struct smp_ops_t gemini_smp_ops = {
529         smp_openpic_message_pass,
530         smp_gemini_probe,
531         smp_gemini_kick_cpu,
532         smp_gemini_setup_cpu,
533 };
534 #endif /* CONFIG_SMP */
535
536 void __init platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
537                           unsigned long r6, unsigned long r7)
538 {
539         int i;
540
541         parse_bootinfo(find_bootinfo());
542
543         for(i = 0; i < GEMINI_LEDS; i++)
544                 gemini_led_off(i);
545
546         ISA_DMA_THRESHOLD = 0;
547         DMA_MODE_READ = 0;
548         DMA_MODE_WRITE = 0;
549
550 #ifdef CONFIG_BLK_DEV_INITRD
551         if ( r4 )
552         {
553                 initrd_start = r4 + KERNELBASE;
554                 initrd_end = r5 + KERNELBASE;
555         }
556 #endif
557
558         ppc_md.setup_arch = gemini_setup_arch;
559         ppc_md.show_cpuinfo = gemini_show_cpuinfo;
560         ppc_md.irq_cannonicalize = NULL;
561         ppc_md.init_IRQ = gemini_init_IRQ;
562         ppc_md.get_irq = openpic_get_irq;
563         ppc_md.init = NULL;
564
565         ppc_md.restart = gemini_restart;
566         ppc_md.power_off = gemini_power_off;
567         ppc_md.halt = gemini_halt;
568
569         ppc_md.time_init = gemini_time_init;
570         ppc_md.set_rtc_time = gemini_set_rtc_time;
571         ppc_md.get_rtc_time = gemini_get_rtc_time;
572         ppc_md.calibrate_decr = gemini_calibrate_decr;
573
574         ppc_md.find_end_of_memory = gemini_find_end_of_memory;
575         ppc_md.setup_io_mappings = gemini_map_io;
576
577         /* no keyboard/mouse/video stuff yet.. */
578         ppc_md.kbd_setkeycode = NULL;
579         ppc_md.kbd_getkeycode = NULL;
580         ppc_md.kbd_translate = NULL;
581         ppc_md.kbd_unexpected_up = NULL;
582         ppc_md.kbd_leds = NULL;
583         ppc_md.kbd_init_hw = NULL;
584         ppc_md.ppc_kbd_sysrq_xlate = NULL;
585         ppc_md.pcibios_fixup_bus = gemini_pcibios_fixup;
586
587 #ifdef CONFIG_SMP
588         ppc_md.smp_ops = &gemini_smp_ops;
589 #endif /* CONFIG_SMP */
590 }