wdenk | 4d75a50 | 2003-03-25 16:50:56 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | |
| 26 | #ifdef CONFIG_PCI |
| 27 | |
| 28 | #include <pci.h> |
| 29 | #include <asm/m8260_pci.h> |
| 30 | |
| 31 | /* |
| 32 | * Local->PCI map (from CPU) controlled by |
| 33 | * MPC826x master window |
| 34 | * |
| 35 | * 0x80000000 - 0xBFFFFFFF Total CPU2PCI space PCIBR0 |
| 36 | * |
| 37 | * 0x80000000 - 0x8FFFFFFF PCI Mem with prefetch (Outbound ATU #1) |
| 38 | * 0x90000000 - 0x9FFFFFFF PCI Mem w/o prefetch (Outbound ATU #2) |
| 39 | * 0xA0000000 - 0xAFFFFFFF 32-bit PCI IO (Outbound ATU #3) |
| 40 | * |
| 41 | * PCI->Local map (from PCI) |
| 42 | * MPC826x slave window controlled by |
| 43 | * |
| 44 | * 0x00000000 - 0x07FFFFFF MPC826x local memory (Inbound ATU #1) |
| 45 | */ |
| 46 | |
| 47 | /* |
| 48 | * Slave window that allows PCI masters to access MPC826x local memory. |
| 49 | * This window is set up using the first set of Inbound ATU registers |
| 50 | */ |
| 51 | |
| 52 | #define PCI_SLV_MEM_LOCAL CFG_SDRAM_BASE /* Local base */ |
| 53 | #define PCI_SLV_MEM_BUS 0x00000000 /* PCI base */ |
| 54 | #define PICMR0_MASK_ATTRIB (PICMR_MASK_512MB | PICMR_ENABLE | \ |
| 55 | PICMR_PREFETCH_EN) |
| 56 | |
| 57 | /* |
| 58 | * This is the window that allows the CPU to access PCI address space. |
| 59 | * It will be setup with the SIU PCIBR0 register. All three PCI master |
| 60 | * windows, which allow the CPU to access PCI prefetch, non prefetch, |
| 61 | * and IO space (see below), must all fit within this window. |
| 62 | */ |
| 63 | |
| 64 | #define PCI_MSTR_LOCAL 0x80000000 /* Local base */ |
| 65 | #define PCIMSK0_MASK PCIMSK_1GB /* Size of window */ |
| 66 | |
| 67 | /* |
| 68 | * Master window that allows the CPU to access PCI Memory (prefetch). |
| 69 | * This window will be setup with the first set of Outbound ATU registers |
| 70 | * in the bridge. |
| 71 | */ |
| 72 | |
| 73 | #define PCI_MSTR_MEM_LOCAL 0x80000000 /* Local base */ |
| 74 | #define PCI_MSTR_MEM_BUS 0x80000000 /* PCI base */ |
| 75 | #define CPU_PCI_MEM_START PCI_MSTR_MEM_LOCAL |
| 76 | #define PCI_MSTR_MEM_SIZE 0x10000000 /* 256MB */ |
| 77 | #define POCMR0_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PREFETCH_EN) |
| 78 | |
| 79 | /* |
| 80 | * Master window that allows the CPU to access PCI Memory (non-prefetch). |
| 81 | * This window will be setup with the second set of Outbound ATU registers |
| 82 | * in the bridge. |
| 83 | */ |
| 84 | |
| 85 | #define PCI_MSTR_MEMIO_LOCAL 0x90000000 /* Local base */ |
| 86 | #define PCI_MSTR_MEMIO_BUS 0x90000000 /* PCI base */ |
| 87 | #define CPU_PCI_MEMIO_START PCI_MSTR_MEMIO_LOCAL |
| 88 | #define PCI_MSTR_MEMIO_SIZE 0x10000000 /* 256MB */ |
| 89 | #define POCMR1_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE) |
| 90 | |
| 91 | /* |
| 92 | * Master window that allows the CPU to access PCI IO space. |
| 93 | * This window will be setup with the third set of Outbound ATU registers |
| 94 | * in the bridge. |
| 95 | */ |
| 96 | |
| 97 | #define PCI_MSTR_IO_LOCAL 0xA0000000 /* Local base */ |
| 98 | #define PCI_MSTR_IO_BUS 0xA0000000 /* PCI base */ |
| 99 | #define CPU_PCI_IO_START PCI_MSTR_IO_LOCAL |
| 100 | #define PCI_MSTR_IO_SIZE 0x10000000 /* 256MB */ |
| 101 | #define POCMR2_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PCI_IO) |
| 102 | |
| 103 | /* PCI bus configuration registers. |
| 104 | */ |
| 105 | |
| 106 | #define PCI_CLASS_BRIDGE_CTLR 0x06 |
| 107 | |
| 108 | |
| 109 | static inline void pci_outl(u32 addr, u32 data) |
| 110 | { |
| 111 | *(volatile u32 *) addr = cpu_to_le32(data); |
| 112 | } |
| 113 | |
| 114 | void pci_mpc8250_init(struct pci_controller *hose) |
| 115 | { |
| 116 | u16 tempShort; |
| 117 | u32 immr_addr = CFG_IMMR; |
| 118 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 119 | pci_dev_t host_devno = PCI_BDF(0, 0, 0); |
| 120 | |
| 121 | pci_setup_indirect(hose, CFG_IMMR + PCI_CFG_ADDR_REG, |
| 122 | CFG_IMMR + PCI_CFG_DATA_REG); |
| 123 | |
| 124 | /* |
| 125 | * Setting required to enable IRQ1-IRQ7 (SIUMCR [DPPC]), |
| 126 | * and local bus for PCI (SIUMCR [LBPC]). |
| 127 | */ |
| 128 | immap->im_siu_conf.sc_siumcr = 0x00640000; |
| 129 | |
| 130 | /* Make PCI lowest priority */ |
| 131 | /* Each 4 bits is a device bus request and the MS 4bits |
| 132 | is highest priority */ |
| 133 | /* Bus 4bit value |
| 134 | --- ---------- |
| 135 | CPM high 0b0000 |
| 136 | CPM middle 0b0001 |
| 137 | CPM low 0b0010 |
| 138 | PCI reguest 0b0011 |
| 139 | Reserved 0b0100 |
| 140 | Reserved 0b0101 |
| 141 | Internal Core 0b0110 |
| 142 | External Master 1 0b0111 |
| 143 | External Master 2 0b1000 |
| 144 | External Master 3 0b1001 |
| 145 | The rest are reserved */ |
| 146 | immap->im_siu_conf.sc_ppc_alrh = 0x61207893; |
| 147 | |
| 148 | /* Park bus on core while modifying PCI Bus accesses */ |
| 149 | immap->im_siu_conf.sc_ppc_acr = 0x6; |
| 150 | |
| 151 | /* |
| 152 | * Set up master window that allows the CPU to access PCI space. This |
| 153 | * window is set up using the first SIU PCIBR registers. |
| 154 | */ |
| 155 | *(volatile unsigned long*)(immr_addr + M8265_PCIMSK0) = PCIMSK0_MASK; |
| 156 | *(volatile unsigned long*)(immr_addr + M8265_PCIBR0) = |
| 157 | PCI_MSTR_LOCAL | PCIBR_ENABLE; |
| 158 | |
| 159 | /* Release PCI RST (by default the PCI RST signal is held low) */ |
| 160 | pci_outl (immr_addr | PCI_GCR_REG, PCIGCR_PCI_BUS_EN); |
| 161 | |
| 162 | /* give it some time */ |
| 163 | udelay(1000); |
| 164 | |
| 165 | /* |
| 166 | * Set up master window that allows the CPU to access PCI Memory (prefetch) |
| 167 | * space. This window is set up using the first set of Outbound ATU registers. |
| 168 | */ |
| 169 | pci_outl (immr_addr | POTAR_REG0, PCI_MSTR_MEM_BUS >> 12); /* PCI base */ |
| 170 | pci_outl (immr_addr | POBAR_REG0, PCI_MSTR_MEM_LOCAL >> 12); /* Local base */ |
| 171 | pci_outl (immr_addr | POCMR_REG0, POCMR0_MASK_ATTRIB); /* Size & attribute */ |
| 172 | |
| 173 | /* |
| 174 | * Set up master window that allows the CPU to access PCI Memory (non-prefetch) |
| 175 | * space. This window is set up using the second set of Outbound ATU registers. |
| 176 | */ |
| 177 | pci_outl (immr_addr | POTAR_REG1, PCI_MSTR_MEMIO_BUS >> 12); /* PCI base */ |
| 178 | pci_outl (immr_addr | POBAR_REG1, PCI_MSTR_MEMIO_LOCAL >> 12); /* Local base */ |
| 179 | pci_outl (immr_addr | POCMR_REG1, POCMR1_MASK_ATTRIB); /* Size & attribute */ |
| 180 | |
| 181 | /* |
| 182 | * Set up master window that allows the CPU to access PCI IO space. This window |
| 183 | * is set up using the third set of Outbound ATU registers. |
| 184 | */ |
| 185 | pci_outl (immr_addr | POTAR_REG2, PCI_MSTR_IO_BUS >> 12); /* PCI base */ |
| 186 | pci_outl (immr_addr | POBAR_REG2, PCI_MSTR_IO_LOCAL >> 12); /* Local base */ |
| 187 | pci_outl (immr_addr | POCMR_REG2, POCMR2_MASK_ATTRIB); /* Size & attribute */ |
| 188 | |
| 189 | /* |
| 190 | * Set up slave window that allows PCI masters to access MPC826x local memory. |
| 191 | * This window is set up using the first set of Inbound ATU registers |
| 192 | */ |
| 193 | pci_outl (immr_addr | PITAR_REG0, PCI_SLV_MEM_LOCAL >> 12); /* Local base */ |
| 194 | pci_outl (immr_addr | PIBAR_REG0, PCI_SLV_MEM_BUS >> 12); /* PCI base */ |
| 195 | pci_outl (immr_addr | PICMR_REG0, PICMR0_MASK_ATTRIB); /* Size & attribute */ |
| 196 | |
| 197 | /* See above for description - puts PCI request as highest priority */ |
| 198 | immap->im_siu_conf.sc_ppc_alrh = 0x03124567; |
| 199 | |
| 200 | /* Park the bus on the PCI */ |
| 201 | immap->im_siu_conf.sc_ppc_acr = PPC_ACR_BUS_PARK_PCI; |
| 202 | |
| 203 | /* Host mode - specify the bridge as a host-PCI bridge */ |
| 204 | |
| 205 | pci_hose_write_config_byte(hose, host_devno, PCI_CLASS_CODE, |
| 206 | PCI_CLASS_BRIDGE_CTLR); |
| 207 | |
| 208 | /* Enable the host bridge to be a master on the PCI bus, and to act as a PCI memory target */ |
| 209 | pci_hose_read_config_word(hose, host_devno, PCI_COMMAND, &tempShort); |
| 210 | pci_hose_write_config_word(hose, host_devno, PCI_COMMAND, |
| 211 | tempShort | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
| 212 | |
| 213 | hose->first_busno = 0; |
| 214 | hose->last_busno = 0xff; |
| 215 | |
| 216 | /* System memory space */ |
| 217 | pci_set_region(hose->regions + 0, |
| 218 | CFG_SDRAM_BASE, |
| 219 | CFG_SDRAM_BASE, |
| 220 | 0x4000000, |
| 221 | PCI_REGION_MEM | PCI_REGION_MEMORY); |
| 222 | |
| 223 | /* PCI memory space */ |
| 224 | pci_set_region(hose->regions + 1, |
| 225 | PCI_MSTR_MEM_BUS, |
| 226 | PCI_MSTR_MEM_LOCAL, |
| 227 | PCI_MSTR_MEM_SIZE, |
| 228 | PCI_REGION_MEM); |
| 229 | |
| 230 | /* PCI I/O space */ |
| 231 | pci_set_region(hose->regions + 2, |
| 232 | PCI_MSTR_IO_BUS, |
| 233 | PCI_MSTR_IO_LOCAL, |
| 234 | PCI_MSTR_IO_SIZE, |
| 235 | PCI_REGION_IO); |
| 236 | |
| 237 | hose->region_count = 3; |
| 238 | |
| 239 | pci_register_hose(hose); |
| 240 | |
| 241 | hose->last_busno = pci_hose_scan(hose); |
| 242 | } |
| 243 | |
| 244 | #endif /* CONFIG_PCI */ |