日期:2014-05-16 浏览次数:20677 次
在前面我们已经明确了LCD驱动其实就是一个字符设备驱动,它的主设备号为29,次设备号同注册的帧缓冲设备有关,从0开始最多支持32个帧缓冲设备。接下来将主要是对LCD这个字符设备的file_operations分析。
struct file_operations定义:
1424 static const struct file_operations fb_fops = {
1425 .owner = THIS_MODULE,
1426 .read = fb_read,
1427 .write = fb_write,
1428 .unlocked_ioctl = fb_ioctl,
1429 #ifdef CONFIG_COMPAT
1430 .compat_ioctl = fb_compat_ioctl,
1431 #endif
1432 .mmap = fb_mmap,
1433 .open = fb_open,
1434 .release = fb_release,
1435 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
1436 .get_unmapped_area = get_fb_unmapped_area,
1437 #endif
1438 #ifdef CONFIG_FB_DEFERRED_IO
1439 .fsync = fb_deferred_io_fsync,
1440 #endif
1441 };
先看其中的open和release函数的实现。
1372 static int
1373 fb_open(struct inode *inode, struct file *file)
1374 __acquires(&info->lock)
1375 __releases(&info->lock)
1376 {
1377 int fbidx = iminor(inode);
1378 struct fb_info *info;
1379 int res = 0;
1380
1381 if (fbidx >= FB_MAX)
1382 return -ENODEV;
1383 info = registered_fb[fbidx];
1384 if (!info)
1385 request_module("fb%d", fbidx);
1386 info = registered_fb[fbidx];
1387 if (!info)
1388 return -ENODEV;
1389 mutex_lock(&info->lock);
1390 if (!try_module_get(info->fbops->owner)) {
1391 res = -ENODEV;
1392 goto out;
1393 }
1394 file->private_data = info;
1395 if (info->fbops->fb_open) {
1396 res = info->fbops->fb_open(info,1);
1397 if (res)
1398 module_put(info->fbops->owner);
1399 }
1400 #ifdef CONFIG_FB_DEFERRED_IO
1401 if (info->fbdefio)
1402 &nb