blob: 47d3d0480506071eac46ceff49dc2e0dfa3d98f2 [file] [log] [blame]
Parth Dixit80bb5232016-01-05 15:26:22 +05301/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
Aparna Mallavarapuca676882015-01-19 20:39:06 +05302 *
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>
lijuang3606df82015-09-02 21:14:43 +080060#include <smem.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053061
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -070062#include "target/display.h"
63
Aparna Mallavarapuca676882015-01-19 20:39:06 +053064#if LONG_PRESS_POWER_ON
65#include <shutdown_detect.h>
66#endif
67
Matthew Qin47dfdb72015-06-10 21:29:11 +080068#if PON_VIB_SUPPORT
69#include <vibrator.h>
70#endif
71
72#if PON_VIB_SUPPORT
73#define VIBRATE_TIME 250
74#endif
75
Aparna Mallavarapuca676882015-01-19 20:39:06 +053076#define PMIC_ARB_CHANNEL_NUM 0
77#define PMIC_ARB_OWNER_ID 0
78#define TLMM_VOL_UP_BTN_GPIO 85
Unnati Gandhife004a92015-06-01 13:06:06 +053079#define TLMM_VOL_UP_BTN_GPIO_8956 113
Parth Dixit720d3b92015-10-30 01:21:34 +053080#define TLMM_VOL_UP_BTN_GPIO_8937 91
Wufengf2e37312016-04-12 16:09:47 +080081#define TLMM_VOL_DOWN_BTN_GPIO 128
Aparna Mallavarapuca676882015-01-19 20:39:06 +053082
83#define FASTBOOT_MODE 0x77665500
Aparna Mallavarapu680a1332015-04-29 19:14:09 +053084#define RECOVERY_MODE 0x77665502
Aparna Mallavarapuca676882015-01-19 20:39:06 +053085#define PON_SOFT_RB_SPARE 0x88F
86
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +053087#define CE1_INSTANCE 1
88#define CE_EE 1
89#define CE_FIFO_SIZE 64
90#define CE_READ_PIPE 3
91#define CE_WRITE_PIPE 2
92#define CE_READ_PIPE_LOCK_GRP 0
93#define CE_WRITE_PIPE_LOCK_GRP 0
94#define CE_ARRAY_SIZE 20
Wufengf2e37312016-04-12 16:09:47 +080095#define SUB_TYPE_SKUT 0x0A
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +053096
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053097struct mmc_device *dev;
98
99static uint32_t mmc_pwrctl_base[] =
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530100 { MSM_SDC1_BASE, MSM_SDC2_BASE };
101
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530102static uint32_t mmc_sdhci_base[] =
103 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
104
105static uint32_t mmc_sdc_pwrctl_irq[] =
106 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530107
108void target_early_init(void)
109{
110#if WITH_DEBUG_UART
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530111 uart_dm_init(2, 0, BLSP1_UART1_BASE);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530112#endif
113}
114
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530115static void set_sdc_power_ctrl()
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530116{
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530117 /* Drive strength configs for sdc pins */
118 struct tlmm_cfgs sdc1_hdrv_cfg[] =
119 {
120 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, 0},
121 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, 0},
122 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK , 0},
123 };
124
125 /* Pull configs for sdc pins */
126 struct tlmm_cfgs sdc1_pull_cfg[] =
127 {
128 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, 0},
129 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0},
130 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0},
131 };
132
Aparna Mallavarapu29138912015-04-13 23:45:35 +0530133 struct tlmm_cfgs sdc1_rclk_cfg[] =
134 {
135 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, 0},
136 };
137
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530138 /* Set the drive strength & pull control values */
139 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
140 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
Aparna Mallavarapu29138912015-04-13 23:45:35 +0530141 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530142}
143
144void target_sdc_init()
145{
146 struct mmc_config_data config;
147
148 /* Set drive strength & pull ctrl values */
149 set_sdc_power_ctrl();
150
151 /* Try slot 1*/
152 config.slot = 1;
153 config.bus_width = DATA_BUS_WIDTH_8BIT;
Aparna Mallavarapu680a1332015-04-29 19:14:09 +0530154 config.max_clk_rate = MMC_CLK_192MHZ;
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530155 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
156 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
157 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
158 config.hs400_support = 1;
159
160 if (!(dev = mmc_init(&config))) {
161 /* Try slot 2 */
162 config.slot = 2;
163 config.max_clk_rate = MMC_CLK_200MHZ;
164 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
165 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
166 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
167 config.hs400_support = 0;
168
169 if (!(dev = mmc_init(&config))) {
170 dprintf(CRITICAL, "mmc init failed!");
171 ASSERT(0);
172 }
173 }
174}
175
176void *target_mmc_device()
177{
178 return (void *) dev;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530179}
180
181/* Return 1 if vol_up pressed */
Rami Butsteine51318a2015-05-27 16:23:17 +0300182int target_volume_up()
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530183{
lijuang2d2b8a02015-06-05 21:34:15 +0800184 static uint8_t first_time = 0;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530185 uint8_t status = 0;
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530186 uint32_t vol_up_gpio;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530187
Unnati Gandhife004a92015-06-01 13:06:06 +0530188 if(platform_is_msm8956())
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530189 vol_up_gpio = TLMM_VOL_UP_BTN_GPIO_8956;
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530190 else if(platform_is_msm8937() || platform_is_msm8917())
Parth Dixit720d3b92015-10-30 01:21:34 +0530191 vol_up_gpio = TLMM_VOL_UP_BTN_GPIO_8937;
Unnati Gandhife004a92015-06-01 13:06:06 +0530192 else
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530193 vol_up_gpio = TLMM_VOL_UP_BTN_GPIO;
194
lijuang2d2b8a02015-06-05 21:34:15 +0800195 if (!first_time) {
196 gpio_tlmm_config(vol_up_gpio, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530197
lijuang2d2b8a02015-06-05 21:34:15 +0800198 /* Wait for the gpio config to take effect - debounce time */
199 udelay(10000);
200
201 first_time = 1;
202 }
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530203
204 /* Get status of GPIO */
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530205 status = gpio_status(vol_up_gpio);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530206
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530207 /* Active low signal. */
Aparna Mallavarapudb938b62015-04-09 01:00:55 +0530208 return !status;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530209}
210
211/* Return 1 if vol_down pressed */
212uint32_t target_volume_down()
213{
Wufengf2e37312016-04-12 16:09:47 +0800214 static bool vol_down_key_init = false;
215
216 if ((board_hardware_id() == HW_PLATFORM_QRD) &&
217 (board_hardware_subtype() == SUB_TYPE_SKUT)) {
218 uint32_t status = 0;
219
220 if (!vol_down_key_init) {
221 gpio_tlmm_config(TLMM_VOL_DOWN_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP,
222 GPIO_2MA, GPIO_ENABLE);
223 /* Wait for the gpio config to take effect - debounce time */
224 thread_sleep(10);
225 vol_down_key_init = true;
226 }
227
228 /* Get status of GPIO */
229 status = gpio_status(TLMM_VOL_DOWN_BTN_GPIO);
230
231 /* Active low signal. */
232 return !status;
233 } else {
234 /* Volume down button tied in with PMIC RESIN. */
235 return pm8x41_resin_status();
236 }
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530237}
238
Parth Dixit300a3b92015-06-19 16:38:12 +0530239uint32_t target_is_pwrkey_pon_reason()
240{
241 uint8_t pon_reason = pm8950_get_pon_reason();
242 if (pm8x41_get_is_cold_boot() && ((pon_reason == KPDPWR_N) || (pon_reason == (KPDPWR_N|PON1))))
243 return 1;
244 else
245 return 0;
246}
247
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530248static void target_keystatus()
249{
250 keys_init();
251
252 if(target_volume_down())
253 keys_post_event(KEY_VOLUMEDOWN, 1);
254
255 if(target_volume_up())
256 keys_post_event(KEY_VOLUMEUP, 1);
257}
258
259/* Configure PMIC and Drop PS_HOLD for shutdown */
260void shutdown_device()
261{
262 dprintf(CRITICAL, "Going down for shutdown.\n");
263
264 /* Configure PMIC for shutdown */
265 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
266
267 /* Drop PS_HOLD for MSM */
268 writel(0x00, MPM2_MPM_PS_HOLD);
269
270 mdelay(5000);
271
272 dprintf(CRITICAL, "shutdown failed\n");
273
274 ASSERT(0);
275}
276
277
278void target_init(void)
279{
Parth Dixit5b954e02015-10-17 22:20:31 +0530280#if VERIFIED_BOOT
Parth Dixitb73ff342015-10-27 17:34:08 +0530281#if !VBOOT_MOTA
Parth Dixit6e6bad52015-07-30 19:02:38 +0530282 int ret = 0;
Parth Dixit5b954e02015-10-17 22:20:31 +0530283#endif
Parth Dixitb73ff342015-10-27 17:34:08 +0530284#endif
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530285 dprintf(INFO, "target_init()\n");
286
287 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
288
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530289 if(platform_is_msm8937() || platform_is_msm8917())
Parth Dixit3e6dead2015-12-08 15:04:54 +0530290 {
291 uint8_t pmi_rev = 0;
292 uint32_t pmi_type = 0;
293
294 pmi_type = board_pmic_target(1) & 0xffff;
295 if(pmi_type == PMIC_IS_PMI8950)
296 {
297 /* read pmic spare register for rev */
298 pmi_rev = pmi8950_get_pmi_subtype();
299 if(pmi_rev)
300 board_pmi_target_set(1,pmi_rev);
301 }
302 }
303
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530304 target_keystatus();
305
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530306 target_sdc_init();
307 if (partition_read_table())
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530308 {
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530309 dprintf(CRITICAL, "Error reading the partition table info\n");
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530310 ASSERT(0);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530311 }
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530312
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530313#if LONG_PRESS_POWER_ON
314 shutdown_detect();
315#endif
Matthew Qin47dfdb72015-06-10 21:29:11 +0800316
317#if PON_VIB_SUPPORT
318 /* turn on vibrator to indicate that phone is booting up to end user */
319 vib_timed_turn_on(VIBRATE_TIME);
320#endif
321
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530322 if (target_use_signed_kernel())
323 target_crypto_init_params();
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530324
Parth Dixit5b954e02015-10-17 22:20:31 +0530325#if VERIFIED_BOOT
Parth Dixitb73ff342015-10-27 17:34:08 +0530326#if !VBOOT_MOTA
Parth Dixit0eb73692015-08-09 17:32:27 +0530327 clock_ce_enable(CE1_INSTANCE);
328
Parth Dixit6e6bad52015-07-30 19:02:38 +0530329 /* Initialize Qseecom */
330 ret = qseecom_init();
331
332 if (ret < 0)
333 {
334 dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret);
335 ASSERT(0);
336 }
337
338 /* Start Qseecom */
339 ret = qseecom_tz_init();
340
341 if (ret < 0)
342 {
343 dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret);
344 ASSERT(0);
345 }
346
Parth Dixitb4b2ffa2015-10-09 15:31:14 +0530347 if (rpmb_init() < 0)
348 {
349 dprintf(CRITICAL, "RPMB init failed\n");
350 ASSERT(0);
351 }
352
Parth Dixit6e6bad52015-07-30 19:02:38 +0530353 /*
354 * Load the sec app for first time
355 */
356 if (load_sec_app() < 0)
357 {
358 dprintf(CRITICAL, "Failed to load App for verified\n");
359 ASSERT(0);
360 }
Parth Dixit5b954e02015-10-17 22:20:31 +0530361#endif
Parth Dixitb73ff342015-10-27 17:34:08 +0530362#endif
Parth Dixit5b954e02015-10-17 22:20:31 +0530363
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530364#if SMD_SUPPORT
365 rpm_smd_init();
366#endif
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530367}
368
369void target_serialno(unsigned char *buf)
370{
371 uint32_t serialno;
372 if (target_is_emmc_boot()) {
373 serialno = mmc_get_psn();
374 snprintf((char *)buf, 13, "%x", serialno);
375 }
376}
377
378unsigned board_machtype(void)
379{
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530380 return LINUX_MACHTYPE_UNKNOWN;
381}
382
383/* Detect the target type */
384void target_detect(struct board_data *board)
385{
386 /* This is already filled as part of board.c */
387}
388
389/* Detect the modem type */
390void target_baseband_detect(struct board_data *board)
391{
392 uint32_t platform;
393
394 platform = board->platform;
395
396 switch(platform) {
397 case MSM8952:
398 case MSM8956:
399 case MSM8976:
Parth Dixit4ec3fe22015-10-30 00:44:33 +0530400 case MSM8937:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530401 case MSM8917:
402 case MSM8217:
403 case MSM8617:
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530404 board->baseband = BASEBAND_MSM;
405 break;
Aparna Mallavarapu815b3242015-04-29 11:08:14 +0530406 case APQ8052:
407 case APQ8056:
408 case APQ8076:
Parth Dixit4ec3fe22015-10-30 00:44:33 +0530409 case APQ8037:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530410 case APQ8017:
Aparna Mallavarapu815b3242015-04-29 11:08:14 +0530411 board->baseband = BASEBAND_APQ;
412 break;
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530413 default:
414 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
415 ASSERT(0);
416 };
417}
418
419unsigned target_baseband()
420{
421 return board_baseband();
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530422}
423
424unsigned check_reboot_mode(void)
425{
426 uint32_t restart_reason = 0;
427
428 /* Read reboot reason and scrub it */
429 restart_reason = readl(RESTART_REASON_ADDR);
430 writel(0x00, RESTART_REASON_ADDR);
431
432 return restart_reason;
433}
434
435unsigned check_hard_reboot_mode(void)
436{
437 uint8_t hard_restart_reason = 0;
438 uint8_t value = 0;
439
440 /* Read reboot reason and scrub it
441 * Bit-5, bit-6 and bit-7 of SOFT_RB_SPARE for hard reset reason
442 */
443 value = pm8x41_reg_read(PON_SOFT_RB_SPARE);
444 hard_restart_reason = value >> 5;
445 pm8x41_reg_write(PON_SOFT_RB_SPARE, value & 0x1f);
446
447 return hard_restart_reason;
448}
449
lijuang395b5e62015-11-19 17:39:44 +0800450int set_download_mode(enum reboot_reason mode)
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530451{
452 int ret = 0;
453 ret = scm_dload_mode(mode);
454
455 pm8x41_clear_pmic_watchdog();
456
457 return ret;
458}
459
460int emmc_recovery_init(void)
461{
462 return _emmc_recovery_init();
463}
464
465void reboot_device(unsigned reboot_reason)
466{
467 uint8_t reset_type = 0;
468 uint32_t ret = 0;
469
lijuang395b5e62015-11-19 17:39:44 +0800470 /* Set cookie for dload mode */
471 if(set_download_mode(reboot_reason)) {
472 dprintf(CRITICAL, "HALT: set_download_mode not supported\n");
473 return;
474 }
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530475
476 writel(reboot_reason, RESTART_REASON_ADDR);
477
478 /* For Reboot-bootloader and Dload cases do a warm reset
479 * For Reboot cases do a hard reset
480 */
lijuang395b5e62015-11-19 17:39:44 +0800481 if((reboot_reason == FASTBOOT_MODE) || (reboot_reason == NORMAL_DLOAD) ||
482 (reboot_reason == EMERGENCY_DLOAD) || (reboot_reason == RECOVERY_MODE))
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530483 reset_type = PON_PSHOLD_WARM_RESET;
484 else
485 reset_type = PON_PSHOLD_HARD_RESET;
486
Parth Dixitbe107962015-10-16 14:33:20 +0530487 pm8994_reset_configure(reset_type);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530488
489 ret = scm_halt_pmic_arbiter();
490 if (ret)
491 dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret);
492
493 /* Drop PS_HOLD for MSM */
494 writel(0x00, MPM2_MPM_PS_HOLD);
495
496 mdelay(5000);
497
498 dprintf(CRITICAL, "Rebooting failed\n");
499}
500
501#if USER_FORCE_RESET_SUPPORT
502/* Return 1 if it is a force resin triggered by user. */
503uint32_t is_user_force_reset(void)
504{
505 uint8_t poff_reason1 = pm8x41_get_pon_poff_reason1();
506 uint8_t poff_reason2 = pm8x41_get_pon_poff_reason2();
507
508 dprintf(SPEW, "poff_reason1: %d\n", poff_reason1);
509 dprintf(SPEW, "poff_reason2: %d\n", poff_reason2);
510 if (pm8x41_get_is_cold_boot() && (poff_reason1 == KPDPWR_AND_RESIN ||
511 poff_reason2 == STAGE3))
512 return 1;
513 else
514 return 0;
515}
516#endif
517
Zhenhua Huangb46b9b52015-04-21 19:53:09 +0800518#define SMBCHG_USB_RT_STS 0x21310
519#define USBIN_UV_RT_STS BIT(0)
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530520unsigned target_pause_for_battery_charge(void)
521{
522 uint8_t pon_reason = pm8x41_get_pon_reason();
523 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
Zhenhua Huangb46b9b52015-04-21 19:53:09 +0800524 bool usb_present_sts = !(USBIN_UV_RT_STS &
525 pm8x41_reg_read(SMBCHG_USB_RT_STS));
526 dprintf(INFO, "%s : pon_reason is:0x%x cold_boot:%d usb_sts:%d\n", __func__,
527 pon_reason, is_cold_boot, usb_present_sts);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530528 /* In case of fastboot reboot,adb reboot or if we see the power key
529 * pressed we do not want go into charger mode.
530 * fastboot reboot is warm boot with PON hard reset bit not set
531 * adb reboot is a cold boot with PON hard reset bit set
532 */
533 if (is_cold_boot &&
534 (!(pon_reason & HARD_RST)) &&
535 (!(pon_reason & KPDPWR_N)) &&
Zhenhua Huangb46b9b52015-04-21 19:53:09 +0800536 usb_present_sts)
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530537 return 1;
538 else
539 return 0;
540}
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530541
542void target_uninit(void)
543{
c_wufeng8324c042016-01-25 10:37:37 +0800544#if PON_VIB_SUPPORT
545 turn_off_vib_early();
546#endif
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530547 mmc_put_card_to_sleep(dev);
548 sdhci_mode_disable(&dev->host);
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530549 if (crypto_initialized())
Vijay Kumar Pendotib0f9ba32016-04-15 16:55:30 +0530550 {
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530551 crypto_eng_cleanup();
Vijay Kumar Pendotib0f9ba32016-04-15 16:55:30 +0530552 clock_ce_disable(CE1_INSTANCE);
553 }
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530554
555 if (target_is_ssd_enabled())
556 clock_ce_disable(CE1_INSTANCE);
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530557
Parth Dixit5b954e02015-10-17 22:20:31 +0530558#if VERIFIED_BOOT
Parth Dixitb73ff342015-10-27 17:34:08 +0530559#if !VBOOT_MOTA
Parth Dixit6e6bad52015-07-30 19:02:38 +0530560 if (is_sec_app_loaded())
561 {
562 if (send_milestone_call_to_tz() < 0)
563 {
564 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
565 ASSERT(0);
566 }
567 }
568
569 if (rpmb_uninit() < 0)
570 {
571 dprintf(CRITICAL, "RPMB uninit failed\n");
572 ASSERT(0);
573 }
574
Parth Dixit0eb73692015-08-09 17:32:27 +0530575 clock_ce_disable(CE1_INSTANCE);
Parth Dixit5b954e02015-10-17 22:20:31 +0530576#endif
Parth Dixitb73ff342015-10-27 17:34:08 +0530577#endif
Parth Dixit5b954e02015-10-17 22:20:31 +0530578
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530579#if SMD_SUPPORT
580 rpm_smd_uninit();
581#endif
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530582}
583
584void target_usb_init(void)
585{
586 uint32_t val;
587
588 /* Select and enable external configuration with USB PHY */
589 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
590
591 /* Enable sess_vld */
592 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
593 writel(val, USB_GENCONFIG_2);
594
595 /* Enable external vbus configuration in the LINK */
596 val = readl(USB_USBCMD);
597 val |= SESS_VLD_CTRL;
598 writel(val, USB_USBCMD);
599}
600
601void target_usb_stop(void)
602{
603 /* Disable VBUS mimicing in the controller. */
604 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
605}
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530606
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700607static uint8_t splash_override;
608/* Returns 1 if target supports continuous splash screen. */
609int target_cont_splash_screen()
610{
611 uint8_t splash_screen = 0;
612 if (!splash_override) {
613 switch (board_hardware_id()) {
614 case HW_PLATFORM_MTP:
615 case HW_PLATFORM_SURF:
Vishnuvardhan Prodduturie116c002015-07-14 17:14:25 +0530616 case HW_PLATFORM_RCM:
feifanz174c82c2015-04-15 18:57:07 +0800617 case HW_PLATFORM_QRD:
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700618 splash_screen = 1;
619 break;
620 default:
621 splash_screen = 0;
622 break;
623 }
624 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
625 }
626 return splash_screen;
627}
628
629void target_force_cont_splash_disable(uint8_t override)
630{
631 splash_override = override;
632}
633
Ray Zhangf95f5b92015-06-25 15:34:29 +0800634uint8_t target_panel_auto_detect_enabled()
635{
636 uint8_t ret = 0;
637
638 switch(board_hardware_id())
639 {
640 case HW_PLATFORM_QRD:
641 ret = platform_is_msm8956() ? 1 : 0;
642 break;
643 case HW_PLATFORM_SURF:
644 case HW_PLATFORM_MTP:
645 default:
646 ret = 0;
647 }
648 return ret;
649}
650
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530651/* Do any target specific intialization needed before entering fastboot mode */
652void target_fastboot_init(void)
653{
654 if (target_is_ssd_enabled()) {
655 clock_ce_enable(CE1_INSTANCE);
656 target_load_ssd_keystore();
657 }
658}
659
660void target_load_ssd_keystore(void)
661{
662 uint64_t ptn;
663 int index;
664 uint64_t size;
665 uint32_t *buffer = NULL;
666
667 if (!target_is_ssd_enabled())
668 return;
669
670 index = partition_get_index("ssd");
671
672 ptn = partition_get_offset(index);
673 if (ptn == 0){
674 dprintf(CRITICAL, "Error: ssd partition not found\n");
675 return;
676 }
677
678 size = partition_get_size(index);
679 if (size == 0) {
680 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
681 return;
682 }
683
684 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
685 if (!buffer) {
686 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
687 return;
688 }
689
690 if (mmc_read(ptn, buffer, size)) {
691 dprintf(CRITICAL, "Error: cannot read data\n");
692 free(buffer);
693 return;
694 }
695
696 clock_ce_enable(CE1_INSTANCE);
697 scm_protect_keystore(buffer, size);
698 clock_ce_disable(CE1_INSTANCE);
699 free(buffer);
700}
701
702crypto_engine_type board_ce_type(void)
703{
704 return CRYPTO_ENGINE_TYPE_HW;
705}
706
707/* Set up params for h/w CE. */
708void target_crypto_init_params()
709{
710 struct crypto_init_params ce_params;
711
712 /* Set up base addresses and instance. */
713 ce_params.crypto_instance = CE1_INSTANCE;
714 ce_params.crypto_base = MSM_CE1_BASE;
715 ce_params.bam_base = MSM_CE1_BAM_BASE;
716
717 /* Set up BAM config. */
718 ce_params.bam_ee = CE_EE;
719 ce_params.pipes.read_pipe = CE_READ_PIPE;
720 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
721 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
722 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
723
724 /* Assign buffer sizes. */
725 ce_params.num_ce = CE_ARRAY_SIZE;
726 ce_params.read_fifo_size = CE_FIFO_SIZE;
727 ce_params.write_fifo_size = CE_FIFO_SIZE;
728
729 /* BAM is initialized by TZ for this platform.
730 * Do not do it again as the initialization address space
731 * is locked.
732 */
733 ce_params.do_bam_init = 0;
734
735 crypto_init_params(&ce_params);
736}
lijuang3606df82015-09-02 21:14:43 +0800737
738uint32_t target_get_pmic()
739{
740 return PMIC_IS_PMI8950;
741}