blob: 57ef22f43cc28abae7ca41e1738168d2e12eca14 [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 *
Mayank Grover759e0b02017-04-11 11:59:06 +05304 * Copyright (c) 2015-2017, 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
60#define BATT_VOLTAGE_NUMR 122070
61#define BATT_VOLTAGE_DENR 1000
lijuang3606df82015-09-02 21:14:43 +080062
Mayank Grover204776b2017-09-06 10:59:21 +053063#if VERIFIED_BOOT
64static int vb_version = INVALID;
65#endif
Amol Jadi57abe4c2011-05-24 15:47:27 -070066/*
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070067 * default implementations of these routines, if the target code
68 * chooses not to implement.
69 */
70
71__WEAK void target_early_init(void)
72{
73}
74
75__WEAK void target_init(void)
76{
77}
78
David Ng3679bc52010-02-09 15:43:43 -080079__WEAK void *target_get_scratch_address(void)
80{
81 return (void *)(SCRATCH_ADDR);
82}
83
Vivek Mehta5f1c9d42011-04-01 20:11:59 -070084__WEAK unsigned target_get_max_flash_size(void)
85{
86 return (120 * 1024 * 1024);
87}
88
Tanya Brokhman1c94f1a2015-02-15 09:05:03 +020089__WEAK int flash_ubi_img(void)
90{
91 return 0;
92}
93
Tanya Brokhman84eaaf62015-02-24 21:57:06 +020094__WEAK int update_ubi_vol(void)
95{
96 return 0;
97}
98
David Ng183a7422009-12-07 14:55:21 -080099__WEAK int target_is_emmc_boot(void)
100{
David Ng025c1d92009-12-09 23:46:00 -0800101#if _EMMC_BOOT
102 return 1;
103#else
David Ng183a7422009-12-07 14:55:21 -0800104 return 0;
David Ng025c1d92009-12-09 23:46:00 -0800105#endif
David Ng183a7422009-12-07 14:55:21 -0800106}
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800107
108__WEAK unsigned check_reboot_mode(void)
109{
110 return 0;
111}
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800112
lijuangc518f5d2015-02-10 10:22:53 +0800113__WEAK unsigned check_hard_reboot_mode(void)
114{
115 return 0;
116}
117
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800118__WEAK void reboot_device(unsigned reboot_reason)
119{
120}
Chandan Uddaraju7f5b9012010-02-06 16:37:48 -0800121
Matthew Qindefd5562014-07-11 18:02:40 +0800122__WEAK uint32_t is_user_force_reset(void)
123{
124 return 0;
125}
126
lijuang395b5e62015-11-19 17:39:44 +0800127__WEAK int set_download_mode(enum reboot_reason mode)
Pavel Nedev76a3e212013-05-09 10:37:21 +0300128{
lijuang395b5e62015-11-19 17:39:44 +0800129 if(mode == NORMAL_DLOAD || mode == EMERGENCY_DLOAD) {
130#if PLATFORM_USE_SCM_DLOAD
131 return scm_dload_mode(mode);
132#else
133 return -1;
134#endif
135 }
136
137 return 0;
Pavel Nedev76a3e212013-05-09 10:37:21 +0300138}
139
David Ngf773dde2010-07-26 19:55:08 -0700140__WEAK unsigned target_pause_for_battery_charge(void)
141{
142 return 0;
143}
Ajay Dudanid04110c2011-01-17 23:55:07 -0800144
145__WEAK unsigned target_baseband()
146{
147 return 0;
148}
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800149
150__WEAK void target_serialno(unsigned char *buf)
151{
Ajay Dudanif63d02f2011-10-01 08:29:53 -0700152 snprintf((char *) buf, 13, "%s",TARGET(BOARD));
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800153}
Amol Jadi57abe4c2011-05-24 15:47:27 -0700154
155__WEAK void target_fastboot_init()
156{
157}
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -0700158
159__WEAK int emmc_recovery_init(void)
160{
161 return 0;
162}
Shashank Mittalcd98d472011-08-02 14:29:24 -0700163
164__WEAK bool target_use_signed_kernel(void)
165{
166#if _SIGNED_KERNEL
167 return 1;
168#else
169 return 0;
170#endif
171}
Amol Jadi6834f1a2012-06-29 14:42:59 -0700172
Stanimir Varbanov8bc68c72013-07-08 18:22:04 +0300173__WEAK bool target_is_ssd_enabled(void)
174{
175#ifdef SSD_ENABLE
176 return 1;
177#else
178 return 0;
179#endif
180}
181
Stanimir Varbanov677001e2013-07-18 18:16:39 +0300182__WEAK void target_load_ssd_keystore(void)
183{
184}
Amol Jadi6834f1a2012-06-29 14:42:59 -0700185
186/* Default target does not support continuous splash screen feature. */
187__WEAK int target_cont_splash_screen()
188{
189 return 0;
190}
Amol Jadida118b92012-07-06 19:53:18 -0700191
192/* Default target specific initialization before using USB */
193__WEAK void target_usb_init(void)
194{
195}
196
197/* Default target specific usb shutdown */
198__WEAK void target_usb_stop(void)
199{
200}
Channagoud Kadabifa6179e2013-06-18 18:35:14 -0700201
202/* Default target specific target uninit */
203__WEAK void target_uninit(void)
204{
205}
Dhaval Patelcdcb6462013-07-18 14:46:57 -0700206
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530207__WEAK bool target_display_panel_node(char *pbuf, uint16_t buf_size)
Dhaval Patelcdcb6462013-07-18 14:46:57 -0700208{
209 return false;
210}
Channagoud Kadabi9fbdcdf2013-09-19 16:24:16 -0700211
Aravind Venkateswaran6385f7e2014-02-25 16:45:11 -0800212__WEAK void target_display_init(const char *panel_name)
Aravind Venkateswarandd50c1a2014-02-25 14:42:43 -0800213{
214}
215
216__WEAK void target_display_shutdown(void)
217{
218}
219
Casey Piperf8cebb62013-09-11 15:56:17 -0700220__WEAK uint8_t target_panel_auto_detect_enabled()
221{
222 return 0;
223}
224
Casey Piper48bfc0d2013-11-18 13:24:35 -0800225__WEAK uint8_t target_is_edp()
226{
227 return 0;
228}
229
Amol Jadi417c7f22013-10-07 12:52:21 -0700230/* default usb controller to be used. */
231__WEAK const char * target_usb_controller()
232{
233 return "ci";
234}
Amol Jadi9ff7bb52013-10-11 14:11:45 -0700235
236/* override for target specific usb phy reset. */
237__WEAK void target_usb_phy_reset(void)
238{
239}
Hanumant Singh8e1ac232014-01-29 13:41:51 -0800240
241/* determine if target is in warm boot. */
242__WEAK bool target_warm_boot(void)
243{
244 return false;
245}
Aparna Mallavarapu373d38b2014-05-23 14:47:19 +0530246
247/* Determine the HLOS subtype of the target */
248__WEAK uint32_t target_get_hlos_subtype(void)
249{
250 return 0;
251}
Channagoud Kadabi82cf5c62014-08-24 22:17:34 -0700252
253/* Initialize crypto parameters */
254__WEAK void target_crypto_init_params()
255{
256}
Channagoud Kadabi41c81a62014-10-08 19:55:30 -0700257
Parth Dixit550ddf32016-11-28 17:00:29 +0530258__WEAK bool target_is_pmi_enabled(void)
259{
260 return 1;
261}
262
Channagoud Kadabi41c81a62014-10-08 19:55:30 -0700263/* Default CFG delay value */
264__WEAK uint32_t target_ddr_cfg_val()
265{
266 return DDR_CONFIG_VAL;
267}
Channagoud Kadabi2021cef2015-02-25 12:08:32 -0800268
Parth Dixitff1928a2016-11-16 19:57:21 +0530269/* Default CFG register value */
270uint32_t target_ddr_cfg_reg()
271{
272 uint32_t platform = board_platform_id();
273 uint32_t ret = SDCC_HC_REG_DDR_CONFIG;
274
275 switch(platform)
276 {
277 case MSM8937:
278 case MSM8940:
279 case APQ8037:
280 case MSM8917:
281 case MSM8920:
282 case MSM8217:
283 case MSM8617:
284 case APQ8017:
285 case MSM8953:
286 case APQ8053:
Mayank Grover759e0b02017-04-11 11:59:06 +0530287 case SDM450:
Parth Dixitff1928a2016-11-16 19:57:21 +0530288 /* SDCC HC DDR CONFIG has shifted by 4 bytes for these platform */
289 ret += 4;
290 break;
291 default:
292 break;
293 }
294 return ret;
295}
296
Mayank Grover204776b2017-09-06 10:59:21 +0530297#if VERIFIED_BOOT
298int target_get_vb_version()
299{
300 if (vb_version == INVALID)
301 {
Mayank Grover6edf5e12017-10-26 12:07:01 +0530302 /* Incase of keymaster present,verified boot for M version */
Mayank Grover204776b2017-09-06 10:59:21 +0530303 if (partition_get_index("keymaster") != INVALID_PTN)
Mayank Grover6edf5e12017-10-26 12:07:01 +0530304 vb_version = VB_M;
Mayank Grover204776b2017-09-06 10:59:21 +0530305 else
306 /* Incase keymaster is not present,
307 we use keystore for verification. */
Mayank Grover6edf5e12017-10-26 12:07:01 +0530308 vb_version = VB_L;
Mayank Grover204776b2017-09-06 10:59:21 +0530309 }
310 return vb_version;
311}
312#endif
313
AnilKumar Chimata29a19c32017-08-10 14:48:55 +0530314#if VERIFIED_BOOT_LE
315int verified_boot_le = 1;
316#else
317int verified_boot_le = 0;
318#endif
319
320int is_vb_le_enabled(void)
321{
322 uint32_t platform = board_platform_id();
323
324 switch(platform)
325 {
326 case APQ8053:
327 return verified_boot_le;
328 default:
329 break;
330 }
331 return 0;
332}
333
Wufeng Jiang71246c22015-08-06 19:07:09 +0800334#if PON_VIB_SUPPORT
Parth Dixit7f683712015-12-23 15:59:16 +0530335void get_vibration_type(struct qpnp_hap *config)
Wufeng Jiang71246c22015-08-06 19:07:09 +0800336{
Wufeng Jiang71246c22015-08-06 19:07:09 +0800337 uint32_t hw_id = board_hardware_id();
338 uint32_t platform = board_platform_id();
Parth Dixit7f683712015-12-23 15:59:16 +0530339
340 config->vib_type = VIB_ERM_TYPE;
341 config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_1c;
342 config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_04;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800343 switch(hw_id){
344 case HW_PLATFORM_MTP:
345 switch(platform){
346 case MSM8952:
Parth Dixit7f683712015-12-23 15:59:16 +0530347 config->vib_type = VIB_ERM_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800348 break;
349 case MSM8976:
vijay kumare9287242015-09-04 18:40:15 +0530350 case MSM8956:
351 case APQ8056:
Parth Dixit7f683712015-12-23 15:59:16 +0530352 config->vib_type = VIB_LRA_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800353 break;
Parth Dixit7f683712015-12-23 15:59:16 +0530354 case MSM8937:
Parth Dixitd71e4172016-05-17 14:59:54 +0530355 case MSM8940:
Parth Dixit7f683712015-12-23 15:59:16 +0530356 case APQ8037:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530357 case MSM8917:
Mayank Groverb093c932016-10-03 18:04:13 +0530358 case MSM8920:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530359 case MSM8217:
360 case MSM8617:
361 case APQ8017:
Gaurav Nebhwani6c945a42016-02-16 17:26:51 +0530362 case MSM8953:
363 case APQ8053:
Mayank Grover759e0b02017-04-11 11:59:06 +0530364 case SDM450:
Parth Dixit7f683712015-12-23 15:59:16 +0530365 config->vib_type = VIB_LRA_TYPE;
366 config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_41;
367 config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_03;
Gaurav Nebhwani8e20d832016-02-12 15:07:58 +0530368 break;
vijay kumare9287242015-09-04 18:40:15 +0530369 default:
370 dprintf(CRITICAL,"Unsupported platform id\n");
371 break;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800372 }
373 break;
374 case HW_PLATFORM_QRD:
Parth Dixit7f683712015-12-23 15:59:16 +0530375 config->vib_type = VIB_ERM_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800376 break;
vijay kumare9287242015-09-04 18:40:15 +0530377 default:
Parth Dixit7f683712015-12-23 15:59:16 +0530378 dprintf(CRITICAL,"Unsupported hardware id\n");
vijay kumare9287242015-09-04 18:40:15 +0530379 break;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800380 }
Wufeng Jiang71246c22015-08-06 19:07:09 +0800381}
382#endif
383
Channagoud Kadabi2021cef2015-02-25 12:08:32 -0800384/* Return Build variant */
385__WEAK bool target_build_variant_user()
386{
387#if USER_BUILD_VARIANT
388 return true;
389#else
390 return false;
391#endif
392}
lijuang3606df82015-09-02 21:14:43 +0800393
394__WEAK uint32_t target_get_pmic()
395{
396 return PMIC_IS_UNKNOWN;
397}
398
Krishna Manikandan92affec2017-12-05 17:47:37 +0530399__WEAK bool is_display_disabled()
400{
401 return false;
402}
lijuang3606df82015-09-02 21:14:43 +0800403/* Check battery if it's exist */
404bool target_battery_is_present()
405{
406 bool batt_is_exist;
407 uint8_t value = 0;
408 uint32_t pmic;
409
410 pmic = target_get_pmic();
411
412 switch(pmic)
413 {
414 case PMIC_IS_PM8909:
415 case PMIC_IS_PM8916:
416 case PMIC_IS_PM8941:
417 value = REG_READ(BAT_IF_BAT_PRES_STATUS);
418 break;
419 case PMIC_IS_PMI8950:
420 case PMIC_IS_PMI8994:
421 case PMIC_IS_PMI8996:
Parth Dixit550ddf32016-11-28 17:00:29 +0530422 if(target_is_pmi_enabled())
423 {
424 value = REG_READ(PMIC_SLAVE_ID|
425 BAT_IF_BAT_PRES_STATUS);
426 }
lijuang3606df82015-09-02 21:14:43 +0800427 break;
Mayank Grover3f20adf2017-07-03 16:33:22 +0530428 case PMIC_IS_PM660:
429 value = REG_READ(BAT_IF_INT_RT_STS);
430 /* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4)
431 are set, battery is not present. */
432 if (value & (BIT(5) | BIT(4)))
433 return false;
434 else
435 return true;
436 break;
lijuang3606df82015-09-02 21:14:43 +0800437 default:
438 dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
439 break;
440 }
441
442 batt_is_exist = value >> 7;
443
444 return batt_is_exist;
445
446}
447
448#if CHECK_BAT_VOLTAGE
449/* Return battery voltage */
450uint32_t target_get_battery_voltage()
451{
452 uint32_t pmic;
453 uint32_t vbat = 0;
Mayank Grover3f20adf2017-07-03 16:33:22 +0530454 uint8_t buff[2];
455 uint16_t temp;
lijuang3606df82015-09-02 21:14:43 +0800456
457 pmic = target_get_pmic();
458
459 switch(pmic)
460 {
461 case PMIC_IS_PM8909:
462 case PMIC_IS_PM8916:
463 case PMIC_IS_PM8941:
464 vbat = pm8x41_get_batt_voltage(); //uv
465 break;
466 case PMIC_IS_PMI8950:
467 case PMIC_IS_PMI8994:
468 case PMIC_IS_PMI8996:
Parth Dixit550ddf32016-11-28 17:00:29 +0530469 if(target_is_pmi_enabled())
470 {
471 if (!pm_fg_usr_get_vbat(1, &vbat)) {
472 vbat = vbat*1000; //uv
473 } else {
474 dprintf(CRITICAL, "ERROR: Get battery voltage failed!!!\n");
475 }
lijuang3606df82015-09-02 21:14:43 +0800476 }
477 break;
Mayank Grover3f20adf2017-07-03 16:33:22 +0530478 case PMIC_IS_PM660:
479 buff[0] = REG_READ(BATT_INFO_VBATT_LSB);
480 buff[1] = REG_READ(BATT_INFO_VBATT_MSB);
481 temp = buff[1] << 8 | buff[0];
482 /* {MSB,LSB} to decode the voltage level, refer register description. */
483 vbat = (((uint32_t)temp)*BATT_VOLTAGE_NUMR/BATT_VOLTAGE_DENR);
484 break;
lijuang3606df82015-09-02 21:14:43 +0800485 default:
486 dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
487 break;
488 }
489
490 return vbat;
491}
492
493/* Add safeguards such as refusing to flash if minimum battery levels
494 * are not present or be bypass if the device doesn't have a battery
495 */
496bool target_battery_soc_ok()
497{
498 if (!target_battery_is_present()) {
499 dprintf(INFO, "battery is not present\n");
500 return true;
501 }
502
503 if (target_get_battery_voltage() >= BATTERY_MIN_VOLTAGE)
504 return true;
505
506 return false;
507}
508#endif