Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 1 | /* |
Casey Piper | a277d88 | 2013-10-21 10:11:04 -0700 | [diff] [blame] | 2 | * Copyright (c) 2008 Travis Geiselbrecht |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 3 | * |
Umang Agrawal | 5990e74 | 2017-12-19 12:08:03 +0530 | [diff] [blame] | 4 | * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. |
lijuang | c518f5d | 2015-02-10 10:22:53 +0800 | [diff] [blame] | 5 | * |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 6 | * 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 Nedev | a4c9d3a | 2013-05-15 14:42:34 +0300 | [diff] [blame] | 29 | #include <dload_util.h> |
Channagoud Kadabi | 41c81a6 | 2014-10-08 19:55:30 -0700 | [diff] [blame] | 30 | #include <sdhci_msm.h> |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 31 | #if PON_VIB_SUPPORT |
Wufeng Jiang | 1ce072f | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 32 | #include <smem.h> |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 33 | #include <vibrator.h> |
| 34 | #include <board.h> |
| 35 | #endif |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 36 | |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 37 | #include <smem.h> |
| 38 | #include <pm8x41_adc.h> |
| 39 | #include <pm8x41_hw.h> |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 40 | #include <scm.h> |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 41 | |
| 42 | #if CHECK_BAT_VOLTAGE |
| 43 | #include <pm_fg_adc_usr.h> |
| 44 | #endif |
| 45 | |
Monika Singh | aec24f0 | 2018-03-14 09:05:46 +0530 | [diff] [blame] | 46 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Monika Singh | e7a2aa6 | 2018-04-13 11:40:55 +0530 | [diff] [blame] | 47 | #include <partition_parser.h> |
Mayank Grover | 204776b | 2017-09-06 10:59:21 +0530 | [diff] [blame] | 48 | #include <ab_partition_parser.h> |
| 49 | #endif |
| 50 | |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 51 | #define EXPAND(NAME) #NAME |
| 52 | #define TARGET(NAME) EXPAND(NAME) |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 53 | |
lijuang | 6619221 | 2015-09-22 10:25:48 +0800 | [diff] [blame] | 54 | #define BATTERY_MIN_VOLTAGE 3200000 //uv |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 55 | #define PMIC_SLAVE_ID 0x20000 |
| 56 | #define BAT_IF_BAT_PRES_STATUS 0x1208 |
Mayank Grover | 3f20adf | 2017-07-03 16:33:22 +0530 | [diff] [blame] | 57 | #define BAT_IF_INT_RT_STS 0x1210 |
| 58 | #define BATT_INFO_VBATT_LSB 0x41A0 |
| 59 | #define BATT_INFO_VBATT_MSB 0x41A1 |
Umang Agrawal | 5990e74 | 2017-12-19 12:08:03 +0530 | [diff] [blame] | 60 | #define ADC_V_DATA_LSB 0x248C0 |
| 61 | #define ADC_V_DATA_MSB 0x248C1 |
Mayank Grover | 3f20adf | 2017-07-03 16:33:22 +0530 | [diff] [blame] | 62 | #define BATT_VOLTAGE_NUMR 122070 |
Umang Agrawal | 5990e74 | 2017-12-19 12:08:03 +0530 | [diff] [blame] | 63 | #define QGAUGE_VOLTAGE_NUMR 194637 |
Mayank Grover | 3f20adf | 2017-07-03 16:33:22 +0530 | [diff] [blame] | 64 | #define BATT_VOLTAGE_DENR 1000 |
Monika Singh | aec24f0 | 2018-03-14 09:05:46 +0530 | [diff] [blame] | 65 | #define INVALID -1 |
Mayank Grover | 204776b | 2017-09-06 10:59:21 +0530 | [diff] [blame] | 66 | static int vb_version = INVALID; |
Monika Singh | aec24f0 | 2018-03-14 09:05:46 +0530 | [diff] [blame] | 67 | |
Amol Jadi | 57abe4c | 2011-05-24 15:47:27 -0700 | [diff] [blame] | 68 | /* |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 69 | * 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 Ng | 3679bc5 | 2010-02-09 15:43:43 -0800 | [diff] [blame] | 81 | __WEAK void *target_get_scratch_address(void) |
| 82 | { |
| 83 | return (void *)(SCRATCH_ADDR); |
| 84 | } |
| 85 | |
Vivek Mehta | 5f1c9d4 | 2011-04-01 20:11:59 -0700 | [diff] [blame] | 86 | __WEAK unsigned target_get_max_flash_size(void) |
| 87 | { |
| 88 | return (120 * 1024 * 1024); |
| 89 | } |
| 90 | |
Tanya Brokhman | 1c94f1a | 2015-02-15 09:05:03 +0200 | [diff] [blame] | 91 | __WEAK int flash_ubi_img(void) |
| 92 | { |
| 93 | return 0; |
| 94 | } |
| 95 | |
Tanya Brokhman | 84eaaf6 | 2015-02-24 21:57:06 +0200 | [diff] [blame] | 96 | __WEAK int update_ubi_vol(void) |
| 97 | { |
| 98 | return 0; |
| 99 | } |
| 100 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 101 | __WEAK int target_is_emmc_boot(void) |
| 102 | { |
David Ng | 025c1d9 | 2009-12-09 23:46:00 -0800 | [diff] [blame] | 103 | #if _EMMC_BOOT |
| 104 | return 1; |
| 105 | #else |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 106 | return 0; |
David Ng | 025c1d9 | 2009-12-09 23:46:00 -0800 | [diff] [blame] | 107 | #endif |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 108 | } |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 109 | |
| 110 | __WEAK unsigned check_reboot_mode(void) |
| 111 | { |
| 112 | return 0; |
| 113 | } |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 114 | |
lijuang | c518f5d | 2015-02-10 10:22:53 +0800 | [diff] [blame] | 115 | __WEAK unsigned check_hard_reboot_mode(void) |
| 116 | { |
| 117 | return 0; |
| 118 | } |
| 119 | |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 120 | __WEAK void reboot_device(unsigned reboot_reason) |
| 121 | { |
| 122 | } |
Chandan Uddaraju | 7f5b901 | 2010-02-06 16:37:48 -0800 | [diff] [blame] | 123 | |
Matthew Qin | defd556 | 2014-07-11 18:02:40 +0800 | [diff] [blame] | 124 | __WEAK uint32_t is_user_force_reset(void) |
| 125 | { |
| 126 | return 0; |
| 127 | } |
| 128 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 129 | __WEAK int set_download_mode(enum reboot_reason mode) |
Pavel Nedev | 76a3e21 | 2013-05-09 10:37:21 +0300 | [diff] [blame] | 130 | { |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 131 | 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 Nedev | 76a3e21 | 2013-05-09 10:37:21 +0300 | [diff] [blame] | 140 | } |
| 141 | |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 142 | __WEAK unsigned target_pause_for_battery_charge(void) |
| 143 | { |
| 144 | return 0; |
| 145 | } |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 146 | |
| 147 | __WEAK unsigned target_baseband() |
| 148 | { |
| 149 | return 0; |
| 150 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 151 | |
| 152 | __WEAK void target_serialno(unsigned char *buf) |
| 153 | { |
Ajay Dudani | f63d02f | 2011-10-01 08:29:53 -0700 | [diff] [blame] | 154 | snprintf((char *) buf, 13, "%s",TARGET(BOARD)); |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 155 | } |
Amol Jadi | 57abe4c | 2011-05-24 15:47:27 -0700 | [diff] [blame] | 156 | |
| 157 | __WEAK void target_fastboot_init() |
| 158 | { |
| 159 | } |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 160 | |
| 161 | __WEAK int emmc_recovery_init(void) |
| 162 | { |
| 163 | return 0; |
| 164 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 165 | |
| 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 Jadi | 6834f1a | 2012-06-29 14:42:59 -0700 | [diff] [blame] | 174 | |
Stanimir Varbanov | 8bc68c7 | 2013-07-08 18:22:04 +0300 | [diff] [blame] | 175 | __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 Varbanov | 677001e | 2013-07-18 18:16:39 +0300 | [diff] [blame] | 184 | __WEAK void target_load_ssd_keystore(void) |
| 185 | { |
| 186 | } |
Amol Jadi | 6834f1a | 2012-06-29 14:42:59 -0700 | [diff] [blame] | 187 | |
| 188 | /* Default target does not support continuous splash screen feature. */ |
| 189 | __WEAK int target_cont_splash_screen() |
| 190 | { |
| 191 | return 0; |
| 192 | } |
Amol Jadi | da118b9 | 2012-07-06 19:53:18 -0700 | [diff] [blame] | 193 | |
| 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 Kadabi | fa6179e | 2013-06-18 18:35:14 -0700 | [diff] [blame] | 203 | |
| 204 | /* Default target specific target uninit */ |
| 205 | __WEAK void target_uninit(void) |
| 206 | { |
| 207 | } |
Dhaval Patel | cdcb646 | 2013-07-18 14:46:57 -0700 | [diff] [blame] | 208 | |
Padmanabhan Komanduru | bccbcdc | 2015-06-30 16:19:24 +0530 | [diff] [blame] | 209 | __WEAK bool target_display_panel_node(char *pbuf, uint16_t buf_size) |
Dhaval Patel | cdcb646 | 2013-07-18 14:46:57 -0700 | [diff] [blame] | 210 | { |
| 211 | return false; |
| 212 | } |
Channagoud Kadabi | 9fbdcdf | 2013-09-19 16:24:16 -0700 | [diff] [blame] | 213 | |
Aravind Venkateswaran | 6385f7e | 2014-02-25 16:45:11 -0800 | [diff] [blame] | 214 | __WEAK void target_display_init(const char *panel_name) |
Aravind Venkateswaran | dd50c1a | 2014-02-25 14:42:43 -0800 | [diff] [blame] | 215 | { |
| 216 | } |
| 217 | |
| 218 | __WEAK void target_display_shutdown(void) |
| 219 | { |
| 220 | } |
| 221 | |
Casey Piper | f8cebb6 | 2013-09-11 15:56:17 -0700 | [diff] [blame] | 222 | __WEAK uint8_t target_panel_auto_detect_enabled() |
| 223 | { |
| 224 | return 0; |
| 225 | } |
| 226 | |
Casey Piper | 48bfc0d | 2013-11-18 13:24:35 -0800 | [diff] [blame] | 227 | __WEAK uint8_t target_is_edp() |
| 228 | { |
| 229 | return 0; |
| 230 | } |
| 231 | |
Amol Jadi | 417c7f2 | 2013-10-07 12:52:21 -0700 | [diff] [blame] | 232 | /* default usb controller to be used. */ |
| 233 | __WEAK const char * target_usb_controller() |
| 234 | { |
| 235 | return "ci"; |
| 236 | } |
Amol Jadi | 9ff7bb5 | 2013-10-11 14:11:45 -0700 | [diff] [blame] | 237 | |
| 238 | /* override for target specific usb phy reset. */ |
| 239 | __WEAK void target_usb_phy_reset(void) |
| 240 | { |
| 241 | } |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 242 | |
| 243 | /* determine if target is in warm boot. */ |
| 244 | __WEAK bool target_warm_boot(void) |
| 245 | { |
| 246 | return false; |
| 247 | } |
Aparna Mallavarapu | 373d38b | 2014-05-23 14:47:19 +0530 | [diff] [blame] | 248 | |
| 249 | /* Determine the HLOS subtype of the target */ |
| 250 | __WEAK uint32_t target_get_hlos_subtype(void) |
| 251 | { |
| 252 | return 0; |
| 253 | } |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 254 | |
| 255 | /* Initialize crypto parameters */ |
| 256 | __WEAK void target_crypto_init_params() |
| 257 | { |
| 258 | } |
Channagoud Kadabi | 41c81a6 | 2014-10-08 19:55:30 -0700 | [diff] [blame] | 259 | |
Parth Dixit | 550ddf3 | 2016-11-28 17:00:29 +0530 | [diff] [blame] | 260 | __WEAK bool target_is_pmi_enabled(void) |
| 261 | { |
| 262 | return 1; |
| 263 | } |
| 264 | |
Channagoud Kadabi | 41c81a6 | 2014-10-08 19:55:30 -0700 | [diff] [blame] | 265 | /* Default CFG delay value */ |
| 266 | __WEAK uint32_t target_ddr_cfg_val() |
| 267 | { |
| 268 | return DDR_CONFIG_VAL; |
| 269 | } |
Channagoud Kadabi | 2021cef | 2015-02-25 12:08:32 -0800 | [diff] [blame] | 270 | |
Mayank Grover | e8a534f | 2018-05-09 12:06:17 +0530 | [diff] [blame] | 271 | /* Target uses system as root */ |
| 272 | bool 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 | |
Parth Dixit | ff1928a | 2016-11-16 19:57:21 +0530 | [diff] [blame] | 281 | /* Default CFG register value */ |
| 282 | uint32_t target_ddr_cfg_reg() |
| 283 | { |
| 284 | uint32_t platform = board_platform_id(); |
| 285 | uint32_t ret = SDCC_HC_REG_DDR_CONFIG; |
| 286 | |
| 287 | switch(platform) |
| 288 | { |
| 289 | case MSM8937: |
| 290 | case MSM8940: |
| 291 | case APQ8037: |
| 292 | case MSM8917: |
| 293 | case MSM8920: |
| 294 | case MSM8217: |
| 295 | case MSM8617: |
| 296 | case APQ8017: |
| 297 | case MSM8953: |
| 298 | case APQ8053: |
Mayank Grover | 759e0b0 | 2017-04-11 11:59:06 +0530 | [diff] [blame] | 299 | case SDM450: |
Mayank Grover | 3dc285c | 2017-12-26 12:47:09 +0530 | [diff] [blame] | 300 | case SDA450: |
lijuang | 2f1c1f5 | 2017-12-12 14:44:32 +0800 | [diff] [blame] | 301 | case SDM632: |
| 302 | case SDA632: |
lijuang | f656368 | 2018-04-04 20:26:52 +0800 | [diff] [blame] | 303 | case SDM429: |
| 304 | case SDM439: |
lijuang | 5c8797d | 2018-04-23 19:10:16 +0800 | [diff] [blame] | 305 | case SDA429: |
| 306 | case SDA439: |
lijuang | 5c1f468 | 2018-10-09 19:37:36 +0800 | [diff] [blame] | 307 | case QM215: |
Parth Dixit | ff1928a | 2016-11-16 19:57:21 +0530 | [diff] [blame] | 308 | /* SDCC HC DDR CONFIG has shifted by 4 bytes for these platform */ |
| 309 | ret += 4; |
| 310 | break; |
| 311 | default: |
| 312 | break; |
| 313 | } |
| 314 | return ret; |
| 315 | } |
Monika Singh | e7a2aa6 | 2018-04-13 11:40:55 +0530 | [diff] [blame] | 316 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 204776b | 2017-09-06 10:59:21 +0530 | [diff] [blame] | 317 | int target_get_vb_version() |
| 318 | { |
| 319 | if (vb_version == INVALID) |
| 320 | { |
Mayank Grover | 6edf5e1 | 2017-10-26 12:07:01 +0530 | [diff] [blame] | 321 | /* Incase of keymaster present,verified boot for M version */ |
Mayank Grover | 204776b | 2017-09-06 10:59:21 +0530 | [diff] [blame] | 322 | if (partition_get_index("keymaster") != INVALID_PTN) |
Mayank Grover | 6edf5e1 | 2017-10-26 12:07:01 +0530 | [diff] [blame] | 323 | vb_version = VB_M; |
Mayank Grover | 204776b | 2017-09-06 10:59:21 +0530 | [diff] [blame] | 324 | else |
| 325 | /* Incase keymaster is not present, |
| 326 | we use keystore for verification. */ |
Mayank Grover | 6edf5e1 | 2017-10-26 12:07:01 +0530 | [diff] [blame] | 327 | vb_version = VB_L; |
Mayank Grover | 204776b | 2017-09-06 10:59:21 +0530 | [diff] [blame] | 328 | } |
| 329 | return vb_version; |
| 330 | } |
Monika Singh | e7a2aa6 | 2018-04-13 11:40:55 +0530 | [diff] [blame] | 331 | #else |
| 332 | int target_get_vb_version() |
| 333 | { |
| 334 | return vb_version; |
| 335 | } |
| 336 | #endif |
Mayank Grover | 204776b | 2017-09-06 10:59:21 +0530 | [diff] [blame] | 337 | |
AnilKumar Chimata | 29a19c3 | 2017-08-10 14:48:55 +0530 | [diff] [blame] | 338 | #if VERIFIED_BOOT_LE |
| 339 | int verified_boot_le = 1; |
| 340 | #else |
| 341 | int verified_boot_le = 0; |
| 342 | #endif |
| 343 | |
| 344 | int is_vb_le_enabled(void) |
| 345 | { |
| 346 | uint32_t platform = board_platform_id(); |
| 347 | |
| 348 | switch(platform) |
| 349 | { |
| 350 | case APQ8053: |
Mohamed Sunfeer | 199bde0 | 2018-07-24 13:47:50 +0530 | [diff] [blame] | 351 | case APQ8009: |
AnilKumar Chimata | 29a19c3 | 2017-08-10 14:48:55 +0530 | [diff] [blame] | 352 | return verified_boot_le; |
| 353 | default: |
| 354 | break; |
| 355 | } |
| 356 | return 0; |
| 357 | } |
| 358 | |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 359 | #if PON_VIB_SUPPORT |
Parth Dixit | 7f68371 | 2015-12-23 15:59:16 +0530 | [diff] [blame] | 360 | void get_vibration_type(struct qpnp_hap *config) |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 361 | { |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 362 | uint32_t hw_id = board_hardware_id(); |
| 363 | uint32_t platform = board_platform_id(); |
Parth Dixit | 7f68371 | 2015-12-23 15:59:16 +0530 | [diff] [blame] | 364 | |
| 365 | config->vib_type = VIB_ERM_TYPE; |
| 366 | config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_1c; |
| 367 | config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_04; |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 368 | switch(hw_id){ |
| 369 | case HW_PLATFORM_MTP: |
| 370 | switch(platform){ |
| 371 | case MSM8952: |
Parth Dixit | 7f68371 | 2015-12-23 15:59:16 +0530 | [diff] [blame] | 372 | config->vib_type = VIB_ERM_TYPE; |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 373 | break; |
| 374 | case MSM8976: |
vijay kumar | e928724 | 2015-09-04 18:40:15 +0530 | [diff] [blame] | 375 | case MSM8956: |
| 376 | case APQ8056: |
Parth Dixit | 7f68371 | 2015-12-23 15:59:16 +0530 | [diff] [blame] | 377 | config->vib_type = VIB_LRA_TYPE; |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 378 | break; |
Parth Dixit | 7f68371 | 2015-12-23 15:59:16 +0530 | [diff] [blame] | 379 | case MSM8937: |
Parth Dixit | d71e417 | 2016-05-17 14:59:54 +0530 | [diff] [blame] | 380 | case MSM8940: |
Parth Dixit | 7f68371 | 2015-12-23 15:59:16 +0530 | [diff] [blame] | 381 | case APQ8037: |
Parth Dixit | 05f3c9f | 2016-03-18 17:14:57 +0530 | [diff] [blame] | 382 | case MSM8917: |
Mayank Grover | b093c93 | 2016-10-03 18:04:13 +0530 | [diff] [blame] | 383 | case MSM8920: |
Parth Dixit | 05f3c9f | 2016-03-18 17:14:57 +0530 | [diff] [blame] | 384 | case MSM8217: |
| 385 | case MSM8617: |
| 386 | case APQ8017: |
Gaurav Nebhwani | 6c945a4 | 2016-02-16 17:26:51 +0530 | [diff] [blame] | 387 | case MSM8953: |
| 388 | case APQ8053: |
Mayank Grover | 759e0b0 | 2017-04-11 11:59:06 +0530 | [diff] [blame] | 389 | case SDM450: |
Mayank Grover | 3dc285c | 2017-12-26 12:47:09 +0530 | [diff] [blame] | 390 | case SDA450: |
lijuang | 2f1c1f5 | 2017-12-12 14:44:32 +0800 | [diff] [blame] | 391 | case SDM632: |
| 392 | case SDA632: |
lijuang | f656368 | 2018-04-04 20:26:52 +0800 | [diff] [blame] | 393 | case SDM429: |
| 394 | case SDM439: |
lijuang | 5c8797d | 2018-04-23 19:10:16 +0800 | [diff] [blame] | 395 | case SDA429: |
| 396 | case SDA439: |
lijuang | 5c1f468 | 2018-10-09 19:37:36 +0800 | [diff] [blame] | 397 | case QM215: |
Parth Dixit | 7f68371 | 2015-12-23 15:59:16 +0530 | [diff] [blame] | 398 | config->vib_type = VIB_LRA_TYPE; |
| 399 | config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_41; |
| 400 | config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_03; |
Gaurav Nebhwani | 8e20d83 | 2016-02-12 15:07:58 +0530 | [diff] [blame] | 401 | break; |
vijay kumar | e928724 | 2015-09-04 18:40:15 +0530 | [diff] [blame] | 402 | default: |
| 403 | dprintf(CRITICAL,"Unsupported platform id\n"); |
| 404 | break; |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 405 | } |
| 406 | break; |
| 407 | case HW_PLATFORM_QRD: |
Parth Dixit | 7f68371 | 2015-12-23 15:59:16 +0530 | [diff] [blame] | 408 | config->vib_type = VIB_ERM_TYPE; |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 409 | break; |
vijay kumar | e928724 | 2015-09-04 18:40:15 +0530 | [diff] [blame] | 410 | default: |
Parth Dixit | 7f68371 | 2015-12-23 15:59:16 +0530 | [diff] [blame] | 411 | dprintf(CRITICAL,"Unsupported hardware id\n"); |
vijay kumar | e928724 | 2015-09-04 18:40:15 +0530 | [diff] [blame] | 412 | break; |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 413 | } |
Wufeng Jiang | 71246c2 | 2015-08-06 19:07:09 +0800 | [diff] [blame] | 414 | } |
| 415 | #endif |
| 416 | |
Channagoud Kadabi | 2021cef | 2015-02-25 12:08:32 -0800 | [diff] [blame] | 417 | /* Return Build variant */ |
| 418 | __WEAK bool target_build_variant_user() |
| 419 | { |
| 420 | #if USER_BUILD_VARIANT |
| 421 | return true; |
| 422 | #else |
| 423 | return false; |
| 424 | #endif |
| 425 | } |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 426 | |
| 427 | __WEAK uint32_t target_get_pmic() |
| 428 | { |
| 429 | return PMIC_IS_UNKNOWN; |
| 430 | } |
| 431 | |
Krishna Manikandan | 92affec | 2017-12-05 17:47:37 +0530 | [diff] [blame] | 432 | __WEAK bool is_display_disabled() |
| 433 | { |
| 434 | return false; |
| 435 | } |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 436 | /* Check battery if it's exist */ |
| 437 | bool target_battery_is_present() |
| 438 | { |
| 439 | bool batt_is_exist; |
| 440 | uint8_t value = 0; |
| 441 | uint32_t pmic; |
| 442 | |
| 443 | pmic = target_get_pmic(); |
| 444 | |
| 445 | switch(pmic) |
| 446 | { |
| 447 | case PMIC_IS_PM8909: |
| 448 | case PMIC_IS_PM8916: |
| 449 | case PMIC_IS_PM8941: |
| 450 | value = REG_READ(BAT_IF_BAT_PRES_STATUS); |
| 451 | break; |
| 452 | case PMIC_IS_PMI8950: |
| 453 | case PMIC_IS_PMI8994: |
| 454 | case PMIC_IS_PMI8996: |
Parth Dixit | 550ddf3 | 2016-11-28 17:00:29 +0530 | [diff] [blame] | 455 | if(target_is_pmi_enabled()) |
| 456 | { |
| 457 | value = REG_READ(PMIC_SLAVE_ID| |
| 458 | BAT_IF_BAT_PRES_STATUS); |
| 459 | } |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 460 | break; |
Mayank Grover | 3f20adf | 2017-07-03 16:33:22 +0530 | [diff] [blame] | 461 | case PMIC_IS_PM660: |
| 462 | value = REG_READ(BAT_IF_INT_RT_STS); |
| 463 | /* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4) |
| 464 | are set, battery is not present. */ |
| 465 | if (value & (BIT(5) | BIT(4))) |
| 466 | return false; |
| 467 | else |
| 468 | return true; |
| 469 | break; |
Umang Agrawal | 20127f3 | 2018-02-19 10:47:40 +0530 | [diff] [blame] | 470 | case PMIC_IS_PMI632: |
| 471 | value = REG_READ(PMIC_SLAVE_ID|BAT_IF_INT_RT_STS); |
| 472 | /* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4) |
| 473 | are set, battery is not present. */ |
| 474 | if (value & (BIT(5) | BIT(4))) |
| 475 | return false; |
| 476 | else |
| 477 | return true; |
| 478 | break; |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 479 | default: |
| 480 | dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n"); |
| 481 | break; |
| 482 | } |
| 483 | |
| 484 | batt_is_exist = value >> 7; |
| 485 | |
| 486 | return batt_is_exist; |
| 487 | |
| 488 | } |
| 489 | |
Jiten Patel | 4f6c74b | 2018-08-29 16:34:56 +0530 | [diff] [blame] | 490 | bool is_target_support_dtbo(void) |
| 491 | { |
| 492 | #if TARGET_DTBO_NOT_SUPPORTED |
| 493 | return false; |
| 494 | #else |
| 495 | return true; |
| 496 | #endif |
| 497 | } |
| 498 | |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 499 | #if CHECK_BAT_VOLTAGE |
| 500 | /* Return battery voltage */ |
| 501 | uint32_t target_get_battery_voltage() |
| 502 | { |
| 503 | uint32_t pmic; |
| 504 | uint32_t vbat = 0; |
Mayank Grover | 3f20adf | 2017-07-03 16:33:22 +0530 | [diff] [blame] | 505 | uint8_t buff[2]; |
| 506 | uint16_t temp; |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 507 | |
| 508 | pmic = target_get_pmic(); |
| 509 | |
| 510 | switch(pmic) |
| 511 | { |
| 512 | case PMIC_IS_PM8909: |
| 513 | case PMIC_IS_PM8916: |
| 514 | case PMIC_IS_PM8941: |
| 515 | vbat = pm8x41_get_batt_voltage(); //uv |
| 516 | break; |
| 517 | case PMIC_IS_PMI8950: |
| 518 | case PMIC_IS_PMI8994: |
| 519 | case PMIC_IS_PMI8996: |
Parth Dixit | 550ddf3 | 2016-11-28 17:00:29 +0530 | [diff] [blame] | 520 | if(target_is_pmi_enabled()) |
| 521 | { |
| 522 | if (!pm_fg_usr_get_vbat(1, &vbat)) { |
| 523 | vbat = vbat*1000; //uv |
| 524 | } else { |
| 525 | dprintf(CRITICAL, "ERROR: Get battery voltage failed!!!\n"); |
| 526 | } |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 527 | } |
| 528 | break; |
Mayank Grover | 3f20adf | 2017-07-03 16:33:22 +0530 | [diff] [blame] | 529 | case PMIC_IS_PM660: |
| 530 | buff[0] = REG_READ(BATT_INFO_VBATT_LSB); |
| 531 | buff[1] = REG_READ(BATT_INFO_VBATT_MSB); |
| 532 | temp = buff[1] << 8 | buff[0]; |
| 533 | /* {MSB,LSB} to decode the voltage level, refer register description. */ |
Umang Agrawal | 82efbba | 2017-12-19 14:51:02 +0530 | [diff] [blame] | 534 | vbat = (((uint64_t)temp)*BATT_VOLTAGE_NUMR/BATT_VOLTAGE_DENR); |
Mayank Grover | 3f20adf | 2017-07-03 16:33:22 +0530 | [diff] [blame] | 535 | break; |
Umang Agrawal | 5990e74 | 2017-12-19 12:08:03 +0530 | [diff] [blame] | 536 | case PMIC_IS_PMI632: |
| 537 | buff[0] = REG_READ(ADC_V_DATA_LSB); |
| 538 | buff[1] = REG_READ(ADC_V_DATA_MSB); |
| 539 | temp = buff[1] << 8 | buff[0]; |
| 540 | /* {MSB,LSB} to decode the voltage level, refer register description. */ |
| 541 | vbat = (((uint64_t)temp)*QGAUGE_VOLTAGE_NUMR/BATT_VOLTAGE_DENR); |
| 542 | break; |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 543 | default: |
| 544 | dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n"); |
| 545 | break; |
| 546 | } |
| 547 | |
| 548 | return vbat; |
| 549 | } |
| 550 | |
| 551 | /* Add safeguards such as refusing to flash if minimum battery levels |
| 552 | * are not present or be bypass if the device doesn't have a battery |
| 553 | */ |
| 554 | bool target_battery_soc_ok() |
| 555 | { |
| 556 | if (!target_battery_is_present()) { |
| 557 | dprintf(INFO, "battery is not present\n"); |
| 558 | return true; |
| 559 | } |
| 560 | |
| 561 | if (target_get_battery_voltage() >= BATTERY_MIN_VOLTAGE) |
| 562 | return true; |
| 563 | |
| 564 | return false; |
| 565 | } |
| 566 | #endif |