Merge ../linux-2.6
[pandora-kernel.git] / arch / ppc / platforms / prpmc750.c
1 /*
2  * Board setup routines for Motorola PrPMC750
3  *
4  * Author: Matt Porter <mporter@mvista.com>
5  *
6  * 2001-2004 (c) MontaVista, Software, Inc.  This file is licensed under
7  * the terms of the GNU General Public License version 2.  This program
8  * is licensed "as is" without any warranty of any kind, whether express
9  * or implied.
10  */
11
12 #include <linux/config.h>
13 #include <linux/stddef.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/errno.h>
17 #include <linux/reboot.h>
18 #include <linux/pci.h>
19 #include <linux/kdev_t.h>
20 #include <linux/types.h>
21 #include <linux/major.h>
22 #include <linux/initrd.h>
23 #include <linux/console.h>
24 #include <linux/delay.h>
25 #include <linux/seq_file.h>
26 #include <linux/ide.h>
27 #include <linux/root_dev.h>
28 #include <linux/slab.h>
29 #include <linux/serial_reg.h>
30
31 #include <asm/byteorder.h>
32 #include <asm/system.h>
33 #include <asm/pgtable.h>
34 #include <asm/page.h>
35 #include <asm/dma.h>
36 #include <asm/io.h>
37 #include <asm/irq.h>
38 #include <asm/machdep.h>
39 #include <asm/pci-bridge.h>
40 #include <asm/uaccess.h>
41 #include <asm/time.h>
42 #include <asm/open_pic.h>
43 #include <asm/bootinfo.h>
44 #include <asm/hawk.h>
45
46 #include "prpmc750.h"
47
48 extern unsigned long loops_per_jiffy;
49
50 extern void gen550_progress(char *, unsigned short);
51
52 static u_char prpmc750_openpic_initsenses[] __initdata =
53 {
54     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_HOSTINT0 */
55     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_UART */
56     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_DEBUGINT */
57     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_HAWK_WDT */
58     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_UNUSED */
59     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_ABORT */
60     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_HOSTINT1 */
61     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_HOSTINT2 */
62     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_HOSTINT3 */
63     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_PMC_INTA */
64     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_PMC_INTB */
65     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_PMC_INTC */
66     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_PMC_INTD */
67     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_UNUSED */
68     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_UNUSED */
69     (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),  /* PRPMC750_INT_UNUSED */
70 };
71
72 /*
73  * Motorola PrPMC750/PrPMC800 in PrPMCBASE or PrPMC-Carrier
74  * Combined irq tables.  Only Base has IDSEL 14, only Carrier has 21 and 22.
75  */
76 static inline int
77 prpmc_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
78 {
79         static char pci_irq_table[][4] =
80         /*
81          *      PCI IDSEL/INTPIN->INTLINE
82          *      A       B       C       D
83          */
84         {
85                 {12,    0,      0,      0},  /* IDSEL 14 - Ethernet, base */
86                 {0,     0,      0,      0},  /* IDSEL 15 - unused */
87                 {10,    11,     12,     9},  /* IDSEL 16 - PMC A1, PMC1 */
88                 {10,    11,     12,     9},  /* IDSEL 17 - PrPMC-A-B, PMC2-B */
89                 {11,    12,     9,      10}, /* IDSEL 18 - PMC A1-B, PMC1-B */
90                 {0,     0,      0,      0},  /* IDSEL 19 - unused */
91                 {9,     10,     11,     12}, /* IDSEL 20 - P2P Bridge */
92                 {11,    12,     9,      10}, /* IDSEL 21 - PMC A2, carrier */
93                 {12,    9,      10,     11}, /* IDSEL 22 - PMC A2-B, carrier */
94         };
95         const long min_idsel = 14, max_idsel = 22, irqs_per_slot = 4;
96         return PCI_IRQ_TABLE_LOOKUP;
97 };
98
99 static void __init prpmc750_pcibios_fixup(void)
100 {
101         struct pci_dev *dev;
102         unsigned short wtmp;
103
104         /*
105          * Kludge to clean up after PPC6BUG which doesn't
106          * configure the CL5446 VGA card.  Also the
107          * resource subsystem doesn't fixup the
108          * PCI mem resources on the CL5446.
109          */
110         if ((dev = pci_get_device(PCI_VENDOR_ID_CIRRUS,
111                                    PCI_DEVICE_ID_CIRRUS_5446, 0))) {
112                 dev->resource[0].start += PRPMC750_PCI_PHY_MEM_OFFSET;
113                 dev->resource[0].end += PRPMC750_PCI_PHY_MEM_OFFSET;
114                 pci_read_config_word(dev, PCI_COMMAND, &wtmp);
115                 pci_write_config_word(dev, PCI_COMMAND, wtmp | 3);
116                 /* Enable Color mode in MISC reg */
117                 outb(0x03, 0x3c2);
118                 /* Select DRAM config reg */
119                 outb(0x0f, 0x3c4);
120                 /* Set proper DRAM config */
121                 outb(0xdf, 0x3c5);
122                 pci_dev_put(dev);
123         }
124 }
125
126 void __init prpmc750_find_bridges(void)
127 {
128         struct pci_controller *hose;
129
130         hose = pcibios_alloc_controller();
131         if (!hose)
132                 return;
133
134         hose->first_busno = 0;
135         hose->last_busno = 0xff;
136         hose->io_base_virt = (void *)PRPMC750_ISA_IO_BASE;
137         hose->pci_mem_offset = PRPMC750_PCI_PHY_MEM_OFFSET;
138
139         pci_init_resource(&hose->io_resource,
140                           PRPMC750_PCI_IO_START,
141                           PRPMC750_PCI_IO_END,
142                           IORESOURCE_IO, "PCI host bridge");
143
144         pci_init_resource(&hose->mem_resources[0],
145                           PRPMC750_PROC_PCI_MEM_START,
146                           PRPMC750_PROC_PCI_MEM_END,
147                           IORESOURCE_MEM, "PCI host bridge");
148
149         hose->io_space.start = PRPMC750_PCI_IO_START;
150         hose->io_space.end = PRPMC750_PCI_IO_END;
151         hose->mem_space.start = PRPMC750_PCI_MEM_START;
152         hose->mem_space.end = PRPMC750_PCI_MEM_END - HAWK_MPIC_SIZE;
153
154         if (hawk_init(hose, PRPMC750_HAWK_PPC_REG_BASE,
155                       PRPMC750_PROC_PCI_MEM_START,
156                       PRPMC750_PROC_PCI_MEM_END - HAWK_MPIC_SIZE,
157                       PRPMC750_PROC_PCI_IO_START, PRPMC750_PROC_PCI_IO_END,
158                       PRPMC750_PROC_PCI_MEM_END - HAWK_MPIC_SIZE + 1)
159             != 0) {
160                 printk(KERN_CRIT "Could not initialize host bridge\n");
161         }
162
163         hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
164
165         ppc_md.pcibios_fixup = prpmc750_pcibios_fixup;
166         ppc_md.pci_swizzle = common_swizzle;
167         ppc_md.pci_map_irq = prpmc_map_irq;
168 }
169 static int prpmc750_show_cpuinfo(struct seq_file *m)
170 {
171         seq_printf(m, "machine\t\t: PrPMC750\n");
172
173         return 0;
174 }
175
176 static void __init prpmc750_setup_arch(void)
177 {
178         /* init to some ~sane value until calibrate_delay() runs */
179         loops_per_jiffy = 50000000 / HZ;
180
181         /* Lookup PCI host bridges */
182         prpmc750_find_bridges();
183
184 #ifdef CONFIG_BLK_DEV_INITRD
185         if (initrd_start)
186                 ROOT_DEV = Root_RAM0;
187         else
188 #endif
189 #ifdef CONFIG_ROOT_NFS
190                 ROOT_DEV = Root_NFS;
191 #else
192                 ROOT_DEV = Root_SDA2;
193 #endif
194
195         OpenPIC_InitSenses = prpmc750_openpic_initsenses;
196         OpenPIC_NumInitSenses = sizeof(prpmc750_openpic_initsenses);
197
198         printk(KERN_INFO "Port by MontaVista Software, Inc. "
199                         "(source@mvista.com)\n");
200 }
201
202 /*
203  * Compute the PrPMC750's bus speed using the baud clock as a
204  * reference.
205  */
206 static unsigned long __init prpmc750_get_bus_speed(void)
207 {
208         unsigned long tbl_start, tbl_end;
209         unsigned long current_state, old_state, bus_speed;
210         unsigned char lcr, dll, dlm;
211         int baud_divisor, count;
212
213         /* Read the UART's baud clock divisor */
214         lcr = readb(PRPMC750_SERIAL_0_LCR);
215         writeb(lcr | UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
216         dll = readb(PRPMC750_SERIAL_0_DLL);
217         dlm = readb(PRPMC750_SERIAL_0_DLM);
218         writeb(lcr & ~UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
219         baud_divisor = (dlm << 8) | dll;
220
221         /*
222          * Use the baud clock divisor and base baud clock
223          * to determine the baud rate and use that as
224          * the number of baud clock edges we use for
225          * the time base sample.  Make it half the baud
226          * rate.
227          */
228         count = PRPMC750_BASE_BAUD / (baud_divisor * 16);
229
230         /* Find the first edge of the baud clock */
231         old_state = readb(PRPMC750_STATUS_REG) & PRPMC750_BAUDOUT_MASK;
232         do {
233                 current_state = readb(PRPMC750_STATUS_REG) &
234                     PRPMC750_BAUDOUT_MASK;
235         } while (old_state == current_state);
236
237         old_state = current_state;
238
239         /* Get the starting time base value */
240         tbl_start = get_tbl();
241
242         /*
243          * Loop until we have found a number of edges equal
244          * to half the count (half the baud rate)
245          */
246         do {
247                 do {
248                         current_state = readb(PRPMC750_STATUS_REG) &
249                             PRPMC750_BAUDOUT_MASK;
250                 } while (old_state == current_state);
251                 old_state = current_state;
252         } while (--count);
253
254         /* Get the ending time base value */
255         tbl_end = get_tbl();
256
257         /* Compute bus speed */
258         bus_speed = (tbl_end - tbl_start) * 128;
259
260         return bus_speed;
261 }
262
263 static void __init prpmc750_calibrate_decr(void)
264 {
265         unsigned long freq;
266         int divisor = 4;
267
268         freq = prpmc750_get_bus_speed();
269
270         tb_ticks_per_jiffy = freq / (HZ * divisor);
271         tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
272 }
273
274 static void prpmc750_restart(char *cmd)
275 {
276         local_irq_disable();
277         writeb(PRPMC750_MODRST_MASK, PRPMC750_MODRST_REG);
278         while (1) ;
279 }
280
281 static void prpmc750_halt(void)
282 {
283         local_irq_disable();
284         while (1) ;
285 }
286
287 static void prpmc750_power_off(void)
288 {
289         prpmc750_halt();
290 }
291
292 static void __init prpmc750_init_IRQ(void)
293 {
294         openpic_init(0);
295 }
296
297 /*
298  * Set BAT 3 to map 0xf0000000 to end of physical memory space.
299  */
300 static __inline__ void prpmc750_set_bat(void)
301 {
302         mb();
303         mtspr(SPRN_DBAT1U, 0xf0001ffe);
304         mtspr(SPRN_DBAT1L, 0xf000002a);
305         mb();
306 }
307
308 /*
309  * We need to read the Falcon/Hawk memory controller
310  * to properly determine this value
311  */
312 static unsigned long __init prpmc750_find_end_of_memory(void)
313 {
314         /* Read the memory size from the Hawk SMC */
315         return hawk_get_mem_size(PRPMC750_HAWK_SMC_BASE);
316 }
317
318 static void __init prpmc750_map_io(void)
319 {
320         io_block_mapping(PRPMC750_ISA_IO_BASE, PRPMC750_ISA_IO_BASE,
321                          0x10000000, _PAGE_IO);
322 #if 0
323         io_block_mapping(0xf0000000, 0xc0000000, 0x08000000, _PAGE_IO);
324 #endif
325         io_block_mapping(0xf8000000, 0xf8000000, 0x08000000, _PAGE_IO);
326 }
327
328 void __init
329 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
330               unsigned long r6, unsigned long r7)
331 {
332         parse_bootinfo(find_bootinfo());
333
334         /* Cover the Hawk registers with a BAT */
335         prpmc750_set_bat();
336
337         isa_io_base = PRPMC750_ISA_IO_BASE;
338         isa_mem_base = PRPMC750_ISA_MEM_BASE;
339         pci_dram_offset = PRPMC750_PCI_DRAM_OFFSET;
340
341         ppc_md.setup_arch = prpmc750_setup_arch;
342         ppc_md.show_cpuinfo = prpmc750_show_cpuinfo;
343         ppc_md.init_IRQ = prpmc750_init_IRQ;
344         ppc_md.get_irq = openpic_get_irq;
345
346         ppc_md.find_end_of_memory = prpmc750_find_end_of_memory;
347         ppc_md.setup_io_mappings = prpmc750_map_io;
348
349         ppc_md.restart = prpmc750_restart;
350         ppc_md.power_off = prpmc750_power_off;
351         ppc_md.halt = prpmc750_halt;
352
353         /* PrPMC750 has no timekeeper part */
354         ppc_md.time_init = NULL;
355         ppc_md.get_rtc_time = NULL;
356         ppc_md.set_rtc_time = NULL;
357         ppc_md.calibrate_decr = prpmc750_calibrate_decr;
358
359 #ifdef  CONFIG_SERIAL_TEXT_DEBUG
360         ppc_md.progress = gen550_progress;
361 #endif                          /* CONFIG_SERIAL_TEXT_DEBUG */
362 }