forked from msm8916-mainline/lk2nd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.c
More file actions
executable file
·533 lines (467 loc) · 10.3 KB
/
Copy pathinit.c
File metadata and controls
executable file
·533 lines (467 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <err.h>
#include <debug.h>
#include <target.h>
#include <compiler.h>
#include <dload_util.h>
#include <sdhci_msm.h>
#if PON_VIB_SUPPORT
#include <smem.h>
#include <vibrator.h>
#include <board.h>
#endif
#include <smem.h>
#include <scm.h>
#if CHECK_BAT_VOLTAGE
#include <pm8x41_adc.h>
#include <pm8x41_hw.h>
#if WITH_DEV_PMIC_PMI8994
#include <pm_fg_adc_usr.h>
#endif
#endif
#if VERIFIED_BOOT || VERIFIED_BOOT_2
#include <partition_parser.h>
#include <ab_partition_parser.h>
#endif
#define EXPAND(NAME) #NAME
#define TARGET(NAME) EXPAND(NAME)
#define BATTERY_MIN_VOLTAGE 3200000 //uv
#define PMIC_SLAVE_ID 0x20000
#define BAT_IF_BAT_PRES_STATUS 0x1208
#define BAT_IF_INT_RT_STS 0x1210
#define BATT_INFO_VBATT_LSB 0x41A0
#define BATT_INFO_VBATT_MSB 0x41A1
#define ADC_V_DATA_LSB 0x248C0
#define ADC_V_DATA_MSB 0x248C1
#define BATT_VOLTAGE_NUMR 122070
#define QGAUGE_VOLTAGE_NUMR 194637
#define BATT_VOLTAGE_DENR 1000
#define INVALID -1
/*
* default implementations of these routines, if the target code
* chooses not to implement.
*/
__WEAK void target_early_init(void)
{
}
__WEAK void target_init(void)
{
}
__WEAK void *target_get_scratch_address(void)
{
return (void *)(SCRATCH_ADDR);
}
__WEAK unsigned target_get_max_flash_size(void)
{
return (120 * 1024 * 1024);
}
__WEAK int flash_ubi_img(void)
{
return 0;
}
__WEAK int update_ubi_vol(void)
{
return 0;
}
__WEAK unsigned check_reboot_mode(void)
{
return 0;
}
__WEAK unsigned check_hard_reboot_mode(void)
{
return 0;
}
__WEAK void reboot_device(unsigned reboot_reason)
{
}
__WEAK int set_download_mode(enum reboot_reason mode)
{
if(mode == NORMAL_DLOAD || mode == EMERGENCY_DLOAD) {
#if PLATFORM_USE_SCM_DLOAD
return scm_dload_mode(mode);
#else
return -1;
#endif
}
return 0;
}
__WEAK unsigned target_pause_for_battery_charge(void)
{
return 0;
}
__WEAK unsigned target_baseband(void)
{
return 0;
}
__WEAK void target_serialno(unsigned char *buf)
{
strlcpy((char *)buf, TARGET(BOARD), 13);
}
__WEAK void target_fastboot_init(void)
{
}
__WEAK int emmc_recovery_init(void)
{
return 0;
}
__WEAK void target_load_ssd_keystore(void)
{
}
__WEAK int target_volume_up()
{
return 0;
}
__WEAK uint32_t target_volume_down()
{
return 0;
}
/* Default target does not support continuous splash screen feature. */
__WEAK int target_cont_splash_screen(void)
{
return 0;
}
/* Default target specific initialization before using USB */
__WEAK void target_usb_init(void)
{
}
/* Default target specific usb shutdown */
__WEAK void target_usb_stop(void)
{
}
/* Default target specific target uninit */
__WEAK void target_uninit(void)
{
}
__WEAK bool target_display_panel_node(char *pbuf, uint16_t buf_size)
{
return false;
}
__WEAK void target_display_init(const char *panel_name)
{
}
__WEAK void target_display_shutdown(void)
{
}
__WEAK uint8_t target_panel_auto_detect_enabled(void)
{
return 0;
}
__WEAK uint8_t target_is_edp(void)
{
return 0;
}
__WEAK uint8_t target_is_spi(void)
{
return 0;
}
/* default usb controller to be used. */
__WEAK const char * target_usb_controller(void)
{
return "ci";
}
/* override for target specific usb phy reset. */
__WEAK void target_usb_phy_reset(void)
{
}
/* determine if target is in warm boot. */
__WEAK bool target_warm_boot(void)
{
return false;
}
/* Determine the HLOS subtype of the target */
__WEAK uint32_t target_get_hlos_subtype(void)
{
return 0;
}
/* Initialize crypto parameters */
__WEAK void target_crypto_init_params(void)
{
}
__WEAK bool target_is_pmi_enabled(void)
{
return 1;
}
/* Default CFG delay value */
__WEAK uint32_t target_ddr_cfg_val(void)
{
return DDR_CONFIG_VAL;
}
__WEAK struct mmc_device *target_get_sd_mmc(void)
{
return NULL;
}
__WEAK unsigned int qseecom_get_version(void)
{
return 0;
}
/* Default CFG register value */
uint32_t target_ddr_cfg_reg(void)
{
uint32_t platform = board_platform_id();
uint32_t ret = SDCC_HC_REG_DDR_CONFIG;
switch(platform)
{
case MSM8937:
case MSM8940:
case APQ8037:
case MSM8917:
case MSM8920:
case MSM8217:
case MSM8617:
case APQ8017:
case MSM8953:
case APQ8053:
case SDM450:
case SDA450:
case SDM632:
case SDA632:
case SDM429:
case SDM439:
case SDA429:
case SDA439:
case QM215:
case QCM2150:
/* SDCC HC DDR CONFIG has shifted by 4 bytes for these platform */
ret += 4;
break;
default:
break;
}
return ret;
}
#if VERIFIED_BOOT || VERIFIED_BOOT_2
int target_get_vb_version(void)
{
static int vb_version = INVALID;
if (vb_version == INVALID)
{
/* Incase of keymaster present,verified boot for M version */
if (partition_get_index("keymaster") != INVALID_PTN)
vb_version = VB_M;
else
/* Incase keymaster is not present,
we use keystore for verification. */
vb_version = VB_L;
}
return vb_version;
}
#endif
#if VERIFIED_BOOT_LE
int is_vb_le_enabled(void)
{
uint32_t platform = board_platform_id();
switch(platform)
{
case APQ8053:
case APQ8009:
case SDX12:
return 1;
default:
break;
}
return 0;
}
#endif
#if PON_VIB_SUPPORT
void get_vibration_type(struct qpnp_hap *config)
{
uint32_t hw_id = board_hardware_id();
uint32_t platform = board_platform_id();
config->vib_type = VIB_ERM_TYPE;
config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_1c;
config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_04;
switch(hw_id){
case HW_PLATFORM_MTP:
switch(platform){
case MSM8952:
config->vib_type = VIB_ERM_TYPE;
break;
case MSM8976:
case MSM8956:
case APQ8056:
config->vib_type = VIB_LRA_TYPE;
break;
case MSM8937:
case MSM8940:
case APQ8037:
case MSM8917:
case MSM8920:
case MSM8217:
case MSM8617:
case APQ8017:
case MSM8953:
case APQ8053:
case SDM450:
case SDA450:
case SDM632:
case SDA632:
case SDM429:
case SDM439:
case SDA429:
case SDA439:
case QM215:
case QCM2150:
case SDM429W:
config->vib_type = VIB_LRA_TYPE;
config->hap_rate_cfg1 = QPNP_HAP_RATE_CFG1_41;
config->hap_rate_cfg2 = QPNP_HAP_RATE_CFG2_03;
break;
default:
dprintf(CRITICAL,"Unsupported platform id\n");
break;
}
break;
case HW_PLATFORM_QRD:
config->vib_type = VIB_ERM_TYPE;
break;
default:
dprintf(CRITICAL,"Unsupported hardware id\n");
break;
}
}
#endif
__WEAK uint32_t target_get_pmic(void)
{
return PMIC_IS_UNKNOWN;
}
__WEAK bool is_display_disabled(void)
{
return false;
}
#if CHECK_BAT_VOLTAGE
/* Check battery if it's exist */
bool target_battery_is_present(void)
{
bool batt_is_exist;
uint8_t value = 0;
uint32_t pmic;
pmic = target_get_pmic();
switch(pmic)
{
case PMIC_IS_PM8909:
case PMIC_IS_PM8916:
case PMIC_IS_PM8941:
value = REG_READ(BAT_IF_BAT_PRES_STATUS);
break;
case PMIC_IS_PMI8950:
case PMIC_IS_PMI8994:
case PMIC_IS_PMI8996:
if(target_is_pmi_enabled())
{
value = REG_READ(PMIC_SLAVE_ID|
BAT_IF_BAT_PRES_STATUS);
}
break;
case PMIC_IS_PM660:
value = REG_READ(BAT_IF_INT_RT_STS);
/* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4)
are set, battery is not present. */
if (value & (BIT(5) | BIT(4)))
return false;
else
return true;
break;
case PMIC_IS_PMI632:
value = REG_READ(PMIC_SLAVE_ID|BAT_IF_INT_RT_STS);
/* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4)
are set, battery is not present. */
if (value & (BIT(5) | BIT(4)))
return false;
else
return true;
break;
default:
dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
break;
}
batt_is_exist = value >> 7;
return batt_is_exist;
}
#endif
#if CHECK_BAT_VOLTAGE
/* Return battery voltage */
uint32_t target_get_battery_voltage(void)
{
uint32_t pmic;
uint32_t vbat = 0;
uint8_t buff[2];
uint16_t temp;
pmic = target_get_pmic();
switch(pmic)
{
case PMIC_IS_PM8909:
case PMIC_IS_PM8916:
case PMIC_IS_PM8941:
vbat = pm8x41_get_batt_voltage(); //uv
break;
#if WITH_DEV_PMIC_PMI8994
case PMIC_IS_PMI8950:
case PMIC_IS_PMI8994:
case PMIC_IS_PMI8996:
if(target_is_pmi_enabled())
{
if (!pm_fg_usr_get_vbat(1, &vbat)) {
vbat = vbat*1000; //uv
} else {
dprintf(CRITICAL, "ERROR: Get battery voltage failed!!!\n");
}
}
break;
#endif
case PMIC_IS_PM660:
buff[0] = REG_READ(BATT_INFO_VBATT_LSB);
buff[1] = REG_READ(BATT_INFO_VBATT_MSB);
temp = buff[1] << 8 | buff[0];
/* {MSB,LSB} to decode the voltage level, refer register description. */
vbat = (((uint64_t)temp)*BATT_VOLTAGE_NUMR/BATT_VOLTAGE_DENR);
break;
case PMIC_IS_PMI632:
buff[0] = REG_READ(ADC_V_DATA_LSB);
buff[1] = REG_READ(ADC_V_DATA_MSB);
temp = buff[1] << 8 | buff[0];
/* {MSB,LSB} to decode the voltage level, refer register description. */
vbat = (((uint64_t)temp)*QGAUGE_VOLTAGE_NUMR/BATT_VOLTAGE_DENR);
break;
default:
dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
break;
}
return vbat;
}
/* Add safeguards such as refusing to flash if minimum battery levels
* are not present or be bypass if the device doesn't have a battery
*/
bool target_battery_soc_ok(void)
{
if (!target_battery_is_present()) {
dprintf(INFO, "battery is not present\n");
return true;
}
if (target_get_battery_voltage() >= BATTERY_MIN_VOLTAGE)
return true;
return false;
}
#endif