1. 程式人生 > >從零開始之驅動發開、linux驅動(二十八、framebuffer驅動框架)

從零開始之驅動發開、linux驅動(二十八、framebuffer驅動框架)

框架

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
};