一、LCD驱动框架:

1.分配一个fb_info结构体:s3c_lcd = framebuffer_alloc(0,NULL);

2.设置fb_info(s3c_lcd): ID、固定参数、可变参数、设置操作函数 及 其他设置

3.注册:register_framebuffer(s3c_lcd);

4.硬件相关的操作:   ①分配引脚用于LCD

          ②根据LCD手册设置控制器参数

          ③分配显存并将地址告诉LCD控制器

显存分配:在嵌入式系统中一般没有专门的显存,而仅仅是从RAM(SDRAM)空间中分配一段显示缓冲区,LCD也可说是一个frame buffer 设备

      lcdc.palette_virt = dma_alloc_writecombine(lcdc.fbdev->dev,MAX_PALETTE_SIZE, &lcdc.palette_phys, GFP_KERNEL);

 硬件时序:
      VCLK:每来一个时钟就向下移动一个像素。
      VD0~VD23:数据宽度,但是我们只用了16位。
      VLINE:(HYSNC,行同步型号,水平方向的,从上一行的行尾调到下一行的行首),
      VSYNC:(垂直同步信号,从最后一行行尾跳转到第一行的行首)
      VDEN:有效才打印颜色

调色板:存储256种颜色的RGB值,每种颜色的RGB值是16位。用这256种颜色编制索引,从OOH~FFH只需 要8位数据宽度,而每个索引所对应的颜色却是16位宽度的颜色信息,通过调色板的转换可以减少显存的开销。

