blob: f56bf2fddaa681d9ce52cd0b7ec30cd54d275058 [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 */
397 dprintf(INFO, "calling vibrator enable\n");
398 vibrator_enable();
399 /* Vibrator end */
400
wangxl1ddbd092015-02-03 20:31:24 +0800401 /*
402 * Set drive strength & pull ctrl for
403 * emmc
404 */
405 set_sdc_power_ctrl();
406
407#if MMC_SDHCI_SUPPORT
408 target_mmc_sdhci_init();
409#else
410 target_mmc_mci_init();
411#endif
412}
413
414unsigned board_machtype(void)
415{
416 return target_id;
417}
418
419/* Do any target specific intialization needed before entering fastboot mode */
420#ifdef SSD_ENABLE
421static void ssd_load_keystore_from_emmc()
422{
423 uint64_t ptn = 0;
424 int index = -1;
425 uint32_t size = SSD_PARTITION_SIZE;
426 int ret = -1;
427
428 uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE,
429 ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE));
430
431 if (!buffer) {
432 dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n");
433 ASSERT(0);
434 }
435
436 index = partition_get_index("ssd");
437
438 ptn = partition_get_offset(index);
439 if(ptn == 0){
440 dprintf(CRITICAL,"ERROR: ssd parition not found");
441 return;
442 }
443
444 if(mmc_read(ptn, buffer, size)){
445 dprintf(CRITICAL,"ERROR:Cannot read data\n");
446 return;
447 }
448
449 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
450 if(ret != 0)
451 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
452
453 free(buffer);
454}
455#endif
456
457void target_fastboot_init(void)
458{
459 /* Set the BOOT_DONE flag in PM8921 */
460 pm8x41_set_boot_done();
461
462#ifdef SSD_ENABLE
463 clock_ce_enable(SSD_CE_INSTANCE_1);
464 ssd_load_keystore_from_emmc();
465#endif
466}
467
468/* Detect the target type */
469void target_detect(struct board_data *board)
470{
471 board->target = LINUX_MACHTYPE_UNKNOWN;
472}
473
474/* Detect the modem type */
475void target_baseband_detect(struct board_data *board)
476{
477 uint32_t platform;
478 uint32_t platform_subtype;
479
480 platform = board->platform;
481
482 switch(platform) {
483 case MSM8974:
484 case MSM8274:
485 case MSM8674:
486 case MSM8274AA:
487 case MSM8274AB:
488 case MSM8274AC:
489 case MSM8674AA:
490 case MSM8674AB:
491 case MSM8674AC:
492 case MSM8974AA:
493 case MSM8974AB:
494 case MSM8974AC:
495 case MSMSAMARIUM2:
496 case MSMSAMARIUM9:
497 board->baseband = BASEBAND_MSM;
498 break;
499 case APQ8074:
500 case APQ8074AA:
501 case APQ8074AB:
502 case APQ8074AC:
503 case MSMSAMARIUM0:
504 board->baseband = BASEBAND_APQ;
505 break;
506 default:
507 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
508 ASSERT(0);
509 };
510}
511
512unsigned target_baseband()
513{
514 return board_baseband();
515}
516
517void target_serialno(unsigned char *buf)
518{
519 unsigned int serialno;
520 if (target_is_emmc_boot()) {
521 serialno = mmc_get_psn();
522 snprintf((char *)buf, 13, "%x", serialno);
523 }
524}
525
526unsigned check_reboot_mode(void)
527{
528 uint32_t restart_reason = 0;
529 uint32_t soc_ver = 0;
530 uint32_t restart_reason_addr;
531
532 soc_ver = board_soc_version();
533
534 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
535 restart_reason_addr = RESTART_REASON_ADDR;
536 else
537 restart_reason_addr = RESTART_REASON_ADDR_V2;
538
539 /* Read reboot reason and scrub it */
540 restart_reason = readl(restart_reason_addr);
541 writel(0x00, restart_reason_addr);
542
543 return restart_reason;
544}
545
546void reboot_device(unsigned reboot_reason)
547{
548 uint32_t soc_ver = 0;
549 uint8_t reset_type = 0;
550
551 soc_ver = board_soc_version();
552
553 /* Write the reboot reason */
554 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
555 writel(reboot_reason, RESTART_REASON_ADDR);
556 else
557 writel(reboot_reason, RESTART_REASON_ADDR_V2);
558
559 if(reboot_reason == FASTBOOT_MODE)
560 reset_type = PON_PSHOLD_WARM_RESET;
561 else
562 reset_type = PON_PSHOLD_HARD_RESET;
563
564 /* Configure PMIC for warm reset */
565 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
566 pm8x41_v2_reset_configure(reset_type);
567 else
568 pm8x41_reset_configure(reset_type);
569
570 /* Drop PS_HOLD for MSM */
571 writel(0x00, MPM2_MPM_PS_HOLD);
572
573 mdelay(5000);
574
575 dprintf(CRITICAL, "Rebooting failed\n");
576}
577
578int set_download_mode(enum dload_mode mode)
579{
580 dload_util_write_cookie(mode == NORMAL_DLOAD ?
581 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
582
583 return 0;
584}
585
586/* Check if MSM needs VBUS mimic for USB */
587static int target_needs_vbus_mimic()
588{
589 if (target_is_8974())
590 return 0;
591
592 return 1;
593}
594
595/* Do target specific usb initialization */
596void target_usb_init(void)
597{
598 uint32_t val;
599
600 /* Enable secondary USB PHY on DragonBoard8074 */
601 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
602 /* Route ChipIDea to use secondary USB HS port2 */
603 writel_relaxed(1, USB2_PHY_SEL);
604
605 /* Enable access to secondary PHY by clamping the low
606 * voltage interface between DVDD of the PHY and Vddcx
607 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
608 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
609 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
610
611 /* Perform power-on-reset of the PHY.
612 * Delay values are arbitrary */
613 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
614 USB_OTG_HS_PHY_CTRL);
615 thread_sleep(10);
616 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
617 USB_OTG_HS_PHY_CTRL);
618 thread_sleep(10);
619
620 /* Enable HSUSB PHY port for ULPI interface,
621 * then configure related parameters within the PHY */
622 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
623 | 0x8c000004), USB_PORTSC);
624 }
625
626 if (target_needs_vbus_mimic())
627 {
628 /* Select and enable external configuration with USB PHY */
629 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
630
631 /* Enable sess_vld */
632 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
633 writel(val, USB_GENCONFIG_2);
634
635 /* Enable external vbus configuration in the LINK */
636 val = readl(USB_USBCMD);
637 val |= SESS_VLD_CTRL;
638 writel(val, USB_USBCMD);
639 }
640}
641
642uint8_t target_panel_auto_detect_enabled()
643{
644 switch(board_hardware_id())
645 {
646 case HW_PLATFORM_SURF:
647 case HW_PLATFORM_MTP:
648 case HW_PLATFORM_FLUID:
649 return 1;
650 break;
651 default:
652 return 0;
653 break;
654 }
655 return 0;
656}
657
658uint8_t target_is_edp()
659{
660 switch(board_hardware_id())
661 {
662 case HW_PLATFORM_LIQUID:
663 return 1;
664 break;
665 default:
666 return 0;
667 break;
668 }
669 return 0;
670}
671
672static uint8_t splash_override;
673/* Returns 1 if target supports continuous splash screen. */
674int target_cont_splash_screen()
675{
676 uint8_t splash_screen = 0;
677 if(!splash_override) {
678 switch(board_hardware_id())
679 {
680 case HW_PLATFORM_SURF:
681 case HW_PLATFORM_MTP:
682 case HW_PLATFORM_FLUID:
683 case HW_PLATFORM_DRAGON:
684 case HW_PLATFORM_LIQUID:
685 dprintf(SPEW, "Target_cont_splash=1\n");
686 splash_screen = 1;
687 break;
688 default:
689 dprintf(SPEW, "Target_cont_splash=0\n");
690 splash_screen = 0;
691 }
692 }
693 return splash_screen;
694}
695
696void target_force_cont_splash_disable(uint8_t override)
697{
698 splash_override = override;
699}
700
701unsigned target_pause_for_battery_charge(void)
702{
703 uint8_t pon_reason = pm8x41_get_pon_reason();
704
705 /* This function will always return 0 to facilitate
706 * automated testing/reboot with usb connected.
707 * uncomment if this feature is needed */
708 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
709 return 1;*/
710
711 return 0;
712}
713
714void target_uninit(void)
715{
716#if MMC_SDHCI_SUPPORT
717 mmc_put_card_to_sleep(dev);
718#else
719 mmc_put_card_to_sleep();
720#endif
721#ifdef SSD_ENABLE
722 clock_ce_disable(SSD_CE_INSTANCE_1);
723#endif
724 if (crypto_initialized())
725 crypto_eng_cleanup();
726
727 /* Disable HC mode before jumping to kernel */
728 sdhci_mode_disable(&dev->host);
729}
730
731void shutdown_device()
732{
733 dprintf(CRITICAL, "Going down for shutdown.\n");
734
735 /* Configure PMIC for shutdown. */
736 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
737 pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN);
738 else
739 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
740
741 /* Drop PS_HOLD for MSM */
742 writel(0x00, MPM2_MPM_PS_HOLD);
743
744 mdelay(5000);
745
746 dprintf(CRITICAL, "Shutdown failed\n");
747}
748
749static void set_sdc_power_ctrl()
750{
751 uint8_t tlmm_hdrv_clk = 0;
752 uint32_t platform_id = 0;
753
754 platform_id = board_platform_id();
755
756 switch(platform_id)
757 {
758 case MSM8274AA:
759 case MSM8274AB:
760 case MSM8674AA:
761 case MSM8674AB:
762 case MSM8974AA:
763 case MSM8974AB:
764 if (board_hardware_id() == HW_PLATFORM_MTP)
765 tlmm_hdrv_clk = TLMM_CUR_VAL_10MA;
766 else
767 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
768 break;
769 default:
770 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
771 };
772
773 /* Drive strength configs for sdc pins */
774 struct tlmm_cfgs sdc1_hdrv_cfg[] =
775 {
776 { SDC1_CLK_HDRV_CTL_OFF, tlmm_hdrv_clk, TLMM_HDRV_MASK },
777 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
778 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
779 };
780
781 /* Pull configs for sdc pins */
782 struct tlmm_cfgs sdc1_pull_cfg[] =
783 {
784 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
785 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
786 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
787 };
788
789 struct tlmm_cfgs sdc1_rclk_cfg[] =
790 {
791 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK },
792 };
793
794 /* Set the drive strength & pull control values */
795 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
796 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
797
798 /* RCLK is supported only with 8974 pro, set rclk to pull down
799 * only for 8974 pro targets
800 */
801 if (!platform_is_8974())
802 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
803}
804
805int emmc_recovery_init(void)
806{
807 return _emmc_recovery_init();
808}
809
810void target_usb_stop(void)
811{
812 uint32_t platform = board_platform_id();
813
814 /* Disable VBUS mimicing in the controller. */
815 if (target_needs_vbus_mimic())
816 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
817}