/*
*
* Connectix USB QuickCam VC Video Camera driver
*
* Copyright 2001 De Marchi Daniele
* Copyright 2004 Terry Mohan
* Copyright 2005 Troy Rollo
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Jan 2001 This driver develop started on the linux
* kernel 2.4.0.
*
*/
#include <linux/config.h>
#include <linux/version.h>
#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0))
#include <linux/wrapper.h>
#endif
#ifdef CONFIG_KMOD
#include <linux/kmod.h>
#endif
#include <linux/proc_fs.h>
#include <linux/vmalloc.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/ctype.h>
#include <linux/parport.h>
#include <linux/delay.h>
#include "qcamvc.h"
//*#define _QCAMVC_DEBUG_
//#define CONFIG_VIDEO_QCAMVC_PP_MODULE
//#undef CONFIG_PROC_FS
static int video_nr = -1;
#ifdef MODULE
MODULE_PARM(video_nr,"i");
MODULE_AUTHOR("De Marchi Daniele <[email protected]>");
MODULE_DESCRIPTION("V4L-driver for QuickCam VC cameras");
MODULE_LICENSE("GPL");
MODULE_SUPPORTED_DEVICE("video");
#endif
#ifdef CONFIG_VIDEO_QCAMVC_PP
extern int qcamvc_pp_init(void);
#endif
#ifdef CONFIG_VIDEO_QCAMVC_USB
extern int qcamvc_usb_init(void);
#endif
static int qcamvc_vopen(struct inode *inode, struct file *file);
static int qcamvc_vrelease(struct inode *inode, struct file *file);
static int qcamvc_vioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
static ssize_t qcamvc_vread(struct file *file, char *data, size_t count, loff_t *ppos);
static int qcamvc_vmmap(struct file *file, struct vm_area_struct *vma);
static int qcamvc_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *arg);
static void qcamvc_parse(struct qcamvc_data *qcamvc, unsigned char *outbuf);
static int qcamvc_camera_init(struct qcamvc_data *qcamvc);
static struct file_operations qcamvc_fops =
{
.owner = THIS_MODULE,
.open = qcamvc_vopen,
.release = qcamvc_vrelease,
.ioctl = qcamvc_vioctl,
.llseek = no_llseek,
.read = qcamvc_vread,
.mmap = qcamvc_vmmap,
};
static struct video_device qcamvc_template =
{
.name = "UNSET",
.type = VID_TYPE_CAPTURE,
.hardware = VID_HARDWARE_QCAM_C,
.fops = &qcamvc_fops,
.minor = -1,
};
#if LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,10)
/* For kernel 2.6.10 and above -- Vikram */
int remap_pfn_range(struct vm_area_struct *vma, unsigned long uvaddr,
unsigned long pfn, unsigned long size, pgprot_t prot);
static inline int remap_page_range(struct vm_area_struct *vma,
unsigned long uvaddr,
unsigned long paddr,
unsigned long size, pgprot_t prot)
{
return remap_pfn_range(vma, uvaddr, paddr >> PAGE_SHIFT, size, prot);
}
#endif
/**********************************************************************
*
* Memory management
*
**********************************************************************/
/* Here we want the physical address of the memory.
* This is used when initializing the contents of the area.
*/
static inline unsigned long kvirt_to_pa(unsigned long adr)
{
unsigned long kva, ret;
kva = (unsigned long) page_address(vmalloc_to_page((void *)adr));
kva |= adr & (PAGE_SIZE-1);
ret = __pa(kva);
return ret;
}
static void *rvmalloc(unsigned long size)
{
void *mem;
unsigned long adr;
size = PAGE_ALIGN(size);
mem = vmalloc_32(size);
if (!mem)
return NULL;
memset(mem, 0, size);
adr = (unsigned long) mem;
while (size > 0) {
SetPageReserved(vmalloc_to_page((void *)adr));
adr += PAGE_SIZE;
size -= PAGE_SIZE;
}
return mem;
}
static void rvfree(void *mem, unsigned long size)
{
unsigned long adr;
if (!mem)
return;
adr = (unsigned long) mem;
while ((long) size > 0) {
ClearPageReserved(vmalloc_to_page((void *)adr));
adr += PAGE_SIZE;
size -= PAGE_SIZE;
}
vfree(mem);
}
static inline int allocate_raw_frame(struct qcamvc_data *qcamvc)
{
if (!qcamvc)
return -EFAULT;
if (!qcamvc->raw_frame)
{
qcamvc->raw_frame = kmalloc(MAX_RAW_IMAGE_SIZE, GFP_KERNEL);
if (!qcamvc->raw_frame)
return -ENOBUFS;
}
/*if ( (qcamvc->bpc == 6) && !qcamvc->raw_frame_temp )
{
qcamvc->raw_frame_temp = kmalloc(MAX_RAW_IMAGE_SIZE, GFP_KERNEL);
if (!qcamvc->raw_frame_temp)
return -ENOBUFS;
}*/
return 0;
}
static void free_raw_frame(struct qcamvc_data *qcamvc)
{
if (!qcamvc) return;
if (qcamvc->raw_frame)
{
kfree(qcamvc->raw_frame);
qcamvc->raw_frame = NULL;
}
/*if (qcamvc->raw_frame_temp)
{
kfree(qcamvc->raw_frame_temp);
qcamvc->raw_frame_temp = NULL;
}*/
}
static inline int allocate_frame_buf(struct qcamvc_data *qcamvc)
{
if (!qcamvc) return -EFAULT;
if (qcamvc->frame_buf) return 0; //already allocated
/* tries to allocate all the memory needed for frame buffers */
qcamvc->frame_buf = rvmalloc(QCAMVC_NUMFRAMES * MAX_FRAME_SIZE);
if (!qcamvc->frame_buf)
return -ENOBUFS;
int i;
for (i = 0; i < QCAMVC_NUMFRAMES; i++)
{
/* stores the starting addresses of each frame buffer in the
qcamvc->frame_buf */
qcamvc->frame[i].data = qcamvc->frame_buf + i * MAX_FRAME_SIZE;
qcamvc->frame[i].state = FRAME_READY;
}
return 0;
}
static void free_frame_buf(struct qcamvc_data *qcamvc)
{
if (!qcamvc) return;
if (qcamvc->frame_buf)
{
rvfree(qcamvc->frame_buf, QCAMVC_NUMFRAMES * MAX_FRAME_SIZE);
qcamvc->frame_buf = NULL;
}
int i;
for (i=0; i < QCAMVC_NUMFRAMES; i++)
{
qcamvc->frame[i].state = FRAME_UNUSED;
qcamvc->frame[i].data = NULL;
}
}
/**********************************************************************
*
* Camera Address Read/Write helpers
*
**********************************************************************/
static int get_register(struct qcamvc_data *qcamvc, unsigned char reg, unsigned char *buf)
{
if (!qcamvc || !qcamvc->ops || !buf) return -1;
if (qcamvc->ops->qcamvc_get_reg(qcamvc->lowlevel_data, reg, buf, 1) != 1)
return -1;
return 0;
}
static int set_register(struct qcamvc_data *qcamvc, unsigned char reg, unsigned char buf)
{
if (!qcamvc || !qcamvc->ops) return -1;
if (qcamvc->ops->qcamvc_set_reg(qcamvc->lowlevel_data, reg, &buf, 1) != 1)
return -1;
return 0;
}
static int set_registers(struct qcamvc_data *qcamvc, unsigned char reg, unsigned char *buf, size_t size)
{
if (!qcamvc || !qcamvc->ops || !buf) return -1;
if (qcamvc->ops->qcamvc_set_reg(qcamvc->lowlevel_data, reg, buf, size) != size)
return -1;
return 0;
}
/**********************************************************************
*
* Image Grabbing
*
**********************************************************************/
static int send_grab_image(struct qcamvc_data *qcamvc, int new_frame)
{
if (new_frame)
qcamvc->frame_count++; /*fresh frame */
if (set_register(qcamvc, QCAM_VC_GET_FRAME, qcamvc->frame_count))
return -ENODEV;
return 0;
}
/* interrogate the camera every 10ms while waiting for an image to be ready. */
/* return 0 not ready, or >0 ready */
static int frame_is_ready(struct qcamvc_data *qcamvc)
{
#if 0
if (!qcamvc) return 0;
struct qcamvc_misc misc = {0};
int attempt = 200; /* 2 second timeout should be plenty */
/* send grab frame command with current frame count */
if (send_grab_image(qcamvc, 0))
return 0;
do
{
if (!get_register(qcamvc, QCAM_VC_SET_MISC, (unsig
没有合适的资源?快使用搜索试试~ 我知道了~
quickcam-vc-1.0.8-test.tar.gz_linux
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 31 浏览量
2022-09-24
12:37:04
上传
评论
收藏 69KB GZ 举报
温馨提示
共17个文件
c:4个
contents:2个
h:1个
VC编写的USB QuickCam驱动程序,实现四种视频格式在linux下的编码,信号来自摄像源
资源推荐
资源详情
资源评论
收起资源包目录
quickcam-vc-1.0.8-test.tar.gz (17个子文件)
qcamvc-1.0.8-test
TODO 618B
CHANGES 3KB
linux_2.6
qcamvc.h 9KB
qcamvc.c 59KB
CONTENTS 261B
qcamvc_pp.c 26KB
Makefile 2KB
qcamvc_usb.c 15KB
README 13KB
INSTALL 3KB
linux_2.4
patch-linux-2.4.22-qcamvc-1.0.6 84KB
utils
qcvc-restore-settings 436B
qcvc-save-settings 565B
qcvc-init 223B
contrib
qcamvc.c 44KB
CONTENTS 169B
COPYING 18KB
共 17 条
- 1
资源评论
weixin_42653672
- 粉丝: 93
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功