亲宝软件园·资讯

展开

linux lcd驱动 详解linux lcd驱动编写

feixiaoxing 人气:0
想了解详解linux lcd驱动编写的相关内容吗,feixiaoxing在本文为您仔细讲解linux lcd驱动的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:linux,lcd驱动,linux,lcd驱动框架,下面大家一起来学习吧。

有些嵌入式设备是不需要lcd的,比如路由器。但是,还有些设备是需要lcd显示内容的,比如游戏机、测试仪、智能手表等等。所以,今天我们就看看lcd驱动在linux上是怎么进行的。

1、代码目录

drivers/video

2、查看video下的Makefile文件

# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_VGASTATE)      += vgastate.o
obj-$(CONFIG_HDMI)        += hdmi.o

obj-$(CONFIG_VT)  += console/
obj-$(CONFIG_FB_STI)  += console/
obj-$(CONFIG_LOGO)  += logo/
obj-y   += backlight/

obj-y   += fbdev/

obj-$(CONFIG_VIDEOMODE_HELPERS) += display_timing.o videomode.o
ifeq ($(CONFIG_OF),y)
obj-$(CONFIG_VIDEOMODE_HELPERS) += of_display_timing.o of_videomode.o
endif

3、fbdev默认是被编译的,一般情况下我们只需要看这个目录就行了

config FB_S3C2410
 tristate "S3C2410 LCD framebuffer support"
 depends on FB && ARCH_S3C24XX
 select FB_CFB_FILLRECT
 select FB_CFB_COPYAREA
 select FB_CFB_IMAGEBLIT
 ---help---
  Frame buffer driver for the built-in LCD controller in the Samsung
  S3C2410 processor.

  This driver is also available as a module ( = code which can be
  inserted and removed from the running kernel whenever you want). The
  module will be called s3c2410fb. If you want to compile it as a module,
  say M here and read <file:Documentation/kbuild/modules.txt>.

  If unsure, say N.
config FB_S3C2410_DEBUG
 bool "S3C2410 lcd debug messages"
 depends on FB_S3C2410
 help
  Turn on debugging messages. Note that you can set/unset at run time
  through sysfs

4、以s3c2410为例,分析得出其lcd主要依赖的macro是FB_S3C2410,

obj-y  += core/

obj-$(CONFIG_FB_S3C2410)  += s3c2410fb.o

5、除了core是默认编译的,我们只需要查看s3c2410fb.c这个文件

static struct platform_driver s3c2410fb_driver = {
 .probe = s3c2410fb_probe,
 .remove = s3c2410fb_remove,
 .suspend = s3c2410fb_suspend,
 .resume = s3c2410fb_resume,
 .driver = {
 .name = "s3c2410-lcd",
 },
};

static struct platform_driver s3c2412fb_driver = {
 .probe = s3c2412fb_probe,
 .remove = s3c2410fb_remove,
 .suspend = s3c2410fb_suspend,
 .resume = s3c2410fb_resume,
 .driver = {
 .name = "s3c2412-lcd",
 },
};

int __init s3c2410fb_init(void)
{
 int ret = platform_driver_register(&s3c2410fb_driver);

 if (ret == 0)
 ret = platform_driver_register(&s3c2412fb_driver);

 return ret;
}

6、不出意外,这又是一个platform设备,接着看看其probe函数做了什么

ret = register_framebuffer(fbinfo);
 if (ret < 0) {
 dev_err(&pdev->dev, "Failed to register framebuffer device: %d\n",
  ret);
 goto free_cpufreq;
 }

7、整个代码,最重要的就是这个register动作,当然还要阅读一下是否存在其他的函数接口

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,
};

8、最后还是老规矩,看看有没有中断需要处理的

ret = request_irq(irq, s3c2410fb_irq, 0, pdev->name, info);

9、后面的话

很多同学把驱动想的很复杂,其实都是一些格式代码。掌握了基本结构,加上芯片手册、硬件协议,一般的驱动都可以在很短的时间内学会,这个不存在问题。尤其是那些在市场上出现了很多年的soc,基本不需要改动就可以直接使用。当然,如果真的发现问题了,我们也要有debug的能力。drivers目录里面的内容很多,但是需要了解和关心的其实不多,努力去做、去解决问题就可以了。

加载全部内容

相关教程
猜你喜欢
用户评论