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