blob: 2097f3673836e0e94eb556fa27dae4a2eae2f93b [file] [log] [blame]
lijuang395b5e62015-11-19 17:39:44 +08001/* Copyright (c) 2014-2016, 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>
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053053
Unnati Gandhif4cb6622014-08-28 13:54:56 +053054#if LONG_PRESS_POWER_ON
55#include <shutdown_detect.h>
56#endif
57
58#if PON_VIB_SUPPORT
59#include <vibrator.h>
60#endif
61
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053062#define PMIC_ARB_CHANNEL_NUM 0
63#define PMIC_ARB_OWNER_ID 0
Unnati Gandhif4cb6622014-08-28 13:54:56 +053064#define TLMM_VOL_UP_BTN_GPIO 90
Matthew Qin7bd789f2015-07-15 15:31:20 +080065#define TLMM_VOL_DOWN_BTN_GPIO 91
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053066
Unnati Gandhif4cb6622014-08-28 13:54:56 +053067#if PON_VIB_SUPPORT
68#define VIBRATE_TIME 250
69#endif
Vijay Kumar Pendotib228cfc2016-06-13 20:15:23 +053070#define HW_SUBTYPE_APQ_NOWGR 0xA
Unnati Gandhif4cb6622014-08-28 13:54:56 +053071
Unnati Gandhif4cb6622014-08-28 13:54:56 +053072#define CE1_INSTANCE 1
73#define CE_EE 1
74#define CE_FIFO_SIZE 64
75#define CE_READ_PIPE 3
76#define CE_WRITE_PIPE 2
77#define CE_READ_PIPE_LOCK_GRP 0
78#define CE_WRITE_PIPE_LOCK_GRP 0
79#define CE_ARRAY_SIZE 20
Matthew Qin7bd789f2015-07-15 15:31:20 +080080#define SUB_TYPE_SKUT 0x0A
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053081
Unnati Gandhic43a2802014-09-19 17:27:25 +053082extern void smem_ptable_init(void);
83extern void smem_add_modem_partitions(struct ptable *flash_ptable);
84void target_sdc_init();
85
86static struct ptable flash_ptable;
87
88/* NANDc BAM pipe numbers */
89#define DATA_CONSUMER_PIPE 0
90#define DATA_PRODUCER_PIPE 1
91#define CMD_PIPE 2
92
93/* NANDc BAM pipe groups */
94#define DATA_PRODUCER_PIPE_GRP 0
95#define DATA_CONSUMER_PIPE_GRP 0
96#define CMD_PIPE_GRP 1
97
98/* NANDc EE */
99#define QPIC_NAND_EE 0
100
101/* NANDc max desc length. */
102#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
103
104#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
105
106struct qpic_nand_init_config config;
107
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530108struct mmc_device *dev;
109
110static uint32_t mmc_pwrctl_base[] =
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530111 { MSM_SDC1_BASE, MSM_SDC2_BASE };
112
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530113static uint32_t mmc_sdhci_base[] =
114 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
115
116static uint32_t mmc_sdc_pwrctl_irq[] =
117 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
118
119static void set_sdc_power_ctrl(void);
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700120static void set_ebi2_config(void);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530121
Unnati Gandhic43a2802014-09-19 17:27:25 +0530122void update_ptable_names(void)
123{
124 uint32_t ptn_index;
125 struct ptentry *ptentry_ptr = flash_ptable.parts;
126 struct ptentry *boot_ptn;
127 unsigned i;
128 uint32_t len;
129
130 /* Change all names to lower case. */
131 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
132 {
133 len = strlen(ptentry_ptr[ptn_index].name);
134
135 for (i = 0; i < len; i++)
136 {
137 if (isupper(ptentry_ptr[ptn_index].name[i]))
138 {
139 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
140 }
141 }
142
143 /* SBL fills in the last partition length as 0xFFFFFFFF.
144 * Update the length field based on the number of blocks on the flash.
145 */
146 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
147 {
148 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
149 }
150 }
151}
152
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530153void target_early_init(void)
154{
155#if WITH_DEBUG_UART
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530156 /* Do not intilaise UART in case the h/w
157 * is RCM.
158 */
159 if( board_hardware_id()!= HW_PLATFORM_RCM )
160 uart_dm_init(1, 0, BLSP1_UART0_BASE);
161 else
162 return;
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530163#endif
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530164
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530165}
166
Unnati Gandhic43a2802014-09-19 17:27:25 +0530167int target_is_emmc_boot(void)
168{
169 return platform_boot_dev_isemmc();
170}
171
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530172void target_sdc_init()
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530173{
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530174 struct mmc_config_data config;
175
176 /* Set drive strength & pull ctrl values */
177 set_sdc_power_ctrl();
178
179 config.bus_width = DATA_BUS_WIDTH_8BIT;
180 config.max_clk_rate = MMC_CLK_177MHZ;
181
182 /* Try slot 1*/
183 config.slot = 1;
184 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
185 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
186 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
187 config.hs400_support = 0;
188
189 if (!(dev = mmc_init(&config))) {
190 /* Try slot 2 */
191 config.slot = 2;
192 config.max_clk_rate = MMC_CLK_200MHZ;
193 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
194 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
195 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
196
197 if (!(dev = mmc_init(&config))) {
198 dprintf(CRITICAL, "mmc init failed!");
199 ASSERT(0);
200 }
201 }
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530202}
203
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530204void *target_mmc_device()
205{
206 return (void *) dev;
207}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530208
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530209/* Return 1 if vol_up pressed */
lijuang2d2b8a02015-06-05 21:34:15 +0800210int target_volume_up()
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530211{
lijuang2d2b8a02015-06-05 21:34:15 +0800212 static uint8_t first_time = 0;
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530213 uint8_t status = 0;
214
lijuang2d2b8a02015-06-05 21:34:15 +0800215 if (!first_time) {
216 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 +0530217
lijuang2d2b8a02015-06-05 21:34:15 +0800218 /* Wait for the gpio config to take effect - debounce time */
219 udelay(10000);
220
221 first_time = 1;
222 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530223
224 /* Get status of GPIO */
225 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
226
227 /* Active low signal. */
228 return !status;
229}
230
231/* Return 1 if vol_down pressed */
232uint32_t target_volume_down()
233{
Matthew Qin7bd789f2015-07-15 15:31:20 +0800234 if ((board_hardware_id() == HW_PLATFORM_QRD) &&
235 (board_hardware_subtype() == SUB_TYPE_SKUT)) {
236 uint32_t status = 0;
237
238 gpio_tlmm_config(TLMM_VOL_DOWN_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
239
240 /* Wait for the gpio config to take effect - debounce time */
241 thread_sleep(10);
242
243 /* Get status of GPIO */
244 status = gpio_status(TLMM_VOL_DOWN_BTN_GPIO);
245
246 /* Active low signal. */
247 return !status;
248 } else {
249 /* Volume down button tied in with PMIC RESIN. */
250 return pm8x41_resin_status();
251 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530252}
253
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530254static void target_keystatus()
255{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530256 keys_init();
257
258 if(target_volume_down())
259 keys_post_event(KEY_VOLUMEDOWN, 1);
260
261 if(target_volume_up())
262 keys_post_event(KEY_VOLUMEUP, 1);
263
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530264}
265
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530266static void set_sdc_power_ctrl()
267{
268 /* Drive strength configs for sdc pins */
269 struct tlmm_cfgs sdc1_hdrv_cfg[] =
270 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700271 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
272 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi9a6e6d42015-02-03 17:44:24 +0530273 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530274 };
275
276 /* Pull configs for sdc pins */
277 struct tlmm_cfgs sdc1_pull_cfg[] =
278 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700279 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
280 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
281 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530282 };
283
284 /* Set the drive strength & pull control values */
285 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
286 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
287}
288
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700289static void set_ebi2_config()
290{
291 /* Drive strength configs for ebi2 pins */
292 struct tlmm_cfgs ebi2_hdrv_cfg[] =
293 {
294 { EBI2_BUSY_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
295 { EBI2_WE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
296 { EBI2_OE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
297 { EBI2_CLE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
298 { EBI2_ALE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
299 { EBI2_CS_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
300 { EBI2_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
301 };
302
303 /* Pull configs for ebi2 pins */
304 struct tlmm_cfgs ebi2_pull_cfg[] =
305 {
306 { EBI2_BUSY_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
307 { EBI2_WE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
308 { EBI2_OE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
309 { EBI2_CLE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
310 { EBI2_ALE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
311 { EBI2_CS_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
312 { EBI2_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
313 };
314
315 /* Set the drive strength & pull control values */
316 tlmm_set_hdrive_ctrl(ebi2_hdrv_cfg, ARRAY_SIZE(ebi2_hdrv_cfg));
317 tlmm_set_pull_ctrl(ebi2_pull_cfg, ARRAY_SIZE(ebi2_pull_cfg));
318
319}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530320void target_init(void)
321{
322 uint32_t base_addr;
323 uint8_t slot;
324
325 dprintf(INFO, "target_init()\n");
326
327 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
328
329 target_keystatus();
330
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530331#if BOOT_CONFIG_SUPPORT
Unnati Gandhic43a2802014-09-19 17:27:25 +0530332 platform_read_boot_config();
Unnati Gandhi8e4711b2014-10-13 05:03:00 +0530333#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530334
Unnati Gandhic43a2802014-09-19 17:27:25 +0530335 if (platform_boot_dev_isemmc()) {
336 target_sdc_init();
337 if (partition_read_table())
338 {
339 dprintf(CRITICAL, "Error reading the partition table info\n");
340 ASSERT(0);
341 }
342
343 } else {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700344 set_ebi2_config();
Unnati Gandhic43a2802014-09-19 17:27:25 +0530345 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
346 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
347 config.pipes.cmd_pipe = CMD_PIPE;
348
349 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
350 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
351 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
352
353 config.bam_base = MSM_NAND_BAM_BASE;
354 config.nand_base = MSM_NAND_BASE;
355 config.ee = QPIC_NAND_EE;
356 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
357
358 qpic_nand_init(&config);
359
360 ptable_init(&flash_ptable);
361 smem_ptable_init();
362 smem_add_modem_partitions(&flash_ptable);
363
364 update_ptable_names();
365 flash_set_ptable(&flash_ptable);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530366 }
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530367
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530368#if LONG_PRESS_POWER_ON
369 shutdown_detect();
370#endif
371
372#if PON_VIB_SUPPORT
373
374 /* turn on vibrator to indicate that phone is booting up to end user */
375 vib_timed_turn_on(VIBRATE_TIME);
376#endif
377
378 if (target_use_signed_kernel())
379 target_crypto_init_params();
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530380
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530381#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530382 rpm_smd_init();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700383#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530384}
385
386void target_serialno(unsigned char *buf)
387{
388 uint32_t serialno;
389 if (target_is_emmc_boot()) {
390 serialno = mmc_get_psn();
391 snprintf((char *)buf, 13, "%x", serialno);
392 }
393}
394
395unsigned board_machtype(void)
396{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530397 return LINUX_MACHTYPE_UNKNOWN;
398}
399
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530400/* Detect the target type */
401void target_detect(struct board_data *board)
402{
403 /*
404 * already fill the board->target on board.c
405 */
406}
407
408void target_baseband_detect(struct board_data *board)
409{
410 uint32_t platform;
411
412 platform = board->platform;
413 switch(platform)
414 {
415 case MSM8909:
416 case MSM8209:
417 case MSM8208:
Unnati Gandhi917c8612015-02-06 16:50:32 +0530418 case MSM8609:
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530419 board->baseband = BASEBAND_MSM;
420 break;
421
422 case MDM9209:
423 case MDM9309:
424 case MDM9609:
425 board->baseband = BASEBAND_MDM;
426 break;
427
Unnati Gandhi36e40472014-12-16 12:00:04 +0530428 case APQ8009:
Vijay Kumar Pendotib228cfc2016-06-13 20:15:23 +0530429 if ((board->platform_hw == HW_PLATFORM_MTP) &&
430 (board->platform_subtype == HW_SUBTYPE_APQ_NOWGR))
431 board->baseband = BASEBAND_APQ_NOWGR;
432 else
433 board->baseband = BASEBAND_APQ;
Unnati Gandhi36e40472014-12-16 12:00:04 +0530434 break;
435
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530436 default:
437 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
438 ASSERT(0);
439 };
440}
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530441uint8_t target_panel_auto_detect_enabled()
442{
443 uint8_t ret = 0;
444
445 switch(board_hardware_id()) {
446 default:
447 ret = 0;
448 break;
449 }
450 return ret;
451}
452
453static uint8_t splash_override;
454/* Returns 1 if target supports continuous splash screen. */
455int target_cont_splash_screen()
456{
457 uint8_t splash_screen = 0;
458 if (!splash_override) {
459 switch (board_hardware_id()) {
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530460 case HW_PLATFORM_SURF:
461 case HW_PLATFORM_MTP:
Ray Zhang17a13112014-11-07 14:07:23 +0800462 case HW_PLATFORM_QRD:
Sandeep Panda8ede6502014-12-02 10:56:16 +0530463 case HW_PLATFORM_RCM:
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530464 splash_screen = 1;
465 break;
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530466 default:
467 splash_screen = 0;
468 break;
469 }
470 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
471 }
472 return splash_screen;
473}
474
475void target_force_cont_splash_disable(uint8_t override)
476{
477 splash_override = override;
478}
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530479
vijay kumar58d779b2015-08-31 17:25:49 +0530480int get_target_boot_params(const char *cmdline, const char *part, char **buf)
Unnati Gandhic43a2802014-09-19 17:27:25 +0530481{
482 struct ptable *ptable;
483 int system_ptn_index = -1;
vijay kumar58d779b2015-08-31 17:25:49 +0530484 uint32_t buflen;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530485
486 if (!target_is_emmc_boot()) {
487 if (!cmdline || !part || !buf || buflen < 0) {
488 dprintf(CRITICAL, "WARN: Invalid input param\n");
489 return -1;
490 }
vijay kumar58d779b2015-08-31 17:25:49 +0530491 buflen = strlen(" root=/dev/mtdblock") + sizeof(int) + 1; /*1 character for null termination*/
492 *buf = (char *)malloc(buflen);
493 if(!(*buf)) {
494 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
495 return -1;
496 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530497
498 ptable = flash_get_ptable();
499 if (!ptable) {
500 dprintf(CRITICAL,
501 "WARN: Cannot get flash partition table\n");
vijay kumar58d779b2015-08-31 17:25:49 +0530502 free(*buf);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530503 return -1;
504 }
505
506 system_ptn_index = ptable_get_index(ptable, part);
507 if (system_ptn_index < 0) {
508 dprintf(CRITICAL,
509 "WARN: Cannot get partition index for %s\n", part);
vijay kumar58d779b2015-08-31 17:25:49 +0530510 free(*buf);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530511 return -1;
512 }
513
514 /*
515 * check if cmdline contains "root=" at the beginning of buffer or
516 * " root=" in the middle of buffer.
517 */
518 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
519 (strstr(cmdline, " root="))))
520 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
521 else
vijay kumar58d779b2015-08-31 17:25:49 +0530522 snprintf(*buf, buflen, " root=/dev/mtdblock%d",
Unnati Gandhic43a2802014-09-19 17:27:25 +0530523 system_ptn_index);
vijay kumar58d779b2015-08-31 17:25:49 +0530524 /*in success case buf will be freed in the calling function of this*/
Unnati Gandhic43a2802014-09-19 17:27:25 +0530525 }
526
527 return 0;
528}
529
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530530unsigned target_baseband()
531{
532 return board_baseband();
533}
534
535int emmc_recovery_init(void)
536{
537 return _emmc_recovery_init();
538}
539
540void target_usb_init(void)
541{
542 uint32_t val;
543
544 /* Select and enable external configuration with USB PHY */
545 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
546
547 /* Enable sess_vld */
548 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
549 writel(val, USB_GENCONFIG_2);
550
551 /* Enable external vbus configuration in the LINK */
552 val = readl(USB_USBCMD);
553 val |= SESS_VLD_CTRL;
554 writel(val, USB_USBCMD);
555}
556
557unsigned target_pause_for_battery_charge(void)
558{
559 uint8_t pon_reason = pm8x41_get_pon_reason();
560 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
561 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
562 pon_reason, is_cold_boot);
563 /* In case of fastboot reboot,adb reboot or if we see the power key
564 * pressed we do not want go into charger mode.
565 * fastboot reboot is warm boot with PON hard reset bit not set
566 * adb reboot is a cold boot with PON hard reset bit set
567 */
568 if (is_cold_boot &&
569 (!(pon_reason & HARD_RST)) &&
570 (!(pon_reason & KPDPWR_N)) &&
Chunmei Cai6eb22fe2015-08-20 15:39:06 +0800571 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG) || (pon_reason & CBLPWR_N)))
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530572 return 1;
573 else
574 return 0;
575}
576
577void target_usb_stop(void)
578{
579 /* Disable VBUS mimicing in the controller. */
580 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
581}
582
583
584void target_uninit(void)
585{
586#if PON_VIB_SUPPORT
587 /* wait for the vibrator timer is expried */
588 wait_vib_timeout();
589#endif
590
Unnati Gandhic43a2802014-09-19 17:27:25 +0530591 if (platform_boot_dev_isemmc())
592 {
593 mmc_put_card_to_sleep(dev);
594 sdhci_mode_disable(&dev->host);
595 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530596
597 if (crypto_initialized())
598 crypto_eng_cleanup();
599
600 if (target_is_ssd_enabled())
601 clock_ce_disable(CE1_INSTANCE);
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530602
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530603#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530604 rpm_smd_uninit();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700605#endif
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530606}
607
608/* Do any target specific intialization needed before entering fastboot mode */
609void target_fastboot_init(void)
610{
611 /* Set the BOOT_DONE flag in PM8916 */
612 pm8x41_set_boot_done();
613
614 if (target_is_ssd_enabled()) {
615 clock_ce_enable(CE1_INSTANCE);
616 target_load_ssd_keystore();
617 }
618}
619
lijuang395b5e62015-11-19 17:39:44 +0800620int set_download_mode(enum reboot_reason mode)
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530621{
622 int ret = 0;
623 ret = scm_dload_mode(mode);
624
625 pm8x41_clear_pmic_watchdog();
626
627 return ret;
628}
629
630void target_load_ssd_keystore(void)
631{
632 uint64_t ptn;
633 int index;
634 uint64_t size;
635 uint32_t *buffer = NULL;
636
637 if (!target_is_ssd_enabled())
638 return;
639
640 index = partition_get_index("ssd");
641
642 ptn = partition_get_offset(index);
643 if (ptn == 0){
644 dprintf(CRITICAL, "Error: ssd partition not found\n");
645 return;
646 }
647
648 size = partition_get_size(index);
649 if (size == 0) {
650 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
651 return;
652 }
653
654 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
655 if (!buffer) {
656 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
657 return;
658 }
659 if (mmc_read(ptn, buffer, size)) {
660 dprintf(CRITICAL, "Error: cannot read data\n");
661 free(buffer);
662 return;
663 }
664
665 clock_ce_enable(CE1_INSTANCE);
666 scm_protect_keystore(buffer, size);
667 clock_ce_disable(CE1_INSTANCE);
668 free(buffer);
669}
670
671crypto_engine_type board_ce_type(void)
672{
673 return CRYPTO_ENGINE_TYPE_HW;
674}
675
676/* Set up params for h/w CE. */
677void target_crypto_init_params()
678{
679 struct crypto_init_params ce_params;
680
681 /* Set up base addresses and instance. */
682 ce_params.crypto_instance = CE1_INSTANCE;
683 ce_params.crypto_base = MSM_CE1_BASE;
684 ce_params.bam_base = MSM_CE1_BAM_BASE;
685
686 /* Set up BAM config. */
687 ce_params.bam_ee = CE_EE;
688 ce_params.pipes.read_pipe = CE_READ_PIPE;
689 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
690 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
691 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
692
693 /* Assign buffer sizes. */
694 ce_params.num_ce = CE_ARRAY_SIZE;
695 ce_params.read_fifo_size = CE_FIFO_SIZE;
696 ce_params.write_fifo_size = CE_FIFO_SIZE;
697
698 /* BAM is initialized by TZ for this platform.
699 * Do not do it again as the initialization address space
700 * is locked.
701 */
702 ce_params.do_bam_init = 0;
703
704 crypto_init_params(&ce_params);
705}
706
707uint32_t target_get_hlos_subtype()
708{
709 return board_hlos_subtype();
710}
Channagoud Kadabi400bd112015-08-10 15:38:10 -0700711
712void pmic_reset_configure(uint8_t reset_type)
713{
714 pm8x41_reset_configure(reset_type);
715}
lijuang3606df82015-09-02 21:14:43 +0800716
717uint32_t target_get_pmic()
718{
719 return PMIC_IS_PM8909;
720}