blob: f9e63ee44a77ff9f760857a993d884a6dcef9d50 [file] [log] [blame]
lijuang395b5e62015-11-19 17:39:44 +08001/* Copyright (c) 2014-2016 The Linux Foundation. All rights reserved.
Channagoud Kadabied60a8b2014-06-27 15:35:09 -07002 *
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
Sridhar Parasuram568e7a62015-08-06 13:16:02 -070021 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, nit
22 * PROCUREMENT OF
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <debug.h>
31#include <platform/iomap.h>
32#include <platform/irqs.h>
33#include <platform/gpio.h>
34#include <reg.h>
35#include <target.h>
36#include <platform.h>
37#include <dload_util.h>
38#include <uart_dm.h>
39#include <mmc.h>
40#include <spmi.h>
41#include <board.h>
42#include <smem.h>
43#include <baseband.h>
Sridhar Parasuramd75ade52015-03-09 15:45:16 -070044#include <regulator.h>
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070045#include <dev/keys.h>
46#include <pm8x41.h>
47#include <crypto5_wrapper.h>
48#include <clock.h>
49#include <partition_parser.h>
50#include <scm.h>
51#include <platform/clock.h>
52#include <platform/gpio.h>
53#include <platform/timer.h>
54#include <stdlib.h>
55#include <ufs.h>
56#include <boot_device.h>
57#include <qmp_phy.h>
Channagoud Kadabi7d308202014-12-22 12:07:04 -080058#include <sdhci_msm.h>
59#include <qusb2_phy.h>
Sridhar Parasuram568e7a62015-08-06 13:16:02 -070060#include <secapp_loader.h>
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -080061#include <rpmb.h>
Sridhar Parasuram9f28f672015-03-17 15:40:47 -070062#include <rpm-glink.h>
Channagoud Kadabibb8f1f92015-04-27 11:14:45 -070063#if ENABLE_WBC
64#include <pm_app_smbchg.h>
65#endif
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070066
c_wufengf433f232015-09-21 15:21:21 +080067#if LONG_PRESS_POWER_ON
68#include <shutdown_detect.h>
69#endif
70
c_wufeng196210d2015-09-21 12:49:43 +080071#if PON_VIB_SUPPORT
72#include <vibrator.h>
73#define VIBRATE_TIME 250
74#endif
c_wufengf433f232015-09-21 15:21:21 +080075
Channagoud Kadabi9b28c0b2016-01-11 18:42:33 -080076#include <pm_smbchg_usb_chgpth.h>
77
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -080078#define CE_INSTANCE 1
Channagoud Kadabi7edb9b42015-08-11 23:45:31 -070079#define CE_EE 0
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -080080#define CE_FIFO_SIZE 64
81#define CE_READ_PIPE 3
82#define CE_WRITE_PIPE 2
83#define CE_READ_PIPE_LOCK_GRP 0
84#define CE_WRITE_PIPE_LOCK_GRP 0
85#define CE_ARRAY_SIZE 20
86
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070087#define PMIC_ARB_CHANNEL_NUM 0
88#define PMIC_ARB_OWNER_ID 0
89
Channagoud Kadabi4021fa92015-11-03 16:35:26 -080090enum
91{
92 FUSION_I2S_MTP = 1,
93 FUSION_SLIMBUS = 2,
94} mtp_subtype;
95
96enum
97{
98 FUSION_I2S_CDP = 2,
99} cdp_subtype;
100
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300101static uint8_t flash_memory_slot = 0;
102static void set_sdc_power_ctrl();
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700103static uint32_t mmc_pwrctl_base[] =
104 { MSM_SDC1_BASE, MSM_SDC2_BASE };
105
106static uint32_t mmc_sdhci_base[] =
107 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
108
109static uint32_t mmc_sdc_pwrctl_irq[] =
110 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
111
112struct mmc_device *dev;
113struct ufs_dev ufs_device;
114
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700115void target_early_init(void)
116{
117#if WITH_DEBUG_UART
Channagoud Kadabi35503c42014-11-14 16:22:43 -0800118 uart_dm_init(8, 0, BLSP2_UART1_BASE);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700119#endif
120}
121
122/* Return 1 if vol_up pressed */
Amit Blay6a3e88b2015-06-23 22:25:06 +0300123int target_volume_up()
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700124{
lijuang2d2b8a02015-06-05 21:34:15 +0800125 static uint8_t first_time = 0;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700126 uint8_t status = 0;
127 struct pm8x41_gpio gpio;
128
lijuang2d2b8a02015-06-05 21:34:15 +0800129 if (!first_time) {
130 /* Configure the GPIO */
131 gpio.direction = PM_GPIO_DIR_IN;
132 gpio.function = 0;
133 gpio.pull = PM_GPIO_PULL_UP_30;
134 gpio.vin_sel = 2;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700135
lijuang2d2b8a02015-06-05 21:34:15 +0800136 pm8x41_gpio_config(2, &gpio);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700137
lijuang2d2b8a02015-06-05 21:34:15 +0800138 /* Wait for the pmic gpio config to take effect */
139 udelay(10000);
140
141 first_time = 1;
142 }
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700143
144 /* Get status of P_GPIO_5 */
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800145 pm8x41_gpio_get(2, &status);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700146
147 return !status; /* active low */
148}
149
150/* Return 1 if vol_down pressed */
151uint32_t target_volume_down()
152{
153 return pm8x41_resin_status();
154}
155
156static void target_keystatus()
157{
158 keys_init();
159
160 if(target_volume_down())
161 keys_post_event(KEY_VOLUMEDOWN, 1);
162
163 if(target_volume_up())
164 keys_post_event(KEY_VOLUMEUP, 1);
165}
166
167void target_uninit(void)
168{
169 if (platform_boot_dev_isemmc())
170 {
171 mmc_put_card_to_sleep(dev);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700172 }
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -0800173
174 if (is_sec_app_loaded())
175 {
Sridhar Parasuram568e7a62015-08-06 13:16:02 -0700176 if (send_milestone_call_to_tz() < 0)
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -0800177 {
178 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
179 ASSERT(0);
180 }
181 }
182
Channagoud Kadabibb8f1f92015-04-27 11:14:45 -0700183#if ENABLE_WBC
Channagoud Kadabi22165612015-07-22 14:04:37 -0700184 if (board_hardware_id() == HW_PLATFORM_MTP)
185 pm_appsbl_set_dcin_suspend(1);
Channagoud Kadabibb8f1f92015-04-27 11:14:45 -0700186#endif
187
Channagoud Kadabi7edb9b42015-08-11 23:45:31 -0700188
189 if (crypto_initialized())
190 {
191 crypto_eng_cleanup();
192 clock_ce_disable(CE_INSTANCE);
193 }
194
Sridhar Parasuram9f28f672015-03-17 15:40:47 -0700195 /* Tear down glink channels */
196 rpm_glink_uninit();
197
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -0800198 if (rpmb_uninit() < 0)
199 {
200 dprintf(CRITICAL, "RPMB uninit failed\n");
201 ASSERT(0);
202 }
203
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700204}
205
206static void set_sdc_power_ctrl()
207{
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300208 uint32_t reg = 0;
209 uint8_t clk = 0;
210 uint8_t cmd = 0;
211 uint8_t dat = 0;
212
213 if (flash_memory_slot == 0x1)
214 {
215 clk = TLMM_CUR_VAL_10MA;
216 cmd = TLMM_CUR_VAL_8MA;
217 dat = TLMM_CUR_VAL_8MA;
218 reg = SDC1_HDRV_PULL_CTL;
219 }
220 else if (flash_memory_slot == 0x2)
221 {
222 clk = TLMM_CUR_VAL_16MA;
223 cmd = TLMM_CUR_VAL_10MA;
224 dat = TLMM_CUR_VAL_10MA;
225 reg = SDC2_HDRV_PULL_CTL;
226 }
227
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700228 /* Drive strength configs for sdc pins */
229 struct tlmm_cfgs sdc1_hdrv_cfg[] =
230 {
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300231 { SDC1_CLK_HDRV_CTL_OFF, clk, TLMM_HDRV_MASK, reg },
232 { SDC1_CMD_HDRV_CTL_OFF, cmd, TLMM_HDRV_MASK, reg },
233 { SDC1_DATA_HDRV_CTL_OFF, dat, TLMM_HDRV_MASK, reg },
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700234 };
235
236 /* Pull configs for sdc pins */
237 struct tlmm_cfgs sdc1_pull_cfg[] =
238 {
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300239 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, reg },
240 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg },
241 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg },
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700242 };
243
244 struct tlmm_cfgs sdc1_rclk_cfg[] =
245 {
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300246 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, reg },
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700247 };
248
249 /* Set the drive strength & pull control values */
250 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
251 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
252 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
253}
254
c_wufengf433f232015-09-21 15:21:21 +0800255uint32_t target_is_pwrkey_pon_reason()
256{
257 uint8_t pon_reason = pm8950_get_pon_reason();
258 if (pm8x41_get_is_cold_boot() && ((pon_reason == KPDPWR_N) || (pon_reason == (KPDPWR_N|PON1))))
259 return 1;
260 else
261 return 0;
262}
263
264
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700265void target_sdc_init()
266{
267 struct mmc_config_data config = {0};
268
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700269 config.bus_width = DATA_BUS_WIDTH_8BIT;
270 config.max_clk_rate = MMC_CLK_192MHZ;
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800271 config.hs400_support = 1;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700272
273 /* Try slot 1*/
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300274 flash_memory_slot = 1;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700275 config.slot = 1;
276 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
277 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
278 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
279
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300280 /* Set drive strength & pull ctrl values */
281 set_sdc_power_ctrl();
282
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700283 if (!(dev = mmc_init(&config)))
284 {
285 /* Try slot 2 */
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300286 flash_memory_slot = 2;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700287 config.slot = 2;
288 config.max_clk_rate = MMC_CLK_200MHZ;
289 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
290 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
291 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
292
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300293 /* Set drive strength & pull ctrl values */
294 set_sdc_power_ctrl();
295
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700296 if (!(dev = mmc_init(&config)))
297 {
298 dprintf(CRITICAL, "mmc init failed!");
299 ASSERT(0);
300 }
301 }
302}
303
304void *target_mmc_device()
305{
306 if (platform_boot_dev_isemmc())
307 return (void *) dev;
308 else
309 return (void *) &ufs_device;
310}
311
312void target_init(void)
313{
Sridhar Parasuram568e7a62015-08-06 13:16:02 -0700314 int ret = 0;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700315 dprintf(INFO, "target_init()\n");
316
Sridhar Parasuram1d224322015-06-15 11:03:40 -0700317 pmic_info_populate();
318
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700319 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
320
Channagoud Kadabibb8f1f92015-04-27 11:14:45 -0700321 /* Initialize Glink */
322 rpm_glink_init();
323
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700324 target_keystatus();
325
c_wufengf433f232015-09-21 15:21:21 +0800326#if defined(LONG_PRESS_POWER_ON) || defined(PON_VIB_SUPPORT)
327 switch(board_hardware_id())
328 {
329 case HW_PLATFORM_QRD:
330#if LONG_PRESS_POWER_ON
331 shutdown_detect();
332#endif
c_wufeng196210d2015-09-21 12:49:43 +0800333#if PON_VIB_SUPPORT
334 vib_timed_turn_on(VIBRATE_TIME);
335#endif
c_wufengf433f232015-09-21 15:21:21 +0800336 break;
337 }
338#endif
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700339
340 if (target_use_signed_kernel())
341 target_crypto_init_params();
342
343 platform_read_boot_config();
344
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800345#ifdef MMC_SDHCI_SUPPORT
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700346 if (platform_boot_dev_isemmc())
347 {
348 target_sdc_init();
349 }
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800350#endif
351#ifdef UFS_SUPPORT
352 if (!platform_boot_dev_isemmc())
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700353 {
354 ufs_device.base = UFS_BASE;
355 ufs_init(&ufs_device);
356 }
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800357#endif
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700358
359 /* Storage initialization is complete, read the partition table info */
Channagoud Kadabi58a273b2015-02-10 12:56:22 -0800360 mmc_read_partition_table(0);
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -0800361
Channagoud Kadabi1171d8d2015-07-30 19:12:44 -0700362#if ENABLE_WBC
363 /* Look for battery voltage and make sure we have enough to bootup
364 * Otherwise initiate battery charging
365 * Charging should happen as early as possible, any other driver
366 * initialization before this should consider the power impact
367 */
Channagoud Kadabi25fd8ce2015-08-19 14:45:08 -0700368 switch(board_hardware_id())
369 {
370 case HW_PLATFORM_MTP:
371 case HW_PLATFORM_FLUID:
lijuang0e98add2015-11-10 10:40:27 +0800372 case HW_PLATFORM_QRD:
Parth Dixit550ddf32016-11-28 17:00:29 +0530373 if(target_is_pmi_enabled())
374 pm_appsbl_chg_check_weak_battery_status(1);
Channagoud Kadabi25fd8ce2015-08-19 14:45:08 -0700375 break;
376 default:
377 /* Charging not supported */
378 break;
379 };
Channagoud Kadabi1171d8d2015-07-30 19:12:44 -0700380#endif
381
Sridhar Parasuram568e7a62015-08-06 13:16:02 -0700382 /* Initialize Qseecom */
383 ret = qseecom_init();
384
385 if (ret < 0)
386 {
387 dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret);
388 ASSERT(0);
389 }
390
391 /* Start Qseecom */
392 ret = qseecom_tz_init();
393
394 if (ret < 0)
395 {
396 dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret);
397 ASSERT(0);
398 }
399
Sridhar Parasuramc61ecc22015-09-22 13:53:31 -0700400 if (rpmb_init() < 0)
401 {
402 dprintf(CRITICAL, "RPMB init failed\n");
403 ASSERT(0);
404 }
405
Sridhar Parasuram568e7a62015-08-06 13:16:02 -0700406 /*
407 * Load the sec app for first time
408 */
409 if (load_sec_app() < 0)
410 {
411 dprintf(CRITICAL, "Failed to load App for verified\n");
412 ASSERT(0);
413 }
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700414}
415
416unsigned board_machtype(void)
417{
418 return LINUX_MACHTYPE_UNKNOWN;
419}
420
421/* Detect the target type */
422void target_detect(struct board_data *board)
423{
424 /* This is filled from board.c */
425}
426
Dhaval Patelb95039c2015-03-16 11:14:06 -0700427static uint8_t splash_override;
428/* Returns 1 if target supports continuous splash screen. */
429int target_cont_splash_screen()
430{
431 uint8_t splash_screen = 0;
Channagoud Kadabi25fd8ce2015-08-19 14:45:08 -0700432 if(!splash_override && !pm_appsbl_charging_in_progress()) {
Dhaval Patelb95039c2015-03-16 11:14:06 -0700433 switch(board_hardware_id())
434 {
435 case HW_PLATFORM_SURF:
436 case HW_PLATFORM_MTP:
437 case HW_PLATFORM_FLUID:
feifanz76fe6482015-09-02 15:25:16 +0800438 case HW_PLATFORM_QRD:
Kuogee Hsiehb976dfc2015-08-28 13:21:30 -0700439 case HW_PLATFORM_LIQUID:
Siddharth Zaveriacaacc32015-12-12 15:10:33 -0500440 case HW_PLATFORM_DRAGON:
441 case HW_PLATFORM_ADP:
Dhaval Patelb95039c2015-03-16 11:14:06 -0700442 dprintf(SPEW, "Target_cont_splash=1\n");
443 splash_screen = 1;
444 break;
445 default:
446 dprintf(SPEW, "Target_cont_splash=0\n");
447 splash_screen = 0;
448 }
449 }
450 return splash_screen;
451}
452
453void target_force_cont_splash_disable(uint8_t override)
454{
455 splash_override = override;
456}
457
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700458/* Detect the modem type */
459void target_baseband_detect(struct board_data *board)
460{
461 uint32_t platform;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800462 uint32_t platform_hardware;
463 uint32_t platform_subtype;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700464
465 platform = board->platform;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800466 platform_hardware = board->platform_hw;
467 platform_subtype = board->platform_subtype;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700468
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800469 if (platform_hardware == HW_PLATFORM_SURF)
470 {
471 if (platform_subtype == FUSION_I2S_CDP)
472 board->baseband = BASEBAND_MDM;
473 }
474 else if (platform_hardware == HW_PLATFORM_MTP)
475 {
476 if (platform_subtype == FUSION_I2S_MTP ||
477 platform_subtype == FUSION_SLIMBUS)
478 board->baseband = BASEBAND_MDM;
479 }
480 /*
481 * Special case if MDM is not set look for chip info to decide
482 * platform subtype
483 */
484 if (board->baseband != BASEBAND_MDM)
485 {
486 switch(platform) {
487 case APQ8096:
Channagoud Kadabiee2b65e2016-01-11 19:10:29 -0800488 case APQ8096AU:
489 case APQ8096SG:
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800490 board->baseband = BASEBAND_APQ;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800491 break;
492 case MSM8996:
Channagoud Kadabiee2b65e2016-01-11 19:10:29 -0800493 case MSM8996SG:
494 case MSM8996AU:
495 case MSM8996L:
496 board->baseband = BASEBAND_MSM;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800497 break;
498 default:
499 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
500 ASSERT(0);
501 };
502 }
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700503}
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800504
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700505unsigned target_baseband()
506{
507 return board_baseband();
508}
509
510void target_serialno(unsigned char *buf)
511{
512 unsigned int serialno;
513 if (target_is_emmc_boot()) {
514 serialno = mmc_get_psn();
515 snprintf((char *)buf, 13, "%x", serialno);
516 }
517}
518
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700519int emmc_recovery_init(void)
520{
521 return _emmc_recovery_init();
522}
523
524void target_usb_phy_reset()
525{
526 usb30_qmp_phy_reset();
527 qusb2_phy_reset();
528}
529
Tanya Finkel77318e02016-05-17 14:20:59 +0300530void target_usb_phy_sec_reset()
531{
532 qusb2_phy_reset();
533}
534
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700535target_usb_iface_t* target_usb30_init()
536{
537 target_usb_iface_t *t_usb_iface;
538
539 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
540 ASSERT(t_usb_iface);
541
Tanya Finkel77318e02016-05-17 14:20:59 +0300542
543 /* for SBC we use secondary port */
544 if (board_hardware_id() == HW_PLATFORM_SBC)
545 {
546 /* secondary port have no QMP phy,use only QUSB2 phy that have only reset */
547 t_usb_iface->phy_init = NULL;
548 t_usb_iface->phy_reset = target_usb_phy_sec_reset;
549 t_usb_iface->clock_init = clock_usb20_init;
550 } else {
551 t_usb_iface->phy_init = usb30_qmp_phy_init;
552 t_usb_iface->phy_reset = target_usb_phy_reset;
553 t_usb_iface->clock_init = clock_usb30_init;
554 }
555
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700556 t_usb_iface->vbus_override = 1;
557
558 return t_usb_iface;
559}
560
561/* identify the usb controller to be used for the target */
562const char * target_usb_controller()
563{
564 return "dwc";
565}
566
567uint32_t target_override_pll()
568{
Channagoud Kadabi1e5144b2015-04-28 17:15:05 -0700569 if (board_soc_version() >= 0x20000)
570 return 0;
571 else
572 return 1;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700573}
574
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -0800575crypto_engine_type board_ce_type(void)
576{
Channagoud Kadabi7edb9b42015-08-11 23:45:31 -0700577 return CRYPTO_ENGINE_TYPE_HW;
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -0800578}
579
580/* Set up params for h/w CE. */
581void target_crypto_init_params()
582{
583 struct crypto_init_params ce_params;
584
585 /* Set up base addresses and instance. */
586 ce_params.crypto_instance = CE_INSTANCE;
587 ce_params.crypto_base = MSM_CE_BASE;
588 ce_params.bam_base = MSM_CE_BAM_BASE;
589
590 /* Set up BAM config. */
591 ce_params.bam_ee = CE_EE;
592 ce_params.pipes.read_pipe = CE_READ_PIPE;
593 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
594 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
595 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
596
597 /* Assign buffer sizes. */
598 ce_params.num_ce = CE_ARRAY_SIZE;
599 ce_params.read_fifo_size = CE_FIFO_SIZE;
600 ce_params.write_fifo_size = CE_FIFO_SIZE;
601
602 /* BAM is initialized by TZ for this platform.
603 * Do not do it again as the initialization address space
604 * is locked.
605 */
606 ce_params.do_bam_init = 0;
607
608 crypto_init_params(&ce_params);
609}
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700610
611unsigned target_pause_for_battery_charge(void)
612{
613 uint8_t pon_reason = pm8x41_get_pon_reason();
614 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
Channagoud Kadabi9b28c0b2016-01-11 18:42:33 -0800615 pm_smbchg_usb_chgpth_pwr_pth_type charger_path = PM_SMBCHG_USB_CHGPTH_PWR_PATH__INVALID;
616 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d charger path: %d\n", __func__,
617 pon_reason, is_cold_boot, charger_path);
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700618 /* In case of fastboot reboot,adb reboot or if we see the power key
619 * pressed we do not want go into charger mode.
620 * fastboot reboot is warm boot with PON hard reset bit not set
621 * adb reboot is a cold boot with PON hard reset bit set
622 */
Channagoud Kadabi9b28c0b2016-01-11 18:42:33 -0800623 pm_smbchg_get_charger_path(1, &charger_path);
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700624 if (is_cold_boot &&
625 (!(pon_reason & HARD_RST)) &&
626 (!(pon_reason & KPDPWR_N)) &&
Channagoud Kadabi9b28c0b2016-01-11 18:42:33 -0800627 ((pon_reason & PON1)) &&
628 ((charger_path == PM_SMBCHG_USB_CHGPTH_PWR_PATH__DC_CHARGER) ||
629 (charger_path == PM_SMBCHG_USB_CHGPTH_PWR_PATH__USB_CHARGER)))
630
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700631 return 1;
632 else
633 return 0;
634}
Channagoud Kadabi23edc0c2015-03-27 18:31:32 -0700635
lijuang395b5e62015-11-19 17:39:44 +0800636int set_download_mode(enum reboot_reason mode)
Channagoud Kadabi23edc0c2015-03-27 18:31:32 -0700637{
638 int ret = 0;
639 ret = scm_dload_mode(mode);
640
641 return ret;
642}
Channagoud Kadabiffc4b902015-06-25 23:14:27 -0700643
Channagoud Kadabi65b518d2015-08-05 16:17:14 -0700644void pmic_reset_configure(uint8_t reset_type)
Channagoud Kadabiffc4b902015-06-25 23:14:27 -0700645{
Channagoud Kadabi65b518d2015-08-05 16:17:14 -0700646 pm8994_reset_configure(reset_type);
Channagoud Kadabiffc4b902015-06-25 23:14:27 -0700647}
lijuang3606df82015-09-02 21:14:43 +0800648
649uint32_t target_get_pmic()
650{
651 return PMIC_IS_PMI8996;
652}
Channagoud Kadabi85c7ec32016-01-28 23:09:21 -0800653
654int target_update_cmdline(char *cmdline)
655{
656 uint32_t platform_id = board_platform_id();
657 int len = 0;
658 if (platform_id == APQ8096SG || platform_id == MSM8996SG)
659 {
660 strlcpy(cmdline, " fpsimd.fpsimd_settings=0", TARGET_MAX_CMDLNBUF);
661 len = strlen (cmdline);
Prasad Sodagudid76d1802016-05-03 23:18:14 +0530662
663 /* App settings are not required for other than v1.0 SoC */
664 if (board_soc_version() > 0x10000) {
665 strlcpy(cmdline + len, " app_setting.use_app_setting=0", TARGET_MAX_CMDLNBUF - len);
666 len = strlen (cmdline);
667 }
Channagoud Kadabi85c7ec32016-01-28 23:09:21 -0800668 }
669
670 return len;
671}
anisha agarwalebc52bc2016-07-08 15:50:00 -0700672
673#if _APPEND_CMDLINE
674int get_target_boot_params(const char *cmdline, const char *part, char **buf)
675{
676 int system_ptn_index = -1;
677 unsigned int lun = 0;
678 char lun_char_base = 'a', lun_char_limit = 'h';
679
680 /*allocate buflen for largest possible string*/
681 uint32_t buflen = strlen(" root=/dev/mmcblock0p") + sizeof(int) + 1; /*1 character for null termination*/
682
683 if (!cmdline || !part ) {
684 dprintf(CRITICAL, "WARN: Invalid input param\n");
685 return -1;
686 }
687
688 system_ptn_index = partition_get_index(part);
689 if (system_ptn_index == -1)
690 {
691 dprintf(CRITICAL,"Unable to find partition %s\n",part);
692 return -1;
693 }
694
695 *buf = (char *)malloc(buflen);
696 if(!(*buf)) {
697 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
698 return -1;
699 }
700
701 /*
702 * check if cmdline contains "root="/"" at the beginning of buffer or
703 * " root="/"ubi.mtd" in the middle of buffer.
704 */
705 if ((strncmp(cmdline," root=",strlen(" root=")) == 0) ||
706 strstr(cmdline, " root="))
707 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
708 else
709 {
710 if (platform_boot_dev_isemmc()) {
711 snprintf(*buf, buflen, " root=/dev/mmcblock0p%d",
712 system_ptn_index + 1);
713 } else {
714 lun = partition_get_lun(system_ptn_index);
715 if ((lun_char_base + lun) > lun_char_limit) {
716 dprintf(CRITICAL, "lun value exceeds limit\n");
717 return -1;
718 }
719 snprintf(*buf, buflen, " root=/dev/sd%c%d",
720 lun_char_base + lun,
721 partition_get_index_in_lun(part, lun));
722 }
723 }
724 /*in success case buf will be freed in the calling function of this*/
725 return 0;
726}
727#endif