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