tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / platform / sprd / sys_reset.c
1 /*
2  * Copyright (C) 2012 Spreadtrum Communications Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #include <soc/sprd/sys_reset.h>
15 #include <linux/string.h>
16 #include <asm/bitops.h>
17
18 void sprd_set_reboot_mode(const char *cmd)
19 {
20         if(cmd)
21                 printk("sprd_set_reboot_mode:cmd=%s\n",cmd);
22         if (cmd && !(strncmp(cmd, "recovery", 8))) {
23                 sci_adi_raw_write(ANA_RST_STATUS, HWRST_STATUS_RECOVERY);
24         } else if (cmd && !strncmp(cmd, "alarm", 5)) {
25                 sci_adi_raw_write(ANA_RST_STATUS, HWRST_STATUS_ALARM);
26         } else if (cmd && !strncmp(cmd, "fastsleep", 9)) {
27                 sci_adi_raw_write(ANA_RST_STATUS, HWRST_STATUS_SLEEP);
28         } else if (cmd && !strncmp(cmd, "bootloader", 10)) {
29                 sci_adi_raw_write(ANA_RST_STATUS, HWRST_STATUS_FASTBOOT);
30         } else if (cmd && !strncmp(cmd, "panic", 5)) {
31                 sci_adi_raw_write(ANA_RST_STATUS, HWRST_STATUS_PANIC);
32         } else if (cmd && !strncmp(cmd, "special", 7)) {
33                 sci_adi_raw_write(ANA_RST_STATUS, HWRST_STATUS_SPECIAL);
34         } else if (cmd && !strncmp(cmd, "cftreboot", 9)) {
35                 sci_adi_raw_write(ANA_RST_STATUS, HWRST_STATUS_CFTREBOOT);
36         } else if (cmd && !strncmp(cmd, "autodloader", 11)) {
37                 sci_adi_raw_write(ANA_RST_STATUS, HWRST_STATUS_AUTODLOADER);
38         } else if (cmd && !strncmp(cmd, "iqmode", 6)) {
39                 sci_adi_raw_write(ANA_RST_STATUS, HWRST_STATUS_IQMODE);
40         } else if(cmd){
41                 sci_adi_raw_write(ANA_RST_STATUS, HWRST_STATUS_NORMAL);
42         }else{
43                 sci_adi_raw_write(ANA_RST_STATUS, HWRST_STATUS_SPECIAL);
44         }
45 }
46
47 void sprd_turnon_watchdog(unsigned int ms)
48 {
49         uint32_t cnt;
50
51         cnt = (ms * 1000) / WDG_CLK;
52
53         /*enable interface clk*/
54         sci_adi_set(ANA_AGEN, AGEN_WDG_EN);
55         /*enable work clk*/
56         sci_adi_set(ANA_RTC_CLK_EN, AGEN_RTC_WDG_EN);
57         sci_adi_raw_write(WDG_LOCK, WDG_UNLOCK_KEY);
58         sci_adi_set(WDG_CTRL, WDG_NEW_VER_EN);
59         WDG_LOAD_TIMER_VALUE(cnt);
60         sci_adi_set(WDG_CTRL, WDG_CNT_EN_BIT | WDG_RST_EN_BIT);
61         sci_adi_raw_write(WDG_LOCK, (uint16_t) (~WDG_UNLOCK_KEY));
62 }
63
64 void sprd_turnoff_watchdog(void)
65 {
66         sci_adi_raw_write(WDG_LOCK, WDG_UNLOCK_KEY);
67         /*wdg counter stop*/
68         sci_adi_clr(WDG_CTRL, WDG_CNT_EN_BIT);
69         /*disable the reset mode*/
70         sci_adi_clr(WDG_CTRL, WDG_RST_EN_BIT);
71         sci_adi_raw_write(WDG_LOCK, (uint16_t) (~WDG_UNLOCK_KEY));
72         /*stop the interface and work clk*/
73         sci_adi_clr(ANA_AGEN, AGEN_WDG_EN);
74         sci_adi_clr(ANA_RTC_CLK_EN, AGEN_RTC_WDG_EN);
75 }