blob: 4cfe8982071f09e22cd52a2f9a66929d9387084a [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
153 uart_dm_init(1, 0, BLSP1_UART1_BASE);
154#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
316 rpm_smd_init();
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530317}
318
319void target_serialno(unsigned char *buf)
320{
321 uint32_t serialno;
322 if (target_is_emmc_boot()) {
323 serialno = mmc_get_psn();
324 snprintf((char *)buf, 13, "%x", serialno);
325 }
326}
327
328unsigned board_machtype(void)
329{
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530330 return LINUX_MACHTYPE_UNKNOWN;
331}
332
333unsigned check_reboot_mode(void)
334{
335 uint32_t restart_reason = 0;
336
337 /* Read reboot reason and scrub it */
338 restart_reason = readl(RESTART_REASON_ADDR);
339 writel(0x00, RESTART_REASON_ADDR);
340
341 return restart_reason;
342}
343
344static int scm_dload_mode(int mode)
345{
346 int ret = 0;
347 uint32_t dload_type;
348
349 dprintf(SPEW, "DLOAD mode: %d\n", mode);
350 if (mode == NORMAL_DLOAD)
351 dload_type = SCM_DLOAD_MODE;
352 else if(mode == EMERGENCY_DLOAD)
353 dload_type = SCM_EDLOAD_MODE;
354 else
355 dload_type = 0;
356
357 ret = scm_call_atomic2(SCM_SVC_BOOT, SCM_DLOAD_CMD, dload_type, 0);
358 if (ret)
359 dprintf(CRITICAL, "Failed to write to boot misc: %d\n", ret);
360
361 ret = scm_call_atomic2(SCM_SVC_BOOT, WDOG_DEBUG_DISABLE, 1, 0);
362 if (ret)
363 dprintf(CRITICAL, "Failed to disable the wdog debug \n");
364
365 return ret;
366}
367
368/* Configure PMIC and Drop PS_HOLD for shutdown */
369void shutdown_device()
370{
371 dprintf(CRITICAL, "Going down for shutdown.\n");
372
373 /* Configure PMIC for shutdown */
374 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
375
376 /* Drop PS_HOLD for MSM */
377 writel(0x00, MPM2_MPM_PS_HOLD);
378
379 mdelay(5000);
380
381}
382
383void reboot_device(unsigned reboot_reason)
384{
385 uint8_t reset_type = 0;
386 uint32_t ret = 0;
387
388 /* Need to clear the SW_RESET_ENTRY register and
389 * write to the BOOT_MISC_REG for known reset cases
390 */
391 if(reboot_reason != DLOAD)
392 scm_dload_mode(NORMAL_MODE);
393
394 writel(reboot_reason, RESTART_REASON_ADDR);
395
396 /* For Reboot-bootloader and Dload cases do a warm reset
397 * For Reboot cases do a hard reset
398 */
399 if((reboot_reason == FASTBOOT_MODE) || (reboot_reason == DLOAD))
400 reset_type = PON_PSHOLD_WARM_RESET;
401 else
402 reset_type = PON_PSHOLD_HARD_RESET;
403
404 pm8x41_reset_configure(reset_type);
405
406 ret = scm_halt_pmic_arbiter();
407
408 if (ret)
409 dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret);
410
411 /* Drop PS_HOLD for MSM */
412 writel(0x00, MPM2_MPM_PS_HOLD);
413
414 mdelay(5000);
415
416 dprintf(CRITICAL, "Rebooting failed\n");
Unnati Gandhi4d07fac2014-07-04 17:38:25 +0530417}
418
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530419/* Detect the target type */
420void target_detect(struct board_data *board)
421{
422 /*
423 * already fill the board->target on board.c
424 */
425}
426
427void target_baseband_detect(struct board_data *board)
428{
429 uint32_t platform;
430
431 platform = board->platform;
432 switch(platform)
433 {
434 case MSM8909:
435 case MSM8209:
436 case MSM8208:
437 board->baseband = BASEBAND_MSM;
438 break;
439
440 case MDM9209:
441 case MDM9309:
442 case MDM9609:
443 board->baseband = BASEBAND_MDM;
444 break;
445
446 default:
447 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
448 ASSERT(0);
449 };
450}
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530451uint8_t target_panel_auto_detect_enabled()
452{
453 uint8_t ret = 0;
454
455 switch(board_hardware_id()) {
456 default:
457 ret = 0;
458 break;
459 }
460 return ret;
461}
462
463static uint8_t splash_override;
464/* Returns 1 if target supports continuous splash screen. */
465int target_cont_splash_screen()
466{
467 uint8_t splash_screen = 0;
468 if (!splash_override) {
469 switch (board_hardware_id()) {
470 default:
471 splash_screen = 0;
472 break;
473 }
474 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
475 }
476 return splash_screen;
477}
478
479void target_force_cont_splash_disable(uint8_t override)
480{
481 splash_override = override;
482}
Unnati Gandhia556a4d2014-08-12 10:42:21 +0530483
Unnati Gandhic43a2802014-09-19 17:27:25 +0530484int get_target_boot_params(const char *cmdline, const char *part, char *buf,
485 int buflen)
486{
487 struct ptable *ptable;
488 int system_ptn_index = -1;
489
490 if (!target_is_emmc_boot()) {
491 if (!cmdline || !part || !buf || buflen < 0) {
492 dprintf(CRITICAL, "WARN: Invalid input param\n");
493 return -1;
494 }
495
496 ptable = flash_get_ptable();
497 if (!ptable) {
498 dprintf(CRITICAL,
499 "WARN: Cannot get flash partition table\n");
500 return -1;
501 }
502
503 system_ptn_index = ptable_get_index(ptable, part);
504 if (system_ptn_index < 0) {
505 dprintf(CRITICAL,
506 "WARN: Cannot get partition index for %s\n", part);
507 return -1;
508 }
509
510 /*
511 * check if cmdline contains "root=" at the beginning of buffer or
512 * " root=" in the middle of buffer.
513 */
514 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
515 (strstr(cmdline, " root="))))
516 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
517 else
518 snprintf(buf, buflen, " root=/dev/mtdblock%d",
519 system_ptn_index);
520 }
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)) &&
566 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG)))
567 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
598 rpm_smd_uninit();
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530599}
600
601/* Do any target specific intialization needed before entering fastboot mode */
602void target_fastboot_init(void)
603{
604 /* Set the BOOT_DONE flag in PM8916 */
605 pm8x41_set_boot_done();
606
607 if (target_is_ssd_enabled()) {
608 clock_ce_enable(CE1_INSTANCE);
609 target_load_ssd_keystore();
610 }
611}
612
613int set_download_mode(enum dload_mode mode)
614{
615 int ret = 0;
616 ret = scm_dload_mode(mode);
617
618 pm8x41_clear_pmic_watchdog();
619
620 return ret;
621}
622
623void target_load_ssd_keystore(void)
624{
625 uint64_t ptn;
626 int index;
627 uint64_t size;
628 uint32_t *buffer = NULL;
629
630 if (!target_is_ssd_enabled())
631 return;
632
633 index = partition_get_index("ssd");
634
635 ptn = partition_get_offset(index);
636 if (ptn == 0){
637 dprintf(CRITICAL, "Error: ssd partition not found\n");
638 return;
639 }
640
641 size = partition_get_size(index);
642 if (size == 0) {
643 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
644 return;
645 }
646
647 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
648 if (!buffer) {
649 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
650 return;
651 }
652 if (mmc_read(ptn, buffer, size)) {
653 dprintf(CRITICAL, "Error: cannot read data\n");
654 free(buffer);
655 return;
656 }
657
658 clock_ce_enable(CE1_INSTANCE);
659 scm_protect_keystore(buffer, size);
660 clock_ce_disable(CE1_INSTANCE);
661 free(buffer);
662}
663
664crypto_engine_type board_ce_type(void)
665{
666 return CRYPTO_ENGINE_TYPE_HW;
667}
668
669/* Set up params for h/w CE. */
670void target_crypto_init_params()
671{
672 struct crypto_init_params ce_params;
673
674 /* Set up base addresses and instance. */
675 ce_params.crypto_instance = CE1_INSTANCE;
676 ce_params.crypto_base = MSM_CE1_BASE;
677 ce_params.bam_base = MSM_CE1_BAM_BASE;
678
679 /* Set up BAM config. */
680 ce_params.bam_ee = CE_EE;
681 ce_params.pipes.read_pipe = CE_READ_PIPE;
682 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
683 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
684 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
685
686 /* Assign buffer sizes. */
687 ce_params.num_ce = CE_ARRAY_SIZE;
688 ce_params.read_fifo_size = CE_FIFO_SIZE;
689 ce_params.write_fifo_size = CE_FIFO_SIZE;
690
691 /* BAM is initialized by TZ for this platform.
692 * Do not do it again as the initialization address space
693 * is locked.
694 */
695 ce_params.do_bam_init = 0;
696
697 crypto_init_params(&ce_params);
698}
699
700uint32_t target_get_hlos_subtype()
701{
702 return board_hlos_subtype();
703}