2 * arch/ppc/platforms/cpci690.c
4 * Board setup routines for the Force CPCI690 board.
6 * Author: Mark A. Greer <mgreer@mvista.com>
8 * 2003 (c) MontaVista Software, Inc. This file is licensed under
9 * the terms of the GNU General Public License version 2. This programr
10 * is licensed "as is" without any warranty of any kind, whether express
13 #include <linux/config.h>
14 #include <linux/delay.h>
15 #include <linux/pci.h>
16 #include <linux/ide.h>
17 #include <linux/irq.h>
19 #include <linux/seq_file.h>
20 #include <linux/console.h>
21 #include <linux/initrd.h>
22 #include <linux/root_dev.h>
23 #include <linux/mv643xx.h>
24 #include <asm/bootinfo.h>
25 #include <asm/machdep.h>
28 #include <asm/mv64x60.h>
29 #include <platforms/cpci690.h>
31 #define BOARD_VENDOR "Force"
32 #define BOARD_MACHINE "CPCI690"
34 /* Set IDE controllers into Native mode? */
35 #define SET_PCI_IDE_NATIVE
37 static struct mv64x60_handle bh;
38 static u32 cpci690_br_base;
40 static const unsigned int cpu_7xx[16] = { /* 7xx & 74xx (but not 745x) */
41 18, 15, 14, 2, 4, 13, 5, 9, 6, 11, 8, 10, 16, 12, 7, 0
47 cpci690_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
49 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
51 if (hose->index == 0) {
52 static char pci_irq_table[][4] =
54 * PCI IDSEL/INTPIN->INTLINE
58 { 90, 91, 88, 89}, /* IDSEL 30/20 - Sentinel */
61 const long min_idsel = 20, max_idsel = 20, irqs_per_slot = 4;
62 return PCI_IRQ_TABLE_LOOKUP;
65 static char pci_irq_table[][4] =
67 * PCI IDSEL/INTPIN->INTLINE
71 { 93, 94, 95, 92}, /* IDSEL 28/18 - PMC slot 2 */
72 { 0, 0, 0, 0}, /* IDSEL 29/19 - Not used */
73 { 94, 95, 92, 93}, /* IDSEL 30/20 - PMC slot 1 */
76 const long min_idsel = 18, max_idsel = 20, irqs_per_slot = 4;
77 return PCI_IRQ_TABLE_LOOKUP;
82 cpci690_get_bus_speed(void)
88 cpci690_get_cpu_speed(void)
92 hid1 = mfspr(HID1) >> 28;
93 return cpci690_get_bus_speed() * cpu_7xx[hid1]/2;
97 #define MB (1024UL * KB)
98 #define GB (1024UL * MB)
101 cpci690_find_end_of_memory(void)
104 static u32 board_size;
105 static u8 first_time = 1;
108 /* Using cpci690_set_bat() mapping ==> virt addr == phys addr */
109 switch (in_8((u8 *) (cpci690_br_base +
110 CPCI690_BR_MEM_CTLR)) & 0x07) {
124 board_size = 1*GB + 512*MB;
130 board_size = 0xffffffff; /* use mem ctlr size */
133 mem_ctlr_size = mv64x60_get_mem_size(CONFIG_MV64X60_NEW_BASE,
134 MV64x60_TYPE_GT64260A);
136 /* Check that mem ctlr & board reg agree. If not, pick MIN. */
137 if (board_size != mem_ctlr_size) {
138 printk(KERN_WARNING "Board register & memory controller"
139 "mem size disagree (board reg: 0x%lx, "
140 "mem ctlr: 0x%lx)\n",
141 (ulong)board_size, (ulong)mem_ctlr_size);
142 board_size = min(board_size, mem_ctlr_size);
152 cpci690_setup_bridge(void)
154 struct mv64x60_setup_info si;
157 memset(&si, 0, sizeof(si));
159 si.phys_reg_base = CONFIG_MV64X60_NEW_BASE;
161 si.pci_0.enable_bus = 1;
162 si.pci_0.pci_io.cpu_base = CPCI690_PCI0_IO_START_PROC_ADDR;
163 si.pci_0.pci_io.pci_base_hi = 0;
164 si.pci_0.pci_io.pci_base_lo = CPCI690_PCI0_IO_START_PCI_ADDR;
165 si.pci_0.pci_io.size = CPCI690_PCI0_IO_SIZE;
166 si.pci_0.pci_io.swap = MV64x60_CPU2PCI_SWAP_NONE;
167 si.pci_0.pci_mem[0].cpu_base = CPCI690_PCI0_MEM_START_PROC_ADDR;
168 si.pci_0.pci_mem[0].pci_base_hi = CPCI690_PCI0_MEM_START_PCI_HI_ADDR;
169 si.pci_0.pci_mem[0].pci_base_lo = CPCI690_PCI0_MEM_START_PCI_LO_ADDR;
170 si.pci_0.pci_mem[0].size = CPCI690_PCI0_MEM_SIZE;
171 si.pci_0.pci_mem[0].swap = MV64x60_CPU2PCI_SWAP_NONE;
172 si.pci_0.pci_cmd_bits = 0;
173 si.pci_0.latency_timer = 0x80;
175 si.pci_1.enable_bus = 1;
176 si.pci_1.pci_io.cpu_base = CPCI690_PCI1_IO_START_PROC_ADDR;
177 si.pci_1.pci_io.pci_base_hi = 0;
178 si.pci_1.pci_io.pci_base_lo = CPCI690_PCI1_IO_START_PCI_ADDR;
179 si.pci_1.pci_io.size = CPCI690_PCI1_IO_SIZE;
180 si.pci_1.pci_io.swap = MV64x60_CPU2PCI_SWAP_NONE;
181 si.pci_1.pci_mem[0].cpu_base = CPCI690_PCI1_MEM_START_PROC_ADDR;
182 si.pci_1.pci_mem[0].pci_base_hi = CPCI690_PCI1_MEM_START_PCI_HI_ADDR;
183 si.pci_1.pci_mem[0].pci_base_lo = CPCI690_PCI1_MEM_START_PCI_LO_ADDR;
184 si.pci_1.pci_mem[0].size = CPCI690_PCI1_MEM_SIZE;
185 si.pci_1.pci_mem[0].swap = MV64x60_CPU2PCI_SWAP_NONE;
186 si.pci_1.pci_cmd_bits = 0;
187 si.pci_1.latency_timer = 0x80;
189 for (i=0; i<MV64x60_CPU2MEM_WINDOWS; i++) {
190 si.cpu_prot_options[i] = 0;
191 si.cpu_snoop_options[i] = GT64260_CPU_SNOOP_WB;
192 si.pci_0.acc_cntl_options[i] =
193 GT64260_PCI_ACC_CNTL_DREADEN |
194 GT64260_PCI_ACC_CNTL_RDPREFETCH |
195 GT64260_PCI_ACC_CNTL_RDLINEPREFETCH |
196 GT64260_PCI_ACC_CNTL_RDMULPREFETCH |
197 GT64260_PCI_ACC_CNTL_SWAP_NONE |
198 GT64260_PCI_ACC_CNTL_MBURST_32_BTYES;
199 si.pci_0.snoop_options[i] = GT64260_PCI_SNOOP_WB;
200 si.pci_1.acc_cntl_options[i] =
201 GT64260_PCI_ACC_CNTL_DREADEN |
202 GT64260_PCI_ACC_CNTL_RDPREFETCH |
203 GT64260_PCI_ACC_CNTL_RDLINEPREFETCH |
204 GT64260_PCI_ACC_CNTL_RDMULPREFETCH |
205 GT64260_PCI_ACC_CNTL_SWAP_NONE |
206 GT64260_PCI_ACC_CNTL_MBURST_32_BTYES;
207 si.pci_1.snoop_options[i] = GT64260_PCI_SNOOP_WB;
210 /* Lookup PCI host bridges */
211 if (mv64x60_init(&bh, &si))
212 printk(KERN_ERR "Bridge initialization failed.\n");
214 pci_dram_offset = 0; /* System mem at same addr on PCI & cpu bus */
215 ppc_md.pci_swizzle = common_swizzle;
216 ppc_md.pci_map_irq = cpci690_map_irq;
217 ppc_md.pci_exclude_device = mv64x60_pci_exclude_device;
219 mv64x60_set_bus(&bh, 0, 0);
220 bh.hose_a->first_busno = 0;
221 bh.hose_a->last_busno = 0xff;
222 bh.hose_a->last_busno = pciauto_bus_scan(bh.hose_a, 0);
224 bh.hose_b->first_busno = bh.hose_a->last_busno + 1;
225 mv64x60_set_bus(&bh, 1, bh.hose_b->first_busno);
226 bh.hose_b->last_busno = 0xff;
227 bh.hose_b->last_busno = pciauto_bus_scan(bh.hose_b,
228 bh.hose_b->first_busno);
234 cpci690_setup_peripherals(void)
236 /* Set up windows to CPLD, RTC/TODC, IPMI. */
237 mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_0_WIN, CPCI690_BR_BASE,
239 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_0_WIN);
240 cpci690_br_base = (u32)ioremap(CPCI690_BR_BASE, CPCI690_BR_SIZE);
242 mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_1_WIN, CPCI690_TODC_BASE,
243 CPCI690_TODC_SIZE, 0);
244 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_1_WIN);
245 TODC_INIT(TODC_TYPE_MK48T35, 0, 0,
246 ioremap(CPCI690_TODC_BASE, CPCI690_TODC_SIZE), 8);
248 mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_2_WIN, CPCI690_IPMI_BASE,
249 CPCI690_IPMI_SIZE, 0);
250 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_2_WIN);
252 mv64x60_set_bits(&bh, MV64x60_PCI0_ARBITER_CNTL, (1<<31));
253 mv64x60_set_bits(&bh, MV64x60_PCI1_ARBITER_CNTL, (1<<31));
255 mv64x60_set_bits(&bh, MV64x60_CPU_MASTER_CNTL, (1<<9)); /* Only 1 cpu */
258 * Turn off timer/counters. Not turning off watchdog timer because
259 * can't read its reg on the 64260A so don't know if we'll be enabling
262 mv64x60_clr_bits(&bh, MV64x60_TIMR_CNTR_0_3_CNTL,
263 ((1<<0) | (1<<8) | (1<<16) | (1<<24)));
264 mv64x60_clr_bits(&bh, GT64260_TIMR_CNTR_4_7_CNTL,
265 ((1<<0) | (1<<8) | (1<<16) | (1<<24)));
268 * Set MPSC Multiplex RMII
269 * NOTE: ethernet driver modifies bit 0 and 1
271 mv64x60_write(&bh, GT64260_MPP_SERIAL_PORTS_MULTIPLEX, 0x00001102);
273 #define GPP_EXTERNAL_INTERRUPTS \
274 ((1<<24) | (1<<25) | (1<<26) | (1<<27) | \
275 (1<<28) | (1<<29) | (1<<30) | (1<<31))
276 /* PCI interrupts are inputs */
277 mv64x60_clr_bits(&bh, MV64x60_GPP_IO_CNTL, GPP_EXTERNAL_INTERRUPTS);
278 /* PCI interrupts are active low */
279 mv64x60_set_bits(&bh, MV64x60_GPP_LEVEL_CNTL, GPP_EXTERNAL_INTERRUPTS);
281 /* Clear any pending interrupts for these inputs and enable them. */
282 mv64x60_write(&bh, MV64x60_GPP_INTR_CAUSE, ~GPP_EXTERNAL_INTERRUPTS);
283 mv64x60_set_bits(&bh, MV64x60_GPP_INTR_MASK, GPP_EXTERNAL_INTERRUPTS);
285 /* Route MPP interrupt inputs to GPP */
286 mv64x60_write(&bh, MV64x60_MPP_CNTL_2, 0x00000000);
287 mv64x60_write(&bh, MV64x60_MPP_CNTL_3, 0x00000000);
293 cpci690_setup_arch(void)
296 ppc_md.progress("cpci690_setup_arch: enter", 0);
297 #ifdef CONFIG_BLK_DEV_INITRD
299 ROOT_DEV = Root_RAM0;
302 #ifdef CONFIG_ROOT_NFS
305 ROOT_DEV = Root_SDA2;
309 ppc_md.progress("cpci690_setup_arch: Enabling L2 cache", 0);
311 /* Enable L2 and L3 caches (if 745x) */
312 _set_L2CR(_get_L2CR() | L2CR_L2E);
313 _set_L3CR(_get_L3CR() | L3CR_L3E);
316 ppc_md.progress("cpci690_setup_arch: Initializing bridge", 0);
318 cpci690_setup_bridge(); /* set up PCI bridge(s) */
319 cpci690_setup_peripherals(); /* set up chip selects/GPP/MPP etc */
322 ppc_md.progress("cpci690_setup_arch: bridge init complete", 0);
324 printk(KERN_INFO "%s %s port (C) 2003 MontaVista Software, Inc. "
325 "(source@mvista.com)\n", BOARD_VENDOR, BOARD_MACHINE);
328 ppc_md.progress("cpci690_setup_arch: exit", 0);
333 /* Platform device data fixup routines. */
334 #if defined(CONFIG_SERIAL_MPSC)
336 cpci690_fixup_mpsc_pdata(struct platform_device *pdev)
338 struct mpsc_pdata *pdata;
340 pdata = (struct mpsc_pdata *)pdev->dev.platform_data;
342 pdata->max_idle = 40;
343 pdata->default_baud = 9600;
344 pdata->brg_clk_src = 8;
345 pdata->brg_clk_freq = 133000000;
351 cpci690_platform_notify(struct device *dev)
355 void ((*rtn)(struct platform_device *pdev));
357 { MPSC_CTLR_NAME "0", cpci690_fixup_mpsc_pdata },
358 { MPSC_CTLR_NAME "1", cpci690_fixup_mpsc_pdata },
360 struct platform_device *pdev;
363 if (dev && dev->bus_id)
364 for (i=0; i<ARRAY_SIZE(dev_map); i++)
365 if (!strncmp(dev->bus_id, dev_map[i].bus_id,
368 pdev = container_of(dev,
369 struct platform_device, dev);
370 dev_map[i].rtn(pdev);
378 cpci690_reset_board(void)
383 out_8((u8 *)(cpci690_br_base + CPCI690_BR_SW_RESET), 0x11);
386 panic("restart failed\n");
390 cpci690_restart(char *cmd)
392 cpci690_reset_board();
403 cpci690_power_off(void)
410 cpci690_show_cpuinfo(struct seq_file *m)
412 seq_printf(m, "vendor\t\t: " BOARD_VENDOR "\n");
413 seq_printf(m, "machine\t\t: " BOARD_MACHINE "\n");
414 seq_printf(m, "cpu MHz\t\t: %d\n", cpci690_get_cpu_speed()/1000/1000);
415 seq_printf(m, "bus MHz\t\t: %d\n", cpci690_get_bus_speed()/1000/1000);
421 cpci690_calibrate_decr(void)
425 freq = cpci690_get_bus_speed()/4;
427 printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
428 freq/1000000, freq%1000000);
430 tb_ticks_per_jiffy = freq / HZ;
431 tb_to_us = mulhwu_scale_factor(freq, 1000000);
436 static __inline__ void
437 cpci690_set_bat(u32 addr, u32 size)
441 size = ((size >> 17) - 1) << 2;
444 mtspr(DBAT1U, addr | size | 0x2); /* Vs == 1; Vp == 0 */
445 mtspr(DBAT1L, addr | 0x2a); /* WIMG bits == 0101; PP == r/w access */
451 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
455 io_block_mapping(CONFIG_MV64X60_NEW_BASE, CONFIG_MV64X60_NEW_BASE,
461 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
462 unsigned long r6, unsigned long r7)
464 #ifdef CONFIG_BLK_DEV_INITRD
465 initrd_start=initrd_end=0;
466 initrd_below_start_ok=0;
467 #endif /* CONFIG_BLK_DEV_INITRD */
469 parse_bootinfo(find_bootinfo());
471 loops_per_jiffy = cpci690_get_cpu_speed() / HZ;
475 ppc_md.setup_arch = cpci690_setup_arch;
476 ppc_md.show_cpuinfo = cpci690_show_cpuinfo;
477 ppc_md.init_IRQ = gt64260_init_irq;
478 ppc_md.get_irq = gt64260_get_irq;
479 ppc_md.restart = cpci690_restart;
480 ppc_md.power_off = cpci690_power_off;
481 ppc_md.halt = cpci690_halt;
482 ppc_md.find_end_of_memory = cpci690_find_end_of_memory;
483 ppc_md.time_init = todc_time_init;
484 ppc_md.set_rtc_time = todc_set_rtc_time;
485 ppc_md.get_rtc_time = todc_get_rtc_time;
486 ppc_md.nvram_read_val = todc_direct_read_val;
487 ppc_md.nvram_write_val = todc_direct_write_val;
488 ppc_md.calibrate_decr = cpci690_calibrate_decr;
491 * Need to map in board regs (used by cpci690_find_end_of_memory())
492 * and the bridge's regs (used by progress);
494 cpci690_set_bat(CPCI690_BR_BASE, 32 * MB);
495 cpci690_br_base = CPCI690_BR_BASE;
497 #ifdef CONFIG_SERIAL_TEXT_DEBUG
498 ppc_md.setup_io_mappings = cpci690_map_io;
499 ppc_md.progress = mv64x60_mpsc_progress;
500 mv64x60_progress_init(CONFIG_MV64X60_NEW_BASE);
501 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
503 ppc_md.setup_io_mappings = cpci690_map_io;
504 ppc_md.early_serial_map = cpci690_early_serial_map;
505 #endif /* CONFIG_KGDB */
507 #if defined(CONFIG_SERIAL_MPSC)
508 platform_notify = cpci690_platform_notify;