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> |
Umang Agrawal | 233d511 | 2019-05-23 16:31:14 +0530 | [diff] [blame] | 40 | #include <smem.h> |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 41 | |
| 42 | #if USER_FORCE_RESET_SUPPORT |
| 43 | /* Return 1 if it is a force resin triggered by user. */ |
| 44 | uint32_t is_user_force_reset(void) |
| 45 | { |
Umang Agrawal | 233d511 | 2019-05-23 16:31:14 +0530 | [diff] [blame] | 46 | uint8_t poff_reason1; |
| 47 | uint8_t poff_reason2; |
| 48 | uint8_t is_cold_boot; |
| 49 | uint32_t pmic = target_get_pmic(); |
| 50 | bool s3_reset; |
| 51 | |
| 52 | if (pmic == PMIC_IS_PM660) { |
| 53 | poff_reason1 = pm660_get_pon_poff_reason1(); |
| 54 | poff_reason2 = pm660_get_pon_poff_reason2(); |
| 55 | is_cold_boot = pm660_get_is_cold_boot(); |
| 56 | s3_reset = (poff_reason2 == PM660_STAGE3); |
| 57 | } else { |
| 58 | poff_reason1 = pm8x41_get_pon_poff_reason1(); |
| 59 | poff_reason2 = pm8x41_get_pon_poff_reason2(); |
| 60 | is_cold_boot = pm8x41_get_is_cold_boot(); |
| 61 | s3_reset = (poff_reason2 == STAGE3); |
| 62 | } |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 63 | |
| 64 | dprintf(SPEW, "poff_reason1: %d\n", poff_reason1); |
| 65 | dprintf(SPEW, "poff_reason2: %d\n", poff_reason2); |
Umang Agrawal | 233d511 | 2019-05-23 16:31:14 +0530 | [diff] [blame] | 66 | if (is_cold_boot && (poff_reason1 == KPDPWR_AND_RESIN || s3_reset)) |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 67 | return 1; |
| 68 | else |
| 69 | return 0; |
| 70 | } |
| 71 | #endif |
| 72 | |
| 73 | unsigned check_reboot_mode(void) |
| 74 | { |
| 75 | uint32_t restart_reason = 0; |
| 76 | |
| 77 | /* Read reboot reason and scrub it */ |
| 78 | restart_reason = readl(RESTART_REASON_ADDR); |
| 79 | writel(0x00, RESTART_REASON_ADDR); |
| 80 | |
| 81 | return restart_reason; |
| 82 | } |
| 83 | |
| 84 | unsigned check_hard_reboot_mode(void) |
| 85 | { |
| 86 | uint8_t hard_restart_reason = 0; |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 87 | |
| 88 | /* Read reboot reason and scrub it |
Channagoud Kadabi | 17a0c94 | 2015-10-08 17:40:35 -0700 | [diff] [blame] | 89 | * Bit-2 to bit-7 of SOFT_RB_SPARE for hard reset reason |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 90 | */ |
Channagoud Kadabi | 88e52c1 | 2015-08-06 15:21:14 -0700 | [diff] [blame] | 91 | hard_restart_reason = REG_READ(PON_SOFT_RB_SPARE); |
Channagoud Kadabi | 17a0c94 | 2015-10-08 17:40:35 -0700 | [diff] [blame] | 92 | REG_WRITE(PON_SOFT_RB_SPARE, hard_restart_reason & 0x03); |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 93 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 94 | /* Extract the bits 2 to 7 and return */ |
Channagoud Kadabi | 17a0c94 | 2015-10-08 17:40:35 -0700 | [diff] [blame] | 95 | return (hard_restart_reason & 0xFC) >> 2; |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 96 | } |
| 97 | |
lijuang | dc20de1 | 2015-02-11 12:09:57 +0800 | [diff] [blame] | 98 | /* Return true if it is triggered by alarm. */ |
| 99 | uint32_t check_alarm_boot(void) |
| 100 | { |
| 101 | /* Check reboot reason and power on reason */ |
| 102 | if (pm8x41_get_is_cold_boot()) { |
| 103 | if (pm8x41_get_pon_reason() == RTC_TRG) |
| 104 | return 1; |
| 105 | } else { |
| 106 | if (readl(RESTART_REASON_ADDR) == ALARM_BOOT) |
| 107 | return 1; |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 113 | void reboot_device(unsigned reboot_reason) |
| 114 | { |
| 115 | uint8_t reset_type = 0; |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 116 | int ret = 0; |
| 117 | #if USE_PON_REBOOT_REG |
| 118 | uint8_t value; |
| 119 | #endif |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 120 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 121 | /* Set cookie for dload mode */ |
| 122 | if(set_download_mode(reboot_reason)) { |
| 123 | dprintf(CRITICAL, "HALT: set_download_mode not supported\n"); |
| 124 | return; |
| 125 | } |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 126 | |
lijuang | f0c7b62 | 2016-05-24 16:06:12 +0800 | [diff] [blame] | 127 | if (reboot_reason != NORMAL_DLOAD && reboot_reason != EMERGENCY_DLOAD) { |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 128 | #if USE_PON_REBOOT_REG |
lijuang | f0c7b62 | 2016-05-24 16:06:12 +0800 | [diff] [blame] | 129 | value = REG_READ(PON_SOFT_RB_SPARE); |
| 130 | value |= (reboot_reason << 2); |
| 131 | REG_WRITE(PON_SOFT_RB_SPARE, value); |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 132 | #else |
lijuang | f0c7b62 | 2016-05-24 16:06:12 +0800 | [diff] [blame] | 133 | writel(reboot_reason, RESTART_REASON_ADDR); |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 134 | #endif |
lijuang | f0c7b62 | 2016-05-24 16:06:12 +0800 | [diff] [blame] | 135 | } |
| 136 | |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 137 | /* For Dload cases do a warm reset |
| 138 | * For other cases do a hard reset |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 139 | */ |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 140 | #if USE_PON_REBOOT_REG |
lijuang | 1cff838 | 2016-01-11 17:56:54 +0800 | [diff] [blame] | 141 | if(reboot_reason == NORMAL_DLOAD || reboot_reason == EMERGENCY_DLOAD) { |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 142 | #else |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 143 | if(reboot_reason == FASTBOOT_MODE || reboot_reason == NORMAL_DLOAD || |
lijuang | 1cff838 | 2016-01-11 17:56:54 +0800 | [diff] [blame] | 144 | reboot_reason == EMERGENCY_DLOAD || reboot_reason == RECOVERY_MODE) { |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 145 | #endif |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 146 | reset_type = PON_PSHOLD_WARM_RESET; |
lijuang | 1cff838 | 2016-01-11 17:56:54 +0800 | [diff] [blame] | 147 | #if DISABLE_DLOAD_MODE |
| 148 | if (reboot_reason == NORMAL_DLOAD) |
| 149 | reset_type = PON_PSHOLD_HARD_RESET; |
| 150 | #endif |
| 151 | } else { |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 152 | reset_type = PON_PSHOLD_HARD_RESET; |
lijuang | 1cff838 | 2016-01-11 17:56:54 +0800 | [diff] [blame] | 153 | } |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 154 | |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 155 | pmic_reset_configure(reset_type); |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 156 | |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 157 | /* Force spmi shutdown to avoid spmi lock up on some pmics */ |
| 158 | ret = is_scm_call_available(SCM_SVC_PWR, SCM_IO_DISABLE_PMIC_ARBITER); |
| 159 | if ( ret > 0) |
| 160 | { |
| 161 | ret = scm_halt_pmic_arbiter(); |
| 162 | if (ret) |
| 163 | dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret); |
| 164 | } |
lijuang | fdf2fa6 | 2015-03-11 16:46:41 +0800 | [diff] [blame] | 165 | |
| 166 | /* Drop PS_HOLD for MSM */ |
| 167 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 168 | |
| 169 | mdelay(5000); |
| 170 | |
| 171 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 172 | } |
| 173 | |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 174 | void shutdown_device() |
| 175 | { |
| 176 | dprintf(CRITICAL, "Going down for shutdown.\n"); |
| 177 | |
| 178 | /* Configure PMIC for shutdown. */ |
| 179 | pmic_reset_configure(PON_PSHOLD_SHUTDOWN); |
| 180 | |
| 181 | /* Drop PS_HOLD for MSM */ |
| 182 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 183 | |
| 184 | mdelay(5000); |
| 185 | |
| 186 | dprintf(CRITICAL, "Shutdown failed\n"); |
| 187 | |
| 188 | ASSERT(0); |
| 189 | } |