blob: 199f1f56966410b9d827d6907db64888bd8f5211 [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:
Mayank Grover3dc285c2017-12-26 12:47:09 +0530362 case SDA450:
Gaurav Nebhwani22a0d9f2015-12-29 13:49:26 +0530363 board->baseband = BASEBAND_APQ;
364 break;
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530365 default:
366 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
367 ASSERT(0);
368 };
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530369}
370
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530371unsigned target_baseband()
372{
373 return board_baseband();
374}
lijuang395b5e62015-11-19 17:39:44 +0800375
376int set_download_mode(enum reboot_reason mode)
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530377{
378 int ret = 0;
379 ret = scm_dload_mode(mode);
380
381 pm8x41_clear_pmic_watchdog();
382
383 return ret;
384}
385
386int emmc_recovery_init(void)
387{
388 return _emmc_recovery_init();
389}
390
391unsigned target_pause_for_battery_charge(void)
392{
393 uint8_t pon_reason = pm8x41_get_pon_reason();
394 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
Zhenhua Huangcf812d72016-01-27 17:27:47 +0800395 bool usb_present_sts = !(USBIN_UV_RT_STS &
396 pm8x41_reg_read(SMBCHG_USB_RT_STS));
397 dprintf(INFO, "%s : pon_reason is:0x%x cold_boot:%d usb_sts:%d\n", __func__,
398 pon_reason, is_cold_boot, usb_present_sts);
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530399 /* In case of fastboot reboot,adb reboot or if we see the power key
400 * pressed we do not want go into charger mode.
401 * fastboot reboot is warm boot with PON hard reset bit not set
402 * adb reboot is a cold boot with PON hard reset bit set
403 */
404 if (is_cold_boot &&
405 (!(pon_reason & HARD_RST)) &&
406 (!(pon_reason & KPDPWR_N)) &&
Zhenhua Huangcf812d72016-01-27 17:27:47 +0800407 usb_present_sts)
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530408 return 1;
409 else
410 return 0;
411}
412
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530413void target_uninit(void)
414{
415 mmc_put_card_to_sleep(dev);
416 sdhci_mode_disable(&dev->host);
417 if (crypto_initialized())
418 crypto_eng_cleanup();
419
420 if (target_is_ssd_enabled())
421 clock_ce_disable(CE1_INSTANCE);
422
423#if VERIFIED_BOOT
Mayank Grover8b2f19a2017-10-26 12:12:17 +0530424 if (VB_M <= target_get_vb_version())
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530425 {
Mayank Grover6878e012017-09-06 11:04:03 +0530426 if (is_sec_app_loaded())
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530427 {
Mayank Grover6878e012017-09-06 11:04:03 +0530428 if (send_milestone_call_to_tz() < 0)
429 {
430 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
431 ASSERT(0);
432 }
433 }
434
435 if (rpmb_uninit() < 0)
436 {
437 dprintf(CRITICAL, "RPMB uninit failed\n");
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530438 ASSERT(0);
439 }
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530440
Mayank Grover6878e012017-09-06 11:04:03 +0530441 clock_ce_disable(CE1_INSTANCE);
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530442 }
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530443#endif
444
445#if SMD_SUPPORT
446 rpm_smd_uninit();
447#endif
448}
449
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530450/* UTMI MUX configuration to connect PHY to SNPS controller:
451 * Configure primary HS phy mux to use UTMI interface
452 * (connected to usb30 controller).
453 */
454static void tcsr_hs_phy_mux_configure(void)
455{
456 uint32_t reg;
457
458 reg = readl(USB2_PHY_SEL);
459
460 writel(reg | 0x1, USB2_PHY_SEL);
461}
462
463/* configure hs phy mux if using dwc controller */
464void target_usb_phy_mux_configure(void)
465{
466 if(!strcmp(target_usb_controller(), "dwc"))
467 {
468 tcsr_hs_phy_mux_configure();
469 }
470}
471
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530472void target_usb_phy_reset()
473{
474
475 usb30_qmp_phy_reset();
476 qusb2_phy_reset();
477}
478
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530479/* Initialize target specific USB handlers */
480target_usb_iface_t* target_usb30_init()
481{
482 target_usb_iface_t *t_usb_iface;
483
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530484 t_usb_iface = (target_usb_iface_t *) calloc(1, sizeof(target_usb_iface_t));
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530485 ASSERT(t_usb_iface);
486
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530487 t_usb_iface->mux_config = NULL;
488 t_usb_iface->phy_init = usb30_qmp_phy_init;
489 t_usb_iface->phy_reset = target_usb_phy_reset;
490 t_usb_iface->clock_init = clock_usb30_init;
491 t_usb_iface->vbus_override = 1;
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530492
493 return t_usb_iface;
494}
495
496/* identify the usb controller to be used for the target */
497const char * target_usb_controller()
498{
499 return "dwc";
500}
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530501
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530502/* Do any target specific intialization needed before entering fastboot mode */
503void target_fastboot_init(void)
504{
505 if (target_is_ssd_enabled()) {
506 clock_ce_enable(CE1_INSTANCE);
507 target_load_ssd_keystore();
508 }
509}
510
511void target_load_ssd_keystore(void)
512{
513 uint64_t ptn;
514 int index;
515 uint64_t size;
516 uint32_t *buffer = NULL;
517
518 if (!target_is_ssd_enabled())
519 return;
520
521 index = partition_get_index("ssd");
522
523 ptn = partition_get_offset(index);
524 if (ptn == 0){
525 dprintf(CRITICAL, "Error: ssd partition not found\n");
526 return;
527 }
528
529 size = partition_get_size(index);
530 if (size == 0) {
531 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
532 return;
533 }
534
535 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
536 if (!buffer) {
537 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
538 return;
539 }
540
541 if (mmc_read(ptn, buffer, size)) {
542 dprintf(CRITICAL, "Error: cannot read data\n");
543 free(buffer);
544 return;
545 }
546
547 clock_ce_enable(CE1_INSTANCE);
548 scm_protect_keystore(buffer, size);
549 clock_ce_disable(CE1_INSTANCE);
550 free(buffer);
551}
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530552
553crypto_engine_type board_ce_type(void)
554{
555 return CRYPTO_ENGINE_TYPE_HW;
556}
557
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530558/* Set up params for h/w CE. */
559void target_crypto_init_params()
560{
561 struct crypto_init_params ce_params;
562
563 /* Set up base addresses and instance. */
564 ce_params.crypto_instance = CE1_INSTANCE;
565 ce_params.crypto_base = MSM_CE1_BASE;
566 ce_params.bam_base = MSM_CE1_BAM_BASE;
567
568 /* Set up BAM config. */
569 ce_params.bam_ee = CE_EE;
570 ce_params.pipes.read_pipe = CE_READ_PIPE;
571 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
572 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
573 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
574
575 /* Assign buffer sizes. */
576 ce_params.num_ce = CE_ARRAY_SIZE;
577 ce_params.read_fifo_size = CE_FIFO_SIZE;
578 ce_params.write_fifo_size = CE_FIFO_SIZE;
579
580 /* BAM is initialized by TZ for this platform.
581 * Do not do it again as the initialization address space
582 * is locked.
583 */
584 ce_params.do_bam_init = 0;
585
586 crypto_init_params(&ce_params);
587}
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530588
589void pmic_reset_configure(uint8_t reset_type)
590{
P.V. Phani Kumar765fe3e2016-01-23 00:59:03 +0530591 pm8994_reset_configure(reset_type);
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530592}
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530593
594uint32_t target_get_pmic()
595{
596 return PMIC_IS_PMI8950;
597}
598
599struct qmp_reg qmp_settings[] =
600{
Mayank Grovere55fe622016-10-13 18:39:05 +0530601 {0x804, 0x01}, /* USB3PHY_PCIE_USB3_PCS_POWER_DOWN_CONTROL */
602
603 /* Common block settings */
604 {0xAC, 0x14}, /* QSERDES_COM_SYSCLK_EN_SEL */
605 {0x34, 0x08}, /* QSERDES_COM_BIAS_EN_CLKBUFLR_EN */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530606 {0x174, 0x30}, /* QSERDES_COM_CLK_SELECT */
Mayank Grovere55fe622016-10-13 18:39:05 +0530607 {0x70, 0x0F}, /* USB3PHY_QSERDES_COM_BG_TRIM */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530608 {0x19c, 0x01}, /* QSERDES_COM_SVS_MODE_CLK_SEL */
609 {0x178, 0x00}, /* QSERDES_COM_HSCLK_SEL */
Mayank Grovere55fe622016-10-13 18:39:05 +0530610 {0x194, 0x06}, /* QSERDES_COM_CMN_CONFIG */
611 {0x48, 0x0F}, /* USB3PHY_QSERDES_COM_PLL_IVCO */
612 {0x3C, 0x02}, /* QSERDES_COM_SYS_CLK_CTRL */
613
614 /* PLL & Loop filter settings */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530615 {0xd0, 0x82}, /* QSERDES_COM_DEC_START_MODE0 */
616 {0xdc, 0x55}, /* QSERDES_COM_DIV_FRAC_START1_MODE0 */
617 {0xe0, 0x55}, /* QSERDES_COM_DIV_FRAC_START2_MODE0 */
618 {0xe4, 0x03}, /* QSERDES_COM_DIV_FRAC_START3_MODE0 */
619 {0x78, 0x0b}, /* QSERDES_COM_CP_CTRL_MODE0 */
620 {0x84, 0x16}, /* QSERDES_COM_PLL_RCTRL_MODE0 */
621 {0x90, 0x28}, /* QSERDES_COM_PLL_CCTRL_MODE0 */
622 {0x108, 0x80}, /* QSERDES_COM_INTEGLOOP_GAIN0_MODE0 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530623 {0x4c, 0x15}, /* QSERDES_COM_LOCK_CMP1_MODE0 */
624 {0x50, 0x34}, /* QSERDES_COM_LOCK_CMP2_MODE0 */
625 {0x54, 0x00}, /* QSERDES_COM_LOCK_CMP3_MODE0 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530626 {0x18c, 0x00}, /* QSERDES_COM_CORE_CLK_EN */
627 {0xcc, 0x00}, /* QSERDES_COM_LOCK_CMP_CFG */
628 {0x128, 0x00}, /* QSERDES_COM_VCO_TUNE_MAP */
629 {0x0C, 0x0A}, /* QSERDES_COM_BG_TIMER */
Mayank Grovere55fe622016-10-13 18:39:05 +0530630
631 /* SSC Settings */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530632 {0x10, 0x01}, /* QSERDES_COM_SSC_EN_CENTER */
633 {0x1c, 0x31}, /* QSERDES_COM_SSC_PER1 */
634 {0x20, 0x01}, /* QSERDES_COM_SSC_PER2 */
635 {0x14, 0x00}, /* QSERDES_COM_SSC_ADJ_PER1 */
636 {0x18, 0x00}, /* QSERDES_COM_SSC_ADJ_PER2 */
637 {0x24, 0xde}, /* QSERDES_COM_SSC_STEP_SIZE1 */
638 {0x28, 0x07}, /* QSERDES_COM_SSC_STEP_SIZE2 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530639
640 /* Rx Settings */
Mayank Grovere55fe622016-10-13 18:39:05 +0530641 {0x41C, 0x06}, /* QSERDES_RX_UCDR_SO_GAIN */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530642 {0x4d8, 0x02}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2 */
Mayank Grovere55fe622016-10-13 18:39:05 +0530643 {0x4dc, 0x4c}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3 */
644 {0x4e0, 0xb8}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530645 {0x508, 0x77}, /* QSERDES_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1 */
646 {0x50c, 0x80}, /* QSERDES_RX_RX_OFFSET_ADAPTOR_CNTRL2 */
647 {0x514, 0x03}, /* QSERDES_RX_SIGDET_CNTRL */
648 {0x51c, 0x16}, /* QSERDES_RX_SIGDET_DEGLITCH_CNTRL */
Mayank Grovere55fe622016-10-13 18:39:05 +0530649 {0x510, 0x0C}, /* QSERDES_RX_SIGDET_ENABLES */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530650
651 /* Tx settings */
652 {0x268, 0x45}, /* QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN */
653 {0x2ac, 0x12}, /* QSERDES_TX_RCV_DETECT_LVL_2 */
654 {0x294, 0x06}, /* QSERDES_TX_LANE_MODE */
Mayank Grovere55fe622016-10-13 18:39:05 +0530655 {0x824, 0x15}, /* PCIE_USB3_PCS_TXDEEMPH_M6DB_V0 */
656 {0x828, 0x0E}, /* PCIE_USB3_PCS_TXDEEMPH_M3P5DB_V0 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530657
658 /* FLL settings */
659 {0x8c8, 0x83}, /* PCIE_USB3_PCS_FLL_CNTRL2 */
660 {0x8c4, 0x02}, /* PCIE_USB3_PCS_FLL_CNTRL1 */
661 {0x8cc, 0x09}, /* PCIE_USB3_PCS_FLL_CNT_VAL_L */
662 {0x8D0, 0xA2}, /* PCIE_USB3_PCS_FLL_CNT_VAL_H_TOL */
663 {0x8D4, 0x85}, /* PCIE_USB3_PCS_FLL_MAN_CODE */
664
665 /* PCS Settings */
666 {0x880, 0xD1}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG1 */
667 {0x884, 0x1F}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG2 */
668 {0x888, 0x47}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG3 */
Mayank Grovere55fe622016-10-13 18:39:05 +0530669 {0x864, 0x1B}, /* PCIE_USB3_PCS_POWER_STATE_CONFIG2 */
P.V. Phani Kumar77826d32015-12-26 20:56:35 +0530670 {0x8B8, 0x75}, /* PCIE_USB3_PCS_RXEQTRAINING_WAIT_TIME */
671 {0x8BC, 0x13}, /* PCIE_USB3_PCS_RXEQTRAINING_RUN_TIME */
672 {0x8B0, 0x86}, /* PCIE_USB3_PCS_LFPS_TX_ECSTART_EQTLOCK */
673 {0x8A0, 0x04}, /* PCIE_USB3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK */
674 {0x88C, 0x44}, /* PCIE_USB3_PCS_TSYNC_RSYNC_TIME */
675 {0x870, 0xE7}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_P1U2_L */
676 {0x874, 0x03}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_P1U2_H */
677 {0x878, 0x40}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_U3_L */
678 {0x87c, 0x00}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_U3_H */
679 {0x9D8, 0x88}, /* PCIE_USB3_PCS_RX_SIGDET_LVL */
680 {0x808, 0x03}, /* PCIE_USB3_PCS_START_CONTROL */
681 {0x800, 0x00}, /* PCIE_USB3_PCS_SW_RESET */
682};
683
684struct qmp_reg *target_get_qmp_settings()
685{
686 return qmp_settings;
687}
688
689int target_get_qmp_regsize()
690{
691 return ARRAY_SIZE(qmp_settings);
692}
Padmanabhan Komanduru0104a892016-01-22 16:58:10 +0530693static uint8_t splash_override;
694/* Returns 1 if target supports continuous splash screen. */
695int target_cont_splash_screen()
696{
697 uint8_t splash_screen = 0;
698 if (!splash_override) {
699 switch (board_hardware_id()) {
700 case HW_PLATFORM_MTP:
701 case HW_PLATFORM_SURF:
702 case HW_PLATFORM_RCM:
703 case HW_PLATFORM_QRD:
704 splash_screen = 1;
705 break;
706 default:
707 splash_screen = 0;
708 break;
709 }
710 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
711 }
712 return splash_screen;
713}
714
715void target_force_cont_splash_disable(uint8_t override)
716{
717 splash_override = override;
718}