Added PCI support for MPC8349ADS board
[platform/kernel/u-boot.git] / board / mpc8349ads / pci.c
1 /*
2  * See file CREDITS for list of people who contributed to this
3  * project.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA
19  *
20  */
21
22 #include <asm/mmu.h>
23 #include <common.h>
24 #include <asm/global_data.h>
25 #include <pci.h>
26 #include <i2c.h>
27
28 #ifdef CONFIG_PCI
29
30 /* System RAM mapped to PCI space */
31 #define CONFIG_PCI_SYS_MEM_BUS  CFG_SDRAM_BASE
32 #define CONFIG_PCI_SYS_MEM_PHYS CFG_SDRAM_BASE
33
34 #ifndef CONFIG_PCI_PNP
35 static struct pci_config_table pci_mpc83xxads_config_table[] = {
36         {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
37          PCI_IDSEL_NUMBER, PCI_ANY_ID,
38          pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
39                                      PCI_ENET0_MEMADDR,
40                                      PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
41                 }
42         },
43         {}
44 };
45 #endif
46
47 static struct pci_controller pci_hose[] = {
48        {
49 #ifndef CONFIG_PCI_PNP
50        config_table:pci_mpc83xxads_config_table,
51 #endif
52        },
53        {
54 #ifndef CONFIG_PCI_PNP
55        config_table:pci_mpc83xxads_config_table,
56 #endif
57        }
58 };
59
60 /**************************************************************************
61  *
62  * pib_init() -- initialize the PCA9555PW IO expander on the PIB board
63  *
64  */
65 void
66 pib_init(void)
67 {
68         u8 val8;
69         /*
70          * Assign PIB PMC slot to desired PCI bus
71          */
72         mpc8349_i2c = (i2c_t*)(CFG_IMMRBAR + CFG_I2C2_OFFSET);
73         i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE);
74
75         val8 = 0;
76         i2c_write(0x23, 0x6, 1, &val8, 1);
77         i2c_write(0x23, 0x7, 1, &val8, 1);
78         val8 = 0xff;
79         i2c_write(0x23, 0x2, 1, &val8, 1);
80         i2c_write(0x23, 0x3, 1, &val8, 1);
81
82         val8 = 0;
83         i2c_write(0x26, 0x6, 1, &val8, 1);
84         val8 = 0x34;
85         i2c_write(0x26, 0x7, 1, &val8, 1);
86 #if defined(PCI_64BIT)
87         val8 = 0xf4;    /* PMC2:PCI1/64-bit */
88 #elif defined(PCI_ALL_PCI1)
89         val8 = 0xf3;    /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI1 */
90 #elif defined(PCI_ONE_PCI1)
91         val8 = 0xf9;    /* PMC1:PCI1 PMC2:PCI2 PMC3:PCI2 */
92 #else
93         val8 = 0xf5;    /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI2 */
94 #endif
95         i2c_write(0x26, 0x2, 1, &val8, 1);
96         val8 = 0xff;
97         i2c_write(0x26, 0x3, 1, &val8, 1);
98         val8 = 0;
99         i2c_write(0x27, 0x6, 1, &val8, 1);
100         i2c_write(0x27, 0x7, 1, &val8, 1);
101         val8 = 0xff;
102         i2c_write(0x27, 0x2, 1, &val8, 1);
103         val8 = 0xef;
104         i2c_write(0x27, 0x3, 1, &val8, 1);
105         asm("eieio");
106
107 #if defined(PCI_64BIT)
108         printf("PCI1: 64-bit on PMC2\n");
109 #elif defined(PCI_ALL_PCI1)
110         printf("PCI1: 32-bit on PMC1, PMC2, PMC3\n");
111 #elif defined(PCI_ONE_PCI1)
112         printf("PCI1: 32-bit on PMC1\n");
113         printf("PCI2: 32-bit on PMC2, PMC3\n");
114 #else
115         printf("PCI1: 32-bit on PMC1, PMC2\n");
116         printf("PCI2: 32-bit on PMC3\n");
117 #endif
118 }
119
120 /**************************************************************************
121  * pci_init_board()
122  *
123  * NOTICE: PCI2 is not currently supported
124  *
125  */
126 void
127 pci_init_board(void)
128 {
129         DECLARE_GLOBAL_DATA_PTR;
130         volatile immap_t *      immr;
131         volatile clk8349_t *    clk;
132         volatile law8349_t *    pci_law;
133         volatile pot8349_t *    pci_pot;
134         volatile pcictrl8349_t *        pci_ctrl;
135         volatile pciconf8349_t *        pci_conf;
136         u16 reg16;
137         u32 reg32;
138         struct  pci_controller * hose;
139
140         immr = (immap_t *)CFG_IMMRBAR;
141         clk = (clk8349_t *)&immr->clk;
142         pci_law = immr->sysconf.pcilaw;
143         pci_pot = immr->ios.pot;
144         pci_ctrl = immr->pci_ctrl;
145         pci_conf = immr->pci_conf;
146
147         hose = &pci_hose[0];
148
149         pib_init();
150
151         /*
152          * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
153          */
154
155         reg32 = clk->occr;
156         udelay(2000);
157         clk->occr = 0xff000000;
158         udelay(2000);
159
160         /*
161          * Release PCI RST Output signal
162          */
163         pci_ctrl[0].gcr = 0;
164         udelay(2000);
165         pci_ctrl[0].gcr = 1;
166         udelay(2000);
167
168         /*
169          * Configure PCI Local Access Windows
170          */
171         pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR;
172         pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
173
174         pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR;
175         pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_32M;
176
177         /*
178          * Configure PCI Outbound Translation Windows
179          */
180
181         /* PCI1 mem space */
182         pci_pot[0].potar = (CFG_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
183         pci_pot[0].pobar = (CFG_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
184         pci_pot[0].pocmr = POCMR_EN | (POCMR_CM_512M & POCMR_CM_MASK);
185
186         /* PCI1 IO space */
187         pci_pot[1].potar = (CFG_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
188         pci_pot[1].pobar = (CFG_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
189         pci_pot[1].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_16M & POCMR_CM_MASK);
190
191         /*
192          * Configure PCI Inbound Translation Windows
193          */
194
195         /* we need RAM mapped to PCI space for the devices to
196          * access main memory */
197         pci_ctrl[0].pitar1 = 0x0;
198         pci_ctrl[0].pibar1 = 0x0;
199         pci_ctrl[0].piebar1 = 0x0;
200         pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | PIWAR_IWS_2G;
201
202         hose->first_busno = 0;
203         hose->last_busno = 0xff;
204
205         /* PCI memory space */
206         pci_set_region(hose->regions + 0,
207                        CFG_PCI1_MEM_BASE,
208                        CFG_PCI1_MEM_PHYS,
209                        CFG_PCI1_MEM_SIZE,
210                        PCI_REGION_MEM);
211
212         /* PCI IO space */
213         pci_set_region(hose->regions + 1,
214                        CFG_PCI1_IO_BASE,
215                        CFG_PCI1_IO_PHYS,
216                        CFG_PCI1_IO_SIZE,
217                        PCI_REGION_IO);
218
219         /* System memory space */
220         pci_set_region(hose->regions + 2,
221                        CONFIG_PCI_SYS_MEM_BUS,
222                        CONFIG_PCI_SYS_MEM_PHYS,
223                        gd->ram_size,
224                        PCI_REGION_MEM | PCI_REGION_MEMORY);
225
226         hose->region_count = 3;
227
228         pci_setup_indirect(hose,
229                            (CFG_IMMRBAR+0x8300),
230                            (CFG_IMMRBAR+0x8304));
231
232         pci_register_hose(hose);
233
234         /*
235          * Write to Command register
236          */
237         reg16 = 0xff;
238         pci_hose_read_config_word (hose, PCI_BDF(0,0,0), PCI_COMMAND,
239                                         &reg16);
240         reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
241         pci_hose_write_config_word(hose, PCI_BDF(0,0,0), PCI_COMMAND,
242                                         reg16);
243
244         /*
245          * Clear non-reserved bits in status register.
246          */
247         pci_hose_write_config_word(hose, PCI_BDF(0,0,0), PCI_STATUS,
248                                         0xffff);
249         pci_hose_write_config_byte(hose, PCI_BDF(0,0,0), PCI_LATENCY_TIMER,
250                                         0x80);
251
252 #ifdef CONFIG_PCI_SCAN_SHOW
253         printf("PCI:   Bus Dev VenId DevId Class Int\n");
254 #endif
255         /*
256          * Hose scan.
257          */
258         hose->last_busno = pci_hose_scan(hose);
259 }
260 #endif /* CONFIG_PCI */