tizen 2.4 release
[kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / tiger / watchdog_hal.c
1 /******************************************************************************
2  ** File Name:      watchdog_hal.c                                                 *
3  ** Author:         Jimmy.Jia                                                 *
4  ** DATE:           10/28/2004                                                *
5  ** Copyright:      2004 Spreadtrum, Incoporated. All Rights Reserved.        *
6  ** Description:    This file defines the basic operation interfaces of       *
7  **                 serrial device. It manages create, send, receive          *
8  **                 interface of serrial port.                                *
9  ******************************************************************************
10
11  ******************************************************************************
12  **                        Edit History                                       *
13  ** ------------------------------------------------------------------------- *
14  ** DATE           NAME             DESCRIPTION                               *
15  ** 04/02/2002     Jimmy.Jia        Create.                                   *
16 **  01/03/2008     Yi.Qiu        For SC6600L                                  *
17  ******************************************************************************/
18
19 /**---------------------------------------------------------------------------*
20  **                         Dependencies                                      *
21  **---------------------------------------------------------------------------*/
22 #include <asm/arch/sci_types.h>
23 #include <asm/arch/sc_reg.h>
24 #include <asm/arch/os_api.h>
25 #include <asm/arch/wdg_drvapi.h>
26 //#include "fiq_drvapi.h"
27 #include <asm/arch/watchdog_phy.h>
28
29 #define  WDG_TRACE  
30 /**---------------------------------------------------------------------------*
31  **                      Function Declaration                                 *
32  **---------------------------------------------------------------------------*/
33
34 /*****************************************************************************/
35 //  Description:    This function disable WDG timer
36 //  Author:         Jimmy.Jia
37 //  Note:           no rtc_clk to drive the counter
38 //
39 /*****************************************************************************/
40 PUBLIC void WDG_TimerStop
41 (
42     void
43 )
44 {
45     WDG_CONFIG_T config;
46     int32        ret;
47
48     WDG_TRACE ("Watch Dog Trace: WDG_TimerStop");
49     WDG_PHY_INT_CLR();
50
51     config.state    = WDG_TIMER_STATE_STOP  ;
52     config.mode     = WDG_TIMEOUT_MODE_RESET;
53     config.val      = WDG_MAX_COUNT;
54
55     ret = WDG_PHY_CONFIG (&config);
56
57     return;
58 }
59
60 /*****************************************************************************/
61 //  Description:    This function initialize and setup timer with given value
62 //  Author:         Jimmy.Jia
63 //  Note:           rtc_clk drive the counter
64 //                  load regiter is 32 bits wide so that don't check if param's valid
65 /*****************************************************************************/
66 PUBLIC void WDG_TimerStart
67 (
68     uint32 init_val
69 )
70 {
71     WDG_CONFIG_T config;
72     int32        ret;
73
74     WDG_TRACE ("Watch Dog Trace: WDG_TimerStart");
75
76     config.state    = WDG_TIMER_STATE_START ;
77     //config.mode     = WDG_TIMEOUT_MODE_KEEP;
78     config.mode     = WDG_TIMEOUT_MODE_RESET;
79     config.val      = init_val;
80
81     ret = WDG_PHY_CONFIG (&config);
82
83 }
84
85 /*****************************************************************************/
86 //  Description:    This function handle WatchDog Interrupt
87 //  Author:         Binggo Zhou
88 //  Note:
89 /*****************************************************************************/
90 PUBLIC void WDG_TimerHandler (uint32 int_num)
91 {
92     WDG_PHY_INT_CLR();
93 }
94
95 /*****************************************************************************/
96 //  Description:    This function init WatchDog
97 //  Author:         Binggo Zhou
98 //  Note:
99 /*****************************************************************************/
100 PUBLIC void WDG_TimerInit (void)
101 {
102     WDG_CONFIG_T config;
103     uint32       status;
104     int32        ret;
105
106     WDG_TRACE ("Watch Dog Trace: WDG_TimerInit");
107
108     config.state    = WDG_TIMER_STATE_START ;
109     config.mode     = WDG_TIMEOUT_MODE_RESET;
110     config.val      = WDG_INIT_COUNT;
111
112     ret = WDG_PHY_CONFIG (&config);
113 #if 0   //added by mingwei
114     status = FIQ_RegHandler (TB_WDG_INT, WDG_TimerHandler);
115     SCI_PASSERT ( (FIQ_SUCCESS == status || FIQ_ISR_ASSIGNED == status),
116                   ("%s, %d, fiq regist status: %d", __MODULE__, __LINE__, status));
117 #endif
118 }
119
120 /*****************************************************************************/
121 //  Description:    This function Reset MCU
122 //  Author:         Younger.Yang
123 //  Note:
124 /*****************************************************************************/
125 PUBLIC void WDG_ResetMCU (void)
126 {
127     WDG_CONFIG_T config;
128     int32        ret;
129
130     WDG_TRACE ("Watch Dog Trace: WDG_ResetMCU");
131     config.state    = WDG_TIMER_STATE_START ;
132     config.mode     = WDG_TIMEOUT_MODE_RESET;
133     config.val      = 0x50;
134
135     ret = WDG_PHY_CONFIG (&config);
136 }
137
138 /*****************************************************************************/
139 //  Description:    This function Load WatchDog Timer Value
140 //  Author:         Binggo Zhou
141 //  Note:
142 /*****************************************************************************/
143 PUBLIC void WDG_TimerLoad (uint32 time_ms)
144 {
145     WDG_CONFIG_T config;
146     int32        ret;
147
148     WDG_TRACE ("Watch Dog Trace: WDG_TimerLoad %d", time_ms);
149
150     config.state    = WDG_TIMER_STATE_KEEP  ;
151     config.mode     = WDG_TIMEOUT_MODE_KEEP ;
152     config.val      = (time_ms * 1000) / 30;
153
154     ret = WDG_PHY_CONFIG (&config);
155 }