blob: 9675b61bab12c0b10c09d2b50dd49b4eb65e6625 [file] [log] [blame]
Taniya Dascd1d0232012-07-03 17:50:47 +05301/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/reboot.h>
19#include <linux/pm.h>
20#include <asm/system_misc.h>
21#include <mach/proc_comm.h>
22
23#include "devices-msm7x2xa.h"
Taniya Dascd1d0232012-07-03 17:50:47 +053024
25static uint32_t restart_reason = 0x776655AA;
26
27static void msm_pm_power_off(void)
28{
Taniya Dascd1d0232012-07-03 17:50:47 +053029 msm_proc_comm(PCOM_POWER_DOWN, 0, 0);
30 for (;;)
31 ;
32}
33
34static void msm_pm_restart(char str, const char *cmd)
35{
Taniya Dascd1d0232012-07-03 17:50:47 +053036 pr_debug("The reset reason is %x\n", restart_reason);
37
38 /* Disable interrupts */
39 local_irq_disable();
40 local_fiq_disable();
41
42 /*
43 * Take out a flat memory mapping and will
44 * insert a 1:1 mapping in place of
45 * the user-mode pages to ensure predictable results
46 * This function takes care of flushing the caches
47 * and flushing the TLB.
48 */
49 setup_mm_for_reboot();
50
51 msm_proc_comm(PCOM_RESET_CHIP, &restart_reason, 0);
52
53 for (;;)
54 ;
55}
56
57static int msm_reboot_call
58 (struct notifier_block *this, unsigned long code, void *_cmd)
59{
60 if ((code == SYS_RESTART) && _cmd) {
61 char *cmd = _cmd;
62 if (!strncmp(cmd, "bootloader", 10)) {
63 restart_reason = 0x77665500;
64 } else if (!strncmp(cmd, "recovery", 8)) {
65 restart_reason = 0x77665502;
66 } else if (!strncmp(cmd, "eraseflash", 10)) {
67 restart_reason = 0x776655EF;
68 } else if (!strncmp(cmd, "oem-", 4)) {
69 unsigned long code;
70 int res;
71 res = kstrtoul(cmd + 4, 16, &code);
72 code &= 0xff;
73 restart_reason = 0x6f656d00 | code;
74 } else {
75 restart_reason = 0x77665501;
76 }
77 }
78 return NOTIFY_DONE;
79}
80
81static struct notifier_block msm_reboot_notifier = {
82 .notifier_call = msm_reboot_call,
83};
84
85static int __init msm_pm_restart_init(void)
86{
87 int ret;
88
89 pm_power_off = msm_pm_power_off;
90 arm_pm_restart = msm_pm_restart;
91
92 ret = register_reboot_notifier(&msm_reboot_notifier);
93 if (ret)
94 pr_err("Failed to register reboot notifier\n");
95
96 return ret;
97}
98late_initcall(msm_pm_restart_init);