blob: dc3186d1931ccc89c8533bb8dd3e5ac1a7155846 [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:
Channagoud Kadabi25fd8ce2015-08-19 14:45:08 -0700373 pm_appsbl_chg_check_weak_battery_status(1);
374 break;
375 default:
376 /* Charging not supported */
377 break;
378 };
Channagoud Kadabi1171d8d2015-07-30 19:12:44 -0700379#endif
380
Sridhar Parasuram568e7a62015-08-06 13:16:02 -0700381 /* Initialize Qseecom */
382 ret = qseecom_init();
383
384 if (ret < 0)
385 {
386 dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret);
387 ASSERT(0);
388 }
389
390 /* Start Qseecom */
391 ret = qseecom_tz_init();
392
393 if (ret < 0)
394 {
395 dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret);
396 ASSERT(0);
397 }
398
Sridhar Parasuramc61ecc22015-09-22 13:53:31 -0700399 if (rpmb_init() < 0)
400 {
401 dprintf(CRITICAL, "RPMB init failed\n");
402 ASSERT(0);
403 }
404
Sridhar Parasuram568e7a62015-08-06 13:16:02 -0700405 /*
406 * Load the sec app for first time
407 */
408 if (load_sec_app() < 0)
409 {
410 dprintf(CRITICAL, "Failed to load App for verified\n");
411 ASSERT(0);
412 }
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700413}
414
415unsigned board_machtype(void)
416{
417 return LINUX_MACHTYPE_UNKNOWN;
418}
419
420/* Detect the target type */
421void target_detect(struct board_data *board)
422{
423 /* This is filled from board.c */
424}
425
Dhaval Patelb95039c2015-03-16 11:14:06 -0700426static uint8_t splash_override;
427/* Returns 1 if target supports continuous splash screen. */
428int target_cont_splash_screen()
429{
430 uint8_t splash_screen = 0;
Channagoud Kadabi25fd8ce2015-08-19 14:45:08 -0700431 if(!splash_override && !pm_appsbl_charging_in_progress()) {
Dhaval Patelb95039c2015-03-16 11:14:06 -0700432 switch(board_hardware_id())
433 {
434 case HW_PLATFORM_SURF:
435 case HW_PLATFORM_MTP:
436 case HW_PLATFORM_FLUID:
feifanz76fe6482015-09-02 15:25:16 +0800437 case HW_PLATFORM_QRD:
Kuogee Hsiehb976dfc2015-08-28 13:21:30 -0700438 case HW_PLATFORM_LIQUID:
Siddharth Zaveriacaacc32015-12-12 15:10:33 -0500439 case HW_PLATFORM_DRAGON:
440 case HW_PLATFORM_ADP:
Dhaval Patelb95039c2015-03-16 11:14:06 -0700441 dprintf(SPEW, "Target_cont_splash=1\n");
442 splash_screen = 1;
443 break;
444 default:
445 dprintf(SPEW, "Target_cont_splash=0\n");
446 splash_screen = 0;
447 }
448 }
449 return splash_screen;
450}
451
452void target_force_cont_splash_disable(uint8_t override)
453{
454 splash_override = override;
455}
456
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700457/* Detect the modem type */
458void target_baseband_detect(struct board_data *board)
459{
460 uint32_t platform;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800461 uint32_t platform_hardware;
462 uint32_t platform_subtype;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700463
464 platform = board->platform;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800465 platform_hardware = board->platform_hw;
466 platform_subtype = board->platform_subtype;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700467
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800468 if (platform_hardware == HW_PLATFORM_SURF)
469 {
470 if (platform_subtype == FUSION_I2S_CDP)
471 board->baseband = BASEBAND_MDM;
472 }
473 else if (platform_hardware == HW_PLATFORM_MTP)
474 {
475 if (platform_subtype == FUSION_I2S_MTP ||
476 platform_subtype == FUSION_SLIMBUS)
477 board->baseband = BASEBAND_MDM;
478 }
479 /*
480 * Special case if MDM is not set look for chip info to decide
481 * platform subtype
482 */
483 if (board->baseband != BASEBAND_MDM)
484 {
485 switch(platform) {
486 case APQ8096:
Channagoud Kadabiee2b65e2016-01-11 19:10:29 -0800487 case APQ8096AU:
488 case APQ8096SG:
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800489 board->baseband = BASEBAND_APQ;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800490 break;
491 case MSM8996:
Channagoud Kadabiee2b65e2016-01-11 19:10:29 -0800492 case MSM8996SG:
493 case MSM8996AU:
494 case MSM8996L:
495 board->baseband = BASEBAND_MSM;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800496 break;
497 default:
498 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
499 ASSERT(0);
500 };
501 }
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700502}
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800503
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700504unsigned target_baseband()
505{
506 return board_baseband();
507}
508
509void target_serialno(unsigned char *buf)
510{
511 unsigned int serialno;
512 if (target_is_emmc_boot()) {
513 serialno = mmc_get_psn();
514 snprintf((char *)buf, 13, "%x", serialno);
515 }
516}
517
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700518int emmc_recovery_init(void)
519{
520 return _emmc_recovery_init();
521}
522
523void target_usb_phy_reset()
524{
525 usb30_qmp_phy_reset();
526 qusb2_phy_reset();
527}
528
Tanya Finkel77318e02016-05-17 14:20:59 +0300529void target_usb_phy_sec_reset()
530{
531 qusb2_phy_reset();
532}
533
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700534target_usb_iface_t* target_usb30_init()
535{
536 target_usb_iface_t *t_usb_iface;
537
538 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
539 ASSERT(t_usb_iface);
540
Tanya Finkel77318e02016-05-17 14:20:59 +0300541
542 /* for SBC we use secondary port */
543 if (board_hardware_id() == HW_PLATFORM_SBC)
544 {
545 /* secondary port have no QMP phy,use only QUSB2 phy that have only reset */
546 t_usb_iface->phy_init = NULL;
547 t_usb_iface->phy_reset = target_usb_phy_sec_reset;
548 t_usb_iface->clock_init = clock_usb20_init;
549 } else {
550 t_usb_iface->phy_init = usb30_qmp_phy_init;
551 t_usb_iface->phy_reset = target_usb_phy_reset;
552 t_usb_iface->clock_init = clock_usb30_init;
553 }
554
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700555 t_usb_iface->vbus_override = 1;
556
557 return t_usb_iface;
558}
559
560/* identify the usb controller to be used for the target */
561const char * target_usb_controller()
562{
563 return "dwc";
564}
565
566uint32_t target_override_pll()
567{
Channagoud Kadabi1e5144b2015-04-28 17:15:05 -0700568 if (board_soc_version() >= 0x20000)
569 return 0;
570 else
571 return 1;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700572}
573
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -0800574crypto_engine_type board_ce_type(void)
575{
Channagoud Kadabi7edb9b42015-08-11 23:45:31 -0700576 return CRYPTO_ENGINE_TYPE_HW;
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -0800577}
578
579/* Set up params for h/w CE. */
580void target_crypto_init_params()
581{
582 struct crypto_init_params ce_params;
583
584 /* Set up base addresses and instance. */
585 ce_params.crypto_instance = CE_INSTANCE;
586 ce_params.crypto_base = MSM_CE_BASE;
587 ce_params.bam_base = MSM_CE_BAM_BASE;
588
589 /* Set up BAM config. */
590 ce_params.bam_ee = CE_EE;
591 ce_params.pipes.read_pipe = CE_READ_PIPE;
592 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
593 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
594 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
595
596 /* Assign buffer sizes. */
597 ce_params.num_ce = CE_ARRAY_SIZE;
598 ce_params.read_fifo_size = CE_FIFO_SIZE;
599 ce_params.write_fifo_size = CE_FIFO_SIZE;
600
601 /* BAM is initialized by TZ for this platform.
602 * Do not do it again as the initialization address space
603 * is locked.
604 */
605 ce_params.do_bam_init = 0;
606
607 crypto_init_params(&ce_params);
608}
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700609
610unsigned target_pause_for_battery_charge(void)
611{
612 uint8_t pon_reason = pm8x41_get_pon_reason();
613 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
Channagoud Kadabi9b28c0b2016-01-11 18:42:33 -0800614 pm_smbchg_usb_chgpth_pwr_pth_type charger_path = PM_SMBCHG_USB_CHGPTH_PWR_PATH__INVALID;
615 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d charger path: %d\n", __func__,
616 pon_reason, is_cold_boot, charger_path);
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700617 /* In case of fastboot reboot,adb reboot or if we see the power key
618 * pressed we do not want go into charger mode.
619 * fastboot reboot is warm boot with PON hard reset bit not set
620 * adb reboot is a cold boot with PON hard reset bit set
621 */
Channagoud Kadabi9b28c0b2016-01-11 18:42:33 -0800622 pm_smbchg_get_charger_path(1, &charger_path);
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700623 if (is_cold_boot &&
624 (!(pon_reason & HARD_RST)) &&
625 (!(pon_reason & KPDPWR_N)) &&
Channagoud Kadabi9b28c0b2016-01-11 18:42:33 -0800626 ((pon_reason & PON1)) &&
627 ((charger_path == PM_SMBCHG_USB_CHGPTH_PWR_PATH__DC_CHARGER) ||
628 (charger_path == PM_SMBCHG_USB_CHGPTH_PWR_PATH__USB_CHARGER)))
629
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700630 return 1;
631 else
632 return 0;
633}
Channagoud Kadabi23edc0c2015-03-27 18:31:32 -0700634
lijuang395b5e62015-11-19 17:39:44 +0800635int set_download_mode(enum reboot_reason mode)
Channagoud Kadabi23edc0c2015-03-27 18:31:32 -0700636{
637 int ret = 0;
638 ret = scm_dload_mode(mode);
639
640 return ret;
641}
Channagoud Kadabiffc4b902015-06-25 23:14:27 -0700642
Channagoud Kadabi65b518d2015-08-05 16:17:14 -0700643void pmic_reset_configure(uint8_t reset_type)
Channagoud Kadabiffc4b902015-06-25 23:14:27 -0700644{
Channagoud Kadabi65b518d2015-08-05 16:17:14 -0700645 pm8994_reset_configure(reset_type);
Channagoud Kadabiffc4b902015-06-25 23:14:27 -0700646}
lijuang3606df82015-09-02 21:14:43 +0800647
648uint32_t target_get_pmic()
649{
650 return PMIC_IS_PMI8996;
651}
Channagoud Kadabi85c7ec32016-01-28 23:09:21 -0800652
653int target_update_cmdline(char *cmdline)
654{
655 uint32_t platform_id = board_platform_id();
656 int len = 0;
657 if (platform_id == APQ8096SG || platform_id == MSM8996SG)
658 {
659 strlcpy(cmdline, " fpsimd.fpsimd_settings=0", TARGET_MAX_CMDLNBUF);
660 len = strlen (cmdline);
Prasad Sodagudid76d1802016-05-03 23:18:14 +0530661
662 /* App settings are not required for other than v1.0 SoC */
663 if (board_soc_version() > 0x10000) {
664 strlcpy(cmdline + len, " app_setting.use_app_setting=0", TARGET_MAX_CMDLNBUF - len);
665 len = strlen (cmdline);
666 }
Channagoud Kadabi85c7ec32016-01-28 23:09:21 -0800667 }
668
669 return len;
670}
anisha agarwalebc52bc2016-07-08 15:50:00 -0700671
672#if _APPEND_CMDLINE
673int get_target_boot_params(const char *cmdline, const char *part, char **buf)
674{
675 int system_ptn_index = -1;
676 unsigned int lun = 0;
677 char lun_char_base = 'a', lun_char_limit = 'h';
678
679 /*allocate buflen for largest possible string*/
680 uint32_t buflen = strlen(" root=/dev/mmcblock0p") + sizeof(int) + 1; /*1 character for null termination*/
681
682 if (!cmdline || !part ) {
683 dprintf(CRITICAL, "WARN: Invalid input param\n");
684 return -1;
685 }
686
687 system_ptn_index = partition_get_index(part);
688 if (system_ptn_index == -1)
689 {
690 dprintf(CRITICAL,"Unable to find partition %s\n",part);
691 return -1;
692 }
693
694 *buf = (char *)malloc(buflen);
695 if(!(*buf)) {
696 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
697 return -1;
698 }
699
700 /*
701 * check if cmdline contains "root="/"" at the beginning of buffer or
702 * " root="/"ubi.mtd" in the middle of buffer.
703 */
704 if ((strncmp(cmdline," root=",strlen(" root=")) == 0) ||
705 strstr(cmdline, " root="))
706 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
707 else
708 {
709 if (platform_boot_dev_isemmc()) {
710 snprintf(*buf, buflen, " root=/dev/mmcblock0p%d",
711 system_ptn_index + 1);
712 } else {
713 lun = partition_get_lun(system_ptn_index);
714 if ((lun_char_base + lun) > lun_char_limit) {
715 dprintf(CRITICAL, "lun value exceeds limit\n");
716 return -1;
717 }
718 snprintf(*buf, buflen, " root=/dev/sd%c%d",
719 lun_char_base + lun,
720 partition_get_index_in_lun(part, lun));
721 }
722 }
723 /*in success case buf will be freed in the calling function of this*/
724 return 0;
725}
726#endif