blob: 0a47fdc1d36c047a7340bae19e6095d94310bcd8 [file] [log] [blame]
wdenk28536032003-03-25 16:50:56 +00001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denk34ca9d32005-09-25 18:49:35 +02005 * Copyright (c) 2005 MontaVista Software, Inc.
Wolfgang Denk8cc89d92005-09-25 16:27:55 +02006 * Vitaly Bordug <vbordug@ru.mvista.com>
7 * Added support for PCI bridge on MPC8272ADS
8 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02009 * SPDX-License-Identifier: GPL-2.0+
wdenk28536032003-03-25 16:50:56 +000010 */
11
12#include <common.h>
13
14#ifdef CONFIG_PCI
15
16#include <pci.h>
wdenkbf2f8c92003-05-22 22:52:13 +000017#include <mpc8260.h>
wdenk28536032003-03-25 16:50:56 +000018#include <asm/m8260_pci.h>
wdenk56ed43e2004-02-22 23:46:08 +000019#include <asm/io.h>
Matvejchikov Ilya8743c792008-07-06 13:57:00 +040020#ifdef CONFIG_OF_LIBFDT
21#include <libfdt.h>
22#include <fdt_support.h>
23#endif
Wolfgang Denk6405a152006-03-31 18:32:53 +020024
Wolfgang Denke5357d02006-05-30 23:32:44 +020025#if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272 || defined CONFIG_PM826
Wolfgang Denk6405a152006-03-31 18:32:53 +020026DECLARE_GLOBAL_DATA_PTR;
27#endif
28
wdenk28536032003-03-25 16:50:56 +000029/*
wdenk56ed43e2004-02-22 23:46:08 +000030 * Local->PCI map (from CPU) controlled by
wdenk28536032003-03-25 16:50:56 +000031 * MPC826x master window
32 *
wdenk56ed43e2004-02-22 23:46:08 +000033 * 0x80000000 - 0xBFFFFFFF CPU2PCI space PCIBR0
34 * 0xF4000000 - 0xF7FFFFFF CPU2PCI space PCIBR1
wdenk57b2d802003-06-27 21:31:46 +000035 *
wdenk56ed43e2004-02-22 23:46:08 +000036 * 0x80000000 - 0x9FFFFFFF 0x80000000 - 0x9FFFFFFF (Outbound ATU #1)
37 * PCI Mem with prefetch
wdenkbf2f8c92003-05-22 22:52:13 +000038 *
wdenk56ed43e2004-02-22 23:46:08 +000039 * 0xA0000000 - 0xBFFFFFFF 0xA0000000 - 0xBFFFFFFF (Outbound ATU #2)
40 * PCI Mem w/o prefetch
wdenkbf2f8c92003-05-22 22:52:13 +000041 *
wdenk56ed43e2004-02-22 23:46:08 +000042 * 0xF4000000 - 0xF7FFFFFF 0x00000000 - 0x03FFFFFF (Outbound ATU #3)
43 * 32-bit PCI IO
wdenk57b2d802003-06-27 21:31:46 +000044 *
wdenk28536032003-03-25 16:50:56 +000045 * PCI->Local map (from PCI)
wdenk56ed43e2004-02-22 23:46:08 +000046 * MPC826x slave window controlled by
wdenk28536032003-03-25 16:50:56 +000047 *
wdenk56ed43e2004-02-22 23:46:08 +000048 * 0x00000000 - 0x1FFFFFFF 0x00000000 - 0x1FFFFFFF (Inbound ATU #1)
49 * MPC826x local memory
wdenk28536032003-03-25 16:50:56 +000050 */
51
wdenk57b2d802003-06-27 21:31:46 +000052/*
53 * Slave window that allows PCI masters to access MPC826x local memory.
wdenk28536032003-03-25 16:50:56 +000054 * This window is set up using the first set of Inbound ATU registers
55 */
56
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020057#ifndef CONFIG_SYS_PCI_SLV_MEM_LOCAL
58#define PCI_SLV_MEM_LOCAL CONFIG_SYS_SDRAM_BASE /* Local base */
wdenk57b2d802003-06-27 21:31:46 +000059#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020060#define PCI_SLV_MEM_LOCAL CONFIG_SYS_PCI_SLV_MEM_LOCAL
wdenkbf2f8c92003-05-22 22:52:13 +000061#endif
62
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020063#ifndef CONFIG_SYS_PCI_SLV_MEM_BUS
wdenk56ed43e2004-02-22 23:46:08 +000064#define PCI_SLV_MEM_BUS 0x00000000 /* PCI base */
wdenkbf2f8c92003-05-22 22:52:13 +000065#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020066#define PCI_SLV_MEM_BUS CONFIG_SYS_PCI_SLV_MEM_BUS
wdenkbf2f8c92003-05-22 22:52:13 +000067#endif
68
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069#ifndef CONFIG_SYS_PICMR0_MASK_ATTRIB
wdenk28536032003-03-25 16:50:56 +000070#define PICMR0_MASK_ATTRIB (PICMR_MASK_512MB | PICMR_ENABLE | \
wdenk57b2d802003-06-27 21:31:46 +000071 PICMR_PREFETCH_EN)
wdenkbf2f8c92003-05-22 22:52:13 +000072#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020073#define PICMR0_MASK_ATTRIB CONFIG_SYS_PICMR0_MASK_ATTRIB
wdenkbf2f8c92003-05-22 22:52:13 +000074#endif
wdenk28536032003-03-25 16:50:56 +000075
wdenk57b2d802003-06-27 21:31:46 +000076/*
wdenkbf2f8c92003-05-22 22:52:13 +000077 * These are the windows that allow the CPU to access PCI address space.
wdenk57b2d802003-06-27 21:31:46 +000078 * All three PCI master windows, which allow the CPU to access PCI
79 * prefetch, non prefetch, and IO space (see below), must all fit within
wdenkbf2f8c92003-05-22 22:52:13 +000080 * these windows.
wdenk28536032003-03-25 16:50:56 +000081 */
82
wdenkbf2f8c92003-05-22 22:52:13 +000083/* PCIBR0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020084#ifndef CONFIG_SYS_PCI_MSTR0_LOCAL
wdenk56ed43e2004-02-22 23:46:08 +000085#define PCI_MSTR0_LOCAL 0x80000000 /* Local base */
wdenk57b2d802003-06-27 21:31:46 +000086#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020087#define PCI_MSTR0_LOCAL CONFIG_SYS_PCI_MSTR0_LOCAL
wdenkbf2f8c92003-05-22 22:52:13 +000088#endif
89
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020090#ifndef CONFIG_SYS_PCIMSK0_MASK
wdenk56ed43e2004-02-22 23:46:08 +000091#define PCIMSK0_MASK PCIMSK_1GB /* Size of window */
wdenkbf2f8c92003-05-22 22:52:13 +000092#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020093#define PCIMSK0_MASK CONFIG_SYS_PCIMSK0_MASK
wdenkbf2f8c92003-05-22 22:52:13 +000094#endif
95
96/* PCIBR1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020097#ifndef CONFIG_SYS_PCI_MSTR1_LOCAL
wdenk56ed43e2004-02-22 23:46:08 +000098#define PCI_MSTR1_LOCAL 0xF4000000 /* Local base */
wdenk57b2d802003-06-27 21:31:46 +000099#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200100#define PCI_MSTR1_LOCAL CONFIG_SYS_PCI_MSTR1_LOCAL
wdenkbf2f8c92003-05-22 22:52:13 +0000101#endif
102
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103#ifndef CONFIG_SYS_PCIMSK1_MASK
wdenk56ed43e2004-02-22 23:46:08 +0000104#define PCIMSK1_MASK PCIMSK_64MB /* Size of window */
wdenkbf2f8c92003-05-22 22:52:13 +0000105#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200106#define PCIMSK1_MASK CONFIG_SYS_PCIMSK1_MASK
wdenkbf2f8c92003-05-22 22:52:13 +0000107#endif
wdenk28536032003-03-25 16:50:56 +0000108
wdenk57b2d802003-06-27 21:31:46 +0000109/*
wdenk28536032003-03-25 16:50:56 +0000110 * Master window that allows the CPU to access PCI Memory (prefetch).
111 * This window will be setup with the first set of Outbound ATU registers
112 * in the bridge.
113 */
114
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200115#ifndef CONFIG_SYS_PCI_MSTR_MEM_LOCAL
wdenk56ed43e2004-02-22 23:46:08 +0000116#define PCI_MSTR_MEM_LOCAL 0x80000000 /* Local base */
wdenkbf2f8c92003-05-22 22:52:13 +0000117#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200118#define PCI_MSTR_MEM_LOCAL CONFIG_SYS_PCI_MSTR_MEM_LOCAL
wdenkbf2f8c92003-05-22 22:52:13 +0000119#endif
120
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200121#ifndef CONFIG_SYS_PCI_MSTR_MEM_BUS
wdenk56ed43e2004-02-22 23:46:08 +0000122#define PCI_MSTR_MEM_BUS 0x80000000 /* PCI base */
wdenkbf2f8c92003-05-22 22:52:13 +0000123#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200124#define PCI_MSTR_MEM_BUS CONFIG_SYS_PCI_MSTR_MEM_BUS
wdenkbf2f8c92003-05-22 22:52:13 +0000125#endif
126
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200127#ifndef CONFIG_SYS_CPU_PCI_MEM_START
wdenkbf2f8c92003-05-22 22:52:13 +0000128#define CPU_PCI_MEM_START PCI_MSTR_MEM_LOCAL
129#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200130#define CPU_PCI_MEM_START CONFIG_SYS_CPU_PCI_MEM_START
wdenkbf2f8c92003-05-22 22:52:13 +0000131#endif
132
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200133#ifndef CONFIG_SYS_PCI_MSTR_MEM_SIZE
wdenk56ed43e2004-02-22 23:46:08 +0000134#define PCI_MSTR_MEM_SIZE 0x10000000 /* 256MB */
wdenkbf2f8c92003-05-22 22:52:13 +0000135#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136#define PCI_MSTR_MEM_SIZE CONFIG_SYS_PCI_MSTR_MEM_SIZE
wdenkbf2f8c92003-05-22 22:52:13 +0000137#endif
138
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200139#ifndef CONFIG_SYS_POCMR0_MASK_ATTRIB
wdenk28536032003-03-25 16:50:56 +0000140#define POCMR0_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PREFETCH_EN)
wdenkbf2f8c92003-05-22 22:52:13 +0000141#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200142#define POCMR0_MASK_ATTRIB CONFIG_SYS_POCMR0_MASK_ATTRIB
wdenkbf2f8c92003-05-22 22:52:13 +0000143#endif
wdenk28536032003-03-25 16:50:56 +0000144
wdenk57b2d802003-06-27 21:31:46 +0000145/*
wdenk28536032003-03-25 16:50:56 +0000146 * Master window that allows the CPU to access PCI Memory (non-prefetch).
147 * This window will be setup with the second set of Outbound ATU registers
148 * in the bridge.
149 */
150
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200151#ifndef CONFIG_SYS_PCI_MSTR_MEMIO_LOCAL
wdenk56ed43e2004-02-22 23:46:08 +0000152#define PCI_MSTR_MEMIO_LOCAL 0x90000000 /* Local base */
wdenk57b2d802003-06-27 21:31:46 +0000153#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200154#define PCI_MSTR_MEMIO_LOCAL CONFIG_SYS_PCI_MSTR_MEMIO_LOCAL
wdenkbf2f8c92003-05-22 22:52:13 +0000155#endif
156
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200157#ifndef CONFIG_SYS_PCI_MSTR_MEMIO_BUS
wdenk56ed43e2004-02-22 23:46:08 +0000158#define PCI_MSTR_MEMIO_BUS 0x90000000 /* PCI base */
wdenk57b2d802003-06-27 21:31:46 +0000159#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200160#define PCI_MSTR_MEMIO_BUS CONFIG_SYS_PCI_MSTR_MEMIO_BUS
wdenkbf2f8c92003-05-22 22:52:13 +0000161#endif
162
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200163#ifndef CONFIG_SYS_CPU_PCI_MEMIO_START
wdenk57b2d802003-06-27 21:31:46 +0000164#define CPU_PCI_MEMIO_START PCI_MSTR_MEMIO_LOCAL
165#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200166#define CPU_PCI_MEMIO_START CONFIG_SYS_CPU_PCI_MEMIO_START
wdenkbf2f8c92003-05-22 22:52:13 +0000167#endif
168
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200169#ifndef CONFIG_SYS_PCI_MSTR_MEMIO_SIZE
wdenk56ed43e2004-02-22 23:46:08 +0000170#define PCI_MSTR_MEMIO_SIZE 0x10000000 /* 256 MB */
wdenk57b2d802003-06-27 21:31:46 +0000171#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200172#define PCI_MSTR_MEMIO_SIZE CONFIG_SYS_PCI_MSTR_MEMIO_SIZE
wdenkbf2f8c92003-05-22 22:52:13 +0000173#endif
174
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200175#ifndef CONFIG_SYS_POCMR1_MASK_ATTRIB
wdenk56ed43e2004-02-22 23:46:08 +0000176#define POCMR1_MASK_ATTRIB (POCMR_MASK_512MB | POCMR_ENABLE)
wdenkbf2f8c92003-05-22 22:52:13 +0000177#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200178#define POCMR1_MASK_ATTRIB CONFIG_SYS_POCMR1_MASK_ATTRIB
wdenkbf2f8c92003-05-22 22:52:13 +0000179#endif
wdenk28536032003-03-25 16:50:56 +0000180
wdenk57b2d802003-06-27 21:31:46 +0000181/*
wdenk28536032003-03-25 16:50:56 +0000182 * Master window that allows the CPU to access PCI IO space.
183 * This window will be setup with the third set of Outbound ATU registers
184 * in the bridge.
185 */
186
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200187#ifndef CONFIG_SYS_PCI_MSTR_IO_LOCAL
wdenk56ed43e2004-02-22 23:46:08 +0000188#define PCI_MSTR_IO_LOCAL 0xA0000000 /* Local base */
wdenk57b2d802003-06-27 21:31:46 +0000189#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200190#define PCI_MSTR_IO_LOCAL CONFIG_SYS_PCI_MSTR_IO_LOCAL
wdenkbf2f8c92003-05-22 22:52:13 +0000191#endif
192
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200193#ifndef CONFIG_SYS_PCI_MSTR_IO_BUS
wdenk56ed43e2004-02-22 23:46:08 +0000194#define PCI_MSTR_IO_BUS 0xA0000000 /* PCI base */
wdenk57b2d802003-06-27 21:31:46 +0000195#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200196#define PCI_MSTR_IO_BUS CONFIG_SYS_PCI_MSTR_IO_BUS
wdenkbf2f8c92003-05-22 22:52:13 +0000197#endif
198
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200199#ifndef CONFIG_SYS_CPU_PCI_IO_START
wdenk57b2d802003-06-27 21:31:46 +0000200#define CPU_PCI_IO_START PCI_MSTR_IO_LOCAL
201#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200202#define CPU_PCI_IO_START CONFIG_SYS_CPU_PCI_IO_START
wdenkbf2f8c92003-05-22 22:52:13 +0000203#endif
204
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200205#ifndef CONFIG_SYS_PCI_MSTR_IO_SIZE
wdenk56ed43e2004-02-22 23:46:08 +0000206#define PCI_MSTR_IO_SIZE 0x10000000 /* 256MB */
wdenk57b2d802003-06-27 21:31:46 +0000207#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200208#define PCI_MSTR_IO_SIZE CONFIG_SYS_PCI_MSTR_IO_SIZE
wdenke5d61c72003-05-18 11:30:09 +0000209#endif
wdenkbf2f8c92003-05-22 22:52:13 +0000210
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200211#ifndef CONFIG_SYS_POCMR2_MASK_ATTRIB
wdenk56ed43e2004-02-22 23:46:08 +0000212#define POCMR2_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PCI_IO)
wdenkbf2f8c92003-05-22 22:52:13 +0000213#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200214#define POCMR2_MASK_ATTRIB CONFIG_SYS_POCMR2_MASK_ATTRIB
wdenkbf2f8c92003-05-22 22:52:13 +0000215#endif
wdenk28536032003-03-25 16:50:56 +0000216
217/* PCI bus configuration registers.
218 */
219
220#define PCI_CLASS_BRIDGE_CTLR 0x06
221
222
wdenk56ed43e2004-02-22 23:46:08 +0000223static inline void pci_outl (u32 addr, u32 data)
wdenk28536032003-03-25 16:50:56 +0000224{
wdenk56ed43e2004-02-22 23:46:08 +0000225 *(volatile u32 *) addr = cpu_to_le32 (data);
wdenk28536032003-03-25 16:50:56 +0000226}
227
wdenk56ed43e2004-02-22 23:46:08 +0000228void pci_mpc8250_init (struct pci_controller *hose)
wdenk28536032003-03-25 16:50:56 +0000229{
wdenk56ed43e2004-02-22 23:46:08 +0000230 u16 tempShort;
231
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200232 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk56ed43e2004-02-22 23:46:08 +0000233 pci_dev_t host_devno = PCI_BDF (0, 0, 0);
wdenk28536032003-03-25 16:50:56 +0000234
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200235 pci_setup_indirect (hose, CONFIG_SYS_IMMR + PCI_CFG_ADDR_REG,
236 CONFIG_SYS_IMMR + PCI_CFG_DATA_REG);
wdenk28536032003-03-25 16:50:56 +0000237
wdenk56ed43e2004-02-22 23:46:08 +0000238 /*
239 * Setting required to enable local bus for PCI (SIUMCR [LBPC]).
240 */
wdenkbf2f8c92003-05-22 22:52:13 +0000241#ifdef CONFIG_MPC8266ADS
wdenk56ed43e2004-02-22 23:46:08 +0000242 immap->im_siu_conf.sc_siumcr =
243 (immap->im_siu_conf.sc_siumcr & ~SIUMCR_LBPC11)
244 | SIUMCR_LBPC01;
Wolfgang Denk8cc89d92005-09-25 16:27:55 +0200245#elif defined CONFIG_MPC8272
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200246 immap->im_siu_conf.sc_siumcr = (immap->im_siu_conf.sc_siumcr &
247 ~SIUMCR_BBD &
248 ~SIUMCR_ESE &
249 ~SIUMCR_PBSE &
250 ~SIUMCR_CDIS &
251 ~SIUMCR_DPPC11 &
252 ~SIUMCR_L2CPC11 &
253 ~SIUMCR_LBPC11 &
254 ~SIUMCR_APPC11 &
255 ~SIUMCR_CS10PC11 &
256 ~SIUMCR_BCTLC11 &
257 ~SIUMCR_MMR11)
258 | SIUMCR_DPPC11
259 | SIUMCR_L2CPC01
260 | SIUMCR_LBPC00
261 | SIUMCR_APPC10
262 | SIUMCR_CS10PC00
263 | SIUMCR_BCTLC00
264 | SIUMCR_MMR11;
Heiko Schocher3ec43662006-12-21 17:17:02 +0100265#elif defined(CONFIG_TQM8272)
Heiko Schocher609ed902007-03-21 08:45:17 +0100266/* nothing to do for this Board here */
wdenkbf2f8c92003-05-22 22:52:13 +0000267#else
wdenk56ed43e2004-02-22 23:46:08 +0000268 /*
269 * Setting required to enable IRQ1-IRQ7 (SIUMCR [DPPC]),
270 * and local bus for PCI (SIUMCR [LBPC]).
271 */
272 immap->im_siu_conf.sc_siumcr = (immap->im_siu_conf.sc_siumcr &
273 ~SIUMCR_LBPC11 &
wdenk57b2d802003-06-27 21:31:46 +0000274 ~SIUMCR_CS10PC11 &
wdenk56ed43e2004-02-22 23:46:08 +0000275 ~SIUMCR_LBPC11) |
276 SIUMCR_LBPC01 |
277 SIUMCR_CS10PC01 |
278 SIUMCR_APPC10;
wdenkbf2f8c92003-05-22 22:52:13 +0000279#endif
wdenk28536032003-03-25 16:50:56 +0000280
wdenk56ed43e2004-02-22 23:46:08 +0000281 /* Make PCI lowest priority */
282 /* Each 4 bits is a device bus request and the MS 4bits
283 is highest priority */
284 /* Bus 4bit value
285 --- ----------
286 CPM high 0b0000
287 CPM middle 0b0001
288 CPM low 0b0010
289 PCI reguest 0b0011
290 Reserved 0b0100
291 Reserved 0b0101
292 Internal Core 0b0110
293 External Master 1 0b0111
294 External Master 2 0b1000
295 External Master 3 0b1001
296 The rest are reserved */
297 immap->im_siu_conf.sc_ppc_alrh = 0x61207893;
wdenk28536032003-03-25 16:50:56 +0000298
wdenk56ed43e2004-02-22 23:46:08 +0000299 /* Park bus on core while modifying PCI Bus accesses */
300 immap->im_siu_conf.sc_ppc_acr = 0x6;
wdenk28536032003-03-25 16:50:56 +0000301
wdenk56ed43e2004-02-22 23:46:08 +0000302 /*
303 * Set up master windows that allow the CPU to access PCI space. These
304 * windows are set up using the two SIU PCIBR registers.
305 */
306 immap->im_memctl.memc_pcimsk0 = PCIMSK0_MASK;
307 immap->im_memctl.memc_pcibr0 = PCI_MSTR0_LOCAL | PCIBR_ENABLE;
wdenkbf2f8c92003-05-22 22:52:13 +0000308
Wolfgang Denk8cc89d92005-09-25 16:27:55 +0200309#if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
wdenk792c44a2004-04-18 21:17:30 +0000310 immap->im_memctl.memc_pcimsk1 = PCIMSK1_MASK;
311 immap->im_memctl.memc_pcibr1 = PCI_MSTR1_LOCAL | PCIBR_ENABLE;
wdenk57b2d802003-06-27 21:31:46 +0000312#endif
wdenk28536032003-03-25 16:50:56 +0000313
wdenk56ed43e2004-02-22 23:46:08 +0000314 /* Release PCI RST (by default the PCI RST signal is held low) */
315 immap->im_pci.pci_gcr = cpu_to_le32 (PCIGCR_PCI_BUS_EN);
wdenk28536032003-03-25 16:50:56 +0000316
wdenk56ed43e2004-02-22 23:46:08 +0000317 /* give it some time */
318 {
Wolfgang Denk8cc89d92005-09-25 16:27:55 +0200319#if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
wdenk57b2d802003-06-27 21:31:46 +0000320 /* Give the PCI cards more time to initialize before query
wdenk56ed43e2004-02-22 23:46:08 +0000321 This might be good for other boards also
322 */
323 int i;
324
325 for (i = 0; i < 1000; ++i)
wdenkbf2f8c92003-05-22 22:52:13 +0000326#endif
wdenk56ed43e2004-02-22 23:46:08 +0000327 udelay (1000);
328 }
wdenk28536032003-03-25 16:50:56 +0000329
wdenk56ed43e2004-02-22 23:46:08 +0000330 /*
331 * Set up master window that allows the CPU to access PCI Memory (prefetch)
332 * space. This window is set up using the first set of Outbound ATU registers.
333 */
334 immap->im_pci.pci_potar0 = cpu_to_le32 (PCI_MSTR_MEM_BUS >> 12); /* PCI base */
335 immap->im_pci.pci_pobar0 = cpu_to_le32 (PCI_MSTR_MEM_LOCAL >> 12); /* Local base */
336 immap->im_pci.pci_pocmr0 = cpu_to_le32 (POCMR0_MASK_ATTRIB); /* Size & attribute */
wdenk28536032003-03-25 16:50:56 +0000337
wdenk56ed43e2004-02-22 23:46:08 +0000338 /*
339 * Set up master window that allows the CPU to access PCI Memory (non-prefetch)
340 * space. This window is set up using the second set of Outbound ATU registers.
341 */
342 immap->im_pci.pci_potar1 = cpu_to_le32 (PCI_MSTR_MEMIO_BUS >> 12); /* PCI base */
343 immap->im_pci.pci_pobar1 = cpu_to_le32 (PCI_MSTR_MEMIO_LOCAL >> 12); /* Local base */
344 immap->im_pci.pci_pocmr1 = cpu_to_le32 (POCMR1_MASK_ATTRIB); /* Size & attribute */
wdenk57b2d802003-06-27 21:31:46 +0000345
wdenk56ed43e2004-02-22 23:46:08 +0000346 /*
347 * Set up master window that allows the CPU to access PCI IO space. This window
348 * is set up using the third set of Outbound ATU registers.
349 */
350 immap->im_pci.pci_potar2 = cpu_to_le32 (PCI_MSTR_IO_BUS >> 12); /* PCI base */
351 immap->im_pci.pci_pobar2 = cpu_to_le32 (PCI_MSTR_IO_LOCAL >> 12); /* Local base */
352 immap->im_pci.pci_pocmr2 = cpu_to_le32 (POCMR2_MASK_ATTRIB); /* Size & attribute */
wdenk28536032003-03-25 16:50:56 +0000353
wdenk56ed43e2004-02-22 23:46:08 +0000354 /*
355 * Set up slave window that allows PCI masters to access MPC826x local memory.
356 * This window is set up using the first set of Inbound ATU registers
357 */
358 immap->im_pci.pci_pitar0 = cpu_to_le32 (PCI_SLV_MEM_LOCAL >> 12); /* PCI base */
359 immap->im_pci.pci_pibar0 = cpu_to_le32 (PCI_SLV_MEM_BUS >> 12); /* Local base */
360 immap->im_pci.pci_picmr0 = cpu_to_le32 (PICMR0_MASK_ATTRIB); /* Size & attribute */
wdenk28536032003-03-25 16:50:56 +0000361
wdenk56ed43e2004-02-22 23:46:08 +0000362 /* See above for description - puts PCI request as highest priority */
Wolfgang Denk8cc89d92005-09-25 16:27:55 +0200363#ifdef CONFIG_MPC8272
364 immap->im_siu_conf.sc_ppc_alrh = 0x01236745;
365#else
wdenk56ed43e2004-02-22 23:46:08 +0000366 immap->im_siu_conf.sc_ppc_alrh = 0x03124567;
Wolfgang Denk8cc89d92005-09-25 16:27:55 +0200367#endif
wdenk28536032003-03-25 16:50:56 +0000368
wdenk56ed43e2004-02-22 23:46:08 +0000369 /* Park the bus on the PCI */
370 immap->im_siu_conf.sc_ppc_acr = PPC_ACR_BUS_PARK_PCI;
wdenk28536032003-03-25 16:50:56 +0000371
wdenk56ed43e2004-02-22 23:46:08 +0000372 /* Host mode - specify the bridge as a host-PCI bridge */
wdenk28536032003-03-25 16:50:56 +0000373
wdenk56ed43e2004-02-22 23:46:08 +0000374 pci_hose_write_config_byte (hose, host_devno, PCI_CLASS_CODE,
375 PCI_CLASS_BRIDGE_CTLR);
wdenk28536032003-03-25 16:50:56 +0000376
wdenk56ed43e2004-02-22 23:46:08 +0000377 /* Enable the host bridge to be a master on the PCI bus, and to act as a PCI memory target */
378 pci_hose_read_config_word (hose, host_devno, PCI_COMMAND, &tempShort);
379 pci_hose_write_config_word (hose, host_devno, PCI_COMMAND,
380 tempShort | PCI_COMMAND_MASTER |
381 PCI_COMMAND_MEMORY);
wdenk28536032003-03-25 16:50:56 +0000382
wdenkabda5ca2003-05-31 18:35:21 +0000383 /* do some bridge init, should be done on all 8260 based bridges */
wdenk56ed43e2004-02-22 23:46:08 +0000384 pci_hose_write_config_byte (hose, host_devno, PCI_CACHE_LINE_SIZE,
385 0x08);
386 pci_hose_write_config_byte (hose, host_devno, PCI_LATENCY_TIMER,
387 0xF8);
wdenkabda5ca2003-05-31 18:35:21 +0000388
wdenk56ed43e2004-02-22 23:46:08 +0000389 hose->first_busno = 0;
390 hose->last_busno = 0xff;
wdenk28536032003-03-25 16:50:56 +0000391
wdenk56ed43e2004-02-22 23:46:08 +0000392 /* System memory space */
Wolfgang Denke5357d02006-05-30 23:32:44 +0200393#if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272 || defined CONFIG_PM826
wdenk56ed43e2004-02-22 23:46:08 +0000394 pci_set_region (hose->regions + 0,
395 PCI_SLV_MEM_BUS,
396 PCI_SLV_MEM_LOCAL,
Kumar Galaefa1f1d2009-02-06 09:49:31 -0600397 gd->ram_size, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
wdenkbf2f8c92003-05-22 22:52:13 +0000398#else
wdenk56ed43e2004-02-22 23:46:08 +0000399 pci_set_region (hose->regions + 0,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200400 CONFIG_SYS_SDRAM_BASE,
401 CONFIG_SYS_SDRAM_BASE,
Kumar Galaefa1f1d2009-02-06 09:49:31 -0600402 0x4000000, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
wdenkbf2f8c92003-05-22 22:52:13 +0000403#endif
wdenk28536032003-03-25 16:50:56 +0000404
wdenk56ed43e2004-02-22 23:46:08 +0000405 /* PCI memory space */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200406#if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
wdenk56ed43e2004-02-22 23:46:08 +0000407 pci_set_region (hose->regions + 1,
408 PCI_MSTR_MEMIO_BUS,
409 PCI_MSTR_MEMIO_LOCAL,
410 PCI_MSTR_MEMIO_SIZE, PCI_REGION_MEM);
wdenkbf2f8c92003-05-22 22:52:13 +0000411#else
wdenk56ed43e2004-02-22 23:46:08 +0000412 pci_set_region (hose->regions + 1,
413 PCI_MSTR_MEM_BUS,
414 PCI_MSTR_MEM_LOCAL,
415 PCI_MSTR_MEM_SIZE, PCI_REGION_MEM);
wdenkbf2f8c92003-05-22 22:52:13 +0000416#endif
wdenk28536032003-03-25 16:50:56 +0000417
wdenk56ed43e2004-02-22 23:46:08 +0000418 /* PCI I/O space */
419 pci_set_region (hose->regions + 2,
420 PCI_MSTR_IO_BUS,
421 PCI_MSTR_IO_LOCAL, PCI_MSTR_IO_SIZE, PCI_REGION_IO);
422
423 hose->region_count = 3;
wdenk28536032003-03-25 16:50:56 +0000424
wdenk56ed43e2004-02-22 23:46:08 +0000425 pci_register_hose (hose);
426 /* Mask off master abort machine checks */
427 immap->im_pci.pci_emr &= cpu_to_le32 (~PCI_ERROR_PCI_NO_RSP);
428 eieio ();
wdenk28536032003-03-25 16:50:56 +0000429
wdenk56ed43e2004-02-22 23:46:08 +0000430 hose->last_busno = pci_hose_scan (hose);
wdenk28536032003-03-25 16:50:56 +0000431
wdenk56ed43e2004-02-22 23:46:08 +0000432
433 /* clear the error in the error status register */
434 immap->im_pci.pci_esr = cpu_to_le32 (PCI_ERROR_PCI_NO_RSP);
435
436 /* unmask master abort machine checks */
437 immap->im_pci.pci_emr |= cpu_to_le32 (PCI_ERROR_PCI_NO_RSP);
wdenk28536032003-03-25 16:50:56 +0000438}
439
Matvejchikov Ilya8743c792008-07-06 13:57:00 +0400440#if defined(CONFIG_OF_LIBFDT)
441void ft_pci_setup(void *blob, bd_t *bd)
442{
443 do_fixup_by_prop_u32(blob, "device_type", "pci", 4,
Wolfgang Denk20de6ac2008-08-12 12:10:11 +0200444 "clock-frequency", gd->pci_clk, 1);
Matvejchikov Ilya8743c792008-07-06 13:57:00 +0400445}
446#endif
447
wdenk56ed43e2004-02-22 23:46:08 +0000448#endif /* CONFIG_PCI */