blob: 484a10c5cb576ee2f0d98afd700334c0e442f329 [file] [log] [blame]
Aparna Mallavarapuca676882015-01-19 20:39:06 +05301/* Copyright (c) 2015, 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>
36#include <platform/gpio.h>
37#include <dev/keys.h>
38#include <spmi_v2.h>
39#include <pm8x41.h>
Aparna Mallavarapubc6315e2015-04-11 04:00:43 +053040#include <pm8x41_hw.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053041#include <board.h>
42#include <baseband.h>
43#include <hsusb.h>
44#include <scm.h>
45#include <platform/gpio.h>
46#include <platform/gpio.h>
47#include <platform/irqs.h>
48#include <platform/clock.h>
Aparna Mallavarapubc6315e2015-04-11 04:00:43 +053049#include <platform/timer.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053050#include <crypto5_wrapper.h>
51#include <partition_parser.h>
52#include <stdlib.h>
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +053053#include <rpm-smd.h>
Aparna Mallavarapubc6315e2015-04-11 04:00:43 +053054#include <spmi.h>
55#include <sdhci_msm.h>
56#include <clock.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053057
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -070058#include "target/display.h"
59
Aparna Mallavarapuca676882015-01-19 20:39:06 +053060#if LONG_PRESS_POWER_ON
61#include <shutdown_detect.h>
62#endif
63
Matthew Qin47dfdb72015-06-10 21:29:11 +080064#if PON_VIB_SUPPORT
65#include <vibrator.h>
66#endif
67
68#if PON_VIB_SUPPORT
69#define VIBRATE_TIME 250
70#endif
71
Aparna Mallavarapuca676882015-01-19 20:39:06 +053072#define PMIC_ARB_CHANNEL_NUM 0
73#define PMIC_ARB_OWNER_ID 0
74#define TLMM_VOL_UP_BTN_GPIO 85
Unnati Gandhife004a92015-06-01 13:06:06 +053075#define TLMM_VOL_UP_BTN_GPIO_8956 113
Aparna Mallavarapuca676882015-01-19 20:39:06 +053076
77#define FASTBOOT_MODE 0x77665500
Aparna Mallavarapu680a1332015-04-29 19:14:09 +053078#define RECOVERY_MODE 0x77665502
Aparna Mallavarapuca676882015-01-19 20:39:06 +053079#define PON_SOFT_RB_SPARE 0x88F
80
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +053081#define CE1_INSTANCE 1
82#define CE_EE 1
83#define CE_FIFO_SIZE 64
84#define CE_READ_PIPE 3
85#define CE_WRITE_PIPE 2
86#define CE_READ_PIPE_LOCK_GRP 0
87#define CE_WRITE_PIPE_LOCK_GRP 0
88#define CE_ARRAY_SIZE 20
89
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053090struct mmc_device *dev;
91
92static uint32_t mmc_pwrctl_base[] =
Aparna Mallavarapuca676882015-01-19 20:39:06 +053093 { MSM_SDC1_BASE, MSM_SDC2_BASE };
94
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053095static uint32_t mmc_sdhci_base[] =
96 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
97
98static uint32_t mmc_sdc_pwrctl_irq[] =
99 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530100
101void target_early_init(void)
102{
103#if WITH_DEBUG_UART
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530104 uart_dm_init(2, 0, BLSP1_UART1_BASE);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530105#endif
106}
107
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530108static void set_sdc_power_ctrl()
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530109{
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530110 /* Drive strength configs for sdc pins */
111 struct tlmm_cfgs sdc1_hdrv_cfg[] =
112 {
113 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, 0},
114 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, 0},
115 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK , 0},
116 };
117
118 /* Pull configs for sdc pins */
119 struct tlmm_cfgs sdc1_pull_cfg[] =
120 {
121 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, 0},
122 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0},
123 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0},
124 };
125
Aparna Mallavarapu29138912015-04-13 23:45:35 +0530126 struct tlmm_cfgs sdc1_rclk_cfg[] =
127 {
128 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, 0},
129 };
130
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530131 /* Set the drive strength & pull control values */
132 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
133 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
Aparna Mallavarapu29138912015-04-13 23:45:35 +0530134 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530135}
136
137void target_sdc_init()
138{
139 struct mmc_config_data config;
140
141 /* Set drive strength & pull ctrl values */
142 set_sdc_power_ctrl();
143
144 /* Try slot 1*/
145 config.slot = 1;
146 config.bus_width = DATA_BUS_WIDTH_8BIT;
Aparna Mallavarapu680a1332015-04-29 19:14:09 +0530147 config.max_clk_rate = MMC_CLK_192MHZ;
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530148 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
149 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
150 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
151 config.hs400_support = 1;
152
153 if (!(dev = mmc_init(&config))) {
154 /* Try slot 2 */
155 config.slot = 2;
156 config.max_clk_rate = MMC_CLK_200MHZ;
157 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
158 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
159 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
160 config.hs400_support = 0;
161
162 if (!(dev = mmc_init(&config))) {
163 dprintf(CRITICAL, "mmc init failed!");
164 ASSERT(0);
165 }
166 }
167}
168
169void *target_mmc_device()
170{
171 return (void *) dev;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530172}
173
174/* Return 1 if vol_up pressed */
Rami Butsteine51318a2015-05-27 16:23:17 +0300175int target_volume_up()
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530176{
177 uint8_t status = 0;
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530178 uint32_t vol_up_gpio;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530179
Unnati Gandhife004a92015-06-01 13:06:06 +0530180 if(platform_is_msm8956())
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530181 vol_up_gpio = TLMM_VOL_UP_BTN_GPIO_8956;
182
Unnati Gandhife004a92015-06-01 13:06:06 +0530183 else
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530184 vol_up_gpio = TLMM_VOL_UP_BTN_GPIO;
185
186 gpio_tlmm_config(vol_up_gpio, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530187
188 /* Wait for the gpio config to take effect - debounce time */
189 thread_sleep(10);
190
191 /* Get status of GPIO */
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530192 status = gpio_status(vol_up_gpio);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530193
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530194 /* Active low signal. */
Aparna Mallavarapudb938b62015-04-09 01:00:55 +0530195 return !status;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530196}
197
198/* Return 1 if vol_down pressed */
199uint32_t target_volume_down()
200{
201 /* Volume down button tied in with PMIC RESIN. */
202 return pm8x41_resin_status();
203}
204
205static void target_keystatus()
206{
207 keys_init();
208
209 if(target_volume_down())
210 keys_post_event(KEY_VOLUMEDOWN, 1);
211
212 if(target_volume_up())
213 keys_post_event(KEY_VOLUMEUP, 1);
214}
215
216/* Configure PMIC and Drop PS_HOLD for shutdown */
217void shutdown_device()
218{
219 dprintf(CRITICAL, "Going down for shutdown.\n");
220
221 /* Configure PMIC for shutdown */
222 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
223
224 /* Drop PS_HOLD for MSM */
225 writel(0x00, MPM2_MPM_PS_HOLD);
226
227 mdelay(5000);
228
229 dprintf(CRITICAL, "shutdown failed\n");
230
231 ASSERT(0);
232}
233
234
235void target_init(void)
236{
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530237 dprintf(INFO, "target_init()\n");
238
239 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
240
241 target_keystatus();
242
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530243 target_sdc_init();
244 if (partition_read_table())
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530245 {
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530246 dprintf(CRITICAL, "Error reading the partition table info\n");
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530247 ASSERT(0);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530248 }
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530249
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530250#if LONG_PRESS_POWER_ON
251 shutdown_detect();
252#endif
Matthew Qin47dfdb72015-06-10 21:29:11 +0800253
254#if PON_VIB_SUPPORT
255 /* turn on vibrator to indicate that phone is booting up to end user */
256 vib_timed_turn_on(VIBRATE_TIME);
257#endif
258
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530259 if (target_use_signed_kernel())
260 target_crypto_init_params();
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530261
262#if SMD_SUPPORT
263 rpm_smd_init();
264#endif
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530265}
266
267void target_serialno(unsigned char *buf)
268{
269 uint32_t serialno;
270 if (target_is_emmc_boot()) {
271 serialno = mmc_get_psn();
272 snprintf((char *)buf, 13, "%x", serialno);
273 }
274}
275
276unsigned board_machtype(void)
277{
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530278 return LINUX_MACHTYPE_UNKNOWN;
279}
280
281/* Detect the target type */
282void target_detect(struct board_data *board)
283{
284 /* This is already filled as part of board.c */
285}
286
287/* Detect the modem type */
288void target_baseband_detect(struct board_data *board)
289{
290 uint32_t platform;
291
292 platform = board->platform;
293
294 switch(platform) {
295 case MSM8952:
296 case MSM8956:
297 case MSM8976:
298 board->baseband = BASEBAND_MSM;
299 break;
Aparna Mallavarapu815b3242015-04-29 11:08:14 +0530300 case APQ8052:
301 case APQ8056:
302 case APQ8076:
303 board->baseband = BASEBAND_APQ;
304 break;
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530305 default:
306 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
307 ASSERT(0);
308 };
309}
310
311unsigned target_baseband()
312{
313 return board_baseband();
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530314}
315
316unsigned check_reboot_mode(void)
317{
318 uint32_t restart_reason = 0;
319
320 /* Read reboot reason and scrub it */
321 restart_reason = readl(RESTART_REASON_ADDR);
322 writel(0x00, RESTART_REASON_ADDR);
323
324 return restart_reason;
325}
326
327unsigned check_hard_reboot_mode(void)
328{
329 uint8_t hard_restart_reason = 0;
330 uint8_t value = 0;
331
332 /* Read reboot reason and scrub it
333 * Bit-5, bit-6 and bit-7 of SOFT_RB_SPARE for hard reset reason
334 */
335 value = pm8x41_reg_read(PON_SOFT_RB_SPARE);
336 hard_restart_reason = value >> 5;
337 pm8x41_reg_write(PON_SOFT_RB_SPARE, value & 0x1f);
338
339 return hard_restart_reason;
340}
341
342int set_download_mode(enum dload_mode mode)
343{
344 int ret = 0;
345 ret = scm_dload_mode(mode);
346
347 pm8x41_clear_pmic_watchdog();
348
349 return ret;
350}
351
352int emmc_recovery_init(void)
353{
354 return _emmc_recovery_init();
355}
356
357void reboot_device(unsigned reboot_reason)
358{
359 uint8_t reset_type = 0;
360 uint32_t ret = 0;
361
362 /* Need to clear the SW_RESET_ENTRY register and
363 * write to the BOOT_MISC_REG for known reset cases
364 */
365 if(reboot_reason != DLOAD)
366 scm_dload_mode(NORMAL_MODE);
367
368 writel(reboot_reason, RESTART_REASON_ADDR);
369
370 /* For Reboot-bootloader and Dload cases do a warm reset
371 * For Reboot cases do a hard reset
372 */
Aparna Mallavarapu680a1332015-04-29 19:14:09 +0530373 if((reboot_reason == FASTBOOT_MODE) || (reboot_reason == DLOAD) || (reboot_reason == RECOVERY_MODE))
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530374 reset_type = PON_PSHOLD_WARM_RESET;
375 else
376 reset_type = PON_PSHOLD_HARD_RESET;
377
378 pm8x41_reset_configure(reset_type);
379
380 ret = scm_halt_pmic_arbiter();
381 if (ret)
382 dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret);
383
384 /* Drop PS_HOLD for MSM */
385 writel(0x00, MPM2_MPM_PS_HOLD);
386
387 mdelay(5000);
388
389 dprintf(CRITICAL, "Rebooting failed\n");
390}
391
392#if USER_FORCE_RESET_SUPPORT
393/* Return 1 if it is a force resin triggered by user. */
394uint32_t is_user_force_reset(void)
395{
396 uint8_t poff_reason1 = pm8x41_get_pon_poff_reason1();
397 uint8_t poff_reason2 = pm8x41_get_pon_poff_reason2();
398
399 dprintf(SPEW, "poff_reason1: %d\n", poff_reason1);
400 dprintf(SPEW, "poff_reason2: %d\n", poff_reason2);
401 if (pm8x41_get_is_cold_boot() && (poff_reason1 == KPDPWR_AND_RESIN ||
402 poff_reason2 == STAGE3))
403 return 1;
404 else
405 return 0;
406}
407#endif
408
Zhenhua Huangb46b9b52015-04-21 19:53:09 +0800409#define SMBCHG_USB_RT_STS 0x21310
410#define USBIN_UV_RT_STS BIT(0)
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530411unsigned target_pause_for_battery_charge(void)
412{
413 uint8_t pon_reason = pm8x41_get_pon_reason();
414 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
Zhenhua Huangb46b9b52015-04-21 19:53:09 +0800415 bool usb_present_sts = !(USBIN_UV_RT_STS &
416 pm8x41_reg_read(SMBCHG_USB_RT_STS));
417 dprintf(INFO, "%s : pon_reason is:0x%x cold_boot:%d usb_sts:%d\n", __func__,
418 pon_reason, is_cold_boot, usb_present_sts);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530419 /* In case of fastboot reboot,adb reboot or if we see the power key
420 * pressed we do not want go into charger mode.
421 * fastboot reboot is warm boot with PON hard reset bit not set
422 * adb reboot is a cold boot with PON hard reset bit set
423 */
424 if (is_cold_boot &&
425 (!(pon_reason & HARD_RST)) &&
426 (!(pon_reason & KPDPWR_N)) &&
Zhenhua Huangb46b9b52015-04-21 19:53:09 +0800427 usb_present_sts)
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530428 return 1;
429 else
430 return 0;
431}
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530432
433void target_uninit(void)
434{
435 mmc_put_card_to_sleep(dev);
436 sdhci_mode_disable(&dev->host);
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530437 if (crypto_initialized())
438 crypto_eng_cleanup();
439
440 if (target_is_ssd_enabled())
441 clock_ce_disable(CE1_INSTANCE);
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530442
443#if SMD_SUPPORT
444 rpm_smd_uninit();
445#endif
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530446}
447
448void target_usb_init(void)
449{
450 uint32_t val;
451
452 /* Select and enable external configuration with USB PHY */
453 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
454
455 /* Enable sess_vld */
456 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
457 writel(val, USB_GENCONFIG_2);
458
459 /* Enable external vbus configuration in the LINK */
460 val = readl(USB_USBCMD);
461 val |= SESS_VLD_CTRL;
462 writel(val, USB_USBCMD);
463}
464
465void target_usb_stop(void)
466{
467 /* Disable VBUS mimicing in the controller. */
468 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
469}
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530470
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700471static uint8_t splash_override;
472/* Returns 1 if target supports continuous splash screen. */
473int target_cont_splash_screen()
474{
475 uint8_t splash_screen = 0;
476 if (!splash_override) {
477 switch (board_hardware_id()) {
478 case HW_PLATFORM_MTP:
479 case HW_PLATFORM_SURF:
feifanz174c82c2015-04-15 18:57:07 +0800480 case HW_PLATFORM_QRD:
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700481 splash_screen = 1;
482 break;
483 default:
484 splash_screen = 0;
485 break;
486 }
487 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
488 }
489 return splash_screen;
490}
491
492void target_force_cont_splash_disable(uint8_t override)
493{
494 splash_override = override;
495}
496
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530497/* Do any target specific intialization needed before entering fastboot mode */
498void target_fastboot_init(void)
499{
500 if (target_is_ssd_enabled()) {
501 clock_ce_enable(CE1_INSTANCE);
502 target_load_ssd_keystore();
503 }
504}
505
506void target_load_ssd_keystore(void)
507{
508 uint64_t ptn;
509 int index;
510 uint64_t size;
511 uint32_t *buffer = NULL;
512
513 if (!target_is_ssd_enabled())
514 return;
515
516 index = partition_get_index("ssd");
517
518 ptn = partition_get_offset(index);
519 if (ptn == 0){
520 dprintf(CRITICAL, "Error: ssd partition not found\n");
521 return;
522 }
523
524 size = partition_get_size(index);
525 if (size == 0) {
526 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
527 return;
528 }
529
530 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
531 if (!buffer) {
532 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
533 return;
534 }
535
536 if (mmc_read(ptn, buffer, size)) {
537 dprintf(CRITICAL, "Error: cannot read data\n");
538 free(buffer);
539 return;
540 }
541
542 clock_ce_enable(CE1_INSTANCE);
543 scm_protect_keystore(buffer, size);
544 clock_ce_disable(CE1_INSTANCE);
545 free(buffer);
546}
547
548crypto_engine_type board_ce_type(void)
549{
550 return CRYPTO_ENGINE_TYPE_HW;
551}
552
553/* Set up params for h/w CE. */
554void target_crypto_init_params()
555{
556 struct crypto_init_params ce_params;
557
558 /* Set up base addresses and instance. */
559 ce_params.crypto_instance = CE1_INSTANCE;
560 ce_params.crypto_base = MSM_CE1_BASE;
561 ce_params.bam_base = MSM_CE1_BAM_BASE;
562
563 /* Set up BAM config. */
564 ce_params.bam_ee = CE_EE;
565 ce_params.pipes.read_pipe = CE_READ_PIPE;
566 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
567 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
568 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
569
570 /* Assign buffer sizes. */
571 ce_params.num_ce = CE_ARRAY_SIZE;
572 ce_params.read_fifo_size = CE_FIFO_SIZE;
573 ce_params.write_fifo_size = CE_FIFO_SIZE;
574
575 /* BAM is initialized by TZ for this platform.
576 * Do not do it again as the initialization address space
577 * is locked.
578 */
579 ce_params.do_bam_init = 0;
580
581 crypto_init_params(&ce_params);
582}