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