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