blob: a89d5fd7a64cfe9faeac18f6f7d63bb4a66bae53 [file] [log] [blame]
wdenk02379022003-08-05 18:22:44 +00001/*
2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk02379022003-08-05 18:22:44 +00006 */
7
8#include <common.h>
9
Detlev Zundela414c7a2010-03-12 10:01:12 +010010#if defined(CONFIG_PCI)
wdenk02379022003-08-05 18:22:44 +000011
12#include <asm/processor.h>
13#include <asm/io.h>
14#include <pci.h>
15#include <mpc5xxx.h>
16
17/* System RAM mapped over PCI */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020018#define CONFIG_PCI_MEMORY_BUS CONFIG_SYS_SDRAM_BASE
19#define CONFIG_PCI_MEMORY_PHYS CONFIG_SYS_SDRAM_BASE
wdenk02379022003-08-05 18:22:44 +000020#define CONFIG_PCI_MEMORY_SIZE (1024 * 1024 * 1024)
21
22/* PCIIWCR bit fields */
23#define IWCR_MEM (0 << 3)
24#define IWCR_IO (1 << 3)
25#define IWCR_READ (0 << 1)
26#define IWCR_READLINE (1 << 1)
27#define IWCR_READMULT (2 << 1)
28#define IWCR_EN (1 << 0)
29
30static int mpc5200_read_config_dword(struct pci_controller *hose,
31 pci_dev_t dev, int offset, u32* value)
32{
33 *(volatile u32 *)MPC5XXX_PCI_CAR = (1 << 31) | dev | offset;
34 eieio();
wdenkfc314ce2003-09-14 19:08:39 +000035 udelay(10);
Stefan Roese99200d22005-08-22 17:51:53 +020036#if (defined CONFIG_PF5200 || defined CONFIG_CPCI5200)
37 if (dev & 0x00ff0000) {
38 u32 val;
39 val = in_le16((volatile u16 *)(CONFIG_PCI_IO_PHYS+2));
40 udelay(10);
41 val = val << 16;
42 val |= in_le16((volatile u16 *)(CONFIG_PCI_IO_PHYS+0));
43 *value = val;
44 } else {
45 *value = in_le32((volatile u32 *)CONFIG_PCI_IO_PHYS);
46 }
47 udelay(10);
48#else
wdenk02379022003-08-05 18:22:44 +000049 *value = in_le32((volatile u32 *)CONFIG_PCI_IO_PHYS);
Stefan Roese99200d22005-08-22 17:51:53 +020050#endif
wdenk02379022003-08-05 18:22:44 +000051 eieio();
52 *(volatile u32 *)MPC5XXX_PCI_CAR = 0;
wdenkfc314ce2003-09-14 19:08:39 +000053 udelay(10);
wdenk02379022003-08-05 18:22:44 +000054 return 0;
55}
56
57static int mpc5200_write_config_dword(struct pci_controller *hose,
58 pci_dev_t dev, int offset, u32 value)
59{
60 *(volatile u32 *)MPC5XXX_PCI_CAR = (1 << 31) | dev | offset;
61 eieio();
wdenkfc314ce2003-09-14 19:08:39 +000062 udelay(10);
wdenk02379022003-08-05 18:22:44 +000063 out_le32((volatile u32 *)CONFIG_PCI_IO_PHYS, value);
64 eieio();
65 *(volatile u32 *)MPC5XXX_PCI_CAR = 0;
wdenkfc314ce2003-09-14 19:08:39 +000066 udelay(10);
wdenk02379022003-08-05 18:22:44 +000067 return 0;
68}
69
70void pci_mpc5xxx_init (struct pci_controller *hose)
71{
72 hose->first_busno = 0;
73 hose->last_busno = 0xff;
74
75 /* System space */
76 pci_set_region(hose->regions + 0,
77 CONFIG_PCI_MEMORY_BUS,
78 CONFIG_PCI_MEMORY_PHYS,
79 CONFIG_PCI_MEMORY_SIZE,
Kumar Galaefa1f1d2009-02-06 09:49:31 -060080 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
wdenk02379022003-08-05 18:22:44 +000081
82 /* PCI memory space */
83 pci_set_region(hose->regions + 1,
84 CONFIG_PCI_MEM_BUS,
85 CONFIG_PCI_MEM_PHYS,
86 CONFIG_PCI_MEM_SIZE,
87 PCI_REGION_MEM);
88
89 /* PCI IO space */
90 pci_set_region(hose->regions + 2,
91 CONFIG_PCI_IO_BUS,
92 CONFIG_PCI_IO_PHYS,
93 CONFIG_PCI_IO_SIZE,
94 PCI_REGION_IO);
95
96 hose->region_count = 3;
97
98 pci_register_hose(hose);
99
100 /* GPIO Multiplexing - enable PCI */
101 *(vu_long *)MPC5XXX_GPS_PORT_CONFIG &= ~(1 << 15);
wdenk9c53f402003-10-15 23:53:47 +0000102
wdenk02379022003-08-05 18:22:44 +0000103 /* Set host bridge as pci master and enable memory decoding */
104 *(vu_long *)MPC5XXX_PCI_CMD |=
105 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
wdenk9c53f402003-10-15 23:53:47 +0000106
wdenk02379022003-08-05 18:22:44 +0000107 /* Set maximum latency timer */
108 *(vu_long *)MPC5XXX_PCI_CFG |= (0xf800);
109
110 /* Set cache line size */
111 *(vu_long *)MPC5XXX_PCI_CFG = (*(vu_long *)MPC5XXX_PCI_CFG & ~0xff) |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200112 (CONFIG_SYS_CACHELINE_SIZE / 4);
wdenk9c53f402003-10-15 23:53:47 +0000113
wdenk02379022003-08-05 18:22:44 +0000114 /* Map MBAR to PCI space */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200115 *(vu_long *)MPC5XXX_PCI_BAR0 = CONFIG_SYS_MBAR;
116 *(vu_long *)MPC5XXX_PCI_TBATR0 = CONFIG_SYS_MBAR | 1;
wdenk9c53f402003-10-15 23:53:47 +0000117
wdenk02379022003-08-05 18:22:44 +0000118 /* Map RAM to PCI space */
119 *(vu_long *)MPC5XXX_PCI_BAR1 = CONFIG_PCI_MEMORY_BUS | (1 << 3);
120 *(vu_long *)MPC5XXX_PCI_TBATR1 = CONFIG_PCI_MEMORY_PHYS | 1;
121
wdenk02379022003-08-05 18:22:44 +0000122 /* Park XLB on PCI */
123 *(vu_long *)(MPC5XXX_XLBARB + 0x40) &= ~((7 << 8) | (3 << 5));
124 *(vu_long *)(MPC5XXX_XLBARB + 0x40) |= (3 << 8) | (3 << 5);
125
wdenk02379022003-08-05 18:22:44 +0000126 /* Disable interrupts from PCI controller */
127 *(vu_long *)MPC5XXX_PCI_GSCR &= ~(7 << 12);
Wolfgang Denk3bb216f2005-12-16 15:14:18 +0100128 *(vu_long *)MPC5XXX_PCI_ICR &= ~(7 << 24);
129
130 /* Set PCI retry counter to 0 = infinite retry. */
131 /* The default of 255 is too short for slow devices. */
132 *(vu_long *)MPC5XXX_PCI_ICR &= 0xFFFFFF00;
wdenk9c53f402003-10-15 23:53:47 +0000133
wdenk02379022003-08-05 18:22:44 +0000134 /* Disable initiator windows */
135 *(vu_long *)MPC5XXX_PCI_IWCR = 0;
wdenk9c53f402003-10-15 23:53:47 +0000136
wdenk02379022003-08-05 18:22:44 +0000137 /* Map PCI memory to physical space */
138 *(vu_long *)MPC5XXX_PCI_IW0BTAR = CONFIG_PCI_MEM_PHYS |
139 (((CONFIG_PCI_MEM_SIZE - 1) >> 8) & 0x00ff0000) |
140 (CONFIG_PCI_MEM_BUS >> 16);
141 *(vu_long *)MPC5XXX_PCI_IWCR |= (IWCR_MEM | IWCR_READ | IWCR_EN) << 24;
142
143 /* Map PCI I/O to physical space */
144 *(vu_long *)MPC5XXX_PCI_IW1BTAR = CONFIG_PCI_IO_PHYS |
145 (((CONFIG_PCI_IO_SIZE - 1) >> 8) & 0x00ff0000) |
146 (CONFIG_PCI_IO_BUS >> 16);
147 *(vu_long *)MPC5XXX_PCI_IWCR |= (IWCR_IO | IWCR_READ | IWCR_EN) << 16;
148
149 /* Reset the PCI bus */
150 *(vu_long *)MPC5XXX_PCI_GSCR |= 1;
151 udelay(1000);
152 *(vu_long *)MPC5XXX_PCI_GSCR &= ~1;
153 udelay(1000);
154
155 pci_set_ops(hose,
156 pci_hose_read_config_byte_via_dword,
157 pci_hose_read_config_word_via_dword,
158 mpc5200_read_config_dword,
159 pci_hose_write_config_byte_via_dword,
160 pci_hose_write_config_word_via_dword,
161 mpc5200_write_config_dword);
wdenk9c53f402003-10-15 23:53:47 +0000162
wdenk02379022003-08-05 18:22:44 +0000163 udelay(1000);
164
165#ifdef CONFIG_PCI_SCAN_SHOW
166 printf("PCI: Bus Dev VenId DevId Class Int\n");
167#endif
168
169 hose->last_busno = pci_hose_scan(hose);
170}
Detlev Zundela414c7a2010-03-12 10:01:12 +0100171#endif /* CONFIG_PCI */