usbmodeswitch: Updated to v.1.2.6 from shibby's branch.
[tomato.git] / release / src-rt / shared / sisdram.S
blobd810c08be7797599d2c39a690049d809c64ef67f
1 /*
2  * BCM947XX DRAM init & sizing
3  *
4  * Used by both cfe and shared/boot.
5  *
6  * Copyright (C) 2010, Broadcom Corporation. All Rights Reserved.
7  * 
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  * 
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
15  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
17  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  *
20  * $Id: sisdram.S,v 1.8 2008-12-04 01:08:42 Exp $
21  */
23 #include "mipsinc.h"
24 #include "hndsoc.h"
25 #include "sbchipc.h"
26 #include "bcmdevs.h"
29 /* Debug macro - write a number to a chipc reg - use it with caution,
30  *  it changes k0 and k1 registers.
31  */
32 #ifdef  BCMDBG
33 #if     defined(IL_BIGENDIAN) && defined(BCMHND74K)
34 #define FLADDR_OFF      0
35 #define FLDATA_OFF      12
36 #else
37 #define FLADDR_OFF      4
38 #define FLDATA_OFF      8
39 #endif
41 #define TRACEINIT(x) \
42         li      k0,KSEG1ADDR(0x18000040); \
43         li      k1,x; \
44         sw      k1,FLADDR_OFF(k0)
45         
46 #define TRACE(x) \
47         li      k1,x; \
48         sw      k1,FLADDR_OFF(k0)
50 #define TRACE2(x) \
51         li      k1,x; \
52         sw      k1,FLDATA_OFF(k0)
54 #else
55 #define TRACEINIT(x)
56 #define TRACE(x)
57 #define TRACE2(x)
58 #endif  /* BCMDBG */
60         /*
61          * This file exists because board_draminit is an entry point for cfe as well
62          * as for hndrte & min_osl. Because of the former case, we cannot assume
63          * any of the register settings from boot.S,
64          */
66         .text
67         LEAF(board_draminit)
68         .set    noreorder
70         TRACEINIT(0x535301)
71         move    gp,ra
73         /* Figure out if we have an SB or AI chip */
74         li      s2,KSEG1ADDR(SI_ENUM_BASE)      # s2 = SI_ENUM_BASE
75         li      t0,CID_TYPE_MASK
76         lw      s6,CC_CHIPID(s2)                # s6 = ChipId reg
77         and     t1,t0,s6
78         srl     s7,t1,CID_TYPE_SHIFT            # s7 = ChipType (0 for SB, = 1 for AI)
80         /* Check if we booted from flash, compute reloc for text addresses */
81         bal     1f
82         nop
84 1:      li      t0,PHYSADDR_MASK
85         and     t0,t0,ra
86         li      t1,SI_FLASH1
87         blt     t0,t1,2f
88         move    s5,zero
89         la      t0,1b
90         sub     s5,ra,t0                        # s5: Relocation factor
92         /* Call appropriate draminit for chip type */
93 2:      TRACE(0x535302)
94 #if     !defined(BCMCHIPTYPE) || (BCMCHIPTYPE == 0)
95         la      t2,sb_draminit
96         beqz    s7,3f
97         nop
98 #endif
99         TRACE(0x535303)
100 #if     !defined(BCMCHIPTYPE) || (BCMCHIPTYPE == 1)
101         la      t2,ai_draminit
102         bnez    s7,3f
103         nop
104 #endif
106 #ifdef  BCMCHIPTYPE
107         /* BCMCHIPTYPE defined but does not match this chip */
108         TRACE2(0x5353fe)
109         b       sisdead
110         nop
111 #endif
113 3:      add     t2,t2,s5
114         jalr    t2
115         nop
117         /* Size memory if needed (Need to reinit TRACE after sb_draminit) */
118         TRACEINIT(0x535304)
119         beqz    v0,szmem
120         nop
121         
122         li      a0,-1                           # -1 means no controller
123         bne     v0,a0,4f
124         nop
126 sisdead:
127         TRACE2(0x5353ff)
128         b       sisdead
129         nop
131 4:      jr      gp
132         nop
134 szmem:
135         TRACE(0x535305)
136         li      s3,KSEG1                        # s3 = KSEG1
137         li      t2,0xaa55beef
138         sw      zero,0x3c(s3)
139         li      v0,(1 << 20)
140         li      v1,(128 << 20)
142 5:      or      t0,v0,s3
143         sw      t2,0x3c(t0)
144         lw      t1,0x3c(t0)                     # Read back to ensure completion
145         lw      t1,0x3c(s3)
146         beq     t1,t2,6f
147         nop
149         sll     v0,v0,1
150         bne     v0,v1,5b
151         nop
152         /* Didn't find an alias, must be 128MB */
154 6:      jr      gp
155         nop
157         END(board_draminit)