从零开始之驱动发开、linux驱动(二十八、framebuffer驱动框架)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_16777851/article/details/83420128

框架

1.注册一个framebuffer类。

2.注册一个主设备号,因为fb个数通常比较少,所以可以用老的接口统一注册。

3.为2中的注册实现通用的fops,注意这里是通用的,特殊的架构在通用的里面还是要调用专门fb注册时实现的操作接口。(参考下面)

4.提供统一的注册,卸载接口。

5.注册卸载中对一些应用层可设的参数提供一些attribute操作接口,比如分辨率,bpp,显示模式等。

6.为5中实现对应的show和store接口。

7.基本所有的store都需要对应用层设置的参数检查,通过之后,调用每个fb注册时专有的设置函数。这种函数就是把写的参数,写到真正的硬件寄存器。


static const struct file_operations fb_fops = {
	.owner =	THIS_MODULE,
	.read =		fb_read,            /* 通用的什么都没做,如果特殊架构实现了,则优先使用架构自己的 */
	.write =	fb_write,           /* 通用的写显存,如果特殊架构实现了,则优先使用架构自己的 */
	.unlocked_ioctl = fb_ioctl,
#ifdef CONFIG_COMPAT
	.compat_ioctl = fb_compat_ioctl,
#endif
	.mmap =		fb_mmap,
	.open =		fb_open,
	.release =	fb_release,
#ifdef HAVE_ARCH_FB_UNMAPPED_AREA
	.get_unmapped_area = get_fb_unmapped_area,
#endif
#ifdef CONFIG_FB_DEFERRED_IO
	.fsync =	fb_deferred_io_fsync,
#endif
	.llseek =	default_llseek,
};

驱动

1.通常是使用平台总线或设备树对数据和驱动分离。

2.撰写probe,remove函数等。

3.probe中实现对硬件的初始化,参数计算转换,资源映射,中断申请等。

4.实现fb_ops中一些和硬件相关的函数。参考下面三星平台。

这里面设置的函数主要是,针对attribute里面设置需要更新真正的硬件参数时调用。


static struct fb_ops s3c_fb_ops = {
	.owner		= THIS_MODULE,
	.fb_check_var	= s3c_fb_check_var,
	.fb_set_par	= s3c_fb_set_par,
	.fb_blank	= s3c_fb_blank,
	.fb_setcolreg	= s3c_fb_setcolreg,
	.fb_fillrect	= cfb_fillrect,
	.fb_copyarea	= cfb_copyarea,
	.fb_imageblit	= cfb_imageblit,
	.fb_pan_display	= s3c_fb_pan_display,
	.fb_ioctl	= s3c_fb_ioctl,
};

这个是注册时在sysfs中创建,使用


/* When cmap is added back in it should be a binary attribute
 * not a text one. Consideration should also be given to converting
 * fbdev to use configfs instead of sysfs */
static struct device_attribute device_attrs[] = {
	__ATTR(bits_per_pixel, S_IRUGO|S_IWUSR, show_bpp, store_bpp),
	__ATTR(blank, S_IRUGO|S_IWUSR, show_blank, store_blank),
	__ATTR(console, S_IRUGO|S_IWUSR, show_console, store_console),
	__ATTR(cursor, S_IRUGO|S_IWUSR, show_cursor, store_cursor),
	__ATTR(mode, S_IRUGO|S_IWUSR, show_mode, store_mode),
	__ATTR(modes, S_IRUGO|S_IWUSR, show_modes, store_modes),
	__ATTR(pan, S_IRUGO|S_IWUSR, show_pan, store_pan),
	__ATTR(virtual_size, S_IRUGO|S_IWUSR, show_virtual, store_virtual),
	__ATTR(name, S_IRUGO, show_name, NULL),
	__ATTR(stride, S_IRUGO, show_stride, NULL),
	__ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
	__ATTR(state, S_IRUGO|S_IWUSR, show_fbstate, store_fbstate),
#ifdef CONFIG_FB_BACKLIGHT
	__ATTR(bl_curve, S_IRUGO|S_IWUSR, show_bl_curve, store_bl_curve),
#endif
};

猜你喜欢

转载自blog.csdn.net/qq_16777851/article/details/83420128