二、LCD驱动代码:

  lcd_4.3.c

  1. #include <linux/module.h>
    #include <linux/kernel.h>
  2. #include <linux/errno.h>
  3. #include <linux/string.h>
  4. #include <linux/mm.h>
  5. #include <linux/slab.h>
  6. #include <linux/delay.h>
  7. #include <linux/fb.h>
  8. #include <linux/init.h>
  9. #include <linux/dma-mapping.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/workqueue.h>
  12. #include <linux/wait.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/clk.h>
  15. #include <asm/io.h>
  16. #include <asm/uaccess.h>
  17. #include <asm/div64.h>
  18. #include <asm/mach/map.h>
  19. #include <asm/arch/regs-lcd.h>
    #include <asm/arch/regs-gpio.h>
  20. #include <asm/arch/fb.h>
  21. static int s3c_lcdfb_setcolreg(unsigned int regno, unsigned int red,
  22. unsigned int green, unsigned int blue,
  23. unsigned int transp, struct fb_info *info);
  24. struct lcd_regs {
  25. unsigned long lcdcon1;
  26. unsigned long lcdcon2;
  27. unsigned long lcdcon3;
  28. unsigned long lcdcon4;
  29. unsigned long lcdcon5;
  30. unsigned long lcdsaddr1;
  31. unsigned long lcdsaddr2;
  32. unsigned long lcdsaddr3;
  33. unsigned long redlut;
  34. unsigned long greenlut;
  35. unsigned long bluelut;
  36. unsigned long reserved[];
  37. unsigned long dithmode;
  38. unsigned long tpal;
  39. unsigned long lcdintpnd;
  40. unsigned long lcdsrcpnd;
  41. unsigned long lcdintmsk;
  42. unsigned long lpcsel;
  43. };

  44. static struct fb_ops s3c_lcdfb_ops = {
  45. .owner = THIS_MODULE,
  46. .fb_setcolreg = s3c_lcdfb_setcolreg, //设置调色板
  47. .fb_fillrect = cfb_fillrect,
  48. .fb_copyarea = cfb_copyarea,
  49. .fb_imageblit = cfb_imageblit,
  50. };
  51. static struct fb_info *s3c_lcd;
  52. static volatile unsigned long *gpbcon;
  53. static volatile unsigned long *gpbdat;
  54. static volatile unsigned long *gpccon;
  55. static volatile unsigned long *gpdcon;
  56. static volatile unsigned long *gpgcon;
  57. static volatile struct lcd_regs* lcd_regs;
  58. static u32 pseudo_palette[];
  59. /* from pxafb.c */
  60. static inline unsigned int chan_to_field(unsigned int chan, struct fb_bitfield *bf)
  61. {
  62. chan &= 0xffff;
  63. chan >>= - bf->length;
  64. return chan << bf->offset;
  65. }
  66. static int s3c_lcdfb_setcolreg(unsigned int regno, unsigned int red,
  67. unsigned int green, unsigned int blue,
  68. unsigned int transp, struct fb_info *info)
  69. {
  70. unsigned int val;
  71. if (regno > )
  72. return ;
  73. /* 用red,green,blue三原色构造出val */
  74. val = chan_to_field(red, &info->var.red);
  75. val |= chan_to_field(green, &info->var.green);
  76. val |= chan_to_field(blue, &info->var.blue);
  77. //((u32 *)(info->pseudo_palette))[regno] = val;
  78. pseudo_palette[regno] = val;
  79. return ;
  80. }
  81. static int lcd_init(void)
  82. {
  83. /* 1. 分配一个fb_info */
  84. s3c_lcd = framebuffer_alloc(, NULL);
  85. /* 2. 设置 */
  86. /* 2.1 设置固定的参数 */
  87. strcpy(s3c_lcd->fix.id, "mylcd");
  88. s3c_lcd->fix.smem_len = **/;
  89. s3c_lcd->fix.type = FB_TYPE_PACKED_PIXELS;
  90. s3c_lcd->fix.visual = FB_VISUAL_TRUECOLOR; /* TFT */
  91. s3c_lcd->fix.line_length = *;
  92. /* 2.2 设置可变的参数 */
  93. s3c_lcd->var.xres = ;
  94. s3c_lcd->var.yres = ;
  95. s3c_lcd->var.xres_virtual = ;
  96. s3c_lcd->var.yres_virtual = ;
  97. s3c_lcd->var.bits_per_pixel = ;
  98. /* RGB:565 */
  99. s3c_lcd->var.red.offset = ;
  100. s3c_lcd->var.red.length = ;
  101. s3c_lcd->var.green.offset = ;
  102. s3c_lcd->var.green.length = ;
  103. s3c_lcd->var.blue.offset = ;
  104. s3c_lcd->var.blue.length = ;
  105. s3c_lcd->var.activate = FB_ACTIVATE_NOW;
  106. /* 2.3 设置操作函数 */
  107. s3c_lcd->fbops = &s3c_lcdfb_ops;
  108. /* 2.4 其他的设置 */
  109. s3c_lcd->pseudo_palette = pseudo_palette;
  110. //s3c_lcd->screen_base = ; /* 显存的虚拟地址 */
  111. s3c_lcd->screen_size = **/;
  112. /* 3. 硬件相关的操作 */
  113. /* 3.1 配置GPIO用于LCD */
  114. gpbcon = ioremap(0x56000010, );
  115. gpbdat = gpbcon+;
  116. gpccon = ioremap(0x56000020, );
  117. gpdcon = ioremap(0x56000030, );
  118. gpgcon = ioremap(0x56000060, );
  119. *gpccon = 0xaaaaaaaa; /* GPIO管脚用于VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND */
  120. *gpdcon = 0xaaaaaaaa; /* GPIO管脚用于VD[23:8] */
  121. *gpbcon &= ~(); /* GPB0设置为输出引脚 */
  122. *gpbcon |= ;
  123. *gpbdat &= ~; /* 输出低电平,默认关闭背光 */
  124. *gpgcon |= (<<); /* GPG4用作LCD_PWREN */
  125. /* 3.2 根据LCD手册设置LCD控制器, 比如VCLK的频率等 */
  126. lcd_regs = ioremap(0x4D000000, sizeof(struct lcd_regs));
  127. /* bit[17:8]: VCLK = HCLK / [(CLKVAL+1) x 2], LCD手册P14
  128. * 10MHz(100ns) = 100MHz / [(CLKVAL+1) x 2]
  129. * CLKVAL = 4
  130. * bit[6:5]: 0b11, TFT LCD
  131. * bit[4:1]: 0b1100, 16 bpp for TFT
  132. * bit[0] : 0 = Disable the video output and the LCD control signal.
  133. */
  134. lcd_regs->lcdcon1 = (<<) | (<<) | (0x0c<<);
  135. #if 1
  136. /* 垂直方向的时间参数
  137. * bit[31:24]: VBPD, VSYNC之后再过多长时间才能发出第1行数据
  138. * LCD手册 T0-T2-T1=4
  139. * VBPD=3
  140. * bit[23:14]: 多少行, 320, 所以LINEVAL=320-1=319
  141. * bit[13:6] : VFPD, 发出最后一行数据之后,再过多长时间才发出VSYNC
  142. * LCD手册T2-T5=322-320=2, 所以VFPD=2-1=1
  143. * bit[5:0] : VSPW, VSYNC信号的脉冲宽度, LCD手册T1=1, 所以VSPW=1-1=0
  144. */
  145. lcd_regs->lcdcon2 = (<<) | (<<) | (<<) | ();
  146. /* 水平方向的时间参数
  147. * bit[25:19]: HBPD, VSYNC之后再过多长时间才能发出第1行数据
  148. * LCD手册 T6-T7-T8=17
  149. * HBPD=16
  150. * bit[18:8]: 多少列, 240, 所以HOZVAL=240-1=239
  151. * bit[7:0] : HFPD, 发出最后一行里最后一个象素数据之后,再过多长时间才发出HSYNC
  152. * LCD手册T8-T11=251-240=11, 所以HFPD=11-1=10
  153. */
  154. lcd_regs->lcdcon3 = (<<) | (<<) | ();
  155. /* 水平方向的同步信号
  156. * bit[7:0] : HSPW, HSYNC信号的脉冲宽度, LCD手册T7=5, 所以HSPW=5-1=4
  157. */
  158. lcd_regs->lcdcon4 = ;
  159. #else
  160. lcd_regs->lcdcon2 = S3C2410_LCDCON2_VBPD() | \
  161. S3C2410_LCDCON2_LINEVAL() | \
  162. S3C2410_LCDCON2_VFPD() | \
  163. S3C2410_LCDCON2_VSPW();
  164. lcd_regs->lcdcon3 = S3C2410_LCDCON3_HBPD() | \
  165. S3C2410_LCDCON3_HOZVAL() | \
  166. S3C2410_LCDCON3_HFPD();
  167. lcd_regs->lcdcon4 = S3C2410_LCDCON4_MVAL() | \
  168. S3C2410_LCDCON4_HSPW();
  169. #endif
  170. /* 信号的极性
  171. * bit[11]: 1=565 format
  172. * bit[10]: 0 = The video data is fetched at VCLK falling edge
  173. * bit[9] : 1 = HSYNC信号要反转,即低电平有效
  174. * bit[8] : 1 = VSYNC信号要反转,即低电平有效
  175. * bit[6] : 0 = VDEN不用反转
  176. * bit[3] : 0 = PWREN输出0
  177. * bit[1] : 0 = BSWP
  178. * bit[0] : 1 = HWSWP 2440手册P413
  179. */
  180. lcd_regs->lcdcon5 = (<<) | (<<) | (<<) | (<<) | (<<);
  181. /* 3.3 分配显存(framebuffer), 并把地址告诉LCD控制器 */
  182. s3c_lcd->screen_base = dma_alloc_writecombine(NULL, s3c_lcd->fix.smem_len, &s3c_lcd->fix.smem_start, GFP_KERNEL);
  183. lcd_regs->lcdsaddr1 = (s3c_lcd->fix.smem_start >> ) & ~(<<);
  184. lcd_regs->lcdsaddr2 = ((s3c_lcd->fix.smem_start + s3c_lcd->fix.smem_len) >> ) & 0x1fffff;
  185. lcd_regs->lcdsaddr3 = (*/); /* 一行的长度(单位: 2字节) */
  186. //s3c_lcd->fix.smem_start = xxx; /* 分配到的显存物理地址 */
  187. /* 启动LCD */
  188. lcd_regs->lcdcon1 |= (<<); /* 使能LCD控制器 */
  189. lcd_regs->lcdcon5 |= (<<); /* 使能LCD本身 */
  190. *gpbdat |= ; /* 输出高电平, 使能背光 */
  191. /* 4. 注册 */
  192. register_framebuffer(s3c_lcd);
  193. return ;
  194. }
  195. static void lcd_exit(void)
  196. {
  197. unregister_framebuffer(s3c_lcd);
  198. lcd_regs->lcdcon1 &= ~(<<); /* 关闭LCD本身 */
  199. *gpbdat &= ~; /* 关闭背光 */
  200. dma_free_writecombine(NULL, s3c_lcd->fix.smem_len, s3c_lcd->screen_base, s3c_lcd->fix.smem_start);
  201. iounmap(lcd_regs);
  202. iounmap(gpbcon);
  203. iounmap(gpccon);
  204. iounmap(gpdcon);
  205. iounmap(gpgcon);
  206. framebuffer_release(s3c_lcd);
  207. }
  208. module_init(lcd_init);
  209. module_exit(lcd_exit);
  210. MODULE_LICENSE("GPL");

