blob: 4a5a3db239e3886c51dc50f2ed8e6acd6a1b7848 [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
Unnati Gandhic43a2802014-09-19 17:27:25 +0530125void update_ptable_names(void)
126{
127 uint32_t ptn_index;
128 struct ptentry *ptentry_ptr = flash_ptable.parts;
129 struct ptentry *boot_ptn;
130 unsigned i;
131 uint32_t len;
132
133 /* Change all names to lower case. */
134 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
135 {
136 len = strlen(ptentry_ptr[ptn_index].name);
137
138 for (i = 0; i < len; i++)
139 {
140 if (isupper(ptentry_ptr[ptn_index].name[i]))
141 {
142 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
143 }
144 }
145
146 /* SBL fills in the last partition length as 0xFFFFFFFF.
147 * Update the length field based on the number of blocks on the flash.
148 */
149 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
150 {
151 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
152 }
153 }
154}
155
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530156void target_early_init(void)
157{
158#if WITH_DEBUG_UART
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530159 /* Do not intilaise UART in case the h/w
160 * is RCM.
161 */
Baochu Xu7a8327b2017-12-01 10:40:21 +0800162 uint32_t platform_subtype = board_hardware_subtype();
163
164 if( board_hardware_id() == HW_PLATFORM_RCM )
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530165 return;
Baochu Xu7a8327b2017-12-01 10:40:21 +0800166 else if ( platform_subtype == HW_PLATFORM_SUBTYPE_8909_PM660_V1)
167 uart_dm_init(2, 0, BLSP1_UART1_BASE);
168 else
169 uart_dm_init(1, 0, BLSP1_UART0_BASE);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530170#endif
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530171
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530172}
173
Unnati Gandhic43a2802014-09-19 17:27:25 +0530174int target_is_emmc_boot(void)
175{
176 return platform_boot_dev_isemmc();
177}
178
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530179void target_sdc_init()
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530180{
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530181 struct mmc_config_data config;
182
183 /* Set drive strength & pull ctrl values */
184 set_sdc_power_ctrl();
185
186 config.bus_width = DATA_BUS_WIDTH_8BIT;
187 config.max_clk_rate = MMC_CLK_177MHZ;
188
189 /* Try slot 1*/
190 config.slot = 1;
191 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
192 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
193 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
194 config.hs400_support = 0;
195
196 if (!(dev = mmc_init(&config))) {
197 /* Try slot 2 */
198 config.slot = 2;
199 config.max_clk_rate = MMC_CLK_200MHZ;
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
204 if (!(dev = mmc_init(&config))) {
205 dprintf(CRITICAL, "mmc init failed!");
206 ASSERT(0);
207 }
208 }
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530209}
210
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530211void *target_mmc_device()
212{
213 return (void *) dev;
214}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530215
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530216/* Return 1 if vol_up pressed */
lijuang2d2b8a02015-06-05 21:34:15 +0800217int target_volume_up()
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530218{
lijuang2d2b8a02015-06-05 21:34:15 +0800219 static uint8_t first_time = 0;
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530220 uint8_t status = 0;
221
lijuang2d2b8a02015-06-05 21:34:15 +0800222 if (!first_time) {
223 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 +0530224
lijuang2d2b8a02015-06-05 21:34:15 +0800225 /* Wait for the gpio config to take effect - debounce time */
226 udelay(10000);
227
228 first_time = 1;
229 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530230
231 /* Get status of GPIO */
232 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
233
234 /* Active low signal. */
235 return !status;
236}
237
238/* Return 1 if vol_down pressed */
239uint32_t target_volume_down()
240{
Matthew Qin7bd789f2015-07-15 15:31:20 +0800241 if ((board_hardware_id() == HW_PLATFORM_QRD) &&
242 (board_hardware_subtype() == SUB_TYPE_SKUT)) {
243 uint32_t status = 0;
244
245 gpio_tlmm_config(TLMM_VOL_DOWN_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
246
247 /* Wait for the gpio config to take effect - debounce time */
248 thread_sleep(10);
249
250 /* Get status of GPIO */
251 status = gpio_status(TLMM_VOL_DOWN_BTN_GPIO);
252
253 /* Active low signal. */
254 return !status;
255 } else {
256 /* Volume down button tied in with PMIC RESIN. */
257 return pm8x41_resin_status();
258 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530259}
260
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530261static void target_keystatus()
262{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530263 keys_init();
264
265 if(target_volume_down())
266 keys_post_event(KEY_VOLUMEDOWN, 1);
267
268 if(target_volume_up())
269 keys_post_event(KEY_VOLUMEUP, 1);
270
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530271}
272
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530273static void set_sdc_power_ctrl()
274{
275 /* Drive strength configs for sdc pins */
276 struct tlmm_cfgs sdc1_hdrv_cfg[] =
277 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700278 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
279 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi9a6e6d42015-02-03 17:44:24 +0530280 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530281 };
282
283 /* Pull configs for sdc pins */
284 struct tlmm_cfgs sdc1_pull_cfg[] =
285 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700286 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
287 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
288 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530289 };
290
291 /* Set the drive strength & pull control values */
292 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
293 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
294}
295
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700296static void set_ebi2_config()
297{
298 /* Drive strength configs for ebi2 pins */
299 struct tlmm_cfgs ebi2_hdrv_cfg[] =
300 {
301 { EBI2_BUSY_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
302 { EBI2_WE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
303 { EBI2_OE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
304 { EBI2_CLE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
305 { EBI2_ALE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
306 { EBI2_CS_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
307 { EBI2_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
308 };
309
310 /* Pull configs for ebi2 pins */
311 struct tlmm_cfgs ebi2_pull_cfg[] =
312 {
313 { EBI2_BUSY_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
314 { EBI2_WE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
315 { EBI2_OE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
316 { EBI2_CLE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
317 { EBI2_ALE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
318 { EBI2_CS_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
319 { EBI2_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
320 };
321
322 /* Set the drive strength & pull control values */
323 tlmm_set_hdrive_ctrl(ebi2_hdrv_cfg, ARRAY_SIZE(ebi2_hdrv_cfg));
324 tlmm_set_pull_ctrl(ebi2_pull_cfg, ARRAY_SIZE(ebi2_pull_cfg));
325
326}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530327void target_init(void)
328{
329 uint32_t base_addr;
330 uint8_t slot;
Mayank Grover7e351832017-04-21 15:03:58 +0530331#if VERIFIED_BOOT
332 int ret = 0;
333#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530334 dprintf(INFO, "target_init()\n");
335
336 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
337
338 target_keystatus();
339
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530340#if BOOT_CONFIG_SUPPORT
Unnati Gandhic43a2802014-09-19 17:27:25 +0530341 platform_read_boot_config();
Unnati Gandhi8e4711b2014-10-13 05:03:00 +0530342#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530343
Unnati Gandhic43a2802014-09-19 17:27:25 +0530344 if (platform_boot_dev_isemmc()) {
345 target_sdc_init();
346 if (partition_read_table())
347 {
348 dprintf(CRITICAL, "Error reading the partition table info\n");
349 ASSERT(0);
350 }
351
352 } else {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700353 set_ebi2_config();
Unnati Gandhic43a2802014-09-19 17:27:25 +0530354 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
355 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
356 config.pipes.cmd_pipe = CMD_PIPE;
357
358 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
359 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
360 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
361
362 config.bam_base = MSM_NAND_BAM_BASE;
363 config.nand_base = MSM_NAND_BASE;
364 config.ee = QPIC_NAND_EE;
365 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
366
367 qpic_nand_init(&config);
368
369 ptable_init(&flash_ptable);
370 smem_ptable_init();
371 smem_add_modem_partitions(&flash_ptable);
372
373 update_ptable_names();
374 flash_set_ptable(&flash_ptable);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530375 }
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530376
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530377#if LONG_PRESS_POWER_ON
378 shutdown_detect();
379#endif
380
381#if PON_VIB_SUPPORT
382
383 /* turn on vibrator to indicate that phone is booting up to end user */
Mayank Grover7e351832017-04-21 15:03:58 +0530384 vib_timed_turn_on(VIBRATE_TIME);
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530385#endif
386
387 if (target_use_signed_kernel())
388 target_crypto_init_params();
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530389
Mayank Grover7e351832017-04-21 15:03:58 +0530390#if VERIFIED_BOOT
Mayank Grover509301a2017-10-26 12:10:11 +0530391 if (VB_M <= target_get_vb_version())
Mayank Grover7e351832017-04-21 15:03:58 +0530392 {
393 clock_ce_enable(CE1_INSTANCE);
394
395 /* Initialize Qseecom */
396 ret = qseecom_init();
397
398 if (ret < 0)
399 {
400 dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret);
401 ASSERT(0);
402 }
403
404 /* Start Qseecom */
405 ret = qseecom_tz_init();
406
407 if (ret < 0)
408 {
409 dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret);
410 ASSERT(0);
411 }
412
413 if (rpmb_init() < 0)
414 {
415 dprintf(CRITICAL, "RPMB init failed\n");
416 ASSERT(0);
417 }
418
419 /*
420 * Load the sec app for first time
421 */
422 if (load_sec_app() < 0)
423 {
424 dprintf(CRITICAL, "Failed to load App for verified\n");
425 ASSERT(0);
426 }
427 }
428#endif
429
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530430#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530431 rpm_smd_init();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700432#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530433}
434
435void target_serialno(unsigned char *buf)
436{
437 uint32_t serialno;
438 if (target_is_emmc_boot()) {
439 serialno = mmc_get_psn();
440 snprintf((char *)buf, 13, "%x", serialno);
441 }
442}
443
444unsigned board_machtype(void)
445{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530446 return LINUX_MACHTYPE_UNKNOWN;
447}
448
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530449/* Detect the target type */
450void target_detect(struct board_data *board)
451{
452 /*
453 * already fill the board->target on board.c
454 */
455}
456
457void target_baseband_detect(struct board_data *board)
458{
459 uint32_t platform;
460
461 platform = board->platform;
462 switch(platform)
463 {
464 case MSM8909:
465 case MSM8209:
466 case MSM8208:
Unnati Gandhi917c8612015-02-06 16:50:32 +0530467 case MSM8609:
vijay kumarba95efb2015-09-08 15:24:12 +0530468 case MSM8909W:
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530469 board->baseband = BASEBAND_MSM;
470 break;
471
472 case MDM9209:
473 case MDM9309:
474 case MDM9609:
475 board->baseband = BASEBAND_MDM;
476 break;
477
Unnati Gandhi36e40472014-12-16 12:00:04 +0530478 case APQ8009:
vijay kumarba95efb2015-09-08 15:24:12 +0530479 case APQ8009W:
Vijay Kumar Pendotib228cfc2016-06-13 20:15:23 +0530480 if ((board->platform_hw == HW_PLATFORM_MTP) &&
Parth Dixit102ac212016-10-21 20:38:14 +0530481 ((board->platform_subtype == HW_SUBTYPE_APQ_NOWGR) ||
482 (board->platform_subtype == HW_PLATFORM_SUBTYPE_SWOC_NOWGR_CIRC)))
Vijay Kumar Pendotib228cfc2016-06-13 20:15:23 +0530483 board->baseband = BASEBAND_APQ_NOWGR;
484 else
485 board->baseband = BASEBAND_APQ;
Unnati Gandhi36e40472014-12-16 12:00:04 +0530486 break;
487
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530488 default:
489 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
490 ASSERT(0);
491 };
492}
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530493uint8_t target_panel_auto_detect_enabled()
494{
495 uint8_t ret = 0;
496
497 switch(board_hardware_id()) {
498 default:
499 ret = 0;
500 break;
501 }
502 return ret;
503}
504
505static uint8_t splash_override;
506/* Returns 1 if target supports continuous splash screen. */
507int target_cont_splash_screen()
508{
509 uint8_t splash_screen = 0;
510 if (!splash_override) {
511 switch (board_hardware_id()) {
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530512 case HW_PLATFORM_SURF:
513 case HW_PLATFORM_MTP:
Ray Zhang17a13112014-11-07 14:07:23 +0800514 case HW_PLATFORM_QRD:
Sandeep Panda8ede6502014-12-02 10:56:16 +0530515 case HW_PLATFORM_RCM:
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530516 splash_screen = 1;
517 break;
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530518 default:
519 splash_screen = 0;
520 break;
521 }
522 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
523 }
524 return splash_screen;
525}
526
527void target_force_cont_splash_disable(uint8_t override)
528{
529 splash_override = override;
530}
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530531
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530532/*Update this command line only for LE based builds*/
vijay kumar58d779b2015-08-31 17:25:49 +0530533int get_target_boot_params(const char *cmdline, const char *part, char **buf)
Unnati Gandhic43a2802014-09-19 17:27:25 +0530534{
535 struct ptable *ptable;
536 int system_ptn_index = -1;
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530537 int le_based = -1;
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530538 uint32_t buflen = 0;
539
540 if (!cmdline || !part ) {
541 dprintf(CRITICAL, "WARN: Invalid input param\n");
542 return -1;
543 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530544
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530545 /*LE partition.xml will have recoveryfs partition*/
546 if (target_is_emmc_boot())
547 le_based = partition_get_index("recoveryfs");
548 else
549 /*Nand targets by default have this*/
550 le_based = 1;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530551
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530552 if (le_based != -1)
553 {
554 if (!target_is_emmc_boot())
555 {
556 ptable = flash_get_ptable();
557 if (!ptable)
558 {
559 dprintf(CRITICAL,
560 "WARN: Cannot get flash partition table\n");
561 return -1;
562 }
563 system_ptn_index = ptable_get_index(ptable, part);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530564 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530565 else
566 system_ptn_index = partition_get_index(part);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530567 if (system_ptn_index < 0) {
568 dprintf(CRITICAL,
569 "WARN: Cannot get partition index for %s\n", part);
570 return -1;
571 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530572 /*
573 * check if cmdline contains "root=" at the beginning of buffer or
574 * " root=" in the middle of buffer.
575 */
576 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530577 (strstr(cmdline, " root=")))) {
Unnati Gandhic43a2802014-09-19 17:27:25 +0530578 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530579 return -1;
580 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530581 else
vijay kumar58d779b2015-08-31 17:25:49 +0530582 /*in success case buf will be freed in the calling function of this*/
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530583 {
584 if (!target_is_emmc_boot())
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530585 {
Mayank Groverc1190022017-02-23 17:28:46 +0530586 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 +0530587
588 /* In success case, this memory is freed in calling function */
589 *buf = (char *)malloc(buflen);
590 if(!(*buf)) {
591 dprintf(CRITICAL,"Unable to allocate memory for boot params \n");
592 return -1;
593 }
594
Mayank Groverc1190022017-02-23 17:28:46 +0530595 /* Adding command line parameters according to target boot type */
596 snprintf(*buf, buflen, UBI_CMDLINE);
597 snprintf(*buf+strlen(*buf), buflen, " root=ubi0:rootfs ubi.mtd=%d", system_ptn_index);
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530598 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530599 else
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530600 {
601 /* Extra character is for Null termination */
602 buflen = strlen(" root=/dev/mmcblk0p") + sizeof(int) + 1;
603
604 /* In success case, this memory is freed in calling function */
605 *buf = (char *)malloc(buflen);
606 if(!(*buf)) {
607 dprintf(CRITICAL,"Unable to allocate memory for boot params \n");
608 return -1;
609 }
610
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530611 /*For Emmc case increase the ptn_index by 1*/
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530612 snprintf(*buf, buflen, " root=/dev/mmcblk0p%d",system_ptn_index + 1);
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530613 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530614 }
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530615
616 /*Return for LE based Targets.*/
617 return 0;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530618 }
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530619 return -1;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530620}
621
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530622unsigned target_baseband()
623{
624 return board_baseband();
625}
626
627int emmc_recovery_init(void)
628{
629 return _emmc_recovery_init();
630}
631
632void target_usb_init(void)
633{
634 uint32_t val;
635
636 /* Select and enable external configuration with USB PHY */
637 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
638
639 /* Enable sess_vld */
640 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
641 writel(val, USB_GENCONFIG_2);
642
643 /* Enable external vbus configuration in the LINK */
644 val = readl(USB_USBCMD);
645 val |= SESS_VLD_CTRL;
646 writel(val, USB_USBCMD);
647}
648
649unsigned target_pause_for_battery_charge(void)
650{
Mayank Grover6f125882017-12-05 10:28:32 +0530651 uint32_t pmic = target_get_pmic();
652 uint8_t pon_reason = 0;
653 uint8_t is_cold_boot = 0;
654
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530655 /* In case of fastboot reboot,adb reboot or if we see the power key
656 * pressed we do not want go into charger mode.
657 * fastboot reboot is warm boot with PON hard reset bit not set
658 * adb reboot is a cold boot with PON hard reset bit set
659 */
Mayank Grover6f125882017-12-05 10:28:32 +0530660 if (pmic == PMIC_IS_PM660)
661 {
662 pon_reason = pm660_get_pon_reason();
663 is_cold_boot = pm660_get_is_cold_boot();
664 }
665 else
666 {
667 pon_reason = pm8x41_get_pon_reason();
668 is_cold_boot = pm8x41_get_is_cold_boot();
669 }
670 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
671 pon_reason, is_cold_boot);
672
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530673 if (is_cold_boot &&
674 (!(pon_reason & HARD_RST)) &&
675 (!(pon_reason & KPDPWR_N)) &&
Chunmei Cai6eb22fe2015-08-20 15:39:06 +0800676 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG) || (pon_reason & CBLPWR_N)))
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530677 return 1;
678 else
679 return 0;
680}
681
682void target_usb_stop(void)
683{
684 /* Disable VBUS mimicing in the controller. */
685 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
686}
687
688
689void target_uninit(void)
690{
691#if PON_VIB_SUPPORT
692 /* wait for the vibrator timer is expried */
693 wait_vib_timeout();
694#endif
695
Unnati Gandhic43a2802014-09-19 17:27:25 +0530696 if (platform_boot_dev_isemmc())
697 {
698 mmc_put_card_to_sleep(dev);
699 sdhci_mode_disable(&dev->host);
700 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530701
702 if (crypto_initialized())
703 crypto_eng_cleanup();
704
705 if (target_is_ssd_enabled())
706 clock_ce_disable(CE1_INSTANCE);
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530707
Mayank Grover7e351832017-04-21 15:03:58 +0530708#if VERIFIED_BOOT
Mayank Grover509301a2017-10-26 12:10:11 +0530709 if(VB_M <= target_get_vb_version())
Mayank Grover7e351832017-04-21 15:03:58 +0530710 {
711 if (is_sec_app_loaded())
712 {
713 if (send_milestone_call_to_tz() < 0)
714 {
715 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
716 ASSERT(0);
717 }
718 }
719
720 if (rpmb_uninit() < 0)
721 {
722 dprintf(CRITICAL, "RPMB uninit failed\n");
723 ASSERT(0);
724 }
725
726 clock_ce_disable(CE1_INSTANCE);
727 }
728#endif
729
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530730#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530731 rpm_smd_uninit();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700732#endif
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530733}
734
735/* Do any target specific intialization needed before entering fastboot mode */
736void target_fastboot_init(void)
737{
738 /* Set the BOOT_DONE flag in PM8916 */
739 pm8x41_set_boot_done();
740
741 if (target_is_ssd_enabled()) {
742 clock_ce_enable(CE1_INSTANCE);
743 target_load_ssd_keystore();
744 }
745}
746
lijuang395b5e62015-11-19 17:39:44 +0800747int set_download_mode(enum reboot_reason mode)
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530748{
749 int ret = 0;
750 ret = scm_dload_mode(mode);
751
752 pm8x41_clear_pmic_watchdog();
753
754 return ret;
755}
756
757void target_load_ssd_keystore(void)
758{
759 uint64_t ptn;
760 int index;
761 uint64_t size;
762 uint32_t *buffer = NULL;
763
764 if (!target_is_ssd_enabled())
765 return;
766
767 index = partition_get_index("ssd");
768
769 ptn = partition_get_offset(index);
770 if (ptn == 0){
771 dprintf(CRITICAL, "Error: ssd partition not found\n");
772 return;
773 }
774
775 size = partition_get_size(index);
776 if (size == 0) {
777 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
778 return;
779 }
780
781 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
782 if (!buffer) {
783 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
784 return;
785 }
786 if (mmc_read(ptn, buffer, size)) {
787 dprintf(CRITICAL, "Error: cannot read data\n");
788 free(buffer);
789 return;
790 }
791
792 clock_ce_enable(CE1_INSTANCE);
793 scm_protect_keystore(buffer, size);
794 clock_ce_disable(CE1_INSTANCE);
795 free(buffer);
796}
797
798crypto_engine_type board_ce_type(void)
799{
800 return CRYPTO_ENGINE_TYPE_HW;
801}
802
803/* Set up params for h/w CE. */
804void target_crypto_init_params()
805{
806 struct crypto_init_params ce_params;
807
808 /* Set up base addresses and instance. */
809 ce_params.crypto_instance = CE1_INSTANCE;
810 ce_params.crypto_base = MSM_CE1_BASE;
811 ce_params.bam_base = MSM_CE1_BAM_BASE;
812
813 /* Set up BAM config. */
814 ce_params.bam_ee = CE_EE;
815 ce_params.pipes.read_pipe = CE_READ_PIPE;
816 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
817 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
818 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
819
820 /* Assign buffer sizes. */
821 ce_params.num_ce = CE_ARRAY_SIZE;
822 ce_params.read_fifo_size = CE_FIFO_SIZE;
823 ce_params.write_fifo_size = CE_FIFO_SIZE;
824
825 /* BAM is initialized by TZ for this platform.
826 * Do not do it again as the initialization address space
827 * is locked.
828 */
829 ce_params.do_bam_init = 0;
830
831 crypto_init_params(&ce_params);
832}
833
834uint32_t target_get_hlos_subtype()
835{
836 return board_hlos_subtype();
837}
Channagoud Kadabi400bd112015-08-10 15:38:10 -0700838
839void pmic_reset_configure(uint8_t reset_type)
840{
841 pm8x41_reset_configure(reset_type);
842}
lijuang3606df82015-09-02 21:14:43 +0800843
844uint32_t target_get_pmic()
845{
Baochu Xu34bb8e62017-12-05 14:22:06 +0800846 if ((board_hardware_subtype() == HW_PLATFORM_SUBTYPE_8909_PM660) ||
847 (board_hardware_subtype() == HW_PLATFORM_SUBTYPE_8909_PM660_V1))
Mayank Grover3f20adf2017-07-03 16:33:22 +0530848 return PMIC_IS_PM660;
849 else
850 return PMIC_IS_PM8909;
lijuang3606df82015-09-02 21:14:43 +0800851}