blob: e8189ccfda0178b376ca7655a809424a24698049 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
Casey Pipera277d882013-10-21 10:11:04 -07002 * Copyright (c) 2008 Travis Geiselbrecht
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07003 *
Umang Agrawal5990e742017-12-19 12:08:03 +05304 * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
lijuangc518f5d2015-02-10 10:22:53 +08005 *
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07006 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction,
9 * including without limitation the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25#include <err.h>
26#include <debug.h>
27#include <target.h>
28#include <compiler.h>
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +030029#include <dload_util.h>
Channagoud Kadabi41c81a62014-10-08 19:55:30 -070030#include <sdhci_msm.h>
Wufeng Jiang71246c22015-08-06 19:07:09 +080031#if PON_VIB_SUPPORT
Wufeng Jiang1ce072f2015-08-06 19:07:09 +080032#include <smem.h>
Wufeng Jiang71246c22015-08-06 19:07:09 +080033#include <vibrator.h>
34#include <board.h>
35#endif
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070036
lijuang3606df82015-09-02 21:14:43 +080037#include <smem.h>
38#include <pm8x41_adc.h>
39#include <pm8x41_hw.h>
lijuang395b5e62015-11-19 17:39:44 +080040#include <scm.h>
lijuang3606df82015-09-02 21:14:43 +080041
42#if CHECK_BAT_VOLTAGE
43#include <pm_fg_adc_usr.h>
44#endif
45
Mayank Grover204776b2017-09-06 10:59:21 +053046#if VERIFIED_BOOT
47#include <partition_parser.h>
48#include <ab_partition_parser.h>
49#endif
50
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -080051#define EXPAND(NAME) #NAME
52#define TARGET(NAME) EXPAND(NAME)
lijuang3606df82015-09-02 21:14:43 +080053
lijuang66192212015-09-22 10:25:48 +080054#define BATTERY_MIN_VOLTAGE 3200000 //uv
lijuang3606df82015-09-02 21:14:43 +080055#define PMIC_SLAVE_ID 0x20000
56#define BAT_IF_BAT_PRES_STATUS 0x1208
Mayank Grover3f20adf2017-07-03 16:33:22 +053057#define BAT_IF_INT_RT_STS 0x1210
58#define BATT_INFO_VBATT_LSB 0x41A0
59#define BATT_INFO_VBATT_MSB 0x41A1
Umang Agrawal5990e742017-12-19 12:08:03 +053060#define ADC_V_DATA_LSB 0x248C0
61#define ADC_V_DATA_MSB 0x248C1
Mayank Grover3f20adf2017-07-03 16:33:22 +053062#define BATT_VOLTAGE_NUMR 122070
Umang Agrawal5990e742017-12-19 12:08:03 +053063#define QGAUGE_VOLTAGE_NUMR 194637
Mayank Grover3f20adf2017-07-03 16:33:22 +053064#define BATT_VOLTAGE_DENR 1000
lijuang3606df82015-09-02 21:14:43 +080065
Mayank Grover204776b2017-09-06 10:59:21 +053066#if VERIFIED_BOOT
67static int vb_version = INVALID;
68#endif
Amol Jadi57abe4c2011-05-24 15:47:27 -070069/*
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070070 * default implementations of these routines, if the target code
71 * chooses not to implement.
72 */
73
74__WEAK void target_early_init(void)
75{
76}
77
78__WEAK void target_init(void)
79{
80}
81
David Ng3679bc52010-02-09 15:43:43 -080082__WEAK void *target_get_scratch_address(void)
83{
84 return (void *)(SCRATCH_ADDR);
85}
86
Vivek Mehta5f1c9d42011-04-01 20:11:59 -070087__WEAK unsigned target_get_max_flash_size(void)
88{
89 return (120 * 1024 * 1024);
90}
91
Tanya Brokhman1c94f1a2015-02-15 09:05:03 +020092__WEAK int flash_ubi_img(void)
93{
94 return 0;
95}
96
Tanya Brokhman84eaaf62015-02-24 21:57:06 +020097__WEAK int update_ubi_vol(void)
98{
99 return 0;
100}
101
David Ng183a7422009-12-07 14:55:21 -0800102__WEAK int target_is_emmc_boot(void)
103{
David Ng025c1d92009-12-09 23:46:00 -0800104#if _EMMC_BOOT
105 return 1;
106#else
David Ng183a7422009-12-07 14:55:21 -0800107 return 0;
David Ng025c1d92009-12-09 23:46:00 -0800108#endif
David Ng183a7422009-12-07 14:55:21 -0800109}
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800110
111__WEAK unsigned check_reboot_mode(void)
112{
113 return 0;
114}
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800115
lijuangc518f5d2015-02-10 10:22:53 +0800116__WEAK unsigned check_hard_reboot_mode(void)
117{
118 return 0;
119}
120
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800121__WEAK void reboot_device(unsigned reboot_reason)
122{
123}
Chandan Uddaraju7f5b9012010-02-06 16:37:48 -0800124
Matthew Qindefd5562014-07-11 18:02:40 +0800125__WEAK uint32_t is_user_force_reset(void)
126{
127 return 0;
128}
129
lijuang395b5e62015-11-19 17:39:44 +0800130__WEAK int set_download_mode(enum reboot_reason mode)
Pavel Nedev76a3e212013-05-09 10:37:21 +0300131{
lijuang395b5e62015-11-19 17:39:44 +0800132 if(mode == NORMAL_DLOAD || mode == EMERGENCY_DLOAD) {
133#if PLATFORM_USE_SCM_DLOAD
134 return scm_dload_mode(mode);
135#else
136 return -1;
137#endif
138 }
139
140 return 0;
Pavel Nedev76a3e212013-05-09 10:37:21 +0300141}
142
David Ngf773dde2010-07-26 19:55:08 -0700143__WEAK unsigned target_pause_for_battery_charge(void)
144{
145 return 0;
146}
Ajay Dudanid04110c2011-01-17 23:55:07 -0800147
148__WEAK unsigned target_baseband()
149{
150 return 0;
151}
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800152
153__WEAK void target_serialno(unsigned char *buf)
154{
Ajay Dudanif63d02f2011-10-01 08:29:53 -0700155 snprintf((char *) buf, 13, "%s",TARGET(BOARD));
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800156}
Amol Jadi57abe4c2011-05-24 15:47:27 -0700157
158__WEAK void target_fastboot_init()
159{
160}
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -0700161
162__WEAK int emmc_recovery_init(void)
163{
164 return 0;
165}
Shashank Mittalcd98d472011-08-02 14:29:24 -0700166
167__WEAK bool target_use_signed_kernel(void)
168{
169#if _SIGNED_KERNEL
170 return 1;
171#else
172 return 0;
173#endif
174}
Amol Jadi6834f1a2012-06-29 14:42:59 -0700175
Stanimir Varbanov8bc68c72013-07-08 18:22:04 +0300176__WEAK bool target_is_ssd_enabled(void)
177{
178#ifdef SSD_ENABLE
179 return 1;
180#else
181 return 0;
182#endif
183}
184
Stanimir Varbanov677001e2013-07-18 18:16:39 +0300185__WEAK void target_load_ssd_keystore(void)
186{
187}
Amol Jadi6834f1a2012-06-29 14:42:59 -0700188
189/* Default target does not support continuous splash screen feature. */
190__WEAK int target_cont_splash_screen()
191{
192 return 0;
193}
Amol Jadida118b92012-07-06 19:53:18 -0700194
195/* Default target specific initialization before using USB */
196__WEAK void target_usb_init(void)
197{
198}
199
200/* Default target specific usb shutdown */
201__WEAK void target_usb_stop(void)
202{
203}
Channagoud Kadabifa6179e2013-06-18 18:35:14 -0700204
205/* Default target specific target uninit */
206__WEAK void target_uninit(void)
207{
208}
Dhaval Patelcdcb6462013-07-18 14:46:57 -0700209
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530210__WEAK bool target_display_panel_node(char *pbuf, uint16_t buf_size)
Dhaval Patelcdcb6462013-07-18 14:46:57 -0700211{
212 return false;
213}
Channagoud Kadabi9fbdcdf2013-09-19 16:24:16 -0700214
Aravind Venkateswaran6385f7e2014-02-25 16:45:11 -0800215__WEAK void target_display_init(const char *panel_name)
Aravind Venkateswarandd50c1a2014-02-25 14:42:43 -0800216{
217}
218
219__WEAK void target_display_shutdown(void)
220{
221}
222
Casey Piperf8cebb62013-09-11 15:56:17 -0700223__WEAK uint8_t target_panel_auto_detect_enabled()
224{
225 return 0;
226}
227
Casey Piper48bfc0d2013-11-18 13:24:35 -0800228__WEAK uint8_t target_is_edp()
229{
230 return 0;
231}
232
Amol Jadi417c7f22013-10-07 12:52:21 -0700233/* default usb controller to be used. */
234__WEAK const char * target_usb_controller()
235{
236 return "ci";
237}
Amol Jadi9ff7bb52013-10-11 14:11:45 -0700238
239/* override for target specific usb phy reset. */
240__WEAK void target_usb_phy_reset(void)
241{
242}
Hanumant Singh8e1ac232014-01-29 13:41:51 -0800243
244/* determine if target is in warm boot. */
245__WEAK bool target_warm_boot(void)
246{
247 return false;
248}
Aparna Mallavarapu373d38b2014-05-23 14:47:19 +0530249
250/* Determine the HLOS subtype of the target */
251__WEAK uint32_t target_get_hlos_subtype(void)
252{
253 return 0;
254}
Channagoud Kadabi82cf5c62014-08-24 22:17:34 -0700255
256/* Initialize crypto parameters */
257__WEAK void target_crypto_init_params()
258{
259}
Channagoud Kadabi41c81a62014-10-08 19:55:30 -0700260
Parth Dixit550ddf32016-11-28 17:00:29 +0530261__WEAK bool target_is_pmi_enabled(void)
262{
263 return 1;
264}
265
Channagoud Kadabi41c81a62014-10-08 19:55:30 -0700266/* Default CFG delay value */
267__WEAK uint32_t target_ddr_cfg_val()
268{
269 return DDR_CONFIG_VAL;
270}
Channagoud Kadabi2021cef2015-02-25 12:08:32 -0800271
Parth Dixitff1928a2016-11-16 19:57:21 +0530272/* Default CFG register value */
273uint32_t target_ddr_cfg_reg()
274{
275 uint32_t platform = board_platform_id();
276 uint32_t ret = SDCC_HC_REG_DDR_CONFIG;
277
278 switch(platform)
279 {
280 case MSM8937:
281 case MSM8940:
282 case APQ8037:
283 case MSM8917:
284 case MSM8920:
285 case MSM8217:
286 case MSM8617:
287 case APQ8017:
288 case MSM8953:
289 case APQ8053:
Mayank Grover759e0b02017-04-11 11:59:06 +0530290 case SDM450:
Mayank Grover3dc285c2017-12-26 12:47:09 +0530291 case SDA450:
lijuang2f1c1f52017-12-12 14:44:32 +0800292 case SDM632:
293 case SDA632:
Parth Dixitff1928a2016-11-16 19:57:21 +0530294 /* SDCC HC DDR CONFIG has shifted by 4 bytes for these platform */
295 ret += 4;
296 break;
297 default:
298 break;
299 }
300 return ret;
301}
302
Mayank Grover204776b2017-09-06 10:59:21 +0530303#if VERIFIED_BOOT
304int target_get_vb_version()
305{
306 if (vb_version == INVALID)
307 {
Mayank Grover6edf5e12017-10-26 12:07:01 +0530308 /* Incase of keymaster present,verified boot for M version */
Mayank Grover204776b2017-09-06 10:59:21 +0530309 if (partition_get_index("keymaster") != INVALID_PTN)
Mayank Grover6edf5e12017-10-26 12:07:01 +0530310 vb_version = VB_M;
Mayank Grover204776b2017-09-06 10:59:21 +0530311 else
312 /* Incase keymaster is not present,
313 we use keystore for verification. */
Mayank Grover6edf5e12017-10-26 12:07:01 +0530314 vb_version = VB_L;
Mayank Grover204776b2017-09-06 10:59:21 +0530315 }
316 return vb_version;
317}
318#endif
319
AnilKumar Chimata29a19c32017-08-10 14:48:55 +0530320#if VERIFIED_BOOT_LE
321int verified_boot_le = 1;
322#else
323int verified_boot_le = 0;
324#endif
325
326int is_vb_le_enabled(void)
327{
328 uint32_t platform = board_platform_id();
329
330 switch(platform)
331 {
332 case APQ8053:
333 return verified_boot_le;
334 default:
335 break;
336 }
337 return 0;
338}
339
Wufeng Jiang71246c22015-08-06 19:07:09 +0800340#if PON_VIB_SUPPORT
Parth Dixit7f683712015-12-23 15:59:16 +0530341void get_vibration_type(struct qpnp_hap *config)
Wufeng Jiang71246c22015-08-06 19:07:09 +0800342{
Wufeng Jiang71246c22015-08-06 19:07:09 +0800343 uint32_t hw_id = board_hardware_id();
344 uint32_t platform = board_platform_id();
Parth Dixit7f683712015-12-23 15:59:16 +0530345
346 config->vib_type = VIB_ERM_TYPE;
347 config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_1c;
348 config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_04;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800349 switch(hw_id){
350 case HW_PLATFORM_MTP:
351 switch(platform){
352 case MSM8952:
Parth Dixit7f683712015-12-23 15:59:16 +0530353 config->vib_type = VIB_ERM_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800354 break;
355 case MSM8976:
vijay kumare9287242015-09-04 18:40:15 +0530356 case MSM8956:
357 case APQ8056:
Parth Dixit7f683712015-12-23 15:59:16 +0530358 config->vib_type = VIB_LRA_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800359 break;
Parth Dixit7f683712015-12-23 15:59:16 +0530360 case MSM8937:
Parth Dixitd71e4172016-05-17 14:59:54 +0530361 case MSM8940:
Parth Dixit7f683712015-12-23 15:59:16 +0530362 case APQ8037:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530363 case MSM8917:
Mayank Groverb093c932016-10-03 18:04:13 +0530364 case MSM8920:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530365 case MSM8217:
366 case MSM8617:
367 case APQ8017:
Gaurav Nebhwani6c945a42016-02-16 17:26:51 +0530368 case MSM8953:
369 case APQ8053:
Mayank Grover759e0b02017-04-11 11:59:06 +0530370 case SDM450:
Mayank Grover3dc285c2017-12-26 12:47:09 +0530371 case SDA450:
lijuang2f1c1f52017-12-12 14:44:32 +0800372 case SDM632:
373 case SDA632:
Parth Dixit7f683712015-12-23 15:59:16 +0530374 config->vib_type = VIB_LRA_TYPE;
375 config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_41;
376 config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_03;
Gaurav Nebhwani8e20d832016-02-12 15:07:58 +0530377 break;
vijay kumare9287242015-09-04 18:40:15 +0530378 default:
379 dprintf(CRITICAL,"Unsupported platform id\n");
380 break;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800381 }
382 break;
383 case HW_PLATFORM_QRD:
Parth Dixit7f683712015-12-23 15:59:16 +0530384 config->vib_type = VIB_ERM_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800385 break;
vijay kumare9287242015-09-04 18:40:15 +0530386 default:
Parth Dixit7f683712015-12-23 15:59:16 +0530387 dprintf(CRITICAL,"Unsupported hardware id\n");
vijay kumare9287242015-09-04 18:40:15 +0530388 break;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800389 }
Wufeng Jiang71246c22015-08-06 19:07:09 +0800390}
391#endif
392
Channagoud Kadabi2021cef2015-02-25 12:08:32 -0800393/* Return Build variant */
394__WEAK bool target_build_variant_user()
395{
396#if USER_BUILD_VARIANT
397 return true;
398#else
399 return false;
400#endif
401}
lijuang3606df82015-09-02 21:14:43 +0800402
403__WEAK uint32_t target_get_pmic()
404{
405 return PMIC_IS_UNKNOWN;
406}
407
Krishna Manikandan92affec2017-12-05 17:47:37 +0530408__WEAK bool is_display_disabled()
409{
410 return false;
411}
lijuang3606df82015-09-02 21:14:43 +0800412/* Check battery if it's exist */
413bool target_battery_is_present()
414{
415 bool batt_is_exist;
416 uint8_t value = 0;
417 uint32_t pmic;
418
419 pmic = target_get_pmic();
420
421 switch(pmic)
422 {
423 case PMIC_IS_PM8909:
424 case PMIC_IS_PM8916:
425 case PMIC_IS_PM8941:
426 value = REG_READ(BAT_IF_BAT_PRES_STATUS);
427 break;
428 case PMIC_IS_PMI8950:
429 case PMIC_IS_PMI8994:
430 case PMIC_IS_PMI8996:
Parth Dixit550ddf32016-11-28 17:00:29 +0530431 if(target_is_pmi_enabled())
432 {
433 value = REG_READ(PMIC_SLAVE_ID|
434 BAT_IF_BAT_PRES_STATUS);
435 }
lijuang3606df82015-09-02 21:14:43 +0800436 break;
Mayank Grover3f20adf2017-07-03 16:33:22 +0530437 case PMIC_IS_PM660:
438 value = REG_READ(BAT_IF_INT_RT_STS);
439 /* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4)
440 are set, battery is not present. */
441 if (value & (BIT(5) | BIT(4)))
442 return false;
443 else
444 return true;
445 break;
Umang Agrawal20127f32018-02-19 10:47:40 +0530446 case PMIC_IS_PMI632:
447 value = REG_READ(PMIC_SLAVE_ID|BAT_IF_INT_RT_STS);
448 /* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4)
449 are set, battery is not present. */
450 if (value & (BIT(5) | BIT(4)))
451 return false;
452 else
453 return true;
454 break;
lijuang3606df82015-09-02 21:14:43 +0800455 default:
456 dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
457 break;
458 }
459
460 batt_is_exist = value >> 7;
461
462 return batt_is_exist;
463
464}
465
466#if CHECK_BAT_VOLTAGE
467/* Return battery voltage */
468uint32_t target_get_battery_voltage()
469{
470 uint32_t pmic;
471 uint32_t vbat = 0;
Mayank Grover3f20adf2017-07-03 16:33:22 +0530472 uint8_t buff[2];
473 uint16_t temp;
lijuang3606df82015-09-02 21:14:43 +0800474
475 pmic = target_get_pmic();
476
477 switch(pmic)
478 {
479 case PMIC_IS_PM8909:
480 case PMIC_IS_PM8916:
481 case PMIC_IS_PM8941:
482 vbat = pm8x41_get_batt_voltage(); //uv
483 break;
484 case PMIC_IS_PMI8950:
485 case PMIC_IS_PMI8994:
486 case PMIC_IS_PMI8996:
Parth Dixit550ddf32016-11-28 17:00:29 +0530487 if(target_is_pmi_enabled())
488 {
489 if (!pm_fg_usr_get_vbat(1, &vbat)) {
490 vbat = vbat*1000; //uv
491 } else {
492 dprintf(CRITICAL, "ERROR: Get battery voltage failed!!!\n");
493 }
lijuang3606df82015-09-02 21:14:43 +0800494 }
495 break;
Mayank Grover3f20adf2017-07-03 16:33:22 +0530496 case PMIC_IS_PM660:
497 buff[0] = REG_READ(BATT_INFO_VBATT_LSB);
498 buff[1] = REG_READ(BATT_INFO_VBATT_MSB);
499 temp = buff[1] << 8 | buff[0];
500 /* {MSB,LSB} to decode the voltage level, refer register description. */
Umang Agrawal82efbba2017-12-19 14:51:02 +0530501 vbat = (((uint64_t)temp)*BATT_VOLTAGE_NUMR/BATT_VOLTAGE_DENR);
Mayank Grover3f20adf2017-07-03 16:33:22 +0530502 break;
Umang Agrawal5990e742017-12-19 12:08:03 +0530503 case PMIC_IS_PMI632:
504 buff[0] = REG_READ(ADC_V_DATA_LSB);
505 buff[1] = REG_READ(ADC_V_DATA_MSB);
506 temp = buff[1] << 8 | buff[0];
507 /* {MSB,LSB} to decode the voltage level, refer register description. */
508 vbat = (((uint64_t)temp)*QGAUGE_VOLTAGE_NUMR/BATT_VOLTAGE_DENR);
509 break;
lijuang3606df82015-09-02 21:14:43 +0800510 default:
511 dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
512 break;
513 }
514
515 return vbat;
516}
517
518/* Add safeguards such as refusing to flash if minimum battery levels
519 * are not present or be bypass if the device doesn't have a battery
520 */
521bool target_battery_soc_ok()
522{
523 if (!target_battery_is_present()) {
524 dprintf(INFO, "battery is not present\n");
525 return true;
526 }
527
528 if (target_get_battery_voltage() >= BATTERY_MIN_VOLTAGE)
529 return true;
530
531 return false;
532}
533#endif