Makefile

  1. KERN_DIR = /work/system/linux-2.6.22.6
  2.  
  3. all:
  4. make -C $(KERN_DIR) M=`pwd` modules
  5.  
  6. clean:
  7. make -C $(KERN_DIR) M=`pwd` modules clean
  8. rm -rf modules.order
  9.  
  10. obj-m += lcd_4.3.o

三、测试驱动;

方法1:修改内核自带的lcd驱动代码  /drivers/video/s3c2410fb.c 以支持单板的LCD ;

方法2:配置内核lcd驱动编译为模块:

  make menuconfig

  Device Drivers  --->

    Graphics support  --->

      <*> Support for frame buffer devices  --->

         <M>   S3C2410 LCD framebuffer support

  

  make modules  ---> 生成 .ko

  make uImage    ---> 生成去掉lcd驱动的内核镜像

  1. U-boot下载烧录新内核:
      tftp 0x30000000 uImage
  2.   nand erase.part kernel
  3.   nand write.i 0x30000000 kernel $filesize
      reset
  4. 或者 nfs 网络挂载启动新内核: nfs 32000000 192.168.1.123:/work/nfs_root/uImage_new; bootm 32000000
  5. 新内核启动后可以发现 /dev/fb0 节点已经不存在,
    加载移植好的lcd驱动模块: insmod /mnt/nfs_root/3.4.83_driver/lcd_4.3.ko
    然后 /dev/fb0 重新生成。

