Channagoud Kadabi | f8ad8e7 | 2015-01-06 15:10:13 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2014-2015 The Linux Foundation. All rights reserved. |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [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 |
Sridhar Parasuram | 568e7a6 | 2015-08-06 13:16:02 -0700 | [diff] [blame] | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, nit |
| 22 | * PROCUREMENT OF |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #include <debug.h> |
| 31 | #include <platform/iomap.h> |
| 32 | #include <platform/irqs.h> |
| 33 | #include <platform/gpio.h> |
| 34 | #include <reg.h> |
| 35 | #include <target.h> |
| 36 | #include <platform.h> |
| 37 | #include <dload_util.h> |
| 38 | #include <uart_dm.h> |
| 39 | #include <mmc.h> |
| 40 | #include <spmi.h> |
| 41 | #include <board.h> |
| 42 | #include <smem.h> |
| 43 | #include <baseband.h> |
Sridhar Parasuram | d75ade5 | 2015-03-09 15:45:16 -0700 | [diff] [blame] | 44 | #include <regulator.h> |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 45 | #include <dev/keys.h> |
| 46 | #include <pm8x41.h> |
| 47 | #include <crypto5_wrapper.h> |
| 48 | #include <clock.h> |
| 49 | #include <partition_parser.h> |
| 50 | #include <scm.h> |
| 51 | #include <platform/clock.h> |
| 52 | #include <platform/gpio.h> |
| 53 | #include <platform/timer.h> |
| 54 | #include <stdlib.h> |
| 55 | #include <ufs.h> |
| 56 | #include <boot_device.h> |
| 57 | #include <qmp_phy.h> |
Channagoud Kadabi | 7d30820 | 2014-12-22 12:07:04 -0800 | [diff] [blame] | 58 | #include <sdhci_msm.h> |
| 59 | #include <qusb2_phy.h> |
Sridhar Parasuram | 568e7a6 | 2015-08-06 13:16:02 -0700 | [diff] [blame] | 60 | #include <secapp_loader.h> |
Channagoud Kadabi | 2bab29b | 2015-02-11 13:26:03 -0800 | [diff] [blame] | 61 | #include <rpmb.h> |
Sridhar Parasuram | 9f28f67 | 2015-03-17 15:40:47 -0700 | [diff] [blame] | 62 | #include <rpm-glink.h> |
Channagoud Kadabi | bb8f1f9 | 2015-04-27 11:14:45 -0700 | [diff] [blame] | 63 | #if ENABLE_WBC |
| 64 | #include <pm_app_smbchg.h> |
| 65 | #endif |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 66 | |
c_wufeng | f433f23 | 2015-09-21 15:21:21 +0800 | [diff] [blame] | 67 | #if LONG_PRESS_POWER_ON |
| 68 | #include <shutdown_detect.h> |
| 69 | #endif |
| 70 | |
c_wufeng | 196210d | 2015-09-21 12:49:43 +0800 | [diff] [blame] | 71 | #if PON_VIB_SUPPORT |
| 72 | #include <vibrator.h> |
| 73 | #define VIBRATE_TIME 250 |
| 74 | #endif |
c_wufeng | f433f23 | 2015-09-21 15:21:21 +0800 | [diff] [blame] | 75 | |
Channagoud Kadabi | 4a870cf | 2015-01-21 10:39:01 -0800 | [diff] [blame] | 76 | #define CE_INSTANCE 1 |
Channagoud Kadabi | 7edb9b4 | 2015-08-11 23:45:31 -0700 | [diff] [blame] | 77 | #define CE_EE 0 |
Channagoud Kadabi | 4a870cf | 2015-01-21 10:39:01 -0800 | [diff] [blame] | 78 | #define CE_FIFO_SIZE 64 |
| 79 | #define CE_READ_PIPE 3 |
| 80 | #define CE_WRITE_PIPE 2 |
| 81 | #define CE_READ_PIPE_LOCK_GRP 0 |
| 82 | #define CE_WRITE_PIPE_LOCK_GRP 0 |
| 83 | #define CE_ARRAY_SIZE 20 |
| 84 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 85 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 86 | #define PMIC_ARB_OWNER_ID 0 |
| 87 | |
| 88 | static void set_sdc_power_ctrl(void); |
| 89 | static uint32_t mmc_pwrctl_base[] = |
| 90 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 91 | |
| 92 | static uint32_t mmc_sdhci_base[] = |
| 93 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE }; |
| 94 | |
| 95 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 96 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ }; |
| 97 | |
| 98 | struct mmc_device *dev; |
| 99 | struct ufs_dev ufs_device; |
| 100 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 101 | void target_early_init(void) |
| 102 | { |
| 103 | #if WITH_DEBUG_UART |
Channagoud Kadabi | 35503c4 | 2014-11-14 16:22:43 -0800 | [diff] [blame] | 104 | uart_dm_init(8, 0, BLSP2_UART1_BASE); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 105 | #endif |
| 106 | } |
| 107 | |
| 108 | /* Return 1 if vol_up pressed */ |
Amit Blay | 6a3e88b | 2015-06-23 22:25:06 +0300 | [diff] [blame] | 109 | int target_volume_up() |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 110 | { |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 111 | static uint8_t first_time = 0; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 112 | uint8_t status = 0; |
| 113 | struct pm8x41_gpio gpio; |
| 114 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 115 | if (!first_time) { |
| 116 | /* Configure the GPIO */ |
| 117 | gpio.direction = PM_GPIO_DIR_IN; |
| 118 | gpio.function = 0; |
| 119 | gpio.pull = PM_GPIO_PULL_UP_30; |
| 120 | gpio.vin_sel = 2; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 121 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 122 | pm8x41_gpio_config(2, &gpio); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 123 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 124 | /* Wait for the pmic gpio config to take effect */ |
| 125 | udelay(10000); |
| 126 | |
| 127 | first_time = 1; |
| 128 | } |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 129 | |
| 130 | /* Get status of P_GPIO_5 */ |
Channagoud Kadabi | 99d2370 | 2015-02-02 20:52:17 -0800 | [diff] [blame] | 131 | pm8x41_gpio_get(2, &status); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 132 | |
| 133 | return !status; /* active low */ |
| 134 | } |
| 135 | |
| 136 | /* Return 1 if vol_down pressed */ |
| 137 | uint32_t target_volume_down() |
| 138 | { |
| 139 | return pm8x41_resin_status(); |
| 140 | } |
| 141 | |
| 142 | static void target_keystatus() |
| 143 | { |
| 144 | keys_init(); |
| 145 | |
| 146 | if(target_volume_down()) |
| 147 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 148 | |
| 149 | if(target_volume_up()) |
| 150 | keys_post_event(KEY_VOLUMEUP, 1); |
| 151 | } |
| 152 | |
| 153 | void target_uninit(void) |
| 154 | { |
| 155 | if (platform_boot_dev_isemmc()) |
| 156 | { |
| 157 | mmc_put_card_to_sleep(dev); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 158 | } |
Channagoud Kadabi | 2bab29b | 2015-02-11 13:26:03 -0800 | [diff] [blame] | 159 | |
| 160 | if (is_sec_app_loaded()) |
| 161 | { |
Sridhar Parasuram | 568e7a6 | 2015-08-06 13:16:02 -0700 | [diff] [blame] | 162 | if (send_milestone_call_to_tz() < 0) |
Channagoud Kadabi | 2bab29b | 2015-02-11 13:26:03 -0800 | [diff] [blame] | 163 | { |
| 164 | dprintf(CRITICAL, "Failed to unload App for rpmb\n"); |
| 165 | ASSERT(0); |
| 166 | } |
| 167 | } |
| 168 | |
Channagoud Kadabi | bb8f1f9 | 2015-04-27 11:14:45 -0700 | [diff] [blame] | 169 | #if ENABLE_WBC |
Channagoud Kadabi | 2216561 | 2015-07-22 14:04:37 -0700 | [diff] [blame] | 170 | if (board_hardware_id() == HW_PLATFORM_MTP) |
| 171 | pm_appsbl_set_dcin_suspend(1); |
Channagoud Kadabi | bb8f1f9 | 2015-04-27 11:14:45 -0700 | [diff] [blame] | 172 | #endif |
| 173 | |
Channagoud Kadabi | 7edb9b4 | 2015-08-11 23:45:31 -0700 | [diff] [blame] | 174 | |
| 175 | if (crypto_initialized()) |
| 176 | { |
| 177 | crypto_eng_cleanup(); |
| 178 | clock_ce_disable(CE_INSTANCE); |
| 179 | } |
| 180 | |
Sridhar Parasuram | 9f28f67 | 2015-03-17 15:40:47 -0700 | [diff] [blame] | 181 | /* Tear down glink channels */ |
| 182 | rpm_glink_uninit(); |
| 183 | |
Channagoud Kadabi | 2bab29b | 2015-02-11 13:26:03 -0800 | [diff] [blame] | 184 | if (rpmb_uninit() < 0) |
| 185 | { |
| 186 | dprintf(CRITICAL, "RPMB uninit failed\n"); |
| 187 | ASSERT(0); |
| 188 | } |
| 189 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static void set_sdc_power_ctrl() |
| 193 | { |
| 194 | /* Drive strength configs for sdc pins */ |
| 195 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 196 | { |
| 197 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL }, |
| 198 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL }, |
| 199 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL }, |
| 200 | }; |
| 201 | |
| 202 | /* Pull configs for sdc pins */ |
| 203 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 204 | { |
| 205 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL }, |
| 206 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL }, |
| 207 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL }, |
| 208 | }; |
| 209 | |
| 210 | struct tlmm_cfgs sdc1_rclk_cfg[] = |
| 211 | { |
| 212 | { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL }, |
| 213 | }; |
| 214 | |
| 215 | /* Set the drive strength & pull control values */ |
| 216 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 217 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 218 | tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg)); |
| 219 | } |
| 220 | |
c_wufeng | f433f23 | 2015-09-21 15:21:21 +0800 | [diff] [blame] | 221 | uint32_t target_is_pwrkey_pon_reason() |
| 222 | { |
| 223 | uint8_t pon_reason = pm8950_get_pon_reason(); |
| 224 | if (pm8x41_get_is_cold_boot() && ((pon_reason == KPDPWR_N) || (pon_reason == (KPDPWR_N|PON1)))) |
| 225 | return 1; |
| 226 | else |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 231 | void target_sdc_init() |
| 232 | { |
| 233 | struct mmc_config_data config = {0}; |
| 234 | |
| 235 | /* Set drive strength & pull ctrl values */ |
| 236 | set_sdc_power_ctrl(); |
| 237 | |
| 238 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 239 | config.max_clk_rate = MMC_CLK_192MHZ; |
Channagoud Kadabi | 99d2370 | 2015-02-02 20:52:17 -0800 | [diff] [blame] | 240 | config.hs400_support = 1; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 241 | |
| 242 | /* Try slot 1*/ |
| 243 | config.slot = 1; |
| 244 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 245 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 246 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 247 | |
| 248 | if (!(dev = mmc_init(&config))) |
| 249 | { |
| 250 | /* Try slot 2 */ |
| 251 | config.slot = 2; |
| 252 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 253 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 254 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 255 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 256 | |
| 257 | if (!(dev = mmc_init(&config))) |
| 258 | { |
| 259 | dprintf(CRITICAL, "mmc init failed!"); |
| 260 | ASSERT(0); |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | void *target_mmc_device() |
| 266 | { |
| 267 | if (platform_boot_dev_isemmc()) |
| 268 | return (void *) dev; |
| 269 | else |
| 270 | return (void *) &ufs_device; |
| 271 | } |
| 272 | |
| 273 | void target_init(void) |
| 274 | { |
Sridhar Parasuram | 568e7a6 | 2015-08-06 13:16:02 -0700 | [diff] [blame] | 275 | int ret = 0; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 276 | dprintf(INFO, "target_init()\n"); |
| 277 | |
Sridhar Parasuram | 1d22432 | 2015-06-15 11:03:40 -0700 | [diff] [blame] | 278 | pmic_info_populate(); |
| 279 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 280 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 281 | |
Channagoud Kadabi | bb8f1f9 | 2015-04-27 11:14:45 -0700 | [diff] [blame] | 282 | /* Initialize Glink */ |
| 283 | rpm_glink_init(); |
| 284 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 285 | target_keystatus(); |
| 286 | |
c_wufeng | f433f23 | 2015-09-21 15:21:21 +0800 | [diff] [blame] | 287 | #if defined(LONG_PRESS_POWER_ON) || defined(PON_VIB_SUPPORT) |
| 288 | switch(board_hardware_id()) |
| 289 | { |
| 290 | case HW_PLATFORM_QRD: |
| 291 | #if LONG_PRESS_POWER_ON |
| 292 | shutdown_detect(); |
| 293 | #endif |
c_wufeng | 196210d | 2015-09-21 12:49:43 +0800 | [diff] [blame] | 294 | #if PON_VIB_SUPPORT |
| 295 | vib_timed_turn_on(VIBRATE_TIME); |
| 296 | #endif |
c_wufeng | f433f23 | 2015-09-21 15:21:21 +0800 | [diff] [blame] | 297 | break; |
| 298 | } |
| 299 | #endif |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 300 | |
| 301 | if (target_use_signed_kernel()) |
| 302 | target_crypto_init_params(); |
| 303 | |
| 304 | platform_read_boot_config(); |
| 305 | |
Sridhar Parasuram | 50b9d96 | 2015-02-12 11:28:09 -0800 | [diff] [blame] | 306 | #ifdef MMC_SDHCI_SUPPORT |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 307 | if (platform_boot_dev_isemmc()) |
| 308 | { |
| 309 | target_sdc_init(); |
| 310 | } |
Sridhar Parasuram | 50b9d96 | 2015-02-12 11:28:09 -0800 | [diff] [blame] | 311 | #endif |
| 312 | #ifdef UFS_SUPPORT |
| 313 | if (!platform_boot_dev_isemmc()) |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 314 | { |
| 315 | ufs_device.base = UFS_BASE; |
| 316 | ufs_init(&ufs_device); |
| 317 | } |
Sridhar Parasuram | 50b9d96 | 2015-02-12 11:28:09 -0800 | [diff] [blame] | 318 | #endif |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 319 | |
| 320 | /* Storage initialization is complete, read the partition table info */ |
Channagoud Kadabi | 58a273b | 2015-02-10 12:56:22 -0800 | [diff] [blame] | 321 | mmc_read_partition_table(0); |
Channagoud Kadabi | 2bab29b | 2015-02-11 13:26:03 -0800 | [diff] [blame] | 322 | |
Channagoud Kadabi | 1171d8d | 2015-07-30 19:12:44 -0700 | [diff] [blame] | 323 | #if ENABLE_WBC |
| 324 | /* Look for battery voltage and make sure we have enough to bootup |
| 325 | * Otherwise initiate battery charging |
| 326 | * Charging should happen as early as possible, any other driver |
| 327 | * initialization before this should consider the power impact |
| 328 | */ |
Channagoud Kadabi | 25fd8ce | 2015-08-19 14:45:08 -0700 | [diff] [blame] | 329 | switch(board_hardware_id()) |
| 330 | { |
| 331 | case HW_PLATFORM_MTP: |
| 332 | case HW_PLATFORM_FLUID: |
lijuang | 0e98add | 2015-11-10 10:40:27 +0800 | [diff] [blame] | 333 | case HW_PLATFORM_QRD: |
Channagoud Kadabi | 25fd8ce | 2015-08-19 14:45:08 -0700 | [diff] [blame] | 334 | pm_appsbl_chg_check_weak_battery_status(1); |
| 335 | break; |
| 336 | default: |
| 337 | /* Charging not supported */ |
| 338 | break; |
| 339 | }; |
Channagoud Kadabi | 1171d8d | 2015-07-30 19:12:44 -0700 | [diff] [blame] | 340 | #endif |
| 341 | |
Sridhar Parasuram | 568e7a6 | 2015-08-06 13:16:02 -0700 | [diff] [blame] | 342 | /* Initialize Qseecom */ |
| 343 | ret = qseecom_init(); |
| 344 | |
| 345 | if (ret < 0) |
| 346 | { |
| 347 | dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret); |
| 348 | ASSERT(0); |
| 349 | } |
| 350 | |
| 351 | /* Start Qseecom */ |
| 352 | ret = qseecom_tz_init(); |
| 353 | |
| 354 | if (ret < 0) |
| 355 | { |
| 356 | dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret); |
| 357 | ASSERT(0); |
| 358 | } |
| 359 | |
Sridhar Parasuram | c61ecc2 | 2015-09-22 13:53:31 -0700 | [diff] [blame] | 360 | if (rpmb_init() < 0) |
| 361 | { |
| 362 | dprintf(CRITICAL, "RPMB init failed\n"); |
| 363 | ASSERT(0); |
| 364 | } |
| 365 | |
Sridhar Parasuram | 568e7a6 | 2015-08-06 13:16:02 -0700 | [diff] [blame] | 366 | /* |
| 367 | * Load the sec app for first time |
| 368 | */ |
| 369 | if (load_sec_app() < 0) |
| 370 | { |
| 371 | dprintf(CRITICAL, "Failed to load App for verified\n"); |
| 372 | ASSERT(0); |
| 373 | } |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | unsigned board_machtype(void) |
| 377 | { |
| 378 | return LINUX_MACHTYPE_UNKNOWN; |
| 379 | } |
| 380 | |
| 381 | /* Detect the target type */ |
| 382 | void target_detect(struct board_data *board) |
| 383 | { |
| 384 | /* This is filled from board.c */ |
| 385 | } |
| 386 | |
Dhaval Patel | b95039c | 2015-03-16 11:14:06 -0700 | [diff] [blame] | 387 | static uint8_t splash_override; |
| 388 | /* Returns 1 if target supports continuous splash screen. */ |
| 389 | int target_cont_splash_screen() |
| 390 | { |
| 391 | uint8_t splash_screen = 0; |
Channagoud Kadabi | 25fd8ce | 2015-08-19 14:45:08 -0700 | [diff] [blame] | 392 | if(!splash_override && !pm_appsbl_charging_in_progress()) { |
Dhaval Patel | b95039c | 2015-03-16 11:14:06 -0700 | [diff] [blame] | 393 | switch(board_hardware_id()) |
| 394 | { |
| 395 | case HW_PLATFORM_SURF: |
| 396 | case HW_PLATFORM_MTP: |
| 397 | case HW_PLATFORM_FLUID: |
feifanz | 76fe648 | 2015-09-02 15:25:16 +0800 | [diff] [blame] | 398 | case HW_PLATFORM_QRD: |
Kuogee Hsieh | b976dfc | 2015-08-28 13:21:30 -0700 | [diff] [blame] | 399 | case HW_PLATFORM_LIQUID: |
Dhaval Patel | b95039c | 2015-03-16 11:14:06 -0700 | [diff] [blame] | 400 | dprintf(SPEW, "Target_cont_splash=1\n"); |
| 401 | splash_screen = 1; |
| 402 | break; |
| 403 | default: |
| 404 | dprintf(SPEW, "Target_cont_splash=0\n"); |
| 405 | splash_screen = 0; |
| 406 | } |
| 407 | } |
| 408 | return splash_screen; |
| 409 | } |
| 410 | |
| 411 | void target_force_cont_splash_disable(uint8_t override) |
| 412 | { |
| 413 | splash_override = override; |
| 414 | } |
| 415 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 416 | /* Detect the modem type */ |
| 417 | void target_baseband_detect(struct board_data *board) |
| 418 | { |
| 419 | uint32_t platform; |
| 420 | |
| 421 | platform = board->platform; |
| 422 | |
| 423 | switch(platform) { |
Channagoud Kadabi | 439df82 | 2015-05-26 11:14:16 -0700 | [diff] [blame] | 424 | case APQ8096: |
| 425 | board->baseband = BASEBAND_APQ; |
| 426 | break; |
Channagoud Kadabi | 4a4c05e | 2015-03-30 15:18:58 -0700 | [diff] [blame] | 427 | case MSM8996: |
Channagoud Kadabi | 99d2370 | 2015-02-02 20:52:17 -0800 | [diff] [blame] | 428 | if (board->platform_version == 0x10000) |
| 429 | board->baseband = BASEBAND_APQ; |
| 430 | else |
| 431 | board->baseband = BASEBAND_MSM; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 432 | break; |
| 433 | default: |
| 434 | dprintf(CRITICAL, "Platform type: %u is not supported\n",platform); |
| 435 | ASSERT(0); |
| 436 | }; |
| 437 | } |
| 438 | unsigned target_baseband() |
| 439 | { |
| 440 | return board_baseband(); |
| 441 | } |
| 442 | |
| 443 | void target_serialno(unsigned char *buf) |
| 444 | { |
| 445 | unsigned int serialno; |
| 446 | if (target_is_emmc_boot()) { |
| 447 | serialno = mmc_get_psn(); |
| 448 | snprintf((char *)buf, 13, "%x", serialno); |
| 449 | } |
| 450 | } |
| 451 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 452 | int emmc_recovery_init(void) |
| 453 | { |
| 454 | return _emmc_recovery_init(); |
| 455 | } |
| 456 | |
| 457 | void target_usb_phy_reset() |
| 458 | { |
| 459 | usb30_qmp_phy_reset(); |
| 460 | qusb2_phy_reset(); |
| 461 | } |
| 462 | |
| 463 | target_usb_iface_t* target_usb30_init() |
| 464 | { |
| 465 | target_usb_iface_t *t_usb_iface; |
| 466 | |
| 467 | t_usb_iface = calloc(1, sizeof(target_usb_iface_t)); |
| 468 | ASSERT(t_usb_iface); |
| 469 | |
| 470 | t_usb_iface->phy_init = usb30_qmp_phy_init; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 471 | t_usb_iface->phy_reset = target_usb_phy_reset; |
| 472 | t_usb_iface->clock_init = clock_usb30_init; |
| 473 | t_usb_iface->vbus_override = 1; |
| 474 | |
| 475 | return t_usb_iface; |
| 476 | } |
| 477 | |
| 478 | /* identify the usb controller to be used for the target */ |
| 479 | const char * target_usb_controller() |
| 480 | { |
| 481 | return "dwc"; |
| 482 | } |
| 483 | |
| 484 | uint32_t target_override_pll() |
| 485 | { |
Channagoud Kadabi | 1e5144b | 2015-04-28 17:15:05 -0700 | [diff] [blame] | 486 | if (board_soc_version() >= 0x20000) |
| 487 | return 0; |
| 488 | else |
| 489 | return 1; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Channagoud Kadabi | 4a870cf | 2015-01-21 10:39:01 -0800 | [diff] [blame] | 492 | crypto_engine_type board_ce_type(void) |
| 493 | { |
Channagoud Kadabi | 7edb9b4 | 2015-08-11 23:45:31 -0700 | [diff] [blame] | 494 | return CRYPTO_ENGINE_TYPE_HW; |
Channagoud Kadabi | 4a870cf | 2015-01-21 10:39:01 -0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /* Set up params for h/w CE. */ |
| 498 | void target_crypto_init_params() |
| 499 | { |
| 500 | struct crypto_init_params ce_params; |
| 501 | |
| 502 | /* Set up base addresses and instance. */ |
| 503 | ce_params.crypto_instance = CE_INSTANCE; |
| 504 | ce_params.crypto_base = MSM_CE_BASE; |
| 505 | ce_params.bam_base = MSM_CE_BAM_BASE; |
| 506 | |
| 507 | /* Set up BAM config. */ |
| 508 | ce_params.bam_ee = CE_EE; |
| 509 | ce_params.pipes.read_pipe = CE_READ_PIPE; |
| 510 | ce_params.pipes.write_pipe = CE_WRITE_PIPE; |
| 511 | ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP; |
| 512 | ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP; |
| 513 | |
| 514 | /* Assign buffer sizes. */ |
| 515 | ce_params.num_ce = CE_ARRAY_SIZE; |
| 516 | ce_params.read_fifo_size = CE_FIFO_SIZE; |
| 517 | ce_params.write_fifo_size = CE_FIFO_SIZE; |
| 518 | |
| 519 | /* BAM is initialized by TZ for this platform. |
| 520 | * Do not do it again as the initialization address space |
| 521 | * is locked. |
| 522 | */ |
| 523 | ce_params.do_bam_init = 0; |
| 524 | |
| 525 | crypto_init_params(&ce_params); |
| 526 | } |
Channagoud Kadabi | 083290f | 2015-03-13 14:18:38 -0700 | [diff] [blame] | 527 | |
| 528 | unsigned target_pause_for_battery_charge(void) |
| 529 | { |
| 530 | uint8_t pon_reason = pm8x41_get_pon_reason(); |
| 531 | uint8_t is_cold_boot = pm8x41_get_is_cold_boot(); |
| 532 | dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__, |
| 533 | pon_reason, is_cold_boot); |
| 534 | /* In case of fastboot reboot,adb reboot or if we see the power key |
| 535 | * pressed we do not want go into charger mode. |
| 536 | * fastboot reboot is warm boot with PON hard reset bit not set |
| 537 | * adb reboot is a cold boot with PON hard reset bit set |
| 538 | */ |
| 539 | if (is_cold_boot && |
| 540 | (!(pon_reason & HARD_RST)) && |
| 541 | (!(pon_reason & KPDPWR_N)) && |
| 542 | ((pon_reason & PON1))) |
| 543 | return 1; |
| 544 | else |
| 545 | return 0; |
| 546 | } |
Channagoud Kadabi | 23edc0c | 2015-03-27 18:31:32 -0700 | [diff] [blame] | 547 | |
| 548 | int set_download_mode(enum dload_mode mode) |
| 549 | { |
| 550 | int ret = 0; |
| 551 | ret = scm_dload_mode(mode); |
| 552 | |
| 553 | return ret; |
| 554 | } |
Channagoud Kadabi | ffc4b90 | 2015-06-25 23:14:27 -0700 | [diff] [blame] | 555 | |
Channagoud Kadabi | 65b518d | 2015-08-05 16:17:14 -0700 | [diff] [blame] | 556 | void pmic_reset_configure(uint8_t reset_type) |
Channagoud Kadabi | ffc4b90 | 2015-06-25 23:14:27 -0700 | [diff] [blame] | 557 | { |
Channagoud Kadabi | 65b518d | 2015-08-05 16:17:14 -0700 | [diff] [blame] | 558 | pm8994_reset_configure(reset_type); |
Channagoud Kadabi | ffc4b90 | 2015-06-25 23:14:27 -0700 | [diff] [blame] | 559 | } |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 560 | |
| 561 | uint32_t target_get_pmic() |
| 562 | { |
| 563 | return PMIC_IS_PMI8996; |
| 564 | } |