⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ivtvfb.c

📁 trident tm5600的linux驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/*    On Screen Display cx23415 Framebuffer driver    This module presents the cx23415 OSD (onscreen display) framebuffer memory    as a standard Linux /dev/fb style framebuffer device. The framebuffer has    support for 8, 16 & 32 bpp packed pixel formats with alpha channel. In 16bpp    mode, there is a choice of a three color depths (12, 15 or 16 bits), but no    local alpha. The colorspace is selectable between rgb & yuv.    Depending on the TV standard configured in the ivtv module at load time,    the initial resolution is either 640x400 (NTSC) or 640x480 (PAL) at 8bpp.    Video timings are locked to ensure a vertical refresh rate of 50Hz (PAL)    or 59.94 (NTSC)    Copyright (c) 2003 Matt T. Yourst <yourst@yourst.com>    Derived from drivers/video/vesafb.c    Portions (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>    2.6 kernel port:    Copyright (C) 2004 Matthias Badaire    Copyright (C) 2004  Chris Kennedy <c@groovy.org>    Copyright (C) 2006  Ian Armstrong <ian@iarmst.demon.co.uk>    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <linux/module.h>#include <linux/kernel.h>#include <linux/fb.h>#include <linux/ivtvfb.h>#ifdef CONFIG_MTRR#include <asm/mtrr.h>#endif#include "ivtv-driver.h"#include "ivtv-i2c.h"#include "ivtv-udma.h"#include "ivtv-mailbox.h"/* card parameters */static int ivtvfb_card_id = -1;static int ivtvfb_debug = 0;static int osd_laced;static int osd_depth;static int osd_upper;static int osd_left;static int osd_yres;static int osd_xres;module_param(ivtvfb_card_id, int, 0444);module_param_named(debug,ivtvfb_debug, int, 0644);module_param(osd_laced, bool, 0444);module_param(osd_depth, int, 0444);module_param(osd_upper, int, 0444);module_param(osd_left, int, 0444);module_param(osd_yres, int, 0444);module_param(osd_xres, int, 0444);MODULE_PARM_DESC(ivtvfb_card_id,		 "Only use framebuffer of the specified ivtv card (0-31)\n"		 "\t\t\tdefault -1: initialize all available framebuffers");MODULE_PARM_DESC(debug,		 "Debug level (bitmask). Default: errors only\n"		 "\t\t\t(debug = 3 gives full debugging)");/* Why upper, left, xres, yres, depth, laced ? To match terminology used   by fbset.   Why start at 1 for left & upper coordinate ? Because X doesn't allow 0 */MODULE_PARM_DESC(osd_laced,		 "Interlaced mode\n"		 "\t\t\t0=off\n"		 "\t\t\t1=on\n"		 "\t\t\tdefault off");MODULE_PARM_DESC(osd_depth,		 "Bits per pixel - 8, 16, 32\n"		 "\t\t\tdefault 8");MODULE_PARM_DESC(osd_upper,		 "Vertical start position\n"		 "\t\t\tdefault 0 (Centered)");MODULE_PARM_DESC(osd_left,		 "Horizontal start position\n"		 "\t\t\tdefault 0 (Centered)");MODULE_PARM_DESC(osd_yres,		 "Display height\n"		 "\t\t\tdefault 480 (PAL)\n"		 "\t\t\t        400 (NTSC)");MODULE_PARM_DESC(osd_xres,		 "Display width\n"		 "\t\t\tdefault 640");MODULE_AUTHOR("Kevin Thayer, Chris Kennedy, Hans Verkuil, John Harvey, Ian Armstrong");MODULE_LICENSE("GPL");/* --------------------------------------------------------------------- */#define IVTVFB_DBGFLG_WARN  (1 << 0)#define IVTVFB_DBGFLG_INFO  (1 << 1)#define IVTVFB_DEBUG(x, type, fmt, args...) \	do { \		if ((x) & ivtvfb_debug) \			printk(KERN_INFO "ivtvfb%d " type ": " fmt, itv->num , ## args); \	} while (0)#define IVTVFB_DEBUG_WARN(fmt, args...)  IVTVFB_DEBUG(IVTVFB_DBGFLG_WARN, "warning", fmt , ## args)#define IVTVFB_DEBUG_INFO(fmt, args...)  IVTVFB_DEBUG(IVTVFB_DBGFLG_INFO, "info", fmt , ## args)/* Standard kernel messages */#define IVTVFB_ERR(fmt, args...)   printk(KERN_ERR  "ivtvfb%d: " fmt, itv->num , ## args)#define IVTVFB_WARN(fmt, args...)  printk(KERN_WARNING  "ivtvfb%d: " fmt, itv->num , ## args)#define IVTVFB_INFO(fmt, args...)  printk(KERN_INFO "ivtvfb%d: " fmt, itv->num , ## args)/* --------------------------------------------------------------------- */#define IVTV_OSD_MAX_WIDTH  720#define IVTV_OSD_MAX_HEIGHT 576#define IVTV_OSD_BPP_8      0x00#define IVTV_OSD_BPP_16_444 0x03#define IVTV_OSD_BPP_16_555 0x02#define IVTV_OSD_BPP_16_565 0x01#define IVTV_OSD_BPP_32     0x04struct osd_info {	/* Physical base address */	unsigned long video_pbase;	/* Relative base address (relative to start of decoder memory) */	u32 video_rbase;	/* Mapped base address */	volatile char __iomem *video_vbase;	/* Buffer size */	u32 video_buffer_size;#ifdef CONFIG_MTRR	/* video_base rounded down as required by hardware MTRRs */	unsigned long fb_start_aligned_physaddr;	/* video_base rounded up as required by hardware MTRRs */	unsigned long fb_end_aligned_physaddr;#endif	/* Store the buffer offset */	int set_osd_coords_x;	int set_osd_coords_y;	/* Current dimensions (NOT VISIBLE SIZE!) */	int display_width;	int display_height;	int display_byte_stride;	/* Current bits per pixel */	int bits_per_pixel;	int bytes_per_pixel;	/* Frame buffer stuff */	struct fb_info ivtvfb_info;	struct fb_var_screeninfo ivtvfb_defined;	struct fb_fix_screeninfo ivtvfb_fix;};struct ivtv_osd_coords {	unsigned long offset;	unsigned long max_offset;	int pixel_stride;	int lines;	int x;	int y;};/* --------------------------------------------------------------------- *//* ivtv API calls for framebuffer related support */static int ivtvfb_get_framebuffer(struct ivtv *itv, u32 *fbbase,				       u32 *fblength){	u32 data[CX2341X_MBOX_MAX_DATA];	int rc;	rc = ivtv_vapi_result(itv, data, CX2341X_OSD_GET_FRAMEBUFFER, 0);	*fbbase = data[0];	*fblength = data[1];	return rc;}static int ivtvfb_get_osd_coords(struct ivtv *itv,				      struct ivtv_osd_coords *osd){	struct osd_info *oi = itv->osd_info;	u32 data[CX2341X_MBOX_MAX_DATA];	ivtv_vapi_result(itv, data, CX2341X_OSD_GET_OSD_COORDS, 0);	osd->offset = data[0] - oi->video_rbase;	osd->max_offset = oi->display_width * oi->display_height * 4;	osd->pixel_stride = data[1];	osd->lines = data[2];	osd->x = data[3];	osd->y = data[4];	return 0;}static int ivtvfb_set_osd_coords(struct ivtv *itv, const struct ivtv_osd_coords *osd){	struct osd_info *oi = itv->osd_info;	oi->display_width = osd->pixel_stride;	oi->display_byte_stride = osd->pixel_stride * oi->bytes_per_pixel;	oi->set_osd_coords_x += osd->x;	oi->set_osd_coords_y = osd->y;	return ivtv_vapi(itv, CX2341X_OSD_SET_OSD_COORDS, 5,			osd->offset + oi->video_rbase,			osd->pixel_stride,			osd->lines, osd->x, osd->y);}static int ivtvfb_set_display_window(struct ivtv *itv, struct v4l2_rect *ivtv_window){	int osd_height_limit = itv->is_50hz ? 576 : 480;	/* Only fail if resolution too high, otherwise fudge the start coords. */	if ((ivtv_window->height > osd_height_limit) || (ivtv_window->width > IVTV_OSD_MAX_WIDTH))		return -EINVAL;	/* Ensure we don't exceed display limits */	if (ivtv_window->top + ivtv_window->height > osd_height_limit) {		IVTVFB_DEBUG_WARN("ivtv_ioctl_fb_set_display_window - Invalid height setting (%d, %d)\n",			ivtv_window->top, ivtv_window->height);		ivtv_window->top = osd_height_limit - ivtv_window->height;	}	if (ivtv_window->left + ivtv_window->width > IVTV_OSD_MAX_WIDTH) {		IVTVFB_DEBUG_WARN("ivtv_ioctl_fb_set_display_window - Invalid width setting (%d, %d)\n",			ivtv_window->left, ivtv_window->width);		ivtv_window->left = IVTV_OSD_MAX_WIDTH - ivtv_window->width;	}	/* Set the OSD origin */	write_reg((ivtv_window->top << 16) | ivtv_window->left, 0x02a04);	/* How much to display */	write_reg(((ivtv_window->top+ivtv_window->height) << 16) | (ivtv_window->left+ivtv_window->width), 0x02a08);	/* Pass this info back the yuv handler */	itv->yuv_info.osd_vis_w = ivtv_window->width;	itv->yuv_info.osd_vis_h = ivtv_window->height;	itv->yuv_info.osd_x_offset = ivtv_window->left;	itv->yuv_info.osd_y_offset = ivtv_window->top;	return 0;}static int ivtvfb_prep_dec_dma_to_device(struct ivtv *itv,				  unsigned long ivtv_dest_addr, void __user *userbuf,				  int size_in_bytes){	DEFINE_WAIT(wait);	int got_sig = 0;	mutex_lock(&itv->udma.lock);	/* Map User DMA */	if (ivtv_udma_setup(itv, ivtv_dest_addr, userbuf, size_in_bytes) <= 0) {		mutex_unlock(&itv->udma.lock);		IVTVFB_WARN("ivtvfb_prep_dec_dma_to_device, "			       "Error with get_user_pages: %d bytes, %d pages returned\n",			       size_in_bytes, itv->udma.page_count);		/* get_user_pages must have failed completely */		return -EIO;	}	IVTVFB_DEBUG_INFO("ivtvfb_prep_dec_dma_to_device, %d bytes, %d pages\n",		       size_in_bytes, itv->udma.page_count);	ivtv_udma_prepare(itv);	prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE);	/* if no UDMA is pending and no UDMA is in progress, then the DMA	   is finished */	while (itv->i_flags & (IVTV_F_I_UDMA_PENDING | IVTV_F_I_UDMA)) {		/* don't interrupt if the DMA is in progress but break off		   a still pending DMA. */		got_sig = signal_pending(current);		if (got_sig && test_and_clear_bit(IVTV_F_I_UDMA_PENDING, &itv->i_flags))			break;		got_sig = 0;		schedule();	}	finish_wait(&itv->dma_waitq, &wait);	/* Unmap Last DMA Xfer */	ivtv_udma_unmap(itv);	mutex_unlock(&itv->udma.lock);	if (got_sig) {		IVTV_DEBUG_INFO("User stopped OSD\n");		return -EINTR;	}	return 0;}static int ivtvfb_prep_frame(struct ivtv *itv, int cmd, void __user *source,			      unsigned long dest_offset, int count){	DEFINE_WAIT(wait);	struct osd_info *oi = itv->osd_info;	/* Nothing to do */	if (count == 0) {		IVTVFB_DEBUG_WARN("ivtvfb_prep_frame: Nothing to do. count = 0\n");		return -EINVAL;	}	/* Check Total FB Size */	if ((dest_offset + count) > oi->video_buffer_size) {		IVTVFB_WARN("ivtvfb_prep_frame: Overflowing the framebuffer %ld, only %d available\n",			dest_offset + count, oi->video_buffer_size);		return -E2BIG;	}	/* Not fatal, but will have undesirable results */	if ((unsigned long)source & 3)		IVTVFB_WARN("ivtvfb_prep_frame: Source address not 32 bit aligned (0x%08lx)\n",			(unsigned long)source);	if (dest_offset & 3)		IVTVFB_WARN("ivtvfb_prep_frame: Dest offset not 32 bit aligned (%ld)\n", dest_offset);	if (count & 3)		IVTVFB_WARN("ivtvfb_prep_frame: Count not a multiple of 4 (%d)\n", count);	/* Check Source */	if (!access_ok(VERIFY_READ, source + dest_offset, count)) {		IVTVFB_WARN("Invalid userspace pointer 0x%08lx\n",			(unsigned long)source);		IVTVFB_DEBUG_WARN("access_ok() failed for offset 0x%08lx source 0x%08lx count %d\n",			dest_offset, (unsigned long)source,			count);		return -EINVAL;	}	/* OSD Address to send DMA to */	dest_offset += IVTV_DECODER_OFFSET + oi->video_rbase;	/* Fill Buffers */	return ivtvfb_prep_dec_dma_to_device(itv, dest_offset, source, count);}#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22)static ssize_t ivtvfb_write(struct fb_info *info, const char __user *buf,						size_t count, loff_t *ppos){#elsestatic ssize_t ivtvfb_write(struct file *file, const char __user *buf,						size_t count, loff_t *ppos){	struct inode *inode = file->f_dentry->d_inode;	int fbidx = iminor(inode);	struct fb_info *info = registered_fb[fbidx];#endif	unsigned long p = *ppos;	void *dst;	int err = 0;	int dma_err;	unsigned long total_size;	struct ivtv *itv = (struct ivtv *) info->par;	unsigned long dma_offset =			IVTV_DECODER_OFFSET + itv->osd_info->video_rbase;	unsigned long dma_size;	u16 lead = 0, tail = 0;	if (info->state != FBINFO_STATE_RUNNING)		return -EPERM;	total_size = info->screen_size;	if (total_size == 0)		total_size = info->fix.smem_len;	if (p > total_size)		return -EFBIG;	if (count > total_size) {		err = -EFBIG;		count = total_size;	}	if (count + p > total_size) {		if (!err)			err = -ENOSPC;		count = total_size - p;	}	dst = (void __force *) (info->screen_base + p);	if (info->fbops->fb_sync)		info->fbops->fb_sync(info);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -