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