Chinaunix首页 | 论坛 | 博客
  • 博客访问: 475693
  • 博文数量: 92
  • 博客积分: 3146
  • 博客等级: 中校
  • 技术积分: 2314
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-27 10:20
文章分类

全部博文(92)

文章存档

2014年(3)

2013年(17)

2012年(16)

2011年(22)

2010年(34)

分类: LINUX

2012-06-10 09:00:06

最近在开发板上飞了一块新的lcd,不晓得是不是因为飞线太复杂的缘故,通过kernel的时候屏幕就是不亮,通过spec配置基本都一样。然后就想通过最原始的方式来验证lcd,就是在uboot里初始化lcd,smdkc110里默认的是没有初始化lcd的,而且编译的话好像还有错,所以就自己写了一个lcd.c。用到以下两个文件就可以了
核心源码是/common/lcd.c   /cpu/s5pc11x /fimd.c
下面是lcd.c的代码

点击(此处)折叠或打开

  1. #include <config.h>
  2. #include <common.h>
  3. #include <command.h>
  4. #include <version.h>
  5. #include <stdarg.h>
  6. #include <linux/types.h>
  7. #include <devices.h>
  8. #if defined(CONFIG_POST)
  9. #include <post.h>
  10. #endif
  11. #include <lcd.h>
  12. #include <watchdog.h>
  13. #ifdef CONFIG_LCD

  14. /************************************************************************/
  15. /* ** FONT DATA */
  16. /************************************************************************/
  17. //#include <fonts.h> /* Get font data, width and height*/

  18. #define LCD_WIDTH 1024
  19. #define LCD_HEIGHT 600
  20. #define LCD_BGCOLOR 0xffffff
  21. #define LCD_SETCURSOR(Xpos,Ypos) (CFG_LCD_FBUFFER + Xpos*LCD_WIDTH*4 + Ypos*4)

  22. static unsigned int TextColor = 0x0000;
  23. static unsigned int BackColor = LCD_BGCOLOR;

  24. void LCD_Initialize_NONAME1(void); //fimd.c中的LCD初始化函数


  25. typedef struct vidinfo
  26. {    
  27.     ushort    vl_col;        /* Number of columns (i.e. 640) */    
  28.     ushort    vl_row;        /* Number of rows (i.e. 480) */    
  29.     ushort    vl_width;    /* Width of display area in millimeters */
  30.     ushort    vl_height;    /* Height of display area in millimeters */    /* LCD configuration register */    
  31.     u_char    vl_clkp;    /* Clock polarity */    
  32.     u_char    vl_oep;        /* Output Enable polarity */    
  33.     u_char    vl_hsp;        /* Horizontal Sync polarity */    
  34.     u_char    vl_vsp;        /* Vertical Sync polarity */    
  35.     u_char    vl_dp;        /* Data polarity */    
  36.     u_char    vl_bpix;    /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8, 4 = 16 */    
  37.     u_char    vl_lbw;        /* LCD Bus width, 0 = 4, 1 = 8 */    
  38.     u_char    vl_splt;    /* Split display, 0 = single-scan, 1 = dual-scan */    
  39.     u_char    vl_clor;    /* Color, 0 = mono, 1 = color */    
  40.     u_char    vl_tft;        /* 0 = passive, 1 = TFT */    /* Horizontal control register. Timing from data sheet */    
  41.     ushort    vl_hpw;        /* Horz sync pulse width */    
  42.     u_char    vl_blw;        /* Wait before of line */    
  43.     u_char    vl_elw;        /* Wait end of line */    /* Vertical control register. */
  44.     u_char    vl_vpw;        /* Vertical sync pulse width */    
  45.     u_char    vl_bfw;        /* Wait before of frame */    
  46.     u_char    vl_efw;        /* Wait end of frame */    /* PXA LCD controller params */
  47.     //struct    pxafb_info pxa;
  48. } vidinfo_t;

  49. vidinfo_t panel_info = {1024,600,1024,600,1,1,1,1,1,24,0,0,0,1,40,56,56,20,8,8};

  50. /*
  51.  * Frame buffer memory information
  52.  */
  53. //void *lcd_base; /* Start of framebuffer memory*/

  54. static int lcd_init ();
  55. void lcd_Enable (void);



  56. /************************************************************************/
  57. /* ** GENERIC Initialization Routines */
  58. /************************************************************************/
  59. int drv_lcd_init (void)
  60. {
  61.     device_t lcddev;
  62.     int rc;
  63.     // lcd_base = (void*)CFG_LCD_FBUFFER;

  64.     lcd_init (); /* LCD initialization */
  65. #ifdef CONFIG_NO_VIDEO_CONSOLE
  66.     return 0;
  67. #endif
  68.     // Device initialization
  69.     memset (&lcddev, 0, sizeof (lcddev));
  70.     strcpy (lcddev.name, "lcd");
  71.     lcddev.ext = 0;
  72.     lcddev.flags = DEV_FLAGS_OUTPUT;
  73.     ///cddev.putc = lcd_putc;
  74.     //lcddev.puts = lcd_puts;
  75.     rc = device_register (&lcddev); //重定向输出信息
  76.     return (rc == 0) ? 1 : rc;
  77. }
  78. /*----------------------------------------------------------------------*/
  79. static int lcd_init ()
  80. {
  81.     /* Initialize the lcd controller */
  82.     printf("LCD Initializing......");
  83.     //LCD_Initialize_NONAME1();
  84.     LCD_Init(1);//上面的其实也可以初始化lcd
  85.     printf("complete\n");
  86.     LCD_clear(); //刷蓝色背景色
  87.     //LCD_DisplayChar(0,0,'E'); //在(0,0)处写字母”E”
  88.     return 0;
  89. }
  90. #if 0
  91. void LCD_DrawChar(u16 Xpos, u16 Ypos, char *c)
  92. {
  93.   u32 index = 0, i = 0;
  94.   u16 Xaddress = 0;
  95.    Xaddress = Xpos;
  96.     u32* pBuffer = (u32*)LCD_SETCURSOR(Xaddress, Ypos);
  97.   for(index = 0; index < 24; index++)
  98.   {
  99.     for(i = 0; i < 16; i++)
  100.     {
  101.       if((c[index] & (1 << i)) == 0x00)
  102.       {
  103.         *pBuffer++ = BackColor;
  104.       }
  105.       else
  106.       {
  107.         *pBuffer++ = TextColor;
  108.       }
  109.     }
  110.     Xaddress++;
  111.     pBuffer = (u32*)LCD_SETCURSOR(Xaddress, Ypos);
  112.   }
  113. }

  114. void LCD_DisplayChar(u16 Line, u16 Column, u8 Ascii)
  115. {
  116.   Ascii -= 32;
  117.   LCD_DrawChar(Line, Column, &ASCII_Table[Ascii * 24]);
  118. }
  119. #endif
  120. void LCD_clear()
  121. {
  122.     u16 i, j;
  123.     u32* pBuffer = (u32*)CFG_LCD_FBUFFER;
  124.     for (i=0; i < LCD_HEIGHT; i++)
  125.     {
  126.         for (j=0; j < LCD_WIDTH; j++)
  127.         {
  128.             *pBuffer++ = BackColor;
  129.         }
  130.     }
  131. }
  132. ulong calc_fbsize (void)
  133. {
  134.      ulong size;
  135.     
  136.      int line_length = (panel_info.vl_col * panel_info.vl_bpix) / 8;
  137.      size = line_length * panel_info.vl_row;
  138. #ifdef CFG_LCD_FBUFFER
  139.      size = 2457600;
  140. #endif
  141.      return size;
  142. }
  143. /************************************************************************/
  144. /* ** ROM capable initialization part - needed to reserve FB memory*/
  145. /************************************************************************/
  146. /*
  147.  * This is called early in the system initialization to grab memory
  148.  * for the LCD controller.
  149.  * Returns new address for monitor, after reserving LCD buffer memory
  150.  *
  151.  * Note that this is running from ROM, so no write access to global data.
  152.  */
  153. ulong lcd_setmem (ulong addr)
  154. {
  155.     ulong size;
  156.     int line_length = (panel_info.vl_col * panel_info.vl_bpix) / 8;
  157.     debug ("LCD panel info: %d x %d, %d bit/pix\n",
  158.     panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
  159.     size = line_length * panel_info.vl_row;
  160. #ifdef CFG_LCD_FBUFFER
  161.      size = 2457600; //1024*600*4 bytes
  162. #endif
  163.     /* Round up to nearest full page */
  164.     size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  165.     /* Allocate pages for the frame buffer. */
  166.     addr -= size;
  167.     debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
  168.     return (addr);
  169. }

  170. int do_clearlcd(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  171. {
  172.     printf("huabinbin test do_clearlcd");
  173.     drv_lcd_init();
  174. }
  175. #endif /* CONFIG_LCD */
如果有需要的话你还可以再LCD_Init(1)这个函数去修改一些极性配置,我的平台
Outp32(0xf8000004, 0x016EC080);  这里可以修改那四个参数的极性配置。
只是很遗憾,屏幕显示的效果还是和kernel一样,但我想应该不影响这篇文章的正确性,等打好板子再来确认一下,这也是怕自己到时忘了,所以先记录下来!
阅读(2333) | 评论(1) | 转发(2) |
给主人留下些什么吧!~~

3451619742013-03-20 16:30:29

兄弟,我现在用的是real 210的板子,我做的是Linux这块,我想给lcd在uboot启动时有个启动画面,这个怎么实现呢?能方便告诉你qq不呢?