]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/ppc/platforms/cpci690.c
Merge Paulus' tree
[karo-tx-linux.git] / arch / ppc / platforms / cpci690.c
1 /*
2  * arch/ppc/platforms/cpci690.c
3  *
4  * Board setup routines for the Force CPCI690 board.
5  *
6  * Author: Mark A. Greer <mgreer@mvista.com>
7  *
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
11  * or implied.
12  */
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>
18 #include <linux/fs.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 <linux/platform_device.h>
25 #include <asm/bootinfo.h>
26 #include <asm/machdep.h>
27 #include <asm/todc.h>
28 #include <asm/time.h>
29 #include <asm/mv64x60.h>
30 #include <platforms/cpci690.h>
31
32 #define BOARD_VENDOR    "Force"
33 #define BOARD_MACHINE   "CPCI690"
34
35 /* Set IDE controllers into Native mode? */
36 #define SET_PCI_IDE_NATIVE
37
38 static struct mv64x60_handle    bh;
39 static void __iomem *cpci690_br_base;
40
41 TODC_ALLOC();
42
43 static int __init
44 cpci690_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
45 {
46         struct pci_controller   *hose = pci_bus_to_hose(dev->bus->number);
47
48         if (hose->index == 0) {
49                 static char pci_irq_table[][4] =
50                 /*
51                  *      PCI IDSEL/INTPIN->INTLINE
52                  *         A   B   C   D
53                  */
54                 {
55                         { 90, 91, 88, 89 }, /* IDSEL 30/20 - Sentinel */
56                 };
57
58                 const long min_idsel = 20, max_idsel = 20, irqs_per_slot = 4;
59                 return PCI_IRQ_TABLE_LOOKUP;
60         } else {
61                 static char pci_irq_table[][4] =
62                 /*
63                  *      PCI IDSEL/INTPIN->INTLINE
64                  *         A   B   C   D
65                  */
66                 {
67                         { 93, 94, 95, 92 }, /* IDSEL 28/18 - PMC slot 2 */
68                         {  0,  0,  0,  0 }, /* IDSEL 29/19 - Not used */
69                         { 94, 95, 92, 93 }, /* IDSEL 30/20 - PMC slot 1 */
70                 };
71
72                 const long min_idsel = 18, max_idsel = 20, irqs_per_slot = 4;
73                 return PCI_IRQ_TABLE_LOOKUP;
74         }
75 }
76
77 #define GB      (1024UL * 1024UL * 1024UL)
78
79 static u32
80 cpci690_get_bus_freq(void)
81 {
82         if (boot_mem_size >= (1*GB)) /* bus speed based on mem size */
83                 return 100000000;
84         else
85                 return 133333333;
86 }
87
88 static const unsigned int cpu_750xx[32] = { /* 750FX & 750GX */
89          0,  0,  2,  2,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,/* 0-15*/
90         16, 17, 18, 19, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40,  0 /*16-31*/
91 };
92
93 static int
94 cpci690_get_cpu_freq(void)
95 {
96         unsigned long   pll_cfg;
97
98         pll_cfg = (mfspr(SPRN_HID1) & 0xf8000000) >> 27;
99         return cpci690_get_bus_freq() * cpu_750xx[pll_cfg]/2;
100 }
101
102 static void __init
103 cpci690_setup_bridge(void)
104 {
105         struct mv64x60_setup_info       si;
106         int                             i;
107
108         memset(&si, 0, sizeof(si));
109
110         si.phys_reg_base = CONFIG_MV64X60_NEW_BASE;
111
112         si.pci_0.enable_bus = 1;
113         si.pci_0.pci_io.cpu_base = CPCI690_PCI0_IO_START_PROC_ADDR;
114         si.pci_0.pci_io.pci_base_hi = 0;
115         si.pci_0.pci_io.pci_base_lo = CPCI690_PCI0_IO_START_PCI_ADDR;
116         si.pci_0.pci_io.size = CPCI690_PCI0_IO_SIZE;
117         si.pci_0.pci_io.swap = MV64x60_CPU2PCI_SWAP_NONE;
118         si.pci_0.pci_mem[0].cpu_base = CPCI690_PCI0_MEM_START_PROC_ADDR;
119         si.pci_0.pci_mem[0].pci_base_hi = CPCI690_PCI0_MEM_START_PCI_HI_ADDR;
120         si.pci_0.pci_mem[0].pci_base_lo = CPCI690_PCI0_MEM_START_PCI_LO_ADDR;
121         si.pci_0.pci_mem[0].size = CPCI690_PCI0_MEM_SIZE;
122         si.pci_0.pci_mem[0].swap = MV64x60_CPU2PCI_SWAP_NONE;
123         si.pci_0.pci_cmd_bits = 0;
124         si.pci_0.latency_timer = 0x80;
125
126         si.pci_1.enable_bus = 1;
127         si.pci_1.pci_io.cpu_base = CPCI690_PCI1_IO_START_PROC_ADDR;
128         si.pci_1.pci_io.pci_base_hi = 0;
129         si.pci_1.pci_io.pci_base_lo = CPCI690_PCI1_IO_START_PCI_ADDR;
130         si.pci_1.pci_io.size = CPCI690_PCI1_IO_SIZE;
131         si.pci_1.pci_io.swap = MV64x60_CPU2PCI_SWAP_NONE;
132         si.pci_1.pci_mem[0].cpu_base = CPCI690_PCI1_MEM_START_PROC_ADDR;
133         si.pci_1.pci_mem[0].pci_base_hi = CPCI690_PCI1_MEM_START_PCI_HI_ADDR;
134         si.pci_1.pci_mem[0].pci_base_lo = CPCI690_PCI1_MEM_START_PCI_LO_ADDR;
135         si.pci_1.pci_mem[0].size = CPCI690_PCI1_MEM_SIZE;
136         si.pci_1.pci_mem[0].swap = MV64x60_CPU2PCI_SWAP_NONE;
137         si.pci_1.pci_cmd_bits = 0;
138         si.pci_1.latency_timer = 0x80;
139
140         for (i=0; i<MV64x60_CPU2MEM_WINDOWS; i++) {
141                 si.cpu_prot_options[i] = 0;
142                 si.cpu_snoop_options[i] = GT64260_CPU_SNOOP_WB;
143                 si.pci_0.acc_cntl_options[i] =
144                         GT64260_PCI_ACC_CNTL_DREADEN |
145                         GT64260_PCI_ACC_CNTL_RDPREFETCH |
146                         GT64260_PCI_ACC_CNTL_RDLINEPREFETCH |
147                         GT64260_PCI_ACC_CNTL_RDMULPREFETCH |
148                         GT64260_PCI_ACC_CNTL_SWAP_NONE |
149                         GT64260_PCI_ACC_CNTL_MBURST_32_BTYES;
150                 si.pci_0.snoop_options[i] = GT64260_PCI_SNOOP_WB;
151                 si.pci_1.acc_cntl_options[i] =
152                         GT64260_PCI_ACC_CNTL_DREADEN |
153                         GT64260_PCI_ACC_CNTL_RDPREFETCH |
154                         GT64260_PCI_ACC_CNTL_RDLINEPREFETCH |
155                         GT64260_PCI_ACC_CNTL_RDMULPREFETCH |
156                         GT64260_PCI_ACC_CNTL_SWAP_NONE |
157                         GT64260_PCI_ACC_CNTL_MBURST_32_BTYES;
158                 si.pci_1.snoop_options[i] = GT64260_PCI_SNOOP_WB;
159         }
160
161         /* Lookup PCI host bridges */
162         if (mv64x60_init(&bh, &si))
163                 printk(KERN_ERR "Bridge initialization failed.\n");
164
165         pci_dram_offset = 0; /* System mem at same addr on PCI & cpu bus */
166         ppc_md.pci_swizzle = common_swizzle;
167         ppc_md.pci_map_irq = cpci690_map_irq;
168         ppc_md.pci_exclude_device = mv64x60_pci_exclude_device;
169
170         mv64x60_set_bus(&bh, 0, 0);
171         bh.hose_a->first_busno = 0;
172         bh.hose_a->last_busno = 0xff;
173         bh.hose_a->last_busno = pciauto_bus_scan(bh.hose_a, 0);
174
175         bh.hose_b->first_busno = bh.hose_a->last_busno + 1;
176         mv64x60_set_bus(&bh, 1, bh.hose_b->first_busno);
177         bh.hose_b->last_busno = 0xff;
178         bh.hose_b->last_busno = pciauto_bus_scan(bh.hose_b,
179                 bh.hose_b->first_busno);
180 }
181
182 static void __init
183 cpci690_setup_peripherals(void)
184 {
185         /* Set up windows to CPLD, RTC/TODC, IPMI. */
186         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_0_WIN, CPCI690_BR_BASE,
187                 CPCI690_BR_SIZE, 0);
188         bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_0_WIN);
189         cpci690_br_base = ioremap(CPCI690_BR_BASE, CPCI690_BR_SIZE);
190
191         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_1_WIN, CPCI690_TODC_BASE,
192                 CPCI690_TODC_SIZE, 0);
193         bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_1_WIN);
194         TODC_INIT(TODC_TYPE_MK48T35, 0, 0,
195                         ioremap(CPCI690_TODC_BASE, CPCI690_TODC_SIZE), 8);
196
197         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_2_WIN, CPCI690_IPMI_BASE,
198                 CPCI690_IPMI_SIZE, 0);
199         bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_2_WIN);
200
201         mv64x60_set_bits(&bh, MV64x60_PCI0_ARBITER_CNTL, (1<<31));
202         mv64x60_set_bits(&bh, MV64x60_PCI1_ARBITER_CNTL, (1<<31));
203
204         mv64x60_set_bits(&bh, MV64x60_CPU_MASTER_CNTL, (1<<9)); /* Only 1 cpu */
205
206         /*
207          * Turn off timer/counters.  Not turning off watchdog timer because
208          * can't read its reg on the 64260A so don't know if we'll be enabling
209          * or disabling.
210          */
211         mv64x60_clr_bits(&bh, MV64x60_TIMR_CNTR_0_3_CNTL,
212                         ((1<<0) | (1<<8) | (1<<16) | (1<<24)));
213         mv64x60_clr_bits(&bh, GT64260_TIMR_CNTR_4_7_CNTL,
214                         ((1<<0) | (1<<8) | (1<<16) | (1<<24)));
215
216         /*
217          * Set MPSC Multiplex RMII
218          * NOTE: ethernet driver modifies bit 0 and 1
219          */
220         mv64x60_write(&bh, GT64260_MPP_SERIAL_PORTS_MULTIPLEX, 0x00001102);
221
222 #define GPP_EXTERNAL_INTERRUPTS \
223                 ((1<<24) | (1<<25) | (1<<26) | (1<<27) | \
224                  (1<<28) | (1<<29) | (1<<30) | (1<<31))
225         /* PCI interrupts are inputs */
226         mv64x60_clr_bits(&bh, MV64x60_GPP_IO_CNTL, GPP_EXTERNAL_INTERRUPTS);
227         /* PCI interrupts are active low */
228         mv64x60_set_bits(&bh, MV64x60_GPP_LEVEL_CNTL, GPP_EXTERNAL_INTERRUPTS);
229
230         /* Clear any pending interrupts for these inputs and enable them. */
231         mv64x60_write(&bh, MV64x60_GPP_INTR_CAUSE, ~GPP_EXTERNAL_INTERRUPTS);
232         mv64x60_set_bits(&bh, MV64x60_GPP_INTR_MASK, GPP_EXTERNAL_INTERRUPTS);
233
234         /* Route MPP interrupt inputs to GPP */
235         mv64x60_write(&bh, MV64x60_MPP_CNTL_2, 0x00000000);
236         mv64x60_write(&bh, MV64x60_MPP_CNTL_3, 0x00000000);
237 }
238
239 static void __init
240 cpci690_setup_arch(void)
241 {
242         if (ppc_md.progress)
243                 ppc_md.progress("cpci690_setup_arch: enter", 0);
244 #ifdef CONFIG_BLK_DEV_INITRD
245         if (initrd_start)
246                 ROOT_DEV = Root_RAM0;
247         else
248 #endif
249 #ifdef   CONFIG_ROOT_NFS
250                 ROOT_DEV = Root_NFS;
251 #else
252                 ROOT_DEV = Root_SDA2;
253 #endif
254
255         if (ppc_md.progress)
256                 ppc_md.progress("cpci690_setup_arch: Enabling L2 cache", 0);
257
258         /* Enable L2 and L3 caches (if 745x) */
259         _set_L2CR(_get_L2CR() | L2CR_L2E);
260         _set_L3CR(_get_L3CR() | L3CR_L3E);
261
262         if (ppc_md.progress)
263                 ppc_md.progress("cpci690_setup_arch: Initializing bridge", 0);
264
265         cpci690_setup_bridge();         /* set up PCI bridge(s) */
266         cpci690_setup_peripherals();    /* set up chip selects/GPP/MPP etc */
267
268         if (ppc_md.progress)
269                 ppc_md.progress("cpci690_setup_arch: bridge init complete", 0);
270
271         printk(KERN_INFO "%s %s port (C) 2003 MontaVista Software, Inc. "
272                 "(source@mvista.com)\n", BOARD_VENDOR, BOARD_MACHINE);
273
274         if (ppc_md.progress)
275                 ppc_md.progress("cpci690_setup_arch: exit", 0);
276 }
277
278 /* Platform device data fixup routines. */
279 #if defined(CONFIG_SERIAL_MPSC)
280 static void __init
281 cpci690_fixup_mpsc_pdata(struct platform_device *pdev)
282 {
283         struct mpsc_pdata *pdata;
284
285         pdata = (struct mpsc_pdata *)pdev->dev.platform_data;
286
287         pdata->max_idle = 40;
288         pdata->default_baud = CPCI690_MPSC_BAUD;
289         pdata->brg_clk_src = CPCI690_MPSC_CLK_SRC;
290         pdata->brg_clk_freq = cpci690_get_bus_freq();
291 }
292
293 static int __init
294 cpci690_platform_notify(struct device *dev)
295 {
296         static struct {
297                 char    *bus_id;
298                 void    ((*rtn)(struct platform_device *pdev));
299         } dev_map[] = {
300                 { MPSC_CTLR_NAME ".0", cpci690_fixup_mpsc_pdata },
301                 { MPSC_CTLR_NAME ".1", cpci690_fixup_mpsc_pdata },
302         };
303         struct platform_device  *pdev;
304         int     i;
305
306         if (dev && dev->bus_id)
307                 for (i=0; i<ARRAY_SIZE(dev_map); i++)
308                         if (!strncmp(dev->bus_id, dev_map[i].bus_id,
309                                 BUS_ID_SIZE)) {
310
311                                 pdev = container_of(dev,
312                                         struct platform_device, dev);
313                                 dev_map[i].rtn(pdev);
314                         }
315
316         return 0;
317 }
318 #endif
319
320 static void
321 cpci690_reset_board(void)
322 {
323         u32     i = 10000;
324
325         local_irq_disable();
326         out_8((cpci690_br_base + CPCI690_BR_SW_RESET), 0x11);
327
328         while (i != 0) i++;
329         panic("restart failed\n");
330 }
331
332 static void
333 cpci690_restart(char *cmd)
334 {
335         cpci690_reset_board();
336 }
337
338 static void
339 cpci690_halt(void)
340 {
341         while (1);
342         /* NOTREACHED */
343 }
344
345 static void
346 cpci690_power_off(void)
347 {
348         cpci690_halt();
349         /* NOTREACHED */
350 }
351
352 static int
353 cpci690_show_cpuinfo(struct seq_file *m)
354 {
355         char    *s;
356
357         seq_printf(m, "cpu MHz\t\t: %d\n",
358                 (cpci690_get_cpu_freq() + 500000) / 1000000);
359         seq_printf(m, "bus MHz\t\t: %d\n",
360                 (cpci690_get_bus_freq() + 500000) / 1000000);
361         seq_printf(m, "vendor\t\t: " BOARD_VENDOR "\n");
362         seq_printf(m, "machine\t\t: " BOARD_MACHINE "\n");
363         seq_printf(m, "FPGA Revision\t: %d\n",
364                 in_8(cpci690_br_base + CPCI690_BR_MEM_CTLR) >> 5);
365
366         switch(bh.type) {
367         case MV64x60_TYPE_GT64260A:
368                 s = "gt64260a";
369                 break;
370         case MV64x60_TYPE_GT64260B:
371                 s = "gt64260b";
372                 break;
373         case MV64x60_TYPE_MV64360:
374                 s = "mv64360";
375                 break;
376         case MV64x60_TYPE_MV64460:
377                 s = "mv64460";
378                 break;
379         default:
380                 s = "Unknown";
381         }
382         seq_printf(m, "bridge type\t: %s\n", s);
383         seq_printf(m, "bridge rev\t: 0x%x\n", bh.rev);
384 #if defined(CONFIG_NOT_COHERENT_CACHE)
385         seq_printf(m, "coherency\t: %s\n", "off");
386 #else
387         seq_printf(m, "coherency\t: %s\n", "on");
388 #endif
389
390         return 0;
391 }
392
393 static void __init
394 cpci690_calibrate_decr(void)
395 {
396         ulong freq;
397
398         freq = cpci690_get_bus_freq() / 4;
399
400         printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
401                freq/1000000, freq%1000000);
402
403         tb_ticks_per_jiffy = freq / HZ;
404         tb_to_us = mulhwu_scale_factor(freq, 1000000);
405 }
406
407 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_MPSC)
408 static void __init
409 cpci690_map_io(void)
410 {
411         io_block_mapping(CONFIG_MV64X60_NEW_BASE, CONFIG_MV64X60_NEW_BASE,
412                 128 * 1024, _PAGE_IO);
413 }
414 #endif
415
416 void __init
417 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
418               unsigned long r6, unsigned long r7)
419 {
420         parse_bootinfo(find_bootinfo());
421
422 #ifdef CONFIG_BLK_DEV_INITRD
423         /* take care of initrd if we have one */
424         if (r4) {
425                 initrd_start = r4 + KERNELBASE;
426                 initrd_end = r5 + KERNELBASE;
427         }
428 #endif /* CONFIG_BLK_DEV_INITRD */
429
430         isa_mem_base = 0;
431
432         ppc_md.setup_arch = cpci690_setup_arch;
433         ppc_md.show_cpuinfo = cpci690_show_cpuinfo;
434         ppc_md.init_IRQ = gt64260_init_irq;
435         ppc_md.get_irq = gt64260_get_irq;
436         ppc_md.restart = cpci690_restart;
437         ppc_md.power_off = cpci690_power_off;
438         ppc_md.halt = cpci690_halt;
439         ppc_md.time_init = todc_time_init;
440         ppc_md.set_rtc_time = todc_set_rtc_time;
441         ppc_md.get_rtc_time = todc_get_rtc_time;
442         ppc_md.nvram_read_val = todc_direct_read_val;
443         ppc_md.nvram_write_val = todc_direct_write_val;
444         ppc_md.calibrate_decr = cpci690_calibrate_decr;
445
446 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_MPSC)
447         ppc_md.setup_io_mappings = cpci690_map_io;
448 #ifdef CONFIG_SERIAL_TEXT_DEBUG
449         ppc_md.progress = mv64x60_mpsc_progress;
450         mv64x60_progress_init(CONFIG_MV64X60_NEW_BASE);
451 #endif  /* CONFIG_SERIAL_TEXT_DEBUG */
452 #endif  /* defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_MPSC) */
453
454 #if defined(CONFIG_SERIAL_MPSC)
455         platform_notify = cpci690_platform_notify;
456 #endif
457 }