Mayank Grover | 141c9bc | 2018-03-13 18:26:43 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +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> |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 36 | #include <dev/keys.h> |
| 37 | #include <spmi_v2.h> |
| 38 | #include <pm8x41.h> |
| 39 | #include <board.h> |
| 40 | #include <baseband.h> |
| 41 | #include <hsusb.h> |
| 42 | #include <scm.h> |
| 43 | #include <platform/gpio.h> |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 44 | #include <platform/irqs.h> |
| 45 | #include <platform/clock.h> |
| 46 | #include <crypto5_wrapper.h> |
| 47 | #include <partition_parser.h> |
| 48 | #include <stdlib.h> |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 49 | #include <gpio.h> |
Unnati Gandhi | c24a86f | 2014-09-19 16:07:16 +0530 | [diff] [blame] | 50 | #include <rpm-smd.h> |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 51 | #include <qpic_nand.h> |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 52 | #include <smem.h> |
Mayank Grover | 7e35183 | 2017-04-21 15:03:58 +0530 | [diff] [blame] | 53 | #include <secapp_loader.h> |
| 54 | #include <rpmb.h> |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 55 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 56 | #if LONG_PRESS_POWER_ON |
| 57 | #include <shutdown_detect.h> |
| 58 | #endif |
| 59 | |
| 60 | #if PON_VIB_SUPPORT |
| 61 | #include <vibrator.h> |
| 62 | #endif |
| 63 | |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 64 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 65 | #define PMIC_ARB_OWNER_ID 0 |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 66 | #define TLMM_VOL_UP_BTN_GPIO 90 |
Matthew Qin | 7bd789f | 2015-07-15 15:31:20 +0800 | [diff] [blame] | 67 | #define TLMM_VOL_DOWN_BTN_GPIO 91 |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 68 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 69 | #if PON_VIB_SUPPORT |
| 70 | #define VIBRATE_TIME 250 |
| 71 | #endif |
Vijay Kumar Pendoti | b228cfc | 2016-06-13 20:15:23 +0530 | [diff] [blame] | 72 | #define HW_SUBTYPE_APQ_NOWGR 0xA |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 73 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 74 | #define CE1_INSTANCE 1 |
| 75 | #define CE_EE 1 |
| 76 | #define CE_FIFO_SIZE 64 |
| 77 | #define CE_READ_PIPE 3 |
| 78 | #define CE_WRITE_PIPE 2 |
| 79 | #define CE_READ_PIPE_LOCK_GRP 0 |
| 80 | #define CE_WRITE_PIPE_LOCK_GRP 0 |
| 81 | #define CE_ARRAY_SIZE 20 |
Matthew Qin | 7bd789f | 2015-07-15 15:31:20 +0800 | [diff] [blame] | 82 | #define SUB_TYPE_SKUT 0x0A |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 83 | |
Mayank Grover | 141c9bc | 2018-03-13 18:26:43 +0530 | [diff] [blame] | 84 | /* Fastboot switch GPIO for Intrinsic board. */ |
| 85 | #define USB_SW_GPIO_INTRINSIC_SOM 3 |
| 86 | |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 87 | extern void smem_ptable_init(void); |
| 88 | extern void smem_add_modem_partitions(struct ptable *flash_ptable); |
| 89 | void target_sdc_init(); |
| 90 | |
| 91 | static struct ptable flash_ptable; |
| 92 | |
| 93 | /* NANDc BAM pipe numbers */ |
| 94 | #define DATA_CONSUMER_PIPE 0 |
| 95 | #define DATA_PRODUCER_PIPE 1 |
| 96 | #define CMD_PIPE 2 |
| 97 | |
| 98 | /* NANDc BAM pipe groups */ |
| 99 | #define DATA_PRODUCER_PIPE_GRP 0 |
| 100 | #define DATA_CONSUMER_PIPE_GRP 0 |
| 101 | #define CMD_PIPE_GRP 1 |
| 102 | |
| 103 | /* NANDc EE */ |
| 104 | #define QPIC_NAND_EE 0 |
| 105 | |
| 106 | /* NANDc max desc length. */ |
| 107 | #define QPIC_NAND_MAX_DESC_LEN 0x7FFF |
| 108 | |
| 109 | #define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF |
Mayank Grover | c119002 | 2017-02-23 17:28:46 +0530 | [diff] [blame] | 110 | #define UBI_CMDLINE " rootfstype=ubifs rootflags=bulk_read" |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 111 | |
| 112 | struct qpic_nand_init_config config; |
| 113 | |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 114 | struct mmc_device *dev; |
| 115 | |
| 116 | static uint32_t mmc_pwrctl_base[] = |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 117 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 118 | |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 119 | static uint32_t mmc_sdhci_base[] = |
| 120 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE }; |
| 121 | |
| 122 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 123 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ }; |
| 124 | |
| 125 | static void set_sdc_power_ctrl(void); |
Aparna Mallavarapu | 5f80cbf | 2014-10-13 11:10:22 -0700 | [diff] [blame] | 126 | static void set_ebi2_config(void); |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 127 | |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 128 | void update_ptable_names(void) |
| 129 | { |
| 130 | uint32_t ptn_index; |
| 131 | struct ptentry *ptentry_ptr = flash_ptable.parts; |
| 132 | struct ptentry *boot_ptn; |
| 133 | unsigned i; |
| 134 | uint32_t len; |
| 135 | |
| 136 | /* Change all names to lower case. */ |
| 137 | for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++) |
| 138 | { |
| 139 | len = strlen(ptentry_ptr[ptn_index].name); |
| 140 | |
| 141 | for (i = 0; i < len; i++) |
| 142 | { |
| 143 | if (isupper(ptentry_ptr[ptn_index].name[i])) |
| 144 | { |
| 145 | ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /* SBL fills in the last partition length as 0xFFFFFFFF. |
| 150 | * Update the length field based on the number of blocks on the flash. |
| 151 | */ |
| 152 | if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN) |
| 153 | { |
| 154 | ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start; |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 159 | void target_early_init(void) |
| 160 | { |
| 161 | #if WITH_DEBUG_UART |
Unnati Gandhi | 1d7ca72 | 2015-03-12 16:51:09 +0530 | [diff] [blame] | 162 | /* Do not intilaise UART in case the h/w |
| 163 | * is RCM. |
| 164 | */ |
Baochu Xu | 7a8327b | 2017-12-01 10:40:21 +0800 | [diff] [blame] | 165 | uint32_t platform_subtype = board_hardware_subtype(); |
| 166 | |
| 167 | if( board_hardware_id() == HW_PLATFORM_RCM ) |
Unnati Gandhi | 1d7ca72 | 2015-03-12 16:51:09 +0530 | [diff] [blame] | 168 | return; |
Baochu Xu | 7a8327b | 2017-12-01 10:40:21 +0800 | [diff] [blame] | 169 | else if ( platform_subtype == HW_PLATFORM_SUBTYPE_8909_PM660_V1) |
| 170 | uart_dm_init(2, 0, BLSP1_UART1_BASE); |
| 171 | else |
| 172 | uart_dm_init(1, 0, BLSP1_UART0_BASE); |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 173 | #endif |
Unnati Gandhi | 1d7ca72 | 2015-03-12 16:51:09 +0530 | [diff] [blame] | 174 | |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 175 | } |
| 176 | |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 177 | int target_is_emmc_boot(void) |
| 178 | { |
| 179 | return platform_boot_dev_isemmc(); |
| 180 | } |
| 181 | |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 182 | void target_sdc_init() |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 183 | { |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 184 | struct mmc_config_data config; |
| 185 | |
| 186 | /* Set drive strength & pull ctrl values */ |
| 187 | set_sdc_power_ctrl(); |
| 188 | |
| 189 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 190 | config.max_clk_rate = MMC_CLK_177MHZ; |
| 191 | |
| 192 | /* Try slot 1*/ |
| 193 | config.slot = 1; |
| 194 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 195 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 196 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 197 | config.hs400_support = 0; |
| 198 | |
| 199 | if (!(dev = mmc_init(&config))) { |
| 200 | /* Try slot 2 */ |
| 201 | config.slot = 2; |
| 202 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 203 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 204 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 205 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 206 | |
| 207 | if (!(dev = mmc_init(&config))) { |
| 208 | dprintf(CRITICAL, "mmc init failed!"); |
| 209 | ASSERT(0); |
| 210 | } |
| 211 | } |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 212 | } |
| 213 | |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 214 | void *target_mmc_device() |
| 215 | { |
| 216 | return (void *) dev; |
| 217 | } |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 218 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 219 | /* Return 1 if vol_up pressed */ |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 220 | int target_volume_up() |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 221 | { |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 222 | static uint8_t first_time = 0; |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 223 | uint8_t status = 0; |
| 224 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 225 | if (!first_time) { |
| 226 | gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE); |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 227 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 228 | /* Wait for the gpio config to take effect - debounce time */ |
| 229 | udelay(10000); |
| 230 | |
| 231 | first_time = 1; |
| 232 | } |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 233 | |
| 234 | /* Get status of GPIO */ |
| 235 | status = gpio_status(TLMM_VOL_UP_BTN_GPIO); |
| 236 | |
| 237 | /* Active low signal. */ |
| 238 | return !status; |
| 239 | } |
| 240 | |
| 241 | /* Return 1 if vol_down pressed */ |
| 242 | uint32_t target_volume_down() |
| 243 | { |
Matthew Qin | 7bd789f | 2015-07-15 15:31:20 +0800 | [diff] [blame] | 244 | if ((board_hardware_id() == HW_PLATFORM_QRD) && |
| 245 | (board_hardware_subtype() == SUB_TYPE_SKUT)) { |
| 246 | uint32_t status = 0; |
| 247 | |
| 248 | gpio_tlmm_config(TLMM_VOL_DOWN_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE); |
| 249 | |
| 250 | /* Wait for the gpio config to take effect - debounce time */ |
| 251 | thread_sleep(10); |
| 252 | |
| 253 | /* Get status of GPIO */ |
| 254 | status = gpio_status(TLMM_VOL_DOWN_BTN_GPIO); |
| 255 | |
| 256 | /* Active low signal. */ |
| 257 | return !status; |
| 258 | } else { |
| 259 | /* Volume down button tied in with PMIC RESIN. */ |
| 260 | return pm8x41_resin_status(); |
| 261 | } |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 262 | } |
| 263 | |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 264 | static void target_keystatus() |
| 265 | { |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 266 | keys_init(); |
| 267 | |
| 268 | if(target_volume_down()) |
| 269 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 270 | |
| 271 | if(target_volume_up()) |
| 272 | keys_post_event(KEY_VOLUMEUP, 1); |
| 273 | |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 274 | } |
| 275 | |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 276 | static void set_sdc_power_ctrl() |
| 277 | { |
| 278 | /* Drive strength configs for sdc pins */ |
| 279 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 280 | { |
Aparna Mallavarapu | 5f80cbf | 2014-10-13 11:10:22 -0700 | [diff] [blame] | 281 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL }, |
| 282 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL }, |
Unnati Gandhi | 9a6e6d4 | 2015-02-03 17:44:24 +0530 | [diff] [blame] | 283 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL }, |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 284 | }; |
| 285 | |
| 286 | /* Pull configs for sdc pins */ |
| 287 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 288 | { |
Aparna Mallavarapu | 5f80cbf | 2014-10-13 11:10:22 -0700 | [diff] [blame] | 289 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL }, |
| 290 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL }, |
| 291 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL }, |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 292 | }; |
| 293 | |
| 294 | /* Set the drive strength & pull control values */ |
| 295 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 296 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 297 | } |
| 298 | |
Aparna Mallavarapu | 5f80cbf | 2014-10-13 11:10:22 -0700 | [diff] [blame] | 299 | static void set_ebi2_config() |
| 300 | { |
| 301 | /* Drive strength configs for ebi2 pins */ |
| 302 | struct tlmm_cfgs ebi2_hdrv_cfg[] = |
| 303 | { |
| 304 | { EBI2_BUSY_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 305 | { EBI2_WE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 306 | { EBI2_OE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 307 | { EBI2_CLE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 308 | { EBI2_ALE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 309 | { EBI2_CS_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 310 | { EBI2_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL }, |
| 311 | }; |
| 312 | |
| 313 | /* Pull configs for ebi2 pins */ |
| 314 | struct tlmm_cfgs ebi2_pull_cfg[] = |
| 315 | { |
| 316 | { EBI2_BUSY_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 317 | { EBI2_WE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 318 | { EBI2_OE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 319 | { EBI2_CLE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 320 | { EBI2_ALE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 321 | { EBI2_CS_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 322 | { EBI2_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL }, |
| 323 | }; |
| 324 | |
| 325 | /* Set the drive strength & pull control values */ |
| 326 | tlmm_set_hdrive_ctrl(ebi2_hdrv_cfg, ARRAY_SIZE(ebi2_hdrv_cfg)); |
| 327 | tlmm_set_pull_ctrl(ebi2_pull_cfg, ARRAY_SIZE(ebi2_pull_cfg)); |
| 328 | |
| 329 | } |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 330 | void target_init(void) |
| 331 | { |
| 332 | uint32_t base_addr; |
| 333 | uint8_t slot; |
Jiten Patel | 8d56b46 | 2018-08-29 16:51:07 +0530 | [diff] [blame] | 334 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 7e35183 | 2017-04-21 15:03:58 +0530 | [diff] [blame] | 335 | int ret = 0; |
| 336 | #endif |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 337 | dprintf(INFO, "target_init()\n"); |
| 338 | |
| 339 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 340 | |
| 341 | target_keystatus(); |
| 342 | |
Unnati Gandhi | 36ef225 | 2014-11-04 18:45:14 +0530 | [diff] [blame] | 343 | #if BOOT_CONFIG_SUPPORT |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 344 | platform_read_boot_config(); |
Unnati Gandhi | 8e4711b | 2014-10-13 05:03:00 +0530 | [diff] [blame] | 345 | #endif |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 346 | |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 347 | if (platform_boot_dev_isemmc()) { |
| 348 | target_sdc_init(); |
| 349 | if (partition_read_table()) |
| 350 | { |
| 351 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 352 | ASSERT(0); |
| 353 | } |
| 354 | |
| 355 | } else { |
Aparna Mallavarapu | 5f80cbf | 2014-10-13 11:10:22 -0700 | [diff] [blame] | 356 | set_ebi2_config(); |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 357 | config.pipes.read_pipe = DATA_PRODUCER_PIPE; |
| 358 | config.pipes.write_pipe = DATA_CONSUMER_PIPE; |
| 359 | config.pipes.cmd_pipe = CMD_PIPE; |
| 360 | |
| 361 | config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP; |
| 362 | config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP; |
| 363 | config.pipes.cmd_pipe_grp = CMD_PIPE_GRP; |
| 364 | |
| 365 | config.bam_base = MSM_NAND_BAM_BASE; |
| 366 | config.nand_base = MSM_NAND_BASE; |
| 367 | config.ee = QPIC_NAND_EE; |
| 368 | config.max_desc_len = QPIC_NAND_MAX_DESC_LEN; |
| 369 | |
| 370 | qpic_nand_init(&config); |
| 371 | |
| 372 | ptable_init(&flash_ptable); |
| 373 | smem_ptable_init(); |
| 374 | smem_add_modem_partitions(&flash_ptable); |
| 375 | |
| 376 | update_ptable_names(); |
| 377 | flash_set_ptable(&flash_ptable); |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 378 | } |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 379 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 380 | #if LONG_PRESS_POWER_ON |
| 381 | shutdown_detect(); |
| 382 | #endif |
| 383 | |
| 384 | #if PON_VIB_SUPPORT |
| 385 | |
| 386 | /* turn on vibrator to indicate that phone is booting up to end user */ |
Mayank Grover | 7e35183 | 2017-04-21 15:03:58 +0530 | [diff] [blame] | 387 | vib_timed_turn_on(VIBRATE_TIME); |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 388 | #endif |
| 389 | |
| 390 | if (target_use_signed_kernel()) |
| 391 | target_crypto_init_params(); |
Unnati Gandhi | c24a86f | 2014-09-19 16:07:16 +0530 | [diff] [blame] | 392 | |
Jiten Patel | 8d56b46 | 2018-08-29 16:51:07 +0530 | [diff] [blame] | 393 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 509301a | 2017-10-26 12:10:11 +0530 | [diff] [blame] | 394 | if (VB_M <= target_get_vb_version()) |
Mayank Grover | 7e35183 | 2017-04-21 15:03:58 +0530 | [diff] [blame] | 395 | { |
| 396 | clock_ce_enable(CE1_INSTANCE); |
| 397 | |
| 398 | /* Initialize Qseecom */ |
| 399 | ret = qseecom_init(); |
| 400 | |
| 401 | if (ret < 0) |
| 402 | { |
| 403 | dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret); |
| 404 | ASSERT(0); |
| 405 | } |
| 406 | |
| 407 | /* Start Qseecom */ |
| 408 | ret = qseecom_tz_init(); |
| 409 | |
| 410 | if (ret < 0) |
| 411 | { |
| 412 | dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret); |
| 413 | ASSERT(0); |
| 414 | } |
| 415 | |
| 416 | if (rpmb_init() < 0) |
| 417 | { |
| 418 | dprintf(CRITICAL, "RPMB init failed\n"); |
| 419 | ASSERT(0); |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * Load the sec app for first time |
| 424 | */ |
| 425 | if (load_sec_app() < 0) |
| 426 | { |
| 427 | dprintf(CRITICAL, "Failed to load App for verified\n"); |
| 428 | ASSERT(0); |
| 429 | } |
| 430 | } |
| 431 | #endif |
| 432 | |
Unnati Gandhi | 36ef225 | 2014-11-04 18:45:14 +0530 | [diff] [blame] | 433 | #if SMD_SUPPORT |
Unnati Gandhi | c24a86f | 2014-09-19 16:07:16 +0530 | [diff] [blame] | 434 | rpm_smd_init(); |
Aparna Mallavarapu | 96fe9d9 | 2014-10-19 12:48:01 -0700 | [diff] [blame] | 435 | #endif |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | void target_serialno(unsigned char *buf) |
| 439 | { |
| 440 | uint32_t serialno; |
Saranya Chidura | 1600c2d | 2018-08-30 19:11:05 +0530 | [diff] [blame] | 441 | if (target_is_emmc_boot()) |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 442 | serialno = mmc_get_psn(); |
Saranya Chidura | 1600c2d | 2018-08-30 19:11:05 +0530 | [diff] [blame] | 443 | else |
| 444 | serialno = board_chip_serial(); |
| 445 | |
| 446 | snprintf((char *)buf, SERIAL_NUMBER_LEN, "%x", serialno); |
| 447 | |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | unsigned board_machtype(void) |
| 451 | { |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 452 | return LINUX_MACHTYPE_UNKNOWN; |
| 453 | } |
| 454 | |
Unnati Gandhi | a556a4d | 2014-08-12 10:42:21 +0530 | [diff] [blame] | 455 | /* Detect the target type */ |
| 456 | void target_detect(struct board_data *board) |
| 457 | { |
| 458 | /* |
| 459 | * already fill the board->target on board.c |
| 460 | */ |
| 461 | } |
| 462 | |
| 463 | void target_baseband_detect(struct board_data *board) |
| 464 | { |
| 465 | uint32_t platform; |
| 466 | |
| 467 | platform = board->platform; |
| 468 | switch(platform) |
| 469 | { |
| 470 | case MSM8909: |
| 471 | case MSM8209: |
| 472 | case MSM8208: |
Unnati Gandhi | 917c861 | 2015-02-06 16:50:32 +0530 | [diff] [blame] | 473 | case MSM8609: |
vijay kumar | ba95efb | 2015-09-08 15:24:12 +0530 | [diff] [blame] | 474 | case MSM8909W: |
Unnati Gandhi | a556a4d | 2014-08-12 10:42:21 +0530 | [diff] [blame] | 475 | board->baseband = BASEBAND_MSM; |
| 476 | break; |
| 477 | |
| 478 | case MDM9209: |
| 479 | case MDM9309: |
| 480 | case MDM9609: |
| 481 | board->baseband = BASEBAND_MDM; |
| 482 | break; |
| 483 | |
Unnati Gandhi | 36e4047 | 2014-12-16 12:00:04 +0530 | [diff] [blame] | 484 | case APQ8009: |
vijay kumar | ba95efb | 2015-09-08 15:24:12 +0530 | [diff] [blame] | 485 | case APQ8009W: |
Vijay Kumar Pendoti | b228cfc | 2016-06-13 20:15:23 +0530 | [diff] [blame] | 486 | if ((board->platform_hw == HW_PLATFORM_MTP) && |
Parth Dixit | 102ac21 | 2016-10-21 20:38:14 +0530 | [diff] [blame] | 487 | ((board->platform_subtype == HW_SUBTYPE_APQ_NOWGR) || |
| 488 | (board->platform_subtype == HW_PLATFORM_SUBTYPE_SWOC_NOWGR_CIRC))) |
Vijay Kumar Pendoti | b228cfc | 2016-06-13 20:15:23 +0530 | [diff] [blame] | 489 | board->baseband = BASEBAND_APQ_NOWGR; |
| 490 | else |
| 491 | board->baseband = BASEBAND_APQ; |
Unnati Gandhi | 36e4047 | 2014-12-16 12:00:04 +0530 | [diff] [blame] | 492 | break; |
| 493 | |
Unnati Gandhi | a556a4d | 2014-08-12 10:42:21 +0530 | [diff] [blame] | 494 | default: |
| 495 | dprintf(CRITICAL, "Platform type: %u is not supported\n", platform); |
| 496 | ASSERT(0); |
| 497 | }; |
| 498 | } |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 499 | uint8_t target_panel_auto_detect_enabled() |
| 500 | { |
| 501 | uint8_t ret = 0; |
| 502 | |
| 503 | switch(board_hardware_id()) { |
| 504 | default: |
| 505 | ret = 0; |
| 506 | break; |
| 507 | } |
| 508 | return ret; |
| 509 | } |
| 510 | |
| 511 | static uint8_t splash_override; |
| 512 | /* Returns 1 if target supports continuous splash screen. */ |
| 513 | int target_cont_splash_screen() |
| 514 | { |
| 515 | uint8_t splash_screen = 0; |
| 516 | if (!splash_override) { |
| 517 | switch (board_hardware_id()) { |
Shivaraj Shetty | 7db7eec | 2014-11-05 20:48:35 +0530 | [diff] [blame] | 518 | case HW_PLATFORM_SURF: |
| 519 | case HW_PLATFORM_MTP: |
Ray Zhang | 17a1311 | 2014-11-07 14:07:23 +0800 | [diff] [blame] | 520 | case HW_PLATFORM_QRD: |
Sandeep Panda | 8ede650 | 2014-12-02 10:56:16 +0530 | [diff] [blame] | 521 | case HW_PLATFORM_RCM: |
Shivaraj Shetty | 7db7eec | 2014-11-05 20:48:35 +0530 | [diff] [blame] | 522 | splash_screen = 1; |
| 523 | break; |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 524 | default: |
| 525 | splash_screen = 0; |
| 526 | break; |
| 527 | } |
| 528 | dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen); |
| 529 | } |
| 530 | return splash_screen; |
| 531 | } |
| 532 | |
| 533 | void target_force_cont_splash_disable(uint8_t override) |
| 534 | { |
| 535 | splash_override = override; |
| 536 | } |
Unnati Gandhi | a556a4d | 2014-08-12 10:42:21 +0530 | [diff] [blame] | 537 | |
Vijay Kumar Pendoti | 9268863 | 2016-05-27 11:35:32 +0530 | [diff] [blame] | 538 | /*Update this command line only for LE based builds*/ |
vijay kumar | 58d779b | 2015-08-31 17:25:49 +0530 | [diff] [blame] | 539 | int get_target_boot_params(const char *cmdline, const char *part, char **buf) |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 540 | { |
| 541 | struct ptable *ptable; |
| 542 | int system_ptn_index = -1; |
Vijay Kumar Pendoti | 9268863 | 2016-05-27 11:35:32 +0530 | [diff] [blame] | 543 | int le_based = -1; |
P.V. Phani Kumar | 3de93a0 | 2016-08-05 13:05:08 +0530 | [diff] [blame] | 544 | uint32_t buflen = 0; |
| 545 | |
| 546 | if (!cmdline || !part ) { |
| 547 | dprintf(CRITICAL, "WARN: Invalid input param\n"); |
| 548 | return -1; |
| 549 | } |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 550 | |
Vijay Kumar Pendoti | 9268863 | 2016-05-27 11:35:32 +0530 | [diff] [blame] | 551 | /*LE partition.xml will have recoveryfs partition*/ |
| 552 | if (target_is_emmc_boot()) |
| 553 | le_based = partition_get_index("recoveryfs"); |
| 554 | else |
| 555 | /*Nand targets by default have this*/ |
| 556 | le_based = 1; |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 557 | |
Vijay Kumar Pendoti | 9268863 | 2016-05-27 11:35:32 +0530 | [diff] [blame] | 558 | if (le_based != -1) |
| 559 | { |
| 560 | if (!target_is_emmc_boot()) |
| 561 | { |
| 562 | ptable = flash_get_ptable(); |
| 563 | if (!ptable) |
| 564 | { |
| 565 | dprintf(CRITICAL, |
| 566 | "WARN: Cannot get flash partition table\n"); |
| 567 | return -1; |
| 568 | } |
| 569 | system_ptn_index = ptable_get_index(ptable, part); |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 570 | } |
Vijay Kumar Pendoti | 9268863 | 2016-05-27 11:35:32 +0530 | [diff] [blame] | 571 | else |
| 572 | system_ptn_index = partition_get_index(part); |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 573 | if (system_ptn_index < 0) { |
| 574 | dprintf(CRITICAL, |
| 575 | "WARN: Cannot get partition index for %s\n", part); |
| 576 | return -1; |
| 577 | } |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 578 | /* |
| 579 | * check if cmdline contains "root=" at the beginning of buffer or |
| 580 | * " root=" in the middle of buffer. |
| 581 | */ |
| 582 | if (((!strncmp(cmdline, "root=", strlen("root="))) || |
P.V. Phani Kumar | d9a0842 | 2016-08-30 13:35:29 +0530 | [diff] [blame] | 583 | (strstr(cmdline, " root=")))) { |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 584 | dprintf(DEBUG, "DEBUG: cmdline has root=\n"); |
P.V. Phani Kumar | d9a0842 | 2016-08-30 13:35:29 +0530 | [diff] [blame] | 585 | return -1; |
| 586 | } |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 587 | else |
vijay kumar | 58d779b | 2015-08-31 17:25:49 +0530 | [diff] [blame] | 588 | /*in success case buf will be freed in the calling function of this*/ |
Vijay Kumar Pendoti | 9268863 | 2016-05-27 11:35:32 +0530 | [diff] [blame] | 589 | { |
| 590 | if (!target_is_emmc_boot()) |
P.V. Phani Kumar | 3de93a0 | 2016-08-05 13:05:08 +0530 | [diff] [blame] | 591 | { |
Mayank Grover | c119002 | 2017-02-23 17:28:46 +0530 | [diff] [blame] | 592 | buflen = strlen(UBI_CMDLINE) + strlen(" root=ubi0:rootfs ubi.mtd=") + sizeof(int) + 1; /* 1 byte for null character*/ |
P.V. Phani Kumar | 3de93a0 | 2016-08-05 13:05:08 +0530 | [diff] [blame] | 593 | |
| 594 | /* In success case, this memory is freed in calling function */ |
| 595 | *buf = (char *)malloc(buflen); |
| 596 | if(!(*buf)) { |
| 597 | dprintf(CRITICAL,"Unable to allocate memory for boot params \n"); |
| 598 | return -1; |
| 599 | } |
| 600 | |
Mayank Grover | c119002 | 2017-02-23 17:28:46 +0530 | [diff] [blame] | 601 | /* Adding command line parameters according to target boot type */ |
| 602 | snprintf(*buf, buflen, UBI_CMDLINE); |
| 603 | snprintf(*buf+strlen(*buf), buflen, " root=ubi0:rootfs ubi.mtd=%d", system_ptn_index); |
P.V. Phani Kumar | 3de93a0 | 2016-08-05 13:05:08 +0530 | [diff] [blame] | 604 | } |
Vijay Kumar Pendoti | 9268863 | 2016-05-27 11:35:32 +0530 | [diff] [blame] | 605 | else |
P.V. Phani Kumar | 3de93a0 | 2016-08-05 13:05:08 +0530 | [diff] [blame] | 606 | { |
| 607 | /* Extra character is for Null termination */ |
| 608 | buflen = strlen(" root=/dev/mmcblk0p") + sizeof(int) + 1; |
| 609 | |
| 610 | /* In success case, this memory is freed in calling function */ |
| 611 | *buf = (char *)malloc(buflen); |
| 612 | if(!(*buf)) { |
| 613 | dprintf(CRITICAL,"Unable to allocate memory for boot params \n"); |
| 614 | return -1; |
| 615 | } |
| 616 | |
Vijay Kumar Pendoti | 9268863 | 2016-05-27 11:35:32 +0530 | [diff] [blame] | 617 | /*For Emmc case increase the ptn_index by 1*/ |
P.V. Phani Kumar | d9a0842 | 2016-08-30 13:35:29 +0530 | [diff] [blame] | 618 | snprintf(*buf, buflen, " root=/dev/mmcblk0p%d",system_ptn_index + 1); |
P.V. Phani Kumar | 3de93a0 | 2016-08-05 13:05:08 +0530 | [diff] [blame] | 619 | } |
Vijay Kumar Pendoti | 9268863 | 2016-05-27 11:35:32 +0530 | [diff] [blame] | 620 | } |
P.V. Phani Kumar | 3de93a0 | 2016-08-05 13:05:08 +0530 | [diff] [blame] | 621 | |
| 622 | /*Return for LE based Targets.*/ |
| 623 | return 0; |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 624 | } |
P.V. Phani Kumar | 3de93a0 | 2016-08-05 13:05:08 +0530 | [diff] [blame] | 625 | return -1; |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 626 | } |
| 627 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 628 | unsigned target_baseband() |
| 629 | { |
| 630 | return board_baseband(); |
| 631 | } |
| 632 | |
| 633 | int emmc_recovery_init(void) |
| 634 | { |
| 635 | return _emmc_recovery_init(); |
| 636 | } |
| 637 | |
| 638 | void target_usb_init(void) |
| 639 | { |
| 640 | uint32_t val; |
| 641 | |
| 642 | /* Select and enable external configuration with USB PHY */ |
| 643 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 644 | |
| 645 | /* Enable sess_vld */ |
| 646 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 647 | writel(val, USB_GENCONFIG_2); |
| 648 | |
| 649 | /* Enable external vbus configuration in the LINK */ |
| 650 | val = readl(USB_USBCMD); |
| 651 | val |= SESS_VLD_CTRL; |
| 652 | writel(val, USB_USBCMD); |
| 653 | } |
| 654 | |
| 655 | unsigned target_pause_for_battery_charge(void) |
| 656 | { |
Mayank Grover | 6f12588 | 2017-12-05 10:28:32 +0530 | [diff] [blame] | 657 | uint32_t pmic = target_get_pmic(); |
| 658 | uint8_t pon_reason = 0; |
| 659 | uint8_t is_cold_boot = 0; |
| 660 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 661 | /* In case of fastboot reboot,adb reboot or if we see the power key |
| 662 | * pressed we do not want go into charger mode. |
| 663 | * fastboot reboot is warm boot with PON hard reset bit not set |
| 664 | * adb reboot is a cold boot with PON hard reset bit set |
| 665 | */ |
Mayank Grover | 6f12588 | 2017-12-05 10:28:32 +0530 | [diff] [blame] | 666 | if (pmic == PMIC_IS_PM660) |
| 667 | { |
| 668 | pon_reason = pm660_get_pon_reason(); |
| 669 | is_cold_boot = pm660_get_is_cold_boot(); |
| 670 | } |
| 671 | else |
| 672 | { |
| 673 | pon_reason = pm8x41_get_pon_reason(); |
| 674 | is_cold_boot = pm8x41_get_is_cold_boot(); |
| 675 | } |
| 676 | dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__, |
| 677 | pon_reason, is_cold_boot); |
| 678 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 679 | if (is_cold_boot && |
| 680 | (!(pon_reason & HARD_RST)) && |
| 681 | (!(pon_reason & KPDPWR_N)) && |
Chunmei Cai | 6eb22fe | 2015-08-20 15:39:06 +0800 | [diff] [blame] | 682 | ((pon_reason & USB_CHG) || (pon_reason & DC_CHG) || (pon_reason & CBLPWR_N))) |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 683 | return 1; |
| 684 | else |
| 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | void target_usb_stop(void) |
| 689 | { |
| 690 | /* Disable VBUS mimicing in the controller. */ |
| 691 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR); |
| 692 | } |
| 693 | |
| 694 | |
| 695 | void target_uninit(void) |
| 696 | { |
| 697 | #if PON_VIB_SUPPORT |
| 698 | /* wait for the vibrator timer is expried */ |
| 699 | wait_vib_timeout(); |
| 700 | #endif |
| 701 | |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 702 | if (platform_boot_dev_isemmc()) |
| 703 | { |
| 704 | mmc_put_card_to_sleep(dev); |
| 705 | sdhci_mode_disable(&dev->host); |
| 706 | } |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 707 | |
| 708 | if (crypto_initialized()) |
| 709 | crypto_eng_cleanup(); |
| 710 | |
| 711 | if (target_is_ssd_enabled()) |
| 712 | clock_ce_disable(CE1_INSTANCE); |
Unnati Gandhi | c24a86f | 2014-09-19 16:07:16 +0530 | [diff] [blame] | 713 | |
Jiten Patel | 8d56b46 | 2018-08-29 16:51:07 +0530 | [diff] [blame] | 714 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 509301a | 2017-10-26 12:10:11 +0530 | [diff] [blame] | 715 | if(VB_M <= target_get_vb_version()) |
Mayank Grover | 7e35183 | 2017-04-21 15:03:58 +0530 | [diff] [blame] | 716 | { |
| 717 | if (is_sec_app_loaded()) |
| 718 | { |
| 719 | if (send_milestone_call_to_tz() < 0) |
| 720 | { |
| 721 | dprintf(CRITICAL, "Failed to unload App for rpmb\n"); |
| 722 | ASSERT(0); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | if (rpmb_uninit() < 0) |
| 727 | { |
| 728 | dprintf(CRITICAL, "RPMB uninit failed\n"); |
| 729 | ASSERT(0); |
| 730 | } |
| 731 | |
| 732 | clock_ce_disable(CE1_INSTANCE); |
| 733 | } |
| 734 | #endif |
| 735 | |
Unnati Gandhi | 36ef225 | 2014-11-04 18:45:14 +0530 | [diff] [blame] | 736 | #if SMD_SUPPORT |
Unnati Gandhi | c24a86f | 2014-09-19 16:07:16 +0530 | [diff] [blame] | 737 | rpm_smd_uninit(); |
Aparna Mallavarapu | 96fe9d9 | 2014-10-19 12:48:01 -0700 | [diff] [blame] | 738 | #endif |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 742 | void target_fastboot_init(void) |
| 743 | { |
Mayank Grover | 141c9bc | 2018-03-13 18:26:43 +0530 | [diff] [blame] | 744 | uint32_t hw_id = board_hardware_id(); |
| 745 | uint32_t platform_subtype = board_hardware_subtype(); |
| 746 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 747 | /* Set the BOOT_DONE flag in PM8916 */ |
| 748 | pm8x41_set_boot_done(); |
| 749 | |
| 750 | if (target_is_ssd_enabled()) { |
| 751 | clock_ce_enable(CE1_INSTANCE); |
| 752 | target_load_ssd_keystore(); |
| 753 | } |
Mayank Grover | 141c9bc | 2018-03-13 18:26:43 +0530 | [diff] [blame] | 754 | |
| 755 | if ((HW_PLATFORM_MTP == hw_id) && |
| 756 | (HW_PLATFORM_SUBTYPE_INTRINSIC_SOM == platform_subtype)) |
| 757 | { |
| 758 | dprintf(SPEW, "Enabling PMIC GPIO for USB detection\n"); |
| 759 | |
| 760 | struct pm8x41_gpio usbgpio_param = { |
| 761 | .direction = PM_GPIO_DIR_OUT, |
| 762 | .vin_sel = 0, |
| 763 | .out_strength = PM_GPIO_OUT_DRIVE_MED, |
| 764 | .function = PM_GPIO_FUNC_HIGH, |
| 765 | .pull = PM_GPIO_PULLDOWN_10, |
| 766 | .inv_int_pol = PM_GPIO_INVERT, |
| 767 | }; |
| 768 | |
| 769 | pm8x41_gpio_config(USB_SW_GPIO_INTRINSIC_SOM, &usbgpio_param); |
| 770 | pm8x41_gpio_set(USB_SW_GPIO_INTRINSIC_SOM, 0); |
| 771 | } |
| 772 | |
| 773 | return; |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 774 | } |
| 775 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 776 | int set_download_mode(enum reboot_reason mode) |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 777 | { |
| 778 | int ret = 0; |
| 779 | ret = scm_dload_mode(mode); |
| 780 | |
| 781 | pm8x41_clear_pmic_watchdog(); |
| 782 | |
| 783 | return ret; |
| 784 | } |
| 785 | |
| 786 | void target_load_ssd_keystore(void) |
| 787 | { |
| 788 | uint64_t ptn; |
| 789 | int index; |
| 790 | uint64_t size; |
| 791 | uint32_t *buffer = NULL; |
| 792 | |
| 793 | if (!target_is_ssd_enabled()) |
| 794 | return; |
| 795 | |
| 796 | index = partition_get_index("ssd"); |
| 797 | |
| 798 | ptn = partition_get_offset(index); |
| 799 | if (ptn == 0){ |
| 800 | dprintf(CRITICAL, "Error: ssd partition not found\n"); |
| 801 | return; |
| 802 | } |
| 803 | |
| 804 | size = partition_get_size(index); |
| 805 | if (size == 0) { |
| 806 | dprintf(CRITICAL, "Error: invalid ssd partition size\n"); |
| 807 | return; |
| 808 | } |
| 809 | |
| 810 | buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE)); |
| 811 | if (!buffer) { |
| 812 | dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n"); |
| 813 | return; |
| 814 | } |
| 815 | if (mmc_read(ptn, buffer, size)) { |
| 816 | dprintf(CRITICAL, "Error: cannot read data\n"); |
| 817 | free(buffer); |
| 818 | return; |
| 819 | } |
| 820 | |
| 821 | clock_ce_enable(CE1_INSTANCE); |
| 822 | scm_protect_keystore(buffer, size); |
| 823 | clock_ce_disable(CE1_INSTANCE); |
| 824 | free(buffer); |
| 825 | } |
| 826 | |
| 827 | crypto_engine_type board_ce_type(void) |
| 828 | { |
| 829 | return CRYPTO_ENGINE_TYPE_HW; |
| 830 | } |
| 831 | |
| 832 | /* Set up params for h/w CE. */ |
| 833 | void target_crypto_init_params() |
| 834 | { |
| 835 | struct crypto_init_params ce_params; |
| 836 | |
| 837 | /* Set up base addresses and instance. */ |
| 838 | ce_params.crypto_instance = CE1_INSTANCE; |
| 839 | ce_params.crypto_base = MSM_CE1_BASE; |
| 840 | ce_params.bam_base = MSM_CE1_BAM_BASE; |
| 841 | |
| 842 | /* Set up BAM config. */ |
| 843 | ce_params.bam_ee = CE_EE; |
| 844 | ce_params.pipes.read_pipe = CE_READ_PIPE; |
| 845 | ce_params.pipes.write_pipe = CE_WRITE_PIPE; |
| 846 | ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP; |
| 847 | ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP; |
| 848 | |
| 849 | /* Assign buffer sizes. */ |
| 850 | ce_params.num_ce = CE_ARRAY_SIZE; |
| 851 | ce_params.read_fifo_size = CE_FIFO_SIZE; |
| 852 | ce_params.write_fifo_size = CE_FIFO_SIZE; |
| 853 | |
| 854 | /* BAM is initialized by TZ for this platform. |
| 855 | * Do not do it again as the initialization address space |
| 856 | * is locked. |
| 857 | */ |
| 858 | ce_params.do_bam_init = 0; |
| 859 | |
| 860 | crypto_init_params(&ce_params); |
| 861 | } |
| 862 | |
| 863 | uint32_t target_get_hlos_subtype() |
| 864 | { |
| 865 | return board_hlos_subtype(); |
| 866 | } |
Channagoud Kadabi | 400bd11 | 2015-08-10 15:38:10 -0700 | [diff] [blame] | 867 | |
| 868 | void pmic_reset_configure(uint8_t reset_type) |
| 869 | { |
| 870 | pm8x41_reset_configure(reset_type); |
| 871 | } |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 872 | |
| 873 | uint32_t target_get_pmic() |
| 874 | { |
Arun kumar | cf6e06e | 2018-09-26 12:49:53 +0530 | [diff] [blame] | 875 | uint32_t hw_id = board_hardware_id(); |
| 876 | uint32_t platform = board_platform_id(); |
| 877 | uint32_t platform_subtype = board_hardware_subtype(); |
| 878 | |
| 879 | if ((MSM8909 == platform) && |
| 880 | (HW_PLATFORM_MTP == hw_id) && |
| 881 | (HW_PLATFORM_SUBTYPE_8909_PM8916 == platform_subtype)) |
| 882 | return PMIC_IS_PM8916; |
| 883 | else if ((platform_subtype == HW_PLATFORM_SUBTYPE_8909_PM660) || |
| 884 | (platform_subtype == HW_PLATFORM_SUBTYPE_8909_PM660_V1) || |
| 885 | (platform_subtype == HW_PLATFORM_SUBTYPE_8909_COMPAL_ALPHA)) |
Mayank Grover | 3f20adf | 2017-07-03 16:33:22 +0530 | [diff] [blame] | 886 | return PMIC_IS_PM660; |
| 887 | else |
| 888 | return PMIC_IS_PM8909; |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 889 | } |