wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * IXP PCI Init |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 3 | * |
| 4 | * (C) Copyright 2011 |
| 5 | * Michael Schwingen, michael@schwingen.org |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 6 | * (C) Copyright 2004 eslab.whut.edu.cn |
| 7 | * Yue Hu(huyue_whut@yahoo.com.cn), Ligong Xue(lgxue@hotmail.com) |
| 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 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. |
| 16 | * |
| 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. |
| 21 | * |
| 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, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 28 | #include <common.h> |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 29 | #include <asm/processor.h> |
| 30 | #include <asm/io.h> |
| 31 | #include <pci.h> |
| 32 | #include <asm/arch/ixp425.h> |
| 33 | #include <asm/arch/ixp425pci.h> |
| 34 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
| 37 | static void non_prefetch_read(unsigned int addr, unsigned int cmd, |
| 38 | unsigned int *data); |
| 39 | static void non_prefetch_write(unsigned int addr, unsigned int cmd, |
| 40 | unsigned int data); |
| 41 | |
| 42 | /*define the sub vendor and subsystem to be used */ |
| 43 | #define IXP425_PCI_SUB_VENDOR_SYSTEM 0x00000000 |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 44 | |
| 45 | #define PCI_MEMORY_BUS 0x00000000 |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 46 | #define PCI_MEMORY_PHY 0x00000000 |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 47 | #define PCI_MEMORY_SIZE 0x04000000 |
| 48 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 49 | #define PCI_MEM_BUS 0x48000000 |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 50 | #define PCI_MEM_PHY 0x00000000 |
| 51 | #define PCI_MEM_SIZE 0x04000000 |
| 52 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 53 | #define PCI_IO_BUS 0x00000000 |
| 54 | #define PCI_IO_PHY 0x00000000 |
| 55 | #define PCI_IO_SIZE 0x00010000 |
| 56 | |
| 57 | /* build address value for config sycle */ |
| 58 | static unsigned int pci_config_addr(pci_dev_t bdf, unsigned int reg) |
| 59 | { |
| 60 | unsigned int bus = PCI_BUS(bdf); |
| 61 | unsigned int dev = PCI_DEV(bdf); |
| 62 | unsigned int func = PCI_FUNC(bdf); |
| 63 | unsigned int addr; |
| 64 | |
| 65 | if (bus) { /* secondary bus, use type 1 config cycle */ |
| 66 | addr = bdf | (reg & ~3) | 1; |
| 67 | } else { |
| 68 | /* |
| 69 | primary bus, type 0 config cycle. address bits 31:28 |
| 70 | specify the device 10:8 specify the function |
| 71 | */ |
| 72 | addr = BIT((31 - dev)) | (func << 8) | (reg & ~3); |
| 73 | } |
| 74 | |
| 75 | return addr; |
| 76 | } |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 77 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 78 | static int pci_config_status(void) |
| 79 | { |
| 80 | unsigned int regval; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 81 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 82 | regval = readl(PCI_CSR_BASE + PCI_ISR_OFFSET); |
| 83 | if ((regval & PCI_ISR_PFE) == 0) |
| 84 | return OK; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 85 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 86 | /* no device present, make sure that the master abort bit is reset */ |
| 87 | writel(PCI_ISR_PFE, PCI_CSR_BASE + PCI_ISR_OFFSET); |
| 88 | return ERROR; |
| 89 | } |
| 90 | |
| 91 | static int pci_ixp_hose_read_config_dword(struct pci_controller *hose, |
| 92 | pci_dev_t bdf, int where, unsigned int *val) |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 93 | { |
| 94 | unsigned int retval; |
| 95 | unsigned int addr; |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 96 | int stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 97 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 98 | debug("pci_ixp_hose_read_config_dword: bdf %x, reg %x", bdf, where); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 99 | /*Set the address to be read */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 100 | addr = pci_config_addr(bdf, where); |
| 101 | non_prefetch_read(addr, NP_CMD_CONFIGREAD, &retval); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 102 | *val = retval; |
| 103 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 104 | stat = pci_config_status(); |
| 105 | if (stat < 0) |
| 106 | *val = -1; |
| 107 | debug("-> val %x, status %x\n", *val, stat); |
| 108 | return stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 111 | static int pci_ixp_hose_read_config_word(struct pci_controller *hose, |
| 112 | pci_dev_t bdf, int where, unsigned short *val) |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 113 | { |
| 114 | unsigned int n; |
| 115 | unsigned int retval; |
| 116 | unsigned int addr; |
| 117 | unsigned int byteEnables; |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 118 | int stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 119 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 120 | debug("pci_ixp_hose_read_config_word: bdf %x, reg %x", bdf, where); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 121 | n = where % 4; |
| 122 | /*byte enables are 4 bits active low, the position of each |
| 123 | bit maps to the byte that it enables */ |
| 124 | byteEnables = |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 125 | (~(BIT(n) | BIT((n + 1)))) & |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 126 | IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK; |
| 127 | byteEnables = byteEnables << PCI_NP_CBE_BESL; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 128 | /*Set the address to be read */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 129 | addr = pci_config_addr(bdf, where); |
| 130 | non_prefetch_read(addr, byteEnables | NP_CMD_CONFIGREAD, &retval); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 131 | |
| 132 | /*Pick out the word we are interested in */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 133 | *val = retval >> (8 * n); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 134 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 135 | stat = pci_config_status(); |
| 136 | if (stat < 0) |
| 137 | *val = -1; |
| 138 | debug("-> val %x, status %x\n", *val, stat); |
| 139 | return stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 142 | static int pci_ixp_hose_read_config_byte(struct pci_controller *hose, |
| 143 | pci_dev_t bdf, int where, unsigned char *val) |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 144 | { |
| 145 | unsigned int retval; |
| 146 | unsigned int n; |
| 147 | unsigned int byteEnables; |
| 148 | unsigned int addr; |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 149 | int stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 150 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 151 | debug("pci_ixp_hose_read_config_byte: bdf %x, reg %x", bdf, where); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 152 | n = where % 4; |
| 153 | /*byte enables are 4 bits, active low, the position of each |
| 154 | bit maps to the byte that it enables */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 155 | byteEnables = (~BIT(n)) & IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 156 | byteEnables = byteEnables << PCI_NP_CBE_BESL; |
| 157 | |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 158 | /*Set the address to be read */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 159 | addr = pci_config_addr(bdf, where); |
| 160 | non_prefetch_read(addr, byteEnables | NP_CMD_CONFIGREAD, &retval); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 161 | /*Pick out the byte we are interested in */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 162 | *val = retval >> (8 * n); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 163 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 164 | stat = pci_config_status(); |
| 165 | if (stat < 0) |
| 166 | *val = -1; |
| 167 | debug("-> val %x, status %x\n", *val, stat); |
| 168 | return stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 171 | static int pci_ixp_hose_write_config_byte(struct pci_controller *hose, |
| 172 | pci_dev_t bdf, int where, unsigned char val) |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 173 | { |
| 174 | unsigned int addr; |
| 175 | unsigned int byteEnables; |
| 176 | unsigned int n; |
| 177 | unsigned int ldata; |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 178 | int stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 179 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 180 | debug("pci_ixp_hose_write_config_byte: bdf %x, reg %x, val %x", |
| 181 | bdf, where, val); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 182 | n = where % 4; |
| 183 | /*byte enables are 4 bits active low, the position of each |
| 184 | bit maps to the byte that it enables */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 185 | byteEnables = (~BIT(n)) & IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 186 | byteEnables = byteEnables << PCI_NP_CBE_BESL; |
| 187 | ldata = val << (8 * n); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 188 | /*Set the address to be written */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 189 | addr = pci_config_addr(bdf, where); |
| 190 | non_prefetch_write(addr, byteEnables | NP_CMD_CONFIGWRITE, ldata); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 191 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 192 | stat = pci_config_status(); |
| 193 | debug("-> status %x\n", stat); |
| 194 | return stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 197 | static int pci_ixp_hose_write_config_word(struct pci_controller *hose, |
| 198 | pci_dev_t bdf, int where, unsigned short val) |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 199 | { |
| 200 | unsigned int addr; |
| 201 | unsigned int byteEnables; |
| 202 | unsigned int n; |
| 203 | unsigned int ldata; |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 204 | int stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 205 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 206 | debug("pci_ixp_hose_write_config_word: bdf %x, reg %x, val %x", |
| 207 | bdf, where, val); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 208 | n = where % 4; |
| 209 | /*byte enables are 4 bits active low, the position of each |
| 210 | bit maps to the byte that it enables */ |
| 211 | byteEnables = |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 212 | (~(BIT(n) | BIT((n + 1)))) & |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 213 | IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK; |
| 214 | byteEnables = byteEnables << PCI_NP_CBE_BESL; |
| 215 | ldata = val << (8 * n); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 216 | /*Set the address to be written */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 217 | addr = pci_config_addr(bdf, where); |
| 218 | non_prefetch_write(addr, byteEnables | NP_CMD_CONFIGWRITE, ldata); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 219 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 220 | stat = pci_config_status(); |
| 221 | debug("-> status %x\n", stat); |
| 222 | return stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 225 | static int pci_ixp_hose_write_config_dword(struct pci_controller *hose, |
| 226 | pci_dev_t bdf, int where, unsigned int val) |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 227 | { |
| 228 | unsigned int addr; |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 229 | int stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 230 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 231 | debug("pci_ixp_hose_write_config_dword: bdf %x, reg %x, val %x", |
| 232 | bdf, where, val); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 233 | /*Set the address to be written */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 234 | addr = pci_config_addr(bdf, where); |
| 235 | non_prefetch_write(addr, NP_CMD_CONFIGWRITE, val); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 236 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 237 | stat = pci_config_status(); |
| 238 | debug("-> status %x\n", stat); |
| 239 | return stat; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 242 | static void non_prefetch_read(unsigned int addr, |
| 243 | unsigned int cmd, unsigned int *data) |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 244 | { |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 245 | writel(addr, PCI_CSR_BASE + PCI_NP_AD_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 246 | |
| 247 | /*set up and execute the read */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 248 | writel(cmd, PCI_CSR_BASE + PCI_NP_CBE_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 249 | |
| 250 | /*The result of the read is now in np_rdata */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 251 | *data = readl(PCI_CSR_BASE + PCI_NP_RDATA_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 252 | |
| 253 | return; |
| 254 | } |
| 255 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 256 | static void non_prefetch_write(unsigned int addr, |
| 257 | unsigned int cmd, unsigned int data) |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 258 | { |
| 259 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 260 | writel(addr, PCI_CSR_BASE + PCI_NP_AD_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 261 | /*set up the write */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 262 | writel(cmd, PCI_CSR_BASE + PCI_NP_CBE_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 263 | /*Execute the write by writing to NP_WDATA */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 264 | writel(data, PCI_CSR_BASE + PCI_NP_WDATA_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 265 | |
| 266 | return; |
| 267 | } |
| 268 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 269 | static void crp_write(unsigned int offset, unsigned int data) |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 270 | { |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 271 | /* |
| 272 | * The CRP address register bit 16 indicates that we want to do a |
| 273 | * write |
| 274 | */ |
| 275 | writel(PCI_CRP_WRITE | offset, PCI_CSR_BASE + PCI_CRP_AD_CBE_OFFSET); |
| 276 | writel(data, PCI_CSR_BASE + PCI_CRP_WDATA_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 279 | void pci_ixp_init(struct pci_controller *hose) |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 280 | { |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 281 | unsigned int csr; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 282 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 283 | /* |
| 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 |
| 286 | * AHB bus |
| 287 | */ |
| 288 | #ifdef __ARMEB__ |
| 289 | csr = PCI_CSR_ABE | PCI_CSR_PDS | PCI_CSR_ADS; |
| 290 | #else |
| 291 | csr = PCI_CSR_ABE; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 292 | #endif |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 293 | writel(csr, PCI_CSR_BASE + PCI_CSR_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 294 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 295 | writel(0, PCI_CSR_BASE + PCI_INTEN_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 296 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 297 | /* |
| 298 | * We configure the PCI inbound memory windows to be |
| 299 | * 1:1 mapped to SDRAM |
| 300 | */ |
| 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); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 305 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 306 | /* |
| 307 | * Enable CSR window at 64 MiB to allow PCI masters |
| 308 | * to continue prefetching past 64 MiB boundary. |
| 309 | */ |
| 310 | crp_write(PCI_CFG_BASE_ADDRESS_4, 0x04000000); |
| 311 | /* |
| 312 | * Enable the IO window to be way up high, at 0xfffffc00 |
| 313 | */ |
| 314 | crp_write(PCI_CFG_BASE_ADDRESS_5, 0xfffffc01); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 315 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 316 | /*Setup PCI-AHB and AHB-PCI address mappings */ |
| 317 | writel(0x00010203, PCI_CSR_BASE + PCI_AHBMEMBASE_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 318 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 319 | writel(0x00000000, PCI_CSR_BASE + PCI_AHBIOBASE_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 320 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 321 | writel(0x48494a4b, PCI_CSR_BASE + PCI_PCIMEMBASE_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 322 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 323 | crp_write(PCI_CFG_SUB_VENDOR_ID, IXP425_PCI_SUB_VENDOR_SYSTEM); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 324 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 325 | crp_write(PCI_CFG_COMMAND, PCI_CFG_CMD_MAE | PCI_CFG_CMD_BME); |
| 326 | udelay(1000); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 327 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 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); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 331 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 332 | /* |
| 333 | * Set Initialize Complete in PCI Control Register: allow IXP4XX to |
| 334 | * respond to PCI configuration cycles. |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 335 | */ |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 336 | csr |= PCI_CSR_IC; |
| 337 | writel(csr, PCI_CSR_BASE + PCI_CSR_OFFSET); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 338 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 339 | hose->first_busno = 0; |
| 340 | hose->last_busno = 0; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 341 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 342 | /* System memory space */ |
| 343 | pci_set_region(hose->regions + 0, |
| 344 | PCI_MEMORY_BUS, |
| 345 | PCI_MEMORY_PHY, PCI_MEMORY_SIZE, PCI_REGION_SYS_MEMORY); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 346 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 347 | /* PCI memory space */ |
| 348 | pci_set_region(hose->regions + 1, |
| 349 | PCI_MEM_BUS, |
| 350 | PCI_MEM_PHY, PCI_MEM_SIZE, PCI_REGION_MEM); |
| 351 | /* PCI I/O space */ |
| 352 | pci_set_region(hose->regions + 2, |
| 353 | PCI_IO_BUS, PCI_IO_PHY, PCI_IO_SIZE, PCI_REGION_IO); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 354 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 355 | hose->region_count = 3; |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 356 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 357 | pci_set_ops(hose, |
| 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); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 364 | |
Michael Schwingen | b9de2fa | 2011-05-23 00:00:12 +0200 | [diff] [blame] | 365 | pci_register_hose(hose); |
| 366 | hose->last_busno = pci_hose_scan(hose); |
wdenk | 26c5843 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 367 | } |