转载自 http://blog.csdn.net/mahao1107/article/details/53404495
cm驱动的源代码解读
在我们调屏之前,我们一定要弄懂源代码框架以及每一行代码代表的意思,那么就让我们首先来看看代码(以ili9806e为例)
1 #if defined(BUILD_LK)
2 #include <string.h>
3 #else
4 #include <linux/string.h>
5 #endif
6
7 #ifdef BUILD_LK
8 #include <platform/disp_drv_platform.h>
9
10 #elif defined(BUILD_UBOOT)
11 #include <asm/arch/mt_gpio.h>
12 #else
13
14 #include <mach/mt_gpio.h>
15 #endif
16 #include <cust_gpio_usage.h>
17
18 #include "lcm_drv.h"
19
20
22
23
24
25
26 #define FRAME_WIDTH (480)
27 #define FRAME_HEIGHT (800)
28
29 #define REGFLAG_DELAY 0xFD
30 #define REGFLAG_END_OF_TABLE 0xFE // END OF REGISTERS MARKER
31
32 #define LCM_DSI_CMD_MODE 0
33
34
35 #ifndef TRUE
36 #define TRUE 1
37 #endif
38
39 #ifndef FALSE
40 #define FALSE 0
41 #endif
42
43 #define GPIO_LCM_ID GPIO18
44 #define LCM_TDT 0
45
46 bool lcm_ili9806e_vendor=LCM_TDT;
47
48
49
50 #define LCM_ID_ILI9806E (0x980604)
51
52 #define LCM_DEBUG
53
54
55
56
57
58
59
60 static LCM_UTIL_FUNCS lcm_util = {0};
61
62
63 #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v))) //这里就会直接使用GPIO_LCD_RST硬引脚
64 #define UDELAY(n) (lcm_util.udelay(n))
65 #define MDELAY(n) (lcm_util.mdelay(n))
66
68
69
70
71
72
73 #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
74 #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
75
76
77 #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
78 #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
79 #define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd)
80 #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
81
82
83 struct LCM_setting_table {
84 unsigned char cmd;
85 unsigned char count;
86 unsigned char para_list[64];
87 };
88
90
91 static struct LCM_setting_table lcm_initialization_setting[] = {
92
93
94
95 {0xFF,5,{0xFF,0x98,0x06,0x04,0x01}},
96 {0x08,1,{0x10}},
97 {0x21,1,{0x01}},
98 {0x30,1,{0x02}},
99 {0x31,1,{0x00}},
100 {0x60,1,{0x07}},
101 {0x61,1,{0x04}},
102 {0x62,1,{0x08}},
103 {0x63,1,{0x04}},
104 {0x40,1,{0x10}},
105 {0x41,1,{0x44}},
106 {0x42,1,{0x03}},
107 {0x43,1,{0x89}},
108 {0x44,1,{0x86}},
109
.....(此处省略代码n条初始化代码)
234 {0x11,1,{0x00}},
235 {REGFLAG_DELAY,120,{}},
236 {0x29,1,{0x00}},
237 {REGFLAG_DELAY, 20, {}},
238
239 {REGFLAG_END_OF_TABLE, 0x00, {}}
240 };
241
420
421 static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update)
422 {
423 unsigned int i;
424
425 for(i = 0; i < count; i++) {
426
427 unsigned cmd;
428 cmd = table[i].cmd;
429
430 switch (cmd) {
431
432 case REGFLAG_DELAY :
433 MDELAY(table[i].count);
434 break;
435
436 case REGFLAG_END_OF_TABLE :
437 break;
438
439 default:
440 dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
441 }
442 }
443
444 }
445
448
449
450
451
452 static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
453 {
454 memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
455 }
456
457
458
459 static void lcm_get_params(LCM_PARAMS *params)
460 {
461 memset(params, 0, sizeof(LCM_PARAMS));
462
463 params->type = LCM_TYPE_DSI;
464
465 params->width = FRAME_WIDTH;
466 params->height = FRAME_HEIGHT;
467
468
469
470
471 #ifndef BUILD_UBOOT
472
473
474 params->dbi.te_mode = LCM_DBI_TE_MODE_DISABLED;
475 #endif
476
477
478 #if (LCM_DSI_CMD_MODE)
479 params->dsi.mode = CMD_MODE;
480 #else
481 params->dsi.mode = SYNC_PULSE_VDO_MODE;
482 #endif
483
484
485
486
487
488 params->dsi.LANE_NUM = LCM_TWO_LANE;
489
490 params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
491 params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
492 params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
493 params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
494
495
496
497 params->dsi.packet_size=256;
498
499
500 params->dsi.intermediat_buffer_num = 2;
501
502 params->dsi.PS=LCM_PACKED_PS_24BIT_RGB888;
503
504
505
506 params->dsi.vertical_sync_active = 6;
507 params->dsi.vertical_backporch = 14;
508 params->dsi.vertical_frontporch = 20;
509 params->dsi.vertical_active_line = FRAME_HEIGHT;
510
511
512
513 params->dsi.horizontal_sync_active = 10;
514 params->dsi.horizontal_backporch = 80;
515 params->dsi.horizontal_frontporch = 80;
516 params->dsi.horizontal_active_pixel = FRAME_WIDTH;
517
518
519
520
521
522
523
524 params->dsi.PLL_CLOCK = 130;
525
526
527 }
528
529
530
531 static bool lcm_select_panel(void)
532 {
533 int value=0;
534
535 mt_set_gpio_mode(GPIO_LCM_ID,GPIO_MODE_00);
536
537 mt_set_gpio_pull_enable(GPIO_LCM_ID, GPIO_PULL_DISABLE);
538
539 mt_set_gpio_dir(GPIO_LCM_ID, GPIO_DIR_IN);
540
541 value+=mt_get_gpio_in(GPIO_LCM_ID);
542 if(value)
543 return LCM_TDT;
544
545 return LCM_TDT;
546 }
547
548
549
550
551
552 static void lcm_init(void)
553 {
554
560
561
562 SET_RESET_PIN(1);
563 SET_RESET_PIN(0);
564 MDELAY(100);
565 SET_RESET_PIN(1);
566 MDELAY(50);
567
568
569 push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
570 }
571
572
573
574
580 static void lcm_suspend(void)
581 {
582 #ifdef BUILD_LK
583 printf("%s, ALS/PS bbbbbbbbbbbbbbb \n", __func__);
584 #else
585 printk("%s, ALS/PS bbbbbbbbbbbbbb \n", __func__);
586 #endif
587
588 push_table(lcm_deep_sleep_mode_in_setting, sizeof(lcm_deep_sleep_mode_in_setting) / sizeof(struct LCM_setting_table), 1);
589 }
590
591
592
593
594 static void lcm_resume(void)
595 {
596
597 lcm_init();
598
599
600
601 }
602
603
604
605
606 static void lcm_update(unsigned int x, unsigned int y,
607 unsigned int width, unsigned int height)
608 {
609 unsigned int x0 = x;
610 unsigned int y0 = y;
611 unsigned int x1 = x0 + width - 1;
612 unsigned int y1 = y0 + height - 1;
613
614 unsigned char x0_MSB = ((x0>>8)&0xFF);
615 unsigned char x0_LSB = (x0&0xFF);
616 unsigned char x1_MSB = ((x1>>8)&0xFF);
617 unsigned char x1_LSB = (x1&0xFF);
618 unsigned char y0_MSB = ((y0>>8)&0xFF);
619 unsigned char y0_LSB = (y0&0xFF);
620 unsigned char y1_MSB = ((y1>>8)&0xFF);
621 unsigned char y1_LSB = (y1&0xFF);
622
623 unsigned int data_array[16];
633 dsi_set_cmdq(data_array, 7, 0);
634
635 }
636
637
638 static unsigned int lcm_esd_test = FALSE;
639
640 static unsigned int lcm_esd_check(void)
641 {
642 #ifndef BUILD_LK
643 char buffer[3];
644 char buffer2[4];
645 int array[4];
646
647 if(lcm_esd_test)
648 {
649 lcm_esd_test = FALSE;
650 return TRUE;
651 }
652 return TRUE;
653 #endif
654
655 }
656
657 static unsigned int lcm_esd_recover(void)
658 {
659 #ifndef BUILD_LK
660 lcm_init();
661
662
663 printk("lcm_esd_recover\n");
664
665 return TRUE;
666 #endif
667 }
668
669
670
671 static unsigned int lcm_compare_id(void)
672 {
673
674 int array[4];
675 char buffer[5];
676 char id_high=0;
677 char id_midd=0;
678 char id_low=0;
679 int id=0;
680
681
682
687
688
689 SET_RESET_PIN(1);
690 SET_RESET_PIN(0);
691 MDELAY(100);
692 SET_RESET_PIN(1);
693 MDELAY(50);
694
695
696 array[0]=0x00063902;
697 array[1]=0x0698ffff;
698 array[2]=0x00000104;
699 dsi_set_cmdq(array, 3, 1);
700 MDELAY(10);
701
702
703 array[0]=0x00033700;
704 dsi_set_cmdq(array, 1, 1);
705
706
707 read_reg_v2(0x00, buffer,1);
708 id_high = buffer[0];
709
710 read_reg_v2(0x01, buffer,1);
711 id_midd = buffer[0];
712
713 read_reg_v2(0x02, buffer,1);
714 id_low = buffer[0];
715
716 id =(id_high << 16) | (id_midd << 8) | id_low;
717
718 #if defined(BUILD_LK)
719 printf("ILI9806E compare-LK:0x%02x,0x%02x,0x%02x,0x%02x\n", id_high, id_midd, id_low, id);
720 #else
721 printk("ILI9806E compare:0x%02x,0x%02x,0x%02x,0x%02x\n", id_high, id_midd, id_low, id);
722 #endif
723
724 return (id == LCM_ID_ILI9806E)?1:0;
725 }
726
727
728
729 LCM_DRIVER ili9806e_wvga_dsi_vdo_lcm_drv=
730 {
731 .name = "ili9806e_wvga_dsi_vdo",
732 .set_util_funcs = lcm_set_util_funcs,
733 .get_params = lcm_get_params,
734 .init = lcm_init,
735 .suspend = lcm_suspend,
736 .resume = lcm_resume,
737 .compare_id = lcm_compare_id,
738 .esd_check = lcm_esd_check,
739 .esd_recover = lcm_esd_recover,
740 #if (LCM_DSI_CMD_MODE)
741 .update = lcm_update,
742 #endif
743 };
744
- 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
一般情况下lcm驱动无非就是这些函数组成,当然lcm屏厂商当然会给我们提供一些初始化代码,以及lcm屏数据手册,这些是我们要认真看的。
lcm移植过程:
lk:
在内核目录下bootable/bootloader/lk/dev/lcm/下存放的是各种lcm厂商的lcm驱动,其中也有一个mt67xx_lcm_list.c文件,
里面定义了所有的lcm驱动)
1.移植是首先要在lcm/目录下建立一个所移植的那个lcm屏的目录文件夹,目录文件夹名字选取是根据你所定义的设备名统一。
2.在建的这个目录下添加lcm驱动和makefile文件,如果你有lcm驱动就放在这个目录下,如果没有,就找lcm目录下其他的lcm驱动
文件夹中的.c文件进行修改后放在此目录下
3.准备工作做好后,修改文件主要有几个,一个是mt67xx_list.c:
在这个文件中加入你所添加的驱动定义:格式和方法参照文件中其他lcm的定义。
另一个是bootable/blltloader/lk/project/这个目录下有你编译的工程文件(就是你lunch的时候选取的那个文件,Project.mk).mk文件,
在这个文件下主要修改的是CUSTOM_LK_LCM、和BOOT_LOGO,把这两个修改成你移植的对应的参数,CUSTOM_LK_LCM要和你的文件名,目录名,
还有你的.c文件中的.name变量的值统一。logo,以及lcm屏的宽、高,看lcm数据手册。
kernel:
kernel/drives/misc/mediatek/lcm/....在这个目录下加入和lk当时候加入的是一样的。直接拷贝过来就可以。同样修改mt67xx_lcm_list.c文件
kernel-3.10/arch/arm64/configs/..目录下是:工程名_debug_defconfig,和对应:工程名_defconfig这两种文件,其中后缀是debug_defconfig的
文件是eng对应的,而defconfig是user对应的。
(在我们的lunch所打印出来的工程中有三种后缀,eng(调试工程)、user(用户工程)、userdebug,
进入这个文件后,反斜杠搜索/lcm 然后修改对应的名称和分辨率。
编译: make -j12 2>&1 | tee log.txt
上面讲述的仅仅是加入文件的修改过程,至于调试的话,这个是要积累的经验,把所移植好的代码烧进我们对应的板子,然后编译看效果,然后在针对对应的效果进行调试