]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/powerpc/cpu/mpc8260/pci.c
Merge branch 'master' of git://git.denx.de/u-boot-arm
[karo-tx-uboot.git] / arch / powerpc / cpu / mpc8260 / pci.c
1 /*
2  * (C) Copyright 2003
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * Copyright (c) 2005 MontaVista Software, Inc.
6  * Vitaly Bordug <vbordug@ru.mvista.com>
7  * Added support for PCI bridge on MPC8272ADS
8  *
9  * SPDX-License-Identifier:     GPL-2.0+
10  */
11
12 #include <common.h>
13
14 #ifdef CONFIG_PCI
15
16 #include <pci.h>
17 #include <mpc8260.h>
18 #include <asm/m8260_pci.h>
19 #include <asm/io.h>
20 #ifdef CONFIG_OF_LIBFDT
21 #include <libfdt.h>
22 #include <fdt_support.h>
23 #endif
24
25 #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272 || defined CONFIG_PM826
26 DECLARE_GLOBAL_DATA_PTR;
27 #endif
28
29 /*
30  *   Local->PCI map (from CPU)                             controlled by
31  *   MPC826x master window
32  *
33  *   0x80000000 - 0xBFFFFFFF    CPU2PCI space              PCIBR0
34  *   0xF4000000 - 0xF7FFFFFF    CPU2PCI space              PCIBR1
35  *
36  *   0x80000000 - 0x9FFFFFFF    0x80000000 - 0x9FFFFFFF   (Outbound ATU #1)
37  *                              PCI Mem with prefetch
38  *
39  *   0xA0000000 - 0xBFFFFFFF    0xA0000000 - 0xBFFFFFFF   (Outbound ATU #2)
40  *                              PCI Mem w/o  prefetch
41  *
42  *   0xF4000000 - 0xF7FFFFFF    0x00000000 - 0x03FFFFFF   (Outbound ATU #3)
43  *                              32-bit PCI IO
44  *
45  *   PCI->Local map (from PCI)
46  *   MPC826x slave window                                  controlled by
47  *
48  *   0x00000000 - 0x1FFFFFFF    0x00000000 - 0x1FFFFFFF   (Inbound ATU #1)
49  *                              MPC826x local memory
50  */
51
52 /*
53  * Slave window that allows PCI masters to access MPC826x local memory.
54  * This window is set up using the first set of Inbound ATU registers
55  */
56
57 #ifndef CONFIG_SYS_PCI_SLV_MEM_LOCAL
58 #define PCI_SLV_MEM_LOCAL CONFIG_SYS_SDRAM_BASE /* Local base */
59 #else
60 #define PCI_SLV_MEM_LOCAL CONFIG_SYS_PCI_SLV_MEM_LOCAL
61 #endif
62
63 #ifndef CONFIG_SYS_PCI_SLV_MEM_BUS
64 #define PCI_SLV_MEM_BUS 0x00000000      /* PCI base */
65 #else
66 #define PCI_SLV_MEM_BUS CONFIG_SYS_PCI_SLV_MEM_BUS
67 #endif
68
69 #ifndef CONFIG_SYS_PICMR0_MASK_ATTRIB
70 #define PICMR0_MASK_ATTRIB      (PICMR_MASK_512MB | PICMR_ENABLE | \
71                                  PICMR_PREFETCH_EN)
72 #else
73 #define PICMR0_MASK_ATTRIB CONFIG_SYS_PICMR0_MASK_ATTRIB
74 #endif
75
76 /*
77  * These are the windows that allow the CPU to access PCI address space.
78  * 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
80  * these windows.
81  */
82
83 /* PCIBR0 */
84 #ifndef CONFIG_SYS_PCI_MSTR0_LOCAL
85 #define PCI_MSTR0_LOCAL         0x80000000      /* Local base */
86 #else
87 #define PCI_MSTR0_LOCAL CONFIG_SYS_PCI_MSTR0_LOCAL
88 #endif
89
90 #ifndef CONFIG_SYS_PCIMSK0_MASK
91 #define PCIMSK0_MASK            PCIMSK_1GB      /* Size of window */
92 #else
93 #define PCIMSK0_MASK    CONFIG_SYS_PCIMSK0_MASK
94 #endif
95
96 /* PCIBR1 */
97 #ifndef CONFIG_SYS_PCI_MSTR1_LOCAL
98 #define PCI_MSTR1_LOCAL         0xF4000000      /* Local base */
99 #else
100 #define PCI_MSTR1_LOCAL         CONFIG_SYS_PCI_MSTR1_LOCAL
101 #endif
102
103 #ifndef CONFIG_SYS_PCIMSK1_MASK
104 #define  PCIMSK1_MASK           PCIMSK_64MB     /* Size of window */
105 #else
106 #define  PCIMSK1_MASK           CONFIG_SYS_PCIMSK1_MASK
107 #endif
108
109 /*
110  * 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
115 #ifndef CONFIG_SYS_PCI_MSTR_MEM_LOCAL
116 #define PCI_MSTR_MEM_LOCAL 0x80000000   /* Local base */
117 #else
118 #define PCI_MSTR_MEM_LOCAL CONFIG_SYS_PCI_MSTR_MEM_LOCAL
119 #endif
120
121 #ifndef CONFIG_SYS_PCI_MSTR_MEM_BUS
122 #define PCI_MSTR_MEM_BUS 0x80000000     /* PCI base   */
123 #else
124 #define PCI_MSTR_MEM_BUS CONFIG_SYS_PCI_MSTR_MEM_BUS
125 #endif
126
127 #ifndef CONFIG_SYS_CPU_PCI_MEM_START
128 #define CPU_PCI_MEM_START PCI_MSTR_MEM_LOCAL
129 #else
130 #define CPU_PCI_MEM_START CONFIG_SYS_CPU_PCI_MEM_START
131 #endif
132
133 #ifndef CONFIG_SYS_PCI_MSTR_MEM_SIZE
134 #define PCI_MSTR_MEM_SIZE 0x10000000    /* 256MB */
135 #else
136 #define PCI_MSTR_MEM_SIZE CONFIG_SYS_PCI_MSTR_MEM_SIZE
137 #endif
138
139 #ifndef CONFIG_SYS_POCMR0_MASK_ATTRIB
140 #define POCMR0_MASK_ATTRIB      (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PREFETCH_EN)
141 #else
142 #define POCMR0_MASK_ATTRIB CONFIG_SYS_POCMR0_MASK_ATTRIB
143 #endif
144
145 /*
146  * 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
151 #ifndef CONFIG_SYS_PCI_MSTR_MEMIO_LOCAL
152 #define PCI_MSTR_MEMIO_LOCAL 0x90000000 /* Local base */
153 #else
154 #define PCI_MSTR_MEMIO_LOCAL CONFIG_SYS_PCI_MSTR_MEMIO_LOCAL
155 #endif
156
157 #ifndef CONFIG_SYS_PCI_MSTR_MEMIO_BUS
158 #define PCI_MSTR_MEMIO_BUS 0x90000000   /* PCI base   */
159 #else
160 #define PCI_MSTR_MEMIO_BUS CONFIG_SYS_PCI_MSTR_MEMIO_BUS
161 #endif
162
163 #ifndef CONFIG_SYS_CPU_PCI_MEMIO_START
164 #define CPU_PCI_MEMIO_START PCI_MSTR_MEMIO_LOCAL
165 #else
166 #define CPU_PCI_MEMIO_START CONFIG_SYS_CPU_PCI_MEMIO_START
167 #endif
168
169 #ifndef CONFIG_SYS_PCI_MSTR_MEMIO_SIZE
170 #define PCI_MSTR_MEMIO_SIZE 0x10000000  /* 256 MB */
171 #else
172 #define PCI_MSTR_MEMIO_SIZE CONFIG_SYS_PCI_MSTR_MEMIO_SIZE
173 #endif
174
175 #ifndef CONFIG_SYS_POCMR1_MASK_ATTRIB
176 #define POCMR1_MASK_ATTRIB      (POCMR_MASK_512MB | POCMR_ENABLE)
177 #else
178 #define POCMR1_MASK_ATTRIB CONFIG_SYS_POCMR1_MASK_ATTRIB
179 #endif
180
181 /*
182  * 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
187 #ifndef CONFIG_SYS_PCI_MSTR_IO_LOCAL
188 #define PCI_MSTR_IO_LOCAL 0xA0000000    /* Local base */
189 #else
190 #define PCI_MSTR_IO_LOCAL CONFIG_SYS_PCI_MSTR_IO_LOCAL
191 #endif
192
193 #ifndef CONFIG_SYS_PCI_MSTR_IO_BUS
194 #define PCI_MSTR_IO_BUS 0xA0000000      /* PCI base   */
195 #else
196 #define PCI_MSTR_IO_BUS CONFIG_SYS_PCI_MSTR_IO_BUS
197 #endif
198
199 #ifndef CONFIG_SYS_CPU_PCI_IO_START
200 #define CPU_PCI_IO_START PCI_MSTR_IO_LOCAL
201 #else
202 #define CPU_PCI_IO_START CONFIG_SYS_CPU_PCI_IO_START
203 #endif
204
205 #ifndef CONFIG_SYS_PCI_MSTR_IO_SIZE
206 #define PCI_MSTR_IO_SIZE 0x10000000     /* 256MB */
207 #else
208 #define PCI_MSTR_IO_SIZE CONFIG_SYS_PCI_MSTR_IO_SIZE
209 #endif
210
211 #ifndef CONFIG_SYS_POCMR2_MASK_ATTRIB
212 #define POCMR2_MASK_ATTRIB      (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PCI_IO)
213 #else
214 #define POCMR2_MASK_ATTRIB CONFIG_SYS_POCMR2_MASK_ATTRIB
215 #endif
216
217 /* PCI bus configuration registers.
218  */
219
220 #define PCI_CLASS_BRIDGE_CTLR   0x06
221
222
223 static inline void pci_outl (u32 addr, u32 data)
224 {
225         *(volatile u32 *) addr = cpu_to_le32 (data);
226 }
227
228 void pci_mpc8250_init (struct pci_controller *hose)
229 {
230         u16 tempShort;
231
232         volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
233         pci_dev_t host_devno = PCI_BDF (0, 0, 0);
234
235         pci_setup_indirect (hose, CONFIG_SYS_IMMR + PCI_CFG_ADDR_REG,
236                             CONFIG_SYS_IMMR + PCI_CFG_DATA_REG);
237
238         /*
239          * Setting required to enable local bus for PCI (SIUMCR [LBPC]).
240          */
241 #ifdef CONFIG_MPC8266ADS
242         immap->im_siu_conf.sc_siumcr =
243                 (immap->im_siu_conf.sc_siumcr & ~SIUMCR_LBPC11)
244                 | SIUMCR_LBPC01;
245 #elif defined CONFIG_MPC8272
246         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;
265 #else
266         /*
267          * Setting required to enable IRQ1-IRQ7 (SIUMCR [DPPC]),
268          * and local bus for PCI (SIUMCR [LBPC]).
269          */
270         immap->im_siu_conf.sc_siumcr = (immap->im_siu_conf.sc_siumcr &
271                                                 ~SIUMCR_LBPC11 &
272                                                 ~SIUMCR_CS10PC11 &
273                                                 ~SIUMCR_LBPC11) |
274                                         SIUMCR_LBPC01 |
275                                         SIUMCR_CS10PC01 |
276                                         SIUMCR_APPC10;
277 #endif
278
279         /* Make PCI lowest priority */
280         /* Each 4 bits is a device bus request  and the MS 4bits
281            is highest priority */
282         /* Bus               4bit value
283            ---               ----------
284            CPM high          0b0000
285            CPM middle        0b0001
286            CPM low           0b0010
287            PCI reguest       0b0011
288            Reserved          0b0100
289            Reserved          0b0101
290            Internal Core     0b0110
291            External Master 1 0b0111
292            External Master 2 0b1000
293            External Master 3 0b1001
294            The rest are reserved */
295         immap->im_siu_conf.sc_ppc_alrh = 0x61207893;
296
297         /* Park bus on core while modifying PCI Bus accesses */
298         immap->im_siu_conf.sc_ppc_acr = 0x6;
299
300         /*
301          * Set up master windows that allow the CPU to access PCI space. These
302          * windows are set up using the two SIU PCIBR registers.
303          */
304         immap->im_memctl.memc_pcimsk0 = PCIMSK0_MASK;
305         immap->im_memctl.memc_pcibr0 = PCI_MSTR0_LOCAL | PCIBR_ENABLE;
306
307 #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
308         immap->im_memctl.memc_pcimsk1 = PCIMSK1_MASK;
309         immap->im_memctl.memc_pcibr1 = PCI_MSTR1_LOCAL | PCIBR_ENABLE;
310 #endif
311
312         /* Release PCI RST (by default the PCI RST signal is held low)  */
313         immap->im_pci.pci_gcr = cpu_to_le32 (PCIGCR_PCI_BUS_EN);
314
315         /* give it some time */
316         {
317 #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
318                 /* Give the PCI cards more time to initialize before query
319                    This might be good for other boards also
320                  */
321                 int i;
322
323                 for (i = 0; i < 1000; ++i)
324 #endif
325                         udelay (1000);
326         }
327
328         /*
329          * Set up master window that allows the CPU to access PCI Memory (prefetch)
330          * space. This window is set up using the first set of Outbound ATU registers.
331          */
332         immap->im_pci.pci_potar0 = cpu_to_le32 (PCI_MSTR_MEM_BUS >> 12);        /* PCI base */
333         immap->im_pci.pci_pobar0 = cpu_to_le32 (PCI_MSTR_MEM_LOCAL >> 12);      /* Local base */
334         immap->im_pci.pci_pocmr0 = cpu_to_le32 (POCMR0_MASK_ATTRIB);    /* Size & attribute */
335
336         /*
337          * Set up master window that allows the CPU to access PCI Memory (non-prefetch)
338          * space. This window is set up using the second set of Outbound ATU registers.
339          */
340         immap->im_pci.pci_potar1 = cpu_to_le32 (PCI_MSTR_MEMIO_BUS >> 12);      /* PCI base */
341         immap->im_pci.pci_pobar1 = cpu_to_le32 (PCI_MSTR_MEMIO_LOCAL >> 12);    /* Local base */
342         immap->im_pci.pci_pocmr1 = cpu_to_le32 (POCMR1_MASK_ATTRIB);    /* Size & attribute */
343
344         /*
345          * Set up master window that allows the CPU to access PCI IO space. This window
346          * is set up using the third set of Outbound ATU registers.
347          */
348         immap->im_pci.pci_potar2 = cpu_to_le32 (PCI_MSTR_IO_BUS >> 12); /* PCI base */
349         immap->im_pci.pci_pobar2 = cpu_to_le32 (PCI_MSTR_IO_LOCAL >> 12);       /* Local base */
350         immap->im_pci.pci_pocmr2 = cpu_to_le32 (POCMR2_MASK_ATTRIB);    /* Size & attribute */
351
352         /*
353          * Set up slave window that allows PCI masters to access MPC826x local memory.
354          * This window is set up using the first set of Inbound ATU registers
355          */
356         immap->im_pci.pci_pitar0 = cpu_to_le32 (PCI_SLV_MEM_LOCAL >> 12);       /* PCI base */
357         immap->im_pci.pci_pibar0 = cpu_to_le32 (PCI_SLV_MEM_BUS >> 12); /* Local base */
358         immap->im_pci.pci_picmr0 = cpu_to_le32 (PICMR0_MASK_ATTRIB);    /* Size & attribute */
359
360         /* See above for description - puts PCI request as highest priority */
361 #ifdef CONFIG_MPC8272
362         immap->im_siu_conf.sc_ppc_alrh = 0x01236745;
363 #else
364         immap->im_siu_conf.sc_ppc_alrh = 0x03124567;
365 #endif
366
367         /* Park the bus on the PCI */
368         immap->im_siu_conf.sc_ppc_acr = PPC_ACR_BUS_PARK_PCI;
369
370         /* Host mode - specify the bridge as a host-PCI bridge */
371
372         pci_hose_write_config_byte (hose, host_devno, PCI_CLASS_CODE,
373                                     PCI_CLASS_BRIDGE_CTLR);
374
375         /* Enable the host bridge to be a master on the PCI bus, and to act as a PCI memory target */
376         pci_hose_read_config_word (hose, host_devno, PCI_COMMAND, &tempShort);
377         pci_hose_write_config_word (hose, host_devno, PCI_COMMAND,
378                                     tempShort | PCI_COMMAND_MASTER |
379                                     PCI_COMMAND_MEMORY);
380
381         /* do some bridge init, should be done on all 8260 based bridges */
382         pci_hose_write_config_byte (hose, host_devno, PCI_CACHE_LINE_SIZE,
383                                     0x08);
384         pci_hose_write_config_byte (hose, host_devno, PCI_LATENCY_TIMER,
385                                     0xF8);
386
387         hose->first_busno = 0;
388         hose->last_busno = 0xff;
389
390         /* System memory space */
391 #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272 || defined CONFIG_PM826
392         pci_set_region (hose->regions + 0,
393                         PCI_SLV_MEM_BUS,
394                         PCI_SLV_MEM_LOCAL,
395                         gd->ram_size, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
396 #else
397         pci_set_region (hose->regions + 0,
398                         CONFIG_SYS_SDRAM_BASE,
399                         CONFIG_SYS_SDRAM_BASE,
400                         0x4000000, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
401 #endif
402
403         /* PCI memory space */
404 #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
405         pci_set_region (hose->regions + 1,
406                         PCI_MSTR_MEMIO_BUS,
407                         PCI_MSTR_MEMIO_LOCAL,
408                         PCI_MSTR_MEMIO_SIZE, PCI_REGION_MEM);
409 #else
410         pci_set_region (hose->regions + 1,
411                         PCI_MSTR_MEM_BUS,
412                         PCI_MSTR_MEM_LOCAL,
413                         PCI_MSTR_MEM_SIZE, PCI_REGION_MEM);
414 #endif
415
416         /* PCI I/O space */
417         pci_set_region (hose->regions + 2,
418                         PCI_MSTR_IO_BUS,
419                         PCI_MSTR_IO_LOCAL, PCI_MSTR_IO_SIZE, PCI_REGION_IO);
420
421         hose->region_count = 3;
422
423         pci_register_hose (hose);
424         /* Mask off master abort machine checks */
425         immap->im_pci.pci_emr &= cpu_to_le32 (~PCI_ERROR_PCI_NO_RSP);
426         eieio ();
427
428         hose->last_busno = pci_hose_scan (hose);
429
430
431         /* clear the error in the error status register */
432         immap->im_pci.pci_esr = cpu_to_le32 (PCI_ERROR_PCI_NO_RSP);
433
434         /* unmask master abort machine checks */
435         immap->im_pci.pci_emr |= cpu_to_le32 (PCI_ERROR_PCI_NO_RSP);
436 }
437
438 #if defined(CONFIG_OF_LIBFDT)
439 void ft_pci_setup(void *blob, bd_t *bd)
440 {
441         do_fixup_by_prop_u32(blob, "device_type", "pci", 4,
442                 "clock-frequency", gd->pci_clk, 1);
443 }
444 #endif
445
446 #endif /* CONFIG_PCI */