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