wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 2 | * Copyright 2004 Freescale Semiconductor. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003 Motorola Inc. |
| 4 | * Xianghua Xiao (x.xiao@motorola.com) |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * PCI Configuration space access support for MPC85xx PCI Bridge |
| 27 | */ |
| 28 | #include <common.h> |
| 29 | #include <asm/cpm_85xx.h> |
| 30 | #include <pci.h> |
| 31 | |
Kumar Gala | 3ab0b2d | 2008-08-12 11:13:08 -0500 | [diff] [blame] | 32 | #if defined(CONFIG_PCI) && !defined(CONFIG_FSL_PCI_INIT) |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 33 | |
Kumar Gala | 3fe8087 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 34 | #ifndef CONFIG_SYS_PCI1_MEM_BUS |
| 35 | #define CONFIG_SYS_PCI1_MEM_BUS CONFIG_SYS_PCI1_MEM_BASE |
| 36 | #endif |
| 37 | |
Kumar Gala | 64bb6d1 | 2008-12-02 16:08:37 -0600 | [diff] [blame] | 38 | #ifndef CONFIG_SYS_PCI1_IO_BUS |
| 39 | #define CONFIG_SYS_PCI1_IO_BUS CONFIG_SYS_PCI1_IO_BASE |
| 40 | #endif |
| 41 | |
Kumar Gala | 3fe8087 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 42 | #ifndef CONFIG_SYS_PCI2_MEM_BUS |
| 43 | #define CONFIG_SYS_PCI2_MEM_BUS CONFIG_SYS_PCI2_MEM_BASE |
| 44 | #endif |
| 45 | |
Kumar Gala | 64bb6d1 | 2008-12-02 16:08:37 -0600 | [diff] [blame] | 46 | #ifndef CONFIG_SYS_PCI2_IO_BUS |
| 47 | #define CONFIG_SYS_PCI2_IO_BUS CONFIG_SYS_PCI2_IO_BASE |
| 48 | #endif |
| 49 | |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 50 | static struct pci_controller *pci_hose; |
| 51 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 52 | void |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 53 | pci_mpc85xx_init(struct pci_controller *board_hose) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 54 | { |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 55 | u16 reg16; |
| 56 | u32 dev; |
| 57 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 58 | volatile ccsr_pcix_t *pcix = (void *)(CONFIG_SYS_MPC85xx_PCIX_ADDR); |
Matthew McClintock | 5b94882 | 2006-10-11 15:13:01 -0500 | [diff] [blame] | 59 | #ifdef CONFIG_MPC85XX_PCI2 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 60 | volatile ccsr_pcix_t *pcix2 = (void *)(CONFIG_SYS_MPC85xx_PCIX2_ADDR); |
Matthew McClintock | 5b94882 | 2006-10-11 15:13:01 -0500 | [diff] [blame] | 61 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 62 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 63 | struct pci_controller * hose; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 64 | |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 65 | pci_hose = board_hose; |
| 66 | |
| 67 | hose = &pci_hose[0]; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 68 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 69 | hose->first_busno = 0; |
| 70 | hose->last_busno = 0xff; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 71 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 72 | pci_setup_indirect(hose, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 73 | (CONFIG_SYS_IMMR+0x8000), |
| 74 | (CONFIG_SYS_IMMR+0x8004)); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 75 | |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 76 | /* |
| 77 | * Hose scan. |
| 78 | */ |
| 79 | dev = PCI_BDF(hose->first_busno, 0, 0); |
| 80 | pci_hose_read_config_word (hose, dev, PCI_COMMAND, ®16); |
| 81 | reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
| 82 | pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16); |
| 83 | |
| 84 | /* |
| 85 | * Clear non-reserved bits in status register. |
| 86 | */ |
| 87 | pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff); |
| 88 | |
Peter Tyser | af7c3e3 | 2008-12-01 13:47:12 -0600 | [diff] [blame] | 89 | if (!(gur->pordevsr & MPC85xx_PORDEVSR_PCI1)) { |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 90 | /* PCI-X init */ |
Matthew McClintock | 5817a86 | 2006-06-28 10:47:03 -0500 | [diff] [blame] | 91 | if (CONFIG_SYS_CLK_FREQ < 66000000) |
| 92 | printf("PCI-X will only work at 66 MHz\n"); |
| 93 | |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 94 | reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ |
| 95 | | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E; |
| 96 | pci_hose_write_config_word(hose, dev, PCIX_COMMAND, reg16); |
| 97 | } |
| 98 | |
Kumar Gala | 3fe8087 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 99 | pcix->potar1 = (CONFIG_SYS_PCI1_MEM_BUS >> 12) & 0x000fffff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 100 | pcix->potear1 = 0x00000000; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 101 | pcix->powbar1 = (CONFIG_SYS_PCI1_MEM_PHYS >> 12) & 0x000fffff; |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 102 | pcix->powbear1 = 0x00000000; |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 103 | pcix->powar1 = (POWAR_EN | POWAR_MEM_READ | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 104 | POWAR_MEM_WRITE | (__ilog2(CONFIG_SYS_PCI1_MEM_SIZE) - 1)); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 105 | |
Kumar Gala | 64bb6d1 | 2008-12-02 16:08:37 -0600 | [diff] [blame] | 106 | pcix->potar2 = (CONFIG_SYS_PCI1_IO_BUS >> 12) & 0x000fffff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 107 | pcix->potear2 = 0x00000000; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 108 | pcix->powbar2 = (CONFIG_SYS_PCI1_IO_PHYS >> 12) & 0x000fffff; |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 109 | pcix->powbear2 = 0x00000000; |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 110 | pcix->powar2 = (POWAR_EN | POWAR_IO_READ | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 111 | POWAR_IO_WRITE | (__ilog2(CONFIG_SYS_PCI1_IO_SIZE) - 1)); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 112 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 113 | pcix->pitar1 = 0x00000000; |
| 114 | pcix->piwbar1 = 0x00000000; |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 115 | pcix->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL | |
| 116 | PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 117 | |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 118 | pcix->powar3 = 0; |
| 119 | pcix->powar4 = 0; |
| 120 | pcix->piwar2 = 0; |
| 121 | pcix->piwar3 = 0; |
wdenk | 0424e5d | 2004-10-10 20:23:57 +0000 | [diff] [blame] | 122 | |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 123 | pci_set_region(hose->regions + 0, |
Kumar Gala | 3fe8087 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 124 | CONFIG_SYS_PCI1_MEM_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 125 | CONFIG_SYS_PCI1_MEM_PHYS, |
| 126 | CONFIG_SYS_PCI1_MEM_SIZE, |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 127 | PCI_REGION_MEM); |
Stefan Roese | 8c69551 | 2005-11-07 13:43:06 +0100 | [diff] [blame] | 128 | |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 129 | pci_set_region(hose->regions + 1, |
Kumar Gala | 64bb6d1 | 2008-12-02 16:08:37 -0600 | [diff] [blame] | 130 | CONFIG_SYS_PCI1_IO_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 131 | CONFIG_SYS_PCI1_IO_PHYS, |
| 132 | CONFIG_SYS_PCI1_IO_SIZE, |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 133 | PCI_REGION_IO); |
| 134 | |
| 135 | hose->region_count = 2; |
| 136 | |
| 137 | pci_register_hose(hose); |
Stefan Roese | 8c69551 | 2005-11-07 13:43:06 +0100 | [diff] [blame] | 138 | |
wdenk | 0424e5d | 2004-10-10 20:23:57 +0000 | [diff] [blame] | 139 | #if defined(CONFIG_MPC8555CDS) || defined(CONFIG_MPC8541CDS) |
| 140 | /* |
| 141 | * This is a SW workaround for an apparent HW problem |
| 142 | * in the PCI controller on the MPC85555/41 CDS boards. |
| 143 | * The first config cycle must be to a valid, known |
| 144 | * device on the PCI bus in order to trick the PCI |
| 145 | * controller state machine into a known valid state. |
| 146 | * Without this, the first config cycle has the chance |
| 147 | * of hanging the controller permanently, just leaving |
| 148 | * it in a semi-working state, or leaving it working. |
| 149 | * |
| 150 | * Pick on the Tundra, Device 17, to get it right. |
| 151 | */ |
| 152 | { |
| 153 | u8 header_type; |
| 154 | |
| 155 | pci_hose_read_config_byte(hose, |
Randy Vinson | 1dfd6d9 | 2007-02-27 19:42:22 -0700 | [diff] [blame] | 156 | PCI_BDF(0,BRIDGE_ID,0), |
wdenk | 0424e5d | 2004-10-10 20:23:57 +0000 | [diff] [blame] | 157 | PCI_HEADER_TYPE, |
| 158 | &header_type); |
| 159 | } |
wdenk | 0424e5d | 2004-10-10 20:23:57 +0000 | [diff] [blame] | 160 | #endif |
| 161 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 162 | hose->last_busno = pci_hose_scan(hose); |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 163 | |
| 164 | #ifdef CONFIG_MPC85XX_PCI2 |
| 165 | hose = &pci_hose[1]; |
| 166 | |
| 167 | hose->first_busno = pci_hose[0].last_busno + 1; |
| 168 | hose->last_busno = 0xff; |
| 169 | |
| 170 | pci_setup_indirect(hose, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 171 | (CONFIG_SYS_IMMR+0x9000), |
| 172 | (CONFIG_SYS_IMMR+0x9004)); |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 173 | |
| 174 | dev = PCI_BDF(hose->first_busno, 0, 0); |
| 175 | pci_hose_read_config_word (hose, dev, PCI_COMMAND, ®16); |
| 176 | reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
| 177 | pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16); |
| 178 | |
| 179 | /* |
| 180 | * Clear non-reserved bits in status register. |
| 181 | */ |
| 182 | pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff); |
| 183 | |
Kumar Gala | 3fe8087 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 184 | pcix2->potar1 = (CONFIG_SYS_PCI2_MEM_BUS >> 12) & 0x000fffff; |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 185 | pcix2->potear1 = 0x00000000; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 186 | pcix2->powbar1 = (CONFIG_SYS_PCI2_MEM_PHYS >> 12) & 0x000fffff; |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 187 | pcix2->powbear1 = 0x00000000; |
| 188 | pcix2->powar1 = (POWAR_EN | POWAR_MEM_READ | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 189 | POWAR_MEM_WRITE | (__ilog2(CONFIG_SYS_PCI2_MEM_SIZE) - 1)); |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 190 | |
Kumar Gala | 64bb6d1 | 2008-12-02 16:08:37 -0600 | [diff] [blame] | 191 | pcix2->potar2 = (CONFIG_SYS_PCI2_IO_BUS >> 12) & 0x000fffff; |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 192 | pcix2->potear2 = 0x00000000; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 193 | pcix2->powbar2 = (CONFIG_SYS_PCI2_IO_PHYS >> 12) & 0x000fffff; |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 194 | pcix2->powbear2 = 0x00000000; |
| 195 | pcix2->powar2 = (POWAR_EN | POWAR_IO_READ | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 196 | POWAR_IO_WRITE | (__ilog2(CONFIG_SYS_PCI2_IO_SIZE) - 1)); |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 197 | |
| 198 | pcix2->pitar1 = 0x00000000; |
| 199 | pcix2->piwbar1 = 0x00000000; |
| 200 | pcix2->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL | |
| 201 | PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G); |
| 202 | |
| 203 | pcix2->powar3 = 0; |
| 204 | pcix2->powar4 = 0; |
| 205 | pcix2->piwar2 = 0; |
| 206 | pcix2->piwar3 = 0; |
| 207 | |
| 208 | pci_set_region(hose->regions + 0, |
Kumar Gala | 3fe8087 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 209 | CONFIG_SYS_PCI2_MEM_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 210 | CONFIG_SYS_PCI2_MEM_PHYS, |
| 211 | CONFIG_SYS_PCI2_MEM_SIZE, |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 212 | PCI_REGION_MEM); |
| 213 | |
| 214 | pci_set_region(hose->regions + 1, |
Kumar Gala | 64bb6d1 | 2008-12-02 16:08:37 -0600 | [diff] [blame] | 215 | CONFIG_SYS_PCI2_IO_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 216 | CONFIG_SYS_PCI2_IO_PHYS, |
| 217 | CONFIG_SYS_PCI2_IO_SIZE, |
Matthew McClintock | f5e4f28 | 2006-06-28 10:45:17 -0500 | [diff] [blame] | 218 | PCI_REGION_IO); |
| 219 | |
| 220 | hose->region_count = 2; |
| 221 | |
| 222 | /* |
| 223 | * Hose scan. |
| 224 | */ |
| 225 | pci_register_hose(hose); |
| 226 | |
| 227 | hose->last_busno = pci_hose_scan(hose); |
| 228 | #endif |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 229 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 230 | #endif /* CONFIG_PCI */ |