lcd驱动架构

lcd的硬件特性以及使用方法比较简单,再次就不罗嗦了,主要写一下驱动架构方面

两个关键文件fbmem.c 和s3c2410fb.c

fbmem.c中是LINUX的缓冲帧函数,缓冲帧就是一块内存,是显示缓冲区的一种抽象,往该内存中写入颜色的数据就会在lcd上显示。

应用程序操作lcd时通过fbmem.c中的file_operations

static const struct file_operations fb_fops = {
.owner = THIS_MODULE,
.read = fb_read,
.write = fb_write,
.ioctl = fb_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = fb_compat_ioctl,
#endif
.mmap = fb_mmap,
.open = fb_open,
.release = fb_release,
#ifdef HAVE_ARCH_FB_UNMAPPED_AREA
.get_unmapped_area = get_fb_unmapped_area,
#endif
#ifdef CONFIG_FB_DEFERRED_IO
.fsync = fb_deferred_io_fsync,
#endif
};

比如应用程序调用read函数,fbmem.c中的fb_read函数将会被调用,顺藤摸瓜就会发现,fb_read函数依赖于 fb_info,如下所示,而fb_info由s3c2410fb.c中设定,即s3c2410fb.c向fbmem.c注册fb_info结构体,该结构体中含有lcd硬件的相关参数,另外lcd的驱动程序用了platform驱动总线模型,在内核里面已经包含了device硬件相关参数,

我们再写驱动程序时只需要写平台驱动,向上注册fb_info就可以了。

fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
unsigned long p = *ppos;
struct inode *inode = file->f_path.dentry->d_inode;
int fbidx = iminor(inode);
struct fb_info *info = registered_fb[fbidx];
u32 *buffer, *dst;
u32 __iomem *src;
int c, i, cnt = 0, err = 0;
unsigned long total_size;


if (!info || ! info->screen_base)
return -ENODEV;


if (info->state != FBINFO_STATE_RUNNING)
return -EPERM;


if (info->fbops->fb_read)
return info->fbops->fb_read(info, buf, count, ppos);

total_size = info->screen_size;


if (total_size == 0)
total_size = info->fix.smem_len;


if (p >= total_size)
return 0;


if (count >= total_size)
count = total_size;


if (count + p > total_size)
count = total_size - p;


buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
GFP_KERNEL);
if (!buffer)
return -ENOMEM;


src = (u32 __iomem *) (info->screen_base + p);


if (info->fbops->fb_sync)
info->fbops->fb_sync(info);


while (count) {
c  = (count > PAGE_SIZE) ? PAGE_SIZE : count;
dst = buffer;
for (i = c >> 2; i--; )
*dst++ = fb_readl(src++);
if (c & 3) {
u8 *dst8 = (u8 *) dst;
u8 __iomem *src8 = (u8 __iomem *) src;


for (i = c & 3; i--;)
*dst8++ = fb_readb(src8++);


src = (u32 __iomem *) src8;
}


if (copy_to_user(buf, buffer, c)) {
err = -EFAULT;
break;
}
*ppos += c;
buf += c;
cnt += c;
count -= c;
}


kfree(buffer);


return (err) ? err : cnt;
}



1. 帧缓冲设备驱动在Linux子系统中的结构如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值