blob: e439c04bc2a2f6ac455485de0d1150ef98b738af [file] [log] [blame]
Unnati Gandhi9a6e6d42015-02-03 17:44:24 +05301/* Copyright (c) 2014-2015, 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
70
Unnati Gandhif4cb6622014-08-28 13:54:56 +053071#define CE1_INSTANCE 1
72#define CE_EE 1
73#define CE_FIFO_SIZE 64
74#define CE_READ_PIPE 3
75#define CE_WRITE_PIPE 2
76#define CE_READ_PIPE_LOCK_GRP 0
77#define CE_WRITE_PIPE_LOCK_GRP 0
78#define CE_ARRAY_SIZE 20
Matthew Qin7bd789f2015-07-15 15:31:20 +080079#define SUB_TYPE_SKUT 0x0A
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053080
Unnati Gandhic43a2802014-09-19 17:27:25 +053081extern void smem_ptable_init(void);
82extern void smem_add_modem_partitions(struct ptable *flash_ptable);
83void target_sdc_init();
84
85static struct ptable flash_ptable;
86
87/* NANDc BAM pipe numbers */
88#define DATA_CONSUMER_PIPE 0
89#define DATA_PRODUCER_PIPE 1
90#define CMD_PIPE 2
91
92/* NANDc BAM pipe groups */
93#define DATA_PRODUCER_PIPE_GRP 0
94#define DATA_CONSUMER_PIPE_GRP 0
95#define CMD_PIPE_GRP 1
96
97/* NANDc EE */
98#define QPIC_NAND_EE 0
99
100/* NANDc max desc length. */
101#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
102
103#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
104
105struct qpic_nand_init_config config;
106
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530107struct mmc_device *dev;
108
109static uint32_t mmc_pwrctl_base[] =
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530110 { MSM_SDC1_BASE, MSM_SDC2_BASE };
111
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530112static uint32_t mmc_sdhci_base[] =
113 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
114
115static uint32_t mmc_sdc_pwrctl_irq[] =
116 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
117
118static void set_sdc_power_ctrl(void);
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700119static void set_ebi2_config(void);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530120
Unnati Gandhic43a2802014-09-19 17:27:25 +0530121void update_ptable_names(void)
122{
123 uint32_t ptn_index;
124 struct ptentry *ptentry_ptr = flash_ptable.parts;
125 struct ptentry *boot_ptn;
126 unsigned i;
127 uint32_t len;
128
129 /* Change all names to lower case. */
130 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
131 {
132 len = strlen(ptentry_ptr[ptn_index].name);
133
134 for (i = 0; i < len; i++)
135 {
136 if (isupper(ptentry_ptr[ptn_index].name[i]))
137 {
138 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
139 }
140 }
141
142 /* SBL fills in the last partition length as 0xFFFFFFFF.
143 * Update the length field based on the number of blocks on the flash.
144 */
145 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
146 {
147 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
148 }
149 }
150}
151
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530152void target_early_init(void)
153{
154#if WITH_DEBUG_UART
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530155 /* Do not intilaise UART in case the h/w
156 * is RCM.
157 */
158 if( board_hardware_id()!= HW_PLATFORM_RCM )
159 uart_dm_init(1, 0, BLSP1_UART0_BASE);
160 else
161 return;
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530162#endif
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530163
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530164}
165
Unnati Gandhic43a2802014-09-19 17:27:25 +0530166int target_is_emmc_boot(void)
167{
168 return platform_boot_dev_isemmc();
169}
170
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530171void target_sdc_init()
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530172{
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530173 struct mmc_config_data config;
174
175 /* Set drive strength & pull ctrl values */
176 set_sdc_power_ctrl();
177
178 config.bus_width = DATA_BUS_WIDTH_8BIT;
179 config.max_clk_rate = MMC_CLK_177MHZ;
180
181 /* Try slot 1*/
182 config.slot = 1;
183 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
184 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
185 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
186 config.hs400_support = 0;
187
188 if (!(dev = mmc_init(&config))) {
189 /* Try slot 2 */
190 config.slot = 2;
191 config.max_clk_rate = MMC_CLK_200MHZ;
192 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
193 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
194 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
195
196 if (!(dev = mmc_init(&config))) {
197 dprintf(CRITICAL, "mmc init failed!");
198 ASSERT(0);
199 }
200 }
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530201}
202
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530203void *target_mmc_device()
204{
205 return (void *) dev;
206}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530207
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530208/* Return 1 if vol_up pressed */
lijuang2d2b8a02015-06-05 21:34:15 +0800209int target_volume_up()
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530210{
lijuang2d2b8a02015-06-05 21:34:15 +0800211 static uint8_t first_time = 0;
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530212 uint8_t status = 0;
213
lijuang2d2b8a02015-06-05 21:34:15 +0800214 if (!first_time) {
215 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 +0530216
lijuang2d2b8a02015-06-05 21:34:15 +0800217 /* Wait for the gpio config to take effect - debounce time */
218 udelay(10000);
219
220 first_time = 1;
221 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530222
223 /* Get status of GPIO */
224 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
225
226 /* Active low signal. */
227 return !status;
228}
229
230/* Return 1 if vol_down pressed */
231uint32_t target_volume_down()
232{
Matthew Qin7bd789f2015-07-15 15:31:20 +0800233 if ((board_hardware_id() == HW_PLATFORM_QRD) &&
234 (board_hardware_subtype() == SUB_TYPE_SKUT)) {
235 uint32_t status = 0;
236
237 gpio_tlmm_config(TLMM_VOL_DOWN_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
238
239 /* Wait for the gpio config to take effect - debounce time */
240 thread_sleep(10);
241
242 /* Get status of GPIO */
243 status = gpio_status(TLMM_VOL_DOWN_BTN_GPIO);
244
245 /* Active low signal. */
246 return !status;
247 } else {
248 /* Volume down button tied in with PMIC RESIN. */
249 return pm8x41_resin_status();
250 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530251}
252
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530253static void target_keystatus()
254{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530255 keys_init();
256
257 if(target_volume_down())
258 keys_post_event(KEY_VOLUMEDOWN, 1);
259
260 if(target_volume_up())
261 keys_post_event(KEY_VOLUMEUP, 1);
262
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530263}
264
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530265static void set_sdc_power_ctrl()
266{
267 /* Drive strength configs for sdc pins */
268 struct tlmm_cfgs sdc1_hdrv_cfg[] =
269 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700270 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
271 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi9a6e6d42015-02-03 17:44:24 +0530272 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530273 };
274
275 /* Pull configs for sdc pins */
276 struct tlmm_cfgs sdc1_pull_cfg[] =
277 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700278 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
279 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
280 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530281 };
282
283 /* Set the drive strength & pull control values */
284 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
285 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
286}
287
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700288static void set_ebi2_config()
289{
290 /* Drive strength configs for ebi2 pins */
291 struct tlmm_cfgs ebi2_hdrv_cfg[] =
292 {
293 { EBI2_BUSY_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
294 { EBI2_WE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
295 { EBI2_OE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
296 { EBI2_CLE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
297 { EBI2_ALE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
298 { EBI2_CS_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
299 { EBI2_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
300 };
301
302 /* Pull configs for ebi2 pins */
303 struct tlmm_cfgs ebi2_pull_cfg[] =
304 {
305 { EBI2_BUSY_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
306 { EBI2_WE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
307 { EBI2_OE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
308 { EBI2_CLE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
309 { EBI2_ALE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
310 { EBI2_CS_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
311 { EBI2_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
312 };
313
314 /* Set the drive strength & pull control values */
315 tlmm_set_hdrive_ctrl(ebi2_hdrv_cfg, ARRAY_SIZE(ebi2_hdrv_cfg));
316 tlmm_set_pull_ctrl(ebi2_pull_cfg, ARRAY_SIZE(ebi2_pull_cfg));
317
318}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530319void target_init(void)
320{
321 uint32_t base_addr;
322 uint8_t slot;
323
324 dprintf(INFO, "target_init()\n");
325
326 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
327
328 target_keystatus();
329
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530330#if BOOT_CONFIG_SUPPORT
Unnati Gandhic43a2802014-09-19 17:27:25 +0530331 platform_read_boot_config();
Unnati Gandhi8e4711b2014-10-13 05:03:00 +0530332#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530333
Unnati Gandhic43a2802014-09-19 17:27:25 +0530334 if (platform_boot_dev_isemmc()) {
335 target_sdc_init();
336 if (partition_read_table())
337 {
338 dprintf(CRITICAL, "Error reading the partition table info\n");
339 ASSERT(0);
340 }
341
342 } else {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700343 set_ebi2_config();
Unnati Gandhic43a2802014-09-19 17:27:25 +0530344 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
345 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
346 config.pipes.cmd_pipe = CMD_PIPE;
347
348 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
349 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
350 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
351
352 config.bam_base = MSM_NAND_BAM_BASE;
353 config.nand_base = MSM_NAND_BASE;
354 config.ee = QPIC_NAND_EE;
355 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
356
357 qpic_nand_init(&config);
358
359 ptable_init(&flash_ptable);
360 smem_ptable_init();
361 smem_add_modem_partitions(&flash_ptable);
362
363 update_ptable_names();
364 flash_set_ptable(&flash_ptable);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530365 }
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530366
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530367#if LONG_PRESS_POWER_ON
368 shutdown_detect();
369#endif
370
371#if PON_VIB_SUPPORT
372
373 /* turn on vibrator to indicate that phone is booting up to end user */
374 vib_timed_turn_on(VIBRATE_TIME);
375#endif
376
377 if (target_use_signed_kernel())
378 target_crypto_init_params();
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530379
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530380#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530381 rpm_smd_init();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700382#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530383}
384
385void target_serialno(unsigned char *buf)
386{
387 uint32_t serialno;
388 if (target_is_emmc_boot()) {
389 serialno = mmc_get_psn();
390 snprintf((char *)buf, 13, "%x", serialno);
391 }
392}
393
394unsigned board_machtype(void)
395{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530396 return LINUX_MACHTYPE_UNKNOWN;
397}
398
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530399/* Detect the target type */
400void target_detect(struct board_data *board)
401{
402 /*
403 * already fill the board->target on board.c
404 */
405}
406
407void target_baseband_detect(struct board_data *board)
408{
409 uint32_t platform;
410
411 platform = board->platform;
412 switch(platform)
413 {
414 case MSM8909:
415 case MSM8209:
416 case MSM8208:
Unnati Gandhi917c8612015-02-06 16:50:32 +0530417 case MSM8609:
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530418 board->baseband = BASEBAND_MSM;
419 break;
420
421 case MDM9209:
422 case MDM9309:
423 case MDM9609:
424 board->baseband = BASEBAND_MDM;
425 break;
426
Unnati Gandhi36e40472014-12-16 12:00:04 +0530427 case APQ8009:
428 board->baseband = BASEBAND_APQ;
429 break;
430
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530431 default:
432 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
433 ASSERT(0);
434 };
435}
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530436uint8_t target_panel_auto_detect_enabled()
437{
438 uint8_t ret = 0;
439
440 switch(board_hardware_id()) {
441 default:
442 ret = 0;
443 break;
444 }
445 return ret;
446}
447
448static uint8_t splash_override;
449/* Returns 1 if target supports continuous splash screen. */
450int target_cont_splash_screen()
451{
452 uint8_t splash_screen = 0;
453 if (!splash_override) {
454 switch (board_hardware_id()) {
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530455 case HW_PLATFORM_SURF:
456 case HW_PLATFORM_MTP:
Ray Zhang17a13112014-11-07 14:07:23 +0800457 case HW_PLATFORM_QRD:
Sandeep Panda8ede6502014-12-02 10:56:16 +0530458 case HW_PLATFORM_RCM:
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530459 splash_screen = 1;
460 break;
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530461 default:
462 splash_screen = 0;
463 break;
464 }
465 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
466 }
467 return splash_screen;
468}
469
470void target_force_cont_splash_disable(uint8_t override)
471{
472 splash_override = override;
473}
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530474
vijay kumar58d779b2015-08-31 17:25:49 +0530475int get_target_boot_params(const char *cmdline, const char *part, char **buf)
Unnati Gandhic43a2802014-09-19 17:27:25 +0530476{
477 struct ptable *ptable;
478 int system_ptn_index = -1;
vijay kumar58d779b2015-08-31 17:25:49 +0530479 uint32_t buflen;
Unnati Gandhic43a2802014-09-19 17:27:25 +0530480
481 if (!target_is_emmc_boot()) {
482 if (!cmdline || !part || !buf || buflen < 0) {
483 dprintf(CRITICAL, "WARN: Invalid input param\n");
484 return -1;
485 }
vijay kumar58d779b2015-08-31 17:25:49 +0530486 buflen = strlen(" root=/dev/mtdblock") + sizeof(int) + 1; /*1 character for null termination*/
487 *buf = (char *)malloc(buflen);
488 if(!(*buf)) {
489 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
490 return -1;
491 }
Unnati Gandhic43a2802014-09-19 17:27:25 +0530492
493 ptable = flash_get_ptable();
494 if (!ptable) {
495 dprintf(CRITICAL,
496 "WARN: Cannot get flash partition table\n");
vijay kumar58d779b2015-08-31 17:25:49 +0530497 free(*buf);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530498 return -1;
499 }
500
501 system_ptn_index = ptable_get_index(ptable, part);
502 if (system_ptn_index < 0) {
503 dprintf(CRITICAL,
504 "WARN: Cannot get partition index for %s\n", part);
vijay kumar58d779b2015-08-31 17:25:49 +0530505 free(*buf);
Unnati Gandhic43a2802014-09-19 17:27:25 +0530506 return -1;
507 }
508
509 /*
510 * check if cmdline contains "root=" at the beginning of buffer or
511 * " root=" in the middle of buffer.
512 */
513 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
514 (strstr(cmdline, " root="))))
515 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
516 else
vijay kumar58d779b2015-08-31 17:25:49 +0530517 snprintf(*buf, buflen, " root=/dev/mtdblock%d",
Unnati Gandhic43a2802014-09-19 17:27:25 +0530518 system_ptn_index);
vijay kumar58d779b2015-08-31 17:25:49 +0530519 /*in success case buf will be freed in the calling function of this*/
Unnati Gandhic43a2802014-09-19 17:27:25 +0530520 }
521
522 return 0;
523}
524
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530525unsigned target_baseband()
526{
527 return board_baseband();
528}
529
530int emmc_recovery_init(void)
531{
532 return _emmc_recovery_init();
533}
534
535void target_usb_init(void)
536{
537 uint32_t val;
538
539 /* Select and enable external configuration with USB PHY */
540 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
541
542 /* Enable sess_vld */
543 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
544 writel(val, USB_GENCONFIG_2);
545
546 /* Enable external vbus configuration in the LINK */
547 val = readl(USB_USBCMD);
548 val |= SESS_VLD_CTRL;
549 writel(val, USB_USBCMD);
550}
551
552unsigned target_pause_for_battery_charge(void)
553{
554 uint8_t pon_reason = pm8x41_get_pon_reason();
555 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
556 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
557 pon_reason, is_cold_boot);
558 /* In case of fastboot reboot,adb reboot or if we see the power key
559 * pressed we do not want go into charger mode.
560 * fastboot reboot is warm boot with PON hard reset bit not set
561 * adb reboot is a cold boot with PON hard reset bit set
562 */
563 if (is_cold_boot &&
564 (!(pon_reason & HARD_RST)) &&
565 (!(pon_reason & KPDPWR_N)) &&
Chunmei Cai6eb22fe2015-08-20 15:39:06 +0800566 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG) || (pon_reason & CBLPWR_N)))
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530567 return 1;
568 else
569 return 0;
570}
571
572void target_usb_stop(void)
573{
574 /* Disable VBUS mimicing in the controller. */
575 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
576}
577
578
579void target_uninit(void)
580{
581#if PON_VIB_SUPPORT
582 /* wait for the vibrator timer is expried */
583 wait_vib_timeout();
584#endif
585
Unnati Gandhic43a2802014-09-19 17:27:25 +0530586 if (platform_boot_dev_isemmc())
587 {
588 mmc_put_card_to_sleep(dev);
589 sdhci_mode_disable(&dev->host);
590 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530591
592 if (crypto_initialized())
593 crypto_eng_cleanup();
594
595 if (target_is_ssd_enabled())
596 clock_ce_disable(CE1_INSTANCE);
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530597
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530598#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530599 rpm_smd_uninit();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700600#endif
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530601}
602
603/* Do any target specific intialization needed before entering fastboot mode */
604void target_fastboot_init(void)
605{
606 /* Set the BOOT_DONE flag in PM8916 */
607 pm8x41_set_boot_done();
608
609 if (target_is_ssd_enabled()) {
610 clock_ce_enable(CE1_INSTANCE);
611 target_load_ssd_keystore();
612 }
613}
614
615int set_download_mode(enum dload_mode mode)
616{
617 int ret = 0;
618 ret = scm_dload_mode(mode);
619
620 pm8x41_clear_pmic_watchdog();
621
622 return ret;
623}
624
625void target_load_ssd_keystore(void)
626{
627 uint64_t ptn;
628 int index;
629 uint64_t size;
630 uint32_t *buffer = NULL;
631
632 if (!target_is_ssd_enabled())
633 return;
634
635 index = partition_get_index("ssd");
636
637 ptn = partition_get_offset(index);
638 if (ptn == 0){
639 dprintf(CRITICAL, "Error: ssd partition not found\n");
640 return;
641 }
642
643 size = partition_get_size(index);
644 if (size == 0) {
645 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
646 return;
647 }
648
649 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
650 if (!buffer) {
651 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
652 return;
653 }
654 if (mmc_read(ptn, buffer, size)) {
655 dprintf(CRITICAL, "Error: cannot read data\n");
656 free(buffer);
657 return;
658 }
659
660 clock_ce_enable(CE1_INSTANCE);
661 scm_protect_keystore(buffer, size);
662 clock_ce_disable(CE1_INSTANCE);
663 free(buffer);
664}
665
666crypto_engine_type board_ce_type(void)
667{
668 return CRYPTO_ENGINE_TYPE_HW;
669}
670
671/* Set up params for h/w CE. */
672void target_crypto_init_params()
673{
674 struct crypto_init_params ce_params;
675
676 /* Set up base addresses and instance. */
677 ce_params.crypto_instance = CE1_INSTANCE;
678 ce_params.crypto_base = MSM_CE1_BASE;
679 ce_params.bam_base = MSM_CE1_BAM_BASE;
680
681 /* Set up BAM config. */
682 ce_params.bam_ee = CE_EE;
683 ce_params.pipes.read_pipe = CE_READ_PIPE;
684 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
685 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
686 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
687
688 /* Assign buffer sizes. */
689 ce_params.num_ce = CE_ARRAY_SIZE;
690 ce_params.read_fifo_size = CE_FIFO_SIZE;
691 ce_params.write_fifo_size = CE_FIFO_SIZE;
692
693 /* BAM is initialized by TZ for this platform.
694 * Do not do it again as the initialization address space
695 * is locked.
696 */
697 ce_params.do_bam_init = 0;
698
699 crypto_init_params(&ce_params);
700}
701
702uint32_t target_get_hlos_subtype()
703{
704 return board_hlos_subtype();
705}
Channagoud Kadabi400bd112015-08-10 15:38:10 -0700706
707void pmic_reset_configure(uint8_t reset_type)
708{
709 pm8x41_reset_configure(reset_type);
710}
lijuang3606df82015-09-02 21:14:43 +0800711
712uint32_t target_get_pmic()
713{
714 return PMIC_IS_PM8909;
715}