2 * arch/ppc/syslib/mv64x60.c
4 * Common routines for the Marvell/Galileo Discovery line of host bridges
5 * (gt64260, mv64360, mv64460, ...).
7 * Author: Mark A. Greer <mgreer@mvista.com>
9 * 2004 (c) MontaVista, Software, Inc. This file is licensed under
10 * the terms of the GNU General Public License version 2. This program
11 * is licensed "as is" without any warranty of any kind, whether express
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/pci.h>
17 #include <linux/slab.h>
18 #include <linux/module.h>
19 #include <linux/string.h>
20 #include <linux/spinlock.h>
21 #include <linux/mv643xx.h>
23 #include <asm/byteorder.h>
26 #include <asm/uaccess.h>
27 #include <asm/machdep.h>
28 #include <asm/pci-bridge.h>
29 #include <asm/delay.h>
30 #include <asm/mv64x60.h>
33 u8 mv64x60_pci_exclude_bridge
= 1;
34 DEFINE_SPINLOCK(mv64x60_lock
);
36 static phys_addr_t mv64x60_bridge_pbase
;
37 static void *mv64x60_bridge_vbase
;
38 static u32 mv64x60_bridge_type
= MV64x60_TYPE_INVALID
;
39 static u32 mv64x60_bridge_rev
;
40 #if defined(CONFIG_SYSFS) && !defined(CONFIG_GT64260)
41 static struct pci_controller sysfs_hose_a
;
44 static u32
gt64260_translate_size(u32 base
, u32 size
, u32 num_bits
);
45 static u32
gt64260_untranslate_size(u32 base
, u32 size
, u32 num_bits
);
46 static void gt64260_set_pci2mem_window(struct pci_controller
*hose
, u32 bus
,
47 u32 window
, u32 base
);
48 static void gt64260_set_pci2regs_window(struct mv64x60_handle
*bh
,
49 struct pci_controller
*hose
, u32 bus
, u32 base
);
50 static u32
gt64260_is_enabled_32bit(struct mv64x60_handle
*bh
, u32 window
);
51 static void gt64260_enable_window_32bit(struct mv64x60_handle
*bh
, u32 window
);
52 static void gt64260_disable_window_32bit(struct mv64x60_handle
*bh
, u32 window
);
53 static void gt64260_enable_window_64bit(struct mv64x60_handle
*bh
, u32 window
);
54 static void gt64260_disable_window_64bit(struct mv64x60_handle
*bh
, u32 window
);
55 static void gt64260_disable_all_windows(struct mv64x60_handle
*bh
,
56 struct mv64x60_setup_info
*si
);
57 static void gt64260a_chip_specific_init(struct mv64x60_handle
*bh
,
58 struct mv64x60_setup_info
*si
);
59 static void gt64260b_chip_specific_init(struct mv64x60_handle
*bh
,
60 struct mv64x60_setup_info
*si
);
62 static u32
mv64360_translate_size(u32 base
, u32 size
, u32 num_bits
);
63 static u32
mv64360_untranslate_size(u32 base
, u32 size
, u32 num_bits
);
64 static void mv64360_set_pci2mem_window(struct pci_controller
*hose
, u32 bus
,
65 u32 window
, u32 base
);
66 static void mv64360_set_pci2regs_window(struct mv64x60_handle
*bh
,
67 struct pci_controller
*hose
, u32 bus
, u32 base
);
68 static u32
mv64360_is_enabled_32bit(struct mv64x60_handle
*bh
, u32 window
);
69 static void mv64360_enable_window_32bit(struct mv64x60_handle
*bh
, u32 window
);
70 static void mv64360_disable_window_32bit(struct mv64x60_handle
*bh
, u32 window
);
71 static void mv64360_enable_window_64bit(struct mv64x60_handle
*bh
, u32 window
);
72 static void mv64360_disable_window_64bit(struct mv64x60_handle
*bh
, u32 window
);
73 static void mv64360_disable_all_windows(struct mv64x60_handle
*bh
,
74 struct mv64x60_setup_info
*si
);
75 static void mv64360_config_io2mem_windows(struct mv64x60_handle
*bh
,
76 struct mv64x60_setup_info
*si
,
77 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2]);
78 static void mv64360_set_mpsc2regs_window(struct mv64x60_handle
*bh
, u32 base
);
79 static void mv64360_chip_specific_init(struct mv64x60_handle
*bh
,
80 struct mv64x60_setup_info
*si
);
81 static void mv64460_chip_specific_init(struct mv64x60_handle
*bh
,
82 struct mv64x60_setup_info
*si
);
86 * Define tables that have the chip-specific info for each type of
87 * Marvell bridge chip.
89 static struct mv64x60_chip_info gt64260a_ci __initdata
= { /* GT64260A */
90 .translate_size
= gt64260_translate_size
,
91 .untranslate_size
= gt64260_untranslate_size
,
92 .set_pci2mem_window
= gt64260_set_pci2mem_window
,
93 .set_pci2regs_window
= gt64260_set_pci2regs_window
,
94 .is_enabled_32bit
= gt64260_is_enabled_32bit
,
95 .enable_window_32bit
= gt64260_enable_window_32bit
,
96 .disable_window_32bit
= gt64260_disable_window_32bit
,
97 .enable_window_64bit
= gt64260_enable_window_64bit
,
98 .disable_window_64bit
= gt64260_disable_window_64bit
,
99 .disable_all_windows
= gt64260_disable_all_windows
,
100 .chip_specific_init
= gt64260a_chip_specific_init
,
101 .window_tab_32bit
= gt64260_32bit_windows
,
102 .window_tab_64bit
= gt64260_64bit_windows
,
105 static struct mv64x60_chip_info gt64260b_ci __initdata
= { /* GT64260B */
106 .translate_size
= gt64260_translate_size
,
107 .untranslate_size
= gt64260_untranslate_size
,
108 .set_pci2mem_window
= gt64260_set_pci2mem_window
,
109 .set_pci2regs_window
= gt64260_set_pci2regs_window
,
110 .is_enabled_32bit
= gt64260_is_enabled_32bit
,
111 .enable_window_32bit
= gt64260_enable_window_32bit
,
112 .disable_window_32bit
= gt64260_disable_window_32bit
,
113 .enable_window_64bit
= gt64260_enable_window_64bit
,
114 .disable_window_64bit
= gt64260_disable_window_64bit
,
115 .disable_all_windows
= gt64260_disable_all_windows
,
116 .chip_specific_init
= gt64260b_chip_specific_init
,
117 .window_tab_32bit
= gt64260_32bit_windows
,
118 .window_tab_64bit
= gt64260_64bit_windows
,
121 static struct mv64x60_chip_info mv64360_ci __initdata
= { /* MV64360 */
122 .translate_size
= mv64360_translate_size
,
123 .untranslate_size
= mv64360_untranslate_size
,
124 .set_pci2mem_window
= mv64360_set_pci2mem_window
,
125 .set_pci2regs_window
= mv64360_set_pci2regs_window
,
126 .is_enabled_32bit
= mv64360_is_enabled_32bit
,
127 .enable_window_32bit
= mv64360_enable_window_32bit
,
128 .disable_window_32bit
= mv64360_disable_window_32bit
,
129 .enable_window_64bit
= mv64360_enable_window_64bit
,
130 .disable_window_64bit
= mv64360_disable_window_64bit
,
131 .disable_all_windows
= mv64360_disable_all_windows
,
132 .config_io2mem_windows
= mv64360_config_io2mem_windows
,
133 .set_mpsc2regs_window
= mv64360_set_mpsc2regs_window
,
134 .chip_specific_init
= mv64360_chip_specific_init
,
135 .window_tab_32bit
= mv64360_32bit_windows
,
136 .window_tab_64bit
= mv64360_64bit_windows
,
139 static struct mv64x60_chip_info mv64460_ci __initdata
= { /* MV64460 */
140 .translate_size
= mv64360_translate_size
,
141 .untranslate_size
= mv64360_untranslate_size
,
142 .set_pci2mem_window
= mv64360_set_pci2mem_window
,
143 .set_pci2regs_window
= mv64360_set_pci2regs_window
,
144 .is_enabled_32bit
= mv64360_is_enabled_32bit
,
145 .enable_window_32bit
= mv64360_enable_window_32bit
,
146 .disable_window_32bit
= mv64360_disable_window_32bit
,
147 .enable_window_64bit
= mv64360_enable_window_64bit
,
148 .disable_window_64bit
= mv64360_disable_window_64bit
,
149 .disable_all_windows
= mv64360_disable_all_windows
,
150 .config_io2mem_windows
= mv64360_config_io2mem_windows
,
151 .set_mpsc2regs_window
= mv64360_set_mpsc2regs_window
,
152 .chip_specific_init
= mv64460_chip_specific_init
,
153 .window_tab_32bit
= mv64360_32bit_windows
,
154 .window_tab_64bit
= mv64360_64bit_windows
,
158 *****************************************************************************
160 * Platform Device Definitions
162 *****************************************************************************
164 #ifdef CONFIG_SERIAL_MPSC
165 static struct mpsc_shared_pdata mv64x60_mpsc_shared_pdata
= {
166 .mrr_val
= 0x3ffffe38,
173 static struct resource mv64x60_mpsc_shared_resources
[] = {
174 /* Do not change the order of the IORESOURCE_MEM resources */
176 .name
= "mpsc routing base",
177 .start
= MV64x60_MPSC_ROUTING_OFFSET
,
178 .end
= MV64x60_MPSC_ROUTING_OFFSET
+
179 MPSC_ROUTING_REG_BLOCK_SIZE
- 1,
180 .flags
= IORESOURCE_MEM
,
183 .name
= "sdma intr base",
184 .start
= MV64x60_SDMA_INTR_OFFSET
,
185 .end
= MV64x60_SDMA_INTR_OFFSET
+
186 MPSC_SDMA_INTR_REG_BLOCK_SIZE
- 1,
187 .flags
= IORESOURCE_MEM
,
191 static struct platform_device mpsc_shared_device
= { /* Shared device */
192 .name
= MPSC_SHARED_NAME
,
194 .num_resources
= ARRAY_SIZE(mv64x60_mpsc_shared_resources
),
195 .resource
= mv64x60_mpsc_shared_resources
,
197 .platform_data
= &mv64x60_mpsc_shared_pdata
,
201 static struct mpsc_pdata mv64x60_mpsc0_pdata
= {
205 .default_baud
= 9600,
207 .default_parity
= 'n',
209 .chr_1_val
= 0x00000000,
210 .chr_2_val
= 0x00000000,
211 .chr_10_val
= 0x00000003,
215 .brg_clk_src
= 8, /* Default to TCLK */
216 .brg_clk_freq
= 100000000, /* Default to 100 MHz */
219 static struct resource mv64x60_mpsc0_resources
[] = {
220 /* Do not change the order of the IORESOURCE_MEM resources */
222 .name
= "mpsc 0 base",
223 .start
= MV64x60_MPSC_0_OFFSET
,
224 .end
= MV64x60_MPSC_0_OFFSET
+ MPSC_REG_BLOCK_SIZE
- 1,
225 .flags
= IORESOURCE_MEM
,
228 .name
= "sdma 0 base",
229 .start
= MV64x60_SDMA_0_OFFSET
,
230 .end
= MV64x60_SDMA_0_OFFSET
+ MPSC_SDMA_REG_BLOCK_SIZE
- 1,
231 .flags
= IORESOURCE_MEM
,
234 .name
= "brg 0 base",
235 .start
= MV64x60_BRG_0_OFFSET
,
236 .end
= MV64x60_BRG_0_OFFSET
+ MPSC_BRG_REG_BLOCK_SIZE
- 1,
237 .flags
= IORESOURCE_MEM
,
240 .name
= "sdma 0 irq",
241 .start
= MV64x60_IRQ_SDMA_0
,
242 .end
= MV64x60_IRQ_SDMA_0
,
243 .flags
= IORESOURCE_IRQ
,
247 static struct platform_device mpsc0_device
= {
248 .name
= MPSC_CTLR_NAME
,
250 .num_resources
= ARRAY_SIZE(mv64x60_mpsc0_resources
),
251 .resource
= mv64x60_mpsc0_resources
,
253 .platform_data
= &mv64x60_mpsc0_pdata
,
257 static struct mpsc_pdata mv64x60_mpsc1_pdata
= {
261 .default_baud
= 9600,
263 .default_parity
= 'n',
265 .chr_1_val
= 0x00000000,
266 .chr_1_val
= 0x00000000,
267 .chr_2_val
= 0x00000000,
268 .chr_10_val
= 0x00000003,
272 .brg_clk_src
= 8, /* Default to TCLK */
273 .brg_clk_freq
= 100000000, /* Default to 100 MHz */
276 static struct resource mv64x60_mpsc1_resources
[] = {
277 /* Do not change the order of the IORESOURCE_MEM resources */
279 .name
= "mpsc 1 base",
280 .start
= MV64x60_MPSC_1_OFFSET
,
281 .end
= MV64x60_MPSC_1_OFFSET
+ MPSC_REG_BLOCK_SIZE
- 1,
282 .flags
= IORESOURCE_MEM
,
285 .name
= "sdma 1 base",
286 .start
= MV64x60_SDMA_1_OFFSET
,
287 .end
= MV64x60_SDMA_1_OFFSET
+ MPSC_SDMA_REG_BLOCK_SIZE
- 1,
288 .flags
= IORESOURCE_MEM
,
291 .name
= "brg 1 base",
292 .start
= MV64x60_BRG_1_OFFSET
,
293 .end
= MV64x60_BRG_1_OFFSET
+ MPSC_BRG_REG_BLOCK_SIZE
- 1,
294 .flags
= IORESOURCE_MEM
,
297 .name
= "sdma 1 irq",
298 .start
= MV64360_IRQ_SDMA_1
,
299 .end
= MV64360_IRQ_SDMA_1
,
300 .flags
= IORESOURCE_IRQ
,
304 static struct platform_device mpsc1_device
= {
305 .name
= MPSC_CTLR_NAME
,
307 .num_resources
= ARRAY_SIZE(mv64x60_mpsc1_resources
),
308 .resource
= mv64x60_mpsc1_resources
,
310 .platform_data
= &mv64x60_mpsc1_pdata
,
315 #ifdef CONFIG_MV643XX_ETH
316 static struct resource mv64x60_eth_shared_resources
[] = {
318 .name
= "ethernet shared base",
319 .start
= MV643XX_ETH_SHARED_REGS
,
320 .end
= MV643XX_ETH_SHARED_REGS
+
321 MV643XX_ETH_SHARED_REGS_SIZE
- 1,
322 .flags
= IORESOURCE_MEM
,
326 static struct platform_device mv64x60_eth_shared_device
= {
327 .name
= MV643XX_ETH_SHARED_NAME
,
329 .num_resources
= ARRAY_SIZE(mv64x60_eth_shared_resources
),
330 .resource
= mv64x60_eth_shared_resources
,
333 #ifdef CONFIG_MV643XX_ETH_0
334 static struct resource mv64x60_eth0_resources
[] = {
337 .start
= MV64x60_IRQ_ETH_0
,
338 .end
= MV64x60_IRQ_ETH_0
,
339 .flags
= IORESOURCE_IRQ
,
343 static struct mv643xx_eth_platform_data eth0_pd
;
345 static struct platform_device eth0_device
= {
346 .name
= MV643XX_ETH_NAME
,
348 .num_resources
= ARRAY_SIZE(mv64x60_eth0_resources
),
349 .resource
= mv64x60_eth0_resources
,
351 .platform_data
= ð0_pd
,
356 #ifdef CONFIG_MV643XX_ETH_1
357 static struct resource mv64x60_eth1_resources
[] = {
360 .start
= MV64x60_IRQ_ETH_1
,
361 .end
= MV64x60_IRQ_ETH_1
,
362 .flags
= IORESOURCE_IRQ
,
366 static struct mv643xx_eth_platform_data eth1_pd
;
368 static struct platform_device eth1_device
= {
369 .name
= MV643XX_ETH_NAME
,
371 .num_resources
= ARRAY_SIZE(mv64x60_eth1_resources
),
372 .resource
= mv64x60_eth1_resources
,
374 .platform_data
= ð1_pd
,
379 #ifdef CONFIG_MV643XX_ETH_2
380 static struct resource mv64x60_eth2_resources
[] = {
383 .start
= MV64x60_IRQ_ETH_2
,
384 .end
= MV64x60_IRQ_ETH_2
,
385 .flags
= IORESOURCE_IRQ
,
389 static struct mv643xx_eth_platform_data eth2_pd
;
391 static struct platform_device eth2_device
= {
392 .name
= MV643XX_ETH_NAME
,
394 .num_resources
= ARRAY_SIZE(mv64x60_eth2_resources
),
395 .resource
= mv64x60_eth2_resources
,
397 .platform_data
= ð2_pd
,
403 #ifdef CONFIG_I2C_MV64XXX
404 static struct mv64xxx_i2c_pdata mv64xxx_i2c_pdata
= {
407 .timeout
= 1000, /* Default timeout of 1 second */
411 static struct resource mv64xxx_i2c_resources
[] = {
412 /* Do not change the order of the IORESOURCE_MEM resources */
414 .name
= "mv64xxx i2c base",
415 .start
= MV64XXX_I2C_OFFSET
,
416 .end
= MV64XXX_I2C_OFFSET
+ MV64XXX_I2C_REG_BLOCK_SIZE
- 1,
417 .flags
= IORESOURCE_MEM
,
420 .name
= "mv64xxx i2c irq",
421 .start
= MV64x60_IRQ_I2C
,
422 .end
= MV64x60_IRQ_I2C
,
423 .flags
= IORESOURCE_IRQ
,
427 static struct platform_device i2c_device
= {
428 .name
= MV64XXX_I2C_CTLR_NAME
,
430 .num_resources
= ARRAY_SIZE(mv64xxx_i2c_resources
),
431 .resource
= mv64xxx_i2c_resources
,
433 .platform_data
= &mv64xxx_i2c_pdata
,
438 #if defined(CONFIG_SYSFS) && !defined(CONFIG_GT64260)
439 static struct mv64xxx_pdata mv64xxx_pdata
= {
443 static struct platform_device mv64xxx_device
= { /* general mv64x60 stuff */
444 .name
= MV64XXX_DEV_NAME
,
447 .platform_data
= &mv64xxx_pdata
,
452 static struct platform_device
*mv64x60_pd_devs
[] __initdata
= {
453 #ifdef CONFIG_SERIAL_MPSC
458 #ifdef CONFIG_MV643XX_ETH
459 &mv64x60_eth_shared_device
,
461 #ifdef CONFIG_MV643XX_ETH_0
464 #ifdef CONFIG_MV643XX_ETH_1
467 #ifdef CONFIG_MV643XX_ETH_2
470 #ifdef CONFIG_I2C_MV64XXX
473 #if defined(CONFIG_SYSFS) && !defined(CONFIG_GT64260)
479 *****************************************************************************
481 * Bridge Initialization Routines
483 *****************************************************************************
488 * Initialze the bridge based on setting passed in via 'si'. The bridge
489 * handle, 'bh', will be set so that it can be used to make subsequent
490 * calls to routines in this file.
493 mv64x60_init(struct mv64x60_handle
*bh
, struct mv64x60_setup_info
*si
)
495 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2];
498 ppc_md
.progress("mv64x60 initialization", 0x0);
500 spin_lock_init(&mv64x60_lock
);
501 mv64x60_early_init(bh
, si
);
503 if (mv64x60_get_type(bh
) || mv64x60_setup_for_chip(bh
)) {
507 ppc_md
.progress("mv64x60_init: Can't determine chip",0);
511 bh
->ci
->disable_all_windows(bh
, si
);
512 mv64x60_get_mem_windows(bh
, mem_windows
);
513 mv64x60_config_cpu2mem_windows(bh
, si
, mem_windows
);
515 if (bh
->ci
->config_io2mem_windows
)
516 bh
->ci
->config_io2mem_windows(bh
, si
, mem_windows
);
517 if (bh
->ci
->set_mpsc2regs_window
)
518 bh
->ci
->set_mpsc2regs_window(bh
, si
->phys_reg_base
);
520 if (si
->pci_1
.enable_bus
) {
521 bh
->io_base_b
= (u32
)ioremap(si
->pci_1
.pci_io
.cpu_base
,
522 si
->pci_1
.pci_io
.size
);
523 isa_io_base
= bh
->io_base_b
;
526 if (si
->pci_0
.enable_bus
) {
527 bh
->io_base_a
= (u32
)ioremap(si
->pci_0
.pci_io
.cpu_base
,
528 si
->pci_0
.pci_io
.size
);
529 isa_io_base
= bh
->io_base_a
;
531 mv64x60_alloc_hose(bh
, MV64x60_PCI0_CONFIG_ADDR
,
532 MV64x60_PCI0_CONFIG_DATA
, &bh
->hose_a
);
533 mv64x60_config_resources(bh
->hose_a
, &si
->pci_0
, bh
->io_base_a
);
534 mv64x60_config_pci_params(bh
->hose_a
, &si
->pci_0
);
536 mv64x60_config_cpu2pci_windows(bh
, &si
->pci_0
, 0);
537 mv64x60_config_pci2mem_windows(bh
, bh
->hose_a
, &si
->pci_0
, 0,
539 bh
->ci
->set_pci2regs_window(bh
, bh
->hose_a
, 0,
543 if (si
->pci_1
.enable_bus
) {
544 mv64x60_alloc_hose(bh
, MV64x60_PCI1_CONFIG_ADDR
,
545 MV64x60_PCI1_CONFIG_DATA
, &bh
->hose_b
);
546 mv64x60_config_resources(bh
->hose_b
, &si
->pci_1
, bh
->io_base_b
);
547 mv64x60_config_pci_params(bh
->hose_b
, &si
->pci_1
);
549 mv64x60_config_cpu2pci_windows(bh
, &si
->pci_1
, 1);
550 mv64x60_config_pci2mem_windows(bh
, bh
->hose_b
, &si
->pci_1
, 1,
552 bh
->ci
->set_pci2regs_window(bh
, bh
->hose_b
, 1,
556 bh
->ci
->chip_specific_init(bh
, si
);
557 mv64x60_pd_fixup(bh
, mv64x60_pd_devs
, ARRAY_SIZE(mv64x60_pd_devs
));
563 * mv64x60_early_init()
565 * Do some bridge work that must take place before we start messing with
566 * the bridge for real.
569 mv64x60_early_init(struct mv64x60_handle
*bh
, struct mv64x60_setup_info
*si
)
571 struct pci_controller hose_a
, hose_b
;
573 memset(bh
, 0, sizeof(*bh
));
575 bh
->p_base
= si
->phys_reg_base
;
576 bh
->v_base
= ioremap(bh
->p_base
, MV64x60_INTERNAL_SPACE_SIZE
);
578 mv64x60_bridge_pbase
= bh
->p_base
;
579 mv64x60_bridge_vbase
= bh
->v_base
;
581 /* Assuming pci mode [reserved] bits 4:5 on 64260 are 0 */
582 bh
->pci_mode_a
= mv64x60_read(bh
, MV64x60_PCI0_MODE
) &
583 MV64x60_PCIMODE_MASK
;
584 bh
->pci_mode_b
= mv64x60_read(bh
, MV64x60_PCI1_MODE
) &
585 MV64x60_PCIMODE_MASK
;
587 /* Need temporary hose structs to call mv64x60_set_bus() */
588 memset(&hose_a
, 0, sizeof(hose_a
));
589 memset(&hose_b
, 0, sizeof(hose_b
));
590 setup_indirect_pci_nomap(&hose_a
, bh
->v_base
+ MV64x60_PCI0_CONFIG_ADDR
,
591 bh
->v_base
+ MV64x60_PCI0_CONFIG_DATA
);
592 setup_indirect_pci_nomap(&hose_b
, bh
->v_base
+ MV64x60_PCI1_CONFIG_ADDR
,
593 bh
->v_base
+ MV64x60_PCI1_CONFIG_DATA
);
594 bh
->hose_a
= &hose_a
;
595 bh
->hose_b
= &hose_b
;
597 #if defined(CONFIG_SYSFS) && !defined(CONFIG_GT64260)
598 /* Save a copy of hose_a for sysfs functions -- hack */
599 memcpy(&sysfs_hose_a
, &hose_a
, sizeof(hose_a
));
602 mv64x60_set_bus(bh
, 0, 0);
603 mv64x60_set_bus(bh
, 1, 0);
608 /* Clear bit 0 of PCI addr decode control so PCI->CPU remap 1:1 */
609 mv64x60_clr_bits(bh
, MV64x60_PCI0_PCI_DECODE_CNTL
, 0x00000001);
610 mv64x60_clr_bits(bh
, MV64x60_PCI1_PCI_DECODE_CNTL
, 0x00000001);
612 /* Bit 12 MUST be 0; set bit 27--don't auto-update cpu remap regs */
613 mv64x60_clr_bits(bh
, MV64x60_CPU_CONFIG
, (1<<12));
614 mv64x60_set_bits(bh
, MV64x60_CPU_CONFIG
, (1<<27));
616 mv64x60_set_bits(bh
, MV64x60_PCI0_TO_RETRY
, 0xffff);
617 mv64x60_set_bits(bh
, MV64x60_PCI1_TO_RETRY
, 0xffff);
621 *****************************************************************************
623 * Window Config Routines
625 *****************************************************************************
628 * mv64x60_get_32bit_window()
630 * Determine the base address and size of a 32-bit window on the bridge.
633 mv64x60_get_32bit_window(struct mv64x60_handle
*bh
, u32 window
,
634 u32
*base
, u32
*size
)
636 u32 val
, base_reg
, size_reg
, base_bits
, size_bits
;
637 u32 (*get_from_field
)(u32 val
, u32 num_bits
);
639 base_reg
= bh
->ci
->window_tab_32bit
[window
].base_reg
;
642 size_reg
= bh
->ci
->window_tab_32bit
[window
].size_reg
;
643 base_bits
= bh
->ci
->window_tab_32bit
[window
].base_bits
;
644 size_bits
= bh
->ci
->window_tab_32bit
[window
].size_bits
;
645 get_from_field
= bh
->ci
->window_tab_32bit
[window
].get_from_field
;
647 val
= mv64x60_read(bh
, base_reg
);
648 *base
= get_from_field(val
, base_bits
);
651 val
= mv64x60_read(bh
, size_reg
);
652 val
= get_from_field(val
, size_bits
);
653 *size
= bh
->ci
->untranslate_size(*base
, val
, size_bits
);
661 pr_debug("get 32bit window: %d, base: 0x%x, size: 0x%x\n",
662 window
, *base
, *size
);
666 * mv64x60_set_32bit_window()
668 * Set the base address and size of a 32-bit window on the bridge.
671 mv64x60_set_32bit_window(struct mv64x60_handle
*bh
, u32 window
,
672 u32 base
, u32 size
, u32 other_bits
)
674 u32 val
, base_reg
, size_reg
, base_bits
, size_bits
;
675 u32 (*map_to_field
)(u32 val
, u32 num_bits
);
677 pr_debug("set 32bit window: %d, base: 0x%x, size: 0x%x, other: 0x%x\n",
678 window
, base
, size
, other_bits
);
680 base_reg
= bh
->ci
->window_tab_32bit
[window
].base_reg
;
683 size_reg
= bh
->ci
->window_tab_32bit
[window
].size_reg
;
684 base_bits
= bh
->ci
->window_tab_32bit
[window
].base_bits
;
685 size_bits
= bh
->ci
->window_tab_32bit
[window
].size_bits
;
686 map_to_field
= bh
->ci
->window_tab_32bit
[window
].map_to_field
;
688 val
= map_to_field(base
, base_bits
) | other_bits
;
689 mv64x60_write(bh
, base_reg
, val
);
692 val
= bh
->ci
->translate_size(base
, size
, size_bits
);
693 val
= map_to_field(val
, size_bits
);
694 mv64x60_write(bh
, size_reg
, val
);
697 (void)mv64x60_read(bh
, base_reg
); /* Flush FIFO */
702 * mv64x60_get_64bit_window()
704 * Determine the base address and size of a 64-bit window on the bridge.
707 mv64x60_get_64bit_window(struct mv64x60_handle
*bh
, u32 window
,
708 u32
*base_hi
, u32
*base_lo
, u32
*size
)
710 u32 val
, base_lo_reg
, size_reg
, base_lo_bits
, size_bits
;
711 u32 (*get_from_field
)(u32 val
, u32 num_bits
);
713 base_lo_reg
= bh
->ci
->window_tab_64bit
[window
].base_lo_reg
;
715 if (base_lo_reg
!= 0) {
716 size_reg
= bh
->ci
->window_tab_64bit
[window
].size_reg
;
717 base_lo_bits
= bh
->ci
->window_tab_64bit
[window
].base_lo_bits
;
718 size_bits
= bh
->ci
->window_tab_64bit
[window
].size_bits
;
719 get_from_field
= bh
->ci
->window_tab_64bit
[window
].get_from_field
;
721 *base_hi
= mv64x60_read(bh
,
722 bh
->ci
->window_tab_64bit
[window
].base_hi_reg
);
724 val
= mv64x60_read(bh
, base_lo_reg
);
725 *base_lo
= get_from_field(val
, base_lo_bits
);
728 val
= mv64x60_read(bh
, size_reg
);
729 val
= get_from_field(val
, size_bits
);
730 *size
= bh
->ci
->untranslate_size(*base_lo
, val
,
740 pr_debug("get 64bit window: %d, base hi: 0x%x, base lo: 0x%x, "
741 "size: 0x%x\n", window
, *base_hi
, *base_lo
, *size
);
745 * mv64x60_set_64bit_window()
747 * Set the base address and size of a 64-bit window on the bridge.
750 mv64x60_set_64bit_window(struct mv64x60_handle
*bh
, u32 window
,
751 u32 base_hi
, u32 base_lo
, u32 size
, u32 other_bits
)
753 u32 val
, base_lo_reg
, size_reg
, base_lo_bits
, size_bits
;
754 u32 (*map_to_field
)(u32 val
, u32 num_bits
);
756 pr_debug("set 64bit window: %d, base hi: 0x%x, base lo: 0x%x, "
757 "size: 0x%x, other: 0x%x\n",
758 window
, base_hi
, base_lo
, size
, other_bits
);
760 base_lo_reg
= bh
->ci
->window_tab_64bit
[window
].base_lo_reg
;
762 if (base_lo_reg
!= 0) {
763 size_reg
= bh
->ci
->window_tab_64bit
[window
].size_reg
;
764 base_lo_bits
= bh
->ci
->window_tab_64bit
[window
].base_lo_bits
;
765 size_bits
= bh
->ci
->window_tab_64bit
[window
].size_bits
;
766 map_to_field
= bh
->ci
->window_tab_64bit
[window
].map_to_field
;
768 mv64x60_write(bh
, bh
->ci
->window_tab_64bit
[window
].base_hi_reg
,
771 val
= map_to_field(base_lo
, base_lo_bits
) | other_bits
;
772 mv64x60_write(bh
, base_lo_reg
, val
);
775 val
= bh
->ci
->translate_size(base_lo
, size
, size_bits
);
776 val
= map_to_field(val
, size_bits
);
777 mv64x60_write(bh
, size_reg
, val
);
780 (void)mv64x60_read(bh
, base_lo_reg
); /* Flush FIFO */
787 * Take the high-order 'num_bits' of 'val' & mask off low bits.
790 mv64x60_mask(u32 val
, u32 num_bits
)
792 return val
& (0xffffffff << (32 - num_bits
));
796 * mv64x60_shift_left()
798 * Take the low-order 'num_bits' of 'val', shift left to align at bit 31 (MSB).
801 mv64x60_shift_left(u32 val
, u32 num_bits
)
803 return val
<< (32 - num_bits
);
807 * mv64x60_shift_right()
809 * Take the high-order 'num_bits' of 'val', shift right to align at bit 0 (LSB).
812 mv64x60_shift_right(u32 val
, u32 num_bits
)
814 return val
>> (32 - num_bits
);
818 *****************************************************************************
820 * Chip Identification Routines
822 *****************************************************************************
827 * Determine the type of bridge chip we have.
830 mv64x60_get_type(struct mv64x60_handle
*bh
)
832 struct pci_controller hose
;
836 memset(&hose
, 0, sizeof(hose
));
837 setup_indirect_pci_nomap(&hose
, bh
->v_base
+ MV64x60_PCI0_CONFIG_ADDR
,
838 bh
->v_base
+ MV64x60_PCI0_CONFIG_DATA
);
840 save_exclude
= mv64x60_pci_exclude_bridge
;
841 mv64x60_pci_exclude_bridge
= 0;
842 /* Sanity check of bridge's Vendor ID */
843 early_read_config_word(&hose
, 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID
, &val
);
845 if (val
!= PCI_VENDOR_ID_MARVELL
) {
846 mv64x60_pci_exclude_bridge
= save_exclude
;
850 /* Get the revision of the chip */
851 early_read_config_word(&hose
, 0, PCI_DEVFN(0, 0), PCI_CLASS_REVISION
,
853 bh
->rev
= (u32
)(val
& 0xff);
855 /* Figure out the type of Marvell bridge it is */
856 early_read_config_word(&hose
, 0, PCI_DEVFN(0, 0), PCI_DEVICE_ID
, &val
);
857 mv64x60_pci_exclude_bridge
= save_exclude
;
860 case PCI_DEVICE_ID_MARVELL_GT64260
:
863 bh
->type
= MV64x60_TYPE_GT64260A
;
867 printk(KERN_WARNING
"Unsupported GT64260 rev %04x\n",
869 /* Assume its similar to a 'B' rev and fallthru */
871 bh
->type
= MV64x60_TYPE_GT64260B
;
876 case PCI_DEVICE_ID_MARVELL_MV64360
:
877 /* Marvell won't tell me how to distinguish a 64361 & 64362 */
878 bh
->type
= MV64x60_TYPE_MV64360
;
881 case PCI_DEVICE_ID_MARVELL_MV64460
:
882 bh
->type
= MV64x60_TYPE_MV64460
;
886 printk(KERN_ERR
"Unknown Marvell bridge type %04x\n", val
);
890 /* Hang onto bridge type & rev for PIC code */
891 mv64x60_bridge_type
= bh
->type
;
892 mv64x60_bridge_rev
= bh
->rev
;
898 * mv64x60_setup_for_chip()
900 * Set 'bh' to use the proper set of routine for the bridge chip that we have.
903 mv64x60_setup_for_chip(struct mv64x60_handle
*bh
)
907 /* Set up chip-specific info based on the chip/bridge type */
909 case MV64x60_TYPE_GT64260A
:
910 bh
->ci
= >64260a_ci
;
913 case MV64x60_TYPE_GT64260B
:
914 bh
->ci
= >64260b_ci
;
917 case MV64x60_TYPE_MV64360
:
918 bh
->ci
= &mv64360_ci
;
921 case MV64x60_TYPE_MV64460
:
922 bh
->ci
= &mv64460_ci
;
925 case MV64x60_TYPE_INVALID
:
928 ppc_md
.progress("mv64x60: Unsupported bridge", 0x0);
929 printk(KERN_ERR
"mv64x60: Unsupported bridge\n");
937 * mv64x60_get_bridge_vbase()
939 * Return the virtual address of the bridge's registers.
942 mv64x60_get_bridge_vbase(void)
944 return mv64x60_bridge_vbase
;
948 * mv64x60_get_bridge_type()
950 * Return the type of bridge on the platform.
953 mv64x60_get_bridge_type(void)
955 return mv64x60_bridge_type
;
959 * mv64x60_get_bridge_rev()
961 * Return the revision of the bridge on the platform.
964 mv64x60_get_bridge_rev(void)
966 return mv64x60_bridge_rev
;
970 *****************************************************************************
972 * System Memory Window Related Routines
974 *****************************************************************************
977 * mv64x60_get_mem_size()
979 * Calculate the amount of memory that the memory controller is set up for.
980 * This should only be used by board-specific code if there is no other
981 * way to determine the amount of memory in the system.
984 mv64x60_get_mem_size(u32 bridge_base
, u32 chip_type
)
986 struct mv64x60_handle bh
;
987 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2];
990 memset(&bh
, 0, sizeof(bh
));
993 bh
.v_base
= (void *)bridge_base
;
995 if (!mv64x60_setup_for_chip(&bh
)) {
996 mv64x60_get_mem_windows(&bh
, mem_windows
);
997 rc
= mv64x60_calc_mem_size(&bh
, mem_windows
);
1004 * mv64x60_get_mem_windows()
1006 * Get the values in the memory controller & return in the 'mem_windows' array.
1009 mv64x60_get_mem_windows(struct mv64x60_handle
*bh
,
1010 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2])
1014 for (win
=MV64x60_CPU2MEM_0_WIN
,i
=0;win
<=MV64x60_CPU2MEM_3_WIN
;win
++,i
++)
1015 if (bh
->ci
->is_enabled_32bit(bh
, win
))
1016 mv64x60_get_32bit_window(bh
, win
,
1017 &mem_windows
[i
][0], &mem_windows
[i
][1]);
1019 mem_windows
[i
][0] = 0;
1020 mem_windows
[i
][1] = 0;
1025 * mv64x60_calc_mem_size()
1027 * Using the memory controller register values in 'mem_windows', determine
1028 * how much memory it is set up for.
1031 mv64x60_calc_mem_size(struct mv64x60_handle
*bh
,
1032 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2])
1036 for (i
=0; i
<MV64x60_CPU2MEM_WINDOWS
; i
++)
1037 total
+= mem_windows
[i
][1];
1043 *****************************************************************************
1045 * CPU->System MEM, PCI Config Routines
1047 *****************************************************************************
1050 * mv64x60_config_cpu2mem_windows()
1052 * Configure CPU->Memory windows on the bridge.
1054 static u32 prot_tab
[] __initdata
= {
1055 MV64x60_CPU_PROT_0_WIN
, MV64x60_CPU_PROT_1_WIN
,
1056 MV64x60_CPU_PROT_2_WIN
, MV64x60_CPU_PROT_3_WIN
1059 static u32 cpu_snoop_tab
[] __initdata
= {
1060 MV64x60_CPU_SNOOP_0_WIN
, MV64x60_CPU_SNOOP_1_WIN
,
1061 MV64x60_CPU_SNOOP_2_WIN
, MV64x60_CPU_SNOOP_3_WIN
1065 mv64x60_config_cpu2mem_windows(struct mv64x60_handle
*bh
,
1066 struct mv64x60_setup_info
*si
,
1067 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2])
1071 /* Set CPU protection & snoop windows */
1072 for (win
=MV64x60_CPU2MEM_0_WIN
,i
=0;win
<=MV64x60_CPU2MEM_3_WIN
;win
++,i
++)
1073 if (bh
->ci
->is_enabled_32bit(bh
, win
)) {
1074 mv64x60_set_32bit_window(bh
, prot_tab
[i
],
1075 mem_windows
[i
][0], mem_windows
[i
][1],
1076 si
->cpu_prot_options
[i
]);
1077 bh
->ci
->enable_window_32bit(bh
, prot_tab
[i
]);
1079 if (bh
->ci
->window_tab_32bit
[cpu_snoop_tab
[i
]].
1081 mv64x60_set_32bit_window(bh
, cpu_snoop_tab
[i
],
1082 mem_windows
[i
][0], mem_windows
[i
][1],
1083 si
->cpu_snoop_options
[i
]);
1084 bh
->ci
->enable_window_32bit(bh
,
1092 * mv64x60_config_cpu2pci_windows()
1094 * Configure the CPU->PCI windows for one of the PCI buses.
1096 static u32 win_tab
[2][4] __initdata
= {
1097 { MV64x60_CPU2PCI0_IO_WIN
, MV64x60_CPU2PCI0_MEM_0_WIN
,
1098 MV64x60_CPU2PCI0_MEM_1_WIN
, MV64x60_CPU2PCI0_MEM_2_WIN
},
1099 { MV64x60_CPU2PCI1_IO_WIN
, MV64x60_CPU2PCI1_MEM_0_WIN
,
1100 MV64x60_CPU2PCI1_MEM_1_WIN
, MV64x60_CPU2PCI1_MEM_2_WIN
},
1103 static u32 remap_tab
[2][4] __initdata
= {
1104 { MV64x60_CPU2PCI0_IO_REMAP_WIN
, MV64x60_CPU2PCI0_MEM_0_REMAP_WIN
,
1105 MV64x60_CPU2PCI0_MEM_1_REMAP_WIN
, MV64x60_CPU2PCI0_MEM_2_REMAP_WIN
},
1106 { MV64x60_CPU2PCI1_IO_REMAP_WIN
, MV64x60_CPU2PCI1_MEM_0_REMAP_WIN
,
1107 MV64x60_CPU2PCI1_MEM_1_REMAP_WIN
, MV64x60_CPU2PCI1_MEM_2_REMAP_WIN
}
1111 mv64x60_config_cpu2pci_windows(struct mv64x60_handle
*bh
,
1112 struct mv64x60_pci_info
*pi
, u32 bus
)
1116 if (pi
->pci_io
.size
> 0) {
1117 mv64x60_set_32bit_window(bh
, win_tab
[bus
][0],
1118 pi
->pci_io
.cpu_base
, pi
->pci_io
.size
, pi
->pci_io
.swap
);
1119 mv64x60_set_32bit_window(bh
, remap_tab
[bus
][0],
1120 pi
->pci_io
.pci_base_lo
, 0, 0);
1121 bh
->ci
->enable_window_32bit(bh
, win_tab
[bus
][0]);
1122 } else /* Actually, the window should already be disabled */
1123 bh
->ci
->disable_window_32bit(bh
, win_tab
[bus
][0]);
1126 if (pi
->pci_mem
[i
].size
> 0) {
1127 mv64x60_set_32bit_window(bh
, win_tab
[bus
][i
+1],
1128 pi
->pci_mem
[i
].cpu_base
, pi
->pci_mem
[i
].size
,
1129 pi
->pci_mem
[i
].swap
);
1130 mv64x60_set_64bit_window(bh
, remap_tab
[bus
][i
+1],
1131 pi
->pci_mem
[i
].pci_base_hi
,
1132 pi
->pci_mem
[i
].pci_base_lo
, 0, 0);
1133 bh
->ci
->enable_window_32bit(bh
, win_tab
[bus
][i
+1]);
1134 } else /* Actually, the window should already be disabled */
1135 bh
->ci
->disable_window_32bit(bh
, win_tab
[bus
][i
+1]);
1139 *****************************************************************************
1141 * PCI->System MEM Config Routines
1143 *****************************************************************************
1146 * mv64x60_config_pci2mem_windows()
1148 * Configure the PCI->Memory windows on the bridge.
1150 static u32 pci_acc_tab
[2][4] __initdata
= {
1151 { MV64x60_PCI02MEM_ACC_CNTL_0_WIN
, MV64x60_PCI02MEM_ACC_CNTL_1_WIN
,
1152 MV64x60_PCI02MEM_ACC_CNTL_2_WIN
, MV64x60_PCI02MEM_ACC_CNTL_3_WIN
},
1153 { MV64x60_PCI12MEM_ACC_CNTL_0_WIN
, MV64x60_PCI12MEM_ACC_CNTL_1_WIN
,
1154 MV64x60_PCI12MEM_ACC_CNTL_2_WIN
, MV64x60_PCI12MEM_ACC_CNTL_3_WIN
}
1157 static u32 pci_snoop_tab
[2][4] __initdata
= {
1158 { MV64x60_PCI02MEM_SNOOP_0_WIN
, MV64x60_PCI02MEM_SNOOP_1_WIN
,
1159 MV64x60_PCI02MEM_SNOOP_2_WIN
, MV64x60_PCI02MEM_SNOOP_3_WIN
},
1160 { MV64x60_PCI12MEM_SNOOP_0_WIN
, MV64x60_PCI12MEM_SNOOP_1_WIN
,
1161 MV64x60_PCI12MEM_SNOOP_2_WIN
, MV64x60_PCI12MEM_SNOOP_3_WIN
}
1164 static u32 pci_size_tab
[2][4] __initdata
= {
1165 { MV64x60_PCI0_MEM_0_SIZE
, MV64x60_PCI0_MEM_1_SIZE
,
1166 MV64x60_PCI0_MEM_2_SIZE
, MV64x60_PCI0_MEM_3_SIZE
},
1167 { MV64x60_PCI1_MEM_0_SIZE
, MV64x60_PCI1_MEM_1_SIZE
,
1168 MV64x60_PCI1_MEM_2_SIZE
, MV64x60_PCI1_MEM_3_SIZE
}
1172 mv64x60_config_pci2mem_windows(struct mv64x60_handle
*bh
,
1173 struct pci_controller
*hose
, struct mv64x60_pci_info
*pi
,
1174 u32 bus
, u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2])
1179 * Set the access control, snoop, BAR size, and window base addresses.
1180 * PCI->MEM windows base addresses will match exactly what the
1181 * CPU->MEM windows are.
1183 for (win
=MV64x60_CPU2MEM_0_WIN
,i
=0;win
<=MV64x60_CPU2MEM_3_WIN
;win
++,i
++)
1184 if (bh
->ci
->is_enabled_32bit(bh
, win
)) {
1185 mv64x60_set_64bit_window(bh
,
1186 pci_acc_tab
[bus
][i
], 0,
1187 mem_windows
[i
][0], mem_windows
[i
][1],
1188 pi
->acc_cntl_options
[i
]);
1189 bh
->ci
->enable_window_64bit(bh
, pci_acc_tab
[bus
][i
]);
1191 if (bh
->ci
->window_tab_64bit
[
1192 pci_snoop_tab
[bus
][i
]].base_lo_reg
!= 0) {
1194 mv64x60_set_64bit_window(bh
,
1195 pci_snoop_tab
[bus
][i
], 0,
1196 mem_windows
[i
][0], mem_windows
[i
][1],
1197 pi
->snoop_options
[i
]);
1198 bh
->ci
->enable_window_64bit(bh
,
1199 pci_snoop_tab
[bus
][i
]);
1202 bh
->ci
->set_pci2mem_window(hose
, bus
, i
,
1204 mv64x60_write(bh
, pci_size_tab
[bus
][i
],
1205 mv64x60_mask(mem_windows
[i
][1] - 1, 20));
1207 /* Enable the window */
1208 mv64x60_clr_bits(bh
, ((bus
== 0) ?
1209 MV64x60_PCI0_BAR_ENABLE
:
1210 MV64x60_PCI1_BAR_ENABLE
), (1 << i
));
1215 *****************************************************************************
1217 * Hose & Resource Alloc/Init Routines
1219 *****************************************************************************
1222 * mv64x60_alloc_hoses()
1224 * Allocate the PCI hose structures for the bridge's PCI buses.
1227 mv64x60_alloc_hose(struct mv64x60_handle
*bh
, u32 cfg_addr
, u32 cfg_data
,
1228 struct pci_controller
**hose
)
1230 *hose
= pcibios_alloc_controller();
1231 setup_indirect_pci_nomap(*hose
, bh
->v_base
+ cfg_addr
,
1232 bh
->v_base
+ cfg_data
);
1236 * mv64x60_config_resources()
1238 * Calculate the offsets, etc. for the hose structures to reflect all of
1239 * the address remapping that happens as you go from CPU->PCI and PCI->MEM.
1242 mv64x60_config_resources(struct pci_controller
*hose
,
1243 struct mv64x60_pci_info
*pi
, u32 io_base
)
1246 /* 2 hoses; 4 resources/hose; string <= 64 bytes */
1247 static char s
[2][4][64];
1249 if (pi
->pci_io
.size
!= 0) {
1250 sprintf(s
[hose
->index
][0], "PCI hose %d I/O Space",
1252 pci_init_resource(&hose
->io_resource
, io_base
- isa_io_base
,
1253 io_base
- isa_io_base
+ pi
->pci_io
.size
- 1,
1254 IORESOURCE_IO
, s
[hose
->index
][0]);
1255 hose
->io_space
.start
= pi
->pci_io
.pci_base_lo
;
1256 hose
->io_space
.end
= pi
->pci_io
.pci_base_lo
+ pi
->pci_io
.size
-1;
1257 hose
->io_base_phys
= pi
->pci_io
.cpu_base
;
1258 hose
->io_base_virt
= (void *)isa_io_base
;
1262 if (pi
->pci_mem
[i
].size
!= 0) {
1263 sprintf(s
[hose
->index
][i
+1], "PCI hose %d MEM Space %d",
1265 pci_init_resource(&hose
->mem_resources
[i
],
1266 pi
->pci_mem
[i
].cpu_base
,
1267 pi
->pci_mem
[i
].cpu_base
+ pi
->pci_mem
[i
].size
-1,
1268 IORESOURCE_MEM
, s
[hose
->index
][i
+1]);
1271 hose
->mem_space
.end
= pi
->pci_mem
[0].pci_base_lo
+
1272 pi
->pci_mem
[0].size
- 1;
1273 hose
->pci_mem_offset
= pi
->pci_mem
[0].cpu_base
-
1274 pi
->pci_mem
[0].pci_base_lo
;
1278 * mv64x60_config_pci_params()
1280 * Configure a hose's PCI config space parameters.
1283 mv64x60_config_pci_params(struct pci_controller
*hose
,
1284 struct mv64x60_pci_info
*pi
)
1290 devfn
= PCI_DEVFN(0,0);
1292 save_exclude
= mv64x60_pci_exclude_bridge
;
1293 mv64x60_pci_exclude_bridge
= 0;
1295 /* Set class code to indicate host bridge */
1296 u16_val
= PCI_CLASS_BRIDGE_HOST
; /* 0x0600 (host bridge) */
1297 early_write_config_word(hose
, 0, devfn
, PCI_CLASS_DEVICE
, u16_val
);
1299 /* Enable bridge to be PCI master & respond to PCI MEM cycles */
1300 early_read_config_word(hose
, 0, devfn
, PCI_COMMAND
, &u16_val
);
1301 u16_val
&= ~(PCI_COMMAND_IO
| PCI_COMMAND_INVALIDATE
|
1302 PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
| PCI_COMMAND_FAST_BACK
);
1303 u16_val
|= pi
->pci_cmd_bits
| PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
;
1304 early_write_config_word(hose
, 0, devfn
, PCI_COMMAND
, u16_val
);
1306 /* Set latency timer, cache line size, clear BIST */
1307 u16_val
= (pi
->latency_timer
<< 8) | (L1_CACHE_LINE_SIZE
>> 2);
1308 early_write_config_word(hose
, 0, devfn
, PCI_CACHE_LINE_SIZE
, u16_val
);
1310 mv64x60_pci_exclude_bridge
= save_exclude
;
1314 *****************************************************************************
1316 * PCI Related Routine
1318 *****************************************************************************
1323 * Set the bus number for the hose directly under the bridge.
1326 mv64x60_set_bus(struct mv64x60_handle
*bh
, u32 bus
, u32 child_bus
)
1328 struct pci_controller
*hose
;
1329 u32 pci_mode
, p2p_cfg
, pci_cfg_offset
, val
;
1333 pci_mode
= bh
->pci_mode_a
;
1334 p2p_cfg
= MV64x60_PCI0_P2P_CONFIG
;
1335 pci_cfg_offset
= 0x64;
1338 pci_mode
= bh
->pci_mode_b
;
1339 p2p_cfg
= MV64x60_PCI1_P2P_CONFIG
;
1340 pci_cfg_offset
= 0xe4;
1345 val
= mv64x60_read(bh
, p2p_cfg
);
1347 if (pci_mode
== MV64x60_PCIMODE_CONVENTIONAL
) {
1348 val
&= 0xe0000000; /* Force dev num to 0, turn off P2P bridge */
1349 val
|= (child_bus
<< 16) | 0xff;
1350 mv64x60_write(bh
, p2p_cfg
, val
);
1351 (void)mv64x60_read(bh
, p2p_cfg
); /* Flush FIFO */
1352 } else { /* PCI-X */
1354 * Need to use the current bus/dev number (that's in the
1355 * P2P CONFIG reg) to access the bridge's pci config space.
1357 save_exclude
= mv64x60_pci_exclude_bridge
;
1358 mv64x60_pci_exclude_bridge
= 0;
1359 early_write_config_dword(hose
, (val
& 0x00ff0000) >> 16,
1360 PCI_DEVFN(((val
& 0x1f000000) >> 24), 0),
1361 pci_cfg_offset
, child_bus
<< 8);
1362 mv64x60_pci_exclude_bridge
= save_exclude
;
1367 * mv64x60_pci_exclude_device()
1369 * This routine is used to make the bridge not appear when the
1370 * PCI subsystem is accessing PCI devices (in PCI config space).
1373 mv64x60_pci_exclude_device(u8 bus
, u8 devfn
)
1375 struct pci_controller
*hose
;
1377 hose
= pci_bus_to_hose(bus
);
1379 /* Skip slot 0 on both hoses */
1380 if ((mv64x60_pci_exclude_bridge
== 1) && (PCI_SLOT(devfn
) == 0) &&
1381 (hose
->first_busno
== bus
))
1383 return PCIBIOS_DEVICE_NOT_FOUND
;
1385 return PCIBIOS_SUCCESSFUL
;
1386 } /* mv64x60_pci_exclude_device() */
1389 *****************************************************************************
1391 * Platform Device Routines
1393 *****************************************************************************
1397 * mv64x60_pd_fixup()
1399 * Need to add the base addr of where the bridge's regs are mapped in the
1400 * physical addr space so drivers can ioremap() them.
1403 mv64x60_pd_fixup(struct mv64x60_handle
*bh
, struct platform_device
*pd_devs
[],
1409 for (i
=0; i
<entries
; i
++) {
1412 while ((r
= platform_get_resource(pd_devs
[i
],IORESOURCE_MEM
,j
))
1415 r
->start
+= bh
->p_base
;
1416 r
->end
+= bh
->p_base
;
1425 * Add the mv64x60 platform devices to the list of platform devices.
1428 mv64x60_add_pds(void)
1430 return platform_add_devices(mv64x60_pd_devs
,
1431 ARRAY_SIZE(mv64x60_pd_devs
));
1433 arch_initcall(mv64x60_add_pds
);
1436 *****************************************************************************
1438 * GT64260-Specific Routines
1440 *****************************************************************************
1443 * gt64260_translate_size()
1445 * On the GT64260, the size register is really the "top" address of the window.
1448 gt64260_translate_size(u32 base
, u32 size
, u32 num_bits
)
1450 return base
+ mv64x60_mask(size
- 1, num_bits
);
1454 * gt64260_untranslate_size()
1456 * Translate the top address of a window into a window size.
1459 gt64260_untranslate_size(u32 base
, u32 size
, u32 num_bits
)
1462 size
= size
- base
+ (1 << (32 - num_bits
));
1470 * gt64260_set_pci2mem_window()
1472 * The PCI->MEM window registers are actually in PCI config space so need
1473 * to set them by setting the correct config space BARs.
1475 static u32 gt64260_reg_addrs
[2][4] __initdata
= {
1476 { 0x10, 0x14, 0x18, 0x1c }, { 0x90, 0x94, 0x98, 0x9c }
1480 gt64260_set_pci2mem_window(struct pci_controller
*hose
, u32 bus
, u32 window
,
1485 pr_debug("set pci->mem window: %d, hose: %d, base: 0x%x\n", window
,
1488 save_exclude
= mv64x60_pci_exclude_bridge
;
1489 mv64x60_pci_exclude_bridge
= 0;
1490 early_write_config_dword(hose
, 0, PCI_DEVFN(0, 0),
1491 gt64260_reg_addrs
[bus
][window
], mv64x60_mask(base
, 20) | 0x8);
1492 mv64x60_pci_exclude_bridge
= save_exclude
;
1496 * gt64260_set_pci2regs_window()
1498 * Set where the bridge's registers appear in PCI MEM space.
1500 static u32 gt64260_offset
[2] __initdata
= {0x20, 0xa0};
1503 gt64260_set_pci2regs_window(struct mv64x60_handle
*bh
,
1504 struct pci_controller
*hose
, u32 bus
, u32 base
)
1508 pr_debug("set pci->internal regs hose: %d, base: 0x%x\n", hose
->index
,
1511 save_exclude
= mv64x60_pci_exclude_bridge
;
1512 mv64x60_pci_exclude_bridge
= 0;
1513 early_write_config_dword(hose
, 0, PCI_DEVFN(0,0), gt64260_offset
[bus
],
1515 mv64x60_pci_exclude_bridge
= save_exclude
;
1519 * gt64260_is_enabled_32bit()
1521 * On a GT64260, a window is enabled iff its top address is >= to its base
1525 gt64260_is_enabled_32bit(struct mv64x60_handle
*bh
, u32 window
)
1529 if ((gt64260_32bit_windows
[window
].base_reg
!= 0) &&
1530 (gt64260_32bit_windows
[window
].size_reg
!= 0) &&
1531 ((mv64x60_read(bh
, gt64260_32bit_windows
[window
].size_reg
) &
1532 ((1 << gt64260_32bit_windows
[window
].size_bits
) - 1)) >=
1533 (mv64x60_read(bh
, gt64260_32bit_windows
[window
].base_reg
) &
1534 ((1 << gt64260_32bit_windows
[window
].base_bits
) - 1))))
1542 * gt64260_enable_window_32bit()
1544 * On the GT64260, a window is enabled iff the top address is >= to the base
1545 * address of the window. Since the window has already been configured by
1546 * the time this routine is called, we have nothing to do here.
1549 gt64260_enable_window_32bit(struct mv64x60_handle
*bh
, u32 window
)
1551 pr_debug("enable 32bit window: %d\n", window
);
1555 * gt64260_disable_window_32bit()
1557 * On a GT64260, you disable a window by setting its top address to be less
1558 * than its base address.
1561 gt64260_disable_window_32bit(struct mv64x60_handle
*bh
, u32 window
)
1563 pr_debug("disable 32bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
1564 window
, gt64260_32bit_windows
[window
].base_reg
,
1565 gt64260_32bit_windows
[window
].size_reg
);
1567 if ((gt64260_32bit_windows
[window
].base_reg
!= 0) &&
1568 (gt64260_32bit_windows
[window
].size_reg
!= 0)) {
1570 /* To disable, make bottom reg higher than top reg */
1571 mv64x60_write(bh
, gt64260_32bit_windows
[window
].base_reg
,0xfff);
1572 mv64x60_write(bh
, gt64260_32bit_windows
[window
].size_reg
, 0);
1577 * gt64260_enable_window_64bit()
1579 * On the GT64260, a window is enabled iff the top address is >= to the base
1580 * address of the window. Since the window has already been configured by
1581 * the time this routine is called, we have nothing to do here.
1584 gt64260_enable_window_64bit(struct mv64x60_handle
*bh
, u32 window
)
1586 pr_debug("enable 64bit window: %d\n", window
);
1590 * gt64260_disable_window_64bit()
1592 * On a GT64260, you disable a window by setting its top address to be less
1593 * than its base address.
1596 gt64260_disable_window_64bit(struct mv64x60_handle
*bh
, u32 window
)
1598 pr_debug("disable 64bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
1599 window
, gt64260_64bit_windows
[window
].base_lo_reg
,
1600 gt64260_64bit_windows
[window
].size_reg
);
1602 if ((gt64260_64bit_windows
[window
].base_lo_reg
!= 0) &&
1603 (gt64260_64bit_windows
[window
].size_reg
!= 0)) {
1605 /* To disable, make bottom reg higher than top reg */
1606 mv64x60_write(bh
, gt64260_64bit_windows
[window
].base_lo_reg
,
1608 mv64x60_write(bh
, gt64260_64bit_windows
[window
].base_hi_reg
, 0);
1609 mv64x60_write(bh
, gt64260_64bit_windows
[window
].size_reg
, 0);
1614 * gt64260_disable_all_windows()
1616 * The GT64260 has several windows that aren't represented in the table of
1617 * windows at the top of this file. This routine turns all of them off
1618 * except for the memory controller windows, of course.
1621 gt64260_disable_all_windows(struct mv64x60_handle
*bh
,
1622 struct mv64x60_setup_info
*si
)
1626 /* Disable 32bit windows (don't disable cpu->mem windows) */
1627 for (i
=MV64x60_CPU2DEV_0_WIN
; i
<MV64x60_32BIT_WIN_COUNT
; i
++) {
1629 preserve
= si
->window_preserve_mask_32_lo
& (1 << i
);
1631 preserve
= si
->window_preserve_mask_32_hi
& (1<<(i
-32));
1634 gt64260_disable_window_32bit(bh
, i
);
1637 /* Disable 64bit windows */
1638 for (i
=0; i
<MV64x60_64BIT_WIN_COUNT
; i
++)
1639 if (!(si
->window_preserve_mask_64
& (1<<i
)))
1640 gt64260_disable_window_64bit(bh
, i
);
1642 /* Turn off cpu protection windows not in gt64260_32bit_windows[] */
1643 mv64x60_write(bh
, GT64260_CPU_PROT_BASE_4
, 0xfff);
1644 mv64x60_write(bh
, GT64260_CPU_PROT_SIZE_4
, 0);
1645 mv64x60_write(bh
, GT64260_CPU_PROT_BASE_5
, 0xfff);
1646 mv64x60_write(bh
, GT64260_CPU_PROT_SIZE_5
, 0);
1647 mv64x60_write(bh
, GT64260_CPU_PROT_BASE_6
, 0xfff);
1648 mv64x60_write(bh
, GT64260_CPU_PROT_SIZE_6
, 0);
1649 mv64x60_write(bh
, GT64260_CPU_PROT_BASE_7
, 0xfff);
1650 mv64x60_write(bh
, GT64260_CPU_PROT_SIZE_7
, 0);
1652 /* Turn off PCI->MEM access cntl wins not in gt64260_64bit_windows[] */
1653 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_4_BASE_LO
, 0xfff);
1654 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_4_BASE_HI
, 0);
1655 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_4_SIZE
, 0);
1656 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_5_BASE_LO
, 0xfff);
1657 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_5_BASE_HI
, 0);
1658 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_5_SIZE
, 0);
1659 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_6_BASE_LO
, 0xfff);
1660 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_6_BASE_HI
, 0);
1661 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_6_SIZE
, 0);
1662 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_7_BASE_LO
, 0xfff);
1663 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_7_BASE_HI
, 0);
1664 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_7_SIZE
, 0);
1666 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_4_BASE_LO
, 0xfff);
1667 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_4_BASE_HI
, 0);
1668 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_4_SIZE
, 0);
1669 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_5_BASE_LO
, 0xfff);
1670 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_5_BASE_HI
, 0);
1671 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_5_SIZE
, 0);
1672 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_6_BASE_LO
, 0xfff);
1673 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_6_BASE_HI
, 0);
1674 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_6_SIZE
, 0);
1675 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_7_BASE_LO
, 0xfff);
1676 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_7_BASE_HI
, 0);
1677 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_7_SIZE
, 0);
1679 /* Disable all PCI-><whatever> windows */
1680 mv64x60_set_bits(bh
, MV64x60_PCI0_BAR_ENABLE
, 0x07fffdff);
1681 mv64x60_set_bits(bh
, MV64x60_PCI1_BAR_ENABLE
, 0x07fffdff);
1684 * Some firmwares enable a bunch of intr sources
1685 * for the PCI INT output pins.
1687 mv64x60_write(bh
, GT64260_IC_CPU_INTR_MASK_LO
, 0);
1688 mv64x60_write(bh
, GT64260_IC_CPU_INTR_MASK_HI
, 0);
1689 mv64x60_write(bh
, GT64260_IC_PCI0_INTR_MASK_LO
, 0);
1690 mv64x60_write(bh
, GT64260_IC_PCI0_INTR_MASK_HI
, 0);
1691 mv64x60_write(bh
, GT64260_IC_PCI1_INTR_MASK_LO
, 0);
1692 mv64x60_write(bh
, GT64260_IC_PCI1_INTR_MASK_HI
, 0);
1693 mv64x60_write(bh
, GT64260_IC_CPU_INT_0_MASK
, 0);
1694 mv64x60_write(bh
, GT64260_IC_CPU_INT_1_MASK
, 0);
1695 mv64x60_write(bh
, GT64260_IC_CPU_INT_2_MASK
, 0);
1696 mv64x60_write(bh
, GT64260_IC_CPU_INT_3_MASK
, 0);
1700 * gt64260a_chip_specific_init()
1702 * Implement errata work arounds for the GT64260A.
1705 gt64260a_chip_specific_init(struct mv64x60_handle
*bh
,
1706 struct mv64x60_setup_info
*si
)
1708 #ifdef CONFIG_SERIAL_MPSC
1711 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1716 if (si
->pci_0
.enable_bus
)
1717 mv64x60_set_bits(bh
, MV64x60_PCI0_CMD
,
1718 ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
1720 if (si
->pci_1
.enable_bus
)
1721 mv64x60_set_bits(bh
, MV64x60_PCI1_CMD
,
1722 ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
1725 * Dave Wilhardt found that bit 4 in the PCI Command registers must
1726 * be set if you are using cache coherency.
1728 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1729 /* Res #MEM-4 -- cpu read buffer to buffer 1 */
1730 if ((mv64x60_read(bh
, MV64x60_CPU_MODE
) & 0xf0) == 0x40)
1731 mv64x60_set_bits(bh
, GT64260_SDRAM_CONFIG
, (1<<26));
1733 save_exclude
= mv64x60_pci_exclude_bridge
;
1734 mv64x60_pci_exclude_bridge
= 0;
1735 if (si
->pci_0
.enable_bus
) {
1736 early_read_config_dword(bh
->hose_a
, 0, PCI_DEVFN(0,0),
1738 val
|= PCI_COMMAND_INVALIDATE
;
1739 early_write_config_dword(bh
->hose_a
, 0, PCI_DEVFN(0,0),
1743 if (si
->pci_1
.enable_bus
) {
1744 early_read_config_dword(bh
->hose_b
, 0, PCI_DEVFN(0,0),
1746 val
|= PCI_COMMAND_INVALIDATE
;
1747 early_write_config_dword(bh
->hose_b
, 0, PCI_DEVFN(0,0),
1750 mv64x60_pci_exclude_bridge
= save_exclude
;
1753 /* Disable buffer/descriptor snooping */
1754 mv64x60_clr_bits(bh
, 0xf280, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
1755 mv64x60_clr_bits(bh
, 0xf2c0, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
1757 #ifdef CONFIG_SERIAL_MPSC
1758 mv64x60_mpsc0_pdata
.mirror_regs
= 1;
1759 mv64x60_mpsc0_pdata
.cache_mgmt
= 1;
1760 mv64x60_mpsc1_pdata
.mirror_regs
= 1;
1761 mv64x60_mpsc1_pdata
.cache_mgmt
= 1;
1763 if ((r
= platform_get_resource(&mpsc1_device
, IORESOURCE_IRQ
, 0))
1765 r
->start
= MV64x60_IRQ_SDMA_0
;
1766 r
->end
= MV64x60_IRQ_SDMA_0
;
1772 * gt64260b_chip_specific_init()
1774 * Implement errata work arounds for the GT64260B.
1777 gt64260b_chip_specific_init(struct mv64x60_handle
*bh
,
1778 struct mv64x60_setup_info
*si
)
1780 #ifdef CONFIG_SERIAL_MPSC
1783 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1788 if (si
->pci_0
.enable_bus
)
1789 mv64x60_set_bits(bh
, MV64x60_PCI0_CMD
,
1790 ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
1792 if (si
->pci_1
.enable_bus
)
1793 mv64x60_set_bits(bh
, MV64x60_PCI1_CMD
,
1794 ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
1797 * Dave Wilhardt found that bit 4 in the PCI Command registers must
1798 * be set if you are using cache coherency.
1800 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1801 mv64x60_set_bits(bh
, GT64260_CPU_WB_PRIORITY_BUFFER_DEPTH
, 0xf);
1803 /* Res #MEM-4 -- cpu read buffer to buffer 1 */
1804 if ((mv64x60_read(bh
, MV64x60_CPU_MODE
) & 0xf0) == 0x40)
1805 mv64x60_set_bits(bh
, GT64260_SDRAM_CONFIG
, (1<<26));
1807 save_exclude
= mv64x60_pci_exclude_bridge
;
1808 mv64x60_pci_exclude_bridge
= 0;
1809 if (si
->pci_0
.enable_bus
) {
1810 early_read_config_dword(bh
->hose_a
, 0, PCI_DEVFN(0,0),
1812 val
|= PCI_COMMAND_INVALIDATE
;
1813 early_write_config_dword(bh
->hose_a
, 0, PCI_DEVFN(0,0),
1817 if (si
->pci_1
.enable_bus
) {
1818 early_read_config_dword(bh
->hose_b
, 0, PCI_DEVFN(0,0),
1820 val
|= PCI_COMMAND_INVALIDATE
;
1821 early_write_config_dword(bh
->hose_b
, 0, PCI_DEVFN(0,0),
1824 mv64x60_pci_exclude_bridge
= save_exclude
;
1827 /* Disable buffer/descriptor snooping */
1828 mv64x60_clr_bits(bh
, 0xf280, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
1829 mv64x60_clr_bits(bh
, 0xf2c0, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
1831 #ifdef CONFIG_SERIAL_MPSC
1833 * The 64260B is not supposed to have the bug where the MPSC & ENET
1834 * can't access cache coherent regions. However, testing has shown
1835 * that the MPSC, at least, still has this bug.
1837 mv64x60_mpsc0_pdata
.cache_mgmt
= 1;
1838 mv64x60_mpsc1_pdata
.cache_mgmt
= 1;
1840 if ((r
= platform_get_resource(&mpsc1_device
, IORESOURCE_IRQ
, 0))
1842 r
->start
= MV64x60_IRQ_SDMA_0
;
1843 r
->end
= MV64x60_IRQ_SDMA_0
;
1849 *****************************************************************************
1851 * MV64360-Specific Routines
1853 *****************************************************************************
1856 * mv64360_translate_size()
1858 * On the MV64360, the size register is set similar to the size you get
1859 * from a pci config space BAR register. That is, programmed from LSB to MSB
1860 * as a sequence of 1's followed by a sequence of 0's. IOW, "size -1" with the
1861 * assumption that the size is a power of 2.
1864 mv64360_translate_size(u32 base_addr
, u32 size
, u32 num_bits
)
1866 return mv64x60_mask(size
- 1, num_bits
);
1870 * mv64360_untranslate_size()
1872 * Translate the size register value of a window into a window size.
1875 mv64360_untranslate_size(u32 base_addr
, u32 size
, u32 num_bits
)
1878 size
>>= (32 - num_bits
);
1880 size
<<= (32 - num_bits
);
1887 * mv64360_set_pci2mem_window()
1889 * The PCI->MEM window registers are actually in PCI config space so need
1890 * to set them by setting the correct config space BARs.
1896 } static mv64360_reg_addrs
[2][4] __initdata
= {
1897 {{ 0, 0x14, 0x10 }, { 0, 0x1c, 0x18 },
1898 { 1, 0x14, 0x10 }, { 1, 0x1c, 0x18 }},
1899 {{ 0, 0x94, 0x90 }, { 0, 0x9c, 0x98 },
1900 { 1, 0x94, 0x90 }, { 1, 0x9c, 0x98 }}
1904 mv64360_set_pci2mem_window(struct pci_controller
*hose
, u32 bus
, u32 window
,
1909 pr_debug("set pci->mem window: %d, hose: %d, base: 0x%x\n", window
,
1912 save_exclude
= mv64x60_pci_exclude_bridge
;
1913 mv64x60_pci_exclude_bridge
= 0;
1914 early_write_config_dword(hose
, 0,
1915 PCI_DEVFN(0, mv64360_reg_addrs
[bus
][window
].fcn
),
1916 mv64360_reg_addrs
[bus
][window
].base_hi_bar
, 0);
1917 early_write_config_dword(hose
, 0,
1918 PCI_DEVFN(0, mv64360_reg_addrs
[bus
][window
].fcn
),
1919 mv64360_reg_addrs
[bus
][window
].base_lo_bar
,
1920 mv64x60_mask(base
,20) | 0xc);
1921 mv64x60_pci_exclude_bridge
= save_exclude
;
1925 * mv64360_set_pci2regs_window()
1927 * Set where the bridge's registers appear in PCI MEM space.
1929 static u32 mv64360_offset
[2][2] __initdata
= {{0x20, 0x24}, {0xa0, 0xa4}};
1932 mv64360_set_pci2regs_window(struct mv64x60_handle
*bh
,
1933 struct pci_controller
*hose
, u32 bus
, u32 base
)
1937 pr_debug("set pci->internal regs hose: %d, base: 0x%x\n", hose
->index
,
1940 save_exclude
= mv64x60_pci_exclude_bridge
;
1941 mv64x60_pci_exclude_bridge
= 0;
1942 early_write_config_dword(hose
, 0, PCI_DEVFN(0,0),
1943 mv64360_offset
[bus
][0], (base
<< 16));
1944 early_write_config_dword(hose
, 0, PCI_DEVFN(0,0),
1945 mv64360_offset
[bus
][1], 0);
1946 mv64x60_pci_exclude_bridge
= save_exclude
;
1950 * mv64360_is_enabled_32bit()
1952 * On a MV64360, a window is enabled by either clearing a bit in the
1953 * CPU BAR Enable reg or setting a bit in the window's base reg.
1954 * Note that this doesn't work for windows on the PCI slave side but we don't
1955 * check those so its okay.
1958 mv64360_is_enabled_32bit(struct mv64x60_handle
*bh
, u32 window
)
1962 if (((mv64360_32bit_windows
[window
].base_reg
!= 0) &&
1963 (mv64360_32bit_windows
[window
].size_reg
!= 0)) ||
1964 (window
== MV64x60_CPU2SRAM_WIN
)) {
1966 extra
= mv64360_32bit_windows
[window
].extra
;
1968 switch (extra
& MV64x60_EXTRA_MASK
) {
1969 case MV64x60_EXTRA_CPUWIN_ENAB
:
1970 rc
= (mv64x60_read(bh
, MV64360_CPU_BAR_ENABLE
) &
1971 (1 << (extra
& 0x1f))) == 0;
1974 case MV64x60_EXTRA_CPUPROT_ENAB
:
1975 rc
= (mv64x60_read(bh
,
1976 mv64360_32bit_windows
[window
].base_reg
) &
1977 (1 << (extra
& 0x1f))) != 0;
1980 case MV64x60_EXTRA_ENET_ENAB
:
1981 rc
= (mv64x60_read(bh
, MV64360_ENET2MEM_BAR_ENABLE
) &
1982 (1 << (extra
& 0x7))) == 0;
1985 case MV64x60_EXTRA_MPSC_ENAB
:
1986 rc
= (mv64x60_read(bh
, MV64360_MPSC2MEM_BAR_ENABLE
) &
1987 (1 << (extra
& 0x3))) == 0;
1990 case MV64x60_EXTRA_IDMA_ENAB
:
1991 rc
= (mv64x60_read(bh
, MV64360_IDMA2MEM_BAR_ENABLE
) &
1992 (1 << (extra
& 0x7))) == 0;
1996 printk(KERN_ERR
"mv64360_is_enabled: %s\n",
1997 "32bit table corrupted");
2005 * mv64360_enable_window_32bit()
2007 * On a MV64360, a window is enabled by either clearing a bit in the
2008 * CPU BAR Enable reg or setting a bit in the window's base reg.
2011 mv64360_enable_window_32bit(struct mv64x60_handle
*bh
, u32 window
)
2015 pr_debug("enable 32bit window: %d\n", window
);
2017 if (((mv64360_32bit_windows
[window
].base_reg
!= 0) &&
2018 (mv64360_32bit_windows
[window
].size_reg
!= 0)) ||
2019 (window
== MV64x60_CPU2SRAM_WIN
)) {
2021 extra
= mv64360_32bit_windows
[window
].extra
;
2023 switch (extra
& MV64x60_EXTRA_MASK
) {
2024 case MV64x60_EXTRA_CPUWIN_ENAB
:
2025 mv64x60_clr_bits(bh
, MV64360_CPU_BAR_ENABLE
,
2026 (1 << (extra
& 0x1f)));
2029 case MV64x60_EXTRA_CPUPROT_ENAB
:
2030 mv64x60_set_bits(bh
,
2031 mv64360_32bit_windows
[window
].base_reg
,
2032 (1 << (extra
& 0x1f)));
2035 case MV64x60_EXTRA_ENET_ENAB
:
2036 mv64x60_clr_bits(bh
, MV64360_ENET2MEM_BAR_ENABLE
,
2037 (1 << (extra
& 0x7)));
2040 case MV64x60_EXTRA_MPSC_ENAB
:
2041 mv64x60_clr_bits(bh
, MV64360_MPSC2MEM_BAR_ENABLE
,
2042 (1 << (extra
& 0x3)));
2045 case MV64x60_EXTRA_IDMA_ENAB
:
2046 mv64x60_clr_bits(bh
, MV64360_IDMA2MEM_BAR_ENABLE
,
2047 (1 << (extra
& 0x7)));
2051 printk(KERN_ERR
"mv64360_enable: %s\n",
2052 "32bit table corrupted");
2058 * mv64360_disable_window_32bit()
2060 * On a MV64360, a window is disabled by either setting a bit in the
2061 * CPU BAR Enable reg or clearing a bit in the window's base reg.
2064 mv64360_disable_window_32bit(struct mv64x60_handle
*bh
, u32 window
)
2068 pr_debug("disable 32bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
2069 window
, mv64360_32bit_windows
[window
].base_reg
,
2070 mv64360_32bit_windows
[window
].size_reg
);
2072 if (((mv64360_32bit_windows
[window
].base_reg
!= 0) &&
2073 (mv64360_32bit_windows
[window
].size_reg
!= 0)) ||
2074 (window
== MV64x60_CPU2SRAM_WIN
)) {
2076 extra
= mv64360_32bit_windows
[window
].extra
;
2078 switch (extra
& MV64x60_EXTRA_MASK
) {
2079 case MV64x60_EXTRA_CPUWIN_ENAB
:
2080 mv64x60_set_bits(bh
, MV64360_CPU_BAR_ENABLE
,
2081 (1 << (extra
& 0x1f)));
2084 case MV64x60_EXTRA_CPUPROT_ENAB
:
2085 mv64x60_clr_bits(bh
,
2086 mv64360_32bit_windows
[window
].base_reg
,
2087 (1 << (extra
& 0x1f)));
2090 case MV64x60_EXTRA_ENET_ENAB
:
2091 mv64x60_set_bits(bh
, MV64360_ENET2MEM_BAR_ENABLE
,
2092 (1 << (extra
& 0x7)));
2095 case MV64x60_EXTRA_MPSC_ENAB
:
2096 mv64x60_set_bits(bh
, MV64360_MPSC2MEM_BAR_ENABLE
,
2097 (1 << (extra
& 0x3)));
2100 case MV64x60_EXTRA_IDMA_ENAB
:
2101 mv64x60_set_bits(bh
, MV64360_IDMA2MEM_BAR_ENABLE
,
2102 (1 << (extra
& 0x7)));
2106 printk(KERN_ERR
"mv64360_disable: %s\n",
2107 "32bit table corrupted");
2113 * mv64360_enable_window_64bit()
2115 * On the MV64360, a 64-bit window is enabled by setting a bit in the window's
2119 mv64360_enable_window_64bit(struct mv64x60_handle
*bh
, u32 window
)
2121 pr_debug("enable 64bit window: %d\n", window
);
2123 if ((mv64360_64bit_windows
[window
].base_lo_reg
!= 0) &&
2124 (mv64360_64bit_windows
[window
].size_reg
!= 0)) {
2126 if ((mv64360_64bit_windows
[window
].extra
& MV64x60_EXTRA_MASK
)
2127 == MV64x60_EXTRA_PCIACC_ENAB
)
2128 mv64x60_set_bits(bh
,
2129 mv64360_64bit_windows
[window
].base_lo_reg
,
2130 (1 << (mv64360_64bit_windows
[window
].extra
&
2133 printk(KERN_ERR
"mv64360_enable: %s\n",
2134 "64bit table corrupted");
2139 * mv64360_disable_window_64bit()
2141 * On a MV64360, a 64-bit window is disabled by clearing a bit in the window's
2145 mv64360_disable_window_64bit(struct mv64x60_handle
*bh
, u32 window
)
2147 pr_debug("disable 64bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
2148 window
, mv64360_64bit_windows
[window
].base_lo_reg
,
2149 mv64360_64bit_windows
[window
].size_reg
);
2151 if ((mv64360_64bit_windows
[window
].base_lo_reg
!= 0) &&
2152 (mv64360_64bit_windows
[window
].size_reg
!= 0)) {
2153 if ((mv64360_64bit_windows
[window
].extra
& MV64x60_EXTRA_MASK
)
2154 == MV64x60_EXTRA_PCIACC_ENAB
)
2155 mv64x60_clr_bits(bh
,
2156 mv64360_64bit_windows
[window
].base_lo_reg
,
2157 (1 << (mv64360_64bit_windows
[window
].extra
&
2160 printk(KERN_ERR
"mv64360_disable: %s\n",
2161 "64bit table corrupted");
2166 * mv64360_disable_all_windows()
2168 * The MV64360 has a few windows that aren't represented in the table of
2169 * windows at the top of this file. This routine turns all of them off
2170 * except for the memory controller windows, of course.
2173 mv64360_disable_all_windows(struct mv64x60_handle
*bh
,
2174 struct mv64x60_setup_info
*si
)
2178 /* Disable 32bit windows (don't disable cpu->mem windows) */
2179 for (i
=MV64x60_CPU2DEV_0_WIN
; i
<MV64x60_32BIT_WIN_COUNT
; i
++) {
2181 preserve
= si
->window_preserve_mask_32_lo
& (1 << i
);
2183 preserve
= si
->window_preserve_mask_32_hi
& (1<<(i
-32));
2186 mv64360_disable_window_32bit(bh
, i
);
2189 /* Disable 64bit windows */
2190 for (i
=0; i
<MV64x60_64BIT_WIN_COUNT
; i
++)
2191 if (!(si
->window_preserve_mask_64
& (1<<i
)))
2192 mv64360_disable_window_64bit(bh
, i
);
2194 /* Turn off PCI->MEM access cntl wins not in mv64360_64bit_windows[] */
2195 mv64x60_clr_bits(bh
, MV64x60_PCI0_ACC_CNTL_4_BASE_LO
, 0);
2196 mv64x60_clr_bits(bh
, MV64x60_PCI0_ACC_CNTL_5_BASE_LO
, 0);
2197 mv64x60_clr_bits(bh
, MV64x60_PCI1_ACC_CNTL_4_BASE_LO
, 0);
2198 mv64x60_clr_bits(bh
, MV64x60_PCI1_ACC_CNTL_5_BASE_LO
, 0);
2200 /* Disable all PCI-><whatever> windows */
2201 mv64x60_set_bits(bh
, MV64x60_PCI0_BAR_ENABLE
, 0x0000f9ff);
2202 mv64x60_set_bits(bh
, MV64x60_PCI1_BAR_ENABLE
, 0x0000f9ff);
2206 * mv64360_config_io2mem_windows()
2208 * ENET, MPSC, and IDMA ctlrs on the MV64[34]60 have separate windows that
2209 * must be set up so that the respective ctlr can access system memory.
2211 static u32 enet_tab
[MV64x60_CPU2MEM_WINDOWS
] __initdata
= {
2212 MV64x60_ENET2MEM_0_WIN
, MV64x60_ENET2MEM_1_WIN
,
2213 MV64x60_ENET2MEM_2_WIN
, MV64x60_ENET2MEM_3_WIN
,
2216 static u32 mpsc_tab
[MV64x60_CPU2MEM_WINDOWS
] __initdata
= {
2217 MV64x60_MPSC2MEM_0_WIN
, MV64x60_MPSC2MEM_1_WIN
,
2218 MV64x60_MPSC2MEM_2_WIN
, MV64x60_MPSC2MEM_3_WIN
,
2221 static u32 idma_tab
[MV64x60_CPU2MEM_WINDOWS
] __initdata
= {
2222 MV64x60_IDMA2MEM_0_WIN
, MV64x60_IDMA2MEM_1_WIN
,
2223 MV64x60_IDMA2MEM_2_WIN
, MV64x60_IDMA2MEM_3_WIN
,
2226 static u32 dram_selects
[MV64x60_CPU2MEM_WINDOWS
] __initdata
=
2227 { 0xe, 0xd, 0xb, 0x7 };
2230 mv64360_config_io2mem_windows(struct mv64x60_handle
*bh
,
2231 struct mv64x60_setup_info
*si
,
2232 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2])
2236 pr_debug("config_io2regs_windows: enet, mpsc, idma -> bridge regs\n");
2238 mv64x60_write(bh
, MV64360_ENET2MEM_ACC_PROT_0
, 0);
2239 mv64x60_write(bh
, MV64360_ENET2MEM_ACC_PROT_1
, 0);
2240 mv64x60_write(bh
, MV64360_ENET2MEM_ACC_PROT_2
, 0);
2242 mv64x60_write(bh
, MV64360_MPSC2MEM_ACC_PROT_0
, 0);
2243 mv64x60_write(bh
, MV64360_MPSC2MEM_ACC_PROT_1
, 0);
2245 mv64x60_write(bh
, MV64360_IDMA2MEM_ACC_PROT_0
, 0);
2246 mv64x60_write(bh
, MV64360_IDMA2MEM_ACC_PROT_1
, 0);
2247 mv64x60_write(bh
, MV64360_IDMA2MEM_ACC_PROT_2
, 0);
2248 mv64x60_write(bh
, MV64360_IDMA2MEM_ACC_PROT_3
, 0);
2250 /* Assume that mem ctlr has no more windows than embedded I/O ctlr */
2251 for (win
=MV64x60_CPU2MEM_0_WIN
,i
=0;win
<=MV64x60_CPU2MEM_3_WIN
;win
++,i
++)
2252 if (bh
->ci
->is_enabled_32bit(bh
, win
)) {
2253 mv64x60_set_32bit_window(bh
, enet_tab
[i
],
2254 mem_windows
[i
][0], mem_windows
[i
][1],
2255 (dram_selects
[i
] << 8) |
2256 (si
->enet_options
[i
] & 0x3000));
2257 bh
->ci
->enable_window_32bit(bh
, enet_tab
[i
]);
2259 /* Give enet r/w access to memory region */
2260 mv64x60_set_bits(bh
, MV64360_ENET2MEM_ACC_PROT_0
,
2262 mv64x60_set_bits(bh
, MV64360_ENET2MEM_ACC_PROT_1
,
2264 mv64x60_set_bits(bh
, MV64360_ENET2MEM_ACC_PROT_2
,
2267 mv64x60_set_32bit_window(bh
, mpsc_tab
[i
],
2268 mem_windows
[i
][0], mem_windows
[i
][1],
2269 (dram_selects
[i
] << 8) |
2270 (si
->mpsc_options
[i
] & 0x3000));
2271 bh
->ci
->enable_window_32bit(bh
, mpsc_tab
[i
]);
2273 /* Give mpsc r/w access to memory region */
2274 mv64x60_set_bits(bh
, MV64360_MPSC2MEM_ACC_PROT_0
,
2276 mv64x60_set_bits(bh
, MV64360_MPSC2MEM_ACC_PROT_1
,
2279 mv64x60_set_32bit_window(bh
, idma_tab
[i
],
2280 mem_windows
[i
][0], mem_windows
[i
][1],
2281 (dram_selects
[i
] << 8) |
2282 (si
->idma_options
[i
] & 0x3000));
2283 bh
->ci
->enable_window_32bit(bh
, idma_tab
[i
]);
2285 /* Give idma r/w access to memory region */
2286 mv64x60_set_bits(bh
, MV64360_IDMA2MEM_ACC_PROT_0
,
2288 mv64x60_set_bits(bh
, MV64360_IDMA2MEM_ACC_PROT_1
,
2290 mv64x60_set_bits(bh
, MV64360_IDMA2MEM_ACC_PROT_2
,
2292 mv64x60_set_bits(bh
, MV64360_IDMA2MEM_ACC_PROT_3
,
2298 * mv64360_set_mpsc2regs_window()
2300 * MPSC has a window to the bridge's internal registers. Call this routine
2301 * to change that window so it doesn't conflict with the windows mapping the
2302 * mpsc to system memory.
2305 mv64360_set_mpsc2regs_window(struct mv64x60_handle
*bh
, u32 base
)
2307 pr_debug("set mpsc->internal regs, base: 0x%x\n", base
);
2308 mv64x60_write(bh
, MV64360_MPSC2REGS_BASE
, base
& 0xffff0000);
2312 * mv64360_chip_specific_init()
2314 * Implement errata work arounds for the MV64360.
2317 mv64360_chip_specific_init(struct mv64x60_handle
*bh
,
2318 struct mv64x60_setup_info
*si
)
2320 #if !defined(CONFIG_NOT_COHERENT_CACHE)
2321 mv64x60_set_bits(bh
, MV64360_D_UNIT_CONTROL_HIGH
, (1<<24));
2323 #ifdef CONFIG_SERIAL_MPSC
2324 mv64x60_mpsc0_pdata
.brg_can_tune
= 1;
2325 mv64x60_mpsc0_pdata
.cache_mgmt
= 1;
2326 mv64x60_mpsc1_pdata
.brg_can_tune
= 1;
2327 mv64x60_mpsc1_pdata
.cache_mgmt
= 1;
2332 * mv64460_chip_specific_init()
2334 * Implement errata work arounds for the MV64460.
2337 mv64460_chip_specific_init(struct mv64x60_handle
*bh
,
2338 struct mv64x60_setup_info
*si
)
2340 #if !defined(CONFIG_NOT_COHERENT_CACHE)
2341 mv64x60_set_bits(bh
, MV64360_D_UNIT_CONTROL_HIGH
, (1<<24) | (1<<25));
2342 mv64x60_set_bits(bh
, MV64460_D_UNIT_MMASK
, (1<<1) | (1<<4));
2344 #ifdef CONFIG_SERIAL_MPSC
2345 mv64x60_mpsc0_pdata
.brg_can_tune
= 1;
2346 mv64x60_mpsc0_pdata
.cache_mgmt
= 1;
2347 mv64x60_mpsc1_pdata
.brg_can_tune
= 1;
2348 mv64x60_mpsc1_pdata
.cache_mgmt
= 1;
2353 #if defined(CONFIG_SYSFS) && !defined(CONFIG_GT64260)
2354 /* Export the hotswap register via sysfs for enum event monitoring */
2355 #define VAL_LEN_MAX 11 /* 32-bit hex or dec stringified number + '\n' */
2357 DECLARE_MUTEX(mv64xxx_hs_lock
);
2360 mv64xxx_hs_reg_read(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
2367 if (count
< VAL_LEN_MAX
)
2370 if (down_interruptible(&mv64xxx_hs_lock
))
2371 return -ERESTARTSYS
;
2372 save_exclude
= mv64x60_pci_exclude_bridge
;
2373 mv64x60_pci_exclude_bridge
= 0;
2374 early_read_config_dword(&sysfs_hose_a
, 0, PCI_DEVFN(0, 0),
2375 MV64360_PCICFG_CPCI_HOTSWAP
, &v
);
2376 mv64x60_pci_exclude_bridge
= save_exclude
;
2377 up(&mv64xxx_hs_lock
);
2379 return sprintf(buf
, "0x%08x\n", v
);
2383 mv64xxx_hs_reg_write(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
2393 if (sscanf(buf
, "%i", &v
) == 1) {
2394 if (down_interruptible(&mv64xxx_hs_lock
))
2395 return -ERESTARTSYS
;
2396 save_exclude
= mv64x60_pci_exclude_bridge
;
2397 mv64x60_pci_exclude_bridge
= 0;
2398 early_write_config_dword(&sysfs_hose_a
, 0, PCI_DEVFN(0, 0),
2399 MV64360_PCICFG_CPCI_HOTSWAP
, v
);
2400 mv64x60_pci_exclude_bridge
= save_exclude
;
2401 up(&mv64xxx_hs_lock
);
2409 static struct bin_attribute mv64xxx_hs_reg_attr
= { /* Hotswap register */
2412 .mode
= S_IRUGO
| S_IWUSR
,
2413 .owner
= THIS_MODULE
,
2415 .size
= VAL_LEN_MAX
,
2416 .read
= mv64xxx_hs_reg_read
,
2417 .write
= mv64xxx_hs_reg_write
,
2420 /* Provide sysfs file indicating if this platform supports the hs_reg */
2422 mv64xxx_hs_reg_valid_show(struct device
*dev
, struct device_attribute
*attr
,
2425 struct platform_device
*pdev
;
2426 struct mv64xxx_pdata
*pdp
;
2429 pdev
= container_of(dev
, struct platform_device
, dev
);
2430 pdp
= (struct mv64xxx_pdata
*)pdev
->dev
.platform_data
;
2432 if (down_interruptible(&mv64xxx_hs_lock
))
2433 return -ERESTARTSYS
;
2434 v
= pdp
->hs_reg_valid
;
2435 up(&mv64xxx_hs_lock
);
2437 return sprintf(buf
, "%i\n", v
);
2439 static DEVICE_ATTR(hs_reg_valid
, S_IRUGO
, mv64xxx_hs_reg_valid_show
, NULL
);
2442 mv64xxx_sysfs_init(void)
2444 sysfs_create_bin_file(&mv64xxx_device
.dev
.kobj
, &mv64xxx_hs_reg_attr
);
2445 sysfs_create_file(&mv64xxx_device
.dev
.kobj
,&dev_attr_hs_reg_valid
.attr
);
2448 subsys_initcall(mv64xxx_sysfs_init
);