-end-

  1.  

Linux学习: LCD驱动的更多相关文章

  1. Smart210学习-----lcd驱动

    帧缓冲设备 1.1帧缓冲设备:帧缓冲(framebuffer)是 Linux 系统为显示设备提供的一个接口,它将显示缓冲区抽象,屏蔽图像硬件的底层差异,允许上层应用程序在图形模式下直接对显示缓冲区进行 ...

  2. Linux的LCD驱动分析及移植

    测试平台 宿主机平台:Ubuntu 12.04.4 LTS 目标机:Easy-ARM IMX283 目标机内核:Linux 2.6.35.3 LCD驱动分析 LCD屏的驱动总体上分成两块,一块是GUI ...

  3. Linux学习: 触摸屏驱动

    一.Linux输入子系统的结构: 二.触摸屏驱动代码: s3c_ts.c #include <linux/errno.h> #include <linux/kernel.h> ...

  4. Linux驱动:LCD驱动框架分析

    一直想花时间来整理一下Linux内核LCD驱动,却一直都忙着做其他事情去了,这些天特意抽出时间来整理之前落下的笔记,故事就这样开始了.LCD驱动也是字符设备驱动的一种,框架上相对于字符设备驱动稍微复杂 ...

  5. 嵌入式Linux驱动学习之路(十八)LCD驱动

    驱动代码: /************************************************************************* > File Name: lcd ...

  6. LCD驱动学习笔记

    通过这几天的学习发现驱动的框架感觉都差不多,一般分为以下几个步骤: 分配一个结构体 struct x *x = amlloc(); 设置结构体的参数 硬件寄存器 file_operations 注册 ...

  7. AM335x(TQ335x)学习笔记——LCD驱动移植

    TI的LCD控制器驱动是非常完善的,共通的地方已经由驱动封装好了,与按键一样,我们可以通过DTS配置完成LCD的显示.下面,我们来讨论下使用DTS方式配置内核完成LCD驱动的思路. (1)初步分析 由 ...

  8. Linux驱动之LCD驱动编写

    在Linux驱动之内核自带的S3C2440的LCD驱动分析这篇博客中已经分析了编写LCD驱动的步骤,接下来就按照这个步骤来字尝试字节编写LCD驱动.用的LCD屏幕为tft屏,每个像素点为16bit.对 ...

  9. linux 驱动之LCD驱动(有framebuffer)

    <简介> LCD驱动里有个很重要的概念叫帧缓冲(framebuffer),它是Linux系统为显示设备提供的一个接口,应用程序在图形模式允许对显示缓冲区进行读写操作.用户根本不用关心物理显 ...

随机推荐

  1. 日常英语---十、MapleStory/Monsters/Level 191-201(Sad Erda:向你发射炮弹进行攻击)

    日常英语---十.MapleStory/Monsters/Level 191-201(Sad Erda:向你发射炮弹进行攻击) 一.总结 一句话总结:一种悲伤的精神,形成于奥术之河,一个黑法师能够融合 ...

  2. ubuntu下安装Firefox中国版解决Ubuntu与Windows下Firefox账号同步问题(已解决)

    1. 下载最新版本火狐Linux版 下载地址:http://firefox.com.cn/download/ 选择火狐Linux64-bit版,下载后文件为:Firefox-latest-x86_64 ...

  3. Ribbon

    Ribbon是一个客户端的负载均衡器,它提供对大量的HTTP和TCP客户端的访问控制.Feign也是用的Ribbon,所以在这一章你也可以用@FeignClient Ribbon的一个核心概念是命名的 ...

  4. 提取出一个组装基因组的gap(N)和重复序列区域,保存为bed格式

    参见: Question: How to extract allnon-seqencedpositions from a genome (Fasta file)? test.fa >chr1 N ...

  5. 混合线性模型(linear mixed models)

    一般线性模型.混合线性模型.广义线性模型 广义线性模型GLM很简单,举个例子,药物的疗效和服用药物的剂量有关.这个相关性可能是多种多样的,可能是简单线性关系(发烧时吃一片药退烧0.1度,两片药退烧0. ...

  6. Mac必备神器之Go2Shell

    一.作用     可以快速在当前目录打开Shell命令行窗口   二.安装 1.打开官网 http://zipzapmac.com/go2shell 2.点击下载并安装   3.点击应用图标   三. ...

  7. LeetCode--012--整数转罗马数字(java)

    罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II ,即为两个并 ...

  8. LeetCode--003--无重复字符的最长子串(java)

    给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc&qu ...

  9. LeetCode--415--字符串相加

    问题描述: 给定两个字符串形式的非负整数 num1 和num2 ,计算它们的和. 注意: num1 和num2 的长度都小于 5100. num1 和num2 都只包含数字 0-9. num1 和nu ...

  10. grid 用于同一用例在不同测试环境下的测试结果

    步骤: 1.http://www.seleniumhp.org/download   下载selenium standalone server 2.配置java环境 3.运行selenium serv ...