2 * Common routines for the Motorola SPS MPC106, MPC107 and MPC8240 Host bridge,
5 * Author: Mark A. Greer
8 * 2001 (c) MontaVista, Software, Inc. This file is licensed under
9 * the terms of the GNU General Public License version 2. This program
10 * is licensed "as is" without any warranty of any kind, whether express
15 * *** WARNING - A BAT MUST be set to access the PCI config addr/data regs ***
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/pci.h>
21 #include <linux/slab.h>
22 #include <linux/serial_8250.h>
23 #include <linux/fsl_devices.h>
24 #include <linux/device.h>
26 #include <asm/byteorder.h>
29 #include <asm/uaccess.h>
30 #include <asm/machdep.h>
31 #include <asm/pci-bridge.h>
32 #include <asm/open_pic.h>
33 #include <asm/mpc10x.h>
34 #include <asm/ppc_sys.h>
36 #ifdef CONFIG_MPC10X_OPENPIC
37 #ifdef CONFIG_EPIC_SERIAL_MODE
38 #define EPIC_IRQ_BASE (epic_serial_mode ? 16 : 5)
40 #define EPIC_IRQ_BASE 5
42 #define MPC10X_I2C_IRQ (EPIC_IRQ_BASE + NUM_8259_INTERRUPTS)
43 #define MPC10X_DMA0_IRQ (EPIC_IRQ_BASE + 1 + NUM_8259_INTERRUPTS)
44 #define MPC10X_DMA1_IRQ (EPIC_IRQ_BASE + 2 + NUM_8259_INTERRUPTS)
45 #define MPC10X_UART0_IRQ (EPIC_IRQ_BASE + 4 + NUM_8259_INTERRUPTS)
46 #define MPC10X_UART1_IRQ (EPIC_IRQ_BASE + 5 + NUM_8259_INTERRUPTS)
48 #define MPC10X_I2C_IRQ -1
49 #define MPC10X_DMA0_IRQ -1
50 #define MPC10X_DMA1_IRQ -1
51 #define MPC10X_UART0_IRQ -1
52 #define MPC10X_UART1_IRQ -1
55 static struct fsl_i2c_platform_data mpc10x_i2c_pdata = {
59 static struct plat_serial8250_port serial_plat_uart0[] = {
63 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
67 static struct plat_serial8250_port serial_plat_uart1[] = {
71 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
76 struct platform_device ppc_sys_platform_devices[] = {
80 .dev.platform_data = &mpc10x_i2c_pdata,
82 .resource = (struct resource[]) {
84 .start = MPC10X_EUMB_I2C_OFFSET,
85 .end = MPC10X_EUMB_I2C_OFFSET +
86 MPC10X_EUMB_I2C_SIZE - 1,
87 .flags = IORESOURCE_MEM,
90 .flags = IORESOURCE_IRQ
98 .resource = (struct resource[]) {
100 .start = MPC10X_EUMB_DMA_OFFSET + 0x10,
101 .end = MPC10X_EUMB_DMA_OFFSET + 0x1f,
102 .flags = IORESOURCE_MEM,
105 .flags = IORESOURCE_IRQ,
113 .resource = (struct resource[]) {
115 .start = MPC10X_EUMB_DMA_OFFSET + 0x20,
116 .end = MPC10X_EUMB_DMA_OFFSET + 0x2f,
117 .flags = IORESOURCE_MEM,
120 .flags = IORESOURCE_IRQ,
128 .resource = (struct resource[]) {
130 .start = MPC10X_EUMB_DMA_OFFSET + 0x20,
131 .end = MPC10X_EUMB_DMA_OFFSET + 0x2f,
132 .flags = IORESOURCE_MEM,
135 .flags = IORESOURCE_IRQ,
140 .name = "serial8250",
141 .id = PLAT8250_DEV_PLATFORM,
142 .dev.platform_data = serial_plat_uart0,
145 .name = "serial8250",
146 .id = PLAT8250_DEV_PLATFORM1,
147 .dev.platform_data = serial_plat_uart1,
152 /* We use the PCI ID to match on */
153 struct ppc_sys_spec *cur_ppc_sys_spec;
154 struct ppc_sys_spec ppc_sys_specs[] = {
156 .ppc_sys_name = "8245",
158 .value = MPC10X_BRIDGE_8245,
160 .device_list = (enum ppc_sys_devices[])
162 MPC10X_IIC1, MPC10X_DMA0, MPC10X_DMA1, MPC10X_UART0, MPC10X_UART1,
166 .ppc_sys_name = "8240",
168 .value = MPC10X_BRIDGE_8240,
170 .device_list = (enum ppc_sys_devices[])
172 MPC10X_IIC1, MPC10X_DMA0, MPC10X_DMA1,
176 .ppc_sys_name = "107",
178 .value = MPC10X_BRIDGE_107,
180 .device_list = (enum ppc_sys_devices[])
182 MPC10X_IIC1, MPC10X_DMA0, MPC10X_DMA1,
185 { /* default match */
193 * mach_mpc10x_fixup: This function enables DUART mode if it detects
194 * if it detects two UARTS in the platform device entries.
196 static int __init mach_mpc10x_fixup(struct platform_device *pdev)
198 if (strncmp (pdev->name, "serial8250", 10) == 0 && pdev->id == 1)
199 writeb(readb(serial_plat_uart1[0].membase + 0x11) | 0x1,
200 serial_plat_uart1[0].membase + 0x11);
204 static int __init mach_mpc10x_init(void)
206 ppc_sys_device_fixup = mach_mpc10x_fixup;
209 postcore_initcall(mach_mpc10x_init);
211 /* Set resources to match bridge memory map */
213 mpc10x_bridge_set_resources(int map, struct pci_controller *hose)
217 case MPC10X_MEM_MAP_A:
218 pci_init_resource(&hose->io_resource,
224 pci_init_resource (&hose->mem_resources[0],
230 case MPC10X_MEM_MAP_B:
231 pci_init_resource(&hose->io_resource,
237 pci_init_resource (&hose->mem_resources[0],
244 printk("mpc10x_bridge_set_resources: "
245 "Invalid map specified\n");
247 ppc_md.progress("mpc10x:exit1", 0x100);
252 * Do some initialization and put the EUMB registers at the specified address
253 * (also map the EPIC registers into virtual space--OpenPIC_Addr will be set).
255 * The EPIC is not on the 106, only the 8240 and 107.
258 mpc10x_bridge_init(struct pci_controller *hose,
263 int host_bridge, picr1, picr1_bit, i;
264 ulong pci_config_addr, pci_config_data;
267 if (ppc_md.progress) ppc_md.progress("mpc10x:enter", 0x100);
269 /* Set up for current map so we can get at config regs */
270 switch (current_map) {
271 case MPC10X_MEM_MAP_A:
272 setup_indirect_pci(hose,
273 MPC10X_MAPA_CNFG_ADDR,
274 MPC10X_MAPA_CNFG_DATA);
276 case MPC10X_MEM_MAP_B:
277 setup_indirect_pci(hose,
278 MPC10X_MAPB_CNFG_ADDR,
279 MPC10X_MAPB_CNFG_DATA);
282 printk("mpc10x_bridge_init: %s\n",
283 "Invalid current map specified");
285 ppc_md.progress("mpc10x:exit1", 0x100);
289 /* Make sure it's a supported bridge */
290 early_read_config_dword(hose,
296 switch (host_bridge) {
297 case MPC10X_BRIDGE_106:
298 case MPC10X_BRIDGE_8240:
299 case MPC10X_BRIDGE_107:
300 case MPC10X_BRIDGE_8245:
304 ppc_md.progress("mpc10x:exit2", 0x100);
309 case MPC10X_MEM_MAP_A:
310 MPC10X_SETUP_HOSE(hose, A);
311 pci_config_addr = MPC10X_MAPA_CNFG_ADDR;
312 pci_config_data = MPC10X_MAPA_CNFG_DATA;
313 picr1_bit = MPC10X_CFG_PICR1_ADDR_MAP_A;
315 case MPC10X_MEM_MAP_B:
316 MPC10X_SETUP_HOSE(hose, B);
317 pci_config_addr = MPC10X_MAPB_CNFG_ADDR;
318 pci_config_data = MPC10X_MAPB_CNFG_DATA;
319 picr1_bit = MPC10X_CFG_PICR1_ADDR_MAP_B;
322 printk("mpc10x_bridge_init: %s\n",
323 "Invalid new map specified");
325 ppc_md.progress("mpc10x:exit3", 0x100);
329 /* Make bridge use the 'new_map', if not already usng it */
330 if (current_map != new_map) {
331 early_read_config_dword(hose,
334 MPC10X_CFG_PICR1_REG,
337 picr1 = (picr1 & ~MPC10X_CFG_PICR1_ADDR_MAP_MASK) |
340 early_write_config_dword(hose,
343 MPC10X_CFG_PICR1_REG,
346 asm volatile("sync");
348 /* Undo old mappings & map in new cfg data/addr regs */
349 iounmap((void *)hose->cfg_addr);
350 iounmap((void *)hose->cfg_data);
352 setup_indirect_pci(hose,
357 /* Setup resources to match map */
358 mpc10x_bridge_set_resources(new_map, hose);
361 * Want processor accesses of 0xFDxxxxxx to be mapped
362 * to PCI memory space at 0x00000000. Do not want
363 * host bridge to respond to PCI memory accesses of
364 * 0xFDxxxxxx. Do not want host bridge to respond
365 * to PCI memory addresses 0xFD000000-0xFDFFFFFF;
366 * want processor accesses from 0x000A0000-0x000BFFFF
367 * to be forwarded to system memory.
369 * Only valid if not in agent mode and using MAP B.
371 if (new_map == MPC10X_MEM_MAP_B) {
372 early_read_config_byte(hose,
375 MPC10X_CFG_MAPB_OPTIONS_REG,
378 byte &= ~(MPC10X_CFG_MAPB_OPTIONS_PFAE |
379 MPC10X_CFG_MAPB_OPTIONS_PCICH |
380 MPC10X_CFG_MAPB_OPTIONS_PROCCH);
382 if (host_bridge != MPC10X_BRIDGE_106) {
383 byte |= MPC10X_CFG_MAPB_OPTIONS_CFAE;
386 early_write_config_byte(hose,
389 MPC10X_CFG_MAPB_OPTIONS_REG,
393 if (host_bridge != MPC10X_BRIDGE_106) {
394 early_read_config_byte(hose,
400 if (pir != MPC10X_CFG_PIR_HOST_BRIDGE) {
401 printk("Host bridge in Agent mode\n");
402 /* Read or Set LMBAR & PCSRBAR? */
405 /* Set base addr of the 8240/107 EUMB. */
406 early_write_config_dword(hose,
411 #ifdef CONFIG_MPC10X_OPENPIC
412 /* Map EPIC register part of EUMB into vitual memory - PCORE
413 uses an i8259 instead of EPIC. */
415 ioremap(phys_eumb_base + MPC10X_EUMB_EPIC_OFFSET,
416 MPC10X_EUMB_EPIC_SIZE);
420 #ifdef CONFIG_MPC10X_STORE_GATHERING
421 mpc10x_enable_store_gathering(hose);
423 mpc10x_disable_store_gathering(hose);
426 /* setup platform devices for MPC10x bridges */
427 identify_ppc_sys_by_id (host_bridge);
429 for (i = 0; i < cur_ppc_sys_spec->num_devices; i++) {
430 unsigned int dev_id = cur_ppc_sys_spec->device_list[i];
431 ppc_sys_fixup_mem_resource(&ppc_sys_platform_devices[dev_id],
435 /* IRQ's are determined at runtime */
436 ppc_sys_platform_devices[MPC10X_IIC1].resource[1].start = MPC10X_I2C_IRQ;
437 ppc_sys_platform_devices[MPC10X_IIC1].resource[1].end = MPC10X_I2C_IRQ;
438 ppc_sys_platform_devices[MPC10X_DMA0].resource[1].start = MPC10X_DMA0_IRQ;
439 ppc_sys_platform_devices[MPC10X_DMA0].resource[1].end = MPC10X_DMA0_IRQ;
440 ppc_sys_platform_devices[MPC10X_DMA1].resource[1].start = MPC10X_DMA1_IRQ;
441 ppc_sys_platform_devices[MPC10X_DMA1].resource[1].end = MPC10X_DMA1_IRQ;
443 serial_plat_uart0[0].mapbase += phys_eumb_base;
444 serial_plat_uart0[0].irq = MPC10X_UART0_IRQ;
445 serial_plat_uart0[0].membase = ioremap(serial_plat_uart0[0].mapbase, 0x100);
447 serial_plat_uart1[0].mapbase += phys_eumb_base;
448 serial_plat_uart1[0].irq = MPC10X_UART1_IRQ;
449 serial_plat_uart1[0].membase = ioremap(serial_plat_uart1[0].mapbase, 0x100);
452 * 8240 erratum 26, 8241/8245 erratum 29, 107 erratum 23: speculative
453 * PCI reads may return stale data so turn off.
455 if ((host_bridge == MPC10X_BRIDGE_8240)
456 || (host_bridge == MPC10X_BRIDGE_8245)
457 || (host_bridge == MPC10X_BRIDGE_107)) {
459 early_read_config_dword(hose, 0, PCI_DEVFN(0,0),
460 MPC10X_CFG_PICR1_REG, &picr1);
462 picr1 &= ~MPC10X_CFG_PICR1_SPEC_PCI_RD;
464 early_write_config_dword(hose, 0, PCI_DEVFN(0,0),
465 MPC10X_CFG_PICR1_REG, picr1);
469 * 8241/8245 erratum 28: PCI reads from local memory may return
470 * stale data. Workaround by setting PICR2[0] to disable copyback
471 * optimization. Oddly, the latest available user manual for the
472 * 8245 (Rev 2., dated 10/2003) says PICR2[0] is reserverd.
474 if (host_bridge == MPC10X_BRIDGE_8245) {
477 early_read_config_dword(hose, 0, PCI_DEVFN(0,0),
478 MPC10X_CFG_PICR2_REG, &picr2);
480 picr2 |= MPC10X_CFG_PICR2_COPYBACK_OPT;
482 early_write_config_dword(hose, 0, PCI_DEVFN(0,0),
483 MPC10X_CFG_PICR2_REG, picr2);
486 if (ppc_md.progress) ppc_md.progress("mpc10x:exit", 0x100);
491 * Need to make our own PCI config space access macros because
492 * mpc10x_get_mem_size() is called before the data structures are set up for
493 * the 'early_xxx' and 'indirect_xxx' routines to work.
496 #define MPC10X_CFG_read(val, addr, type, op) *val = op((type)(addr))
497 #define MPC10X_CFG_write(val, addr, type, op) op((type *)(addr), (val))
499 #define MPC10X_PCI_OP(rw, size, type, op, mask) \
501 mpc10x_##rw##_config_##size(uint *cfg_addr, uint *cfg_data, int devfn, int offset, type val) \
504 ((offset & 0xfc) << 24) | (devfn << 16) \
505 | (0 << 8) | 0x80); \
506 MPC10X_CFG_##rw(val, cfg_data + (offset & mask), type, op); \
510 MPC10X_PCI_OP(read, byte, u8 *, in_8, 3)
511 MPC10X_PCI_OP(read, dword, u32 *, in_le32, 0)
513 MPC10X_PCI_OP(write, byte, u8, out_8, 3)
514 MPC10X_PCI_OP(read, word, u16 *, in_le16, 2)
515 MPC10X_PCI_OP(write, word, u16, out_le16, 2)
516 MPC10X_PCI_OP(write, dword, u32, out_le32, 0)
520 * Read the memory controller registers to determine the amount of memory in
521 * the system. This assumes that the firmware has correctly set up the memory
522 * controller registers.
525 mpc10x_get_mem_size(uint mem_map)
527 uint *config_addr, *config_data, val;
528 ulong start, end, total, offset;
533 case MPC10X_MEM_MAP_A:
534 config_addr = (uint *)MPC10X_MAPA_CNFG_ADDR;
535 config_data = (uint *)MPC10X_MAPA_CNFG_DATA;
537 case MPC10X_MEM_MAP_B:
538 config_addr = (uint *)MPC10X_MAPB_CNFG_ADDR;
539 config_data = (uint *)MPC10X_MAPB_CNFG_DATA;
545 mpc10x_read_config_byte(config_addr,
548 MPC10X_MCTLR_MEM_BANK_ENABLES,
553 for (i=0; i<8; i++) {
554 if (bank_enables & (1 << i)) {
555 offset = MPC10X_MCTLR_MEM_START_1 + ((i > 3) ? 4 : 0);
556 mpc10x_read_config_dword(config_addr,
561 start = (val >> ((i & 3) << 3)) & 0xff;
563 offset = MPC10X_MCTLR_EXT_MEM_START_1 + ((i>3) ? 4 : 0);
564 mpc10x_read_config_dword(config_addr,
569 val = (val >> ((i & 3) << 3)) & 0x03;
570 start = (val << 28) | (start << 20);
572 offset = MPC10X_MCTLR_MEM_END_1 + ((i > 3) ? 4 : 0);
573 mpc10x_read_config_dword(config_addr,
578 end = (val >> ((i & 3) << 3)) & 0xff;
580 offset = MPC10X_MCTLR_EXT_MEM_END_1 + ((i > 3) ? 4 : 0);
581 mpc10x_read_config_dword(config_addr,
586 val = (val >> ((i & 3) << 3)) & 0x03;
587 end = (val << 28) | (end << 20) | 0xfffff;
589 total += (end - start + 1);
597 mpc10x_enable_store_gathering(struct pci_controller *hose)
601 early_read_config_dword(hose,
604 MPC10X_CFG_PICR1_REG,
607 picr1 |= MPC10X_CFG_PICR1_ST_GATH_EN;
609 early_write_config_dword(hose,
612 MPC10X_CFG_PICR1_REG,
619 mpc10x_disable_store_gathering(struct pci_controller *hose)
623 early_read_config_dword(hose,
626 MPC10X_CFG_PICR1_REG,
629 picr1 &= ~MPC10X_CFG_PICR1_ST_GATH_EN;
631 early_write_config_dword(hose,
634 MPC10X_CFG_PICR1_REG,
640 #ifdef CONFIG_MPC10X_OPENPIC
641 void __init mpc10x_set_openpic(void)
643 /* Map external IRQs */
644 openpic_set_sources(0, EPIC_IRQ_BASE, OpenPIC_Addr + 0x10200);
645 /* Skip reserved space and map i2c and DMA Ch[01] */
646 openpic_set_sources(EPIC_IRQ_BASE, 3, OpenPIC_Addr + 0x11020);
647 /* Skip reserved space and map Message Unit Interrupt (I2O) */
648 openpic_set_sources(EPIC_IRQ_BASE + 3, 1, OpenPIC_Addr + 0x110C0);
649 /* Skip reserved space and map Serial Interupts */
650 openpic_set_sources(EPIC_IRQ_BASE + 4, 2, OpenPIC_Addr + 0x11120);
652 openpic_init(NUM_8259_INTERRUPTS);