blob: 06be1f02ca40584dfd6adeac424c35aaee26e0b3 [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
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -080046#define EXPAND(NAME) #NAME
47#define TARGET(NAME) EXPAND(NAME)
lijuang3606df82015-09-02 21:14:43 +080048
lijuang66192212015-09-22 10:25:48 +080049#define BATTERY_MIN_VOLTAGE 3200000 //uv
lijuang3606df82015-09-02 21:14:43 +080050#define PMIC_SLAVE_ID 0x20000
51#define BAT_IF_BAT_PRES_STATUS 0x1208
52
Amol Jadi57abe4c2011-05-24 15:47:27 -070053/*
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070054 * default implementations of these routines, if the target code
55 * chooses not to implement.
56 */
57
58__WEAK void target_early_init(void)
59{
60}
61
62__WEAK void target_init(void)
63{
64}
65
David Ng3679bc52010-02-09 15:43:43 -080066__WEAK void *target_get_scratch_address(void)
67{
68 return (void *)(SCRATCH_ADDR);
69}
70
Vivek Mehta5f1c9d42011-04-01 20:11:59 -070071__WEAK unsigned target_get_max_flash_size(void)
72{
73 return (120 * 1024 * 1024);
74}
75
Tanya Brokhman1c94f1a2015-02-15 09:05:03 +020076__WEAK int flash_ubi_img(void)
77{
78 return 0;
79}
80
Tanya Brokhman84eaaf62015-02-24 21:57:06 +020081__WEAK int update_ubi_vol(void)
82{
83 return 0;
84}
85
David Ng183a7422009-12-07 14:55:21 -080086__WEAK int target_is_emmc_boot(void)
87{
David Ng025c1d92009-12-09 23:46:00 -080088#if _EMMC_BOOT
89 return 1;
90#else
David Ng183a7422009-12-07 14:55:21 -080091 return 0;
David Ng025c1d92009-12-09 23:46:00 -080092#endif
David Ng183a7422009-12-07 14:55:21 -080093}
Chandan Uddarajude85d3f2010-01-05 16:32:33 -080094
95__WEAK unsigned check_reboot_mode(void)
96{
97 return 0;
98}
Chandan Uddaraju94183c02010-01-15 15:13:59 -080099
lijuangc518f5d2015-02-10 10:22:53 +0800100__WEAK unsigned check_hard_reboot_mode(void)
101{
102 return 0;
103}
104
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800105__WEAK void reboot_device(unsigned reboot_reason)
106{
107}
Chandan Uddaraju7f5b9012010-02-06 16:37:48 -0800108
Matthew Qindefd5562014-07-11 18:02:40 +0800109__WEAK uint32_t is_user_force_reset(void)
110{
111 return 0;
112}
113
lijuang395b5e62015-11-19 17:39:44 +0800114__WEAK int set_download_mode(enum reboot_reason mode)
Pavel Nedev76a3e212013-05-09 10:37:21 +0300115{
lijuang395b5e62015-11-19 17:39:44 +0800116 if(mode == NORMAL_DLOAD || mode == EMERGENCY_DLOAD) {
117#if PLATFORM_USE_SCM_DLOAD
118 return scm_dload_mode(mode);
119#else
120 return -1;
121#endif
122 }
123
124 return 0;
Pavel Nedev76a3e212013-05-09 10:37:21 +0300125}
126
David Ngf773dde2010-07-26 19:55:08 -0700127__WEAK unsigned target_pause_for_battery_charge(void)
128{
129 return 0;
130}
Ajay Dudanid04110c2011-01-17 23:55:07 -0800131
132__WEAK unsigned target_baseband()
133{
134 return 0;
135}
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800136
137__WEAK void target_serialno(unsigned char *buf)
138{
Ajay Dudanif63d02f2011-10-01 08:29:53 -0700139 snprintf((char *) buf, 13, "%s",TARGET(BOARD));
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800140}
Amol Jadi57abe4c2011-05-24 15:47:27 -0700141
142__WEAK void target_fastboot_init()
143{
144}
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -0700145
146__WEAK int emmc_recovery_init(void)
147{
148 return 0;
149}
Shashank Mittalcd98d472011-08-02 14:29:24 -0700150
151__WEAK bool target_use_signed_kernel(void)
152{
153#if _SIGNED_KERNEL
154 return 1;
155#else
156 return 0;
157#endif
158}
Amol Jadi6834f1a2012-06-29 14:42:59 -0700159
Stanimir Varbanov8bc68c72013-07-08 18:22:04 +0300160__WEAK bool target_is_ssd_enabled(void)
161{
162#ifdef SSD_ENABLE
163 return 1;
164#else
165 return 0;
166#endif
167}
168
Stanimir Varbanov677001e2013-07-18 18:16:39 +0300169__WEAK void target_load_ssd_keystore(void)
170{
171}
Amol Jadi6834f1a2012-06-29 14:42:59 -0700172
173/* Default target does not support continuous splash screen feature. */
174__WEAK int target_cont_splash_screen()
175{
176 return 0;
177}
Amol Jadida118b92012-07-06 19:53:18 -0700178
179/* Default target specific initialization before using USB */
180__WEAK void target_usb_init(void)
181{
182}
183
184/* Default target specific usb shutdown */
185__WEAK void target_usb_stop(void)
186{
187}
Channagoud Kadabifa6179e2013-06-18 18:35:14 -0700188
189/* Default target specific target uninit */
190__WEAK void target_uninit(void)
191{
192}
Dhaval Patelcdcb6462013-07-18 14:46:57 -0700193
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530194__WEAK bool target_display_panel_node(char *pbuf, uint16_t buf_size)
Dhaval Patelcdcb6462013-07-18 14:46:57 -0700195{
196 return false;
197}
Channagoud Kadabi9fbdcdf2013-09-19 16:24:16 -0700198
Aravind Venkateswaran6385f7e2014-02-25 16:45:11 -0800199__WEAK void target_display_init(const char *panel_name)
Aravind Venkateswarandd50c1a2014-02-25 14:42:43 -0800200{
201}
202
203__WEAK void target_display_shutdown(void)
204{
205}
206
Casey Piperf8cebb62013-09-11 15:56:17 -0700207__WEAK uint8_t target_panel_auto_detect_enabled()
208{
209 return 0;
210}
211
Casey Piper48bfc0d2013-11-18 13:24:35 -0800212__WEAK uint8_t target_is_edp()
213{
214 return 0;
215}
216
Amol Jadi417c7f22013-10-07 12:52:21 -0700217/* default usb controller to be used. */
218__WEAK const char * target_usb_controller()
219{
220 return "ci";
221}
Amol Jadi9ff7bb52013-10-11 14:11:45 -0700222
223/* override for target specific usb phy reset. */
224__WEAK void target_usb_phy_reset(void)
225{
226}
Hanumant Singh8e1ac232014-01-29 13:41:51 -0800227
228/* determine if target is in warm boot. */
229__WEAK bool target_warm_boot(void)
230{
231 return false;
232}
Aparna Mallavarapu373d38b2014-05-23 14:47:19 +0530233
234/* Determine the HLOS subtype of the target */
235__WEAK uint32_t target_get_hlos_subtype(void)
236{
237 return 0;
238}
Channagoud Kadabi82cf5c62014-08-24 22:17:34 -0700239
240/* Initialize crypto parameters */
241__WEAK void target_crypto_init_params()
242{
243}
Channagoud Kadabi41c81a62014-10-08 19:55:30 -0700244
Parth Dixit550ddf32016-11-28 17:00:29 +0530245__WEAK bool target_is_pmi_enabled(void)
246{
247 return 1;
248}
249
Channagoud Kadabi41c81a62014-10-08 19:55:30 -0700250/* Default CFG delay value */
251__WEAK uint32_t target_ddr_cfg_val()
252{
253 return DDR_CONFIG_VAL;
254}
Channagoud Kadabi2021cef2015-02-25 12:08:32 -0800255
Parth Dixitff1928a2016-11-16 19:57:21 +0530256/* Default CFG register value */
257uint32_t target_ddr_cfg_reg()
258{
259 uint32_t platform = board_platform_id();
260 uint32_t ret = SDCC_HC_REG_DDR_CONFIG;
261
262 switch(platform)
263 {
264 case MSM8937:
265 case MSM8940:
266 case APQ8037:
267 case MSM8917:
268 case MSM8920:
269 case MSM8217:
270 case MSM8617:
271 case APQ8017:
272 case MSM8953:
273 case APQ8053:
Mayank Grover759e0b02017-04-11 11:59:06 +0530274 case SDM450:
Parth Dixitff1928a2016-11-16 19:57:21 +0530275 /* SDCC HC DDR CONFIG has shifted by 4 bytes for these platform */
276 ret += 4;
277 break;
278 default:
279 break;
280 }
281 return ret;
282}
283
AnilKumar Chimata29a19c32017-08-10 14:48:55 +0530284#if VERIFIED_BOOT_LE
285int verified_boot_le = 1;
286#else
287int verified_boot_le = 0;
288#endif
289
290int is_vb_le_enabled(void)
291{
292 uint32_t platform = board_platform_id();
293
294 switch(platform)
295 {
296 case APQ8053:
297 return verified_boot_le;
298 default:
299 break;
300 }
301 return 0;
302}
303
Wufeng Jiang71246c22015-08-06 19:07:09 +0800304#if PON_VIB_SUPPORT
Parth Dixit7f683712015-12-23 15:59:16 +0530305void get_vibration_type(struct qpnp_hap *config)
Wufeng Jiang71246c22015-08-06 19:07:09 +0800306{
Wufeng Jiang71246c22015-08-06 19:07:09 +0800307 uint32_t hw_id = board_hardware_id();
308 uint32_t platform = board_platform_id();
Parth Dixit7f683712015-12-23 15:59:16 +0530309
310 config->vib_type = VIB_ERM_TYPE;
311 config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_1c;
312 config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_04;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800313 switch(hw_id){
314 case HW_PLATFORM_MTP:
315 switch(platform){
316 case MSM8952:
Parth Dixit7f683712015-12-23 15:59:16 +0530317 config->vib_type = VIB_ERM_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800318 break;
319 case MSM8976:
vijay kumare9287242015-09-04 18:40:15 +0530320 case MSM8956:
321 case APQ8056:
Parth Dixit7f683712015-12-23 15:59:16 +0530322 config->vib_type = VIB_LRA_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800323 break;
Parth Dixit7f683712015-12-23 15:59:16 +0530324 case MSM8937:
Parth Dixitd71e4172016-05-17 14:59:54 +0530325 case MSM8940:
Parth Dixit7f683712015-12-23 15:59:16 +0530326 case APQ8037:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530327 case MSM8917:
Mayank Groverb093c932016-10-03 18:04:13 +0530328 case MSM8920:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530329 case MSM8217:
330 case MSM8617:
331 case APQ8017:
Gaurav Nebhwani6c945a42016-02-16 17:26:51 +0530332 case MSM8953:
333 case APQ8053:
Mayank Grover759e0b02017-04-11 11:59:06 +0530334 case SDM450:
Parth Dixit7f683712015-12-23 15:59:16 +0530335 config->vib_type = VIB_LRA_TYPE;
336 config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_41;
337 config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_03;
Gaurav Nebhwani8e20d832016-02-12 15:07:58 +0530338 break;
vijay kumare9287242015-09-04 18:40:15 +0530339 default:
340 dprintf(CRITICAL,"Unsupported platform id\n");
341 break;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800342 }
343 break;
344 case HW_PLATFORM_QRD:
Parth Dixit7f683712015-12-23 15:59:16 +0530345 config->vib_type = VIB_ERM_TYPE;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800346 break;
vijay kumare9287242015-09-04 18:40:15 +0530347 default:
Parth Dixit7f683712015-12-23 15:59:16 +0530348 dprintf(CRITICAL,"Unsupported hardware id\n");
vijay kumare9287242015-09-04 18:40:15 +0530349 break;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800350 }
Wufeng Jiang71246c22015-08-06 19:07:09 +0800351}
352#endif
353
Channagoud Kadabi2021cef2015-02-25 12:08:32 -0800354/* Return Build variant */
355__WEAK bool target_build_variant_user()
356{
357#if USER_BUILD_VARIANT
358 return true;
359#else
360 return false;
361#endif
362}
lijuang3606df82015-09-02 21:14:43 +0800363
364__WEAK uint32_t target_get_pmic()
365{
366 return PMIC_IS_UNKNOWN;
367}
368
369/* Check battery if it's exist */
370bool target_battery_is_present()
371{
372 bool batt_is_exist;
373 uint8_t value = 0;
374 uint32_t pmic;
375
376 pmic = target_get_pmic();
377
378 switch(pmic)
379 {
380 case PMIC_IS_PM8909:
381 case PMIC_IS_PM8916:
382 case PMIC_IS_PM8941:
383 value = REG_READ(BAT_IF_BAT_PRES_STATUS);
384 break;
385 case PMIC_IS_PMI8950:
386 case PMIC_IS_PMI8994:
387 case PMIC_IS_PMI8996:
Parth Dixit550ddf32016-11-28 17:00:29 +0530388 if(target_is_pmi_enabled())
389 {
390 value = REG_READ(PMIC_SLAVE_ID|
391 BAT_IF_BAT_PRES_STATUS);
392 }
lijuang3606df82015-09-02 21:14:43 +0800393 break;
394 default:
395 dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
396 break;
397 }
398
399 batt_is_exist = value >> 7;
400
401 return batt_is_exist;
402
403}
404
405#if CHECK_BAT_VOLTAGE
406/* Return battery voltage */
407uint32_t target_get_battery_voltage()
408{
409 uint32_t pmic;
410 uint32_t vbat = 0;
411
412 pmic = target_get_pmic();
413
414 switch(pmic)
415 {
416 case PMIC_IS_PM8909:
417 case PMIC_IS_PM8916:
418 case PMIC_IS_PM8941:
419 vbat = pm8x41_get_batt_voltage(); //uv
420 break;
421 case PMIC_IS_PMI8950:
422 case PMIC_IS_PMI8994:
423 case PMIC_IS_PMI8996:
Parth Dixit550ddf32016-11-28 17:00:29 +0530424 if(target_is_pmi_enabled())
425 {
426 if (!pm_fg_usr_get_vbat(1, &vbat)) {
427 vbat = vbat*1000; //uv
428 } else {
429 dprintf(CRITICAL, "ERROR: Get battery voltage failed!!!\n");
430 }
lijuang3606df82015-09-02 21:14:43 +0800431 }
432 break;
433 default:
434 dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
435 break;
436 }
437
438 return vbat;
439}
440
441/* Add safeguards such as refusing to flash if minimum battery levels
442 * are not present or be bypass if the device doesn't have a battery
443 */
444bool target_battery_soc_ok()
445{
446 if (!target_battery_is_present()) {
447 dprintf(INFO, "battery is not present\n");
448 return true;
449 }
450
451 if (target_get_battery_voltage() >= BATTERY_MIN_VOLTAGE)
452 return true;
453
454 return false;
455}
456#endif