hc
2023-11-06 9df731a176aab8e03b984b681b1bea01ccff6644
u-boot/arch/arm/mach-rockchip/kernel_dtb.c
old mode 100755new mode 100644
....@@ -16,503 +16,6 @@
1616
1717 DECLARE_GLOBAL_DATA_PTR;
1818
19
-
20
-#if 1
21
-struct display_fixup_data {
22
- int type;
23
-
24
- int delay_prepare;
25
- int delay_enable;
26
- int delay_disable;
27
- int delay_unprepare;
28
- int delay_reset;
29
- int delay_init;
30
- int size_width;
31
- int size_height;
32
-
33
- int clock_frequency;
34
- int hactive;
35
- int hfront_porch;
36
- int hsync_len;
37
- int hback_porch;
38
- int vactive;
39
- int vfront_porch;
40
- int vsync_len;
41
- int vback_porch;
42
- int hsync_active;
43
- int vsync_active;
44
- int de_active;
45
- int pixelclk_active;
46
-
47
- /* for DSI Panel */
48
- int flags;
49
- int format;
50
- int lanes;
51
- int init_cmd_length;
52
- u8 *init_cmd;
53
-
54
- int nodka_lvds;
55
-};
56
-enum {
57
- PANEL_TYPE_DSI,
58
- PANEL_TYPE_EDP,
59
- PANEL_TYPE_LVDS,
60
-};
61
-
62
-#define CUSTOM_PARTITION_NAME "baseparameter"
63
-#define LCD_PARAM_MAX_COUNT 27
64
-
65
-int lcdParam[LCD_PARAM_MAX_COUNT];
66
-char param_buf_temp[4*1024] = {0};
67
-
68
-void set_lcdparam_test_edp(struct display_fixup_data *data)
69
-{
70
-
71
- data->type = PANEL_TYPE_DSI;
72
- data->delay_prepare = 100;
73
- data->delay_enable = 100;
74
- data->delay_disable = 100;
75
- data->delay_unprepare = 100;
76
- data->delay_reset = 100;
77
- data->delay_init = 100;
78
- data->size_width = 240;
79
- data->size_height = 300;
80
- data->clock_frequency = 60000000;
81
- data->hactive = 1024;
82
- data->hfront_porch = 12;
83
- data->hsync_len = 16;
84
- data->hback_porch = 48;
85
- data->vactive = 600;
86
- data->vfront_porch = 8;
87
- data->vsync_len = 4;
88
- data->vback_porch = 8;
89
- data->hsync_active = 0;
90
- data->vsync_active = 0;
91
- data->de_active = 0;
92
- data->pixelclk_active = 0;
93
- data->flags = 0;
94
- data->format = 0;
95
- data->lanes = 4;
96
- *(data->init_cmd + 0) = 0x05;
97
- *(data->init_cmd + 1) = 0x00;
98
- *(data->init_cmd + 2) = 0x01;
99
- *(data->init_cmd + 3) = 0x01;
100
-
101
- *(data->init_cmd + 4) = 0x05;
102
- *(data->init_cmd + 5) = 0x00;
103
- *(data->init_cmd + 6) = 0x01;
104
- *(data->init_cmd + 7) = 0x02;
105
-
106
- *(data->init_cmd + 8) = 0x05;
107
- *(data->init_cmd + 9) = 0x00;
108
- *(data->init_cmd + 10) = 0x01;
109
- *(data->init_cmd + 11) = 0x03;
110
-
111
- *(data->init_cmd + 12) = 0x05;
112
- *(data->init_cmd + 13) = 0x00;
113
- *(data->init_cmd + 14) = 0x01;
114
- *(data->init_cmd + 15) = 0x05;
115
-
116
-}
117
-
118
-int get_lcdparam_info_from_custom_partition(struct display_fixup_data *data)
119
-{
120
-
121
- struct blk_desc *dev_desc;
122
- disk_partition_t part_info;
123
- char *boot_partname = CUSTOM_PARTITION_NAME;
124
- int ret,i;
125
-
126
- dev_desc = rockchip_get_bootdev();
127
- if (!dev_desc) {
128
- printf("%s: dev_desc is NULL!\n", __func__);
129
- return -ENODEV;
130
- }
131
-
132
- ret = part_get_info_by_name(dev_desc, boot_partname, &part_info);
133
- if (ret < 0) {
134
- printf("%s: failed to get %s part, ret=%d\n",
135
- __func__, boot_partname, ret);
136
- /* RKIMG can support part table without 'boot' */
137
- return -1;
138
- }
139
-
140
- printf("block num: %lu, name %s ,type %s,block size :%lu\n",part_info.size,part_info.name,part_info.type,part_info.blksz);
141
-
142
- ret = blk_dread(dev_desc, part_info.start + 512, 1, param_buf_temp);
143
- if (ret != 1) {
144
- printf("%s: failed to read screen parameter, ret=%d\n",
145
- __func__, ret);
146
- return -1;
147
- }
148
-
149
- for (i = 0; i < LCD_PARAM_MAX_COUNT; i++) {
150
- lcdParam[i] = param_buf_temp[i * 4];
151
- lcdParam[i] = (lcdParam[i] << 8) + param_buf_temp[i * 4 + 1];
152
- lcdParam[i] = (lcdParam[i] << 8) + param_buf_temp[i * 4 + 2];
153
- lcdParam[i] = (lcdParam[i] << 8) + param_buf_temp[i * 4 + 3];
154
- if(lcdParam[i] < 0){
155
- lcdParam[i] = -lcdParam[i];
156
- }
157
- if(lcdParam[i] > 100000 && i != 9){
158
- lcdParam[i] = 0;
159
- }
160
- printf("--get-- lcd_param %d\n",lcdParam[i]);
161
- }
162
-
163
- if(lcdParam[14] == 0 || lcdParam[10] == 0){
164
- return -1;
165
- }
166
- printf("-get- crc32 = 0X%02X%02X%02X%02X\n",
167
- param_buf_temp[LCD_PARAM_MAX_COUNT * 4], param_buf_temp[LCD_PARAM_MAX_COUNT * 4 + 1],
168
- param_buf_temp[LCD_PARAM_MAX_COUNT * 4 + 2], param_buf_temp[LCD_PARAM_MAX_COUNT * 4 + 3]);
169
-
170
- data->type = lcdParam[0];
171
- data->delay_prepare = lcdParam[4];
172
- data->delay_enable = lcdParam[2];
173
- data->delay_disable = lcdParam[3];
174
- data->delay_unprepare = lcdParam[1];
175
- data->delay_reset = lcdParam[5];
176
- data->delay_init = lcdParam[6];
177
- data->size_width = lcdParam[7];
178
- data->size_height = lcdParam[8];
179
- data->clock_frequency = lcdParam[9];
180
- data->hactive = lcdParam[10];
181
- data->hfront_porch = lcdParam[11];
182
- data->hsync_len = lcdParam[12];
183
- data->hback_porch = lcdParam[13];
184
- data->vactive = lcdParam[14];
185
- data->vfront_porch = lcdParam[15];
186
- data->vsync_len = lcdParam[16];
187
- data->vback_porch = lcdParam[17];
188
- data->hsync_active = lcdParam[18];
189
- data->vsync_active = lcdParam[19];
190
- data->de_active = lcdParam[20];
191
- data->pixelclk_active = lcdParam[21];
192
- data->flags = lcdParam[22];
193
- data->format = lcdParam[23];
194
- data->lanes = lcdParam[24];
195
- data->init_cmd_length = lcdParam[25] = 16;
196
- data->nodka_lvds = lcdParam[26];
197
- data->init_cmd = malloc(sizeof(*(data->init_cmd)) * data->init_cmd_length);
198
- for(i = 0; i < data->init_cmd_length; i++){
199
- *(data->init_cmd + i) = param_buf_temp[100 + i];
200
- // printf("init cmd = %x\n",param_buf_temp[100 + i]);
201
-
202
- }
203
-
204
-// set_lcdparam_test_edp(data);
205
-
206
- return 0;
207
-}
208
-
209
-#endif
210
-
211
-
212
-static int find_connector_node(const void *blob, int node)
213
-{
214
- int phandle, remote;
215
- int nodedepth;
216
-
217
- phandle = fdt_getprop_u32_default_node(blob, node, 0,
218
- "remote-endpoint", -1);
219
- remote = fdt_node_offset_by_phandle(blob, phandle);
220
- nodedepth = fdt_node_depth(blob, remote);
221
-
222
- return fdt_supernode_atdepth_offset(blob, remote,
223
- nodedepth - 3, NULL);
224
-}
225
-
226
-static int get_panel_node(const void *blob, int conn_node)
227
-{
228
- int panel, ports, port, ep, remote, ph, nodedepth;
229
-
230
- panel = fdt_subnode_offset(blob, conn_node, "panel");
231
- printf("panel_1=%d\n",panel);
232
- if (panel > 0) {
233
- return panel;
234
- }
235
-
236
- ports = fdt_subnode_offset(blob, conn_node, "ports");
237
- if (ports < 0)
238
- {
239
- return -ENODEV;
240
- }
241
-
242
- fdt_for_each_subnode(port, blob, ports) {
243
- fdt_for_each_subnode(ep, blob, port) {
244
- ph = fdt_getprop_u32_default_node(blob, ep, 0,
245
- "remote-endpoint", 0);
246
- if (!ph)
247
- continue;
248
-
249
- remote = fdt_node_offset_by_phandle(blob, ph);
250
-
251
- nodedepth = fdt_node_depth(blob, remote);
252
- if (nodedepth < 2)
253
- continue;
254
-
255
- panel = fdt_supernode_atdepth_offset(blob, remote,
256
- nodedepth - 2,
257
- NULL);
258
- break;
259
- }
260
- }
261
- printf("panel_2=%d\n",panel);
262
- return panel;
263
-}
264
-
265
-static int fdt_fixup_node_status(void *blob, int node, enum fdt_status status)
266
-{
267
- int ret;
268
-
269
-// printf("My fixup %s %d\n", fdt_get_name(blob, node, NULL), status);
270
-
271
-set_status:
272
- ret = fdt_set_node_status(blob, node, status, 0);
273
- if (ret == -FDT_ERR_NOSPACE) {
274
- ret = fdt_increase_size(blob, 512);
275
- if (!ret)
276
- goto set_status;
277
- else
278
- goto err_size;
279
- } else if (ret < 0) {
280
- printf("Can't set node status: %s\n", fdt_strerror(ret));
281
- return ret;
282
- }
283
-
284
- return 0;
285
-
286
-err_size:
287
- printf("Can't increase blob size: %s\n", fdt_strerror(ret));
288
- return ret;
289
-}
290
-#if 0
291
-static int fdt_fixup_panel_init_sequence(void *fdt, int node,const struct display_fixup_data *data)
292
-{
293
- #if 0
294
- u8 init_buf[] = {0x05, 0x00, 0x01, 0x78, 0x15, 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x01, 0x14,0x39, 0x01, 0x03, 0x02, 0x29, 0x11};
295
- u8 exit_buf[] = {0x05, 0x64, 0x01, 0x29, 0x05, 0x64, 0x01, 0x11};
296
- #endif
297
- int ret;
298
-
299
-add_seq:
300
- ret = fdt_setprop(fdt, node, "panel-init-sequence", data->init_cmd, data->init_cmd_length);
301
- if (ret == -FDT_ERR_NOSPACE) {
302
- printf(" init sequence FDT_ERR_NOSPACE\n");
303
- ret = fdt_increase_size(fdt, data->init_cmd_length * 4);//gln the length needs precision
304
- if (!ret)
305
- goto add_seq;
306
- else
307
- goto err_size;
308
- } else if (ret < 0) {
309
- printf("Can't add property: %s\n", fdt_strerror(ret));
310
- return ret;
311
- }
312
-
313
-#if 0
314
-add_init_seq:
315
- ret = fdt_setprop(fdt, node, "panel-init-sequence", init_buf, sizeof(init_buf));
316
- if (ret == -FDT_ERR_NOSPACE) {
317
- printf(" init sequence FDT_ERR_NOSPACE\n");
318
- ret = fdt_increase_size(fdt, 512);//gln the length needs precision
319
- if (!ret)
320
- goto add_init_seq;
321
- else
322
- goto err_size;
323
- } else if (ret < 0) {
324
- printf("Can't add property: %s\n", fdt_strerror(ret));
325
- return ret;
326
- }
327
-add_exit_seq:
328
- ret = fdt_setprop(fdt, node, "panel-exit-sequence", exit_buf, sizeof(exit_buf));
329
- if (ret == -FDT_ERR_NOSPACE) {
330
- printf(" init sequence FDT_ERR_NOSPACE\n");
331
- ret = fdt_increase_size(fdt, 512);//gln the length needs precision
332
- if (!ret)
333
- goto add_exit_seq;
334
- else
335
- goto err_size;
336
- } else if (ret < 0) {
337
- printf("Can't add property: %s\n", fdt_strerror(ret));
338
- return ret;
339
- }
340
-#endif
341
-
342
- return 0;
343
-
344
-err_size:
345
- printf("Can't increase blob size: %s\n", fdt_strerror(ret));
346
- return ret;
347
-}
348
-#endif
349
-
350
-static int fdt_fixup_setprop_u32(void *fdt, int node, const char *name, u32 data)
351
-{
352
- int ret;
353
-
354
-set_prop:
355
- ret = fdt_setprop_u32(fdt, node, name, data);
356
- if (ret == -FDT_ERR_NOSPACE) {
357
- ret = fdt_increase_size(fdt, 512);
358
- if (!ret)
359
- goto set_prop;
360
- else
361
- goto err_size;
362
- } else if (ret < 0) {
363
- printf("Can't add property: %s\n", fdt_strerror(ret));
364
- return ret;
365
- }
366
-
367
- return 0;
368
-
369
-err_size:
370
- printf("Can't increase blob size: %s\n", fdt_strerror(ret));
371
- return ret;
372
-}
373
-
374
-static void fdt_fixup_display_timing(void *blob, int node,
375
- const struct display_fixup_data *data)
376
-{
377
- fdt_fixup_setprop_u32(blob, node, "clock-frequency", data->clock_frequency);
378
- fdt_fixup_setprop_u32(blob, node, "hactive", data->hactive);
379
- fdt_fixup_setprop_u32(blob, node, "hfront-porch", data->hfront_porch);
380
- fdt_fixup_setprop_u32(blob, node, "hsync-len", data->hsync_len);
381
- fdt_fixup_setprop_u32(blob, node, "hback-porch", data->hback_porch);
382
- fdt_fixup_setprop_u32(blob, node, "vactive", data->vactive);
383
- fdt_fixup_setprop_u32(blob, node, "vfront-porch", data->vfront_porch);
384
- fdt_fixup_setprop_u32(blob, node, "vsync-len", data->vsync_len);
385
- fdt_fixup_setprop_u32(blob, node, "vback-porch", data->vback_porch);
386
- fdt_fixup_setprop_u32(blob, node, "hsync-active", data->hsync_active);
387
- fdt_fixup_setprop_u32(blob, node, "vsync-active", data->vsync_active);
388
- fdt_fixup_setprop_u32(blob, node, "de-active", data->de_active);
389
- fdt_fixup_setprop_u32(blob, node, "pixelclk-active", data->pixelclk_active);
390
-}
391
-
392
-static void fdt_fixup_panel_node(void *blob, int node, const char *name,
393
- const struct display_fixup_data *data)
394
-{
395
-/*
396
- if (!strcmp(name, "dsi")) {
397
- fdt_setprop_u32(blob, node, "dsi,flags", data->flags);
398
- fdt_setprop_u32(blob, node, "dsi,format", data->format);
399
- fdt_setprop_u32(blob, node, "dsi,lanes", data->lanes);
400
- fdt_fixup_panel_init_sequence(blob, node,data);
401
- }
402
-*/
403
- fdt_fixup_setprop_u32(blob, node, "prepare-delay-ms", data->delay_prepare);
404
- fdt_fixup_setprop_u32(blob, node, "enable-delay-ms", data->delay_enable);
405
- fdt_fixup_setprop_u32(blob, node, "disable-delay-ms", data->delay_disable);
406
- fdt_fixup_setprop_u32(blob, node, "unprepare-delay-ms", data->delay_unprepare);
407
- fdt_fixup_setprop_u32(blob, node, "reset-delay-ms", data->delay_reset);
408
- fdt_fixup_setprop_u32(blob, node, "init-delay-ms", data->delay_init);
409
- fdt_fixup_setprop_u32(blob, node, "width-mm", data->size_width);
410
- fdt_fixup_setprop_u32(blob, node, "height-mm", data->size_height);
411
-
412
-}
413
-static void fdt_fixup_nodka_lvds(void *blob, int node,
414
- const struct display_fixup_data *data)
415
-{
416
- if ( data->nodka_lvds != 0 )
417
- fdt_fixup_setprop_u32(blob, node, "nodka-lvds", data->nodka_lvds);
418
-}
419
-
420
-
421
-static int fdt_fixup_display_sub_route(void *blob, const char *name,
422
- enum fdt_status status,
423
- const struct display_fixup_data *data)
424
-{
425
- int route, phandle, connect, connector, panel, dt, timing, route_lvds;
426
- char path[64];
427
- char path_lvds[16] = "/panel";
428
- int ret;
429
- sprintf(path, "/display-subsystem/route/route-%s", name);
430
-
431
-
432
- route = fdt_path_offset(blob, path);
433
- printf("route : %d \n",route);
434
- if (route < 0)
435
- return route;
436
-
437
- route_lvds = fdt_path_offset(blob, path_lvds);
438
- if (route_lvds < 0)
439
- {
440
- printf("can not get route_lvds = %d\n",route_lvds);
441
- return route_lvds;
442
- }
443
- /* fixup lvds gpio channel*/
444
- fdt_fixup_nodka_lvds(blob, route_lvds, data);
445
-
446
- /* fixup route status */
447
- ret = fdt_fixup_node_status(blob, route, status);
448
- if (ret < 0)
449
- return ret;
450
- phandle = fdt_getprop_u32_default_node(blob, route, 0, "connect", -1);
451
- if (phandle < 0)
452
- return phandle;
453
- connect = fdt_node_offset_by_phandle(blob, phandle);
454
- if (connect < 0)
455
- return connect;
456
- connector = find_connector_node(blob, connect);
457
- if (connector < 0)
458
- return connector;
459
- /* fixup connector status */
460
- ret = fdt_fixup_node_status(blob, connector, status);
461
- if (ret < 0)
462
- return ret;
463
- if (status != FDT_STATUS_OKAY) {
464
- return 0;
465
- }
466
- panel = get_panel_node(blob, connector);
467
- if (panel < 0)
468
- return panel;
469
- /* fixup panel info */
470
- fdt_fixup_panel_node(blob, panel, name, data);
471
- dt = fdt_subnode_offset(blob, panel, "display-timings");
472
- if (dt < 0) {
473
- return dt;
474
- }
475
- timing = fdt_subnode_offset(blob, dt, "timing");
476
- if (timing < 0) {
477
- phandle = fdt_getprop_u32_default_node(blob, dt, 0, "native-mode", -1);
478
- if (phandle < 0)
479
- return phandle;
480
-
481
- timing = fdt_node_offset_by_phandle(blob, phandle);
482
- if (timing < 0)
483
- return timing;
484
- }
485
-
486
- /* fixup panel display timing */
487
- fdt_fixup_display_timing(blob, timing, data);
488
- return 0;
489
-}
490
-
491
-static void fdt_fixup_display_route(void *blob, const struct display_fixup_data *data)
492
-{
493
- if (data->type == PANEL_TYPE_DSI) {
494
- fdt_fixup_display_sub_route(blob, "dsi1", FDT_STATUS_OKAY, data);
495
- fdt_fixup_display_sub_route(blob, "edp", FDT_STATUS_DISABLED, data);
496
- fdt_fixup_display_sub_route(blob, "lvds", FDT_STATUS_DISABLED, data);
497
- } else if (data->type == PANEL_TYPE_EDP) {
498
- fdt_fixup_display_sub_route(blob, "dsi1", FDT_STATUS_DISABLED, data);
499
- fdt_fixup_display_sub_route(blob, "edp", FDT_STATUS_OKAY, data);
500
- fdt_fixup_display_sub_route(blob, "lvds", FDT_STATUS_DISABLED, data);
501
- } else if (data->type == PANEL_TYPE_LVDS) {
502
- fdt_fixup_display_sub_route(blob, "lvds", FDT_STATUS_OKAY, data);
503
- fdt_fixup_display_sub_route(blob, "dsi1", FDT_STATUS_DISABLED, data);
504
- fdt_fixup_display_sub_route(blob, "edp", FDT_STATUS_DISABLED, data);
505
- }
506
-}
507
-
508
-
509
-
510
-
511
-
512
-
513
-
514
-
515
-
51619 #ifdef CONFIG_USING_KERNEL_DTB_V2
51720 static int dm_rm_kernel_dev(void)
51821 {
....@@ -798,7 +301,6 @@
798301 #endif
799302 ulong fdt_addr = 0;
800303 int ret = -ENODEV;
801
- struct display_fixup_data fix_data;
802304
803305 printf("DM: v%d\n", IS_ENABLED(CONFIG_USING_KERNEL_DTB_V2) ? 2 : 1);
804306
....@@ -815,12 +317,10 @@
815317 return -ENODEV;
816318 }
817319
818
- if (IS_ENABLED(CONFIG_EMBED_KERNEL_DTB_ALWAYS)) {
819
- resource_init_list();
820
- printf("Always embed kernel dtb\n");
821
- goto dtb_embed;
822
- }
823
-
320
+#ifdef CONFIG_EMBED_KERNEL_DTB_ALWAYS
321
+ printf("Always embed kernel dtb\n");
322
+ goto dtb_embed;
323
+#endif
824324 ret = rockchip_read_dtb_file((void *)fdt_addr);
825325 if (!ret) {
826326 if (!dtb_check_ok((void *)fdt_addr, (void *)gd->fdt_blob)) {
....@@ -831,7 +331,10 @@
831331 }
832332 }
833333
334
+#ifdef CONFIG_EMBED_KERNEL_DTB
335
+#ifdef CONFIG_EMBED_KERNEL_DTB_ALWAYS
834336 dtb_embed:
337
+#endif
835338 if (gd->fdt_blob_kern) {
836339 if (!dtb_check_ok((void *)gd->fdt_blob_kern, (void *)gd->fdt_blob)) {
837340 printf("Embedded kernel dtb mismatch this platform!\n");
....@@ -850,7 +353,9 @@
850353 memcpy((void *)fdt_addr, gd->fdt_blob_kern,
851354 fdt_totalsize(gd->fdt_blob_kern));
852355 printf("DTB: %s\n", CONFIG_EMBED_KERNEL_DTB_PATH);
853
- } else {
356
+ } else
357
+#endif
358
+ {
854359 printf("Failed to get kernel dtb, ret=%d\n", ret);
855360 return -ENOENT;
856361 }
....@@ -870,8 +375,6 @@
870375 phandles_fixup_cru((void *)gd->fdt_blob);
871376 phandles_fixup_gpio((void *)gd->fdt_blob, (void *)ufdt_blob);
872377 #endif
873
- if (!get_lcdparam_info_from_custom_partition(&fix_data))
874
- fdt_fixup_display_route((void *)fdt_addr, &fix_data);
875378
876379 gd->flags |= GD_FLG_KDTB_READY;
877380 gd->of_root_f = gd->of_root;