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