Wei Dongshan Phase 2 Driver Encyclopedia-004_LCD Driver

1. Hierarchical analysis-analysis fbmem.c file

LCD driver

1.1 analysis entry function

(1) Main device number: FB_MAJOR;
(2) file_operations structure: fb_fops;
(3) register_chrdev: It
is exactly the same as the driver analyzed before!

static int __init
fbmem_init(void)
{
    
    
	create_proc_read_entry("fb", 0, NULL, fbmem_read_proc, NULL);

	if (register_chrdev(FB_MAJOR,"fb",&fb_fops))
		printk("unable to get major %d for fb devs\n", FB_MAJOR);

	fb_class = class_create(THIS_MODULE, "graphics");
	if (IS_ERR(fb_class)) {
    
    
		printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class));
		fb_class = NULL;
	}
	return 0;
}

1.2 Analysis of the open function

1. Assuming app: open("/dev/fb0", …) Major device number: 29, Minor device number: 0
kernel: According to the above major device number and this device number, the open function of this driver can be found

 fb_open(struct inode *inode, struct file *file)函数
 	int fbidx = iminor(inode);//找到设备节点的次设备号,这里fbidx=0
 	struct fb_info *info = = registered_fb[fbidx];//依据次设备号

static int fb_open(struct inode *inode, struct file *file)
{
    
    
	int fbidx = iminor(inode);//找到设备节点的次设备号,这里fbidx=0
	struct fb_info *info;
	info = registered_fb[fbidx];//依据次设备号找到
	if (info->fbops->fb_open) {
    
    
		res = info->fbops->fb_open(info,1);
}

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)   

Question 1. Where is registered_fb set?
Answer 1. register_framebuffer

How to write LCD driver?

  1. Allocate a fb_info structure: framebuffer_alloc
  2. Set up
  3. Registration: register_framebuffer
  4. Hardware related operations

2. LCD hardware related operations

LCD hardware principle, please refer to the following link ARM-LCD control principle notes

  1. Configuration pin for LCD
  2. Set the LCD controller according to the LCD manual;
  3. The cpu initializes a video memory (FrameBuffer) and establishes the relationship between the video memory (FrameBuffer) and the LCD controller. The
    LCD controller sends control signals and displayed data to the
    LCD driver. The LCD driver sends an analog signal to the display panel. Control where the panel displays what color point

3. Compile and debug

  1. Change the LCD driver in the kernel to M.
    In order to make the LCD driver in the kernel not conflict with the driver written by yourself, you need to reconfigure the kernel first:
 make menuconfig

Insert picture description here
Insert picture description here
Insert picture description here

 make uImage
 make modules #由于驱动程序中有三个函数需要ko文件支持
  1. Use uboot to reload the kernel through the network port.
    Confirm whether the uboot configuration ip of the development board and the host ip are in the same network segment.
    Insert picture description here
    Use the nfs command to download uImage to the specified address of nand 0x30000000
    Insert picture description here

Guess you like

Origin blog.csdn.net/xiaoaojianghu09/article/details/106172831