Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <platform/iomap.h> |
| 31 | #include <reg.h> |
| 32 | #include <target.h> |
| 33 | #include <platform.h> |
| 34 | #include <uart_dm.h> |
| 35 | #include <mmc.h> |
| 36 | #include <platform/gpio.h> |
| 37 | #include <dev/keys.h> |
| 38 | #include <spmi_v2.h> |
| 39 | #include <pm8x41.h> |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 40 | #include <pm8x41_hw.h> |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 41 | #include <board.h> |
| 42 | #include <baseband.h> |
| 43 | #include <hsusb.h> |
| 44 | #include <scm.h> |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 45 | #include <platform/irqs.h> |
| 46 | #include <platform/clock.h> |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 47 | #include <platform/timer.h> |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 48 | #include <crypto5_wrapper.h> |
| 49 | #include <partition_parser.h> |
| 50 | #include <stdlib.h> |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 51 | #include <rpm-smd.h> |
| 52 | #include <spmi.h> |
| 53 | #include <sdhci_msm.h> |
| 54 | #include <clock.h> |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 55 | #include <boot_device.h> |
| 56 | #include <secapp_loader.h> |
| 57 | #include <rpmb.h> |
| 58 | #include <smem.h> |
| 59 | #include <qmp_phy.h> |
| 60 | #include <qusb2_phy.h> |
Padmanabhan Komanduru | 0104a89 | 2016-01-22 16:58:10 +0530 | [diff] [blame] | 61 | #include "target/display.h" |
Sourabh Banerjee | 51695cc | 2018-02-27 09:40:30 +0530 | [diff] [blame] | 62 | #include "recovery.h" |
| 63 | #include <ab_partition_parser.h> |
tracychui | d184b91 | 2020-06-05 17:31:38 +0800 | [diff] [blame] | 64 | /*[20200605][TracyChui] Implement get Serial Number start*/ |
| 65 | #include <devinfo.h> |
| 66 | /*[20200605][TracyChui] Implement get Serial Number end*/ |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 67 | |
| 68 | #if LONG_PRESS_POWER_ON |
| 69 | #include <shutdown_detect.h> |
| 70 | #endif |
| 71 | |
c_wufeng | 41310ae | 2016-01-14 17:59:22 +0800 | [diff] [blame] | 72 | #if PON_VIB_SUPPORT |
| 73 | #include <vibrator.h> |
| 74 | #define VIBRATE_TIME 250 |
| 75 | #endif |
| 76 | |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 77 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 78 | #define PMIC_ARB_OWNER_ID 0 |
| 79 | #define TLMM_VOL_UP_BTN_GPIO 85 |
| 80 | |
Vamshi Krishna B V | 8275376 | 2018-03-13 18:49:43 +0530 | [diff] [blame] | 81 | #define PRI_PMIC_SLAVE_ID 0 |
| 82 | #define SEC_PMIC_SLAVE_ID 2 |
| 83 | |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 84 | #define FASTBOOT_MODE 0x77665500 |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 85 | #define RECOVERY_MODE 0x77665502 |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 86 | #define PON_SOFT_RB_SPARE 0x88F |
Sourabh Banerjee | 51695cc | 2018-02-27 09:40:30 +0530 | [diff] [blame] | 87 | |
| 88 | #if VERITY_LE |
| 89 | #define ROOTDEV_CMDLINE " root=/dev/dm-0 dm=\"system none ro,0 1 android-verity /dev/mmcblk0p" |
| 90 | #else |
| 91 | #define ROOTDEV_CMDLINE " root=/dev/mmcblk0p" |
| 92 | #endif |
| 93 | |
| 94 | #define RECOVERY_ROOTDEV_CMDLINE " root=/dev/mmcblk0p" |
| 95 | #define ROOTDEV_FSTYPE_CMDLINE (" rootfstype=ext4 ") |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 96 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 97 | #define CE1_INSTANCE 1 |
| 98 | #define CE_EE 1 |
| 99 | #define CE_FIFO_SIZE 64 |
| 100 | #define CE_READ_PIPE 3 |
| 101 | #define CE_WRITE_PIPE 2 |
| 102 | #define CE_READ_PIPE_LOCK_GRP 0 |
| 103 | #define CE_WRITE_PIPE_LOCK_GRP 0 |
| 104 | #define CE_ARRAY_SIZE 20 |
| 105 | |
Vijay Kumar Pendoti | 7e9226c | 2016-09-21 20:49:21 +0530 | [diff] [blame] | 106 | #define SMBCHG_USB_RT_STS 0x21310 |
| 107 | #define USBIN_UV_RT_STS BIT(0) |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 108 | #define USBIN_UV_RT_STS_PMI632 BIT(2) |
Vijay Kumar Pendoti | 7e9226c | 2016-09-21 20:49:21 +0530 | [diff] [blame] | 109 | |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 110 | struct mmc_device *dev; |
| 111 | |
| 112 | static uint32_t mmc_pwrctl_base[] = |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 113 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 114 | |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 115 | static uint32_t mmc_sdhci_base[] = |
| 116 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE }; |
| 117 | |
| 118 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 119 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ }; |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 120 | |
| 121 | void target_early_init(void) |
| 122 | { |
| 123 | #if WITH_DEBUG_UART |
P.V. Phani Kumar | 2e4eeae | 2015-12-31 16:52:54 +0530 | [diff] [blame] | 124 | uart_dm_init(1, 0, BLSP1_UART0_BASE); |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 125 | #endif |
| 126 | } |
| 127 | |
anisha agarwal | ebc52bc | 2016-07-08 15:50:00 -0700 | [diff] [blame] | 128 | #if _APPEND_CMDLINE |
Sourabh Banerjee | 51695cc | 2018-02-27 09:40:30 +0530 | [diff] [blame] | 129 | /* |
| 130 | get_target_boot_params: appends bootparam as per following conditions: |
| 131 | |
| 132 | 1. Always appends "rootfstype=ext4", if it is emmc boot path. |
| 133 | |
| 134 | 2. Appends more bootparams only if multi-slot is not supported |
| 135 | 2.1 If booting into recovery: |
| 136 | rootfstype=ext4 root=/dev/mmcblk0p<NN> |
| 137 | where: root=/dev/mmcblk0p<NN> is block device to "recoveryfs" partition |
| 138 | |
| 139 | 2.2 If booting into normal boot path: |
| 140 | 2.2.1 If verity is enabled: |
| 141 | root=/dev/dm-0 dm=\"system none ro,0 1 android-verity /dev/mmcblk0p<NN> |
| 142 | where: root=/dev/mmcblk0p<NN> is block device to "system" partition |
| 143 | |
| 144 | 2.2.2 If verity is not enabled |
| 145 | rootfstype=ext4 root=/dev/mmcblk0p<NN> |
| 146 | where: root=/dev/mmcblk0p<NN> is block device to "system" partition |
| 147 | */ |
anisha agarwal | ebc52bc | 2016-07-08 15:50:00 -0700 | [diff] [blame] | 148 | int get_target_boot_params(const char *cmdline, const char *part, char **buf) |
| 149 | { |
| 150 | int system_ptn_index = -1; |
| 151 | uint32_t buflen; |
| 152 | int ret = -1; |
| 153 | |
| 154 | if (!cmdline || !part ) { |
| 155 | dprintf(CRITICAL, "WARN: Invalid input param\n"); |
| 156 | return -1; |
| 157 | } |
| 158 | |
| 159 | if (!strstr(cmdline, "root=/dev/ram")) /* This check is to handle kdev boot */ |
| 160 | { |
| 161 | if (target_is_emmc_boot()) { |
Sourabh Banerjee | 51695cc | 2018-02-27 09:40:30 +0530 | [diff] [blame] | 162 | /* |
| 163 | Calculate length for "rootfstype=ext4" |
| 164 | The "rootfstype=ext4" is appended to kernel commandline in all conditions |
| 165 | The conditions are subsequently documented. |
| 166 | */ |
| 167 | buflen = sizeof(ROOTDEV_FSTYPE_CMDLINE); |
| 168 | |
| 169 | /* |
| 170 | Append other bootparams to command line |
| 171 | only if multi-slot is not supported. |
| 172 | */ |
| 173 | if(!partition_multislot_is_supported()) { |
| 174 | /* |
| 175 | When booting into recovery append |
| 176 | block device number for "recoveryfs" |
| 177 | Eventual command line looks like: |
| 178 | ...rootfstype=ext4 root=/dev/mmcblk0p<NN>... |
| 179 | */ |
| 180 | if(boot_into_recovery == true) { |
| 181 | buflen += strlen(RECOVERY_ROOTDEV_CMDLINE) + sizeof(int) + 1; |
| 182 | } else { |
| 183 | /* |
| 184 | When booting normally append command line |
| 185 | with verity bootparam only if VERITY_LE is |
| 186 | defined. The command line is as follows: |
| 187 | ...root=/dev/dm-0 dm=\"system none ro,0 1 android-verity /dev/mmcblk0p<NN>... |
| 188 | OR |
| 189 | ...root=/dev/mmcblk0p<NN>... |
| 190 | */ |
| 191 | buflen += strlen(ROOTDEV_CMDLINE) + sizeof(int) + 1; |
| 192 | } |
| 193 | } |
| 194 | |
anisha agarwal | ebc52bc | 2016-07-08 15:50:00 -0700 | [diff] [blame] | 195 | *buf = (char *)malloc(buflen); |
| 196 | if(!(*buf)) { |
| 197 | dprintf(CRITICAL,"Unable to allocate memory for boot params\n"); |
| 198 | return -1; |
| 199 | } |
| 200 | /* Below is for emmc boot */ |
| 201 | system_ptn_index = partition_get_index(part) + 1; /* Adding +1 as offsets for eMMC start at 1 and NAND at 0 */ |
| 202 | if (system_ptn_index < 0) { |
| 203 | dprintf(CRITICAL, |
Sourabh Banerjee | 51695cc | 2018-02-27 09:40:30 +0530 | [diff] [blame] | 204 | "WARN: Cannot get partition index for %s\n", part); |
anisha agarwal | ebc52bc | 2016-07-08 15:50:00 -0700 | [diff] [blame] | 205 | free(*buf); |
| 206 | return -1; |
| 207 | } |
Sourabh Banerjee | 51695cc | 2018-02-27 09:40:30 +0530 | [diff] [blame] | 208 | |
| 209 | if(!partition_multislot_is_supported()) { |
| 210 | if(boot_into_recovery == true) { |
| 211 | snprintf(*buf, buflen, "%s %s%d", ROOTDEV_FSTYPE_CMDLINE, |
| 212 | RECOVERY_ROOTDEV_CMDLINE, system_ptn_index); |
| 213 | } else { |
| 214 | snprintf(*buf, buflen, "%s %s%d", ROOTDEV_FSTYPE_CMDLINE, |
| 215 | ROOTDEV_CMDLINE, system_ptn_index); |
| 216 | } |
| 217 | } |
| 218 | |
anisha agarwal | ebc52bc | 2016-07-08 15:50:00 -0700 | [diff] [blame] | 219 | ret = 0; |
| 220 | } |
| 221 | } |
| 222 | /*in success case buf will be freed in the calling function of this*/ |
| 223 | return ret; |
| 224 | } |
| 225 | #endif |
| 226 | |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 227 | static void set_sdc_power_ctrl() |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 228 | { |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 229 | /* Drive strength configs for sdc pins */ |
| 230 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 231 | { |
| 232 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, 0}, |
| 233 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, 0}, |
| 234 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK , 0}, |
| 235 | }; |
| 236 | |
| 237 | /* Pull configs for sdc pins */ |
| 238 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 239 | { |
| 240 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, 0}, |
| 241 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0}, |
| 242 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0}, |
| 243 | }; |
| 244 | |
| 245 | struct tlmm_cfgs sdc1_rclk_cfg[] = |
| 246 | { |
| 247 | { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, 0}, |
| 248 | }; |
| 249 | |
| 250 | /* Set the drive strength & pull control values */ |
| 251 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 252 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 253 | tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg)); |
| 254 | } |
| 255 | |
| 256 | void target_sdc_init() |
| 257 | { |
| 258 | struct mmc_config_data config; |
| 259 | |
| 260 | /* Set drive strength & pull ctrl values */ |
| 261 | set_sdc_power_ctrl(); |
| 262 | |
| 263 | config.slot = MMC_SLOT; |
| 264 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 265 | config.max_clk_rate = MMC_CLK_192MHZ; |
| 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 | config.hs400_support = 1; |
| 270 | |
| 271 | if (!(dev = mmc_init(&config))) { |
| 272 | /* Try different config. values */ |
| 273 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 274 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 275 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 276 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 277 | config.hs400_support = 0; |
| 278 | |
| 279 | if (!(dev = mmc_init(&config))) { |
| 280 | dprintf(CRITICAL, "mmc init failed!"); |
| 281 | ASSERT(0); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | void *target_mmc_device() |
| 287 | { |
| 288 | return (void *) dev; |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /* Return 1 if vol_up pressed */ |
Gaurav Nebhwani | d9dd034 | 2016-01-28 16:35:55 +0530 | [diff] [blame] | 292 | int target_volume_up() |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 293 | { |
| 294 | uint8_t status = 0; |
| 295 | |
| 296 | gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE); |
| 297 | |
| 298 | /* Wait for the gpio config to take effect - debounce time */ |
| 299 | thread_sleep(10); |
| 300 | |
| 301 | /* Get status of GPIO */ |
| 302 | status = gpio_status(TLMM_VOL_UP_BTN_GPIO); |
| 303 | |
| 304 | /* Active high signal. */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 305 | return !status; |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /* Return 1 if vol_down pressed */ |
| 309 | uint32_t target_volume_down() |
| 310 | { |
| 311 | /* Volume down button tied in with PMIC RESIN. */ |
| 312 | return pm8x41_resin_status(); |
| 313 | } |
| 314 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 315 | uint32_t target_is_pwrkey_pon_reason() |
| 316 | { |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 317 | uint32_t pmic = target_get_pmic(); |
| 318 | uint8_t pon_reason = 0; |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 319 | bool usb_present_sts = 1; |
| 320 | |
| 321 | if (pmic == PMIC_IS_PMI632) |
| 322 | { |
Umang Agrawal | 5f14ae4 | 2018-02-21 15:51:18 +0530 | [diff] [blame] | 323 | pon_reason = pmi632_get_pon_reason(); |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 324 | usb_present_sts = !(USBIN_UV_RT_STS_PMI632 & |
Vijay Kumar Pendoti | 7e9226c | 2016-09-21 20:49:21 +0530 | [diff] [blame] | 325 | pm8x41_reg_read(SMBCHG_USB_RT_STS)); |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 326 | } |
| 327 | else |
| 328 | { |
| 329 | pon_reason = pm8950_get_pon_reason(); |
Umang Agrawal | 5f14ae4 | 2018-02-21 15:51:18 +0530 | [diff] [blame] | 330 | usb_present_sts = !(USBIN_UV_RT_STS & |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 331 | pm8x41_reg_read(SMBCHG_USB_RT_STS)); |
| 332 | } |
| 333 | |
Umang Agrawal | 5f14ae4 | 2018-02-21 15:51:18 +0530 | [diff] [blame] | 334 | if (pm8x41_get_is_cold_boot() && ((pon_reason == KPDPWR_N) || |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 335 | (pon_reason == (KPDPWR_N|PON1)))) |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 336 | return 1; |
Vijay Kumar Pendoti | 7e9226c | 2016-09-21 20:49:21 +0530 | [diff] [blame] | 337 | else if ((pon_reason == PON1) && (!usb_present_sts)) |
| 338 | return 1; |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 339 | else |
| 340 | return 0; |
| 341 | } |
| 342 | |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 343 | static void target_keystatus() |
| 344 | { |
| 345 | keys_init(); |
| 346 | |
| 347 | if(target_volume_down()) |
| 348 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 349 | |
| 350 | if(target_volume_up()) |
| 351 | keys_post_event(KEY_VOLUMEUP, 1); |
| 352 | } |
| 353 | |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 354 | void target_init(void) |
| 355 | { |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 356 | dprintf(INFO, "target_init()\n"); |
| 357 | |
| 358 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 359 | |
| 360 | target_keystatus(); |
| 361 | |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 362 | target_sdc_init(); |
| 363 | if (partition_read_table()) |
| 364 | { |
| 365 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 366 | ASSERT(0); |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 367 | } |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 368 | |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 369 | #if LONG_PRESS_POWER_ON |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 370 | if (target_is_pmi_enabled()) |
| 371 | shutdown_detect(); |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 372 | #endif |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 373 | |
c_wufeng | 41310ae | 2016-01-14 17:59:22 +0800 | [diff] [blame] | 374 | #if PON_VIB_SUPPORT |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 375 | if (target_is_pmi_enabled()) |
| 376 | vib_timed_turn_on(VIBRATE_TIME); |
c_wufeng | 41310ae | 2016-01-14 17:59:22 +0800 | [diff] [blame] | 377 | #endif |
| 378 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 379 | |
| 380 | if (target_use_signed_kernel()) |
| 381 | target_crypto_init_params(); |
| 382 | |
Mayank Grover | 8b2f19a | 2017-10-26 12:12:17 +0530 | [diff] [blame] | 383 | if (VB_M <= target_get_vb_version()) |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 384 | { |
Mayank Grover | 6878e01 | 2017-09-06 11:04:03 +0530 | [diff] [blame] | 385 | clock_ce_enable(CE1_INSTANCE); |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 386 | |
Mayank Grover | 6878e01 | 2017-09-06 11:04:03 +0530 | [diff] [blame] | 387 | /* Initialize Qseecom */ |
| 388 | if (qseecom_init() < 0) |
| 389 | { |
| 390 | dprintf(CRITICAL, "Failed to initialize qseecom\n"); |
| 391 | ASSERT(0); |
| 392 | } |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 393 | |
Mayank Grover | 6878e01 | 2017-09-06 11:04:03 +0530 | [diff] [blame] | 394 | /* Start Qseecom */ |
| 395 | if (qseecom_tz_init() < 0) |
| 396 | { |
| 397 | dprintf(CRITICAL, "Failed to start qseecom\n"); |
| 398 | ASSERT(0); |
| 399 | } |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 400 | |
Mayank Grover | 6878e01 | 2017-09-06 11:04:03 +0530 | [diff] [blame] | 401 | if (rpmb_init() < 0) |
| 402 | { |
| 403 | dprintf(CRITICAL, "RPMB init failed\n"); |
| 404 | ASSERT(0); |
| 405 | } |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 406 | |
Mayank Grover | 6878e01 | 2017-09-06 11:04:03 +0530 | [diff] [blame] | 407 | /* |
| 408 | * Load the sec app for first time |
| 409 | */ |
| 410 | if (load_sec_app() < 0) |
| 411 | { |
| 412 | dprintf(CRITICAL, "Failed to load App for verified\n"); |
| 413 | ASSERT(0); |
| 414 | } |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 415 | } |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 416 | |
| 417 | #if SMD_SUPPORT |
| 418 | rpm_smd_init(); |
| 419 | #endif |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | void target_serialno(unsigned char *buf) |
| 423 | { |
tracychui | d184b91 | 2020-06-05 17:31:38 +0800 | [diff] [blame] | 424 | /*[20200605][TracyChui] Implement get Serial Number start*/ |
| 425 | #if defined(ENABLE_PRODINFO_ACCESS) |
ymlu(180285) | e5289bf | 2020-07-29 14:43:11 +0800 | [diff] [blame^] | 426 | prod_info prod = {PRODINFO_MAGIC, {0}, {0}, 0}; |
tracychui | d184b91 | 2020-06-05 17:31:38 +0800 | [diff] [blame] | 427 | if (target_is_emmc_boot()) { |
| 428 | read_prod_info(&prod); |
| 429 | snprintf((char *)buf, PRODINFO_MAX_SSN_LEN + 1, "%s", prod.ssn); |
| 430 | } |
| 431 | #else |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 432 | uint32_t serialno; |
| 433 | if (target_is_emmc_boot()) { |
| 434 | serialno = mmc_get_psn(); |
| 435 | snprintf((char *)buf, 13, "%x", serialno); |
| 436 | } |
tracychui | d184b91 | 2020-06-05 17:31:38 +0800 | [diff] [blame] | 437 | #endif |
| 438 | /*[20200605][TracyChui] Implement get Serial Number end */ |
| 439 | |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | unsigned board_machtype(void) |
| 443 | { |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 444 | return LINUX_MACHTYPE_UNKNOWN; |
| 445 | } |
| 446 | |
| 447 | /* Detect the target type */ |
| 448 | void target_detect(struct board_data *board) |
| 449 | { |
| 450 | /* This is already filled as part of board.c */ |
| 451 | } |
| 452 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 453 | /* Detect the modem type */ |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 454 | void target_baseband_detect(struct board_data *board) |
| 455 | { |
| 456 | uint32_t platform; |
| 457 | |
| 458 | platform = board->platform; |
| 459 | |
| 460 | switch(platform) { |
Gaurav Nebhwani | 6c945a4 | 2016-02-16 17:26:51 +0530 | [diff] [blame] | 461 | case MSM8953: |
Mayank Grover | 759e0b0 | 2017-04-11 11:59:06 +0530 | [diff] [blame] | 462 | case SDM450: |
lijuang | 2f1c1f5 | 2017-12-12 14:44:32 +0800 | [diff] [blame] | 463 | case SDM632: |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 464 | board->baseband = BASEBAND_MSM; |
| 465 | break; |
Gaurav Nebhwani | 6c945a4 | 2016-02-16 17:26:51 +0530 | [diff] [blame] | 466 | case APQ8053: |
Mayank Grover | 3dc285c | 2017-12-26 12:47:09 +0530 | [diff] [blame] | 467 | case SDA450: |
lijuang | 2f1c1f5 | 2017-12-12 14:44:32 +0800 | [diff] [blame] | 468 | case SDA632: |
Gaurav Nebhwani | 22a0d9f | 2015-12-29 13:49:26 +0530 | [diff] [blame] | 469 | board->baseband = BASEBAND_APQ; |
| 470 | break; |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 471 | default: |
| 472 | dprintf(CRITICAL, "Platform type: %u is not supported\n",platform); |
| 473 | ASSERT(0); |
| 474 | }; |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 475 | } |
| 476 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 477 | unsigned target_baseband() |
| 478 | { |
| 479 | return board_baseband(); |
| 480 | } |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 481 | |
| 482 | int set_download_mode(enum reboot_reason mode) |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 483 | { |
| 484 | int ret = 0; |
| 485 | ret = scm_dload_mode(mode); |
| 486 | |
| 487 | pm8x41_clear_pmic_watchdog(); |
| 488 | |
| 489 | return ret; |
| 490 | } |
| 491 | |
| 492 | int emmc_recovery_init(void) |
| 493 | { |
| 494 | return _emmc_recovery_init(); |
| 495 | } |
| 496 | |
| 497 | unsigned target_pause_for_battery_charge(void) |
| 498 | { |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 499 | uint32_t pmic = target_get_pmic(); |
Umang Agrawal | 5f14ae4 | 2018-02-21 15:51:18 +0530 | [diff] [blame] | 500 | uint8_t pon_reason = pm8x41_get_pon_reason(); |
| 501 | uint8_t is_cold_boot = pm8x41_get_is_cold_boot(); |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 502 | bool usb_present_sts = 1; |
| 503 | |
Umang Agrawal | 5f14ae4 | 2018-02-21 15:51:18 +0530 | [diff] [blame] | 504 | if (target_is_pmi_enabled()) |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 505 | { |
Umang Agrawal | 5f14ae4 | 2018-02-21 15:51:18 +0530 | [diff] [blame] | 506 | if (pmic == PMIC_IS_PMI632) |
| 507 | usb_present_sts = !(USBIN_UV_RT_STS_PMI632 & |
Zhenhua Huang | cf812d7 | 2016-01-27 17:27:47 +0800 | [diff] [blame] | 508 | pm8x41_reg_read(SMBCHG_USB_RT_STS)); |
Umang Agrawal | 5f14ae4 | 2018-02-21 15:51:18 +0530 | [diff] [blame] | 509 | else |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 510 | usb_present_sts = !(USBIN_UV_RT_STS & |
| 511 | pm8x41_reg_read(SMBCHG_USB_RT_STS)); |
| 512 | } |
| 513 | |
Zhenhua Huang | cf812d7 | 2016-01-27 17:27:47 +0800 | [diff] [blame] | 514 | dprintf(INFO, "%s : pon_reason is:0x%x cold_boot:%d usb_sts:%d\n", __func__, |
| 515 | pon_reason, is_cold_boot, usb_present_sts); |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 516 | /* In case of fastboot reboot,adb reboot or if we see the power key |
| 517 | * pressed we do not want go into charger mode. |
| 518 | * fastboot reboot is warm boot with PON hard reset bit not set |
| 519 | * adb reboot is a cold boot with PON hard reset bit set |
| 520 | */ |
| 521 | if (is_cold_boot && |
| 522 | (!(pon_reason & HARD_RST)) && |
| 523 | (!(pon_reason & KPDPWR_N)) && |
Zhenhua Huang | cf812d7 | 2016-01-27 17:27:47 +0800 | [diff] [blame] | 524 | usb_present_sts) |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 525 | return 1; |
| 526 | else |
| 527 | return 0; |
| 528 | } |
| 529 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 530 | void target_uninit(void) |
| 531 | { |
Mayank Grover | 92e5597 | 2018-03-23 17:58:16 +0530 | [diff] [blame] | 532 | #if PON_VIB_SUPPORT |
| 533 | if(target_is_pmi_enabled()) |
| 534 | turn_off_vib_early(); |
| 535 | #endif |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 536 | mmc_put_card_to_sleep(dev); |
| 537 | sdhci_mode_disable(&dev->host); |
| 538 | if (crypto_initialized()) |
| 539 | crypto_eng_cleanup(); |
| 540 | |
| 541 | if (target_is_ssd_enabled()) |
| 542 | clock_ce_disable(CE1_INSTANCE); |
| 543 | |
Mayank Grover | 8b2f19a | 2017-10-26 12:12:17 +0530 | [diff] [blame] | 544 | if (VB_M <= target_get_vb_version()) |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 545 | { |
Mayank Grover | 6878e01 | 2017-09-06 11:04:03 +0530 | [diff] [blame] | 546 | if (is_sec_app_loaded()) |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 547 | { |
Mayank Grover | 6878e01 | 2017-09-06 11:04:03 +0530 | [diff] [blame] | 548 | if (send_milestone_call_to_tz() < 0) |
| 549 | { |
| 550 | dprintf(CRITICAL, "Failed to unload App for rpmb\n"); |
| 551 | ASSERT(0); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | if (rpmb_uninit() < 0) |
| 556 | { |
| 557 | dprintf(CRITICAL, "RPMB uninit failed\n"); |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 558 | ASSERT(0); |
| 559 | } |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 560 | |
Mayank Grover | 6878e01 | 2017-09-06 11:04:03 +0530 | [diff] [blame] | 561 | clock_ce_disable(CE1_INSTANCE); |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 562 | } |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 563 | |
| 564 | #if SMD_SUPPORT |
| 565 | rpm_smd_uninit(); |
| 566 | #endif |
| 567 | } |
| 568 | |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 569 | /* UTMI MUX configuration to connect PHY to SNPS controller: |
| 570 | * Configure primary HS phy mux to use UTMI interface |
| 571 | * (connected to usb30 controller). |
| 572 | */ |
| 573 | static void tcsr_hs_phy_mux_configure(void) |
| 574 | { |
| 575 | uint32_t reg; |
| 576 | |
| 577 | reg = readl(USB2_PHY_SEL); |
| 578 | |
| 579 | writel(reg | 0x1, USB2_PHY_SEL); |
| 580 | } |
| 581 | |
| 582 | /* configure hs phy mux if using dwc controller */ |
| 583 | void target_usb_phy_mux_configure(void) |
| 584 | { |
| 585 | if(!strcmp(target_usb_controller(), "dwc")) |
| 586 | { |
| 587 | tcsr_hs_phy_mux_configure(); |
| 588 | } |
| 589 | } |
| 590 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 591 | void target_usb_phy_reset() |
| 592 | { |
| 593 | |
| 594 | usb30_qmp_phy_reset(); |
| 595 | qusb2_phy_reset(); |
| 596 | } |
| 597 | |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 598 | /* Initialize target specific USB handlers */ |
| 599 | target_usb_iface_t* target_usb30_init() |
| 600 | { |
| 601 | target_usb_iface_t *t_usb_iface; |
| 602 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 603 | t_usb_iface = (target_usb_iface_t *) calloc(1, sizeof(target_usb_iface_t)); |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 604 | ASSERT(t_usb_iface); |
| 605 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 606 | t_usb_iface->mux_config = NULL; |
| 607 | t_usb_iface->phy_init = usb30_qmp_phy_init; |
| 608 | t_usb_iface->phy_reset = target_usb_phy_reset; |
| 609 | t_usb_iface->clock_init = clock_usb30_init; |
| 610 | t_usb_iface->vbus_override = 1; |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 611 | |
| 612 | return t_usb_iface; |
| 613 | } |
| 614 | |
| 615 | /* identify the usb controller to be used for the target */ |
| 616 | const char * target_usb_controller() |
| 617 | { |
| 618 | return "dwc"; |
| 619 | } |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 620 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 621 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 622 | void target_fastboot_init(void) |
| 623 | { |
| 624 | if (target_is_ssd_enabled()) { |
| 625 | clock_ce_enable(CE1_INSTANCE); |
| 626 | target_load_ssd_keystore(); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | void target_load_ssd_keystore(void) |
| 631 | { |
| 632 | uint64_t ptn; |
| 633 | int index; |
| 634 | uint64_t size; |
| 635 | uint32_t *buffer = NULL; |
| 636 | |
| 637 | if (!target_is_ssd_enabled()) |
| 638 | return; |
| 639 | |
| 640 | index = partition_get_index("ssd"); |
| 641 | |
| 642 | ptn = partition_get_offset(index); |
| 643 | if (ptn == 0){ |
| 644 | dprintf(CRITICAL, "Error: ssd partition not found\n"); |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | size = partition_get_size(index); |
| 649 | if (size == 0) { |
| 650 | dprintf(CRITICAL, "Error: invalid ssd partition size\n"); |
| 651 | return; |
| 652 | } |
| 653 | |
| 654 | buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE)); |
| 655 | if (!buffer) { |
| 656 | dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n"); |
| 657 | return; |
| 658 | } |
| 659 | |
| 660 | if (mmc_read(ptn, buffer, size)) { |
| 661 | dprintf(CRITICAL, "Error: cannot read data\n"); |
| 662 | free(buffer); |
| 663 | return; |
| 664 | } |
| 665 | |
| 666 | clock_ce_enable(CE1_INSTANCE); |
| 667 | scm_protect_keystore(buffer, size); |
| 668 | clock_ce_disable(CE1_INSTANCE); |
| 669 | free(buffer); |
| 670 | } |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 671 | |
| 672 | crypto_engine_type board_ce_type(void) |
| 673 | { |
| 674 | return CRYPTO_ENGINE_TYPE_HW; |
| 675 | } |
| 676 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 677 | /* Set up params for h/w CE. */ |
| 678 | void target_crypto_init_params() |
| 679 | { |
| 680 | struct crypto_init_params ce_params; |
| 681 | |
| 682 | /* Set up base addresses and instance. */ |
| 683 | ce_params.crypto_instance = CE1_INSTANCE; |
| 684 | ce_params.crypto_base = MSM_CE1_BASE; |
| 685 | ce_params.bam_base = MSM_CE1_BAM_BASE; |
| 686 | |
| 687 | /* Set up BAM config. */ |
| 688 | ce_params.bam_ee = CE_EE; |
| 689 | ce_params.pipes.read_pipe = CE_READ_PIPE; |
| 690 | ce_params.pipes.write_pipe = CE_WRITE_PIPE; |
| 691 | ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP; |
| 692 | ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP; |
| 693 | |
| 694 | /* Assign buffer sizes. */ |
| 695 | ce_params.num_ce = CE_ARRAY_SIZE; |
| 696 | ce_params.read_fifo_size = CE_FIFO_SIZE; |
| 697 | ce_params.write_fifo_size = CE_FIFO_SIZE; |
| 698 | |
| 699 | /* BAM is initialized by TZ for this platform. |
| 700 | * Do not do it again as the initialization address space |
| 701 | * is locked. |
| 702 | */ |
| 703 | ce_params.do_bam_init = 0; |
| 704 | |
| 705 | crypto_init_params(&ce_params); |
| 706 | } |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 707 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 708 | uint32_t target_get_pmic() |
| 709 | { |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 710 | if (target_is_pmi_enabled()) { |
Umang Agrawal | 3ee3f6f | 2018-04-17 18:54:50 +0530 | [diff] [blame] | 711 | uint32_t pmi_type = board_pmic_target(1) & PMIC_TYPE_MASK; |
Umang Agrawal | abccfc9 | 2017-12-19 12:05:27 +0530 | [diff] [blame] | 712 | if (pmi_type == PMIC_IS_PMI632) |
| 713 | return PMIC_IS_PMI632; |
| 714 | else |
| 715 | return PMIC_IS_PMI8950; |
| 716 | } |
| 717 | else { |
| 718 | return PMIC_IS_UNKNOWN; |
| 719 | } |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 720 | } |
| 721 | |
Umang Agrawal | 89f6dcb | 2018-01-03 19:07:47 +0530 | [diff] [blame] | 722 | void pmic_reset_configure(uint8_t reset_type) |
| 723 | { |
| 724 | uint32_t pmi_type; |
Vamshi Krishna B V | 8275376 | 2018-03-13 18:49:43 +0530 | [diff] [blame] | 725 | uint8_t sec_reset_type = reset_type; |
Umang Agrawal | 89f6dcb | 2018-01-03 19:07:47 +0530 | [diff] [blame] | 726 | |
| 727 | pmi_type = target_get_pmic(); |
| 728 | if (pmi_type == PMIC_IS_PMI632) |
Vamshi Krishna B V | 8275376 | 2018-03-13 18:49:43 +0530 | [diff] [blame] | 729 | { |
Umang Agrawal | 89f6dcb | 2018-01-03 19:07:47 +0530 | [diff] [blame] | 730 | pmi632_reset_configure(reset_type); |
Vamshi Krishna B V | 8275376 | 2018-03-13 18:49:43 +0530 | [diff] [blame] | 731 | } |
Umang Agrawal | 89f6dcb | 2018-01-03 19:07:47 +0530 | [diff] [blame] | 732 | else |
Vamshi Krishna B V | 8275376 | 2018-03-13 18:49:43 +0530 | [diff] [blame] | 733 | { |
| 734 | if (reset_type == PON_PSHOLD_HARD_RESET) |
| 735 | sec_reset_type = PON_PSHOLD_SHUTDOWN; |
| 736 | |
| 737 | pm8996_reset_configure(PRI_PMIC_SLAVE_ID, reset_type); |
| 738 | pm8996_reset_configure(SEC_PMIC_SLAVE_ID, sec_reset_type); |
| 739 | } |
Umang Agrawal | 89f6dcb | 2018-01-03 19:07:47 +0530 | [diff] [blame] | 740 | } |
| 741 | |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 742 | struct qmp_reg qmp_settings[] = |
| 743 | { |
Mayank Grover | e55fe62 | 2016-10-13 18:39:05 +0530 | [diff] [blame] | 744 | {0x804, 0x01}, /* USB3PHY_PCIE_USB3_PCS_POWER_DOWN_CONTROL */ |
| 745 | |
| 746 | /* Common block settings */ |
| 747 | {0xAC, 0x14}, /* QSERDES_COM_SYSCLK_EN_SEL */ |
| 748 | {0x34, 0x08}, /* QSERDES_COM_BIAS_EN_CLKBUFLR_EN */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 749 | {0x174, 0x30}, /* QSERDES_COM_CLK_SELECT */ |
Mayank Grover | e55fe62 | 2016-10-13 18:39:05 +0530 | [diff] [blame] | 750 | {0x70, 0x0F}, /* USB3PHY_QSERDES_COM_BG_TRIM */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 751 | {0x19c, 0x01}, /* QSERDES_COM_SVS_MODE_CLK_SEL */ |
| 752 | {0x178, 0x00}, /* QSERDES_COM_HSCLK_SEL */ |
Mayank Grover | e55fe62 | 2016-10-13 18:39:05 +0530 | [diff] [blame] | 753 | {0x194, 0x06}, /* QSERDES_COM_CMN_CONFIG */ |
| 754 | {0x48, 0x0F}, /* USB3PHY_QSERDES_COM_PLL_IVCO */ |
| 755 | {0x3C, 0x02}, /* QSERDES_COM_SYS_CLK_CTRL */ |
| 756 | |
| 757 | /* PLL & Loop filter settings */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 758 | {0xd0, 0x82}, /* QSERDES_COM_DEC_START_MODE0 */ |
| 759 | {0xdc, 0x55}, /* QSERDES_COM_DIV_FRAC_START1_MODE0 */ |
| 760 | {0xe0, 0x55}, /* QSERDES_COM_DIV_FRAC_START2_MODE0 */ |
| 761 | {0xe4, 0x03}, /* QSERDES_COM_DIV_FRAC_START3_MODE0 */ |
| 762 | {0x78, 0x0b}, /* QSERDES_COM_CP_CTRL_MODE0 */ |
| 763 | {0x84, 0x16}, /* QSERDES_COM_PLL_RCTRL_MODE0 */ |
| 764 | {0x90, 0x28}, /* QSERDES_COM_PLL_CCTRL_MODE0 */ |
| 765 | {0x108, 0x80}, /* QSERDES_COM_INTEGLOOP_GAIN0_MODE0 */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 766 | {0x4c, 0x15}, /* QSERDES_COM_LOCK_CMP1_MODE0 */ |
| 767 | {0x50, 0x34}, /* QSERDES_COM_LOCK_CMP2_MODE0 */ |
| 768 | {0x54, 0x00}, /* QSERDES_COM_LOCK_CMP3_MODE0 */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 769 | {0x18c, 0x00}, /* QSERDES_COM_CORE_CLK_EN */ |
| 770 | {0xcc, 0x00}, /* QSERDES_COM_LOCK_CMP_CFG */ |
| 771 | {0x128, 0x00}, /* QSERDES_COM_VCO_TUNE_MAP */ |
| 772 | {0x0C, 0x0A}, /* QSERDES_COM_BG_TIMER */ |
Mayank Grover | e55fe62 | 2016-10-13 18:39:05 +0530 | [diff] [blame] | 773 | |
| 774 | /* SSC Settings */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 775 | {0x10, 0x01}, /* QSERDES_COM_SSC_EN_CENTER */ |
| 776 | {0x1c, 0x31}, /* QSERDES_COM_SSC_PER1 */ |
| 777 | {0x20, 0x01}, /* QSERDES_COM_SSC_PER2 */ |
| 778 | {0x14, 0x00}, /* QSERDES_COM_SSC_ADJ_PER1 */ |
| 779 | {0x18, 0x00}, /* QSERDES_COM_SSC_ADJ_PER2 */ |
| 780 | {0x24, 0xde}, /* QSERDES_COM_SSC_STEP_SIZE1 */ |
| 781 | {0x28, 0x07}, /* QSERDES_COM_SSC_STEP_SIZE2 */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 782 | |
| 783 | /* Rx Settings */ |
Mayank Grover | e55fe62 | 2016-10-13 18:39:05 +0530 | [diff] [blame] | 784 | {0x41C, 0x06}, /* QSERDES_RX_UCDR_SO_GAIN */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 785 | {0x4d8, 0x02}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2 */ |
Mayank Grover | e55fe62 | 2016-10-13 18:39:05 +0530 | [diff] [blame] | 786 | {0x4dc, 0x4c}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3 */ |
| 787 | {0x4e0, 0xb8}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4 */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 788 | {0x508, 0x77}, /* QSERDES_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1 */ |
| 789 | {0x50c, 0x80}, /* QSERDES_RX_RX_OFFSET_ADAPTOR_CNTRL2 */ |
| 790 | {0x514, 0x03}, /* QSERDES_RX_SIGDET_CNTRL */ |
| 791 | {0x51c, 0x16}, /* QSERDES_RX_SIGDET_DEGLITCH_CNTRL */ |
Mayank Grover | e55fe62 | 2016-10-13 18:39:05 +0530 | [diff] [blame] | 792 | {0x510, 0x0C}, /* QSERDES_RX_SIGDET_ENABLES */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 793 | |
| 794 | /* Tx settings */ |
| 795 | {0x268, 0x45}, /* QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN */ |
| 796 | {0x2ac, 0x12}, /* QSERDES_TX_RCV_DETECT_LVL_2 */ |
| 797 | {0x294, 0x06}, /* QSERDES_TX_LANE_MODE */ |
Mayank Grover | e55fe62 | 2016-10-13 18:39:05 +0530 | [diff] [blame] | 798 | {0x824, 0x15}, /* PCIE_USB3_PCS_TXDEEMPH_M6DB_V0 */ |
| 799 | {0x828, 0x0E}, /* PCIE_USB3_PCS_TXDEEMPH_M3P5DB_V0 */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 800 | |
| 801 | /* FLL settings */ |
| 802 | {0x8c8, 0x83}, /* PCIE_USB3_PCS_FLL_CNTRL2 */ |
| 803 | {0x8c4, 0x02}, /* PCIE_USB3_PCS_FLL_CNTRL1 */ |
| 804 | {0x8cc, 0x09}, /* PCIE_USB3_PCS_FLL_CNT_VAL_L */ |
| 805 | {0x8D0, 0xA2}, /* PCIE_USB3_PCS_FLL_CNT_VAL_H_TOL */ |
| 806 | {0x8D4, 0x85}, /* PCIE_USB3_PCS_FLL_MAN_CODE */ |
| 807 | |
| 808 | /* PCS Settings */ |
| 809 | {0x880, 0xD1}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG1 */ |
| 810 | {0x884, 0x1F}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG2 */ |
| 811 | {0x888, 0x47}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG3 */ |
Mayank Grover | e55fe62 | 2016-10-13 18:39:05 +0530 | [diff] [blame] | 812 | {0x864, 0x1B}, /* PCIE_USB3_PCS_POWER_STATE_CONFIG2 */ |
P.V. Phani Kumar | 77826d3 | 2015-12-26 20:56:35 +0530 | [diff] [blame] | 813 | {0x8B8, 0x75}, /* PCIE_USB3_PCS_RXEQTRAINING_WAIT_TIME */ |
| 814 | {0x8BC, 0x13}, /* PCIE_USB3_PCS_RXEQTRAINING_RUN_TIME */ |
| 815 | {0x8B0, 0x86}, /* PCIE_USB3_PCS_LFPS_TX_ECSTART_EQTLOCK */ |
| 816 | {0x8A0, 0x04}, /* PCIE_USB3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK */ |
| 817 | {0x88C, 0x44}, /* PCIE_USB3_PCS_TSYNC_RSYNC_TIME */ |
| 818 | {0x870, 0xE7}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_P1U2_L */ |
| 819 | {0x874, 0x03}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_P1U2_H */ |
| 820 | {0x878, 0x40}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_U3_L */ |
| 821 | {0x87c, 0x00}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_U3_H */ |
| 822 | {0x9D8, 0x88}, /* PCIE_USB3_PCS_RX_SIGDET_LVL */ |
| 823 | {0x808, 0x03}, /* PCIE_USB3_PCS_START_CONTROL */ |
| 824 | {0x800, 0x00}, /* PCIE_USB3_PCS_SW_RESET */ |
| 825 | }; |
| 826 | |
| 827 | struct qmp_reg *target_get_qmp_settings() |
| 828 | { |
| 829 | return qmp_settings; |
| 830 | } |
| 831 | |
| 832 | int target_get_qmp_regsize() |
| 833 | { |
| 834 | return ARRAY_SIZE(qmp_settings); |
| 835 | } |
Padmanabhan Komanduru | 0104a89 | 2016-01-22 16:58:10 +0530 | [diff] [blame] | 836 | static uint8_t splash_override; |
| 837 | /* Returns 1 if target supports continuous splash screen. */ |
| 838 | int target_cont_splash_screen() |
| 839 | { |
| 840 | uint8_t splash_screen = 0; |
| 841 | if (!splash_override) { |
| 842 | switch (board_hardware_id()) { |
| 843 | case HW_PLATFORM_MTP: |
| 844 | case HW_PLATFORM_SURF: |
| 845 | case HW_PLATFORM_RCM: |
| 846 | case HW_PLATFORM_QRD: |
| 847 | splash_screen = 1; |
| 848 | break; |
| 849 | default: |
| 850 | splash_screen = 0; |
| 851 | break; |
| 852 | } |
| 853 | dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen); |
| 854 | } |
| 855 | return splash_screen; |
| 856 | } |
| 857 | |
| 858 | void target_force_cont_splash_disable(uint8_t override) |
| 859 | { |
| 860 | splash_override = override; |
| 861 | } |