blob: 3c635922729b637fb7a238f768f02ab39a0f6b74 [file] [log] [blame]
John Rigbyd1228c92008-02-26 09:38:14 -07001/*
2 * Copyright (C) Freescale Semiconductor, Inc. 2006, 2007. All rights reserved.
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24
25#include <asm/mmu.h>
26#include <asm/global_data.h>
27#include <pci.h>
28#if defined(CONFIG_OF_LIBFDT)
29#include <libfdt.h>
30#include <fdt_support.h>
31#endif
32
33DECLARE_GLOBAL_DATA_PTR;
34
35/* System RAM mapped to PCI space */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020036#define CONFIG_PCI_SYS_MEM_BUS CONFIG_SYS_SDRAM_BASE
37#define CONFIG_PCI_SYS_MEM_PHYS CONFIG_SYS_SDRAM_BASE
John Rigbyd1228c92008-02-26 09:38:14 -070038
39static struct pci_controller pci_hose;
40
41
42/**************************************************************************
43 * pci_init_board()
44 *
45 */
46void
47pci_init_board(void)
48{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020049 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
John Rigbyd1228c92008-02-26 09:38:14 -070050 volatile law512x_t *pci_law;
51 volatile pot512x_t *pci_pot;
52 volatile pcictrl512x_t *pci_ctrl;
53 volatile pciconf512x_t *pci_conf;
54 u16 reg16;
55 u32 reg32;
56 u32 dev;
Wolfgang Denke6b91012009-05-16 10:47:39 +020057 int i;
John Rigbyd1228c92008-02-26 09:38:14 -070058 struct pci_controller *hose;
59
60 /* Set PCI divider for 33MHz */
61 reg32 = immr->clk.scfr[0];
62 reg32 &= ~(SCFR1_PCI_DIV_MASK);
63 reg32 |= SCFR1_PCI_DIV << SCFR1_PCI_DIV_SHIFT;
64 immr->clk.scfr[0] = reg32;
65
66 pci_law = immr->sysconf.pcilaw;
67 pci_pot = immr->ios.pot;
68 pci_ctrl = &immr->pci_ctrl;
69 pci_conf = &immr->pci_conf;
70
71 hose = &pci_hose;
72
73 /*
74 * Release PCI RST Output signal
75 */
76 pci_ctrl->gcr = 0;
77 udelay(2000);
78 pci_ctrl->gcr = 1;
79
80 /* We need to wait at least a 1sec based on PCI specs */
Wolfgang Denke6b91012009-05-16 10:47:39 +020081 for (i = 0; i < 1000; i++)
82 udelay(1000);
John Rigbyd1228c92008-02-26 09:38:14 -070083
84 /*
85 * Configure PCI Local Access Windows
86 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020087 pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
John Rigbyd1228c92008-02-26 09:38:14 -070088 pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M;
89
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020090 pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
John Rigbyd1228c92008-02-26 09:38:14 -070091 pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_16M;
92
93 /*
94 * Configure PCI Outbound Translation Windows
95 */
96
97 /* PCI mem space - prefetch */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098 pci_pot[0].potar = (CONFIG_SYS_PCI_MEM_BASE >> 12) & POTAR_TA_MASK;
99 pci_pot[0].pobar = (CONFIG_SYS_PCI_MEM_PHYS >> 12) & POBAR_BA_MASK;
John Rigbyd1228c92008-02-26 09:38:14 -0700100 pci_pot[0].pocmr = POCMR_EN | POCMR_PRE | POCMR_CM_256M;
101
102 /* PCI IO space */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103 pci_pot[1].potar = (CONFIG_SYS_PCI_IO_BASE >> 12) & POTAR_TA_MASK;
104 pci_pot[1].pobar = (CONFIG_SYS_PCI_IO_PHYS >> 12) & POBAR_BA_MASK;
John Rigbyd1228c92008-02-26 09:38:14 -0700105 pci_pot[1].pocmr = POCMR_EN | POCMR_IO | POCMR_CM_16M;
106
107 /* PCI mmio - non-prefetch mem space */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200108 pci_pot[2].potar = (CONFIG_SYS_PCI_MMIO_BASE >> 12) & POTAR_TA_MASK;
109 pci_pot[2].pobar = (CONFIG_SYS_PCI_MMIO_PHYS >> 12) & POBAR_BA_MASK;
John Rigbyd1228c92008-02-26 09:38:14 -0700110 pci_pot[2].pocmr = POCMR_EN | POCMR_CM_256M;
111
112 /*
113 * Configure PCI Inbound Translation Windows
114 */
115
116 /* we need RAM mapped to PCI space for the devices to
117 * access main memory */
118 pci_ctrl[0].pitar1 = 0x0;
119 pci_ctrl[0].pibar1 = 0x0;
120 pci_ctrl[0].piebar1 = 0x0;
121 pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
122 PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
123
124 hose->first_busno = 0;
125 hose->last_busno = 0xff;
126
127 /* PCI memory prefetch space */
128 pci_set_region(hose->regions + 0,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200129 CONFIG_SYS_PCI_MEM_BASE,
130 CONFIG_SYS_PCI_MEM_PHYS,
131 CONFIG_SYS_PCI_MEM_SIZE,
John Rigbyd1228c92008-02-26 09:38:14 -0700132 PCI_REGION_MEM|PCI_REGION_PREFETCH);
133
134 /* PCI memory space */
135 pci_set_region(hose->regions + 1,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136 CONFIG_SYS_PCI_MMIO_BASE,
137 CONFIG_SYS_PCI_MMIO_PHYS,
138 CONFIG_SYS_PCI_MMIO_SIZE,
John Rigbyd1228c92008-02-26 09:38:14 -0700139 PCI_REGION_MEM);
140
141 /* PCI IO space */
142 pci_set_region(hose->regions + 2,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200143 CONFIG_SYS_PCI_IO_BASE,
144 CONFIG_SYS_PCI_IO_PHYS,
145 CONFIG_SYS_PCI_IO_SIZE,
John Rigbyd1228c92008-02-26 09:38:14 -0700146 PCI_REGION_IO);
147
148 /* System memory space */
149 pci_set_region(hose->regions + 3,
150 CONFIG_PCI_SYS_MEM_BUS,
151 CONFIG_PCI_SYS_MEM_PHYS,
152 gd->ram_size,
Kumar Galaefa1f1d2009-02-06 09:49:31 -0600153 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
John Rigbyd1228c92008-02-26 09:38:14 -0700154
155 hose->region_count = 4;
156
157 pci_setup_indirect(hose,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200158 (CONFIG_SYS_IMMR + 0x8300),
159 (CONFIG_SYS_IMMR + 0x8304));
John Rigbyd1228c92008-02-26 09:38:14 -0700160
161 pci_register_hose(hose);
162
163 /*
164 * Write to Command register
165 */
166 reg16 = 0xff;
167 dev = PCI_BDF(hose->first_busno, 0, 0);
168 pci_hose_read_config_word(hose, dev, PCI_COMMAND, &reg16);
169 reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
170 pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
171
172 /*
173 * Clear non-reserved bits in status register.
174 */
175 pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
176 pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
177 pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
178
179#ifdef CONFIG_PCI_SCAN_SHOW
180 printf("PCI: Bus Dev VenId DevId Class Int\n");
181#endif
182 /*
183 * Hose scan.
184 */
185 hose->last_busno = pci_hose_scan(hose);
186}
187
188#if defined(CONFIG_OF_LIBFDT)
189void ft_pci_setup(void *blob, bd_t *bd)
190{
191 int nodeoffset;
192 int tmp[2];
193 const char *path;
194
195 nodeoffset = fdt_path_offset(blob, "/aliases");
196 if (nodeoffset >= 0) {
197 path = fdt_getprop(blob, nodeoffset, "pci", NULL);
198 if (path) {
199 tmp[0] = cpu_to_be32(pci_hose.first_busno);
200 tmp[1] = cpu_to_be32(pci_hose.last_busno);
201 do_fixup_by_path(blob, path, "bus-range",
202 &tmp, sizeof(tmp), 1);
203
204 tmp[0] = cpu_to_be32(gd->pci_clk);
205 do_fixup_by_path(blob, path, "clock-frequency",
206 &tmp, sizeof(tmp[0]), 1);
207 }
208 }
209}
210#endif /* CONFIG_OF_LIBFDT */