blob: 4a5ebe18f1853e929649f0aa71351e858d8f49ea [file] [log] [blame]
Mayank Grover141c9bc2018-03-13 18:26:43 +05301/* Copyright (c) 2014-2018, 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
Mayank Grover141c9bc2018-03-13 18:26:43 +053084/* Fastboot switch GPIO for Intrinsic board. */
85#define USB_SW_GPIO_INTRINSIC_SOM 3
86
Unnati Gandhic43a2802014-09-19 17:27:25 +053087extern void smem_ptable_init(void);
88extern void smem_add_modem_partitions(struct ptable *flash_ptable);
89void target_sdc_init();
90
91static struct ptable flash_ptable;
92
93/* NANDc BAM pipe numbers */
94#define DATA_CONSUMER_PIPE 0
95#define DATA_PRODUCER_PIPE 1
96#define CMD_PIPE 2
97
98/* NANDc BAM pipe groups */
99#define DATA_PRODUCER_PIPE_GRP 0
100#define DATA_CONSUMER_PIPE_GRP 0
101#define CMD_PIPE_GRP 1
102
103/* NANDc EE */
104#define QPIC_NAND_EE 0
105
106/* NANDc max desc length. */
107#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
108
109#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
Mayank Groverc1190022017-02-23 17:28:46 +0530110#define UBI_CMDLINE " rootfstype=ubifs rootflags=bulk_read"
Unnati Gandhic43a2802014-09-19 17:27:25 +0530111
112struct qpic_nand_init_config config;
113
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530114struct mmc_device *dev;
115
116static uint32_t mmc_pwrctl_base[] =
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530117 { MSM_SDC1_BASE, MSM_SDC2_BASE };
118
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530119static uint32_t mmc_sdhci_base[] =
120 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
121
122static uint32_t mmc_sdc_pwrctl_irq[] =
123 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
124
125static void set_sdc_power_ctrl(void);
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700126static void set_ebi2_config(void);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530127
Unnati Gandhic43a2802014-09-19 17:27:25 +0530128void update_ptable_names(void)
129{
130 uint32_t ptn_index;
131 struct ptentry *ptentry_ptr = flash_ptable.parts;
132 struct ptentry *boot_ptn;
133 unsigned i;
134 uint32_t len;
135
136 /* Change all names to lower case. */
137 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
138 {
139 len = strlen(ptentry_ptr[ptn_index].name);
140
141 for (i = 0; i < len; i++)
142 {
143 if (isupper(ptentry_ptr[ptn_index].name[i]))
144 {
145 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
146 }
147 }
148
149 /* SBL fills in the last partition length as 0xFFFFFFFF.
150 * Update the length field based on the number of blocks on the flash.
151 */
152 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
153 {
154 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
155 }
156 }
157}
158
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530159void target_early_init(void)
160{
161#if WITH_DEBUG_UART
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530162 /* Do not intilaise UART in case the h/w
163 * is RCM.
164 */
Baochu Xu7a8327b2017-12-01 10:40:21 +0800165 uint32_t platform_subtype = board_hardware_subtype();
166
167 if( board_hardware_id() == HW_PLATFORM_RCM )
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530168 return;
Baochu Xu7a8327b2017-12-01 10:40:21 +0800169 else if ( platform_subtype == HW_PLATFORM_SUBTYPE_8909_PM660_V1)
170 uart_dm_init(2, 0, BLSP1_UART1_BASE);
171 else
172 uart_dm_init(1, 0, BLSP1_UART0_BASE);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530173#endif
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530174
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530175}
176
Unnati Gandhic43a2802014-09-19 17:27:25 +0530177int target_is_emmc_boot(void)
178{
179 return platform_boot_dev_isemmc();
180}
181
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530182void target_sdc_init()
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530183{
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530184 struct mmc_config_data config;
185
186 /* Set drive strength & pull ctrl values */
187 set_sdc_power_ctrl();
188
189 config.bus_width = DATA_BUS_WIDTH_8BIT;
190 config.max_clk_rate = MMC_CLK_177MHZ;
191
192 /* Try slot 1*/
193 config.slot = 1;
194 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
195 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
196 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
197 config.hs400_support = 0;
198
199 if (!(dev = mmc_init(&config))) {
200 /* Try slot 2 */
201 config.slot = 2;
202 config.max_clk_rate = MMC_CLK_200MHZ;
203 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
204 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
205 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
206
207 if (!(dev = mmc_init(&config))) {
208 dprintf(CRITICAL, "mmc init failed!");
209 ASSERT(0);
210 }
211 }
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530212}
213
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530214void *target_mmc_device()
215{
216 return (void *) dev;
217}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530218
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530219/* Return 1 if vol_up pressed */
lijuang2d2b8a02015-06-05 21:34:15 +0800220int target_volume_up()
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530221{
lijuang2d2b8a02015-06-05 21:34:15 +0800222 static uint8_t first_time = 0;
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530223 uint8_t status = 0;
224
lijuang2d2b8a02015-06-05 21:34:15 +0800225 if (!first_time) {
226 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 +0530227
lijuang2d2b8a02015-06-05 21:34:15 +0800228 /* Wait for the gpio config to take effect - debounce time */
229 udelay(10000);
230
231 first_time = 1;
232 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530233
234 /* Get status of GPIO */
235 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
236
237 /* Active low signal. */
238 return !status;
239}
240
241/* Return 1 if vol_down pressed */
242uint32_t target_volume_down()
243{
Matthew Qin7bd789f2015-07-15 15:31:20 +0800244 if ((board_hardware_id() == HW_PLATFORM_QRD) &&
245 (board_hardware_subtype() == SUB_TYPE_SKUT)) {
246 uint32_t status = 0;
247
248 gpio_tlmm_config(TLMM_VOL_DOWN_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
249
250 /* Wait for the gpio config to take effect - debounce time */
251 thread_sleep(10);
252
253 /* Get status of GPIO */
254 status = gpio_status(TLMM_VOL_DOWN_BTN_GPIO);
255
256 /* Active low signal. */
257 return !status;
258 } else {
259 /* Volume down button tied in with PMIC RESIN. */
260 return pm8x41_resin_status();
261 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530262}
263
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530264static void target_keystatus()
265{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530266 keys_init();
267
268 if(target_volume_down())
269 keys_post_event(KEY_VOLUMEDOWN, 1);
270
271 if(target_volume_up())
272 keys_post_event(KEY_VOLUMEUP, 1);
273
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530274}
275
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530276static void set_sdc_power_ctrl()
277{
278 /* Drive strength configs for sdc pins */
279 struct tlmm_cfgs sdc1_hdrv_cfg[] =
280 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700281 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
282 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi9a6e6d42015-02-03 17:44:24 +0530283 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530284 };
285
286 /* Pull configs for sdc pins */
287 struct tlmm_cfgs sdc1_pull_cfg[] =
288 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700289 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
290 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
291 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530292 };
293
294 /* Set the drive strength & pull control values */
295 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
296 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
297}
298
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700299static void set_ebi2_config()
300{
301 /* Drive strength configs for ebi2 pins */
302 struct tlmm_cfgs ebi2_hdrv_cfg[] =
303 {
304 { EBI2_BUSY_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
305 { EBI2_WE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
306 { EBI2_OE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
307 { EBI2_CLE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
308 { EBI2_ALE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
309 { EBI2_CS_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
310 { EBI2_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
311 };
312
313 /* Pull configs for ebi2 pins */
314 struct tlmm_cfgs ebi2_pull_cfg[] =
315 {
316 { EBI2_BUSY_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
317 { EBI2_WE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
318 { EBI2_OE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
319 { EBI2_CLE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
320 { EBI2_ALE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
321 { EBI2_CS_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
322 { EBI2_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
323 };
324
325 /* Set the drive strength & pull control values */
326 tlmm_set_hdrive_ctrl(ebi2_hdrv_cfg, ARRAY_SIZE(ebi2_hdrv_cfg));
327 tlmm_set_pull_ctrl(ebi2_pull_cfg, ARRAY_SIZE(ebi2_pull_cfg));
328
329}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530330void target_init(void)
331{
332 uint32_t base_addr;
333 uint8_t slot;
Jiten Patel8d56b462018-08-29 16:51:07 +0530334#if VERIFIED_BOOT || VERIFIED_BOOT_2
Mayank Grover7e351832017-04-21 15:03:58 +0530335 int ret = 0;
336#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530337 dprintf(INFO, "target_init()\n");
338
339 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
340
341 target_keystatus();
342
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530343#if BOOT_CONFIG_SUPPORT
Unnati Gandhic43a2802014-09-19 17:27:25 +0530344 platform_read_boot_config();
Unnati Gandhi8e4711b2014-10-13 05:03:00 +0530345#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530346
Unnati Gandhic43a2802014-09-19 17:27:25 +0530347 if (platform_boot_dev_isemmc()) {
348 target_sdc_init();
349 if (partition_read_table())
350 {
351 dprintf(CRITICAL, "Error reading the partition table info\n");
352 ASSERT(0);
353 }
354
355 } else {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700356 set_ebi2_config();
Unnati Gandhic43a2802014-09-19 17:27:25 +0530357 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
358 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
359 config.pipes.cmd_pipe = CMD_PIPE;
360
361 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
362 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
363 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
364
365 config.bam_base = MSM_NAND_BAM_BASE;
366 config.nand_base = MSM_NAND_BASE;
367 config.ee = QPIC_NAND_EE;
368 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
369
370 qpic_nand_init(&config);
371
372 ptable_init(&flash_ptable);
373 smem_ptable_init();
374 smem_add_modem_partitions(&flash_ptable);
375
376 update_ptable_names();
377 flash_set_ptable(&flash_ptable);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530378 }
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530379
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530380#if LONG_PRESS_POWER_ON
381 shutdown_detect();
382#endif
383
384#if PON_VIB_SUPPORT
385
386 /* turn on vibrator to indicate that phone is booting up to end user */
Mayank Grover7e351832017-04-21 15:03:58 +0530387 vib_timed_turn_on(VIBRATE_TIME);
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530388#endif
389
390 if (target_use_signed_kernel())
391 target_crypto_init_params();
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530392
Jiten Patel8d56b462018-08-29 16:51:07 +0530393#if VERIFIED_BOOT || VERIFIED_BOOT_2
Mayank Grover509301a2017-10-26 12:10:11 +0530394 if (VB_M <= target_get_vb_version())
Mayank Grover7e351832017-04-21 15:03:58 +0530395 {
396 clock_ce_enable(CE1_INSTANCE);
397
398 /* Initialize Qseecom */
399 ret = qseecom_init();
400
401 if (ret < 0)
402 {
403 dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret);
404 ASSERT(0);
405 }
406
407 /* Start Qseecom */
408 ret = qseecom_tz_init();
409
410 if (ret < 0)
411 {
412 dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret);
413 ASSERT(0);
414 }
415
416 if (rpmb_init() < 0)
417 {
418 dprintf(CRITICAL, "RPMB init failed\n");
419 ASSERT(0);
420 }
421
422 /*
423 * Load the sec app for first time
424 */
425 if (load_sec_app() < 0)
426 {
427 dprintf(CRITICAL, "Failed to load App for verified\n");
428 ASSERT(0);
429 }
430 }
431#endif
432
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530433#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530434 rpm_smd_init();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700435#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530436}
437
438void target_serialno(unsigned char *buf)
439{
440 uint32_t serialno;
Saranya Chidura1600c2d2018-08-30 19:11:05 +0530441 if (target_is_emmc_boot())
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530442 serialno = mmc_get_psn();
Saranya Chidura1600c2d2018-08-30 19:11:05 +0530443 else
444 serialno = board_chip_serial();
445
446 snprintf((char *)buf, SERIAL_NUMBER_LEN, "%x", serialno);
447
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530448}
449
450unsigned board_machtype(void)
451{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530452 return LINUX_MACHTYPE_UNKNOWN;
453}
454
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530455/* Detect the target type */
456void target_detect(struct board_data *board)
457{
458 /*
459 * already fill the board->target on board.c
460 */
461}
462
463void target_baseband_detect(struct board_data *board)
464{
465 uint32_t platform;
466
467 platform = board->platform;
468 switch(platform)
469 {
470 case MSM8909:
471 case MSM8209:
472 case MSM8208:
Unnati Gandhi917c8612015-02-06 16:50:32 +0530473 case MSM8609:
vijay kumarba95efb2015-09-08 15:24:12 +0530474 case MSM8909W:
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530475 board->baseband = BASEBAND_MSM;
476 break;
477
478 case MDM9209:
479 case MDM9309:
480 case MDM9609:
481 board->baseband = BASEBAND_MDM;
482 break;
483
Unnati Gandhi36e40472014-12-16 12:00:04 +0530484 case APQ8009:
vijay kumarba95efb2015-09-08 15:24:12 +0530485 case APQ8009W:
Vijay Kumar Pendotib228cfc2016-06-13 20:15:23 +0530486 if ((board->platform_hw == HW_PLATFORM_MTP) &&
Parth Dixit102ac212016-10-21 20:38:14 +0530487 ((board->platform_subtype == HW_SUBTYPE_APQ_NOWGR) ||
488 (board->platform_subtype == HW_PLATFORM_SUBTYPE_SWOC_NOWGR_CIRC)))
Vijay Kumar Pendotib228cfc2016-06-13 20:15:23 +0530489 board->baseband = BASEBAND_APQ_NOWGR;
490 else
491 board->baseband = BASEBAND_APQ;
Unnati Gandhi36e40472014-12-16 12:00:04 +0530492 break;
493
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530494 default:
495 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
496 ASSERT(0);
497 };
498}
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530499uint8_t target_panel_auto_detect_enabled()
500{
501 uint8_t ret = 0;
502
503 switch(board_hardware_id()) {
504 default:
505 ret = 0;
506 break;
507 }
508 return ret;
509}
510
511static uint8_t splash_override;
512/* Returns 1 if target supports continuous splash screen. */
513int target_cont_splash_screen()
514{
515 uint8_t splash_screen = 0;
516 if (!splash_override) {
517 switch (board_hardware_id()) {
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530518 case HW_PLATFORM_SURF:
519 case HW_PLATFORM_MTP:
Ray Zhang17a13112014-11-07 14:07:23 +0800520 case HW_PLATFORM_QRD:
Sandeep Panda8ede6502014-12-02 10:56:16 +0530521 case HW_PLATFORM_RCM:
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530522 splash_screen = 1;
523 break;
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530524 default:
525 splash_screen = 0;
526 break;
527 }
528 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
529 }
530 return splash_screen;
531}
532
533void target_force_cont_splash_disable(uint8_t override)
534{
535 splash_override = override;
536}
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530537
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530538/*Update this command line only for LE based builds*/
vijay kumar58d779b2015-08-31 17:25:49 +0530539int get_target_boot_params(const char *cmdline, const char *part, char **buf)
Unnati Gandhic43a2802014-09-19 17:27:25 +0530540{
541 struct ptable *ptable;
542 int system_ptn_index = -1;
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530543 int le_based = -1;
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530544 uint32_t buflen = 0;
545
546 if (!cmdline || !part ) {
547 dprintf(CRITICAL, "WARN: Invalid input param\n");
548 return -1;
549 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530550
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530551 /*LE partition.xml will have recoveryfs partition*/
552 if (target_is_emmc_boot())
553 le_based = partition_get_index("recoveryfs");
554 else
555 /*Nand targets by default have this*/
556 le_based = 1;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530557
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530558 if (le_based != -1)
559 {
560 if (!target_is_emmc_boot())
561 {
562 ptable = flash_get_ptable();
563 if (!ptable)
564 {
565 dprintf(CRITICAL,
566 "WARN: Cannot get flash partition table\n");
567 return -1;
568 }
569 system_ptn_index = ptable_get_index(ptable, part);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530570 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530571 else
572 system_ptn_index = partition_get_index(part);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530573 if (system_ptn_index < 0) {
574 dprintf(CRITICAL,
575 "WARN: Cannot get partition index for %s\n", part);
576 return -1;
577 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530578 /*
579 * check if cmdline contains "root=" at the beginning of buffer or
580 * " root=" in the middle of buffer.
581 */
582 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530583 (strstr(cmdline, " root=")))) {
Unnati Gandhic43a2802014-09-19 17:27:25 +0530584 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530585 return -1;
586 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530587 else
vijay kumar58d779b2015-08-31 17:25:49 +0530588 /*in success case buf will be freed in the calling function of this*/
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530589 {
590 if (!target_is_emmc_boot())
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530591 {
Mayank Groverc1190022017-02-23 17:28:46 +0530592 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 +0530593
594 /* In success case, this memory is freed in calling function */
595 *buf = (char *)malloc(buflen);
596 if(!(*buf)) {
597 dprintf(CRITICAL,"Unable to allocate memory for boot params \n");
598 return -1;
599 }
600
Mayank Groverc1190022017-02-23 17:28:46 +0530601 /* Adding command line parameters according to target boot type */
602 snprintf(*buf, buflen, UBI_CMDLINE);
603 snprintf(*buf+strlen(*buf), buflen, " root=ubi0:rootfs ubi.mtd=%d", system_ptn_index);
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530604 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530605 else
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530606 {
607 /* Extra character is for Null termination */
608 buflen = strlen(" root=/dev/mmcblk0p") + sizeof(int) + 1;
609
610 /* In success case, this memory is freed in calling function */
611 *buf = (char *)malloc(buflen);
612 if(!(*buf)) {
613 dprintf(CRITICAL,"Unable to allocate memory for boot params \n");
614 return -1;
615 }
616
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530617 /*For Emmc case increase the ptn_index by 1*/
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530618 snprintf(*buf, buflen, " root=/dev/mmcblk0p%d",system_ptn_index + 1);
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530619 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530620 }
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530621
622 /*Return for LE based Targets.*/
623 return 0;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530624 }
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530625 return -1;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530626}
627
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530628unsigned target_baseband()
629{
630 return board_baseband();
631}
632
633int emmc_recovery_init(void)
634{
635 return _emmc_recovery_init();
636}
637
638void target_usb_init(void)
639{
640 uint32_t val;
641
642 /* Select and enable external configuration with USB PHY */
643 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
644
645 /* Enable sess_vld */
646 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
647 writel(val, USB_GENCONFIG_2);
648
649 /* Enable external vbus configuration in the LINK */
650 val = readl(USB_USBCMD);
651 val |= SESS_VLD_CTRL;
652 writel(val, USB_USBCMD);
653}
654
655unsigned target_pause_for_battery_charge(void)
656{
Mayank Grover6f125882017-12-05 10:28:32 +0530657 uint32_t pmic = target_get_pmic();
658 uint8_t pon_reason = 0;
659 uint8_t is_cold_boot = 0;
660
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530661 /* In case of fastboot reboot,adb reboot or if we see the power key
662 * pressed we do not want go into charger mode.
663 * fastboot reboot is warm boot with PON hard reset bit not set
664 * adb reboot is a cold boot with PON hard reset bit set
665 */
Mayank Grover6f125882017-12-05 10:28:32 +0530666 if (pmic == PMIC_IS_PM660)
667 {
668 pon_reason = pm660_get_pon_reason();
669 is_cold_boot = pm660_get_is_cold_boot();
670 }
671 else
672 {
673 pon_reason = pm8x41_get_pon_reason();
674 is_cold_boot = pm8x41_get_is_cold_boot();
675 }
676 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
677 pon_reason, is_cold_boot);
678
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530679 if (is_cold_boot &&
680 (!(pon_reason & HARD_RST)) &&
681 (!(pon_reason & KPDPWR_N)) &&
Chunmei Cai6eb22fe2015-08-20 15:39:06 +0800682 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG) || (pon_reason & CBLPWR_N)))
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530683 return 1;
684 else
685 return 0;
686}
687
688void target_usb_stop(void)
689{
690 /* Disable VBUS mimicing in the controller. */
691 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
692}
693
694
695void target_uninit(void)
696{
697#if PON_VIB_SUPPORT
698 /* wait for the vibrator timer is expried */
699 wait_vib_timeout();
700#endif
701
Unnati Gandhic43a2802014-09-19 17:27:25 +0530702 if (platform_boot_dev_isemmc())
703 {
704 mmc_put_card_to_sleep(dev);
705 sdhci_mode_disable(&dev->host);
706 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530707
708 if (crypto_initialized())
709 crypto_eng_cleanup();
710
711 if (target_is_ssd_enabled())
712 clock_ce_disable(CE1_INSTANCE);
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530713
Jiten Patel8d56b462018-08-29 16:51:07 +0530714#if VERIFIED_BOOT || VERIFIED_BOOT_2
Mayank Grover509301a2017-10-26 12:10:11 +0530715 if(VB_M <= target_get_vb_version())
Mayank Grover7e351832017-04-21 15:03:58 +0530716 {
717 if (is_sec_app_loaded())
718 {
719 if (send_milestone_call_to_tz() < 0)
720 {
721 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
722 ASSERT(0);
723 }
724 }
725
726 if (rpmb_uninit() < 0)
727 {
728 dprintf(CRITICAL, "RPMB uninit failed\n");
729 ASSERT(0);
730 }
731
732 clock_ce_disable(CE1_INSTANCE);
733 }
734#endif
735
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530736#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530737 rpm_smd_uninit();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700738#endif
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530739}
740
741/* Do any target specific intialization needed before entering fastboot mode */
742void target_fastboot_init(void)
743{
Mayank Grover141c9bc2018-03-13 18:26:43 +0530744 uint32_t hw_id = board_hardware_id();
745 uint32_t platform_subtype = board_hardware_subtype();
746
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530747 /* Set the BOOT_DONE flag in PM8916 */
748 pm8x41_set_boot_done();
749
750 if (target_is_ssd_enabled()) {
751 clock_ce_enable(CE1_INSTANCE);
752 target_load_ssd_keystore();
753 }
Mayank Grover141c9bc2018-03-13 18:26:43 +0530754
755 if ((HW_PLATFORM_MTP == hw_id) &&
756 (HW_PLATFORM_SUBTYPE_INTRINSIC_SOM == platform_subtype))
757 {
758 dprintf(SPEW, "Enabling PMIC GPIO for USB detection\n");
759
760 struct pm8x41_gpio usbgpio_param = {
761 .direction = PM_GPIO_DIR_OUT,
762 .vin_sel = 0,
763 .out_strength = PM_GPIO_OUT_DRIVE_MED,
764 .function = PM_GPIO_FUNC_HIGH,
765 .pull = PM_GPIO_PULLDOWN_10,
766 .inv_int_pol = PM_GPIO_INVERT,
767 };
768
769 pm8x41_gpio_config(USB_SW_GPIO_INTRINSIC_SOM, &usbgpio_param);
770 pm8x41_gpio_set(USB_SW_GPIO_INTRINSIC_SOM, 0);
771 }
772
773 return;
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530774}
775
lijuang395b5e62015-11-19 17:39:44 +0800776int set_download_mode(enum reboot_reason mode)
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530777{
778 int ret = 0;
779 ret = scm_dload_mode(mode);
780
781 pm8x41_clear_pmic_watchdog();
782
783 return ret;
784}
785
786void target_load_ssd_keystore(void)
787{
788 uint64_t ptn;
789 int index;
790 uint64_t size;
791 uint32_t *buffer = NULL;
792
793 if (!target_is_ssd_enabled())
794 return;
795
796 index = partition_get_index("ssd");
797
798 ptn = partition_get_offset(index);
799 if (ptn == 0){
800 dprintf(CRITICAL, "Error: ssd partition not found\n");
801 return;
802 }
803
804 size = partition_get_size(index);
805 if (size == 0) {
806 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
807 return;
808 }
809
810 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
811 if (!buffer) {
812 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
813 return;
814 }
815 if (mmc_read(ptn, buffer, size)) {
816 dprintf(CRITICAL, "Error: cannot read data\n");
817 free(buffer);
818 return;
819 }
820
821 clock_ce_enable(CE1_INSTANCE);
822 scm_protect_keystore(buffer, size);
823 clock_ce_disable(CE1_INSTANCE);
824 free(buffer);
825}
826
827crypto_engine_type board_ce_type(void)
828{
829 return CRYPTO_ENGINE_TYPE_HW;
830}
831
832/* Set up params for h/w CE. */
833void target_crypto_init_params()
834{
835 struct crypto_init_params ce_params;
836
837 /* Set up base addresses and instance. */
838 ce_params.crypto_instance = CE1_INSTANCE;
839 ce_params.crypto_base = MSM_CE1_BASE;
840 ce_params.bam_base = MSM_CE1_BAM_BASE;
841
842 /* Set up BAM config. */
843 ce_params.bam_ee = CE_EE;
844 ce_params.pipes.read_pipe = CE_READ_PIPE;
845 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
846 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
847 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
848
849 /* Assign buffer sizes. */
850 ce_params.num_ce = CE_ARRAY_SIZE;
851 ce_params.read_fifo_size = CE_FIFO_SIZE;
852 ce_params.write_fifo_size = CE_FIFO_SIZE;
853
854 /* BAM is initialized by TZ for this platform.
855 * Do not do it again as the initialization address space
856 * is locked.
857 */
858 ce_params.do_bam_init = 0;
859
860 crypto_init_params(&ce_params);
861}
862
863uint32_t target_get_hlos_subtype()
864{
865 return board_hlos_subtype();
866}
Channagoud Kadabi400bd112015-08-10 15:38:10 -0700867
868void pmic_reset_configure(uint8_t reset_type)
869{
870 pm8x41_reset_configure(reset_type);
871}
lijuang3606df82015-09-02 21:14:43 +0800872
873uint32_t target_get_pmic()
874{
Arun kumarcf6e06e2018-09-26 12:49:53 +0530875 uint32_t hw_id = board_hardware_id();
876 uint32_t platform = board_platform_id();
877 uint32_t platform_subtype = board_hardware_subtype();
878
879 if ((MSM8909 == platform) &&
880 (HW_PLATFORM_MTP == hw_id) &&
881 (HW_PLATFORM_SUBTYPE_8909_PM8916 == platform_subtype))
882 return PMIC_IS_PM8916;
883 else if ((platform_subtype == HW_PLATFORM_SUBTYPE_8909_PM660) ||
884 (platform_subtype == HW_PLATFORM_SUBTYPE_8909_PM660_V1) ||
885 (platform_subtype == HW_PLATFORM_SUBTYPE_8909_COMPAL_ALPHA))
Mayank Grover3f20adf2017-07-03 16:33:22 +0530886 return PMIC_IS_PM660;
887 else
888 return PMIC_IS_PM8909;
lijuang3606df82015-09-02 21:14:43 +0800889}