<2012 12 05> FL2440开发板的U-boot-2010.09版本移植(八)LCD的支持

一、LCD时序配置

     fl2440开发板的LCD是3.5寸屏型号是WXCAT35-TG3#001,这是一款320x240分辨率的TFT LCD屏,先来了解一下TFT LCD的时序如下:

图1 TFT LCD时序

(1)VSYNC信号来一个脉冲时,表示一帧的开始

(2) VSPW表示VSYNC信号的脉冲宽度为(VSPW+1)个HSYNC信号周期,即(VSPW+1)行,这(VSPW+1)行的数据无效。

(3)VSYNC信号脉冲之后,还要经过(VBPD+1)个(HSYNC)信号周期,有效的行数据才出现。所以,在VSYNC信号有效之后,总共还要经过(VSPW+1+VBPD+1)个无效行,

(4)随后连续发出(LINEVAL+1)行的有效数据

(5)最后是(VFPD+1)个无效行,完整的一帧结束,紧接着就是下一帧的数据了(即下一个VSYNC信号)。

(6)HSYNC信号有效时,表示一行数据的开始

(7) HSPW表示HSYNC信号的脉冲宽度为(HSPW+1)个VCLK信号周期,即(HSPW+1)个像素,这(HSPW+1)个像素的数据无效。

(8)HSYNC信号脉冲之后,还要经过(HBPD+1)个VCLK信号周期,有效的像素数据才会出现。所以,在HSYNC信号有效之后,总共还要经过(HSPW + 1 + HBPD + 1)个无效的像素,第一个有效像素才出现。

(9)随后即连续发出(HOZVAL+1)个像素的有效数据。

(10)最后是(HFPD+1)个无效的像素,完整的一行结束,紧接着就是下一行的数据了(即下一个HSYNC信号)。

TFT LCD的正常工作主要需要配置S3C2440的寄存器LCDCON1~LCDCON5

二、u-boot支持LCD的配置工作

首先要添加一个文件,driver/video/s3c2410_fb.c,其内容为:

