2 * Copyright (C) 1995 Linus Torvalds
3 * Adapted from 'alpha' version by Gary Thomas
4 * Modified by Cort Dougan (cort@cs.nmt.edu)
5 * Synergy Microsystems board support by Dan Cox (dan@synergymicro.com)
9 #include <linux/stddef.h>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/errno.h>
13 #include <linux/reboot.h>
14 #include <linux/pci.h>
15 #include <linux/time.h>
16 #include <linux/kdev_t.h>
17 #include <linux/types.h>
18 #include <linux/major.h>
19 #include <linux/initrd.h>
20 #include <linux/console.h>
21 #include <linux/seq_file.h>
22 #include <linux/root_dev.h>
23 #include <linux/bcd.h>
25 #include <asm/system.h>
26 #include <asm/pgtable.h>
30 #include <asm/m48t35.h>
31 #include <platforms/gemini.h>
33 #include <asm/open_pic.h>
34 #include <asm/bootinfo.h>
35 #include <asm/machdep.h>
37 void gemini_find_bridges(void);
38 static int gemini_get_clock_speed(void);
39 extern void gemini_pcibios_fixup(void);
41 static char *gemini_board_families[] = {
42 "VGM", "VSS", "KGM", "VGR", "VCM", "VCS", "KCM", "VCR"
44 static int gemini_board_count = sizeof(gemini_board_families) /
45 sizeof(gemini_board_families[0]);
47 static unsigned int cpu_7xx[16] = {
48 0, 15, 14, 0, 0, 13, 5, 9, 6, 11, 8, 10, 16, 12, 7, 0
50 static unsigned int cpu_6xx[16] = {
51 0, 0, 14, 0, 0, 13, 5, 9, 6, 11, 8, 10, 0, 12, 7, 0
55 * prom_init is the Gemini version of prom.c:prom_init. We only need
56 * the BSS clearing code, so I copied that out of prom.c. This is a
57 * lot simpler than hacking prom.c so it will build with Gemini. -VAL
60 #define PTRRELOC(x) ((typeof(x))((unsigned long)(x) + offset))
65 unsigned long offset = reloc_offset();
67 extern char __bss_start, _end;
69 /* First zero the BSS -- use memset, some arches don't have
71 memset_io(PTRRELOC(&__bss_start),0 , &_end - &__bss_start);
74 phys = offset + KERNELBASE;
82 gemini_show_cpuinfo(struct seq_file *m)
84 unsigned char reg, rev;
88 reg = readb(GEMINI_FEAT);
89 family = gemini_board_families[((reg>>4) & 0xf)];
90 if (((reg>>4) & 0xf) > gemini_board_count)
91 printk(KERN_ERR "cpuinfo(): unable to determine board family\n");
93 reg = readb(GEMINI_BREV);
94 type = (reg>>4) & 0xf;
97 reg = readb(GEMINI_BECO);
99 seq_printf(m, "machine\t\t: Gemini %s%d, rev %c, eco %d\n",
100 family, type, (rev + 'A'), (reg & 0xf));
102 seq_printf(m, "board\t\t: Gemini %s", family);
104 seq_printf(m, "%c", (type - 10) + 'A');
106 seq_printf(m, "%d", type);
108 seq_printf(m, ", rev %c, eco %d\n", (rev + 'A'), (reg & 0xf));
110 seq_printf(m, "clock\t\t: %dMhz\n", gemini_get_clock_speed());
115 static u_char gemini_openpic_initsenses[] = {
122 1, /* remainder are level-triggered */
125 #define GEMINI_MPIC_ADDR (0xfcfc0000)
126 #define GEMINI_MPIC_PCI_CFG (0x80005800)
128 void __init gemini_openpic_init(void)
131 OpenPIC_Addr = (volatile struct OpenPIC *)
132 grackle_read(GEMINI_MPIC_PCI_CFG + 0x10);
133 OpenPIC_InitSenses = gemini_openpic_initsenses;
134 OpenPIC_NumInitSenses = sizeof( gemini_openpic_initsenses );
136 ioremap( GEMINI_MPIC_ADDR, OPENPIC_SIZE);
140 extern unsigned long loops_per_jiffy;
141 extern int root_mountflags;
142 extern char cmd_line[];
145 gemini_heartbeat(void)
147 static unsigned long led = GEMINI_LEDBASE+(4*8);
148 static char direction = 8;
151 /* We only want to do this on 1 CPU */
152 if (smp_processor_id())
155 if ( (led + direction) > (GEMINI_LEDBASE+(7*8)) ||
156 (led + direction) < (GEMINI_LEDBASE+(4*8)) )
160 ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
163 void __init gemini_setup_arch(void)
165 extern char cmd_line[];
168 loops_per_jiffy = 50000000/HZ;
170 #ifdef CONFIG_BLK_DEV_INITRD
171 /* bootable off CDROM */
176 ROOT_DEV = Root_SDA1;
178 /* nothing but serial consoles... */
179 sprintf(cmd_line, "%s console=ttyS0", cmd_line);
181 printk("Boot arguments: %s\n", cmd_line);
183 ppc_md.heartbeat = gemini_heartbeat;
184 ppc_md.heartbeat_reset = HZ/8;
185 ppc_md.heartbeat_count = 1;
187 /* Lookup PCI hosts */
188 gemini_find_bridges();
189 /* take special pains to map the MPIC, since it isn't mapped yet */
190 gemini_openpic_init();
197 gemini_get_clock_speed(void)
199 unsigned long hid1, pvr;
202 pvr = mfspr(SPRN_PVR);
203 hid1 = (mfspr(SPRN_HID1) >> 28) & 0xf;
204 if (PVR_VER(pvr) == 8 ||
206 hid1 = cpu_7xx[hid1];
208 hid1 = cpu_6xx[hid1];
210 switch((readb(GEMINI_BSTAT) & 0xc) >> 2) {
214 clock = (hid1*100)/3;
218 clock = (hid1*125)/3;
229 void __init gemini_init_l2(void)
231 unsigned char reg, brev, fam, creg;
235 reg = readb(GEMINI_L2CFG);
236 brev = readb(GEMINI_BREV);
237 fam = readb(GEMINI_FEAT);
238 pvr = mfspr(SPRN_PVR);
240 switch(PVR_VER(pvr)) {
244 cache = (((reg >> 6) & 0x3) << 28);
249 /* Pre-3.0 processor revs had snooping errata. Leave
250 their L2's disabled with SMP. -- Dan */
251 if (PVR_CFG(pvr) < 3) {
252 printk("Pre-3.0 750; L2 left disabled!\n");
255 #endif /* CONFIG_SMP */
257 /* Special case: VGM5-B's came before L2 ratios were set on
258 the board. Processor speed shouldn't be too high, so
259 set L2 ratio to 1:1.5. */
260 if ((brev == 0x51) && ((fam & 0xa0) >> 4) == 0)
263 /* determine best cache ratio based upon what the board
264 tells us (which sometimes _may_ not be true) and
265 the processor speed. */
267 if (gemini_get_clock_speed() > 250)
273 static unsigned long l2_size_val = 0;
276 l2_size_val = _get_L2CR();
282 creg = readb(GEMINI_CPUSTAT);
283 if (((creg & 0xc) >> 2) != 1)
284 printk("Dual-604 boards don't support the use of L2\n");
286 writeb(1, GEMINI_L2CFG);
289 printk("Unknown processor; L2 left disabled\n");
293 cache |= ((1<<reg) << 25);
294 cache |= (L2CR_L2RAM_MASK|L2CR_L2CTL|L2CR_L2DO);
296 _set_L2CR(cache | L2CR_L2E);
301 gemini_restart(char *cmd)
304 /* make a clean restart, not via the MPIC */
310 gemini_power_off(void)
318 gemini_restart(NULL);
321 void __init gemini_init_IRQ(void)
323 /* gemini has no 8259 */
324 openpic_init(1, 0, 0, -1);
327 #define gemini_rtc_read(x) (readb(GEMINI_RTC+(x)))
328 #define gemini_rtc_write(val,x) (writeb((val),(GEMINI_RTC+(x))))
330 /* ensure that the RTC is up and running */
331 long __init gemini_time_init(void)
335 reg = gemini_rtc_read(M48T35_RTC_CONTROL);
337 if ( reg & M48T35_RTC_STOPPED ) {
338 printk(KERN_INFO "M48T35 real-time-clock was stopped. Now starting...\n");
339 gemini_rtc_write((reg & ~(M48T35_RTC_STOPPED)), M48T35_RTC_CONTROL);
340 gemini_rtc_write((reg | M48T35_RTC_SET), M48T35_RTC_CONTROL);
348 gemini_get_rtc_time(void)
350 unsigned int year, mon, day, hour, min, sec;
353 reg = gemini_rtc_read(M48T35_RTC_CONTROL);
354 gemini_rtc_write((reg|M48T35_RTC_READ), M48T35_RTC_CONTROL);
356 printk("get rtc: reg = %x\n", reg);
360 sec = gemini_rtc_read(M48T35_RTC_SECONDS);
361 min = gemini_rtc_read(M48T35_RTC_MINUTES);
362 hour = gemini_rtc_read(M48T35_RTC_HOURS);
363 day = gemini_rtc_read(M48T35_RTC_DOM);
364 mon = gemini_rtc_read(M48T35_RTC_MONTH);
365 year = gemini_rtc_read(M48T35_RTC_YEAR);
366 } while( sec != gemini_rtc_read(M48T35_RTC_SECONDS));
368 printk("get rtc: sec=%x, min=%x, hour=%x, day=%x, mon=%x, year=%x\n",
369 sec, min, hour, day, mon, year);
372 gemini_rtc_write(reg, M48T35_RTC_CONTROL);
381 if ((year += 1900) < 1970)
384 printk("get rtc: sec=%x, min=%x, hour=%x, day=%x, mon=%x, year=%x\n",
385 sec, min, hour, day, mon, year);
388 return mktime( year, mon, day, hour, min, sec );
393 gemini_set_rtc_time( unsigned long now )
400 reg = gemini_rtc_read(M48T35_RTC_CONTROL);
402 printk("set rtc: reg = %x\n", reg);
405 gemini_rtc_write((reg|M48T35_RTC_SET), M48T35_RTC_CONTROL);
407 printk("set rtc: tm vals - sec=%x, min=%x, hour=%x, mon=%x, mday=%x, year=%x\n",
408 tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mon, tm.tm_mday, tm.tm_year);
412 BIN_TO_BCD(tm.tm_sec);
413 BIN_TO_BCD(tm.tm_min);
414 BIN_TO_BCD(tm.tm_hour);
415 BIN_TO_BCD(tm.tm_mon);
416 BIN_TO_BCD(tm.tm_mday);
417 BIN_TO_BCD(tm.tm_year);
419 printk("set rtc: tm vals - sec=%x, min=%x, hour=%x, mon=%x, mday=%x, year=%x\n",
420 tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mon, tm.tm_mday, tm.tm_year);
423 gemini_rtc_write(tm.tm_sec, M48T35_RTC_SECONDS);
424 gemini_rtc_write(tm.tm_min, M48T35_RTC_MINUTES);
425 gemini_rtc_write(tm.tm_hour, M48T35_RTC_HOURS);
426 gemini_rtc_write(tm.tm_mday, M48T35_RTC_DOM);
427 gemini_rtc_write(tm.tm_mon, M48T35_RTC_MONTH);
428 gemini_rtc_write(tm.tm_year, M48T35_RTC_YEAR);
431 gemini_rtc_write(reg, M48T35_RTC_CONTROL);
436 /* use the RTC to determine the decrementer count */
437 void __init gemini_calibrate_decr(void)
442 /* determine processor bus speed */
443 reg = readb(GEMINI_BSTAT);
445 switch(((reg & 0x0c)>>2)&0x3) {
460 tb_ticks_per_jiffy = freq / HZ / divisor;
461 tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);
464 unsigned long __init gemini_find_end_of_memory(void)
469 reg = readb(GEMINI_MEMCFG);
470 total = ((1<<((reg & 0x7) - 1)) *
471 (8<<((reg >> 3) & 0x7)));
472 total *= (1024*1024);
479 io_block_mapping(0xf0000000, 0xf0000000, 0x10000000, _PAGE_IO);
480 io_block_mapping(0x80000000, 0x80000000, 0x10000000, _PAGE_IO);
485 smp_gemini_probe(void)
489 nr = (readb(GEMINI_CPUSTAT) & GEMINI_CPU_COUNT_MASK) >> 2;
494 openpic_request_IPIs();
495 for (i = 1; i < nr; ++i)
503 smp_gemini_kick_cpu(int nr)
505 openpic_reset_processor_phys(1 << nr);
506 openpic_reset_processor_phys(0);
510 smp_gemini_setup_cpu(int cpu_nr)
513 do_openpic_setup_cpu();
518 static struct smp_ops_t gemini_smp_ops = {
519 smp_openpic_message_pass,
522 smp_gemini_setup_cpu,
523 .give_timebase = smp_generic_give_timebase,
524 .take_timebase = smp_generic_take_timebase,
526 #endif /* CONFIG_SMP */
528 void __init platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
529 unsigned long r6, unsigned long r7)
533 /* Restore BATs for now */
534 mtspr(SPRN_DBAT3U, 0xf0001fff);
535 mtspr(SPRN_DBAT3L, 0xf000002a);
537 parse_bootinfo(find_bootinfo());
539 for(i = 0; i < GEMINI_LEDS; i++)
542 ISA_DMA_THRESHOLD = 0;
546 #ifdef CONFIG_BLK_DEV_INITRD
549 initrd_start = r4 + KERNELBASE;
550 initrd_end = r5 + KERNELBASE;
554 ppc_md.setup_arch = gemini_setup_arch;
555 ppc_md.show_cpuinfo = gemini_show_cpuinfo;
556 ppc_md.init_IRQ = gemini_init_IRQ;
557 ppc_md.get_irq = openpic_get_irq;
560 ppc_md.restart = gemini_restart;
561 ppc_md.power_off = gemini_power_off;
562 ppc_md.halt = gemini_halt;
564 ppc_md.time_init = gemini_time_init;
565 ppc_md.set_rtc_time = gemini_set_rtc_time;
566 ppc_md.get_rtc_time = gemini_get_rtc_time;
567 ppc_md.calibrate_decr = gemini_calibrate_decr;
569 ppc_md.find_end_of_memory = gemini_find_end_of_memory;
570 ppc_md.setup_io_mappings = gemini_map_io;
572 ppc_md.pcibios_fixup_bus = gemini_pcibios_fixup;
575 smp_ops = &gemini_smp_ops;
576 #endif /* CONFIG_SMP */