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/autoconf.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>
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_time_init(void);
44 extern unsigned long getMemorySize(void);
46 #if defined(CONFIG_BCM96348) && defined(CONFIG_PCI)
47 #include <linux/pci.h>
48 #include <linux/delay.h>
49 #include <bcm_map_part.h>
52 static volatile MpiRegisters * mpi = (MpiRegisters *)(MPI_BASE);
55 /* This function should be in a board specific directory. For now,
56 * assume that all boards that include this file use a Broadcom chip
57 * with a soft reset bit in the PLL control register.
59 static void brcm_machine_restart(char *command)
61 const unsigned long ulSoftReset = 0x00000001;
62 unsigned long *pulPllCtrl = (unsigned long *) 0xfffe0008;
63 *pulPllCtrl |= ulSoftReset;
66 static void brcm_machine_halt(void)
68 printk("System halted\n");
72 #if defined(CONFIG_BCM96348) && defined(CONFIG_PCI)
74 static void mpi_SetLocalPciConfigReg(uint32 reg, uint32 value)
76 /* write index then value */
77 mpi->pcicfgcntrl = PCI_CFG_REG_WRITE_EN + reg;;
78 mpi->pcicfgdata = value;
81 static uint32 mpi_GetLocalPciConfigReg(uint32 reg)
83 /* write index then get value */
84 mpi->pcicfgcntrl = PCI_CFG_REG_WRITE_EN + reg;;
85 return mpi->pcicfgdata;
89 * mpi_ResetPcCard: Set/Reset the PcCard
91 static void mpi_ResetPcCard(int cardtype, BOOL bReset)
93 if (cardtype == MPI_CARDTYPE_NONE) {
97 if (cardtype == MPI_CARDTYPE_CARDBUS) {
102 mpi->pcmcia_cntl1 = (mpi->pcmcia_cntl1 & ~PCCARD_CARD_RESET);
104 mpi->pcmcia_cntl1 = (mpi->pcmcia_cntl1 | PCCARD_CARD_RESET);
109 * mpi_ConfigCs: Configure an MPI/EBI chip select
111 static void mpi_ConfigCs(uint32 cs, uint32 base, uint32 size, uint32 flags)
113 mpi->cs[cs].base = ((base & 0x1FFFFFFF) | size);
114 mpi->cs[cs].config = flags;
118 * mpi_InitPcmciaSpace
120 static void mpi_InitPcmciaSpace(void)
122 // ChipSelect 4 controls PCMCIA Memory accesses
123 mpi_ConfigCs(PCMCIA_COMMON_BASE, pcmciaMem, EBI_SIZE_1M, (EBI_WORD_WIDE|EBI_ENABLE));
124 // ChipSelect 5 controls PCMCIA Attribute accesses
125 mpi_ConfigCs(PCMCIA_ATTRIBUTE_BASE, pcmciaAttr, EBI_SIZE_1M, (EBI_WORD_WIDE|EBI_ENABLE));
126 // ChipSelect 6 controls PCMCIA I/O accesses
127 mpi_ConfigCs(PCMCIA_IO_BASE, pcmciaIo, EBI_SIZE_64K, (EBI_WORD_WIDE|EBI_ENABLE));
129 mpi->pcmcia_cntl2 = ((PCMCIA_ATTR_ACTIVE << RW_ACTIVE_CNT_BIT) |
130 (PCMCIA_ATTR_INACTIVE << INACTIVE_CNT_BIT) |
131 (PCMCIA_ATTR_CE_SETUP << CE_SETUP_CNT_BIT) |
132 (PCMCIA_ATTR_CE_HOLD << CE_HOLD_CNT_BIT));
134 mpi->pcmcia_cntl2 |= (PCMCIA_HALFWORD_EN | PCMCIA_BYTESWAP_DIS);
138 * cardtype_vcc_detect: PC Card's card detect and voltage sense connection
140 * CD1#/ CD2#/ VS1#/ VS2#/ Card Initial Vcc
141 * CCD1# CCD2# CVS1 CVS2 Type
143 * GND GND open open 16-bit 5 vdc
145 * GND GND GND open 16-bit 3.3 vdc
147 * GND GND open GND 16-bit x.x vdc
149 * GND GND GND GND 16-bit 3.3 & x.x vdc
151 *====================================================================
153 * CVS1 GND CCD1# open CardBus 3.3 vdc
155 * GND CVS2 open CCD2# CardBus x.x vdc
157 * GND CVS1 CCD2# open CardBus y.y vdc
159 * GND CVS2 GND CCD2# CardBus 3.3 & x.x vdc
161 * CVS2 GND open CCD1# CardBus x.x & y.y vdc
163 * GND CVS1 CCD2# open CardBus 3.3, x.x & y.y vdc
166 static int cardtype_vcc_detect(void)
171 cardtype = MPI_CARDTYPE_NONE;
172 mpi->pcmcia_cntl1 = 0x0000A000; // Turn on the output enables and drive
173 // the CVS pins to 0.
174 data32 = mpi->pcmcia_cntl1;
175 switch (data32 & 0x00000003) // Test CD1# and CD2#, see if card is plugged in.
177 case 0x00000003: // No Card is in the slot.
178 printk("mpi: No Card is in the PCMCIA slot\n");
181 case 0x00000002: // Partial insertion, No CD2#.
182 printk("mpi: Card in the PCMCIA slot partial insertion, no CD2 signal\n");
185 case 0x00000001: // Partial insertion, No CD1#.
186 printk("mpi: Card in the PCMCIA slot partial insertion, no CD1 signal\n");
190 mpi->pcmcia_cntl1 = 0x0000A0C0; // Turn off the CVS output enables and
191 // float the CVS pins.
193 data32 = mpi->pcmcia_cntl1;
194 // Read the Register.
195 switch (data32 & 0x0000000C) // See what is on the CVS pins.
197 case 0x00000000: // CVS1 and CVS2 are tied to ground, only 1 option.
198 printk("mpi: Detected 3.3 & x.x 16-bit PCMCIA card\n");
199 cardtype = MPI_CARDTYPE_PCMCIA;
202 case 0x00000004: // CVS1 is open or tied to CCD1/CCD2 and CVS2 is tied to ground.
203 // 2 valid voltage options.
204 switch (data32 & 0x00000003) // Test the values of CCD1 and CCD2.
206 case 0x00000003: // CCD1 and CCD2 are tied to 1 of the CVS pins.
207 // This is not a valid combination.
208 printk("mpi: Unknown card plugged into slot\n");
211 case 0x00000002: // CCD2 is tied to either CVS1 or CVS2.
212 mpi->pcmcia_cntl1 = 0x0000A080; // Drive CVS1 to a 0.
214 data32 = mpi->pcmcia_cntl1;
215 if (data32 & 0x00000002) { // CCD2 is tied to CVS2, not valid.
216 printk("mpi: Unknown card plugged into slot\n");
217 } else { // CCD2 is tied to CVS1.
218 printk("mpi: Detected 3.3, x.x and y.y Cardbus card\n");
219 cardtype = MPI_CARDTYPE_CARDBUS;
223 case 0x00000001: // CCD1 is tied to either CVS1 or CVS2.
224 // This is not a valid combination.
225 printk("mpi: Unknown card plugged into slot\n");
228 case 0x00000000: // CCD1 and CCD2 are tied to ground.
229 printk("mpi: Detected x.x vdc 16-bit PCMCIA card\n");
230 cardtype = MPI_CARDTYPE_PCMCIA;
235 case 0x00000008: // CVS2 is open or tied to CCD1/CCD2 and CVS1 is tied to ground.
236 // 2 valid voltage options.
237 switch (data32 & 0x00000003) // Test the values of CCD1 and CCD2.
239 case 0x00000003: // CCD1 and CCD2 are tied to 1 of the CVS pins.
240 // This is not a valid combination.
241 printk("mpi: Unknown card plugged into slot\n");
244 case 0x00000002: // CCD2 is tied to either CVS1 or CVS2.
245 mpi->pcmcia_cntl1 = 0x0000A040; // Drive CVS2 to a 0.
247 data32 = mpi->pcmcia_cntl1;
248 if (data32 & 0x00000002) { // CCD2 is tied to CVS1, not valid.
249 printk("mpi: Unknown card plugged into slot\n");
250 } else {// CCD2 is tied to CVS2.
251 printk("mpi: Detected 3.3 and x.x Cardbus card\n");
252 cardtype = MPI_CARDTYPE_CARDBUS;
256 case 0x00000001: // CCD1 is tied to either CVS1 or CVS2.
257 // This is not a valid combination.
258 printk("mpi: Unknown card plugged into slot\n");
261 case 0x00000000: // CCD1 and CCD2 are tied to ground.
262 cardtype = MPI_CARDTYPE_PCMCIA;
263 printk("mpi: Detected 3.3 vdc 16-bit PCMCIA card\n");
268 case 0x0000000C: // CVS1 and CVS2 are open or tied to CCD1/CCD2.
269 // 5 valid voltage options.
271 switch (data32 & 0x00000003) // Test the values of CCD1 and CCD2.
273 case 0x00000003: // CCD1 and CCD2 are tied to 1 of the CVS pins.
274 // This is not a valid combination.
275 printk("mpi: Unknown card plugged into slot\n");
278 case 0x00000002: // CCD2 is tied to either CVS1 or CVS2.
279 // CCD1 is tied to ground.
280 mpi->pcmcia_cntl1 = 0x0000A040; // Drive CVS2 to a 0.
282 data32 = mpi->pcmcia_cntl1;
283 if (data32 & 0x00000002) { // CCD2 is tied to CVS1.
284 printk("mpi: Detected y.y vdc Cardbus card\n");
285 } else { // CCD2 is tied to CVS2.
286 printk("mpi: Detected x.x vdc Cardbus card\n");
288 cardtype = MPI_CARDTYPE_CARDBUS;
291 case 0x00000001: // CCD1 is tied to either CVS1 or CVS2.
292 // CCD2 is tied to ground.
294 mpi->pcmcia_cntl1 = 0x0000A040; // Drive CVS2 to a 0.
296 data32 = mpi->pcmcia_cntl1;
297 if (data32 & 0x00000001) {// CCD1 is tied to CVS1.
298 printk("mpi: Detected 3.3 vdc Cardbus card\n");
299 } else { // CCD1 is tied to CVS2.
300 printk("mpi: Detected x.x and y.y Cardbus card\n");
302 cardtype = MPI_CARDTYPE_CARDBUS;
305 case 0x00000000: // CCD1 and CCD2 are tied to ground.
306 cardtype = MPI_CARDTYPE_PCMCIA;
307 printk("mpi: Detected 5 vdc 16-bit PCMCIA card\n");
313 printk("mpi: Unknown card plugged into slot\n");
322 * mpi_DetectPcCard: Detect the plugged in PC-Card
323 * Return: < 0 => Unknown card detected
324 * 0 => No card detected
325 * 1 => 16-bit card detected
326 * 2 => 32-bit CardBus card detected
328 static int mpi_DetectPcCard(void)
332 cardtype = cardtype_vcc_detect();
334 case MPI_CARDTYPE_PCMCIA:
335 mpi->pcmcia_cntl1 &= ~0x0000e000; // disable enable bits
336 //mpi->pcmcia_cntl1 = (mpi->pcmcia_cntl1 & ~PCCARD_CARD_RESET);
337 mpi->pcmcia_cntl1 |= (PCMCIA_ENABLE | PCMCIA_GPIO_ENABLE);
338 mpi_InitPcmciaSpace();
339 mpi_ResetPcCard(cardtype, FALSE);
340 // Hold card in reset for 10ms
342 mpi_ResetPcCard(cardtype, TRUE);
343 // Let card come out of reset
346 case MPI_CARDTYPE_CARDBUS:
347 // 8 => CardBus Enable
348 // 1 => PCI Slot Number
349 // C => Float VS1 & VS2
350 mpi->pcmcia_cntl1 = (mpi->pcmcia_cntl1 & 0xFFFF0000) |
355 /* access to this memory window will be to/from CardBus */
356 mpi->l2pmremap1 |= CARDBUS_MEM;
358 // Need to reset the Cardbus Card. There's no CardManager to do this,
359 // and we need to be ready for PCI configuration.
360 mpi_ResetPcCard(cardtype, FALSE);
361 // Hold card in reset for 10ms
363 mpi_ResetPcCard(cardtype, TRUE);
364 // Let card come out of reset
373 static int mpi_init(void)
377 unsigned int chiprev;
378 unsigned int sdramsize;
380 chipid = (PERF->RevID & 0xFFFF0000) >> 16;
381 chiprev = (PERF->RevID & 0xFF);
382 sdramsize = getMemorySize();
384 * Init the pci interface
386 data = GPIO->GPIOMode; // GPIO mode register
387 data |= GROUP2_PCI | GROUP1_MII_PCCARD; // PCI internal arbiter + Cardbus
388 GPIO->GPIOMode = data; // PCI internal arbiter
391 * In the BCM6348 CardBus support is defaulted to Slot 0
392 * because there is no external IDSEL for CardBus. To disable
393 * the CardBus and allow a standard PCI card in Slot 0
394 * set the cbus_idsel field to 0x1f.
397 uData = mpi->pcmcia_cntl1;
398 uData |= CARDBUS_IDSEL;
399 mpi->pcmcia_cntl1 = uData;
401 // Setup PCI I/O Window range. Give 64K to PCI I/O
402 mpi->l2piorange = ~(BCM_PCI_IO_SIZE_64KB-1);
403 // UBUS to PCI I/O base address
404 mpi->l2piobase = BCM_PCI_IO_BASE & BCM_PCI_ADDR_MASK;
405 // UBUS to PCI I/O Window remap
406 mpi->l2pioremap = (BCM_PCI_IO_BASE | MEM_WINDOW_EN);
408 // enable PCI related GPIO pins and data swap between system and PCI bus
409 mpi->locbuscntrl = (EN_PCI_GPIO | DIR_U2P_NOSWAP);
411 /* Enable 6348 BusMaster and Memory access mode */
412 data = mpi_GetLocalPciConfigReg(PCI_COMMAND);
413 data |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
414 mpi_SetLocalPciConfigReg(PCI_COMMAND, data);
416 /* Configure two 16 MByte PCI to System memory regions. */
417 /* These memory regions are used when PCI device is a bus master */
418 /* Accesses to the SDRAM from PCI bus will be "byte swapped" for this region */
419 mpi_SetLocalPciConfigReg(PCI_BASE_ADDRESS_3, BCM_HOST_MEM_SPACE1);
422 /* Accesses to the SDRAM from PCI bus will not be "byte swapped" for this region */
423 mpi_SetLocalPciConfigReg(PCI_BASE_ADDRESS_4, BCM_HOST_MEM_SPACE2);
425 mpi->pcimodesel |= (PCI_BAR2_NOSWAP | 0x40);
427 if ((chipid == 0x6348) && (chiprev == 0xb0)) {
428 mpi->sp0range = ~(sdramsize-1);
429 mpi->sp1range = ~(sdramsize-1);
432 * Change 6348 PCI Cfg Reg. offset 0x40 to PCI memory read retry count infinity
433 * by set 0 in bit 8~15. This resolve read Bcm4306 srom return 0xffff in
436 data = mpi_GetLocalPciConfigReg(BRCM_PCI_CONFIG_TIMER);
437 data &= ~BRCM_PCI_CONFIG_TIMER_RETRY_MASK;
439 mpi_SetLocalPciConfigReg(BRCM_PCI_CONFIG_TIMER, data);
441 /* enable pci interrupt */
442 mpi->locintstat |= (EXT_PCI_INT << 16);
446 ioport_resource.start = BCM_PCI_IO_BASE;
447 ioport_resource.end = BCM_PCI_IO_BASE + BCM_PCI_IO_SIZE_64KB;
449 #if defined(CONFIG_USB)
450 PERF->blkEnables |= USBH_CLK_EN;
452 *USBH_NON_OHCI = NON_OHCI_BYTE_SWAP;
459 static int __init brcm63xx_setup(void)
461 extern int panic_timeout;
463 _machine_restart = brcm_machine_restart;
464 _machine_halt = brcm_machine_halt;
465 pm_power_off = brcm_machine_halt;
467 board_time_init = brcm_time_init;
471 #if defined(CONFIG_BCM96348) && defined(CONFIG_PCI)
472 /* mpi initialization */
478 void __init plat_mem_setup(void)
483 /***************************************************************************
484 * C++ New and delete operator functions
485 ***************************************************************************/
487 /* void *operator new(unsigned int sz) */
488 void *_Znwj(unsigned int sz)
490 return( kmalloc(sz, GFP_KERNEL) );
493 /* void *operator new[](unsigned int sz)*/
494 void *_Znaj(unsigned int sz)
496 return( kmalloc(sz, GFP_KERNEL) );
499 /* placement new operator */
500 /* void *operator new (unsigned int size, void *ptr) */
501 void *ZnwjPv(unsigned int size, void *ptr)
506 /* void operator delete(void *m) */
512 /* void operator delete[](void *m) */
518 EXPORT_SYMBOL(_Znwj);
519 EXPORT_SYMBOL(_Znaj);
520 EXPORT_SYMBOL(ZnwjPv);
521 EXPORT_SYMBOL(_ZdlPv);
522 EXPORT_SYMBOL(_ZdaPv);