http://www.usr.com/support/gpl/USR9107_release1.1.tar.gz
[bcm963xx.git] / kernel / linux / arch / mips / brcm-boards / bcm963xx / setup.c
1 /*
2 <:copyright-gpl 
3  Copyright 2002 Broadcom Corp. All Rights Reserved. 
4  
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. 
8  
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 
12  for more details. 
13  
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. 
17 :>
18 */
19 /*
20  * Generic setup routines for Broadcom 963xx MIPS boards
21  */
22
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>
31 #include <linux/mm.h>
32 #include <linux/slab.h>
33 #include <linux/module.h>
34
35 #include <asm/addrspace.h>
36 #include <asm/bcache.h>
37 #include <asm/irq.h>
38 #include <asm/time.h>
39 #include <asm/reboot.h>
40 #include <asm/gdb-stub.h>
41
42 extern void brcm_timer_setup(struct irqaction *irq);
43 extern unsigned long getMemorySize(void);
44
45 #if defined(CONFIG_BCM96348) && defined(CONFIG_PCI)
46 #include <linux/pci.h>
47 #include <linux/delay.h>
48 #include <bcm_map_part.h>
49 #include <bcmpci.h>
50
51 static volatile MpiRegisters * mpi = (MpiRegisters *)(MPI_BASE);
52 #endif
53
54 /* This function should be in a board specific directory.  For now,
55  * assume that all boards that include this file use a Broadcom chip
56  * with a soft reset bit in the PLL control register.
57  */
58 static void brcm_machine_restart(char *command)
59 {
60     const unsigned long ulSoftReset = 0x00000001;
61     unsigned long *pulPllCtrl = (unsigned long *) 0xfffe0008;
62     *pulPllCtrl |= ulSoftReset;
63 }
64
65 static void brcm_machine_halt(void)
66 {
67     printk("System halted\n");
68     while (1);
69 }
70
71 #if defined(CONFIG_BCM96348) && defined(CONFIG_PCI)
72
73 static void mpi_SetLocalPciConfigReg(uint32 reg, uint32 value)
74 {
75     /* write index then value */
76     mpi->pcicfgcntrl = PCI_CFG_REG_WRITE_EN + reg;;
77     mpi->pcicfgdata = value;
78 }
79
80 static uint32 mpi_GetLocalPciConfigReg(uint32 reg)
81 {
82     /* write index then get value */
83     mpi->pcicfgcntrl = PCI_CFG_REG_WRITE_EN + reg;;
84     return mpi->pcicfgdata;
85 }
86
87 /*
88  * mpi_ResetPcCard: Set/Reset the PcCard
89  */
90 static void mpi_ResetPcCard(int cardtype, BOOL bReset)
91 {
92     if (cardtype == MPI_CARDTYPE_NONE) {
93         return;
94     }
95
96     if (cardtype == MPI_CARDTYPE_CARDBUS) {
97         bReset = ! bReset;
98     }
99
100     if (bReset) {
101         mpi->pcmcia_cntl1 = (mpi->pcmcia_cntl1 & ~PCCARD_CARD_RESET);
102     } else {
103         mpi->pcmcia_cntl1 = (mpi->pcmcia_cntl1 | PCCARD_CARD_RESET);
104     }
105 }
106
107 /*
108  * mpi_ConfigCs: Configure an MPI/EBI chip select
109  */
110 static void mpi_ConfigCs(uint32 cs, uint32 base, uint32 size, uint32 flags)
111 {
112     mpi->cs[cs].base = ((base & 0x1FFFFFFF) | size);
113     mpi->cs[cs].config = flags;
114 }
115
116 /*
117  * mpi_InitPcmciaSpace
118  */
119 static void mpi_InitPcmciaSpace(void)
120 {
121     // ChipSelect 4 controls PCMCIA Memory accesses
122     mpi_ConfigCs(PCMCIA_COMMON_BASE, pcmciaMem, EBI_SIZE_1M, (EBI_WORD_WIDE|EBI_ENABLE));
123     // ChipSelect 5 controls PCMCIA Attribute accesses
124     mpi_ConfigCs(PCMCIA_ATTRIBUTE_BASE, pcmciaAttr, EBI_SIZE_1M, (EBI_WORD_WIDE|EBI_ENABLE));
125     // ChipSelect 6 controls PCMCIA I/O accesses
126     mpi_ConfigCs(PCMCIA_IO_BASE, pcmciaIo, EBI_SIZE_64K, (EBI_WORD_WIDE|EBI_ENABLE));
127
128     mpi->pcmcia_cntl2 = ((PCMCIA_ATTR_ACTIVE << RW_ACTIVE_CNT_BIT) | 
129                          (PCMCIA_ATTR_INACTIVE << INACTIVE_CNT_BIT) | 
130                          (PCMCIA_ATTR_CE_SETUP << CE_SETUP_CNT_BIT) | 
131                          (PCMCIA_ATTR_CE_HOLD << CE_HOLD_CNT_BIT));
132
133     mpi->pcmcia_cntl2 |= (PCMCIA_HALFWORD_EN | PCMCIA_BYTESWAP_DIS);
134 }
135
136 /*
137  * cardtype_vcc_detect: PC Card's card detect and voltage sense connection
138  * 
139  *   CD1#/      CD2#/     VS1#/     VS2#/    Card       Initial Vcc
140  *  CCD1#      CCD2#     CVS1      CVS2      Type
141  *
142  *   GND        GND       open      open     16-bit     5 vdc
143  *
144  *   GND        GND       GND       open     16-bit     3.3 vdc
145  *
146  *   GND        GND       open      GND      16-bit     x.x vdc
147  *
148  *   GND        GND       GND       GND      16-bit     3.3 & x.x vdc
149  *
150  *====================================================================
151  *
152  *   CVS1       GND       CCD1#     open     CardBus    3.3 vdc
153  *
154  *   GND        CVS2      open      CCD2#    CardBus    x.x vdc
155  *
156  *   GND        CVS1      CCD2#     open     CardBus    y.y vdc
157  *
158  *   GND        CVS2      GND       CCD2#    CardBus    3.3 & x.x vdc
159  *
160  *   CVS2       GND       open      CCD1#    CardBus    x.x & y.y vdc
161  *
162  *   GND        CVS1      CCD2#     open     CardBus    3.3, x.x & y.y vdc
163  *
164  */
165 static int cardtype_vcc_detect(void)
166 {
167     uint32 data32;
168     int cardtype;
169
170     cardtype = MPI_CARDTYPE_NONE;
171     mpi->pcmcia_cntl1 = 0x0000A000; // Turn on the output enables and drive
172                                         // the CVS pins to 0.
173     data32 = mpi->pcmcia_cntl1;
174     switch (data32 & 0x00000003)  // Test CD1# and CD2#, see if card is plugged in.
175     {
176     case 0x00000003:  // No Card is in the slot.
177         printk("mpi: No Card is in the PCMCIA slot\n");
178         break;
179
180     case 0x00000002:  // Partial insertion, No CD2#.
181         printk("mpi: Card in the PCMCIA slot partial insertion, no CD2 signal\n");
182         break;
183
184     case 0x00000001:  // Partial insertion, No CD1#.
185         printk("mpi: Card in the PCMCIA slot partial insertion, no CD1 signal\n");
186         break;
187
188     case 0x00000000:
189         mpi->pcmcia_cntl1 = 0x0000A0C0; // Turn off the CVS output enables and
190                                         // float the CVS pins.
191         mdelay(1);
192         data32 = mpi->pcmcia_cntl1;
193         // Read the Register.
194         switch (data32 & 0x0000000C)  // See what is on the CVS pins.
195         {
196         case 0x00000000: // CVS1 and CVS2 are tied to ground, only 1 option.
197             printk("mpi: Detected 3.3 & x.x 16-bit PCMCIA card\n");
198             cardtype = MPI_CARDTYPE_PCMCIA;
199             break;
200           
201         case 0x00000004: // CVS1 is open or tied to CCD1/CCD2 and CVS2 is tied to ground.
202                          // 2 valid voltage options.
203         switch (data32 & 0x00000003)  // Test the values of CCD1 and CCD2.
204         {
205             case 0x00000003:  // CCD1 and CCD2 are tied to 1 of the CVS pins.
206                               // This is not a valid combination.
207                 printk("mpi: Unknown card plugged into slot\n"); 
208                 break;
209       
210             case 0x00000002:  // CCD2 is tied to either CVS1 or CVS2. 
211                 mpi->pcmcia_cntl1 = 0x0000A080; // Drive CVS1 to a 0.
212                 mdelay(1);
213                 data32 = mpi->pcmcia_cntl1;
214                 if (data32 & 0x00000002) { // CCD2 is tied to CVS2, not valid.
215                     printk("mpi: Unknown card plugged into slot\n"); 
216                 } else {                   // CCD2 is tied to CVS1.
217                     printk("mpi: Detected 3.3, x.x and y.y Cardbus card\n");
218                     cardtype = MPI_CARDTYPE_CARDBUS;
219                 }
220                 break;
221                 
222             case 0x00000001: // CCD1 is tied to either CVS1 or CVS2.
223                              // This is not a valid combination.
224                 printk("mpi: Unknown card plugged into slot\n"); 
225                 break;
226                 
227             case 0x00000000:  // CCD1 and CCD2 are tied to ground.
228                 printk("mpi: Detected x.x vdc 16-bit PCMCIA card\n");
229                 cardtype = MPI_CARDTYPE_PCMCIA;
230                 break;
231             }
232             break;
233           
234         case 0x00000008: // CVS2 is open or tied to CCD1/CCD2 and CVS1 is tied to ground.
235                          // 2 valid voltage options.
236             switch (data32 & 0x00000003)  // Test the values of CCD1 and CCD2.
237             {
238             case 0x00000003:  // CCD1 and CCD2 are tied to 1 of the CVS pins.
239                               // This is not a valid combination.
240                 printk("mpi: Unknown card plugged into slot\n"); 
241                 break;
242       
243             case 0x00000002:  // CCD2 is tied to either CVS1 or CVS2.
244                 mpi->pcmcia_cntl1 = 0x0000A040; // Drive CVS2 to a 0.
245                 mdelay(1);
246                 data32 = mpi->pcmcia_cntl1;
247                 if (data32 & 0x00000002) { // CCD2 is tied to CVS1, not valid.
248                     printk("mpi: Unknown card plugged into slot\n"); 
249                 } else {// CCD2 is tied to CVS2.
250                     printk("mpi: Detected 3.3 and x.x Cardbus card\n");
251                     cardtype = MPI_CARDTYPE_CARDBUS;
252                 }
253                 break;
254
255             case 0x00000001: // CCD1 is tied to either CVS1 or CVS2.
256                              // This is not a valid combination.
257                 printk("mpi: Unknown card plugged into slot\n"); 
258                 break;
259
260             case 0x00000000:  // CCD1 and CCD2 are tied to ground.
261                 cardtype = MPI_CARDTYPE_PCMCIA;
262                 printk("mpi: Detected 3.3 vdc 16-bit PCMCIA card\n");
263                 break;
264             }
265             break;
266           
267         case 0x0000000C:  // CVS1 and CVS2 are open or tied to CCD1/CCD2.
268                           // 5 valid voltage options.
269       
270             switch (data32 & 0x00000003)  // Test the values of CCD1 and CCD2.
271             {
272             case 0x00000003:  // CCD1 and CCD2 are tied to 1 of the CVS pins.
273                               // This is not a valid combination.
274                 printk("mpi: Unknown card plugged into slot\n"); 
275                 break;
276       
277             case 0x00000002:  // CCD2 is tied to either CVS1 or CVS2.
278                               // CCD1 is tied to ground.
279                 mpi->pcmcia_cntl1 = 0x0000A040; // Drive CVS2 to a 0.
280                 mdelay(1);
281                 data32 = mpi->pcmcia_cntl1;
282                 if (data32 & 0x00000002) {  // CCD2 is tied to CVS1.
283                     printk("mpi: Detected y.y vdc Cardbus card\n");
284                 } else {                    // CCD2 is tied to CVS2.
285                     printk("mpi: Detected x.x vdc Cardbus card\n");
286                 }
287                 cardtype = MPI_CARDTYPE_CARDBUS;
288                 break;
289       
290             case 0x00000001: // CCD1 is tied to either CVS1 or CVS2.
291                              // CCD2 is tied to ground.
292       
293                 mpi->pcmcia_cntl1 = 0x0000A040; // Drive CVS2 to a 0.
294                 mdelay(1);
295                 data32 = mpi->pcmcia_cntl1;
296                 if (data32 & 0x00000001) {// CCD1 is tied to CVS1.
297                     printk("mpi: Detected 3.3 vdc Cardbus card\n");
298                 } else {                    // CCD1 is tied to CVS2.
299                     printk("mpi: Detected x.x and y.y Cardbus card\n");
300                 }
301                 cardtype = MPI_CARDTYPE_CARDBUS;
302                 break;
303       
304             case 0x00000000:  // CCD1 and CCD2 are tied to ground.
305                 cardtype = MPI_CARDTYPE_PCMCIA;
306                 printk("mpi: Detected 5 vdc 16-bit PCMCIA card\n");
307                 break;
308             }
309             break;
310       
311         default:
312             printk("mpi: Unknown card plugged into slot\n"); 
313             break;
314         
315         }
316     }
317     return cardtype;
318 }
319
320 /*
321  * mpi_DetectPcCard: Detect the plugged in PC-Card
322  * Return: < 0 => Unknown card detected
323  *         0 => No card detected
324  *         1 => 16-bit card detected
325  *         2 => 32-bit CardBus card detected
326  */
327 static int mpi_DetectPcCard(void)
328 {
329     int cardtype;
330
331     cardtype = cardtype_vcc_detect();
332     switch(cardtype) {
333         case MPI_CARDTYPE_PCMCIA:
334             mpi->pcmcia_cntl1 &= ~0x0000e000; // disable enable bits
335             //mpi->pcmcia_cntl1 = (mpi->pcmcia_cntl1 & ~PCCARD_CARD_RESET);
336             mpi->pcmcia_cntl1 |= (PCMCIA_ENABLE | PCMCIA_GPIO_ENABLE);
337             mpi_InitPcmciaSpace();
338             mpi_ResetPcCard(cardtype, FALSE);
339             // Hold card in reset for 10ms
340             mdelay(10);
341             mpi_ResetPcCard(cardtype, TRUE);
342             // Let card come out of reset
343             mdelay(100);
344             break;
345         case MPI_CARDTYPE_CARDBUS:
346             // 8 => CardBus Enable
347             // 1 => PCI Slot Number
348             // C => Float VS1 & VS2
349             mpi->pcmcia_cntl1 = (mpi->pcmcia_cntl1 & 0xFFFF0000) | 
350                                 CARDBUS_ENABLE | 
351                                 (CARDBUS_SLOT << 8)| 
352                                 VS2_OEN |
353                                 VS1_OEN;
354             /* access to this memory window will be to/from CardBus */
355             mpi->l2pmremap1 |= CARDBUS_MEM;
356
357             // Need to reset the Cardbus Card. There's no CardManager to do this, 
358             // and we need to be ready for PCI configuration. 
359             mpi_ResetPcCard(cardtype, FALSE);
360             // Hold card in reset for 10ms
361             mdelay(10);
362             mpi_ResetPcCard(cardtype, TRUE);
363             // Let card come out of reset
364             mdelay(100);
365             break;
366         default:
367             break;
368     }
369     return cardtype;
370 }
371
372 static int mpi_init(void)
373 {
374     unsigned long data;
375     unsigned int chipid;
376     unsigned int chiprev;
377     unsigned int sdramsize;
378
379     chipid  = (PERF->RevID & 0xFFFF0000) >> 16;
380     chiprev = (PERF->RevID & 0xFF);
381     sdramsize = getMemorySize();
382     /*
383      * Init the pci interface 
384      */
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
388
389     /*
390      * In the BCM6348 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.
394     */
395     /*
396     uData = mpi->pcmcia_cntl1;
397     uData |= CARDBUS_IDSEL;
398     mpi->pcmcia_cntl1 = uData;
399     */
400     // Setup PCI I/O Window range. Give 64K to PCI I/O
401     mpi->l2piorange = ~(BCM_PCI_IO_SIZE_64KB-1);
402     // UBUS to PCI I/O base address 
403     mpi->l2piobase = BCM_PCI_IO_BASE & BCM_PCI_ADDR_MASK;
404     // UBUS to PCI I/O Window remap
405     mpi->l2pioremap = (BCM_PCI_IO_BASE | MEM_WINDOW_EN);
406
407     // enable PCI related GPIO pins and data swap between system and PCI bus
408     mpi->locbuscntrl = (EN_PCI_GPIO | DIR_U2P_NOSWAP);
409
410     /* Enable 6348 BusMaster and Memory access mode */
411     data = mpi_GetLocalPciConfigReg(PCI_COMMAND);
412     data |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
413     mpi_SetLocalPciConfigReg(PCI_COMMAND, data);
414
415     /* Configure two 16 MByte PCI to System memory regions. */
416     /* These memory regions are used when PCI device is a bus master */
417     /* Accesses to the SDRAM from PCI bus will be "byte swapped" for this region */
418     mpi_SetLocalPciConfigReg(PCI_BASE_ADDRESS_3, BCM_HOST_MEM_SPACE1);
419     mpi->sp0remap = 0x0;
420
421     /* Accesses to the SDRAM from PCI bus will not be "byte swapped" for this region */
422     mpi_SetLocalPciConfigReg(PCI_BASE_ADDRESS_4, BCM_HOST_MEM_SPACE2);
423     mpi->sp1remap = 0x0;
424     mpi->pcimodesel |= (PCI_BAR2_NOSWAP | 0x40);
425
426     if ((chipid == 0x6348) && (chiprev == 0xb0)) {
427         mpi->sp0range = ~(sdramsize-1);
428         mpi->sp1range = ~(sdramsize-1);
429     }
430     /*
431      * Change 6348 PCI Cfg Reg. offset 0x40 to PCI memory read retry count infinity
432      * by set 0 in bit 8~15.  This resolve read Bcm4306 srom return 0xffff in
433      * first read.
434      */
435     data = mpi_GetLocalPciConfigReg(BRCM_PCI_CONFIG_TIMER);
436     data &= ~BRCM_PCI_CONFIG_TIMER_RETRY_MASK;
437     data |= 0x00000080;
438     mpi_SetLocalPciConfigReg(BRCM_PCI_CONFIG_TIMER, data);
439
440     /* enable pci interrupt */
441     mpi->locintstat |= (EXT_PCI_INT << 16);
442
443     mpi_DetectPcCard();
444
445     ioport_resource.start = BCM_PCI_IO_BASE;
446     ioport_resource.end = BCM_PCI_IO_BASE + BCM_PCI_IO_SIZE_64KB;
447
448 #if defined(CONFIG_USB)
449     PERF->blkEnables |= USBH_CLK_EN;
450     mdelay(100);
451     *USBH_NON_OHCI = NON_OHCI_BYTE_SWAP;
452 #endif
453
454     return 0;
455 }
456 #endif
457
458 static int __init brcm63xx_setup(void)
459 {
460     extern int panic_timeout;
461
462     _machine_restart = brcm_machine_restart;
463     _machine_halt = brcm_machine_halt;
464     _machine_power_off = brcm_machine_halt;
465
466     board_timer_setup = brcm_timer_setup;
467
468     panic_timeout = 180;
469
470 #if defined(CONFIG_BCM96348) && defined(CONFIG_PCI)
471     /* mpi initialization */
472     mpi_init();
473 #endif
474     return 0;
475 }
476
477 early_initcall(brcm63xx_setup);
478
479 /***************************************************************************
480  * C++ New and delete operator functions
481  ***************************************************************************/
482
483 /* void *operator new(unsigned int sz) */
484 void *_Znwj(unsigned int sz)
485 {
486     return( kmalloc(sz, GFP_KERNEL) );
487 }
488
489 /* void *operator new[](unsigned int sz)*/
490 void *_Znaj(unsigned int sz)
491 {
492     return( kmalloc(sz, GFP_KERNEL) );
493 }
494
495 /* placement new operator */
496 /* void *operator new (unsigned int size, void *ptr) */
497 void *ZnwjPv(unsigned int size, void *ptr)
498 {
499     return ptr;
500 }
501
502 /* void operator delete(void *m) */
503 void _ZdlPv(void *m)
504 {
505     kfree(m);
506 }
507
508 /* void operator delete[](void *m) */
509 void _ZdaPv(void *m)
510 {
511     kfree(m);
512 }
513
514 EXPORT_SYMBOL(_Znwj);
515 EXPORT_SYMBOL(_Znaj);
516 EXPORT_SYMBOL(ZnwjPv);
517 EXPORT_SYMBOL(_ZdlPv);
518 EXPORT_SYMBOL(_ZdaPv);
519