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