blob: c15bb5971fa7fcd48bdc19667113ba66bc329328 [file] [log] [blame]
wangxl1ddbd092015-02-03 20:31:24 +08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <platform/iomap.h>
31#include <platform/irqs.h>
32#include <platform/gpio.h>
33#include <reg.h>
34#include <target.h>
35#include <platform.h>
36#include <dload_util.h>
37#include <uart_dm.h>
38#include <mmc.h>
39#include <spmi.h>
40#include <board.h>
41#include <smem.h>
42#include <baseband.h>
43#include <dev/keys.h>
44#include <pm8x41.h>
45#include <crypto5_wrapper.h>
46#include <hsusb.h>
47#include <clock.h>
48#include <partition_parser.h>
49#include <scm.h>
50#include <platform/clock.h>
51#include <platform/gpio.h>
52#include <stdlib.h>
53
54enum hw_platform_subtype
55{
56 HW_PLATFORM_SUBTYPE_CDP_INTERPOSER = 8,
57};
58
59extern bool target_use_signed_kernel(void);
60static void set_sdc_power_ctrl();
61
62static unsigned int target_id;
63static uint32_t pmic_ver;
64
65#if MMC_SDHCI_SUPPORT
66struct mmc_device *dev;
67#endif
68
69#define PMIC_ARB_CHANNEL_NUM 0
70#define PMIC_ARB_OWNER_ID 0
71
72#define WDOG_DEBUG_DISABLE_BIT 17
73
74#define CE_INSTANCE 2
75#define CE_EE 1
76#define CE_FIFO_SIZE 64
77#define CE_READ_PIPE 3
78#define CE_WRITE_PIPE 2
79#define CE_READ_PIPE_LOCK_GRP 0
80#define CE_WRITE_PIPE_LOCK_GRP 0
81#define CE_ARRAY_SIZE 20
82
83#ifdef SSD_ENABLE
84#define SSD_CE_INSTANCE_1 1
85#define SSD_PARTITION_SIZE 8192
86#endif
87
88#define FASTBOOT_MODE 0x77665500
89
90#define BOARD_SOC_VERSION1(soc_rev) (soc_rev >= 0x10000 && soc_rev < 0x20000)
91
92#if MMC_SDHCI_SUPPORT
93static uint32_t mmc_sdhci_base[] =
94 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE, MSM_SDC4_SDHCI_BASE };
95#endif
96
97static uint32_t mmc_sdc_base[] =
98 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
99
100static uint32_t mmc_sdc_pwrctl_irq[] =
101 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ, SDCC3_PWRCTL_IRQ, SDCC4_PWRCTL_IRQ };
102
103void target_early_init(void)
104{
105#if WITH_DEBUG_UART
106 uart_dm_init(1, 0, BLSP1_UART1_BASE);
107#endif
108}
109
110/* Check for 8974 chip */
111static int target_is_8974()
112{
113 uint32_t platform = board_platform_id();
114 int ret = 0;
115
116 switch(platform)
117 {
118 case APQ8074:
119 case MSM8274:
120 case MSM8674:
121 case MSM8974:
122 ret = 1;
123 break;
124 default:
125 ret = 0;
126 };
127
128 return ret;
129}
130
131/* Return 1 if vol_up pressed */
132static int target_volume_up()
133{
134 uint8_t status = 0;
135 struct pm8x41_gpio gpio;
136
137 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
138 * whether key is pressed or not.
139 * Ignore volume_up key on CDP for now.
140 */
141 if (board_hardware_id() == HW_PLATFORM_SURF)
142 return 0;
143
144 /* Configure the GPIO */
145 gpio.direction = PM_GPIO_DIR_IN;
146 gpio.function = 0;
147 gpio.pull = PM_GPIO_PULL_UP_30;
148 gpio.vin_sel = 2;
149
150 pm8x41_gpio_config(5, &gpio);
151
152 /* Wait for the pmic gpio config to take effect */
153 thread_sleep(1);
154
155 /* Get status of P_GPIO_5 */
156 pm8x41_gpio_get(5, &status);
157
158 return !status; /* active low */
159}
160
161/* Return 1 if vol_down pressed */
162uint32_t target_volume_down()
163{
wangxl68432522015-02-04 11:04:42 +0800164 uint8_t status = 0;
165 struct pm8x41_gpio gpio;
166
167 if (board_hardware_id() == HW_PLATFORM_SURF)
168 return 0;
169
170 /* Configure the GPIO */
171 gpio.direction = PM_GPIO_DIR_IN;
172 gpio.function = 0;
173 gpio.pull = PM_GPIO_PULL_UP_30;
174 gpio.vin_sel = 2;
175
176 pm8x41_gpio_config(2, &gpio);
177
178 /* Wait for the pmic gpio config to take effect */
179 thread_sleep(1);
180
181 /* Get status of P_GPIO_2 */
182 pm8x41_gpio_get(2, &status);
183
184 return !status; /* active low */
wangxl1ddbd092015-02-03 20:31:24 +0800185}
186
187static void target_keystatus()
188{
189 keys_init();
190
191 if(target_volume_down())
192 keys_post_event(KEY_VOLUMEDOWN, 1);
193
194 if(target_volume_up())
195 keys_post_event(KEY_VOLUMEUP, 1);
196}
197
198/* Set up params for h/w CE. */
199void target_crypto_init_params()
200{
201 struct crypto_init_params ce_params;
202
203 /* Set up base addresses and instance. */
204 ce_params.crypto_instance = CE_INSTANCE;
205 ce_params.crypto_base = MSM_CE2_BASE;
206 ce_params.bam_base = MSM_CE2_BAM_BASE;
207
208 /* Set up BAM config. */
209 ce_params.bam_ee = CE_EE;
210 ce_params.pipes.read_pipe = CE_READ_PIPE;
211 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
212 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
213 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
214
215 /* Assign buffer sizes. */
216 ce_params.num_ce = CE_ARRAY_SIZE;
217 ce_params.read_fifo_size = CE_FIFO_SIZE;
218 ce_params.write_fifo_size = CE_FIFO_SIZE;
219
220 /* BAM is initialized by TZ for this platform.
221 * Do not do it again as the initialization address space
222 * is locked.
223 */
224 ce_params.do_bam_init = 0;
225
226 crypto_init_params(&ce_params);
227}
228
229crypto_engine_type board_ce_type(void)
230{
231 return CRYPTO_ENGINE_TYPE_HW;
232}
233
234#if MMC_SDHCI_SUPPORT
235static void target_mmc_sdhci_init()
236{
237 struct mmc_config_data config = {0};
238 uint32_t soc_ver = 0;
239
240 soc_ver = board_soc_version();
241
242 /*
243 * 8974 v1 fluid devices, have a hardware bug
244 * which limits the bus width to 4 bit.
245 */
246 switch(board_hardware_id())
247 {
248 case HW_PLATFORM_FLUID:
249 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
250 config.bus_width = DATA_BUS_WIDTH_4BIT;
251 else
252 config.bus_width = DATA_BUS_WIDTH_8BIT;
253 break;
254 default:
255 config.bus_width = DATA_BUS_WIDTH_8BIT;
256 };
257
258 /* Trying Slot 1*/
259 config.slot = 1;
260 /*
261 * For 8974 AC platform the software clock
262 * plan recommends to use the following frequencies:
263 * 200 MHz --> 192 MHZ
264 * 400 MHZ --> 384 MHZ
265 * only for emmc slot
266 */
267 if (platform_is_8974ac())
268 config.max_clk_rate = MMC_CLK_192MHZ;
269 else
270 config.max_clk_rate = MMC_CLK_200MHZ;
271 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
272 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
273 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
274
275 if (!(dev = mmc_init(&config))) {
276 /* Trying Slot 2 next */
277 config.slot = 2;
278 config.max_clk_rate = MMC_CLK_200MHZ;
279 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
280 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
281 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
282
283 if (!(dev = mmc_init(&config))) {
284 dprintf(CRITICAL, "mmc init failed!");
285 ASSERT(0);
286 }
287 }
288
289 /*
290 * MMC initialization is complete, read the partition table info
291 */
292 if (partition_read_table()) {
293 dprintf(CRITICAL, "Error reading the partition table info\n");
294 ASSERT(0);
295 }
296}
297
298struct mmc_device *target_mmc_device()
299{
300 return dev;
301}
302
303#else
304static void target_mmc_mci_init()
305{
306 uint32_t base_addr;
307 uint8_t slot;
308
309 /* Trying Slot 1 */
310 slot = 1;
311 base_addr = mmc_sdc_base[slot - 1];
312
313 if (mmc_boot_main(slot, base_addr))
314 {
315 /* Trying Slot 2 next */
316 slot = 2;
317 base_addr = mmc_sdc_base[slot - 1];
318 if (mmc_boot_main(slot, base_addr)) {
319 dprintf(CRITICAL, "mmc init failed!");
320 ASSERT(0);
321 }
322 }
323}
324
325/*
326 * Function to set the capabilities for the host
327 */
328void target_mmc_caps(struct mmc_host *host)
329{
330 uint32_t soc_ver = 0;
331
332 soc_ver = board_soc_version();
333
334 /*
335 * 8974 v1 fluid devices, have a hardware bug
336 * which limits the bus width to 4 bit.
337 */
338 switch(board_hardware_id())
339 {
340 case HW_PLATFORM_FLUID:
341 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
342 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
343 else
344 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
345 break;
346 default:
347 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
348 };
349
350 host->caps.ddr_mode = 1;
351 host->caps.hs200_mode = 1;
352 host->caps.hs_clk_rate = MMC_CLK_96MHZ;
353}
354#endif
355
chenxl072348dc4322015-05-11 13:48:24 +0800356#define DRV2603_VIBRATOR_EN 86
357#define DRV2603_VIBRATOR_PWM 85
358#define FUNC_GPIO 0
359
360/* Vibrator enable */
361void vibrator_enable()
362{
363 uint32_t pm8x41_ldo_base = 0x13F00;
364 struct pm8x41_ldo ldo18 = LDO(pm8x41_ldo_base + 0x100 * 18, 0);
365 /* Turn on LDO18 for Vibrator */
366 pm8x41_ldo_set_voltage(&ldo18, 2850000);
367 pm8x41_ldo_control(&ldo18, 1);
368 dprintf(INFO,"%s \n",__func__);
369 udelay(200);
370 gpio_tlmm_config(DRV2603_VIBRATOR_PWM, FUNC_GPIO, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA, GPIO_DISABLE);
371 gpio_set(85, 2);
372 udelay(200);
373 gpio_tlmm_config(DRV2603_VIBRATOR_EN, FUNC_GPIO, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA, GPIO_DISABLE);
374 gpio_set(86, 2);
375 mdelay(200);
376 gpio_tlmm_config(DRV2603_VIBRATOR_EN, FUNC_GPIO, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
377 gpio_tlmm_config(DRV2603_VIBRATOR_PWM, FUNC_GPIO, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
378 pm8x41_ldo_control(&ldo18, 0);
379}
380/* Vibrator end */
wangxl1ddbd092015-02-03 20:31:24 +0800381
382void target_init(void)
383{
384 dprintf(INFO, "target_init()\n");
385
386 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
387
388 /* Save PM8941 version info. */
389 pmic_ver = pm8x41_get_pmic_rev();
390
391 target_keystatus();
392
393 if (target_use_signed_kernel())
394 target_crypto_init_params();
395
chenxl072348dc4322015-05-11 13:48:24 +0800396 /* Vibrator start */
wangxl4b8e0d32016-01-05 17:14:27 +0800397 if (!target_pause_for_battery_charge()){
398 dprintf(INFO, "calling vibrator enable\n");
399 vibrator_enable();
400 }
chenxl072348dc4322015-05-11 13:48:24 +0800401 /* Vibrator end */
402
wangxl1ddbd092015-02-03 20:31:24 +0800403 /*
404 * Set drive strength & pull ctrl for
405 * emmc
406 */
407 set_sdc_power_ctrl();
408
409#if MMC_SDHCI_SUPPORT
410 target_mmc_sdhci_init();
411#else
412 target_mmc_mci_init();
413#endif
414}
415
416unsigned board_machtype(void)
417{
418 return target_id;
419}
420
421/* Do any target specific intialization needed before entering fastboot mode */
422#ifdef SSD_ENABLE
423static void ssd_load_keystore_from_emmc()
424{
425 uint64_t ptn = 0;
426 int index = -1;
427 uint32_t size = SSD_PARTITION_SIZE;
428 int ret = -1;
429
430 uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE,
431 ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE));
432
433 if (!buffer) {
434 dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n");
435 ASSERT(0);
436 }
437
438 index = partition_get_index("ssd");
439
440 ptn = partition_get_offset(index);
441 if(ptn == 0){
442 dprintf(CRITICAL,"ERROR: ssd parition not found");
443 return;
444 }
445
446 if(mmc_read(ptn, buffer, size)){
447 dprintf(CRITICAL,"ERROR:Cannot read data\n");
448 return;
449 }
450
451 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
452 if(ret != 0)
453 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
454
455 free(buffer);
456}
457#endif
458
459void target_fastboot_init(void)
460{
461 /* Set the BOOT_DONE flag in PM8921 */
462 pm8x41_set_boot_done();
463
464#ifdef SSD_ENABLE
465 clock_ce_enable(SSD_CE_INSTANCE_1);
466 ssd_load_keystore_from_emmc();
467#endif
468}
469
470/* Detect the target type */
471void target_detect(struct board_data *board)
472{
473 board->target = LINUX_MACHTYPE_UNKNOWN;
474}
475
476/* Detect the modem type */
477void target_baseband_detect(struct board_data *board)
478{
479 uint32_t platform;
480 uint32_t platform_subtype;
481
482 platform = board->platform;
483
484 switch(platform) {
485 case MSM8974:
486 case MSM8274:
487 case MSM8674:
488 case MSM8274AA:
489 case MSM8274AB:
490 case MSM8274AC:
491 case MSM8674AA:
492 case MSM8674AB:
493 case MSM8674AC:
494 case MSM8974AA:
495 case MSM8974AB:
496 case MSM8974AC:
497 case MSMSAMARIUM2:
498 case MSMSAMARIUM9:
499 board->baseband = BASEBAND_MSM;
500 break;
501 case APQ8074:
502 case APQ8074AA:
503 case APQ8074AB:
504 case APQ8074AC:
505 case MSMSAMARIUM0:
506 board->baseband = BASEBAND_APQ;
507 break;
508 default:
509 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
510 ASSERT(0);
511 };
512}
513
514unsigned target_baseband()
515{
516 return board_baseband();
517}
518
519void target_serialno(unsigned char *buf)
520{
521 unsigned int serialno;
522 if (target_is_emmc_boot()) {
523 serialno = mmc_get_psn();
524 snprintf((char *)buf, 13, "%x", serialno);
525 }
526}
527
528unsigned check_reboot_mode(void)
529{
530 uint32_t restart_reason = 0;
531 uint32_t soc_ver = 0;
532 uint32_t restart_reason_addr;
533
534 soc_ver = board_soc_version();
535
536 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
537 restart_reason_addr = RESTART_REASON_ADDR;
538 else
539 restart_reason_addr = RESTART_REASON_ADDR_V2;
540
541 /* Read reboot reason and scrub it */
542 restart_reason = readl(restart_reason_addr);
543 writel(0x00, restart_reason_addr);
544
545 return restart_reason;
546}
547
548void reboot_device(unsigned reboot_reason)
549{
550 uint32_t soc_ver = 0;
551 uint8_t reset_type = 0;
552
553 soc_ver = board_soc_version();
554
555 /* Write the reboot reason */
556 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
557 writel(reboot_reason, RESTART_REASON_ADDR);
558 else
559 writel(reboot_reason, RESTART_REASON_ADDR_V2);
560
561 if(reboot_reason == FASTBOOT_MODE)
562 reset_type = PON_PSHOLD_WARM_RESET;
563 else
564 reset_type = PON_PSHOLD_HARD_RESET;
565
566 /* Configure PMIC for warm reset */
567 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
568 pm8x41_v2_reset_configure(reset_type);
569 else
570 pm8x41_reset_configure(reset_type);
571
572 /* Drop PS_HOLD for MSM */
573 writel(0x00, MPM2_MPM_PS_HOLD);
574
575 mdelay(5000);
576
577 dprintf(CRITICAL, "Rebooting failed\n");
578}
579
580int set_download_mode(enum dload_mode mode)
581{
582 dload_util_write_cookie(mode == NORMAL_DLOAD ?
583 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
584
585 return 0;
586}
587
588/* Check if MSM needs VBUS mimic for USB */
589static int target_needs_vbus_mimic()
590{
591 if (target_is_8974())
592 return 0;
593
594 return 1;
595}
596
597/* Do target specific usb initialization */
598void target_usb_init(void)
599{
600 uint32_t val;
601
602 /* Enable secondary USB PHY on DragonBoard8074 */
603 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
604 /* Route ChipIDea to use secondary USB HS port2 */
605 writel_relaxed(1, USB2_PHY_SEL);
606
607 /* Enable access to secondary PHY by clamping the low
608 * voltage interface between DVDD of the PHY and Vddcx
609 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
610 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
611 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
612
613 /* Perform power-on-reset of the PHY.
614 * Delay values are arbitrary */
615 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
616 USB_OTG_HS_PHY_CTRL);
617 thread_sleep(10);
618 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
619 USB_OTG_HS_PHY_CTRL);
620 thread_sleep(10);
621
622 /* Enable HSUSB PHY port for ULPI interface,
623 * then configure related parameters within the PHY */
624 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
625 | 0x8c000004), USB_PORTSC);
626 }
627
628 if (target_needs_vbus_mimic())
629 {
630 /* Select and enable external configuration with USB PHY */
631 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
632
633 /* Enable sess_vld */
634 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
635 writel(val, USB_GENCONFIG_2);
636
637 /* Enable external vbus configuration in the LINK */
638 val = readl(USB_USBCMD);
639 val |= SESS_VLD_CTRL;
640 writel(val, USB_USBCMD);
641 }
642}
643
644uint8_t target_panel_auto_detect_enabled()
645{
646 switch(board_hardware_id())
647 {
648 case HW_PLATFORM_SURF:
649 case HW_PLATFORM_MTP:
650 case HW_PLATFORM_FLUID:
651 return 1;
652 break;
653 default:
654 return 0;
655 break;
656 }
657 return 0;
658}
659
660uint8_t target_is_edp()
661{
662 switch(board_hardware_id())
663 {
664 case HW_PLATFORM_LIQUID:
665 return 1;
666 break;
667 default:
668 return 0;
669 break;
670 }
671 return 0;
672}
673
674static uint8_t splash_override;
675/* Returns 1 if target supports continuous splash screen. */
676int target_cont_splash_screen()
677{
678 uint8_t splash_screen = 0;
679 if(!splash_override) {
680 switch(board_hardware_id())
681 {
682 case HW_PLATFORM_SURF:
683 case HW_PLATFORM_MTP:
684 case HW_PLATFORM_FLUID:
685 case HW_PLATFORM_DRAGON:
686 case HW_PLATFORM_LIQUID:
687 dprintf(SPEW, "Target_cont_splash=1\n");
688 splash_screen = 1;
689 break;
690 default:
691 dprintf(SPEW, "Target_cont_splash=0\n");
692 splash_screen = 0;
693 }
694 }
695 return splash_screen;
696}
697
698void target_force_cont_splash_disable(uint8_t override)
699{
700 splash_override = override;
701}
702
703unsigned target_pause_for_battery_charge(void)
704{
705 uint8_t pon_reason = pm8x41_get_pon_reason();
Ameya Thakur5969c9a2013-06-25 13:46:21 -0700706 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
Ameya Thakurfe7e8d32013-07-17 16:53:53 -0700707 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
708 pon_reason, is_cold_boot);
Ameya Thakur0ed4bb22013-07-19 17:52:51 -0700709 /* In case of fastboot reboot,adb reboot or if we see the power key
710 * pressed we do not want go into charger mode.
Ameya Thakurfe7e8d32013-07-17 16:53:53 -0700711 * fastboot reboot is warm boot with PON hard reset bit not set
712 * adb reboot is a cold boot with PON hard reset bit set
713 */
Ameya Thakur0ed4bb22013-07-19 17:52:51 -0700714 if (is_cold_boot &&
715 (!(pon_reason & HARD_RST)) &&
716 (!(pon_reason & KPDPWR_N)) &&
Ameya Thakurfe7e8d32013-07-17 16:53:53 -0700717 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG)))
718 return 1;
719 else
720 return 0;
wangxl1ddbd092015-02-03 20:31:24 +0800721}
722
723void target_uninit(void)
724{
725#if MMC_SDHCI_SUPPORT
726 mmc_put_card_to_sleep(dev);
727#else
728 mmc_put_card_to_sleep();
729#endif
730#ifdef SSD_ENABLE
731 clock_ce_disable(SSD_CE_INSTANCE_1);
732#endif
733 if (crypto_initialized())
734 crypto_eng_cleanup();
735
736 /* Disable HC mode before jumping to kernel */
737 sdhci_mode_disable(&dev->host);
738}
739
740void shutdown_device()
741{
742 dprintf(CRITICAL, "Going down for shutdown.\n");
743
744 /* Configure PMIC for shutdown. */
745 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
746 pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN);
747 else
748 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
749
750 /* Drop PS_HOLD for MSM */
751 writel(0x00, MPM2_MPM_PS_HOLD);
752
753 mdelay(5000);
754
755 dprintf(CRITICAL, "Shutdown failed\n");
756}
757
758static void set_sdc_power_ctrl()
759{
760 uint8_t tlmm_hdrv_clk = 0;
761 uint32_t platform_id = 0;
762
763 platform_id = board_platform_id();
764
765 switch(platform_id)
766 {
767 case MSM8274AA:
768 case MSM8274AB:
769 case MSM8674AA:
770 case MSM8674AB:
771 case MSM8974AA:
772 case MSM8974AB:
773 if (board_hardware_id() == HW_PLATFORM_MTP)
774 tlmm_hdrv_clk = TLMM_CUR_VAL_10MA;
775 else
776 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
777 break;
778 default:
779 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
780 };
781
782 /* Drive strength configs for sdc pins */
783 struct tlmm_cfgs sdc1_hdrv_cfg[] =
784 {
785 { SDC1_CLK_HDRV_CTL_OFF, tlmm_hdrv_clk, TLMM_HDRV_MASK },
786 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
787 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
788 };
789
790 /* Pull configs for sdc pins */
791 struct tlmm_cfgs sdc1_pull_cfg[] =
792 {
793 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
794 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
795 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
796 };
797
798 struct tlmm_cfgs sdc1_rclk_cfg[] =
799 {
800 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK },
801 };
802
803 /* Set the drive strength & pull control values */
804 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
805 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
806
807 /* RCLK is supported only with 8974 pro, set rclk to pull down
808 * only for 8974 pro targets
809 */
810 if (!platform_is_8974())
811 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
812}
813
814int emmc_recovery_init(void)
815{
816 return _emmc_recovery_init();
817}
818
819void target_usb_stop(void)
820{
821 uint32_t platform = board_platform_id();
822
823 /* Disable VBUS mimicing in the controller. */
824 if (target_needs_vbus_mimic())
825 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
826}