概述
1.LCD驱动框架
1.1程序结构
打开设备
app:
open(“/dev/fb0”, …)
kernel:
fb_open
int fbidx = iminor(inode);
struct fb_info *info = = registered_fb[0];
读设备
app:
read()
kernel:
fb_read
int fbidx = iminor(inode);
struct fb_info *info = registered_fb[fbidx];
if (info->fbops->fb_read)
return info->fbops->fb_read(info, buf, count, ppos);
src = (u32 __iomem *) (info->screen_base + p);
dst = buffer;
*dst++ = fb_readl(src++);
copy_to_user(buf, buffer, c)
可以看到,驱动程序依赖于registered_fb结构。
2.LCD驱动
具体步骤如下:
1.分配一个fb_info
2.设置
2.1 设置固定的参数
2.2 设置可变的参数
2.3 设置操作函数
2.4 其他的设置
3.硬件相关的操作
3.1 配置GPIO用于LCD
3.2 根据LCD手册设置LCD控制器,比如VCLK频率等
3.3 分配显存(framebuffer),并把地址告诉LCD控制器
这里,硬件相关的操作需要结合2440和LCD的手册进行配置。详细情况参考韦东山老师的视频。
4.注册
3.驱动测试
- make memuconfig去掉原来的LCD驱动程序
cd /work/system/linux-2.6.22.6/
make menuconfig
显示如下信息
scripts/kconfig/mconf arch/arm/Kconfig
drivers/serial/Kconfig:235:warning: multi-line strings not supported
.config - Linux Kernel v2.6.22.6 Configuration
----------------------------------------------------------------------------------------------------
+--------------------------------- Linux Kernel Configuration ----------------------------------+
|
Arrow keys navigate the menu.
<Enter> selects submenus --->.
Highlighted letters are
|
|
hotkeys.
Pressing <Y> includes, <N> excludes, <M> modularizes features.
Press <Esc><Esc>
|
|
to exit, <?> for Help, </> for Search.
Legend: [*] built-in
[ ] excluded
<M> module
< >
|
|
module capable
|
| +-------------------------------------------------------------------------------------------+ |
| |
Code maturity level options
--->
| |
| |
General setup
--->
| |
| |
Loadable module support
--->
| |
| |
Block layer
--->
| |
| |
System Type
--->
| |
| |
Bus support
--->
| |
| |
Kernel Features
--->
| |
| |
Boot options
--->
| |
| |
Floating point emulation
--->
| |
| +----------v(+)-----------------------------------------------------------------------------+ |
+-----------------------------------------------------------------------------------------------+
|
<Select>
< Exit >
< Help >
|
+-----------------------------------------------------------------------------------------------+
将S3C2410 LCD framebuffer support修改为M
-> Device Drivers
-> Graphics support
S3C2410 LCD framebuffer support
2.编译kernel
book@book-desktop:/work/system/linux-2.6.22.6$ make uImage
…
iis_probe' and 's3c2410iis_remove')
Kernel: arch/arm/boot/Image is ready
Kernel: arch/arm/boot/zImage is ready
Image arch/arm/boot/uImage is ready
book@book-desktop:/work/system/linux-2.6.22.6$ cp arch/arm/boot/uImage /work/nfs_root/uImage_nolcd
book@book-desktop:/work/system/linux-2.6.22.6$ ls /work/nfs_root/uImage_nolcd -l
-rw-r--r-- 1 book book 1842388 2016-08-10 01:02 /work/nfs_root/uImage_nolcd
3.编译模块
book@book-desktop:/work/system/linux-2.6.22.6$ make modules
…
Building modules, stage 2.
MODPOST 26 modules
4.使用新uImage启动开发板
开发板reboot,进入uboot
# reboot
…
+---------------------------------------------+
| S3C2440A USB Downloader ver R0.03 2004 Jan
|
+---------------------------------------------+
USB: IN_ENDPOINT:1 OUT_ENDPOINT:3
FORMAT: <ADDR(DATA):4>+<SIZE(n+10):4>+<DATA:n>+<CS:2>
NOTE: Power off/on or press the reset button for 1 sec
in order to get a valid USB device address.
Hit any key to stop autoboot:
0
##### 100ask Bootloader for OpenJTAG #####
[n] Download u-boot to Nand Flash
[k] Download Linux kernel uImage
[j] Download root_jffs2 image
[y] Download root_yaffs image
[d] Download to SDRAM & Run
[z] Download zImage into RAM
[g] Boot linux from RAM
[f] Format the Nand Flash
[s] Set the boot parameters
[b] Boot the system
[r] Reboot u-boot
[q] Quit from menu
Enter your selection: q
OpenJTAG>
查看开发板IP地址和服务器IP地址是否在同一网段
OpenJTAG> print
bootcmd=nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0
bootdelay=2
baudrate=115200
ethaddr=08:00:3e:26:0a:5b
netmask=255.255.255.0
mtdids=nand0=nandflash0
mtdparts=mtdparts=nandflash0:256k@0(bootloader),128k(params),2m(kernel),-(root)
bootargs=noinitrd root=/dev/nfs nfsroot=192.168.10.175:/work/nfs_root/first_fs ip=192.168.10.11:192.168.10.175:192.168.10.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC0
ipaddr=192.168.10.11
serverip=192.168.10.101
stdin=serial
stdout=serial
stderr=serial
partition=nand0,0
mtddevnum=0
mtddevname=bootloader
Environment size: 556/131068 bytes
nfs下载新uImage
OpenJTAG> nfs 30000000 192.168.10.175:/work/nfs_root/uImage_nolcd
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
could not establish link
File transfer via NFS from server 192.168.10.175; our IP address is 192.168.10.11
Filename '/work/nfs_root/uImage_nolcd'.
Load address: 0x30000000
Loading: checksum bad
checksum bad
checksum bad
checksum bad
checksum bad
checksum bad
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
###################################
done
Bytes transferred = 1842388 (1c1cd4 hex)
5.准备驱动程序
编译lcd.c
book@book-desktop:/work/my_drivers/10th_lcd$ make
…
book@book-desktop:/work/my_drivers/10th_lcd$ cp lcd.ko /work/nfs_root/first_fs
book@book-desktop:/work/my_drivers/10th_lcd$ ls -l /work/nfs_root/first_fs/lcd*
-rw-r--r-- 1 book book 79529 2016-08-10 01:21 /work/nfs_root/first_fs/lcd.ko
拷贝cfbcopyarea.ko,cfbfillrect.ko,cfbimgblt.ko
book@book-desktop:/work/system/linux-2.6.22.6$ cp drivers/video/cfb*.ko /work/nfs_root/first_fs
book@book-desktop:/work/system/linux-2.6.22.6$ ls -l /work/nfs_root/first_fs/cfb*.ko
-rw-r--r-- 1 book book 79735 2016-08-10 01:18 /work/nfs_root/first_fs/cfbcopyarea.ko
-rw-r--r-- 1 book book 79524 2016-08-10 01:18 /work/nfs_root/first_fs/cfbfillrect.ko
-rw-r--r-- 1 book book 78123 2016-08-10 01:18 /work/nfs_root/first_fs/cfbimgblt.ko
6.装载驱动
# insmod cfbcopyarea.ko
# insmod cfbfillrect.ko
# insmod cfbimgblt.ko
# insmod lcd.ko
7.查看结果
# ls /dev/fb*
/dev/fb0
/dev/fb1
# cat lcd.ko > /dev/fb1
LCD屏幕出现花屏
4.代码
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/dma-mapping.h>
#include <linux/interrupt.h>
#include <linux/workqueue.h>
#include <linux/wait.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/div64.h>
#include <asm/mach/map.h>
#include <asm/arch/regs-lcd.h>
#include <asm/arch/regs-gpio.h>
#include <asm/arch/fb.h>
struct lcd_regs {
unsigned long
lcdcon1;
unsigned long
lcdcon2;
unsigned long
lcdcon3;
unsigned long
lcdcon4;
unsigned long
lcdcon5;
unsigned long
lcdsaddr1;
unsigned long
lcdsaddr2;
unsigned long
lcdsaddr3;
unsigned long
redlut;
unsigned long
greenlut;
unsigned long
bluelut;
unsigned long
reserved[9];
unsigned long
dithmode;
unsigned long
tpal;
unsigned long
lcdintpnd;
unsigned long
lcdsrcpnd;
unsigned long
lcdintmsk;
unsigned long
lpcsel;
};
static struct fb_info *s3c_lcd;
static volatile unsigned long *gpbcon;
static volatile unsigned long *gpbdat;
static volatile unsigned long *gpccon;
static volatile unsigned long *gpdcon;
static volatile unsigned long *gpgcon;
static volatile struct lcd_regs *lcd_regs;
static u32 pseudo_platette[16];
static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
{
chan &= 0xffff;
chan >>= 16 - bf->length;
return chan << bf->offset;
}
static int s3c_lcdfb_setcolreg(unsigned int regno, unsigned int red,
unsigned int green, unsigned int blue,
unsigned int transp, struct fb_info *info)
{
unsigned int val;
if(regno > 16)
return 1;
val
= chan_to_field(red, &info->var.red);
val |= chan_to_field(green, &info->var.green);
val |= chan_to_field(blue, &info->var.blue);
pseudo_platette[regno] = val;
return 0;
}
static struct fb_ops s3c_lcdfb_ops = {
.owner
= THIS_MODULE,
.fb_setcolreg
= s3c_lcdfb_setcolreg,
.fb_fillrect
= cfb_fillrect,
.fb_copyarea
= cfb_copyarea,
.fb_imageblit
= cfb_imageblit,
};
static int lcd_init(void)
{
/* 1.分配一个fb_info */
s3c_lcd = framebuffer_alloc(0, NULL);
/* 2.设置 */
/* 2.1 设置固定的参数 */
strcpy(s3c_lcd->fix.id, "mylcd");
s3c_lcd->fix.smem_len
= 240*320*16/8;
s3c_lcd->fix.type
= FB_TYPE_PACKED_PIXELS;
s3c_lcd->fix.visual
= FB_VISUAL_TRUECOLOR;
s3c_lcd->fix.line_length = 240*2;
/* 2.2 设置可变的参数 */
s3c_lcd->var.xres
= 240;
s3c_lcd->var.yres
= 320;
s3c_lcd->var.xres_virtual
= 240;
s3c_lcd->var.yres_virtual
= 320;
s3c_lcd->var.bits_per_pixel = 16;
/* RGB:665 */
s3c_lcd->var.red.offset
= 11;
s3c_lcd->var.red.length
= 5;
s3c_lcd->var.green.offset
= 5;
s3c_lcd->var.green.length
= 6;
s3c_lcd->var.blue.offset
= 0;
s3c_lcd->var.blue.length
= 5;
s3c_lcd->var.activate
= FB_ACTIVATE_NOW;
/* 2.3 设置操作函数 */
s3c_lcd->fbops
= &s3c_lcdfb_ops;
/* 2.4 其他的设置 */
s3c_lcd->screen_size
= 240*324*16/8;
s3c_lcd->pseudo_palette = pseudo_platette;
//s3c_lcd->screen_base = ;
/* 3.硬件相关的操作 */
/* 3.1 配置GPIO用于LCD */
gpbcon = ioremap(0x56000010, 8);
gpbdat = gpbcon + 1;
gpccon = ioremap(0x56000020, 4);
gpdcon = ioremap(0x56000030, 4);
gpgcon = ioremap(0x56000060, 4);
*gpccon = 0xaaaaaaaa;
*gpdcon = 0xaaaaaaaa;
*gpbcon &= ~(3);
*gpbcon |= 1;
*gpbdat &= ~1;
*gpgcon |= (3<<8);
/* 3.2 根据LCD手册设置LCD控制器,比如VCLK频率等 */
lcd_regs = ioremap(0x4D000000, sizeof(struct lcd_regs));
lcd_regs->lcdcon1 = (4<<8) | (3<<5) | (0x0c<<1);
lcd_regs->lcdcon2 = (3<<24) | (319<<14) | (1<<6) | (0<<0);
lcd_regs->lcdcon3 = (16<<19) | (239<<8) | (10<<0);
lcd_regs->lcdcon4 = 4;
lcd_regs->lcdcon5 = (1<<11) | (0<<10) | (1<<9) | (1<<8) | (1<<0);
/* 3.3 分配显存(framebuffer),并把地址告诉LCD控制器 */
s3c_lcd->screen_base = dma_alloc_writecombine(NULL, s3c_lcd->fix.smem_len, &s3c_lcd->fix.smem_start, GFP_KERNEL);
lcd_regs->lcdsaddr1
= (s3c_lcd->fix.smem_start >> 1) & ~(3<<30);
lcd_regs->lcdsaddr2
= ((s3c_lcd->fix.smem_start + s3c_lcd->fix.smem_len) >> 1) & 0x1fffff;
lcd_regs->lcdsaddr3
= (240*16/16);
lcd_regs->lcdcon1 |= (1<<0);
lcd_regs->lcdcon5 |= (1<<3);
*gpbdat |= 1;
/* 4.注册 */
register_framebuffer(s3c_lcd);
return 0;
}
static void lcd_exit(void)
{
unregister_framebuffer(s3c_lcd);
lcd_regs->lcdcon1 &= ~(1<<0);
*gpbdat &= ~1;
dma_free_writecombine(NULL, s3c_lcd->fix.smem_len, s3c_lcd->screen_base, s3c_lcd->fix.smem_start);
iounmap(lcd_regs);
iounmap(gpbcon);
iounmap(gpccon);
iounmap(gpdcon);
iounmap(gpgcon);
framebuffer_release(s3c_lcd);
}
module_init(lcd_init);
module_exit(lcd_exit);
MODULE_LICENSE("GPL");
5.参考资料
韦东山Linux第2期视频_深入写驱动/LCD驱动程序*
参考kernel文件Fbmem.c
最后
以上就是斯文紫菜为你收集整理的【记录】LCD驱动1.LCD驱动框架2.LCD驱动3.驱动测试4.代码5.参考资料的全部内容,希望文章能够帮你解决【记录】LCD驱动1.LCD驱动框架2.LCD驱动3.驱动测试4.代码5.参考资料所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复