2 * arch/ppc/syslib/mpc10x_common.c
4 * Common routines for the Motorola SPS MPC106, MPC107 and MPC8240 Host bridge,
7 * Author: Mark A. Greer
10 * 2001 (c) MontaVista, Software, Inc. This file is licensed under
11 * the terms of the GNU General Public License version 2. This program
12 * is licensed "as is" without any warranty of any kind, whether express
17 * *** WARNING - A BAT MUST be set to access the PCI config addr/data regs ***
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/pci.h>
23 #include <linux/slab.h>
24 #include <linux/serial_8250.h>
25 #include <linux/fsl_devices.h>
26 #include <linux/device.h>
28 #include <asm/byteorder.h>
31 #include <asm/uaccess.h>
32 #include <asm/machdep.h>
33 #include <asm/pci-bridge.h>
34 #include <asm/open_pic.h>
35 #include <asm/mpc10x.h>
36 #include <asm/ppc_sys.h>
38 #ifdef CONFIG_MPC10X_OPENPIC
39 #ifdef CONFIG_EPIC_SERIAL_MODE
40 #define EPIC_IRQ_BASE (epic_serial_mode ? 16 : 5)
42 #define EPIC_IRQ_BASE 5
44 #define MPC10X_I2C_IRQ (EPIC_IRQ_BASE + NUM_8259_INTERRUPTS)
45 #define MPC10X_DMA0_IRQ (EPIC_IRQ_BASE + 1 + NUM_8259_INTERRUPTS)
46 #define MPC10X_DMA1_IRQ (EPIC_IRQ_BASE + 2 + NUM_8259_INTERRUPTS)
48 #define MPC10X_I2C_IRQ -1
49 #define MPC10X_DMA0_IRQ -1
50 #define MPC10X_DMA1_IRQ -1
53 static struct fsl_i2c_platform_data mpc10x_i2c_pdata
= {
57 static struct plat_serial8250_port serial_platform_data
[] = {
61 struct platform_device ppc_sys_platform_devices
[] = {
65 .dev
.platform_data
= &mpc10x_i2c_pdata
,
67 .resource
= (struct resource
[]) {
69 .start
= MPC10X_EUMB_I2C_OFFSET
,
70 .end
= MPC10X_EUMB_I2C_OFFSET
+
71 MPC10X_EUMB_I2C_SIZE
- 1,
72 .flags
= IORESOURCE_MEM
,
75 .flags
= IORESOURCE_IRQ
83 .resource
= (struct resource
[]) {
85 .start
= MPC10X_EUMB_DMA_OFFSET
+ 0x10,
86 .end
= MPC10X_EUMB_DMA_OFFSET
+ 0x1f,
87 .flags
= IORESOURCE_MEM
,
90 .flags
= IORESOURCE_IRQ
,
98 .resource
= (struct resource
[]) {
100 .start
= MPC10X_EUMB_DMA_OFFSET
+ 0x20,
101 .end
= MPC10X_EUMB_DMA_OFFSET
+ 0x2f,
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
,
125 .name
= "serial8250",
127 .dev
.platform_data
= serial_platform_data
,
131 /* We use the PCI ID to match on */
132 struct ppc_sys_spec
*cur_ppc_sys_spec
;
133 struct ppc_sys_spec ppc_sys_specs
[] = {
135 .ppc_sys_name
= "8245",
137 .value
= MPC10X_BRIDGE_8245
,
139 .device_list
= (enum ppc_sys_devices
[])
141 MPC10X_IIC1
, MPC10X_DMA0
, MPC10X_DMA1
, MPC10X_DUART
,
145 .ppc_sys_name
= "8240",
147 .value
= MPC10X_BRIDGE_8240
,
149 .device_list
= (enum ppc_sys_devices
[])
151 MPC10X_IIC1
, MPC10X_DMA0
, MPC10X_DMA1
,
155 .ppc_sys_name
= "107",
157 .value
= MPC10X_BRIDGE_107
,
159 .device_list
= (enum ppc_sys_devices
[])
161 MPC10X_IIC1
, MPC10X_DMA0
, MPC10X_DMA1
,
164 { /* default match */
171 /* Set resources to match bridge memory map */
173 mpc10x_bridge_set_resources(int map
, struct pci_controller
*hose
)
177 case MPC10X_MEM_MAP_A
:
178 pci_init_resource(&hose
->io_resource
,
184 pci_init_resource (&hose
->mem_resources
[0],
190 case MPC10X_MEM_MAP_B
:
191 pci_init_resource(&hose
->io_resource
,
197 pci_init_resource (&hose
->mem_resources
[0],
204 printk("mpc10x_bridge_set_resources: "
205 "Invalid map specified\n");
207 ppc_md
.progress("mpc10x:exit1", 0x100);
211 * Do some initialization and put the EUMB registers at the specified address
212 * (also map the EPIC registers into virtual space--OpenPIC_Addr will be set).
214 * The EPIC is not on the 106, only the 8240 and 107.
217 mpc10x_bridge_init(struct pci_controller
*hose
,
222 int host_bridge
, picr1
, picr1_bit
, i
;
223 ulong pci_config_addr
, pci_config_data
;
226 if (ppc_md
.progress
) ppc_md
.progress("mpc10x:enter", 0x100);
228 /* Set up for current map so we can get at config regs */
229 switch (current_map
) {
230 case MPC10X_MEM_MAP_A
:
231 setup_indirect_pci(hose
,
232 MPC10X_MAPA_CNFG_ADDR
,
233 MPC10X_MAPA_CNFG_DATA
);
235 case MPC10X_MEM_MAP_B
:
236 setup_indirect_pci(hose
,
237 MPC10X_MAPB_CNFG_ADDR
,
238 MPC10X_MAPB_CNFG_DATA
);
241 printk("mpc10x_bridge_init: %s\n",
242 "Invalid current map specified");
244 ppc_md
.progress("mpc10x:exit1", 0x100);
248 /* Make sure it's a supported bridge */
249 early_read_config_dword(hose
,
255 switch (host_bridge
) {
256 case MPC10X_BRIDGE_106
:
257 case MPC10X_BRIDGE_8240
:
258 case MPC10X_BRIDGE_107
:
259 case MPC10X_BRIDGE_8245
:
263 ppc_md
.progress("mpc10x:exit2", 0x100);
268 case MPC10X_MEM_MAP_A
:
269 MPC10X_SETUP_HOSE(hose
, A
);
270 pci_config_addr
= MPC10X_MAPA_CNFG_ADDR
;
271 pci_config_data
= MPC10X_MAPA_CNFG_DATA
;
272 picr1_bit
= MPC10X_CFG_PICR1_ADDR_MAP_A
;
274 case MPC10X_MEM_MAP_B
:
275 MPC10X_SETUP_HOSE(hose
, B
);
276 pci_config_addr
= MPC10X_MAPB_CNFG_ADDR
;
277 pci_config_data
= MPC10X_MAPB_CNFG_DATA
;
278 picr1_bit
= MPC10X_CFG_PICR1_ADDR_MAP_B
;
281 printk("mpc10x_bridge_init: %s\n",
282 "Invalid new map specified");
284 ppc_md
.progress("mpc10x:exit3", 0x100);
288 /* Make bridge use the 'new_map', if not already usng it */
289 if (current_map
!= new_map
) {
290 early_read_config_dword(hose
,
293 MPC10X_CFG_PICR1_REG
,
296 picr1
= (picr1
& ~MPC10X_CFG_PICR1_ADDR_MAP_MASK
) |
299 early_write_config_dword(hose
,
302 MPC10X_CFG_PICR1_REG
,
305 asm volatile("sync");
307 /* Undo old mappings & map in new cfg data/addr regs */
308 iounmap((void *)hose
->cfg_addr
);
309 iounmap((void *)hose
->cfg_data
);
311 setup_indirect_pci(hose
,
316 /* Setup resources to match map */
317 mpc10x_bridge_set_resources(new_map
, hose
);
320 * Want processor accesses of 0xFDxxxxxx to be mapped
321 * to PCI memory space at 0x00000000. Do not want
322 * host bridge to respond to PCI memory accesses of
323 * 0xFDxxxxxx. Do not want host bridge to respond
324 * to PCI memory addresses 0xFD000000-0xFDFFFFFF;
325 * want processor accesses from 0x000A0000-0x000BFFFF
326 * to be forwarded to system memory.
328 * Only valid if not in agent mode and using MAP B.
330 if (new_map
== MPC10X_MEM_MAP_B
) {
331 early_read_config_byte(hose
,
334 MPC10X_CFG_MAPB_OPTIONS_REG
,
337 byte
&= ~(MPC10X_CFG_MAPB_OPTIONS_PFAE
|
338 MPC10X_CFG_MAPB_OPTIONS_PCICH
|
339 MPC10X_CFG_MAPB_OPTIONS_PROCCH
);
341 if (host_bridge
!= MPC10X_BRIDGE_106
) {
342 byte
|= MPC10X_CFG_MAPB_OPTIONS_CFAE
;
345 early_write_config_byte(hose
,
348 MPC10X_CFG_MAPB_OPTIONS_REG
,
352 if (host_bridge
!= MPC10X_BRIDGE_106
) {
353 early_read_config_byte(hose
,
359 if (pir
!= MPC10X_CFG_PIR_HOST_BRIDGE
) {
360 printk("Host bridge in Agent mode\n");
361 /* Read or Set LMBAR & PCSRBAR? */
364 /* Set base addr of the 8240/107 EUMB. */
365 early_write_config_dword(hose
,
370 #ifdef CONFIG_MPC10X_OPENPIC
371 /* Map EPIC register part of EUMB into vitual memory - PCORE
372 uses an i8259 instead of EPIC. */
374 ioremap(phys_eumb_base
+ MPC10X_EUMB_EPIC_OFFSET
,
375 MPC10X_EUMB_EPIC_SIZE
);
379 #ifdef CONFIG_MPC10X_STORE_GATHERING
380 mpc10x_enable_store_gathering(hose
);
382 mpc10x_disable_store_gathering(hose
);
385 /* setup platform devices for MPC10x bridges */
386 identify_ppc_sys_by_id (host_bridge
);
388 for (i
= 0; i
< cur_ppc_sys_spec
->num_devices
; i
++) {
389 unsigned int dev_id
= cur_ppc_sys_spec
->device_list
[i
];
390 ppc_sys_fixup_mem_resource(&ppc_sys_platform_devices
[dev_id
],
394 /* IRQ's are determined at runtime */
395 ppc_sys_platform_devices
[MPC10X_IIC1
].resource
[1].start
= MPC10X_I2C_IRQ
;
396 ppc_sys_platform_devices
[MPC10X_IIC1
].resource
[1].end
= MPC10X_I2C_IRQ
;
397 ppc_sys_platform_devices
[MPC10X_DMA0
].resource
[1].start
= MPC10X_DMA0_IRQ
;
398 ppc_sys_platform_devices
[MPC10X_DMA0
].resource
[1].end
= MPC10X_DMA0_IRQ
;
399 ppc_sys_platform_devices
[MPC10X_DMA1
].resource
[1].start
= MPC10X_DMA1_IRQ
;
400 ppc_sys_platform_devices
[MPC10X_DMA1
].resource
[1].end
= MPC10X_DMA1_IRQ
;
403 * 8240 erratum 26, 8241/8245 erratum 29, 107 erratum 23: speculative
404 * PCI reads may return stale data so turn off.
406 if ((host_bridge
== MPC10X_BRIDGE_8240
)
407 || (host_bridge
== MPC10X_BRIDGE_8245
)
408 || (host_bridge
== MPC10X_BRIDGE_107
)) {
410 early_read_config_dword(hose
, 0, PCI_DEVFN(0,0),
411 MPC10X_CFG_PICR1_REG
, &picr1
);
413 picr1
&= ~MPC10X_CFG_PICR1_SPEC_PCI_RD
;
415 early_write_config_dword(hose
, 0, PCI_DEVFN(0,0),
416 MPC10X_CFG_PICR1_REG
, picr1
);
420 * 8241/8245 erratum 28: PCI reads from local memory may return
421 * stale data. Workaround by setting PICR2[0] to disable copyback
422 * optimization. Oddly, the latest available user manual for the
423 * 8245 (Rev 2., dated 10/2003) says PICR2[0] is reserverd.
425 if (host_bridge
== MPC10X_BRIDGE_8245
) {
428 early_read_config_dword(hose
, 0, PCI_DEVFN(0,0),
429 MPC10X_CFG_PICR2_REG
, &picr2
);
431 picr2
|= MPC10X_CFG_PICR2_COPYBACK_OPT
;
433 early_write_config_dword(hose
, 0, PCI_DEVFN(0,0),
434 MPC10X_CFG_PICR2_REG
, picr2
);
437 if (ppc_md
.progress
) ppc_md
.progress("mpc10x:exit", 0x100);
442 * Need to make our own PCI config space access macros because
443 * mpc10x_get_mem_size() is called before the data structures are set up for
444 * the 'early_xxx' and 'indirect_xxx' routines to work.
447 #define MPC10X_CFG_read(val, addr, type, op) *val = op((type)(addr))
448 #define MPC10X_CFG_write(val, addr, type, op) op((type *)(addr), (val))
450 #define MPC10X_PCI_OP(rw, size, type, op, mask) \
452 mpc10x_##rw##_config_##size(uint *cfg_addr, uint *cfg_data, int devfn, int offset, type val) \
455 ((offset & 0xfc) << 24) | (devfn << 16) \
456 | (0 << 8) | 0x80); \
457 MPC10X_CFG_##rw(val, cfg_data + (offset & mask), type, op); \
461 MPC10X_PCI_OP(read
, byte
, u8
*, in_8
, 3)
462 MPC10X_PCI_OP(read
, dword
, u32
*, in_le32
, 0)
464 MPC10X_PCI_OP(write
, byte
, u8
, out_8
, 3)
465 MPC10X_PCI_OP(read
, word
, u16
*, in_le16
, 2)
466 MPC10X_PCI_OP(write
, word
, u16
, out_le16
, 2)
467 MPC10X_PCI_OP(write
, dword
, u32
, out_le32
, 0)
471 * Read the memory controller registers to determine the amount of memory in
472 * the system. This assumes that the firmware has correctly set up the memory
473 * controller registers.
476 mpc10x_get_mem_size(uint mem_map
)
478 uint
*config_addr
, *config_data
, val
;
479 ulong start
, end
, total
, offset
;
484 case MPC10X_MEM_MAP_A
:
485 config_addr
= (uint
*)MPC10X_MAPA_CNFG_ADDR
;
486 config_data
= (uint
*)MPC10X_MAPA_CNFG_DATA
;
488 case MPC10X_MEM_MAP_B
:
489 config_addr
= (uint
*)MPC10X_MAPB_CNFG_ADDR
;
490 config_data
= (uint
*)MPC10X_MAPB_CNFG_DATA
;
496 mpc10x_read_config_byte(config_addr
,
499 MPC10X_MCTLR_MEM_BANK_ENABLES
,
504 for (i
=0; i
<8; i
++) {
505 if (bank_enables
& (1 << i
)) {
506 offset
= MPC10X_MCTLR_MEM_START_1
+ ((i
> 3) ? 4 : 0);
507 mpc10x_read_config_dword(config_addr
,
512 start
= (val
>> ((i
& 3) << 3)) & 0xff;
514 offset
= MPC10X_MCTLR_EXT_MEM_START_1
+ ((i
>3) ? 4 : 0);
515 mpc10x_read_config_dword(config_addr
,
520 val
= (val
>> ((i
& 3) << 3)) & 0x03;
521 start
= (val
<< 28) | (start
<< 20);
523 offset
= MPC10X_MCTLR_MEM_END_1
+ ((i
> 3) ? 4 : 0);
524 mpc10x_read_config_dword(config_addr
,
529 end
= (val
>> ((i
& 3) << 3)) & 0xff;
531 offset
= MPC10X_MCTLR_EXT_MEM_END_1
+ ((i
> 3) ? 4 : 0);
532 mpc10x_read_config_dword(config_addr
,
537 val
= (val
>> ((i
& 3) << 3)) & 0x03;
538 end
= (val
<< 28) | (end
<< 20) | 0xfffff;
540 total
+= (end
- start
+ 1);
548 mpc10x_enable_store_gathering(struct pci_controller
*hose
)
552 early_read_config_dword(hose
,
555 MPC10X_CFG_PICR1_REG
,
558 picr1
|= MPC10X_CFG_PICR1_ST_GATH_EN
;
560 early_write_config_dword(hose
,
563 MPC10X_CFG_PICR1_REG
,
570 mpc10x_disable_store_gathering(struct pci_controller
*hose
)
574 early_read_config_dword(hose
,
577 MPC10X_CFG_PICR1_REG
,
580 picr1
&= ~MPC10X_CFG_PICR1_ST_GATH_EN
;
582 early_write_config_dword(hose
,
585 MPC10X_CFG_PICR1_REG
,
591 #ifdef CONFIG_MPC10X_OPENPIC
592 void __init
mpc10x_set_openpic(void)
594 /* Map external IRQs */
595 openpic_set_sources(0, EPIC_IRQ_BASE
, OpenPIC_Addr
+ 0x10200);
596 /* Skip reserved space and map i2c and DMA Ch[01] */
597 openpic_set_sources(EPIC_IRQ_BASE
, 3, OpenPIC_Addr
+ 0x11020);
598 /* Skip reserved space and map Message Unit Interrupt (I2O) */
599 openpic_set_sources(EPIC_IRQ_BASE
+ 3, 1, OpenPIC_Addr
+ 0x110C0);
601 openpic_init(NUM_8259_INTERRUPTS
);