blob: 8b4a48b365413bdbb1731979d130631bb8cfec7a [file] [log] [blame]
Mayank Grover759e0b02017-04-11 11:59:06 +05301/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +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>
P.V. Phani Kumara053a322015-08-13 18:36:05 +053040#include <pm8x41_hw.h>
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053041#include <board.h>
42#include <baseband.h>
43#include <hsusb.h>
44#include <scm.h>
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053045#include <platform/irqs.h>
46#include <platform/clock.h>
P.V. Phani Kumara053a322015-08-13 18:36:05 +053047#include <platform/timer.h>
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053048#include <crypto5_wrapper.h>
49#include <partition_parser.h>
50#include <stdlib.h>
P.V. Phani Kumara053a322015-08-13 18:36:05 +053051#include <rpm-smd.h>
52#include <spmi.h>
53#include <sdhci_msm.h>
54#include <clock.h>
P.V. Phani Kumar77826d32015-12-26 20:56:35 +053055#include <boot_device.h>
56#include <secapp_loader.h>
57#include <rpmb.h>
58#include <smem.h>
59#include <qmp_phy.h>
60#include <qusb2_phy.h>
Padmanabhan Komanduru0104a892016-01-22 16:58:10 +053061#include "target/display.h"
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053062
63#if LONG_PRESS_POWER_ON
64#include <shutdown_detect.h>
65#endif
66
c_wufeng41310ae2016-01-14 17:59:22 +080067#if PON_VIB_SUPPORT
68#include <vibrator.h>
69#define VIBRATE_TIME 250
70#endif
71
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053072#define PMIC_ARB_CHANNEL_NUM 0
73#define PMIC_ARB_OWNER_ID 0
74#define TLMM_VOL_UP_BTN_GPIO 85
75
76#define FASTBOOT_MODE 0x77665500
P.V. Phani Kumar77826d32015-12-26 20:56:35 +053077#define RECOVERY_MODE 0x77665502
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053078#define PON_SOFT_RB_SPARE 0x88F
anisha agarwalebc52bc2016-07-08 15:50:00 -070079#define EXT4_CMDLINE " rootfstype=ext4 root=/dev/mmcblk0p"
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053080
P.V. Phani Kumar77826d32015-12-26 20:56:35 +053081#define CE1_INSTANCE 1
82#define CE_EE 1
83#define CE_FIFO_SIZE 64
84#define CE_READ_PIPE 3
85#define CE_WRITE_PIPE 2
86#define CE_READ_PIPE_LOCK_GRP 0
87#define CE_WRITE_PIPE_LOCK_GRP 0
88#define CE_ARRAY_SIZE 20
89
Vijay Kumar Pendoti7e9226c2016-09-21 20:49:21 +053090#define SMBCHG_USB_RT_STS 0x21310
91#define USBIN_UV_RT_STS BIT(0)
92
P.V. Phani Kumara053a322015-08-13 18:36:05 +053093struct mmc_device *dev;
94
95static uint32_t mmc_pwrctl_base[] =
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053096 { MSM_SDC1_BASE, MSM_SDC2_BASE };
97
P.V. Phani Kumara053a322015-08-13 18:36:05 +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 Mallavarapu01fc00a2015-06-01 20:37:05 +0530103
104void target_early_init(void)
105{
106#if WITH_DEBUG_UART
P.V. Phani Kumar2e4eeae2015-12-31 16:52:54 +0530107 uart_dm_init(1, 0, BLSP1_UART0_BASE);
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530108#endif
109}
110
anisha agarwalebc52bc2016-07-08 15:50:00 -0700111#if _APPEND_CMDLINE
112int get_target_boot_params(const char *cmdline, const char *part, char **buf)
113{
114 int system_ptn_index = -1;
115 uint32_t buflen;
116 int ret = -1;
117
118 if (!cmdline || !part ) {
119 dprintf(CRITICAL, "WARN: Invalid input param\n");
120 return -1;
121 }
122
123 if (!strstr(cmdline, "root=/dev/ram")) /* This check is to handle kdev boot */
124 {
125 if (target_is_emmc_boot()) {
126 buflen = strlen(EXT4_CMDLINE) + sizeof(int) +1;
127 *buf = (char *)malloc(buflen);
128 if(!(*buf)) {
129 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
130 return -1;
131 }
132 /* Below is for emmc boot */
133 system_ptn_index = partition_get_index(part) + 1; /* Adding +1 as offsets for eMMC start at 1 and NAND at 0 */
134 if (system_ptn_index < 0) {
135 dprintf(CRITICAL,
136 "WARN: Cannot get partition index for %s\n", part);
137 free(*buf);
138 return -1;
139 }
140 snprintf(*buf, buflen, EXT4_CMDLINE"%d", system_ptn_index);
141 ret = 0;
142 }
143 }
144 /*in success case buf will be freed in the calling function of this*/
145 return ret;
146}
147#endif
148
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530149static void set_sdc_power_ctrl()
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530150{
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530151 /* Drive strength configs for sdc pins */
152 struct tlmm_cfgs sdc1_hdrv_cfg[] =
153 {
154 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, 0},
155 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, 0},
156 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK , 0},
157 };
158
159 /* Pull configs for sdc pins */
160 struct tlmm_cfgs sdc1_pull_cfg[] =
161 {
162 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, 0},
163 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0},
164 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0},
165 };
166
167 struct tlmm_cfgs sdc1_rclk_cfg[] =
168 {
169 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, 0},
170 };
171
172 /* Set the drive strength & pull control values */
173 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
174 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
175 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
176}
177
178void target_sdc_init()
179{
180 struct mmc_config_data config;
181
182 /* Set drive strength & pull ctrl values */
183 set_sdc_power_ctrl();
184
185 config.slot = MMC_SLOT;
186 config.bus_width = DATA_BUS_WIDTH_8BIT;
187 config.max_clk_rate = MMC_CLK_192MHZ;
188 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
189 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
190 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
191 config.hs400_support = 1;
192
193 if (!(dev = mmc_init(&config))) {
194 /* Try different config. values */
195 config.max_clk_rate = MMC_CLK_200MHZ;
196 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
197 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
198 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
199 config.hs400_support = 0;
200
201 if (!(dev = mmc_init(&config))) {
202 dprintf(CRITICAL, "mmc init failed!");
203 ASSERT(0);
204 }
205 }
206}
207
208void *target_mmc_device()
209{
210 return (void *) dev;
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530211}
212
213/* Return 1 if vol_up pressed */
Gaurav Nebhwanid9dd0342016-01-28 16:35:55 +0530214int target_volume_up()
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530215{
216 uint8_t status = 0;
217
218 gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
219
220 /* Wait for the gpio config to take effect - debounce time */
221 thread_sleep(10);
222
223 /* Get status of GPIO */
224 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
225
226 /* Active high signal. */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530227 return !status;
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530228}
229
230/* Return 1 if vol_down pressed */
231uint32_t target_volume_down()
232{
233 /* Volume down button tied in with PMIC RESIN. */
234 return pm8x41_resin_status();
235}
236
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530237uint32_t target_is_pwrkey_pon_reason()
238{
239 uint8_t pon_reason = pm8950_get_pon_reason();
Vijay Kumar Pendoti7e9226c2016-09-21 20:49:21 +0530240 bool usb_present_sts = !(USBIN_UV_RT_STS &
241 pm8x41_reg_read(SMBCHG_USB_RT_STS));
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530242 if (pm8x41_get_is_cold_boot() && ((pon_reason == KPDPWR_N) || (pon_reason == (KPDPWR_N|PON1))))
243 return 1;
Vijay Kumar Pendoti7e9226c2016-09-21 20:49:21 +0530244 else if ((pon_reason == PON1) && (!usb_present_sts))
245 return 1;
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530246 else
247 return 0;
248}
249
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530250static void target_keystatus()
251{
252 keys_init();
253
254 if(target_volume_down())
255 keys_post_event(KEY_VOLUMEDOWN, 1);
256
257 if(target_volume_up())
258 keys_post_event(KEY_VOLUMEUP, 1);
259}
260
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530261void target_init(void)
262{
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530263 dprintf(INFO, "target_init()\n");
264
265 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
266
267 target_keystatus();
268
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530269 target_sdc_init();
270 if (partition_read_table())
271 {
272 dprintf(CRITICAL, "Error reading the partition table info\n");
273 ASSERT(0);
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530274 }
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530275
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530276#if LONG_PRESS_POWER_ON
277 shutdown_detect();
278#endif
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530279
c_wufeng41310ae2016-01-14 17:59:22 +0800280#if PON_VIB_SUPPORT
281 vib_timed_turn_on(VIBRATE_TIME);
282#endif
283
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530284
285 if (target_use_signed_kernel())
286 target_crypto_init_params();
287
288#if VERIFIED_BOOT
Mayank Grover8b2f19a2017-10-26 12:12:17 +0530289 if (VB_M <= target_get_vb_version())
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530290 {
Mayank Grover6878e012017-09-06 11:04:03 +0530291 clock_ce_enable(CE1_INSTANCE);
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530292
Mayank Grover6878e012017-09-06 11:04:03 +0530293 /* Initialize Qseecom */
294 if (qseecom_init() < 0)
295 {
296 dprintf(CRITICAL, "Failed to initialize qseecom\n");
297 ASSERT(0);
298 }
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530299
Mayank Grover6878e012017-09-06 11:04:03 +0530300 /* Start Qseecom */
301 if (qseecom_tz_init() < 0)
302 {
303 dprintf(CRITICAL, "Failed to start qseecom\n");
304 ASSERT(0);
305 }
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530306
Mayank Grover6878e012017-09-06 11:04:03 +0530307 if (rpmb_init() < 0)
308 {
309 dprintf(CRITICAL, "RPMB init failed\n");
310 ASSERT(0);
311 }
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530312
Mayank Grover6878e012017-09-06 11:04:03 +0530313 /*
314 * Load the sec app for first time
315 */
316 if (load_sec_app() < 0)
317 {
318 dprintf(CRITICAL, "Failed to load App for verified\n");
319 ASSERT(0);
320 }
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530321 }
322#endif
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530323
324#if SMD_SUPPORT
325 rpm_smd_init();
326#endif
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530327}
328
329void target_serialno(unsigned char *buf)
330{
331 uint32_t serialno;
332 if (target_is_emmc_boot()) {
333 serialno = mmc_get_psn();
334 snprintf((char *)buf, 13, "%x", serialno);
335 }
336}
337
338unsigned board_machtype(void)
339{
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530340 return LINUX_MACHTYPE_UNKNOWN;
341}
342
343/* Detect the target type */
344void target_detect(struct board_data *board)
345{
346 /* This is already filled as part of board.c */
347}
348
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530349/* Detect the modem type */
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530350void target_baseband_detect(struct board_data *board)
351{
352 uint32_t platform;
353
354 platform = board->platform;
355
356 switch(platform) {
Gaurav Nebhwani6c945a42016-02-16 17:26:51 +0530357 case MSM8953:
Mayank Grover759e0b02017-04-11 11:59:06 +0530358 case SDM450:
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530359 board->baseband = BASEBAND_MSM;
360 break;
Gaurav Nebhwani6c945a42016-02-16 17:26:51 +0530361 case APQ8053:
Gaurav Nebhwani22a0d9f2015-12-29 13:49:26 +0530362 board->baseband = BASEBAND_APQ;
363 break;
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530364 default:
365 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
366 ASSERT(0);
367 };
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530368}
369
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530370unsigned target_baseband()
371{
372 return board_baseband();
373}
lijuang395b5e62015-11-19 17:39:44 +0800374
375int set_download_mode(enum reboot_reason mode)
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530376{
377 int ret = 0;
378 ret = scm_dload_mode(mode);
379
380 pm8x41_clear_pmic_watchdog();
381
382 return ret;
383}
384
385int emmc_recovery_init(void)
386{
387 return _emmc_recovery_init();
388}
389
390unsigned target_pause_for_battery_charge(void)
391{
392 uint8_t pon_reason = pm8x41_get_pon_reason();
393 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
Zhenhua Huangcf812d72016-01-27 17:27:47 +0800394 bool usb_present_sts = !(USBIN_UV_RT_STS &
395 pm8x41_reg_read(SMBCHG_USB_RT_STS));
396 dprintf(INFO, "%s : pon_reason is:0x%x cold_boot:%d usb_sts:%d\n", __func__,
397 pon_reason, is_cold_boot, usb_present_sts);
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530398 /* In case of fastboot reboot,adb reboot or if we see the power key
399 * pressed we do not want go into charger mode.
400 * fastboot reboot is warm boot with PON hard reset bit not set
401 * adb reboot is a cold boot with PON hard reset bit set
402 */
403 if (is_cold_boot &&
404 (!(pon_reason & HARD_RST)) &&
405 (!(pon_reason & KPDPWR_N)) &&
Zhenhua Huangcf812d72016-01-27 17:27:47 +0800406 usb_present_sts)
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530407 return 1;
408 else
409 return 0;
410}
411
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530412void target_uninit(void)
413{
414 mmc_put_card_to_sleep(dev);
415 sdhci_mode_disable(&dev->host);
416 if (crypto_initialized())
417 crypto_eng_cleanup();
418
419 if (target_is_ssd_enabled())
420 clock_ce_disable(CE1_INSTANCE);
421
422#if VERIFIED_BOOT
Mayank Grover8b2f19a2017-10-26 12:12:17 +0530423 if (VB_M <= target_get_vb_version())
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530424 {
Mayank Grover6878e012017-09-06 11:04:03 +0530425 if (is_sec_app_loaded())
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530426 {
Mayank Grover6878e012017-09-06 11:04:03 +0530427 if (send_milestone_call_to_tz() < 0)
428 {
429 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
430 ASSERT(0);
431 }
432 }
433
434 if (rpmb_uninit() < 0)
435 {
436 dprintf(CRITICAL, "RPMB uninit failed\n");
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530437 ASSERT(0);
438 }
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530439
Mayank Grover6878e012017-09-06 11:04:03 +0530440 clock_ce_disable(CE1_INSTANCE);
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530441 }
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530442#endif
443
444#if SMD_SUPPORT
445 rpm_smd_uninit();
446#endif
447}
448
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530449/* UTMI MUX configuration to connect PHY to SNPS controller:
450 * Configure primary HS phy mux to use UTMI interface
451 * (connected to usb30 controller).
452 */
453static void tcsr_hs_phy_mux_configure(void)
454{
455 uint32_t reg;
456
457 reg = readl(USB2_PHY_SEL);
458
459 writel(reg | 0x1, USB2_PHY_SEL);
460}
461
462/* configure hs phy mux if using dwc controller */
463void target_usb_phy_mux_configure(void)
464{
465 if(!strcmp(target_usb_controller(), "dwc"))
466 {
467 tcsr_hs_phy_mux_configure();
468 }
469}
470
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530471void target_usb_phy_reset()
472{
473
474 usb30_qmp_phy_reset();
475 qusb2_phy_reset();
476}
477
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530478/* Initialize target specific USB handlers */
479target_usb_iface_t* target_usb30_init()
480{
481 target_usb_iface_t *t_usb_iface;
482
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530483 t_usb_iface = (target_usb_iface_t *) calloc(1, sizeof(target_usb_iface_t));
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530484 ASSERT(t_usb_iface);
485
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530486 t_usb_iface->mux_config = NULL;
487 t_usb_iface->phy_init = usb30_qmp_phy_init;
488 t_usb_iface->phy_reset = target_usb_phy_reset;
489 t_usb_iface->clock_init = clock_usb30_init;
490 t_usb_iface->vbus_override = 1;
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530491
492 return t_usb_iface;
493}
494
495/* identify the usb controller to be used for the target */
496const char * target_usb_controller()
497{
498 return "dwc";
499}
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530500
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530501/* Do any target specific intialization needed before entering fastboot mode */
502void target_fastboot_init(void)
503{
504 if (target_is_ssd_enabled()) {
505 clock_ce_enable(CE1_INSTANCE);
506 target_load_ssd_keystore();
507 }
508}
509
510void target_load_ssd_keystore(void)
511{
512 uint64_t ptn;
513 int index;
514 uint64_t size;
515 uint32_t *buffer = NULL;
516
517 if (!target_is_ssd_enabled())
518 return;
519
520 index = partition_get_index("ssd");
521
522 ptn = partition_get_offset(index);
523 if (ptn == 0){
524 dprintf(CRITICAL, "Error: ssd partition not found\n");
525 return;
526 }
527
528 size = partition_get_size(index);
529 if (size == 0) {
530 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
531 return;
532 }
533
534 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
535 if (!buffer) {
536 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
537 return;
538 }
539
540 if (mmc_read(ptn, buffer, size)) {
541 dprintf(CRITICAL, "Error: cannot read data\n");
542 free(buffer);
543 return;
544 }
545
546 clock_ce_enable(CE1_INSTANCE);
547 scm_protect_keystore(buffer, size);
548 clock_ce_disable(CE1_INSTANCE);
549 free(buffer);
550}
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530551
552crypto_engine_type board_ce_type(void)
553{
554 return CRYPTO_ENGINE_TYPE_HW;
555}
556
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530557/* Set up params for h/w CE. */
558void target_crypto_init_params()
559{
560 struct crypto_init_params ce_params;
561
562 /* Set up base addresses and instance. */
563 ce_params.crypto_instance = CE1_INSTANCE;
564 ce_params.crypto_base = MSM_CE1_BASE;
565 ce_params.bam_base = MSM_CE1_BAM_BASE;
566
567 /* Set up BAM config. */
568 ce_params.bam_ee = CE_EE;
569 ce_params.pipes.read_pipe = CE_READ_PIPE;
570 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
571 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
572 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
573
574 /* Assign buffer sizes. */
575 ce_params.num_ce = CE_ARRAY_SIZE;
576 ce_params.read_fifo_size = CE_FIFO_SIZE;
577 ce_params.write_fifo_size = CE_FIFO_SIZE;
578
579 /* BAM is initialized by TZ for this platform.
580 * Do not do it again as the initialization address space
581 * is locked.
582 */
583 ce_params.do_bam_init = 0;
584
585 crypto_init_params(&ce_params);
586}
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530587
588void pmic_reset_configure(uint8_t reset_type)
589{
P.V. Phani Kumar765fe3e2016-01-23 00:59:03 +0530590 pm8994_reset_configure(reset_type);
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530591}
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530592
593uint32_t target_get_pmic()
594{
595 return PMIC_IS_PMI8950;
596}
597
598struct qmp_reg qmp_settings[] =
599{
Mayank Grovere55fe622016-10-13 18:39:05 +0530600 {0x804, 0x01}, /* USB3PHY_PCIE_USB3_PCS_POWER_DOWN_CONTROL */
601
602 /* Common block settings */
603 {0xAC, 0x14}, /* QSERDES_COM_SYSCLK_EN_SEL */
604 {0x34, 0x08}, /* QSERDES_COM_BIAS_EN_CLKBUFLR_EN */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530605 {0x174, 0x30}, /* QSERDES_COM_CLK_SELECT */
Mayank Grovere55fe622016-10-13 18:39:05 +0530606 {0x70, 0x0F}, /* USB3PHY_QSERDES_COM_BG_TRIM */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530607 {0x19c, 0x01}, /* QSERDES_COM_SVS_MODE_CLK_SEL */
608 {0x178, 0x00}, /* QSERDES_COM_HSCLK_SEL */
Mayank Grovere55fe622016-10-13 18:39:05 +0530609 {0x194, 0x06}, /* QSERDES_COM_CMN_CONFIG */
610 {0x48, 0x0F}, /* USB3PHY_QSERDES_COM_PLL_IVCO */
611 {0x3C, 0x02}, /* QSERDES_COM_SYS_CLK_CTRL */
612
613 /* PLL & Loop filter settings */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530614 {0xd0, 0x82}, /* QSERDES_COM_DEC_START_MODE0 */
615 {0xdc, 0x55}, /* QSERDES_COM_DIV_FRAC_START1_MODE0 */
616 {0xe0, 0x55}, /* QSERDES_COM_DIV_FRAC_START2_MODE0 */
617 {0xe4, 0x03}, /* QSERDES_COM_DIV_FRAC_START3_MODE0 */
618 {0x78, 0x0b}, /* QSERDES_COM_CP_CTRL_MODE0 */
619 {0x84, 0x16}, /* QSERDES_COM_PLL_RCTRL_MODE0 */
620 {0x90, 0x28}, /* QSERDES_COM_PLL_CCTRL_MODE0 */
621 {0x108, 0x80}, /* QSERDES_COM_INTEGLOOP_GAIN0_MODE0 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530622 {0x4c, 0x15}, /* QSERDES_COM_LOCK_CMP1_MODE0 */
623 {0x50, 0x34}, /* QSERDES_COM_LOCK_CMP2_MODE0 */
624 {0x54, 0x00}, /* QSERDES_COM_LOCK_CMP3_MODE0 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530625 {0x18c, 0x00}, /* QSERDES_COM_CORE_CLK_EN */
626 {0xcc, 0x00}, /* QSERDES_COM_LOCK_CMP_CFG */
627 {0x128, 0x00}, /* QSERDES_COM_VCO_TUNE_MAP */
628 {0x0C, 0x0A}, /* QSERDES_COM_BG_TIMER */
Mayank Grovere55fe622016-10-13 18:39:05 +0530629
630 /* SSC Settings */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530631 {0x10, 0x01}, /* QSERDES_COM_SSC_EN_CENTER */
632 {0x1c, 0x31}, /* QSERDES_COM_SSC_PER1 */
633 {0x20, 0x01}, /* QSERDES_COM_SSC_PER2 */
634 {0x14, 0x00}, /* QSERDES_COM_SSC_ADJ_PER1 */
635 {0x18, 0x00}, /* QSERDES_COM_SSC_ADJ_PER2 */
636 {0x24, 0xde}, /* QSERDES_COM_SSC_STEP_SIZE1 */
637 {0x28, 0x07}, /* QSERDES_COM_SSC_STEP_SIZE2 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530638
639 /* Rx Settings */
Mayank Grovere55fe622016-10-13 18:39:05 +0530640 {0x41C, 0x06}, /* QSERDES_RX_UCDR_SO_GAIN */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530641 {0x4d8, 0x02}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2 */
Mayank Grovere55fe622016-10-13 18:39:05 +0530642 {0x4dc, 0x4c}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3 */
643 {0x4e0, 0xb8}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530644 {0x508, 0x77}, /* QSERDES_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1 */
645 {0x50c, 0x80}, /* QSERDES_RX_RX_OFFSET_ADAPTOR_CNTRL2 */
646 {0x514, 0x03}, /* QSERDES_RX_SIGDET_CNTRL */
647 {0x51c, 0x16}, /* QSERDES_RX_SIGDET_DEGLITCH_CNTRL */
Mayank Grovere55fe622016-10-13 18:39:05 +0530648 {0x510, 0x0C}, /* QSERDES_RX_SIGDET_ENABLES */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530649
650 /* Tx settings */
651 {0x268, 0x45}, /* QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN */
652 {0x2ac, 0x12}, /* QSERDES_TX_RCV_DETECT_LVL_2 */
653 {0x294, 0x06}, /* QSERDES_TX_LANE_MODE */
Mayank Grovere55fe622016-10-13 18:39:05 +0530654 {0x824, 0x15}, /* PCIE_USB3_PCS_TXDEEMPH_M6DB_V0 */
655 {0x828, 0x0E}, /* PCIE_USB3_PCS_TXDEEMPH_M3P5DB_V0 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530656
657 /* FLL settings */
658 {0x8c8, 0x83}, /* PCIE_USB3_PCS_FLL_CNTRL2 */
659 {0x8c4, 0x02}, /* PCIE_USB3_PCS_FLL_CNTRL1 */
660 {0x8cc, 0x09}, /* PCIE_USB3_PCS_FLL_CNT_VAL_L */
661 {0x8D0, 0xA2}, /* PCIE_USB3_PCS_FLL_CNT_VAL_H_TOL */
662 {0x8D4, 0x85}, /* PCIE_USB3_PCS_FLL_MAN_CODE */
663
664 /* PCS Settings */
665 {0x880, 0xD1}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG1 */
666 {0x884, 0x1F}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG2 */
667 {0x888, 0x47}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG3 */
Mayank Grovere55fe622016-10-13 18:39:05 +0530668 {0x864, 0x1B}, /* PCIE_USB3_PCS_POWER_STATE_CONFIG2 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530669 {0x8B8, 0x75}, /* PCIE_USB3_PCS_RXEQTRAINING_WAIT_TIME */
670 {0x8BC, 0x13}, /* PCIE_USB3_PCS_RXEQTRAINING_RUN_TIME */
671 {0x8B0, 0x86}, /* PCIE_USB3_PCS_LFPS_TX_ECSTART_EQTLOCK */
672 {0x8A0, 0x04}, /* PCIE_USB3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK */
673 {0x88C, 0x44}, /* PCIE_USB3_PCS_TSYNC_RSYNC_TIME */
674 {0x870, 0xE7}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_P1U2_L */
675 {0x874, 0x03}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_P1U2_H */
676 {0x878, 0x40}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_U3_L */
677 {0x87c, 0x00}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_U3_H */
678 {0x9D8, 0x88}, /* PCIE_USB3_PCS_RX_SIGDET_LVL */
679 {0x808, 0x03}, /* PCIE_USB3_PCS_START_CONTROL */
680 {0x800, 0x00}, /* PCIE_USB3_PCS_SW_RESET */
681};
682
683struct qmp_reg *target_get_qmp_settings()
684{
685 return qmp_settings;
686}
687
688int target_get_qmp_regsize()
689{
690 return ARRAY_SIZE(qmp_settings);
691}
Padmanabhan Komanduru0104a892016-01-22 16:58:10 +0530692static uint8_t splash_override;
693/* Returns 1 if target supports continuous splash screen. */
694int target_cont_splash_screen()
695{
696 uint8_t splash_screen = 0;
697 if (!splash_override) {
698 switch (board_hardware_id()) {
699 case HW_PLATFORM_MTP:
700 case HW_PLATFORM_SURF:
701 case HW_PLATFORM_RCM:
702 case HW_PLATFORM_QRD:
703 splash_screen = 1;
704 break;
705 default:
706 splash_screen = 0;
707 break;
708 }
709 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
710 }
711 return splash_screen;
712}
713
714void target_force_cont_splash_disable(uint8_t override)
715{
716 splash_override = override;
717}