詳解linux lcd驅(qū)動編寫
有些嵌入式設(shè)備是不需要lcd的,比如路由器。但是,還有些設(shè)備是需要lcd顯示內(nèi)容的,比如游戲機、測試儀、智能手表等等。所以,今天我們就看看lcd驅(qū)動在linux上是怎么進(jìn)行的。
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默認(rèn)是被編譯的,一般情況下我們只需要看這個目錄就行了
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是默認(rèn)編譯的,我們只需要查看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設(shè)備,接著看看其probe函數(shù)做了什么
ret = register_framebuffer(fbinfo);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to register framebuffer device: %d\n",
ret);
goto free_cpufreq;
}
7、整個代碼,最重要的就是這個register動作,當(dāng)然還要閱讀一下是否存在其他的函數(shù)接口
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ī)矩,看看有沒有中斷需要處理的
ret = request_irq(irq, s3c2410fb_irq, 0, pdev->name, info);
9、后面的話
很多同學(xué)把驅(qū)動想的很復(fù)雜,其實都是一些格式代碼。掌握了基本結(jié)構(gòu),加上芯片手冊、硬件協(xié)議,一般的驅(qū)動都可以在很短的時間內(nèi)學(xué)會,這個不存在問題。尤其是那些在市場上出現(xiàn)了很多年的soc,基本不需要改動就可以直接使用。當(dāng)然,如果真的發(fā)現(xiàn)問題了,我們也要有debug的能力。drivers目錄里面的內(nèi)容很多,但是需要了解和關(guān)心的其實不多,努力去做、去解決問題就可以了。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信