?? winbond_9967cf.c
字號:
/* * * Totally unofficial, unsupported and non-working version. * * USB-Video4Linux driver for the Winbond W9967CF and W9968CF webcam IC's * video streaming capabilities. The latter chip is used by the `Creative * Webcam Go' and `Creative Webcam Go Plus' webcam/digital camera. * * (c) 2000 by Bart Alewijnse scarfboy@yahoo.com * Raffaele Spangaro keatch@f2s.com * * Started off by Bart Alewijnse, scarfboy@yahoo.com * Raffaele Spangaro, keatch@f2s.com * * <Other thanks goes here> * * For help or questions, see linux/Documentation/usb/winbond.txt * (check/correct when we actually make it) * or the project documentation/link to it on SourceForge. * (http://www.sourceforge.net/projects/winbond-webcam) * * Based on the Linux CPiA driver written by Peter Pregler, Scott J. Bertin * and Johannes Erdfelt. * * 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. * */#include <linux/config.h>#include <linux/module.h>#include <linux/version.h>#include <linux/init.h>#include <linux/fs.h>#include <linux/vmalloc.h>#include <linux/slab.h>#include <linux/proc_fs.h>#include <linux/ctype.h>#include <linux/pagemap.h>#include <linux/usb.h>#include <asm/io.h>#include <asm/semaphore.h>#include <linux/wrapper.h>#include "winbond_9967cf.h"#define __NO_VERSION__#define IMG_ALLOC_BUF 355*288*2#define TRANSFER_BUF_SIZE 1023/* Both Vendor/Product ID's that we know means a w9967cf or w9968cf */static __devinitdata struct usb_device_id device_table [] = { { idVendor: 0x041e, idProduct: 0x4003 }, /* WebCam Go Plus */ { idVendor: 0x1046, idProduct: 0x9967 }, /* Webcam Go, w9967cf and */ { } /* other regular w9967cf/w9968cf based cams */};MODULE_DEVICE_TABLE (usb, device_table);/*** This code is a shameless copy from ibmcam.c. Some shortened a bit (line-wise). ***/static 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)) { ptep = pte_offset(pmd, adr); pte = *ptep; if (pte_present(pte)) { ret = (unsigned long) page_address(pte_page(pte)); ret |= (adr & (PAGE_SIZE - 1)); } } } return ret;}static inline unsigned long uvirt_to_bus(unsigned long adr){ return virt_to_bus((void *)uvirt_to_kva( pgd_offset(current->mm, adr), adr) );}static inline unsigned long kvirt_to_bus(unsigned long adr){ unsigned long va; va = VMALLOC_VMADDR(adr); return virt_to_bus((void *)uvirt_to_kva(pgd_offset_k(va), va));}static inline unsigned long kvirt_to_pa(unsigned long adr){ unsigned long va; va = VMALLOC_VMADDR(adr); return __pa(uvirt_to_kva(pgd_offset_k(va), va));}static void *rvmalloc(unsigned long size){ void *mem; unsigned long adr; /* Round it off to PAGE_SIZE */ size += (PAGE_SIZE - 1); size &= ~(PAGE_SIZE - 1); 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 (size > 0) { mem_map_reserve(virt_to_page(__va(kvirt_to_pa(adr)))); adr += PAGE_SIZE; if (size > PAGE_SIZE) size -= PAGE_SIZE; else size = 0; } return mem;}static void rvfree(void *mem, unsigned long size){ unsigned long adr, page; if (!mem) return; size += (PAGE_SIZE - 1); size &= ~(PAGE_SIZE - 1); adr=(unsigned long) mem; while (size > 0) { page = kvirt_to_pa(adr); mem_map_unreserve(virt_to_page(__va(page))); adr += PAGE_SIZE; if (size > PAGE_SIZE) size -= PAGE_SIZE; else size = 0; } vfree(mem);}/* End of shameless copy :) *//* * Vendor specific functions; gets and sets the registers of both chips *//* Register get */static short w9967cf_reg_get(struct usb_device *mydev, short reg_index, short* buffer){ int ret; unsigned short ri = (unsigned short) reg_index; ret=usb_control_msg(mydev, usb_rcvctrlpipe(mydev, 0), GET_W9967CF_CONTROL,USB_DIR_IN | USB_TYPE_VENDOR, 0, ri, (short *)buffer,/* value, index, data */ 2, 5*HZ /* length, timeout */ ); if (!ret) printk("w9967cf driver: reg_get failed, index 0x%02X,ret=%d\n", (unsigned short)reg_index,ret); return ret;}/* Register set */static short w9967cf_reg_set(struct usb_device *mydev, short reg_index, short reg_value){ int ret; ret=usb_control_msg(mydev, usb_sndctrlpipe(mydev, 0), SET_W9967CF_CONTROL, USB_DIR_OUT | USB_TYPE_VENDOR, reg_value, reg_index, NULL, 0, 5*HZ ); if (ret) printk("w9967cf driver: reg_set failed, index %02X, value"\ " %04X \n",reg_index, reg_value); return ret;}/* Set the specified bit to the desidered value ... */static short w9967cf_set_bit(struct usb_device *mydev, short reg_index, short bit_num, short bit_value) { short value; short mask; if(w9967cf_reg_get(mydev,reg_index,&value)<0) return -1; mask = (1<<bit_num); // info("mask=%x",mask); if (bit_value == 1) { if ((w9967cf_reg_set(mydev,reg_index,value|mask)<0)) { info("Error set_bit 1 reg=%x,value=%x,mask=%x,bitnum=%x", reg_index,value,mask,bit_num); } } else { if ((w9967cf_reg_set(mydev,reg_index,value&(~mask))<0)) { info("Error set_bit 0 reg=%x,value=%x,mask=%x,bitnum=%x", reg_index,value,mask,bit_num); } } return 1;}/* Make a register dump in a determinarted range */static void w9967cf_dump_regs(struct usb_device *mydev, short start_index, short end_index) { short reg_value=0; int i; info("Dumping register from %d to %d",start_index,end_index); for(i=start_index;i<=end_index;i++) { w9967cf_reg_get(mydev,i,®_value); info("Reg %2x: %x",i,reg_value); reg_value=0; } }/* This function is used when read is called !!!. TO do Work in progress. No locks. When called the isoc function should be called !!!*/static long w9967cf_read(struct video_device *dev, char *buf, unsigned long count, int noblock){ w9967cfcam *cam = (w9967cfcam *)dev; short reg_value; int i; w9967cf_reg_set(cam->dev, 0x10, 0x009d); w9967cf_reg_set(cam->dev, 0x12, 0x01dd); w9967cf_reg_set(cam->dev, 0x11, 0x0010); w9967cf_reg_set(cam->dev, 0x13, 0x0100); w9967cf_reg_set(cam->dev, 0x20, 0x1000); w9967cf_reg_set(cam->dev, 0x21, 0x0000); w9967cf_reg_set(cam->dev, 0x22, 0x0100); w9967cf_reg_set(cam->dev, 0x23, 0x0001); w9967cf_reg_set(cam->dev, 0x24, 0xa600); w9967cf_reg_set(cam->dev, 0x25, 0x0000); w9967cf_reg_set(cam->dev, 0x2c, 0x00a0); w9967cf_reg_set(cam->dev, 0x2d, 0x0050); w9967cf_reg_set(cam->dev, 0x00, 0xbf10); w9967cf_reg_set(cam->dev, 0x01, 0x0023); w9967cf_reg_set(cam->dev, 0x16, 0x8000); w9967cf_reg_set(cam->dev, 0x3c, 0x8a05); schedule_timeout(1 + 1200 * HZ / 1000); copy_to_user(buf, cam->fbuf, 355*255); w9967cf_dump_regs(cam->dev,0x0,0x16); w9967cf_dump_regs(cam->dev,0x30,0x3c); return 0;}/* Init the chip Set only the default values for capturing and enable FIFO USB Could be rewritten partially. Not yet implemented at all.*/static int w9967cf_init_chip(w9967cfcam *cam) { //short reg_value; info("Init chip!!!"); /* Clipping window and default size *//* if(w9967cf_reg_set(cam->dev, W9967_CROP_START_X, 0x009d)<0) return -1; *//* if(w9967cf_reg_set(cam->dev, W9967_CROP_START_Y, 0x0010)<0) return -1; *//* if(w9967cf_reg_set(cam->dev, W9967_CROP_END_X, 0x01dd)<0) *//* return -1; *//* if(w9967cf_reg_set(cam->dev, W9967_CROP_END_Y, 0x0100)<0) *//* return -1; *//* if(w9967cf_reg_set(cam->dev, W9967_CAPTURE_WIDTH, 0x140)<0) *//* return -1; *//* if(w9967cf_reg_set(cam->dev, W9967_CAPTURE_HEIGHT, 0xf0)<0) *//* return -1; */ info("Init chip done!!"); return 0;}/* * Video4Linux interface */static int w9967cf_ioctl(struct video_device *vdev,unsigned int cmd,void *arg){ w9967cfcam *cam = (w9967cfcam *)vdev; switch (cmd) { case VIDIOCGCAP: /* Video Capability */ { struct video_capability capab; capab.type = VID_TYPE_CAPTURE; /* Captures to memory */ capab.channels = 1; capab.audios = 0; capab.minwidth = 128; capab.minheight = 96; capab.maxwidth = 640; capab.maxheight = 480; /* See the question. No problem for me. */ strcpy(capab.name, "Webcam Go (W996[78]CF)"); if(copy_to_user(arg, &capab, sizeof(capab))) return -EFAULT; return 0; } case VIDIOCGCHAN: /* Channel Info */ { struct video_channel c; if(copy_from_user(&c, arg, sizeof(c))) return -EFAULT; if (c.channel !=0) return -EINVAL; c.flags = 0; c.tuners = 0; c.type = VIDEO_TYPE_CAMERA; c.norm = VIDEO_MODE_AUTO; strcpy(c.name, "Webcam Go (W996[78]CF)"); if(copy_to_user(arg, &c, sizeof(c))) return -EFAULT; return 0; } case VIDIOCSCHAN: /* Set Active Channel */ { struct video_channel chan; if (copy_from_user(&chan, arg, sizeof(chan))) return -EFAULT; if (chan.channel != 0) return -EINVAL; return 0; } case VIDIOCGPICT: /* Get Picture Adjustment*/ { struct video_picture p; p.brightness = cam->brightness; p.hue = cam->hue; p.colour = cam->colour; p.contrast = cam->contrast; p.whiteness = cam->whiteness; p.depth = 24; switch (cam->ctrlreg.vid_dataformat ) { case W9967CF_YUV422_PACKED: p.palette = VIDEO_PALETTE_YUV422; break; case W9967CF_YUV422_PLANAR: p.palette = VIDEO_PALETTE_YUV422P; break; case W9967CF_YUV420_PACKED: p.palette = VIDEO_PALETTE_YUV420; break; case W9967CF_YUV420_PLANAR: p.palette = VIDEO_PALETTE_YUV420P; break; default: { printk("w9967cf driver: No valid palette"\ " (VIDIOCGPICT), report this please\n"); return -EFAULT; p.palette = VIDEO_PALETTE_YUV422; } } if(copy_to_user(arg, &p, sizeof(p))) return -EFAULT; return 0; } case VIDIOCSPICT: /* Set Picture Settings */ { struct video_picture v; if(copy_from_user(&v, arg, sizeof(v))) return -EFAULT; cam->frame_depth = v.depth; switch (v.palette) { case VIDEO_PALETTE_GREY: { cam->ctrlreg.vid_dataformat = VIDEO_PALETTE_GREY; } case VIDEO_PALETTE_RGB24: { cam->ctrlreg.vid_dataformat = VIDEO_PALETTE_RGB24; } case VIDEO_PALETTE_YUV422: { cam->ctrlreg.vid_dataformat = W9967CF_YUV422_PACKED; } case VIDEO_PALETTE_YUV422P: { cam->ctrlreg.vid_dataformat = W9967CF_YUV422_PLANAR; } case VIDEO_PALETTE_YUV420: { cam->ctrlreg.vid_dataformat = W9967CF_YUV420_PACKED; } case VIDEO_PALETTE_YUV420P: { cam->ctrlreg.vid_dataformat = W9967CF_YUV420_PLANAR; } default: { printk("w9967cf driver: Not a valid palette (VIDIOCSPICT),"\ " report this please\n Setting to YUV422 Packed"); cam->ctrlreg.vid_dataformat = W9967CF_YUV422_PACKED; return -EINVAL; } } /* end of palette switch */ cam->brightness = v.brightness; cam->hue = v.hue; cam->colour = v.colour; cam->contrast = v.contrast; cam->whiteness = v.whiteness; //w9967cf_update_registers(cam); return 0; } case VIDIOCSWIN: /* Set Capture Area */ { struct video_window vw; if (copy_from_user(&vw, arg, sizeof(vw))) return -EFAULT; if (vw.clipcount) return -EINVAL; //I don't clip. //if (vw.flags) return -EINVAL; //wait until not grabbing if (! (vw.width==128 && vw.height==96) || (vw.width==160 && vw.height==120) || (vw.width==320 && vw.height==240) ||
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -