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