Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1 | /* |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 2 | * (C) Copyright 2006 - 2008 |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * Copyright (c) 2005 Cisco Systems. All rights reserved. |
| 6 | * Roland Dreier <rolandd@cisco.com> |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | */ |
| 22 | |
Stefan Roese | 3dced49 | 2007-10-05 07:57:20 +0200 | [diff] [blame] | 23 | /* define DEBUG for debugging output (obviously ;-)) */ |
Stefan Roese | db4f454 | 2007-10-05 09:22:33 +0200 | [diff] [blame] | 24 | #if 0 |
Stefan Roese | 3dced49 | 2007-10-05 07:57:20 +0200 | [diff] [blame] | 25 | #define DEBUG |
| 26 | #endif |
| 27 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 28 | #include <common.h> |
| 29 | #include <pci.h> |
Stefan Roese | 7105abd | 2008-07-10 11:38:26 +0200 | [diff] [blame] | 30 | #include <ppc4xx.h> |
| 31 | #include <asm/processor.h> |
| 32 | #include <asm-ppc/io.h> |
Stefan Roese | 14fd12f | 2009-10-02 14:35:16 +0200 | [diff] [blame] | 33 | #include <asm/errno.h> |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 34 | |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 35 | #if (defined(CONFIG_440SPE) || defined(CONFIG_405EX) || \ |
| 36 | defined(CONFIG_460EX) || defined(CONFIG_460GT)) && \ |
Dirk Eibach | 6bb88a0 | 2009-02-03 15:15:21 +0100 | [diff] [blame] | 37 | defined(CONFIG_PCI) && !defined(CONFIG_PCI_DISABLE_PCIE) |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 38 | |
Stefan Roese | 216f063 | 2007-10-03 07:34:10 +0200 | [diff] [blame] | 39 | #include <asm/4xx_pcie.h> |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 40 | |
| 41 | enum { |
| 42 | PTYPE_ENDPOINT = 0x0, |
| 43 | PTYPE_LEGACY_ENDPOINT = 0x1, |
| 44 | PTYPE_ROOT_PORT = 0x4, |
| 45 | |
| 46 | LNKW_X1 = 0x1, |
| 47 | LNKW_X4 = 0x4, |
| 48 | LNKW_X8 = 0x8 |
| 49 | }; |
| 50 | |
Stefan Roese | e53b5cd | 2009-10-29 15:04:35 +0100 | [diff] [blame] | 51 | #if 1 // test-only |
| 52 | int board_pcie_first(void); |
| 53 | int board_pcie_last(void); |
| 54 | static struct pci_controller pcie_hose[CONFIG_SYS_PCIE_NR_PORTS]; |
| 55 | |
| 56 | /* |
| 57 | * Per default, all cards are present, so we need to check if the |
| 58 | * link comes up. |
| 59 | */ |
| 60 | int __board_pcie_card_present(int port) |
| 61 | { |
| 62 | return 1; |
| 63 | } |
| 64 | int board_pcie_card_present(int port) |
| 65 | __attribute__((weak, alias("__board_pcie_card_present"))); |
| 66 | |
| 67 | /* |
| 68 | * Some boards have runtime detection of the first and last PCIe |
| 69 | * slot used, so let's provide weak default functions for the |
| 70 | * common version. |
| 71 | */ |
| 72 | int __board_pcie_first(void) |
| 73 | { |
| 74 | return 0; |
| 75 | } |
| 76 | int board_pcie_first(void) |
| 77 | __attribute__((weak, alias("__board_pcie_first"))); |
| 78 | |
| 79 | int __board_pcie_last(void) |
| 80 | { |
| 81 | return CONFIG_SYS_PCIE_NR_PORTS - 1; |
| 82 | } |
| 83 | int board_pcie_last(void) |
| 84 | __attribute__((weak, alias("__board_pcie_last"))); |
| 85 | |
| 86 | void __board_pcie_setup_port(int port, int rootpoint) |
| 87 | { |
| 88 | /* noting in this weak default implementation */ |
| 89 | } |
| 90 | void board_pcie_setup_port(int port, int rootpoint) |
| 91 | __attribute__((weak, alias("__board_pcie_setup_port"))); |
| 92 | |
| 93 | void pcie_setup_hoses(int busno) |
| 94 | { |
| 95 | struct pci_controller *hose; |
| 96 | int i, bus; |
| 97 | int ret = 0; |
| 98 | char *env; |
| 99 | unsigned int delay; |
| 100 | int first = board_pcie_first(); |
| 101 | int last = board_pcie_last(); |
| 102 | |
| 103 | /* |
| 104 | * Assume we're called after the PCI(X) hose(s) are initialized, |
| 105 | * which takes bus ID 0... and therefore start numbering PCIe's |
| 106 | * from the next number. |
| 107 | */ |
| 108 | bus = busno; |
| 109 | |
| 110 | for (i = first; i <= last; i++) { |
| 111 | /* |
| 112 | * Some boards (e.g. Katmai) can detects via hardware |
| 113 | * if a PCIe card is plugged, so let's check this. |
| 114 | */ |
| 115 | if (!board_pcie_card_present(i)) |
| 116 | continue; |
| 117 | |
| 118 | if (is_end_point(i)) { |
| 119 | board_pcie_setup_port(i, 0); |
| 120 | ret = ppc4xx_init_pcie_endport(i); |
| 121 | } else { |
| 122 | board_pcie_setup_port(i, 1); |
| 123 | ret = ppc4xx_init_pcie_rootport(i); |
| 124 | } |
| 125 | if (ret == -ENODEV) |
| 126 | continue; |
| 127 | if (ret) { |
| 128 | printf("PCIE%d: initialization as %s failed\n", i, |
| 129 | is_end_point(i) ? "endpoint" : "root-complex"); |
| 130 | continue; |
| 131 | } |
| 132 | |
| 133 | hose = &pcie_hose[i]; |
| 134 | hose->first_busno = bus; |
| 135 | hose->last_busno = bus; |
| 136 | hose->current_busno = bus; |
| 137 | |
| 138 | /* setup mem resource */ |
| 139 | pci_set_region(hose->regions + 0, |
| 140 | CONFIG_SYS_PCIE_MEMBASE + i * CONFIG_SYS_PCIE_MEMSIZE, |
| 141 | CONFIG_SYS_PCIE_MEMBASE + i * CONFIG_SYS_PCIE_MEMSIZE, |
| 142 | CONFIG_SYS_PCIE_MEMSIZE, |
| 143 | PCI_REGION_MEM); |
| 144 | hose->region_count = 1; |
| 145 | pci_register_hose(hose); |
| 146 | |
| 147 | if (is_end_point(i)) { |
| 148 | ppc4xx_setup_pcie_endpoint(hose, i); |
| 149 | /* |
| 150 | * Reson for no scanning is endpoint can not generate |
| 151 | * upstream configuration accesses. |
| 152 | */ |
| 153 | } else { |
| 154 | ppc4xx_setup_pcie_rootpoint(hose, i); |
| 155 | env = getenv ("pciscandelay"); |
| 156 | if (env != NULL) { |
| 157 | delay = simple_strtoul(env, NULL, 10); |
| 158 | if (delay > 5) |
| 159 | printf("Warning, expect noticable delay before " |
| 160 | "PCIe scan due to 'pciscandelay' value!\n"); |
| 161 | mdelay(delay * 1000); |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Config access can only go down stream |
| 166 | */ |
| 167 | hose->last_busno = pci_hose_scan(hose); |
| 168 | bus = hose->last_busno + 1; |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | #endif |
| 173 | |
Stefan Roese | 89bac40 | 2007-10-13 16:43:23 +0200 | [diff] [blame] | 174 | static int validate_endpoint(struct pci_controller *hose) |
| 175 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 176 | if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE0_CFGBASE) |
Stefan Roese | 89bac40 | 2007-10-13 16:43:23 +0200 | [diff] [blame] | 177 | return (is_end_point(0)); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 178 | else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE1_CFGBASE) |
Stefan Roese | 89bac40 | 2007-10-13 16:43:23 +0200 | [diff] [blame] | 179 | return (is_end_point(1)); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 180 | #if CONFIG_SYS_PCIE_NR_PORTS > 2 |
| 181 | else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE2_CFGBASE) |
Stefan Roese | 89bac40 | 2007-10-13 16:43:23 +0200 | [diff] [blame] | 182 | return (is_end_point(2)); |
| 183 | #endif |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 188 | static u8* pcie_get_base(struct pci_controller *hose, unsigned int devfn) |
| 189 | { |
| 190 | u8 *base = (u8*)hose->cfg_data; |
| 191 | |
| 192 | /* use local configuration space for the first bus */ |
| 193 | if (PCI_BUS(devfn) == 0) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 194 | if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE0_CFGBASE) |
| 195 | base = (u8*)CONFIG_SYS_PCIE0_XCFGBASE; |
| 196 | if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE1_CFGBASE) |
| 197 | base = (u8*)CONFIG_SYS_PCIE1_XCFGBASE; |
| 198 | #if CONFIG_SYS_PCIE_NR_PORTS > 2 |
| 199 | if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE2_CFGBASE) |
| 200 | base = (u8*)CONFIG_SYS_PCIE2_XCFGBASE; |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 201 | #endif |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | return base; |
| 205 | } |
| 206 | |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 207 | static void pcie_dmer_disable(void) |
Grzegorz Bernacki | d84fe30 | 2007-07-31 18:51:48 +0200 | [diff] [blame] | 208 | { |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 209 | mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE), |
| 210 | mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) | GPL_DMER_MASK_DISA); |
| 211 | mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE), |
| 212 | mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) | GPL_DMER_MASK_DISA); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 213 | #if CONFIG_SYS_PCIE_NR_PORTS > 2 |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 214 | mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE), |
| 215 | mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) | GPL_DMER_MASK_DISA); |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 216 | #endif |
Grzegorz Bernacki | d84fe30 | 2007-07-31 18:51:48 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 219 | static void pcie_dmer_enable(void) |
Grzegorz Bernacki | d84fe30 | 2007-07-31 18:51:48 +0200 | [diff] [blame] | 220 | { |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 221 | mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE0_BASE), |
| 222 | mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) & ~GPL_DMER_MASK_DISA); |
| 223 | mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE1_BASE), |
| 224 | mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) & ~GPL_DMER_MASK_DISA); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 225 | #if CONFIG_SYS_PCIE_NR_PORTS > 2 |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 226 | mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE2_BASE), |
| 227 | mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) & ~GPL_DMER_MASK_DISA); |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 228 | #endif |
Grzegorz Bernacki | d84fe30 | 2007-07-31 18:51:48 +0200 | [diff] [blame] | 229 | } |
| 230 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 231 | static int pcie_read_config(struct pci_controller *hose, unsigned int devfn, |
| 232 | int offset, int len, u32 *val) { |
| 233 | |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 234 | u8 *address; |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 235 | *val = 0; |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 236 | |
Stefan Roese | 89bac40 | 2007-10-13 16:43:23 +0200 | [diff] [blame] | 237 | if (validate_endpoint(hose)) |
| 238 | return 0; /* No upstream config access */ |
| 239 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 240 | /* |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 241 | * Bus numbers are relative to hose->first_busno |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 242 | */ |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 243 | devfn -= PCI_BDF(hose->first_busno, 0, 0); |
| 244 | |
| 245 | /* |
| 246 | * NOTICE: configuration space ranges are currenlty mapped only for |
| 247 | * the first 16 buses, so such limit must be imposed. In case more |
| 248 | * buses are required the TLB settings in board/amcc/<board>/init.S |
| 249 | * need to be altered accordingly (one bus takes 1 MB of memory space). |
| 250 | */ |
| 251 | if (PCI_BUS(devfn) >= 16) |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 252 | return 0; |
| 253 | |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 254 | /* |
| 255 | * Only single device/single function is supported for the primary and |
| 256 | * secondary buses of the 440SPe host bridge. |
| 257 | */ |
| 258 | if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) && |
| 259 | ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1))) |
| 260 | return 0; |
Stefan Roese | 43867c8 | 2007-10-02 11:44:46 +0200 | [diff] [blame] | 261 | |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 262 | address = pcie_get_base(hose, devfn); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 263 | offset += devfn << 4; |
| 264 | |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 265 | /* |
| 266 | * Reading from configuration space of non-existing device can |
| 267 | * generate transaction errors. For the read duration we suppress |
| 268 | * assertion of machine check exceptions to avoid those. |
| 269 | */ |
| 270 | pcie_dmer_disable (); |
| 271 | |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 272 | debug("%s: cfg_data=%08x offset=%08x\n", __func__, hose->cfg_data, offset); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 273 | switch (len) { |
| 274 | case 1: |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 275 | *val = in_8(hose->cfg_data + offset); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 276 | break; |
| 277 | case 2: |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 278 | *val = in_le16((u16 *)(hose->cfg_data + offset)); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 279 | break; |
| 280 | default: |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 281 | *val = in_le32((u32*)(hose->cfg_data + offset)); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 282 | break; |
| 283 | } |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 284 | |
| 285 | pcie_dmer_enable (); |
| 286 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | static int pcie_write_config(struct pci_controller *hose, unsigned int devfn, |
| 291 | int offset, int len, u32 val) { |
| 292 | |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 293 | u8 *address; |
Stefan Roese | 43867c8 | 2007-10-02 11:44:46 +0200 | [diff] [blame] | 294 | |
Stefan Roese | 89bac40 | 2007-10-13 16:43:23 +0200 | [diff] [blame] | 295 | if (validate_endpoint(hose)) |
| 296 | return 0; /* No upstream config access */ |
| 297 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 298 | /* |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 299 | * Bus numbers are relative to hose->first_busno |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 300 | */ |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 301 | devfn -= PCI_BDF(hose->first_busno, 0, 0); |
Stefan Roese | 43867c8 | 2007-10-02 11:44:46 +0200 | [diff] [blame] | 302 | |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 303 | /* |
| 304 | * Same constraints as in pcie_read_config(). |
| 305 | */ |
| 306 | if (PCI_BUS(devfn) >= 16) |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 307 | return 0; |
| 308 | |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 309 | if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) && |
| 310 | ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1))) |
| 311 | return 0; |
Stefan Roese | 43867c8 | 2007-10-02 11:44:46 +0200 | [diff] [blame] | 312 | |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 313 | address = pcie_get_base(hose, devfn); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 314 | offset += devfn << 4; |
| 315 | |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 316 | /* |
| 317 | * Suppress MCK exceptions, similar to pcie_read_config() |
| 318 | */ |
| 319 | pcie_dmer_disable (); |
| 320 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 321 | switch (len) { |
| 322 | case 1: |
| 323 | out_8(hose->cfg_data + offset, val); |
| 324 | break; |
| 325 | case 2: |
| 326 | out_le16((u16 *)(hose->cfg_data + offset), val); |
| 327 | break; |
| 328 | default: |
| 329 | out_le32((u32 *)(hose->cfg_data + offset), val); |
| 330 | break; |
| 331 | } |
Grzegorz Bernacki | eff9bc1 | 2007-09-07 17:46:18 +0200 | [diff] [blame] | 332 | |
| 333 | pcie_dmer_enable (); |
| 334 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val) |
| 339 | { |
| 340 | u32 v; |
| 341 | int rv; |
| 342 | |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 343 | rv = pcie_read_config(hose, dev, offset, 1, &v); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 344 | *val = (u8)v; |
| 345 | return rv; |
| 346 | } |
| 347 | |
| 348 | int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val) |
| 349 | { |
| 350 | u32 v; |
| 351 | int rv; |
| 352 | |
| 353 | rv = pcie_read_config(hose, dev, offset, 2, &v); |
| 354 | *val = (u16)v; |
| 355 | return rv; |
| 356 | } |
| 357 | |
| 358 | int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val) |
| 359 | { |
| 360 | u32 v; |
| 361 | int rv; |
| 362 | |
| 363 | rv = pcie_read_config(hose, dev, offset, 3, &v); |
| 364 | *val = (u32)v; |
| 365 | return rv; |
| 366 | } |
| 367 | |
| 368 | int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val) |
| 369 | { |
| 370 | return pcie_write_config(hose,(u32)dev,offset,1,val); |
| 371 | } |
| 372 | |
| 373 | int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val) |
| 374 | { |
| 375 | return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val); |
| 376 | } |
| 377 | |
| 378 | int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val) |
| 379 | { |
| 380 | return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val); |
| 381 | } |
| 382 | |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 383 | #if defined(CONFIG_440SPE) |
Stefan Roese | 9c00e51 | 2007-10-03 07:48:09 +0200 | [diff] [blame] | 384 | static void ppc4xx_setup_utl(u32 port) { |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 385 | |
| 386 | volatile void *utl_base = NULL; |
| 387 | |
| 388 | /* |
| 389 | * Map UTL registers |
| 390 | */ |
| 391 | switch (port) { |
| 392 | case 0: |
Rafal Jaworowski | e979909 | 2006-08-11 12:35:52 +0200 | [diff] [blame] | 393 | mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c); |
| 394 | mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000); |
| 395 | mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 396 | mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 397 | break; |
| 398 | |
| 399 | case 1: |
Rafal Jaworowski | e979909 | 2006-08-11 12:35:52 +0200 | [diff] [blame] | 400 | mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c); |
| 401 | mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000); |
| 402 | mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 403 | mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 404 | break; |
| 405 | |
| 406 | case 2: |
Rafal Jaworowski | e979909 | 2006-08-11 12:35:52 +0200 | [diff] [blame] | 407 | mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c); |
| 408 | mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000); |
| 409 | mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 410 | mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 411 | break; |
| 412 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 413 | utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port); |
Wolfgang Denk | dd314d1 | 2006-08-27 18:10:01 +0200 | [diff] [blame] | 414 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 415 | /* |
| 416 | * Set buffer allocations and then assert VRB and TXE. |
| 417 | */ |
| 418 | out_be32(utl_base + PEUTL_OUTTR, 0x08000000); |
| 419 | out_be32(utl_base + PEUTL_INTR, 0x02000000); |
| 420 | out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000); |
| 421 | out_be32(utl_base + PEUTL_PBBSZ, 0x53000000); |
| 422 | out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000); |
| 423 | out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000); |
| 424 | out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000); |
Rafal Jaworowski | e979909 | 2006-08-11 12:35:52 +0200 | [diff] [blame] | 425 | out_be32(utl_base + PEUTL_PCTL, 0x80800066); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static int check_error(void) |
| 429 | { |
| 430 | u32 valPE0, valPE1, valPE2; |
| 431 | int err = 0; |
| 432 | |
| 433 | /* SDR0_PEGPLLLCT1 reset */ |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 434 | if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000)) |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 435 | printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 436 | |
| 437 | valPE0 = SDR_READ(PESDR0_RCSSET); |
| 438 | valPE1 = SDR_READ(PESDR1_RCSSET); |
| 439 | valPE2 = SDR_READ(PESDR2_RCSSET); |
| 440 | |
| 441 | /* SDR0_PExRCSSET rstgu */ |
| 442 | if (!(valPE0 & 0x01000000) || |
| 443 | !(valPE1 & 0x01000000) || |
| 444 | !(valPE2 & 0x01000000)) { |
| 445 | printf("PCIE: SDR0_PExRCSSET rstgu error\n"); |
| 446 | err = -1; |
| 447 | } |
| 448 | |
| 449 | /* SDR0_PExRCSSET rstdl */ |
| 450 | if (!(valPE0 & 0x00010000) || |
| 451 | !(valPE1 & 0x00010000) || |
| 452 | !(valPE2 & 0x00010000)) { |
| 453 | printf("PCIE: SDR0_PExRCSSET rstdl error\n"); |
| 454 | err = -1; |
| 455 | } |
| 456 | |
| 457 | /* SDR0_PExRCSSET rstpyn */ |
| 458 | if ((valPE0 & 0x00001000) || |
| 459 | (valPE1 & 0x00001000) || |
| 460 | (valPE2 & 0x00001000)) { |
| 461 | printf("PCIE: SDR0_PExRCSSET rstpyn error\n"); |
| 462 | err = -1; |
| 463 | } |
| 464 | |
| 465 | /* SDR0_PExRCSSET hldplb */ |
| 466 | if ((valPE0 & 0x10000000) || |
| 467 | (valPE1 & 0x10000000) || |
| 468 | (valPE2 & 0x10000000)) { |
| 469 | printf("PCIE: SDR0_PExRCSSET hldplb error\n"); |
| 470 | err = -1; |
| 471 | } |
| 472 | |
| 473 | /* SDR0_PExRCSSET rdy */ |
| 474 | if ((valPE0 & 0x00100000) || |
| 475 | (valPE1 & 0x00100000) || |
| 476 | (valPE2 & 0x00100000)) { |
| 477 | printf("PCIE: SDR0_PExRCSSET rdy error\n"); |
| 478 | err = -1; |
| 479 | } |
| 480 | |
| 481 | /* SDR0_PExRCSSET shutdown */ |
| 482 | if ((valPE0 & 0x00000100) || |
| 483 | (valPE1 & 0x00000100) || |
| 484 | (valPE2 & 0x00000100)) { |
| 485 | printf("PCIE: SDR0_PExRCSSET shutdown error\n"); |
| 486 | err = -1; |
| 487 | } |
| 488 | return err; |
| 489 | } |
| 490 | |
| 491 | /* |
| 492 | * Initialize PCI Express core |
| 493 | */ |
Stefan Roese | 9c00e51 | 2007-10-03 07:48:09 +0200 | [diff] [blame] | 494 | int ppc4xx_init_pcie(void) |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 495 | { |
| 496 | int time_out = 20; |
| 497 | |
| 498 | /* Set PLL clock receiver to LVPECL */ |
| 499 | SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28); |
| 500 | |
Rupjyoti Sarmah | 73343ca | 2009-09-21 11:26:19 -0700 | [diff] [blame] | 501 | if (check_error()) { |
| 502 | printf("ERROR: failed to set PCIe reference clock receiver --" |
| 503 | "PESDR0_PLLLCT1 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT1)); |
| 504 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 505 | return -1; |
Rupjyoti Sarmah | 73343ca | 2009-09-21 11:26:19 -0700 | [diff] [blame] | 506 | } |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 507 | |
Rupjyoti Sarmah | 73343ca | 2009-09-21 11:26:19 -0700 | [diff] [blame] | 508 | /* Did resistance calibration work? */ |
| 509 | if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000)) { |
| 510 | printf("ERROR: PCIe resistance calibration failed --" |
| 511 | "PESDR0_PLLLCT2 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT2)); |
| 512 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 513 | return -1; |
| 514 | } |
| 515 | /* De-assert reset of PCIe PLL, wait for lock */ |
| 516 | SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24)); |
Rupjyoti Sarmah | 73343ca | 2009-09-21 11:26:19 -0700 | [diff] [blame] | 517 | udelay(300); /* 300 uS is maximum time lock should take */ |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 518 | |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 519 | while (time_out) { |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 520 | if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) { |
| 521 | time_out--; |
Rupjyoti Sarmah | 73343ca | 2009-09-21 11:26:19 -0700 | [diff] [blame] | 522 | udelay(20); /* Wait 20 uS more if needed */ |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 523 | } else |
| 524 | break; |
| 525 | } |
| 526 | if (!time_out) { |
Rupjyoti Sarmah | 73343ca | 2009-09-21 11:26:19 -0700 | [diff] [blame] | 527 | printf("ERROR: PCIe PLL VCO output not locked to ref clock --" |
| 528 | "PESDR0_PLLLCTS=0x%08x\n", SDR_READ(PESDR0_PLLLCT3)); |
| 529 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 530 | return -1; |
| 531 | } |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 532 | return 0; |
| 533 | } |
| 534 | #endif |
| 535 | |
| 536 | #if defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 537 | static void ppc4xx_setup_utl(u32 port) |
| 538 | { |
| 539 | volatile void *utl_base = NULL; |
| 540 | |
| 541 | /* |
| 542 | * Map UTL registers at 0x0801_n000 (4K 0xfff mask) PEGPLn_REGMSK |
| 543 | */ |
| 544 | switch (port) { |
| 545 | case 0: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 546 | mtdcr(DCRN_PEGPL_REGBAH(PCIE0), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE)); |
| 547 | mtdcr(DCRN_PEGPL_REGBAL(PCIE0), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE)); |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 548 | mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* BAM 11100000=4KB */ |
| 549 | mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0); |
| 550 | break; |
| 551 | |
| 552 | case 1: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 553 | mtdcr(DCRN_PEGPL_REGBAH(PCIE1), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE)); |
| 554 | mtdcr(DCRN_PEGPL_REGBAL(PCIE1), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE) |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 555 | + 0x1000); |
| 556 | mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* BAM 11100000=4KB */ |
| 557 | mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0); |
| 558 | break; |
| 559 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 560 | utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port); |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 561 | |
| 562 | /* |
| 563 | * Set buffer allocations and then assert VRB and TXE. |
| 564 | */ |
| 565 | out_be32(utl_base + PEUTL_PBCTL, 0x0800000c); /* PLBME, CRRE */ |
| 566 | out_be32(utl_base + PEUTL_OUTTR, 0x08000000); |
| 567 | out_be32(utl_base + PEUTL_INTR, 0x02000000); |
| 568 | out_be32(utl_base + PEUTL_OPDBSZ, 0x04000000); /* OPD = 512 Bytes */ |
| 569 | out_be32(utl_base + PEUTL_PBBSZ, 0x00000000); /* Max 512 Bytes */ |
| 570 | out_be32(utl_base + PEUTL_IPHBSZ, 0x02000000); |
| 571 | out_be32(utl_base + PEUTL_IPDBSZ, 0x04000000); /* IPD = 512 Bytes */ |
| 572 | out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000); |
| 573 | out_be32(utl_base + PEUTL_PCTL, 0x80800066); /* VRB,TXE,timeout=default */ |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * TODO: double check PCI express SDR based on the latest user manual |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 578 | * Some registers specified here no longer exist.. has to be |
| 579 | * updated based on the final EAS spec. |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 580 | */ |
| 581 | static int check_error(void) |
| 582 | { |
| 583 | u32 valPE0, valPE1; |
| 584 | int err = 0; |
| 585 | |
| 586 | valPE0 = SDR_READ(SDRN_PESDR_RCSSET(0)); |
| 587 | valPE1 = SDR_READ(SDRN_PESDR_RCSSET(1)); |
| 588 | |
| 589 | /* SDR0_PExRCSSET rstgu */ |
| 590 | if (!(valPE0 & PESDRx_RCSSET_RSTGU) || !(valPE1 & PESDRx_RCSSET_RSTGU)) { |
| 591 | printf("PCIE: SDR0_PExRCSSET rstgu error\n"); |
| 592 | err = -1; |
| 593 | } |
| 594 | |
| 595 | /* SDR0_PExRCSSET rstdl */ |
| 596 | if (!(valPE0 & PESDRx_RCSSET_RSTDL) || !(valPE1 & PESDRx_RCSSET_RSTDL)) { |
| 597 | printf("PCIE: SDR0_PExRCSSET rstdl error\n"); |
| 598 | err = -1; |
| 599 | } |
| 600 | |
| 601 | /* SDR0_PExRCSSET rstpyn */ |
| 602 | if ((valPE0 & PESDRx_RCSSET_RSTPYN) || (valPE1 & PESDRx_RCSSET_RSTPYN)) { |
| 603 | printf("PCIE: SDR0_PExRCSSET rstpyn error\n"); |
| 604 | err = -1; |
| 605 | } |
| 606 | |
| 607 | /* SDR0_PExRCSSET hldplb */ |
| 608 | if ((valPE0 & PESDRx_RCSSET_HLDPLB) || (valPE1 & PESDRx_RCSSET_HLDPLB)) { |
| 609 | printf("PCIE: SDR0_PExRCSSET hldplb error\n"); |
| 610 | err = -1; |
| 611 | } |
| 612 | |
| 613 | /* SDR0_PExRCSSET rdy */ |
| 614 | if ((valPE0 & PESDRx_RCSSET_RDY) || (valPE1 & PESDRx_RCSSET_RDY)) { |
| 615 | printf("PCIE: SDR0_PExRCSSET rdy error\n"); |
| 616 | err = -1; |
| 617 | } |
| 618 | |
| 619 | return err; |
| 620 | } |
| 621 | |
| 622 | /* |
| 623 | * Initialize PCI Express core as described in User Manual |
| 624 | * TODO: double check PE SDR PLL Register with the updated user manual. |
| 625 | */ |
| 626 | int ppc4xx_init_pcie(void) |
| 627 | { |
| 628 | if (check_error()) |
| 629 | return -1; |
| 630 | |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 631 | return 0; |
| 632 | } |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 633 | #endif /* CONFIG_460EX */ |
| 634 | |
| 635 | #if defined(CONFIG_405EX) |
Stefan Roese | 1ce9fe9 | 2007-11-16 14:16:54 +0100 | [diff] [blame] | 636 | static void ppc4xx_setup_utl(u32 port) |
| 637 | { |
| 638 | u32 utl_base; |
| 639 | |
| 640 | /* |
| 641 | * Map UTL registers at 0xef4f_n000 (4K 0xfff mask) PEGPLn_REGMSK |
| 642 | */ |
| 643 | switch (port) { |
| 644 | case 0: |
| 645 | mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x00000000); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 646 | mtdcr(DCRN_PEGPL_REGBAL(PCIE0), CONFIG_SYS_PCIE0_UTLBASE); |
Stefan Roese | 9580595 | 2007-11-18 14:44:44 +0100 | [diff] [blame] | 647 | mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* 4k region, valid */ |
Stefan Roese | 1ce9fe9 | 2007-11-16 14:16:54 +0100 | [diff] [blame] | 648 | mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0); |
| 649 | break; |
| 650 | |
| 651 | case 1: |
| 652 | mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x00000000); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 653 | mtdcr(DCRN_PEGPL_REGBAL(PCIE1), CONFIG_SYS_PCIE1_UTLBASE); |
Stefan Roese | 9580595 | 2007-11-18 14:44:44 +0100 | [diff] [blame] | 654 | mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* 4k region, valid */ |
Stefan Roese | 1ce9fe9 | 2007-11-16 14:16:54 +0100 | [diff] [blame] | 655 | mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0); |
| 656 | |
| 657 | break; |
| 658 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 659 | utl_base = (port==0) ? CONFIG_SYS_PCIE0_UTLBASE : CONFIG_SYS_PCIE1_UTLBASE; |
Stefan Roese | 1ce9fe9 | 2007-11-16 14:16:54 +0100 | [diff] [blame] | 660 | |
| 661 | /* |
| 662 | * Set buffer allocations and then assert VRB and TXE. |
| 663 | */ |
| 664 | out_be32((u32 *)(utl_base + PEUTL_OUTTR), 0x02000000); |
| 665 | out_be32((u32 *)(utl_base + PEUTL_INTR), 0x02000000); |
| 666 | out_be32((u32 *)(utl_base + PEUTL_OPDBSZ), 0x04000000); |
| 667 | out_be32((u32 *)(utl_base + PEUTL_PBBSZ), 0x21000000); |
| 668 | out_be32((u32 *)(utl_base + PEUTL_IPHBSZ), 0x02000000); |
| 669 | out_be32((u32 *)(utl_base + PEUTL_IPDBSZ), 0x04000000); |
| 670 | out_be32((u32 *)(utl_base + PEUTL_RCIRQEN), 0x00f00000); |
| 671 | out_be32((u32 *)(utl_base + PEUTL_PCTL), 0x80800066); |
| 672 | |
| 673 | out_be32((u32 *)(utl_base + PEUTL_PBCTL), 0x0800000c); |
| 674 | out_be32((u32 *)(utl_base + PEUTL_RCSTA), |
| 675 | in_be32((u32 *)(utl_base + PEUTL_RCSTA)) | 0x000040000); |
| 676 | } |
| 677 | |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 678 | int ppc4xx_init_pcie(void) |
| 679 | { |
| 680 | /* |
| 681 | * Nothing to do on 405EX |
| 682 | */ |
| 683 | return 0; |
| 684 | } |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 685 | #endif /* CONFIG_405EX */ |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 686 | |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 687 | /* |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 688 | * Board-specific pcie initialization |
| 689 | * Platform code can reimplement ppc4xx_init_pcie_port_hw() if needed |
| 690 | */ |
| 691 | |
| 692 | /* |
| 693 | * Initialize various parts of the PCI Express core for our port: |
| 694 | * |
| 695 | * - Set as a root port and enable max width |
| 696 | * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4). |
| 697 | * - Set up UTL configuration. |
| 698 | * - Increase SERDES drive strength to levels suggested by AMCC. |
| 699 | * - De-assert RSTPYN, RSTDL and RSTGU. |
| 700 | * |
| 701 | * NOTICE for 440SPE revB chip: PESDRn_UTLSET2 is not set - we leave it |
| 702 | * with default setting 0x11310000. The register has new fields, |
| 703 | * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core |
| 704 | * hang. |
| 705 | */ |
| 706 | #if defined(CONFIG_440SPE) |
| 707 | int __ppc4xx_init_pcie_port_hw(int port, int rootport) |
| 708 | { |
| 709 | u32 val = 1 << 24; |
| 710 | u32 utlset1; |
| 711 | |
| 712 | if (rootport) { |
| 713 | val = PTYPE_ROOT_PORT << 20; |
| 714 | utlset1 = 0x21222222; |
| 715 | } else { |
| 716 | val = PTYPE_LEGACY_ENDPOINT << 20; |
| 717 | utlset1 = 0x20222222; |
| 718 | } |
| 719 | |
| 720 | if (port == 0) |
| 721 | val |= LNKW_X8 << 12; |
| 722 | else |
| 723 | val |= LNKW_X4 << 12; |
| 724 | |
| 725 | SDR_WRITE(SDRN_PESDR_DLPSET(port), val); |
| 726 | SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1); |
| 727 | if (!ppc440spe_revB()) |
| 728 | SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x11000000); |
| 729 | SDR_WRITE(SDRN_PESDR_HSSL0SET1(port), 0x35000000); |
| 730 | SDR_WRITE(SDRN_PESDR_HSSL1SET1(port), 0x35000000); |
| 731 | SDR_WRITE(SDRN_PESDR_HSSL2SET1(port), 0x35000000); |
| 732 | SDR_WRITE(SDRN_PESDR_HSSL3SET1(port), 0x35000000); |
| 733 | if (port == 0) { |
| 734 | SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000); |
| 735 | SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000); |
| 736 | SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000); |
| 737 | SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000); |
| 738 | } |
| 739 | SDR_WRITE(SDRN_PESDR_RCSSET(port), (SDR_READ(SDRN_PESDR_RCSSET(port)) & |
| 740 | ~(1 << 24 | 1 << 16)) | 1 << 12); |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | #endif /* CONFIG_440SPE */ |
| 745 | |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 746 | #if defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 747 | int __ppc4xx_init_pcie_port_hw(int port, int rootport) |
| 748 | { |
Stefan Roese | 142b1d4 | 2008-07-01 17:03:19 +0200 | [diff] [blame] | 749 | u32 val; |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 750 | u32 utlset1; |
| 751 | |
Stefan Roese | 142b1d4 | 2008-07-01 17:03:19 +0200 | [diff] [blame] | 752 | if (rootport) |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 753 | val = PTYPE_ROOT_PORT << 20; |
Stefan Roese | 142b1d4 | 2008-07-01 17:03:19 +0200 | [diff] [blame] | 754 | else |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 755 | val = PTYPE_LEGACY_ENDPOINT << 20; |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 756 | |
| 757 | if (port == 0) { |
| 758 | val |= LNKW_X1 << 12; |
Stefan Roese | 142b1d4 | 2008-07-01 17:03:19 +0200 | [diff] [blame] | 759 | utlset1 = 0x20000000; |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 760 | } else { |
| 761 | val |= LNKW_X4 << 12; |
Stefan Roese | 142b1d4 | 2008-07-01 17:03:19 +0200 | [diff] [blame] | 762 | utlset1 = 0x20101101; |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | SDR_WRITE(SDRN_PESDR_DLPSET(port), val); |
| 766 | SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1); |
| 767 | SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01210000); |
| 768 | |
| 769 | switch (port) { |
| 770 | case 0: |
| 771 | SDR_WRITE(PESDR0_L0CDRCTL, 0x00003230); |
Tirumala R Marri | 75e22a4 | 2008-08-21 21:54:53 -0700 | [diff] [blame] | 772 | SDR_WRITE(PESDR0_L0DRV, 0x00000130); |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 773 | SDR_WRITE(PESDR0_L0CLK, 0x00000006); |
| 774 | |
| 775 | SDR_WRITE(PESDR0_PHY_CTL_RST,0x10000000); |
| 776 | break; |
| 777 | |
| 778 | case 1: |
| 779 | SDR_WRITE(PESDR1_L0CDRCTL, 0x00003230); |
| 780 | SDR_WRITE(PESDR1_L1CDRCTL, 0x00003230); |
| 781 | SDR_WRITE(PESDR1_L2CDRCTL, 0x00003230); |
| 782 | SDR_WRITE(PESDR1_L3CDRCTL, 0x00003230); |
Tirumala R Marri | 75e22a4 | 2008-08-21 21:54:53 -0700 | [diff] [blame] | 783 | SDR_WRITE(PESDR1_L0DRV, 0x00000130); |
| 784 | SDR_WRITE(PESDR1_L1DRV, 0x00000130); |
| 785 | SDR_WRITE(PESDR1_L2DRV, 0x00000130); |
| 786 | SDR_WRITE(PESDR1_L3DRV, 0x00000130); |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 787 | SDR_WRITE(PESDR1_L0CLK, 0x00000006); |
| 788 | SDR_WRITE(PESDR1_L1CLK, 0x00000006); |
| 789 | SDR_WRITE(PESDR1_L2CLK, 0x00000006); |
| 790 | SDR_WRITE(PESDR1_L3CLK, 0x00000006); |
| 791 | |
| 792 | SDR_WRITE(PESDR1_PHY_CTL_RST,0x10000000); |
| 793 | break; |
| 794 | } |
| 795 | |
| 796 | SDR_WRITE(SDRN_PESDR_RCSSET(port), SDR_READ(SDRN_PESDR_RCSSET(port)) | |
| 797 | (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN)); |
| 798 | |
| 799 | /* Poll for PHY reset */ |
| 800 | switch (port) { |
| 801 | case 0: |
| 802 | while (!(SDR_READ(PESDR0_RSTSTA) & 0x1)) |
| 803 | udelay(10); |
| 804 | break; |
| 805 | case 1: |
| 806 | while (!(SDR_READ(PESDR1_RSTSTA) & 0x1)) |
| 807 | udelay(10); |
| 808 | break; |
| 809 | } |
| 810 | |
| 811 | SDR_WRITE(SDRN_PESDR_RCSSET(port), |
| 812 | (SDR_READ(SDRN_PESDR_RCSSET(port)) & |
| 813 | ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) | |
| 814 | PESDRx_RCSSET_RSTPYN); |
| 815 | |
| 816 | return 0; |
| 817 | } |
| 818 | #endif /* CONFIG_440SPE */ |
| 819 | |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 820 | #if defined(CONFIG_405EX) |
| 821 | int __ppc4xx_init_pcie_port_hw(int port, int rootport) |
| 822 | { |
| 823 | u32 val; |
| 824 | |
| 825 | if (rootport) |
| 826 | val = 0x00401000; |
| 827 | else |
| 828 | val = 0x00101000; |
| 829 | |
| 830 | SDR_WRITE(SDRN_PESDR_DLPSET(port), val); |
Stefan Roese | 4aabdc8 | 2007-11-13 08:06:11 +0100 | [diff] [blame] | 831 | SDR_WRITE(SDRN_PESDR_UTLSET1(port), 0x00000000); |
| 832 | SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01010000); |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 833 | SDR_WRITE(SDRN_PESDR_PHYSET1(port), 0x720F0000); |
| 834 | SDR_WRITE(SDRN_PESDR_PHYSET2(port), 0x70600003); |
| 835 | |
| 836 | /* Assert the PE0_PHY reset */ |
| 837 | SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01010000); |
| 838 | udelay(1000); |
| 839 | |
| 840 | /* deassert the PE0_hotreset */ |
Stefan Roese | e7fe4c5 | 2007-10-18 07:39:38 +0200 | [diff] [blame] | 841 | if (is_end_point(port)) |
| 842 | SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01111000); |
| 843 | else |
| 844 | SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01101000); |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 845 | |
| 846 | /* poll for phy !reset */ |
| 847 | while (!(SDR_READ(SDRN_PESDR_PHYSTA(port)) & 0x00001000)) |
| 848 | ; |
| 849 | |
| 850 | /* deassert the PE0_gpl_utl_reset */ |
| 851 | SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x00101000); |
| 852 | |
| 853 | if (port == 0) |
| 854 | mtdcr(DCRN_PEGPL_CFG(PCIE0), 0x10000000); /* guarded on */ |
| 855 | else |
| 856 | mtdcr(DCRN_PEGPL_CFG(PCIE1), 0x10000000); /* guarded on */ |
| 857 | |
| 858 | return 0; |
| 859 | } |
| 860 | #endif /* CONFIG_405EX */ |
| 861 | |
| 862 | int ppc4xx_init_pcie_port_hw(int port, int rootport) |
Stefan Roese | 9580595 | 2007-11-18 14:44:44 +0100 | [diff] [blame] | 863 | __attribute__((weak, alias("__ppc4xx_init_pcie_port_hw"))); |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 864 | |
| 865 | /* |
| 866 | * We map PCI Express configuration access into the 512MB regions |
| 867 | * |
| 868 | * NOTICE: revB is very strict about PLB real addressess and ranges to |
| 869 | * be mapped for config space; it seems to only work with d_nnnn_nnnn |
| 870 | * range (hangs the core upon config transaction attempts when set |
| 871 | * otherwise) while revA uses c_nnnn_nnnn. |
| 872 | * |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 873 | * For 440SPe revA: |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 874 | * PCIE0: 0xc_4000_0000 |
| 875 | * PCIE1: 0xc_8000_0000 |
| 876 | * PCIE2: 0xc_c000_0000 |
| 877 | * |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 878 | * For 440SPe revB: |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 879 | * PCIE0: 0xd_0000_0000 |
| 880 | * PCIE1: 0xd_2000_0000 |
| 881 | * PCIE2: 0xd_4000_0000 |
| 882 | * |
| 883 | * For 405EX: |
| 884 | * PCIE0: 0xa000_0000 |
| 885 | * PCIE1: 0xc000_0000 |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 886 | * |
| 887 | * For 460EX/GT: |
| 888 | * PCIE0: 0xd_0000_0000 |
| 889 | * PCIE1: 0xd_2000_0000 |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 890 | */ |
| 891 | static inline u64 ppc4xx_get_cfgaddr(int port) |
| 892 | { |
| 893 | #if defined(CONFIG_405EX) |
| 894 | if (port == 0) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 895 | return (u64)CONFIG_SYS_PCIE0_CFGBASE; |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 896 | else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 897 | return (u64)CONFIG_SYS_PCIE1_CFGBASE; |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 898 | #endif |
| 899 | #if defined(CONFIG_440SPE) |
| 900 | if (ppc440spe_revB()) { |
| 901 | switch (port) { |
| 902 | default: /* to satisfy compiler */ |
| 903 | case 0: |
| 904 | return 0x0000000d00000000ULL; |
| 905 | case 1: |
| 906 | return 0x0000000d20000000ULL; |
| 907 | case 2: |
| 908 | return 0x0000000d40000000ULL; |
| 909 | } |
| 910 | } else { |
| 911 | switch (port) { |
| 912 | default: /* to satisfy compiler */ |
| 913 | case 0: |
| 914 | return 0x0000000c40000000ULL; |
| 915 | case 1: |
| 916 | return 0x0000000c80000000ULL; |
| 917 | case 2: |
| 918 | return 0x0000000cc0000000ULL; |
| 919 | } |
| 920 | } |
| 921 | #endif |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 922 | #if defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 923 | if (port == 0) |
| 924 | return 0x0000000d00000000ULL; |
| 925 | else |
| 926 | return 0x0000000d20000000ULL; |
| 927 | #endif |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | /* |
| 931 | * 4xx boards as end point and root point setup |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 932 | * and |
| 933 | * testing inbound and out bound windows |
| 934 | * |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 935 | * 4xx boards can be plugged into another 4xx boards or you can get PCI-E |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 936 | * cable which can be used to setup loop back from one port to another port. |
| 937 | * Please rememeber that unless there is a endpoint plugged in to root port it |
| 938 | * will not initialize. It is the same in case of endpoint , unless there is |
| 939 | * root port attached it will not initialize. |
| 940 | * |
| 941 | * In this release of software all the PCI-E ports are configured as either |
| 942 | * endpoint or rootpoint.In future we will have support for selective ports |
| 943 | * setup as endpoint and root point in single board. |
| 944 | * |
| 945 | * Once your board came up as root point , you can verify by reading |
| 946 | * /proc/bus/pci/devices. Where you can see the configuration registers |
| 947 | * of end point device attached to the port. |
| 948 | * |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 949 | * Enpoint cofiguration can be verified by connecting 4xx board to any |
| 950 | * host or another 4xx board. Then try to scan the device. In case of |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 951 | * linux use "lspci" or appripriate os command. |
| 952 | * |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 953 | * How do I verify the inbound and out bound windows ? (4xx to 4xx) |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 954 | * in this configuration inbound and outbound windows are setup to access |
| 955 | * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address |
| 956 | * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000, |
| 957 | * This is waere your POM(PLB out bound memory window) mapped. then |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 958 | * read the data from other 4xx board's u-boot prompt at address |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 959 | * 0x9000 0000(SRAM). Data should match. |
| 960 | * In case of inbound , write data to u-boot command prompt at 0xb000 0000 |
| 961 | * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check |
| 962 | * data at 0x9000 0000(SRAM).Data should match. |
| 963 | */ |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 964 | int ppc4xx_init_pcie_port(int port, int rootport) |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 965 | { |
| 966 | static int core_init; |
| 967 | volatile u32 val = 0; |
| 968 | int attempts; |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 969 | u64 addr; |
| 970 | u32 low, high; |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 971 | |
| 972 | if (!core_init) { |
Stefan Roese | 9c00e51 | 2007-10-03 07:48:09 +0200 | [diff] [blame] | 973 | if (ppc4xx_init_pcie()) |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 974 | return -1; |
Stefan Roese | 89bac40 | 2007-10-13 16:43:23 +0200 | [diff] [blame] | 975 | ++core_init; |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | /* |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 979 | * Initialize various parts of the PCI Express core for our port |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 980 | */ |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 981 | ppc4xx_init_pcie_port_hw(port, rootport); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 982 | |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 983 | /* |
| 984 | * Notice: the following delay has critical impact on device |
| 985 | * initialization - if too short (<50ms) the link doesn't get up. |
| 986 | */ |
| 987 | mdelay(100); |
| 988 | |
Stefan Roese | be6fea9 | 2007-10-03 21:16:32 +0200 | [diff] [blame] | 989 | val = SDR_READ(SDRN_PESDR_RCSSTS(port)); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 990 | if (val & (1 << 20)) { |
| 991 | printf("PCIE%d: PGRST failed %08x\n", port, val); |
| 992 | return -1; |
| 993 | } |
| 994 | |
| 995 | /* |
| 996 | * Verify link is up |
| 997 | */ |
Stefan Roese | be6fea9 | 2007-10-03 21:16:32 +0200 | [diff] [blame] | 998 | val = SDR_READ(SDRN_PESDR_LOOP(port)); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 999 | if (!(val & 0x00001000)) { |
| 1000 | printf("PCIE%d: link is not up.\n", port); |
Stefan Roese | 14fd12f | 2009-10-02 14:35:16 +0200 | [diff] [blame] | 1001 | return -ENODEV; |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | /* |
| 1005 | * Setup UTL registers - but only on revA! |
| 1006 | * We use default settings for revB chip. |
| 1007 | */ |
| 1008 | if (!ppc440spe_revB()) |
Stefan Roese | 9c00e51 | 2007-10-03 07:48:09 +0200 | [diff] [blame] | 1009 | ppc4xx_setup_utl(port); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1010 | |
| 1011 | /* |
| 1012 | * We map PCI Express configuration access into the 512MB regions |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1013 | */ |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1014 | addr = ppc4xx_get_cfgaddr(port); |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 1015 | low = U64_TO_U32_LOW(addr); |
| 1016 | high = U64_TO_U32_HIGH(addr); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1017 | |
| 1018 | switch (port) { |
| 1019 | case 0: |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1020 | mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high); |
| 1021 | mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1022 | mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */ |
| 1023 | break; |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1024 | case 1: |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1025 | mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high); |
| 1026 | mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1027 | mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */ |
| 1028 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1029 | #if CONFIG_SYS_PCIE_NR_PORTS > 2 |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1030 | case 2: |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1031 | mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high); |
| 1032 | mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1033 | mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */ |
| 1034 | break; |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 1035 | #endif |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | /* |
| 1039 | * Check for VC0 active and assert RDY. |
| 1040 | */ |
| 1041 | attempts = 10; |
Stefan Roese | be6fea9 | 2007-10-03 21:16:32 +0200 | [diff] [blame] | 1042 | while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 16))) { |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1043 | if (!(attempts--)) { |
| 1044 | printf("PCIE%d: VC0 not active\n", port); |
| 1045 | return -1; |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1046 | } |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1047 | mdelay(1000); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1048 | } |
Stefan Roese | be6fea9 | 2007-10-03 21:16:32 +0200 | [diff] [blame] | 1049 | SDR_WRITE(SDRN_PESDR_RCSSET(port), |
| 1050 | SDR_READ(SDRN_PESDR_RCSSET(port)) | 1 << 20); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1051 | mdelay(100); |
| 1052 | |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1056 | int ppc4xx_init_pcie_rootport(int port) |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1057 | { |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1058 | return ppc4xx_init_pcie_port(port, 1); |
| 1059 | } |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1060 | |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1061 | int ppc4xx_init_pcie_endport(int port) |
| 1062 | { |
| 1063 | return ppc4xx_init_pcie_port(port, 0); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1064 | } |
| 1065 | |
Stefan Roese | 9c00e51 | 2007-10-03 07:48:09 +0200 | [diff] [blame] | 1066 | void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port) |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1067 | { |
| 1068 | volatile void *mbase = NULL; |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1069 | volatile void *rmbase = NULL; |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1070 | |
| 1071 | pci_set_ops(hose, |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1072 | pcie_read_config_byte, |
| 1073 | pcie_read_config_word, |
| 1074 | pcie_read_config_dword, |
| 1075 | pcie_write_config_byte, |
| 1076 | pcie_write_config_word, |
| 1077 | pcie_write_config_dword); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1078 | |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1079 | switch (port) { |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1080 | case 0: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1081 | mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE; |
| 1082 | rmbase = (u32 *)CONFIG_SYS_PCIE0_CFGBASE; |
| 1083 | hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE; |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1084 | break; |
| 1085 | case 1: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1086 | mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE; |
| 1087 | rmbase = (u32 *)CONFIG_SYS_PCIE1_CFGBASE; |
| 1088 | hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE; |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1089 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1090 | #if CONFIG_SYS_PCIE_NR_PORTS > 2 |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1091 | case 2: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1092 | mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE; |
| 1093 | rmbase = (u32 *)CONFIG_SYS_PCIE2_CFGBASE; |
| 1094 | hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE; |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1095 | break; |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 1096 | #endif |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | /* |
| 1100 | * Set bus numbers on our root port |
| 1101 | */ |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 1102 | out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0); |
| 1103 | out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1); |
| 1104 | out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1105 | |
| 1106 | /* |
| 1107 | * Set up outbound translation to hose->mem_space from PLB |
| 1108 | * addresses at an offset of 0xd_0000_0000. We set the low |
| 1109 | * bits of the mask to 11 to turn off splitting into 8 |
| 1110 | * subregions and to enable the outbound translation. |
| 1111 | */ |
| 1112 | out_le32(mbase + PECFG_POM0LAH, 0x00000000); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1113 | out_le32(mbase + PECFG_POM0LAL, CONFIG_SYS_PCIE_MEMBASE + |
| 1114 | port * CONFIG_SYS_PCIE_MEMSIZE); |
Stefan Roese | 3dced49 | 2007-10-05 07:57:20 +0200 | [diff] [blame] | 1115 | debug("PECFG_POM0LA=%08x.%08x\n", in_le32(mbase + PECFG_POM0LAH), |
| 1116 | in_le32(mbase + PECFG_POM0LAL)); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1117 | |
| 1118 | switch (port) { |
| 1119 | case 0: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1120 | mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH); |
| 1121 | mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE + |
| 1122 | port * CONFIG_SYS_PCIE_MEMSIZE); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1123 | mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff); |
| 1124 | mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0), |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1125 | ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3); |
Stefan Roese | 3dced49 | 2007-10-05 07:57:20 +0200 | [diff] [blame] | 1126 | debug("0:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n", |
| 1127 | mfdcr(DCRN_PEGPL_OMR1BAH(PCIE0)), |
| 1128 | mfdcr(DCRN_PEGPL_OMR1BAL(PCIE0)), |
| 1129 | mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE0)), |
| 1130 | mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE0))); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1131 | break; |
| 1132 | case 1: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1133 | mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH); |
| 1134 | mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE + |
| 1135 | port * CONFIG_SYS_PCIE_MEMSIZE); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1136 | mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff); |
| 1137 | mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1), |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1138 | ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3); |
Stefan Roese | 3dced49 | 2007-10-05 07:57:20 +0200 | [diff] [blame] | 1139 | debug("1:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n", |
| 1140 | mfdcr(DCRN_PEGPL_OMR1BAH(PCIE1)), |
| 1141 | mfdcr(DCRN_PEGPL_OMR1BAL(PCIE1)), |
| 1142 | mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE1)), |
| 1143 | mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE1))); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1144 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1145 | #if CONFIG_SYS_PCIE_NR_PORTS > 2 |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1146 | case 2: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1147 | mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH); |
| 1148 | mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE + |
| 1149 | port * CONFIG_SYS_PCIE_MEMSIZE); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1150 | mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff); |
| 1151 | mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2), |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1152 | ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3); |
Stefan Roese | 3dced49 | 2007-10-05 07:57:20 +0200 | [diff] [blame] | 1153 | debug("2:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n", |
| 1154 | mfdcr(DCRN_PEGPL_OMR1BAH(PCIE2)), |
| 1155 | mfdcr(DCRN_PEGPL_OMR1BAL(PCIE2)), |
| 1156 | mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE2)), |
| 1157 | mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE2))); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1158 | break; |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 1159 | #endif |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1160 | } |
| 1161 | |
Stefan Roese | e2ea080 | 2009-02-18 13:18:00 +0100 | [diff] [blame] | 1162 | /* Set up 4GB inbound memory window at 0 */ |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1163 | out_le32(mbase + PCI_BASE_ADDRESS_0, 0); |
| 1164 | out_le32(mbase + PCI_BASE_ADDRESS_1, 0); |
Stefan Roese | e2ea080 | 2009-02-18 13:18:00 +0100 | [diff] [blame] | 1165 | out_le32(mbase + PECFG_BAR0HMPA, 0x7ffffff); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1166 | out_le32(mbase + PECFG_BAR0LMPA, 0); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1167 | |
| 1168 | out_le32(mbase + PECFG_PIM01SAH, 0xffff0000); |
| 1169 | out_le32(mbase + PECFG_PIM01SAL, 0x00000000); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1170 | out_le32(mbase + PECFG_PIM0LAL, 0); |
| 1171 | out_le32(mbase + PECFG_PIM0LAH, 0); |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 1172 | out_le32(mbase + PECFG_PIM1LAL, 0x00000000); |
| 1173 | out_le32(mbase + PECFG_PIM1LAH, 0x00000004); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1174 | out_le32(mbase + PECFG_PIMEN, 0x1); |
| 1175 | |
| 1176 | /* Enable I/O, Mem, and Busmaster cycles */ |
| 1177 | out_le16((u16 *)(mbase + PCI_COMMAND), |
| 1178 | in_le16((u16 *)(mbase + PCI_COMMAND)) | |
| 1179 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); |
Stefan Roese | 43867c8 | 2007-10-02 11:44:46 +0200 | [diff] [blame] | 1180 | |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 1181 | /* Set Device and Vendor Id */ |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 1182 | out_le16(mbase + 0x200, 0xaaa0 + port); |
| 1183 | out_le16(mbase + 0x202, 0xbed0 + port); |
Grzegorz Bernacki | d2f2133 | 2007-09-07 18:20:23 +0200 | [diff] [blame] | 1184 | |
| 1185 | /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */ |
| 1186 | out_le32(mbase + 0x208, 0x06040001); |
| 1187 | |
Stefan Roese | 4e45662 | 2007-10-05 14:23:43 +0200 | [diff] [blame] | 1188 | printf("PCIE%d: successfully set as root-complex\n", port); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1189 | } |
| 1190 | |
Stefan Roese | 9c00e51 | 2007-10-03 07:48:09 +0200 | [diff] [blame] | 1191 | int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port) |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1192 | { |
| 1193 | volatile void *mbase = NULL; |
| 1194 | int attempts = 0; |
| 1195 | |
| 1196 | pci_set_ops(hose, |
| 1197 | pcie_read_config_byte, |
| 1198 | pcie_read_config_word, |
| 1199 | pcie_read_config_dword, |
| 1200 | pcie_write_config_byte, |
| 1201 | pcie_write_config_word, |
| 1202 | pcie_write_config_dword); |
| 1203 | |
| 1204 | switch (port) { |
| 1205 | case 0: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1206 | mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE; |
| 1207 | hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE; |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1208 | break; |
| 1209 | case 1: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1210 | mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE; |
| 1211 | hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE; |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1212 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1213 | #if defined(CONFIG_SYS_PCIE2_CFGBASE) |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1214 | case 2: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1215 | mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE; |
| 1216 | hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE; |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1217 | break; |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 1218 | #endif |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | /* |
| 1222 | * Set up outbound translation to hose->mem_space from PLB |
| 1223 | * addresses at an offset of 0xd_0000_0000. We set the low |
| 1224 | * bits of the mask to 11 to turn off splitting into 8 |
| 1225 | * subregions and to enable the outbound translation. |
| 1226 | */ |
| 1227 | out_le32(mbase + PECFG_POM0LAH, 0x00001ff8); |
| 1228 | out_le32(mbase + PECFG_POM0LAL, 0x00001000); |
| 1229 | |
| 1230 | switch (port) { |
| 1231 | case 0: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1232 | mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH); |
| 1233 | mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE + |
| 1234 | port * CONFIG_SYS_PCIE_MEMSIZE); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1235 | mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff); |
| 1236 | mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0), |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1237 | ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1238 | break; |
| 1239 | case 1: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1240 | mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH); |
| 1241 | mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE + |
| 1242 | port * CONFIG_SYS_PCIE_MEMSIZE); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1243 | mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff); |
| 1244 | mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1), |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1245 | ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1246 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1247 | #if CONFIG_SYS_PCIE_NR_PORTS > 2 |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1248 | case 2: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1249 | mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH); |
| 1250 | mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE + |
| 1251 | port * CONFIG_SYS_PCIE_MEMSIZE); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1252 | mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff); |
| 1253 | mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2), |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1254 | ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1255 | break; |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 1256 | #endif |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1257 | } |
| 1258 | |
Stefan Roese | e7fe4c5 | 2007-10-18 07:39:38 +0200 | [diff] [blame] | 1259 | /* Set up 64MB inbound memory window at 0 */ |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1260 | out_le32(mbase + PCI_BASE_ADDRESS_0, 0); |
| 1261 | out_le32(mbase + PCI_BASE_ADDRESS_1, 0); |
Stefan Roese | e7fe4c5 | 2007-10-18 07:39:38 +0200 | [diff] [blame] | 1262 | |
| 1263 | out_le32(mbase + PECFG_PIM01SAH, 0xffffffff); |
| 1264 | out_le32(mbase + PECFG_PIM01SAL, 0xfc000000); |
| 1265 | |
| 1266 | /* Setup BAR0 */ |
| 1267 | out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffff); |
| 1268 | out_le32(mbase + PECFG_BAR0LMPA, 0xfc000000 | PCI_BASE_ADDRESS_MEM_TYPE_64); |
| 1269 | |
| 1270 | /* Disable BAR1 & BAR2 */ |
| 1271 | out_le32(mbase + PECFG_BAR1MPA, 0); |
| 1272 | out_le32(mbase + PECFG_BAR2HMPA, 0); |
| 1273 | out_le32(mbase + PECFG_BAR2LMPA, 0); |
| 1274 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1275 | out_le32(mbase + PECFG_PIM0LAL, U64_TO_U32_LOW(CONFIG_SYS_PCIE_INBOUND_BASE)); |
| 1276 | out_le32(mbase + PECFG_PIM0LAH, U64_TO_U32_HIGH(CONFIG_SYS_PCIE_INBOUND_BASE)); |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1277 | out_le32(mbase + PECFG_PIMEN, 0x1); |
| 1278 | |
| 1279 | /* Enable I/O, Mem, and Busmaster cycles */ |
| 1280 | out_le16((u16 *)(mbase + PCI_COMMAND), |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1281 | in_le16((u16 *)(mbase + PCI_COMMAND)) | |
| 1282 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); |
Stefan Roese | 7a41bde | 2007-10-05 09:18:23 +0200 | [diff] [blame] | 1283 | out_le16(mbase + 0x200, 0xcaad); /* Setting vendor ID */ |
| 1284 | out_le16(mbase + 0x202, 0xfeed); /* Setting device ID */ |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1285 | |
Stefan Roese | e7fe4c5 | 2007-10-18 07:39:38 +0200 | [diff] [blame] | 1286 | /* Set Class Code to Processor/PPC */ |
| 1287 | out_le32(mbase + 0x208, 0x0b200001); |
| 1288 | |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1289 | attempts = 10; |
Stefan Roese | be6fea9 | 2007-10-03 21:16:32 +0200 | [diff] [blame] | 1290 | while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 8))) { |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1291 | if (!(attempts--)) { |
| 1292 | printf("PCIE%d: BME not active\n", port); |
| 1293 | return -1; |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1294 | } |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1295 | mdelay(1000); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1296 | } |
Stefan Roese | a0d9634 | 2007-10-03 10:38:09 +0200 | [diff] [blame] | 1297 | |
Stefan Roese | 4e45662 | 2007-10-05 14:23:43 +0200 | [diff] [blame] | 1298 | printf("PCIE%d: successfully set as endpoint\n", port); |
Stefan Roese | 074e975 | 2006-08-29 08:05:15 +0200 | [diff] [blame] | 1299 | |
| 1300 | return 0; |
Rafal Jaworowski | a2e7ef0 | 2006-08-10 12:43:17 +0200 | [diff] [blame] | 1301 | } |
Stefan Roese | 8d98230 | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1302 | #endif /* CONFIG_440SPE && CONFIG_PCI */ |