2 * arch/ppc/platforms/k2.c
4 * Board setup routines for SBS K2
6 * Author: Matt Porter <mporter@mvista.com>
8 * Updated by: Randy Vinson <rvinson@mvista.com.
10 * 2001-2004 (c) MontaVista, Software, Inc. This file is licensed under
11 * the terms of the GNU General Public License version 2. This program
12 * is licensed "as is" without any warranty of any kind, whether express
16 #include <linux/config.h>
17 #include <linux/stddef.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/errno.h>
21 #include <linux/reboot.h>
22 #include <linux/pci.h>
23 #include <linux/kdev_t.h>
24 #include <linux/types.h>
25 #include <linux/major.h>
26 #include <linux/initrd.h>
27 #include <linux/console.h>
28 #include <linux/delay.h>
29 #include <linux/ide.h>
30 #include <linux/irq.h>
31 #include <linux/seq_file.h>
32 #include <linux/root_dev.h>
34 #include <asm/system.h>
35 #include <asm/pgtable.h>
39 #include <asm/machdep.h>
41 #include <asm/i8259.h>
43 #include <asm/bootinfo.h>
45 #include <syslib/cpc710.h>
48 extern unsigned long loops_per_jiffy;
49 extern void gen550_progress(char *, unsigned short);
51 static unsigned int cpu_7xx[16] = {
52 0, 15, 14, 0, 0, 13, 5, 9, 6, 11, 8, 10, 16, 12, 7, 0
54 static unsigned int cpu_6xx[16] = {
55 0, 0, 14, 0, 0, 13, 5, 9, 6, 11, 8, 10, 0, 12, 7, 0
58 static inline int __init
59 k2_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
61 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
63 * Check our hose index. If we are zero then we are on the
64 * local PCI hose, otherwise we are on the cPCI hose.
67 static char pci_irq_table[][4] =
69 * PCI IDSEL/INTPIN->INTLINE
73 {1, 0, 0, 0}, /* Ethernet */
74 {5, 5, 5, 5}, /* PMC Site 1 */
75 {6, 6, 6, 6}, /* PMC Site 2 */
76 {0, 0, 0, 0}, /* unused */
77 {0, 0, 0, 0}, /* unused */
78 {0, 0, 0, 0}, /* PCI-ISA Bridge */
79 {0, 0, 0, 0}, /* unused */
80 {0, 0, 0, 0}, /* unused */
81 {0, 0, 0, 0}, /* unused */
82 {0, 0, 0, 0}, /* unused */
83 {0, 0, 0, 0}, /* unused */
84 {0, 0, 0, 0}, /* unused */
85 {0, 0, 0, 0}, /* unused */
86 {0, 0, 0, 0}, /* unused */
87 {15, 0, 0, 0}, /* M5229 IDE */
89 const long min_idsel = 3, max_idsel = 17, irqs_per_slot = 4;
90 return PCI_IRQ_TABLE_LOOKUP;
92 static char pci_irq_table[][4] =
94 * PCI IDSEL/INTPIN->INTLINE
98 {10, 11, 12, 9}, /* cPCI slot 8 */
99 {11, 12, 9, 10}, /* cPCI slot 7 */
100 {12, 9, 10, 11}, /* cPCI slot 6 */
101 {9, 10, 11, 12}, /* cPCI slot 5 */
102 {10, 11, 12, 9}, /* cPCI slot 4 */
103 {11, 12, 9, 10}, /* cPCI slot 3 */
104 {12, 9, 10, 11}, /* cPCI slot 2 */
106 const long min_idsel = 15, max_idsel = 21, irqs_per_slot = 4;
107 return PCI_IRQ_TABLE_LOOKUP;
111 void k2_pcibios_fixup(void)
113 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
114 struct pci_dev *ide_dev;
117 * Enable DMA support on hdc
119 ide_dev = pci_get_device(PCI_VENDOR_ID_AL,
120 PCI_DEVICE_ID_AL_M5229, NULL);
124 unsigned long ide_dma_base;
126 ide_dma_base = pci_resource_start(ide_dev, 4);
127 outb(0x00, ide_dma_base + 0x2);
128 outb(0x20, ide_dma_base + 0xa);
129 pci_dev_put(ide_dev);
134 void k2_pcibios_fixup_resources(struct pci_dev *dev)
138 if ((dev->vendor == PCI_VENDOR_ID_IBM) &&
139 (dev->device == PCI_DEVICE_ID_IBM_CPC710_PCI64)) {
140 pr_debug("Fixup CPC710 resources\n");
141 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
142 dev->resource[i].start = 0;
143 dev->resource[i].end = 0;
148 void k2_setup_hoses(void)
150 struct pci_controller *hose_a, *hose_b;
153 * Reconfigure CPC710 memory map so
154 * we have some more PCI memory space.
158 __raw_writel(0x808000e0, PGCHP); /* Set FPHB mode */
161 __raw_writel(0x00000000, K2_PCI32_BAR + PIBAR); /* PCI I/O base */
162 __raw_writel(0x00000000, K2_PCI32_BAR + PMBAR); /* PCI Mem base */
163 __raw_writel(0xf0000000, K2_PCI32_BAR + MSIZE); /* 256MB */
164 __raw_writel(0xfff00000, K2_PCI32_BAR + IOSIZE); /* 1MB */
165 __raw_writel(0xc0000000, K2_PCI32_BAR + SMBAR); /* Base@0xc0000000 */
166 __raw_writel(0x80000000, K2_PCI32_BAR + SIBAR); /* Base@0x80000000 */
167 __raw_writel(0x000000c0, K2_PCI32_BAR + PSSIZE); /* 1GB space */
168 __raw_writel(0x000000c0, K2_PCI32_BAR + PPSIZE); /* 1GB space */
169 __raw_writel(0x00000000, K2_PCI32_BAR + BARPS); /* Base@0x00000000 */
170 __raw_writel(0x00000000, K2_PCI32_BAR + BARPP); /* Base@0x00000000 */
171 __raw_writel(0x00000080, K2_PCI32_BAR + PSBAR); /* Base@0x80 */
172 __raw_writel(0x00000000, K2_PCI32_BAR + PPBAR);
174 __raw_writel(0xc0000000, K2_PCI32_BAR + BPMDLK);
175 __raw_writel(0xd0000000, K2_PCI32_BAR + TPMDLK);
176 __raw_writel(0x80000000, K2_PCI32_BAR + BIODLK);
177 __raw_writel(0x80100000, K2_PCI32_BAR + TIODLK);
178 __raw_writel(0xe0008000, K2_PCI32_BAR + DLKCTRL);
179 __raw_writel(0xffffffff, K2_PCI32_BAR + DLKDEV);
182 __raw_writel(0x00100000, K2_PCI64_BAR + PIBAR); /* PCI I/O base */
183 __raw_writel(0x10000000, K2_PCI64_BAR + PMBAR); /* PCI Mem base */
184 __raw_writel(0xf0000000, K2_PCI64_BAR + MSIZE); /* 256MB */
185 __raw_writel(0xfff00000, K2_PCI64_BAR + IOSIZE); /* 1MB */
186 __raw_writel(0xd0000000, K2_PCI64_BAR + SMBAR); /* Base@0xd0000000 */
187 __raw_writel(0x80100000, K2_PCI64_BAR + SIBAR); /* Base@0x80100000 */
188 __raw_writel(0x000000c0, K2_PCI64_BAR + PSSIZE); /* 1GB space */
189 __raw_writel(0x000000c0, K2_PCI64_BAR + PPSIZE); /* 1GB space */
190 __raw_writel(0x00000000, K2_PCI64_BAR + BARPS); /* Base@0x00000000 */
191 __raw_writel(0x00000000, K2_PCI64_BAR + BARPP); /* Base@0x00000000 */
193 /* Setup PCI32 hose */
194 hose_a = pcibios_alloc_controller();
198 hose_a->first_busno = 0;
199 hose_a->last_busno = 0xff;
200 hose_a->pci_mem_offset = K2_PCI32_MEM_BASE;
202 pci_init_resource(&hose_a->io_resource,
205 IORESOURCE_IO, "PCI32 host bridge");
207 pci_init_resource(&hose_a->mem_resources[0],
208 K2_PCI32_LOWER_MEM + K2_PCI32_MEM_BASE,
209 K2_PCI32_UPPER_MEM + K2_PCI32_MEM_BASE,
210 IORESOURCE_MEM, "PCI32 host bridge");
212 hose_a->io_space.start = K2_PCI32_LOWER_IO;
213 hose_a->io_space.end = K2_PCI32_UPPER_IO;
214 hose_a->mem_space.start = K2_PCI32_LOWER_MEM;
215 hose_a->mem_space.end = K2_PCI32_UPPER_MEM;
216 hose_a->io_base_virt = (void *)K2_ISA_IO_BASE;
218 setup_indirect_pci(hose_a, K2_PCI32_CONFIG_ADDR, K2_PCI32_CONFIG_DATA);
220 /* Initialize PCI32 bus registers */
221 early_write_config_byte(hose_a,
224 CPC710_BUS_NUMBER, hose_a->first_busno);
226 early_write_config_byte(hose_a,
229 CPC710_SUB_BUS_NUMBER, hose_a->last_busno);
231 /* Enable PCI interrupt polling */
232 early_write_config_byte(hose_a,
234 PCI_DEVFN(8, 0), 0x45, 0x80);
236 /* Route polled PCI interrupts */
237 early_write_config_byte(hose_a,
239 PCI_DEVFN(8, 0), 0x48, 0x58);
241 early_write_config_byte(hose_a,
243 PCI_DEVFN(8, 0), 0x49, 0x07);
245 early_write_config_byte(hose_a,
247 PCI_DEVFN(8, 0), 0x4a, 0x31);
249 early_write_config_byte(hose_a,
251 PCI_DEVFN(8, 0), 0x4b, 0xb9);
253 /* route secondary IDE channel interrupt to IRQ 15 */
254 early_write_config_byte(hose_a,
256 PCI_DEVFN(8, 0), 0x75, 0x0f);
258 /* enable IDE controller IDSEL */
259 early_write_config_byte(hose_a,
261 PCI_DEVFN(8, 0), 0x58, 0x48);
263 /* Enable IDE function */
264 early_write_config_byte(hose_a,
266 PCI_DEVFN(17, 0), 0x50, 0x03);
268 /* Set M5229 IDE controller to native mode */
269 early_write_config_byte(hose_a,
271 PCI_DEVFN(17, 0), PCI_CLASS_PROG, 0xdf);
273 hose_a->last_busno = pciauto_bus_scan(hose_a, hose_a->first_busno);
275 /* Write out correct max subordinate bus number for hose A */
276 early_write_config_byte(hose_a,
279 CPC710_SUB_BUS_NUMBER, hose_a->last_busno);
281 /* Only setup PCI64 hose if we are in the system slot */
282 if (!(readb(K2_MISC_REG) & K2_SYS_SLOT_MASK)) {
283 /* Setup PCI64 hose */
284 hose_b = pcibios_alloc_controller();
288 hose_b->first_busno = hose_a->last_busno + 1;
289 hose_b->last_busno = 0xff;
291 /* Reminder: quit changing the following, it is correct. */
292 hose_b->pci_mem_offset = K2_PCI32_MEM_BASE;
294 pci_init_resource(&hose_b->io_resource,
297 IORESOURCE_IO, "PCI64 host bridge");
299 pci_init_resource(&hose_b->mem_resources[0],
300 K2_PCI64_LOWER_MEM + K2_PCI32_MEM_BASE,
301 K2_PCI64_UPPER_MEM + K2_PCI32_MEM_BASE,
302 IORESOURCE_MEM, "PCI64 host bridge");
304 hose_b->io_space.start = K2_PCI64_LOWER_IO;
305 hose_b->io_space.end = K2_PCI64_UPPER_IO;
306 hose_b->mem_space.start = K2_PCI64_LOWER_MEM;
307 hose_b->mem_space.end = K2_PCI64_UPPER_MEM;
308 hose_b->io_base_virt = (void *)K2_ISA_IO_BASE;
310 setup_indirect_pci(hose_b,
311 K2_PCI64_CONFIG_ADDR, K2_PCI64_CONFIG_DATA);
313 /* Initialize PCI64 bus registers */
314 early_write_config_byte(hose_b,
317 CPC710_SUB_BUS_NUMBER, 0xff);
319 early_write_config_byte(hose_b,
322 CPC710_BUS_NUMBER, hose_b->first_busno);
324 hose_b->last_busno = pciauto_bus_scan(hose_b,
325 hose_b->first_busno);
327 /* Write out correct max subordinate bus number for hose B */
328 early_write_config_byte(hose_b,
331 CPC710_SUB_BUS_NUMBER,
334 /* Configure PCI64 PSBAR */
335 early_write_config_dword(hose_b,
339 K2_PCI64_SYS_MEM_BASE);
342 /* Configure i8259 level/edge settings */
346 #ifdef CONFIG_CPC710_DATA_GATHERING
349 tmp = __raw_readl(ABCNTL);
350 /* Enable data gathering on both PCI interfaces */
351 __raw_writel(tmp | 0x05000000, ABCNTL);
355 ppc_md.pcibios_fixup = k2_pcibios_fixup;
356 ppc_md.pcibios_fixup_resources = k2_pcibios_fixup_resources;
357 ppc_md.pci_swizzle = common_swizzle;
358 ppc_md.pci_map_irq = k2_map_irq;
361 static int k2_get_bus_speed(void)
364 unsigned char board_id;
366 board_id = *(unsigned char *)K2_BOARD_ID_REG;
368 switch (K2_BUS_SPD(board_id)) {
372 bus_speed = 100000000;
376 bus_speed = 83333333;
380 bus_speed = 75000000;
384 bus_speed = 66666666;
390 static int k2_get_cpu_speed(void)
395 hid1 = mfspr(SPRN_HID1) >> 28;
397 if ((mfspr(SPRN_PVR) >> 16) == 8)
398 hid1 = cpu_7xx[hid1];
400 hid1 = cpu_6xx[hid1];
402 cpu_speed = k2_get_bus_speed() * hid1 / 2;
406 static void __init k2_calibrate_decr(void)
408 int freq, divisor = 4;
410 /* determine processor bus speed */
411 freq = k2_get_bus_speed();
412 tb_ticks_per_jiffy = freq / HZ / divisor;
413 tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
416 static int k2_show_cpuinfo(struct seq_file *m)
418 unsigned char k2_geo_bits, k2_system_slot;
420 seq_printf(m, "vendor\t\t: SBS\n");
421 seq_printf(m, "machine\t\t: K2\n");
422 seq_printf(m, "cpu speed\t: %dMhz\n", k2_get_cpu_speed() / 1000000);
423 seq_printf(m, "bus speed\t: %dMhz\n", k2_get_bus_speed() / 1000000);
424 seq_printf(m, "memory type\t: SDRAM\n");
426 k2_geo_bits = readb(K2_MSIZ_GEO_REG) & K2_GEO_ADR_MASK;
427 k2_system_slot = !(readb(K2_MISC_REG) & K2_SYS_SLOT_MASK);
428 seq_printf(m, "backplane\t: %s slot board",
429 k2_system_slot ? "System" : "Non system");
430 seq_printf(m, "with geographical address %x\n", k2_geo_bits);
437 static void __init k2_setup_arch(void)
441 /* Setup TODC access */
442 TODC_INIT(TODC_TYPE_MK48T37, 0, 0,
443 ioremap(K2_RTC_BASE_ADDRESS, K2_RTC_SIZE), 8);
445 /* init to some ~sane value until calibrate_delay() runs */
446 loops_per_jiffy = 50000000 / HZ;
448 /* make FLASH transactions higher priority than PCI to avoid deadlock */
449 __raw_writel(__raw_readl(SIOC1) | 0x80000000, SIOC1);
451 /* Set hardware to access FLASH page 2 */
452 __raw_writel(1 << 29, GPOUT);
454 /* Setup PCI host bridges */
457 #ifdef CONFIG_BLK_DEV_INITRD
459 ROOT_DEV = Root_RAM0;
462 #ifdef CONFIG_ROOT_NFS
465 ROOT_DEV = Root_HDC1;
468 /* Identify the system */
469 printk(KERN_INFO "System Identification: SBS K2 - PowerPC 750 @ "
470 "%d Mhz\n", k2_get_cpu_speed() / 1000000);
471 printk(KERN_INFO "Port by MontaVista Software, Inc. "
472 "(source@mvista.com)\n");
474 /* Identify the CPU manufacturer */
475 cpu = PVR_REV(mfspr(SPRN_PVR));
476 printk(KERN_INFO "CPU manufacturer: %s [rev=%04x]\n",
477 (cpu & (1 << 15)) ? "IBM" : "Motorola", cpu);
480 static void k2_restart(char *cmd)
484 /* Flip FLASH back to page 1 to access firmware image */
485 __raw_writel(0, GPOUT);
487 /* SRR0 has system reset vector, SRR1 has default MSR value */
488 /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
489 mtspr(SPRN_SRR0, 0xfff00100);
491 __asm__ __volatile__("rfi\n\t");
497 static void k2_power_off(void)
502 static void k2_halt(void)
508 * Set BAT 3 to map PCI32 I/O space.
510 static __inline__ void k2_set_bat(void)
512 /* wait for all outstanding memory accesses to complete */
516 mtspr(SPRN_DBAT2U, 0x80001ffe);
517 mtspr(SPRN_DBAT2L, 0x8000002a);
518 mtspr(SPRN_DBAT3U, 0xf0001ffe);
519 mtspr(SPRN_DBAT3L, 0xf000002a);
521 /* wait for updates */
525 static unsigned long __init k2_find_end_of_memory(void)
528 unsigned char msize = 7; /* Default to 128MB */
530 msize = K2_MEM_SIZE(readb(K2_MSIZ_GEO_REG));
535 * This will break without a lowered
536 * KERNELBASE or CONFIG_HIGHMEM on.
537 * It seems non 1GB builds exist yet,
540 total = K2_MEM_SIZE_1GB;
544 total = K2_MEM_SIZE_512MB;
548 total = K2_MEM_SIZE_256MB;
551 total = K2_MEM_SIZE_128MB;
555 ("K2: Invalid memory size detected, defaulting to 128MB\n");
556 total = K2_MEM_SIZE_128MB;
562 static void __init k2_map_io(void)
564 io_block_mapping(K2_PCI32_IO_BASE,
565 K2_PCI32_IO_BASE, 0x00200000, _PAGE_IO);
566 io_block_mapping(0xff000000, 0xff000000, 0x01000000, _PAGE_IO);
569 static void __init k2_init_irq(void)
573 for (i = 0; i < 16; i++)
574 irq_desc[i].handler = &i8259_pic;
579 void __init platform_init(unsigned long r3, unsigned long r4,
580 unsigned long r5, unsigned long r6, unsigned long r7)
582 parse_bootinfo((struct bi_record *)(r3 + KERNELBASE));
586 isa_io_base = K2_ISA_IO_BASE;
587 isa_mem_base = K2_ISA_MEM_BASE;
588 pci_dram_offset = K2_PCI32_SYS_MEM_BASE;
590 ppc_md.setup_arch = k2_setup_arch;
591 ppc_md.show_cpuinfo = k2_show_cpuinfo;
592 ppc_md.init_IRQ = k2_init_irq;
593 ppc_md.get_irq = i8259_irq;
595 ppc_md.find_end_of_memory = k2_find_end_of_memory;
596 ppc_md.setup_io_mappings = k2_map_io;
598 ppc_md.restart = k2_restart;
599 ppc_md.power_off = k2_power_off;
600 ppc_md.halt = k2_halt;
602 ppc_md.time_init = todc_time_init;
603 ppc_md.set_rtc_time = todc_set_rtc_time;
604 ppc_md.get_rtc_time = todc_get_rtc_time;
605 ppc_md.calibrate_decr = k2_calibrate_decr;
607 ppc_md.nvram_read_val = todc_direct_read_val;
608 ppc_md.nvram_write_val = todc_direct_write_val;
610 #ifdef CONFIG_SERIAL_TEXT_DEBUG
611 ppc_md.progress = gen550_progress;