Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 4 | * Marius Groeger <mgroeger@sysgo.de> |
| 5 | * |
| 6 | * (C) Copyright 2002 |
| 7 | * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch> |
| 8 | * |
| 9 | * (C) Copyright 2003 |
| 10 | * Texas Instruments, <www.ti.com> |
| 11 | * Kshitij Gupta <Kshitij@ti.com> |
| 12 | * |
| 13 | * (C) Copyright 2004 |
| 14 | * ARM Ltd. |
| 15 | * Philippe Robin, <philippe.robin@arm.com> |
| 16 | * |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 17 | * (C) Copyright 2011 |
| 18 | * Linaro |
| 19 | * Linus Walleij <linus.walleij@linaro.org> |
| 20 | * |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 21 | * See file CREDITS for list of people who contributed to this |
| 22 | * project. |
| 23 | * |
| 24 | * This program is free software; you can redistribute it and/or |
| 25 | * modify it under the terms of the GNU General Public License as |
| 26 | * published by the Free Software Foundation; either version 2 of |
| 27 | * the License, or (at your option) any later version. |
| 28 | * |
| 29 | * This program is distributed in the hope that it will be useful, |
| 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 32 | * GNU General Public License for more details. |
| 33 | * |
| 34 | * You should have received a copy of the GNU General Public License |
| 35 | * along with this program; if not, write to the Free Software |
| 36 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 37 | * MA 02111-1307 USA |
| 38 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 39 | #include <common.h> |
| 40 | #include <pci.h> |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 41 | #include <asm/io.h> |
| 42 | #include "integrator-sc.h" |
| 43 | #include "pci_v3.h" |
| 44 | |
| 45 | #define INTEGRATOR_BOOT_ROM_BASE 0x20000000 |
| 46 | #define INTEGRATOR_HDR0_SDRAM_BASE 0x80000000 |
| 47 | |
| 48 | /* |
| 49 | * These are in the physical addresses on the CPU side, i.e. |
| 50 | * where we read and write stuff - you don't want to try to |
| 51 | * move these around |
| 52 | */ |
| 53 | #define PHYS_PCI_MEM_BASE 0x40000000 |
| 54 | #define PHYS_PCI_IO_BASE 0x60000000 /* PCI I/O space base */ |
| 55 | #define PHYS_PCI_CONFIG_BASE 0x61000000 |
| 56 | #define PHYS_PCI_V3_BASE 0x62000000 /* V360EPC registers */ |
| 57 | #define SZ_256M 0x10000000 |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 58 | |
| 59 | /* |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 60 | * These are in the PCI BUS address space |
| 61 | * Set to 0x00000000 in the Linux kernel, 0x40000000 in Boot monitor |
| 62 | * we follow the example of the kernel, because that is the address |
| 63 | * range that devices actually use - what would they be doing at |
| 64 | * 0x40000000? |
| 65 | */ |
| 66 | #define PCI_BUS_NONMEM_START 0x00000000 |
| 67 | #define PCI_BUS_NONMEM_SIZE SZ_256M |
| 68 | |
| 69 | #define PCI_BUS_PREMEM_START (PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE) |
| 70 | #define PCI_BUS_PREMEM_SIZE SZ_256M |
| 71 | |
| 72 | #if PCI_BUS_NONMEM_START & 0x000fffff |
| 73 | #error PCI_BUS_NONMEM_START must be megabyte aligned |
| 74 | #endif |
| 75 | #if PCI_BUS_PREMEM_START & 0x000fffff |
| 76 | #error PCI_BUS_PREMEM_START must be megabyte aligned |
| 77 | #endif |
| 78 | |
| 79 | /* |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 80 | * Initialize PCI Devices, report devices found. |
| 81 | */ |
| 82 | |
| 83 | #ifndef CONFIG_PCI_PNP |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 84 | #define PCI_ENET0_IOADDR 0x60000000 /* First card in PCI I/O space */ |
| 85 | #define PCI_ENET0_MEMADDR 0x40000000 /* First card in PCI memory space */ |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 86 | static struct pci_config_table pci_integrator_config_table[] = { |
| 87 | { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0f, PCI_ANY_ID, |
| 88 | pci_cfgfunc_config_device, { PCI_ENET0_IOADDR, |
| 89 | PCI_ENET0_MEMADDR, |
| 90 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }}, |
| 91 | { } |
| 92 | }; |
| 93 | #endif /* CONFIG_PCI_PNP */ |
| 94 | |
| 95 | /* V3 access routines */ |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 96 | #define v3_writeb(o, v) __raw_writeb(v, PHYS_PCI_V3_BASE + (unsigned int)(o)) |
| 97 | #define v3_readb(o) (__raw_readb(PHYS_PCI_V3_BASE + (unsigned int)(o))) |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 98 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 99 | #define v3_writew(o, v) __raw_writew(v, PHYS_PCI_V3_BASE + (unsigned int)(o)) |
| 100 | #define v3_readw(o) (__raw_readw(PHYS_PCI_V3_BASE + (unsigned int)(o))) |
| 101 | |
| 102 | #define v3_writel(o, v) __raw_writel(v, PHYS_PCI_V3_BASE + (unsigned int)(o)) |
| 103 | #define v3_readl(o) (__raw_readl(PHYS_PCI_V3_BASE + (unsigned int)(o))) |
| 104 | |
| 105 | static unsigned long v3_open_config_window(pci_dev_t bdf, int offset) |
| 106 | { |
| 107 | unsigned int address, mapaddress; |
| 108 | unsigned int busnr = PCI_BUS(bdf); |
| 109 | unsigned int devfn = PCI_FUNC(bdf); |
| 110 | |
| 111 | /* |
| 112 | * Trap out illegal values |
| 113 | */ |
| 114 | if (offset > 255) |
| 115 | BUG(); |
| 116 | if (busnr > 255) |
| 117 | BUG(); |
| 118 | if (devfn > 255) |
| 119 | BUG(); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 120 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 121 | if (busnr == 0) { |
| 122 | /* |
| 123 | * Linux calls the thing U-Boot calls "DEV" "SLOT" |
| 124 | * instead, but it's the same 5 bits |
| 125 | */ |
| 126 | int slot = PCI_DEV(bdf); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 127 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 128 | /* |
| 129 | * local bus segment so need a type 0 config cycle |
| 130 | * |
| 131 | * build the PCI configuration "address" with one-hot in |
| 132 | * A31-A11 |
| 133 | * |
| 134 | * mapaddress: |
| 135 | * 3:1 = config cycle (101) |
| 136 | * 0 = PCI A1 & A0 are 0 (0) |
| 137 | */ |
| 138 | address = PCI_FUNC(bdf) << 8; |
| 139 | mapaddress = V3_LB_MAP_TYPE_CONFIG; |
| 140 | |
| 141 | if (slot > 12) |
| 142 | /* |
| 143 | * high order bits are handled by the MAP register |
| 144 | */ |
| 145 | mapaddress |= 1 << (slot - 5); |
| 146 | else |
| 147 | /* |
| 148 | * low order bits handled directly in the address |
| 149 | */ |
| 150 | address |= 1 << (slot + 11); |
| 151 | } else { |
| 152 | /* |
| 153 | * not the local bus segment so need a type 1 config cycle |
| 154 | * |
| 155 | * address: |
| 156 | * 23:16 = bus number |
| 157 | * 15:11 = slot number (7:3 of devfn) |
| 158 | * 10:8 = func number (2:0 of devfn) |
| 159 | * |
| 160 | * mapaddress: |
| 161 | * 3:1 = config cycle (101) |
| 162 | * 0 = PCI A1 & A0 from host bus (1) |
| 163 | */ |
| 164 | mapaddress = V3_LB_MAP_TYPE_CONFIG | V3_LB_MAP_AD_LOW_EN; |
| 165 | address = (busnr << 16) | (devfn << 8); |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * Set up base0 to see all 512Mbytes of memory space (not |
| 170 | * prefetchable), this frees up base1 for re-use by |
| 171 | * configuration memory |
| 172 | */ |
| 173 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) | |
| 174 | V3_LB_BASE_ADR_SIZE_512MB | V3_LB_BASE_ENABLE); |
| 175 | |
| 176 | /* |
| 177 | * Set up base1/map1 to point into configuration space. |
| 178 | */ |
| 179 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_CONFIG_BASE) | |
| 180 | V3_LB_BASE_ADR_SIZE_16MB | V3_LB_BASE_ENABLE); |
| 181 | v3_writew(V3_LB_MAP1, mapaddress); |
| 182 | |
| 183 | return PHYS_PCI_CONFIG_BASE + address + offset; |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 184 | } |
| 185 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 186 | static void v3_close_config_window(void) |
| 187 | { |
| 188 | /* |
| 189 | * Reassign base1 for use by prefetchable PCI memory |
| 190 | */ |
| 191 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) | |
| 192 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH | |
| 193 | V3_LB_BASE_ENABLE); |
| 194 | v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) | |
| 195 | V3_LB_MAP_TYPE_MEM_MULTIPLE); |
| 196 | |
| 197 | /* |
| 198 | * And shrink base0 back to a 256M window (NOTE: MAP0 already correct) |
| 199 | */ |
| 200 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) | |
| 201 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 202 | } |
| 203 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 204 | static int pci_integrator_read_byte(struct pci_controller *hose, pci_dev_t bdf, |
| 205 | int offset, unsigned char *val) |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 206 | { |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 207 | unsigned long addr; |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 208 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 209 | addr = v3_open_config_window(bdf, offset); |
| 210 | *val = __raw_readb(addr); |
| 211 | v3_close_config_window(); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 215 | static int pci_integrator_read__word(struct pci_controller *hose, |
| 216 | pci_dev_t bdf, int offset, |
| 217 | unsigned short *val) |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 218 | { |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 219 | unsigned long addr; |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 220 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 221 | addr = v3_open_config_window(bdf, offset); |
| 222 | *val = __raw_readw(addr); |
| 223 | v3_close_config_window(); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 224 | return 0; |
| 225 | } |
| 226 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 227 | static int pci_integrator_read_dword(struct pci_controller *hose, |
| 228 | pci_dev_t bdf, int offset, |
| 229 | unsigned int *val) |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 230 | { |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 231 | unsigned long addr; |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 232 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 233 | addr = v3_open_config_window(bdf, offset); |
| 234 | *val = __raw_readl(addr); |
| 235 | v3_close_config_window(); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 236 | return 0; |
| 237 | } |
| 238 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 239 | static int pci_integrator_write_byte(struct pci_controller *hose, |
| 240 | pci_dev_t bdf, int offset, |
| 241 | unsigned char val) |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 242 | { |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 243 | unsigned long addr; |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 244 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 245 | addr = v3_open_config_window(bdf, offset); |
| 246 | __raw_writeb((u8)val, addr); |
| 247 | __raw_readb(addr); |
| 248 | v3_close_config_window(); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 249 | return 0; |
| 250 | } |
| 251 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 252 | static int pci_integrator_write_word(struct pci_controller *hose, |
| 253 | pci_dev_t bdf, int offset, |
| 254 | unsigned short val) |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 255 | { |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 256 | unsigned long addr; |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 257 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 258 | addr = v3_open_config_window(bdf, offset); |
| 259 | __raw_writew((u8)val, addr); |
| 260 | __raw_readw(addr); |
| 261 | v3_close_config_window(); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 265 | static int pci_integrator_write_dword(struct pci_controller *hose, |
| 266 | pci_dev_t bdf, int offset, |
| 267 | unsigned int val) |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 268 | { |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 269 | unsigned long addr; |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 270 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 271 | addr = v3_open_config_window(bdf, offset); |
| 272 | __raw_writel((u8)val, addr); |
| 273 | __raw_readl(addr); |
| 274 | v3_close_config_window(); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 275 | return 0; |
| 276 | } |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 277 | |
| 278 | struct pci_controller integrator_hose = { |
| 279 | #ifndef CONFIG_PCI_PNP |
| 280 | config_table: pci_integrator_config_table, |
| 281 | #endif |
| 282 | }; |
| 283 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 284 | void pci_init_board(void) |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 285 | { |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 286 | struct pci_controller *hose = &integrator_hose; |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 287 | u16 val; |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 288 | |
| 289 | /* setting this register will take the V3 out of reset */ |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 290 | __raw_writel(SC_PCI_PCIEN, SC_PCI); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 291 | |
Linus Walleij | 38ff13d | 2012-03-03 21:21:13 +0100 | [diff] [blame] | 292 | /* Wait for 230 ms (from spec) before accessing any V3 registers */ |
| 293 | mdelay(230); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 294 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 295 | /* Now write the Base I/O Address Word to PHYS_PCI_V3_BASE + 0x6E */ |
| 296 | v3_writew(V3_LB_IO_BASE, (PHYS_PCI_V3_BASE >> 16)); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 297 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 298 | /* Wait for the mailbox to settle */ |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 299 | do { |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 300 | v3_writeb(V3_MAIL_DATA, 0xAA); |
| 301 | v3_writeb(V3_MAIL_DATA + 4, 0x55); |
| 302 | } while (v3_readb(V3_MAIL_DATA) != 0xAA || |
| 303 | v3_readb(V3_MAIL_DATA + 4) != 0x55); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 304 | |
| 305 | /* Make sure that V3 register access is not locked, if it is, unlock it */ |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 306 | if (v3_readw(V3_SYSTEM) & V3_SYSTEM_M_LOCK) |
| 307 | v3_writew(V3_SYSTEM, 0xA05F); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 308 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 309 | /* |
| 310 | * Ensure that the slave accesses from PCI are disabled while we |
| 311 | * setup memory windows |
| 312 | */ |
| 313 | val = v3_readw(V3_PCI_CMD); |
| 314 | val &= ~(V3_COMMAND_M_MEM_EN | V3_COMMAND_M_IO_EN); |
| 315 | v3_writew(V3_PCI_CMD, val); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 316 | |
| 317 | /* Clear RST_OUT to 0; keep the PCI bus in reset until we've finished */ |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 318 | val = v3_readw(V3_SYSTEM); |
| 319 | val &= ~V3_SYSTEM_M_RST_OUT; |
| 320 | v3_writew(V3_SYSTEM, val); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 321 | |
| 322 | /* Make all accesses from PCI space retry until we're ready for them */ |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 323 | val = v3_readw(V3_PCI_CFG); |
| 324 | val |= V3_PCI_CFG_M_RETRY_EN; |
| 325 | v3_writew(V3_PCI_CFG, val); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 326 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 327 | /* |
| 328 | * Set up any V3 PCI Configuration Registers that we absolutely have to. |
| 329 | * LB_CFG controls Local Bus protocol. |
| 330 | * Enable LocalBus byte strobes for READ accesses too. |
| 331 | * set bit 7 BE_IMODE and bit 6 BE_OMODE |
| 332 | */ |
| 333 | val = v3_readw(V3_LB_CFG); |
| 334 | val |= 0x0C0; |
| 335 | v3_writew(V3_LB_CFG, val); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 336 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 337 | /* PCI_CMD controls overall PCI operation. Enable PCI bus master. */ |
| 338 | val = v3_readw(V3_PCI_CMD); |
| 339 | val |= V3_COMMAND_M_MASTER_EN; |
| 340 | v3_writew(V3_PCI_CMD, val); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 341 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 342 | /* |
| 343 | * PCI_MAP0 controls where the PCI to CPU memory window is on |
| 344 | * Local Bus |
| 345 | */ |
| 346 | v3_writel(V3_PCI_MAP0, |
| 347 | (INTEGRATOR_BOOT_ROM_BASE) | (V3_PCI_MAP_M_ADR_SIZE_512MB | |
| 348 | V3_PCI_MAP_M_REG_EN | |
| 349 | V3_PCI_MAP_M_ENABLE)); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 350 | |
| 351 | /* PCI_BASE0 is the PCI address of the start of the window */ |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 352 | v3_writel(V3_PCI_BASE0, INTEGRATOR_BOOT_ROM_BASE); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 353 | |
| 354 | /* PCI_MAP1 is LOCAL address of the start of the window */ |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 355 | v3_writel(V3_PCI_MAP1, |
| 356 | (INTEGRATOR_HDR0_SDRAM_BASE) | (V3_PCI_MAP_M_ADR_SIZE_1GB | |
| 357 | V3_PCI_MAP_M_REG_EN | |
| 358 | V3_PCI_MAP_M_ENABLE)); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 359 | |
| 360 | /* PCI_BASE1 is the PCI address of the start of the window */ |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 361 | v3_writel(V3_PCI_BASE1, INTEGRATOR_HDR0_SDRAM_BASE); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 362 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 363 | /* |
| 364 | * Set up memory the windows from local bus memory into PCI |
| 365 | * configuration, I/O and Memory regions. |
| 366 | * PCI I/O, LB_BASE2 and LB_MAP2 are used exclusively for this. |
| 367 | */ |
| 368 | v3_writew(V3_LB_BASE2, |
| 369 | v3_addr_to_lb_map(PHYS_PCI_IO_BASE) | V3_LB_BASE_ENABLE); |
| 370 | v3_writew(V3_LB_MAP2, 0); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 371 | |
| 372 | /* PCI Configuration, use LB_BASE1/LB_MAP1. */ |
| 373 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 374 | /* |
| 375 | * PCI Memory use LB_BASE0/LB_MAP0 and LB_BASE1/LB_MAP1 |
| 376 | * Map first 256Mbytes as non-prefetchable via BASE0/MAP0 |
| 377 | */ |
| 378 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) | |
| 379 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE); |
| 380 | v3_writew(V3_LB_MAP0, |
| 381 | v3_addr_to_lb_map(PCI_BUS_NONMEM_START) | V3_LB_MAP_TYPE_MEM); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 382 | |
| 383 | /* Map second 256 Mbytes as prefetchable via BASE1/MAP1 */ |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 384 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) | |
| 385 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH | |
| 386 | V3_LB_BASE_ENABLE); |
| 387 | v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) | |
| 388 | V3_LB_MAP_TYPE_MEM_MULTIPLE); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 389 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 390 | /* Dump PCI to local address space mappings */ |
| 391 | debug("LB_BASE0 = %08x\n", v3_readl(V3_LB_BASE0)); |
| 392 | debug("LB_MAP0 = %04x\n", v3_readw(V3_LB_MAP0)); |
| 393 | debug("LB_BASE1 = %08x\n", v3_readl(V3_LB_BASE1)); |
| 394 | debug("LB_MAP1 = %04x\n", v3_readw(V3_LB_MAP1)); |
| 395 | debug("LB_BASE2 = %04x\n", v3_readw(V3_LB_BASE2)); |
| 396 | debug("LB_MAP2 = %04x\n", v3_readw(V3_LB_MAP2)); |
| 397 | debug("LB_IO_BASE = %04x\n", v3_readw(V3_LB_IO_BASE)); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 398 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 399 | /* |
| 400 | * Allow accesses to PCI Configuration space and set up A1, A0 for |
| 401 | * type 1 config cycles |
| 402 | */ |
| 403 | val = v3_readw(V3_PCI_CFG); |
| 404 | val &= ~(V3_PCI_CFG_M_RETRY_EN | V3_PCI_CFG_M_AD_LOW1); |
| 405 | val |= V3_PCI_CFG_M_AD_LOW0; |
| 406 | v3_writew(V3_PCI_CFG, val); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 407 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 408 | /* now we can allow incoming PCI MEMORY accesses */ |
| 409 | val = v3_readw(V3_PCI_CMD); |
| 410 | val |= V3_COMMAND_M_MEM_EN; |
| 411 | v3_writew(V3_PCI_CMD, val); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 412 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 413 | /* |
| 414 | * Set RST_OUT to take the PCI bus is out of reset, PCI devices can |
| 415 | * now initialise. |
| 416 | */ |
| 417 | val = v3_readw(V3_SYSTEM); |
| 418 | val |= V3_SYSTEM_M_RST_OUT; |
| 419 | v3_writew(V3_SYSTEM, val); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 420 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 421 | /* Lock the V3 system register so that no one else can play with it */ |
| 422 | val = v3_readw(V3_SYSTEM); |
| 423 | val |= V3_SYSTEM_M_LOCK; |
| 424 | v3_writew(V3_SYSTEM, val); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 425 | |
| 426 | /* |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 427 | * Configure and register the PCI hose |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 428 | */ |
| 429 | hose->first_busno = 0; |
| 430 | hose->last_busno = 0xff; |
| 431 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 432 | /* System memory space, window 0 256 MB non-prefetchable */ |
| 433 | pci_set_region(hose->regions + 0, |
| 434 | PCI_BUS_NONMEM_START, PHYS_PCI_MEM_BASE, |
| 435 | SZ_256M, |
| 436 | PCI_REGION_MEM); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 437 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 438 | /* System memory space, window 1 256 MB prefetchable */ |
| 439 | pci_set_region(hose->regions + 1, |
| 440 | PCI_BUS_PREMEM_START, PHYS_PCI_MEM_BASE + SZ_256M, |
| 441 | SZ_256M, |
| 442 | PCI_REGION_MEM | |
| 443 | PCI_REGION_PREFETCH); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 444 | |
| 445 | /* PCI I/O space */ |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 446 | pci_set_region(hose->regions + 2, |
| 447 | 0x00000000, PHYS_PCI_IO_BASE, 0x01000000, |
| 448 | PCI_REGION_IO); |
| 449 | |
| 450 | /* PCI Memory - config space */ |
| 451 | pci_set_region(hose->regions + 3, |
| 452 | 0x00000000, PHYS_PCI_CONFIG_BASE, 0x01000000, |
| 453 | PCI_REGION_MEM); |
| 454 | /* PCI V3 regs */ |
| 455 | pci_set_region(hose->regions + 4, |
| 456 | 0x00000000, PHYS_PCI_V3_BASE, 0x01000000, |
| 457 | PCI_REGION_MEM); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 458 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 459 | hose->region_count = 5; |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 460 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 461 | pci_set_ops(hose, |
| 462 | pci_integrator_read_byte, |
| 463 | pci_integrator_read__word, |
| 464 | pci_integrator_read_dword, |
| 465 | pci_integrator_write_byte, |
| 466 | pci_integrator_write_word, |
| 467 | pci_integrator_write_dword); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 468 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 469 | pci_register_hose(hose); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 470 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 471 | pciauto_config_init(hose); |
| 472 | pciauto_config_device(hose, 0); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 473 | |
Linus Walleij | d222d1b | 2012-01-30 13:49:34 +0000 | [diff] [blame] | 474 | hose->last_busno = pci_hose_scan(hose); |
Jean-Christophe PLAGNIOL-VILLARD | 29383e5 | 2009-05-17 00:58:36 +0200 | [diff] [blame] | 475 | } |