📄 spca5xx.c
字号:
{176, 144, 0x10, 0x94, 0x104A, 896}, {160, 120, 0, 0x94, 0x204A, 384}, {0, 0, 0, 0, 0}};/* default value used for spca505 and spca505b */static __u16 spca50x_ext_modes[][6] = { /* x , y , Code, Value (6), Value (7), pipe */ {640, 480, 0, 0x10, 0x10, 1023}, /* Tested spca505b+VGA sensor */ {352, 288, 1, 0x1a, 0x1a, 1023}, /* Tested */ {320, 240, 2, 0x1c, 0x1d, 896}, /* Tested 20:01:2004 */ {176, 144, 4, 0x34, 0x34, 512}, /* Tested */ {160, 120, 5, 0x40, 0x40, 384}, /* Tested */ {0, 0, 0, 0, 0}};static __u16 spca506_ext_modes[][6] = { /* In this table, element 3 (clk) controls the * clock, and gets written to 0x8700. */ /* x , y , Code, clk, n/a, pipe */ {640, 480, 0x00, 0x10, 0x10, 1023}, {352, 288, 0x01, 0x1a, 0x1a, 1023}, {320, 240, 0x02, 0x1c, 0x1c, 1023}, //896 {176, 144, 0x04, 0x34, 0x34, 1023}, {160, 120, 0x05, 0x40, 0x40, 1023}, {0, 0, 0, 0, 0}};// 1a 1b 20 static __u16 spca508_ext_modes[][6] = { /* In this table, element 3 (clk) controls the * clock, and gets written to 0x8700. */ /* x , y , Code, clk, n/a, pipe */ {352, 288, 0x00, 0x28, 0x00, 1023}, {320, 240, 0x01, 0x28, 0x00, 1023}, {176, 144, 0x02, 0x23, 0x00, 1023}, {160, 120, 0x03, 0x23, 0x00, 1023}, {0, 0, 0, 0, 0}};static __u16 tv8532_ext_modes[][6] = { /* x , y , Code, clk, n/a, pipe */ {352, 288, 0x00, 0x28, 0x00, 1023}, {320, 240, 0x10, 0x28, 0x00, 1023}, {176, 144, 0x01, 0x23, 0x00, 1023}, /*{160, 120, 0x03, 0x23, 0x00, 1023}, */ {0, 0, 0, 0, 0}};#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. *//* 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. */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); /* restore the offset */ 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); /* Clear the ram out, no junk to the user */ adr = (unsigned long) mem; while ((long) size > 0) { mem_map_reserve(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) { mem_map_unreserve(vmalloc_to_page((void *) adr)); 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);#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 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;}static void create_proc_spca50x_cam(struct usb_spca50x *spca50x){ char name[PROC_NAME_LEN]; struct proc_dir_entry *ent; if (!spca50x_proc_entry || !spca50x) return;//Create videoxx proc entry sprintf(name, "video%d", spca50x->vdev->minor); PDEBUG(4, "creating /proc/video/spca50x/%s", name); ent = create_proc_entry(name, S_IFREG | S_IRUGO | S_IWUSR, spca50x_proc_entry); if (!ent) return; ent->data = spca50x; ent->read_proc = spca50x_read_proc; ent->write_proc = spca50x_write_proc; spca50x->proc_entry = ent;// Create the controlxx proc entry sprintf(name, "control%d", spca50x->vdev->minor); PDEBUG(4, "creating /proc/video/spca50x/%s", name); ent = create_proc_entry(name, S_IFREG | S_IRUGO | S_IWUSR, spca50x_proc_entry); if (!ent) return; ent->data = spca50x; ent->read_proc = spca50x_ctlread_proc; ent->write_proc = spca50x_ctlwrite_proc; spca50x->ctl_proc_entry = ent;}static void destroy_proc_spca50x_cam(struct usb_spca50x *spca50x){ char name[PROC_NAME_LEN]; if (!spca50x || !spca50x_proc_entry) return; /* destroy videoxx proc entry */ if (spca50x->proc_entry != NULL) { sprintf(name, "video%d", spca50x->vdev->minor);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -