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
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2019 Stephan Gerhold <stephan@gerhold.net>
*/
#include <common.h>
#include <env.h>
#include <fdt_support.h>
#include <init.h>
#include <log.h>
#include <stdlib.h>
#include <asm/global_data.h>
#include <asm/setup.h>
#include <asm/system.h>
DECLARE_GLOBAL_DATA_PTR;
/* Parse atags provided by Samsung bootloader to get available memory */
static ulong fw_mach __section(".data");
static ulong fw_atags __section(".data");
static const struct tag *fw_atags_copy;
static uint fw_atags_size;
void save_boot_params(ulong r0, ulong r1, ulong r2, ulong r3)
{
fw_mach = r1;
fw_atags = r2;
save_boot_params_ret();
}
static const struct tag *fw_atags_get(void)
{
const struct tag *tags = (const struct tag *)fw_atags;
if (tags->hdr.tag != ATAG_CORE) {
log_err("Invalid atags: tag 0x%x at %p\n", tags->hdr.tag, tags);
return NULL;
}
return tags;
}
int dram_init(void)
{
const struct tag *t, *tags = fw_atags_get();
if (!tags)
return -EINVAL;
for_each_tag(t, tags) {
if (t->hdr.tag != ATAG_MEM)
continue;
debug("Memory: %#x-%#x (size %#x)\n", t->u.mem.start,
t->u.mem.start + t->u.mem.size, t->u.mem.size);
gd->ram_size += t->u.mem.size;
}
return 0;
}
int dram_init_banksize(void)
{
const struct tag *t, *tags = fw_atags_get();
unsigned int bank = 0;
if (!tags)
return -EINVAL;
for_each_tag(t, tags) {
if (t->hdr.tag != ATAG_MEM)
continue;
gd->bd->bi_dram[bank].start = t->u.mem.start;
gd->bd->bi_dram[bank].size = t->u.mem.size;
if (++bank == CONFIG_NR_DRAM_BANKS)
break;
}
return 0;
}
int board_init(void)
{
gd->bd->bi_arch_number = fw_mach;
gd->bd->bi_boot_params = fw_atags;
return 0;
}
static void parse_serial(const struct tag_serialnr *serialnr)
{
char serial[17];
if (env_get("serial#"))
return;
sprintf(serial, "%08x%08x", serialnr->high, serialnr->low);
env_set("serial#", serial);
}
#define SBL_BOARD "board_id="
#define SBL_LCDTYPE "lcdtype="
static ulong board_id = 0;
static ulong lcdtype = 0;
static void parse_cmdline(const struct tag_cmdline *cmdline)
{
char *buf;
/* Export this to sbl_cmdline (secondary boot loader command line) */
env_set("sbl_cmdline", cmdline->cmdline);
buf = strstr(cmdline->cmdline, SBL_BOARD);
if (!buf)
return;
buf += strlen(SBL_BOARD);
board_id = simple_strtoul(buf, NULL, 10);
buf = strstr(cmdline->cmdline, SBL_LCDTYPE);
if (!buf)
return;
buf += strlen(SBL_LCDTYPE);
lcdtype = simple_strtoul(buf, NULL, 10);
}
/*
* The downstream/vendor kernel (provided by Samsung) uses ATAGS for booting.
* It also requires an extremely long cmdline provided by the primary bootloader
* that is not suitable for booting mainline.
*
* Since downstream is the only user of ATAGS, we emulate the behavior of the
* Samsung bootloader by generating only the initrd atag in U-Boot, and copying
* all other ATAGS as-is from the primary bootloader.
*/
static inline bool skip_atag(u32 tag)
{
return (tag == ATAG_NONE || tag == ATAG_CORE ||
tag == ATAG_INITRD || tag == ATAG_INITRD2);
}
static void copy_atags(const struct tag *tags)
{
const struct tag *t;
struct tag *copy;
if (!tags)
return;
/* Calculate necessary size for tags we want to copy */
for_each_tag(t, tags) {
if (skip_atag(t->hdr.tag))
continue;
if (t->hdr.tag == ATAG_SERIAL)
parse_serial(&t->u.serialnr);
if (t->hdr.tag == ATAG_CMDLINE)
parse_cmdline(&t->u.cmdline);
fw_atags_size += t->hdr.size * sizeof(u32);
}
if (!fw_atags_size)
return; /* No tags to copy */
copy = malloc(fw_atags_size);
if (!copy)
return;
fw_atags_copy = copy;
/* Copy tags */
for_each_tag(t, tags) {
if (skip_atag(t->hdr.tag))
continue;
memcpy(copy, t, t->hdr.size * sizeof(u32));
copy = tag_next(copy);
}
}
int misc_init_r(void)
{
copy_atags(fw_atags_get());
return 0;
}
void setup_board_tags(struct tag **in_params)
{
if (!fw_atags_copy)
return;
/*
* fw_atags_copy contains only full "struct tag" (plus data)
* so copying it bytewise here should be fine.
*/
memcpy(*in_params, fw_atags_copy, fw_atags_size);
*(u8 **)in_params += fw_atags_size;
}
/* These numbers are unique per product but not across all products */
#define SAMSUNG_CODINA_LCD_LMS380KF01 4
#define SAMSUNG_CODINA_LCD_S6D27A1 13
#define SAMSUNG_SKOMER_LCD_HVA40WV1 10
#define SAMSUNG_SKOMER_LCD_NT35512 12
static void codina_patch_display(void *fdt)
{
int node;
int ret;
node = fdt_path_offset(fdt, "/spi-gpio-0/panel");
if (node < 0) {
printf("cannot find Codina panel node\n");
return;
}
if (lcdtype == SAMSUNG_CODINA_LCD_LMS380KF01) {
ret = fdt_setprop_string(fdt, node, "compatible", "samsung,lms380kf01");
if (ret < 0)
printf("could not set LCD compatible\n");
else
printf("updated LCD compatible to LMS380KF01\n");
} else if (lcdtype == SAMSUNG_CODINA_LCD_S6D27A1) {
ret = fdt_setprop_string(fdt, node, "compatible", "samsung,s6d27a1");
if (ret < 0)
printf("could not set LCD compatible\n");
else
printf("updated LCD compatible to S6D27A1\n");
} else {
printf("unknown LCD type\n");
}
}
static void skomer_kyle_patch_display(void *fdt)
{
int node;
int ret;
node = fdt_path_offset(fdt, "/soc/mcde/dsi/panel");
if (node < 0) {
printf("cannot find Skomer/Kyle panel node\n");
return;
}
if (lcdtype == SAMSUNG_SKOMER_LCD_HVA40WV1) {
ret = fdt_setprop_string(fdt, node, "compatible", "hydis,hva40wv1");
if (ret < 0)
printf("could not set LCD compatible\n");
else
printf("updated LCD compatible to Hydis HVA40WV1\n");
} else if (lcdtype == SAMSUNG_SKOMER_LCD_NT35512) {
/*
* FIXME: This panel is actually a BOE product, but we don't know
* the exact product name, so the compatible for the NT35512
* is used for the time being. The vendor drivers also call it NT35512.
*/
ret = fdt_setprop_string(fdt, node, "compatible", "novatek,nt35512");
if (ret < 0)
printf("could not set LCD compatible\n");
else
printf("updated LCD compatible to Novatek NT35512\n");
} else {
printf("unknown LCD type\n");
}
}
int ft_board_setup(void *fdt, struct bd_info *bd)
{
const char *str;
int node;
int ret;
printf("stemmy patch: DTB at 0x%08lx\n", (ulong)fdt);
/* Inspect FDT to see what we've got here */
ret = fdt_check_header(fdt);
if (ret < 0) {
printf("invalid DTB\n");
return ret;
}
node = fdt_path_offset(fdt, "/");
if (node < 0) {
printf("cannot find root node\n");
return node;
}
str = fdt_stringlist_get(fdt, node, "compatible", 0, NULL);
if (!str) {
printf("could not find board compatible\n");
return -1;
}
if (!strcmp(str, "samsung,janice")) {
switch(board_id) {
case 7:
printf("Janice GT-I9070 Board Rev 0.0\n");
break;
case 8:
printf("Janice GT-I9070 Board Rev 0.1\n");
break;
case 9:
printf("Janice GT-I9070 Board Rev 0.2\n");
break;
case 10:
printf("Janice GT-I9070 Board Rev 0.3\n");
break;
case 11:
printf("Janice GT-I9070 Board Rev 0.4\n");
break;
case 12:
printf("Janice GT-I9070 Board Rev 0.5\n");
break;
case 13:
printf("Janice GT-I9070 Board Rev 0.6\n");
break;
default:
break;
}
} else if (!strcmp(str, "samsung,gavini")) {
switch(board_id) {
case 7:
printf("Gavini GT-I8530 Board Rev 0.0\n");
break;
case 8:
printf("Gavini GT-I8530 Board Rev 0.0A\n");
break;
case 9:
printf("Gavini GT-I8530 Board Rev 0.0B\n");
break;
case 10:
printf("Gavini GT-I8530 Board Rev 0.0A_EMUL\n");
break;
case 11:
printf("Gavini GT-I8530 Board Rev 0.0C\n");
break;
case 12:
printf("Gavini GT-I8530 Board Rev 0.0D\n");
break;
case 13:
printf("Gavini GT-I8530 Board Rev 0.1\n");
break;
case 14:
printf("Gavini GT-I8530 Board Rev 0.3\n");
break;
default:
break;
}
} else if (!strcmp(str, "samsung,codina")) {
switch(board_id) {
case 7:
printf("Codina GT-I8160 Board Rev 0.0\n");
break;
case 8:
printf("Codina GT-I8160 Board Rev 0.1\n");
break;
case 9:
printf("Codina GT-I8160 Board Rev 0.2\n");
break;
case 10:
printf("Codina GT-I8160 Board Rev 0.3\n");
break;
case 11:
printf("Codina GT-I8160 Board Rev 0.4\n");
break;
case 12:
printf("Codina GT-I8160 Board Rev 0.5\n");
break;
default:
break;
}
codina_patch_display(fdt);
} else if (!strcmp(str, "samsung,codina-tmo")) {
switch(board_id) {
case 0x101:
printf("Codina SGH-T599 Board pre-Rev 0.0\n");
break;
case 0x102:
printf("Codina SGH-T599 Board Rev 0.0\n");
break;
case 0x103:
printf("Codina SGH-T599 Board Rev 0.1\n");
break;
case 0x104:
printf("Codina SGH-T599 Board Rev 0.2\n");
break;
case 0x105:
printf("Codina SGH-T599 Board Rev 0.4\n");
break;
case 0x106:
printf("Codina SGH-T599 Board Rev 0.6\n");
break;
case 0x107:
printf("Codina SGH-T599 Board Rev 0.7\n");
break;
default:
break;
}
codina_patch_display(fdt);
} else if (!strcmp(str, "samsung,golden")) {
switch(board_id) {
case 0x102:
printf("Golden GT-I8190 Board SW bringup\n");
break;
case 0x103:
printf("Golden GT-I8190 Board Rev 0.2\n");
break;
case 0x104:
printf("Golden GT-I8190 Board Rev 0.3\n");
break;
case 0x105:
printf("Golden GT-I8190 Board Rev 0.4\n");
break;
case 0x106:
printf("Golden GT-I8190 Board Rev 0.5\n");
break;
case 0x107:
printf("Golden GT-I8190 Board Rev 0.6\n");
break;
default:
break;
}
} else if (!strcmp(str, "samsung,skomer")) {
switch(board_id) {
case 0x101:
printf("Skomer GT-S7710 Board Rev 0.0\n");
break;
case 0x102:
printf("Skomer GT-S7710 Board Rev 0.1\n");
break;
case 0x103:
printf("Skomer GT-S7710 Board Rev 0.2\n");
break;
case 0x104:
printf("Skomer GT-S7710 Board Rev 0.3\n");
break;
case 0x105:
printf("Skomer GT-S7710 Board Rev 0.4\n");
break;
case 0x106:
printf("Skomer GT-S7710 Board Rev 0.5\n");
break;
case 0x107:
printf("Skomer GT-S7710 Board Rev 0.6\n");
break;
case 0x108:
printf("Skomer GT-S7710 Board Rev 0.7\n");
break;
case 0x109:
printf("Skomer GT-S7710 Board Rev 0.8\n");
break;
default:
break;
}
skomer_kyle_patch_display(fdt);
} else if (!strcmp(str, "samsung,kyle")) {
switch(board_id) {
case 0x101:
printf("Kyle SGH-I407 Board Rev 0.0\n");
break;
case 0x102:
printf("Kyle SGH-I407 Board Rev 0.1\n");
break;
case 0x103:
printf("Kyle SGH-I407 Board Rev 0.2\n");
break;
case 0x104:
printf("Kyle SGH-I407 Board Rev 0.3\n");
break;
case 0x105:
printf("Kyle SGH-I407 Board Rev 0.4\n");
break;
case 0x106:
printf("Kyle SGH-I407 Board Rev 0.5\n");
break;
case 0x107:
printf("Kyle SGH-I407 Board Rev 0.6\n");
break;
default:
break;
}
skomer_kyle_patch_display(fdt);
}
return 0;
}
|