tizen 2.4 release
[kernel/u-boot-tm1.git] / arch / arm / cpu / arm926ejs / sc8800g / chip_phy_v3.c
1 /******************************************************************************
2  ** File Name:      chip_phy_v3.c                                             *
3  ** Author:         Richard Yang                                              *
4  ** DATE:           08/14/2002                                                *
5  ** Copyright:      2002 Spreatrum, Incoporated. All Rights Reserved.         *
6  ** Description:    This file defines the basic information on chip.          *
7  ******************************************************************************
8
9  ******************************************************************************
10  **                        Edit History                                       *
11  ** ------------------------------------------------------------------------- *
12  ** DATE           NAME             DESCRIPTION                               *
13  ** 08/14/2002     Richard.Yang     Create.                                   *
14  ** 09/16/2003     Xueliang.Wang    Modify CR4013                             *
15  ** 08/23/2004     JImmy.Jia        Modify for SC6600D                        *
16  ******************************************************************************/
17
18 /**---------------------------------------------------------------------------*
19  **                         Dependencies                                      *
20  **---------------------------------------------------------------------------*/
21 #include "sc_reg.h"
22 #include "adi_hal_internal.h"
23 #include "wdg_drvapi.h"
24 #include "mocor_boot_mode.h"
25
26 /**---------------------------------------------------------------------------*
27  **                         Compiler Flag                                     *
28  **---------------------------------------------------------------------------*/
29 #ifdef   __cplusplus
30 extern   "C"
31 {
32 #endif
33
34 /**---------------------------------------------------------------------------*
35  **                         Macro defines.
36  **---------------------------------------------------------------------------*/
37 #define HW_RST_MASK       0x1F
38
39 #define HWRST_ADDR     (DMA_REG_BASE + 0x400 + 31 * 0x20 + 8)  //src addr reg in chn 31
40
41 #define ENABLE_DMA_MODULE \
42                 do{ \
43                         if(!(CHIP_REG_GET(AHB_CTL0) & BIT_6)) \
44                         { \
45                             CHIP_REG_OR(AHB_CTL0, BIT_6);    \
46                         } \
47                     }while(0);
48
49 /**---------------------------------------------------------------------------*
50  **                         Struct defines.
51  **---------------------------------------------------------------------------*/
52
53 /**---------------------------------------------------------------------------*
54  **                         Global variables                                  *
55  **---------------------------------------------------------------------------*/
56
57 /**---------------------------------------------------------------------------*
58  **                         Function Definitions                              *
59  **---------------------------------------------------------------------------*/
60 /*****************************************************************************/
61 // Description :    This function is used to reset MCU.
62 // Global resource dependence :
63 // Author :         Xueliang.Wang
64 // Note :
65 /*****************************************************************************/
66 void CHIP_ResetMCU (void)  //reset interrupt disable??
67 {
68     // This loop is very important to let the reset process work well on V3 board
69     // @Richard
70     uint32 i = 10000;
71     ANA_REG_OR (ANA_AGEN, (AGEN_WDG_EN | AGEN_RTC_WDG_EN));
72     WDG_TimerInit ();
73     while (i--);    
74     WDG_ResetMCU ();
75     {
76         volatile uint32 tick1 = SCI_GetTickCount();
77         volatile uint32 tick2 = SCI_GetTickCount();
78         while ( (tick2 - tick1) < 500)
79         {
80             tick2 = SCI_GetTickCount();
81         }
82     }
83 }
84
85 /*****************************************************************************/
86 //  Description:    Returns the HW_RST register address.
87 //  Author:         Jeff.Li
88 //  Note :          Because there is no register which can restore information
89 //                  when watchdog resets the system, so we choose IRAM.
90 /*****************************************************************************/
91 LOCAL uint32 CHIP_PHY_GetHwRstAddr (void)
92 {
93     // Returns a DWORD of IRAM shared with DCAM
94 #if 0
95     return 0x4000A7FC;
96 #else
97         return HWRST_ADDR;
98 #endif
99 }
100
101 /*****************************************************************************/
102 //  Description:    Returns the reset mode register address.
103 //  Author:         Jeff.Li
104 //  Note:
105 /*****************************************************************************/
106 LOCAL uint32 CHIP_PHY_GetRstModeAddr (void)
107 {
108     return GR_ARM_BOOT_ADDR;
109 }
110
111 /*****************************************************************************/
112 //  Description:    Gets the register in analog die to judge the reset mode. 
113 //  Author:         Jeff.Li
114 //  Note:           !It is called before __main now, so it can not call the adi
115 //                  interface because it contains SCI_DisableIRQ inside, below 
116 //                  writes the adi read interface individually. Because the la-
117 //                  ckless of SCI_DisableIRQ, so this function must be called 
118 //                  before system interrupt is turnned on!
119 /*****************************************************************************/
120 LOCAL uint32 CHIP_PHY_GetANAReg (void)
121 {
122     uint32 adi_rd_data;
123
124     // Set read command
125     * (volatile uint32 *) ADI_ARM_RD_CMD = ANA_HWRST_STATUS;
126
127     // Wait read operation complete, RD_data[31] will be cleared after the read 
128     // operation complete
129     do
130     {
131         adi_rd_data = * (volatile uint32 *) ADI_RD_DATA;
132     }
133     while (adi_rd_data & BIT_31);
134
135     return ((adi_rd_data & 0x0000FFFF));
136 }
137
138 /*****************************************************************************/
139 //  Description:    This fuction returns the HW_RST value written before reset.
140 //  Author:         Jeff.Li
141 //  Note:           
142 /*****************************************************************************/
143 LOCAL uint32 CHIP_PHY_GetHWFlag (void)
144 {
145     // Switch IRAM from DCAM to ARM
146     REG32 (AHB_CTL1) |= BIT_0;
147     
148     return CHIP_REG_GET (CHIP_PHY_GetHwRstAddr ());
149 }
150
151 /*****************************************************************************/
152 //  Description:    PHY layer realization of BOOT_SetRstMode.
153 //  Author:         Jeff.Li
154 //  Note:           The valid bit filed is from bit15 to bit0
155 /*****************************************************************************/
156 PUBLIC void CHIP_PHY_SetRstMode (uint32 val)
157 {
158     CHIP_REG_AND (CHIP_PHY_GetRstModeAddr (), ~0xFFFF);
159     CHIP_REG_OR (CHIP_PHY_GetRstModeAddr (), (val&0xFFFF));
160 }
161
162 /*****************************************************************************/
163 //  Description:    This fuction returns the reset mode value.
164 //  Author:         Jeff.Li
165 //  Note:
166 /*****************************************************************************/
167 PUBLIC uint32 CHIP_PHY_GetRstMode (void)
168 {
169     return (CHIP_REG_GET (CHIP_PHY_GetRstModeAddr ()) & 0xFFFF);
170 }
171
172 /*****************************************************************************/
173 //  Description:    PHY layer realization of BOOT_ResetHWFlag. It resets the HW
174 //                  reset register after system initialization.
175 //  Author:         Jeff.Li
176 //  Note:           The valid bit filed of analog register is from bit11 to bit0.
177 //                  | 11   10   9   8 |  7   6   5   4  |  3   2   1   0   |
178 //                  |ALL_HRST_MONITOR | POR_HRST_MONITOR| WDG_HRST_MONITOR |
179 //
180 //                  The valid bit filed of HW_RST is from bit11 to bit0.
181 /*****************************************************************************/
182 PUBLIC void CHIP_PHY_ResetHWFlag (uint32 val)
183 {
184 #if 0
185     // Reset the analog die register
186     ANA_REG_AND (ANA_HWRST_STATUS, (~0xF));
187     ANA_REG_OR (ANA_HWRST_STATUS, (val & 0xF));
188
189     // Reset the HW_RST
190     CHIP_REG_AND (CHIP_PHY_GetHwRstAddr (), ~0xFFFF);
191     CHIP_REG_OR (CHIP_PHY_GetHwRstAddr (), (val&0xFFFF));
192
193 #else
194     //set WDG Mon to 0xF
195     ANA_REG_AND (ANA_HWRST_STATUS, (~0xF));
196     ANA_REG_OR (ANA_HWRST_STATUS, (val & 0xF));
197     
198     ENABLE_DMA_MODULE
199
200     CHIP_REG_AND(CHIP_PHY_GetHwRstAddr(), (~HW_RST_MASK));
201     CHIP_REG_OR(CHIP_PHY_GetHwRstAddr(), (val & HW_RST_MASK));
202 #endif
203 }
204
205 /*****************************************************************************/
206 //  Description:    PHY layer realization of BOOT_SetWDGHWFlag. It Writes flag
207 //                  to the register which would not be reset by watchdog reset.
208 //  Author:         Jeff.Li
209 //  Note:           The valid bit filed is from bit15 to bit0
210 /*****************************************************************************/
211 PUBLIC void CHIP_PHY_SetWDGHWFlag (WDG_HW_FLAG_T type, uint32 val)
212 {
213     if(TYPE_RESET == type)
214     {
215 #if 0
216         // Switch IRAM from DCAM to ARM
217         REG32 (AHB_CTL1) |= BIT_0;
218         
219         CHIP_REG_AND (CHIP_PHY_GetHwRstAddr (), ~0xFFFF);
220         CHIP_REG_OR (CHIP_PHY_GetHwRstAddr (), (val&0xFFFF));
221 #else
222         ENABLE_DMA_MODULE        
223
224         CHIP_REG_AND(CHIP_PHY_GetHwRstAddr(), (~HW_RST_MASK));
225         CHIP_REG_OR(CHIP_PHY_GetHwRstAddr(), (val & HW_RST_MASK));
226 #endif
227     } else {
228         //wrong type, TODO
229     }
230 }
231
232
233 /*****************************************************************************/
234 //  Description:    PHY layer realization of __BOOT_IRAM_EN.
235 //  Author:         Jeff.Li
236 //  Note:           Do nothing. There are 32KB internal ram dedicated for ARM.
237 /*****************************************************************************/
238 PUBLIC void CHIP_PHY_BootIramEn ()
239 {
240 }
241
242 /*****************************************************************************/
243 // Description :    This function returns whether the watchdog reset is caused
244 //                  by software reset or system halted.
245 // Author :         Jeff.Li
246 // Note :           The valid bit filed is from bit15 to bit0
247 /*****************************************************************************/
248 PUBLIC BOOLEAN CHIP_PHY_IsWDGRstByMCU (uint32 flag)
249 {
250     // Copy the value of HW_RST register to the register specific to reset mode
251     CHIP_REG_SET (CHIP_PHY_GetRstModeAddr (),
252                   (CHIP_PHY_GetHWFlag () & 0xFFFF));
253
254     if ((CHIP_PHY_GetHWFlag () & 0xFFFF) == (flag & 0xFFFF))
255     {
256         return SCI_FALSE;
257     }
258     else
259     {
260         return SCI_TRUE;
261     }
262 }
263
264 /*****************************************************************************/
265 // Description :    This function returns whether the reset is caused by power
266 //                  up.
267 // Author :         Jeff.Li
268 // Note :           | 11   10   9   8 |  7   6   5   4  |  3   2   1   0   |
269 //                  |ALL_HRST_MONITOR | POR_HRST_MONITOR| WDG_HRST_MONITOR |
270 /*****************************************************************************/
271 PUBLIC BOOLEAN CHIP_PHY_IsResetByPowerUp()
272 {
273     if ((CHIP_PHY_GetANAReg () & 0xF0) == 0x0)
274     {
275         return SCI_TRUE;
276     }
277     else
278     {
279         return SCI_FALSE;
280     }
281 }
282
283 /*****************************************************************************/
284 // Description :    This function returns whether the reset is caused by watch-
285 //                  dog reset.
286 // Author :         Jeff.Li
287 // Note :           | 11   10   9   8 |  7   6   5   4  |  3   2   1   0   |
288 //                  |ALL_HRST_MONITOR | POR_HRST_MONITOR| WDG_HRST_MONITOR |
289 /*****************************************************************************/
290 PUBLIC BOOLEAN CHIP_PHY_IsResetByWatchDog()
291 {
292     if ((CHIP_PHY_GetANAReg () & 0xF) == 0x0)
293     {
294         return SCI_TRUE;
295     }
296     else
297     {
298         return SCI_FALSE;
299     }
300 }
301
302 /**---------------------------------------------------------------------------*
303  **                         Compiler Flag                                     *
304  **---------------------------------------------------------------------------*/
305 #ifdef __cplusplus
306 }
307 #endif