微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > S5PV210(TQ210)学习笔记——LCD驱动编写

S5PV210(TQ210)学习笔记——LCD驱动编写

时间:11-28 来源:互联网 点击:
网上S5PV210内核移植的文章不是很多,而描述2440和6410内核移植的文章多数是讲如何移植,而非手动编写,但是,韦东山老师的视频中讲述了如何从头编写LCD驱动,当然是以2440为例的,我看过视频之后在TQ210平台上进行了实验,实验成功,详细的原理部分以我现在的水平还难以表达清楚。下载是我自己写的代码,适用于TQ210的7寸电容屏。

  1. #include
  2. #include
  3. #include
  4. #include
  5. staticstructfb_info*lcd_info;
  6. unsignedlongpseudo_palette[16];
  7. unsignedlong*display_control;
  8. volatileunsignedlong*gpf0con;
  9. volatileunsignedlong*gpf1con;
  10. volatileunsignedlong*gpf2con;
  11. volatileunsignedlong*gpf3con;
  12. volatileunsignedlong*gpd0con;
  13. volatileunsignedlong*gpd0dat;
  14. volatileunsignedlong*vidcon0;
  15. volatileunsignedlong*vidcon1;
  16. volatileunsignedlong*vidtcon0;
  17. volatileunsignedlong*vidtcon1;
  18. volatileunsignedlong*vidtcon2;
  19. volatileunsignedlong*wincon0;
  20. volatileunsignedlong*vidosd0a;
  21. volatileunsignedlong*vidosd0b;
  22. volatileunsignedlong*vidosd0c;
  23. volatileunsignedlong*vidw00add0b0;
  24. volatileunsignedlong*vidw00add1b0;
  25. volatileunsignedlong*shodowcon;
  26. structclk*lcd_clk;
  27. staticinlineunsignedintchan_to_field(unsignedintchan,structfb_bitfield*bf)
  28. {
  29. chan&=0xffff;
  30. chan>>=16-bf->length;
  31. returnchanoffset;
  32. }
  33. staticintlcdfb_setcolreg(unsignedintregno,unsignedintred,
  34. unsignedintgreen,unsignedintblue,
  35. unsignedinttransp,structfb_info*info)
  36. {
  37. unsignedintval;
  38. if(regno>16)
  39. return1;
  40. /*用red,green,blue三原色构造出val*/
  41. val=chan_to_field(red,&info->var.red);
  42. val|=chan_to_field(green,&info->var.green);
  43. val|=chan_to_field(blue,&info->var.blue);
  44. //((u32*)(info->pseudo_palette))[regno]=val;
  45. pseudo_palette[regno]=val;
  46. return0;
  47. }
  48. staticstructfb_opslcd_fbops={
  49. .owner=THIS_MODULE,
  50. .fb_setcolreg=lcdfb_setcolreg,
  51. .fb_fillrect=cfb_fillrect,
  52. .fb_copyarea=cfb_copyarea,
  53. .fb_imageblit=cfb_imageblit,
  54. };
  55. staticintlcd_init(void){
  56. intret;
  57. /*分配fb_info*/
  58. lcd_info=framebuffer_alloc(0,NULL);
  59. if(lcd_info==NULL){
  60. printk(KERN_ERR"allocframebufferfailed!");
  61. return-ENOMEM;
  62. }
  63. /*配置fb_info各成员*/
  64. /*fix*/
  65. strcpy(lcd_info->fix.id,"s5pv210_lcd");
  66. lcd_info->fix.smem_len=800*480*4;
  67. lcd_info->fix.type=FB_TYPE_PACKED_PIXELS;
  68. lcd_info->fix.visual=FB_VISUAL_TRUECOLOR;
  69. lcd_info->fix.line_length=800*4;
  70. /*var*/
  71. lcd_info->var.xres=800;
  72. lcd_info->var.yres=480;
  73. lcd_info->var.xres_virtual=800;
  74. lcd_info->var.yres_virtual=480;
  75. lcd_info->var.bits_per_pixel=32;
  76. lcd_info->var.red.offset=16;
  77. lcd_info->var.red.length=8;
  78. lcd_info->var.green.offset=8;
  79. lcd_info->var.green.length=8;
  80. lcd_info->var.blue.offset=0;
  81. lcd_info->var.blue.length=8;
  82. lcd_info->var.activate=FB_ACTIVATE_NOW;
  83. lcd_info->screen_size=800*480*4;
  84. lcd_info->pseudo_palette=pseudo_palette;
  85. lcd_info->fbops=&lcd_fbops;
  86. /*配置硬件资源*/
  87. /*映射内存*/
  88. display_control=ioremap(0xe0107008,4);
  89. gpf0con=ioremap(0xE0200120,4);
  90. gpf1con=ioremap(0xE0200140,4);
  91. gpf2con=ioremap(0xE0200160,4);
  92. gpf3con=ioremap(0xE0200180,4);
  93. gpd0con=ioremap(0xE02000A0,4);
  94. gpd0dat=ioremap(0xE02000A4,4);
  95. vidcon0=ioremap(0xF8000000,4);
  96. vidcon1=ioremap(0xF8000004,4);
  97. vidtcon0=ioremap(0xF8000010,4);
  98. vidtcon1=ioremap(0xF8000014,4);
  99. vidtcon2=ioremap(0xF8000018,4);
  100. wincon0=ioremap(0xF8000020,4);
  101. vidosd0a=ioremap(0xF8000040,4);
  102. vidosd0b=ioremap(0xF8000044,4);
  103. vidosd0c=ioremap(0xF8000048,4);
  104. vidw00add0b0=ioremap(0xF80000A0,4);
  105. vidw00add1b0=ioremap(0xF80000D0,4);
  106. shodowcon=ioremap(0xF8000034,4);
  107. /*配置GPIO*/
  108. *gpf0con=0x22222222;
  109. *gpf1con=0x22222222;
  110. *gpf2con=0x22222222;
  111. *gpf3con=0x22222222;
  112. *gpd0con&=~0xf;
  113. *gpd0con|=0x1;
  114. *gpd0dat|=1<0;
  115. *display_control=2<0;
  116. /*使能时钟*/
  117. lcd_clk=clk_get(NULL,"lcd");
  118. if(!lcd_clk||IS_ERR(lcd_clk)){
  119. printk(KERN_INFO"failedtogetlcdclocksource");
  120. }
  121. clk_enable(lcd_clk);
  122. /*配置LCD控制器*/
  123. *vidcon0=(4<6)|(1<4);
  124. *vidcon1=(1<6)|(1<5)|(1<4);
  125. *vidtcon0=(17<16)|(26<8)|(4<0);
  126. *vidtcon1=(40<16)|(214<8)|(4<0);
  127. *vidtcon2=(479<11)|(799<0);
  128. *wincon0&=~(0xf<2);
  129. *wincon0|=(0xb<2);
  130. *vidosd0a=(0<11)|(0<0);
  131. *vidosd0b=(799<11)|(479<0);
  132. *vidosd0c=480*800;
  133. //物理地址
  134. lcd_info->lcd_info->scree

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top