blob: bb4015540a5cf09e35d4d79ccf0ba7cb54064d90 [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 Grover7ba3baa2019-04-25 11:56:13 +05304 * Copyright (c) 2015-2019, 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
Monika Singhaec24f02018-03-14 09:05:46 +053046#if VERIFIED_BOOT || VERIFIED_BOOT_2
Monika Singhe7a2aa62018-04-13 11:40:55 +053047#include <partition_parser.h>
Mayank Grover204776b2017-09-06 10:59:21 +053048#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
Monika Singhaec24f02018-03-14 09:05:46 +053065#define INVALID -1
Mayank Grover204776b2017-09-06 10:59:21 +053066static int vb_version = INVALID;
Monika Singhaec24f02018-03-14 09:05:46 +053067
Amol Jadi57abe4c2011-05-24 15:47:27 -070068/*
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070069 * default implementations of these routines, if the target code
70 * chooses not to implement.
71 */
72
73__WEAK void target_early_init(void)
74{
75}
76
77__WEAK void target_init(void)
78{
79}
80
David Ng3679bc52010-02-09 15:43:43 -080081__WEAK void *target_get_scratch_address(void)
82{
83 return (void *)(SCRATCH_ADDR);
84}
85
Vivek Mehta5f1c9d42011-04-01 20:11:59 -070086__WEAK unsigned target_get_max_flash_size(void)
87{
88 return (120 * 1024 * 1024);
89}
90
Tanya Brokhman1c94f1a2015-02-15 09:05:03 +020091__WEAK int flash_ubi_img(void)
92{
93 return 0;
94}
95
Tanya Brokhman84eaaf62015-02-24 21:57:06 +020096__WEAK int update_ubi_vol(void)
97{
98 return 0;
99}
100
David Ng183a7422009-12-07 14:55:21 -0800101__WEAK int target_is_emmc_boot(void)
102{
David Ng025c1d92009-12-09 23:46:00 -0800103#if _EMMC_BOOT
104 return 1;
105#else
David Ng183a7422009-12-07 14:55:21 -0800106 return 0;
David Ng025c1d92009-12-09 23:46:00 -0800107#endif
David Ng183a7422009-12-07 14:55:21 -0800108}
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800109
110__WEAK unsigned check_reboot_mode(void)
111{
112 return 0;
113}
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800114
lijuangc518f5d2015-02-10 10:22:53 +0800115__WEAK unsigned check_hard_reboot_mode(void)
116{
117 return 0;
118}
119
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800120__WEAK void reboot_device(unsigned reboot_reason)
121{
122}
Chandan Uddaraju7f5b9012010-02-06 16:37:48 -0800123
Matthew Qindefd5562014-07-11 18:02:40 +0800124__WEAK uint32_t is_user_force_reset(void)
125{
126 return 0;
127}
128
lijuang395b5e62015-11-19 17:39:44 +0800129__WEAK int set_download_mode(enum reboot_reason mode)
Pavel Nedev76a3e212013-05-09 10:37:21 +0300130{
lijuang395b5e62015-11-19 17:39:44 +0800131 if(mode == NORMAL_DLOAD || mode == EMERGENCY_DLOAD) {
132#if PLATFORM_USE_SCM_DLOAD
133 return scm_dload_mode(mode);
134#else
135 return -1;
136#endif
137 }
138
139 return 0;
Pavel Nedev76a3e212013-05-09 10:37:21 +0300140}
141
David Ngf773dde2010-07-26 19:55:08 -0700142__WEAK unsigned target_pause_for_battery_charge(void)
143{
144 return 0;
145}
Ajay Dudanid04110c2011-01-17 23:55:07 -0800146
147__WEAK unsigned target_baseband()
148{
149 return 0;
150}
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800151
152__WEAK void target_serialno(unsigned char *buf)
153{
Ajay Dudanif63d02f2011-10-01 08:29:53 -0700154 snprintf((char *) buf, 13, "%s",TARGET(BOARD));
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800155}
Amol Jadi57abe4c2011-05-24 15:47:27 -0700156
157__WEAK void target_fastboot_init()
158{
159}
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -0700160
161__WEAK int emmc_recovery_init(void)
162{
163 return 0;
164}
Shashank Mittalcd98d472011-08-02 14:29:24 -0700165
166__WEAK bool target_use_signed_kernel(void)
167{
168#if _SIGNED_KERNEL
169 return 1;
170#else
171 return 0;
172#endif
173}
Amol Jadi6834f1a2012-06-29 14:42:59 -0700174
Stanimir Varbanov8bc68c72013-07-08 18:22:04 +0300175__WEAK bool target_is_ssd_enabled(void)
176{
177#ifdef SSD_ENABLE
178 return 1;
179#else
180 return 0;
181#endif
182}
183
Stanimir Varbanov677001e2013-07-18 18:16:39 +0300184__WEAK void target_load_ssd_keystore(void)
185{
186}
Amol Jadi6834f1a2012-06-29 14:42:59 -0700187
188/* Default target does not support continuous splash screen feature. */
189__WEAK int target_cont_splash_screen()
190{
191 return 0;
192}
Amol Jadida118b92012-07-06 19:53:18 -0700193
194/* Default target specific initialization before using USB */
195__WEAK void target_usb_init(void)
196{
197}
198
199/* Default target specific usb shutdown */
200__WEAK void target_usb_stop(void)
201{
202}
Channagoud Kadabifa6179e2013-06-18 18:35:14 -0700203
204/* Default target specific target uninit */
205__WEAK void target_uninit(void)
206{
207}
Dhaval Patelcdcb6462013-07-18 14:46:57 -0700208
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530209__WEAK bool target_display_panel_node(char *pbuf, uint16_t buf_size)
Dhaval Patelcdcb6462013-07-18 14:46:57 -0700210{
211 return false;
212}
Channagoud Kadabi9fbdcdf2013-09-19 16:24:16 -0700213
Aravind Venkateswaran6385f7e2014-02-25 16:45:11 -0800214__WEAK void target_display_init(const char *panel_name)
Aravind Venkateswarandd50c1a2014-02-25 14:42:43 -0800215{
216}
217
218__WEAK void target_display_shutdown(void)
219{
220}
221
Casey Piperf8cebb62013-09-11 15:56:17 -0700222__WEAK uint8_t target_panel_auto_detect_enabled()
223{
224 return 0;
225}
226
Casey Piper48bfc0d2013-11-18 13:24:35 -0800227__WEAK uint8_t target_is_edp()
228{
229 return 0;
230}
231
Amol Jadi417c7f22013-10-07 12:52:21 -0700232/* default usb controller to be used. */
233__WEAK const char * target_usb_controller()
234{
235 return "ci";
236}
Amol Jadi9ff7bb52013-10-11 14:11:45 -0700237
238/* override for target specific usb phy reset. */
239__WEAK void target_usb_phy_reset(void)
240{
241}
Hanumant Singh8e1ac232014-01-29 13:41:51 -0800242
243/* determine if target is in warm boot. */
244__WEAK bool target_warm_boot(void)
245{
246 return false;
247}
Aparna Mallavarapu373d38b2014-05-23 14:47:19 +0530248
249/* Determine the HLOS subtype of the target */
250__WEAK uint32_t target_get_hlos_subtype(void)
251{
252 return 0;
253}
Channagoud Kadabi82cf5c62014-08-24 22:17:34 -0700254
255/* Initialize crypto parameters */
256__WEAK void target_crypto_init_params()
257{
258}
Channagoud Kadabi41c81a62014-10-08 19:55:30 -0700259
Parth Dixit550ddf32016-11-28 17:00:29 +0530260__WEAK bool target_is_pmi_enabled(void)
261{
262 return 1;
263}
264
Channagoud Kadabi41c81a62014-10-08 19:55:30 -0700265/* Default CFG delay value */
266__WEAK uint32_t target_ddr_cfg_val()
267{
268 return DDR_CONFIG_VAL;
269}
Channagoud Kadabi2021cef2015-02-25 12:08:32 -0800270
Mayank Grovere8a534f2018-05-09 12:06:17 +0530271/* Target uses system as root */
272bool target_uses_system_as_root(void)
273{
274#if TARGET_USE_SYSTEM_AS_ROOT_IMAGE
275 if (target_get_vb_version() >= VB_M)
276 return true;
277#endif
278 return false;
279}
280
Mayank Grover7ba3baa2019-04-25 11:56:13 +0530281/* Check dynamic partition support is enabled for target */
282bool target_dynamic_partition_supported(void)
283{
284#if DYNAMIC_PARTITION_SUPPORT
285 return true;
286#else
287 return false;
288#endif
289}
290
Parth Dixitff1928a2016-11-16 19:57:21 +0530291/* Default CFG register value */
292uint32_t target_ddr_cfg_reg()
293{
294 uint32_t platform = board_platform_id();
295 uint32_t ret = SDCC_HC_REG_DDR_CONFIG;
296
297 switch(platform)
298 {
299 case MSM8937:
300 case MSM8940:
301 case APQ8037:
302 case MSM8917:
303 case MSM8920:
304 case MSM8217:
305 case MSM8617:
306 case APQ8017:
307 case MSM8953:
308 case APQ8053:
Mayank Grover759e0b02017-04-11 11:59:06 +0530309 case SDM450:
Mayank Grover3dc285c2017-12-26 12:47:09 +0530310 case SDA450:
lijuang2f1c1f52017-12-12 14:44:32 +0800311 case SDM632:
312 case SDA632:
lijuangf6563682018-04-04 20:26:52 +0800313 case SDM429:
314 case SDM439:
lijuang5c8797d2018-04-23 19:10:16 +0800315 case SDA429:
316 case SDA439:
lijuang5c1f4682018-10-09 19:37:36 +0800317 case QM215:
Nagireddy Annemb2d8e9a2019-09-06 17:54:29 +0530318 case QCM2150:
Parth Dixitff1928a2016-11-16 19:57:21 +0530319 /* SDCC HC DDR CONFIG has shifted by 4 bytes for these platform */
320 ret += 4;
321 break;
322 default:
323 break;
324 }
325 return ret;
326}
Monika Singhe7a2aa62018-04-13 11:40:55 +0530327#if VERIFIED_BOOT || VERIFIED_BOOT_2
Mayank Grover204776b2017-09-06 10:59:21 +0530328int target_get_vb_version()
329{
330 if (vb_version == INVALID)
331 {
Mayank Grover6edf5e12017-10-26 12:07:01 +0530332 /* Incase of keymaster present,verified boot for M version */
Mayank Grover204776b2017-09-06 10:59:21 +0530333 if (partition_get_index("keymaster") != INVALID_PTN)
Mayank Grover6edf5e12017-10-26 12:07:01 +0530334 vb_version = VB_M;
Mayank Grover204776b2017-09-06 10:59:21 +0530335 else
336 /* Incase keymaster is not present,
337 we use keystore for verification. */
Mayank Grover6edf5e12017-10-26 12:07:01 +0530338 vb_version = VB_L;
Mayank Grover204776b2017-09-06 10:59:21 +0530339 }
340 return vb_version;
341}
Monika Singhe7a2aa62018-04-13 11:40:55 +0530342#else
343int target_get_vb_version()
344{
345 return vb_version;
346}
347#endif
Mayank Grover204776b2017-09-06 10:59:21 +0530348
AnilKumar Chimata29a19c32017-08-10 14:48:55 +0530349#if VERIFIED_BOOT_LE
350int verified_boot_le = 1;
351#else
352int verified_boot_le = 0;
353#endif
354
355int is_vb_le_enabled(void)
356{
357 uint32_t platform = board_platform_id();
358
359 switch(platform)
360 {
361 case APQ8053:
Mohamed Sunfeer199bde02018-07-24 13:47:50 +0530362 case APQ8009:
AnilKumar Chimata29a19c32017-08-10 14:48:55 +0530363 return verified_boot_le;
364 default:
365 break;
366 }
367 return 0;
368}
369
Wufeng Jiang71246c22015-08-06 19:07:09 +0800370#if PON_VIB_SUPPORT
Parth Dixit7f683712015-12-23 15:59:16 +0530371void get_vibration_type(struct qpnp_hap *config)
Wufeng Jiang71246c22015-08-06 19:07:09 +0800372{
Wufeng Jiang71246c22015-08-06 19:07:09 +0800373 uint32_t hw_id = board_hardware_id();
374 uint32_t platform = board_platform_id();
Parth Dixit7f683712015-12-23 15:59:16 +0530375
376 config->vib_type = VIB_ERM_TYPE;
377 config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_1c;
378 config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_04;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800379 switch(hw_id){
380 case HW_PLATFORM_MTP:
381 switch(platform){
382 case MSM8952:
Parth Dixit7f683712015-12-23 15:59:16 +0530383 config->vib_type = VIB_ERM_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800384 break;
385 case MSM8976:
vijay kumare9287242015-09-04 18:40:15 +0530386 case MSM8956:
387 case APQ8056:
Parth Dixit7f683712015-12-23 15:59:16 +0530388 config->vib_type = VIB_LRA_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800389 break;
Parth Dixit7f683712015-12-23 15:59:16 +0530390 case MSM8937:
Parth Dixitd71e4172016-05-17 14:59:54 +0530391 case MSM8940:
Parth Dixit7f683712015-12-23 15:59:16 +0530392 case APQ8037:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530393 case MSM8917:
Mayank Groverb093c932016-10-03 18:04:13 +0530394 case MSM8920:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530395 case MSM8217:
396 case MSM8617:
397 case APQ8017:
Gaurav Nebhwani6c945a42016-02-16 17:26:51 +0530398 case MSM8953:
399 case APQ8053:
Mayank Grover759e0b02017-04-11 11:59:06 +0530400 case SDM450:
Mayank Grover3dc285c2017-12-26 12:47:09 +0530401 case SDA450:
lijuang2f1c1f52017-12-12 14:44:32 +0800402 case SDM632:
403 case SDA632:
lijuangf6563682018-04-04 20:26:52 +0800404 case SDM429:
405 case SDM439:
lijuang5c8797d2018-04-23 19:10:16 +0800406 case SDA429:
407 case SDA439:
lijuang5c1f4682018-10-09 19:37:36 +0800408 case QM215:
Nagireddy Annemb2d8e9a2019-09-06 17:54:29 +0530409 case QCM2150:
Umang Agrawalfa9614a2019-05-22 12:05:46 +0530410 case SDM429W:
Parth Dixit7f683712015-12-23 15:59:16 +0530411 config->vib_type = VIB_LRA_TYPE;
412 config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_41;
413 config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_03;
Gaurav Nebhwani8e20d832016-02-12 15:07:58 +0530414 break;
vijay kumare9287242015-09-04 18:40:15 +0530415 default:
416 dprintf(CRITICAL,"Unsupported platform id\n");
417 break;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800418 }
419 break;
420 case HW_PLATFORM_QRD:
Parth Dixit7f683712015-12-23 15:59:16 +0530421 config->vib_type = VIB_ERM_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800422 break;
vijay kumare9287242015-09-04 18:40:15 +0530423 default:
Parth Dixit7f683712015-12-23 15:59:16 +0530424 dprintf(CRITICAL,"Unsupported hardware id\n");
vijay kumare9287242015-09-04 18:40:15 +0530425 break;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800426 }
Wufeng Jiang71246c22015-08-06 19:07:09 +0800427}
428#endif
429
Channagoud Kadabi2021cef2015-02-25 12:08:32 -0800430/* Return Build variant */
431__WEAK bool target_build_variant_user()
432{
433#if USER_BUILD_VARIANT
434 return true;
435#else
436 return false;
437#endif
438}
lijuang3606df82015-09-02 21:14:43 +0800439
440__WEAK uint32_t target_get_pmic()
441{
442 return PMIC_IS_UNKNOWN;
443}
444
Krishna Manikandan92affec2017-12-05 17:47:37 +0530445__WEAK bool is_display_disabled()
446{
447 return false;
448}
lijuang3606df82015-09-02 21:14:43 +0800449/* Check battery if it's exist */
450bool target_battery_is_present()
451{
452 bool batt_is_exist;
453 uint8_t value = 0;
454 uint32_t pmic;
455
456 pmic = target_get_pmic();
457
458 switch(pmic)
459 {
460 case PMIC_IS_PM8909:
461 case PMIC_IS_PM8916:
462 case PMIC_IS_PM8941:
463 value = REG_READ(BAT_IF_BAT_PRES_STATUS);
464 break;
465 case PMIC_IS_PMI8950:
466 case PMIC_IS_PMI8994:
467 case PMIC_IS_PMI8996:
Parth Dixit550ddf32016-11-28 17:00:29 +0530468 if(target_is_pmi_enabled())
469 {
470 value = REG_READ(PMIC_SLAVE_ID|
471 BAT_IF_BAT_PRES_STATUS);
472 }
lijuang3606df82015-09-02 21:14:43 +0800473 break;
Mayank Grover3f20adf2017-07-03 16:33:22 +0530474 case PMIC_IS_PM660:
475 value = REG_READ(BAT_IF_INT_RT_STS);
476 /* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4)
477 are set, battery is not present. */
478 if (value & (BIT(5) | BIT(4)))
479 return false;
480 else
481 return true;
482 break;
Umang Agrawal20127f32018-02-19 10:47:40 +0530483 case PMIC_IS_PMI632:
484 value = REG_READ(PMIC_SLAVE_ID|BAT_IF_INT_RT_STS);
485 /* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4)
486 are set, battery is not present. */
487 if (value & (BIT(5) | BIT(4)))
488 return false;
489 else
490 return true;
491 break;
lijuang3606df82015-09-02 21:14:43 +0800492 default:
493 dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
494 break;
495 }
496
497 batt_is_exist = value >> 7;
498
499 return batt_is_exist;
500
501}
502
Jiten Patel4f6c74b2018-08-29 16:34:56 +0530503bool is_target_support_dtbo(void)
504{
505#if TARGET_DTBO_NOT_SUPPORTED
506 return false;
507#else
508 return true;
509#endif
510}
511
lijuang3606df82015-09-02 21:14:43 +0800512#if CHECK_BAT_VOLTAGE
513/* Return battery voltage */
514uint32_t target_get_battery_voltage()
515{
516 uint32_t pmic;
517 uint32_t vbat = 0;
Mayank Grover3f20adf2017-07-03 16:33:22 +0530518 uint8_t buff[2];
519 uint16_t temp;
lijuang3606df82015-09-02 21:14:43 +0800520
521 pmic = target_get_pmic();
522
523 switch(pmic)
524 {
525 case PMIC_IS_PM8909:
526 case PMIC_IS_PM8916:
527 case PMIC_IS_PM8941:
528 vbat = pm8x41_get_batt_voltage(); //uv
529 break;
530 case PMIC_IS_PMI8950:
531 case PMIC_IS_PMI8994:
532 case PMIC_IS_PMI8996:
Parth Dixit550ddf32016-11-28 17:00:29 +0530533 if(target_is_pmi_enabled())
534 {
535 if (!pm_fg_usr_get_vbat(1, &vbat)) {
536 vbat = vbat*1000; //uv
537 } else {
538 dprintf(CRITICAL, "ERROR: Get battery voltage failed!!!\n");
539 }
lijuang3606df82015-09-02 21:14:43 +0800540 }
541 break;
Mayank Grover3f20adf2017-07-03 16:33:22 +0530542 case PMIC_IS_PM660:
543 buff[0] = REG_READ(BATT_INFO_VBATT_LSB);
544 buff[1] = REG_READ(BATT_INFO_VBATT_MSB);
545 temp = buff[1] << 8 | buff[0];
546 /* {MSB,LSB} to decode the voltage level, refer register description. */
Umang Agrawal82efbba2017-12-19 14:51:02 +0530547 vbat = (((uint64_t)temp)*BATT_VOLTAGE_NUMR/BATT_VOLTAGE_DENR);
Mayank Grover3f20adf2017-07-03 16:33:22 +0530548 break;
Umang Agrawal5990e742017-12-19 12:08:03 +0530549 case PMIC_IS_PMI632:
550 buff[0] = REG_READ(ADC_V_DATA_LSB);
551 buff[1] = REG_READ(ADC_V_DATA_MSB);
552 temp = buff[1] << 8 | buff[0];
553 /* {MSB,LSB} to decode the voltage level, refer register description. */
554 vbat = (((uint64_t)temp)*QGAUGE_VOLTAGE_NUMR/BATT_VOLTAGE_DENR);
555 break;
lijuang3606df82015-09-02 21:14:43 +0800556 default:
557 dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
558 break;
559 }
560
561 return vbat;
562}
563
564/* Add safeguards such as refusing to flash if minimum battery levels
565 * are not present or be bypass if the device doesn't have a battery
566 */
567bool target_battery_soc_ok()
568{
569 if (!target_battery_is_present()) {
570 dprintf(INFO, "battery is not present\n");
571 return true;
572 }
573
574 if (target_get_battery_voltage() >= BATTERY_MIN_VOLTAGE)
575 return true;
576
577 return false;
578}
579#endif