blob: 0c711debdea03e7d83ad124d0fc7bff4e64b2597 [file] [log] [blame]
Aparna Mallavarapuca676882015-01-19 20:39:06 +05301/* Copyright (c) 2015, 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 <reg.h>
32#include <target.h>
33#include <platform.h>
34#include <uart_dm.h>
35#include <mmc.h>
36#include <platform/gpio.h>
37#include <dev/keys.h>
38#include <spmi_v2.h>
39#include <pm8x41.h>
Aparna Mallavarapubc6315e2015-04-11 04:00:43 +053040#include <pm8x41_hw.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053041#include <board.h>
42#include <baseband.h>
43#include <hsusb.h>
44#include <scm.h>
45#include <platform/gpio.h>
46#include <platform/gpio.h>
47#include <platform/irqs.h>
48#include <platform/clock.h>
Aparna Mallavarapubc6315e2015-04-11 04:00:43 +053049#include <platform/timer.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053050#include <crypto5_wrapper.h>
51#include <partition_parser.h>
52#include <stdlib.h>
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +053053#include <rpm-smd.h>
Aparna Mallavarapubc6315e2015-04-11 04:00:43 +053054#include <spmi.h>
55#include <sdhci_msm.h>
56#include <clock.h>
Parth Dixit6e6bad52015-07-30 19:02:38 +053057#include <boot_device.h>
58#include <secapp_loader.h>
59#include <rpmb.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053060
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -070061#include "target/display.h"
62
Aparna Mallavarapuca676882015-01-19 20:39:06 +053063#if LONG_PRESS_POWER_ON
64#include <shutdown_detect.h>
65#endif
66
Matthew Qin47dfdb72015-06-10 21:29:11 +080067#if PON_VIB_SUPPORT
68#include <vibrator.h>
69#endif
70
71#if PON_VIB_SUPPORT
72#define VIBRATE_TIME 250
73#endif
74
Aparna Mallavarapuca676882015-01-19 20:39:06 +053075#define PMIC_ARB_CHANNEL_NUM 0
76#define PMIC_ARB_OWNER_ID 0
77#define TLMM_VOL_UP_BTN_GPIO 85
Unnati Gandhife004a92015-06-01 13:06:06 +053078#define TLMM_VOL_UP_BTN_GPIO_8956 113
Aparna Mallavarapuca676882015-01-19 20:39:06 +053079
80#define FASTBOOT_MODE 0x77665500
Aparna Mallavarapu680a1332015-04-29 19:14:09 +053081#define RECOVERY_MODE 0x77665502
Aparna Mallavarapuca676882015-01-19 20:39:06 +053082#define PON_SOFT_RB_SPARE 0x88F
83
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +053084#define CE1_INSTANCE 1
85#define CE_EE 1
86#define CE_FIFO_SIZE 64
87#define CE_READ_PIPE 3
88#define CE_WRITE_PIPE 2
89#define CE_READ_PIPE_LOCK_GRP 0
90#define CE_WRITE_PIPE_LOCK_GRP 0
91#define CE_ARRAY_SIZE 20
92
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053093struct mmc_device *dev;
94
95static uint32_t mmc_pwrctl_base[] =
Aparna Mallavarapuca676882015-01-19 20:39:06 +053096 { MSM_SDC1_BASE, MSM_SDC2_BASE };
97
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053098static uint32_t mmc_sdhci_base[] =
99 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
100
101static uint32_t mmc_sdc_pwrctl_irq[] =
102 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530103
104void target_early_init(void)
105{
106#if WITH_DEBUG_UART
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530107 uart_dm_init(2, 0, BLSP1_UART1_BASE);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530108#endif
109}
110
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530111static void set_sdc_power_ctrl()
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530112{
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530113 /* Drive strength configs for sdc pins */
114 struct tlmm_cfgs sdc1_hdrv_cfg[] =
115 {
116 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, 0},
117 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, 0},
118 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK , 0},
119 };
120
121 /* Pull configs for sdc pins */
122 struct tlmm_cfgs sdc1_pull_cfg[] =
123 {
124 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, 0},
125 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0},
126 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0},
127 };
128
Aparna Mallavarapu29138912015-04-13 23:45:35 +0530129 struct tlmm_cfgs sdc1_rclk_cfg[] =
130 {
131 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, 0},
132 };
133
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530134 /* Set the drive strength & pull control values */
135 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
136 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
Aparna Mallavarapu29138912015-04-13 23:45:35 +0530137 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530138}
139
140void target_sdc_init()
141{
142 struct mmc_config_data config;
143
144 /* Set drive strength & pull ctrl values */
145 set_sdc_power_ctrl();
146
147 /* Try slot 1*/
148 config.slot = 1;
149 config.bus_width = DATA_BUS_WIDTH_8BIT;
Aparna Mallavarapu680a1332015-04-29 19:14:09 +0530150 config.max_clk_rate = MMC_CLK_192MHZ;
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530151 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
152 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
153 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
154 config.hs400_support = 1;
155
156 if (!(dev = mmc_init(&config))) {
157 /* Try slot 2 */
158 config.slot = 2;
159 config.max_clk_rate = MMC_CLK_200MHZ;
160 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
161 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
162 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
163 config.hs400_support = 0;
164
165 if (!(dev = mmc_init(&config))) {
166 dprintf(CRITICAL, "mmc init failed!");
167 ASSERT(0);
168 }
169 }
170}
171
172void *target_mmc_device()
173{
174 return (void *) dev;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530175}
176
177/* Return 1 if vol_up pressed */
Rami Butsteine51318a2015-05-27 16:23:17 +0300178int target_volume_up()
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530179{
lijuang2d2b8a02015-06-05 21:34:15 +0800180 static uint8_t first_time = 0;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530181 uint8_t status = 0;
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530182 uint32_t vol_up_gpio;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530183
Unnati Gandhife004a92015-06-01 13:06:06 +0530184 if(platform_is_msm8956())
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530185 vol_up_gpio = TLMM_VOL_UP_BTN_GPIO_8956;
186
Unnati Gandhife004a92015-06-01 13:06:06 +0530187 else
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530188 vol_up_gpio = TLMM_VOL_UP_BTN_GPIO;
189
lijuang2d2b8a02015-06-05 21:34:15 +0800190 if (!first_time) {
191 gpio_tlmm_config(vol_up_gpio, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530192
lijuang2d2b8a02015-06-05 21:34:15 +0800193 /* Wait for the gpio config to take effect - debounce time */
194 udelay(10000);
195
196 first_time = 1;
197 }
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530198
199 /* Get status of GPIO */
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530200 status = gpio_status(vol_up_gpio);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530201
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530202 /* Active low signal. */
Aparna Mallavarapudb938b62015-04-09 01:00:55 +0530203 return !status;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530204}
205
206/* Return 1 if vol_down pressed */
207uint32_t target_volume_down()
208{
209 /* Volume down button tied in with PMIC RESIN. */
210 return pm8x41_resin_status();
211}
212
Parth Dixit300a3b92015-06-19 16:38:12 +0530213uint32_t target_is_pwrkey_pon_reason()
214{
215 uint8_t pon_reason = pm8950_get_pon_reason();
216 if (pm8x41_get_is_cold_boot() && ((pon_reason == KPDPWR_N) || (pon_reason == (KPDPWR_N|PON1))))
217 return 1;
218 else
219 return 0;
220}
221
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530222static void target_keystatus()
223{
224 keys_init();
225
226 if(target_volume_down())
227 keys_post_event(KEY_VOLUMEDOWN, 1);
228
229 if(target_volume_up())
230 keys_post_event(KEY_VOLUMEUP, 1);
231}
232
233/* Configure PMIC and Drop PS_HOLD for shutdown */
234void shutdown_device()
235{
236 dprintf(CRITICAL, "Going down for shutdown.\n");
237
238 /* Configure PMIC for shutdown */
239 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
240
241 /* Drop PS_HOLD for MSM */
242 writel(0x00, MPM2_MPM_PS_HOLD);
243
244 mdelay(5000);
245
246 dprintf(CRITICAL, "shutdown failed\n");
247
248 ASSERT(0);
249}
250
251
252void target_init(void)
253{
Parth Dixit6e6bad52015-07-30 19:02:38 +0530254 int ret = 0;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530255 dprintf(INFO, "target_init()\n");
256
257 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
258
259 target_keystatus();
260
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530261 target_sdc_init();
262 if (partition_read_table())
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530263 {
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530264 dprintf(CRITICAL, "Error reading the partition table info\n");
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530265 ASSERT(0);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530266 }
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530267
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530268#if LONG_PRESS_POWER_ON
269 shutdown_detect();
270#endif
Matthew Qin47dfdb72015-06-10 21:29:11 +0800271
272#if PON_VIB_SUPPORT
273 /* turn on vibrator to indicate that phone is booting up to end user */
274 vib_timed_turn_on(VIBRATE_TIME);
275#endif
276
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530277 if (target_use_signed_kernel())
278 target_crypto_init_params();
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530279
Parth Dixit0eb73692015-08-09 17:32:27 +0530280 clock_ce_enable(CE1_INSTANCE);
281
Parth Dixit6e6bad52015-07-30 19:02:38 +0530282 /* Initialize Qseecom */
283 ret = qseecom_init();
284
285 if (ret < 0)
286 {
287 dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret);
288 ASSERT(0);
289 }
290
291 /* Start Qseecom */
292 ret = qseecom_tz_init();
293
294 if (ret < 0)
295 {
296 dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret);
297 ASSERT(0);
298 }
299
300 /*
301 * Load the sec app for first time
302 */
303 if (load_sec_app() < 0)
304 {
305 dprintf(CRITICAL, "Failed to load App for verified\n");
306 ASSERT(0);
307 }
308
309 if (rpmb_init() < 0)
310 {
311 dprintf(CRITICAL, "RPMB init failed\n");
312 ASSERT(0);
313 }
314
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530315#if SMD_SUPPORT
316 rpm_smd_init();
317#endif
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530318}
319
320void target_serialno(unsigned char *buf)
321{
322 uint32_t serialno;
323 if (target_is_emmc_boot()) {
324 serialno = mmc_get_psn();
325 snprintf((char *)buf, 13, "%x", serialno);
326 }
327}
328
329unsigned board_machtype(void)
330{
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530331 return LINUX_MACHTYPE_UNKNOWN;
332}
333
334/* Detect the target type */
335void target_detect(struct board_data *board)
336{
337 /* This is already filled as part of board.c */
338}
339
340/* Detect the modem type */
341void target_baseband_detect(struct board_data *board)
342{
343 uint32_t platform;
344
345 platform = board->platform;
346
347 switch(platform) {
348 case MSM8952:
349 case MSM8956:
350 case MSM8976:
Parth Dixit529f7a62015-08-25 21:11:18 +0530351 case MSMTHORIUM:
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530352 board->baseband = BASEBAND_MSM;
353 break;
Aparna Mallavarapu815b3242015-04-29 11:08:14 +0530354 case APQ8052:
355 case APQ8056:
356 case APQ8076:
357 board->baseband = BASEBAND_APQ;
358 break;
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530359 default:
360 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
361 ASSERT(0);
362 };
363}
364
365unsigned target_baseband()
366{
367 return board_baseband();
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530368}
369
370unsigned check_reboot_mode(void)
371{
372 uint32_t restart_reason = 0;
373
374 /* Read reboot reason and scrub it */
375 restart_reason = readl(RESTART_REASON_ADDR);
376 writel(0x00, RESTART_REASON_ADDR);
377
378 return restart_reason;
379}
380
381unsigned check_hard_reboot_mode(void)
382{
383 uint8_t hard_restart_reason = 0;
384 uint8_t value = 0;
385
386 /* Read reboot reason and scrub it
387 * Bit-5, bit-6 and bit-7 of SOFT_RB_SPARE for hard reset reason
388 */
389 value = pm8x41_reg_read(PON_SOFT_RB_SPARE);
390 hard_restart_reason = value >> 5;
391 pm8x41_reg_write(PON_SOFT_RB_SPARE, value & 0x1f);
392
393 return hard_restart_reason;
394}
395
396int set_download_mode(enum dload_mode mode)
397{
398 int ret = 0;
399 ret = scm_dload_mode(mode);
400
401 pm8x41_clear_pmic_watchdog();
402
403 return ret;
404}
405
406int emmc_recovery_init(void)
407{
408 return _emmc_recovery_init();
409}
410
411void reboot_device(unsigned reboot_reason)
412{
413 uint8_t reset_type = 0;
414 uint32_t ret = 0;
415
416 /* Need to clear the SW_RESET_ENTRY register and
417 * write to the BOOT_MISC_REG for known reset cases
418 */
419 if(reboot_reason != DLOAD)
420 scm_dload_mode(NORMAL_MODE);
421
422 writel(reboot_reason, RESTART_REASON_ADDR);
423
424 /* For Reboot-bootloader and Dload cases do a warm reset
425 * For Reboot cases do a hard reset
426 */
Aparna Mallavarapu680a1332015-04-29 19:14:09 +0530427 if((reboot_reason == FASTBOOT_MODE) || (reboot_reason == DLOAD) || (reboot_reason == RECOVERY_MODE))
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530428 reset_type = PON_PSHOLD_WARM_RESET;
429 else
430 reset_type = PON_PSHOLD_HARD_RESET;
431
432 pm8x41_reset_configure(reset_type);
433
434 ret = scm_halt_pmic_arbiter();
435 if (ret)
436 dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret);
437
438 /* Drop PS_HOLD for MSM */
439 writel(0x00, MPM2_MPM_PS_HOLD);
440
441 mdelay(5000);
442
443 dprintf(CRITICAL, "Rebooting failed\n");
444}
445
446#if USER_FORCE_RESET_SUPPORT
447/* Return 1 if it is a force resin triggered by user. */
448uint32_t is_user_force_reset(void)
449{
450 uint8_t poff_reason1 = pm8x41_get_pon_poff_reason1();
451 uint8_t poff_reason2 = pm8x41_get_pon_poff_reason2();
452
453 dprintf(SPEW, "poff_reason1: %d\n", poff_reason1);
454 dprintf(SPEW, "poff_reason2: %d\n", poff_reason2);
455 if (pm8x41_get_is_cold_boot() && (poff_reason1 == KPDPWR_AND_RESIN ||
456 poff_reason2 == STAGE3))
457 return 1;
458 else
459 return 0;
460}
461#endif
462
Zhenhua Huangb46b9b52015-04-21 19:53:09 +0800463#define SMBCHG_USB_RT_STS 0x21310
464#define USBIN_UV_RT_STS BIT(0)
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530465unsigned target_pause_for_battery_charge(void)
466{
467 uint8_t pon_reason = pm8x41_get_pon_reason();
468 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
Zhenhua Huangb46b9b52015-04-21 19:53:09 +0800469 bool usb_present_sts = !(USBIN_UV_RT_STS &
470 pm8x41_reg_read(SMBCHG_USB_RT_STS));
471 dprintf(INFO, "%s : pon_reason is:0x%x cold_boot:%d usb_sts:%d\n", __func__,
472 pon_reason, is_cold_boot, usb_present_sts);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530473 /* In case of fastboot reboot,adb reboot or if we see the power key
474 * pressed we do not want go into charger mode.
475 * fastboot reboot is warm boot with PON hard reset bit not set
476 * adb reboot is a cold boot with PON hard reset bit set
477 */
478 if (is_cold_boot &&
479 (!(pon_reason & HARD_RST)) &&
480 (!(pon_reason & KPDPWR_N)) &&
Zhenhua Huangb46b9b52015-04-21 19:53:09 +0800481 usb_present_sts)
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530482 return 1;
483 else
484 return 0;
485}
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530486
487void target_uninit(void)
488{
489 mmc_put_card_to_sleep(dev);
490 sdhci_mode_disable(&dev->host);
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530491 if (crypto_initialized())
492 crypto_eng_cleanup();
493
494 if (target_is_ssd_enabled())
495 clock_ce_disable(CE1_INSTANCE);
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530496
Parth Dixit6e6bad52015-07-30 19:02:38 +0530497
498 if (is_sec_app_loaded())
499 {
500 if (send_milestone_call_to_tz() < 0)
501 {
502 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
503 ASSERT(0);
504 }
505 }
506
507 if (rpmb_uninit() < 0)
508 {
509 dprintf(CRITICAL, "RPMB uninit failed\n");
510 ASSERT(0);
511 }
512
Parth Dixit0eb73692015-08-09 17:32:27 +0530513 clock_ce_disable(CE1_INSTANCE);
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530514#if SMD_SUPPORT
515 rpm_smd_uninit();
516#endif
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530517}
518
519void target_usb_init(void)
520{
521 uint32_t val;
522
523 /* Select and enable external configuration with USB PHY */
524 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
525
526 /* Enable sess_vld */
527 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
528 writel(val, USB_GENCONFIG_2);
529
530 /* Enable external vbus configuration in the LINK */
531 val = readl(USB_USBCMD);
532 val |= SESS_VLD_CTRL;
533 writel(val, USB_USBCMD);
534}
535
536void target_usb_stop(void)
537{
538 /* Disable VBUS mimicing in the controller. */
539 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
540}
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530541
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700542static uint8_t splash_override;
543/* Returns 1 if target supports continuous splash screen. */
544int target_cont_splash_screen()
545{
546 uint8_t splash_screen = 0;
547 if (!splash_override) {
548 switch (board_hardware_id()) {
549 case HW_PLATFORM_MTP:
550 case HW_PLATFORM_SURF:
Vishnuvardhan Prodduturie116c002015-07-14 17:14:25 +0530551 case HW_PLATFORM_RCM:
feifanz174c82c2015-04-15 18:57:07 +0800552 case HW_PLATFORM_QRD:
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700553 splash_screen = 1;
554 break;
555 default:
556 splash_screen = 0;
557 break;
558 }
559 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
560 }
561 return splash_screen;
562}
563
564void target_force_cont_splash_disable(uint8_t override)
565{
566 splash_override = override;
567}
568
Ray Zhangf95f5b92015-06-25 15:34:29 +0800569uint8_t target_panel_auto_detect_enabled()
570{
571 uint8_t ret = 0;
572
573 switch(board_hardware_id())
574 {
575 case HW_PLATFORM_QRD:
576 ret = platform_is_msm8956() ? 1 : 0;
577 break;
578 case HW_PLATFORM_SURF:
579 case HW_PLATFORM_MTP:
580 default:
581 ret = 0;
582 }
583 return ret;
584}
585
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530586/* Do any target specific intialization needed before entering fastboot mode */
587void target_fastboot_init(void)
588{
589 if (target_is_ssd_enabled()) {
590 clock_ce_enable(CE1_INSTANCE);
591 target_load_ssd_keystore();
592 }
593}
594
595void target_load_ssd_keystore(void)
596{
597 uint64_t ptn;
598 int index;
599 uint64_t size;
600 uint32_t *buffer = NULL;
601
602 if (!target_is_ssd_enabled())
603 return;
604
605 index = partition_get_index("ssd");
606
607 ptn = partition_get_offset(index);
608 if (ptn == 0){
609 dprintf(CRITICAL, "Error: ssd partition not found\n");
610 return;
611 }
612
613 size = partition_get_size(index);
614 if (size == 0) {
615 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
616 return;
617 }
618
619 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
620 if (!buffer) {
621 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
622 return;
623 }
624
625 if (mmc_read(ptn, buffer, size)) {
626 dprintf(CRITICAL, "Error: cannot read data\n");
627 free(buffer);
628 return;
629 }
630
631 clock_ce_enable(CE1_INSTANCE);
632 scm_protect_keystore(buffer, size);
633 clock_ce_disable(CE1_INSTANCE);
634 free(buffer);
635}
636
637crypto_engine_type board_ce_type(void)
638{
639 return CRYPTO_ENGINE_TYPE_HW;
640}
641
642/* Set up params for h/w CE. */
643void target_crypto_init_params()
644{
645 struct crypto_init_params ce_params;
646
647 /* Set up base addresses and instance. */
648 ce_params.crypto_instance = CE1_INSTANCE;
649 ce_params.crypto_base = MSM_CE1_BASE;
650 ce_params.bam_base = MSM_CE1_BAM_BASE;
651
652 /* Set up BAM config. */
653 ce_params.bam_ee = CE_EE;
654 ce_params.pipes.read_pipe = CE_READ_PIPE;
655 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
656 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
657 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
658
659 /* Assign buffer sizes. */
660 ce_params.num_ce = CE_ARRAY_SIZE;
661 ce_params.read_fifo_size = CE_FIFO_SIZE;
662 ce_params.write_fifo_size = CE_FIFO_SIZE;
663
664 /* BAM is initialized by TZ for this platform.
665 * Do not do it again as the initialization address space
666 * is locked.
667 */
668 ce_params.do_bam_init = 0;
669
670 crypto_init_params(&ce_params);
671}