tizen 2.4 release
[kernel/u-boot-tm1.git] / arch / arm / cpu / arm926ejs / sc8800g / watchdog_phy_v3.c
1 /******************************************************************************
2  ** File Name:      watchdog_phy_v3.c                                                 *
3  ** Author:         Jie Dai                                                   *
4  ** DATE:           08/02/2010                                                *
5  ** Copyright:      2010 Spreatrum, Incoporated. All Rights Reserved.         *
6  ** Description:    This file define the physical layer of I2C device.      *
7  ******************************************************************************
8
9  ******************************************************************************
10  **                        Edit History                                       *
11  ** ------------------------------------------------------------------------- *
12  ** DATE           NAME             DESCRIPTION                               *
13  ** 08/02/2010     Jie Dai            Create.                                 *
14  ******************************************************************************/
15
16 /**---------------------------------------------------------------------------*
17  **                         Dependencies                                      *
18  **---------------------------------------------------------------------------*/
19 #include <asm/arch/os_api.h>
20 #include <asm/arch/sc_reg.h>
21 #include <asm/arch/adi_hal_internal.h>
22 #include <asm/arch/watchdog_phy.h>
23
24 /**---------------------------------------------------------------------------*
25  **                         Compiler Flag                                     *
26  **---------------------------------------------------------------------------*/
27 #ifdef   __cplusplus
28 extern   "C"
29 {
30 #endif
31
32 #define ANA_WDG_LOAD_TIMEOUT_NUM    (10000)
33 #define ANA_WDG_CLR_INT_TIMEOUT_NUM (10000)
34
35 #define WDG_LOAD_TIMER_VALUE(value) \
36     do{\
37         uint32   cnt          =  0;\
38         ANA_REG_SET( WDG_LOAD_HIGH, (uint16)(((value) >> 16 ) & 0xffff));\
39         ANA_REG_SET( WDG_LOAD_LOW , (uint16)((value)  & 0xffff) );\
40         while((ANA_REG_GET(WDG_INT_RAW) & WDG_LD_BUSY_BIT) && ( cnt < ANA_WDG_LOAD_TIMEOUT_NUM )) cnt++;\
41     }while(0)
42
43 #define CLEAR_WDG_INT(msk) \
44     do{ \
45         uint32   cnt          =  0;\
46         ANA_REG_SET(WDG_INT_CLR, (msk));\
47         while((ANA_REG_GET(WDG_INT_RAW) & (msk))&&(cnt < ANA_WDG_CLR_INT_TIMEOUT_NUM)) cnt++; \
48     }while(0)
49
50
51 /**---------------------------------------------------------------------------*
52  **                            Macro Define
53  **---------------------------------------------------------------------------*/
54 #define  WDG_TRACE 
55
56 /*****************************************************************************/
57 //  Description:    This function config the watch dog module.
58 //  Dependency:     No
59 //  Author:         Jie.Dai
60 //  Note:
61 /*****************************************************************************/
62 PUBLIC int32 WDG_PHY_CONFIG (WDG_CONFIG_T *cfg)
63 {
64     uint32 ctrl = 0;
65     uint32 val  = 0;
66
67     ANA_REG_SET (WDG_LOCK, WDG_UNLOCK_KEY);
68
69     switch (cfg->mode)
70     {
71         case WDG_TIMEOUT_MODE_RESET:
72             ANA_REG_AND (WDG_CTRL, (~WDG_INT_EN_BIT));
73             break;
74
75         case WDG_TIMEOUT_MODE_INT:
76             ANA_REG_OR (WDG_CTRL, WDG_INT_EN_BIT);
77             break;
78
79         default:
80             break;  //No need to change
81     }
82
83     if (WDG_TIMER_STATE_STOP != cfg->state)
84     {
85         WDG_LOAD_TIMER_VALUE (cfg->val);
86     }
87
88     switch (cfg->state)
89     {
90         case WDG_TIMER_STATE_STOP:
91             ANA_REG_AND (WDG_CTRL, (~WDG_CNT_EN_BIT));
92             break;
93
94         case WDG_TIMER_STATE_START:
95             ANA_REG_OR (WDG_CTRL, WDG_CNT_EN_BIT);
96             break;
97
98         default:
99             break;  //No need to change
100     }
101
102     // WDG_TRACE ("Watch Dog Trace: Watch Dog LOAD    0x%8.8x", CHIP_REG_GET (WDG_LOAD));
103
104     ANA_REG_SET (WDG_LOCK, (~WDG_UNLOCK_KEY));
105
106     return 0;
107 }
108
109 /*****************************************************************************/
110 //  Description:    This function clear the watch dog interrupt
111 //  Dependency:     No
112 //  Author:         Jie.Dai
113 //  Note:
114 /*****************************************************************************/
115 PUBLIC int32 WDG_PHY_INT_CLR (void)
116 {
117     ANA_REG_SET (WDG_LOCK, WDG_UNLOCK_KEY);
118     CLEAR_WDG_INT (WDG_INT_CLEAR_BIT);
119     ANA_REG_SET (WDG_LOCK, (~WDG_UNLOCK_KEY));
120     return 0;
121 }
122 PUBLIC void WDG_ClockOn(void)
123 {
124     ANA_REG_OR(ANA_AGEN, AGEN_WDG_EN | AGEN_RTC_ARCH_EN | AGEN_RTC_WDG_EN);
125 }
126
127
128
129
130 /**---------------------------------------------------------------------------*
131  **                         Compiler Flag                                     *
132  **---------------------------------------------------------------------------*/
133
134 #ifdef   __cplusplus
135 }
136 #endif
137
138 /*  End Of File */
139
140