[cpp]  view plain copy
  1. /* 
  2.  * (C) Copyright 2006 by OpenMoko, Inc. 
  3.  * Author: Harald Welte <laforge@openmoko.org> 
  4.  * 
  5.  * This program is free software; you can redistribute it and/or 
  6.  * modify it under the terms of the GNU General Public License as 
  7.  * published by the Free Software Foundation; either version 2 of 
  8.  * the License, or (at your option) any later version. 
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, 
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  13.  * GNU General Public License for more details. 
  14.  * 
  15.  * You should have received a copy of the GNU General Public License 
  16.  * along with this program; if not, write to the Free Software 
  17.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
  18.  * MA 02111-1307 USA 
  19.  */  
  20. #include <common.h>  
  21.    
  22. #if defined(CONFIG_VIDEO_S3C2410)||defined(CONFIG_VIDEO_S3C2440)  
  23.    
  24. #include <video_fb.h>  
  25. #include <asm/arch/s3c2410.h>  
  26.   
  27. #include "videomodes.h"  
  28. /* 
  29.  * Export Graphic Device 
  30.  */  
  31. static GraphicDevice smi;  
  32.    
  33. #define VIDEO_MEM_SIZE  0x200000        /* 240x320x16bit = 0x25800 bytes */  
  34.    
  35. extern void board_video_init( GraphicDevice *pGD);  
  36. /* 
  37.  * Add by yanghao 
  38.  */  
  39. /******************************************************************************* 
  40.  * 
  41.  * Init video chip with common Linux graphic modes (lilo) 
  42.  */  
  43. void *video_hw_init (void)  
  44. {  
  45.     struct s3c24x0_lcd * const lcd = s3c24x0_get_base_lcd();  
  46.     GraphicDevice *pGD = (GraphicDevice *)&smi;  
  47.     int videomode;  
  48.     unsigned long t1, hsynch, vsynch;  
  49.     char *penv;  
  50.     int tmp, i, bits_per_pixel;  
  51.     struct ctfb_res_modes *res_mode;  
  52.     struct ctfb_res_modes var_mode;  
  53. //    unsigned char videoout;  
  54.    
  55.     /* Search for video chip */  
  56.     printf("Video: ");  
  57.     tmp = 0;  
  58.    
  59.          videomode = CONFIG_SYS_DEFAULT_VIDEO_MODE;  
  60.          /* get video mode via environment */  
  61.          if ((penv = getenv ("videomode")) != NULL) {  
  62.                  /* deceide if it is a string */  
  63.                  if (penv[0] <= '9') {  
  64.                          videomode = (int) simple_strtoul (penv, NULL, 16);  
  65.                          tmp = 1;  
  66.                  }  
  67.          } else {  
  68.                  tmp = 1;  
  69.          }  
  70.          if (tmp) {  
  71.                  /* parameter are vesa modes */  
  72.                  /* search params */  
  73.                  for (i = 0; i < VESA_MODES_COUNT; i++) {  
  74.                          if (vesa_modes[i].vesanr == videomode)  
  75.                                  break;  
  76.                  }  
  77.                  if (i == VESA_MODES_COUNT) {  
  78.                          printf ("no VESA Mode found, switching to mode 0x%x ", CONFIG_SYS_DEFAULT_VIDEO_MODE);  
  79.                          i = 0;  
  80.                 }  
  81.                  res_mode =  
  82.                          (struct ctfb_res_modes *) &res_mode_init[vesa_modes[i].  
  83.                                                                   resindex];  
  84.                  bits_per_pixel = vesa_modes[i].bits_per_pixel;  
  85.          } else {  
  86.    
  87.                 res_mode = (struct ctfb_res_modes *) &var_mode;  
  88.                  bits_per_pixel = video_get_params (res_mode, penv);  
  89.          }  
  90.    
  91.          /* calculate hsynch and vsynch freq (info only) */  
  92.          t1 = (res_mode->left_margin + res_mode->xres +  
  93.                res_mode->right_margin + res_mode->hsync_len) / 8;  
  94.          t1 *= 8;  
  95.          t1 *= res_mode->pixclock;  
  96.          t1 /= 1000;  
  97.          hsynch = 1000000000L / t1;  
  98.          t1 *=  
  99.                  (res_mode->upper_margin + res_mode->yres +  
  100.                   res_mode->lower_margin + res_mode->vsync_len);  
  101.          t1 /= 1000;  
  102.          vsynch = 1000000000L / t1;  
  103.    
  104.          /* fill in Graphic device struct */  
  105.          sprintf (pGD->modeIdent, "%dx%dx%d %ldkHz %ldHz", res_mode->xres,  
  106.                   res_mode->yres, bits_per_pixel, (hsynch / 1000),  
  107.                   (vsynch / 1000));  
  108.          printf ("%s\n", pGD->modeIdent);  
  109.          pGD->winSizeX = res_mode->xres;  
  110.          pGD->winSizeY = res_mode->yres;  
  111.          pGD->plnSizeX = res_mode->xres;  
  112.          pGD->plnSizeY = res_mode->yres;  
  113.                
  114.          switch (bits_per_pixel) {  
  115.          case 8:  
  116.                  pGD->gdfBytesPP = 1;  
  117.                  pGD->gdfIndex = GDF__8BIT_INDEX;  
  118.                  break;  
  119.          case 15:  
  120.                  pGD->gdfBytesPP = 2;  
  121.                  pGD->gdfIndex = GDF_15BIT_555RGB;  
  122.                  break;  
  123.          case 16:  
  124.                  pGD->gdfBytesPP = 2;  
  125.                  pGD->gdfIndex = GDF_16BIT_565RGB;  
  126.                  break;  
  127.          case 24:  
  128.                  pGD->gdfBytesPP = 3;  
  129.                  pGD->gdfIndex = GDF_24BIT_888RGB;  
  130.                  break;  
  131.          }  
  132.    
  133.          /* statically configure settings */  
  134.         pGD->winSizeX = pGD->plnSizeX = 320;  
  135.          pGD->winSizeY = pGD->plnSizeY = 240;  
  136.          pGD->gdfBytesPP = 2;  
  137.          pGD->gdfIndex = GDF_16BIT_565RGB;  
  138.    
  139.          pGD->frameAdrs = LCD_VIDEO_ADDR;  
  140.          pGD->memSize = VIDEO_MEM_SIZE;  
  141.    
  142.          board_video_init(pGD);  
  143.    
  144.          lcd->LCDSADDR1 = pGD->frameAdrs >> 1;  
  145.    
  146.          /* This marks the end of the frame buffer. */  
  147.          lcd->LCDSADDR2 = (lcd->LCDSADDR1&0x1fffff) + (pGD->winSizeX+0) * pGD->winSizeY;  
  148.          lcd->LCDSADDR3 = (pGD->winSizeX & 0x7ff);  
  149.    
  150.          /* Clear video memory */  
  151.          memset((void *)pGD->frameAdrs, 0, pGD->memSize);  
  152.    
  153.          /* Enable  Display  */  
  154.          lcd->LCDCON1 |= 0x01;   /* ENVID = 1 */  
  155.    
  156.          return ((void*)&smi);  
  157.  }   
  158.  #endif /* CONFIG_VIDEO_S3C2410 */  

修改driver/video/videomodes.h文件第25行左右为:

[cpp]  view plain copy
  1. #ifndef CONFIG_SYS_DEFAULT_VIDEO_MODE  
  2. //#define CONFIG_SYS_DEFAULT_VIDEO_MODE 0x301  
  3.   
  4.   
  5. #define CONFIG_SYS_DEFAULT_VIDEO_MODE   0x211  
  6. #endif  

紧接着修改driver/video/videomodes.h第81行左右为:

[cpp]  view plain copy
  1. #define RES_MODE_1280x1024  5  
  2. #define RES_MODE_240x320        6     
  3. #define RES_MODES_COUNT     7  
  4.   
  5. #define VESA_MODES_COUNT 20  

在driver/video/videomodes..c文件struct ctfb_vesa_modes vesa_modes定义中添加(第78行左右)本开发板LCD的相关配置:

