Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1 | /* |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 2 | * Copyright (C) Freescale Semiconductor,Inc. |
| 3 | * 2005, 2006. All rights reserved. |
| 4 | * |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 5 | * Ed Swarthout (ed.swarthout@freescale.com) |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 6 | * Jason Jin (Jason.jin@freescale.com) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 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 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | /* |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 28 | * PCIE Configuration space access support for PCIE Bridge |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 29 | */ |
| 30 | #include <common.h> |
| 31 | #include <pci.h> |
| 32 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 33 | #if defined(CONFIG_PCI) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 34 | void |
| 35 | pci_mpc86xx_init(struct pci_controller *hose) |
| 36 | { |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 37 | volatile immap_t *immap = (immap_t *) CFG_CCSRBAR; |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 38 | volatile ccsr_pex_t *pcie1 = &immap->im_pex1; |
| 39 | u16 temp16; |
| 40 | u32 temp32; |
| 41 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 42 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 43 | uint host1_agent = (gur->porbmsr & MPC86xx_PORBMSR_HA) >> 17; |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 44 | uint pcie1_host = (host1_agent == 2) || (host1_agent == 3); |
| 45 | uint pcie1_agent = (host1_agent == 0) || (host1_agent == 1); |
| 46 | uint devdisr = gur->devdisr; |
| 47 | uint io_sel = (gur->pordevsr & MPC86xx_PORDEVSR_IO_SEL) >> 16; |
| 48 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 49 | if ((io_sel == 2 || io_sel == 3 || io_sel == 5 || io_sel == 6 || |
| 50 | io_sel == 7 || io_sel == 0xf) |
| 51 | && !(devdisr & MPC86xx_DEVDISR_PCIEX1)) { |
| 52 | printf("PCI-EXPRESS 1: Configured as %s \n", |
| 53 | pcie1_agent ? "Agent" : "Host"); |
| 54 | if (pcie1_agent) |
| 55 | return; /*Don't scan bus when configured as agent */ |
| 56 | printf(" Scanning PCIE bus"); |
| 57 | debug("0x%08x=0x%08x ", |
| 58 | &pcie1->pme_msg_det, |
| 59 | pcie1->pme_msg_det); |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 60 | if (pcie1->pme_msg_det) { |
| 61 | pcie1->pme_msg_det = 0xffffffff; |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 62 | debug(" with errors. Clearing. Now 0x%08x", |
| 63 | pcie1->pme_msg_det); |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 64 | } |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 65 | debug("\n"); |
| 66 | } else { |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 67 | printf("PCI-EXPRESS 1 disabled!\n"); |
| 68 | return; |
| 69 | } |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 70 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 71 | /* |
| 72 | * Set first_bus=0 only skipped B0:D0:F0 which is |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 73 | * a reserved device in M1575, but make it easy for |
| 74 | * most of the scan process. |
| 75 | */ |
| 76 | hose->first_busno = 0x00; |
| 77 | hose->last_busno = 0xfe; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 78 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 79 | pcie_setup_indirect(hose, (CFG_IMMR + 0x8000), (CFG_IMMR + 0x8004)); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 80 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 81 | pci_hose_read_config_word(hose, |
| 82 | PCI_BDF(0, 0, 0), PCI_COMMAND, &temp16); |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 83 | temp16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 84 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO; |
| 85 | pci_hose_write_config_word(hose, |
| 86 | PCI_BDF(0, 0, 0), PCI_COMMAND, temp16); |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 87 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 88 | pci_hose_write_config_word(hose, PCI_BDF(0, 0, 0), PCI_STATUS, 0xffff); |
| 89 | pci_hose_write_config_byte(hose, |
| 90 | PCI_BDF(0, 0, 0), PCI_LATENCY_TIMER, 0x80); |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 91 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 92 | pci_hose_read_config_dword(hose, PCI_BDF(0, 0, 0), PCI_PRIMARY_BUS, |
| 93 | &temp32); |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 94 | temp32 = (temp32 & 0xff000000) | (0xff) | (0x0 << 8) | (0xfe << 16); |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 95 | pci_hose_write_config_dword(hose, PCI_BDF(0, 0, 0), PCI_PRIMARY_BUS, |
| 96 | temp32); |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 97 | |
| 98 | pcie1->powar1 = 0; |
| 99 | pcie1->powar2 = 0; |
| 100 | pcie1->piwar1 = 0; |
| 101 | pcie1->piwar1 = 0; |
| 102 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 103 | pcie1->powbar1 = (CFG_PCI1_MEM_BASE >> 12) & 0x000fffff; |
| 104 | pcie1->powar1 = 0x8004401c; /* 512M MEM space */ |
| 105 | pcie1->potar1 = (CFG_PCI1_MEM_BASE >> 12) & 0x000fffff; |
| 106 | pcie1->potear1 = 0x00000000; |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 107 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 108 | pcie1->powbar2 = (CFG_PCI1_IO_BASE >> 12) & 0x000fffff; |
| 109 | pcie1->powar2 = 0x80088017; /* 16M IO space */ |
| 110 | pcie1->potar2 = 0x00000000; |
| 111 | pcie1->potear2 = 0x00000000; |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 112 | |
| 113 | pcie1->pitar1 = 0x00000000; |
| 114 | pcie1->piwbar1 = 0x00000000; |
| 115 | /* Enable, Prefetch, Local Mem, * Snoop R/W, 2G */ |
| 116 | pcie1->piwar1 = 0xa0f5501e; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 117 | |
| 118 | pci_set_region(hose->regions + 0, |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 119 | CFG_PCI_MEMORY_BUS, |
| 120 | CFG_PCI_MEMORY_PHYS, |
| 121 | CFG_PCI_MEMORY_SIZE, |
| 122 | PCI_REGION_MEM | PCI_REGION_MEMORY); |
| 123 | |
| 124 | pci_set_region(hose->regions + 1, |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 125 | CFG_PCI1_MEM_BASE, |
| 126 | CFG_PCI1_MEM_PHYS, |
| 127 | CFG_PCI1_MEM_SIZE, |
| 128 | PCI_REGION_MEM); |
| 129 | |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 130 | pci_set_region(hose->regions + 2, |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 131 | CFG_PCI1_IO_BASE, |
| 132 | CFG_PCI1_IO_PHYS, |
| 133 | CFG_PCI1_IO_SIZE, |
| 134 | PCI_REGION_IO); |
| 135 | |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 136 | hose->region_count = 3; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 137 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 138 | pci_register_hose(hose); |
| 139 | |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 140 | hose->last_busno = pci_hose_scan(hose); |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 141 | debug("pcie_mpc86xx_init: last_busno %x\n", hose->last_busno); |
| 142 | debug("pcie_mpc86xx init: current_busno %x\n ", hose->current_busno); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 143 | |
Jin Zhengxiong-R64188 | 377d596 | 2006-06-27 18:11:54 +0800 | [diff] [blame] | 144 | printf("....PCIE1 scan & enumeration done\n"); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 145 | } |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 146 | #endif /* CONFIG_PCI */ |