Eugene Yasman | 6382ee0 | 2013-01-16 13:00:56 +0200 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame] | 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. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 15 | * |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame] | 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. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <platform/iomap.h> |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 31 | #include <platform/gpio.h> |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 32 | #include <reg.h> |
| 33 | #include <target.h> |
| 34 | #include <platform.h> |
Pavel Nedev | 0351149 | 2013-03-08 19:05:32 -0800 | [diff] [blame] | 35 | #include <dload_util.h> |
Deepa Dinamani | 26e9326 | 2012-05-21 17:35:14 -0700 | [diff] [blame] | 36 | #include <uart_dm.h> |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 37 | #include <mmc.h> |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 38 | #include <spmi.h> |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 39 | #include <board.h> |
| 40 | #include <smem.h> |
| 41 | #include <baseband.h> |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 42 | #include <dev/keys.h> |
| 43 | #include <pm8x41.h> |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 44 | #include <crypto5_wrapper.h> |
Eugene Yasman | a0d1812 | 2013-02-26 13:23:05 +0200 | [diff] [blame] | 45 | #include <hsusb.h> |
| 46 | #include <clock.h> |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 47 | #include <partition_parser.h> |
| 48 | #include <scm.h> |
| 49 | #include <platform/clock.h> |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 50 | #include <platform/gpio.h> |
Channagoud Kadabi | f84830c | 2013-04-19 14:35:47 -0700 | [diff] [blame] | 51 | #include <stdlib.h> |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 52 | |
| 53 | extern bool target_use_signed_kernel(void); |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 54 | static void set_sdc_power_ctrl(); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 55 | |
| 56 | static unsigned int target_id; |
Deepa Dinamani | 07f1571 | 2013-03-08 17:02:13 -0800 | [diff] [blame] | 57 | static uint32_t pmic_ver; |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 58 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 59 | #if MMC_SDHCI_SUPPORT |
| 60 | struct mmc_device *dev; |
| 61 | #endif |
| 62 | |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 63 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 64 | #define PMIC_ARB_OWNER_ID 0 |
| 65 | |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame] | 66 | #define WDOG_DEBUG_DISABLE_BIT 17 |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 67 | |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 68 | #define CE_INSTANCE 2 |
| 69 | #define CE_EE 1 |
| 70 | #define CE_FIFO_SIZE 64 |
| 71 | #define CE_READ_PIPE 3 |
| 72 | #define CE_WRITE_PIPE 2 |
| 73 | #define CE_ARRAY_SIZE 20 |
| 74 | |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 75 | #ifdef SSD_ENABLE |
| 76 | #define SSD_CE_INSTANCE_1 1 |
| 77 | #define SSD_PARTITION_SIZE 8192 |
| 78 | #endif |
| 79 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 80 | #if MMC_SDHCI_SUPPORT |
| 81 | static uint32_t mmc_sdhci_base[] = |
| 82 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE, MSM_SDC4_SDHCI_BASE }; |
| 83 | #endif |
| 84 | |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 85 | static uint32_t mmc_sdc_base[] = |
| 86 | { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE }; |
| 87 | |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 88 | void target_early_init(void) |
| 89 | { |
Deepa Dinamani | b073ba2 | 2012-08-10 11:06:41 -0700 | [diff] [blame] | 90 | #if WITH_DEBUG_UART |
Neeti Desai | ac01127 | 2012-08-29 18:24:54 -0700 | [diff] [blame] | 91 | uart_dm_init(1, 0, BLSP1_UART1_BASE); |
Deepa Dinamani | b073ba2 | 2012-08-10 11:06:41 -0700 | [diff] [blame] | 92 | #endif |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 95 | /* Return 1 if vol_up pressed */ |
| 96 | static int target_volume_up() |
| 97 | { |
| 98 | uint8_t status = 0; |
| 99 | struct pm8x41_gpio gpio; |
| 100 | |
| 101 | /* CDP vol_up seems to be always grounded. So gpio status is read as 0, |
| 102 | * whether key is pressed or not. |
| 103 | * Ignore volume_up key on CDP for now. |
| 104 | */ |
| 105 | if (board_hardware_id() == HW_PLATFORM_SURF) |
| 106 | return 0; |
| 107 | |
| 108 | /* Configure the GPIO */ |
| 109 | gpio.direction = PM_GPIO_DIR_IN; |
| 110 | gpio.function = 0; |
| 111 | gpio.pull = PM_GPIO_PULL_UP_30; |
Eugene Yasman | 6382ee0 | 2013-01-16 13:00:56 +0200 | [diff] [blame] | 112 | gpio.vin_sel = 2; |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 113 | |
| 114 | pm8x41_gpio_config(5, &gpio); |
| 115 | |
| 116 | /* Get status of P_GPIO_5 */ |
| 117 | pm8x41_gpio_get(5, &status); |
| 118 | |
| 119 | return !status; /* active low */ |
| 120 | } |
| 121 | |
| 122 | /* Return 1 if vol_down pressed */ |
Deepa Dinamani | 66a8796 | 2013-02-04 10:39:30 -0800 | [diff] [blame] | 123 | uint32_t target_volume_down() |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 124 | { |
Deepa Dinamani | 66a8796 | 2013-02-04 10:39:30 -0800 | [diff] [blame] | 125 | /* Volume down button is tied in with RESIN on MSM8974. */ |
Deepa Dinamani | 07f1571 | 2013-03-08 17:02:13 -0800 | [diff] [blame] | 126 | if (pmic_ver == PMIC_VERSION_V2) |
Deepa Dinamani | 13bfc85 | 2013-02-05 17:56:47 -0800 | [diff] [blame] | 127 | return pm8x41_resin_bark_workaround_status(); |
| 128 | else |
| 129 | return pm8x41_resin_status(); |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static void target_keystatus() |
| 133 | { |
| 134 | keys_init(); |
| 135 | |
| 136 | if(target_volume_down()) |
| 137 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 138 | |
| 139 | if(target_volume_up()) |
| 140 | keys_post_event(KEY_VOLUMEUP, 1); |
| 141 | } |
| 142 | |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 143 | /* Set up params for h/w CE. */ |
| 144 | void target_crypto_init_params() |
| 145 | { |
| 146 | struct crypto_init_params ce_params; |
| 147 | |
| 148 | /* Set up base addresses and instance. */ |
| 149 | ce_params.crypto_instance = CE_INSTANCE; |
| 150 | ce_params.crypto_base = MSM_CE2_BASE; |
| 151 | ce_params.bam_base = MSM_CE2_BAM_BASE; |
| 152 | |
| 153 | /* Set up BAM config. */ |
| 154 | ce_params.bam_ee = CE_EE; |
| 155 | ce_params.pipes.read_pipe = CE_READ_PIPE; |
| 156 | ce_params.pipes.write_pipe = CE_WRITE_PIPE; |
| 157 | |
| 158 | /* Assign buffer sizes. */ |
| 159 | ce_params.num_ce = CE_ARRAY_SIZE; |
| 160 | ce_params.read_fifo_size = CE_FIFO_SIZE; |
| 161 | ce_params.write_fifo_size = CE_FIFO_SIZE; |
| 162 | |
| 163 | crypto_init_params(&ce_params); |
| 164 | } |
| 165 | |
| 166 | crypto_engine_type board_ce_type(void) |
| 167 | { |
| 168 | return CRYPTO_ENGINE_TYPE_HW; |
| 169 | } |
| 170 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 171 | #if MMC_SDHCI_SUPPORT |
| 172 | static target_mmc_sdhci_init() |
| 173 | { |
| 174 | struct mmc_config_data config; |
| 175 | uint32_t soc_ver = 0; |
| 176 | |
| 177 | /* Enable sdhci mode */ |
| 178 | sdhci_mode_enable(1); |
| 179 | |
| 180 | soc_ver = board_soc_version(); |
| 181 | |
| 182 | /* |
| 183 | * 8974 v1 fluid devices, have a hardware bug |
| 184 | * which limits the bus width to 4 bit. |
| 185 | */ |
| 186 | switch(board_hardware_id()) |
| 187 | { |
| 188 | case HW_PLATFORM_FLUID: |
| 189 | if (soc_ver >= BOARD_SOC_VERSION2) |
| 190 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 191 | else |
| 192 | config.bus_width = DATA_BUS_WIDTH_4BIT; |
| 193 | break; |
| 194 | default: |
| 195 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 196 | }; |
| 197 | |
| 198 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 199 | |
| 200 | /* Trying Slot 1*/ |
| 201 | config.slot = 1; |
| 202 | config.base = mmc_sdhci_base[config.slot - 1]; |
| 203 | |
| 204 | if (!(dev = mmc_init(&config))) { |
| 205 | /* Trying Slot 2 next */ |
| 206 | config.slot = 2; |
| 207 | config.base = mmc_sdhci_base[config.slot - 1]; |
| 208 | if (!(dev = mmc_init(&config))) { |
| 209 | dprintf(CRITICAL, "mmc init failed!"); |
| 210 | ASSERT(0); |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | struct mmc_device *target_mmc_device() |
| 216 | { |
| 217 | return dev; |
| 218 | } |
| 219 | #else |
| 220 | static target_mmc_mci_init() |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 221 | { |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 222 | uint32_t base_addr; |
| 223 | uint8_t slot; |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 224 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 225 | /* Trying Slot 1 */ |
| 226 | slot = 1; |
| 227 | base_addr = mmc_sdc_base[slot - 1]; |
| 228 | |
| 229 | if (mmc_boot_main(slot, base_addr)) |
| 230 | { |
| 231 | /* Trying Slot 2 next */ |
| 232 | slot = 2; |
| 233 | base_addr = mmc_sdc_base[slot - 1]; |
| 234 | if (mmc_boot_main(slot, base_addr)) { |
| 235 | dprintf(CRITICAL, "mmc init failed!"); |
| 236 | ASSERT(0); |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | /* |
| 242 | * Function to set the capabilities for the host |
| 243 | */ |
| 244 | void target_mmc_caps(struct mmc_host *host) |
| 245 | { |
| 246 | uint32_t soc_ver = 0; |
| 247 | |
| 248 | soc_ver = board_soc_version(); |
| 249 | |
| 250 | /* |
| 251 | * 8974 v1 fluid devices, have a hardware bug |
| 252 | * which limits the bus width to 4 bit. |
| 253 | */ |
| 254 | switch(board_hardware_id()) |
| 255 | { |
| 256 | case HW_PLATFORM_FLUID: |
| 257 | if (soc_ver >= BOARD_SOC_VERSION2) |
| 258 | host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT; |
| 259 | else |
| 260 | host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT; |
| 261 | break; |
| 262 | default: |
| 263 | host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT; |
| 264 | }; |
| 265 | |
| 266 | host->caps.ddr_mode = 1; |
| 267 | host->caps.hs200_mode = 1; |
| 268 | host->caps.hs_clk_rate = MMC_CLK_96MHZ; |
| 269 | } |
| 270 | #endif |
| 271 | |
| 272 | |
| 273 | void target_init(void) |
| 274 | { |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 275 | dprintf(INFO, "target_init()\n"); |
| 276 | |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 277 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 278 | |
Deepa Dinamani | 07f1571 | 2013-03-08 17:02:13 -0800 | [diff] [blame] | 279 | /* Save PM8941 version info. */ |
| 280 | pmic_ver = pm8x41_get_pmic_rev(); |
| 281 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 282 | target_keystatus(); |
| 283 | |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 284 | if (target_use_signed_kernel()) |
| 285 | target_crypto_init_params(); |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 286 | /* Display splash screen if enabled */ |
| 287 | #if DISPLAY_SPLASH_SCREEN |
Channagoud Kadabi | 8a9c6a2 | 2013-02-05 14:43:48 -0800 | [diff] [blame] | 288 | dprintf(INFO, "Display Init: Start\n"); |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 289 | display_init(); |
Channagoud Kadabi | 8a9c6a2 | 2013-02-05 14:43:48 -0800 | [diff] [blame] | 290 | dprintf(INFO, "Display Init: Done\n"); |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 291 | #endif |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 292 | |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 293 | /* |
| 294 | * Set drive strength & pull ctrl for |
| 295 | * emmc |
| 296 | */ |
| 297 | set_sdc_power_ctrl(); |
| 298 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 299 | #if MMC_SDHCI_SUPPORT |
| 300 | target_mmc_sdhci_init(); |
| 301 | #else |
| 302 | target_mmc_mci_init(); |
| 303 | #endif |
Deepa Dinamani | d18b47a | 2012-06-27 13:06:03 -0700 | [diff] [blame] | 304 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 305 | /* |
| 306 | * MMC initialization is complete, read the partition table info |
| 307 | */ |
| 308 | if (partition_read_table()) { |
| 309 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 310 | ASSERT(0); |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 311 | } |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | unsigned board_machtype(void) |
| 315 | { |
| 316 | return target_id; |
| 317 | } |
| 318 | |
| 319 | /* Do any target specific intialization needed before entering fastboot mode */ |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 320 | #ifdef SSD_ENABLE |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 321 | static void ssd_load_keystore_from_emmc() |
| 322 | { |
| 323 | uint64_t ptn = 0; |
| 324 | int index = -1; |
| 325 | uint32_t size = SSD_PARTITION_SIZE; |
| 326 | int ret = -1; |
| 327 | |
Channagoud Kadabi | f84830c | 2013-04-19 14:35:47 -0700 | [diff] [blame] | 328 | uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE, |
| 329 | ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE)); |
| 330 | |
| 331 | if (!buffer) { |
| 332 | dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n"); |
| 333 | ASSERT(0); |
| 334 | } |
| 335 | |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 336 | index = partition_get_index("ssd"); |
| 337 | |
| 338 | ptn = partition_get_offset(index); |
| 339 | if(ptn == 0){ |
| 340 | dprintf(CRITICAL,"ERROR: ssd parition not found"); |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | if(mmc_read(ptn, buffer, size)){ |
| 345 | dprintf(CRITICAL,"ERROR:Cannot read data\n"); |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | ret = scm_protect_keystore((uint32_t *)&buffer[0],size); |
| 350 | if(ret != 0) |
| 351 | dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed"); |
Channagoud Kadabi | f84830c | 2013-04-19 14:35:47 -0700 | [diff] [blame] | 352 | |
| 353 | free(buffer); |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 354 | } |
| 355 | #endif |
| 356 | |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 357 | void target_fastboot_init(void) |
| 358 | { |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 359 | /* Set the BOOT_DONE flag in PM8921 */ |
| 360 | pm8x41_set_boot_done(); |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 361 | |
| 362 | #ifdef SSD_ENABLE |
| 363 | clock_ce_enable(SSD_CE_INSTANCE_1); |
| 364 | ssd_load_keystore_from_emmc(); |
| 365 | #endif |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 366 | } |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 367 | |
| 368 | /* Detect the target type */ |
| 369 | void target_detect(struct board_data *board) |
| 370 | { |
| 371 | board->target = LINUX_MACHTYPE_UNKNOWN; |
| 372 | } |
| 373 | |
| 374 | /* Detect the modem type */ |
| 375 | void target_baseband_detect(struct board_data *board) |
| 376 | { |
Channagoud Kadabi | f1d4442 | 2013-02-21 22:59:35 -0800 | [diff] [blame] | 377 | uint32_t platform; |
| 378 | uint32_t platform_subtype; |
| 379 | |
| 380 | platform = board->platform; |
| 381 | platform_subtype = board->platform_subtype; |
| 382 | |
| 383 | /* |
| 384 | * Look for platform subtype if present, else |
| 385 | * check for platform type to decide on the |
| 386 | * baseband type |
| 387 | */ |
| 388 | switch(platform_subtype) { |
| 389 | case HW_PLATFORM_SUBTYPE_UNKNOWN: |
| 390 | break; |
Joel King | ead31e8 | 2013-04-20 11:26:01 -0700 | [diff] [blame] | 391 | case HW_PLATFORM_SUBTYPE_MDM: |
| 392 | board->baseband = BASEBAND_MDM; |
| 393 | return; |
Channagoud Kadabi | f1d4442 | 2013-02-21 22:59:35 -0800 | [diff] [blame] | 394 | default: |
| 395 | dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype); |
| 396 | ASSERT(0); |
| 397 | }; |
| 398 | |
| 399 | switch(platform) { |
| 400 | case MSM8974: |
Deepa Dinamani | 713a76f | 2013-05-03 13:17:24 -0700 | [diff] [blame] | 401 | case MSM8274: |
| 402 | case MSM8674: |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 403 | board->baseband = BASEBAND_MSM; |
Channagoud Kadabi | f1d4442 | 2013-02-21 22:59:35 -0800 | [diff] [blame] | 404 | break; |
| 405 | case APQ8074: |
| 406 | board->baseband = BASEBAND_APQ; |
| 407 | break; |
| 408 | default: |
| 409 | dprintf(CRITICAL, "Platform type: %u is not supported\n",platform); |
| 410 | ASSERT(0); |
| 411 | }; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 412 | } |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 413 | |
Deepa Dinamani | 927a6b6 | 2013-03-28 17:05:32 -0700 | [diff] [blame] | 414 | unsigned target_baseband() |
| 415 | { |
| 416 | return board_baseband(); |
| 417 | } |
| 418 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 419 | void target_serialno(unsigned char *buf) |
| 420 | { |
| 421 | unsigned int serialno; |
| 422 | if (target_is_emmc_boot()) { |
| 423 | serialno = mmc_get_psn(); |
| 424 | snprintf((char *)buf, 13, "%x", serialno); |
| 425 | } |
| 426 | } |
Amol Jadi | 6639d45 | 2012-08-16 14:51:19 -0700 | [diff] [blame] | 427 | |
| 428 | unsigned check_reboot_mode(void) |
| 429 | { |
| 430 | uint32_t restart_reason = 0; |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 431 | uint32_t soc_ver = 0; |
| 432 | uint32_t restart_reason_addr; |
| 433 | |
| 434 | soc_ver = board_soc_version(); |
| 435 | |
| 436 | if (soc_ver >= BOARD_SOC_VERSION2) |
| 437 | restart_reason_addr = RESTART_REASON_ADDR_V2; |
| 438 | else |
| 439 | restart_reason_addr = RESTART_REASON_ADDR; |
Amol Jadi | 6639d45 | 2012-08-16 14:51:19 -0700 | [diff] [blame] | 440 | |
| 441 | /* Read reboot reason and scrub it */ |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 442 | restart_reason = readl(restart_reason_addr); |
| 443 | writel(0x00, restart_reason_addr); |
Amol Jadi | 6639d45 | 2012-08-16 14:51:19 -0700 | [diff] [blame] | 444 | |
| 445 | return restart_reason; |
| 446 | } |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 447 | |
| 448 | void reboot_device(unsigned reboot_reason) |
| 449 | { |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 450 | uint32_t soc_ver = 0; |
| 451 | |
| 452 | soc_ver = board_soc_version(); |
| 453 | |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 454 | /* Write the reboot reason */ |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 455 | if (soc_ver >= BOARD_SOC_VERSION2) |
| 456 | writel(reboot_reason, RESTART_REASON_ADDR_V2); |
| 457 | else |
| 458 | writel(reboot_reason, RESTART_REASON_ADDR); |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 459 | |
| 460 | /* Configure PMIC for warm reset */ |
Deepa Dinamani | 07f1571 | 2013-03-08 17:02:13 -0800 | [diff] [blame] | 461 | if (pmic_ver == PMIC_VERSION_V2) |
| 462 | pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET); |
| 463 | else |
| 464 | pm8x41_reset_configure(PON_PSHOLD_WARM_RESET); |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 465 | |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame] | 466 | /* Disable Watchdog Debug. |
| 467 | * Required becuase of a H/W bug which causes the system to |
| 468 | * reset partially even for non watchdog resets. |
| 469 | */ |
| 470 | writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG); |
| 471 | |
Deepa Dinamani | e0808e5 | 2012-11-26 15:22:46 -0800 | [diff] [blame] | 472 | dsb(); |
| 473 | |
| 474 | /* Wait until the write takes effect. */ |
| 475 | while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT)); |
| 476 | |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 477 | /* Drop PS_HOLD for MSM */ |
| 478 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 479 | |
| 480 | mdelay(5000); |
| 481 | |
| 482 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 483 | } |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 484 | |
Pavel Nedev | 0351149 | 2013-03-08 19:05:32 -0800 | [diff] [blame] | 485 | int set_download_mode(void) |
| 486 | { |
| 487 | dload_util_write_cookie(FORCE_DLOAD_MODE_ADDR_V2); |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
Eugene Yasman | a0d1812 | 2013-02-26 13:23:05 +0200 | [diff] [blame] | 492 | /* Do target specific usb initialization */ |
| 493 | void target_usb_init(void) |
| 494 | { |
| 495 | /* Enable secondary USB PHY on DragonBoard8074 */ |
| 496 | if (board_hardware_id() == HW_PLATFORM_DRAGON) { |
| 497 | /* Route ChipIDea to use secondary USB HS port2 */ |
| 498 | writel_relaxed(1, USB2_PHY_SEL); |
| 499 | |
| 500 | /* Enable access to secondary PHY by clamping the low |
| 501 | * voltage interface between DVDD of the PHY and Vddcx |
| 502 | * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */ |
| 503 | writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL) |
| 504 | | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL); |
| 505 | |
| 506 | /* Perform power-on-reset of the PHY. |
| 507 | * Delay values are arbitrary */ |
| 508 | writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1, |
| 509 | USB_OTG_HS_PHY_CTRL); |
| 510 | thread_sleep(10); |
| 511 | writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE, |
| 512 | USB_OTG_HS_PHY_CTRL); |
| 513 | thread_sleep(10); |
| 514 | |
| 515 | /* Enable HSUSB PHY port for ULPI interface, |
| 516 | * then configure related parameters within the PHY */ |
| 517 | writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000) |
| 518 | | 0x8c000004), USB_PORTSC); |
| 519 | } |
| 520 | } |
| 521 | |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 522 | /* Returns 1 if target supports continuous splash screen. */ |
| 523 | int target_cont_splash_screen() |
| 524 | { |
Siddhartha Agrawal | 17a6b83 | 2013-02-17 18:36:25 -0800 | [diff] [blame] | 525 | switch(board_hardware_id()) |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 526 | { |
Siddhartha Agrawal | 17a6b83 | 2013-02-17 18:36:25 -0800 | [diff] [blame] | 527 | case HW_PLATFORM_SURF: |
| 528 | case HW_PLATFORM_MTP: |
| 529 | case HW_PLATFORM_FLUID: |
Asaf Penso | b85263f | 2013-05-01 10:54:34 +0300 | [diff] [blame^] | 530 | case HW_PLATFORM_DRAGON: |
Siddhartha Agrawal | 17a6b83 | 2013-02-17 18:36:25 -0800 | [diff] [blame] | 531 | dprintf(SPEW, "Target_cont_splash=1\n"); |
| 532 | return 1; |
| 533 | break; |
| 534 | default: |
| 535 | dprintf(SPEW, "Target_cont_splash=0\n"); |
| 536 | return 0; |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 537 | } |
| 538 | } |
sundarajan srinivasan | b5db0a9 | 2013-02-12 19:19:27 -0800 | [diff] [blame] | 539 | |
| 540 | unsigned target_pause_for_battery_charge(void) |
| 541 | { |
| 542 | uint8_t pon_reason = pm8x41_get_pon_reason(); |
| 543 | |
| 544 | /* This function will always return 0 to facilitate |
| 545 | * automated testing/reboot with usb connected. |
| 546 | * uncomment if this feature is needed */ |
| 547 | /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG)) |
| 548 | return 1;*/ |
| 549 | |
| 550 | return 0; |
| 551 | } |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 552 | |
| 553 | void target_usb_stop(void) |
| 554 | { |
| 555 | #ifdef SSD_ENABLE |
| 556 | clock_ce_disable(SSD_CE_INSTANCE_1); |
| 557 | #endif |
| 558 | } |
Deepa Dinamani | 65df982 | 2013-03-08 13:38:34 -0800 | [diff] [blame] | 559 | |
| 560 | void shutdown_device() |
| 561 | { |
| 562 | dprintf(CRITICAL, "Going down for shutdown.\n"); |
| 563 | |
| 564 | /* Configure PMIC for shutdown. */ |
| 565 | if (pmic_ver == PMIC_VERSION_V2) |
| 566 | pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN); |
| 567 | else |
| 568 | pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN); |
| 569 | |
| 570 | /* Drop PS_HOLD for MSM */ |
| 571 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 572 | |
| 573 | mdelay(5000); |
| 574 | |
| 575 | dprintf(CRITICAL, "Shutdown failed\n"); |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | static void set_sdc_power_ctrl() |
| 579 | { |
| 580 | /* Drive strength configs for sdc pins */ |
| 581 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 582 | { |
| 583 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK }, |
| 584 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
| 585 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
| 586 | }; |
| 587 | |
| 588 | /* Pull configs for sdc pins */ |
| 589 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 590 | { |
| 591 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK }, |
| 592 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 593 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 594 | }; |
| 595 | |
| 596 | /* Set the drive strength & pull control values */ |
| 597 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 598 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 599 | } |
Stanimir Varbanov | f64a029 | 2013-04-29 11:58:27 +0300 | [diff] [blame] | 600 | |
| 601 | int emmc_recovery_init(void) |
| 602 | { |
| 603 | return _emmc_recovery_init(); |
| 604 | } |