blob: 539d98d35c1923b3edcd64b2911e3c7f7500a73d [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>
Vijay Kumar Pendotie1fff022016-05-04 13:04:32 +053047#include <pm8x41_hw.h>
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070048#include <crypto5_wrapper.h>
49#include <clock.h>
50#include <partition_parser.h>
51#include <scm.h>
52#include <platform/clock.h>
53#include <platform/gpio.h>
54#include <platform/timer.h>
55#include <stdlib.h>
56#include <ufs.h>
57#include <boot_device.h>
58#include <qmp_phy.h>
Channagoud Kadabi7d308202014-12-22 12:07:04 -080059#include <sdhci_msm.h>
60#include <qusb2_phy.h>
Sridhar Parasuram568e7a62015-08-06 13:16:02 -070061#include <secapp_loader.h>
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -080062#include <rpmb.h>
Sridhar Parasuram9f28f672015-03-17 15:40:47 -070063#include <rpm-glink.h>
Channagoud Kadabibb8f1f92015-04-27 11:14:45 -070064#if ENABLE_WBC
65#include <pm_app_smbchg.h>
66#endif
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070067
c_wufengf433f232015-09-21 15:21:21 +080068#if LONG_PRESS_POWER_ON
69#include <shutdown_detect.h>
70#endif
71
c_wufeng196210d2015-09-21 12:49:43 +080072#if PON_VIB_SUPPORT
73#include <vibrator.h>
74#define VIBRATE_TIME 250
75#endif
c_wufengf433f232015-09-21 15:21:21 +080076
Channagoud Kadabi9b28c0b2016-01-11 18:42:33 -080077#include <pm_smbchg_usb_chgpth.h>
78
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -080079#define CE_INSTANCE 1
Channagoud Kadabi7edb9b42015-08-11 23:45:31 -070080#define CE_EE 0
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -080081#define CE_FIFO_SIZE 64
82#define CE_READ_PIPE 3
83#define CE_WRITE_PIPE 2
84#define CE_READ_PIPE_LOCK_GRP 0
85#define CE_WRITE_PIPE_LOCK_GRP 0
86#define CE_ARRAY_SIZE 20
87
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070088#define PMIC_ARB_CHANNEL_NUM 0
89#define PMIC_ARB_OWNER_ID 0
90
Vijay Kumar Pendotie1fff022016-05-04 13:04:32 +053091#define SMBCHG_USB_RT_STS 0x21310
92#define SMBCHG_DC_RT_STS 0x21410
93#define USBIN_UV_RT_STS BIT(0)
94#define USBIN_OV_RT_STS BIT(1)
95#define DCIN_UV_RT_STS BIT(0)
96#define DCIN_OV_RT_STS BIT(1)
97
Channagoud Kadabi4021fa92015-11-03 16:35:26 -080098enum
99{
100 FUSION_I2S_MTP = 1,
101 FUSION_SLIMBUS = 2,
102} mtp_subtype;
103
104enum
105{
106 FUSION_I2S_CDP = 2,
107} cdp_subtype;
108
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300109static uint8_t flash_memory_slot = 0;
110static void set_sdc_power_ctrl();
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700111static uint32_t mmc_pwrctl_base[] =
112 { MSM_SDC1_BASE, MSM_SDC2_BASE };
113
114static uint32_t mmc_sdhci_base[] =
115 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
116
117static uint32_t mmc_sdc_pwrctl_irq[] =
118 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
119
120struct mmc_device *dev;
121struct ufs_dev ufs_device;
122
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700123void target_early_init(void)
124{
125#if WITH_DEBUG_UART
Channagoud Kadabi35503c42014-11-14 16:22:43 -0800126 uart_dm_init(8, 0, BLSP2_UART1_BASE);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700127#endif
128}
129
130/* Return 1 if vol_up pressed */
Amit Blay6a3e88b2015-06-23 22:25:06 +0300131int target_volume_up()
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700132{
lijuang2d2b8a02015-06-05 21:34:15 +0800133 static uint8_t first_time = 0;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700134 uint8_t status = 0;
135 struct pm8x41_gpio gpio;
136
lijuang2d2b8a02015-06-05 21:34:15 +0800137 if (!first_time) {
138 /* Configure the GPIO */
139 gpio.direction = PM_GPIO_DIR_IN;
140 gpio.function = 0;
141 gpio.pull = PM_GPIO_PULL_UP_30;
142 gpio.vin_sel = 2;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700143
lijuang2d2b8a02015-06-05 21:34:15 +0800144 pm8x41_gpio_config(2, &gpio);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700145
lijuang2d2b8a02015-06-05 21:34:15 +0800146 /* Wait for the pmic gpio config to take effect */
147 udelay(10000);
148
149 first_time = 1;
150 }
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700151
152 /* Get status of P_GPIO_5 */
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800153 pm8x41_gpio_get(2, &status);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700154
155 return !status; /* active low */
156}
157
158/* Return 1 if vol_down pressed */
159uint32_t target_volume_down()
160{
161 return pm8x41_resin_status();
162}
163
164static void target_keystatus()
165{
166 keys_init();
167
168 if(target_volume_down())
169 keys_post_event(KEY_VOLUMEDOWN, 1);
170
171 if(target_volume_up())
172 keys_post_event(KEY_VOLUMEUP, 1);
173}
174
175void target_uninit(void)
176{
177 if (platform_boot_dev_isemmc())
178 {
179 mmc_put_card_to_sleep(dev);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700180 }
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -0800181
182 if (is_sec_app_loaded())
183 {
Sridhar Parasuram568e7a62015-08-06 13:16:02 -0700184 if (send_milestone_call_to_tz() < 0)
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -0800185 {
186 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
187 ASSERT(0);
188 }
189 }
190
Channagoud Kadabibb8f1f92015-04-27 11:14:45 -0700191#if ENABLE_WBC
Channagoud Kadabi22165612015-07-22 14:04:37 -0700192 if (board_hardware_id() == HW_PLATFORM_MTP)
193 pm_appsbl_set_dcin_suspend(1);
Channagoud Kadabibb8f1f92015-04-27 11:14:45 -0700194#endif
195
Channagoud Kadabi7edb9b42015-08-11 23:45:31 -0700196
197 if (crypto_initialized())
198 {
199 crypto_eng_cleanup();
200 clock_ce_disable(CE_INSTANCE);
201 }
202
Sridhar Parasuram9f28f672015-03-17 15:40:47 -0700203 /* Tear down glink channels */
204 rpm_glink_uninit();
205
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -0800206 if (rpmb_uninit() < 0)
207 {
208 dprintf(CRITICAL, "RPMB uninit failed\n");
209 ASSERT(0);
210 }
211
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700212}
213
214static void set_sdc_power_ctrl()
215{
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300216 uint32_t reg = 0;
217 uint8_t clk = 0;
218 uint8_t cmd = 0;
219 uint8_t dat = 0;
220
221 if (flash_memory_slot == 0x1)
222 {
223 clk = TLMM_CUR_VAL_10MA;
224 cmd = TLMM_CUR_VAL_8MA;
225 dat = TLMM_CUR_VAL_8MA;
226 reg = SDC1_HDRV_PULL_CTL;
227 }
228 else if (flash_memory_slot == 0x2)
229 {
230 clk = TLMM_CUR_VAL_16MA;
231 cmd = TLMM_CUR_VAL_10MA;
232 dat = TLMM_CUR_VAL_10MA;
233 reg = SDC2_HDRV_PULL_CTL;
234 }
235
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700236 /* Drive strength configs for sdc pins */
237 struct tlmm_cfgs sdc1_hdrv_cfg[] =
238 {
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300239 { SDC1_CLK_HDRV_CTL_OFF, clk, TLMM_HDRV_MASK, reg },
240 { SDC1_CMD_HDRV_CTL_OFF, cmd, TLMM_HDRV_MASK, reg },
241 { SDC1_DATA_HDRV_CTL_OFF, dat, TLMM_HDRV_MASK, reg },
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700242 };
243
244 /* Pull configs for sdc pins */
245 struct tlmm_cfgs sdc1_pull_cfg[] =
246 {
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300247 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, reg },
248 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg },
249 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg },
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700250 };
251
252 struct tlmm_cfgs sdc1_rclk_cfg[] =
253 {
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300254 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, reg },
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700255 };
256
257 /* Set the drive strength & pull control values */
258 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
259 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
260 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
261}
262
c_wufengf433f232015-09-21 15:21:21 +0800263uint32_t target_is_pwrkey_pon_reason()
264{
265 uint8_t pon_reason = pm8950_get_pon_reason();
Vijay Kumar Pendotie1fff022016-05-04 13:04:32 +0530266
c_wufengf433f232015-09-21 15:21:21 +0800267 if (pm8x41_get_is_cold_boot() && ((pon_reason == KPDPWR_N) || (pon_reason == (KPDPWR_N|PON1))))
268 return 1;
Vijay Kumar Pendotie1fff022016-05-04 13:04:32 +0530269 else if (pon_reason == PON1)
270 {
271 /* DC charger is present or USB charger is present */
272 if (((USBIN_UV_RT_STS | USBIN_OV_RT_STS) & pm8x41_reg_read(SMBCHG_USB_RT_STS)) == 0 ||
273 ((DCIN_UV_RT_STS | DCIN_OV_RT_STS) & pm8x41_reg_read(SMBCHG_DC_RT_STS)) == 0)
274 return 0;
275 else
276 return 1;
277 }
c_wufengf433f232015-09-21 15:21:21 +0800278 else
279 return 0;
280}
281
282
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700283void target_sdc_init()
284{
285 struct mmc_config_data config = {0};
286
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700287 config.bus_width = DATA_BUS_WIDTH_8BIT;
288 config.max_clk_rate = MMC_CLK_192MHZ;
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800289 config.hs400_support = 1;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700290
291 /* Try slot 1*/
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300292 flash_memory_slot = 1;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700293 config.slot = 1;
294 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
295 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
296 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
297
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300298 /* Set drive strength & pull ctrl values */
299 set_sdc_power_ctrl();
300
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700301 if (!(dev = mmc_init(&config)))
302 {
303 /* Try slot 2 */
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300304 flash_memory_slot = 2;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700305 config.slot = 2;
306 config.max_clk_rate = MMC_CLK_200MHZ;
307 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
308 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
309 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
310
Tanya Finkel619fc2a2016-08-16 14:11:26 +0300311 /* Set drive strength & pull ctrl values */
312 set_sdc_power_ctrl();
313
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700314 if (!(dev = mmc_init(&config)))
315 {
316 dprintf(CRITICAL, "mmc init failed!");
317 ASSERT(0);
318 }
319 }
320}
321
322void *target_mmc_device()
323{
324 if (platform_boot_dev_isemmc())
325 return (void *) dev;
326 else
327 return (void *) &ufs_device;
328}
329
330void target_init(void)
331{
Sridhar Parasuram568e7a62015-08-06 13:16:02 -0700332 int ret = 0;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700333 dprintf(INFO, "target_init()\n");
334
Sridhar Parasuram1d224322015-06-15 11:03:40 -0700335 pmic_info_populate();
336
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700337 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
338
Channagoud Kadabibb8f1f92015-04-27 11:14:45 -0700339 /* Initialize Glink */
340 rpm_glink_init();
341
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700342 target_keystatus();
343
c_wufengf433f232015-09-21 15:21:21 +0800344#if defined(LONG_PRESS_POWER_ON) || defined(PON_VIB_SUPPORT)
345 switch(board_hardware_id())
346 {
347 case HW_PLATFORM_QRD:
348#if LONG_PRESS_POWER_ON
349 shutdown_detect();
350#endif
c_wufeng196210d2015-09-21 12:49:43 +0800351#if PON_VIB_SUPPORT
352 vib_timed_turn_on(VIBRATE_TIME);
353#endif
c_wufengf433f232015-09-21 15:21:21 +0800354 break;
355 }
356#endif
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700357
358 if (target_use_signed_kernel())
359 target_crypto_init_params();
360
361 platform_read_boot_config();
362
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800363#ifdef MMC_SDHCI_SUPPORT
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700364 if (platform_boot_dev_isemmc())
365 {
366 target_sdc_init();
367 }
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800368#endif
369#ifdef UFS_SUPPORT
370 if (!platform_boot_dev_isemmc())
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700371 {
372 ufs_device.base = UFS_BASE;
373 ufs_init(&ufs_device);
374 }
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800375#endif
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700376
377 /* Storage initialization is complete, read the partition table info */
Channagoud Kadabi58a273b2015-02-10 12:56:22 -0800378 mmc_read_partition_table(0);
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -0800379
Channagoud Kadabi1171d8d2015-07-30 19:12:44 -0700380#if ENABLE_WBC
381 /* Look for battery voltage and make sure we have enough to bootup
382 * Otherwise initiate battery charging
383 * Charging should happen as early as possible, any other driver
384 * initialization before this should consider the power impact
385 */
Channagoud Kadabi25fd8ce2015-08-19 14:45:08 -0700386 switch(board_hardware_id())
387 {
388 case HW_PLATFORM_MTP:
389 case HW_PLATFORM_FLUID:
lijuang0e98add2015-11-10 10:40:27 +0800390 case HW_PLATFORM_QRD:
Parth Dixit550ddf32016-11-28 17:00:29 +0530391 if(target_is_pmi_enabled())
392 pm_appsbl_chg_check_weak_battery_status(1);
Channagoud Kadabi25fd8ce2015-08-19 14:45:08 -0700393 break;
394 default:
395 /* Charging not supported */
396 break;
397 };
Channagoud Kadabi1171d8d2015-07-30 19:12:44 -0700398#endif
399
Sridhar Parasuram568e7a62015-08-06 13:16:02 -0700400 /* Initialize Qseecom */
401 ret = qseecom_init();
402
403 if (ret < 0)
404 {
405 dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret);
406 ASSERT(0);
407 }
408
409 /* Start Qseecom */
410 ret = qseecom_tz_init();
411
412 if (ret < 0)
413 {
414 dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret);
415 ASSERT(0);
416 }
417
Sridhar Parasuramc61ecc22015-09-22 13:53:31 -0700418 if (rpmb_init() < 0)
419 {
420 dprintf(CRITICAL, "RPMB init failed\n");
421 ASSERT(0);
422 }
423
Sridhar Parasuram568e7a62015-08-06 13:16:02 -0700424 /*
425 * Load the sec app for first time
426 */
427 if (load_sec_app() < 0)
428 {
429 dprintf(CRITICAL, "Failed to load App for verified\n");
430 ASSERT(0);
431 }
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700432}
433
434unsigned board_machtype(void)
435{
436 return LINUX_MACHTYPE_UNKNOWN;
437}
438
439/* Detect the target type */
440void target_detect(struct board_data *board)
441{
442 /* This is filled from board.c */
443}
444
Dhaval Patelb95039c2015-03-16 11:14:06 -0700445static uint8_t splash_override;
446/* Returns 1 if target supports continuous splash screen. */
447int target_cont_splash_screen()
448{
449 uint8_t splash_screen = 0;
Channagoud Kadabi25fd8ce2015-08-19 14:45:08 -0700450 if(!splash_override && !pm_appsbl_charging_in_progress()) {
Dhaval Patelb95039c2015-03-16 11:14:06 -0700451 switch(board_hardware_id())
452 {
453 case HW_PLATFORM_SURF:
454 case HW_PLATFORM_MTP:
455 case HW_PLATFORM_FLUID:
feifanz76fe6482015-09-02 15:25:16 +0800456 case HW_PLATFORM_QRD:
Kuogee Hsiehb976dfc2015-08-28 13:21:30 -0700457 case HW_PLATFORM_LIQUID:
Siddharth Zaveriacaacc32015-12-12 15:10:33 -0500458 case HW_PLATFORM_DRAGON:
459 case HW_PLATFORM_ADP:
Dhaval Patelb95039c2015-03-16 11:14:06 -0700460 dprintf(SPEW, "Target_cont_splash=1\n");
461 splash_screen = 1;
462 break;
463 default:
464 dprintf(SPEW, "Target_cont_splash=0\n");
465 splash_screen = 0;
466 }
467 }
468 return splash_screen;
469}
470
471void target_force_cont_splash_disable(uint8_t override)
472{
473 splash_override = override;
474}
475
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700476/* Detect the modem type */
477void target_baseband_detect(struct board_data *board)
478{
479 uint32_t platform;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800480 uint32_t platform_hardware;
481 uint32_t platform_subtype;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700482
483 platform = board->platform;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800484 platform_hardware = board->platform_hw;
485 platform_subtype = board->platform_subtype;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700486
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800487 if (platform_hardware == HW_PLATFORM_SURF)
488 {
489 if (platform_subtype == FUSION_I2S_CDP)
490 board->baseband = BASEBAND_MDM;
491 }
492 else if (platform_hardware == HW_PLATFORM_MTP)
493 {
494 if (platform_subtype == FUSION_I2S_MTP ||
495 platform_subtype == FUSION_SLIMBUS)
496 board->baseband = BASEBAND_MDM;
497 }
498 /*
499 * Special case if MDM is not set look for chip info to decide
500 * platform subtype
501 */
502 if (board->baseband != BASEBAND_MDM)
503 {
504 switch(platform) {
505 case APQ8096:
Channagoud Kadabiee2b65e2016-01-11 19:10:29 -0800506 case APQ8096AU:
507 case APQ8096SG:
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800508 board->baseband = BASEBAND_APQ;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800509 break;
510 case MSM8996:
Channagoud Kadabiee2b65e2016-01-11 19:10:29 -0800511 case MSM8996SG:
512 case MSM8996AU:
513 case MSM8996L:
514 board->baseband = BASEBAND_MSM;
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800515 break;
516 default:
517 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
518 ASSERT(0);
519 };
520 }
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700521}
Channagoud Kadabi4021fa92015-11-03 16:35:26 -0800522
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700523unsigned target_baseband()
524{
525 return board_baseband();
526}
527
528void target_serialno(unsigned char *buf)
529{
530 unsigned int serialno;
531 if (target_is_emmc_boot()) {
532 serialno = mmc_get_psn();
533 snprintf((char *)buf, 13, "%x", serialno);
534 }
535}
536
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700537int emmc_recovery_init(void)
538{
539 return _emmc_recovery_init();
540}
541
542void target_usb_phy_reset()
543{
544 usb30_qmp_phy_reset();
545 qusb2_phy_reset();
546}
547
Tanya Finkel77318e02016-05-17 14:20:59 +0300548void target_usb_phy_sec_reset()
549{
550 qusb2_phy_reset();
551}
552
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700553target_usb_iface_t* target_usb30_init()
554{
555 target_usb_iface_t *t_usb_iface;
556
557 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
558 ASSERT(t_usb_iface);
559
Tanya Finkel77318e02016-05-17 14:20:59 +0300560
561 /* for SBC we use secondary port */
562 if (board_hardware_id() == HW_PLATFORM_SBC)
563 {
564 /* secondary port have no QMP phy,use only QUSB2 phy that have only reset */
565 t_usb_iface->phy_init = NULL;
566 t_usb_iface->phy_reset = target_usb_phy_sec_reset;
567 t_usb_iface->clock_init = clock_usb20_init;
568 } else {
569 t_usb_iface->phy_init = usb30_qmp_phy_init;
570 t_usb_iface->phy_reset = target_usb_phy_reset;
571 t_usb_iface->clock_init = clock_usb30_init;
572 }
573
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700574 t_usb_iface->vbus_override = 1;
575
576 return t_usb_iface;
577}
578
579/* identify the usb controller to be used for the target */
580const char * target_usb_controller()
581{
582 return "dwc";
583}
584
585uint32_t target_override_pll()
586{
Channagoud Kadabi1e5144b2015-04-28 17:15:05 -0700587 if (board_soc_version() >= 0x20000)
588 return 0;
589 else
590 return 1;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700591}
592
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -0800593crypto_engine_type board_ce_type(void)
594{
Channagoud Kadabi7edb9b42015-08-11 23:45:31 -0700595 return CRYPTO_ENGINE_TYPE_HW;
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -0800596}
597
598/* Set up params for h/w CE. */
599void target_crypto_init_params()
600{
601 struct crypto_init_params ce_params;
602
603 /* Set up base addresses and instance. */
604 ce_params.crypto_instance = CE_INSTANCE;
605 ce_params.crypto_base = MSM_CE_BASE;
606 ce_params.bam_base = MSM_CE_BAM_BASE;
607
608 /* Set up BAM config. */
609 ce_params.bam_ee = CE_EE;
610 ce_params.pipes.read_pipe = CE_READ_PIPE;
611 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
612 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
613 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
614
615 /* Assign buffer sizes. */
616 ce_params.num_ce = CE_ARRAY_SIZE;
617 ce_params.read_fifo_size = CE_FIFO_SIZE;
618 ce_params.write_fifo_size = CE_FIFO_SIZE;
619
620 /* BAM is initialized by TZ for this platform.
621 * Do not do it again as the initialization address space
622 * is locked.
623 */
624 ce_params.do_bam_init = 0;
625
626 crypto_init_params(&ce_params);
627}
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700628
629unsigned target_pause_for_battery_charge(void)
630{
631 uint8_t pon_reason = pm8x41_get_pon_reason();
632 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
Channagoud Kadabi9b28c0b2016-01-11 18:42:33 -0800633 pm_smbchg_usb_chgpth_pwr_pth_type charger_path = PM_SMBCHG_USB_CHGPTH_PWR_PATH__INVALID;
634 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d charger path: %d\n", __func__,
635 pon_reason, is_cold_boot, charger_path);
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700636 /* In case of fastboot reboot,adb reboot or if we see the power key
637 * pressed we do not want go into charger mode.
638 * fastboot reboot is warm boot with PON hard reset bit not set
639 * adb reboot is a cold boot with PON hard reset bit set
640 */
Channagoud Kadabi9b28c0b2016-01-11 18:42:33 -0800641 pm_smbchg_get_charger_path(1, &charger_path);
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700642 if (is_cold_boot &&
643 (!(pon_reason & HARD_RST)) &&
644 (!(pon_reason & KPDPWR_N)) &&
Channagoud Kadabi9b28c0b2016-01-11 18:42:33 -0800645 ((pon_reason & PON1)) &&
646 ((charger_path == PM_SMBCHG_USB_CHGPTH_PWR_PATH__DC_CHARGER) ||
647 (charger_path == PM_SMBCHG_USB_CHGPTH_PWR_PATH__USB_CHARGER)))
648
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700649 return 1;
650 else
651 return 0;
652}
Channagoud Kadabi23edc0c2015-03-27 18:31:32 -0700653
lijuang395b5e62015-11-19 17:39:44 +0800654int set_download_mode(enum reboot_reason mode)
Channagoud Kadabi23edc0c2015-03-27 18:31:32 -0700655{
656 int ret = 0;
657 ret = scm_dload_mode(mode);
658
659 return ret;
660}
Channagoud Kadabiffc4b902015-06-25 23:14:27 -0700661
Channagoud Kadabi65b518d2015-08-05 16:17:14 -0700662void pmic_reset_configure(uint8_t reset_type)
Channagoud Kadabiffc4b902015-06-25 23:14:27 -0700663{
Channagoud Kadabi65b518d2015-08-05 16:17:14 -0700664 pm8994_reset_configure(reset_type);
Channagoud Kadabiffc4b902015-06-25 23:14:27 -0700665}
lijuang3606df82015-09-02 21:14:43 +0800666
667uint32_t target_get_pmic()
668{
669 return PMIC_IS_PMI8996;
670}
Channagoud Kadabi85c7ec32016-01-28 23:09:21 -0800671
672int target_update_cmdline(char *cmdline)
673{
674 uint32_t platform_id = board_platform_id();
675 int len = 0;
676 if (platform_id == APQ8096SG || platform_id == MSM8996SG)
677 {
678 strlcpy(cmdline, " fpsimd.fpsimd_settings=0", TARGET_MAX_CMDLNBUF);
679 len = strlen (cmdline);
Prasad Sodagudid76d1802016-05-03 23:18:14 +0530680
681 /* App settings are not required for other than v1.0 SoC */
682 if (board_soc_version() > 0x10000) {
683 strlcpy(cmdline + len, " app_setting.use_app_setting=0", TARGET_MAX_CMDLNBUF - len);
684 len = strlen (cmdline);
685 }
Channagoud Kadabi85c7ec32016-01-28 23:09:21 -0800686 }
687
688 return len;
689}
anisha agarwalebc52bc2016-07-08 15:50:00 -0700690
691#if _APPEND_CMDLINE
692int get_target_boot_params(const char *cmdline, const char *part, char **buf)
693{
694 int system_ptn_index = -1;
695 unsigned int lun = 0;
696 char lun_char_base = 'a', lun_char_limit = 'h';
697
698 /*allocate buflen for largest possible string*/
699 uint32_t buflen = strlen(" root=/dev/mmcblock0p") + sizeof(int) + 1; /*1 character for null termination*/
700
701 if (!cmdline || !part ) {
702 dprintf(CRITICAL, "WARN: Invalid input param\n");
703 return -1;
704 }
705
706 system_ptn_index = partition_get_index(part);
707 if (system_ptn_index == -1)
708 {
709 dprintf(CRITICAL,"Unable to find partition %s\n",part);
710 return -1;
711 }
712
713 *buf = (char *)malloc(buflen);
714 if(!(*buf)) {
715 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
716 return -1;
717 }
718
719 /*
720 * check if cmdline contains "root="/"" at the beginning of buffer or
721 * " root="/"ubi.mtd" in the middle of buffer.
722 */
723 if ((strncmp(cmdline," root=",strlen(" root=")) == 0) ||
724 strstr(cmdline, " root="))
725 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
726 else
727 {
728 if (platform_boot_dev_isemmc()) {
729 snprintf(*buf, buflen, " root=/dev/mmcblock0p%d",
730 system_ptn_index + 1);
731 } else {
732 lun = partition_get_lun(system_ptn_index);
733 if ((lun_char_base + lun) > lun_char_limit) {
734 dprintf(CRITICAL, "lun value exceeds limit\n");
735 return -1;
736 }
737 snprintf(*buf, buflen, " root=/dev/sd%c%d",
738 lun_char_base + lun,
739 partition_get_index_in_lun(part, lun));
740 }
741 }
742 /*in success case buf will be freed in the calling function of this*/
743 return 0;
744}
745#endif