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

📄 spca5xx.c

📁 linux摄像头驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
    {USB_DEVICE(0x055f, 0xc232)},	/* Mustek MDC3500 */    {USB_DEVICE(0x046d, 0x08ac)},	/* Logitech QuickCam Cool*/    {USB_DEVICE(0x046d, 0x08d9)},	/* Logitech QuickCam IM/Connect */    {USB_DEVICE(0x046d, 0x08da)},	/* Logitech QuickCam Messenger */    {USB_DEVICE(0x0000, 0x0000)},	/* MystFromOri Unknow Camera */    {}				/* Terminating entry */};MODULE_DEVICE_TABLE(usb, device_table);/*  We also setup the function for getting  page number from the virtual address */#define VIRT_TO_PAGE virt_to_page#else				/* LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0) */#define VIRT_TO_PAGE MAP_NR#endif				/* LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0) *//* * Let's include the initialization data for each camera type */#include "spcausb.h"#include "spca500_init.h"#include "spca501_init.h"#include "spca505_init.h"#include "spca506.h"#include "spca508_init.h"#include "spca561.h"#include "sp5xxfw2.h"#include "sonix.h"#include "zc3xx.h"#include "cx11646.h"#include "tv8532.h"#include "et61xx51.h"#include "mr97311.h"#include "pac207.h"#ifdef CONFIG_PROC_FS/* Not sure what we should do with this. I think it is V4L level 2 stuff *//* Currently only use RGB24 */static struct palette_list plist[] = {    {VIDEO_PALETTE_GREY, "GREY"},    {VIDEO_PALETTE_HI240, "HI240"},    {VIDEO_PALETTE_RGB565, "RGB565"},    {VIDEO_PALETTE_RGB24, "RGB24"},    {VIDEO_PALETTE_RGB32, "RGB32"},    {VIDEO_PALETTE_RGB555, "RGB555"},    {VIDEO_PALETTE_YUV422, "YUV422"},    {VIDEO_PALETTE_YUYV, "YUYV"},    {VIDEO_PALETTE_UYVY, "UYVY"},    {VIDEO_PALETTE_YUV420, "YUV420"},    {VIDEO_PALETTE_YUV411, "YUV411"},    {VIDEO_PALETTE_RAW, "RAW"},    {VIDEO_PALETTE_YUV422P, "YUV422P"},    {VIDEO_PALETTE_YUV411P, "YUV411P"},    {VIDEO_PALETTE_YUV420P, "YUV420P"},    {VIDEO_PALETTE_YUV410P, "YUV410P"},    {VIDEO_PALETTE_RAW_JPEG, "RJPG"},    {VIDEO_PALETTE_JPEG, "JPEG"},    {-1, NULL}};#endif				/* CONFIG_PROC_FS *//* function for the tasklet */void outpict_do_tasklet(unsigned long ptr);/********************************************************************** * * Memory management * * This is a shameless copy from the USB-cpia driver (linux kernel * version 2.3.29 or so, I have no idea what this code actually does ;). * Actually it seems to be a copy of a shameless copy of the bttv-driver. * Or that is a copy of a shameless copy of ... (To the powers: is there * no generic kernel-function to do this sort of stuff?) * * Yes, it was a shameless copy from the bttv-driver. IIRC, Alan says * there will be one, but apparentely not yet -jerdfelt * * So I copied it again for the ov511 driver -claudio * And again for the spca50x driver -jcrisp **********************************************************************//* Given PGD from the address space's page table, return the kernel * virtual mapping of the physical memory mapped at ADR. */#ifndef RH9_REMAPstatic inline unsigned long uvirt_to_kva(pgd_t * pgd, unsigned long adr){    unsigned long ret = 0UL;    pmd_t *pmd;    pte_t *ptep, pte;    if (!pgd_none(*pgd)) {#if PUD_SHIFT	pud_t *pud = pud_offset(pgd, adr);	if (!pud_none(*pud)) {	    pmd = pmd_offset(pud, adr);#else	pmd = pmd_offset(pgd, adr);#endif	if (!pmd_none(*pmd)) {	    ptep = pte_offset_kernel(pmd, adr);	    pte = *ptep;	    if (pte_present(pte)) {		ret = (unsigned long) page_address(pte_page(pte));		ret |= (adr & (PAGE_SIZE - 1));	    }#if PUD_SHIFT	}#endif    }}return ret;}#endif				/* RH9_REMAP *//* Here we want the physical address of the memory. * This is used when initializing the contents of the * area and marking the pages as reserved. */#ifdef RH9_REMAPstatic 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);	/* restore the offset */    ret = __pa(kva);    return ret;}#else				/* RH9_REMAP */#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)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;}#elsestatic inline unsigned long kvirt_to_pa(unsigned long adr){    unsigned long va, kva, ret;    va = VMALLOC_VMADDR(adr);    kva = uvirt_to_kva(pgd_offset_k(va), va);    ret = __pa(kva);    return ret;}#endif#endif				/* RH9_REMAP */static void *rvmalloc(unsigned long size){    void *mem;    unsigned long adr;#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 23)    unsigned long page;#endif    size = PAGE_ALIGN(size);    mem = vmalloc_32(size);    if (!mem)	return NULL;    memset(mem, 0, size);	/* Clear the ram out, no junk to the user */    adr = (unsigned long) mem;    while ((long) size > 0) {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 68)	SetPageReserved(vmalloc_to_page((void *) adr));#else#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 23)	mem_map_reserve(vmalloc_to_page((void *) adr));#else	page = kvirt_to_pa(adr);	mem_map_reserve(VIRT_TO_PAGE(__va(page)));#endif#endif	adr += PAGE_SIZE;	size -= PAGE_SIZE;    }    return mem;}static void rvfree(void *mem, unsigned long size){    unsigned long adr;#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 23)    unsigned long page;#endif    if (!mem)	return;    adr = (unsigned long) mem;    while ((long) size > 0) {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 68)	ClearPageReserved(vmalloc_to_page((void *) adr));#else#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 23)	mem_map_unreserve(vmalloc_to_page((void *) adr));#else	page = kvirt_to_pa(adr);	mem_map_unreserve(VIRT_TO_PAGE(__va(page)));#endif#endif	adr += PAGE_SIZE;	size -= PAGE_SIZE;    }    vfree(mem);}/********************************************************************** * /proc interface * Based on the CPiA driver version 0.7.4 -claudio * ..and again copied from the ov511 driver for the SPCA50x driver - jac **********************************************************************/#ifdef CONFIG_PROC_FSstatic struct proc_dir_entry *spca50x_proc_entry = NULL;#ifdef CONFIG_VIDEO_PROC_FSextern struct proc_dir_entry *video_proc_entry;#endif				/* CONFIG_VIDEO_PROC_FS */#define YES_NO(x) ((x) ? "yes" : "no")static intspca50x_read_proc(char *page, char **start, off_t off,		  int count, int *eof, void *data){    char *out = page;    int i, j, len;    struct usb_spca50x *spca50x = data;    /* IMPORTANT: This output MUST be kept under PAGE_SIZE     *            or we need to get more sophisticated. */    out += sprintf(out, "driver          : SPCA5XX USB Camera\n");    out += sprintf(out, "driver_version  : %s\n", version);    out += sprintf(out, "model           : %s\n", (spca50x->desc) ?		   clist[spca50x->desc].description : "unknown");    out +=	sprintf(out, "streaming       : %s\n", YES_NO(spca50x->streaming));    out +=	sprintf(out, "grabbing        : %s\n", YES_NO(spca50x->grabbing));    out +=	sprintf(out, "compress        : %s\n", YES_NO(spca50x->compress));    out +=	sprintf(out, "data_format     : %s\n",		spca50x->force_rgb ? "RGB" : "BGR");    out +=	sprintf(out, "brightness      : %d\n", spca50x->brightness >> 8);    out += sprintf(out, "colour          : %d\n", spca50x->colour >> 8);    out += sprintf(out, "hue             : %d\n", spca50x->hue >> 8);    out += sprintf(out, "contrast        : %d\n", spca50x->contrast);    out += sprintf(out, "num_frames      : %d\n", SPCA50X_NUMFRAMES);    out += sprintf(out, "curframe        : %d\n", spca50x->curframe);    out += sprintf(out, "lastFrameRead   : %d\n", spca50x->lastFrameRead);//    spca50x->avg_lum = get_avg_lum(spca50x);//    out += sprintf(out, "Avg. luminance  : 0x%X %d\n",//		   spca50x->avg_lum, spca50x->avg_lum);    for (i = 0; i < SPCA50X_NUMFRAMES; i++) {	out += sprintf(out, "frame           : %d\n", i);	out +=	    sprintf(out, "  sequence      : %d\n", spca50x->frame[i].seq);	out +=	    sprintf(out, "  grabstate     : %d\n",		    spca50x->frame[i].grabstate);	out +=	    sprintf(out, "  depth         : %d\n",		    spca50x->frame[i].depth);	out +=	    sprintf(out, "  size          : %d %d\n",		    spca50x->frame[i].width, spca50x->frame[i].height);	out += sprintf(out, "  format        : ");	for (j = 0; plist[j].num >= 0; j++) {	    if (plist[j].num == spca50x->frame[i].format) {		out += sprintf(out, "%s\n", plist[j].name);		break;	    }	}	if (plist[j].num < 0)	    out += sprintf(out, "unknown\n");	out += sprintf(out, "  data_buffer   : 0x%p\n",		       spca50x->frame[i].data);    }    out += sprintf(out, "packet_size     : %d\n", spca50x->packet_size);    out += sprintf(out, "framebuffer     : 0x%p\n", spca50x->fbuf);    len = out - page;    len -= off;    if (len < count) {	*eof = 1;	if (len <= 0)	    return 0;    } else	len = count;    *start = page + off;    return len;}static intspca50x_write_proc(struct file *file, const char *buffer,		   unsigned long count, void *data){    return -EINVAL;}/* * Function services read requests to control proc entry * and prints all the static variables */static intspca50x_ctlread_proc(char *page, char **start, off_t off,		     int count, int *eof, void *data){    char *out = page;    int len = 0;    struct usb_spca50x *spca50x = data;    out += sprintf(out, "force_rgb = %d\n", spca50x->force_rgb);    out += sprintf(out, "min_bpp = %d\n", spca50x->min_bpp);    out += sprintf(out, "lum_level = %d\n", spca50x->lum_level);    out += sprintf(out, "debug = %d\n", debug);    len = out - page;    len -= off;    if (len < count) {	*eof = 1;	if (len <= 0)	    return 0;    } else	len = count;    *start = page + off;    return len;}/* * Function compares two strings. * Return offset in pussy where prick ends if "prick" may penetrate  * int "pussy" like prick into pussy, -1 otherwise. */static inline int match(const char *prick, const char *pussy, int len2){    int len1 = strlen(prick);	//length of male string    int i;			//just an index variable    const char *tmp;		//temporary pointer for my own pleasure    // We skip all spaces and tabs    for (i = 0; i < len2 && (pussy[i] == ' ' || pussy[i] == '\t'); i++) {    }    tmp = pussy + i;		// pointer to pussy with skipped shit (spaces and tabs)    len2 = strlen(tmp);		//calculate length again    if (len1 > len2)	return -1;		//Fuck off, no fucking    if (!strncmp(prick, tmp, len1))	return i + len1;    return -1;}/* * Try to calculate value from string (atoi). Converts   * decimal integer */static inline int atoi(const char *str){    int result = 0;		//result of the function    int i;			//just an index variable    for (i = 0; str[i] >= '0' && str[i] <= '9'; i++) {	result *= 10;	result += str[i] - '0';    }    return result;}static intspca50x_ctlwrite_proc(struct file *file, const char *buffer,		      unsigned long count, void *data){    int off;			//where look for a value    struct usb_spca50x *spca50x = data;    if ((off = match("lum_level=", buffer, count)) >= 0)	spca50x->lum_level = atoi(buffer + off);    if ((off = match("min_bpp=", buffer, count)) >= 0)	spca50x->min_bpp = atoi(buffer + off);    if ((off = match("force_rgb=", buffer, count)) >= 0)	spca50x->force_rgb = atoi(buffer + off);    if ((off = match("debug=", buffer, count)) >= 0)	debug = atoi(buffer + off);    return count;

⌨️ 快捷键说明

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