blob: a6f3001f95296f24c6919ca17fe2b0666d92de79 [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 Gandhi8e4711b2014-10-13 05:03:00 +0530269#if ENABLE_BOOT_CONFIG_SUPPORT
Unnati Gandhic43a2802014-09-19 17:27:25 +0530270 platform_read_boot_config();
Unnati Gandhi8e4711b2014-10-13 05:03:00 +0530271#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530272
Unnati Gandhic43a2802014-09-19 17:27:25 +0530273 if (platform_boot_dev_isemmc()) {
274 target_sdc_init();
275 if (partition_read_table())
276 {
277 dprintf(CRITICAL, "Error reading the partition table info\n");
278 ASSERT(0);
279 }
280
281 } else {
282 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
283 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
284 config.pipes.cmd_pipe = CMD_PIPE;
285
286 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
287 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
288 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
289
290 config.bam_base = MSM_NAND_BAM_BASE;
291 config.nand_base = MSM_NAND_BASE;
292 config.ee = QPIC_NAND_EE;
293 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
294
295 qpic_nand_init(&config);
296
297 ptable_init(&flash_ptable);
298 smem_ptable_init();
299 smem_add_modem_partitions(&flash_ptable);
300
301 update_ptable_names();
302 flash_set_ptable(&flash_ptable);
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530303 }
Unnati Gandhi4d637e42014-07-11 14:47:25 +0530304
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530305#if LONG_PRESS_POWER_ON
306 shutdown_detect();
307#endif
308
309#if PON_VIB_SUPPORT
310
311 /* turn on vibrator to indicate that phone is booting up to end user */
312 vib_timed_turn_on(VIBRATE_TIME);
313#endif
314
315 if (target_use_signed_kernel())
316 target_crypto_init_params();
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530317
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700318#if ENABLE_SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530319 rpm_smd_init();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700320#endif
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530321}
322
323void target_serialno(unsigned char *buf)
324{
325 uint32_t serialno;
326 if (target_is_emmc_boot()) {
327 serialno = mmc_get_psn();
328 snprintf((char *)buf, 13, "%x", serialno);
329 }
330}
331
332unsigned board_machtype(void)
333{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530334 return LINUX_MACHTYPE_UNKNOWN;
335}
336
337unsigned check_reboot_mode(void)
338{
339 uint32_t restart_reason = 0;
340
341 /* Read reboot reason and scrub it */
342 restart_reason = readl(RESTART_REASON_ADDR);
343 writel(0x00, RESTART_REASON_ADDR);
344
345 return restart_reason;
346}
347
348static int scm_dload_mode(int mode)
349{
350 int ret = 0;
351 uint32_t dload_type;
352
353 dprintf(SPEW, "DLOAD mode: %d\n", mode);
354 if (mode == NORMAL_DLOAD)
355 dload_type = SCM_DLOAD_MODE;
356 else if(mode == EMERGENCY_DLOAD)
357 dload_type = SCM_EDLOAD_MODE;
358 else
359 dload_type = 0;
360
361 ret = scm_call_atomic2(SCM_SVC_BOOT, SCM_DLOAD_CMD, dload_type, 0);
362 if (ret)
363 dprintf(CRITICAL, "Failed to write to boot misc: %d\n", ret);
364
365 ret = scm_call_atomic2(SCM_SVC_BOOT, WDOG_DEBUG_DISABLE, 1, 0);
366 if (ret)
367 dprintf(CRITICAL, "Failed to disable the wdog debug \n");
368
369 return ret;
370}
371
372/* Configure PMIC and Drop PS_HOLD for shutdown */
373void shutdown_device()
374{
375 dprintf(CRITICAL, "Going down for shutdown.\n");
376
377 /* Configure PMIC for shutdown */
378 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
379
380 /* Drop PS_HOLD for MSM */
381 writel(0x00, MPM2_MPM_PS_HOLD);
382
383 mdelay(5000);
384
385}
386
387void reboot_device(unsigned reboot_reason)
388{
389 uint8_t reset_type = 0;
390 uint32_t ret = 0;
391
392 /* Need to clear the SW_RESET_ENTRY register and
393 * write to the BOOT_MISC_REG for known reset cases
394 */
395 if(reboot_reason != DLOAD)
396 scm_dload_mode(NORMAL_MODE);
397
398 writel(reboot_reason, RESTART_REASON_ADDR);
399
400 /* For Reboot-bootloader and Dload cases do a warm reset
401 * For Reboot cases do a hard reset
402 */
403 if((reboot_reason == FASTBOOT_MODE) || (reboot_reason == DLOAD))
404 reset_type = PON_PSHOLD_WARM_RESET;
405 else
406 reset_type = PON_PSHOLD_HARD_RESET;
407
408 pm8x41_reset_configure(reset_type);
409
410 ret = scm_halt_pmic_arbiter();
411
412 if (ret)
413 dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret);
414
415 /* Drop PS_HOLD for MSM */
416 writel(0x00, MPM2_MPM_PS_HOLD);
417
418 mdelay(5000);
419
420 dprintf(CRITICAL, "Rebooting failed\n");
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530421}
422
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530423/* Detect the target type */
424void target_detect(struct board_data *board)
425{
426 /*
427 * already fill the board->target on board.c
428 */
429}
430
431void target_baseband_detect(struct board_data *board)
432{
433 uint32_t platform;
434
435 platform = board->platform;
436 switch(platform)
437 {
438 case MSM8909:
439 case MSM8209:
440 case MSM8208:
441 board->baseband = BASEBAND_MSM;
442 break;
443
444 case MDM9209:
445 case MDM9309:
446 case MDM9609:
447 board->baseband = BASEBAND_MDM;
448 break;
449
450 default:
451 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
452 ASSERT(0);
453 };
454}
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530455uint8_t target_panel_auto_detect_enabled()
456{
457 uint8_t ret = 0;
458
459 switch(board_hardware_id()) {
460 default:
461 ret = 0;
462 break;
463 }
464 return ret;
465}
466
467static uint8_t splash_override;
468/* Returns 1 if target supports continuous splash screen. */
469int target_cont_splash_screen()
470{
471 uint8_t splash_screen = 0;
472 if (!splash_override) {
473 switch (board_hardware_id()) {
474 default:
475 splash_screen = 0;
476 break;
477 }
478 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
479 }
480 return splash_screen;
481}
482
483void target_force_cont_splash_disable(uint8_t override)
484{
485 splash_override = override;
486}
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530487
Unnati Gandhic43a2802014-09-19 17:27:25 +0530488int get_target_boot_params(const char *cmdline, const char *part, char *buf,
489 int buflen)
490{
491 struct ptable *ptable;
492 int system_ptn_index = -1;
493
494 if (!target_is_emmc_boot()) {
495 if (!cmdline || !part || !buf || buflen < 0) {
496 dprintf(CRITICAL, "WARN: Invalid input param\n");
497 return -1;
498 }
499
500 ptable = flash_get_ptable();
501 if (!ptable) {
502 dprintf(CRITICAL,
503 "WARN: Cannot get flash partition table\n");
504 return -1;
505 }
506
507 system_ptn_index = ptable_get_index(ptable, part);
508 if (system_ptn_index < 0) {
509 dprintf(CRITICAL,
510 "WARN: Cannot get partition index for %s\n", part);
511 return -1;
512 }
513
514 /*
515 * check if cmdline contains "root=" at the beginning of buffer or
516 * " root=" in the middle of buffer.
517 */
518 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
519 (strstr(cmdline, " root="))))
520 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
521 else
522 snprintf(buf, buflen, " root=/dev/mtdblock%d",
523 system_ptn_index);
524 }
525
526 return 0;
527}
528
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530529unsigned target_baseband()
530{
531 return board_baseband();
532}
533
534int emmc_recovery_init(void)
535{
536 return _emmc_recovery_init();
537}
538
539void target_usb_init(void)
540{
541 uint32_t val;
542
543 /* Select and enable external configuration with USB PHY */
544 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
545
546 /* Enable sess_vld */
547 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
548 writel(val, USB_GENCONFIG_2);
549
550 /* Enable external vbus configuration in the LINK */
551 val = readl(USB_USBCMD);
552 val |= SESS_VLD_CTRL;
553 writel(val, USB_USBCMD);
554}
555
556unsigned target_pause_for_battery_charge(void)
557{
558 uint8_t pon_reason = pm8x41_get_pon_reason();
559 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
560 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
561 pon_reason, is_cold_boot);
562 /* In case of fastboot reboot,adb reboot or if we see the power key
563 * pressed we do not want go into charger mode.
564 * fastboot reboot is warm boot with PON hard reset bit not set
565 * adb reboot is a cold boot with PON hard reset bit set
566 */
567 if (is_cold_boot &&
568 (!(pon_reason & HARD_RST)) &&
569 (!(pon_reason & KPDPWR_N)) &&
570 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG)))
571 return 1;
572 else
573 return 0;
574}
575
576void target_usb_stop(void)
577{
578 /* Disable VBUS mimicing in the controller. */
579 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
580}
581
582
583void target_uninit(void)
584{
585#if PON_VIB_SUPPORT
586 /* wait for the vibrator timer is expried */
587 wait_vib_timeout();
588#endif
589
Unnati Gandhic43a2802014-09-19 17:27:25 +0530590 if (platform_boot_dev_isemmc())
591 {
592 mmc_put_card_to_sleep(dev);
593 sdhci_mode_disable(&dev->host);
594 }
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530595
596 if (crypto_initialized())
597 crypto_eng_cleanup();
598
599 if (target_is_ssd_enabled())
600 clock_ce_disable(CE1_INSTANCE);
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530601
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700602#if ENABLE_SMD_SUPPORT
Unnati Gandhic24a86f2014-09-19 16:07:16 +0530603 rpm_smd_uninit();
Aparna Mallavarapu96fe9d92014-10-19 12:48:01 -0700604#endif
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530605}
606
607/* Do any target specific intialization needed before entering fastboot mode */
608void target_fastboot_init(void)
609{
610 /* Set the BOOT_DONE flag in PM8916 */
611 pm8x41_set_boot_done();
612
613 if (target_is_ssd_enabled()) {
614 clock_ce_enable(CE1_INSTANCE);
615 target_load_ssd_keystore();
616 }
617}
618
619int set_download_mode(enum dload_mode mode)
620{
621 int ret = 0;
622 ret = scm_dload_mode(mode);
623
624 pm8x41_clear_pmic_watchdog();
625
626 return ret;
627}
628
629void target_load_ssd_keystore(void)
630{
631 uint64_t ptn;
632 int index;
633 uint64_t size;
634 uint32_t *buffer = NULL;
635
636 if (!target_is_ssd_enabled())
637 return;
638
639 index = partition_get_index("ssd");
640
641 ptn = partition_get_offset(index);
642 if (ptn == 0){
643 dprintf(CRITICAL, "Error: ssd partition not found\n");
644 return;
645 }
646
647 size = partition_get_size(index);
648 if (size == 0) {
649 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
650 return;
651 }
652
653 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
654 if (!buffer) {
655 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
656 return;
657 }
658 if (mmc_read(ptn, buffer, size)) {
659 dprintf(CRITICAL, "Error: cannot read data\n");
660 free(buffer);
661 return;
662 }
663
664 clock_ce_enable(CE1_INSTANCE);
665 scm_protect_keystore(buffer, size);
666 clock_ce_disable(CE1_INSTANCE);
667 free(buffer);
668}
669
670crypto_engine_type board_ce_type(void)
671{
672 return CRYPTO_ENGINE_TYPE_HW;
673}
674
675/* Set up params for h/w CE. */
676void target_crypto_init_params()
677{
678 struct crypto_init_params ce_params;
679
680 /* Set up base addresses and instance. */
681 ce_params.crypto_instance = CE1_INSTANCE;
682 ce_params.crypto_base = MSM_CE1_BASE;
683 ce_params.bam_base = MSM_CE1_BAM_BASE;
684
685 /* Set up BAM config. */
686 ce_params.bam_ee = CE_EE;
687 ce_params.pipes.read_pipe = CE_READ_PIPE;
688 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
689 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
690 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
691
692 /* Assign buffer sizes. */
693 ce_params.num_ce = CE_ARRAY_SIZE;
694 ce_params.read_fifo_size = CE_FIFO_SIZE;
695 ce_params.write_fifo_size = CE_FIFO_SIZE;
696
697 /* BAM is initialized by TZ for this platform.
698 * Do not do it again as the initialization address space
699 * is locked.
700 */
701 ce_params.do_bam_init = 0;
702
703 crypto_init_params(&ce_params);
704}
705
706uint32_t target_get_hlos_subtype()
707{
708 return board_hlos_subtype();
709}