5 * Michael Schwingen, michael@schwingen.org
6 * (C) Copyright 2004 eslab.whut.edu.cn
7 * Yue Hu(huyue_whut@yahoo.com.cn), Ligong Xue(lgxue@hotmail.com)
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #include <asm/processor.h>
32 #include <asm/arch/ixp425.h>
33 #include <asm/arch/ixp425pci.h>
35 DECLARE_GLOBAL_DATA_PTR;
37 static void non_prefetch_read(unsigned int addr, unsigned int cmd,
39 static void non_prefetch_write(unsigned int addr, unsigned int cmd,
42 /*define the sub vendor and subsystem to be used */
43 #define IXP425_PCI_SUB_VENDOR_SYSTEM 0x00000000
45 #define PCI_MEMORY_BUS 0x00000000
46 #define PCI_MEMORY_PHY 0x00000000
47 #define PCI_MEMORY_SIZE 0x04000000
49 #define PCI_MEM_BUS 0x48000000
50 #define PCI_MEM_PHY 0x00000000
51 #define PCI_MEM_SIZE 0x04000000
53 #define PCI_IO_BUS 0x00000000
54 #define PCI_IO_PHY 0x00000000
55 #define PCI_IO_SIZE 0x00010000
57 /* build address value for config sycle */
58 static unsigned int pci_config_addr(pci_dev_t bdf, unsigned int reg)
60 unsigned int bus = PCI_BUS(bdf);
61 unsigned int dev = PCI_DEV(bdf);
62 unsigned int func = PCI_FUNC(bdf);
65 if (bus) { /* secondary bus, use type 1 config cycle */
66 addr = bdf | (reg & ~3) | 1;
69 primary bus, type 0 config cycle. address bits 31:28
70 specify the device 10:8 specify the function
72 addr = BIT((31 - dev)) | (func << 8) | (reg & ~3);
78 static int pci_config_status(void)
82 regval = readl(PCI_CSR_BASE + PCI_ISR_OFFSET);
83 if ((regval & PCI_ISR_PFE) == 0)
86 /* no device present, make sure that the master abort bit is reset */
87 writel(PCI_ISR_PFE, PCI_CSR_BASE + PCI_ISR_OFFSET);
91 static int pci_ixp_hose_read_config_dword(struct pci_controller *hose,
92 pci_dev_t bdf, int where, unsigned int *val)
98 debug("pci_ixp_hose_read_config_dword: bdf %x, reg %x", bdf, where);
99 /*Set the address to be read */
100 addr = pci_config_addr(bdf, where);
101 non_prefetch_read(addr, NP_CMD_CONFIGREAD, &retval);
104 stat = pci_config_status();
107 debug("-> val %x, status %x\n", *val, stat);
111 static int pci_ixp_hose_read_config_word(struct pci_controller *hose,
112 pci_dev_t bdf, int where, unsigned short *val)
117 unsigned int byteEnables;
120 debug("pci_ixp_hose_read_config_word: bdf %x, reg %x", bdf, where);
122 /*byte enables are 4 bits active low, the position of each
123 bit maps to the byte that it enables */
125 (~(BIT(n) | BIT((n + 1)))) &
126 IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
127 byteEnables = byteEnables << PCI_NP_CBE_BESL;
128 /*Set the address to be read */
129 addr = pci_config_addr(bdf, where);
130 non_prefetch_read(addr, byteEnables | NP_CMD_CONFIGREAD, &retval);
132 /*Pick out the word we are interested in */
133 *val = retval >> (8 * n);
135 stat = pci_config_status();
138 debug("-> val %x, status %x\n", *val, stat);
142 static int pci_ixp_hose_read_config_byte(struct pci_controller *hose,
143 pci_dev_t bdf, int where, unsigned char *val)
147 unsigned int byteEnables;
151 debug("pci_ixp_hose_read_config_byte: bdf %x, reg %x", bdf, where);
153 /*byte enables are 4 bits, active low, the position of each
154 bit maps to the byte that it enables */
155 byteEnables = (~BIT(n)) & IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
156 byteEnables = byteEnables << PCI_NP_CBE_BESL;
158 /*Set the address to be read */
159 addr = pci_config_addr(bdf, where);
160 non_prefetch_read(addr, byteEnables | NP_CMD_CONFIGREAD, &retval);
161 /*Pick out the byte we are interested in */
162 *val = retval >> (8 * n);
164 stat = pci_config_status();
167 debug("-> val %x, status %x\n", *val, stat);
171 static int pci_ixp_hose_write_config_byte(struct pci_controller *hose,
172 pci_dev_t bdf, int where, unsigned char val)
175 unsigned int byteEnables;
180 debug("pci_ixp_hose_write_config_byte: bdf %x, reg %x, val %x",
183 /*byte enables are 4 bits active low, the position of each
184 bit maps to the byte that it enables */
185 byteEnables = (~BIT(n)) & IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
186 byteEnables = byteEnables << PCI_NP_CBE_BESL;
187 ldata = val << (8 * n);
188 /*Set the address to be written */
189 addr = pci_config_addr(bdf, where);
190 non_prefetch_write(addr, byteEnables | NP_CMD_CONFIGWRITE, ldata);
192 stat = pci_config_status();
193 debug("-> status %x\n", stat);
197 static int pci_ixp_hose_write_config_word(struct pci_controller *hose,
198 pci_dev_t bdf, int where, unsigned short val)
201 unsigned int byteEnables;
206 debug("pci_ixp_hose_write_config_word: bdf %x, reg %x, val %x",
209 /*byte enables are 4 bits active low, the position of each
210 bit maps to the byte that it enables */
212 (~(BIT(n) | BIT((n + 1)))) &
213 IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
214 byteEnables = byteEnables << PCI_NP_CBE_BESL;
215 ldata = val << (8 * n);
216 /*Set the address to be written */
217 addr = pci_config_addr(bdf, where);
218 non_prefetch_write(addr, byteEnables | NP_CMD_CONFIGWRITE, ldata);
220 stat = pci_config_status();
221 debug("-> status %x\n", stat);
225 static int pci_ixp_hose_write_config_dword(struct pci_controller *hose,
226 pci_dev_t bdf, int where, unsigned int val)
231 debug("pci_ixp_hose_write_config_dword: bdf %x, reg %x, val %x",
233 /*Set the address to be written */
234 addr = pci_config_addr(bdf, where);
235 non_prefetch_write(addr, NP_CMD_CONFIGWRITE, val);
237 stat = pci_config_status();
238 debug("-> status %x\n", stat);
242 static void non_prefetch_read(unsigned int addr,
243 unsigned int cmd, unsigned int *data)
245 writel(addr, PCI_CSR_BASE + PCI_NP_AD_OFFSET);
247 /*set up and execute the read */
248 writel(cmd, PCI_CSR_BASE + PCI_NP_CBE_OFFSET);
250 /*The result of the read is now in np_rdata */
251 *data = readl(PCI_CSR_BASE + PCI_NP_RDATA_OFFSET);
256 static void non_prefetch_write(unsigned int addr,
257 unsigned int cmd, unsigned int data)
260 writel(addr, PCI_CSR_BASE + PCI_NP_AD_OFFSET);
261 /*set up the write */
262 writel(cmd, PCI_CSR_BASE + PCI_NP_CBE_OFFSET);
263 /*Execute the write by writing to NP_WDATA */
264 writel(data, PCI_CSR_BASE + PCI_NP_WDATA_OFFSET);
269 static void crp_write(unsigned int offset, unsigned int data)
272 * The CRP address register bit 16 indicates that we want to do a
275 writel(PCI_CRP_WRITE | offset, PCI_CSR_BASE + PCI_CRP_AD_CBE_OFFSET);
276 writel(data, PCI_CSR_BASE + PCI_CRP_WDATA_OFFSET);
279 void pci_ixp_init(struct pci_controller *hose)
284 * Specify that the AHB bus is operating in big endian mode. Set up
285 * byte lane swapping between little-endian PCI and the big-endian
289 csr = PCI_CSR_ABE | PCI_CSR_PDS | PCI_CSR_ADS;
293 writel(csr, PCI_CSR_BASE + PCI_CSR_OFFSET);
295 writel(0, PCI_CSR_BASE + PCI_INTEN_OFFSET);
298 * We configure the PCI inbound memory windows to be
299 * 1:1 mapped to SDRAM
301 crp_write(PCI_CFG_BASE_ADDRESS_0, 0x00000000);
302 crp_write(PCI_CFG_BASE_ADDRESS_1, 0x01000000);
303 crp_write(PCI_CFG_BASE_ADDRESS_2, 0x02000000);
304 crp_write(PCI_CFG_BASE_ADDRESS_3, 0x03000000);
307 * Enable CSR window at 64 MiB to allow PCI masters
308 * to continue prefetching past 64 MiB boundary.
310 crp_write(PCI_CFG_BASE_ADDRESS_4, 0x04000000);
312 * Enable the IO window to be way up high, at 0xfffffc00
314 crp_write(PCI_CFG_BASE_ADDRESS_5, 0xfffffc01);
316 /*Setup PCI-AHB and AHB-PCI address mappings */
317 writel(0x00010203, PCI_CSR_BASE + PCI_AHBMEMBASE_OFFSET);
319 writel(0x00000000, PCI_CSR_BASE + PCI_AHBIOBASE_OFFSET);
321 writel(0x48494a4b, PCI_CSR_BASE + PCI_PCIMEMBASE_OFFSET);
323 crp_write(PCI_CFG_SUB_VENDOR_ID, IXP425_PCI_SUB_VENDOR_SYSTEM);
325 crp_write(PCI_CFG_COMMAND, PCI_CFG_CMD_MAE | PCI_CFG_CMD_BME);
328 /* clear error bits in status register */
329 writel(PCI_ISR_PSE | PCI_ISR_PFE | PCI_ISR_PPE | PCI_ISR_AHBE,
330 PCI_CSR_BASE + PCI_ISR_OFFSET);
333 * Set Initialize Complete in PCI Control Register: allow IXP4XX to
334 * respond to PCI configuration cycles.
337 writel(csr, PCI_CSR_BASE + PCI_CSR_OFFSET);
339 hose->first_busno = 0;
340 hose->last_busno = 0;
342 /* System memory space */
343 pci_set_region(hose->regions + 0,
345 PCI_MEMORY_PHY, PCI_MEMORY_SIZE, PCI_REGION_SYS_MEMORY);
347 /* PCI memory space */
348 pci_set_region(hose->regions + 1,
350 PCI_MEM_PHY, PCI_MEM_SIZE, PCI_REGION_MEM);
352 pci_set_region(hose->regions + 2,
353 PCI_IO_BUS, PCI_IO_PHY, PCI_IO_SIZE, PCI_REGION_IO);
355 hose->region_count = 3;
358 pci_ixp_hose_read_config_byte,
359 pci_ixp_hose_read_config_word,
360 pci_ixp_hose_read_config_dword,
361 pci_ixp_hose_write_config_byte,
362 pci_ixp_hose_write_config_word,
363 pci_ixp_hose_write_config_dword);
365 pci_register_hose(hose);
366 hose->last_busno = pci_hose_scan(hose);