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