blob: 7a8184a50123f982722570081fdc58f40c19ca35 [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
wdenk0ac6f8b2004-07-09 23:27:13 +00002 * Copyright 2004 Freescale Semiconductor.
wdenk42d1f032003-10-15 23:53:47 +00003 * 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 Gala129ba612008-08-12 11:13:08 -050032#if defined(CONFIG_PCI) && !defined(CONFIG_FSL_PCI_INIT)
wdenk0ac6f8b2004-07-09 23:27:13 +000033
Kumar Gala10795f42008-12-02 16:08:36 -060034#ifndef CONFIG_SYS_PCI1_MEM_BUS
35#define CONFIG_SYS_PCI1_MEM_BUS CONFIG_SYS_PCI1_MEM_BASE
36#endif
37
38#ifndef CONFIG_SYS_PCI2_MEM_BUS
39#define CONFIG_SYS_PCI2_MEM_BUS CONFIG_SYS_PCI2_MEM_BASE
40#endif
41
Matthew McClintock08745462006-06-28 10:45:17 -050042static struct pci_controller *pci_hose;
43
wdenk9aea9532004-08-01 23:02:45 +000044void
Matthew McClintock08745462006-06-28 10:45:17 -050045pci_mpc85xx_init(struct pci_controller *board_hose)
wdenk42d1f032003-10-15 23:53:47 +000046{
Matthew McClintock08745462006-06-28 10:45:17 -050047 u16 reg16;
48 u32 dev;
49
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020050 volatile ccsr_pcix_t *pcix = (void *)(CONFIG_SYS_MPC85xx_PCIX_ADDR);
Matthew McClintock7376eb82006-10-11 15:13:01 -050051#ifdef CONFIG_MPC85XX_PCI2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020052 volatile ccsr_pcix_t *pcix2 = (void *)(CONFIG_SYS_MPC85xx_PCIX2_ADDR);
Matthew McClintock7376eb82006-10-11 15:13:01 -050053#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020054 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Matthew McClintock08745462006-06-28 10:45:17 -050055 struct pci_controller * hose;
wdenk42d1f032003-10-15 23:53:47 +000056
Matthew McClintock08745462006-06-28 10:45:17 -050057 pci_hose = board_hose;
58
59 hose = &pci_hose[0];
wdenk42d1f032003-10-15 23:53:47 +000060
wdenk0ac6f8b2004-07-09 23:27:13 +000061 hose->first_busno = 0;
62 hose->last_busno = 0xff;
wdenk42d1f032003-10-15 23:53:47 +000063
Matthew McClintock08745462006-06-28 10:45:17 -050064 pci_setup_indirect(hose,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020065 (CONFIG_SYS_IMMR+0x8000),
66 (CONFIG_SYS_IMMR+0x8004));
Matthew McClintock08745462006-06-28 10:45:17 -050067
68 /*
69 * Hose scan.
70 */
71 dev = PCI_BDF(hose->first_busno, 0, 0);
72 pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
73 reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
74 pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
75
76 /*
77 * Clear non-reserved bits in status register.
78 */
79 pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
80
Peter Tyser9427ccd2008-12-01 13:47:12 -060081 if (!(gur->pordevsr & MPC85xx_PORDEVSR_PCI1)) {
Matthew McClintock08745462006-06-28 10:45:17 -050082 /* PCI-X init */
Matthew McClintock38433cc2006-06-28 10:47:03 -050083 if (CONFIG_SYS_CLK_FREQ < 66000000)
84 printf("PCI-X will only work at 66 MHz\n");
85
Matthew McClintock08745462006-06-28 10:45:17 -050086 reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
87 | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
88 pci_hose_write_config_word(hose, dev, PCIX_COMMAND, reg16);
89 }
90
Kumar Gala10795f42008-12-02 16:08:36 -060091 pcix->potar1 = (CONFIG_SYS_PCI1_MEM_BUS >> 12) & 0x000fffff;
Matthew McClintock08745462006-06-28 10:45:17 -050092 pcix->potear1 = 0x00000000;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020093 pcix->powbar1 = (CONFIG_SYS_PCI1_MEM_PHYS >> 12) & 0x000fffff;
Matthew McClintock08745462006-06-28 10:45:17 -050094 pcix->powbear1 = 0x00000000;
95 pcix->powar1 = (POWAR_EN | POWAR_MEM_READ |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020096 POWAR_MEM_WRITE | (__ilog2(CONFIG_SYS_PCI1_MEM_SIZE) - 1));
Matthew McClintock08745462006-06-28 10:45:17 -050097
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020098 pcix->potar2 = (CONFIG_SYS_PCI1_IO_BASE >> 12) & 0x000fffff;
Matthew McClintock08745462006-06-28 10:45:17 -050099 pcix->potear2 = 0x00000000;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200100 pcix->powbar2 = (CONFIG_SYS_PCI1_IO_PHYS >> 12) & 0x000fffff;
Matthew McClintock08745462006-06-28 10:45:17 -0500101 pcix->powbear2 = 0x00000000;
102 pcix->powar2 = (POWAR_EN | POWAR_IO_READ |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200103 POWAR_IO_WRITE | (__ilog2(CONFIG_SYS_PCI1_IO_SIZE) - 1));
Matthew McClintock08745462006-06-28 10:45:17 -0500104
105 pcix->pitar1 = 0x00000000;
106 pcix->piwbar1 = 0x00000000;
107 pcix->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
108 PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G);
109
110 pcix->powar3 = 0;
111 pcix->powar4 = 0;
112 pcix->piwar2 = 0;
113 pcix->piwar3 = 0;
114
wdenk9aea9532004-08-01 23:02:45 +0000115 pci_set_region(hose->regions + 0,
Kumar Gala10795f42008-12-02 16:08:36 -0600116 CONFIG_SYS_PCI1_MEM_BUS,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200117 CONFIG_SYS_PCI1_MEM_PHYS,
118 CONFIG_SYS_PCI1_MEM_SIZE,
wdenk9aea9532004-08-01 23:02:45 +0000119 PCI_REGION_MEM);
wdenk42d1f032003-10-15 23:53:47 +0000120
wdenk9aea9532004-08-01 23:02:45 +0000121 pci_set_region(hose->regions + 1,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200122 CONFIG_SYS_PCI1_IO_BASE,
123 CONFIG_SYS_PCI1_IO_PHYS,
124 CONFIG_SYS_PCI1_IO_SIZE,
wdenk9aea9532004-08-01 23:02:45 +0000125 PCI_REGION_IO);
wdenk42d1f032003-10-15 23:53:47 +0000126
wdenk0ac6f8b2004-07-09 23:27:13 +0000127 hose->region_count = 2;
wdenk42d1f032003-10-15 23:53:47 +0000128
wdenk9aea9532004-08-01 23:02:45 +0000129 pci_register_hose(hose);
wdenkcf336782004-10-10 20:23:57 +0000130
131#if defined(CONFIG_MPC8555CDS) || defined(CONFIG_MPC8541CDS)
132 /*
133 * This is a SW workaround for an apparent HW problem
134 * in the PCI controller on the MPC85555/41 CDS boards.
135 * The first config cycle must be to a valid, known
136 * device on the PCI bus in order to trick the PCI
137 * controller state machine into a known valid state.
138 * Without this, the first config cycle has the chance
139 * of hanging the controller permanently, just leaving
140 * it in a semi-working state, or leaving it working.
141 *
142 * Pick on the Tundra, Device 17, to get it right.
143 */
144 {
145 u8 header_type;
146
147 pci_hose_read_config_byte(hose,
Randy Vinson7f3f2bd2007-02-27 19:42:22 -0700148 PCI_BDF(0,BRIDGE_ID,0),
wdenkcf336782004-10-10 20:23:57 +0000149 PCI_HEADER_TYPE,
150 &header_type);
151 }
wdenkcf336782004-10-10 20:23:57 +0000152#endif
153
wdenk9aea9532004-08-01 23:02:45 +0000154 hose->last_busno = pci_hose_scan(hose);
Matthew McClintock08745462006-06-28 10:45:17 -0500155
156#ifdef CONFIG_MPC85XX_PCI2
157 hose = &pci_hose[1];
158
159 hose->first_busno = pci_hose[0].last_busno + 1;
160 hose->last_busno = 0xff;
161
162 pci_setup_indirect(hose,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200163 (CONFIG_SYS_IMMR+0x9000),
164 (CONFIG_SYS_IMMR+0x9004));
Matthew McClintock08745462006-06-28 10:45:17 -0500165
166 dev = PCI_BDF(hose->first_busno, 0, 0);
167 pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
168 reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
169 pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
170
171 /*
172 * Clear non-reserved bits in status register.
173 */
174 pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
175
Kumar Gala10795f42008-12-02 16:08:36 -0600176 pcix2->potar1 = (CONFIG_SYS_PCI2_MEM_BUS >> 12) & 0x000fffff;
Matthew McClintock08745462006-06-28 10:45:17 -0500177 pcix2->potear1 = 0x00000000;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200178 pcix2->powbar1 = (CONFIG_SYS_PCI2_MEM_PHYS >> 12) & 0x000fffff;
Matthew McClintock08745462006-06-28 10:45:17 -0500179 pcix2->powbear1 = 0x00000000;
180 pcix2->powar1 = (POWAR_EN | POWAR_MEM_READ |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200181 POWAR_MEM_WRITE | (__ilog2(CONFIG_SYS_PCI2_MEM_SIZE) - 1));
Matthew McClintock08745462006-06-28 10:45:17 -0500182
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200183 pcix2->potar2 = (CONFIG_SYS_PCI2_IO_BASE >> 12) & 0x000fffff;
Matthew McClintock08745462006-06-28 10:45:17 -0500184 pcix2->potear2 = 0x00000000;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200185 pcix2->powbar2 = (CONFIG_SYS_PCI2_IO_PHYS >> 12) & 0x000fffff;
Matthew McClintock08745462006-06-28 10:45:17 -0500186 pcix2->powbear2 = 0x00000000;
187 pcix2->powar2 = (POWAR_EN | POWAR_IO_READ |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200188 POWAR_IO_WRITE | (__ilog2(CONFIG_SYS_PCI2_IO_SIZE) - 1));
Matthew McClintock08745462006-06-28 10:45:17 -0500189
190 pcix2->pitar1 = 0x00000000;
191 pcix2->piwbar1 = 0x00000000;
192 pcix2->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
193 PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G);
194
195 pcix2->powar3 = 0;
196 pcix2->powar4 = 0;
197 pcix2->piwar2 = 0;
198 pcix2->piwar3 = 0;
199
200 pci_set_region(hose->regions + 0,
Kumar Gala10795f42008-12-02 16:08:36 -0600201 CONFIG_SYS_PCI2_MEM_BUS,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200202 CONFIG_SYS_PCI2_MEM_PHYS,
203 CONFIG_SYS_PCI2_MEM_SIZE,
Matthew McClintock08745462006-06-28 10:45:17 -0500204 PCI_REGION_MEM);
205
206 pci_set_region(hose->regions + 1,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200207 CONFIG_SYS_PCI2_IO_BASE,
208 CONFIG_SYS_PCI2_IO_PHYS,
209 CONFIG_SYS_PCI2_IO_SIZE,
Matthew McClintock08745462006-06-28 10:45:17 -0500210 PCI_REGION_IO);
211
212 hose->region_count = 2;
213
214 /*
215 * Hose scan.
216 */
217 pci_register_hose(hose);
218
219 hose->last_busno = pci_hose_scan(hose);
220#endif
wdenk42d1f032003-10-15 23:53:47 +0000221}
wdenk42d1f032003-10-15 23:53:47 +0000222#endif /* CONFIG_PCI */