blob: 07fff1e8a708f00c247ffba7aa30fb8a4efba64e [file] [log] [blame]
lijuang395b5e62015-11-19 17:39:44 +08001/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -08002 *
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 <platform/irqs.h>
32#include <platform/gpio.h>
33#include <reg.h>
34#include <target.h>
35#include <platform.h>
36#include <dload_util.h>
37#include <uart_dm.h>
38#include <mmc.h>
39#include <spmi.h>
40#include <board.h>
41#include <smem.h>
42#include <baseband.h>
43#include <dev/keys.h>
44#include <pm8x41.h>
45#include <crypto5_wrapper.h>
46#include <hsusb.h>
47#include <clock.h>
48#include <partition_parser.h>
49#include <scm.h>
50#include <platform/clock.h>
51#include <platform/gpio.h>
52#include <platform/timer.h>
53#include <stdlib.h>
vijay kumar4e5859e2014-09-22 17:49:02 +053054#include <string.h>
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080055#include <ufs.h>
Sundarajan Srinivasand598b122014-03-21 17:33:29 -070056#include <boot_device.h>
Channagoud Kadabi3dcc4ed2014-04-10 14:59:41 -070057#include <qmp_phy.h>
Joonwoo Park8b309972014-06-09 16:58:38 -070058#include <qusb2_phy.h>
Sundarajan Srinivasan19b95c72014-07-24 16:37:04 -070059#include <rpm-smd.h>
vijay kumar4e5859e2014-09-22 17:49:02 +053060#include <sdhci_msm.h>
Shimrit Malichi561a5e52015-01-20 09:58:40 +020061#include <pm8x41_wled.h>
62#include <qpnp_led.h>
Sridhar Parasuram2ff7e232015-05-28 11:59:29 -070063#include <boot_device.h>
64#include <secapp_loader.h>
65#include <rpmb.h>
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080066
Veera Sundaram Sankaran089f70d2014-12-09 14:17:05 -080067#include "target/display.h"
68
Channagoud Kadabi27ff9342014-06-16 11:19:29 -070069#define CE_INSTANCE 2
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -070070#define CE_EE 1
71#define CE_FIFO_SIZE 64
72#define CE_READ_PIPE 3
73#define CE_WRITE_PIPE 2
74#define CE_READ_PIPE_LOCK_GRP 0
75#define CE_WRITE_PIPE_LOCK_GRP 0
76#define CE_ARRAY_SIZE 20
77
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080078#define PMIC_ARB_CHANNEL_NUM 0
79#define PMIC_ARB_OWNER_ID 0
80
81#define FASTBOOT_MODE 0x77665500
82
Shimrit Malichi561a5e52015-01-20 09:58:40 +020083#define PMIC_LED_SLAVE_ID 3
Channagoud Kadabi41c81a62014-10-08 19:55:30 -070084#define DDR_CFG_DLY_VAL 0x80040870
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080085
Sridhar Parasuram357d2b92014-12-05 10:39:23 -080086void target_crypto_init_params(void);
Channagoud Kadabie804d642014-08-20 17:43:57 -070087static void set_sdc_power_ctrl(uint8_t slot);
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080088static uint32_t mmc_pwrctl_base[] =
89 { MSM_SDC1_BASE, MSM_SDC2_BASE };
90
91static uint32_t mmc_sdhci_base[] =
92 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
93
94static uint32_t mmc_sdc_pwrctl_irq[] =
95 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
96
97struct mmc_device *dev;
98struct ufs_dev ufs_device;
99
100extern void ulpi_write(unsigned val, unsigned reg);
Sridhar Parasuram39419a32014-09-12 18:11:05 -0700101extern int platform_is_msm8994();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800102
103void target_early_init(void)
104{
105#if WITH_DEBUG_UART
106 uart_dm_init(2, 0, BLSP1_UART1_BASE);
107#endif
108}
109
110/* Return 1 if vol_up pressed */
Reut Zysman18411272015-02-09 13:47:27 +0200111int target_volume_up()
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800112{
lijuang2d2b8a02015-06-05 21:34:15 +0800113 static uint8_t first_time = 0;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800114 uint8_t status = 0;
115 struct pm8x41_gpio gpio;
116
lijuang2d2b8a02015-06-05 21:34:15 +0800117 if (!first_time) {
118 /* Configure the GPIO */
119 gpio.direction = PM_GPIO_DIR_IN;
120 gpio.function = 0;
121 gpio.pull = PM_GPIO_PULL_UP_30;
122 gpio.vin_sel = 2;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800123
lijuang2d2b8a02015-06-05 21:34:15 +0800124 pm8x41_gpio_config(3, &gpio);
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800125
lijuang2d2b8a02015-06-05 21:34:15 +0800126 /* Wait for the pmic gpio config to take effect */
127 udelay(10000);
128
129 first_time = 1;
130 }
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800131
132 /* Get status of P_GPIO_5 */
133 pm8x41_gpio_get(3, &status);
134
135 return !status; /* active low */
136}
137
138/* Return 1 if vol_down pressed */
139uint32_t target_volume_down()
140{
141 return pm8x41_resin_status();
142}
143
144static void target_keystatus()
145{
146 keys_init();
147
148 if(target_volume_down())
149 keys_post_event(KEY_VOLUMEDOWN, 1);
150
151 if(target_volume_up())
152 keys_post_event(KEY_VOLUMEUP, 1);
153}
154
155void target_uninit(void)
156{
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700157 if (platform_boot_dev_isemmc())
Channagoud Kadabid6a45ea2014-06-02 21:12:51 -0700158 {
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800159 mmc_put_card_to_sleep(dev);
Channagoud Kadabid6a45ea2014-06-02 21:12:51 -0700160 /* Disable HC mode before jumping to kernel */
161 sdhci_mode_disable(&dev->host);
162 }
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700163
164 if (crypto_initialized())
Channagoud Kadabi2c488742014-12-02 11:37:18 -0800165 {
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700166 crypto_eng_cleanup();
Channagoud Kadabi2c488742014-12-02 11:37:18 -0800167 clock_ce_disable(CE_INSTANCE);
168 }
Sundarajan Srinivasan19b95c72014-07-24 16:37:04 -0700169
Sridhar Parasuram2ff7e232015-05-28 11:59:29 -0700170 if (is_sec_app_loaded())
171 {
172 if (send_milestone_call_to_tz() < 0)
173 {
174 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
175 ASSERT(0);
176 }
177 }
178
179 if (rpmb_uninit() < 0)
180 {
181 dprintf(CRITICAL, "RPMB uninit failed\n");
182 ASSERT(0);
183 }
Sundarajan Srinivasan19b95c72014-07-24 16:37:04 -0700184 rpm_smd_uninit();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800185}
186
187/* Do target specific usb initialization */
188void target_usb_init(void)
189{
190 uint32_t val;
191
Sundarajan Srinivasan0ebf2fc2014-04-23 16:45:18 -0700192 if(board_hardware_id() == HW_PLATFORM_DRAGON)
193 {
194 /* Select the QUSB2 PHY */
195 writel(0x1, USB2_PHY_SEL);
196
Joonwoo Park8b309972014-06-09 16:58:38 -0700197 qusb2_phy_reset();
Sundarajan Srinivasan0ebf2fc2014-04-23 16:45:18 -0700198 }
199
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800200 /* Enable sess_vld */
201 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
202 writel(val, USB_GENCONFIG_2);
203
204 /* Enable external vbus configuration in the LINK */
205 val = readl(USB_USBCMD);
206 val |= SESS_VLD_CTRL;
207 writel(val, USB_USBCMD);
208}
209
210void target_usb_stop(void)
211{
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800212}
213
Channagoud Kadabib9473932014-10-09 13:08:35 -0700214unsigned target_pause_for_battery_charge(void)
215{
216 uint8_t pon_reason = pm8x41_get_pon_reason();
217 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
218 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
219 pon_reason, is_cold_boot);
220 /* In case of fastboot reboot,adb reboot or if we see the power key
221 * pressed we do not want go into charger mode.
222 * fastboot reboot is warm boot with PON hard reset bit not set
223 * adb reboot is a cold boot with PON hard reset bit set
224 */
225 if (is_cold_boot &&
226 (!(pon_reason & HARD_RST)) &&
227 (!(pon_reason & KPDPWR_N)) &&
Channagoud Kadabi439833a2014-10-22 13:42:06 -0700228 ((pon_reason & PON1)))
Channagoud Kadabib9473932014-10-09 13:08:35 -0700229 return 1;
230 else
231 return 0;
232}
233
Channagoud Kadabie804d642014-08-20 17:43:57 -0700234static void set_sdc_power_ctrl(uint8_t slot)
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800235{
Channagoud Kadabie804d642014-08-20 17:43:57 -0700236 uint32_t reg = 0;
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700237 uint8_t clk;
238 uint8_t cmd;
239 uint8_t dat;
Channagoud Kadabie804d642014-08-20 17:43:57 -0700240
241 if (slot == 0x1)
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700242 {
Channagoud Kadabic8da67d2014-11-20 12:07:11 -0800243 clk = TLMM_CUR_VAL_10MA;
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700244 cmd = TLMM_CUR_VAL_8MA;
245 dat = TLMM_CUR_VAL_8MA;
Channagoud Kadabie804d642014-08-20 17:43:57 -0700246 reg = SDC1_HDRV_PULL_CTL;
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700247 }
Channagoud Kadabie804d642014-08-20 17:43:57 -0700248 else if (slot == 0x2)
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700249 {
250 clk = TLMM_CUR_VAL_16MA;
251 cmd = TLMM_CUR_VAL_10MA;
252 dat = TLMM_CUR_VAL_10MA;
Channagoud Kadabie804d642014-08-20 17:43:57 -0700253 reg = SDC2_HDRV_PULL_CTL;
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700254 }
255 else
256 {
257 dprintf(CRITICAL, "Unsupported SDC slot passed\n");
258 return;
259 }
Channagoud Kadabie804d642014-08-20 17:43:57 -0700260
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800261 /* Drive strength configs for sdc pins */
262 struct tlmm_cfgs sdc1_hdrv_cfg[] =
263 {
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700264 { SDC1_CLK_HDRV_CTL_OFF, clk, TLMM_HDRV_MASK, reg },
265 { SDC1_CMD_HDRV_CTL_OFF, cmd, TLMM_HDRV_MASK, reg },
266 { SDC1_DATA_HDRV_CTL_OFF, dat, TLMM_HDRV_MASK, reg },
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800267 };
268
269 /* Pull configs for sdc pins */
270 struct tlmm_cfgs sdc1_pull_cfg[] =
271 {
Channagoud Kadabie804d642014-08-20 17:43:57 -0700272 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, reg },
273 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg },
274 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg },
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800275 };
276
Channagoud Kadabi95717152014-06-04 17:59:29 -0700277 struct tlmm_cfgs sdc1_rclk_cfg[] =
278 {
Channagoud Kadabie804d642014-08-20 17:43:57 -0700279 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, reg },
Channagoud Kadabi95717152014-06-04 17:59:29 -0700280 };
281
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800282 /* 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));
Channagoud Kadabi95717152014-06-04 17:59:29 -0700285 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800286}
287
288void target_sdc_init()
289{
Channagoud Kadabia66a6f22014-05-28 17:19:44 -0700290 struct mmc_config_data config = {0};
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800291
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800292 config.bus_width = DATA_BUS_WIDTH_8BIT;
293 config.max_clk_rate = MMC_CLK_192MHZ;
294
295 /* Try slot 1*/
296 config.slot = 1;
297 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
298 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
299 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Channagoud Kadabi6b3a9982014-06-05 12:59:46 -0700300 config.hs400_support = 1;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800301
Channagoud Kadabie804d642014-08-20 17:43:57 -0700302 /* Set drive strength & pull ctrl values */
303 set_sdc_power_ctrl(config.slot);
304
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800305 if (!(dev = mmc_init(&config)))
306 {
307 /* Try slot 2 */
308 config.slot = 2;
309 config.max_clk_rate = MMC_CLK_200MHZ;
310 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
311 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
312 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
313
Channagoud Kadabie804d642014-08-20 17:43:57 -0700314 /* Set drive strength & pull ctrl values */
315 set_sdc_power_ctrl(config.slot);
316
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800317 if (!(dev = mmc_init(&config)))
318 {
319 dprintf(CRITICAL, "mmc init failed!");
320 ASSERT(0);
321 }
322 }
323}
324
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800325void *target_mmc_device()
326{
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700327 if (platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800328 return (void *) dev;
329 else
330 return (void *) &ufs_device;
331}
332
333void target_init(void)
334{
Sridhar Parasuram2ff7e232015-05-28 11:59:29 -0700335 int ret = 0;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800336 dprintf(INFO, "target_init()\n");
337
338 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
339
340 target_keystatus();
341
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700342
343 if (target_use_signed_kernel())
344 target_crypto_init_params();
345
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700346 platform_read_boot_config();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800347
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800348#ifdef MMC_SDHCI_SUPPORT
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700349 if (platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800350 {
351 target_sdc_init();
352 }
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800353#endif
354#ifdef UFS_SUPPORT
355 if(!platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800356 {
357 ufs_device.base = UFS_BASE;
358 ufs_init(&ufs_device);
359 }
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800360#endif
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800361 /* Storage initialization is complete, read the partition table info */
Channagoud Kadabi78a368e2014-10-21 22:25:35 -0700362 mmc_read_partition_table(0);
Sundarajan Srinivasan19b95c72014-07-24 16:37:04 -0700363
Sridhar Parasuram2ff7e232015-05-28 11:59:29 -0700364 /* Initialize Qseecom */
365 ret = qseecom_init();
366
367 if (ret < 0)
368 {
369 dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret);
370 ASSERT(0);
371 }
372
373 /* Start Qseecom */
374 ret = qseecom_tz_init();
375
376 if (ret < 0)
377 {
378 dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret);
379 ASSERT(0);
380 }
381
382 /*
383 * Load the sec app for first time
384 */
385 if (load_sec_app() < 0)
386 {
387 dprintf(CRITICAL, "Failed to load App for verified\n");
388 ASSERT(0);
389 }
390
391 if (rpmb_init() < 0)
392 {
393 dprintf(CRITICAL, "RPMB init failed\n");
394 ASSERT(0);
395 }
396
397
Sundarajan Srinivasan19b95c72014-07-24 16:37:04 -0700398 rpm_smd_init();
Shimrit Malichi561a5e52015-01-20 09:58:40 +0200399
400 /* QPNP LED init for boot process notification */
401 if (board_hardware_id() == HW_PLATFORM_LIQUID){
402 pm8x41_wled_config_slave_id(PMIC_LED_SLAVE_ID);
403 qpnp_led_init(QPNP_LED_BLUE, QPNP_LED_CTRL_BASE,
404 QPNP_BLUE_LPG_CTRL_BASE);
405 }
406
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800407}
408
409unsigned board_machtype(void)
410{
411 return LINUX_MACHTYPE_UNKNOWN;
412}
413
414/* Detect the target type */
415void target_detect(struct board_data *board)
416{
417 /* This is filled from board.c */
418}
419
Justin Philipbe9de5c2014-09-17 12:26:49 +0530420static uint8_t splash_override;
Dhaval Patel019057a2014-08-12 13:52:25 -0700421/* Returns 1 if target supports continuous splash screen. */
422int target_cont_splash_screen()
423{
Justin Philipbe9de5c2014-09-17 12:26:49 +0530424 uint8_t splash_screen = 0;
425 if(!splash_override) {
426 switch(board_hardware_id())
427 {
428 case HW_PLATFORM_SURF:
429 case HW_PLATFORM_MTP:
430 case HW_PLATFORM_FLUID:
Siddhartha Agrawalcddb0b82014-10-14 15:07:18 -0700431 case HW_PLATFORM_LIQUID:
Justin Philipbe9de5c2014-09-17 12:26:49 +0530432 dprintf(SPEW, "Target_cont_splash=1\n");
433 splash_screen = 1;
434 break;
435 default:
436 dprintf(SPEW, "Target_cont_splash=0\n");
437 splash_screen = 0;
438 }
439 }
440 return splash_screen;
441}
442
443void target_force_cont_splash_disable(uint8_t override)
444{
445 splash_override = override;
Dhaval Patel019057a2014-08-12 13:52:25 -0700446}
447
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800448/* Detect the modem type */
449void target_baseband_detect(struct board_data *board)
450{
451 uint32_t platform;
452
453 platform = board->platform;
454
455 switch(platform) {
Channagoud Kadabi44ea30d2014-04-14 13:59:42 -0700456 case MSM8994:
Channagoud Kadabi23c90ab2014-08-28 15:49:19 -0700457 case MSM8992:
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800458 board->baseband = BASEBAND_MSM;
459 break;
Channagoud Kadabi30ef4452014-07-12 13:03:30 -0700460 case APQ8094:
Channagoud Kadabi23c90ab2014-08-28 15:49:19 -0700461 case APQ8092:
Channagoud Kadabi30ef4452014-07-12 13:03:30 -0700462 board->baseband = BASEBAND_APQ;
463 break;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800464 default:
465 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
466 ASSERT(0);
467 };
468}
469unsigned target_baseband()
470{
471 return board_baseband();
472}
473
474void target_serialno(unsigned char *buf)
475{
Sridhar Parasuram4bce0a92014-10-22 12:49:36 -0700476 uint32_t serialno;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800477 if (target_is_emmc_boot()) {
Sridhar Parasuram4bce0a92014-10-22 12:49:36 -0700478 if (platform_boot_dev_isemmc())
479 serialno = mmc_get_psn();
480 else
481 serialno = board_chip_serial();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800482 snprintf((char *)buf, 13, "%x", serialno);
483 }
484}
485
486unsigned check_reboot_mode(void)
487{
488 uint32_t restart_reason = 0;
489 uint32_t restart_reason_addr;
490
Sridhar Parasuram39419a32014-09-12 18:11:05 -0700491 if (platform_is_msm8994())
492 restart_reason_addr = RESTART_REASON_ADDR;
493 else
494 restart_reason_addr = RESTART_REASON_ADDR2;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800495
496 /* Read reboot reason and scrub it */
497 restart_reason = readl(restart_reason_addr);
498 writel(0x00, restart_reason_addr);
499
500 return restart_reason;
501}
502
lijuang395b5e62015-11-19 17:39:44 +0800503int set_download_mode(enum reboot_reason mode)
504{
505 if (mode == NORMAL_DLOAD || mode == EMERGENCY_DLOAD) {
506 if (platform_is_msm8994())
507 dload_util_write_cookie(mode == NORMAL_DLOAD ?
508 DLOAD_MODE_ADDR : EMERGENCY_DLOAD_MODE_ADDR, mode);
509 else
510 dload_util_write_cookie(mode == NORMAL_DLOAD ?
511 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
512 }
513
514 return 0;
515}
516
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800517void reboot_device(unsigned reboot_reason)
518{
519 uint8_t reset_type = 0;
Channagoud Kadabie6a80b32015-03-02 12:42:50 -0800520 uint32_t restart_reason_addr;
521
lijuang395b5e62015-11-19 17:39:44 +0800522 /* Set cookie for dload mode */
523 if(set_download_mode(reboot_reason)) {
524 dprintf(CRITICAL, "HALT: set_download_mode not supported\n");
525 return;
526 }
527
Channagoud Kadabie6a80b32015-03-02 12:42:50 -0800528 if (platform_is_msm8994())
529 restart_reason_addr = RESTART_REASON_ADDR;
530 else
531 restart_reason_addr = RESTART_REASON_ADDR2;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800532
533 /* Write the reboot reason */
Channagoud Kadabie6a80b32015-03-02 12:42:50 -0800534 writel(reboot_reason, restart_reason_addr);
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800535
Channagoud Kadabi44da93e2015-08-20 15:10:46 -0700536 if(reboot_reason == FASTBOOT_MODE || reboot_reason == DLOAD)
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800537 reset_type = PON_PSHOLD_WARM_RESET;
538 else
539 reset_type = PON_PSHOLD_HARD_RESET;
540
Channagoud Kadabiba025ec2015-02-19 15:06:33 -0800541 pm8994_reset_configure(reset_type);
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800542
543 /* Drop PS_HOLD for MSM */
544 writel(0x00, MPM2_MPM_PS_HOLD);
545
546 mdelay(5000);
547
548 dprintf(CRITICAL, "Rebooting failed\n");
549}
550
551int emmc_recovery_init(void)
552{
553 return _emmc_recovery_init();
554}
Channagoud Kadabi3dcc4ed2014-04-10 14:59:41 -0700555
556target_usb_iface_t* target_usb30_init()
557{
558 target_usb_iface_t *t_usb_iface;
559
560 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
561 ASSERT(t_usb_iface);
562
563 t_usb_iface->mux_config = target_usb_phy_mux_configure;
564 t_usb_iface->phy_init = usb30_qmp_phy_init;
565 t_usb_iface->phy_reset = usb30_qmp_phy_reset;
566 t_usb_iface->clock_init = clock_usb30_init;
567 t_usb_iface->vbus_override = 1;
568
569 return t_usb_iface;
570}
571
572/* identify the usb controller to be used for the target */
573const char * target_usb_controller()
574{
Tanya Finkel90abab72014-07-30 09:55:23 +0300575 if(board_hardware_id() == HW_PLATFORM_DRAGON)
576 return "ci";
Channagoud Kadabi3dcc4ed2014-04-10 14:59:41 -0700577 return "dwc";
578}
579
580/* mux hs phy to route to dwc controller */
581static void phy_mux_configure_with_tcsr()
582{
583 /* As per the hardware team, set the mux for snps controller */
584 RMWREG32(TCSR_PHSS_USB2_PHY_SEL, 0x0, 0x1, 0x1);
585}
586
587/* configure hs phy mux if using dwc controller */
588void target_usb_phy_mux_configure(void)
589{
590 if(!strcmp(target_usb_controller(), "dwc"))
591 {
592 phy_mux_configure_with_tcsr();
593 }
594}
Channagoud Kadabi3c2be1c2014-06-01 18:59:21 -0700595
596uint32_t target_override_pll()
597{
598 return 1;
599}
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700600
601/* Set up params for h/w CE. */
602void target_crypto_init_params()
603{
604 struct crypto_init_params ce_params;
605
606 /* Set up base addresses and instance. */
607 ce_params.crypto_instance = CE_INSTANCE;
Channagoud Kadabi27ff9342014-06-16 11:19:29 -0700608 ce_params.crypto_base = MSM_CE2_BASE;
609 ce_params.bam_base = MSM_CE2_BAM_BASE;
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700610
611 /* Set up BAM config. */
612 ce_params.bam_ee = CE_EE;
613 ce_params.pipes.read_pipe = CE_READ_PIPE;
614 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
615 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
616 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
617
618 /* Assign buffer sizes. */
619 ce_params.num_ce = CE_ARRAY_SIZE;
620 ce_params.read_fifo_size = CE_FIFO_SIZE;
621 ce_params.write_fifo_size = CE_FIFO_SIZE;
622
623 /* BAM is initialized by TZ for this platform.
624 * Do not do it again as the initialization address space
625 * is locked.
626 */
627 ce_params.do_bam_init = 0;
628
629 crypto_init_params(&ce_params);
630}
631
632crypto_engine_type board_ce_type(void)
633{
634 return CRYPTO_ENGINE_TYPE_HW;
635}
Channagoud Kadabi84f860f2014-07-01 15:46:09 -0700636
637void shutdown_device()
638{
639 dprintf(CRITICAL, "Going down for shutdown.\n");
640
641 /* Configure PMIC for shutdown. */
Channagoud Kadabiba025ec2015-02-19 15:06:33 -0800642 pm8994_reset_configure(PON_PSHOLD_SHUTDOWN);
Channagoud Kadabi84f860f2014-07-01 15:46:09 -0700643
644 /* Drop PS_HOLD for MSM */
645 writel(0x00, MPM2_MPM_PS_HOLD);
646
647 mdelay(5000);
648
649 dprintf(CRITICAL, "Shutdown failed\n");
650
651 ASSERT(0);
652}
Sundarajan Srinivasancd3bb3c2014-07-23 12:25:44 -0700653
Channagoud Kadabi41c81a62014-10-08 19:55:30 -0700654uint32_t target_ddr_cfg_val()
655{
656 return DDR_CFG_DLY_VAL;
657}
Channagoud Kadabi44da93e2015-08-20 15:10:46 -0700658
lijuang3606df82015-09-02 21:14:43 +0800659uint32_t target_get_pmic()
660{
661 return PMIC_IS_PMI8994;
662}