Parth Dixit | 80bb523 | 2016-01-05 15:26:22 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [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> |
| 34 | #include <uart_dm.h> |
| 35 | #include <mmc.h> |
| 36 | #include <platform/gpio.h> |
| 37 | #include <dev/keys.h> |
| 38 | #include <spmi_v2.h> |
| 39 | #include <pm8x41.h> |
Aparna Mallavarapu | bc6315e | 2015-04-11 04:00:43 +0530 | [diff] [blame] | 40 | #include <pm8x41_hw.h> |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 41 | #include <board.h> |
| 42 | #include <baseband.h> |
| 43 | #include <hsusb.h> |
| 44 | #include <scm.h> |
| 45 | #include <platform/gpio.h> |
| 46 | #include <platform/gpio.h> |
| 47 | #include <platform/irqs.h> |
| 48 | #include <platform/clock.h> |
Aparna Mallavarapu | bc6315e | 2015-04-11 04:00:43 +0530 | [diff] [blame] | 49 | #include <platform/timer.h> |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 50 | #include <crypto5_wrapper.h> |
| 51 | #include <partition_parser.h> |
| 52 | #include <stdlib.h> |
Aparna Mallavarapu | fa5f8a7 | 2015-03-31 06:21:36 +0530 | [diff] [blame] | 53 | #include <rpm-smd.h> |
Aparna Mallavarapu | bc6315e | 2015-04-11 04:00:43 +0530 | [diff] [blame] | 54 | #include <spmi.h> |
| 55 | #include <sdhci_msm.h> |
| 56 | #include <clock.h> |
Parth Dixit | 6e6bad5 | 2015-07-30 19:02:38 +0530 | [diff] [blame] | 57 | #include <boot_device.h> |
| 58 | #include <secapp_loader.h> |
| 59 | #include <rpmb.h> |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 60 | #include <smem.h> |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 61 | |
Padmanabhan Komanduru | 9d49f89 | 2015-04-10 12:58:46 -0700 | [diff] [blame] | 62 | #include "target/display.h" |
| 63 | |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 64 | #if LONG_PRESS_POWER_ON |
| 65 | #include <shutdown_detect.h> |
| 66 | #endif |
| 67 | |
Matthew Qin | 47dfdb7 | 2015-06-10 21:29:11 +0800 | [diff] [blame] | 68 | #if PON_VIB_SUPPORT |
| 69 | #include <vibrator.h> |
| 70 | #endif |
| 71 | |
| 72 | #if PON_VIB_SUPPORT |
| 73 | #define VIBRATE_TIME 250 |
| 74 | #endif |
| 75 | |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 76 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 77 | #define PMIC_ARB_OWNER_ID 0 |
| 78 | #define TLMM_VOL_UP_BTN_GPIO 85 |
Unnati Gandhi | fe004a9 | 2015-06-01 13:06:06 +0530 | [diff] [blame] | 79 | #define TLMM_VOL_UP_BTN_GPIO_8956 113 |
Parth Dixit | 720d3b9 | 2015-10-30 01:21:34 +0530 | [diff] [blame] | 80 | #define TLMM_VOL_UP_BTN_GPIO_8937 91 |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 81 | |
| 82 | #define FASTBOOT_MODE 0x77665500 |
Aparna Mallavarapu | 680a133 | 2015-04-29 19:14:09 +0530 | [diff] [blame] | 83 | #define RECOVERY_MODE 0x77665502 |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 84 | #define PON_SOFT_RB_SPARE 0x88F |
| 85 | |
Aparna Mallavarapu | 1e8b093 | 2015-03-29 23:38:13 +0530 | [diff] [blame] | 86 | #define CE1_INSTANCE 1 |
| 87 | #define CE_EE 1 |
| 88 | #define CE_FIFO_SIZE 64 |
| 89 | #define CE_READ_PIPE 3 |
| 90 | #define CE_WRITE_PIPE 2 |
| 91 | #define CE_READ_PIPE_LOCK_GRP 0 |
| 92 | #define CE_WRITE_PIPE_LOCK_GRP 0 |
| 93 | #define CE_ARRAY_SIZE 20 |
| 94 | |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 95 | struct mmc_device *dev; |
| 96 | |
| 97 | static uint32_t mmc_pwrctl_base[] = |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 98 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 99 | |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 100 | static uint32_t mmc_sdhci_base[] = |
| 101 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE }; |
| 102 | |
| 103 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 104 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ }; |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 105 | |
| 106 | void target_early_init(void) |
| 107 | { |
| 108 | #if WITH_DEBUG_UART |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 109 | uart_dm_init(2, 0, BLSP1_UART1_BASE); |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 110 | #endif |
| 111 | } |
| 112 | |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 113 | static void set_sdc_power_ctrl() |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 114 | { |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 115 | /* Drive strength configs for sdc pins */ |
| 116 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 117 | { |
| 118 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, 0}, |
| 119 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, 0}, |
| 120 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK , 0}, |
| 121 | }; |
| 122 | |
| 123 | /* Pull configs for sdc pins */ |
| 124 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 125 | { |
| 126 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, 0}, |
| 127 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0}, |
| 128 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0}, |
| 129 | }; |
| 130 | |
Aparna Mallavarapu | 2913891 | 2015-04-13 23:45:35 +0530 | [diff] [blame] | 131 | struct tlmm_cfgs sdc1_rclk_cfg[] = |
| 132 | { |
| 133 | { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, 0}, |
| 134 | }; |
| 135 | |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 136 | /* Set the drive strength & pull control values */ |
| 137 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 138 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
Aparna Mallavarapu | 2913891 | 2015-04-13 23:45:35 +0530 | [diff] [blame] | 139 | tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg)); |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | void target_sdc_init() |
| 143 | { |
| 144 | struct mmc_config_data config; |
| 145 | |
| 146 | /* Set drive strength & pull ctrl values */ |
| 147 | set_sdc_power_ctrl(); |
| 148 | |
| 149 | /* Try slot 1*/ |
| 150 | config.slot = 1; |
| 151 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
Aparna Mallavarapu | 680a133 | 2015-04-29 19:14:09 +0530 | [diff] [blame] | 152 | config.max_clk_rate = MMC_CLK_192MHZ; |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 153 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 154 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 155 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 156 | config.hs400_support = 1; |
| 157 | |
| 158 | if (!(dev = mmc_init(&config))) { |
| 159 | /* Try slot 2 */ |
| 160 | config.slot = 2; |
| 161 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 162 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 163 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 164 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 165 | config.hs400_support = 0; |
| 166 | |
| 167 | if (!(dev = mmc_init(&config))) { |
| 168 | dprintf(CRITICAL, "mmc init failed!"); |
| 169 | ASSERT(0); |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void *target_mmc_device() |
| 175 | { |
| 176 | return (void *) dev; |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /* Return 1 if vol_up pressed */ |
Rami Butstein | e51318a | 2015-05-27 16:23:17 +0300 | [diff] [blame] | 180 | int target_volume_up() |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 181 | { |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 182 | static uint8_t first_time = 0; |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 183 | uint8_t status = 0; |
Unnati Gandhi | e3a5c0e | 2015-06-14 17:31:07 +0530 | [diff] [blame] | 184 | uint32_t vol_up_gpio; |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 185 | |
Unnati Gandhi | fe004a9 | 2015-06-01 13:06:06 +0530 | [diff] [blame] | 186 | if(platform_is_msm8956()) |
Unnati Gandhi | e3a5c0e | 2015-06-14 17:31:07 +0530 | [diff] [blame] | 187 | vol_up_gpio = TLMM_VOL_UP_BTN_GPIO_8956; |
Parth Dixit | 88a8ee1 | 2016-01-08 15:14:37 +0530 | [diff] [blame] | 188 | else if(platform_is_msm8937() || platform_is_msmgold()) |
Parth Dixit | 720d3b9 | 2015-10-30 01:21:34 +0530 | [diff] [blame] | 189 | vol_up_gpio = TLMM_VOL_UP_BTN_GPIO_8937; |
Unnati Gandhi | fe004a9 | 2015-06-01 13:06:06 +0530 | [diff] [blame] | 190 | else |
Unnati Gandhi | e3a5c0e | 2015-06-14 17:31:07 +0530 | [diff] [blame] | 191 | vol_up_gpio = TLMM_VOL_UP_BTN_GPIO; |
| 192 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 193 | if (!first_time) { |
| 194 | gpio_tlmm_config(vol_up_gpio, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE); |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 195 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 196 | /* Wait for the gpio config to take effect - debounce time */ |
| 197 | udelay(10000); |
| 198 | |
| 199 | first_time = 1; |
| 200 | } |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 201 | |
| 202 | /* Get status of GPIO */ |
Unnati Gandhi | e3a5c0e | 2015-06-14 17:31:07 +0530 | [diff] [blame] | 203 | status = gpio_status(vol_up_gpio); |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 204 | |
Aparna Mallavarapu | fa5f8a7 | 2015-03-31 06:21:36 +0530 | [diff] [blame] | 205 | /* Active low signal. */ |
Aparna Mallavarapu | db938b6 | 2015-04-09 01:00:55 +0530 | [diff] [blame] | 206 | return !status; |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /* Return 1 if vol_down pressed */ |
| 210 | uint32_t target_volume_down() |
| 211 | { |
| 212 | /* Volume down button tied in with PMIC RESIN. */ |
| 213 | return pm8x41_resin_status(); |
| 214 | } |
| 215 | |
Parth Dixit | 300a3b9 | 2015-06-19 16:38:12 +0530 | [diff] [blame] | 216 | uint32_t target_is_pwrkey_pon_reason() |
| 217 | { |
| 218 | uint8_t pon_reason = pm8950_get_pon_reason(); |
| 219 | if (pm8x41_get_is_cold_boot() && ((pon_reason == KPDPWR_N) || (pon_reason == (KPDPWR_N|PON1)))) |
| 220 | return 1; |
| 221 | else |
| 222 | return 0; |
| 223 | } |
| 224 | |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 225 | static void target_keystatus() |
| 226 | { |
| 227 | keys_init(); |
| 228 | |
| 229 | if(target_volume_down()) |
| 230 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 231 | |
| 232 | if(target_volume_up()) |
| 233 | keys_post_event(KEY_VOLUMEUP, 1); |
| 234 | } |
| 235 | |
| 236 | /* Configure PMIC and Drop PS_HOLD for shutdown */ |
| 237 | void shutdown_device() |
| 238 | { |
| 239 | dprintf(CRITICAL, "Going down for shutdown.\n"); |
| 240 | |
| 241 | /* Configure PMIC for shutdown */ |
| 242 | pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN); |
| 243 | |
| 244 | /* Drop PS_HOLD for MSM */ |
| 245 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 246 | |
| 247 | mdelay(5000); |
| 248 | |
| 249 | dprintf(CRITICAL, "shutdown failed\n"); |
| 250 | |
| 251 | ASSERT(0); |
| 252 | } |
| 253 | |
| 254 | |
| 255 | void target_init(void) |
| 256 | { |
Parth Dixit | 5b954e0 | 2015-10-17 22:20:31 +0530 | [diff] [blame] | 257 | #if VERIFIED_BOOT |
Parth Dixit | b73ff34 | 2015-10-27 17:34:08 +0530 | [diff] [blame] | 258 | #if !VBOOT_MOTA |
Parth Dixit | 6e6bad5 | 2015-07-30 19:02:38 +0530 | [diff] [blame] | 259 | int ret = 0; |
Parth Dixit | 5b954e0 | 2015-10-17 22:20:31 +0530 | [diff] [blame] | 260 | #endif |
Parth Dixit | b73ff34 | 2015-10-27 17:34:08 +0530 | [diff] [blame] | 261 | #endif |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 262 | dprintf(INFO, "target_init()\n"); |
| 263 | |
| 264 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 265 | |
Parth Dixit | 88a8ee1 | 2016-01-08 15:14:37 +0530 | [diff] [blame] | 266 | if(platform_is_msm8937() || platform_is_msmgold()) |
Parth Dixit | 3e6dead | 2015-12-08 15:04:54 +0530 | [diff] [blame] | 267 | { |
| 268 | uint8_t pmi_rev = 0; |
| 269 | uint32_t pmi_type = 0; |
| 270 | |
| 271 | pmi_type = board_pmic_target(1) & 0xffff; |
| 272 | if(pmi_type == PMIC_IS_PMI8950) |
| 273 | { |
| 274 | /* read pmic spare register for rev */ |
| 275 | pmi_rev = pmi8950_get_pmi_subtype(); |
| 276 | if(pmi_rev) |
| 277 | board_pmi_target_set(1,pmi_rev); |
| 278 | } |
| 279 | } |
| 280 | |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 281 | target_keystatus(); |
| 282 | |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 283 | target_sdc_init(); |
| 284 | if (partition_read_table()) |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 285 | { |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 286 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 287 | ASSERT(0); |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 288 | } |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 289 | |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 290 | #if LONG_PRESS_POWER_ON |
| 291 | shutdown_detect(); |
| 292 | #endif |
Matthew Qin | 47dfdb7 | 2015-06-10 21:29:11 +0800 | [diff] [blame] | 293 | |
| 294 | #if PON_VIB_SUPPORT |
| 295 | /* turn on vibrator to indicate that phone is booting up to end user */ |
| 296 | vib_timed_turn_on(VIBRATE_TIME); |
| 297 | #endif |
| 298 | |
Aparna Mallavarapu | 1e8b093 | 2015-03-29 23:38:13 +0530 | [diff] [blame] | 299 | if (target_use_signed_kernel()) |
| 300 | target_crypto_init_params(); |
Aparna Mallavarapu | fa5f8a7 | 2015-03-31 06:21:36 +0530 | [diff] [blame] | 301 | |
Parth Dixit | 5b954e0 | 2015-10-17 22:20:31 +0530 | [diff] [blame] | 302 | #if VERIFIED_BOOT |
Parth Dixit | b73ff34 | 2015-10-27 17:34:08 +0530 | [diff] [blame] | 303 | #if !VBOOT_MOTA |
Parth Dixit | 0eb7369 | 2015-08-09 17:32:27 +0530 | [diff] [blame] | 304 | clock_ce_enable(CE1_INSTANCE); |
| 305 | |
Parth Dixit | 6e6bad5 | 2015-07-30 19:02:38 +0530 | [diff] [blame] | 306 | /* Initialize Qseecom */ |
| 307 | ret = qseecom_init(); |
| 308 | |
| 309 | if (ret < 0) |
| 310 | { |
| 311 | dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret); |
| 312 | ASSERT(0); |
| 313 | } |
| 314 | |
| 315 | /* Start Qseecom */ |
| 316 | ret = qseecom_tz_init(); |
| 317 | |
| 318 | if (ret < 0) |
| 319 | { |
| 320 | dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret); |
| 321 | ASSERT(0); |
| 322 | } |
| 323 | |
Parth Dixit | b4b2ffa | 2015-10-09 15:31:14 +0530 | [diff] [blame] | 324 | if (rpmb_init() < 0) |
| 325 | { |
| 326 | dprintf(CRITICAL, "RPMB init failed\n"); |
| 327 | ASSERT(0); |
| 328 | } |
| 329 | |
Parth Dixit | 6e6bad5 | 2015-07-30 19:02:38 +0530 | [diff] [blame] | 330 | /* |
| 331 | * Load the sec app for first time |
| 332 | */ |
| 333 | if (load_sec_app() < 0) |
| 334 | { |
| 335 | dprintf(CRITICAL, "Failed to load App for verified\n"); |
| 336 | ASSERT(0); |
| 337 | } |
Parth Dixit | 5b954e0 | 2015-10-17 22:20:31 +0530 | [diff] [blame] | 338 | #endif |
Parth Dixit | b73ff34 | 2015-10-27 17:34:08 +0530 | [diff] [blame] | 339 | #endif |
Parth Dixit | 5b954e0 | 2015-10-17 22:20:31 +0530 | [diff] [blame] | 340 | |
Aparna Mallavarapu | fa5f8a7 | 2015-03-31 06:21:36 +0530 | [diff] [blame] | 341 | #if SMD_SUPPORT |
| 342 | rpm_smd_init(); |
| 343 | #endif |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void target_serialno(unsigned char *buf) |
| 347 | { |
| 348 | uint32_t serialno; |
| 349 | if (target_is_emmc_boot()) { |
| 350 | serialno = mmc_get_psn(); |
| 351 | snprintf((char *)buf, 13, "%x", serialno); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | unsigned board_machtype(void) |
| 356 | { |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 357 | return LINUX_MACHTYPE_UNKNOWN; |
| 358 | } |
| 359 | |
| 360 | /* Detect the target type */ |
| 361 | void target_detect(struct board_data *board) |
| 362 | { |
| 363 | /* This is already filled as part of board.c */ |
| 364 | } |
| 365 | |
| 366 | /* Detect the modem type */ |
| 367 | void target_baseband_detect(struct board_data *board) |
| 368 | { |
| 369 | uint32_t platform; |
| 370 | |
| 371 | platform = board->platform; |
| 372 | |
| 373 | switch(platform) { |
| 374 | case MSM8952: |
| 375 | case MSM8956: |
| 376 | case MSM8976: |
Parth Dixit | 4ec3fe2 | 2015-10-30 00:44:33 +0530 | [diff] [blame] | 377 | case MSM8937: |
Parth Dixit | 80bb523 | 2016-01-05 15:26:22 +0530 | [diff] [blame] | 378 | case MSMGOLD: |
| 379 | case MSMGOLD2: |
| 380 | case MSMGOLD3: |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 381 | board->baseband = BASEBAND_MSM; |
| 382 | break; |
Aparna Mallavarapu | 815b324 | 2015-04-29 11:08:14 +0530 | [diff] [blame] | 383 | case APQ8052: |
| 384 | case APQ8056: |
| 385 | case APQ8076: |
Parth Dixit | 4ec3fe2 | 2015-10-30 00:44:33 +0530 | [diff] [blame] | 386 | case APQ8037: |
Parth Dixit | 80bb523 | 2016-01-05 15:26:22 +0530 | [diff] [blame] | 387 | case APQGOLD: |
Aparna Mallavarapu | 815b324 | 2015-04-29 11:08:14 +0530 | [diff] [blame] | 388 | board->baseband = BASEBAND_APQ; |
| 389 | break; |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 390 | default: |
| 391 | dprintf(CRITICAL, "Platform type: %u is not supported\n",platform); |
| 392 | ASSERT(0); |
| 393 | }; |
| 394 | } |
| 395 | |
| 396 | unsigned target_baseband() |
| 397 | { |
| 398 | return board_baseband(); |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | unsigned check_reboot_mode(void) |
| 402 | { |
| 403 | uint32_t restart_reason = 0; |
| 404 | |
| 405 | /* Read reboot reason and scrub it */ |
| 406 | restart_reason = readl(RESTART_REASON_ADDR); |
| 407 | writel(0x00, RESTART_REASON_ADDR); |
| 408 | |
| 409 | return restart_reason; |
| 410 | } |
| 411 | |
| 412 | unsigned check_hard_reboot_mode(void) |
| 413 | { |
| 414 | uint8_t hard_restart_reason = 0; |
| 415 | uint8_t value = 0; |
| 416 | |
| 417 | /* Read reboot reason and scrub it |
| 418 | * Bit-5, bit-6 and bit-7 of SOFT_RB_SPARE for hard reset reason |
| 419 | */ |
| 420 | value = pm8x41_reg_read(PON_SOFT_RB_SPARE); |
| 421 | hard_restart_reason = value >> 5; |
| 422 | pm8x41_reg_write(PON_SOFT_RB_SPARE, value & 0x1f); |
| 423 | |
| 424 | return hard_restart_reason; |
| 425 | } |
| 426 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 427 | int set_download_mode(enum reboot_reason mode) |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 428 | { |
| 429 | int ret = 0; |
| 430 | ret = scm_dload_mode(mode); |
| 431 | |
| 432 | pm8x41_clear_pmic_watchdog(); |
| 433 | |
| 434 | return ret; |
| 435 | } |
| 436 | |
| 437 | int emmc_recovery_init(void) |
| 438 | { |
| 439 | return _emmc_recovery_init(); |
| 440 | } |
| 441 | |
| 442 | void reboot_device(unsigned reboot_reason) |
| 443 | { |
| 444 | uint8_t reset_type = 0; |
| 445 | uint32_t ret = 0; |
| 446 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 447 | /* Set cookie for dload mode */ |
| 448 | if(set_download_mode(reboot_reason)) { |
| 449 | dprintf(CRITICAL, "HALT: set_download_mode not supported\n"); |
| 450 | return; |
| 451 | } |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 452 | |
| 453 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 454 | |
| 455 | /* For Reboot-bootloader and Dload cases do a warm reset |
| 456 | * For Reboot cases do a hard reset |
| 457 | */ |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 458 | if((reboot_reason == FASTBOOT_MODE) || (reboot_reason == NORMAL_DLOAD) || |
| 459 | (reboot_reason == EMERGENCY_DLOAD) || (reboot_reason == RECOVERY_MODE)) |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 460 | reset_type = PON_PSHOLD_WARM_RESET; |
| 461 | else |
| 462 | reset_type = PON_PSHOLD_HARD_RESET; |
| 463 | |
Parth Dixit | be10796 | 2015-10-16 14:33:20 +0530 | [diff] [blame] | 464 | pm8994_reset_configure(reset_type); |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 465 | |
| 466 | ret = scm_halt_pmic_arbiter(); |
| 467 | if (ret) |
| 468 | dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret); |
| 469 | |
| 470 | /* Drop PS_HOLD for MSM */ |
| 471 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 472 | |
| 473 | mdelay(5000); |
| 474 | |
| 475 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 476 | } |
| 477 | |
| 478 | #if USER_FORCE_RESET_SUPPORT |
| 479 | /* Return 1 if it is a force resin triggered by user. */ |
| 480 | uint32_t is_user_force_reset(void) |
| 481 | { |
| 482 | uint8_t poff_reason1 = pm8x41_get_pon_poff_reason1(); |
| 483 | uint8_t poff_reason2 = pm8x41_get_pon_poff_reason2(); |
| 484 | |
| 485 | dprintf(SPEW, "poff_reason1: %d\n", poff_reason1); |
| 486 | dprintf(SPEW, "poff_reason2: %d\n", poff_reason2); |
| 487 | if (pm8x41_get_is_cold_boot() && (poff_reason1 == KPDPWR_AND_RESIN || |
| 488 | poff_reason2 == STAGE3)) |
| 489 | return 1; |
| 490 | else |
| 491 | return 0; |
| 492 | } |
| 493 | #endif |
| 494 | |
Zhenhua Huang | b46b9b5 | 2015-04-21 19:53:09 +0800 | [diff] [blame] | 495 | #define SMBCHG_USB_RT_STS 0x21310 |
| 496 | #define USBIN_UV_RT_STS BIT(0) |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 497 | unsigned target_pause_for_battery_charge(void) |
| 498 | { |
| 499 | uint8_t pon_reason = pm8x41_get_pon_reason(); |
| 500 | uint8_t is_cold_boot = pm8x41_get_is_cold_boot(); |
Zhenhua Huang | b46b9b5 | 2015-04-21 19:53:09 +0800 | [diff] [blame] | 501 | bool usb_present_sts = !(USBIN_UV_RT_STS & |
| 502 | pm8x41_reg_read(SMBCHG_USB_RT_STS)); |
| 503 | dprintf(INFO, "%s : pon_reason is:0x%x cold_boot:%d usb_sts:%d\n", __func__, |
| 504 | pon_reason, is_cold_boot, usb_present_sts); |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 505 | /* In case of fastboot reboot,adb reboot or if we see the power key |
| 506 | * pressed we do not want go into charger mode. |
| 507 | * fastboot reboot is warm boot with PON hard reset bit not set |
| 508 | * adb reboot is a cold boot with PON hard reset bit set |
| 509 | */ |
| 510 | if (is_cold_boot && |
| 511 | (!(pon_reason & HARD_RST)) && |
| 512 | (!(pon_reason & KPDPWR_N)) && |
Zhenhua Huang | b46b9b5 | 2015-04-21 19:53:09 +0800 | [diff] [blame] | 513 | usb_present_sts) |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 514 | return 1; |
| 515 | else |
| 516 | return 0; |
| 517 | } |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 518 | |
| 519 | void target_uninit(void) |
| 520 | { |
c_wufeng | 8324c04 | 2016-01-25 10:37:37 +0800 | [diff] [blame] | 521 | #if PON_VIB_SUPPORT |
| 522 | turn_off_vib_early(); |
| 523 | #endif |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 524 | mmc_put_card_to_sleep(dev); |
| 525 | sdhci_mode_disable(&dev->host); |
Aparna Mallavarapu | 1e8b093 | 2015-03-29 23:38:13 +0530 | [diff] [blame] | 526 | if (crypto_initialized()) |
| 527 | crypto_eng_cleanup(); |
| 528 | |
| 529 | if (target_is_ssd_enabled()) |
| 530 | clock_ce_disable(CE1_INSTANCE); |
Aparna Mallavarapu | fa5f8a7 | 2015-03-31 06:21:36 +0530 | [diff] [blame] | 531 | |
Parth Dixit | 5b954e0 | 2015-10-17 22:20:31 +0530 | [diff] [blame] | 532 | #if VERIFIED_BOOT |
Parth Dixit | b73ff34 | 2015-10-27 17:34:08 +0530 | [diff] [blame] | 533 | #if !VBOOT_MOTA |
Parth Dixit | 6e6bad5 | 2015-07-30 19:02:38 +0530 | [diff] [blame] | 534 | if (is_sec_app_loaded()) |
| 535 | { |
| 536 | if (send_milestone_call_to_tz() < 0) |
| 537 | { |
| 538 | dprintf(CRITICAL, "Failed to unload App for rpmb\n"); |
| 539 | ASSERT(0); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | if (rpmb_uninit() < 0) |
| 544 | { |
| 545 | dprintf(CRITICAL, "RPMB uninit failed\n"); |
| 546 | ASSERT(0); |
| 547 | } |
| 548 | |
Parth Dixit | 0eb7369 | 2015-08-09 17:32:27 +0530 | [diff] [blame] | 549 | clock_ce_disable(CE1_INSTANCE); |
Parth Dixit | 5b954e0 | 2015-10-17 22:20:31 +0530 | [diff] [blame] | 550 | #endif |
Parth Dixit | b73ff34 | 2015-10-27 17:34:08 +0530 | [diff] [blame] | 551 | #endif |
Parth Dixit | 5b954e0 | 2015-10-17 22:20:31 +0530 | [diff] [blame] | 552 | |
Aparna Mallavarapu | fa5f8a7 | 2015-03-31 06:21:36 +0530 | [diff] [blame] | 553 | #if SMD_SUPPORT |
| 554 | rpm_smd_uninit(); |
| 555 | #endif |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | void target_usb_init(void) |
| 559 | { |
| 560 | uint32_t val; |
| 561 | |
| 562 | /* Select and enable external configuration with USB PHY */ |
| 563 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 564 | |
| 565 | /* Enable sess_vld */ |
| 566 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 567 | writel(val, USB_GENCONFIG_2); |
| 568 | |
| 569 | /* Enable external vbus configuration in the LINK */ |
| 570 | val = readl(USB_USBCMD); |
| 571 | val |= SESS_VLD_CTRL; |
| 572 | writel(val, USB_USBCMD); |
| 573 | } |
| 574 | |
| 575 | void target_usb_stop(void) |
| 576 | { |
| 577 | /* Disable VBUS mimicing in the controller. */ |
| 578 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR); |
| 579 | } |
Aparna Mallavarapu | 1e8b093 | 2015-03-29 23:38:13 +0530 | [diff] [blame] | 580 | |
Padmanabhan Komanduru | 9d49f89 | 2015-04-10 12:58:46 -0700 | [diff] [blame] | 581 | static uint8_t splash_override; |
| 582 | /* Returns 1 if target supports continuous splash screen. */ |
| 583 | int target_cont_splash_screen() |
| 584 | { |
| 585 | uint8_t splash_screen = 0; |
| 586 | if (!splash_override) { |
| 587 | switch (board_hardware_id()) { |
| 588 | case HW_PLATFORM_MTP: |
| 589 | case HW_PLATFORM_SURF: |
Vishnuvardhan Prodduturi | e116c00 | 2015-07-14 17:14:25 +0530 | [diff] [blame] | 590 | case HW_PLATFORM_RCM: |
feifanz | 174c82c | 2015-04-15 18:57:07 +0800 | [diff] [blame] | 591 | case HW_PLATFORM_QRD: |
Padmanabhan Komanduru | 9d49f89 | 2015-04-10 12:58:46 -0700 | [diff] [blame] | 592 | splash_screen = 1; |
| 593 | break; |
| 594 | default: |
| 595 | splash_screen = 0; |
| 596 | break; |
| 597 | } |
| 598 | dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen); |
| 599 | } |
| 600 | return splash_screen; |
| 601 | } |
| 602 | |
| 603 | void target_force_cont_splash_disable(uint8_t override) |
| 604 | { |
| 605 | splash_override = override; |
| 606 | } |
| 607 | |
Ray Zhang | f95f5b9 | 2015-06-25 15:34:29 +0800 | [diff] [blame] | 608 | uint8_t target_panel_auto_detect_enabled() |
| 609 | { |
| 610 | uint8_t ret = 0; |
| 611 | |
| 612 | switch(board_hardware_id()) |
| 613 | { |
| 614 | case HW_PLATFORM_QRD: |
| 615 | ret = platform_is_msm8956() ? 1 : 0; |
| 616 | break; |
| 617 | case HW_PLATFORM_SURF: |
| 618 | case HW_PLATFORM_MTP: |
| 619 | default: |
| 620 | ret = 0; |
| 621 | } |
| 622 | return ret; |
| 623 | } |
| 624 | |
Aparna Mallavarapu | 1e8b093 | 2015-03-29 23:38:13 +0530 | [diff] [blame] | 625 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 626 | void target_fastboot_init(void) |
| 627 | { |
| 628 | if (target_is_ssd_enabled()) { |
| 629 | clock_ce_enable(CE1_INSTANCE); |
| 630 | target_load_ssd_keystore(); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | void target_load_ssd_keystore(void) |
| 635 | { |
| 636 | uint64_t ptn; |
| 637 | int index; |
| 638 | uint64_t size; |
| 639 | uint32_t *buffer = NULL; |
| 640 | |
| 641 | if (!target_is_ssd_enabled()) |
| 642 | return; |
| 643 | |
| 644 | index = partition_get_index("ssd"); |
| 645 | |
| 646 | ptn = partition_get_offset(index); |
| 647 | if (ptn == 0){ |
| 648 | dprintf(CRITICAL, "Error: ssd partition not found\n"); |
| 649 | return; |
| 650 | } |
| 651 | |
| 652 | size = partition_get_size(index); |
| 653 | if (size == 0) { |
| 654 | dprintf(CRITICAL, "Error: invalid ssd partition size\n"); |
| 655 | return; |
| 656 | } |
| 657 | |
| 658 | buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE)); |
| 659 | if (!buffer) { |
| 660 | dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n"); |
| 661 | return; |
| 662 | } |
| 663 | |
| 664 | if (mmc_read(ptn, buffer, size)) { |
| 665 | dprintf(CRITICAL, "Error: cannot read data\n"); |
| 666 | free(buffer); |
| 667 | return; |
| 668 | } |
| 669 | |
| 670 | clock_ce_enable(CE1_INSTANCE); |
| 671 | scm_protect_keystore(buffer, size); |
| 672 | clock_ce_disable(CE1_INSTANCE); |
| 673 | free(buffer); |
| 674 | } |
| 675 | |
| 676 | crypto_engine_type board_ce_type(void) |
| 677 | { |
| 678 | return CRYPTO_ENGINE_TYPE_HW; |
| 679 | } |
| 680 | |
| 681 | /* Set up params for h/w CE. */ |
| 682 | void target_crypto_init_params() |
| 683 | { |
| 684 | struct crypto_init_params ce_params; |
| 685 | |
| 686 | /* Set up base addresses and instance. */ |
| 687 | ce_params.crypto_instance = CE1_INSTANCE; |
| 688 | ce_params.crypto_base = MSM_CE1_BASE; |
| 689 | ce_params.bam_base = MSM_CE1_BAM_BASE; |
| 690 | |
| 691 | /* Set up BAM config. */ |
| 692 | ce_params.bam_ee = CE_EE; |
| 693 | ce_params.pipes.read_pipe = CE_READ_PIPE; |
| 694 | ce_params.pipes.write_pipe = CE_WRITE_PIPE; |
| 695 | ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP; |
| 696 | ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP; |
| 697 | |
| 698 | /* Assign buffer sizes. */ |
| 699 | ce_params.num_ce = CE_ARRAY_SIZE; |
| 700 | ce_params.read_fifo_size = CE_FIFO_SIZE; |
| 701 | ce_params.write_fifo_size = CE_FIFO_SIZE; |
| 702 | |
| 703 | /* BAM is initialized by TZ for this platform. |
| 704 | * Do not do it again as the initialization address space |
| 705 | * is locked. |
| 706 | */ |
| 707 | ce_params.do_bam_init = 0; |
| 708 | |
| 709 | crypto_init_params(&ce_params); |
| 710 | } |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 711 | |
| 712 | uint32_t target_get_pmic() |
| 713 | { |
| 714 | return PMIC_IS_PMI8950; |
| 715 | } |