blob: 3cc3923f507172a6d3cb80c08598466015acaa99 [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>
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053052
Unnati Gandhif4cb6622014-08-28 13:54:56 +053053#if LONG_PRESS_POWER_ON
54#include <shutdown_detect.h>
55#endif
56
57#if PON_VIB_SUPPORT
58#include <vibrator.h>
59#endif
60
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053061#define PMIC_ARB_CHANNEL_NUM 0
62#define PMIC_ARB_OWNER_ID 0
Unnati Gandhif4cb6622014-08-28 13:54:56 +053063#define TLMM_VOL_UP_BTN_GPIO 90
Matthew Qin7bd789f2015-07-15 15:31:20 +080064#define TLMM_VOL_DOWN_BTN_GPIO 91
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053065
Unnati Gandhif4cb6622014-08-28 13:54:56 +053066#if PON_VIB_SUPPORT
67#define VIBRATE_TIME 250
68#endif
69
Unnati Gandhif4cb6622014-08-28 13:54:56 +053070#define CE1_INSTANCE 1
71#define CE_EE 1
72#define CE_FIFO_SIZE 64
73#define CE_READ_PIPE 3
74#define CE_WRITE_PIPE 2
75#define CE_READ_PIPE_LOCK_GRP 0
76#define CE_WRITE_PIPE_LOCK_GRP 0
77#define CE_ARRAY_SIZE 20
Matthew Qin7bd789f2015-07-15 15:31:20 +080078#define SUB_TYPE_SKUT 0x0A
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053079
Unnati Gandhic43a2802014-09-19 17:27:25 +053080extern void smem_ptable_init(void);
81extern void smem_add_modem_partitions(struct ptable *flash_ptable);
82void target_sdc_init();
83
84static struct ptable flash_ptable;
85
86/* NANDc BAM pipe numbers */
87#define DATA_CONSUMER_PIPE 0
88#define DATA_PRODUCER_PIPE 1
89#define CMD_PIPE 2
90
91/* NANDc BAM pipe groups */
92#define DATA_PRODUCER_PIPE_GRP 0
93#define DATA_CONSUMER_PIPE_GRP 0
94#define CMD_PIPE_GRP 1
95
96/* NANDc EE */
97#define QPIC_NAND_EE 0
98
99/* NANDc max desc length. */
100#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
101
102#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
103
104struct qpic_nand_init_config config;
105
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530106struct mmc_device *dev;
107
108static uint32_t mmc_pwrctl_base[] =
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530109 { MSM_SDC1_BASE, MSM_SDC2_BASE };
110
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530111static uint32_t mmc_sdhci_base[] =
112 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
113
114static uint32_t mmc_sdc_pwrctl_irq[] =
115 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
116
117static void set_sdc_power_ctrl(void);
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700118static void set_ebi2_config(void);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530119
Unnati Gandhic43a2802014-09-19 17:27:25 +0530120void update_ptable_names(void)
121{
122 uint32_t ptn_index;
123 struct ptentry *ptentry_ptr = flash_ptable.parts;
124 struct ptentry *boot_ptn;
125 unsigned i;
126 uint32_t len;
127
128 /* Change all names to lower case. */
129 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
130 {
131 len = strlen(ptentry_ptr[ptn_index].name);
132
133 for (i = 0; i < len; i++)
134 {
135 if (isupper(ptentry_ptr[ptn_index].name[i]))
136 {
137 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
138 }
139 }
140
141 /* SBL fills in the last partition length as 0xFFFFFFFF.
142 * Update the length field based on the number of blocks on the flash.
143 */
144 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
145 {
146 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
147 }
148 }
149}
150
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530151void target_early_init(void)
152{
153#if WITH_DEBUG_UART
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530154 /* Do not intilaise UART in case the h/w
155 * is RCM.
156 */
157 if( board_hardware_id()!= HW_PLATFORM_RCM )
158 uart_dm_init(1, 0, BLSP1_UART0_BASE);
159 else
160 return;
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530161#endif
Unnati Gandhi1d7ca722015-03-12 16:51:09 +0530162
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530163}
164
Unnati Gandhic43a2802014-09-19 17:27:25 +0530165int target_is_emmc_boot(void)
166{
167 return platform_boot_dev_isemmc();
168}
169
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530170void target_sdc_init()
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530171{
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530172 struct mmc_config_data config;
173
174 /* Set drive strength & pull ctrl values */
175 set_sdc_power_ctrl();
176
177 config.bus_width = DATA_BUS_WIDTH_8BIT;
178 config.max_clk_rate = MMC_CLK_177MHZ;
179
180 /* Try slot 1*/
181 config.slot = 1;
182 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
183 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
184 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
185 config.hs400_support = 0;
186
187 if (!(dev = mmc_init(&config))) {
188 /* Try slot 2 */
189 config.slot = 2;
190 config.max_clk_rate = MMC_CLK_200MHZ;
191 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
192 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
193 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
194
195 if (!(dev = mmc_init(&config))) {
196 dprintf(CRITICAL, "mmc init failed!");
197 ASSERT(0);
198 }
199 }
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530200}
201
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530202void *target_mmc_device()
203{
204 return (void *) dev;
205}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530206
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530207/* Return 1 if vol_up pressed */
lijuang2d2b8a02015-06-05 21:34:15 +0800208int target_volume_up()
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530209{
lijuang2d2b8a02015-06-05 21:34:15 +0800210 static uint8_t first_time = 0;
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530211 uint8_t status = 0;
212
lijuang2d2b8a02015-06-05 21:34:15 +0800213 if (!first_time) {
214 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 +0530215
lijuang2d2b8a02015-06-05 21:34:15 +0800216 /* Wait for the gpio config to take effect - debounce time */
217 udelay(10000);
218
219 first_time = 1;
220 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530221
222 /* Get status of GPIO */
223 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
224
225 /* Active low signal. */
226 return !status;
227}
228
229/* Return 1 if vol_down pressed */
230uint32_t target_volume_down()
231{
Matthew Qin7bd789f2015-07-15 15:31:20 +0800232 if ((board_hardware_id() == HW_PLATFORM_QRD) &&
233 (board_hardware_subtype() == SUB_TYPE_SKUT)) {
234 uint32_t status = 0;
235
236 gpio_tlmm_config(TLMM_VOL_DOWN_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
237
238 /* Wait for the gpio config to take effect - debounce time */
239 thread_sleep(10);
240
241 /* Get status of GPIO */
242 status = gpio_status(TLMM_VOL_DOWN_BTN_GPIO);
243
244 /* Active low signal. */
245 return !status;
246 } else {
247 /* Volume down button tied in with PMIC RESIN. */
248 return pm8x41_resin_status();
249 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530250}
251
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530252static void target_keystatus()
253{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530254 keys_init();
255
256 if(target_volume_down())
257 keys_post_event(KEY_VOLUMEDOWN, 1);
258
259 if(target_volume_up())
260 keys_post_event(KEY_VOLUMEUP, 1);
261
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530262}
263
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530264static void set_sdc_power_ctrl()
265{
266 /* Drive strength configs for sdc pins */
267 struct tlmm_cfgs sdc1_hdrv_cfg[] =
268 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700269 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
270 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi9a6e6d42015-02-03 17:44:24 +0530271 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530272 };
273
274 /* Pull configs for sdc pins */
275 struct tlmm_cfgs sdc1_pull_cfg[] =
276 {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700277 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
278 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
279 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530280 };
281
282 /* Set the drive strength & pull control values */
283 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
284 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
285}
286
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700287static void set_ebi2_config()
288{
289 /* Drive strength configs for ebi2 pins */
290 struct tlmm_cfgs ebi2_hdrv_cfg[] =
291 {
292 { EBI2_BUSY_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
293 { EBI2_WE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
294 { EBI2_OE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
295 { EBI2_CLE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
296 { EBI2_ALE_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
297 { EBI2_CS_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
298 { EBI2_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
299 };
300
301 /* Pull configs for ebi2 pins */
302 struct tlmm_cfgs ebi2_pull_cfg[] =
303 {
304 { EBI2_BUSY_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
305 { EBI2_WE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
306 { EBI2_OE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
307 { EBI2_CLE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
308 { EBI2_ALE_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
309 { EBI2_CS_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, TLMM_EBI2_EMMC_GPIO_CFG },
310 { EBI2_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
311 };
312
313 /* Set the drive strength & pull control values */
314 tlmm_set_hdrive_ctrl(ebi2_hdrv_cfg, ARRAY_SIZE(ebi2_hdrv_cfg));
315 tlmm_set_pull_ctrl(ebi2_pull_cfg, ARRAY_SIZE(ebi2_pull_cfg));
316
317}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530318void target_init(void)
319{
320 uint32_t base_addr;
321 uint8_t slot;
322
323 dprintf(INFO, "target_init()\n");
324
325 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
326
327 target_keystatus();
328
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530329#if BOOT_CONFIG_SUPPORT
Unnati Gandhic43a2802014-09-19 17:27:25 +0530330 platform_read_boot_config();
Unnati Gandhi8e4711b2014-10-13 05:03:00 +0530331#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530332
Unnati Gandhic43a2802014-09-19 17:27:25 +0530333 if (platform_boot_dev_isemmc()) {
334 target_sdc_init();
335 if (partition_read_table())
336 {
337 dprintf(CRITICAL, "Error reading the partition table info\n");
338 ASSERT(0);
339 }
340
341 } else {
Aparna Mallavarapu5f80cbf2014-10-13 11:10:22 -0700342 set_ebi2_config();
Unnati Gandhic43a2802014-09-19 17:27:25 +0530343 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
344 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
345 config.pipes.cmd_pipe = CMD_PIPE;
346
347 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
348 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
349 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
350
351 config.bam_base = MSM_NAND_BAM_BASE;
352 config.nand_base = MSM_NAND_BASE;
353 config.ee = QPIC_NAND_EE;
354 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
355
356 qpic_nand_init(&config);
357
358 ptable_init(&flash_ptable);
359 smem_ptable_init();
360 smem_add_modem_partitions(&flash_ptable);
361
362 update_ptable_names();
363 flash_set_ptable(&flash_ptable);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530364 }
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530365
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530366#if LONG_PRESS_POWER_ON
367 shutdown_detect();
368#endif
369
370#if PON_VIB_SUPPORT
371
372 /* turn on vibrator to indicate that phone is booting up to end user */
373 vib_timed_turn_on(VIBRATE_TIME);
374#endif
375
376 if (target_use_signed_kernel())
377 target_crypto_init_params();
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530378
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530379#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530380 rpm_smd_init();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700381#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530382}
383
384void target_serialno(unsigned char *buf)
385{
386 uint32_t serialno;
387 if (target_is_emmc_boot()) {
388 serialno = mmc_get_psn();
389 snprintf((char *)buf, 13, "%x", serialno);
390 }
391}
392
393unsigned board_machtype(void)
394{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530395 return LINUX_MACHTYPE_UNKNOWN;
396}
397
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530398/* Detect the target type */
399void target_detect(struct board_data *board)
400{
401 /*
402 * already fill the board->target on board.c
403 */
404}
405
406void target_baseband_detect(struct board_data *board)
407{
408 uint32_t platform;
409
410 platform = board->platform;
411 switch(platform)
412 {
413 case MSM8909:
414 case MSM8209:
415 case MSM8208:
Unnati Gandhi917c8612015-02-06 16:50:32 +0530416 case MSM8609:
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530417 board->baseband = BASEBAND_MSM;
418 break;
419
420 case MDM9209:
421 case MDM9309:
422 case MDM9609:
423 board->baseband = BASEBAND_MDM;
424 break;
425
Unnati Gandhi36e40472014-12-16 12:00:04 +0530426 case APQ8009:
427 board->baseband = BASEBAND_APQ;
428 break;
429
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530430 default:
431 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
432 ASSERT(0);
433 };
434}
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530435uint8_t target_panel_auto_detect_enabled()
436{
437 uint8_t ret = 0;
438
439 switch(board_hardware_id()) {
440 default:
441 ret = 0;
442 break;
443 }
444 return ret;
445}
446
447static uint8_t splash_override;
448/* Returns 1 if target supports continuous splash screen. */
449int target_cont_splash_screen()
450{
451 uint8_t splash_screen = 0;
452 if (!splash_override) {
453 switch (board_hardware_id()) {
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530454 case HW_PLATFORM_SURF:
455 case HW_PLATFORM_MTP:
Ray Zhang17a13112014-11-07 14:07:23 +0800456 case HW_PLATFORM_QRD:
Sandeep Panda8ede6502014-12-02 10:56:16 +0530457 case HW_PLATFORM_RCM:
Shivaraj Shetty7db7eec2014-11-05 20:48:35 +0530458 splash_screen = 1;
459 break;
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530460 default:
461 splash_screen = 0;
462 break;
463 }
464 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
465 }
466 return splash_screen;
467}
468
469void target_force_cont_splash_disable(uint8_t override)
470{
471 splash_override = override;
472}
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530473
Unnati Gandhic43a2802014-09-19 17:27:25 +0530474int get_target_boot_params(const char *cmdline, const char *part, char *buf,
475 int buflen)
476{
477 struct ptable *ptable;
478 int system_ptn_index = -1;
479
480 if (!target_is_emmc_boot()) {
481 if (!cmdline || !part || !buf || buflen < 0) {
482 dprintf(CRITICAL, "WARN: Invalid input param\n");
483 return -1;
484 }
485
486 ptable = flash_get_ptable();
487 if (!ptable) {
488 dprintf(CRITICAL,
489 "WARN: Cannot get flash partition table\n");
490 return -1;
491 }
492
493 system_ptn_index = ptable_get_index(ptable, part);
494 if (system_ptn_index < 0) {
495 dprintf(CRITICAL,
496 "WARN: Cannot get partition index for %s\n", part);
497 return -1;
498 }
499
500 /*
501 * check if cmdline contains "root=" at the beginning of buffer or
502 * " root=" in the middle of buffer.
503 */
504 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
505 (strstr(cmdline, " root="))))
506 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
507 else
508 snprintf(buf, buflen, " root=/dev/mtdblock%d",
509 system_ptn_index);
510 }
511
512 return 0;
513}
514
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530515unsigned target_baseband()
516{
517 return board_baseband();
518}
519
520int emmc_recovery_init(void)
521{
522 return _emmc_recovery_init();
523}
524
525void target_usb_init(void)
526{
527 uint32_t val;
528
529 /* Select and enable external configuration with USB PHY */
530 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
531
532 /* Enable sess_vld */
533 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
534 writel(val, USB_GENCONFIG_2);
535
536 /* Enable external vbus configuration in the LINK */
537 val = readl(USB_USBCMD);
538 val |= SESS_VLD_CTRL;
539 writel(val, USB_USBCMD);
540}
541
542unsigned target_pause_for_battery_charge(void)
543{
544 uint8_t pon_reason = pm8x41_get_pon_reason();
545 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
546 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
547 pon_reason, is_cold_boot);
548 /* In case of fastboot reboot,adb reboot or if we see the power key
549 * pressed we do not want go into charger mode.
550 * fastboot reboot is warm boot with PON hard reset bit not set
551 * adb reboot is a cold boot with PON hard reset bit set
552 */
553 if (is_cold_boot &&
554 (!(pon_reason & HARD_RST)) &&
555 (!(pon_reason & KPDPWR_N)) &&
Chunmei Cai6eb22fe2015-08-20 15:39:06 +0800556 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG) || (pon_reason & CBLPWR_N)))
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530557 return 1;
558 else
559 return 0;
560}
561
562void target_usb_stop(void)
563{
564 /* Disable VBUS mimicing in the controller. */
565 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
566}
567
568
569void target_uninit(void)
570{
571#if PON_VIB_SUPPORT
572 /* wait for the vibrator timer is expried */
573 wait_vib_timeout();
574#endif
575
Unnati Gandhic43a2802014-09-19 17:27:25 +0530576 if (platform_boot_dev_isemmc())
577 {
578 mmc_put_card_to_sleep(dev);
579 sdhci_mode_disable(&dev->host);
580 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530581
582 if (crypto_initialized())
583 crypto_eng_cleanup();
584
585 if (target_is_ssd_enabled())
586 clock_ce_disable(CE1_INSTANCE);
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530587
Unnati Gandhi36ef2252014-11-04 18:45:14 +0530588#if SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530589 rpm_smd_uninit();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700590#endif
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530591}
592
593/* Do any target specific intialization needed before entering fastboot mode */
594void target_fastboot_init(void)
595{
596 /* Set the BOOT_DONE flag in PM8916 */
597 pm8x41_set_boot_done();
598
599 if (target_is_ssd_enabled()) {
600 clock_ce_enable(CE1_INSTANCE);
601 target_load_ssd_keystore();
602 }
603}
604
605int set_download_mode(enum dload_mode mode)
606{
607 int ret = 0;
608 ret = scm_dload_mode(mode);
609
610 pm8x41_clear_pmic_watchdog();
611
612 return ret;
613}
614
615void target_load_ssd_keystore(void)
616{
617 uint64_t ptn;
618 int index;
619 uint64_t size;
620 uint32_t *buffer = NULL;
621
622 if (!target_is_ssd_enabled())
623 return;
624
625 index = partition_get_index("ssd");
626
627 ptn = partition_get_offset(index);
628 if (ptn == 0){
629 dprintf(CRITICAL, "Error: ssd partition not found\n");
630 return;
631 }
632
633 size = partition_get_size(index);
634 if (size == 0) {
635 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
636 return;
637 }
638
639 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
640 if (!buffer) {
641 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
642 return;
643 }
644 if (mmc_read(ptn, buffer, size)) {
645 dprintf(CRITICAL, "Error: cannot read data\n");
646 free(buffer);
647 return;
648 }
649
650 clock_ce_enable(CE1_INSTANCE);
651 scm_protect_keystore(buffer, size);
652 clock_ce_disable(CE1_INSTANCE);
653 free(buffer);
654}
655
656crypto_engine_type board_ce_type(void)
657{
658 return CRYPTO_ENGINE_TYPE_HW;
659}
660
661/* Set up params for h/w CE. */
662void target_crypto_init_params()
663{
664 struct crypto_init_params ce_params;
665
666 /* Set up base addresses and instance. */
667 ce_params.crypto_instance = CE1_INSTANCE;
668 ce_params.crypto_base = MSM_CE1_BASE;
669 ce_params.bam_base = MSM_CE1_BAM_BASE;
670
671 /* Set up BAM config. */
672 ce_params.bam_ee = CE_EE;
673 ce_params.pipes.read_pipe = CE_READ_PIPE;
674 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
675 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
676 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
677
678 /* Assign buffer sizes. */
679 ce_params.num_ce = CE_ARRAY_SIZE;
680 ce_params.read_fifo_size = CE_FIFO_SIZE;
681 ce_params.write_fifo_size = CE_FIFO_SIZE;
682
683 /* BAM is initialized by TZ for this platform.
684 * Do not do it again as the initialization address space
685 * is locked.
686 */
687 ce_params.do_bam_init = 0;
688
689 crypto_init_params(&ce_params);
690}
691
692uint32_t target_get_hlos_subtype()
693{
694 return board_hlos_subtype();
695}
Channagoud Kadabi400bd112015-08-10 15:38:10 -0700696
697void pmic_reset_configure(uint8_t reset_type)
698{
699 pm8x41_reset_configure(reset_type);
700}