1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <common.h>
29#include <mpc8220.h>
30#include <pci.h>
31#include <asm/io.h>
32
33#if defined(CONFIG_PCI)
34
35
36#define CONFIG_PCI_SYS_MEM_BUS CONFIG_SYS_SDRAM_BASE
37#define CONFIG_PCI_SYS_MEM_PHYS CONFIG_SYS_SDRAM_BASE
38#define CONFIG_PCI_SYS_MEM_SIZE (1024 * 1024 * 1024)
39
40#define cfg_read(val, addr, type, op) *val = op((type)(addr));
41#define cfg_write(val, addr, type, op) op((type *)(addr), (val));
42
43#define PCI_OP(rw, size, type, op, mask) \
44int mpc8220_pci_##rw##_config_##size(struct pci_controller *hose, \
45 pci_dev_t dev, int offset, type val) \
46{ \
47 u32 addr = 0; \
48 u16 cfg_type = 0; \
49 addr = ((offset & 0xfc) | cfg_type | (dev) | 0x80000000); \
50 out_be32(hose->cfg_addr, addr); \
51 __asm__ __volatile__("sync"); \
52 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
53 out_be32(hose->cfg_addr, addr & 0x7fffffff); \
54 __asm__ __volatile__("sync"); \
55 return 0; \
56}
57
58PCI_OP(read, byte, u8 *, in_8, 3)
59PCI_OP(read, word, u16 *, in_le16, 2)
60PCI_OP(write, byte, u8, out_8, 3)
61PCI_OP(write, word, u16, out_le16, 2)
62PCI_OP(write, dword, u32, out_le32, 0)
63
64int mpc8220_pci_read_config_dword(struct pci_controller *hose, pci_dev_t dev,
65 int offset, u32 *val)
66{
67 u32 addr;
68 u32 tmpv;
69 u32 mask = 2;
70
71 addr = ((offset & 0xfc) | (dev) | 0x80000000);
72 out_be32(hose->cfg_addr, addr);
73 __asm__ __volatile__("sync");
74 *val = (u32) in_le16((u16 *) (hose->cfg_data + (offset & mask)));
75 out_be32(hose->cfg_addr, addr & 0x7fffffff);
76 __asm__ __volatile__("sync");
77
78
79 offset += 2;
80 addr = ((offset & 0xfc) | 1 | (dev) | 0x80000000);
81 out_be32(hose->cfg_addr, addr);
82 __asm__ __volatile__("sync");
83 tmpv = (u32) in_le16((u16 *) (hose->cfg_data + (offset & mask)));
84 out_be32(hose->cfg_addr, addr & 0x7fffffff);
85 __asm__ __volatile__("sync");
86
87
88 *val = (tmpv << 16) | *val;
89
90 return 0;
91}
92
93void
94pci_mpc8220_init(struct pci_controller *hose)
95{
96 u32 win0, win1, win2;
97 volatile mpc8220_xcpci_t *xcpci =
98 (volatile mpc8220_xcpci_t *) MMAP_XCPCI;
99
100 volatile pcfg8220_t *portcfg = (volatile pcfg8220_t *) MMAP_PCFG;
101
102 win0 = (u32) CONFIG_PCI_MEM_PHYS;
103 win1 = (u32) CONFIG_PCI_IO_PHYS;
104 win2 = (u32) CONFIG_PCI_CFG_PHYS;
105
106
107 out_be32 (&xcpci->glb_stat_ctl, PCI_GLB_STAT_CTRL_PR);
108
109
110 out_be32 (&xcpci->target_ctrl, 0x00000000);
111
112
113 out_be32 (&xcpci->init_win0, (win0 >> 16) | win0 | 0x003f0000);
114 out_be32 (&xcpci->init_win1, ((win1 >> 16) | win1 ));
115 out_be32 (&xcpci->init_win2, ((win2 >> 16) | win2 ));
116
117 out_be32 (&xcpci->init_win_cfg,
118 PCI_INIT_WIN_CFG_WIN0_CTRL_EN |
119 PCI_INIT_WIN_CFG_WIN1_CTRL_EN | PCI_INIT_WIN_CFG_WIN1_CTRL_IO |
120 PCI_INIT_WIN_CFG_WIN2_CTRL_EN | PCI_INIT_WIN_CFG_WIN2_CTRL_IO);
121
122 out_be32 (&xcpci->init_ctrl, 0x00000000);
123
124
125 out_be32 (&xcpci->stat_cmd_reg, PCI_STAT_CMD_B | PCI_STAT_CMD_M);
126
127
128 out_be32 (&xcpci->bist_htyp_lat_cshl, (0xf8 << PCI_CFG1_LT_SHIFT));
129
130 out_be32 (&xcpci->base0, PCI_BASE_ADDR_REG0);
131 out_be32 (&xcpci->base1, PCI_BASE_ADDR_REG1);
132
133 out_be32 (&xcpci->target_bar0,
134 PCI_TARGET_BASE_ADDR_REG0 | PCI_TARGET_BASE_ADDR_EN);
135 out_be32 (&xcpci->target_bar1,
136 PCI_TARGET_BASE_ADDR_REG1 | PCI_TARGET_BASE_ADDR_EN);
137
138
139 out_be32 (&xcpci->glb_stat_ctl, 0x00000000);
140
141
142
143
144 out_be32((volatile u32 *)&portcfg->pcfg3,
145 (in_be32((volatile u32 *)&portcfg->pcfg3) & 0xFC3FCE7F));
146 out_be32((volatile u32 *)&portcfg->pcfg3,
147 (in_be32((volatile u32 *)&portcfg->pcfg3) | 0x01400180));
148
149 hose->first_busno = 0;
150 hose->last_busno = 0xff;
151
152 pci_set_region(hose->regions + 0,
153 CONFIG_PCI_MEM_BUS,
154 CONFIG_PCI_MEM_PHYS,
155 CONFIG_PCI_MEM_SIZE,
156 PCI_REGION_MEM);
157
158 pci_set_region(hose->regions + 1,
159 CONFIG_PCI_IO_BUS,
160 CONFIG_PCI_IO_PHYS,
161 CONFIG_PCI_IO_SIZE,
162 PCI_REGION_IO);
163
164 pci_set_region(hose->regions + 2,
165 CONFIG_PCI_SYS_MEM_BUS,
166 CONFIG_PCI_SYS_MEM_PHYS,
167 CONFIG_PCI_SYS_MEM_SIZE,
168 PCI_REGION_MEM | PCI_REGION_MEMORY);
169
170 hose->region_count = 3;
171
172 hose->cfg_addr = &(xcpci->cfg_adr);
173 hose->cfg_data = (volatile unsigned char *)CONFIG_PCI_CFG_BUS;
174
175 pci_set_ops(hose,
176 mpc8220_pci_read_config_byte,
177 mpc8220_pci_read_config_word,
178 mpc8220_pci_read_config_dword,
179 mpc8220_pci_write_config_byte,
180 mpc8220_pci_write_config_word,
181 mpc8220_pci_write_config_dword);
182
183
184 pci_register_hose(hose);
185 hose->last_busno = pci_hose_scan(hose);
186
187 out_be32 (&xcpci->base0, PCI_BASE_ADDR_REG0);
188 out_be32 (&xcpci->base1, PCI_BASE_ADDR_REG1);
189}
190
191#endif
192