1、在s3cfb_WXCAT43.c (linux2.6.28\drivers\video\samsung)文件中是有关具体显示器的设置。我们一段一段来看。
#include
#include
#include
#include
#include
#include
#include "s3cfb.h"
#define S3CFB_HFP 2/* front porch */
#define S3CFB_HSW 41/* hsync width */
#define S3CFB_HBP 2/* back porch */
#define S3CFB_VFP 2/* front porch */
#define S3CFB_VSW 10/* vsync width */
#define S3CFB_VBP 2/* back porch */
#define S3CFB_HRES 480/* horizon pixel x resolition */
#define S3CFB_VRES 272/* line cnt y resolution */
#define S3CFB_HRES_VIRTUAL 480/* horizon pixel x resolition */
#define S3CFB_VRES_VIRTUAL 544/* line cnt y resolution */
#define S3CFB_HRES_OSD 480/* horizon pixel x resolition */
#define S3CFB_VRES_OSD 272/* line cnt y resolution */
#define S3CFB_VFRAME_FREQ 60/* frame rate freq */
#define S3CFB_PIXEL_CLOCK (S3CFB_VFRAME_FREQ * (S3CFB_HFP + S3CFB_HSW + S3CFB_HBP + S3CFB_HRES) * (S3CFB_VFP + S3CFB_VSW + S3CFB_VBP + S3CFB_VRES))这个不太明白是干嘛用的?
那么上面这些参数的值是在那里得到的呢?那就要看具体的显示器的手册了。如下所示:
2、在这个文件中,还有两个函数,源码如下:
void s3cfb_init_hw(void)
{
printk(KERN_INFO "LCD TYPE :: LTE480WV will be initialized\n");
s3cfb_set_fimd_info();
s3cfb_set_gpio();
}
这个函数在s3cfb_init_fbinfo函数中被调用,其实就是在LCD对应的probe函数中被调用。
static void s3cfb_init_fbinfo(s3cfb_info_t *finfo, char *drv_name, int index)
{
int i = 0;
if (index == 0)
s3cfb_init_hw();
.........
}
2.1、现在来分析s3cfb_set_fimd_info函数,源码如下:
static void s3cfb_set_fimd_info(void)
{
s3cfb_fimd.vidcon1 = S3C_VIDCON1_IHSYNC_INVERT | S3C_VIDCON1_IVSYNC_INVERT | S3C_VIDCON1_IVDEN_NORMAL;
其中有#define S3C_VIDCON1_IHSYNC_INVERT(1<<6)
#define S3C_VIDCON1_IVSYNC_INVERT(1 << 5)
#define S3C_VIDCON1_IVDEN_NORMAL(0<<4)
看下图:
s3cfb_fimd.vidtcon0 = S3C_VIDTCON0_VBPD(S3CFB_VBP - 1) | S3C_VIDTCON0_VFPD(S3CFB_VFP - 1) | S3C_VIDTCON0_VSPW(S3CFB_VSW - 1);
其中有: /* VIDEO Time Control 0 register - VIDTCON0 */
#define S3C_VIDTCON0_VBPDE(x) (((x)&0xFF)<<24)
#define S3C_VIDTCON0_VBPD(x) (((x)&0xFF)<<16)
#define S3C_VIDTCON0_VFPD(x) (((x)&0xFF)<<8)
#define S3C_VIDTCON0_VSPW(x) (((x)&0xFF)<<0)
s3cfb_fimd.vidtcon1 = S3C_VIDTCON1_HBPD(S3CFB_HBP - 1) | S3C_VIDTCON1_HFPD(S3CFB_HFP - 1) | S3C_VIDTCON1_HSPW(S3CFB_HSW - 1);
s3cfb_fimd.vidtcon2 = S3C_VIDTCON2_LINEVAL(S3CFB_VRES - 1) | S3C_VIDTCON2_HOZVAL(S3CFB_HRES - 1);
s3cfb_fimd.vidosd0a = S3C_VIDOSDxA_OSD_LTX_F(0) | S3C_VIDOSDxA_OSD_LTY_F(0);
s3cfb_fimd.vidosd0b = S3C_VIDOSDxB_OSD_RBX_F(S3CFB_HRES - 1) | S3C_VIDOSDxB_OSD_RBY_F(S3CFB_VRES - 1);
s3cfb_fimd.vidosd1a = S3C_VIDOSDxA_OSD_LTX_F(0) | S3C_VIDOSDxA_OSD_LTY_F(0);
s3cfb_fimd.vidosd1b = S3C_VIDOSDxB_OSD_RBX_F(S3CFB_HRES_OSD - 1) | S3C_VIDOSDxB_OSD_RBY_F(S3CFB_VRES_OSD - 1);
这些也和上面一样的,对照手册,设置就可以了。
s3cfb_fimd.width = S3CFB_HRES; 屏幕的大小信息
s3cfb_fimd.height = S3CFB_VRES;
s3cfb_fimd.xres = S3CFB_HRES;
s3cfb_fimd.yres = S3CFB_VRES;
#if defined(CONFIG_FB_S3C_VIRTUAL_SCREEN) 与虚拟屏有关
s3cfb_fimd.xres_virtual = S3CFB_HRES_VIRTUAL;
s3cfb_fimd.yres_virtual = S3CFB_VRES_VIRTUAL;
#else
s3cfb_fimd.xres_virtual = S3CFB_HRES;
s3cfb_fimd.yres_virtual = S3CFB_VRES;
#endif
s3cfb_fimd.osd_width = S3CFB_HRES_OSD; 还记得上一篇中OSD的含义吗?
s3cfb_fimd.osd_height = S3CFB_VRES_OSD;
s3cfb_fimd.osd_xres = S3CFB_HRES_OSD;
s3cfb_fimd.osd_yres = S3CFB_VRES_OSD;
s3cfb_fimd.osd_xres_virtual = S3CFB_HRES_OSD;
s3cfb_fimd.osd_yres_virtual = S3CFB_VRES_OSD;
s3cfb_fimd.pixclock = S3CFB_PIXEL_CLOCK;
s3cfb_fimd.hsync_len = S3CFB_HSW;
s3cfb_fimd.vsync_len = S3CFB_VSW;
s3cfb_fimd.left_margin = S3CFB_HFP;
s3cfb_fimd.upper_margin = S3CFB_VFP;
s3cfb_fimd.right_margin = S3CFB_HBP;
s3cfb_fimd.lower_margin = S3CFB_VBP;
}
2.2、接着分析另外一个函数s3cfb_set_gpio(),这个函数的源码如下:
int s3cfb_set_gpio(void)
{
unsigned long val;
int i, err;
/* Must be '0' for Normal-path instead of By-pass */
writel(0x0, S3C_HOSTIFB_MIFPCON);
其中有:#define S3C_HOSTIFB_MIFPCONS3C_HOSTIFBREG(0x800C)
#define S3C_HOSTIFAREG(x)((x) + S3C64XX_VA_HOSTIFA)
同时在s3c6410的手册上有这么一句话:
Caution 1: In normal display mode, SEL_BYPASS@ MIFPCON (0x7410_800C) register must be set “0”.
/* enable clock to LCD */使能LCD的时钟
val = readl(S3C_HCLK_GATE);
val |= S3C_CLKCON_HCLK_LCD;
writel(val, S3C_HCLK_GATE);
/* phantom */也和时钟有关
val = readl(S3C_SCLK_GATE);
val |= (1<<14);
writel(val, S3C_SCLK_GATE);
/* ------- */
/* select TFT LCD type (RGB I/F) */设置RGB的数据格式
val = readl(S3C64XX_SPC_BASE);
val &= ~0x3;
val |= (1 << 0);
writel(val, S3C64XX_SPC_BASE);
其中有:#define S3C64XX_SPC_BASE(S3C64XX_VA_GPIO + 0x01A0)
这个参数的设置,和具体的TFT屏有关,在TFT屏的手册中有:24bit RGB Interface
/* VD */主要是芯片引脚的设置,看下图:不过你可能对s3c_gpio_cfgpin函数不明白,它是怎样实现的,我在以前的写的一篇博客中有说明,你可以去查看,本篇后面我会给出链接地址。
for (i = 0; i < 16; i++)
s3c_gpio_cfgpin(S3C64XX_GPI(i), S3C_GPIO_SFN(2));
for (i = 0; i < 12; i++)
s3c_gpio_cfgpin(S3C64XX_GPJ(i), S3C_GPIO_SFN(2));
#ifndef CONFIG_BACKLIGHT_PWM
/* backlight ON */
//printk("oPEN LCD BACKLIGHT1.\n"); 和LCD背光灯有关,看下面的图:
if (gpio_is_valid(S3C64XX_GPF(14))) { //NOTE: orign GPF15 here
err = gpio_request(S3C64XX_GPF(14), "GPF");
if (err) {
printk(KERN_ERR "failed to request GPF for "
"lcd backlight control\n");
return err;
}
gpio_direction_output(S3C64XX_GPF(14), 1);
gpio_set_value(S3C64XX_GPF(14), 1);
}
#endif
//printk("oPEN LCD BACKLIGHT2.\n");
if (gpio_is_valid(S3C64XX_GPE(0))) {
err = gpio_request(S3C64XX_GPE(0), "GPE");
if (err) {
printk(KERN_ERR "failed to request GPE for "
"lcd reset control\n");
return err;
}
gpio_direction_output(S3C64XX_GPE(0), 1);
}
gpio_set_value(S3C64XX_GPE(0), 1);
gpio_free(S3C64XX_GPE(0));
/* module reset */
/*if (gpio_is_valid(S3C64XX_GPN(5))) {
err = gpio_request(S3C64XX_GPN(5), "GPN");
if (err) {
printk(KERN_ERR "failed to request GPN for "
"lcd reset control\n");
return err;
}
gpio_direction_output(S3C64XX_GPN(5), 1);
}
mdelay(100);
gpio_set_value(S3C64XX_GPN(5), 0);
mdelay(10);
gpio_set_value(S3C64XX_GPN(5), 1);
mdelay(10);
*/
#ifndef CONFIG_BACKLIGHT_PWM
gpio_free(S3C64XX_GPF(14));
#endif
//gpio_free(S3C64XX_GPN(5));
return 0;
}
在这个函数出现了许多对GPIO操作的函数,如:s3c_gpio_cfgpin,gpio_direction_output等等,你可能不熟悉这些,下面这个地址链接对这些讲解的很详细。
http://www.linuxidc.com/Linux/2012-05/60224.htm
在前几篇中对LCD平台设备所对应的probe函数进行分析时,对一些函数没有进行详细的分析,因为当时主要是为了突出probe函数的整体结构,现在我们对一些函数进行再次详细点的分析。
(1)、
void s3cfb_pre_init(void)
{
/* initialize the fimd specific */
s3cfb_fimd.vidintcon0 &= ~S3C_VIDINTCON0_FRAMESEL0_MASK;
s3cfb_fimd.vidintcon0 |= S3C_VIDINTCON0_FRAMESEL0_VSYNC;
s3cfb_fimd.vidintcon0 |= S3C_VIDINTCON0_INTFRMEN_ENABLE;
writel(s3cfb_fimd.vidintcon0, S3C_VIDINTCON0);
}
这个函数主要是对VIDINTCON0寄存器的操作,这个寄存器和中断有关。具体的对那些位进行操作和怎样操作,查看手册就可以了。
(2)、
这个函数的主要作用是填充s3cfb_info_t 结构体中的成员。
static void s3cfb_init_fbinfo(s3cfb_info_t *finfo, char *drv_name, int index)
{
int i = 0;
if (index == 0)
s3cfb_init_hw();这个函数我们在上一篇博客中详细讲了,主要是根据具体TFT屏幕的参数对LCD控制寄存器的一些寄存器进行设置,还有对全局量s3cfb_fimd结构体的填充。
strcpy(finfo->fb.fix.id, drv_name);
finfo->win_id = index; 第几层窗口
下面这些代码都是填充不可变参数,这些参数的具体含义,大家可以参考另一篇博客,至于为什么要这样设置,那大家就要自己去查了。
finfo->fb.fix.type = FB_TYPE_PACKED_PIXELS;
finfo->fb.fix.type_aux = 0;
finfo->fb.fix.xpanstep = 0;
finfo->fb.fix.ypanstep = 1;
finfo->fb.fix.ywrapstep = 0;
finfo->fb.fix.accel = FB_ACCEL_NONE;
finfo->fb.fbops = &s3cfb_ops; 指向fb的操作函数集
finfo->fb.flags= FBINFO_FLAG_DEFAULT;
finfo->fb.pseudo_palette = &finfo->pseudo_pal;
填充可变参数结构,同样。
finfo->fb.var.nonstd = 0;
finfo->fb.var.activate = FB_ACTIVATE_NOW;
finfo->fb.var.accel_flags = 0;
finfo->fb.var.vmode = FB_VMODE_NONINTERLACED;
finfo->fb.var.xoffset = s3cfb_fimd.xoffset;
finfo->fb.var.yoffset = s3cfb_fimd.yoffset;
if (index == 0) { 第一层窗口时的设置
finfo->fb.var.height = s3cfb_fimd.height;
finfo->fb.var.width = s3cfb_fimd.width;
finfo->fb.var.xres = s3cfb_fimd.xres;
finfo->fb.var.yres = s3cfb_fimd.yres;
finfo->fb.var.xres_virtual = s3cfb_fimd.xres_virtual;
finfo->fb.var.yres_virtual = s3cfb_fimd.yres_virtual;
} else { 其它层窗口的设置
finfo->fb.var.height = s3cfb_fimd.osd_height;
finfo->fb.var.width = s3cfb_fimd.osd_width;
finfo->fb.var.xres = s3cfb_fimd.osd_xres;
finfo->fb.var.yres = s3cfb_fimd.osd_yres;
finfo->fb.var.xres_virtual = s3cfb_fimd.osd_xres_virtual;
finfo->fb.var.yres_virtual = s3cfb_fimd.osd_yres_virtual;
}
finfo->fb.var.bits_per_pixel = s3cfb_fimd.bpp;
finfo->fb.var.pixclock = s3cfb_fimd.pixclock;
finfo->fb.var.hsync_len = s3cfb_fimd.hsync_len;
finfo->fb.var.left_margin = s3cfb_fimd.left_margin;
finfo->fb.var.right_margin = s3cfb_fimd.right_margin;
finfo->fb.var.vsync_len = s3cfb_fimd.vsync_len;
finfo->fb.var.upper_margin = s3cfb_fimd.upper_margin;
finfo->fb.var.lower_margin = s3cfb_fimd.lower_margin;
finfo->fb.var.sync = s3cfb_fimd.sync;
finfo->fb.var.grayscale = s3cfb_fimd.cmap_grayscale;
finfo->fb.fix.smem_len = finfo->fb.var.xres_virtual * finfo->fb.var.yres_virtual * s3cfb_fimd.bytes_per_pixel;
finfo->fb.fix.line_length = finfo->fb.var.width * s3cfb_fimd.bytes_per_pixel;
#if !defined(CONFIG_FB_S3C_VIRTUAL_SCREEN)
#if defined(CONFIG_FB_S3C_DOUBLE_BUFFERING)
if (index < 2)
finfo->fb.fix.smem_len *= 2;
#else
/*
* Some systems(ex. DirectFB) use FB0 memory as a video memory.
* You can modify the size of multiple.
*/
if (index == 0)
finfo->fb.fix.smem_len *= 5;
#endif
#endif
for (i = 0; i < 256; i++)
finfo->palette_buffer[i] = S3CFB_PALETTE_BUFF_CLEAR; 清除缓冲区
}
(3)、
这个函数用来为显存分配内存
static int __init s3cfb_map_video_memory(s3cfb_info_t *fbi)
{
DPRINTK("map_video_memory(fbi=%p)\n", fbi);
fbi->map_size_f1 = PAGE_ALIGN(fbi->fb.fix.smem_len);
fbi->map_cpu_f1 = dma_alloc_writecombine(fbi->dev, fbi->map_size_f1, &fbi->map_dma_f1, GFP_KERNEL);
//因为系统采用DMA来搬移显示数据,所以使用dma_alloc_writecombine来分配一段内存区域
fbi->map_size_f1 = fbi->fb.fix.smem_len;
if (fbi->map_cpu_f1) { 如果分配成功,对s3cfb_info_t结构体的某些成员,进行填充
/* prevent initial garbage on screen */
printk("Window[%d] - FB1: map_video_memory: clear %p:%08x\n",
fbi->win_id, fbi->map_cpu_f1, fbi->map_size_f1);
memset(fbi->map_cpu_f1, 0xf0, fbi->map_size_f1);
fbi->screen_dma_f1 = fbi->map_dma_f1;
fbi->fb.screen_base = fbi->map_cpu_f1;
fbi->fb.fix.smem_start = fbi->screen_dma_f1;
printk(" FB1: map_video_memory: dma=%08x cpu=%p size=%08x\n",
fbi->map_dma_f1, fbi->map_cpu_f1, fbi->fb.fix.smem_len);
}
if (!fbi->map_cpu_f1)
return -ENOMEM;
#if defined(CONFIG_FB_S3C_DOUBLE_BUFFERING)
if (fbi->win_id < 2 && fbi->map_cpu_f1) {
fbi->map_size_f2 = (fbi->fb.fix.smem_len / 2);
fbi->map_cpu_f2 = fbi->map_cpu_f1 + fbi->map_size_f2;
fbi->map_dma_f2 = fbi->map_dma_f1 + fbi->map_size_f2;
/* prevent initial garbage on screen */
printk("Window[%d] - FB2: map_video_memory: clear %p:%08x\n",
fbi->win_id, fbi->map_cpu_f2, fbi->map_size_f2);
fbi->screen_dma_f2 = fbi->map_dma_f2;
printk(" FB2: map_video_memory: dma=%08x cpu=%p size=%08x\n",
fbi->map_dma_f2, fbi->map_cpu_f2, fbi->map_size_f2);
}
#endif
if (s3cfb_fimd.map_video_memory)
(s3cfb_fimd.map_video_memory)(fbi);
return 0;
}
(4)、
/*
* s3cfb_check_var():
* Get the video params out of 'var'. If a value doesn't fit, round it up,
* if it's too big, return -EINVAL.
*
*/ 此函数检查fb_info中的可变参数。
static int s3cfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
{
s3cfb_info_t *fbi = (s3cfb_info_t *) info;
DPRINTK("check_var(var=%p, info=%p)\n", var, info);
switch (var->bits_per_pixel) { BPP,每像素的位数
case 8: 8BPP
var->red = s3cfb_rgb_8.red;
var->green = s3cfb_rgb_8.green;
var->blue = s3cfb_rgb_8.blue;
var->transp = s3cfb_rgb_8.transp;
s3cfb_fimd.bytes_per_pixel = 1;
break;
其实上面这些red、green等都是 fb_bitfield 的结构体,这个结构体描述了每一像素显示缓冲区的组织方式,在第一篇博客说framebuffer中说过了。
struct fb_bitfield {
__u32 offset; /* beginning of bitfield */
__u32 length; /* length of bitfield */
__u32 msb_right;/* != 0 : Most significant bit is */
/* right */
};
其实在S3cfb.h (linux2.6.28\drivers\video\samsung)文件中还有如下定义:
typedef struct {
struct fb_bitfield red;
struct fb_bitfield green;
struct fb_bitfield blue;
struct fb_bitfield transp;
} s3cfb_rgb_t;
const static s3cfb_rgb_t s3cfb_rgb_8 = {
.red = {.offset = 0, .length = 8,},
.green = {.offset = 0, .length = 8,},
.blue = {.offset = 0, .length = 8,},
.transp = {.offset = 0, .length = 0,},
};
const static s3cfb_rgb_t s3cfb_rgb_16 = {
.red = {.offset = 11, .length = 5,},
.green = {.offset = 5, .length = 6,},
.blue = {.offset = 0, .length = 5,},
.transp = {.offset = 0, .length = 0,},
};
const static s3cfb_rgb_t s3cfb_rgb_24 = {
.red = {.offset = 16, .length = 8,},
.green = {.offset = 8, .length = 8,},
.blue = {.offset = 0, .length = 8,},
.transp = {.offset = 0, .length = 0,},
};
const static s3cfb_rgb_t s3cfb_rgb_28 = {
.red = {.offset = 16, .length = 8,},
.green = {.offset = 8, .length = 8,},
.blue = {.offset = 0, .length = 8,},
.transp = {.offset = 24, .length = 4,},
};
const static s3cfb_rgb_t s3cfb_rgb_32 = {
.red = {.offset = 16, .length = 8,},
.green = {.offset = 8, .length = 8,},
.blue = {.offset = 0, .length = 8,},
.transp = {.offset = 24, .length = 8,},
};
下面也是一样的,看到这些,我想一切尽在不言中了吧?
case 16:
var->red = s3cfb_rgb_16.red;
var->green = s3cfb_rgb_16.green;
var->blue = s3cfb_rgb_16.blue;
var->transp = s3cfb_rgb_16.transp;
s3cfb_fimd.bytes_per_pixel = 2;
break;
case 24:
var->red = s3cfb_rgb_24.red;
var->green = s3cfb_rgb_24.green;
var->blue = s3cfb_rgb_24.blue;
var->transp = s3cfb_rgb_24.transp;
s3cfb_fimd.bytes_per_pixel = 4;
break;
case 28:
var->red = s3cfb_rgb_28.red;
var->green = s3cfb_rgb_28.green;
var->blue = s3cfb_rgb_28.blue;
var->transp = s3cfb_rgb_28.transp;
s3cfb_fimd.bytes_per_pixel = 4;
break;
case 32:
var->red = s3cfb_rgb_32.red;
var->green = s3cfb_rgb_32.green;
var->blue = s3cfb_rgb_32.blue;
var->transp = s3cfb_rgb_32.transp;
s3cfb_fimd.bytes_per_pixel = 4;
break;
}
/* WIN0 cannot support alpha channel. */ 窗口0不支持透明度模式
if( (fbi->win_id == 0) && (var->bits_per_pixel == 28) ){
var->transp.length = 0;
}
return 0;
}
当然,说是详细说这些函数,其实还不是特别详细,因为这涉及到太多的东西,但我们弄明白了这些函数的大致作用,至于具体参数的设置,就需要进一步分析了。