blob: 2203e013d57a4f8d48ed1dd2add10c3ac44e5dd6 [file] [log] [blame]
vijay kumarba95efb2015-09-08 15:24:12 +05301/* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
Unnati Gandhi4d07fac2014-07-04 17:38:25 +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>
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053036#include <dev/keys.h>
37#include <spmi_v2.h>
38#include <pm8x41.h>
39#include <board.h>
40#include <baseband.h>
41#include <hsusb.h>
42#include <scm.h>
43#include <platform/gpio.h>
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053044#include <platform/irqs.h>
45#include <platform/clock.h>
46#include <crypto5_wrapper.h>
47#include <partition_parser.h>
48#include <stdlib.h>
Unnati Gandhi4d637e42014-07-11 14:47:25 +053049#include <gpio.h>
Unnati Gandhic24a86f2014-09-19 16:07:16 +053050#include <rpm-smd.h>
Unnati Gandhic43a2802014-09-19 17:27:25 +053051#include <qpic_nand.h>
lijuang3606df82015-09-02 21:14:43 +080052#include <smem.h>
Mayank Grover7e351832017-04-21 15:03:58 +053053#include <secapp_loader.h>
54#include <rpmb.h>
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053055
Unnati Gandhif4cb6622014-08-28 13:54:56 +053056#if LONG_PRESS_POWER_ON
57#include <shutdown_detect.h>
58#endif
59
60#if PON_VIB_SUPPORT
61#include <vibrator.h>
62#endif
63
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053064#define PMIC_ARB_CHANNEL_NUM 0
65#define PMIC_ARB_OWNER_ID 0
Unnati Gandhif4cb6622014-08-28 13:54:56 +053066#define TLMM_VOL_UP_BTN_GPIO 90
Matthew Qin7bd789f2015-07-15 15:31:20 +080067#define TLMM_VOL_DOWN_BTN_GPIO 91
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053068
Unnati Gandhif4cb6622014-08-28 13:54:56 +053069#if PON_VIB_SUPPORT
70#define VIBRATE_TIME 250
71#endif
Vijay Kumar Pendotib228cfc2016-06-13 20:15:23 +053072#define HW_SUBTYPE_APQ_NOWGR 0xA
Unnati Gandhif4cb6622014-08-28 13:54:56 +053073
Unnati Gandhif4cb6622014-08-28 13:54:56 +053074#define CE1_INSTANCE 1
75#define CE_EE 1
76#define CE_FIFO_SIZE 64
77#define CE_READ_PIPE 3
78#define CE_WRITE_PIPE 2
79#define CE_READ_PIPE_LOCK_GRP 0
80#define CE_WRITE_PIPE_LOCK_GRP 0
81#define CE_ARRAY_SIZE 20
Matthew Qin7bd789f2015-07-15 15:31:20 +080082#define SUB_TYPE_SKUT 0x0A
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053083
Unnati Gandhic43a2802014-09-19 17:27:25 +053084extern void smem_ptable_init(void);
85extern void smem_add_modem_partitions(struct ptable *flash_ptable);
86void target_sdc_init();
87
88static struct ptable flash_ptable;
89
90/* NANDc BAM pipe numbers */
91#define DATA_CONSUMER_PIPE 0
92#define DATA_PRODUCER_PIPE 1
93#define CMD_PIPE 2
94
95/* NANDc BAM pipe groups */
96#define DATA_PRODUCER_PIPE_GRP 0
97#define DATA_CONSUMER_PIPE_GRP 0
98#define CMD_PIPE_GRP 1
99
100/* NANDc EE */
101#define QPIC_NAND_EE 0
102
103/* NANDc max desc length. */
104#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
105
106#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
Mayank Groverc1190022017-02-23 17:28:46 +0530107#define UBI_CMDLINE " rootfstype=ubifs rootflags=bulk_read"
Unnati Gandhic43a2802014-09-19 17:27:25 +0530108
109struct qpic_nand_init_config config;
110
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530111struct mmc_device *dev;
112
113static uint32_t mmc_pwrctl_base[] =
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530114 { MSM_SDC1_BASE, MSM_SDC2_BASE };
115
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530116static uint32_t mmc_sdhci_base[] =
117 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
118
119static uint32_t mmc_sdc_pwrctl_irq[] =
120 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
121
122static void set_sdc_power_ctrl(void);
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700123static void set_ebi2_config(void);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530124
Mayank Grover7e351832017-04-21 15:03:58 +0530125#if VERIFIED_BOOT
126/**
127* Check if keymaster partition is present to test
128* if we have VB on this target.
129**/
130static bool target_is_vb_enabled()
131{
132 if (partition_get_index("keymaster") == INVALID_PTN)
133 return false;
134 return true;
135}
136#endif
137
Unnati Gandhic43a2802014-09-19 17:27:25 +0530138void update_ptable_names(void)
139{
140 uint32_t ptn_index;
141 struct ptentry *ptentry_ptr = flash_ptable.parts;
142 struct ptentry *boot_ptn;
143 unsigned i;
144 uint32_t len;
145
146 /* Change all names to lower case. */
147 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
148 {
149 len = strlen(ptentry_ptr[ptn_index].name);
150
151 for (i = 0; i < len; i++)
152 {
153 if (isupper(ptentry_ptr[ptn_index].name[i]))
154 {
155 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
156 }
157 }
158
159 /* SBL fills in the last partition length as 0xFFFFFFFF.
160 * Update the length field based on the number of blocks on the flash.
161 */
162 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
163 {
164 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
165 }
166 }
167}
168
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530169void target_early_init(void)
170{
171#if WITH_DEBUG_UART
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530172 /* Do not intilaise UART in case the h/w
173 * is RCM.
174 */
175 if( board_hardware_id()!= HW_PLATFORM_RCM )
176 uart_dm_init(1, 0, BLSP1_UART0_BASE);
177 else
178 return;
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530179#endif
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530180
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530181}
182
Unnati Gandhic43a2802014-09-19 17:27:25 +0530183int target_is_emmc_boot(void)
184{
185 return platform_boot_dev_isemmc();
186}
187
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530188void target_sdc_init()
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530189{
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530190 struct mmc_config_data config;
191
192 /* Set drive strength & pull ctrl values */
193 set_sdc_power_ctrl();
194
195 config.bus_width = DATA_BUS_WIDTH_8BIT;
196 config.max_clk_rate = MMC_CLK_177MHZ;
197
198 /* Try slot 1*/
199 config.slot = 1;
200 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
201 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
202 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
203 config.hs400_support = 0;
204
205 if (!(dev = mmc_init(&config))) {
206 /* Try slot 2 */
207 config.slot = 2;
208 config.max_clk_rate = MMC_CLK_200MHZ;
209 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
210 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
211 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
212
213 if (!(dev = mmc_init(&config))) {
214 dprintf(CRITICAL, "mmc init failed!");
215 ASSERT(0);
216 }
217 }
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530218}
219
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530220void *target_mmc_device()
221{
222 return (void *) dev;
223}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530224
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530225/* Return 1 if vol_up pressed */
lijuang2d2b8a02015-06-05 21:34:15 +0800226int target_volume_up()
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530227{
lijuang2d2b8a02015-06-05 21:34:15 +0800228 static uint8_t first_time = 0;
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530229 uint8_t status = 0;
230
lijuang2d2b8a02015-06-05 21:34:15 +0800231 if (!first_time) {
232 gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530233
lijuang2d2b8a02015-06-05 21:34:15 +0800234 /* Wait for the gpio config to take effect - debounce time */
235 udelay(10000);
236
237 first_time = 1;
238 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530239
240 /* Get status of GPIO */
241 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
242
243 /* Active low signal. */
244 return !status;
245}
246
247/* Return 1 if vol_down pressed */
248uint32_t target_volume_down()
249{
Matthew Qin7bd789f2015-07-15 15:31:20 +0800250 if ((board_hardware_id() == HW_PLATFORM_QRD) &&
251 (board_hardware_subtype() == SUB_TYPE_SKUT)) {
252 uint32_t status = 0;
253
254 gpio_tlmm_config(TLMM_VOL_DOWN_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
255
256 /* Wait for the gpio config to take effect - debounce time */
257 thread_sleep(10);
258
259 /* Get status of GPIO */
260 status = gpio_status(TLMM_VOL_DOWN_BTN_GPIO);
261
262 /* Active low signal. */
263 return !status;
264 } else {
265 /* Volume down button tied in with PMIC RESIN. */
266 return pm8x41_resin_status();
267 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530268}
269
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530270static void target_keystatus()
271{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530272 keys_init();
273
274 if(target_volume_down())
275 keys_post_event(KEY_VOLUMEDOWN, 1);
276
277 if(target_volume_up())
278 keys_post_event(KEY_VOLUMEUP, 1);
279
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530280}
281
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530282static void set_sdc_power_ctrl()
283{
284 /* Drive strength configs for sdc pins */
285 struct tlmm_cfgs sdc1_hdrv_cfg[] =
286 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700287 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
288 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi9a6e6d42015-02-03 17:44:24 +0530289 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530290 };
291
292 /* Pull configs for sdc pins */
293 struct tlmm_cfgs sdc1_pull_cfg[] =
294 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700295 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
296 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
297 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530298 };
299
300 /* Set the drive strength & pull control values */
301 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
302 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
303}
304
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700305static void set_ebi2_config()
306{
307 /* Drive strength configs for ebi2 pins */
308 struct tlmm_cfgs ebi2_hdrv_cfg[] =
309 {
310 { EBI2_BUSY_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
311 { EBI2_WE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
312 { EBI2_OE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
313 { EBI2_CLE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
314 { EBI2_ALE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
315 { EBI2_CS_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
316 { EBI2_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
317 };
318
319 /* Pull configs for ebi2 pins */
320 struct tlmm_cfgs ebi2_pull_cfg[] =
321 {
322 { EBI2_BUSY_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
323 { EBI2_WE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
324 { EBI2_OE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
325 { EBI2_CLE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
326 { EBI2_ALE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
327 { EBI2_CS_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
328 { EBI2_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
329 };
330
331 /* Set the drive strength & pull control values */
332 tlmm_set_hdrive_ctrl(ebi2_hdrv_cfg, ARRAY_SIZE(ebi2_hdrv_cfg));
333 tlmm_set_pull_ctrl(ebi2_pull_cfg, ARRAY_SIZE(ebi2_pull_cfg));
334
335}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530336void target_init(void)
337{
338 uint32_t base_addr;
339 uint8_t slot;
Mayank Grover7e351832017-04-21 15:03:58 +0530340#if VERIFIED_BOOT
341 int ret = 0;
342#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530343 dprintf(INFO, "target_init()\n");
344
345 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
346
347 target_keystatus();
348
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530349#if BOOT_CONFIG_SUPPORT
Unnati Gandhic43a2802014-09-19 17:27:25 +0530350 platform_read_boot_config();
Unnati Gandhi8e4711b2014-10-13 05:03:00 +0530351#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530352
Unnati Gandhic43a2802014-09-19 17:27:25 +0530353 if (platform_boot_dev_isemmc()) {
354 target_sdc_init();
355 if (partition_read_table())
356 {
357 dprintf(CRITICAL, "Error reading the partition table info\n");
358 ASSERT(0);
359 }
360
361 } else {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700362 set_ebi2_config();
Unnati Gandhic43a2802014-09-19 17:27:25 +0530363 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
364 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
365 config.pipes.cmd_pipe = CMD_PIPE;
366
367 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
368 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
369 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
370
371 config.bam_base = MSM_NAND_BAM_BASE;
372 config.nand_base = MSM_NAND_BASE;
373 config.ee = QPIC_NAND_EE;
374 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
375
376 qpic_nand_init(&config);
377
378 ptable_init(&flash_ptable);
379 smem_ptable_init();
380 smem_add_modem_partitions(&flash_ptable);
381
382 update_ptable_names();
383 flash_set_ptable(&flash_ptable);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530384 }
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530385
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530386#if LONG_PRESS_POWER_ON
387 shutdown_detect();
388#endif
389
390#if PON_VIB_SUPPORT
391
392 /* turn on vibrator to indicate that phone is booting up to end user */
Mayank Grover7e351832017-04-21 15:03:58 +0530393 vib_timed_turn_on(VIBRATE_TIME);
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530394#endif
395
396 if (target_use_signed_kernel())
397 target_crypto_init_params();
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530398
Mayank Grover7e351832017-04-21 15:03:58 +0530399#if VERIFIED_BOOT
400 if (target_is_vb_enabled())
401 {
402 clock_ce_enable(CE1_INSTANCE);
403
404 /* Initialize Qseecom */
405 ret = qseecom_init();
406
407 if (ret < 0)
408 {
409 dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret);
410 ASSERT(0);
411 }
412
413 /* Start Qseecom */
414 ret = qseecom_tz_init();
415
416 if (ret < 0)
417 {
418 dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret);
419 ASSERT(0);
420 }
421
422 if (rpmb_init() < 0)
423 {
424 dprintf(CRITICAL, "RPMB init failed\n");
425 ASSERT(0);
426 }
427
428 /*
429 * Load the sec app for first time
430 */
431 if (load_sec_app() < 0)
432 {
433 dprintf(CRITICAL, "Failed to load App for verified\n");
434 ASSERT(0);
435 }
436 }
437#endif
438
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530439#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530440 rpm_smd_init();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700441#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530442}
443
444void target_serialno(unsigned char *buf)
445{
446 uint32_t serialno;
447 if (target_is_emmc_boot()) {
448 serialno = mmc_get_psn();
449 snprintf((char *)buf, 13, "%x", serialno);
450 }
451}
452
453unsigned board_machtype(void)
454{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530455 return LINUX_MACHTYPE_UNKNOWN;
456}
457
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530458/* Detect the target type */
459void target_detect(struct board_data *board)
460{
461 /*
462 * already fill the board->target on board.c
463 */
464}
465
466void target_baseband_detect(struct board_data *board)
467{
468 uint32_t platform;
469
470 platform = board->platform;
471 switch(platform)
472 {
473 case MSM8909:
474 case MSM8209:
475 case MSM8208:
Unnati Gandhi917c8612015-02-06 16:50:32 +0530476 case MSM8609:
vijay kumarba95efb2015-09-08 15:24:12 +0530477 case MSM8909W:
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530478 board->baseband = BASEBAND_MSM;
479 break;
480
481 case MDM9209:
482 case MDM9309:
483 case MDM9609:
484 board->baseband = BASEBAND_MDM;
485 break;
486
Unnati Gandhi36e40472014-12-16 12:00:04 +0530487 case APQ8009:
vijay kumarba95efb2015-09-08 15:24:12 +0530488 case APQ8009W:
Vijay Kumar Pendotib228cfc2016-06-13 20:15:23 +0530489 if ((board->platform_hw == HW_PLATFORM_MTP) &&
Parth Dixit102ac212016-10-21 20:38:14 +0530490 ((board->platform_subtype == HW_SUBTYPE_APQ_NOWGR) ||
491 (board->platform_subtype == HW_PLATFORM_SUBTYPE_SWOC_NOWGR_CIRC)))
Vijay Kumar Pendotib228cfc2016-06-13 20:15:23 +0530492 board->baseband = BASEBAND_APQ_NOWGR;
493 else
494 board->baseband = BASEBAND_APQ;
Unnati Gandhi36e40472014-12-16 12:00:04 +0530495 break;
496
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530497 default:
498 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
499 ASSERT(0);
500 };
501}
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530502uint8_t target_panel_auto_detect_enabled()
503{
504 uint8_t ret = 0;
505
506 switch(board_hardware_id()) {
507 default:
508 ret = 0;
509 break;
510 }
511 return ret;
512}
513
514static uint8_t splash_override;
515/* Returns 1 if target supports continuous splash screen. */
516int target_cont_splash_screen()
517{
518 uint8_t splash_screen = 0;
519 if (!splash_override) {
520 switch (board_hardware_id()) {
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530521 case HW_PLATFORM_SURF:
522 case HW_PLATFORM_MTP:
Ray Zhang17a13112014-11-07 14:07:23 +0800523 case HW_PLATFORM_QRD:
Sandeep Panda8ede6502014-12-02 10:56:16 +0530524 case HW_PLATFORM_RCM:
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530525 splash_screen = 1;
526 break;
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530527 default:
528 splash_screen = 0;
529 break;
530 }
531 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
532 }
533 return splash_screen;
534}
535
536void target_force_cont_splash_disable(uint8_t override)
537{
538 splash_override = override;
539}
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530540
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530541/*Update this command line only for LE based builds*/
vijay kumar58d779b2015-08-31 17:25:49 +0530542int get_target_boot_params(const char *cmdline, const char *part, char **buf)
Unnati Gandhic43a2802014-09-19 17:27:25 +0530543{
544 struct ptable *ptable;
545 int system_ptn_index = -1;
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530546 int le_based = -1;
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530547 uint32_t buflen = 0;
548
549 if (!cmdline || !part ) {
550 dprintf(CRITICAL, "WARN: Invalid input param\n");
551 return -1;
552 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530553
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530554 /*LE partition.xml will have recoveryfs partition*/
555 if (target_is_emmc_boot())
556 le_based = partition_get_index("recoveryfs");
557 else
558 /*Nand targets by default have this*/
559 le_based = 1;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530560
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530561 if (le_based != -1)
562 {
563 if (!target_is_emmc_boot())
564 {
565 ptable = flash_get_ptable();
566 if (!ptable)
567 {
568 dprintf(CRITICAL,
569 "WARN: Cannot get flash partition table\n");
570 return -1;
571 }
572 system_ptn_index = ptable_get_index(ptable, part);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530573 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530574 else
575 system_ptn_index = partition_get_index(part);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530576 if (system_ptn_index < 0) {
577 dprintf(CRITICAL,
578 "WARN: Cannot get partition index for %s\n", part);
579 return -1;
580 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530581 /*
582 * check if cmdline contains "root=" at the beginning of buffer or
583 * " root=" in the middle of buffer.
584 */
585 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530586 (strstr(cmdline, " root=")))) {
Unnati Gandhic43a2802014-09-19 17:27:25 +0530587 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530588 return -1;
589 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530590 else
vijay kumar58d779b2015-08-31 17:25:49 +0530591 /*in success case buf will be freed in the calling function of this*/
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530592 {
593 if (!target_is_emmc_boot())
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530594 {
Mayank Groverc1190022017-02-23 17:28:46 +0530595 buflen = strlen(UBI_CMDLINE) + strlen(" root=ubi0:rootfs ubi.mtd=") + sizeof(int) + 1; /* 1 byte for null character*/
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530596
597 /* In success case, this memory is freed in calling function */
598 *buf = (char *)malloc(buflen);
599 if(!(*buf)) {
600 dprintf(CRITICAL,"Unable to allocate memory for boot params \n");
601 return -1;
602 }
603
Mayank Groverc1190022017-02-23 17:28:46 +0530604 /* Adding command line parameters according to target boot type */
605 snprintf(*buf, buflen, UBI_CMDLINE);
606 snprintf(*buf+strlen(*buf), buflen, " root=ubi0:rootfs ubi.mtd=%d", system_ptn_index);
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530607 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530608 else
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530609 {
610 /* Extra character is for Null termination */
611 buflen = strlen(" root=/dev/mmcblk0p") + sizeof(int) + 1;
612
613 /* In success case, this memory is freed in calling function */
614 *buf = (char *)malloc(buflen);
615 if(!(*buf)) {
616 dprintf(CRITICAL,"Unable to allocate memory for boot params \n");
617 return -1;
618 }
619
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530620 /*For Emmc case increase the ptn_index by 1*/
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530621 snprintf(*buf, buflen, " root=/dev/mmcblk0p%d",system_ptn_index + 1);
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530622 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530623 }
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530624
625 /*Return for LE based Targets.*/
626 return 0;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530627 }
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530628 return -1;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530629}
630
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530631unsigned target_baseband()
632{
633 return board_baseband();
634}
635
636int emmc_recovery_init(void)
637{
638 return _emmc_recovery_init();
639}
640
641void target_usb_init(void)
642{
643 uint32_t val;
644
645 /* Select and enable external configuration with USB PHY */
646 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
647
648 /* Enable sess_vld */
649 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
650 writel(val, USB_GENCONFIG_2);
651
652 /* Enable external vbus configuration in the LINK */
653 val = readl(USB_USBCMD);
654 val |= SESS_VLD_CTRL;
655 writel(val, USB_USBCMD);
656}
657
658unsigned target_pause_for_battery_charge(void)
659{
660 uint8_t pon_reason = pm8x41_get_pon_reason();
661 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
662 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
663 pon_reason, is_cold_boot);
664 /* In case of fastboot reboot,adb reboot or if we see the power key
665 * pressed we do not want go into charger mode.
666 * fastboot reboot is warm boot with PON hard reset bit not set
667 * adb reboot is a cold boot with PON hard reset bit set
668 */
669 if (is_cold_boot &&
670 (!(pon_reason & HARD_RST)) &&
671 (!(pon_reason & KPDPWR_N)) &&
Chunmei Cai6eb22fe2015-08-20 15:39:06 +0800672 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG) || (pon_reason & CBLPWR_N)))
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530673 return 1;
674 else
675 return 0;
676}
677
678void target_usb_stop(void)
679{
680 /* Disable VBUS mimicing in the controller. */
681 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
682}
683
684
685void target_uninit(void)
686{
687#if PON_VIB_SUPPORT
688 /* wait for the vibrator timer is expried */
689 wait_vib_timeout();
690#endif
691
Unnati Gandhic43a2802014-09-19 17:27:25 +0530692 if (platform_boot_dev_isemmc())
693 {
694 mmc_put_card_to_sleep(dev);
695 sdhci_mode_disable(&dev->host);
696 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530697
698 if (crypto_initialized())
699 crypto_eng_cleanup();
700
701 if (target_is_ssd_enabled())
702 clock_ce_disable(CE1_INSTANCE);
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530703
Mayank Grover7e351832017-04-21 15:03:58 +0530704#if VERIFIED_BOOT
705 if(target_is_vb_enabled())
706 {
707 if (is_sec_app_loaded())
708 {
709 if (send_milestone_call_to_tz() < 0)
710 {
711 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
712 ASSERT(0);
713 }
714 }
715
716 if (rpmb_uninit() < 0)
717 {
718 dprintf(CRITICAL, "RPMB uninit failed\n");
719 ASSERT(0);
720 }
721
722 clock_ce_disable(CE1_INSTANCE);
723 }
724#endif
725
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530726#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530727 rpm_smd_uninit();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700728#endif
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530729}
730
731/* Do any target specific intialization needed before entering fastboot mode */
732void target_fastboot_init(void)
733{
734 /* Set the BOOT_DONE flag in PM8916 */
735 pm8x41_set_boot_done();
736
737 if (target_is_ssd_enabled()) {
738 clock_ce_enable(CE1_INSTANCE);
739 target_load_ssd_keystore();
740 }
741}
742
lijuang395b5e62015-11-19 17:39:44 +0800743int set_download_mode(enum reboot_reason mode)
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530744{
745 int ret = 0;
746 ret = scm_dload_mode(mode);
747
748 pm8x41_clear_pmic_watchdog();
749
750 return ret;
751}
752
753void target_load_ssd_keystore(void)
754{
755 uint64_t ptn;
756 int index;
757 uint64_t size;
758 uint32_t *buffer = NULL;
759
760 if (!target_is_ssd_enabled())
761 return;
762
763 index = partition_get_index("ssd");
764
765 ptn = partition_get_offset(index);
766 if (ptn == 0){
767 dprintf(CRITICAL, "Error: ssd partition not found\n");
768 return;
769 }
770
771 size = partition_get_size(index);
772 if (size == 0) {
773 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
774 return;
775 }
776
777 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
778 if (!buffer) {
779 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
780 return;
781 }
782 if (mmc_read(ptn, buffer, size)) {
783 dprintf(CRITICAL, "Error: cannot read data\n");
784 free(buffer);
785 return;
786 }
787
788 clock_ce_enable(CE1_INSTANCE);
789 scm_protect_keystore(buffer, size);
790 clock_ce_disable(CE1_INSTANCE);
791 free(buffer);
792}
793
794crypto_engine_type board_ce_type(void)
795{
796 return CRYPTO_ENGINE_TYPE_HW;
797}
798
799/* Set up params for h/w CE. */
800void target_crypto_init_params()
801{
802 struct crypto_init_params ce_params;
803
804 /* Set up base addresses and instance. */
805 ce_params.crypto_instance = CE1_INSTANCE;
806 ce_params.crypto_base = MSM_CE1_BASE;
807 ce_params.bam_base = MSM_CE1_BAM_BASE;
808
809 /* Set up BAM config. */
810 ce_params.bam_ee = CE_EE;
811 ce_params.pipes.read_pipe = CE_READ_PIPE;
812 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
813 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
814 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
815
816 /* Assign buffer sizes. */
817 ce_params.num_ce = CE_ARRAY_SIZE;
818 ce_params.read_fifo_size = CE_FIFO_SIZE;
819 ce_params.write_fifo_size = CE_FIFO_SIZE;
820
821 /* BAM is initialized by TZ for this platform.
822 * Do not do it again as the initialization address space
823 * is locked.
824 */
825 ce_params.do_bam_init = 0;
826
827 crypto_init_params(&ce_params);
828}
829
830uint32_t target_get_hlos_subtype()
831{
832 return board_hlos_subtype();
833}
Channagoud Kadabi400bd112015-08-10 15:38:10 -0700834
835void pmic_reset_configure(uint8_t reset_type)
836{
837 pm8x41_reset_configure(reset_type);
838}
lijuang3606df82015-09-02 21:14:43 +0800839
840uint32_t target_get_pmic()
841{
842 return PMIC_IS_PM8909;
843}