[cpp]  view plain copy
  1. {0x211, RES_MODE_240x320, 16},  

在driver/video/videomodes..c文件struct ctfb_res_modes res_mode_init定义中添加(第100行左右)本开发板LCD的相关配置:

[cpp]  view plain copy
  1. {320, 240, 158025, 58, 15, 3, 5, 8, 15, 0, FB_VMODE_NONINTERLACED},  

紧接着修改driver/video/Makefile文件,在41行后添加:

[plain]  view plain copy
  1. COBJS-$(CONFIG_VIDEO_S3C2440) += videomodes.o  
  2. COBJS-$(CONFIG_VIDEO_S3C2440) += s3c2410_fb.o  

最后,修改文件board/fl2440/fl2440.c,在文件最后添加:

[cpp]  view plain copy
  1. /* 
  2.  * Add by yanghao 
  3.  */  
  4. #if defined(CONFIG_VIDEO_S3C2440)  
  5. #define MVAL                   (13)  
  6. #define MVAL_USED              (0)  
  7. #define INVVDEN                (1)  
  8. #define BSWP                   (0)  
  9. #define HWSWP                  (1)  
  10. //TFT 240320  
  11. #define LCD_XSIZE_TFT_240320   (320)  
  12. #define LCD_YSIZE_TFT_240320   (240)  
  13. //TFT 240320  
  14. #define HOZVAL_TFT_240320      (LCD_XSIZE_TFT_240320-1)  
  15. #define LINEVAL_TFT_240320     (LCD_YSIZE_TFT_240320-1)  
  16. //Timing parameter for WXCAT35-TG#001  
  17. #define VBPD_240320            (3)  
  18. #define VFPD_240320            (5)  
  19. #define VSPW_240320            (15)  
  20. #define HBPD_240320            (58)  
  21. #define HFPD_240320            (15)  
  22. #define HSPW_240320_WXCAT35    (8)//adjust the horizontal displacement of the screen  
  23.   
  24.   
  25. #define CLKVAL_TFT_240320      (7)  
  26. //FCLK = 405MHZ, HCLK = 101.25MHZ, VCLK=4602272HZ  
  27. void board_video_init(GraphicDevice *pGD)  
  28. {  
  29.     struct s3c24x0_lcd * const lcd = s3c24x0_get_base_lcd();  
  30.    /*Configuration for fl2440*/  
  31.     lcd->LCDCON1 = (CLKVAL_TFT_240320 <<8)|(MVAL_USED <<7)|(3<<5)|(12<<1)|0;  
  32.    lcd->LCDCON2 = (VBPD_240320<<24)|(LINEVAL_TFT_240320<<14)|(VFPD_240320<<6)|(VSPW_240320);  
  33.    lcd->LCDCON3 = (HBPD_240320<<19)|(HOZVAL_TFT_240320<<8)|(HFPD_240320);  
  34.    lcd->LCDCON4 = (MVAL<<8)|(HSPW_240320_WXCAT35);  
  35.    lcd->LCDCON5 = (1<<11)|(1<<9)|(1<<8)|(1<<3)|(BSWP<<1)|(HWSWP);  
  36.    lcd->LPCSEL = 0x00000000;  
  37. }  
  38. #endif /*CONFIG_VIDEO_S3C2440*/  

最后还需要在开发板配置文件中添加LCD屏支持的宏定义,修改文件include/configs/fl2440.h文件,在文件中添加:

[cpp]  view plain copy
  1. #include <video_fb.h> //头文件定义处添加  
[cpp]  view plain copy
  1. /*****************add by yanghao support LCD文件末尾处添加********************/  
  2. /*LCD support*/  
  3. #define CONFIG_VIDEO_S3C2440     1  
  4. #define CONFIG_VIDEO_LOGO        1  
  5. #define CONFIG_VIDEO_BMP_LOGO           1  
  6. #define VIDEO_FB_16BPP_WORD_SWAP       1  
  7. #define CONFIG_CMD_BMP                  1  
  8. //#define CONFIG_LCD               1  
  9. #define CONFIG_VIDEO               1  
  10. #define CONFIG_CFB_CONSOLE       1  
  11. #define CFG_CONSOLE_INFO_QUIET        //support display of console information at boot  
  12.   
  13. #define LCD_VIDEO_ADDR          0x33b00000  
  14.   
  15. /*for PC-keyboard*/  
  16. #define VIDEO_KBD_INIT_FCT      0  
  17. /*for PC-keyboard*/  
  18.   
  19. #define VIDEO_TSTC_FCT          serial_tstc  
  20. #define VIDEO_GETC_FCT          serial_getc  
  21.   
  22. #define CONFIG_SERIAL_MULTI     1  
  23. /*LCD support*/  

重新上电后,uboot的输出就都显示在LCD上了,我们的输入还是选择的串口输入,输入信息、输出、错误都显示在LCD屏之上效果图如下:

source http://blog.csdn.net/yanghao23/article/details/7704953

转载于:https://www.cnblogs.com/andrew-wang/archive/2012/12/05/2803447.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值