LCD驱动程序分析
内核中lcd驱动分析

[ 0.366667] [DISP WRN] file:drivers/video/sun7i/disp/OSAL/OSAL_Clock.c,line:347: NULL hdle
de_bsp/de/disp_event.o de_bsp/de/disp_hdmi.o de_bsp/de/disp_hwc.o de_bsp/de/disp_layer.o\
de_bsp/de/disp_lcd.o de_bsp/de/disp_scaler.o de_bsp/de/disp_sprite.o de_bsp/de/disp_tv.o\
{
int ret = 0, err;
printk("hyh in lcd_module_init\n");
__inf("lcd_module_init\n");
alloc_chrdev_region(&devid, 0, 1, "lcd");
==============================内核中LCD驱动分析
20151008 aw LCD
===========driver/video/sun7i
--disp/
--Hdmi/
--lcd/ lcd_init
obj-$(CONFIG_LYCHEE_FB_SUN7I) += disp.o
LCD_get_panel_funs_0(&lcd0_cfg);
基于STM32单片机FSMC接口驱动LCD的配置与分析

基于STM32单片机FSMC接口驱动LCD的配置与分析概述:STM32单片机是一款高性能、低功耗的32位ARM Cortex-M系列微控制器。
它具有丰富的外设接口,其中包括FSMC(Flexible Static Memory Controller)接口,用于连接外部存储器,例如LCD显示器。
本文将详细介绍如何配置和驱动LCD显示器,以及分析FSMC接口的工作原理。
一、LCD驱动接口配置1. 在STM32的标准外设库中,FSMC的配置函数位于STM32F10x_stdperiph_driver库的stm32f10x_fsmc.c和stm32f10x_fsmc.h文件中。
通过这些函数,可以配置FSMC接口的参数,以使它能够连接和驱动LCD。
2.首先,需要配置FSMC的时钟预分频值。
根据LCD的要求以及系统时钟频率,选择适当的预分频值。
这可以通过设置FSMC_BCRx寄存器中的MBKEN和PS字段来实现。
3.然后,需要配置FSMC的存储芯片选择使能信号(CSEN)和片选信号(ALE)。
这可以通过设置FSMC_BCRx寄存器中的CSEN和ALEN字段来实现。
4.接下来,需要配置FSMC的读写延迟、数据宽度、存储器类型等参数。
这可以通过设置FSMC_BTRx和FSMC_BWTRx寄存器来实现。
5.最后,需要配置FSMC的地址线、数据线和控制线的映射关系。
这可以通过设置FSMC_BCRx寄存器中的MWID、MTYP、MUXEN、MWID和NWID 字段来实现。
二、FSMC接口工作原理1.FSMC接口是一种高速并行接口,它通过多路复用来连接不同的外部存储器。
它具有独立的读/写数据线和地址线,以及控制线,用于选择读/写操作和片选信号。
2. FSMC接口支持不同类型的存储器,例如SRAM、NOR Flash、NAND Flash和LCD。
每种存储器都有不同的时序和接口要求。
3.FSMC接口的时序参数主要包括时钟预分频值、读/写延迟、数据宽度和地址线宽度等。
第22章 LCD驱动程序

第 22 章 LCD 驱动程序
选择一个驱动程序
如第 20 章“底层配置”中所描述的那样,宏 LCD_CONTROLLER 定义所使用的 LCD 控制 器。一个控制器由上表列出它的适当的值指定。
下面部分分别讨论每一个有效的驱动程序。
22.2 LCD07X1
支持的硬件
控制器 该驱动程序在下列控制器身上测试通过: •Samsung KS0711 •Samsung KS0741 应该能假设它也能够在任何与这两种控制器结构相类似的控制器上工作。 每像素的位 支持颜色深度为 2 bpp。 接口 芯片支持三种类型接口: 8 位并行(简单总线)接口 4 脚串行外围设备接口(SPI) 3 脚 SPI。 当前版本的驱动程序支持并行或 4 脚 SPI 模式。
µC/GUI 中文手册
第7 页
第 22 章 LCD 驱动程序
问。 下表列出了必须为硬件访问所定义的宏:
宏 LCD_INIT_CONTROLLER LCD_READ_MEM LCD_READ_REG LCD_WRITE_MEM LCD_WRITE_REG
附加的配置开关
说明 初始化 LCD 控制器序列。 读控制器的图像存储器的内容。 读控制器的一个配置寄存器的内容。 向控制器的图像存储器(显示数据随机 RAM)写入数据。 向控制器的一个配置寄存器写入数据。
#define LCD_SWAP_RB (1)
/* 必须设置 */
LCD_INIT_CONTROLLER
当写或者修改初始化宏时,要考虑下列问题:
初始化嵌入 SDRAM,寄存器 20 的第 7 位(SDRAM 初始化位)必须设置为 1(至少在复位
第8 页
µC/GUI 中文手册
200µs 后)。
linux的lcd驱动详细讲解

linux的lcd驱动详细讲解嵌入式驱动程序Day12Top1.LCD驱动设计开发1 LCD驱动设计开发1.1 问题通过lcd驱动开发掌握linux内核framebuffer驱动开发通用方法。
1.2 方案一、帧缓冲(Framebuffer)。
帧缓冲(Framebuffer)是Linux为显示设备提供的一个接口,Linux抽象出FrameBuffer这个设备来供用户态进程实现直接写屏。
Framebuffer机制模仿显卡的功能,将显卡硬件结构抽象掉,可以通过 Framebuffer的读写直接对显存进行操作。
用户可以将Framebuffer看成是显示内存的一个映像,将其映射到进程地址空间之后,就可以直接进行读写操作,而写操作可以立即反应在屏幕上。
这种操作是抽象的,统一的。
用户不必关心物理显存的位置、换页机制等等具体细节。
这些都是由 Framebuffer设备驱动来完成的。
Framebuffer本身不具备任何运算数据的能力,就只好比是一个暂时存放水的水池。
CPU将运算后的结果放到这个水池,水池再将结果流到显示器,中间不会对数据做处理。
应用程序也可以直接读写这个水池的内容。
在应用程序中,一般通过将FrameBuffer 设备映射到进程地址空间的方式使用,比如下面的程序就打开/dev/fb0 设备,并通过mmap 系统调用进行地址映射。
FrameBuffer 设备还提供了若干 ioctl 命令,通过这些命令,可以获得显示设备的一些固定信息(比如显示内存大小)、与显示模式相关的可变信息(比如分辨率、象素结构、每扫描线的字节宽度),以及伪彩色模式下的调色板信息等等。
二、FrameBuffer在Linux中的实现和机制。
Framebuffer对应的源文件在linux/drivers/video/目录下。
总的抽象设备文件为fbcon.c,在这个目录下还有与各种显卡驱动相关的源文件。
1.分析Framebuffer设备驱动。
JZ2440 4.3寸屏LCD驱动和触摸屏驱动分析笔记

JZ2440 4.3寸屏LCD驱动和触摸屏驱动分析笔记 LCD驱动分析S3C2410/2440LCD控制结构图LCDCDMA从SBUS拉取图像数据,将FIFO数据送到VIDPRCS组合后发出,当FIFO减少到0或者阀值,LCDCDMA又自动从SBUS上拉取图像数据。
显示器沿着“Z”字形的路线进行扫描,使用HSYNC(表示“是跳到最左边的时候了”)、VSYNC(表示“是跳到最上边的时候了”)信号来控制扫描路线的跳转。
它只会依据这两个信号来取得、显示数据,并不理会该数据是否有效,何时发出有效数据由显卡决定。
显示器扫描一帧数据的过程S3C2410/2440 TFT LCD时序图每个VSYNC信号便是一帧数据的开始;每个HSYNC信号表示一行数据的开始,不管这些数据是否有效;每个VCLK信号表示正在传输一个像素的数据,无论它是否有效。
数据是否有效只是对CPU的LCD控制器来说的,LCD根据VSYNC、HSYNC、VCLK不停地读取总线数据、显示。
320*240 TFT屏显示器控制图struct fb_info{int node;int flags;struct fb_var_screeninfo var; /* Current var */ struct fb_fix_screeninfo fix; /* Current fix */struct fb_monspecs monspecs;/* Current Monitor specs */struct work_struct queue;/* Framebuffer event queue */struct fb_pixmap pixmap;/* Image hardware mapper */struct fb_pixmap sprite;/* Cursor hardware mapper */struct fb_cmap cmap;/* Current cmap */struct list_head modelist;/* mode list */struct fb_videomode *mode;/* current mode */struct fb_ops *fbops;struct device *device;/* This is the parent */struct device *dev;/* This is this fb device */int class_flag;/* private sysfs flags */#ifdef CONFIG_FB_TILEBLITTINGstruct fb_tile_ops *tileops; /* Tile Blitting */ #endifchar __iomem *screen_base; /* Virtual address */unsigned long screen_size; /* Amount of ioremapped VRAM or 0 */void *pseudo_palette; /* Fake palette of 16 colors */#define FBINFO_STATE_RUNNING 0#define FBINFO_STATE_SUSPENDED 1u32 state;/* Hardware state i.e suspend */void *fbcon_par;/* fbcon use-only private area *//* From here on everything is device dependent */void *par;};struct fb_fix_screeninfo {char id[16];/* identification string eg "TT Builtin" */ unsigned long smem_start;/* Start of frame buffer mem *//* (physical address) */__u32 smem_len;/* Length of frame buffer mem */__u32 type;/* see FB_TYPE_* */__u32 type_aux;/* Interleave for interleaved Planes */__u32 visual;/* see FB_VISUAL_* */__u16 xpanstep;/* zero if no hardware panning */__u16 ypanstep;/* zero if no hardware panning */__u16 ywrapstep;/* zero if no hardware ywrap */__u32 line_length;/* length of a line in bytes */unsigned long mmio_start;/* Start of Memory Mapped I/O *//* (physical address) */__u32 mmio_len;/* Length of Memory Mapped I/O */__u32 accel;/* Indicate to driver which *//* specific chip/card we have */__u16 reserved[3];/* Reserved for future compatibility */};struct fb_var_screeninfo {__u32 xres;/* visible resolution */__u32 yres;__u32 xres_virtual;/* virtual resolution */__u32 yres_virtual;__u32 xoffset; /* offset from virtual to visible */__u32 yoffset; /* resolution */__u32 bits_per_pixel;/* guess what */__u32 grayscale;/* != 0 Graylevels instead of colors */ struct fb_bitfield red;/* bitfield in fb mem if true color, */ struct fb_bitfield green;/* else only length is significant */struct fb_bitfield blue;struct fb_bitfield transp;/* transparency */__u32 nonstd; /* != 0 Non standard pixel format */__u32 activate; /* see FB_ACTIVATE_* */__u32 height; /* height of picture in mm */__u32 width; /* width of picture in mm */__u32 accel_flags;/* (OBSOLETE) see fb_info.flags */__u32 pixclock; /* pixel clock in ps (pico seconds) */ __u32 left_margin;/* time from sync to picture */__u32 right_margin;/* time from picture to sync */__u32 upper_margin;/* time from sync to picture */__u32 lower_margin;__u32 hsync_len;/* length of horizontal sync */__u32 vsync_len;/* length of vertical sync */__u32 sync;/* see FB_SYNC_* */__u32 vmode;/* see FB_VMODE_* */__u32 rotate; /* angle we rotate counter clockwise */ __u32 reserved[5];/* Reserved for future compatibility */ };4.3寸LCD芯片手册TFT屏垂直方向时间参数图解:S3C2440手册TFT屏垂直方向时间参数图解:4.3寸LCD芯片手册TFT屏水平方向时间参数图解:S3C2440手册LCDTFT屏水平方向时间参数图解:#include <linux/module.h>#include <linux/kernel.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/mm.h>#include <linux/slab.h>#include <linux/delay.h>#include <linux/fb.h>#include <linux/init.h>#include <linux/dma-mapping.h>#include <linux/interrupt.h>#include <linux/workqueue.h>#include <linux/wait.h>#include <linux/platform_device.h>#include <linux/clk.h>#include <asm/io.h>#include <asm/uaccess.h>#include <asm/div64.h>#include <asm/mach/map.h>#include <asm/arch/regs-lcd.h>#include <asm/arch/regs-gpio.h>#include <asm/arch/fb.h>/** 设置调色板* 调色板说白了,就是在内存中建一个表,而每个像素* 对应的8位数据是用来在表中查找相应的RGB的值,而* 这个表是有前面的24BPP或16BPP构成的**/static int s3c_lcdfb_setcolreg(unsigned int regno,unsigned int red,unsigned int green,unsigned int blue,unsigned int transp,struct fb_info *info); struct lcd_regs {unsigned long lcdcon1;unsigned long lcdcon2;unsigned long lcdcon3;unsigned long lcdcon4;unsigned long lcdcon5;unsigned long lcdsaddr1;unsigned long lcdsaddr2;unsigned long lcdsaddr3;unsigned long redlut;unsigned long greenlut;unsigned long bluelut;unsigned long reserved[9];unsigned long dithmode;unsigned long tpal;unsigned long lcdintpnd;unsigned long lcdsrcpnd;unsigned long lcdintmsk;unsigned long lpcsel;};/* 对显存的操作 */static struct fb_ops s3c_lcdfb_ops ={.owner = THIS_MODULE,.fb_setcolreg = s3c_lcdfb_setcolreg,.fb_fillrect = cfb_fillrect,/* 填充矩形 */.fb_copyarea = cfb_copyarea,/* 拷贝区域 */.fb_imageblit = cfb_imageblit,/* */};static struct fb_info *s3c_lcd;static volatile unsigned long*gpbcon;static volatile unsigned long*gpbdat;static volatile unsigned long*gpccon;static volatile unsigned long*gpdcon;static volatile unsigned long*gpgcon;static volatile struct lcd_regs* lcd_regs;static u32 pseudo_palette[16];/* from pxafb.c */static inline unsigned int chan_to_field(unsigned int chan, struct fb_bitfield *bf){chan &=0xffff;chan >>=16- bf->length;return chan << bf->offset;}static int s3c_lcdfb_setcolreg(unsigned int regno,unsigned int red,unsigned int green,unsigned int blue,unsigned int transp,struct fb_info *info) {unsigned int val;if(regno >16)return1;/* 用red,green,blue三原色构造出val */val = chan_to_field(red,&info->var.red);val |= chan_to_field(green,&info->var.green);val |= chan_to_field(blue,&info->var.blue);//((u32 *)(info->pseudo_palette))[regno] = val;pseudo_palette[regno]= val;return0;}static int lcd_init(void){/* 1. 分配一个fb_info *//* 原型: struct fb_info *framebuffer_alloc(size_t size, struct device *dev)* 其中的size表示大小,内核在分配结构体的同时会额外的分配一些内存空间原来* 分配的空间中有一个指针,指向这个额外的内存空间,里面存放私有数据。
MicrosoftWord-Linux的LCD驱动分析(四)

MicrosoftWord-Linux的LCD驱动分析(四)Linux 的 LCD 驱动分析(四)四、s3c2410fb_ops 变量详解在上面的文字中,较为详细的解释了platform device 相关的代码,通过上面的代码的执行,一个 platform 设备(framebuffer 被当作了 platform 设备)就加载到内核中去了。
就像一个 PCI 的网卡被加入到内核一样,不同的是 PCI 的网卡占用的是 PCI 总线,内核会直接支同 PCI 而对于 platform 设备需要用上面软件的方法加载到内核,持它。
网卡一样,设备需要驱动程序,刚才只是将 platform 设备注册到内核中,现在它还需要驱动程序,本节中就来看看这些驱动。
4.1 static struct fb_ops s3c2410fb_ops对于 s3c2410 的 framebuffer 驱动支持的操作主要有s3c2410fb_ops 变量中定义,该变量类型为 struct fb_ops,该类型的定义在 include/linux/fb.h 文件中。
下面看看对于 s3c2410 的驱动为该 framebuffer 提供了哪些操作。
static struct fb_ops s3c2410fb_ops = {.owner = THIS_MODULE,.fb_check_var = s3c2410fb_check_var,.fb_set_par = s3c2410fb_set_par,.fb_blank = s3c2410fb_blank,.fb_setcolreg = s3c2410fb_setcolreg,.fb_fillrect = cfb_fillrect,.fb_copyarea = cfb_copyarea,.fb_imageblit = cfb_imageblit,};上面的代码描述了支持的相关操作,下面主要会解释s3c2410****的函数,从.fb_fillrect 开始的三个函数将不会被提及,当然也可以去看看它们的行为是什么。
lcd驱动分析文档

嵌入式linux中的lcd驅動分析作者:傑洲村的木棉學校:廣東工業大學QQ:568109894在嵌入式linux中,lcd和觸控式螢幕驅動都是字元驅動,採用“檔層-驅動層”的介面方式,本文檔中分析的lcd驅動是針對linux2.6.13內核的,本人用的開發板是qq2440,lcd是三星的LTV3500V(帶觸控式螢幕的),具體分析的文件:是"include/linux/fb.h","drivers/video/s3c2410fb.h","drivers/video/s3c2410fb.c","drivers/video/fbmem.c","/include/asm/arch- s3c2410.fb.h(些標頭檔是針對s3c2440或s3c2410晶片的)",“/home/linux/5/kernel-2.6.13/arch/arm/mach-s3c2410/mach-smdk2410.c"(驅動移植主要就是要修改這個檔,配置一些參數)。
詳細看一下LCD的驅動,實際上,幾乎lcd設備驅動所要做的所有事情就是填充fb_info結構然後向系統註冊或登出它(1)fb.h包含了framebuffer所用到的結構(2)fbmem.c處於Framebuffer設備驅動技術的中心位置.它為上層應用程式提供系統調用也為下一層的特定硬體驅動提供介面;那些底層硬體驅動需要用到這兒的介面來向系統內核註冊它們自己. fbmem.c 為所有支援FrameBuffer的設備驅動提供了通用的介面,避免重復工作.(3)s3c2410fb.c就是特定硬體驅動(針對s3c2410晶片的),fbmem.c就是溝通應用層跟s3c2410fb.c的橋樑FrameBuffer設備驅動基於如下幾個檔:1)include/linux/fb.h2)drivers/video/fbmem.c3)drivers/video/s3c2410fb.c4)drivers/video/s3c2410fb.h5)include/asm/arch-s3c2410/fb.h現在先來分析這兩個檔:1.fb.h 包含了framebuffer 所用到的結構1)fb_fix_screeninfo 描述顯示卡的屬性,並且系統運行時不能被修改 structfb_fix_screeninfo {char id[16];unsigned long smem_start;/* identification string eg "TT Builtin" */ /* Start of frame buffer mem *//* (physical address) */__u32 smem_len;/* Length of frame buffer mem */__u32 type;__u32 type_aux;/* see FB_TYPE_* *//* Interleave for interleaved Planes */__u32 visual;/* see FB_VISUAL_* */ __u16 xpanstep;/* zero if no hardware panning */__u16 ypanstep;__u16 ywrapstep; __u32 line_length;/* zero if no hardware panning */ /* zero if no hardware ywrap */ /* length of a line in bytes */unsigned long mmio_start;/* Start of Memory Mapped I/O *//* (physical address) */__u32 mmio_len; __u32 accel;/* Length of Memory Mapped I/O *//* Indicate to driver which */ /* specific chip/card we have */};__u16 reserved[3];/* Reserved for future compatibility */2)fb_var_screeninfo 這個結構描述了顯示卡的特性struct fb_var_screeninfo {__u32 xres;__u32 yres;__u32 xres_virtual;/* visible resolution/* virtual resolution*/*/__u32 yres_virtual;__u32 xoffset; /* offset from virtual to visible */ __u32 yoffset;/* resolution*/__u32 bits_per_pixel; __u32 grayscale;/* guess what/* != 0 Graylevels instead of colors */*/struct fb_bitfield red; /* bitfield in fb mem if true color, */struct fb_bitfield green; /* else only length is significant */struct fb_bitfield blue;struct fb_bitfield transp; /* transparency */__u32 nonstd; /* != 0 Non standard pixel format */ __u32 activate;/* see FB_ACTIVATE_**/__u32 height; __u32 width;/* height of picture in mm/* width of picture in mm*/*/__u32 accel_flags; /* (OBSOLETE) see fb_info.flags *//* Timing: All values in pixclocks, except pixclock (of course) */__u32 pixclock; /* pixel clock in ps (pico seconds) */__u32 left_margin; /* time from sync to picture */__u32 right_margin; /* time from picture to sync */__u32 upper_margin; /* time from sync to picture */__u32 lower_margin;__u32 hsync_len; /* length of horizontal sync */__u32 vsync_len; /* length of vertical sync*/__u32 sync; /* see FB_SYNC_* */__u32 vmode; /* see FB_VMODE_* */__u32 rotate; /* angle we rotate counter clockwise */__u32 reserved[5]; /* Reserved for future compatibility */};3)fb_cmap描述設備無關的顏色映射資訊。
LCD液晶显示驱动程序设计指引

