详解linux lcd驱动编写
有些嵌入式设备是不需要lcd的,比如路由器。但是,还有些设备是需要lcd显示内容的,比如游戏机、测试仪、智能手表等等。所以,今天我们就看看lcd驱动在linux上是怎么进行的。
1、代码目录
1
|
drivers/video
|
2、查看video下的Makefile文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# 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默认是被编译的,一般情况下我们只需要看这个目录就行了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
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,
1
2
3
|
obj-y += core/
obj-$(CONFIG_FB_S3C2410) += s3c2410fb.o
|
5、除了core是默认编译的,我们只需要查看s3c2410fb.c这个文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
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函数做了什么
1
2
3
4
5
6
|
ret = register_framebuffer(fbinfo);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to register framebuffer device: %d\n" ,
ret);
goto free_cpufreq;
}
|
7、整个代码,最重要的就是这个register动作,当然还要阅读一下是否存在其他的函数接口
1
2
3
4
5
6
7
8
9
10
|
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、最后还是老规矩,看看有没有中断需要处理的
1
|
ret = request_irq(irq, s3c2410fb_irq, 0, pdev->name, info);
|
9、后面的话
很多同学把驱动想的很复杂,其实都是一些格式代码。掌握了基本结构,加上芯片手册、硬件协议,一般的驱动都可以在很短的时间内学会,这个不存在问题。尤其是那些在市场上出现了很多年的soc,基本不需要改动就可以直接使用。当然,如果真的发现问题了,我们也要有debug的能力。drivers目录里面的内容很多,但是需要了解和关心的其实不多,努力去做、去解决问题就可以了。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
原文链接:https://blog.csdn.net/feixiaoxing/article/details/79885576
本文由主机测评网发布,不代表主机测评网立场,转载联系作者并注明出处:https://zhuji.jb51.net/linux/5230.html