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 | |
Tanya Finkel | 619fc2a | 2016-08-16 14:11:26 +0300 | [diff] [blame] | 101 | static uint8_t flash_memory_slot = 0; |
| 102 | static void set_sdc_power_ctrl(); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 103 | static uint32_t mmc_pwrctl_base[] = |
| 104 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 105 | |
| 106 | static uint32_t mmc_sdhci_base[] = |
| 107 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE }; |
| 108 | |
| 109 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 110 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ }; |
| 111 | |
| 112 | struct mmc_device *dev; |
| 113 | struct ufs_dev ufs_device; |
| 114 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 115 | void target_early_init(void) |
| 116 | { |
| 117 | #if WITH_DEBUG_UART |
Channagoud Kadabi | 35503c4 | 2014-11-14 16:22:43 -0800 | [diff] [blame] | 118 | uart_dm_init(8, 0, BLSP2_UART1_BASE); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 119 | #endif |
| 120 | } |
| 121 | |
| 122 | /* Return 1 if vol_up pressed */ |
Amit Blay | 6a3e88b | 2015-06-23 22:25:06 +0300 | [diff] [blame] | 123 | int target_volume_up() |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 124 | { |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 125 | static uint8_t first_time = 0; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 126 | uint8_t status = 0; |
| 127 | struct pm8x41_gpio gpio; |
| 128 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 129 | if (!first_time) { |
| 130 | /* Configure the GPIO */ |
| 131 | gpio.direction = PM_GPIO_DIR_IN; |
| 132 | gpio.function = 0; |
| 133 | gpio.pull = PM_GPIO_PULL_UP_30; |
| 134 | gpio.vin_sel = 2; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 135 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 136 | pm8x41_gpio_config(2, &gpio); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 137 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 138 | /* Wait for the pmic gpio config to take effect */ |
| 139 | udelay(10000); |
| 140 | |
| 141 | first_time = 1; |
| 142 | } |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 143 | |
| 144 | /* Get status of P_GPIO_5 */ |
Channagoud Kadabi | 99d2370 | 2015-02-02 20:52:17 -0800 | [diff] [blame] | 145 | pm8x41_gpio_get(2, &status); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 146 | |
| 147 | return !status; /* active low */ |
| 148 | } |
| 149 | |
| 150 | /* Return 1 if vol_down pressed */ |
| 151 | uint32_t target_volume_down() |
| 152 | { |
| 153 | return pm8x41_resin_status(); |
| 154 | } |
| 155 | |
| 156 | static void target_keystatus() |
| 157 | { |
| 158 | keys_init(); |
| 159 | |
| 160 | if(target_volume_down()) |
| 161 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 162 | |
| 163 | if(target_volume_up()) |
| 164 | keys_post_event(KEY_VOLUMEUP, 1); |
| 165 | } |
| 166 | |
| 167 | void target_uninit(void) |
| 168 | { |
| 169 | if (platform_boot_dev_isemmc()) |
| 170 | { |
| 171 | mmc_put_card_to_sleep(dev); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 172 | } |
Channagoud Kadabi | 2bab29b | 2015-02-11 13:26:03 -0800 | [diff] [blame] | 173 | |
| 174 | if (is_sec_app_loaded()) |
| 175 | { |
Sridhar Parasuram | 568e7a6 | 2015-08-06 13:16:02 -0700 | [diff] [blame] | 176 | if (send_milestone_call_to_tz() < 0) |
Channagoud Kadabi | 2bab29b | 2015-02-11 13:26:03 -0800 | [diff] [blame] | 177 | { |
| 178 | dprintf(CRITICAL, "Failed to unload App for rpmb\n"); |
| 179 | ASSERT(0); |
| 180 | } |
| 181 | } |
| 182 | |
Channagoud Kadabi | bb8f1f9 | 2015-04-27 11:14:45 -0700 | [diff] [blame] | 183 | #if ENABLE_WBC |
Channagoud Kadabi | 2216561 | 2015-07-22 14:04:37 -0700 | [diff] [blame] | 184 | if (board_hardware_id() == HW_PLATFORM_MTP) |
| 185 | pm_appsbl_set_dcin_suspend(1); |
Channagoud Kadabi | bb8f1f9 | 2015-04-27 11:14:45 -0700 | [diff] [blame] | 186 | #endif |
| 187 | |
Channagoud Kadabi | 7edb9b4 | 2015-08-11 23:45:31 -0700 | [diff] [blame] | 188 | |
| 189 | if (crypto_initialized()) |
| 190 | { |
| 191 | crypto_eng_cleanup(); |
| 192 | clock_ce_disable(CE_INSTANCE); |
| 193 | } |
| 194 | |
Sridhar Parasuram | 9f28f67 | 2015-03-17 15:40:47 -0700 | [diff] [blame] | 195 | /* Tear down glink channels */ |
| 196 | rpm_glink_uninit(); |
| 197 | |
Channagoud Kadabi | 2bab29b | 2015-02-11 13:26:03 -0800 | [diff] [blame] | 198 | if (rpmb_uninit() < 0) |
| 199 | { |
| 200 | dprintf(CRITICAL, "RPMB uninit failed\n"); |
| 201 | ASSERT(0); |
| 202 | } |
| 203 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static void set_sdc_power_ctrl() |
| 207 | { |
Tanya Finkel | 619fc2a | 2016-08-16 14:11:26 +0300 | [diff] [blame] | 208 | uint32_t reg = 0; |
| 209 | uint8_t clk = 0; |
| 210 | uint8_t cmd = 0; |
| 211 | uint8_t dat = 0; |
| 212 | |
| 213 | if (flash_memory_slot == 0x1) |
| 214 | { |
| 215 | clk = TLMM_CUR_VAL_10MA; |
| 216 | cmd = TLMM_CUR_VAL_8MA; |
| 217 | dat = TLMM_CUR_VAL_8MA; |
| 218 | reg = SDC1_HDRV_PULL_CTL; |
| 219 | } |
| 220 | else if (flash_memory_slot == 0x2) |
| 221 | { |
| 222 | clk = TLMM_CUR_VAL_16MA; |
| 223 | cmd = TLMM_CUR_VAL_10MA; |
| 224 | dat = TLMM_CUR_VAL_10MA; |
| 225 | reg = SDC2_HDRV_PULL_CTL; |
| 226 | } |
| 227 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 228 | /* Drive strength configs for sdc pins */ |
| 229 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 230 | { |
Tanya Finkel | 619fc2a | 2016-08-16 14:11:26 +0300 | [diff] [blame] | 231 | { SDC1_CLK_HDRV_CTL_OFF, clk, TLMM_HDRV_MASK, reg }, |
| 232 | { SDC1_CMD_HDRV_CTL_OFF, cmd, TLMM_HDRV_MASK, reg }, |
| 233 | { SDC1_DATA_HDRV_CTL_OFF, dat, TLMM_HDRV_MASK, reg }, |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | /* Pull configs for sdc pins */ |
| 237 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 238 | { |
Tanya Finkel | 619fc2a | 2016-08-16 14:11:26 +0300 | [diff] [blame] | 239 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, reg }, |
| 240 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg }, |
| 241 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg }, |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | struct tlmm_cfgs sdc1_rclk_cfg[] = |
| 245 | { |
Tanya Finkel | 619fc2a | 2016-08-16 14:11:26 +0300 | [diff] [blame] | 246 | { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, reg }, |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | /* Set the drive strength & pull control values */ |
| 250 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 251 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 252 | tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg)); |
| 253 | } |
| 254 | |
c_wufeng | f433f23 | 2015-09-21 15:21:21 +0800 | [diff] [blame] | 255 | uint32_t target_is_pwrkey_pon_reason() |
| 256 | { |
| 257 | uint8_t pon_reason = pm8950_get_pon_reason(); |
| 258 | if (pm8x41_get_is_cold_boot() && ((pon_reason == KPDPWR_N) || (pon_reason == (KPDPWR_N|PON1)))) |
| 259 | return 1; |
| 260 | else |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 265 | void target_sdc_init() |
| 266 | { |
| 267 | struct mmc_config_data config = {0}; |
| 268 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 269 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 270 | config.max_clk_rate = MMC_CLK_192MHZ; |
Channagoud Kadabi | 99d2370 | 2015-02-02 20:52:17 -0800 | [diff] [blame] | 271 | config.hs400_support = 1; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 272 | |
| 273 | /* Try slot 1*/ |
Tanya Finkel | 619fc2a | 2016-08-16 14:11:26 +0300 | [diff] [blame] | 274 | flash_memory_slot = 1; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 275 | config.slot = 1; |
| 276 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 277 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 278 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 279 | |
Tanya Finkel | 619fc2a | 2016-08-16 14:11:26 +0300 | [diff] [blame] | 280 | /* Set drive strength & pull ctrl values */ |
| 281 | set_sdc_power_ctrl(); |
| 282 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 283 | if (!(dev = mmc_init(&config))) |
| 284 | { |
| 285 | /* Try slot 2 */ |
Tanya Finkel | 619fc2a | 2016-08-16 14:11:26 +0300 | [diff] [blame] | 286 | flash_memory_slot = 2; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 287 | config.slot = 2; |
| 288 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 289 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 290 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 291 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 292 | |
Tanya Finkel | 619fc2a | 2016-08-16 14:11:26 +0300 | [diff] [blame] | 293 | /* Set drive strength & pull ctrl values */ |
| 294 | set_sdc_power_ctrl(); |
| 295 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 296 | if (!(dev = mmc_init(&config))) |
| 297 | { |
| 298 | dprintf(CRITICAL, "mmc init failed!"); |
| 299 | ASSERT(0); |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | void *target_mmc_device() |
| 305 | { |
| 306 | if (platform_boot_dev_isemmc()) |
| 307 | return (void *) dev; |
| 308 | else |
| 309 | return (void *) &ufs_device; |
| 310 | } |
| 311 | |
| 312 | void target_init(void) |
| 313 | { |
Sridhar Parasuram | 568e7a6 | 2015-08-06 13:16:02 -0700 | [diff] [blame] | 314 | int ret = 0; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 315 | dprintf(INFO, "target_init()\n"); |
| 316 | |
Sridhar Parasuram | 1d22432 | 2015-06-15 11:03:40 -0700 | [diff] [blame] | 317 | pmic_info_populate(); |
| 318 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 319 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 320 | |
Channagoud Kadabi | bb8f1f9 | 2015-04-27 11:14:45 -0700 | [diff] [blame] | 321 | /* Initialize Glink */ |
| 322 | rpm_glink_init(); |
| 323 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 324 | target_keystatus(); |
| 325 | |
c_wufeng | f433f23 | 2015-09-21 15:21:21 +0800 | [diff] [blame] | 326 | #if defined(LONG_PRESS_POWER_ON) || defined(PON_VIB_SUPPORT) |
| 327 | switch(board_hardware_id()) |
| 328 | { |
| 329 | case HW_PLATFORM_QRD: |
| 330 | #if LONG_PRESS_POWER_ON |
| 331 | shutdown_detect(); |
| 332 | #endif |
c_wufeng | 196210d | 2015-09-21 12:49:43 +0800 | [diff] [blame] | 333 | #if PON_VIB_SUPPORT |
| 334 | vib_timed_turn_on(VIBRATE_TIME); |
| 335 | #endif |
c_wufeng | f433f23 | 2015-09-21 15:21:21 +0800 | [diff] [blame] | 336 | break; |
| 337 | } |
| 338 | #endif |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 339 | |
| 340 | if (target_use_signed_kernel()) |
| 341 | target_crypto_init_params(); |
| 342 | |
| 343 | platform_read_boot_config(); |
| 344 | |
Sridhar Parasuram | 50b9d96 | 2015-02-12 11:28:09 -0800 | [diff] [blame] | 345 | #ifdef MMC_SDHCI_SUPPORT |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 346 | if (platform_boot_dev_isemmc()) |
| 347 | { |
| 348 | target_sdc_init(); |
| 349 | } |
Sridhar Parasuram | 50b9d96 | 2015-02-12 11:28:09 -0800 | [diff] [blame] | 350 | #endif |
| 351 | #ifdef UFS_SUPPORT |
| 352 | if (!platform_boot_dev_isemmc()) |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 353 | { |
| 354 | ufs_device.base = UFS_BASE; |
| 355 | ufs_init(&ufs_device); |
| 356 | } |
Sridhar Parasuram | 50b9d96 | 2015-02-12 11:28:09 -0800 | [diff] [blame] | 357 | #endif |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 358 | |
| 359 | /* Storage initialization is complete, read the partition table info */ |
Channagoud Kadabi | 58a273b | 2015-02-10 12:56:22 -0800 | [diff] [blame] | 360 | mmc_read_partition_table(0); |
Channagoud Kadabi | 2bab29b | 2015-02-11 13:26:03 -0800 | [diff] [blame] | 361 | |
Channagoud Kadabi | 1171d8d | 2015-07-30 19:12:44 -0700 | [diff] [blame] | 362 | #if ENABLE_WBC |
| 363 | /* Look for battery voltage and make sure we have enough to bootup |
| 364 | * Otherwise initiate battery charging |
| 365 | * Charging should happen as early as possible, any other driver |
| 366 | * initialization before this should consider the power impact |
| 367 | */ |
Channagoud Kadabi | 25fd8ce | 2015-08-19 14:45:08 -0700 | [diff] [blame] | 368 | switch(board_hardware_id()) |
| 369 | { |
| 370 | case HW_PLATFORM_MTP: |
| 371 | case HW_PLATFORM_FLUID: |
lijuang | 0e98add | 2015-11-10 10:40:27 +0800 | [diff] [blame] | 372 | case HW_PLATFORM_QRD: |
Parth Dixit | 550ddf3 | 2016-11-28 17:00:29 +0530 | [diff] [blame] | 373 | if(target_is_pmi_enabled()) |
| 374 | pm_appsbl_chg_check_weak_battery_status(1); |
Channagoud Kadabi | 25fd8ce | 2015-08-19 14:45:08 -0700 | [diff] [blame] | 375 | break; |
| 376 | default: |
| 377 | /* Charging not supported */ |
| 378 | break; |
| 379 | }; |
Channagoud Kadabi | 1171d8d | 2015-07-30 19:12:44 -0700 | [diff] [blame] | 380 | #endif |
| 381 | |
Sridhar Parasuram | 568e7a6 | 2015-08-06 13:16:02 -0700 | [diff] [blame] | 382 | /* Initialize Qseecom */ |
| 383 | ret = qseecom_init(); |
| 384 | |
| 385 | if (ret < 0) |
| 386 | { |
| 387 | dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret); |
| 388 | ASSERT(0); |
| 389 | } |
| 390 | |
| 391 | /* Start Qseecom */ |
| 392 | ret = qseecom_tz_init(); |
| 393 | |
| 394 | if (ret < 0) |
| 395 | { |
| 396 | dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret); |
| 397 | ASSERT(0); |
| 398 | } |
| 399 | |
Sridhar Parasuram | c61ecc2 | 2015-09-22 13:53:31 -0700 | [diff] [blame] | 400 | if (rpmb_init() < 0) |
| 401 | { |
| 402 | dprintf(CRITICAL, "RPMB init failed\n"); |
| 403 | ASSERT(0); |
| 404 | } |
| 405 | |
Sridhar Parasuram | 568e7a6 | 2015-08-06 13:16:02 -0700 | [diff] [blame] | 406 | /* |
| 407 | * Load the sec app for first time |
| 408 | */ |
| 409 | if (load_sec_app() < 0) |
| 410 | { |
| 411 | dprintf(CRITICAL, "Failed to load App for verified\n"); |
| 412 | ASSERT(0); |
| 413 | } |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | unsigned board_machtype(void) |
| 417 | { |
| 418 | return LINUX_MACHTYPE_UNKNOWN; |
| 419 | } |
| 420 | |
| 421 | /* Detect the target type */ |
| 422 | void target_detect(struct board_data *board) |
| 423 | { |
| 424 | /* This is filled from board.c */ |
| 425 | } |
| 426 | |
Dhaval Patel | b95039c | 2015-03-16 11:14:06 -0700 | [diff] [blame] | 427 | static uint8_t splash_override; |
| 428 | /* Returns 1 if target supports continuous splash screen. */ |
| 429 | int target_cont_splash_screen() |
| 430 | { |
| 431 | uint8_t splash_screen = 0; |
Channagoud Kadabi | 25fd8ce | 2015-08-19 14:45:08 -0700 | [diff] [blame] | 432 | if(!splash_override && !pm_appsbl_charging_in_progress()) { |
Dhaval Patel | b95039c | 2015-03-16 11:14:06 -0700 | [diff] [blame] | 433 | switch(board_hardware_id()) |
| 434 | { |
| 435 | case HW_PLATFORM_SURF: |
| 436 | case HW_PLATFORM_MTP: |
| 437 | case HW_PLATFORM_FLUID: |
feifanz | 76fe648 | 2015-09-02 15:25:16 +0800 | [diff] [blame] | 438 | case HW_PLATFORM_QRD: |
Kuogee Hsieh | b976dfc | 2015-08-28 13:21:30 -0700 | [diff] [blame] | 439 | case HW_PLATFORM_LIQUID: |
Siddharth Zaveri | acaacc3 | 2015-12-12 15:10:33 -0500 | [diff] [blame] | 440 | case HW_PLATFORM_DRAGON: |
| 441 | case HW_PLATFORM_ADP: |
Dhaval Patel | b95039c | 2015-03-16 11:14:06 -0700 | [diff] [blame] | 442 | dprintf(SPEW, "Target_cont_splash=1\n"); |
| 443 | splash_screen = 1; |
| 444 | break; |
| 445 | default: |
| 446 | dprintf(SPEW, "Target_cont_splash=0\n"); |
| 447 | splash_screen = 0; |
| 448 | } |
| 449 | } |
| 450 | return splash_screen; |
| 451 | } |
| 452 | |
| 453 | void target_force_cont_splash_disable(uint8_t override) |
| 454 | { |
| 455 | splash_override = override; |
| 456 | } |
| 457 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 458 | /* Detect the modem type */ |
| 459 | void target_baseband_detect(struct board_data *board) |
| 460 | { |
| 461 | uint32_t platform; |
Channagoud Kadabi | 4021fa9 | 2015-11-03 16:35:26 -0800 | [diff] [blame] | 462 | uint32_t platform_hardware; |
| 463 | uint32_t platform_subtype; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 464 | |
| 465 | platform = board->platform; |
Channagoud Kadabi | 4021fa9 | 2015-11-03 16:35:26 -0800 | [diff] [blame] | 466 | platform_hardware = board->platform_hw; |
| 467 | platform_subtype = board->platform_subtype; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 468 | |
Channagoud Kadabi | 4021fa9 | 2015-11-03 16:35:26 -0800 | [diff] [blame] | 469 | if (platform_hardware == HW_PLATFORM_SURF) |
| 470 | { |
| 471 | if (platform_subtype == FUSION_I2S_CDP) |
| 472 | board->baseband = BASEBAND_MDM; |
| 473 | } |
| 474 | else if (platform_hardware == HW_PLATFORM_MTP) |
| 475 | { |
| 476 | if (platform_subtype == FUSION_I2S_MTP || |
| 477 | platform_subtype == FUSION_SLIMBUS) |
| 478 | board->baseband = BASEBAND_MDM; |
| 479 | } |
| 480 | /* |
| 481 | * Special case if MDM is not set look for chip info to decide |
| 482 | * platform subtype |
| 483 | */ |
| 484 | if (board->baseband != BASEBAND_MDM) |
| 485 | { |
| 486 | switch(platform) { |
| 487 | case APQ8096: |
Channagoud Kadabi | ee2b65e | 2016-01-11 19:10:29 -0800 | [diff] [blame] | 488 | case APQ8096AU: |
| 489 | case APQ8096SG: |
Channagoud Kadabi | 99d2370 | 2015-02-02 20:52:17 -0800 | [diff] [blame] | 490 | board->baseband = BASEBAND_APQ; |
Channagoud Kadabi | 4021fa9 | 2015-11-03 16:35:26 -0800 | [diff] [blame] | 491 | break; |
| 492 | case MSM8996: |
Channagoud Kadabi | ee2b65e | 2016-01-11 19:10:29 -0800 | [diff] [blame] | 493 | case MSM8996SG: |
| 494 | case MSM8996AU: |
| 495 | case MSM8996L: |
| 496 | board->baseband = BASEBAND_MSM; |
Channagoud Kadabi | 4021fa9 | 2015-11-03 16:35:26 -0800 | [diff] [blame] | 497 | break; |
| 498 | default: |
| 499 | dprintf(CRITICAL, "Platform type: %u is not supported\n",platform); |
| 500 | ASSERT(0); |
| 501 | }; |
| 502 | } |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 503 | } |
Channagoud Kadabi | 4021fa9 | 2015-11-03 16:35:26 -0800 | [diff] [blame] | 504 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 505 | unsigned target_baseband() |
| 506 | { |
| 507 | return board_baseband(); |
| 508 | } |
| 509 | |
| 510 | void target_serialno(unsigned char *buf) |
| 511 | { |
| 512 | unsigned int serialno; |
| 513 | if (target_is_emmc_boot()) { |
| 514 | serialno = mmc_get_psn(); |
| 515 | snprintf((char *)buf, 13, "%x", serialno); |
| 516 | } |
| 517 | } |
| 518 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 519 | int emmc_recovery_init(void) |
| 520 | { |
| 521 | return _emmc_recovery_init(); |
| 522 | } |
| 523 | |
| 524 | void target_usb_phy_reset() |
| 525 | { |
| 526 | usb30_qmp_phy_reset(); |
| 527 | qusb2_phy_reset(); |
| 528 | } |
| 529 | |
Tanya Finkel | 77318e0 | 2016-05-17 14:20:59 +0300 | [diff] [blame] | 530 | void target_usb_phy_sec_reset() |
| 531 | { |
| 532 | qusb2_phy_reset(); |
| 533 | } |
| 534 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 535 | target_usb_iface_t* target_usb30_init() |
| 536 | { |
| 537 | target_usb_iface_t *t_usb_iface; |
| 538 | |
| 539 | t_usb_iface = calloc(1, sizeof(target_usb_iface_t)); |
| 540 | ASSERT(t_usb_iface); |
| 541 | |
Tanya Finkel | 77318e0 | 2016-05-17 14:20:59 +0300 | [diff] [blame] | 542 | |
| 543 | /* for SBC we use secondary port */ |
| 544 | if (board_hardware_id() == HW_PLATFORM_SBC) |
| 545 | { |
| 546 | /* secondary port have no QMP phy,use only QUSB2 phy that have only reset */ |
| 547 | t_usb_iface->phy_init = NULL; |
| 548 | t_usb_iface->phy_reset = target_usb_phy_sec_reset; |
| 549 | t_usb_iface->clock_init = clock_usb20_init; |
| 550 | } else { |
| 551 | t_usb_iface->phy_init = usb30_qmp_phy_init; |
| 552 | t_usb_iface->phy_reset = target_usb_phy_reset; |
| 553 | t_usb_iface->clock_init = clock_usb30_init; |
| 554 | } |
| 555 | |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 556 | t_usb_iface->vbus_override = 1; |
| 557 | |
| 558 | return t_usb_iface; |
| 559 | } |
| 560 | |
| 561 | /* identify the usb controller to be used for the target */ |
| 562 | const char * target_usb_controller() |
| 563 | { |
| 564 | return "dwc"; |
| 565 | } |
| 566 | |
| 567 | uint32_t target_override_pll() |
| 568 | { |
Channagoud Kadabi | 1e5144b | 2015-04-28 17:15:05 -0700 | [diff] [blame] | 569 | if (board_soc_version() >= 0x20000) |
| 570 | return 0; |
| 571 | else |
| 572 | return 1; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Channagoud Kadabi | 4a870cf | 2015-01-21 10:39:01 -0800 | [diff] [blame] | 575 | crypto_engine_type board_ce_type(void) |
| 576 | { |
Channagoud Kadabi | 7edb9b4 | 2015-08-11 23:45:31 -0700 | [diff] [blame] | 577 | return CRYPTO_ENGINE_TYPE_HW; |
Channagoud Kadabi | 4a870cf | 2015-01-21 10:39:01 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | /* Set up params for h/w CE. */ |
| 581 | void target_crypto_init_params() |
| 582 | { |
| 583 | struct crypto_init_params ce_params; |
| 584 | |
| 585 | /* Set up base addresses and instance. */ |
| 586 | ce_params.crypto_instance = CE_INSTANCE; |
| 587 | ce_params.crypto_base = MSM_CE_BASE; |
| 588 | ce_params.bam_base = MSM_CE_BAM_BASE; |
| 589 | |
| 590 | /* Set up BAM config. */ |
| 591 | ce_params.bam_ee = CE_EE; |
| 592 | ce_params.pipes.read_pipe = CE_READ_PIPE; |
| 593 | ce_params.pipes.write_pipe = CE_WRITE_PIPE; |
| 594 | ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP; |
| 595 | ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP; |
| 596 | |
| 597 | /* Assign buffer sizes. */ |
| 598 | ce_params.num_ce = CE_ARRAY_SIZE; |
| 599 | ce_params.read_fifo_size = CE_FIFO_SIZE; |
| 600 | ce_params.write_fifo_size = CE_FIFO_SIZE; |
| 601 | |
| 602 | /* BAM is initialized by TZ for this platform. |
| 603 | * Do not do it again as the initialization address space |
| 604 | * is locked. |
| 605 | */ |
| 606 | ce_params.do_bam_init = 0; |
| 607 | |
| 608 | crypto_init_params(&ce_params); |
| 609 | } |
Channagoud Kadabi | 083290f | 2015-03-13 14:18:38 -0700 | [diff] [blame] | 610 | |
| 611 | unsigned target_pause_for_battery_charge(void) |
| 612 | { |
| 613 | uint8_t pon_reason = pm8x41_get_pon_reason(); |
| 614 | uint8_t is_cold_boot = pm8x41_get_is_cold_boot(); |
Channagoud Kadabi | 9b28c0b | 2016-01-11 18:42:33 -0800 | [diff] [blame] | 615 | pm_smbchg_usb_chgpth_pwr_pth_type charger_path = PM_SMBCHG_USB_CHGPTH_PWR_PATH__INVALID; |
| 616 | dprintf(INFO, "%s : pon_reason is %d cold_boot:%d charger path: %d\n", __func__, |
| 617 | pon_reason, is_cold_boot, charger_path); |
Channagoud Kadabi | 083290f | 2015-03-13 14:18:38 -0700 | [diff] [blame] | 618 | /* In case of fastboot reboot,adb reboot or if we see the power key |
| 619 | * pressed we do not want go into charger mode. |
| 620 | * fastboot reboot is warm boot with PON hard reset bit not set |
| 621 | * adb reboot is a cold boot with PON hard reset bit set |
| 622 | */ |
Channagoud Kadabi | 9b28c0b | 2016-01-11 18:42:33 -0800 | [diff] [blame] | 623 | pm_smbchg_get_charger_path(1, &charger_path); |
Channagoud Kadabi | 083290f | 2015-03-13 14:18:38 -0700 | [diff] [blame] | 624 | if (is_cold_boot && |
| 625 | (!(pon_reason & HARD_RST)) && |
| 626 | (!(pon_reason & KPDPWR_N)) && |
Channagoud Kadabi | 9b28c0b | 2016-01-11 18:42:33 -0800 | [diff] [blame] | 627 | ((pon_reason & PON1)) && |
| 628 | ((charger_path == PM_SMBCHG_USB_CHGPTH_PWR_PATH__DC_CHARGER) || |
| 629 | (charger_path == PM_SMBCHG_USB_CHGPTH_PWR_PATH__USB_CHARGER))) |
| 630 | |
Channagoud Kadabi | 083290f | 2015-03-13 14:18:38 -0700 | [diff] [blame] | 631 | return 1; |
| 632 | else |
| 633 | return 0; |
| 634 | } |
Channagoud Kadabi | 23edc0c | 2015-03-27 18:31:32 -0700 | [diff] [blame] | 635 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 636 | int set_download_mode(enum reboot_reason mode) |
Channagoud Kadabi | 23edc0c | 2015-03-27 18:31:32 -0700 | [diff] [blame] | 637 | { |
| 638 | int ret = 0; |
| 639 | ret = scm_dload_mode(mode); |
| 640 | |
| 641 | return ret; |
| 642 | } |
Channagoud Kadabi | ffc4b90 | 2015-06-25 23:14:27 -0700 | [diff] [blame] | 643 | |
Channagoud Kadabi | 65b518d | 2015-08-05 16:17:14 -0700 | [diff] [blame] | 644 | void pmic_reset_configure(uint8_t reset_type) |
Channagoud Kadabi | ffc4b90 | 2015-06-25 23:14:27 -0700 | [diff] [blame] | 645 | { |
Channagoud Kadabi | 65b518d | 2015-08-05 16:17:14 -0700 | [diff] [blame] | 646 | pm8994_reset_configure(reset_type); |
Channagoud Kadabi | ffc4b90 | 2015-06-25 23:14:27 -0700 | [diff] [blame] | 647 | } |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 648 | |
| 649 | uint32_t target_get_pmic() |
| 650 | { |
| 651 | return PMIC_IS_PMI8996; |
| 652 | } |
Channagoud Kadabi | 85c7ec3 | 2016-01-28 23:09:21 -0800 | [diff] [blame] | 653 | |
| 654 | int target_update_cmdline(char *cmdline) |
| 655 | { |
| 656 | uint32_t platform_id = board_platform_id(); |
| 657 | int len = 0; |
| 658 | if (platform_id == APQ8096SG || platform_id == MSM8996SG) |
| 659 | { |
| 660 | strlcpy(cmdline, " fpsimd.fpsimd_settings=0", TARGET_MAX_CMDLNBUF); |
| 661 | len = strlen (cmdline); |
Prasad Sodagudi | d76d180 | 2016-05-03 23:18:14 +0530 | [diff] [blame] | 662 | |
| 663 | /* App settings are not required for other than v1.0 SoC */ |
| 664 | if (board_soc_version() > 0x10000) { |
| 665 | strlcpy(cmdline + len, " app_setting.use_app_setting=0", TARGET_MAX_CMDLNBUF - len); |
| 666 | len = strlen (cmdline); |
| 667 | } |
Channagoud Kadabi | 85c7ec3 | 2016-01-28 23:09:21 -0800 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | return len; |
| 671 | } |
anisha agarwal | ebc52bc | 2016-07-08 15:50:00 -0700 | [diff] [blame] | 672 | |
| 673 | #if _APPEND_CMDLINE |
| 674 | int get_target_boot_params(const char *cmdline, const char *part, char **buf) |
| 675 | { |
| 676 | int system_ptn_index = -1; |
| 677 | unsigned int lun = 0; |
| 678 | char lun_char_base = 'a', lun_char_limit = 'h'; |
| 679 | |
| 680 | /*allocate buflen for largest possible string*/ |
| 681 | uint32_t buflen = strlen(" root=/dev/mmcblock0p") + sizeof(int) + 1; /*1 character for null termination*/ |
| 682 | |
| 683 | if (!cmdline || !part ) { |
| 684 | dprintf(CRITICAL, "WARN: Invalid input param\n"); |
| 685 | return -1; |
| 686 | } |
| 687 | |
| 688 | system_ptn_index = partition_get_index(part); |
| 689 | if (system_ptn_index == -1) |
| 690 | { |
| 691 | dprintf(CRITICAL,"Unable to find partition %s\n",part); |
| 692 | return -1; |
| 693 | } |
| 694 | |
| 695 | *buf = (char *)malloc(buflen); |
| 696 | if(!(*buf)) { |
| 697 | dprintf(CRITICAL,"Unable to allocate memory for boot params\n"); |
| 698 | return -1; |
| 699 | } |
| 700 | |
| 701 | /* |
| 702 | * check if cmdline contains "root="/"" at the beginning of buffer or |
| 703 | * " root="/"ubi.mtd" in the middle of buffer. |
| 704 | */ |
| 705 | if ((strncmp(cmdline," root=",strlen(" root=")) == 0) || |
| 706 | strstr(cmdline, " root=")) |
| 707 | dprintf(DEBUG, "DEBUG: cmdline has root=\n"); |
| 708 | else |
| 709 | { |
| 710 | if (platform_boot_dev_isemmc()) { |
| 711 | snprintf(*buf, buflen, " root=/dev/mmcblock0p%d", |
| 712 | system_ptn_index + 1); |
| 713 | } else { |
| 714 | lun = partition_get_lun(system_ptn_index); |
| 715 | if ((lun_char_base + lun) > lun_char_limit) { |
| 716 | dprintf(CRITICAL, "lun value exceeds limit\n"); |
| 717 | return -1; |
| 718 | } |
| 719 | snprintf(*buf, buflen, " root=/dev/sd%c%d", |
| 720 | lun_char_base + lun, |
| 721 | partition_get_index_in_lun(part, lun)); |
| 722 | } |
| 723 | } |
| 724 | /*in success case buf will be freed in the calling function of this*/ |
| 725 | return 0; |
| 726 | } |
| 727 | #endif |