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