Broadcom SDK and wireless driver: another attempt to update to ver. 5.10.147.0
[tomato.git] / release / src-rt / shared / sisdram.S
blob637d524e1d4229fcdf952e2344f1ad73a62c7b3d
1 /*
2  * BCM947XX DRAM init & sizing
3  *
4  * Used by both cfe and shared/boot.
5  *
6  * Copyright (C) 2009, Broadcom Corporation
7  * All Rights Reserved.
8  * 
9  * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
10  * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
11  * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
12  * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
13  *
14  * $Id: sisdram.S,v 1.3.2.4 2008/10/31 21:39:48 Exp $
15  */
17 #include "mipsinc.h"
18 #include "hndsoc.h"
19 #include "sbchipc.h"
20 #include "bcmdevs.h"
23 /* Debug macro - write a number to memory - use it with caution,
24  *  it changes k0 and k1 registers.
25  */
26 #define TRACEINIT(x)
27 #define TRACE(x)
28 #define TRACE2(x)
30         /*
31          * This file exists because board_draminit is an entry point for cfe as well
32          * as for hndrte & min_osl. Because of the former case, we cannot assume
33          * any of the register settings from boot.S,
34          */
36         .text
37         LEAF(board_draminit)
38         .set    noreorder
40         TRACEINIT(0x535301)
41         move    gp,ra
43         /* Figure out if we have an SB or AI chip */
44         li      s2,KSEG1ADDR(SI_ENUM_BASE)      # s2 = SI_ENUM_BASE
45         li      t0,CID_TYPE_MASK
46         lw      s6,CC_CHIPID(s2)                # s6 = ChipId reg
47         and     t1,t0,s6
48         srl     s7,t1,CID_TYPE_SHIFT            # s7 = ChipType (0 for SB, = 1 for AI)
50         /* Check if we booted from flash, compute reloc for text addresses */
51         bal     1f
52         nop
54 1:      li      t0,PHYSADDR_MASK
55         and     t0,t0,ra
56         li      t1,SI_FLASH1
57         blt     t0,t1,2f
58         move    s5,zero
59         la      t0,1b
60         sub     s5,ra,t0                        # s5: Relocation factor
62         /* Call appropriate draminit for chip type */
63 2:      TRACE(0x535302)
64 #if     !defined(BCMCHIPTYPE) || (BCMCHIPTYPE == 0)
65         la      t2,sb_draminit
66         beqz    s7,3f
67         nop
68 #endif
69         TRACE(0x535303)
70 #if     !defined(BCMCHIPTYPE) || (BCMCHIPTYPE == 1)
71         la      t2,ai_draminit
72         bnez    s7,3f
73         nop
74 #endif
76 #ifdef  BCMCHIPTYPE
77         /* BCMCHIPTYPE defined but does not match this chip */
78         TRACE(0x5353fe)
79         b       sisdead
80         nop
81 #endif
83 3:      add     t2,t2,s5
84         jalr    t2
85         nop
87         /* Size memory if needed (Need to reinit TRACE after sb_draminit) */
88         TRACEINIT(0x535304)
89         beqz    v0,szmem
90         nop
91         
92         li      a0,-1                           # -1 means no controller
93         bne     v0,a0,4f
94         nop
96 sisdead:
97         TRACE2(0x5353ff)
98         b       sisdead
99         nop
101 4:      jr      gp
102         nop
104 szmem:
105         TRACE(0x535305)
106         li      s3,KSEG1                        # s3 = KSEG1
107         li      t2,0xaa55beef
108         sw      zero,0x3c(s3)
109         li      v0,(1 << 20)
110         li      v1,(128 << 20)
112 5:      or      t0,v0,s3
113         sw      t2,0x3c(t0)
114         lw      t1,0x3c(t0)                     # Read back to ensure completion
115         lw      t1,0x3c(s3)
116         beq     t1,t2,6f
117         nop
119         sll     v0,v0,1
120         bne     v0,v1,5b
121         nop
122         /* Didn't find an alias, must be 128MB */
124 6:      jr      gp
125         nop
127         END(board_draminit)