blob: 28b862550043e2b2507b02e7833699cc26a894ec [file] [log] [blame]
xf.libfc6e712025-02-07 01:54:34 -08001/*
2 * linux/arch/arm/mach-zx297520v3/reset.c
3 *
4 * Copyright (C) 2015 ZTE-TSP
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/kernel.h>
18#include <linux/interrupt.h>
19#include <linux/irq.h>
20#include <linux/clockchips.h>
21#include <linux/clk.h>
22#include <linux/module.h>
23#include <linux/err.h>
24#include <linux/syscore_ops.h>
25#include <linux/gpio.h>
26#include <linux/miscdevice.h> /* For handling misc devices */
27#include <linux/fs.h> /* For file operations */
28#include <mach/board.h>
29#include <mach/iomap.h>
30#include <mach/spinlock.h>
31#include <linux/mfd/zx234290.h>
32#include <linux/delay.h>
33#include <linux/reboot.h>
34
35#define ZX_RESET_DEV "/dev/zx_reset"
36
37#define ZX_RESET_IOC_MAGIC 'W'
38/*ioctl cmd usd by device*/
39#define ZX_RESET_FAST_REBOOT _IOW(ZX_RESET_IOC_MAGIC, 1, char *)
40
41
42#define GLOBAL_RESET_REG (ZX_TOP_CRM_BASE)
43
44#define USER_RST_UNDEFINE 0
45#define USER_RST_TO_NORMAL 1
46#define USER_RST_TO_CHARGER 2
47#define USER_RST_TO_ALARM 3
48#define USER_RST_TO_EXCEPT 4
49#ifdef CONFIG_DWC_DEVICE_ONLY
50typedef enum
51{
52 GSM_RAM_PWR = 0,
53 GSM_DSP_PWR = 1,
54 EDCP_PWR = 4,
55 USB_CTRL_PWR = 8,
56 USB_HSIC_PWR = 9,
57
58 PARTITION_ALL = 10
59
60} T_ZDrvPow_Partition;
61
62typedef enum
63{
64 POW_MDL_1 = 0,
65 POW_MDL_ALL = 1
66} T_ZDrvPow_PowerModule;
67
68typedef enum
69{
70 POW_ENABLE = 0,
71 POW_DISABLE = 1,
72
73 POW_ENABLE_ALL
74} T_ZDrvPow_PowerEnable;
75
76extern int pow_partition_powerswitch(T_ZDrvPow_Partition part, T_ZDrvPow_PowerEnable ena);
77extern int zx234290_setusb_v0v9_sleepmode(T_ZDrvPmic_SlpMode mode);
78extern int zx234290_setusb_v3v3_sleepmode(T_ZDrvPmic_SlpMode mode);
79#endif
80static bool debug_stop_reboot = false;
81module_param(debug_stop_reboot, bool, 0644);
82
83#ifdef CONFIG_WATCHDOG_RESTART
84extern void wdt_restart(void);
85#endif
86
87extern void zx_denali_nand_lock(void);
88extern void zx_denali_nand_unlock(void);
89
90
91void zx29_restart(char mode, const char *cmd)
92{
93/* change to "#ifdef CONFIG_MFD_ZX234290/CONFIG_MFD_ZX234290_I2C" later! */
94#ifndef CONFIG_ARCH_ZX297520V3_CAP
95 /* reset */
96 unsigned char reg = 0;
97 int ret = 0;
98 u8 restart_flag = 0;
99 unsigned char status = USER_RST_UNDEFINE;
100
101 if (cmd == NULL) {
102 printk(KERN_INFO"restart:enter reboot :reset to normal\n");
103
104 /*set the vale = 1*/
105 status = USER_RST_TO_NORMAL;
106 } else if (strcmp(cmd,"drv_key reboot") == 0) {
107 printk(KERN_INFO"restart:enter drv_key reboot :reset to charger\n");
108
109 /*set the vale = 2*/
110 status = USER_RST_TO_CHARGER;
111 } else if (strcmp(cmd,"drv_except reboot") == 0) {
112 printk(KERN_INFO"restart:enter drv_except reboot :reset to normal\n");
113
114 /* set the vale = 4 */
115 status = USER_RST_TO_EXCEPT;
116 } else if (strcmp(cmd,"mmi_key reboot") == 0) {
117 printk(KERN_INFO"restart:enter mmi_key reboot :reset to charger\n");
118
119 /*set the vale = 2*/
120 status = USER_RST_TO_CHARGER;
121 } else if (strcmp(cmd,"mmi_rtc reboot") == 0) {
122 printk(KERN_INFO"restart: enter mmi_rtc reboot: reset to alarm\n");
123
124 status = USER_RST_TO_ALARM;
125 } else {
126 printk(KERN_INFO"restart: reboot with cmd %s\n", cmd);
127
128 /*set the vale = 1*/
129 status = USER_RST_TO_NORMAL;
130 }
131 if(debug_stop_reboot )
132 {
133 printk(KERN_INFO"debug_stop_reboot= 0x%x, for debug, bug_on!!!!\n", debug_stop_reboot);
134 panic("reboot");
135 }
136 /*reset spifc cs*/
137 soft_spin_lock_nand_psm(NAND_SFLOCK);
138 zx29_gpio_config(ZX29_GPIO_93, GPIO93_SPIFC_CS);
139 gpio_set_value(ZX29_GPIO_86,GPIO_HIGH);
140
141#ifdef CONFIG_XR_WLAN
142 gpio_set_value(ZX29_GPIO_121,GPIO_LOW);
143 if (gpio_get_value(ZX29_GPIO_123) == 1)
144 mdelay(4000);
145#endif
146
147 if (status != USER_RST_TO_EXCEPT) {
148#ifdef CONFIG_DWC_DEVICE_ONLY
149 //add by gsn,for user mode
150 zDrvPmic_SetNormal_Onoff(VUSB_0V9,PM_ENABLE);
151 zDrvPmic_SetNormal_Onoff(VUSB_3V3,PM_ENABLE);
152 pow_partition_powerswitch(USB_CTRL_PWR, POW_ENABLE);
153
154 zx234290_setusb_v0v9_sleepmode(PM_SLPMODE_ECO_SLPV);
155 zx234290_setusb_v3v3_sleepmode(PM_SLPMODE_ECO_SLPV);
156#endif
157 local_irq_disable();
158 soft_spin_lock_psm(I2C2_SFLOCK);
159
160 ret = Zx234290_SetUserReg_PSM(status);
161 if(0!= ret){
162 panic("restart:set restar flag error!\n");
163 }
164
165 #ifdef CONFIG_WATCHDOG_RESTART //delete 32k
166 wdt_restart();
167 #else
168 zx_write_reg(GLOBAL_RESET_REG, 1);
169 #endif
170
171 soft_spin_unlock_psm(I2C2_SFLOCK);
172 local_irq_enable();
173 } else {
174 ret = Zx234290_SetUserReg_PSM(USER_RST_TO_NORMAL);
175 if (ret) {
176 panic("restart:set restar flag error!\n");
177 }
178
179 #ifdef CONFIG_WATCHDOG_RESTART //delete 32k
180 local_irq_disable();
181 wdt_restart();
182 #else
183 zx_write_reg(GLOBAL_RESET_REG, 1);
184 #endif
185 }
186#endif
187}
188EXPORT_SYMBOL(zx29_restart);
189
190
191 /********************************************************************************
192 * Function:
193 * Description:
194 * Parameters:
195 * Returns:
196 * Others:
197 ********************************************************************************/
198
199 static int zx_reset_open(struct inode *inode, struct file *file)
200{
201 return 0;
202}
203
204static int zx_reset_close(struct inode *inode, struct file *file)
205{
206 return 0;
207}
208static long zx_reset_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
209{
210 switch(cmd)
211 {
212 case ZX_RESET_FAST_REBOOT:
213 //zx29_restart (NULL, "at set fast reboot!\n\n");
214#ifndef CONFIG_MTD_SPI_NOR
215 zx_denali_nand_lock();
216#endif
217 kernel_restart("at set fast reboot!\n\n");
218#ifndef CONFIG_MTD_SPI_NOR
219 zx_denali_nand_unlock();
220#endif
221 break;
222
223 default:
224 break;
225 }
226
227 return 0;
228}
229
230
231 static const struct file_operations zx_reset_fops = {
232 .owner = THIS_MODULE,
233 .unlocked_ioctl = zx_reset_ioctl,
234 .open = zx_reset_open,
235 .release = zx_reset_close,
236};
237
238static struct miscdevice zx_reset_miscdev = {
239 .minor = MISC_DYNAMIC_MINOR,
240 .name = "zx_reset",
241 .fops = &zx_reset_fops,
242};
243
244 static int __init zx_reset_init(void)
245 {
246 int ret=0;
247 ret = misc_register(&zx_reset_miscdev);
248 if (ret != 0) {
249 printk(KERN_ERR"reset cannot register miscdev on(err=%d)\n", ret);
250 return ret;
251 }
252 return 0;
253 }
254
255late_initcall_sync(zx_reset_init);
256
257