tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / sc8830 / 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 #include <asm/arch/watchdog_reg_v3.h>
29
30 #define  WDG_TRACE  printf
31 /**---------------------------------------------------------------------------*
32  **                      Function Declaration                                 *
33  **---------------------------------------------------------------------------*/
34
35 /*****************************************************************************/
36 //  Description:    This function disable WDG timer
37 //  Author:         Jimmy.Jia
38 //  Note:           no rtc_clk to drive the counter
39 //
40 /*****************************************************************************/
41 PUBLIC void WDG_TimerStop
42 (
43     void
44 )
45 {
46     WDG_CONFIG_T config;
47     int32        ret;
48
49     WDG_TRACE ("Watch Dog Trace: WDG_TimerStop");
50     WDG_PHY_INT_CLR();
51
52     config.state    = WDG_TIMER_STATE_STOP  ;
53     config.mode     = WDG_TIMEOUT_MODE_RESET;
54     config.val      = WDG_MAX_COUNT;
55
56     ret = WDG_PHY_CONFIG (&config);
57
58     return;
59 }
60
61 /*****************************************************************************/
62 //  Description:    This function initialize and setup timer with given value
63 //  Author:         Jimmy.Jia
64 //  Note:           rtc_clk drive the counter
65 //                  load regiter is 32 bits wide so that don't check if param's valid
66 /*****************************************************************************/
67 PUBLIC void WDG_TimerStart
68 (
69     uint32 init_val
70 )
71 {
72     WDG_CONFIG_T config;
73     int32        ret;
74
75     WDG_TRACE ("Watch Dog Trace: WDG_TimerStart");
76
77     config.state    = WDG_TIMER_STATE_START ;
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 }
114
115 /*****************************************************************************/
116 //  Description:    This function Reset MCU
117 //  Author:         Younger.Yang
118 //  Note:
119 /*****************************************************************************/
120 PUBLIC void WDG_ResetMCU (void)
121 {
122     WDG_CONFIG_T config;
123     int32        ret;
124
125     WDG_TRACE ("Watch Dog Trace: WDG_ResetMCU");
126     config.state    = WDG_TIMER_STATE_START ;
127     config.mode     = WDG_TIMEOUT_MODE_RESET;
128     config.val      = 0x50;
129
130     ret = WDG_PHY_CONFIG (&config);
131 }
132
133 /*****************************************************************************/
134 //  Description:    This function Load WatchDog Timer Value
135 //  Author:         Binggo Zhou
136 //  Note:
137 /*****************************************************************************/
138 PUBLIC void WDG_TimerLoad (uint32 time_ms)
139 {
140     WDG_CONFIG_T config;
141     int32        ret;
142
143     WDG_TRACE ("Watch Dog Trace: WDG_TimerLoad %d", time_ms);
144
145     config.state    = WDG_TIMER_STATE_KEEP  ;
146     config.mode     = WDG_TIMEOUT_MODE_KEEP ;
147     config.val      = (time_ms * 1000) / 30;
148
149     ret = WDG_PHY_CONFIG (&config);
150 }
151
152 PUBLIC uint32 WDG_PHY_RST_INT_ON(void)
153 {
154         uint32 ret = 0;
155         uint32 val = 0;
156         val = WDG_PHY_RST_RAW_INT();
157         printf("hw watchdog int raw status 0x%x\n", val);
158         ret = val & WDG_INT_RST_BIT;
159         WDG_PHY_INT_CLR();
160         return ret;
161 }