2 * Common routines for the Marvell/Galileo Discovery line of host bridges
3 * (gt64260, mv64360, mv64460, ...).
5 * Author: Mark A. Greer <mgreer@mvista.com>
7 * 2004 (c) MontaVista, Software, Inc. This file is licensed under
8 * the terms of the GNU General Public License version 2. This program
9 * is licensed "as is" without any warranty of any kind, whether express
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/pci.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
17 #include <linux/mutex.h>
18 #include <linux/string.h>
19 #include <linux/spinlock.h>
20 #include <linux/mv643xx.h>
21 #include <linux/platform_device.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 __iomem
*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 #if defined(CONFIG_MV643XX_ETH) || defined(CONFIG_MV643XX_ETH_MODULE)
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
= {
344 .shared
= &mv64x60_eth_shared_device
;
348 static struct platform_device eth0_device
= {
349 .name
= MV643XX_ETH_NAME
,
351 .num_resources
= ARRAY_SIZE(mv64x60_eth0_resources
),
352 .resource
= mv64x60_eth0_resources
,
354 .platform_data
= ð0_pd
,
359 #ifdef CONFIG_MV643XX_ETH_1
360 static struct resource mv64x60_eth1_resources
[] = {
363 .start
= MV64x60_IRQ_ETH_1
,
364 .end
= MV64x60_IRQ_ETH_1
,
365 .flags
= IORESOURCE_IRQ
,
369 static struct mv643xx_eth_platform_data eth1_pd
= {
370 .shared
= &mv64x60_eth_shared_device
;
374 static struct platform_device eth1_device
= {
375 .name
= MV643XX_ETH_NAME
,
377 .num_resources
= ARRAY_SIZE(mv64x60_eth1_resources
),
378 .resource
= mv64x60_eth1_resources
,
380 .platform_data
= ð1_pd
,
385 #ifdef CONFIG_MV643XX_ETH_2
386 static struct resource mv64x60_eth2_resources
[] = {
389 .start
= MV64x60_IRQ_ETH_2
,
390 .end
= MV64x60_IRQ_ETH_2
,
391 .flags
= IORESOURCE_IRQ
,
395 static struct mv643xx_eth_platform_data eth2_pd
= {
396 .shared
= &mv64x60_eth_shared_device
;
400 static struct platform_device eth2_device
= {
401 .name
= MV643XX_ETH_NAME
,
403 .num_resources
= ARRAY_SIZE(mv64x60_eth2_resources
),
404 .resource
= mv64x60_eth2_resources
,
406 .platform_data
= ð2_pd
,
412 #ifdef CONFIG_I2C_MV64XXX
413 static struct mv64xxx_i2c_pdata mv64xxx_i2c_pdata
= {
416 .timeout
= 1000, /* Default timeout of 1 second */
419 static struct resource mv64xxx_i2c_resources
[] = {
420 /* Do not change the order of the IORESOURCE_MEM resources */
422 .name
= "mv64xxx i2c base",
423 .start
= MV64XXX_I2C_OFFSET
,
424 .end
= MV64XXX_I2C_OFFSET
+ MV64XXX_I2C_REG_BLOCK_SIZE
- 1,
425 .flags
= IORESOURCE_MEM
,
428 .name
= "mv64xxx i2c irq",
429 .start
= MV64x60_IRQ_I2C
,
430 .end
= MV64x60_IRQ_I2C
,
431 .flags
= IORESOURCE_IRQ
,
435 static struct platform_device i2c_device
= {
436 .name
= MV64XXX_I2C_CTLR_NAME
,
438 .num_resources
= ARRAY_SIZE(mv64xxx_i2c_resources
),
439 .resource
= mv64xxx_i2c_resources
,
441 .platform_data
= &mv64xxx_i2c_pdata
,
446 #ifdef CONFIG_WATCHDOG
447 static struct mv64x60_wdt_pdata mv64x60_wdt_pdata
= {
448 .timeout
= 10, /* default watchdog expiry in seconds */
449 .bus_clk
= 133, /* default bus clock in MHz */
452 static struct resource mv64x60_wdt_resources
[] = {
454 .name
= "mv64x60 wdt base",
455 .start
= MV64x60_WDT_WDC
,
456 .end
= MV64x60_WDT_WDC
+ 8 - 1, /* two 32-bit registers */
457 .flags
= IORESOURCE_MEM
,
461 static struct platform_device wdt_device
= {
462 .name
= MV64x60_WDT_NAME
,
464 .num_resources
= ARRAY_SIZE(mv64x60_wdt_resources
),
465 .resource
= mv64x60_wdt_resources
,
467 .platform_data
= &mv64x60_wdt_pdata
,
472 #if defined(CONFIG_SYSFS) && !defined(CONFIG_GT64260)
473 static struct mv64xxx_pdata mv64xxx_pdata
= {
477 static struct platform_device mv64xxx_device
= { /* general mv64x60 stuff */
478 .name
= MV64XXX_DEV_NAME
,
481 .platform_data
= &mv64xxx_pdata
,
486 static struct platform_device
*mv64x60_pd_devs
[] __initdata
= {
487 #ifdef CONFIG_SERIAL_MPSC
492 #if defined(CONFIG_MV643XX_ETH) || defined(CONFIG_MV643XX_ETH_MODULE)
493 &mv64x60_eth_shared_device
,
495 #ifdef CONFIG_MV643XX_ETH_0
498 #ifdef CONFIG_MV643XX_ETH_1
501 #ifdef CONFIG_MV643XX_ETH_2
504 #ifdef CONFIG_I2C_MV64XXX
507 #ifdef CONFIG_MV64X60_WDT
510 #if defined(CONFIG_SYSFS) && !defined(CONFIG_GT64260)
516 *****************************************************************************
518 * Bridge Initialization Routines
520 *****************************************************************************
525 * Initialize the bridge based on setting passed in via 'si'. The bridge
526 * handle, 'bh', will be set so that it can be used to make subsequent
527 * calls to routines in this file.
530 mv64x60_init(struct mv64x60_handle
*bh
, struct mv64x60_setup_info
*si
)
532 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2];
535 ppc_md
.progress("mv64x60 initialization", 0x0);
537 spin_lock_init(&mv64x60_lock
);
538 mv64x60_early_init(bh
, si
);
540 if (mv64x60_get_type(bh
) || mv64x60_setup_for_chip(bh
)) {
544 ppc_md
.progress("mv64x60_init: Can't determine chip",0);
548 bh
->ci
->disable_all_windows(bh
, si
);
549 mv64x60_get_mem_windows(bh
, mem_windows
);
550 mv64x60_config_cpu2mem_windows(bh
, si
, mem_windows
);
552 if (bh
->ci
->config_io2mem_windows
)
553 bh
->ci
->config_io2mem_windows(bh
, si
, mem_windows
);
554 if (bh
->ci
->set_mpsc2regs_window
)
555 bh
->ci
->set_mpsc2regs_window(bh
, si
->phys_reg_base
);
557 if (si
->pci_1
.enable_bus
) {
558 bh
->io_base_b
= (u32
)ioremap(si
->pci_1
.pci_io
.cpu_base
,
559 si
->pci_1
.pci_io
.size
);
560 isa_io_base
= bh
->io_base_b
;
563 if (si
->pci_0
.enable_bus
) {
564 bh
->io_base_a
= (u32
)ioremap(si
->pci_0
.pci_io
.cpu_base
,
565 si
->pci_0
.pci_io
.size
);
566 isa_io_base
= bh
->io_base_a
;
568 mv64x60_alloc_hose(bh
, MV64x60_PCI0_CONFIG_ADDR
,
569 MV64x60_PCI0_CONFIG_DATA
, &bh
->hose_a
);
570 mv64x60_config_resources(bh
->hose_a
, &si
->pci_0
, bh
->io_base_a
);
571 mv64x60_config_pci_params(bh
->hose_a
, &si
->pci_0
);
573 mv64x60_config_cpu2pci_windows(bh
, &si
->pci_0
, 0);
574 mv64x60_config_pci2mem_windows(bh
, bh
->hose_a
, &si
->pci_0
, 0,
576 bh
->ci
->set_pci2regs_window(bh
, bh
->hose_a
, 0,
580 if (si
->pci_1
.enable_bus
) {
581 mv64x60_alloc_hose(bh
, MV64x60_PCI1_CONFIG_ADDR
,
582 MV64x60_PCI1_CONFIG_DATA
, &bh
->hose_b
);
583 mv64x60_config_resources(bh
->hose_b
, &si
->pci_1
, bh
->io_base_b
);
584 mv64x60_config_pci_params(bh
->hose_b
, &si
->pci_1
);
586 mv64x60_config_cpu2pci_windows(bh
, &si
->pci_1
, 1);
587 mv64x60_config_pci2mem_windows(bh
, bh
->hose_b
, &si
->pci_1
, 1,
589 bh
->ci
->set_pci2regs_window(bh
, bh
->hose_b
, 1,
593 bh
->ci
->chip_specific_init(bh
, si
);
594 mv64x60_pd_fixup(bh
, mv64x60_pd_devs
, ARRAY_SIZE(mv64x60_pd_devs
));
600 * mv64x60_early_init()
602 * Do some bridge work that must take place before we start messing with
603 * the bridge for real.
606 mv64x60_early_init(struct mv64x60_handle
*bh
, struct mv64x60_setup_info
*si
)
608 struct pci_controller hose_a
, hose_b
;
610 memset(bh
, 0, sizeof(*bh
));
612 bh
->p_base
= si
->phys_reg_base
;
613 bh
->v_base
= ioremap(bh
->p_base
, MV64x60_INTERNAL_SPACE_SIZE
);
615 mv64x60_bridge_pbase
= bh
->p_base
;
616 mv64x60_bridge_vbase
= bh
->v_base
;
618 /* Assuming pci mode [reserved] bits 4:5 on 64260 are 0 */
619 bh
->pci_mode_a
= mv64x60_read(bh
, MV64x60_PCI0_MODE
) &
620 MV64x60_PCIMODE_MASK
;
621 bh
->pci_mode_b
= mv64x60_read(bh
, MV64x60_PCI1_MODE
) &
622 MV64x60_PCIMODE_MASK
;
624 /* Need temporary hose structs to call mv64x60_set_bus() */
625 memset(&hose_a
, 0, sizeof(hose_a
));
626 memset(&hose_b
, 0, sizeof(hose_b
));
627 setup_indirect_pci_nomap(&hose_a
, bh
->v_base
+ MV64x60_PCI0_CONFIG_ADDR
,
628 bh
->v_base
+ MV64x60_PCI0_CONFIG_DATA
);
629 setup_indirect_pci_nomap(&hose_b
, bh
->v_base
+ MV64x60_PCI1_CONFIG_ADDR
,
630 bh
->v_base
+ MV64x60_PCI1_CONFIG_DATA
);
631 bh
->hose_a
= &hose_a
;
632 bh
->hose_b
= &hose_b
;
634 #if defined(CONFIG_SYSFS) && !defined(CONFIG_GT64260)
635 /* Save a copy of hose_a for sysfs functions -- hack */
636 memcpy(&sysfs_hose_a
, &hose_a
, sizeof(hose_a
));
639 mv64x60_set_bus(bh
, 0, 0);
640 mv64x60_set_bus(bh
, 1, 0);
645 /* Clear bit 0 of PCI addr decode control so PCI->CPU remap 1:1 */
646 mv64x60_clr_bits(bh
, MV64x60_PCI0_PCI_DECODE_CNTL
, 0x00000001);
647 mv64x60_clr_bits(bh
, MV64x60_PCI1_PCI_DECODE_CNTL
, 0x00000001);
649 /* Bit 12 MUST be 0; set bit 27--don't auto-update cpu remap regs */
650 mv64x60_clr_bits(bh
, MV64x60_CPU_CONFIG
, (1<<12));
651 mv64x60_set_bits(bh
, MV64x60_CPU_CONFIG
, (1<<27));
653 mv64x60_set_bits(bh
, MV64x60_PCI0_TO_RETRY
, 0xffff);
654 mv64x60_set_bits(bh
, MV64x60_PCI1_TO_RETRY
, 0xffff);
658 *****************************************************************************
660 * Window Config Routines
662 *****************************************************************************
665 * mv64x60_get_32bit_window()
667 * Determine the base address and size of a 32-bit window on the bridge.
670 mv64x60_get_32bit_window(struct mv64x60_handle
*bh
, u32 window
,
671 u32
*base
, u32
*size
)
673 u32 val
, base_reg
, size_reg
, base_bits
, size_bits
;
674 u32 (*get_from_field
)(u32 val
, u32 num_bits
);
676 base_reg
= bh
->ci
->window_tab_32bit
[window
].base_reg
;
679 size_reg
= bh
->ci
->window_tab_32bit
[window
].size_reg
;
680 base_bits
= bh
->ci
->window_tab_32bit
[window
].base_bits
;
681 size_bits
= bh
->ci
->window_tab_32bit
[window
].size_bits
;
682 get_from_field
= bh
->ci
->window_tab_32bit
[window
].get_from_field
;
684 val
= mv64x60_read(bh
, base_reg
);
685 *base
= get_from_field(val
, base_bits
);
688 val
= mv64x60_read(bh
, size_reg
);
689 val
= get_from_field(val
, size_bits
);
690 *size
= bh
->ci
->untranslate_size(*base
, val
, size_bits
);
698 pr_debug("get 32bit window: %d, base: 0x%x, size: 0x%x\n",
699 window
, *base
, *size
);
703 * mv64x60_set_32bit_window()
705 * Set the base address and size of a 32-bit window on the bridge.
708 mv64x60_set_32bit_window(struct mv64x60_handle
*bh
, u32 window
,
709 u32 base
, u32 size
, u32 other_bits
)
711 u32 val
, base_reg
, size_reg
, base_bits
, size_bits
;
712 u32 (*map_to_field
)(u32 val
, u32 num_bits
);
714 pr_debug("set 32bit window: %d, base: 0x%x, size: 0x%x, other: 0x%x\n",
715 window
, base
, size
, other_bits
);
717 base_reg
= bh
->ci
->window_tab_32bit
[window
].base_reg
;
720 size_reg
= bh
->ci
->window_tab_32bit
[window
].size_reg
;
721 base_bits
= bh
->ci
->window_tab_32bit
[window
].base_bits
;
722 size_bits
= bh
->ci
->window_tab_32bit
[window
].size_bits
;
723 map_to_field
= bh
->ci
->window_tab_32bit
[window
].map_to_field
;
725 val
= map_to_field(base
, base_bits
) | other_bits
;
726 mv64x60_write(bh
, base_reg
, val
);
729 val
= bh
->ci
->translate_size(base
, size
, size_bits
);
730 val
= map_to_field(val
, size_bits
);
731 mv64x60_write(bh
, size_reg
, val
);
734 (void)mv64x60_read(bh
, base_reg
); /* Flush FIFO */
739 * mv64x60_get_64bit_window()
741 * Determine the base address and size of a 64-bit window on the bridge.
744 mv64x60_get_64bit_window(struct mv64x60_handle
*bh
, u32 window
,
745 u32
*base_hi
, u32
*base_lo
, u32
*size
)
747 u32 val
, base_lo_reg
, size_reg
, base_lo_bits
, size_bits
;
748 u32 (*get_from_field
)(u32 val
, u32 num_bits
);
750 base_lo_reg
= bh
->ci
->window_tab_64bit
[window
].base_lo_reg
;
752 if (base_lo_reg
!= 0) {
753 size_reg
= bh
->ci
->window_tab_64bit
[window
].size_reg
;
754 base_lo_bits
= bh
->ci
->window_tab_64bit
[window
].base_lo_bits
;
755 size_bits
= bh
->ci
->window_tab_64bit
[window
].size_bits
;
756 get_from_field
= bh
->ci
->window_tab_64bit
[window
].get_from_field
;
758 *base_hi
= mv64x60_read(bh
,
759 bh
->ci
->window_tab_64bit
[window
].base_hi_reg
);
761 val
= mv64x60_read(bh
, base_lo_reg
);
762 *base_lo
= get_from_field(val
, base_lo_bits
);
765 val
= mv64x60_read(bh
, size_reg
);
766 val
= get_from_field(val
, size_bits
);
767 *size
= bh
->ci
->untranslate_size(*base_lo
, val
,
777 pr_debug("get 64bit window: %d, base hi: 0x%x, base lo: 0x%x, "
778 "size: 0x%x\n", window
, *base_hi
, *base_lo
, *size
);
782 * mv64x60_set_64bit_window()
784 * Set the base address and size of a 64-bit window on the bridge.
787 mv64x60_set_64bit_window(struct mv64x60_handle
*bh
, u32 window
,
788 u32 base_hi
, u32 base_lo
, u32 size
, u32 other_bits
)
790 u32 val
, base_lo_reg
, size_reg
, base_lo_bits
, size_bits
;
791 u32 (*map_to_field
)(u32 val
, u32 num_bits
);
793 pr_debug("set 64bit window: %d, base hi: 0x%x, base lo: 0x%x, "
794 "size: 0x%x, other: 0x%x\n",
795 window
, base_hi
, base_lo
, size
, other_bits
);
797 base_lo_reg
= bh
->ci
->window_tab_64bit
[window
].base_lo_reg
;
799 if (base_lo_reg
!= 0) {
800 size_reg
= bh
->ci
->window_tab_64bit
[window
].size_reg
;
801 base_lo_bits
= bh
->ci
->window_tab_64bit
[window
].base_lo_bits
;
802 size_bits
= bh
->ci
->window_tab_64bit
[window
].size_bits
;
803 map_to_field
= bh
->ci
->window_tab_64bit
[window
].map_to_field
;
805 mv64x60_write(bh
, bh
->ci
->window_tab_64bit
[window
].base_hi_reg
,
808 val
= map_to_field(base_lo
, base_lo_bits
) | other_bits
;
809 mv64x60_write(bh
, base_lo_reg
, val
);
812 val
= bh
->ci
->translate_size(base_lo
, size
, size_bits
);
813 val
= map_to_field(val
, size_bits
);
814 mv64x60_write(bh
, size_reg
, val
);
817 (void)mv64x60_read(bh
, base_lo_reg
); /* Flush FIFO */
824 * Take the high-order 'num_bits' of 'val' & mask off low bits.
827 mv64x60_mask(u32 val
, u32 num_bits
)
829 return val
& (0xffffffff << (32 - num_bits
));
833 * mv64x60_shift_left()
835 * Take the low-order 'num_bits' of 'val', shift left to align at bit 31 (MSB).
838 mv64x60_shift_left(u32 val
, u32 num_bits
)
840 return val
<< (32 - num_bits
);
844 * mv64x60_shift_right()
846 * Take the high-order 'num_bits' of 'val', shift right to align at bit 0 (LSB).
849 mv64x60_shift_right(u32 val
, u32 num_bits
)
851 return val
>> (32 - num_bits
);
855 *****************************************************************************
857 * Chip Identification Routines
859 *****************************************************************************
864 * Determine the type of bridge chip we have.
867 mv64x60_get_type(struct mv64x60_handle
*bh
)
869 struct pci_controller hose
;
873 memset(&hose
, 0, sizeof(hose
));
874 setup_indirect_pci_nomap(&hose
, bh
->v_base
+ MV64x60_PCI0_CONFIG_ADDR
,
875 bh
->v_base
+ MV64x60_PCI0_CONFIG_DATA
);
877 save_exclude
= mv64x60_pci_exclude_bridge
;
878 mv64x60_pci_exclude_bridge
= 0;
879 /* Sanity check of bridge's Vendor ID */
880 early_read_config_word(&hose
, 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID
, &val
);
882 if (val
!= PCI_VENDOR_ID_MARVELL
) {
883 mv64x60_pci_exclude_bridge
= save_exclude
;
887 /* Get the revision of the chip */
888 early_read_config_word(&hose
, 0, PCI_DEVFN(0, 0), PCI_CLASS_REVISION
,
890 bh
->rev
= (u32
)(val
& 0xff);
892 /* Figure out the type of Marvell bridge it is */
893 early_read_config_word(&hose
, 0, PCI_DEVFN(0, 0), PCI_DEVICE_ID
, &val
);
894 mv64x60_pci_exclude_bridge
= save_exclude
;
897 case PCI_DEVICE_ID_MARVELL_GT64260
:
900 bh
->type
= MV64x60_TYPE_GT64260A
;
904 printk(KERN_WARNING
"Unsupported GT64260 rev %04x\n",
906 /* Assume its similar to a 'B' rev and fallthru */
908 bh
->type
= MV64x60_TYPE_GT64260B
;
913 case PCI_DEVICE_ID_MARVELL_MV64360
:
914 /* Marvell won't tell me how to distinguish a 64361 & 64362 */
915 bh
->type
= MV64x60_TYPE_MV64360
;
918 case PCI_DEVICE_ID_MARVELL_MV64460
:
919 bh
->type
= MV64x60_TYPE_MV64460
;
923 printk(KERN_ERR
"Unknown Marvell bridge type %04x\n", val
);
927 /* Hang onto bridge type & rev for PIC code */
928 mv64x60_bridge_type
= bh
->type
;
929 mv64x60_bridge_rev
= bh
->rev
;
935 * mv64x60_setup_for_chip()
937 * Set 'bh' to use the proper set of routine for the bridge chip that we have.
940 mv64x60_setup_for_chip(struct mv64x60_handle
*bh
)
944 /* Set up chip-specific info based on the chip/bridge type */
946 case MV64x60_TYPE_GT64260A
:
947 bh
->ci
= >64260a_ci
;
950 case MV64x60_TYPE_GT64260B
:
951 bh
->ci
= >64260b_ci
;
954 case MV64x60_TYPE_MV64360
:
955 bh
->ci
= &mv64360_ci
;
958 case MV64x60_TYPE_MV64460
:
959 bh
->ci
= &mv64460_ci
;
962 case MV64x60_TYPE_INVALID
:
965 ppc_md
.progress("mv64x60: Unsupported bridge", 0x0);
966 printk(KERN_ERR
"mv64x60: Unsupported bridge\n");
974 * mv64x60_get_bridge_vbase()
976 * Return the virtual address of the bridge's registers.
979 mv64x60_get_bridge_vbase(void)
981 return mv64x60_bridge_vbase
;
985 * mv64x60_get_bridge_type()
987 * Return the type of bridge on the platform.
990 mv64x60_get_bridge_type(void)
992 return mv64x60_bridge_type
;
996 * mv64x60_get_bridge_rev()
998 * Return the revision of the bridge on the platform.
1001 mv64x60_get_bridge_rev(void)
1003 return mv64x60_bridge_rev
;
1007 *****************************************************************************
1009 * System Memory Window Related Routines
1011 *****************************************************************************
1014 * mv64x60_get_mem_size()
1016 * Calculate the amount of memory that the memory controller is set up for.
1017 * This should only be used by board-specific code if there is no other
1018 * way to determine the amount of memory in the system.
1021 mv64x60_get_mem_size(u32 bridge_base
, u32 chip_type
)
1023 struct mv64x60_handle bh
;
1024 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2];
1027 memset(&bh
, 0, sizeof(bh
));
1029 bh
.type
= chip_type
;
1030 bh
.v_base
= (void *)bridge_base
;
1032 if (!mv64x60_setup_for_chip(&bh
)) {
1033 mv64x60_get_mem_windows(&bh
, mem_windows
);
1034 rc
= mv64x60_calc_mem_size(&bh
, mem_windows
);
1041 * mv64x60_get_mem_windows()
1043 * Get the values in the memory controller & return in the 'mem_windows' array.
1046 mv64x60_get_mem_windows(struct mv64x60_handle
*bh
,
1047 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2])
1051 for (win
=MV64x60_CPU2MEM_0_WIN
,i
=0;win
<=MV64x60_CPU2MEM_3_WIN
;win
++,i
++)
1052 if (bh
->ci
->is_enabled_32bit(bh
, win
))
1053 mv64x60_get_32bit_window(bh
, win
,
1054 &mem_windows
[i
][0], &mem_windows
[i
][1]);
1056 mem_windows
[i
][0] = 0;
1057 mem_windows
[i
][1] = 0;
1062 * mv64x60_calc_mem_size()
1064 * Using the memory controller register values in 'mem_windows', determine
1065 * how much memory it is set up for.
1068 mv64x60_calc_mem_size(struct mv64x60_handle
*bh
,
1069 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2])
1073 for (i
=0; i
<MV64x60_CPU2MEM_WINDOWS
; i
++)
1074 total
+= mem_windows
[i
][1];
1080 *****************************************************************************
1082 * CPU->System MEM, PCI Config Routines
1084 *****************************************************************************
1087 * mv64x60_config_cpu2mem_windows()
1089 * Configure CPU->Memory windows on the bridge.
1091 static u32 prot_tab
[] __initdata
= {
1092 MV64x60_CPU_PROT_0_WIN
, MV64x60_CPU_PROT_1_WIN
,
1093 MV64x60_CPU_PROT_2_WIN
, MV64x60_CPU_PROT_3_WIN
1096 static u32 cpu_snoop_tab
[] __initdata
= {
1097 MV64x60_CPU_SNOOP_0_WIN
, MV64x60_CPU_SNOOP_1_WIN
,
1098 MV64x60_CPU_SNOOP_2_WIN
, MV64x60_CPU_SNOOP_3_WIN
1102 mv64x60_config_cpu2mem_windows(struct mv64x60_handle
*bh
,
1103 struct mv64x60_setup_info
*si
,
1104 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2])
1108 /* Set CPU protection & snoop windows */
1109 for (win
=MV64x60_CPU2MEM_0_WIN
,i
=0;win
<=MV64x60_CPU2MEM_3_WIN
;win
++,i
++)
1110 if (bh
->ci
->is_enabled_32bit(bh
, win
)) {
1111 mv64x60_set_32bit_window(bh
, prot_tab
[i
],
1112 mem_windows
[i
][0], mem_windows
[i
][1],
1113 si
->cpu_prot_options
[i
]);
1114 bh
->ci
->enable_window_32bit(bh
, prot_tab
[i
]);
1116 if (bh
->ci
->window_tab_32bit
[cpu_snoop_tab
[i
]].
1118 mv64x60_set_32bit_window(bh
, cpu_snoop_tab
[i
],
1119 mem_windows
[i
][0], mem_windows
[i
][1],
1120 si
->cpu_snoop_options
[i
]);
1121 bh
->ci
->enable_window_32bit(bh
,
1129 * mv64x60_config_cpu2pci_windows()
1131 * Configure the CPU->PCI windows for one of the PCI buses.
1133 static u32 win_tab
[2][4] __initdata
= {
1134 { MV64x60_CPU2PCI0_IO_WIN
, MV64x60_CPU2PCI0_MEM_0_WIN
,
1135 MV64x60_CPU2PCI0_MEM_1_WIN
, MV64x60_CPU2PCI0_MEM_2_WIN
},
1136 { MV64x60_CPU2PCI1_IO_WIN
, MV64x60_CPU2PCI1_MEM_0_WIN
,
1137 MV64x60_CPU2PCI1_MEM_1_WIN
, MV64x60_CPU2PCI1_MEM_2_WIN
},
1140 static u32 remap_tab
[2][4] __initdata
= {
1141 { MV64x60_CPU2PCI0_IO_REMAP_WIN
, MV64x60_CPU2PCI0_MEM_0_REMAP_WIN
,
1142 MV64x60_CPU2PCI0_MEM_1_REMAP_WIN
, MV64x60_CPU2PCI0_MEM_2_REMAP_WIN
},
1143 { MV64x60_CPU2PCI1_IO_REMAP_WIN
, MV64x60_CPU2PCI1_MEM_0_REMAP_WIN
,
1144 MV64x60_CPU2PCI1_MEM_1_REMAP_WIN
, MV64x60_CPU2PCI1_MEM_2_REMAP_WIN
}
1148 mv64x60_config_cpu2pci_windows(struct mv64x60_handle
*bh
,
1149 struct mv64x60_pci_info
*pi
, u32 bus
)
1153 if (pi
->pci_io
.size
> 0) {
1154 mv64x60_set_32bit_window(bh
, win_tab
[bus
][0],
1155 pi
->pci_io
.cpu_base
, pi
->pci_io
.size
, pi
->pci_io
.swap
);
1156 mv64x60_set_32bit_window(bh
, remap_tab
[bus
][0],
1157 pi
->pci_io
.pci_base_lo
, 0, 0);
1158 bh
->ci
->enable_window_32bit(bh
, win_tab
[bus
][0]);
1159 } else /* Actually, the window should already be disabled */
1160 bh
->ci
->disable_window_32bit(bh
, win_tab
[bus
][0]);
1163 if (pi
->pci_mem
[i
].size
> 0) {
1164 mv64x60_set_32bit_window(bh
, win_tab
[bus
][i
+1],
1165 pi
->pci_mem
[i
].cpu_base
, pi
->pci_mem
[i
].size
,
1166 pi
->pci_mem
[i
].swap
);
1167 mv64x60_set_64bit_window(bh
, remap_tab
[bus
][i
+1],
1168 pi
->pci_mem
[i
].pci_base_hi
,
1169 pi
->pci_mem
[i
].pci_base_lo
, 0, 0);
1170 bh
->ci
->enable_window_32bit(bh
, win_tab
[bus
][i
+1]);
1171 } else /* Actually, the window should already be disabled */
1172 bh
->ci
->disable_window_32bit(bh
, win_tab
[bus
][i
+1]);
1176 *****************************************************************************
1178 * PCI->System MEM Config Routines
1180 *****************************************************************************
1183 * mv64x60_config_pci2mem_windows()
1185 * Configure the PCI->Memory windows on the bridge.
1187 static u32 pci_acc_tab
[2][4] __initdata
= {
1188 { MV64x60_PCI02MEM_ACC_CNTL_0_WIN
, MV64x60_PCI02MEM_ACC_CNTL_1_WIN
,
1189 MV64x60_PCI02MEM_ACC_CNTL_2_WIN
, MV64x60_PCI02MEM_ACC_CNTL_3_WIN
},
1190 { MV64x60_PCI12MEM_ACC_CNTL_0_WIN
, MV64x60_PCI12MEM_ACC_CNTL_1_WIN
,
1191 MV64x60_PCI12MEM_ACC_CNTL_2_WIN
, MV64x60_PCI12MEM_ACC_CNTL_3_WIN
}
1194 static u32 pci_snoop_tab
[2][4] __initdata
= {
1195 { MV64x60_PCI02MEM_SNOOP_0_WIN
, MV64x60_PCI02MEM_SNOOP_1_WIN
,
1196 MV64x60_PCI02MEM_SNOOP_2_WIN
, MV64x60_PCI02MEM_SNOOP_3_WIN
},
1197 { MV64x60_PCI12MEM_SNOOP_0_WIN
, MV64x60_PCI12MEM_SNOOP_1_WIN
,
1198 MV64x60_PCI12MEM_SNOOP_2_WIN
, MV64x60_PCI12MEM_SNOOP_3_WIN
}
1201 static u32 pci_size_tab
[2][4] __initdata
= {
1202 { MV64x60_PCI0_MEM_0_SIZE
, MV64x60_PCI0_MEM_1_SIZE
,
1203 MV64x60_PCI0_MEM_2_SIZE
, MV64x60_PCI0_MEM_3_SIZE
},
1204 { MV64x60_PCI1_MEM_0_SIZE
, MV64x60_PCI1_MEM_1_SIZE
,
1205 MV64x60_PCI1_MEM_2_SIZE
, MV64x60_PCI1_MEM_3_SIZE
}
1209 mv64x60_config_pci2mem_windows(struct mv64x60_handle
*bh
,
1210 struct pci_controller
*hose
, struct mv64x60_pci_info
*pi
,
1211 u32 bus
, u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2])
1216 * Set the access control, snoop, BAR size, and window base addresses.
1217 * PCI->MEM windows base addresses will match exactly what the
1218 * CPU->MEM windows are.
1220 for (win
=MV64x60_CPU2MEM_0_WIN
,i
=0;win
<=MV64x60_CPU2MEM_3_WIN
;win
++,i
++)
1221 if (bh
->ci
->is_enabled_32bit(bh
, win
)) {
1222 mv64x60_set_64bit_window(bh
,
1223 pci_acc_tab
[bus
][i
], 0,
1224 mem_windows
[i
][0], mem_windows
[i
][1],
1225 pi
->acc_cntl_options
[i
]);
1226 bh
->ci
->enable_window_64bit(bh
, pci_acc_tab
[bus
][i
]);
1228 if (bh
->ci
->window_tab_64bit
[
1229 pci_snoop_tab
[bus
][i
]].base_lo_reg
!= 0) {
1231 mv64x60_set_64bit_window(bh
,
1232 pci_snoop_tab
[bus
][i
], 0,
1233 mem_windows
[i
][0], mem_windows
[i
][1],
1234 pi
->snoop_options
[i
]);
1235 bh
->ci
->enable_window_64bit(bh
,
1236 pci_snoop_tab
[bus
][i
]);
1239 bh
->ci
->set_pci2mem_window(hose
, bus
, i
,
1241 mv64x60_write(bh
, pci_size_tab
[bus
][i
],
1242 mv64x60_mask(mem_windows
[i
][1] - 1, 20));
1244 /* Enable the window */
1245 mv64x60_clr_bits(bh
, ((bus
== 0) ?
1246 MV64x60_PCI0_BAR_ENABLE
:
1247 MV64x60_PCI1_BAR_ENABLE
), (1 << i
));
1252 *****************************************************************************
1254 * Hose & Resource Alloc/Init Routines
1256 *****************************************************************************
1259 * mv64x60_alloc_hoses()
1261 * Allocate the PCI hose structures for the bridge's PCI buses.
1264 mv64x60_alloc_hose(struct mv64x60_handle
*bh
, u32 cfg_addr
, u32 cfg_data
,
1265 struct pci_controller
**hose
)
1267 *hose
= pcibios_alloc_controller();
1268 setup_indirect_pci_nomap(*hose
, bh
->v_base
+ cfg_addr
,
1269 bh
->v_base
+ cfg_data
);
1273 * mv64x60_config_resources()
1275 * Calculate the offsets, etc. for the hose structures to reflect all of
1276 * the address remapping that happens as you go from CPU->PCI and PCI->MEM.
1279 mv64x60_config_resources(struct pci_controller
*hose
,
1280 struct mv64x60_pci_info
*pi
, u32 io_base
)
1283 /* 2 hoses; 4 resources/hose; string <= 64 bytes */
1284 static char s
[2][4][64];
1286 if (pi
->pci_io
.size
!= 0) {
1287 sprintf(s
[hose
->index
][0], "PCI hose %d I/O Space",
1289 pci_init_resource(&hose
->io_resource
, io_base
- isa_io_base
,
1290 io_base
- isa_io_base
+ pi
->pci_io
.size
- 1,
1291 IORESOURCE_IO
, s
[hose
->index
][0]);
1292 hose
->io_space
.start
= pi
->pci_io
.pci_base_lo
;
1293 hose
->io_space
.end
= pi
->pci_io
.pci_base_lo
+ pi
->pci_io
.size
-1;
1294 hose
->io_base_phys
= pi
->pci_io
.cpu_base
;
1295 hose
->io_base_virt
= (void *)isa_io_base
;
1299 if (pi
->pci_mem
[i
].size
!= 0) {
1300 sprintf(s
[hose
->index
][i
+1], "PCI hose %d MEM Space %d",
1302 pci_init_resource(&hose
->mem_resources
[i
],
1303 pi
->pci_mem
[i
].cpu_base
,
1304 pi
->pci_mem
[i
].cpu_base
+ pi
->pci_mem
[i
].size
-1,
1305 IORESOURCE_MEM
, s
[hose
->index
][i
+1]);
1308 hose
->mem_space
.end
= pi
->pci_mem
[0].pci_base_lo
+
1309 pi
->pci_mem
[0].size
- 1;
1310 hose
->pci_mem_offset
= pi
->pci_mem
[0].cpu_base
-
1311 pi
->pci_mem
[0].pci_base_lo
;
1315 * mv64x60_config_pci_params()
1317 * Configure a hose's PCI config space parameters.
1320 mv64x60_config_pci_params(struct pci_controller
*hose
,
1321 struct mv64x60_pci_info
*pi
)
1327 devfn
= PCI_DEVFN(0,0);
1329 save_exclude
= mv64x60_pci_exclude_bridge
;
1330 mv64x60_pci_exclude_bridge
= 0;
1332 /* Set class code to indicate host bridge */
1333 u16_val
= PCI_CLASS_BRIDGE_HOST
; /* 0x0600 (host bridge) */
1334 early_write_config_word(hose
, 0, devfn
, PCI_CLASS_DEVICE
, u16_val
);
1336 /* Enable bridge to be PCI master & respond to PCI MEM cycles */
1337 early_read_config_word(hose
, 0, devfn
, PCI_COMMAND
, &u16_val
);
1338 u16_val
&= ~(PCI_COMMAND_IO
| PCI_COMMAND_INVALIDATE
|
1339 PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
| PCI_COMMAND_FAST_BACK
);
1340 u16_val
|= pi
->pci_cmd_bits
| PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
;
1341 early_write_config_word(hose
, 0, devfn
, PCI_COMMAND
, u16_val
);
1343 /* Set latency timer, cache line size, clear BIST */
1344 u16_val
= (pi
->latency_timer
<< 8) | (L1_CACHE_BYTES
>> 2);
1345 early_write_config_word(hose
, 0, devfn
, PCI_CACHE_LINE_SIZE
, u16_val
);
1347 mv64x60_pci_exclude_bridge
= save_exclude
;
1351 *****************************************************************************
1353 * PCI Related Routine
1355 *****************************************************************************
1360 * Set the bus number for the hose directly under the bridge.
1363 mv64x60_set_bus(struct mv64x60_handle
*bh
, u32 bus
, u32 child_bus
)
1365 struct pci_controller
*hose
;
1366 u32 pci_mode
, p2p_cfg
, pci_cfg_offset
, val
;
1370 pci_mode
= bh
->pci_mode_a
;
1371 p2p_cfg
= MV64x60_PCI0_P2P_CONFIG
;
1372 pci_cfg_offset
= 0x64;
1375 pci_mode
= bh
->pci_mode_b
;
1376 p2p_cfg
= MV64x60_PCI1_P2P_CONFIG
;
1377 pci_cfg_offset
= 0xe4;
1382 val
= mv64x60_read(bh
, p2p_cfg
);
1384 if (pci_mode
== MV64x60_PCIMODE_CONVENTIONAL
) {
1385 val
&= 0xe0000000; /* Force dev num to 0, turn off P2P bridge */
1386 val
|= (child_bus
<< 16) | 0xff;
1387 mv64x60_write(bh
, p2p_cfg
, val
);
1388 (void)mv64x60_read(bh
, p2p_cfg
); /* Flush FIFO */
1389 } else { /* PCI-X */
1391 * Need to use the current bus/dev number (that's in the
1392 * P2P CONFIG reg) to access the bridge's pci config space.
1394 save_exclude
= mv64x60_pci_exclude_bridge
;
1395 mv64x60_pci_exclude_bridge
= 0;
1396 early_write_config_dword(hose
, (val
& 0x00ff0000) >> 16,
1397 PCI_DEVFN(((val
& 0x1f000000) >> 24), 0),
1398 pci_cfg_offset
, child_bus
<< 8);
1399 mv64x60_pci_exclude_bridge
= save_exclude
;
1404 * mv64x60_pci_exclude_device()
1406 * This routine is used to make the bridge not appear when the
1407 * PCI subsystem is accessing PCI devices (in PCI config space).
1410 mv64x60_pci_exclude_device(u8 bus
, u8 devfn
)
1412 struct pci_controller
*hose
;
1414 hose
= pci_bus_to_hose(bus
);
1416 /* Skip slot 0 on both hoses */
1417 if ((mv64x60_pci_exclude_bridge
== 1) && (PCI_SLOT(devfn
) == 0) &&
1418 (hose
->first_busno
== bus
))
1420 return PCIBIOS_DEVICE_NOT_FOUND
;
1422 return PCIBIOS_SUCCESSFUL
;
1423 } /* mv64x60_pci_exclude_device() */
1426 *****************************************************************************
1428 * Platform Device Routines
1430 *****************************************************************************
1434 * mv64x60_pd_fixup()
1436 * Need to add the base addr of where the bridge's regs are mapped in the
1437 * physical addr space so drivers can ioremap() them.
1440 mv64x60_pd_fixup(struct mv64x60_handle
*bh
, struct platform_device
*pd_devs
[],
1446 for (i
=0; i
<entries
; i
++) {
1449 while ((r
= platform_get_resource(pd_devs
[i
],IORESOURCE_MEM
,j
))
1452 r
->start
+= bh
->p_base
;
1453 r
->end
+= bh
->p_base
;
1462 * Add the mv64x60 platform devices to the list of platform devices.
1465 mv64x60_add_pds(void)
1467 return platform_add_devices(mv64x60_pd_devs
,
1468 ARRAY_SIZE(mv64x60_pd_devs
));
1470 arch_initcall(mv64x60_add_pds
);
1473 *****************************************************************************
1475 * GT64260-Specific Routines
1477 *****************************************************************************
1480 * gt64260_translate_size()
1482 * On the GT64260, the size register is really the "top" address of the window.
1485 gt64260_translate_size(u32 base
, u32 size
, u32 num_bits
)
1487 return base
+ mv64x60_mask(size
- 1, num_bits
);
1491 * gt64260_untranslate_size()
1493 * Translate the top address of a window into a window size.
1496 gt64260_untranslate_size(u32 base
, u32 size
, u32 num_bits
)
1499 size
= size
- base
+ (1 << (32 - num_bits
));
1507 * gt64260_set_pci2mem_window()
1509 * The PCI->MEM window registers are actually in PCI config space so need
1510 * to set them by setting the correct config space BARs.
1512 static u32 gt64260_reg_addrs
[2][4] __initdata
= {
1513 { 0x10, 0x14, 0x18, 0x1c }, { 0x90, 0x94, 0x98, 0x9c }
1517 gt64260_set_pci2mem_window(struct pci_controller
*hose
, u32 bus
, u32 window
,
1522 pr_debug("set pci->mem window: %d, hose: %d, base: 0x%x\n", window
,
1525 save_exclude
= mv64x60_pci_exclude_bridge
;
1526 mv64x60_pci_exclude_bridge
= 0;
1527 early_write_config_dword(hose
, 0, PCI_DEVFN(0, 0),
1528 gt64260_reg_addrs
[bus
][window
], mv64x60_mask(base
, 20) | 0x8);
1529 mv64x60_pci_exclude_bridge
= save_exclude
;
1533 * gt64260_set_pci2regs_window()
1535 * Set where the bridge's registers appear in PCI MEM space.
1537 static u32 gt64260_offset
[2] __initdata
= {0x20, 0xa0};
1540 gt64260_set_pci2regs_window(struct mv64x60_handle
*bh
,
1541 struct pci_controller
*hose
, u32 bus
, u32 base
)
1545 pr_debug("set pci->internal regs hose: %d, base: 0x%x\n", hose
->index
,
1548 save_exclude
= mv64x60_pci_exclude_bridge
;
1549 mv64x60_pci_exclude_bridge
= 0;
1550 early_write_config_dword(hose
, 0, PCI_DEVFN(0,0), gt64260_offset
[bus
],
1552 mv64x60_pci_exclude_bridge
= save_exclude
;
1556 * gt64260_is_enabled_32bit()
1558 * On a GT64260, a window is enabled iff its top address is >= to its base
1562 gt64260_is_enabled_32bit(struct mv64x60_handle
*bh
, u32 window
)
1566 if ((gt64260_32bit_windows
[window
].base_reg
!= 0) &&
1567 (gt64260_32bit_windows
[window
].size_reg
!= 0) &&
1568 ((mv64x60_read(bh
, gt64260_32bit_windows
[window
].size_reg
) &
1569 ((1 << gt64260_32bit_windows
[window
].size_bits
) - 1)) >=
1570 (mv64x60_read(bh
, gt64260_32bit_windows
[window
].base_reg
) &
1571 ((1 << gt64260_32bit_windows
[window
].base_bits
) - 1))))
1579 * gt64260_enable_window_32bit()
1581 * On the GT64260, a window is enabled iff the top address is >= to the base
1582 * address of the window. Since the window has already been configured by
1583 * the time this routine is called, we have nothing to do here.
1586 gt64260_enable_window_32bit(struct mv64x60_handle
*bh
, u32 window
)
1588 pr_debug("enable 32bit window: %d\n", window
);
1592 * gt64260_disable_window_32bit()
1594 * On a GT64260, you disable a window by setting its top address to be less
1595 * than its base address.
1598 gt64260_disable_window_32bit(struct mv64x60_handle
*bh
, u32 window
)
1600 pr_debug("disable 32bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
1601 window
, gt64260_32bit_windows
[window
].base_reg
,
1602 gt64260_32bit_windows
[window
].size_reg
);
1604 if ((gt64260_32bit_windows
[window
].base_reg
!= 0) &&
1605 (gt64260_32bit_windows
[window
].size_reg
!= 0)) {
1607 /* To disable, make bottom reg higher than top reg */
1608 mv64x60_write(bh
, gt64260_32bit_windows
[window
].base_reg
,0xfff);
1609 mv64x60_write(bh
, gt64260_32bit_windows
[window
].size_reg
, 0);
1614 * gt64260_enable_window_64bit()
1616 * On the GT64260, a window is enabled iff the top address is >= to the base
1617 * address of the window. Since the window has already been configured by
1618 * the time this routine is called, we have nothing to do here.
1621 gt64260_enable_window_64bit(struct mv64x60_handle
*bh
, u32 window
)
1623 pr_debug("enable 64bit window: %d\n", window
);
1627 * gt64260_disable_window_64bit()
1629 * On a GT64260, you disable a window by setting its top address to be less
1630 * than its base address.
1633 gt64260_disable_window_64bit(struct mv64x60_handle
*bh
, u32 window
)
1635 pr_debug("disable 64bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
1636 window
, gt64260_64bit_windows
[window
].base_lo_reg
,
1637 gt64260_64bit_windows
[window
].size_reg
);
1639 if ((gt64260_64bit_windows
[window
].base_lo_reg
!= 0) &&
1640 (gt64260_64bit_windows
[window
].size_reg
!= 0)) {
1642 /* To disable, make bottom reg higher than top reg */
1643 mv64x60_write(bh
, gt64260_64bit_windows
[window
].base_lo_reg
,
1645 mv64x60_write(bh
, gt64260_64bit_windows
[window
].base_hi_reg
, 0);
1646 mv64x60_write(bh
, gt64260_64bit_windows
[window
].size_reg
, 0);
1651 * gt64260_disable_all_windows()
1653 * The GT64260 has several windows that aren't represented in the table of
1654 * windows at the top of this file. This routine turns all of them off
1655 * except for the memory controller windows, of course.
1658 gt64260_disable_all_windows(struct mv64x60_handle
*bh
,
1659 struct mv64x60_setup_info
*si
)
1663 /* Disable 32bit windows (don't disable cpu->mem windows) */
1664 for (i
=MV64x60_CPU2DEV_0_WIN
; i
<MV64x60_32BIT_WIN_COUNT
; i
++) {
1666 preserve
= si
->window_preserve_mask_32_lo
& (1 << i
);
1668 preserve
= si
->window_preserve_mask_32_hi
& (1<<(i
-32));
1671 gt64260_disable_window_32bit(bh
, i
);
1674 /* Disable 64bit windows */
1675 for (i
=0; i
<MV64x60_64BIT_WIN_COUNT
; i
++)
1676 if (!(si
->window_preserve_mask_64
& (1<<i
)))
1677 gt64260_disable_window_64bit(bh
, i
);
1679 /* Turn off cpu protection windows not in gt64260_32bit_windows[] */
1680 mv64x60_write(bh
, GT64260_CPU_PROT_BASE_4
, 0xfff);
1681 mv64x60_write(bh
, GT64260_CPU_PROT_SIZE_4
, 0);
1682 mv64x60_write(bh
, GT64260_CPU_PROT_BASE_5
, 0xfff);
1683 mv64x60_write(bh
, GT64260_CPU_PROT_SIZE_5
, 0);
1684 mv64x60_write(bh
, GT64260_CPU_PROT_BASE_6
, 0xfff);
1685 mv64x60_write(bh
, GT64260_CPU_PROT_SIZE_6
, 0);
1686 mv64x60_write(bh
, GT64260_CPU_PROT_BASE_7
, 0xfff);
1687 mv64x60_write(bh
, GT64260_CPU_PROT_SIZE_7
, 0);
1689 /* Turn off PCI->MEM access cntl wins not in gt64260_64bit_windows[] */
1690 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_4_BASE_LO
, 0xfff);
1691 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_4_BASE_HI
, 0);
1692 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_4_SIZE
, 0);
1693 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_5_BASE_LO
, 0xfff);
1694 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_5_BASE_HI
, 0);
1695 mv64x60_write(bh
, MV64x60_PCI0_ACC_CNTL_5_SIZE
, 0);
1696 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_6_BASE_LO
, 0xfff);
1697 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_6_BASE_HI
, 0);
1698 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_6_SIZE
, 0);
1699 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_7_BASE_LO
, 0xfff);
1700 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_7_BASE_HI
, 0);
1701 mv64x60_write(bh
, GT64260_PCI0_ACC_CNTL_7_SIZE
, 0);
1703 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_4_BASE_LO
, 0xfff);
1704 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_4_BASE_HI
, 0);
1705 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_4_SIZE
, 0);
1706 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_5_BASE_LO
, 0xfff);
1707 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_5_BASE_HI
, 0);
1708 mv64x60_write(bh
, MV64x60_PCI1_ACC_CNTL_5_SIZE
, 0);
1709 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_6_BASE_LO
, 0xfff);
1710 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_6_BASE_HI
, 0);
1711 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_6_SIZE
, 0);
1712 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_7_BASE_LO
, 0xfff);
1713 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_7_BASE_HI
, 0);
1714 mv64x60_write(bh
, GT64260_PCI1_ACC_CNTL_7_SIZE
, 0);
1716 /* Disable all PCI-><whatever> windows */
1717 mv64x60_set_bits(bh
, MV64x60_PCI0_BAR_ENABLE
, 0x07fffdff);
1718 mv64x60_set_bits(bh
, MV64x60_PCI1_BAR_ENABLE
, 0x07fffdff);
1721 * Some firmwares enable a bunch of intr sources
1722 * for the PCI INT output pins.
1724 mv64x60_write(bh
, GT64260_IC_CPU_INTR_MASK_LO
, 0);
1725 mv64x60_write(bh
, GT64260_IC_CPU_INTR_MASK_HI
, 0);
1726 mv64x60_write(bh
, GT64260_IC_PCI0_INTR_MASK_LO
, 0);
1727 mv64x60_write(bh
, GT64260_IC_PCI0_INTR_MASK_HI
, 0);
1728 mv64x60_write(bh
, GT64260_IC_PCI1_INTR_MASK_LO
, 0);
1729 mv64x60_write(bh
, GT64260_IC_PCI1_INTR_MASK_HI
, 0);
1730 mv64x60_write(bh
, GT64260_IC_CPU_INT_0_MASK
, 0);
1731 mv64x60_write(bh
, GT64260_IC_CPU_INT_1_MASK
, 0);
1732 mv64x60_write(bh
, GT64260_IC_CPU_INT_2_MASK
, 0);
1733 mv64x60_write(bh
, GT64260_IC_CPU_INT_3_MASK
, 0);
1737 * gt64260a_chip_specific_init()
1739 * Implement errata workarounds for the GT64260A.
1742 gt64260a_chip_specific_init(struct mv64x60_handle
*bh
,
1743 struct mv64x60_setup_info
*si
)
1745 #ifdef CONFIG_SERIAL_MPSC
1748 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1753 if (si
->pci_0
.enable_bus
)
1754 mv64x60_set_bits(bh
, MV64x60_PCI0_CMD
,
1755 ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
1757 if (si
->pci_1
.enable_bus
)
1758 mv64x60_set_bits(bh
, MV64x60_PCI1_CMD
,
1759 ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
1762 * Dave Wilhardt found that bit 4 in the PCI Command registers must
1763 * be set if you are using cache coherency.
1765 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1766 /* Res #MEM-4 -- cpu read buffer to buffer 1 */
1767 if ((mv64x60_read(bh
, MV64x60_CPU_MODE
) & 0xf0) == 0x40)
1768 mv64x60_set_bits(bh
, GT64260_SDRAM_CONFIG
, (1<<26));
1770 save_exclude
= mv64x60_pci_exclude_bridge
;
1771 mv64x60_pci_exclude_bridge
= 0;
1772 if (si
->pci_0
.enable_bus
) {
1773 early_read_config_dword(bh
->hose_a
, 0, PCI_DEVFN(0,0),
1775 val
|= PCI_COMMAND_INVALIDATE
;
1776 early_write_config_dword(bh
->hose_a
, 0, PCI_DEVFN(0,0),
1780 if (si
->pci_1
.enable_bus
) {
1781 early_read_config_dword(bh
->hose_b
, 0, PCI_DEVFN(0,0),
1783 val
|= PCI_COMMAND_INVALIDATE
;
1784 early_write_config_dword(bh
->hose_b
, 0, PCI_DEVFN(0,0),
1787 mv64x60_pci_exclude_bridge
= save_exclude
;
1790 /* Disable buffer/descriptor snooping */
1791 mv64x60_clr_bits(bh
, 0xf280, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
1792 mv64x60_clr_bits(bh
, 0xf2c0, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
1794 #ifdef CONFIG_SERIAL_MPSC
1795 mv64x60_mpsc0_pdata
.mirror_regs
= 1;
1796 mv64x60_mpsc0_pdata
.cache_mgmt
= 1;
1797 mv64x60_mpsc1_pdata
.mirror_regs
= 1;
1798 mv64x60_mpsc1_pdata
.cache_mgmt
= 1;
1800 if ((r
= platform_get_resource(&mpsc1_device
, IORESOURCE_IRQ
, 0))
1802 r
->start
= MV64x60_IRQ_SDMA_0
;
1803 r
->end
= MV64x60_IRQ_SDMA_0
;
1809 * gt64260b_chip_specific_init()
1811 * Implement errata workarounds for the GT64260B.
1814 gt64260b_chip_specific_init(struct mv64x60_handle
*bh
,
1815 struct mv64x60_setup_info
*si
)
1817 #ifdef CONFIG_SERIAL_MPSC
1820 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1825 if (si
->pci_0
.enable_bus
)
1826 mv64x60_set_bits(bh
, MV64x60_PCI0_CMD
,
1827 ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
1829 if (si
->pci_1
.enable_bus
)
1830 mv64x60_set_bits(bh
, MV64x60_PCI1_CMD
,
1831 ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
1834 * Dave Wilhardt found that bit 4 in the PCI Command registers must
1835 * be set if you are using cache coherency.
1837 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1838 mv64x60_set_bits(bh
, GT64260_CPU_WB_PRIORITY_BUFFER_DEPTH
, 0xf);
1840 /* Res #MEM-4 -- cpu read buffer to buffer 1 */
1841 if ((mv64x60_read(bh
, MV64x60_CPU_MODE
) & 0xf0) == 0x40)
1842 mv64x60_set_bits(bh
, GT64260_SDRAM_CONFIG
, (1<<26));
1844 save_exclude
= mv64x60_pci_exclude_bridge
;
1845 mv64x60_pci_exclude_bridge
= 0;
1846 if (si
->pci_0
.enable_bus
) {
1847 early_read_config_dword(bh
->hose_a
, 0, PCI_DEVFN(0,0),
1849 val
|= PCI_COMMAND_INVALIDATE
;
1850 early_write_config_dword(bh
->hose_a
, 0, PCI_DEVFN(0,0),
1854 if (si
->pci_1
.enable_bus
) {
1855 early_read_config_dword(bh
->hose_b
, 0, PCI_DEVFN(0,0),
1857 val
|= PCI_COMMAND_INVALIDATE
;
1858 early_write_config_dword(bh
->hose_b
, 0, PCI_DEVFN(0,0),
1861 mv64x60_pci_exclude_bridge
= save_exclude
;
1864 /* Disable buffer/descriptor snooping */
1865 mv64x60_clr_bits(bh
, 0xf280, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
1866 mv64x60_clr_bits(bh
, 0xf2c0, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
1868 #ifdef CONFIG_SERIAL_MPSC
1870 * The 64260B is not supposed to have the bug where the MPSC & ENET
1871 * can't access cache coherent regions. However, testing has shown
1872 * that the MPSC, at least, still has this bug.
1874 mv64x60_mpsc0_pdata
.cache_mgmt
= 1;
1875 mv64x60_mpsc1_pdata
.cache_mgmt
= 1;
1877 if ((r
= platform_get_resource(&mpsc1_device
, IORESOURCE_IRQ
, 0))
1879 r
->start
= MV64x60_IRQ_SDMA_0
;
1880 r
->end
= MV64x60_IRQ_SDMA_0
;
1886 *****************************************************************************
1888 * MV64360-Specific Routines
1890 *****************************************************************************
1893 * mv64360_translate_size()
1895 * On the MV64360, the size register is set similar to the size you get
1896 * from a pci config space BAR register. That is, programmed from LSB to MSB
1897 * as a sequence of 1's followed by a sequence of 0's. IOW, "size -1" with the
1898 * assumption that the size is a power of 2.
1901 mv64360_translate_size(u32 base_addr
, u32 size
, u32 num_bits
)
1903 return mv64x60_mask(size
- 1, num_bits
);
1907 * mv64360_untranslate_size()
1909 * Translate the size register value of a window into a window size.
1912 mv64360_untranslate_size(u32 base_addr
, u32 size
, u32 num_bits
)
1915 size
>>= (32 - num_bits
);
1917 size
<<= (32 - num_bits
);
1924 * mv64360_set_pci2mem_window()
1926 * The PCI->MEM window registers are actually in PCI config space so need
1927 * to set them by setting the correct config space BARs.
1933 } static mv64360_reg_addrs
[2][4] __initdata
= {
1934 {{ 0, 0x14, 0x10 }, { 0, 0x1c, 0x18 },
1935 { 1, 0x14, 0x10 }, { 1, 0x1c, 0x18 }},
1936 {{ 0, 0x94, 0x90 }, { 0, 0x9c, 0x98 },
1937 { 1, 0x94, 0x90 }, { 1, 0x9c, 0x98 }}
1941 mv64360_set_pci2mem_window(struct pci_controller
*hose
, u32 bus
, u32 window
,
1946 pr_debug("set pci->mem window: %d, hose: %d, base: 0x%x\n", window
,
1949 save_exclude
= mv64x60_pci_exclude_bridge
;
1950 mv64x60_pci_exclude_bridge
= 0;
1951 early_write_config_dword(hose
, 0,
1952 PCI_DEVFN(0, mv64360_reg_addrs
[bus
][window
].fcn
),
1953 mv64360_reg_addrs
[bus
][window
].base_hi_bar
, 0);
1954 early_write_config_dword(hose
, 0,
1955 PCI_DEVFN(0, mv64360_reg_addrs
[bus
][window
].fcn
),
1956 mv64360_reg_addrs
[bus
][window
].base_lo_bar
,
1957 mv64x60_mask(base
,20) | 0xc);
1958 mv64x60_pci_exclude_bridge
= save_exclude
;
1962 * mv64360_set_pci2regs_window()
1964 * Set where the bridge's registers appear in PCI MEM space.
1966 static u32 mv64360_offset
[2][2] __initdata
= {{0x20, 0x24}, {0xa0, 0xa4}};
1969 mv64360_set_pci2regs_window(struct mv64x60_handle
*bh
,
1970 struct pci_controller
*hose
, u32 bus
, u32 base
)
1974 pr_debug("set pci->internal regs hose: %d, base: 0x%x\n", hose
->index
,
1977 save_exclude
= mv64x60_pci_exclude_bridge
;
1978 mv64x60_pci_exclude_bridge
= 0;
1979 early_write_config_dword(hose
, 0, PCI_DEVFN(0,0),
1980 mv64360_offset
[bus
][0], (base
<< 16));
1981 early_write_config_dword(hose
, 0, PCI_DEVFN(0,0),
1982 mv64360_offset
[bus
][1], 0);
1983 mv64x60_pci_exclude_bridge
= save_exclude
;
1987 * mv64360_is_enabled_32bit()
1989 * On a MV64360, a window is enabled by either clearing a bit in the
1990 * CPU BAR Enable reg or setting a bit in the window's base reg.
1991 * Note that this doesn't work for windows on the PCI slave side but we don't
1992 * check those so its okay.
1995 mv64360_is_enabled_32bit(struct mv64x60_handle
*bh
, u32 window
)
1999 if (((mv64360_32bit_windows
[window
].base_reg
!= 0) &&
2000 (mv64360_32bit_windows
[window
].size_reg
!= 0)) ||
2001 (window
== MV64x60_CPU2SRAM_WIN
)) {
2003 extra
= mv64360_32bit_windows
[window
].extra
;
2005 switch (extra
& MV64x60_EXTRA_MASK
) {
2006 case MV64x60_EXTRA_CPUWIN_ENAB
:
2007 rc
= (mv64x60_read(bh
, MV64360_CPU_BAR_ENABLE
) &
2008 (1 << (extra
& 0x1f))) == 0;
2011 case MV64x60_EXTRA_CPUPROT_ENAB
:
2012 rc
= (mv64x60_read(bh
,
2013 mv64360_32bit_windows
[window
].base_reg
) &
2014 (1 << (extra
& 0x1f))) != 0;
2017 case MV64x60_EXTRA_ENET_ENAB
:
2018 rc
= (mv64x60_read(bh
, MV64360_ENET2MEM_BAR_ENABLE
) &
2019 (1 << (extra
& 0x7))) == 0;
2022 case MV64x60_EXTRA_MPSC_ENAB
:
2023 rc
= (mv64x60_read(bh
, MV64360_MPSC2MEM_BAR_ENABLE
) &
2024 (1 << (extra
& 0x3))) == 0;
2027 case MV64x60_EXTRA_IDMA_ENAB
:
2028 rc
= (mv64x60_read(bh
, MV64360_IDMA2MEM_BAR_ENABLE
) &
2029 (1 << (extra
& 0x7))) == 0;
2033 printk(KERN_ERR
"mv64360_is_enabled: %s\n",
2034 "32bit table corrupted");
2042 * mv64360_enable_window_32bit()
2044 * On a MV64360, a window is enabled by either clearing a bit in the
2045 * CPU BAR Enable reg or setting a bit in the window's base reg.
2048 mv64360_enable_window_32bit(struct mv64x60_handle
*bh
, u32 window
)
2052 pr_debug("enable 32bit window: %d\n", window
);
2054 if (((mv64360_32bit_windows
[window
].base_reg
!= 0) &&
2055 (mv64360_32bit_windows
[window
].size_reg
!= 0)) ||
2056 (window
== MV64x60_CPU2SRAM_WIN
)) {
2058 extra
= mv64360_32bit_windows
[window
].extra
;
2060 switch (extra
& MV64x60_EXTRA_MASK
) {
2061 case MV64x60_EXTRA_CPUWIN_ENAB
:
2062 mv64x60_clr_bits(bh
, MV64360_CPU_BAR_ENABLE
,
2063 (1 << (extra
& 0x1f)));
2066 case MV64x60_EXTRA_CPUPROT_ENAB
:
2067 mv64x60_set_bits(bh
,
2068 mv64360_32bit_windows
[window
].base_reg
,
2069 (1 << (extra
& 0x1f)));
2072 case MV64x60_EXTRA_ENET_ENAB
:
2073 mv64x60_clr_bits(bh
, MV64360_ENET2MEM_BAR_ENABLE
,
2074 (1 << (extra
& 0x7)));
2077 case MV64x60_EXTRA_MPSC_ENAB
:
2078 mv64x60_clr_bits(bh
, MV64360_MPSC2MEM_BAR_ENABLE
,
2079 (1 << (extra
& 0x3)));
2082 case MV64x60_EXTRA_IDMA_ENAB
:
2083 mv64x60_clr_bits(bh
, MV64360_IDMA2MEM_BAR_ENABLE
,
2084 (1 << (extra
& 0x7)));
2088 printk(KERN_ERR
"mv64360_enable: %s\n",
2089 "32bit table corrupted");
2095 * mv64360_disable_window_32bit()
2097 * On a MV64360, a window is disabled by either setting a bit in the
2098 * CPU BAR Enable reg or clearing a bit in the window's base reg.
2101 mv64360_disable_window_32bit(struct mv64x60_handle
*bh
, u32 window
)
2105 pr_debug("disable 32bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
2106 window
, mv64360_32bit_windows
[window
].base_reg
,
2107 mv64360_32bit_windows
[window
].size_reg
);
2109 if (((mv64360_32bit_windows
[window
].base_reg
!= 0) &&
2110 (mv64360_32bit_windows
[window
].size_reg
!= 0)) ||
2111 (window
== MV64x60_CPU2SRAM_WIN
)) {
2113 extra
= mv64360_32bit_windows
[window
].extra
;
2115 switch (extra
& MV64x60_EXTRA_MASK
) {
2116 case MV64x60_EXTRA_CPUWIN_ENAB
:
2117 mv64x60_set_bits(bh
, MV64360_CPU_BAR_ENABLE
,
2118 (1 << (extra
& 0x1f)));
2121 case MV64x60_EXTRA_CPUPROT_ENAB
:
2122 mv64x60_clr_bits(bh
,
2123 mv64360_32bit_windows
[window
].base_reg
,
2124 (1 << (extra
& 0x1f)));
2127 case MV64x60_EXTRA_ENET_ENAB
:
2128 mv64x60_set_bits(bh
, MV64360_ENET2MEM_BAR_ENABLE
,
2129 (1 << (extra
& 0x7)));
2132 case MV64x60_EXTRA_MPSC_ENAB
:
2133 mv64x60_set_bits(bh
, MV64360_MPSC2MEM_BAR_ENABLE
,
2134 (1 << (extra
& 0x3)));
2137 case MV64x60_EXTRA_IDMA_ENAB
:
2138 mv64x60_set_bits(bh
, MV64360_IDMA2MEM_BAR_ENABLE
,
2139 (1 << (extra
& 0x7)));
2143 printk(KERN_ERR
"mv64360_disable: %s\n",
2144 "32bit table corrupted");
2150 * mv64360_enable_window_64bit()
2152 * On the MV64360, a 64-bit window is enabled by setting a bit in the window's
2156 mv64360_enable_window_64bit(struct mv64x60_handle
*bh
, u32 window
)
2158 pr_debug("enable 64bit window: %d\n", window
);
2160 if ((mv64360_64bit_windows
[window
].base_lo_reg
!= 0) &&
2161 (mv64360_64bit_windows
[window
].size_reg
!= 0)) {
2163 if ((mv64360_64bit_windows
[window
].extra
& MV64x60_EXTRA_MASK
)
2164 == MV64x60_EXTRA_PCIACC_ENAB
)
2165 mv64x60_set_bits(bh
,
2166 mv64360_64bit_windows
[window
].base_lo_reg
,
2167 (1 << (mv64360_64bit_windows
[window
].extra
&
2170 printk(KERN_ERR
"mv64360_enable: %s\n",
2171 "64bit table corrupted");
2176 * mv64360_disable_window_64bit()
2178 * On a MV64360, a 64-bit window is disabled by clearing a bit in the window's
2182 mv64360_disable_window_64bit(struct mv64x60_handle
*bh
, u32 window
)
2184 pr_debug("disable 64bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
2185 window
, mv64360_64bit_windows
[window
].base_lo_reg
,
2186 mv64360_64bit_windows
[window
].size_reg
);
2188 if ((mv64360_64bit_windows
[window
].base_lo_reg
!= 0) &&
2189 (mv64360_64bit_windows
[window
].size_reg
!= 0)) {
2190 if ((mv64360_64bit_windows
[window
].extra
& MV64x60_EXTRA_MASK
)
2191 == MV64x60_EXTRA_PCIACC_ENAB
)
2192 mv64x60_clr_bits(bh
,
2193 mv64360_64bit_windows
[window
].base_lo_reg
,
2194 (1 << (mv64360_64bit_windows
[window
].extra
&
2197 printk(KERN_ERR
"mv64360_disable: %s\n",
2198 "64bit table corrupted");
2203 * mv64360_disable_all_windows()
2205 * The MV64360 has a few windows that aren't represented in the table of
2206 * windows at the top of this file. This routine turns all of them off
2207 * except for the memory controller windows, of course.
2210 mv64360_disable_all_windows(struct mv64x60_handle
*bh
,
2211 struct mv64x60_setup_info
*si
)
2215 /* Disable 32bit windows (don't disable cpu->mem windows) */
2216 for (i
=MV64x60_CPU2DEV_0_WIN
; i
<MV64x60_32BIT_WIN_COUNT
; i
++) {
2218 preserve
= si
->window_preserve_mask_32_lo
& (1 << i
);
2220 preserve
= si
->window_preserve_mask_32_hi
& (1<<(i
-32));
2223 mv64360_disable_window_32bit(bh
, i
);
2226 /* Disable 64bit windows */
2227 for (i
=0; i
<MV64x60_64BIT_WIN_COUNT
; i
++)
2228 if (!(si
->window_preserve_mask_64
& (1<<i
)))
2229 mv64360_disable_window_64bit(bh
, i
);
2231 /* Turn off PCI->MEM access cntl wins not in mv64360_64bit_windows[] */
2232 mv64x60_clr_bits(bh
, MV64x60_PCI0_ACC_CNTL_4_BASE_LO
, 0);
2233 mv64x60_clr_bits(bh
, MV64x60_PCI0_ACC_CNTL_5_BASE_LO
, 0);
2234 mv64x60_clr_bits(bh
, MV64x60_PCI1_ACC_CNTL_4_BASE_LO
, 0);
2235 mv64x60_clr_bits(bh
, MV64x60_PCI1_ACC_CNTL_5_BASE_LO
, 0);
2237 /* Disable all PCI-><whatever> windows */
2238 mv64x60_set_bits(bh
, MV64x60_PCI0_BAR_ENABLE
, 0x0000f9ff);
2239 mv64x60_set_bits(bh
, MV64x60_PCI1_BAR_ENABLE
, 0x0000f9ff);
2243 * mv64360_config_io2mem_windows()
2245 * ENET, MPSC, and IDMA ctlrs on the MV64[34]60 have separate windows that
2246 * must be set up so that the respective ctlr can access system memory.
2248 static u32 enet_tab
[MV64x60_CPU2MEM_WINDOWS
] __initdata
= {
2249 MV64x60_ENET2MEM_0_WIN
, MV64x60_ENET2MEM_1_WIN
,
2250 MV64x60_ENET2MEM_2_WIN
, MV64x60_ENET2MEM_3_WIN
,
2253 static u32 mpsc_tab
[MV64x60_CPU2MEM_WINDOWS
] __initdata
= {
2254 MV64x60_MPSC2MEM_0_WIN
, MV64x60_MPSC2MEM_1_WIN
,
2255 MV64x60_MPSC2MEM_2_WIN
, MV64x60_MPSC2MEM_3_WIN
,
2258 static u32 idma_tab
[MV64x60_CPU2MEM_WINDOWS
] __initdata
= {
2259 MV64x60_IDMA2MEM_0_WIN
, MV64x60_IDMA2MEM_1_WIN
,
2260 MV64x60_IDMA2MEM_2_WIN
, MV64x60_IDMA2MEM_3_WIN
,
2263 static u32 dram_selects
[MV64x60_CPU2MEM_WINDOWS
] __initdata
=
2264 { 0xe, 0xd, 0xb, 0x7 };
2267 mv64360_config_io2mem_windows(struct mv64x60_handle
*bh
,
2268 struct mv64x60_setup_info
*si
,
2269 u32 mem_windows
[MV64x60_CPU2MEM_WINDOWS
][2])
2273 pr_debug("config_io2regs_windows: enet, mpsc, idma -> bridge regs\n");
2275 mv64x60_write(bh
, MV64360_ENET2MEM_ACC_PROT_0
, 0);
2276 mv64x60_write(bh
, MV64360_ENET2MEM_ACC_PROT_1
, 0);
2277 mv64x60_write(bh
, MV64360_ENET2MEM_ACC_PROT_2
, 0);
2279 mv64x60_write(bh
, MV64360_MPSC2MEM_ACC_PROT_0
, 0);
2280 mv64x60_write(bh
, MV64360_MPSC2MEM_ACC_PROT_1
, 0);
2282 mv64x60_write(bh
, MV64360_IDMA2MEM_ACC_PROT_0
, 0);
2283 mv64x60_write(bh
, MV64360_IDMA2MEM_ACC_PROT_1
, 0);
2284 mv64x60_write(bh
, MV64360_IDMA2MEM_ACC_PROT_2
, 0);
2285 mv64x60_write(bh
, MV64360_IDMA2MEM_ACC_PROT_3
, 0);
2287 /* Assume that mem ctlr has no more windows than embedded I/O ctlr */
2288 for (win
=MV64x60_CPU2MEM_0_WIN
,i
=0;win
<=MV64x60_CPU2MEM_3_WIN
;win
++,i
++)
2289 if (bh
->ci
->is_enabled_32bit(bh
, win
)) {
2290 mv64x60_set_32bit_window(bh
, enet_tab
[i
],
2291 mem_windows
[i
][0], mem_windows
[i
][1],
2292 (dram_selects
[i
] << 8) |
2293 (si
->enet_options
[i
] & 0x3000));
2294 bh
->ci
->enable_window_32bit(bh
, enet_tab
[i
]);
2296 /* Give enet r/w access to memory region */
2297 mv64x60_set_bits(bh
, MV64360_ENET2MEM_ACC_PROT_0
,
2299 mv64x60_set_bits(bh
, MV64360_ENET2MEM_ACC_PROT_1
,
2301 mv64x60_set_bits(bh
, MV64360_ENET2MEM_ACC_PROT_2
,
2304 mv64x60_set_32bit_window(bh
, mpsc_tab
[i
],
2305 mem_windows
[i
][0], mem_windows
[i
][1],
2306 (dram_selects
[i
] << 8) |
2307 (si
->mpsc_options
[i
] & 0x3000));
2308 bh
->ci
->enable_window_32bit(bh
, mpsc_tab
[i
]);
2310 /* Give mpsc r/w access to memory region */
2311 mv64x60_set_bits(bh
, MV64360_MPSC2MEM_ACC_PROT_0
,
2313 mv64x60_set_bits(bh
, MV64360_MPSC2MEM_ACC_PROT_1
,
2316 mv64x60_set_32bit_window(bh
, idma_tab
[i
],
2317 mem_windows
[i
][0], mem_windows
[i
][1],
2318 (dram_selects
[i
] << 8) |
2319 (si
->idma_options
[i
] & 0x3000));
2320 bh
->ci
->enable_window_32bit(bh
, idma_tab
[i
]);
2322 /* Give idma r/w access to memory region */
2323 mv64x60_set_bits(bh
, MV64360_IDMA2MEM_ACC_PROT_0
,
2325 mv64x60_set_bits(bh
, MV64360_IDMA2MEM_ACC_PROT_1
,
2327 mv64x60_set_bits(bh
, MV64360_IDMA2MEM_ACC_PROT_2
,
2329 mv64x60_set_bits(bh
, MV64360_IDMA2MEM_ACC_PROT_3
,
2335 * mv64360_set_mpsc2regs_window()
2337 * MPSC has a window to the bridge's internal registers. Call this routine
2338 * to change that window so it doesn't conflict with the windows mapping the
2339 * mpsc to system memory.
2342 mv64360_set_mpsc2regs_window(struct mv64x60_handle
*bh
, u32 base
)
2344 pr_debug("set mpsc->internal regs, base: 0x%x\n", base
);
2345 mv64x60_write(bh
, MV64360_MPSC2REGS_BASE
, base
& 0xffff0000);
2349 * mv64360_chip_specific_init()
2351 * Implement errata workarounds for the MV64360.
2354 mv64360_chip_specific_init(struct mv64x60_handle
*bh
,
2355 struct mv64x60_setup_info
*si
)
2357 #if !defined(CONFIG_NOT_COHERENT_CACHE)
2358 mv64x60_set_bits(bh
, MV64360_D_UNIT_CONTROL_HIGH
, (1<<24));
2360 #ifdef CONFIG_SERIAL_MPSC
2361 mv64x60_mpsc0_pdata
.brg_can_tune
= 1;
2362 mv64x60_mpsc0_pdata
.cache_mgmt
= 1;
2363 mv64x60_mpsc1_pdata
.brg_can_tune
= 1;
2364 mv64x60_mpsc1_pdata
.cache_mgmt
= 1;
2369 * mv64460_chip_specific_init()
2371 * Implement errata workarounds for the MV64460.
2374 mv64460_chip_specific_init(struct mv64x60_handle
*bh
,
2375 struct mv64x60_setup_info
*si
)
2377 #if !defined(CONFIG_NOT_COHERENT_CACHE)
2378 mv64x60_set_bits(bh
, MV64360_D_UNIT_CONTROL_HIGH
, (1<<24) | (1<<25));
2379 mv64x60_set_bits(bh
, MV64460_D_UNIT_MMASK
, (1<<1) | (1<<4));
2381 #ifdef CONFIG_SERIAL_MPSC
2382 mv64x60_mpsc0_pdata
.brg_can_tune
= 1;
2383 mv64x60_mpsc0_pdata
.cache_mgmt
= 1;
2384 mv64x60_mpsc1_pdata
.brg_can_tune
= 1;
2385 mv64x60_mpsc1_pdata
.cache_mgmt
= 1;
2390 #if defined(CONFIG_SYSFS) && !defined(CONFIG_GT64260)
2391 /* Export the hotswap register via sysfs for enum event monitoring */
2392 #define VAL_LEN_MAX 11 /* 32-bit hex or dec stringified number + '\n' */
2394 static DEFINE_MUTEX(mv64xxx_hs_lock
);
2397 mv64xxx_hs_reg_read(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
2404 if (count
< VAL_LEN_MAX
)
2407 if (mutex_lock_interruptible(&mv64xxx_hs_lock
))
2408 return -ERESTARTSYS
;
2409 save_exclude
= mv64x60_pci_exclude_bridge
;
2410 mv64x60_pci_exclude_bridge
= 0;
2411 early_read_config_dword(&sysfs_hose_a
, 0, PCI_DEVFN(0, 0),
2412 MV64360_PCICFG_CPCI_HOTSWAP
, &v
);
2413 mv64x60_pci_exclude_bridge
= save_exclude
;
2414 mutex_unlock(&mv64xxx_hs_lock
);
2416 return sprintf(buf
, "0x%08x\n", v
);
2420 mv64xxx_hs_reg_write(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
2430 if (sscanf(buf
, "%i", &v
) == 1) {
2431 if (mutex_lock_interruptible(&mv64xxx_hs_lock
))
2432 return -ERESTARTSYS
;
2433 save_exclude
= mv64x60_pci_exclude_bridge
;
2434 mv64x60_pci_exclude_bridge
= 0;
2435 early_write_config_dword(&sysfs_hose_a
, 0, PCI_DEVFN(0, 0),
2436 MV64360_PCICFG_CPCI_HOTSWAP
, v
);
2437 mv64x60_pci_exclude_bridge
= save_exclude
;
2438 mutex_unlock(&mv64xxx_hs_lock
);
2446 static struct bin_attribute mv64xxx_hs_reg_attr
= { /* Hotswap register */
2449 .mode
= S_IRUGO
| S_IWUSR
,
2451 .size
= VAL_LEN_MAX
,
2452 .read
= mv64xxx_hs_reg_read
,
2453 .write
= mv64xxx_hs_reg_write
,
2456 /* Provide sysfs file indicating if this platform supports the hs_reg */
2458 mv64xxx_hs_reg_valid_show(struct device
*dev
, struct device_attribute
*attr
,
2461 struct platform_device
*pdev
;
2462 struct mv64xxx_pdata
*pdp
;
2465 pdev
= container_of(dev
, struct platform_device
, dev
);
2466 pdp
= (struct mv64xxx_pdata
*)pdev
->dev
.platform_data
;
2468 if (mutex_lock_interruptible(&mv64xxx_hs_lock
))
2469 return -ERESTARTSYS
;
2470 v
= pdp
->hs_reg_valid
;
2471 mutex_unlock(&mv64xxx_hs_lock
);
2473 return sprintf(buf
, "%i\n", v
);
2475 static DEVICE_ATTR(hs_reg_valid
, S_IRUGO
, mv64xxx_hs_reg_valid_show
, NULL
);
2478 mv64xxx_sysfs_init(void)
2480 sysfs_create_bin_file(&mv64xxx_device
.dev
.kobj
, &mv64xxx_hs_reg_attr
);
2481 sysfs_create_file(&mv64xxx_device
.dev
.kobj
,&dev_attr_hs_reg_valid
.attr
);
2484 subsys_initcall(mv64xxx_sysfs_init
);