blob: 56aecd9d6c3c4faae55a23b34454acff5d74cd56 [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) &&
Parth Dixit102ac212016-10-21 20:38:14 +0530430 ((board->platform_subtype == HW_SUBTYPE_APQ_NOWGR) ||
431 (board->platform_subtype == HW_PLATFORM_SUBTYPE_SWOC_NOWGR_CIRC)))
Vijay Kumar Pendotib228cfc2016-06-13 20:15:23 +0530432 board->baseband = BASEBAND_APQ_NOWGR;
433 else
434 board->baseband = BASEBAND_APQ;
Unnati Gandhi36e40472014-12-16 12:00:04 +0530435 break;
436
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530437 default:
438 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
439 ASSERT(0);
440 };
441}
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530442uint8_t target_panel_auto_detect_enabled()
443{
444 uint8_t ret = 0;
445
446 switch(board_hardware_id()) {
447 default:
448 ret = 0;
449 break;
450 }
451 return ret;
452}
453
454static uint8_t splash_override;
455/* Returns 1 if target supports continuous splash screen. */
456int target_cont_splash_screen()
457{
458 uint8_t splash_screen = 0;
459 if (!splash_override) {
460 switch (board_hardware_id()) {
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530461 case HW_PLATFORM_SURF:
462 case HW_PLATFORM_MTP:
Ray Zhang17a13112014-11-07 14:07:23 +0800463 case HW_PLATFORM_QRD:
Sandeep Panda8ede6502014-12-02 10:56:16 +0530464 case HW_PLATFORM_RCM:
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530465 splash_screen = 1;
466 break;
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530467 default:
468 splash_screen = 0;
469 break;
470 }
471 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
472 }
473 return splash_screen;
474}
475
476void target_force_cont_splash_disable(uint8_t override)
477{
478 splash_override = override;
479}
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530480
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530481/*Update this command line only for LE based builds*/
vijay kumar58d779b2015-08-31 17:25:49 +0530482int get_target_boot_params(const char *cmdline, const char *part, char **buf)
Unnati Gandhic43a2802014-09-19 17:27:25 +0530483{
484 struct ptable *ptable;
485 int system_ptn_index = -1;
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530486 int le_based = -1;
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530487 uint32_t buflen = 0;
488
489 if (!cmdline || !part ) {
490 dprintf(CRITICAL, "WARN: Invalid input param\n");
491 return -1;
492 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530493
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530494 /*LE partition.xml will have recoveryfs partition*/
495 if (target_is_emmc_boot())
496 le_based = partition_get_index("recoveryfs");
497 else
498 /*Nand targets by default have this*/
499 le_based = 1;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530500
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530501 if (le_based != -1)
502 {
503 if (!target_is_emmc_boot())
504 {
505 ptable = flash_get_ptable();
506 if (!ptable)
507 {
508 dprintf(CRITICAL,
509 "WARN: Cannot get flash partition table\n");
510 return -1;
511 }
512 system_ptn_index = ptable_get_index(ptable, part);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530513 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530514 else
515 system_ptn_index = partition_get_index(part);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530516 if (system_ptn_index < 0) {
517 dprintf(CRITICAL,
518 "WARN: Cannot get partition index for %s\n", part);
519 return -1;
520 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530521 /*
522 * check if cmdline contains "root=" at the beginning of buffer or
523 * " root=" in the middle of buffer.
524 */
525 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530526 (strstr(cmdline, " root=")))) {
Unnati Gandhic43a2802014-09-19 17:27:25 +0530527 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530528 return -1;
529 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530530 else
vijay kumar58d779b2015-08-31 17:25:49 +0530531 /*in success case buf will be freed in the calling function of this*/
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530532 {
533 if (!target_is_emmc_boot())
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530534 {
535 /* Extra character is for Null termination */
536 buflen = strlen(" root=/dev/mtdblock") + sizeof(int) +1;
537
538 /* In success case, this memory is freed in calling function */
539 *buf = (char *)malloc(buflen);
540 if(!(*buf)) {
541 dprintf(CRITICAL,"Unable to allocate memory for boot params \n");
542 return -1;
543 }
544
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530545 snprintf(*buf, buflen, " root=/dev/mtdblock%d",system_ptn_index);
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530546 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530547 else
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530548 {
549 /* Extra character is for Null termination */
550 buflen = strlen(" root=/dev/mmcblk0p") + sizeof(int) + 1;
551
552 /* In success case, this memory is freed in calling function */
553 *buf = (char *)malloc(buflen);
554 if(!(*buf)) {
555 dprintf(CRITICAL,"Unable to allocate memory for boot params \n");
556 return -1;
557 }
558
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530559 /*For Emmc case increase the ptn_index by 1*/
P.V. Phani Kumard9a08422016-08-30 13:35:29 +0530560 snprintf(*buf, buflen, " root=/dev/mmcblk0p%d",system_ptn_index + 1);
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530561 }
Vijay Kumar Pendoti92688632016-05-27 11:35:32 +0530562 }
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530563
564 /*Return for LE based Targets.*/
565 return 0;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530566 }
P.V. Phani Kumar3de93a02016-08-05 13:05:08 +0530567 return -1;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530568}
569
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530570unsigned target_baseband()
571{
572 return board_baseband();
573}
574
575int emmc_recovery_init(void)
576{
577 return _emmc_recovery_init();
578}
579
580void target_usb_init(void)
581{
582 uint32_t val;
583
584 /* Select and enable external configuration with USB PHY */
585 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
586
587 /* Enable sess_vld */
588 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
589 writel(val, USB_GENCONFIG_2);
590
591 /* Enable external vbus configuration in the LINK */
592 val = readl(USB_USBCMD);
593 val |= SESS_VLD_CTRL;
594 writel(val, USB_USBCMD);
595}
596
597unsigned target_pause_for_battery_charge(void)
598{
599 uint8_t pon_reason = pm8x41_get_pon_reason();
600 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
601 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
602 pon_reason, is_cold_boot);
603 /* In case of fastboot reboot,adb reboot or if we see the power key
604 * pressed we do not want go into charger mode.
605 * fastboot reboot is warm boot with PON hard reset bit not set
606 * adb reboot is a cold boot with PON hard reset bit set
607 */
608 if (is_cold_boot &&
609 (!(pon_reason & HARD_RST)) &&
610 (!(pon_reason & KPDPWR_N)) &&
Chunmei Cai6eb22fe2015-08-20 15:39:06 +0800611 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG) || (pon_reason & CBLPWR_N)))
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530612 return 1;
613 else
614 return 0;
615}
616
617void target_usb_stop(void)
618{
619 /* Disable VBUS mimicing in the controller. */
620 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
621}
622
623
624void target_uninit(void)
625{
626#if PON_VIB_SUPPORT
627 /* wait for the vibrator timer is expried */
628 wait_vib_timeout();
629#endif
630
Unnati Gandhic43a2802014-09-19 17:27:25 +0530631 if (platform_boot_dev_isemmc())
632 {
633 mmc_put_card_to_sleep(dev);
634 sdhci_mode_disable(&dev->host);
635 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530636
637 if (crypto_initialized())
638 crypto_eng_cleanup();
639
640 if (target_is_ssd_enabled())
641 clock_ce_disable(CE1_INSTANCE);
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530642
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530643#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530644 rpm_smd_uninit();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700645#endif
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530646}
647
648/* Do any target specific intialization needed before entering fastboot mode */
649void target_fastboot_init(void)
650{
651 /* Set the BOOT_DONE flag in PM8916 */
652 pm8x41_set_boot_done();
653
654 if (target_is_ssd_enabled()) {
655 clock_ce_enable(CE1_INSTANCE);
656 target_load_ssd_keystore();
657 }
658}
659
lijuang395b5e62015-11-19 17:39:44 +0800660int set_download_mode(enum reboot_reason mode)
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530661{
662 int ret = 0;
663 ret = scm_dload_mode(mode);
664
665 pm8x41_clear_pmic_watchdog();
666
667 return ret;
668}
669
670void target_load_ssd_keystore(void)
671{
672 uint64_t ptn;
673 int index;
674 uint64_t size;
675 uint32_t *buffer = NULL;
676
677 if (!target_is_ssd_enabled())
678 return;
679
680 index = partition_get_index("ssd");
681
682 ptn = partition_get_offset(index);
683 if (ptn == 0){
684 dprintf(CRITICAL, "Error: ssd partition not found\n");
685 return;
686 }
687
688 size = partition_get_size(index);
689 if (size == 0) {
690 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
691 return;
692 }
693
694 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
695 if (!buffer) {
696 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
697 return;
698 }
699 if (mmc_read(ptn, buffer, size)) {
700 dprintf(CRITICAL, "Error: cannot read data\n");
701 free(buffer);
702 return;
703 }
704
705 clock_ce_enable(CE1_INSTANCE);
706 scm_protect_keystore(buffer, size);
707 clock_ce_disable(CE1_INSTANCE);
708 free(buffer);
709}
710
711crypto_engine_type board_ce_type(void)
712{
713 return CRYPTO_ENGINE_TYPE_HW;
714}
715
716/* Set up params for h/w CE. */
717void target_crypto_init_params()
718{
719 struct crypto_init_params ce_params;
720
721 /* Set up base addresses and instance. */
722 ce_params.crypto_instance = CE1_INSTANCE;
723 ce_params.crypto_base = MSM_CE1_BASE;
724 ce_params.bam_base = MSM_CE1_BAM_BASE;
725
726 /* Set up BAM config. */
727 ce_params.bam_ee = CE_EE;
728 ce_params.pipes.read_pipe = CE_READ_PIPE;
729 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
730 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
731 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
732
733 /* Assign buffer sizes. */
734 ce_params.num_ce = CE_ARRAY_SIZE;
735 ce_params.read_fifo_size = CE_FIFO_SIZE;
736 ce_params.write_fifo_size = CE_FIFO_SIZE;
737
738 /* BAM is initialized by TZ for this platform.
739 * Do not do it again as the initialization address space
740 * is locked.
741 */
742 ce_params.do_bam_init = 0;
743
744 crypto_init_params(&ce_params);
745}
746
747uint32_t target_get_hlos_subtype()
748{
749 return board_hlos_subtype();
750}
Channagoud Kadabi400bd112015-08-10 15:38:10 -0700751
752void pmic_reset_configure(uint8_t reset_type)
753{
754 pm8x41_reset_configure(reset_type);
755}
lijuang3606df82015-09-02 21:14:43 +0800756
757uint32_t target_get_pmic()
758{
759 return PMIC_IS_PM8909;
760}