lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2014, 2016, The Linux Foundation. All rights reserved. |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [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> |
Channagoud Kadabi | f6f7174 | 2013-05-23 14:05:05 -0700 | [diff] [blame] | 31 | #include <platform/irqs.h> |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 32 | #include <reg.h> |
| 33 | #include <target.h> |
| 34 | #include <platform.h> |
Pavel Nedev | 16f4923 | 2013-04-29 16:15:36 +0300 | [diff] [blame] | 35 | #include <dload_util.h> |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 36 | #include <uart_dm.h> |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 37 | #include <mmc_sdhci.h> |
Stanimir Varbanov | f0650ca | 2013-07-01 12:30:24 +0300 | [diff] [blame] | 38 | #include <platform/clock.h> |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 39 | #include <platform/gpio.h> |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 40 | #include <spmi.h> |
| 41 | #include <board.h> |
Deepa Dinamani | ff2b9ce | 2013-02-25 11:01:00 -0800 | [diff] [blame] | 42 | #include <smem.h> |
| 43 | #include <baseband.h> |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 44 | #include <dev/keys.h> |
Deepa Dinamani | 058f1cd | 2013-02-25 10:53:01 -0800 | [diff] [blame] | 45 | #include <pm8x41.h> |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 46 | #include <crypto5_wrapper.h> |
Amol Jadi | 85e1919 | 2013-02-28 22:45:04 -0800 | [diff] [blame] | 47 | #include <hsusb.h> |
Stanimir Varbanov | f0650ca | 2013-07-01 12:30:24 +0300 | [diff] [blame] | 48 | #include <scm.h> |
| 49 | #include <stdlib.h> |
| 50 | #include <partition_parser.h> |
Matthew Qin | a746281 | 2014-04-10 16:44:29 +0800 | [diff] [blame] | 51 | |
| 52 | #if LONG_PRESS_POWER_ON |
Matthew Qin | 2ad3dfa | 2014-01-24 16:57:37 +0800 | [diff] [blame] | 53 | #include <shutdown_detect.h> |
Matthew Qin | a746281 | 2014-04-10 16:44:29 +0800 | [diff] [blame] | 54 | #endif |
| 55 | |
Matthew Qin | 5c9c167 | 2014-04-15 12:55:41 +0800 | [diff] [blame] | 56 | #if PON_VIB_SUPPORT |
Matthew Qin | 6443b7d | 2014-02-22 07:20:42 +0800 | [diff] [blame] | 57 | #include <vibrator.h> |
Matthew Qin | 5c9c167 | 2014-04-15 12:55:41 +0800 | [diff] [blame] | 58 | #endif |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 59 | |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 60 | extern bool target_use_signed_kernel(void); |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 61 | static void set_sdc_power_ctrl(void); |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 62 | |
| 63 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 64 | #define PMIC_ARB_OWNER_ID 0 |
| 65 | |
| 66 | #define CRYPTO_ENGINE_INSTANCE 1 |
| 67 | #define CRYPTO_ENGINE_EE 1 |
| 68 | #define CRYPTO_ENGINE_FIFO_SIZE 64 |
| 69 | #define CRYPTO_ENGINE_READ_PIPE 3 |
| 70 | #define CRYPTO_ENGINE_WRITE_PIPE 2 |
Deepa Dinamani | bbcf1ca | 2013-07-09 14:10:57 -0700 | [diff] [blame] | 71 | #define CRYPTO_READ_PIPE_LOCK_GRP 0 |
| 72 | #define CRYPTO_WRITE_PIPE_LOCK_GRP 0 |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 73 | #define CRYPTO_ENGINE_CMD_ARRAY_SIZE 20 |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 74 | |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 75 | #define TLMM_VOL_UP_BTN_GPIO 106 |
Matthew Qin | 5c9c167 | 2014-04-15 12:55:41 +0800 | [diff] [blame] | 76 | |
| 77 | #if PON_VIB_SUPPORT |
Matthew Qin | 6443b7d | 2014-02-22 07:20:42 +0800 | [diff] [blame] | 78 | #define VIBRATE_TIME 250 |
Matthew Qin | 5c9c167 | 2014-04-15 12:55:41 +0800 | [diff] [blame] | 79 | #endif |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 80 | |
Stanimir Varbanov | f0650ca | 2013-07-01 12:30:24 +0300 | [diff] [blame] | 81 | #define SSD_CE_INSTANCE 1 |
| 82 | |
Maria Yu | b8fd082 | 2013-06-26 10:10:45 +0800 | [diff] [blame] | 83 | enum target_subtype { |
| 84 | HW_PLATFORM_SUBTYPE_SKUAA = 1, |
| 85 | HW_PLATFORM_SUBTYPE_SKUF = 2, |
| 86 | HW_PLATFORM_SUBTYPE_SKUAB = 3, |
Jie Cheng | f3d8a3b | 2013-08-01 15:37:55 +0800 | [diff] [blame] | 87 | HW_PLATFORM_SUBTYPE_SKUG = 5, |
Maria Yu | b8fd082 | 2013-06-26 10:10:45 +0800 | [diff] [blame] | 88 | }; |
| 89 | |
Sundarajan Srinivasan | 8031f6c | 2014-03-12 15:45:28 -0700 | [diff] [blame] | 90 | enum mtp_cdp_subtype |
| 91 | { |
| 92 | HW_PLATFORM_SUBTYPE_QVGA = 4, |
| 93 | }; |
| 94 | |
Channagoud Kadabi | f6f7174 | 2013-05-23 14:05:05 -0700 | [diff] [blame] | 95 | static uint32_t mmc_pwrctl_base[] = |
| 96 | { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE }; |
| 97 | |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 98 | static uint32_t mmc_sdhci_base[] = |
| 99 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE }; |
| 100 | |
Channagoud Kadabi | f6f7174 | 2013-05-23 14:05:05 -0700 | [diff] [blame] | 101 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 102 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ, SDCC3_PWRCTL_IRQ }; |
| 103 | |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 104 | struct mmc_device *dev; |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 105 | |
Stanimir Varbanov | f0650ca | 2013-07-01 12:30:24 +0300 | [diff] [blame] | 106 | void target_load_ssd_keystore(void) |
| 107 | { |
| 108 | uint64_t ptn; |
| 109 | int index; |
| 110 | uint64_t size; |
| 111 | uint32_t *buffer; |
| 112 | |
| 113 | if (!target_is_ssd_enabled()) |
| 114 | return; |
| 115 | |
| 116 | index = partition_get_index("ssd"); |
| 117 | |
| 118 | ptn = partition_get_offset(index); |
| 119 | if (ptn == 0){ |
| 120 | dprintf(CRITICAL, "Error: ssd partition not found\n"); |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | size = partition_get_size(index); |
| 125 | if (size == 0) { |
| 126 | dprintf(CRITICAL, "Error: invalid ssd partition size\n"); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE)); |
| 131 | if (!buffer) { |
| 132 | dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n"); |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | if (mmc_read(ptn, buffer, size)) { |
| 137 | dprintf(CRITICAL, "Error: cannot read data\n"); |
| 138 | free(buffer); |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | clock_ce_enable(SSD_CE_INSTANCE); |
| 143 | scm_protect_keystore(buffer, size); |
| 144 | clock_ce_disable(SSD_CE_INSTANCE); |
| 145 | free(buffer); |
| 146 | } |
| 147 | |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 148 | void target_early_init(void) |
| 149 | { |
| 150 | #if WITH_DEBUG_UART |
Deepa Dinamani | 0a6c48c | 2013-02-04 15:45:01 -0800 | [diff] [blame] | 151 | uart_dm_init(1, 0, BLSP1_UART2_BASE); |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 152 | #endif |
| 153 | } |
| 154 | |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 155 | /* Return 1 if vol_up pressed */ |
| 156 | static int target_volume_up() |
| 157 | { |
| 158 | uint8_t status = 0; |
| 159 | |
| 160 | gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE); |
| 161 | |
aiquny | 933017c | 2013-03-02 12:48:52 -0800 | [diff] [blame] | 162 | thread_sleep(10); |
| 163 | |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 164 | /* Get status of GPIO */ |
| 165 | status = gpio_status(TLMM_VOL_UP_BTN_GPIO); |
| 166 | |
| 167 | /* Active low signal. */ |
| 168 | return !status; |
| 169 | } |
| 170 | |
| 171 | /* Return 1 if vol_down pressed */ |
| 172 | uint32_t target_volume_down() |
| 173 | { |
| 174 | /* Volume down button tied in with PMIC RESIN. */ |
| 175 | return pm8x41_resin_status(); |
| 176 | } |
| 177 | |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 178 | static void target_keystatus() |
| 179 | { |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 180 | keys_init(); |
| 181 | |
| 182 | if(target_volume_down()) |
| 183 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 184 | |
| 185 | if(target_volume_up()) |
| 186 | keys_post_event(KEY_VOLUMEUP, 1); |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 189 | /* Set up params for h/w CRYPTO_ENGINE. */ |
| 190 | void target_crypto_init_params() |
| 191 | { |
| 192 | struct crypto_init_params ce_params; |
| 193 | |
| 194 | /* Set up base addresses and instance. */ |
| 195 | ce_params.crypto_instance = CRYPTO_ENGINE_INSTANCE; |
| 196 | ce_params.crypto_base = MSM_CE1_BASE; |
| 197 | ce_params.bam_base = MSM_CE1_BAM_BASE; |
| 198 | |
| 199 | /* Set up BAM config. */ |
Deepa Dinamani | bbcf1ca | 2013-07-09 14:10:57 -0700 | [diff] [blame] | 200 | ce_params.bam_ee = CRYPTO_ENGINE_EE; |
| 201 | ce_params.pipes.read_pipe = CRYPTO_ENGINE_READ_PIPE; |
| 202 | ce_params.pipes.write_pipe = CRYPTO_ENGINE_WRITE_PIPE; |
| 203 | ce_params.pipes.read_pipe_grp = CRYPTO_READ_PIPE_LOCK_GRP; |
| 204 | ce_params.pipes.write_pipe_grp = CRYPTO_WRITE_PIPE_LOCK_GRP; |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 205 | |
| 206 | /* Assign buffer sizes. */ |
| 207 | ce_params.num_ce = CRYPTO_ENGINE_CMD_ARRAY_SIZE; |
| 208 | ce_params.read_fifo_size = CRYPTO_ENGINE_FIFO_SIZE; |
| 209 | ce_params.write_fifo_size = CRYPTO_ENGINE_FIFO_SIZE; |
| 210 | |
Stanimir Varbanov | f0650ca | 2013-07-01 12:30:24 +0300 | [diff] [blame] | 211 | ce_params.do_bam_init = 0; |
| 212 | |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 213 | crypto_init_params(&ce_params); |
| 214 | } |
| 215 | |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 216 | void target_sdc_init() |
| 217 | { |
Channagoud Kadabi | f6f7174 | 2013-05-23 14:05:05 -0700 | [diff] [blame] | 218 | struct mmc_config_data config = {0}; |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 219 | |
| 220 | /* |
| 221 | * Set drive strength & pull ctrl for emmc |
| 222 | */ |
| 223 | set_sdc_power_ctrl(); |
| 224 | |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 225 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 226 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 227 | |
| 228 | /* Trying Slot 1*/ |
| 229 | config.slot = 1; |
Channagoud Kadabi | f6f7174 | 2013-05-23 14:05:05 -0700 | [diff] [blame] | 230 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 231 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 232 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
Aparna Mallavarapu | e737637 | 2014-03-11 13:47:34 +0530 | [diff] [blame] | 233 | config.hs400_support = 0; |
Channagoud Kadabi | f6f7174 | 2013-05-23 14:05:05 -0700 | [diff] [blame] | 234 | |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 235 | if (!(dev = mmc_init(&config))) |
| 236 | { |
| 237 | /* Trying Slot 2 next */ |
| 238 | config.slot = 2; |
Channagoud Kadabi | f6f7174 | 2013-05-23 14:05:05 -0700 | [diff] [blame] | 239 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 240 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 241 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 242 | |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 243 | if (!(dev = mmc_init(&config))) { |
| 244 | dprintf(CRITICAL, "mmc init failed!"); |
| 245 | ASSERT(0); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * MMC initialization is complete, read the partition table info |
| 251 | */ |
| 252 | if (partition_read_table()) { |
| 253 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 254 | ASSERT(0); |
| 255 | } |
| 256 | } |
| 257 | |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 258 | void target_init(void) |
| 259 | { |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 260 | dprintf(INFO, "target_init()\n"); |
| 261 | |
| 262 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 263 | |
| 264 | target_keystatus(); |
| 265 | |
Aparna Mallavarapu | 63a6225 | 2013-08-23 17:59:43 +0530 | [diff] [blame] | 266 | target_sdc_init(); |
| 267 | |
Matthew Qin | a746281 | 2014-04-10 16:44:29 +0800 | [diff] [blame] | 268 | #if LONG_PRESS_POWER_ON |
Matthew Qin | 2ad3dfa | 2014-01-24 16:57:37 +0800 | [diff] [blame] | 269 | shutdown_detect(); |
Matthew Qin | a746281 | 2014-04-10 16:44:29 +0800 | [diff] [blame] | 270 | #endif |
Matthew Qin | 2ad3dfa | 2014-01-24 16:57:37 +0800 | [diff] [blame] | 271 | |
Matthew Qin | 5c9c167 | 2014-04-15 12:55:41 +0800 | [diff] [blame] | 272 | #if PON_VIB_SUPPORT |
Matthew Qin | 6443b7d | 2014-02-22 07:20:42 +0800 | [diff] [blame] | 273 | /* turn on vibrator to indicate that phone is booting up to end user */ |
| 274 | vib_timed_turn_on(VIBRATE_TIME); |
Matthew Qin | 5c9c167 | 2014-04-15 12:55:41 +0800 | [diff] [blame] | 275 | #endif |
Matthew Qin | 6443b7d | 2014-02-22 07:20:42 +0800 | [diff] [blame] | 276 | |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 277 | if (target_use_signed_kernel()) |
| 278 | target_crypto_init_params(); |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 279 | } |
| 280 | |
Deepa Dinamani | 058f1cd | 2013-02-25 10:53:01 -0800 | [diff] [blame] | 281 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 282 | void target_fastboot_init(void) |
| 283 | { |
| 284 | /* Set the BOOT_DONE flag in PM8026 */ |
| 285 | pm8x41_set_boot_done(); |
Stanimir Varbanov | f0650ca | 2013-07-01 12:30:24 +0300 | [diff] [blame] | 286 | |
| 287 | if (target_is_ssd_enabled()) { |
| 288 | clock_ce_enable(SSD_CE_INSTANCE); |
| 289 | target_load_ssd_keystore(); |
| 290 | } |
Deepa Dinamani | 058f1cd | 2013-02-25 10:53:01 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Deepa Dinamani | ff2b9ce | 2013-02-25 11:01:00 -0800 | [diff] [blame] | 293 | /* Detect the target type */ |
| 294 | void target_detect(struct board_data *board) |
| 295 | { |
Maria Yu | ca51ee2 | 2013-06-27 21:45:24 +0800 | [diff] [blame] | 296 | /* |
| 297 | * already fill the board->target on board.c |
| 298 | */ |
Deepa Dinamani | ff2b9ce | 2013-02-25 11:01:00 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Sundarajan Srinivasan | 8031f6c | 2014-03-12 15:45:28 -0700 | [diff] [blame] | 301 | bool target_is_cdp_qvga() |
| 302 | { |
| 303 | return board_hardware_subtype() == HW_PLATFORM_SUBTYPE_QVGA; |
| 304 | } |
| 305 | |
Deepa Dinamani | ff2b9ce | 2013-02-25 11:01:00 -0800 | [diff] [blame] | 306 | /* Detect the modem type */ |
| 307 | void target_baseband_detect(struct board_data *board) |
| 308 | { |
| 309 | uint32_t platform; |
| 310 | uint32_t platform_subtype; |
| 311 | |
| 312 | platform = board->platform; |
| 313 | platform_subtype = board->platform_subtype; |
| 314 | |
| 315 | /* |
| 316 | * Look for platform subtype if present, else |
| 317 | * check for platform type to decide on the |
| 318 | * baseband type |
| 319 | */ |
| 320 | switch(platform_subtype) |
| 321 | { |
| 322 | case HW_PLATFORM_SUBTYPE_UNKNOWN: |
| 323 | break; |
Maria Yu | b8fd082 | 2013-06-26 10:10:45 +0800 | [diff] [blame] | 324 | case HW_PLATFORM_SUBTYPE_SKUAA: |
| 325 | break; |
| 326 | case HW_PLATFORM_SUBTYPE_SKUF: |
| 327 | break; |
| 328 | case HW_PLATFORM_SUBTYPE_SKUAB: |
| 329 | break; |
Jie Cheng | f3d8a3b | 2013-08-01 15:37:55 +0800 | [diff] [blame] | 330 | case HW_PLATFORM_SUBTYPE_SKUG: |
| 331 | break; |
Sundarajan Srinivasan | 8031f6c | 2014-03-12 15:45:28 -0700 | [diff] [blame] | 332 | case HW_PLATFORM_SUBTYPE_QVGA: |
| 333 | break; |
Deepa Dinamani | ff2b9ce | 2013-02-25 11:01:00 -0800 | [diff] [blame] | 334 | default: |
| 335 | dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype); |
| 336 | ASSERT(0); |
| 337 | }; |
| 338 | |
| 339 | switch(platform) |
| 340 | { |
| 341 | case MSM8826: |
| 342 | case MSM8626: |
| 343 | case MSM8226: |
Deepa Dinamani | 7eeecf6 | 2013-05-21 12:43:26 -0700 | [diff] [blame] | 344 | case MSM8926: |
| 345 | case MSM8126: |
| 346 | case MSM8326: |
Deepa Dinamani | cd795aa | 2013-09-05 16:30:53 -0700 | [diff] [blame] | 347 | case MSM8528: |
| 348 | case MSM8628: |
| 349 | case MSM8228: |
| 350 | case MSM8928: |
| 351 | case MSM8128: |
Deepa Dinamani | ff2b9ce | 2013-02-25 11:01:00 -0800 | [diff] [blame] | 352 | board->baseband = BASEBAND_MSM; |
| 353 | break; |
Deepa Dinamani | 7eeecf6 | 2013-05-21 12:43:26 -0700 | [diff] [blame] | 354 | case APQ8026: |
Deepa Dinamani | cd795aa | 2013-09-05 16:30:53 -0700 | [diff] [blame] | 355 | case APQ8028: |
Deepa Dinamani | 7eeecf6 | 2013-05-21 12:43:26 -0700 | [diff] [blame] | 356 | board->baseband = BASEBAND_APQ; |
| 357 | break; |
Deepa Dinamani | ff2b9ce | 2013-02-25 11:01:00 -0800 | [diff] [blame] | 358 | default: |
| 359 | dprintf(CRITICAL, "Platform type: %u is not supported\n", platform); |
| 360 | ASSERT(0); |
| 361 | }; |
| 362 | } |
| 363 | |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 364 | void target_serialno(unsigned char *buf) |
| 365 | { |
| 366 | uint32_t serialno; |
| 367 | if (target_is_emmc_boot()) { |
| 368 | serialno = mmc_get_psn(); |
| 369 | snprintf((char *)buf, 13, "%x", serialno); |
| 370 | } |
| 371 | } |
| 372 | |
Deepa Dinamani | 8d2bb22 | 2013-02-26 14:03:04 -0800 | [diff] [blame] | 373 | unsigned check_reboot_mode(void) |
| 374 | { |
| 375 | uint32_t restart_reason = 0; |
| 376 | |
| 377 | /* Read reboot reason and scrub it */ |
| 378 | restart_reason = readl(RESTART_REASON_ADDR); |
| 379 | writel(0x00, RESTART_REASON_ADDR); |
| 380 | |
| 381 | return restart_reason; |
| 382 | } |
| 383 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 384 | int set_download_mode(enum reboot_reason mode) |
| 385 | { |
| 386 | if (mode == NORMAL_DLOAD || mode == EMERGENCY_DLOAD) { |
| 387 | dload_util_write_cookie(mode == NORMAL_DLOAD ? |
| 388 | DLOAD_MODE_ADDR : EMERGENCY_DLOAD_MODE_ADDR, mode); |
| 389 | |
| 390 | pm8x41_clear_pmic_watchdog(); |
| 391 | } |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
Deepa Dinamani | f7c03c1 | 2013-02-26 14:17:20 -0800 | [diff] [blame] | 396 | void reboot_device(unsigned reboot_reason) |
| 397 | { |
Channagoud Kadabi | 6c792be | 2014-02-25 15:28:08 -0800 | [diff] [blame] | 398 | int ret = 0; |
| 399 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 400 | /* Set cookie for dload mode */ |
| 401 | if(set_download_mode(reboot_reason)) { |
| 402 | dprintf(CRITICAL, "HALT: set_download_mode not supported\n"); |
| 403 | return; |
| 404 | } |
| 405 | |
Deepa Dinamani | f7c03c1 | 2013-02-26 14:17:20 -0800 | [diff] [blame] | 406 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 407 | |
| 408 | /* Configure PMIC for warm reset */ |
| 409 | pm8x41_reset_configure(PON_PSHOLD_WARM_RESET); |
| 410 | |
Channagoud Kadabi | 6c792be | 2014-02-25 15:28:08 -0800 | [diff] [blame] | 411 | ret = scm_halt_pmic_arbiter(); |
| 412 | if (ret) |
| 413 | dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret); |
| 414 | |
Deepa Dinamani | f7c03c1 | 2013-02-26 14:17:20 -0800 | [diff] [blame] | 415 | /* Drop PS_HOLD for MSM */ |
| 416 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 417 | |
| 418 | mdelay(5000); |
| 419 | |
| 420 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 421 | } |
| 422 | |
Matthew Qin | 7eed111 | 2014-02-21 10:34:09 +0800 | [diff] [blame] | 423 | /* Configure PMIC and Drop PS_HOLD for shutdown */ |
| 424 | void shutdown_device() |
| 425 | { |
| 426 | dprintf(CRITICAL, "Going down for shutdown.\n"); |
| 427 | |
| 428 | /* Configure PMIC for shutdown */ |
| 429 | pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN); |
| 430 | |
| 431 | /* Drop PS_HOLD for MSM */ |
| 432 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 433 | |
| 434 | mdelay(5000); |
| 435 | |
| 436 | dprintf(CRITICAL, "shutdown failed\n"); |
| 437 | |
| 438 | ASSERT(0); |
| 439 | } |
| 440 | |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 441 | crypto_engine_type board_ce_type(void) |
| 442 | { |
| 443 | return CRYPTO_ENGINE_TYPE_HW; |
| 444 | } |
| 445 | |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 446 | unsigned board_machtype(void) |
| 447 | { |
Deepa Dinamani | 8d6b425 | 2013-03-06 11:16:41 -0800 | [diff] [blame] | 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | void target_usb_stop(void) |
| 452 | { |
| 453 | /* Disable VBUS mimicing in the controller. */ |
| 454 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR); |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 455 | } |
Amol Jadi | 85e1919 | 2013-02-28 22:45:04 -0800 | [diff] [blame] | 456 | |
Channagoud Kadabi | e3a695a | 2013-06-18 18:35:00 -0700 | [diff] [blame] | 457 | void target_uninit(void) |
| 458 | { |
Matthew Qin | 5c9c167 | 2014-04-15 12:55:41 +0800 | [diff] [blame] | 459 | #if PON_VIB_SUPPORT |
Matthew Qin | 6443b7d | 2014-02-22 07:20:42 +0800 | [diff] [blame] | 460 | /* wait for the vibrator timer is expried */ |
| 461 | wait_vib_timeout(); |
Matthew Qin | 5c9c167 | 2014-04-15 12:55:41 +0800 | [diff] [blame] | 462 | #endif |
Matthew Qin | 6443b7d | 2014-02-22 07:20:42 +0800 | [diff] [blame] | 463 | |
Channagoud Kadabi | e3a695a | 2013-06-18 18:35:00 -0700 | [diff] [blame] | 464 | mmc_put_card_to_sleep(dev); |
Stanimir Varbanov | f0650ca | 2013-07-01 12:30:24 +0300 | [diff] [blame] | 465 | |
Channagoud Kadabi | b53d2d8 | 2013-12-04 12:38:27 -0800 | [diff] [blame] | 466 | if (crypto_initialized()) |
| 467 | crypto_eng_cleanup(); |
Sundarajan Srinivasan | d58d536 | 2014-05-08 16:36:25 -0700 | [diff] [blame] | 468 | |
| 469 | if (target_is_ssd_enabled()) |
| 470 | clock_ce_disable(SSD_CE_INSTANCE); |
Aparna Mallavarapu | a007a0f | 2014-09-24 17:33:14 +0530 | [diff] [blame] | 471 | |
| 472 | /* Disable HC mode before jumping to kernel */ |
| 473 | sdhci_mode_disable(&dev->host); |
Channagoud Kadabi | e3a695a | 2013-06-18 18:35:00 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Amol Jadi | 85e1919 | 2013-02-28 22:45:04 -0800 | [diff] [blame] | 476 | void target_usb_init(void) |
| 477 | { |
| 478 | uint32_t val; |
| 479 | |
| 480 | /* Select and enable external configuration with USB PHY */ |
| 481 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 482 | |
| 483 | /* Enable sess_vld */ |
| 484 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 485 | writel(val, USB_GENCONFIG_2); |
| 486 | |
| 487 | /* Enable external vbus configuration in the LINK */ |
| 488 | val = readl(USB_USBCMD); |
| 489 | val |= SESS_VLD_CTRL; |
| 490 | writel(val, USB_USBCMD); |
| 491 | } |
Deepa Dinamani | cde6457 | 2013-02-25 15:02:25 -0800 | [diff] [blame] | 492 | |
Pradeep Jilagam | feb1598 | 2013-10-29 13:08:51 +0530 | [diff] [blame] | 493 | uint8_t target_panel_auto_detect_enabled() |
| 494 | { |
Aravind Venkateswaran | 05fc7af | 2013-12-18 17:50:35 -0800 | [diff] [blame] | 495 | uint8_t ret = 0; |
rayz | 2e3540d | 2014-02-14 13:17:02 +0800 | [diff] [blame] | 496 | uint32_t hw_subtype = board_hardware_subtype(); |
Aravind Venkateswaran | 05fc7af | 2013-12-18 17:50:35 -0800 | [diff] [blame] | 497 | |
Pradeep Jilagam | feb1598 | 2013-10-29 13:08:51 +0530 | [diff] [blame] | 498 | switch(board_hardware_id()) |
| 499 | { |
| 500 | case HW_PLATFORM_QRD: |
rayz | 2e3540d | 2014-02-14 13:17:02 +0800 | [diff] [blame] | 501 | if (hw_subtype != HW_PLATFORM_SUBTYPE_SKUF |
| 502 | && hw_subtype != HW_PLATFORM_SUBTYPE_SKUG) { |
| 503 | /* Enable autodetect for 8x26 DVT boards only */ |
| 504 | if (((board_target_id() >> 16) & 0xFF) == 0x2) |
| 505 | ret = 1; |
| 506 | else |
| 507 | ret = 0; |
| 508 | } |
Aravind Venkateswaran | 05fc7af | 2013-12-18 17:50:35 -0800 | [diff] [blame] | 509 | break; |
Pradeep Jilagam | feb1598 | 2013-10-29 13:08:51 +0530 | [diff] [blame] | 510 | case HW_PLATFORM_SURF: |
| 511 | case HW_PLATFORM_MTP: |
| 512 | default: |
Aravind Venkateswaran | 05fc7af | 2013-12-18 17:50:35 -0800 | [diff] [blame] | 513 | ret = 0; |
Pradeep Jilagam | feb1598 | 2013-10-29 13:08:51 +0530 | [diff] [blame] | 514 | } |
Aravind Venkateswaran | 05fc7af | 2013-12-18 17:50:35 -0800 | [diff] [blame] | 515 | return ret; |
Pradeep Jilagam | feb1598 | 2013-10-29 13:08:51 +0530 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static uint8_t splash_override; |
Ray Zhang | 743e503 | 2013-05-25 23:25:39 +0800 | [diff] [blame] | 519 | /* Returns 1 if target supports continuous splash screen. */ |
| 520 | int target_cont_splash_screen() |
| 521 | { |
Pradeep Jilagam | feb1598 | 2013-10-29 13:08:51 +0530 | [diff] [blame] | 522 | uint8_t splash_screen = 0; |
| 523 | if(!splash_override) { |
| 524 | switch(board_hardware_id()) |
| 525 | { |
| 526 | case HW_PLATFORM_MTP: |
| 527 | case HW_PLATFORM_QRD: |
| 528 | case HW_PLATFORM_SURF: |
| 529 | dprintf(SPEW, "Target_cont_splash=1\n"); |
| 530 | splash_screen = 1; |
| 531 | break; |
| 532 | default: |
| 533 | dprintf(SPEW, "Target_cont_splash=0\n"); |
| 534 | splash_screen = 0; |
| 535 | } |
| 536 | } |
| 537 | return splash_screen; |
| 538 | } |
| 539 | |
| 540 | void target_force_cont_splash_disable(uint8_t override) |
| 541 | { |
| 542 | splash_override = override; |
Ray Zhang | 743e503 | 2013-05-25 23:25:39 +0800 | [diff] [blame] | 543 | } |
| 544 | |
Deepa Dinamani | cde6457 | 2013-02-25 15:02:25 -0800 | [diff] [blame] | 545 | unsigned target_pause_for_battery_charge(void) |
| 546 | { |
| 547 | uint8_t pon_reason = pm8x41_get_pon_reason(); |
Ameya Thakur | 0604131 | 2013-06-25 13:46:21 -0700 | [diff] [blame] | 548 | uint8_t is_cold_boot = pm8x41_get_is_cold_boot(); |
Ameya Thakur | 531e59a | 2013-07-17 16:53:53 -0700 | [diff] [blame] | 549 | dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__, |
| 550 | pon_reason, is_cold_boot); |
Ameya Thakur | a8711dc | 2013-07-19 17:52:51 -0700 | [diff] [blame] | 551 | /* In case of fastboot reboot,adb reboot or if we see the power key |
| 552 | * pressed we do not want go into charger mode. |
Ameya Thakur | 531e59a | 2013-07-17 16:53:53 -0700 | [diff] [blame] | 553 | * fastboot reboot is warm boot with PON hard reset bit not set |
| 554 | * adb reboot is a cold boot with PON hard reset bit set |
| 555 | */ |
Ameya Thakur | a8711dc | 2013-07-19 17:52:51 -0700 | [diff] [blame] | 556 | if (is_cold_boot && |
| 557 | (!(pon_reason & HARD_RST)) && |
| 558 | (!(pon_reason & KPDPWR_N)) && |
Ameya Thakur | 531e59a | 2013-07-17 16:53:53 -0700 | [diff] [blame] | 559 | ((pon_reason & USB_CHG) || (pon_reason & DC_CHG))) |
| 560 | return 1; |
| 561 | else |
| 562 | return 0; |
Deepa Dinamani | cde6457 | 2013-02-25 15:02:25 -0800 | [diff] [blame] | 563 | } |
Channagoud Kadabi | da54ca1 | 2013-03-29 11:22:15 -0700 | [diff] [blame] | 564 | |
| 565 | unsigned target_baseband() |
| 566 | { |
| 567 | return board_baseband(); |
| 568 | } |
Stanimir Varbanov | 7f9d7a7 | 2013-04-29 12:05:39 +0300 | [diff] [blame] | 569 | |
| 570 | int emmc_recovery_init(void) |
| 571 | { |
Pavel Nedev | 16f4923 | 2013-04-29 16:15:36 +0300 | [diff] [blame] | 572 | return _emmc_recovery_init(); |
| 573 | } |
| 574 | |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 575 | static void set_sdc_power_ctrl() |
| 576 | { |
| 577 | /* Drive strength configs for sdc pins */ |
| 578 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 579 | { |
Channagoud Kadabi | c593a58 | 2014-01-03 16:18:54 -0800 | [diff] [blame] | 580 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK }, |
| 581 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
Channagoud Kadabi | 29d389d | 2013-10-28 14:55:02 -0700 | [diff] [blame] | 582 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK }, |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 583 | }; |
| 584 | |
| 585 | /* Pull configs for sdc pins */ |
| 586 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 587 | { |
| 588 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK }, |
| 589 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 590 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 591 | }; |
| 592 | |
| 593 | /* Set the drive strength & pull control values */ |
| 594 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 595 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 596 | } |
| 597 | |
Channagoud Kadabi | 504de06 | 2013-09-10 15:02:22 -0700 | [diff] [blame] | 598 | void *target_mmc_device() |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 599 | { |
Channagoud Kadabi | 504de06 | 2013-09-10 15:02:22 -0700 | [diff] [blame] | 600 | return (void *) dev; |
Channagoud Kadabi | 3c50c31 | 2013-05-02 17:16:03 -0700 | [diff] [blame] | 601 | } |