3 Copyright 2002 Broadcom Corp. All Rights Reserved.
5 This program is free software; you can distribute it and/or modify it
6 under the terms of the GNU General Public License (Version 2) as
7 published by the Free Software Foundation.
9 This program is distributed in the hope it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
20 * Generic setup routines for Broadcom 963xx MIPS boards
23 #include <linux/config.h>
24 #include <linux/init.h>
25 #include <linux/interrupt.h>
26 #include <linux/kernel.h>
27 #include <linux/kdev_t.h>
28 #include <linux/types.h>
29 #include <linux/console.h>
30 #include <linux/sched.h>
32 #include <linux/slab.h>
33 #include <linux/module.h>
34 #include <linux/delay.h>
36 #include <asm/addrspace.h>
37 #include <asm/bcache.h>
40 #include <asm/reboot.h>
41 #include <asm/gdb-stub.h>
43 extern void brcm_timer_setup(struct irqaction *irq);
44 extern unsigned long getMemorySize(void);
46 #include <bcm_map_part.h>
48 #if defined(CONFIG_PCI)
49 #include <linux/pci.h>
53 /* This function should be in a board specific directory. For now,
54 * assume that all boards that include this file use a Broadcom chip
55 * with a soft reset bit in the PLL control register.
57 static void brcm_machine_restart(char *command)
59 PERF->pll_control |= SOFT_RESET;
62 static void brcm_machine_halt(void)
64 printk("System halted\n");
68 #if defined(CONFIG_PCI)
70 static void mpi_SetLocalPciConfigReg(uint32 reg, uint32 value)
72 /* write index then value */
73 MPI->pcicfgcntrl = PCI_CFG_REG_WRITE_EN + reg;;
74 MPI->pcicfgdata = value;
77 static uint32 mpi_GetLocalPciConfigReg(uint32 reg)
79 /* write index then get value */
80 MPI->pcicfgcntrl = PCI_CFG_REG_WRITE_EN + reg;;
81 return MPI->pcicfgdata;
85 * mpi_ResetPcCard: Set/Reset the PcCard
87 static void mpi_ResetPcCard(int cardtype, BOOL bReset)
89 if (cardtype == MPI_CARDTYPE_NONE) {
93 if (cardtype == MPI_CARDTYPE_CARDBUS) {
98 MPI->pcmcia_cntl1 = (MPI->pcmcia_cntl1 & ~PCCARD_CARD_RESET);
100 MPI->pcmcia_cntl1 = (MPI->pcmcia_cntl1 | PCCARD_CARD_RESET);
105 * mpi_ConfigCs: Configure an MPI/EBI chip select
107 static void mpi_ConfigCs(uint32 cs, uint32 base, uint32 size, uint32 flags)
109 MPI->cs[cs].base = ((base & 0x1FFFFFFF) | size);
110 MPI->cs[cs].config = flags;
114 * mpi_InitPcmciaSpace
116 static void mpi_InitPcmciaSpace(void)
118 // ChipSelect 4 controls PCMCIA Memory accesses
119 mpi_ConfigCs(PCMCIA_COMMON_BASE, pcmciaMem, EBI_SIZE_1M, (EBI_WORD_WIDE|EBI_ENABLE));
120 // ChipSelect 5 controls PCMCIA Attribute accesses
121 mpi_ConfigCs(PCMCIA_ATTRIBUTE_BASE, pcmciaAttr, EBI_SIZE_1M, (EBI_WORD_WIDE|EBI_ENABLE));
122 // ChipSelect 6 controls PCMCIA I/O accesses
123 mpi_ConfigCs(PCMCIA_IO_BASE, pcmciaIo, EBI_SIZE_64K, (EBI_WORD_WIDE|EBI_ENABLE));
125 MPI->pcmcia_cntl2 = ((PCMCIA_ATTR_ACTIVE << RW_ACTIVE_CNT_BIT) |
126 (PCMCIA_ATTR_INACTIVE << INACTIVE_CNT_BIT) |
127 (PCMCIA_ATTR_CE_SETUP << CE_SETUP_CNT_BIT) |
128 (PCMCIA_ATTR_CE_HOLD << CE_HOLD_CNT_BIT));
130 MPI->pcmcia_cntl2 |= (PCMCIA_HALFWORD_EN | PCMCIA_BYTESWAP_DIS);
134 * cardtype_vcc_detect: PC Card's card detect and voltage sense connection
136 * CD1#/ CD2#/ VS1#/ VS2#/ Card Initial Vcc
137 * CCD1# CCD2# CVS1 CVS2 Type
139 * GND GND open open 16-bit 5 vdc
141 * GND GND GND open 16-bit 3.3 vdc
143 * GND GND open GND 16-bit x.x vdc
145 * GND GND GND GND 16-bit 3.3 & x.x vdc
147 *====================================================================
149 * CVS1 GND CCD1# open CardBus 3.3 vdc
151 * GND CVS2 open CCD2# CardBus x.x vdc
153 * GND CVS1 CCD2# open CardBus y.y vdc
155 * GND CVS2 GND CCD2# CardBus 3.3 & x.x vdc
157 * CVS2 GND open CCD1# CardBus x.x & y.y vdc
159 * GND CVS1 CCD2# open CardBus 3.3, x.x & y.y vdc
162 static int cardtype_vcc_detect(void)
167 cardtype = MPI_CARDTYPE_NONE;
168 MPI->pcmcia_cntl1 = (CARDBUS_ENABLE|PCMCIA_GPIO_ENABLE); // Turn on the output enables and drive
169 // the CVS pins to 0.
170 data32 = MPI->pcmcia_cntl1;
171 switch (data32 & (CD2_IN|CD1_IN)) // Test CD1# and CD2#, see if card is plugged in.
173 case (CD2_IN|CD1_IN): // No Card is in the slot.
174 printk("MPI: No Card is in the PCMCIA slot\n");
177 case CD2_IN: // Partial insertion, No CD2#.
178 printk("MPI: Card in the PCMCIA slot partial insertion, no CD2 signal\n");
181 case CD1_IN: // Partial insertion, No CD1#.
182 printk("MPI: Card in the PCMCIA slot partial insertion, no CD1 signal\n");
186 MPI->pcmcia_cntl1 = (CARDBUS_ENABLE|PCMCIA_GPIO_ENABLE|VS2_OEN|VS1_OEN);
187 // Turn off the CVS output enables and
188 // float the CVS pins.
190 data32 = MPI->pcmcia_cntl1;
191 // Read the Register.
192 switch (data32 & (VS2_IN|VS1_IN)) // See what is on the CVS pins.
194 case 0x00000000: // CVS1 and CVS2 are tied to ground, only 1 option.
195 printk("MPI: Detected 3.3 & x.x 16-bit PCMCIA card\n");
196 cardtype = MPI_CARDTYPE_PCMCIA;
199 case VS1_IN: // CVS1 is open or tied to CCD1/CCD2 and CVS2 is tied to ground.
200 // 2 valid voltage options.
201 switch (data32 & (CD2_IN|CD1_IN)) // Test the values of CCD1 and CCD2.
203 case (CD2_IN|CD1_IN): // CCD1 and CCD2 are tied to 1 of the CVS pins.
204 // This is not a valid combination.
205 printk("MPI: Unknown card plugged into slot\n");
208 case CD2_IN: // CCD2 is tied to either CVS1 or CVS2.
209 MPI->pcmcia_cntl1 = (CARDBUS_ENABLE|PCMCIA_GPIO_ENABLE|VS2_OEN); // Drive CVS1 to a 0.
211 data32 = MPI->pcmcia_cntl1;
212 if (data32 & CD2_IN) { // CCD2 is tied to CVS2, not valid.
213 printk("MPI: Unknown card plugged into slot\n");
214 } else { // CCD2 is tied to CVS1.
215 printk("MPI: Detected 3.3, x.x and y.y Cardbus card\n");
216 cardtype = MPI_CARDTYPE_CARDBUS;
220 case CD1_IN: // CCD1 is tied to either CVS1 or CVS2.
221 // This is not a valid combination.
222 printk("MPI: Unknown card plugged into slot\n");
225 case 0x00000000: // CCD1 and CCD2 are tied to ground.
226 printk("MPI: Detected x.x vdc 16-bit PCMCIA card\n");
227 cardtype = MPI_CARDTYPE_PCMCIA;
232 case VS2_IN: // CVS2 is open or tied to CCD1/CCD2 and CVS1 is tied to ground.
233 // 2 valid voltage options.
234 switch (data32 & (CD2_IN|CD1_IN)) // Test the values of CCD1 and CCD2.
236 case (CD2_IN|CD1_IN): // CCD1 and CCD2 are tied to 1 of the CVS pins.
237 // This is not a valid combination.
238 printk("MPI: Unknown card plugged into slot\n");
241 case CD2_IN: // CCD2 is tied to either CVS1 or CVS2.
242 MPI->pcmcia_cntl1 = (CARDBUS_ENABLE|PCMCIA_GPIO_ENABLE|VS1_OEN);// Drive CVS2 to a 0.
244 data32 = MPI->pcmcia_cntl1;
245 if (data32 & CD2_IN) { // CCD2 is tied to CVS1, not valid.
246 printk("MPI: Unknown card plugged into slot\n");
247 } else {// CCD2 is tied to CVS2.
248 printk("MPI: Detected 3.3 and x.x Cardbus card\n");
249 cardtype = MPI_CARDTYPE_CARDBUS;
253 case CD1_IN: // CCD1 is tied to either CVS1 or CVS2.
254 // This is not a valid combination.
255 printk("MPI: Unknown card plugged into slot\n");
258 case 0x00000000: // CCD1 and CCD2 are tied to ground.
259 cardtype = MPI_CARDTYPE_PCMCIA;
260 printk("MPI: Detected 3.3 vdc 16-bit PCMCIA card\n");
265 case (VS2_IN|VS1_IN): // CVS1 and CVS2 are open or tied to CCD1/CCD2.
266 // 5 valid voltage options.
268 switch (data32 & (CD2_IN|CD1_IN)) // Test the values of CCD1 and CCD2.
270 case (CD2_IN|CD1_IN): // CCD1 and CCD2 are tied to 1 of the CVS pins.
271 // This is not a valid combination.
272 printk("MPI: Unknown card plugged into slot\n");
275 case CD2_IN: // CCD2 is tied to either CVS1 or CVS2.
276 // CCD1 is tied to ground.
277 MPI->pcmcia_cntl1 = (CARDBUS_ENABLE|PCMCIA_GPIO_ENABLE|VS1_OEN);// Drive CVS2 to a 0.
279 data32 = MPI->pcmcia_cntl1;
280 if (data32 & CD2_IN) { // CCD2 is tied to CVS1.
281 printk("MPI: Detected y.y vdc Cardbus card\n");
282 } else { // CCD2 is tied to CVS2.
283 printk("MPI: Detected x.x vdc Cardbus card\n");
285 cardtype = MPI_CARDTYPE_CARDBUS;
288 case CD1_IN: // CCD1 is tied to either CVS1 or CVS2.
289 // CCD2 is tied to ground.
291 MPI->pcmcia_cntl1 = (CARDBUS_ENABLE|PCMCIA_GPIO_ENABLE|VS1_OEN);// Drive CVS2 to a 0.
293 data32 = MPI->pcmcia_cntl1;
294 if (data32 & CD1_IN) {// CCD1 is tied to CVS1.
295 printk("MPI: Detected 3.3 vdc Cardbus card\n");
296 } else { // CCD1 is tied to CVS2.
297 printk("MPI: Detected x.x and y.y Cardbus card\n");
299 cardtype = MPI_CARDTYPE_CARDBUS;
302 case 0x00000000: // CCD1 and CCD2 are tied to ground.
303 cardtype = MPI_CARDTYPE_PCMCIA;
304 printk("MPI: Detected 5 vdc 16-bit PCMCIA card\n");
310 printk("MPI: Unknown card plugged into slot\n");
319 * mpi_DetectPcCard: Detect the plugged in PC-Card
320 * Return: < 0 => Unknown card detected
321 * 0 => No card detected
322 * 1 => 16-bit card detected
323 * 2 => 32-bit CardBus card detected
325 static int mpi_DetectPcCard(void)
329 cardtype = cardtype_vcc_detect();
331 case MPI_CARDTYPE_PCMCIA:
332 MPI->pcmcia_cntl1 &= ~(CARDBUS_ENABLE|PCMCIA_ENABLE|PCMCIA_GPIO_ENABLE); // disable enable bits
333 MPI->pcmcia_cntl1 |= (PCMCIA_ENABLE | PCMCIA_GPIO_ENABLE);
334 mpi_InitPcmciaSpace();
335 mpi_ResetPcCard(cardtype, FALSE);
336 // Hold card in reset for 10ms
338 mpi_ResetPcCard(cardtype, TRUE);
339 // Let card come out of reset
342 case MPI_CARDTYPE_CARDBUS:
343 // 8 => CardBus Enable
344 // 1 => PCI Slot Number
345 // C => Float VS1 & VS2
346 MPI->pcmcia_cntl1 = (MPI->pcmcia_cntl1 & 0xFFFF0000) |
350 VS1_OEN | PCMCIA_GPIO_ENABLE;
351 /* access to this memory window will be to/from CardBus */
352 MPI->l2pmremap1 |= CARDBUS_MEM;
354 // Need to reset the Cardbus Card. There's no CardManager to do this,
355 // and we need to be ready for PCI configuration.
356 mpi_ResetPcCard(cardtype, FALSE);
357 // Hold card in reset for 10ms
359 mpi_ResetPcCard(cardtype, TRUE);
360 // Let card come out of reset
369 static int mpi_init(void)
373 unsigned int chiprev;
374 unsigned int sdramsize;
375 unsigned int modesel;
377 chipid = (PERF->RevID & 0xFFFF0000) >> 16;
378 chiprev = (PERF->RevID & 0xFF);
379 sdramsize = getMemorySize();
381 #if defined(CONFIG_BCM96348)
383 * Init the pci interface
385 data = GPIO->GPIOMode; // GPIO mode register
386 data |= GROUP2_PCI | GROUP1_MII_PCCARD; // PCI internal arbiter + Cardbus
387 GPIO->GPIOMode = data; // PCI internal arbiter
390 * CardBus support is defaulted to Slot 0
391 * because there is no external IDSEL for CardBus. To disable
392 * the CardBus and allow a standard PCI card in Slot 0
393 * set the cbus_idsel field to 0x1f.
396 uData = MPI->pcmcia_cntl1;
397 uData |= CARDBUS_IDSEL;
398 MPI->pcmcia_cntl1 = uData;
401 // UBUS to PCI address range
402 // Memory Window 1. Used for devices in slot 0. Potentially can be CardBus
403 MPI->l2pmrange1 = ~(BCM_PCI_MEM_SIZE_16MB-1);
404 // UBUS to PCI Memory base address. This is akin to the ChipSelect base
406 MPI->l2pmbase1 = BCM_CB_MEM_BASE & BCM_PCI_ADDR_MASK;
407 // UBUS to PCI Remap Address. Replaces the masked address bits in the
408 // range register with this setting.
409 // Also, enable direct I/O and direct Memory accesses
410 MPI->l2pmremap1 = (BCM_PCI_MEM_BASE | MEM_WINDOW_EN);
412 // Memory Window 2. Used for devices in other slots
413 MPI->l2pmrange2 = ~(BCM_PCI_MEM_SIZE_16MB-1);
414 // UBUS to PCI Memory base address.
415 MPI->l2pmbase2 = BCM_PCI_MEM_BASE & BCM_PCI_ADDR_MASK;
416 // UBUS to PCI Remap Address
417 MPI->l2pmremap2 = (BCM_PCI_MEM_BASE | MEM_WINDOW_EN);
419 // Setup PCI I/O Window range. Give 64K to PCI I/O
420 MPI->l2piorange = ~(BCM_PCI_IO_SIZE_64KB-1);
421 // UBUS to PCI I/O base address
422 MPI->l2piobase = BCM_PCI_IO_BASE & BCM_PCI_ADDR_MASK;
423 // UBUS to PCI I/O Window remap
424 MPI->l2pioremap = (BCM_PCI_IO_BASE | MEM_WINDOW_EN);
426 // enable PCI related GPIO pins and data swap between system and PCI bus
427 MPI->locbuscntrl = (EN_PCI_GPIO | DIR_U2P_NOSWAP);
429 /* Enable BusMaster and Memory access mode */
430 data = mpi_GetLocalPciConfigReg(PCI_COMMAND);
431 data |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
432 mpi_SetLocalPciConfigReg(PCI_COMMAND, data);
434 /* Configure two 16 MByte PCI to System memory regions. */
435 /* These memory regions are used when PCI device is a bus master */
436 /* Accesses to the SDRAM from PCI bus will be "byte swapped" for this region */
437 mpi_SetLocalPciConfigReg(PCI_BASE_ADDRESS_3, BCM_HOST_MEM_SPACE1);
439 #if defined(CONFIG_BCM96348)
442 MPI->sp0remap = MEM_WINDOW_EN;
445 /* Accesses to the SDRAM from PCI bus will be "byte swapped" for this region */
446 mpi_SetLocalPciConfigReg(PCI_BASE_ADDRESS_4, BCM_HOST_MEM_SPACE2);
448 #if defined(CONFIG_BCM96348)
451 MPI->sp1remap = MEM_WINDOW_EN;
454 modesel = MPI->pcimodesel;
455 modesel &= ~PCI_INT_BUS_RD_PREFETCH;
456 #if defined(CONFIG_BCM96348)
461 MPI->pcimodesel = modesel;
463 if (!((chipid == 0x6348) && ((chiprev & 0xF0) == 0xa0))) {
464 MPI->sp0range = ~(sdramsize-1);
465 MPI->sp1range = ~(sdramsize-1);
468 * Change PCI Cfg Reg. offset 0x40 to PCI memory read retry count infinity
469 * by set 0 in bit 8~15. This resolve read Bcm4306 srom return 0xffff in
472 data = mpi_GetLocalPciConfigReg(BRCM_PCI_CONFIG_TIMER);
473 data &= ~BRCM_PCI_CONFIG_TIMER_RETRY_MASK;
475 mpi_SetLocalPciConfigReg(BRCM_PCI_CONFIG_TIMER, data);
477 /* enable pci interrupt */
478 MPI->locintstat |= (EXT_PCI_INT << 16);
480 #if !defined(CONFIG_BCM_VDSL)
484 ioport_resource.start = BCM_PCI_IO_BASE;
485 ioport_resource.end = BCM_PCI_IO_BASE + BCM_PCI_IO_SIZE_64KB;
491 static int __init bcm63xx_hw_init(void)
493 #if defined(CONFIG_BCM96338)
495 * atm and sdioh share the same reset bit
496 * issue reset needed such that sdioh can work properly after power cycle
498 PERF->BlockSoftReset &= ~BSR_SAR;
500 PERF->BlockSoftReset |= BSR_SAR;
504 #if defined(CONFIG_PCI)
505 /* MPI initialization */
509 #if defined(CONFIG_USB)
510 #if defined(CONFIG_BCM96348)
511 PERF->blkEnables |= USBH_CLK_EN;
513 *USBH = USBH_BYTE_SWAP;
515 USBH->SwapControl = EHCI_ENDIAN_SWAP | OHCI_ENDIAN_SWAP;
516 USBH->TestPortControl = 0x001c0020;
523 arch_initcall(bcm63xx_hw_init);
525 static int __init brcm63xx_setup(void)
527 extern int panic_timeout;
529 _machine_restart = brcm_machine_restart;
530 _machine_halt = brcm_machine_halt;
531 _machine_power_off = brcm_machine_halt;
533 board_timer_setup = brcm_timer_setup;
540 early_initcall(brcm63xx_setup);
542 /***************************************************************************
543 * C++ New and delete operator functions
544 ***************************************************************************/
546 /* void *operator new(unsigned int sz) */
547 void *_Znwj(unsigned int sz)
549 return( kmalloc(sz, GFP_KERNEL) );
552 /* void *operator new[](unsigned int sz)*/
553 void *_Znaj(unsigned int sz)
555 return( kmalloc(sz, GFP_KERNEL) );
558 /* placement new operator */
559 /* void *operator new (unsigned int size, void *ptr) */
560 void *ZnwjPv(unsigned int size, void *ptr)
565 /* void operator delete(void *m) */
571 /* void operator delete[](void *m) */
577 EXPORT_SYMBOL(_Znwj);
578 EXPORT_SYMBOL(_Znaj);
579 EXPORT_SYMBOL(ZnwjPv);
580 EXPORT_SYMBOL(_ZdlPv);
581 EXPORT_SYMBOL(_ZdaPv);