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