lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame^] | 1 | /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <platform/iomap.h> |
| 31 | #include <reg.h> |
| 32 | #include <target.h> |
| 33 | #include <platform.h> |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 34 | #include <pm8x41.h> |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 35 | #include <pm8x41_hw.h> |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 36 | #include <scm.h> |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 37 | #include <stdlib.h> |
| 38 | #include <reboot.h> |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 39 | #include <qtimer.h> |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 40 | |
| 41 | #if USER_FORCE_RESET_SUPPORT |
| 42 | /* Return 1 if it is a force resin triggered by user. */ |
| 43 | uint32_t is_user_force_reset(void) |
| 44 | { |
| 45 | uint8_t poff_reason1 = pm8x41_get_pon_poff_reason1(); |
| 46 | uint8_t poff_reason2 = pm8x41_get_pon_poff_reason2(); |
| 47 | |
| 48 | dprintf(SPEW, "poff_reason1: %d\n", poff_reason1); |
| 49 | dprintf(SPEW, "poff_reason2: %d\n", poff_reason2); |
| 50 | if (pm8x41_get_is_cold_boot() && (poff_reason1 == KPDPWR_AND_RESIN || |
| 51 | poff_reason2 == STAGE3)) |
| 52 | return 1; |
| 53 | else |
| 54 | return 0; |
| 55 | } |
| 56 | #endif |
| 57 | |
| 58 | unsigned check_reboot_mode(void) |
| 59 | { |
| 60 | uint32_t restart_reason = 0; |
| 61 | |
| 62 | /* Read reboot reason and scrub it */ |
| 63 | restart_reason = readl(RESTART_REASON_ADDR); |
| 64 | writel(0x00, RESTART_REASON_ADDR); |
| 65 | |
| 66 | return restart_reason; |
| 67 | } |
| 68 | |
| 69 | unsigned check_hard_reboot_mode(void) |
| 70 | { |
| 71 | uint8_t hard_restart_reason = 0; |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 72 | |
| 73 | /* Read reboot reason and scrub it |
Channagoud Kadabi | 17a0c94 | 2015-10-08 17:40:35 -0700 | [diff] [blame] | 74 | * Bit-2 to bit-7 of SOFT_RB_SPARE for hard reset reason |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 75 | */ |
Channagoud Kadabi | 88e52c1 | 2015-08-06 15:21:14 -0700 | [diff] [blame] | 76 | hard_restart_reason = REG_READ(PON_SOFT_RB_SPARE); |
Channagoud Kadabi | 17a0c94 | 2015-10-08 17:40:35 -0700 | [diff] [blame] | 77 | REG_WRITE(PON_SOFT_RB_SPARE, hard_restart_reason & 0x03); |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 78 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame^] | 79 | /* Extract the bits 2 to 7 and return */ |
Channagoud Kadabi | 17a0c94 | 2015-10-08 17:40:35 -0700 | [diff] [blame] | 80 | return (hard_restart_reason & 0xFC) >> 2; |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 81 | } |
| 82 | |
lijuang | dc20de1 | 2015-02-11 12:09:57 +0800 | [diff] [blame] | 83 | /* Return true if it is triggered by alarm. */ |
| 84 | uint32_t check_alarm_boot(void) |
| 85 | { |
| 86 | /* Check reboot reason and power on reason */ |
| 87 | if (pm8x41_get_is_cold_boot()) { |
| 88 | if (pm8x41_get_pon_reason() == RTC_TRG) |
| 89 | return 1; |
| 90 | } else { |
| 91 | if (readl(RESTART_REASON_ADDR) == ALARM_BOOT) |
| 92 | return 1; |
| 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 98 | void reboot_device(unsigned reboot_reason) |
| 99 | { |
| 100 | uint8_t reset_type = 0; |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 101 | int ret = 0; |
| 102 | #if USE_PON_REBOOT_REG |
| 103 | uint8_t value; |
| 104 | #endif |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 105 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame^] | 106 | /* Set cookie for dload mode */ |
| 107 | if(set_download_mode(reboot_reason)) { |
| 108 | dprintf(CRITICAL, "HALT: set_download_mode not supported\n"); |
| 109 | return; |
| 110 | } |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 111 | |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 112 | #if USE_PON_REBOOT_REG |
| 113 | value = REG_READ(PON_SOFT_RB_SPARE); |
Channagoud Kadabi | 17a0c94 | 2015-10-08 17:40:35 -0700 | [diff] [blame] | 114 | value |= (reboot_reason << 2); |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 115 | REG_WRITE(PON_SOFT_RB_SPARE, value); |
| 116 | #else |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 117 | writel(reboot_reason, RESTART_REASON_ADDR); |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 118 | #endif |
| 119 | /* For Dload cases do a warm reset |
| 120 | * For other cases do a hard reset |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 121 | */ |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 122 | #if USE_PON_REBOOT_REG |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame^] | 123 | if(reboot_reason == NORMAL_DLOAD || reboot_reason == EMERGENCY_DLOAD) |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 124 | #else |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame^] | 125 | if(reboot_reason == FASTBOOT_MODE || reboot_reason == NORMAL_DLOAD || |
| 126 | reboot_reason == EMERGENCY_DLOAD || reboot_reason == RECOVERY_MODE) |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 127 | #endif |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 128 | reset_type = PON_PSHOLD_WARM_RESET; |
| 129 | else |
| 130 | reset_type = PON_PSHOLD_HARD_RESET; |
| 131 | |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 132 | pmic_reset_configure(reset_type); |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 133 | |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 134 | /* Force spmi shutdown to avoid spmi lock up on some pmics */ |
| 135 | ret = is_scm_call_available(SCM_SVC_PWR, SCM_IO_DISABLE_PMIC_ARBITER); |
| 136 | if ( ret > 0) |
| 137 | { |
| 138 | ret = scm_halt_pmic_arbiter(); |
| 139 | if (ret) |
| 140 | dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret); |
| 141 | } |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 142 | |
| 143 | /* Drop PS_HOLD for MSM */ |
| 144 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 145 | |
| 146 | mdelay(5000); |
| 147 | |
| 148 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 149 | } |
| 150 | |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 151 | void shutdown_device() |
| 152 | { |
| 153 | dprintf(CRITICAL, "Going down for shutdown.\n"); |
| 154 | |
| 155 | /* Configure PMIC for shutdown. */ |
| 156 | pmic_reset_configure(PON_PSHOLD_SHUTDOWN); |
| 157 | |
| 158 | /* Drop PS_HOLD for MSM */ |
| 159 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 160 | |
| 161 | mdelay(5000); |
| 162 | |
| 163 | dprintf(CRITICAL, "Shutdown failed\n"); |
| 164 | |
| 165 | ASSERT(0); |
| 166 | } |