Taniya Das | cd1d023 | 2012-07-03 17:50:47 +0530 | [diff] [blame^] | 1 | /* 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" |
| 24 | #include "smd_rpcrouter.h" |
| 25 | |
| 26 | static uint32_t restart_reason = 0x776655AA; |
| 27 | |
| 28 | static void msm_pm_power_off(void) |
| 29 | { |
| 30 | msm_rpcrouter_close(); |
| 31 | msm_proc_comm(PCOM_POWER_DOWN, 0, 0); |
| 32 | for (;;) |
| 33 | ; |
| 34 | } |
| 35 | |
| 36 | static void msm_pm_restart(char str, const char *cmd) |
| 37 | { |
| 38 | msm_rpcrouter_close(); |
| 39 | pr_debug("The reset reason is %x\n", restart_reason); |
| 40 | |
| 41 | /* Disable interrupts */ |
| 42 | local_irq_disable(); |
| 43 | local_fiq_disable(); |
| 44 | |
| 45 | /* |
| 46 | * Take out a flat memory mapping and will |
| 47 | * insert a 1:1 mapping in place of |
| 48 | * the user-mode pages to ensure predictable results |
| 49 | * This function takes care of flushing the caches |
| 50 | * and flushing the TLB. |
| 51 | */ |
| 52 | setup_mm_for_reboot(); |
| 53 | |
| 54 | msm_proc_comm(PCOM_RESET_CHIP, &restart_reason, 0); |
| 55 | |
| 56 | for (;;) |
| 57 | ; |
| 58 | } |
| 59 | |
| 60 | static int msm_reboot_call |
| 61 | (struct notifier_block *this, unsigned long code, void *_cmd) |
| 62 | { |
| 63 | if ((code == SYS_RESTART) && _cmd) { |
| 64 | char *cmd = _cmd; |
| 65 | if (!strncmp(cmd, "bootloader", 10)) { |
| 66 | restart_reason = 0x77665500; |
| 67 | } else if (!strncmp(cmd, "recovery", 8)) { |
| 68 | restart_reason = 0x77665502; |
| 69 | } else if (!strncmp(cmd, "eraseflash", 10)) { |
| 70 | restart_reason = 0x776655EF; |
| 71 | } else if (!strncmp(cmd, "oem-", 4)) { |
| 72 | unsigned long code; |
| 73 | int res; |
| 74 | res = kstrtoul(cmd + 4, 16, &code); |
| 75 | code &= 0xff; |
| 76 | restart_reason = 0x6f656d00 | code; |
| 77 | } else { |
| 78 | restart_reason = 0x77665501; |
| 79 | } |
| 80 | } |
| 81 | return NOTIFY_DONE; |
| 82 | } |
| 83 | |
| 84 | static struct notifier_block msm_reboot_notifier = { |
| 85 | .notifier_call = msm_reboot_call, |
| 86 | }; |
| 87 | |
| 88 | static int __init msm_pm_restart_init(void) |
| 89 | { |
| 90 | int ret; |
| 91 | |
| 92 | pm_power_off = msm_pm_power_off; |
| 93 | arm_pm_restart = msm_pm_restart; |
| 94 | |
| 95 | ret = register_reboot_notifier(&msm_reboot_notifier); |
| 96 | if (ret) |
| 97 | pr_err("Failed to register reboot notifier\n"); |
| 98 | |
| 99 | return ret; |
| 100 | } |
| 101 | late_initcall(msm_pm_restart_init); |