blob: 8cab771a0ed0ed5bafbe98ef4d196183ede8b444 [file] [log] [blame]
Dave Liue740c462006-12-07 21:13:15 +08001/*
Kim Phillips57a2af32009-07-18 18:42:13 -05002 * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
Dave Liue740c462006-12-07 21:13:15 +08003 *
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
13/*
14 * PCI Configuration space access support for MPC83xx PCI Bridge
15 */
16#include <asm/mmu.h>
17#include <asm/io.h>
18#include <common.h>
Kim Phillips57a2af32009-07-18 18:42:13 -050019#include <mpc83xx.h>
Dave Liue740c462006-12-07 21:13:15 +080020#include <pci.h>
21#include <i2c.h>
Dave Liue740c462006-12-07 21:13:15 +080022#include <asm/fsl_i2c.h>
Kim Phillips57a2af32009-07-18 18:42:13 -050023#include "../common/pq-mds-pib.h"
Dave Liue740c462006-12-07 21:13:15 +080024
25DECLARE_GLOBAL_DATA_PTR;
26
Kim Phillips57a2af32009-07-18 18:42:13 -050027static struct pci_region pci1_regions[] = {
28 {
29 bus_start: CONFIG_SYS_PCI1_MEM_BASE,
30 phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
31 size: CONFIG_SYS_PCI1_MEM_SIZE,
32 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
33 },
34 {
35 bus_start: CONFIG_SYS_PCI1_IO_BASE,
36 phys_start: CONFIG_SYS_PCI1_IO_PHYS,
37 size: CONFIG_SYS_PCI1_IO_SIZE,
38 flags: PCI_REGION_IO
39 },
40 {
41 bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
42 phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
43 size: CONFIG_SYS_PCI1_MMIO_SIZE,
44 flags: PCI_REGION_MEM
45 },
46};
Dave Liue740c462006-12-07 21:13:15 +080047
Kim Phillips57a2af32009-07-18 18:42:13 -050048#ifdef CONFIG_MPC83XX_PCI2
49static struct pci_region pci2_regions[] = {
Dave Liue740c462006-12-07 21:13:15 +080050 {
Kim Phillips57a2af32009-07-18 18:42:13 -050051 bus_start: CONFIG_SYS_PCI2_MEM_BASE,
52 phys_start: CONFIG_SYS_PCI2_MEM_PHYS,
53 size: CONFIG_SYS_PCI2_MEM_SIZE,
54 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
Dave Liue740c462006-12-07 21:13:15 +080055 },
Dave Liue740c462006-12-07 21:13:15 +080056 {
Kim Phillips57a2af32009-07-18 18:42:13 -050057 bus_start: CONFIG_SYS_PCI2_IO_BASE,
58 phys_start: CONFIG_SYS_PCI2_IO_PHYS,
59 size: CONFIG_SYS_PCI2_IO_SIZE,
60 flags: PCI_REGION_IO
61 },
62 {
63 bus_start: CONFIG_SYS_PCI2_MMIO_BASE,
64 phys_start: CONFIG_SYS_PCI2_MMIO_PHYS,
65 size: CONFIG_SYS_PCI2_MMIO_SIZE,
66 flags: PCI_REGION_MEM
Dave Liue740c462006-12-07 21:13:15 +080067 },
68};
Kim Phillips57a2af32009-07-18 18:42:13 -050069#endif
70
Dave Liue740c462006-12-07 21:13:15 +080071void pci_init_board(void)
72#ifdef CONFIG_PCISLAVE
73{
Kim Phillips57a2af32009-07-18 18:42:13 -050074 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
75 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
76 volatile pcictrl83xx_t *pci_ctrl = &immr->pci_ctrl[0];
77 struct pci_region *reg[] = { pci1_regions };
78
79 /* Configure PCI Local Access Windows */
80 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
81 pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
Dave Liue740c462006-12-07 21:13:15 +080082
Kim Phillips57a2af32009-07-18 18:42:13 -050083 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
84 pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
85
Peter Tysere2283322010-09-14 19:13:50 -050086 mpc83xx_pci_init(1, reg);
Kim Phillips57a2af32009-07-18 18:42:13 -050087
Dave Liue740c462006-12-07 21:13:15 +080088 /*
89 * Configure PCI Inbound Translation Windows
90 */
91 pci_ctrl[0].pitar0 = 0x0;
92 pci_ctrl[0].pibar0 = 0x0;
93 pci_ctrl[0].piwar0 = PIWAR_EN | PIWAR_RTT_SNOOP |
94 PIWAR_WTT_SNOOP | PIWAR_IWS_4K;
95
96 pci_ctrl[0].pitar1 = 0x0;
97 pci_ctrl[0].pibar1 = 0x0;
98 pci_ctrl[0].piebar1 = 0x0;
99 pci_ctrl[0].piwar1 &= ~PIWAR_EN;
100
101 pci_ctrl[0].pitar2 = 0x0;
102 pci_ctrl[0].pibar2 = 0x0;
103 pci_ctrl[0].piebar2 = 0x0;
104 pci_ctrl[0].piwar2 &= ~PIWAR_EN;
105
Kim Phillips57a2af32009-07-18 18:42:13 -0500106 /* Unlock the configuration bit */
107 mpc83xx_pcislave_unlock(0);
108 printf("PCI: Agent mode enabled\n");
Dave Liue740c462006-12-07 21:13:15 +0800109}
110#else
111{
Kim Phillips57a2af32009-07-18 18:42:13 -0500112 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
113 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
114 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
115#ifndef CONFIG_MPC83XX_PCI2
116 struct pci_region *reg[] = { pci1_regions };
117#else
118 struct pci_region *reg[] = { pci1_regions, pci2_regions };
119#endif
Dave Liue740c462006-12-07 21:13:15 +0800120
Kim Phillips57a2af32009-07-18 18:42:13 -0500121 /* initialize the PCA9555PW IO expander on the PIB board */
122 pib_init();
Dave Liue740c462006-12-07 21:13:15 +0800123
Wolfgang Denk291ba1b2010-10-06 09:05:45 +0200124#if defined(CONFIG_PCI_66M)
Dave Liue740c462006-12-07 21:13:15 +0800125 clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
126 printf("PCI clock is 66MHz\n");
Wolfgang Denk291ba1b2010-10-06 09:05:45 +0200127#elif defined(CONFIG_PCI_33M)
Dave Liue740c462006-12-07 21:13:15 +0800128 clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2 |
129 OCCR_PCICD0 | OCCR_PCICD1 | OCCR_PCICD2 | OCCR_PCICR;
130 printf("PCI clock is 33MHz\n");
131#else
132 clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
133 printf("PCI clock is 66MHz\n");
134#endif
135 udelay(2000);
136
Kim Phillips57a2af32009-07-18 18:42:13 -0500137 /* Configure PCI Local Access Windows */
138 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
Dave Liue740c462006-12-07 21:13:15 +0800139 pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M;
140
Kim Phillips57a2af32009-07-18 18:42:13 -0500141 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
Dave Liue740c462006-12-07 21:13:15 +0800142 pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_1M;
143
Dave Liue740c462006-12-07 21:13:15 +0800144 udelay(2000);
Dave Liue740c462006-12-07 21:13:15 +0800145
Kim Phillips57a2af32009-07-18 18:42:13 -0500146#ifndef CONFIG_MPC83XX_PCI2
Peter Tysere2283322010-09-14 19:13:50 -0500147 mpc83xx_pci_init(1, reg);
Kim Phillips57a2af32009-07-18 18:42:13 -0500148#else
Peter Tysere2283322010-09-14 19:13:50 -0500149 mpc83xx_pci_init(2, reg);
Kim Phillips57a2af32009-07-18 18:42:13 -0500150#endif
Dave Liue740c462006-12-07 21:13:15 +0800151}
152#endif /* CONFIG_PCISLAVE */