forked from msm8916-mainline/lk2nd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.c
524 lines (460 loc) · 15.8 KB
/
board.c
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
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <debug.h>
#include <board.h>
#include <smem.h>
#include <baseband.h>
#include <boot_device.h>
static uint16_t format_major = 0;
static uint16_t format_minor = 0;
static struct board_data board = {UNKNOWN,
0,
0,
0,
HW_PLATFORM_UNKNOWN,
HW_PLATFORM_SUBTYPE_UNKNOWN,
LINUX_MACHTYPE_UNKNOWN,
BASEBAND_MSM,
{{PMIC_IS_INVALID, 0, 0}, {PMIC_IS_INVALID, 0, 0},
{PMIC_IS_INVALID, 0, 0}},
0,
0,
0,
NULL,
};
static void platform_detect(void)
{
struct smem_board_info_v5 board_info_v5;
struct smem_board_info_v6 board_info_v6;
struct smem_board_info_v7 board_info_v7;
struct smem_board_info_v8 board_info_v8;
struct smem_board_info_v9 board_info_v9;
struct smem_board_info_v10 board_info_v10;
struct smem_board_info_v11 board_info_v11;
unsigned int board_info_len = 0;
unsigned ret = 0;
unsigned format = 0;
unsigned pmic_type = 0;
uint8_t i;
ret = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
&format, sizeof(format), 0);
if (ret)
return;
/* Extract the major & minor version info,
* Upper two bytes: major info
* Lower two byets: minor info
*/
format_major = (format & 0xffff0000) >> 16;
format_minor = format & 0x0000ffff;
if (format_major == 0x0)
{
if (format_minor == 3 || format_minor == 4 || format_minor == 5)
{
if (format_minor == 3)
board_info_len = sizeof(board_info_v5.board_info_v3);
else /* v4 has same size as v5, fused_chip is "buffer_align" */
board_info_len = sizeof(board_info_v5);
ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
&board_info_v5,
board_info_len);
if (ret)
return;
board.platform = board_info_v5.board_info_v3.msm_id;
board.platform_version = board_info_v5.board_info_v3.msm_version;
board.platform_hw = board_info_v5.board_info_v3.hw_platform;
}
else if (format_minor == 6)
{
board_info_len = sizeof(board_info_v6);
ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
&board_info_v6,
board_info_len);
if (ret)
return;
board.platform = board_info_v6.board_info_v3.msm_id;
board.platform_version = board_info_v6.board_info_v3.msm_version;
board.platform_hw = board_info_v6.board_info_v3.hw_platform;
board.platform_subtype = board_info_v6.platform_subtype;
}
else if (format_minor == 7)
{
board_info_len = sizeof(board_info_v7);
ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
&board_info_v7,
board_info_len);
if (ret)
return;
board.platform = board_info_v7.board_info_v3.msm_id;
board.platform_version = board_info_v7.board_info_v3.msm_version;
board.platform_hw = board_info_v7.board_info_v3.hw_platform;
board.platform_subtype = board_info_v7.platform_subtype;
board.pmic_info[0].pmic_type = board_info_v7.pmic_type;
board.pmic_info[0].pmic_version = board_info_v7.pmic_version;
}
else if (format_minor == 8)
{
board_info_len = sizeof(board_info_v8);
ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
&board_info_v8,
board_info_len);
if (ret)
return;
board.platform = board_info_v8.board_info_v3.msm_id;
board.platform_version = board_info_v8.board_info_v3.msm_version;
board.platform_hw = board_info_v8.board_info_v3.hw_platform;
board.platform_subtype = board_info_v8.platform_subtype;
/*
* fill in board.target with variant_id information
* bit no |31 24 | 23 16 | 15 8 |7 0|
* board.target = |subtype| plat_hw_ver major | plat_hw_ver minor |hw_platform|
*
*/
board.target = (((board_info_v8.platform_subtype & 0xff) << 24) |
(((board_info_v8.platform_version >> 16) & 0xff) << 16) |
((board_info_v8.platform_version & 0xff) << 8) |
(board_info_v8.board_info_v3.hw_platform & 0xff));
for (i = 0; i < SMEM_V8_SMEM_MAX_PMIC_DEVICES; i++) {
board.pmic_info[i].pmic_type = board_info_v8.pmic_info[i].pmic_type;
board.pmic_info[i].pmic_version = board_info_v8.pmic_info[i].pmic_version;
/*
* fill in pimc_board_info with pmic type and pmic version information
* bit no |31 24 | 23 16 | 15 8 |7 0|
* pimc_board_info = |Unused | Major version | Minor version|PMIC_MODEL|
*
*/
pmic_type = board_info_v8.pmic_info[i].pmic_type == PMIC_IS_INVALID? 0 : board_info_v8.pmic_info[i].pmic_type;
board.pmic_info[i].pmic_target = (((board_info_v8.pmic_info[i].pmic_version >> 16) & 0xff) << 16) |
((board_info_v8.pmic_info[i].pmic_version & 0xff) << 8) | (pmic_type & 0xff);
}
}
else if (format_minor == 0x9)
{
board_info_len = sizeof(board_info_v9);
ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
&board_info_v9,
board_info_len);
if (ret)
return;
board.platform = board_info_v9.board_info_v3.msm_id;
board.platform_version = board_info_v9.board_info_v3.msm_version;
board.platform_hw = board_info_v9.board_info_v3.hw_platform;
board.platform_subtype = board_info_v9.platform_subtype;
/*
* fill in board.target with variant_id information
* bit no |31 24 | 23 16 | 15 8 |7 0|
* board.target = |subtype| plat_hw_ver major | plat_hw_ver minor |hw_platform|
*
*/
board.target = (((board_info_v9.platform_subtype & 0xff) << 24) |
(((board_info_v9.platform_version >> 16) & 0xff) << 16) |
((board_info_v9.platform_version & 0xff) << 8) |
(board_info_v9.board_info_v3.hw_platform & 0xff));
for (i = 0; i < SMEM_V8_SMEM_MAX_PMIC_DEVICES; i++) {
board.pmic_info[i].pmic_type = board_info_v9.pmic_info[i].pmic_type;
board.pmic_info[i].pmic_version = board_info_v9.pmic_info[i].pmic_version;
/*
* fill in pimc_board_info with pmic type and pmic version information
* bit no |31 24 | 23 16 | 15 8 |7 0|
* pimc_board_info = |Unused | Major version | Minor version|PMIC_MODEL|
*
*/
pmic_type = board_info_v9.pmic_info[i].pmic_type == PMIC_IS_INVALID? 0 : board_info_v9.pmic_info[i].pmic_type;
board.pmic_info[i].pmic_target = (((board_info_v9.pmic_info[i].pmic_version >> 16) & 0xff) << 16) |
((board_info_v9.pmic_info[i].pmic_version & 0xff) << 8) | (pmic_type & 0xff);
}
board.foundry_id = board_info_v9.foundry_id;
}
else if (format_minor == 0xA)
{
board_info_len = sizeof(board_info_v10);
ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
&board_info_v10,
board_info_len);
if (ret)
return;
board.platform = board_info_v10.board_info_v3.msm_id;
board.platform_version = board_info_v10.board_info_v3.msm_version;
board.platform_hw = board_info_v10.board_info_v3.hw_platform;
board.platform_subtype = board_info_v10.platform_subtype;
/*
* fill in board.target with variant_id information
* bit no |31 24 | 23 16 | 15 8 |7 0|
* board.target = |subtype| plat_hw_ver major | plat_hw_ver minor |hw_platform|
*
*/
board.target = (((board_info_v10.platform_subtype & 0xff) << 24) |
(((board_info_v10.platform_version >> 16) & 0xff) << 16) |
((board_info_v10.platform_version & 0xff) << 8) |
(board_info_v10.board_info_v3.hw_platform & 0xff));
for (i = 0; i < SMEM_V8_SMEM_MAX_PMIC_DEVICES; i++) {
board.pmic_info[i].pmic_type = board_info_v10.pmic_info[i].pmic_type;
board.pmic_info[i].pmic_version = board_info_v10.pmic_info[i].pmic_version;
/*
* fill in pimc_board_info with pmic type and pmic version information
* bit no |31 24 | 23 16 | 15 8 |7 0|
* pimc_board_info = |Unused | Major version | Minor version|PMIC_MODEL|
*
*/
pmic_type = board_info_v10.pmic_info[i].pmic_type == PMIC_IS_INVALID? 0 : board_info_v10.pmic_info[i].pmic_type;
board.pmic_info[i].pmic_target = (((board_info_v10.pmic_info[i].pmic_version >> 16) & 0xff) << 16) |
((board_info_v10.pmic_info[i].pmic_version & 0xff) << 8) | (pmic_type & 0xff);
}
board.foundry_id = board_info_v10.foundry_id;
board.chip_serial = board_info_v10.chip_serial;
}
else if (format_minor >= 0xB)
{
board_info_len = sizeof(board_info_v11);
ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
&board_info_v11,
board_info_len);
if (ret)
return;
board.platform = board_info_v11.board_info_v3.msm_id;
board.platform_version = board_info_v11.board_info_v3.msm_version;
board.platform_hw = board_info_v11.board_info_v3.hw_platform;
board.platform_subtype = board_info_v11.platform_subtype;
/*
* fill in board.target with variant_id information
* bit no |31 24 |23 16|15 8|7 0|
* board.target = |subtype|plat_hw_ver major|plat_hw_ver minor|hw_platform|
*
*/
board.target = (((board_info_v11.platform_subtype & 0xff) << 24) |
(((board_info_v11.platform_version >> 16) & 0xff) << 16) |
((board_info_v11.platform_version & 0xff) << 8) |
(board_info_v11.board_info_v3.hw_platform & 0xff));
board.foundry_id = board_info_v11.foundry_id;
board.chip_serial = board_info_v11.chip_serial;
board.num_pmics = board_info_v11.num_pmics;
board.pmic_array_offset = board_info_v11.pmic_array_offset;
}
/* HLOS subtype
* bit no |31 20 | 19 16|15 13 |12 11 | 10 8 | 7 0|
* board.platform_hlos_subtype = |reserved | Boot device |Reserved | Panel | DDR detection | subtype|
* | bits | | bits | Detection |
*/
board.platform_hlos_subtype = (board_get_ddr_subtype() << 8) | (platform_get_boot_dev() << 16) | (platform_detect_panel() << 11);
}
else
{
dprintf(CRITICAL, "Unsupported board info format %u.%u\n", format_major, format_minor);
ASSERT(0);
}
}
void pmic_info_populate(void)
{
uint32_t pmic_type = 0;
void *smem_board_info_addr = NULL;
uint32_t smem_board_info_size = 0;
if (format_minor < 0xB)
{
// not needed for smem versions < 0xB
return;
}
smem_board_info_addr = smem_get_alloc_entry(SMEM_BOARD_INFO_LOCATION, &smem_board_info_size);
if (smem_board_info_addr == NULL)
{
dprintf(CRITICAL, "Error reading the smem board info address\n");
ASSERT(0);
}
if (smem_board_info_size < board.pmic_array_offset)
{
dprintf(CRITICAL, "Invalid SMEM board info\n");
ASSERT(0);
}
if(!(board.pmic_info_array = malloc(board.num_pmics * sizeof(struct board_pmic_data))))
{
dprintf(CRITICAL, "Error allocating memory for pmic info array\n");
ASSERT(0);
}
struct board_pmic_data *info = board.pmic_info_array;
for (uint8_t i = 0; i < board.num_pmics; i++)
{
memcpy(info, smem_board_info_addr + board.pmic_array_offset + (i * sizeof(struct smem_pmic_info)), sizeof(struct smem_pmic_info));
/*
* fill in pimc_board_info with pmic type and pmic version information
* bit no |31 24|23 16|15 8|7 0|
* pimc_board_info = |Unused|Major version|Minor version|PMIC_MODEL|
*
*/
pmic_type = info->pmic_type == PMIC_IS_INVALID? 0 : info->pmic_type;
info->pmic_target = (((info->pmic_version >> 16) & 0xff) << 16) |
((info->pmic_version & 0xff) << 8) | (pmic_type & 0xff);
info++;
}
}
void board_init(void)
{
platform_detect();
target_detect(&board);
target_baseband_detect(&board);
}
uint32_t board_platform_id(void)
{
return board.platform;
}
uint32_t board_target_id(void)
{
return board.target;
}
uint32_t board_baseband(void)
{
return board.baseband;
}
uint32_t board_hardware_id(void)
{
return board.platform_hw;
}
uint32_t board_hardware_subtype(void)
{
return board.platform_subtype;
}
uint32_t board_foundry_id(void)
{
return board.foundry_id;
}
uint32_t board_chip_serial(void)
{
return board.chip_serial;
}
uint8_t board_pmic_info(struct board_pmic_data *info, uint8_t num_ent)
{
uint8_t i;
if (format_major == 0x0)
{
if (format_minor < 0xB)
{
for (i = 0; i < num_ent && i < SMEM_MAX_PMIC_DEVICES; i++) {
info->pmic_type = board.pmic_info[i].pmic_type;
info->pmic_version = board.pmic_info[i].pmic_version;
info->pmic_target = board.pmic_info[i].pmic_target;
info++;
}
return (i--);
}
}
return 0;
}
bool board_pmic_type(uint32_t type)
{
uint8_t i;
if (format_major == 0x0 && format_minor >= 0x0B)
{
for (i = 0; i < SMEM_MAX_PMIC_DEVICES; i++)
{
if (type == (board.pmic_info_array[i].pmic_type & 0x0000ffff))
return true;
}
}
return false;
}
void board_pmi_target_set(uint8_t num_ent,uint8_t rev)
{
if (format_major == 0x0 && num_ent < SMEM_MAX_PMIC_DEVICES)
{
if (format_minor < 0xB && num_ent < SMEM_V8_SMEM_MAX_PMIC_DEVICES)
{
board.pmic_info[num_ent].pmic_target &= 0xffffff00;
board.pmic_info[num_ent].pmic_target |= rev;
}
else
{
if (num_ent < board.num_pmics)
{
board.pmic_info_array[num_ent].pmic_target &= 0xffffff00;
board.pmic_info_array[num_ent].pmic_target |= rev;
}
}
}
}
uint32_t board_pmic_target(uint8_t num_ent)
{
if (format_major == 0x0 && num_ent < SMEM_MAX_PMIC_DEVICES)
{
if (format_minor < 0xB && num_ent < SMEM_V8_SMEM_MAX_PMIC_DEVICES)
{
return board.pmic_info[num_ent].pmic_target;
}
else
{
if (num_ent < board.num_pmics)
return board.pmic_info_array[num_ent].pmic_target;
}
}
return 0;
}
uint32_t board_soc_version(void)
{
return board.platform_version;
}
uint32_t board_get_ddr_subtype(void)
{
ram_partition ptn_entry;
unsigned int index;
uint32_t ret = 0;
uint32_t len = 0;
unsigned ddr_size = 0;
/* Make sure RAM partition table is initialized */
ASSERT(smem_ram_ptable_init_v1());
len = smem_get_ram_ptable_len();
/* Calculating the size of the mem_info_ptr */
for (index = 0 ; index < len; index++)
{
smem_get_ram_ptable_entry(&ptn_entry, index);
if((ptn_entry.category == SDRAM) &&
(ptn_entry.type == SYS_MEMORY))
{
ddr_size += ptn_entry.size;
}
}
switch(ddr_size)
{
case DDR_512MB:
ret = SUBTYPE_512MB;
break;
default:
ret = 0;
break;
};
return ret;
}
uint32_t board_hlos_subtype(void)
{
return board.platform_hlos_subtype;
}
void board_update_boot_dev(uint32_t boot_dev)
{
/* HLOS subtype
* bit no |31 20 | 19 16|15 13 |12 11 | 10 8 | 7 0|
* board.platform_hlos_subtype = |reserved | Boot device |Reserved | Panel | DDR detection | subtype|
* | bits | | bits | Detection |
*/
board.platform_hlos_subtype |= (boot_dev << 16);
}