有些嵌入式設(shè)備是不需要lcd的,比如路由器。但是,還有些設(shè)備是需要lcd顯示內(nèi)容的,比如游戲機、測試儀、智能手表等等。所以,今天我們就看看lcd驅(qū)動在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設(shè)備,接著看看其probe函數(shù)做了什么
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動作,當然還要閱讀一下是否存在其他的函數(shù)接口
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、最后還是老規(guī)矩,看看有沒有中斷需要處理的
1
|
ret = request_irq(irq, s3c2410fb_irq, 0, pdev->name, info); |
9、后面的話
很多同學把驅(qū)動想的很復雜,其實都是一些格式代碼。掌握了基本結(jié)構(gòu),加上芯片手冊、硬件協(xié)議,一般的驅(qū)動都可以在很短的時間內(nèi)學會,這個不存在問題。尤其是那些在市場上出現(xiàn)了很多年的soc,基本不需要改動就可以直接使用。當然,如果真的發(fā)現(xiàn)問題了,我們也要有debug的能力。drivers目錄里面的內(nèi)容很多,但是需要了解和關(guān)心的其實不多,努力去做、去解決問題就可以了。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/feixiaoxing/article/details/79885576