blob: 34cd5872b935406a24a19c3aa678b11dd39e007f [file] [log] [blame]
Wolfgang Denk7521af12005-10-09 01:04:33 +02001/*
2 * (C) Copyright 2003
3 * AMIRIX Systems Inc.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <ppc4xx.h>
26#include <asm/processor.h>
27#include <pci.h>
28
29#define PCI_MEM_82559ER_CSR_BASE 0x30200000
30#define PCI_IO_82559ER_CSR_BASE 0x40000200
31
32/** AP1100 specific values */
33#define PSII_BASE 0x30000000 /**< PowerSpan II dual bridge local bus register address */
34#define PSII_CONFIG_ADDR 0x30000290 /**< PowerSpan II Configuration Cycle Address configuration register */
35#define PSII_CONFIG_DATA 0x30000294 /**< PowerSpan II Configuration Cycle Data register. */
36#define PSII_CONFIG_DEST_PCI2 0x01000000 /**< PowerSpan II configuration cycle destination selection, set for PCI2 bus */
37#define PSII_PCI_MEM_BASE 0x30200000 /**< Local Bus address for start of PCI memory space on PCI2 bus. */
38#define PSII_PCI_MEM_SIZE 0x1BE00000 /**< PCI Memory space about 510 Meg. */
39#define AP1000_SYS_MEM_START 0x00000000 /**< System memory starts at 0. */
40#define AP1000_SYS_MEM_SIZE 0x08000000 /**< System memory is 128 Meg. */
41
42/* static int G_verbosity_level = 1; */
43#define G_verbosity_level 1
44
45void write1(unsigned long addr, unsigned char val) {
46 volatile unsigned char* p = (volatile unsigned char*)addr;
47
48 if(G_verbosity_level > 1)
49 printf("write1: addr=%08x val=%02x\n", (unsigned int)addr, val);
50 *p = val;
51 asm("eieio");
52}
53
54unsigned char read1(unsigned long addr) {
55 unsigned char val;
56 volatile unsigned char* p = (volatile unsigned char*)addr;
57
58 if(G_verbosity_level > 1)
59 printf("read1: addr=%08x ", (unsigned int)addr);
60 val = *p;
61 asm("eieio");
62 if(G_verbosity_level > 1)
63 printf("val=%08x\n", val);
64 return val;
65}
66
67void write2(unsigned long addr, unsigned short val) {
68 volatile unsigned short* p = (volatile unsigned short*)addr;
69
70 if(G_verbosity_level > 1)
71 printf("write2: addr=%08x val=%04x -> *p=%04x\n", (unsigned int)addr, val,
72 ((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8));
73
74 *p = ((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8);
75 asm("eieio");
76}
77
78unsigned short read2(unsigned long addr) {
79 unsigned short val;
80 volatile unsigned short* p = (volatile unsigned short*)addr;
81
82 if(G_verbosity_level > 1)
83 printf("read2: addr=%08x ", (unsigned int)addr);
84 val = *p;
85 val = ((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8);
86 asm("eieio");
87 if(G_verbosity_level > 1)
88 printf("*p=%04x -> val=%04x\n",
89 ((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8), val);
90 return val;
91}
92
93void write4(unsigned long addr, unsigned long val) {
94 volatile unsigned long* p = (volatile unsigned long*)addr;
95
96 if(G_verbosity_level > 1)
97 printf("write4: addr=%08x val=%08x -> *p=%08x\n", (unsigned int)addr, (unsigned int)val,
98 (unsigned int)(((val & 0xFF000000) >> 24) | ((val & 0x000000FF) << 24) |
99 ((val & 0x00FF0000) >> 8) | ((val & 0x0000FF00) << 8)));
100
101 *p = ((val & 0xFF000000) >> 24) | ((val & 0x000000FF) << 24) |
102 ((val & 0x00FF0000) >> 8) | ((val & 0x0000FF00) << 8);
103 asm("eieio");
104}
105
106unsigned long read4(unsigned long addr) {
107 unsigned long val;
108 volatile unsigned long* p = (volatile unsigned long*)addr;
109
110 if(G_verbosity_level > 1)
111 printf("read4: addr=%08x", (unsigned int)addr);
112
113 val = *p;
114 val = ((val & 0xFF000000) >> 24) | ((val & 0x000000FF) << 24) |
115 ((val & 0x00FF0000) >> 8) | ((val & 0x0000FF00) << 8);
116 asm("eieio");
117
118 if(G_verbosity_level > 1)
119 printf("*p=%04x -> val=%04x\n",
120 (unsigned int)(((val & 0xFF000000) >> 24) | ((val & 0x000000FF) << 24) |
121 ((val & 0x00FF0000) >> 8) | ((val & 0x0000FF00) << 8)), (unsigned int)val);
122 return val;
123}
124
125void write4be(unsigned long addr, unsigned long val) {
126 volatile unsigned long* p = (volatile unsigned long*)addr;
127
128 if(G_verbosity_level > 1)
129 printf("write4: addr=%08x val=%08x\n", (unsigned int)addr, (unsigned int)val);
130 *p = val;
131 asm("eieio");
132}
133
134/** One byte configuration write on PSII.
135 * Currently fixes destination PCI bus to PCI2, onboard
136 * pci.
137 * @param hose PCI Host controller information. Ignored.
138 * @param dev Encoded PCI device/Bus and Function value.
139 * @param reg PCI Configuration register number.
140 * @param val Address of location for received byte.
141 * @return Always Zero.
142 */
143static int psII_read_config_byte(
144 struct pci_controller *hose,
145 pci_dev_t dev,
146 int reg,
147 u8 *val)
148{
149 write4be(PSII_CONFIG_ADDR,
150 PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
151 (PCI_BUS(dev) << 16) |
152 (PCI_DEV(dev) << 11) |
153 (PCI_FUNC(dev) << 8) |
154 ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
155
156 *val = read1(PSII_CONFIG_DATA+(reg&0x03));
157 return(0);
158}
159
160/** One byte configuration write on PSII.
161 * Currently fixes destination bus to PCI2, onboard
162 * pci.
163 * @param hose PCI Host controller information. Ignored.
164 * @param dev Encoded PCI device/Bus and Function value.
165 * @param reg PCI Configuration register number.
166 * @param val Output byte.
167 * @return Always Zero.
168 */
169static int psII_write_config_byte(
170 struct pci_controller *hose,
171 pci_dev_t dev,
172 int reg,
173 u8 val)
174{
175 write4be(PSII_CONFIG_ADDR,
176 PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
177 (PCI_BUS(dev) << 16) |
178 (PCI_DEV(dev) << 11) |
179 (PCI_FUNC(dev) << 8) |
180 ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
181
182 write1(PSII_CONFIG_DATA+(reg&0x03),(unsigned char )val);
183
184 return(0);
185}
186
187/** One word (16 bit) configuration read on PSII.
188 * Currently fixes destination PCI bus to PCI2, onboard
189 * pci.
190 * @param hose PCI Host controller information. Ignored.
191 * @param dev Encoded PCI device/Bus and Function value.
192 * @param reg PCI Configuration register number.
193 * @param val Address of location for received word.
194 * @return Always Zero.
195 */
196static int psII_read_config_word(
197 struct pci_controller *hose,
198 pci_dev_t dev,
199 int reg,
200 u16 *val)
201{
202 write4be(PSII_CONFIG_ADDR,
203 PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
204 (PCI_BUS(dev) << 16) |
205 (PCI_DEV(dev) << 11) |
206 (PCI_FUNC(dev) << 8) |
207 ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
208
209 *val = read2(PSII_CONFIG_DATA+(reg&0x03));
210 return(0);
211}
212
213/** One word (16 bit) configuration write on PSII.
214 * Currently fixes destination bus to PCI2, onboard
215 * pci.
216 * @param hose PCI Host controller information. Ignored.
217 * @param dev Encoded PCI device/Bus and Function value.
218 * @param reg PCI Configuration register number.
219 * @param val Output word.
220 * @return Always Zero.
221 */
222static int psII_write_config_word(
223 struct pci_controller *hose,
224 pci_dev_t dev,
225 int reg,
226 u16 val)
227{
228 write4be(PSII_CONFIG_ADDR,
229 PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
230 (PCI_BUS(dev) << 16) |
231 (PCI_DEV(dev) << 11) |
232 (PCI_FUNC(dev) << 8) |
233 ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
234
235 write2(PSII_CONFIG_DATA+(reg&0x03),(unsigned short )val);
236
237 return(0);
238}
239
240/** One DWord (32 bit) configuration read on PSII.
241 * Currently fixes destination PCI bus to PCI2, onboard
242 * pci.
243 * @param hose PCI Host controller information. Ignored.
244 * @param dev Encoded PCI device/Bus and Function value.
245 * @param reg PCI Configuration register number.
246 * @param val Address of location for received byte.
247 * @return Always Zero.
248 */
249static int psII_read_config_dword(
250 struct pci_controller *hose,
251 pci_dev_t dev,
252 int reg,
253 u32 *val)
254{
255 write4be(PSII_CONFIG_ADDR,
256 PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
257 (PCI_BUS(dev) << 16) |
258 (PCI_DEV(dev) << 11) |
259 (PCI_FUNC(dev) << 8) |
260 ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
261
262 *val = read4(PSII_CONFIG_DATA);
263 return(0);
264}
265
266/** One DWord (32 bit) configuration write on PSII.
267 * Currently fixes destination bus to PCI2, onboard
268 * pci.
269 * @param hose PCI Host controller information. Ignored.
270 * @param dev Encoded PCI device/Bus and Function value.
271 * @param reg PCI Configuration register number.
272 * @param val Output Dword.
273 * @return Always Zero.
274 */
275static int psII_write_config_dword(
276 struct pci_controller *hose,
277 pci_dev_t dev,
278 int reg,
279 u32 val)
280{
281 write4be(PSII_CONFIG_ADDR,
282 PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
283 (PCI_BUS(dev) << 16) |
284 (PCI_DEV(dev) << 11) |
285 (PCI_FUNC(dev) << 8) |
286 ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
287
288 write4(PSII_CONFIG_DATA,(unsigned long)val);
289
290 return(0);
291}
292
293
294
295static struct pci_config_table ap1000_config_table[] = {
296#ifdef CONFIG_AP1000
297 {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
298 PCI_BUS(CFG_ETH_DEV_FN), PCI_DEV(CFG_ETH_DEV_FN), PCI_FUNC(CFG_ETH_DEV_FN),
299 pci_cfgfunc_config_device,
300 {CFG_ETH_IOBASE, CFG_ETH_MEMBASE, PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
301#endif
302 { }
303};
304
305
306static struct pci_controller psII_hose = {
307 config_table: ap1000_config_table,
308};
309
310void pci_init_board(void)
311{
312 struct pci_controller *hose = &psII_hose;
313
314 /*
315 * Register the hose
316 */
317 hose->first_busno = 0;
318 hose->last_busno = 0xff;
319
320
321 /* System memory space */
322 pci_set_region(hose->regions + 0,
323 AP1000_SYS_MEM_START, AP1000_SYS_MEM_START, AP1000_SYS_MEM_SIZE,
324 PCI_REGION_MEM | PCI_REGION_MEMORY);
325
326 /* PCI Memory space */
327 pci_set_region(hose->regions + 1,
328 PSII_PCI_MEM_BASE, PSII_PCI_MEM_BASE, PSII_PCI_MEM_SIZE,
329 PCI_REGION_MEM);
330
331 /* No IO Memory space - for now */
332
333 pci_set_ops(hose,
334 psII_read_config_byte,
335 psII_read_config_word,
336 psII_read_config_dword,
337 psII_write_config_byte,
338 psII_write_config_word,
339 psII_write_config_dword);
340
341 hose->region_count = 2;
342
343 pci_register_hose(hose);
344
345 hose->last_busno = pci_hose_scan(hose);
346}