美的集团制冷事业本部企业标准QJ/MK03.056-2004 LCD液晶显示驱动程序设计指引1适用范围《LCD液晶显示驱动程序设计指引》主要对采用液晶驱动芯片HD1621(或此系列芯片)进行LCD 液晶的驱动方法进行了分析,说明了驱动芯片的功能、软件编制方法和注意事项,并提供了程序范例,为以后的程序设计者提供类似的开发参考。
2引用资料范例程序采用日本NEC公司的RA78K0S系列汇编语言编写,具体技术资料参照78K0S系列八位单片机UPD78F9177芯片的相关资料。
液晶驱动芯片参考资料:具体见HT1621DATASHEET。
3定义汇编语言:是用于编写微处理器软件的最基本编程语言。
汇编程序包:是一组程序的总称,用于把汇编语言的源程序文件转换成机器代码的程序,通常包括汇编程序﹑连接程序﹑目标码转换程序和其它库管理程序﹑表转换程序等。
LCD:液晶显示器简称。
4HT162X驱动芯片资料介绍4.1概述HT162X系列芯片是由HOTEK公司开发生产的多功能LCD 驱动器芯片,HT162X 的软件配置特性使其适合于各种LCD 的应用包括LCD 模块和显示子系统,主控器与HT162X通信只需要3 到4 条线。
由于采用了电容型偏置电压充电泵使得HT1620 的操作电流非常的小。
HT162X 系列包括多款产品适合不同的应用,目前广泛应用于各种液晶驱动控制上。
4.2芯片特性➢操作电压2.4V~3.3V➢LCD 电压3.6V~4.9V可调➢可选择1/2 或1/3 偏置1/2, 1/3 或1/4 占空比➢内部时基频率源➢片内电容型偏置充电泵➢读/写地址自动增加➢3线(或4线)串行接口➢软件配置特性➢两个可选的蜂鸣器频率2KHz 或4KHz4.3HT162X系列芯片选型表片内振荡器-√√-√√√晶体振荡器√√-√√√√5HT1621芯片说明HT1621为32*4位LCD驱动器,共有四种子型号,分别是HT1621-48SSO、HT1621B-48SSOP/DIP、HT1621D-28SKDIP,我们现在使用的为HT1621B-48SSOP,以下就以此芯片为例进行说明。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//****************************************************** *//* 2007.6.18//****************************************************** *在/kernel/include/asm-arm/arch-s3c2410/bitfield.h 文件中:#ifndef __ASSEMBLY__#define UData(Data) ((unsigned long) (Data))#else#define UData(Data) (Data)#endif例:UData(5); = 5/** MACRO: Fld** Purpose* The macro "Fld" encodes a bit field, given its size and its shift value* with respect to bit 0.** Note* A more intuitive way to encode bit fields would have been to use their* mask. However, extracting size and shift value information from a bit* field''''s mask is cumbersome and might break the assembler (255-character* line-size limit).** Input* Size Size of the bit field, in number of bits.* Shft Shift value of the bit field with respect to bit 0.** Output* Fld Encoded bit field.*/#define Fld(Size, Shft) (((Size) << 16) + (Shft))例:Fld(2,5); = 0x20005/** MACROS: FSize, FShft, FMsk, FAlnMsk, F1stBit** Purpose* The macros "FSize", "FShft", "FMsk", "FAlnMsk", and "F1stBit" return* the size, shift value, mask, aligned mask, and first bit of a* bit field.** Input* Field Encoded bit field (using the macro "Fld").** Output* FSize Size of the bit field, in number of bits.* FShft Shift value of the bit field with respectto bit 0.* FMsk Mask for the bit field.* FAlnMsk Mask for the bit field, aligned on bit 0.* F1stBit First bit of the bit field.*/#define FSize(Field) ((Field) >> 16)例:FSize(0x20005); = 2#define FShft(Field) ((Field) & 0x0000FFFF)例:FShft(0x20005); = 5/** MACRO: FInsrt** Purpose* The macro "FInsrt" inserts a value into a bit field by shifting the* former appropriately.** Input* Value Bit-field value.* Field Encoded bit field (using the macro "Fld").** Output* FInsrt Bit-field value positioned appropriately.*/#define FInsrt(Value, Field) \(UData (Value) << FShft (Field))例:FInsrt(0x3, 0x20005); = 0x3 << 0x0005 = 0x60------------------------------------------------------------------------在/kernel/include/asm-arm/arch-s3c2410/hardware.h 文件中:/** S3C2410 internal I/O mappings** We have the following mapping:* phys virt* 48000000 e8000000*/#define VIO_BASE 0xe8000000 /* virtual start of IO space */#define PIO_START 0x48000000 /* physical start of IO space */#define io_p2v(x) ((x) | 0xa0000000)#define io_v2p(x) ((x) & ~0xa0000000)# define __REG(x) io_p2v(x)# define __PREG(x) io_v2p(x)这里,在实际的寄存器操作中,都用__REG(x) 宏将物理地址转换为了虚拟地址,然后再对这些虚拟地址进行读写操作。
------------------------------------------------------------------------当应用程序对设备文件进行ioctl操作时候会调用它们。
对于fb_get_fix(),应用程序传入的是fb_fix_screeninfo结构,在函数中对其成员变量赋值,主要是smem_start(缓冲区起始地址)和smem_len(缓冲区长度),最终返回给应用程序。
在/kernel/drivers/video/s3c2410fb.c 文件中的s3c2410fb_map_video_memory 函数中:fbi->fb.fix.smem_len = fbi->max_xres * fbi->max_yres * fbi->max_bpp / 8;fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);fbi->map_cpu = consistent_alloc(GFP_KERNEL,fbi->map_size,&fbi->map_dma);if (fbi->map_cpu){fbi->screen_cpu = fbi->map_cpu + PAGE_SIZE;fbi->screen_dma = fbi->map_dma + PAGE_SIZE;fbi->fb.fix.smem_start = fbi->screen_dma;}在/kernel/include/asm-arm/proc-armo/page.h 文件中:/* PAGE_SHIFT determines the page size. This is configurable. */#if defined(CONFIG_PAGESIZE_16)#define PAGE_SHIFT 14 /* 16K */#else /* default */#define PAGE_SHIFT 15 /* 32K */#endif在/kernel/include/asm-arm/page.h 文件中:#define PAGE_SIZE (1UL << PAGE_SHIFT)#define PAGE_MASK (~(PAGE_SIZE-1))/* to align the pointer to the (next) page boundary */#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)在/kernel/arch/arm/mm/consistent.c 文件中:/** This allocates one page of cache-coherent memory space and returns* both the virtual and a "dma" address to that space. It is not clear* whether this could be called from an interrupt context or not. For* now, we expressly forbid it, especially as some of the stuff we do* here is not interrupt context safe.** Note that this does *not* zero the allocated area!*/void *consistent_alloc(int gfp, size_t size, dma_addr_t *dma_handle)这里首先计算出需要视频缓冲区的大小(LCD屏的宽度 * LCD 屏的高度 * 每像素的位数 / 每字节的位数)fbi->fb.fix.smem_len = 240*320*16/8 = 0x25800 =150K(9.375个PAGE)PAGE_SHIFT = 14PAGE_SIZE = 1<<14 = 0x4000 = 16K (1个PAGE)PAGE_MASK = 0xFFFFC000fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len +PAGE_SIZE) = PAGE_ALIGN(150K + 16K) = PAGE_ALIGN(166K) = (166K + 16K - 1) & 0xFFFFC000 = 0x2D7FF & 0xFFFFC000 = 0x2C000 =176Kconsistent_alloc(GFP_KERNEL, 176K, &fbi->map_dma);最后得到:framebuffer(物理地址)|---------------|| ... |-------|---------------| <-- fbi->map_dma| 16K |分配了 |---------------| <-- fbi->screen_dma =fbi->fb.fix.smem_start176K | |共11个 | | 160K = 10个PAGEPAGE | 160K | 可以容下所需的150K 视频缓冲区大小 (16K) | || |-------|---------------|-------| ... ||---------------|//****************************************************** *//* 2007.6.19//****************************************************** *在/kernel/drivers/video/s3c2410fb.c 文件中的s3c2410fb_activate_var 函数中:unsigned long VideoPhysicalTemp = fbi->screen_dma;这里已经得到了framebuffer 在内存中的起始地址为VideoPhysicalTemp,地址数据位为A[30:0]。