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