blob: 2bb068ed4efb159e80bb296d70be1627af19df22 [file] [log] [blame]
Unnati Gandhi4d07fac2014-07-04 17:38:25 +05301/* Copyright (c) 2014, The Linux Foundation. All rights reserved.
2 *
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
Unnati Gandhi4d07fac2014-07-04 17:38:25 +053064
Unnati Gandhif4cb6622014-08-28 13:54:56 +053065#if PON_VIB_SUPPORT
66#define VIBRATE_TIME 250
67#endif
68
69#define FASTBOOT_MODE 0x77665500
70
71#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
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);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530118
Unnati Gandhic43a2802014-09-19 17:27:25 +0530119void update_ptable_names(void)
120{
121 uint32_t ptn_index;
122 struct ptentry *ptentry_ptr = flash_ptable.parts;
123 struct ptentry *boot_ptn;
124 unsigned i;
125 uint32_t len;
126
127 /* Change all names to lower case. */
128 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
129 {
130 len = strlen(ptentry_ptr[ptn_index].name);
131
132 for (i = 0; i < len; i++)
133 {
134 if (isupper(ptentry_ptr[ptn_index].name[i]))
135 {
136 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
137 }
138 }
139
140 /* SBL fills in the last partition length as 0xFFFFFFFF.
141 * Update the length field based on the number of blocks on the flash.
142 */
143 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
144 {
145 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
146 }
147 }
148}
149
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530150void target_early_init(void)
151{
152#if WITH_DEBUG_UART
Unnati Gandhi67adfe12014-09-30 13:14:22 +0530153 uart_dm_init(1, 0, BLSP1_UART0_BASE);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530154#endif
155}
156
Unnati Gandhic43a2802014-09-19 17:27:25 +0530157int target_is_emmc_boot(void)
158{
159 return platform_boot_dev_isemmc();
160}
161
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530162void target_sdc_init()
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530163{
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530164 struct mmc_config_data config;
165
166 /* Set drive strength & pull ctrl values */
167 set_sdc_power_ctrl();
168
169 config.bus_width = DATA_BUS_WIDTH_8BIT;
170 config.max_clk_rate = MMC_CLK_177MHZ;
171
172 /* Try slot 1*/
173 config.slot = 1;
174 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
175 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
176 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
177 config.hs400_support = 0;
178
179 if (!(dev = mmc_init(&config))) {
180 /* Try slot 2 */
181 config.slot = 2;
182 config.max_clk_rate = MMC_CLK_200MHZ;
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
187 if (!(dev = mmc_init(&config))) {
188 dprintf(CRITICAL, "mmc init failed!");
189 ASSERT(0);
190 }
191 }
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530192}
193
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530194void *target_mmc_device()
195{
196 return (void *) dev;
197}
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530198
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530199/* Return 1 if vol_up pressed */
200static int target_volume_up()
201{
202 uint8_t status = 0;
203
204 gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
205
206 /* Wait for the gpio config to take effect - debounce time */
207 thread_sleep(10);
208
209 /* Get status of GPIO */
210 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
211
212 /* Active low signal. */
213 return !status;
214}
215
216/* Return 1 if vol_down pressed */
217uint32_t target_volume_down()
218{
219 /* Volume down button tied in with PMIC RESIN. */
220 return pm8x41_resin_status();
221}
222
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530223static void target_keystatus()
224{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530225 keys_init();
226
227 if(target_volume_down())
228 keys_post_event(KEY_VOLUMEDOWN, 1);
229
230 if(target_volume_up())
231 keys_post_event(KEY_VOLUMEUP, 1);
232
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530233}
234
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530235static void set_sdc_power_ctrl()
236{
237 /* Drive strength configs for sdc pins */
238 struct tlmm_cfgs sdc1_hdrv_cfg[] =
239 {
240 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
241 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
242 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK },
243 };
244
245 /* Pull configs for sdc pins */
246 struct tlmm_cfgs sdc1_pull_cfg[] =
247 {
248 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
249 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
250 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
251 };
252
253 /* Set the drive strength & pull control values */
254 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
255 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
256}
257
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530258void target_init(void)
259{
260 uint32_t base_addr;
261 uint8_t slot;
262
263 dprintf(INFO, "target_init()\n");
264
265 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
266
267 target_keystatus();
268
Unnati Gandhic43a2802014-09-19 17:27:25 +0530269 platform_read_boot_config();
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530270
Unnati Gandhic43a2802014-09-19 17:27:25 +0530271 if (platform_boot_dev_isemmc()) {
272 target_sdc_init();
273 if (partition_read_table())
274 {
275 dprintf(CRITICAL, "Error reading the partition table info\n");
276 ASSERT(0);
277 }
278
279 } else {
280 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
281 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
282 config.pipes.cmd_pipe = CMD_PIPE;
283
284 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
285 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
286 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
287
288 config.bam_base = MSM_NAND_BAM_BASE;
289 config.nand_base = MSM_NAND_BASE;
290 config.ee = QPIC_NAND_EE;
291 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
292
293 qpic_nand_init(&config);
294
295 ptable_init(&flash_ptable);
296 smem_ptable_init();
297 smem_add_modem_partitions(&flash_ptable);
298
299 update_ptable_names();
300 flash_set_ptable(&flash_ptable);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530301 }
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530302
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530303#if LONG_PRESS_POWER_ON
304 shutdown_detect();
305#endif
306
307#if PON_VIB_SUPPORT
308
309 /* turn on vibrator to indicate that phone is booting up to end user */
310 vib_timed_turn_on(VIBRATE_TIME);
311#endif
312
313 if (target_use_signed_kernel())
314 target_crypto_init_params();
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530315
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700316#if ENABLE_SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530317 rpm_smd_init();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700318#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530319}
320
321void target_serialno(unsigned char *buf)
322{
323 uint32_t serialno;
324 if (target_is_emmc_boot()) {
325 serialno = mmc_get_psn();
326 snprintf((char *)buf, 13, "%x", serialno);
327 }
328}
329
330unsigned board_machtype(void)
331{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530332 return LINUX_MACHTYPE_UNKNOWN;
333}
334
335unsigned check_reboot_mode(void)
336{
337 uint32_t restart_reason = 0;
338
339 /* Read reboot reason and scrub it */
340 restart_reason = readl(RESTART_REASON_ADDR);
341 writel(0x00, RESTART_REASON_ADDR);
342
343 return restart_reason;
344}
345
346static int scm_dload_mode(int mode)
347{
348 int ret = 0;
349 uint32_t dload_type;
350
351 dprintf(SPEW, "DLOAD mode: %d\n", mode);
352 if (mode == NORMAL_DLOAD)
353 dload_type = SCM_DLOAD_MODE;
354 else if(mode == EMERGENCY_DLOAD)
355 dload_type = SCM_EDLOAD_MODE;
356 else
357 dload_type = 0;
358
359 ret = scm_call_atomic2(SCM_SVC_BOOT, SCM_DLOAD_CMD, dload_type, 0);
360 if (ret)
361 dprintf(CRITICAL, "Failed to write to boot misc: %d\n", ret);
362
363 ret = scm_call_atomic2(SCM_SVC_BOOT, WDOG_DEBUG_DISABLE, 1, 0);
364 if (ret)
365 dprintf(CRITICAL, "Failed to disable the wdog debug \n");
366
367 return ret;
368}
369
370/* Configure PMIC and Drop PS_HOLD for shutdown */
371void shutdown_device()
372{
373 dprintf(CRITICAL, "Going down for shutdown.\n");
374
375 /* Configure PMIC for shutdown */
376 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
377
378 /* Drop PS_HOLD for MSM */
379 writel(0x00, MPM2_MPM_PS_HOLD);
380
381 mdelay(5000);
382
383}
384
385void reboot_device(unsigned reboot_reason)
386{
387 uint8_t reset_type = 0;
388 uint32_t ret = 0;
389
390 /* Need to clear the SW_RESET_ENTRY register and
391 * write to the BOOT_MISC_REG for known reset cases
392 */
393 if(reboot_reason != DLOAD)
394 scm_dload_mode(NORMAL_MODE);
395
396 writel(reboot_reason, RESTART_REASON_ADDR);
397
398 /* For Reboot-bootloader and Dload cases do a warm reset
399 * For Reboot cases do a hard reset
400 */
401 if((reboot_reason == FASTBOOT_MODE) || (reboot_reason == DLOAD))
402 reset_type = PON_PSHOLD_WARM_RESET;
403 else
404 reset_type = PON_PSHOLD_HARD_RESET;
405
406 pm8x41_reset_configure(reset_type);
407
408 ret = scm_halt_pmic_arbiter();
409
410 if (ret)
411 dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret);
412
413 /* Drop PS_HOLD for MSM */
414 writel(0x00, MPM2_MPM_PS_HOLD);
415
416 mdelay(5000);
417
418 dprintf(CRITICAL, "Rebooting failed\n");
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530419}
420
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530421/* Detect the target type */
422void target_detect(struct board_data *board)
423{
424 /*
425 * already fill the board->target on board.c
426 */
427}
428
429void target_baseband_detect(struct board_data *board)
430{
431 uint32_t platform;
432
433 platform = board->platform;
434 switch(platform)
435 {
436 case MSM8909:
437 case MSM8209:
438 case MSM8208:
439 board->baseband = BASEBAND_MSM;
440 break;
441
442 case MDM9209:
443 case MDM9309:
444 case MDM9609:
445 board->baseband = BASEBAND_MDM;
446 break;
447
448 default:
449 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
450 ASSERT(0);
451 };
452}
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530453uint8_t target_panel_auto_detect_enabled()
454{
455 uint8_t ret = 0;
456
457 switch(board_hardware_id()) {
458 default:
459 ret = 0;
460 break;
461 }
462 return ret;
463}
464
465static uint8_t splash_override;
466/* Returns 1 if target supports continuous splash screen. */
467int target_cont_splash_screen()
468{
469 uint8_t splash_screen = 0;
470 if (!splash_override) {
471 switch (board_hardware_id()) {
472 default:
473 splash_screen = 0;
474 break;
475 }
476 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
477 }
478 return splash_screen;
479}
480
481void target_force_cont_splash_disable(uint8_t override)
482{
483 splash_override = override;
484}
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530485
Unnati Gandhic43a2802014-09-19 17:27:25 +0530486int get_target_boot_params(const char *cmdline, const char *part, char *buf,
487 int buflen)
488{
489 struct ptable *ptable;
490 int system_ptn_index = -1;
491
492 if (!target_is_emmc_boot()) {
493 if (!cmdline || !part || !buf || buflen < 0) {
494 dprintf(CRITICAL, "WARN: Invalid input param\n");
495 return -1;
496 }
497
498 ptable = flash_get_ptable();
499 if (!ptable) {
500 dprintf(CRITICAL,
501 "WARN: Cannot get flash partition table\n");
502 return -1;
503 }
504
505 system_ptn_index = ptable_get_index(ptable, part);
506 if (system_ptn_index < 0) {
507 dprintf(CRITICAL,
508 "WARN: Cannot get partition index for %s\n", part);
509 return -1;
510 }
511
512 /*
513 * check if cmdline contains "root=" at the beginning of buffer or
514 * " root=" in the middle of buffer.
515 */
516 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
517 (strstr(cmdline, " root="))))
518 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
519 else
520 snprintf(buf, buflen, " root=/dev/mtdblock%d",
521 system_ptn_index);
522 }
523
524 return 0;
525}
526
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530527unsigned target_baseband()
528{
529 return board_baseband();
530}
531
532int emmc_recovery_init(void)
533{
534 return _emmc_recovery_init();
535}
536
537void target_usb_init(void)
538{
539 uint32_t val;
540
541 /* Select and enable external configuration with USB PHY */
542 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
543
544 /* Enable sess_vld */
545 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
546 writel(val, USB_GENCONFIG_2);
547
548 /* Enable external vbus configuration in the LINK */
549 val = readl(USB_USBCMD);
550 val |= SESS_VLD_CTRL;
551 writel(val, USB_USBCMD);
552}
553
554unsigned target_pause_for_battery_charge(void)
555{
556 uint8_t pon_reason = pm8x41_get_pon_reason();
557 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
558 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
559 pon_reason, is_cold_boot);
560 /* In case of fastboot reboot,adb reboot or if we see the power key
561 * pressed we do not want go into charger mode.
562 * fastboot reboot is warm boot with PON hard reset bit not set
563 * adb reboot is a cold boot with PON hard reset bit set
564 */
565 if (is_cold_boot &&
566 (!(pon_reason & HARD_RST)) &&
567 (!(pon_reason & KPDPWR_N)) &&
568 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG)))
569 return 1;
570 else
571 return 0;
572}
573
574void target_usb_stop(void)
575{
576 /* Disable VBUS mimicing in the controller. */
577 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
578}
579
580
581void target_uninit(void)
582{
583#if PON_VIB_SUPPORT
584 /* wait for the vibrator timer is expried */
585 wait_vib_timeout();
586#endif
587
Unnati Gandhic43a2802014-09-19 17:27:25 +0530588 if (platform_boot_dev_isemmc())
589 {
590 mmc_put_card_to_sleep(dev);
591 sdhci_mode_disable(&dev->host);
592 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530593
594 if (crypto_initialized())
595 crypto_eng_cleanup();
596
597 if (target_is_ssd_enabled())
598 clock_ce_disable(CE1_INSTANCE);
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530599
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700600#if ENABLE_SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530601 rpm_smd_uninit();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700602#endif
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530603}
604
605/* Do any target specific intialization needed before entering fastboot mode */
606void target_fastboot_init(void)
607{
608 /* Set the BOOT_DONE flag in PM8916 */
609 pm8x41_set_boot_done();
610
611 if (target_is_ssd_enabled()) {
612 clock_ce_enable(CE1_INSTANCE);
613 target_load_ssd_keystore();
614 }
615}
616
617int set_download_mode(enum dload_mode mode)
618{
619 int ret = 0;
620 ret = scm_dload_mode(mode);
621
622 pm8x41_clear_pmic_watchdog();
623
624 return ret;
625}
626
627void target_load_ssd_keystore(void)
628{
629 uint64_t ptn;
630 int index;
631 uint64_t size;
632 uint32_t *buffer = NULL;
633
634 if (!target_is_ssd_enabled())
635 return;
636
637 index = partition_get_index("ssd");
638
639 ptn = partition_get_offset(index);
640 if (ptn == 0){
641 dprintf(CRITICAL, "Error: ssd partition not found\n");
642 return;
643 }
644
645 size = partition_get_size(index);
646 if (size == 0) {
647 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
648 return;
649 }
650
651 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
652 if (!buffer) {
653 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
654 return;
655 }
656 if (mmc_read(ptn, buffer, size)) {
657 dprintf(CRITICAL, "Error: cannot read data\n");
658 free(buffer);
659 return;
660 }
661
662 clock_ce_enable(CE1_INSTANCE);
663 scm_protect_keystore(buffer, size);
664 clock_ce_disable(CE1_INSTANCE);
665 free(buffer);
666}
667
668crypto_engine_type board_ce_type(void)
669{
670 return CRYPTO_ENGINE_TYPE_HW;
671}
672
673/* Set up params for h/w CE. */
674void target_crypto_init_params()
675{
676 struct crypto_init_params ce_params;
677
678 /* Set up base addresses and instance. */
679 ce_params.crypto_instance = CE1_INSTANCE;
680 ce_params.crypto_base = MSM_CE1_BASE;
681 ce_params.bam_base = MSM_CE1_BAM_BASE;
682
683 /* Set up BAM config. */
684 ce_params.bam_ee = CE_EE;
685 ce_params.pipes.read_pipe = CE_READ_PIPE;
686 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
687 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
688 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
689
690 /* Assign buffer sizes. */
691 ce_params.num_ce = CE_ARRAY_SIZE;
692 ce_params.read_fifo_size = CE_FIFO_SIZE;
693 ce_params.write_fifo_size = CE_FIFO_SIZE;
694
695 /* BAM is initialized by TZ for this platform.
696 * Do not do it again as the initialization address space
697 * is locked.
698 */
699 ce_params.do_bam_init = 0;
700
701 crypto_init_params(&ce_params);
702}
703
704uint32_t target_get_hlos_subtype()
705{
706 return board_hlos_subtype();
707}