Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2014, The Linux Foundation. All rights reserved. |
| 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> |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 52 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 53 | #if LONG_PRESS_POWER_ON |
| 54 | #include <shutdown_detect.h> |
| 55 | #endif |
| 56 | |
| 57 | #if PON_VIB_SUPPORT |
| 58 | #include <vibrator.h> |
| 59 | #endif |
| 60 | |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 61 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 62 | #define PMIC_ARB_OWNER_ID 0 |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 63 | #define TLMM_VOL_UP_BTN_GPIO 90 |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 64 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 65 | #if PON_VIB_SUPPORT |
| 66 | #define VIBRATE_TIME 250 |
| 67 | #endif |
| 68 | |
| 69 | #define FASTBOOT_MODE 0x77665500 |
| 70 | |
| 71 | #define CE1_INSTANCE 1 |
| 72 | #define CE_EE 1 |
| 73 | #define CE_FIFO_SIZE 64 |
| 74 | #define CE_READ_PIPE 3 |
| 75 | #define CE_WRITE_PIPE 2 |
| 76 | #define CE_READ_PIPE_LOCK_GRP 0 |
| 77 | #define CE_WRITE_PIPE_LOCK_GRP 0 |
| 78 | #define CE_ARRAY_SIZE 20 |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 79 | |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 80 | extern void smem_ptable_init(void); |
| 81 | extern void smem_add_modem_partitions(struct ptable *flash_ptable); |
| 82 | void target_sdc_init(); |
| 83 | |
| 84 | static struct ptable flash_ptable; |
| 85 | |
| 86 | /* NANDc BAM pipe numbers */ |
| 87 | #define DATA_CONSUMER_PIPE 0 |
| 88 | #define DATA_PRODUCER_PIPE 1 |
| 89 | #define CMD_PIPE 2 |
| 90 | |
| 91 | /* NANDc BAM pipe groups */ |
| 92 | #define DATA_PRODUCER_PIPE_GRP 0 |
| 93 | #define DATA_CONSUMER_PIPE_GRP 0 |
| 94 | #define CMD_PIPE_GRP 1 |
| 95 | |
| 96 | /* NANDc EE */ |
| 97 | #define QPIC_NAND_EE 0 |
| 98 | |
| 99 | /* NANDc max desc length. */ |
| 100 | #define QPIC_NAND_MAX_DESC_LEN 0x7FFF |
| 101 | |
| 102 | #define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF |
| 103 | |
| 104 | struct qpic_nand_init_config config; |
| 105 | |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 106 | struct mmc_device *dev; |
| 107 | |
| 108 | static uint32_t mmc_pwrctl_base[] = |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 109 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 110 | |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 111 | static uint32_t mmc_sdhci_base[] = |
| 112 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE }; |
| 113 | |
| 114 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 115 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ }; |
| 116 | |
| 117 | static void set_sdc_power_ctrl(void); |
Aparna Mallavarapu | 5f80cbf | 2014-10-13 11:10:22 -0700 | [diff] [blame^] | 118 | static void set_ebi2_config(void); |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 119 | |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 120 | void update_ptable_names(void) |
| 121 | { |
| 122 | uint32_t ptn_index; |
| 123 | struct ptentry *ptentry_ptr = flash_ptable.parts; |
| 124 | struct ptentry *boot_ptn; |
| 125 | unsigned i; |
| 126 | uint32_t len; |
| 127 | |
| 128 | /* Change all names to lower case. */ |
| 129 | for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++) |
| 130 | { |
| 131 | len = strlen(ptentry_ptr[ptn_index].name); |
| 132 | |
| 133 | for (i = 0; i < len; i++) |
| 134 | { |
| 135 | if (isupper(ptentry_ptr[ptn_index].name[i])) |
| 136 | { |
| 137 | ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /* SBL fills in the last partition length as 0xFFFFFFFF. |
| 142 | * Update the length field based on the number of blocks on the flash. |
| 143 | */ |
| 144 | if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN) |
| 145 | { |
| 146 | ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start; |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 151 | void target_early_init(void) |
| 152 | { |
| 153 | #if WITH_DEBUG_UART |
Unnati Gandhi | 67adfe1 | 2014-09-30 13:14:22 +0530 | [diff] [blame] | 154 | uart_dm_init(1, 0, BLSP1_UART0_BASE); |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 155 | #endif |
| 156 | } |
| 157 | |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 158 | int target_is_emmc_boot(void) |
| 159 | { |
| 160 | return platform_boot_dev_isemmc(); |
| 161 | } |
| 162 | |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 163 | void target_sdc_init() |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 164 | { |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 165 | struct mmc_config_data config; |
| 166 | |
| 167 | /* Set drive strength & pull ctrl values */ |
| 168 | set_sdc_power_ctrl(); |
| 169 | |
| 170 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 171 | config.max_clk_rate = MMC_CLK_177MHZ; |
| 172 | |
| 173 | /* Try slot 1*/ |
| 174 | config.slot = 1; |
| 175 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 176 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 177 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 178 | config.hs400_support = 0; |
| 179 | |
| 180 | if (!(dev = mmc_init(&config))) { |
| 181 | /* Try slot 2 */ |
| 182 | config.slot = 2; |
| 183 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 184 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 185 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 186 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 187 | |
| 188 | if (!(dev = mmc_init(&config))) { |
| 189 | dprintf(CRITICAL, "mmc init failed!"); |
| 190 | ASSERT(0); |
| 191 | } |
| 192 | } |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 193 | } |
| 194 | |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 195 | void *target_mmc_device() |
| 196 | { |
| 197 | return (void *) dev; |
| 198 | } |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 199 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 200 | /* Return 1 if vol_up pressed */ |
| 201 | static int target_volume_up() |
| 202 | { |
| 203 | uint8_t status = 0; |
| 204 | |
| 205 | gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE); |
| 206 | |
| 207 | /* Wait for the gpio config to take effect - debounce time */ |
| 208 | thread_sleep(10); |
| 209 | |
| 210 | /* Get status of GPIO */ |
| 211 | status = gpio_status(TLMM_VOL_UP_BTN_GPIO); |
| 212 | |
| 213 | /* Active low signal. */ |
| 214 | return !status; |
| 215 | } |
| 216 | |
| 217 | /* Return 1 if vol_down pressed */ |
| 218 | uint32_t target_volume_down() |
| 219 | { |
| 220 | /* Volume down button tied in with PMIC RESIN. */ |
| 221 | return pm8x41_resin_status(); |
| 222 | } |
| 223 | |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 224 | static void target_keystatus() |
| 225 | { |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 226 | keys_init(); |
| 227 | |
| 228 | if(target_volume_down()) |
| 229 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 230 | |
| 231 | if(target_volume_up()) |
| 232 | keys_post_event(KEY_VOLUMEUP, 1); |
| 233 | |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 234 | } |
| 235 | |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 236 | static void set_sdc_power_ctrl() |
| 237 | { |
| 238 | /* Drive strength configs for sdc pins */ |
| 239 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 240 | { |
Aparna Mallavarapu | 5f80cbf | 2014-10-13 11:10:22 -0700 | [diff] [blame^] | 241 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL }, |
| 242 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL }, |
| 243 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL }, |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | /* Pull configs for sdc pins */ |
| 247 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 248 | { |
Aparna Mallavarapu | 5f80cbf | 2014-10-13 11:10:22 -0700 | [diff] [blame^] | 249 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL }, |
| 250 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL }, |
| 251 | { 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] | 252 | }; |
| 253 | |
| 254 | /* Set the drive strength & pull control values */ |
| 255 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 256 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 257 | } |
| 258 | |
Aparna Mallavarapu | 5f80cbf | 2014-10-13 11:10:22 -0700 | [diff] [blame^] | 259 | static void set_ebi2_config() |
| 260 | { |
| 261 | /* Drive strength configs for ebi2 pins */ |
| 262 | struct tlmm_cfgs ebi2_hdrv_cfg[] = |
| 263 | { |
| 264 | { EBI2_BUSY_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 265 | { EBI2_WE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 266 | { EBI2_OE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 267 | { EBI2_CLE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 268 | { EBI2_ALE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 269 | { EBI2_CS_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 270 | { EBI2_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL }, |
| 271 | }; |
| 272 | |
| 273 | /* Pull configs for ebi2 pins */ |
| 274 | struct tlmm_cfgs ebi2_pull_cfg[] = |
| 275 | { |
| 276 | { EBI2_BUSY_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 277 | { EBI2_WE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 278 | { EBI2_OE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 279 | { EBI2_CLE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 280 | { EBI2_ALE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 281 | { EBI2_CS_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG }, |
| 282 | { EBI2_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL }, |
| 283 | }; |
| 284 | |
| 285 | /* Set the drive strength & pull control values */ |
| 286 | tlmm_set_hdrive_ctrl(ebi2_hdrv_cfg, ARRAY_SIZE(ebi2_hdrv_cfg)); |
| 287 | tlmm_set_pull_ctrl(ebi2_pull_cfg, ARRAY_SIZE(ebi2_pull_cfg)); |
| 288 | |
| 289 | } |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 290 | void target_init(void) |
| 291 | { |
| 292 | uint32_t base_addr; |
| 293 | uint8_t slot; |
| 294 | |
| 295 | dprintf(INFO, "target_init()\n"); |
| 296 | |
| 297 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 298 | |
| 299 | target_keystatus(); |
| 300 | |
Unnati Gandhi | 8e4711b | 2014-10-13 05:03:00 +0530 | [diff] [blame] | 301 | #if ENABLE_BOOT_CONFIG_SUPPORT |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 302 | platform_read_boot_config(); |
Unnati Gandhi | 8e4711b | 2014-10-13 05:03:00 +0530 | [diff] [blame] | 303 | #endif |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 304 | |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 305 | if (platform_boot_dev_isemmc()) { |
| 306 | target_sdc_init(); |
| 307 | if (partition_read_table()) |
| 308 | { |
| 309 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 310 | ASSERT(0); |
| 311 | } |
| 312 | |
| 313 | } else { |
Aparna Mallavarapu | 5f80cbf | 2014-10-13 11:10:22 -0700 | [diff] [blame^] | 314 | set_ebi2_config(); |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 315 | config.pipes.read_pipe = DATA_PRODUCER_PIPE; |
| 316 | config.pipes.write_pipe = DATA_CONSUMER_PIPE; |
| 317 | config.pipes.cmd_pipe = CMD_PIPE; |
| 318 | |
| 319 | config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP; |
| 320 | config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP; |
| 321 | config.pipes.cmd_pipe_grp = CMD_PIPE_GRP; |
| 322 | |
| 323 | config.bam_base = MSM_NAND_BAM_BASE; |
| 324 | config.nand_base = MSM_NAND_BASE; |
| 325 | config.ee = QPIC_NAND_EE; |
| 326 | config.max_desc_len = QPIC_NAND_MAX_DESC_LEN; |
| 327 | |
| 328 | qpic_nand_init(&config); |
| 329 | |
| 330 | ptable_init(&flash_ptable); |
| 331 | smem_ptable_init(); |
| 332 | smem_add_modem_partitions(&flash_ptable); |
| 333 | |
| 334 | update_ptable_names(); |
| 335 | flash_set_ptable(&flash_ptable); |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 336 | } |
Unnati Gandhi | 4d637e4 | 2014-07-11 14:47:25 +0530 | [diff] [blame] | 337 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 338 | #if LONG_PRESS_POWER_ON |
| 339 | shutdown_detect(); |
| 340 | #endif |
| 341 | |
| 342 | #if PON_VIB_SUPPORT |
| 343 | |
| 344 | /* turn on vibrator to indicate that phone is booting up to end user */ |
| 345 | vib_timed_turn_on(VIBRATE_TIME); |
| 346 | #endif |
| 347 | |
| 348 | if (target_use_signed_kernel()) |
| 349 | target_crypto_init_params(); |
Unnati Gandhi | c24a86f | 2014-09-19 16:07:16 +0530 | [diff] [blame] | 350 | |
Aparna Mallavarapu | 96fe9d9 | 2014-10-19 12:48:01 -0700 | [diff] [blame] | 351 | #if ENABLE_SMD_SUPPORT |
Unnati Gandhi | c24a86f | 2014-09-19 16:07:16 +0530 | [diff] [blame] | 352 | rpm_smd_init(); |
Aparna Mallavarapu | 96fe9d9 | 2014-10-19 12:48:01 -0700 | [diff] [blame] | 353 | #endif |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | void target_serialno(unsigned char *buf) |
| 357 | { |
| 358 | uint32_t serialno; |
| 359 | if (target_is_emmc_boot()) { |
| 360 | serialno = mmc_get_psn(); |
| 361 | snprintf((char *)buf, 13, "%x", serialno); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | unsigned board_machtype(void) |
| 366 | { |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 367 | return LINUX_MACHTYPE_UNKNOWN; |
| 368 | } |
| 369 | |
| 370 | unsigned check_reboot_mode(void) |
| 371 | { |
| 372 | uint32_t restart_reason = 0; |
| 373 | |
| 374 | /* Read reboot reason and scrub it */ |
| 375 | restart_reason = readl(RESTART_REASON_ADDR); |
| 376 | writel(0x00, RESTART_REASON_ADDR); |
| 377 | |
| 378 | return restart_reason; |
| 379 | } |
| 380 | |
| 381 | static int scm_dload_mode(int mode) |
| 382 | { |
| 383 | int ret = 0; |
| 384 | uint32_t dload_type; |
| 385 | |
| 386 | dprintf(SPEW, "DLOAD mode: %d\n", mode); |
| 387 | if (mode == NORMAL_DLOAD) |
| 388 | dload_type = SCM_DLOAD_MODE; |
| 389 | else if(mode == EMERGENCY_DLOAD) |
| 390 | dload_type = SCM_EDLOAD_MODE; |
| 391 | else |
| 392 | dload_type = 0; |
| 393 | |
| 394 | ret = scm_call_atomic2(SCM_SVC_BOOT, SCM_DLOAD_CMD, dload_type, 0); |
| 395 | if (ret) |
| 396 | dprintf(CRITICAL, "Failed to write to boot misc: %d\n", ret); |
| 397 | |
| 398 | ret = scm_call_atomic2(SCM_SVC_BOOT, WDOG_DEBUG_DISABLE, 1, 0); |
| 399 | if (ret) |
| 400 | dprintf(CRITICAL, "Failed to disable the wdog debug \n"); |
| 401 | |
| 402 | return ret; |
| 403 | } |
| 404 | |
| 405 | /* Configure PMIC and Drop PS_HOLD for shutdown */ |
| 406 | void shutdown_device() |
| 407 | { |
| 408 | dprintf(CRITICAL, "Going down for shutdown.\n"); |
| 409 | |
| 410 | /* Configure PMIC for shutdown */ |
| 411 | pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN); |
| 412 | |
| 413 | /* Drop PS_HOLD for MSM */ |
| 414 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 415 | |
| 416 | mdelay(5000); |
| 417 | |
| 418 | } |
| 419 | |
| 420 | void reboot_device(unsigned reboot_reason) |
| 421 | { |
| 422 | uint8_t reset_type = 0; |
| 423 | uint32_t ret = 0; |
| 424 | |
| 425 | /* Need to clear the SW_RESET_ENTRY register and |
| 426 | * write to the BOOT_MISC_REG for known reset cases |
| 427 | */ |
| 428 | if(reboot_reason != DLOAD) |
| 429 | scm_dload_mode(NORMAL_MODE); |
| 430 | |
| 431 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 432 | |
| 433 | /* For Reboot-bootloader and Dload cases do a warm reset |
| 434 | * For Reboot cases do a hard reset |
| 435 | */ |
| 436 | if((reboot_reason == FASTBOOT_MODE) || (reboot_reason == DLOAD)) |
| 437 | reset_type = PON_PSHOLD_WARM_RESET; |
| 438 | else |
| 439 | reset_type = PON_PSHOLD_HARD_RESET; |
| 440 | |
| 441 | pm8x41_reset_configure(reset_type); |
| 442 | |
| 443 | ret = scm_halt_pmic_arbiter(); |
| 444 | |
| 445 | if (ret) |
| 446 | dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret); |
| 447 | |
| 448 | /* Drop PS_HOLD for MSM */ |
| 449 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 450 | |
| 451 | mdelay(5000); |
| 452 | |
| 453 | dprintf(CRITICAL, "Rebooting failed\n"); |
Unnati Gandhi | 4d07fac | 2014-07-04 17:38:25 +0530 | [diff] [blame] | 454 | } |
| 455 | |
Unnati Gandhi | a556a4d | 2014-08-12 10:42:21 +0530 | [diff] [blame] | 456 | /* Detect the target type */ |
| 457 | void target_detect(struct board_data *board) |
| 458 | { |
| 459 | /* |
| 460 | * already fill the board->target on board.c |
| 461 | */ |
| 462 | } |
| 463 | |
| 464 | void target_baseband_detect(struct board_data *board) |
| 465 | { |
| 466 | uint32_t platform; |
| 467 | |
| 468 | platform = board->platform; |
| 469 | switch(platform) |
| 470 | { |
| 471 | case MSM8909: |
| 472 | case MSM8209: |
| 473 | case MSM8208: |
| 474 | board->baseband = BASEBAND_MSM; |
| 475 | break; |
| 476 | |
| 477 | case MDM9209: |
| 478 | case MDM9309: |
| 479 | case MDM9609: |
| 480 | board->baseband = BASEBAND_MDM; |
| 481 | break; |
| 482 | |
| 483 | default: |
| 484 | dprintf(CRITICAL, "Platform type: %u is not supported\n", platform); |
| 485 | ASSERT(0); |
| 486 | }; |
| 487 | } |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 488 | uint8_t target_panel_auto_detect_enabled() |
| 489 | { |
| 490 | uint8_t ret = 0; |
| 491 | |
| 492 | switch(board_hardware_id()) { |
| 493 | default: |
| 494 | ret = 0; |
| 495 | break; |
| 496 | } |
| 497 | return ret; |
| 498 | } |
| 499 | |
| 500 | static uint8_t splash_override; |
| 501 | /* Returns 1 if target supports continuous splash screen. */ |
| 502 | int target_cont_splash_screen() |
| 503 | { |
| 504 | uint8_t splash_screen = 0; |
| 505 | if (!splash_override) { |
| 506 | switch (board_hardware_id()) { |
| 507 | default: |
| 508 | splash_screen = 0; |
| 509 | break; |
| 510 | } |
| 511 | dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen); |
| 512 | } |
| 513 | return splash_screen; |
| 514 | } |
| 515 | |
| 516 | void target_force_cont_splash_disable(uint8_t override) |
| 517 | { |
| 518 | splash_override = override; |
| 519 | } |
Unnati Gandhi | a556a4d | 2014-08-12 10:42:21 +0530 | [diff] [blame] | 520 | |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 521 | int get_target_boot_params(const char *cmdline, const char *part, char *buf, |
| 522 | int buflen) |
| 523 | { |
| 524 | struct ptable *ptable; |
| 525 | int system_ptn_index = -1; |
| 526 | |
| 527 | if (!target_is_emmc_boot()) { |
| 528 | if (!cmdline || !part || !buf || buflen < 0) { |
| 529 | dprintf(CRITICAL, "WARN: Invalid input param\n"); |
| 530 | return -1; |
| 531 | } |
| 532 | |
| 533 | ptable = flash_get_ptable(); |
| 534 | if (!ptable) { |
| 535 | dprintf(CRITICAL, |
| 536 | "WARN: Cannot get flash partition table\n"); |
| 537 | return -1; |
| 538 | } |
| 539 | |
| 540 | system_ptn_index = ptable_get_index(ptable, part); |
| 541 | if (system_ptn_index < 0) { |
| 542 | dprintf(CRITICAL, |
| 543 | "WARN: Cannot get partition index for %s\n", part); |
| 544 | return -1; |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * check if cmdline contains "root=" at the beginning of buffer or |
| 549 | * " root=" in the middle of buffer. |
| 550 | */ |
| 551 | if (((!strncmp(cmdline, "root=", strlen("root="))) || |
| 552 | (strstr(cmdline, " root=")))) |
| 553 | dprintf(DEBUG, "DEBUG: cmdline has root=\n"); |
| 554 | else |
| 555 | snprintf(buf, buflen, " root=/dev/mtdblock%d", |
| 556 | system_ptn_index); |
| 557 | } |
| 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 562 | unsigned target_baseband() |
| 563 | { |
| 564 | return board_baseband(); |
| 565 | } |
| 566 | |
| 567 | int emmc_recovery_init(void) |
| 568 | { |
| 569 | return _emmc_recovery_init(); |
| 570 | } |
| 571 | |
| 572 | void target_usb_init(void) |
| 573 | { |
| 574 | uint32_t val; |
| 575 | |
| 576 | /* Select and enable external configuration with USB PHY */ |
| 577 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 578 | |
| 579 | /* Enable sess_vld */ |
| 580 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 581 | writel(val, USB_GENCONFIG_2); |
| 582 | |
| 583 | /* Enable external vbus configuration in the LINK */ |
| 584 | val = readl(USB_USBCMD); |
| 585 | val |= SESS_VLD_CTRL; |
| 586 | writel(val, USB_USBCMD); |
| 587 | } |
| 588 | |
| 589 | unsigned target_pause_for_battery_charge(void) |
| 590 | { |
| 591 | uint8_t pon_reason = pm8x41_get_pon_reason(); |
| 592 | uint8_t is_cold_boot = pm8x41_get_is_cold_boot(); |
| 593 | dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__, |
| 594 | pon_reason, is_cold_boot); |
| 595 | /* In case of fastboot reboot,adb reboot or if we see the power key |
| 596 | * pressed we do not want go into charger mode. |
| 597 | * fastboot reboot is warm boot with PON hard reset bit not set |
| 598 | * adb reboot is a cold boot with PON hard reset bit set |
| 599 | */ |
| 600 | if (is_cold_boot && |
| 601 | (!(pon_reason & HARD_RST)) && |
| 602 | (!(pon_reason & KPDPWR_N)) && |
| 603 | ((pon_reason & USB_CHG) || (pon_reason & DC_CHG))) |
| 604 | return 1; |
| 605 | else |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | void target_usb_stop(void) |
| 610 | { |
| 611 | /* Disable VBUS mimicing in the controller. */ |
| 612 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR); |
| 613 | } |
| 614 | |
| 615 | |
| 616 | void target_uninit(void) |
| 617 | { |
| 618 | #if PON_VIB_SUPPORT |
| 619 | /* wait for the vibrator timer is expried */ |
| 620 | wait_vib_timeout(); |
| 621 | #endif |
| 622 | |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 623 | if (platform_boot_dev_isemmc()) |
| 624 | { |
| 625 | mmc_put_card_to_sleep(dev); |
| 626 | sdhci_mode_disable(&dev->host); |
| 627 | } |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 628 | |
| 629 | if (crypto_initialized()) |
| 630 | crypto_eng_cleanup(); |
| 631 | |
| 632 | if (target_is_ssd_enabled()) |
| 633 | clock_ce_disable(CE1_INSTANCE); |
Unnati Gandhi | c24a86f | 2014-09-19 16:07:16 +0530 | [diff] [blame] | 634 | |
Aparna Mallavarapu | 96fe9d9 | 2014-10-19 12:48:01 -0700 | [diff] [blame] | 635 | #if ENABLE_SMD_SUPPORT |
Unnati Gandhi | c24a86f | 2014-09-19 16:07:16 +0530 | [diff] [blame] | 636 | rpm_smd_uninit(); |
Aparna Mallavarapu | 96fe9d9 | 2014-10-19 12:48:01 -0700 | [diff] [blame] | 637 | #endif |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 641 | void target_fastboot_init(void) |
| 642 | { |
| 643 | /* Set the BOOT_DONE flag in PM8916 */ |
| 644 | pm8x41_set_boot_done(); |
| 645 | |
| 646 | if (target_is_ssd_enabled()) { |
| 647 | clock_ce_enable(CE1_INSTANCE); |
| 648 | target_load_ssd_keystore(); |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | int set_download_mode(enum dload_mode mode) |
| 653 | { |
| 654 | int ret = 0; |
| 655 | ret = scm_dload_mode(mode); |
| 656 | |
| 657 | pm8x41_clear_pmic_watchdog(); |
| 658 | |
| 659 | return ret; |
| 660 | } |
| 661 | |
| 662 | void target_load_ssd_keystore(void) |
| 663 | { |
| 664 | uint64_t ptn; |
| 665 | int index; |
| 666 | uint64_t size; |
| 667 | uint32_t *buffer = NULL; |
| 668 | |
| 669 | if (!target_is_ssd_enabled()) |
| 670 | return; |
| 671 | |
| 672 | index = partition_get_index("ssd"); |
| 673 | |
| 674 | ptn = partition_get_offset(index); |
| 675 | if (ptn == 0){ |
| 676 | dprintf(CRITICAL, "Error: ssd partition not found\n"); |
| 677 | return; |
| 678 | } |
| 679 | |
| 680 | size = partition_get_size(index); |
| 681 | if (size == 0) { |
| 682 | dprintf(CRITICAL, "Error: invalid ssd partition size\n"); |
| 683 | return; |
| 684 | } |
| 685 | |
| 686 | buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE)); |
| 687 | if (!buffer) { |
| 688 | dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n"); |
| 689 | return; |
| 690 | } |
| 691 | if (mmc_read(ptn, buffer, size)) { |
| 692 | dprintf(CRITICAL, "Error: cannot read data\n"); |
| 693 | free(buffer); |
| 694 | return; |
| 695 | } |
| 696 | |
| 697 | clock_ce_enable(CE1_INSTANCE); |
| 698 | scm_protect_keystore(buffer, size); |
| 699 | clock_ce_disable(CE1_INSTANCE); |
| 700 | free(buffer); |
| 701 | } |
| 702 | |
| 703 | crypto_engine_type board_ce_type(void) |
| 704 | { |
| 705 | return CRYPTO_ENGINE_TYPE_HW; |
| 706 | } |
| 707 | |
| 708 | /* Set up params for h/w CE. */ |
| 709 | void target_crypto_init_params() |
| 710 | { |
| 711 | struct crypto_init_params ce_params; |
| 712 | |
| 713 | /* Set up base addresses and instance. */ |
| 714 | ce_params.crypto_instance = CE1_INSTANCE; |
| 715 | ce_params.crypto_base = MSM_CE1_BASE; |
| 716 | ce_params.bam_base = MSM_CE1_BAM_BASE; |
| 717 | |
| 718 | /* Set up BAM config. */ |
| 719 | ce_params.bam_ee = CE_EE; |
| 720 | ce_params.pipes.read_pipe = CE_READ_PIPE; |
| 721 | ce_params.pipes.write_pipe = CE_WRITE_PIPE; |
| 722 | ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP; |
| 723 | ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP; |
| 724 | |
| 725 | /* Assign buffer sizes. */ |
| 726 | ce_params.num_ce = CE_ARRAY_SIZE; |
| 727 | ce_params.read_fifo_size = CE_FIFO_SIZE; |
| 728 | ce_params.write_fifo_size = CE_FIFO_SIZE; |
| 729 | |
| 730 | /* BAM is initialized by TZ for this platform. |
| 731 | * Do not do it again as the initialization address space |
| 732 | * is locked. |
| 733 | */ |
| 734 | ce_params.do_bam_init = 0; |
| 735 | |
| 736 | crypto_init_params(&ce_params); |
| 737 | } |
| 738 | |
| 739 | uint32_t target_get_hlos_subtype() |
| 740 | { |
| 741 | return board_hlos_subtype(); |
| 742 | } |