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

📄 spca50x.c

📁 广州斯道2410普及版II的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
 * 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)) {		pmd = pmd_offset(pgd, adr);		if (!pmd_none(*pmd)) {			/* WOLT kernels appear to have changed pte_offset to pte_offset_kernel */#ifdef pte_offset					ptep = pte_offset(pmd, adr);#else /* pte_offset */			ptep = pte_offset_kernel(pmd, adr);#endif /* pte_offset */			pte = *ptep;			if (pte_present(pte)) {				ret = (unsigned long) page_address(pte_page(pte));				ret |= (adr & (PAGE_SIZE - 1));			}		}	}	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 longkvirt_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;}#else static 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;	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		mem_map_reserve(vmalloc_to_page((void *)adr));#endif		adr += PAGE_SIZE;		size -= PAGE_SIZE;	}																	  	return mem;}static voidrvfree(void *mem, unsigned long size){	unsigned long adr;	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		mem_map_unreserve(vmalloc_to_page((void *)adr));#endif		adr += PAGE_SIZE;		size -= PAGE_SIZE;	}	vfree(mem);}/********************************************************************** * Get average luminance **********************************************************************/static inline __u8 get_avg_lum(struct usb_spca50x *spca50x){	__u8 luminance; //The average luminance from camera	switch(spca50x->bridge)	{		case BRIDGE_SPCA501:			luminance = spca50x_reg_read(spca50x->dev, SPCA501_REG_CCDSP, 				0x26, 2) >> 8;			break;#ifdef SPCA50X_ENABLE_EXP_BRIGHTNESS		case BRIDGE_SPCA561:                case BRIDGE_SPCA508:                        luminance = spca50x_reg_read(spca50x->dev, 0, 0x8621, 1);                        break;#endif /* SPCA50X_ENABLE_EXP_BRIGHTNESS */		default:			luminance = 0;			break;	}	return luminance;}/********************************************************************** * Get average R-G and B-G **********************************************************************/static inline __u8 get_avg_RG(struct usb_spca50x *spca50x){	__u8 rg; //The average R-G for window5	switch(spca50x->bridge)	{		case BRIDGE_SPCA501:			rg = spca50x_reg_read(spca50x->dev, SPCA501_REG_CCDSP, 0x30, 				2) >> 8;			break;		default:			rg = 0;			break;	}	return rg;}/********************************************************************** * Get average B-G **********************************************************************/static inline __u8 get_avg_BG(struct usb_spca50x *spca50x){	__u8 bg; //The average B-G for window5	switch(spca50x->bridge)	{		case BRIDGE_SPCA501:			bg = spca50x_reg_read(spca50x->dev, SPCA501_REG_CCDSP, 0x2f, 				2) >> 8;			break;		default:			bg = 0;			break;	}	return bg;}/********************************************************************** * /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 int spca50x_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          : SPCA50X 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, "snap_enabled    : %s\n", YES_NO (spca50x->snap_enabled));	out += sprintf (out, "packet_size     : %d\n", spca50x->packet_size);	out += sprintf (out, "internal ccd    : %s\n", YES_NO (!spca50x->ccd));	out += sprintf (out, "framebuffer     : 0x%p\n", spca50x->fbuf);#ifdef SPCA50X_ENABLE_EXPERIMENTAL	out += sprintf (out, "stable          : %d\n", spca50x->nstable);	out += sprintf (out, "unstable        : %d\n", spca50x->nunstable);	out += sprintf (out, "whiteness       : %d\n", spca50x->whiteness >> 12);	spca50x->avg_rg = get_avg_RG(spca50x);	spca50x->avg_bg = get_avg_BG(spca50x);	out += sprintf (out, "Avg. R-G/B-G  : 0x%X/0x%X %d/%d\n", 	                     spca50x->avg_rg, spca50x->avg_bg, 	                     (char)spca50x->avg_rg, (char)spca50x->avg_bg);#endif /* SPCA50X_ENABLE_EXPERIMENTAL */	len = out - page;	len -= off;	if (len < count) {		*eof = 1;		if (len <= 0) 			return 0;	} else		len = count;	*start = page + off;	return len;}static int spca50x_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 int spca50x_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);#ifdef SPCA50X_ENABLE_OSD	out += sprintf(out, "osd = %d\n", osd);#endif /* SPCA50X_ENABLE_OSD */	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;}#ifdef SPCA50X_ENABLE_RAWPROCENTRYstatic int spca50x_rawread_proc(char  *page,                                char **start,                                off_t  off,                                int    count,                                int   *eof,                                void  *data){	struct usb_spca50x *spca50x = data;	*start = page;	/* check whether the buffer exists */	if (spca50x->rawBuffer == NULL)	{		*eof = 1;		return 0;	}	/* check offset is valid */	if (off > spca50x->rawBufferSize)	{		*eof = 1;		return 0;	}	/* can't read more than exists in the buffer, either */	if ((count+off) > spca50x->rawBufferSize)	{		count = spca50x->rawBufferSize - off;	}	/* can't read more than is available in the output buffer */	if (count > PAGE_SIZE)	{		count = PAGE_SIZE;	}	if (count == 0)	{		*eof = 1;		return 0;	}	/* populate the output buffer */	memcpy(page, spca50x->rawBuffer + off, count);	/* return read count */	return count;}static int spca50x_rawwrite_proc(struct file  *file,                                 const char   *buffer,                                 unsigned long count,                                 void         *data){	struct usb_spca50x *spca50x = data;	/* if anything is written, flush the buffer */	PDEBUG(3, "flushed raw proc entry buffer");	spca50x->rawBufferSize = 0;	return count;}#endif /* SPCA50X_ENABLE_RAWPROCENTRY *//* * 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

⌨️ 快捷键说明

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