diff -Naur linux-2.3.99-pre6-ov511-1.12/drivers/usb/ov511.c linux/drivers/usb/ov511.c --- linux-2.3.99-pre6-ov511-1.12/drivers/usb/ov511.c Sun May 7 03:51:49 2000 +++ linux/drivers/usb/ov511.c Sun May 7 03:52:50 2000 @@ -30,7 +30,7 @@ * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -static const char version[] = "1.12"; +static const char version[] = "1.13"; #define __NO_VERSION__ @@ -142,34 +142,6 @@ * So I copied it again for the OV511 driver -claudio **********************************************************************/ -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)) - -static inline unsigned long uvirt_to_phys(unsigned long adr) -{ - pgd_t *pgd; - pmd_t *pmd; - pte_t *ptep, pte; - - pgd = pgd_offset(current->mm, adr); - if (pgd_none(*pgd)) - return 0; - pmd = pmd_offset(pgd, adr); - if (pmd_none(*pmd)) - return 0; - ptep = pte_offset(pmd, adr/*&(~PGDIR_MASK)*/); - pte = *ptep; - if (pte_present(pte)) - return virt_to_phys((void *)(pte_page(pte)|(adr&(PAGE_SIZE-1)))); - return 0; -} - -static inline unsigned long kvirt_to_pa(unsigned long adr) -{ - return uvirt_to_phys(VMALLOC_VMADDR(adr)); -} - -#else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)) */ - /* Given PGD from the address space's page table, return the kernel * virtual mapping of the physical memory mapped at ADR. */ @@ -206,8 +178,6 @@ ret = __pa(kva); return ret; } -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)) */ - static void *rvmalloc(unsigned long size) { @@ -226,11 +196,7 @@ adr = (unsigned long) mem; while (size > 0) { page = kvirt_to_pa(adr); -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)) - mem_map_reserve(MAP_NR(phys_to_virt(page))); -#else mem_map_reserve(MAP_NR(__va(page))); -#endif adr += PAGE_SIZE; if (size > PAGE_SIZE) size -= PAGE_SIZE; @@ -254,11 +220,7 @@ adr=(unsigned long) mem; while (size > 0) { page = kvirt_to_pa(adr); -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)) - mem_map_unreserve(MAP_NR(phys_to_virt(page))); -#else mem_map_unreserve(MAP_NR(__va(page))); -#endif adr += PAGE_SIZE; if (size > PAGE_SIZE) size -= PAGE_SIZE; @@ -505,34 +467,13 @@ #endif } -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)) -/* - * This is called as the fill_inode function when an inode - * is going into (fill = 1) or out of service (fill = 0). - * We use it here to manage the module use counts. - */ -static void proc_ov511_modcount(struct inode *inode, int fill) -{ -#ifdef MODULE - if (fill) - MOD_INC_USE_COUNT; - else - MOD_DEC_USE_COUNT; -#endif -} -#endif - static void proc_ov511_create(void) { ov511_proc_root = create_proc_entry("ov511", S_IFDIR, 0); - if (ov511_proc_root) { -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)) - ov511_proc_root->fill_inode = &proc_ov511_modcount; -#else + if (ov511_proc_root) ov511_proc_root->owner = THIS_MODULE; -#endif - } else + else printk("Unable to initialise /proc/ov511\n"); /***********/ } @@ -1858,301 +1799,301 @@ return -EIO; switch (cmd) { - case VIDIOCGCAP: - { - struct video_capability b; - - strcpy(b.name, "OV511 USB Camera"); - b.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE; - b.channels = 1; - b.audios = 0; - b.maxwidth = DEFAULT_WIDTH; - b.maxheight = DEFAULT_HEIGHT; - b.minwidth = 32; - b.minheight = 16; + case VIDIOCGCAP: + { + struct video_capability b; + + strcpy(b.name, "OV511 USB Camera"); + b.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE; + b.channels = 1; + b.audios = 0; + b.maxwidth = DEFAULT_WIDTH; + b.maxheight = DEFAULT_HEIGHT; + b.minwidth = 32; + b.minheight = 16; - if (copy_to_user(arg, &b, sizeof(b))) - return -EFAULT; + if (copy_to_user(arg, &b, sizeof(b))) + return -EFAULT; - return 0; - } - case VIDIOCGCHAN: - { - struct video_channel v; - - if (copy_from_user(&v, arg, sizeof(v))) - return -EFAULT; - if (v.channel != 0) - return -EINVAL; + return 0; + } + case VIDIOCGCHAN: + { + struct video_channel v; + + if (copy_from_user(&v, arg, sizeof(v))) + return -EFAULT; + if (v.channel != 0) + return -EINVAL; - v.flags = 0; - v.tuners = 0; - v.type = VIDEO_TYPE_CAMERA; - strcpy(v.name, "Camera"); + v.flags = 0; + v.tuners = 0; + v.type = VIDEO_TYPE_CAMERA; + strcpy(v.name, "Camera"); - if (copy_to_user(arg, &v, sizeof(v))) - return -EFAULT; + if (copy_to_user(arg, &v, sizeof(v))) + return -EFAULT; - return 0; - } - case VIDIOCSCHAN: - { - int v; - - if (copy_from_user(&v, arg, sizeof(v))) - return -EFAULT; + return 0; + } + case VIDIOCSCHAN: + { + int v; - if (v != 0) - return -EINVAL; + if (copy_from_user(&v, arg, sizeof(v))) + return -EFAULT; - return 0; - } + if (v != 0) + return -EINVAL; - case VIDIOCGPICT: - { - struct video_picture p; + return 0; + } + case VIDIOCGPICT: + { + struct video_picture p; - if (ov7610_get_picture(ov511, &p)) - return -EIO; + if (ov7610_get_picture(ov511, &p)) + return -EIO; - if (copy_to_user(arg, &p, sizeof(p))) - return -EFAULT; + if (copy_to_user(arg, &p, sizeof(p))) + return -EFAULT; - return 0; - } - case VIDIOCSPICT: - { - struct video_picture p; + return 0; + } + case VIDIOCSPICT: + { + struct video_picture p; - if (copy_from_user(&p, arg, sizeof(p))) - return -EFAULT; + if (copy_from_user(&p, arg, sizeof(p))) + return -EFAULT; - if (ov7610_set_picture(ov511, &p)) - return -EIO; - - return 0; - } - case VIDIOCGCAPTURE: - { - int vf; - if (copy_from_user(&vf, arg, sizeof(vf))) - return -EFAULT; - ov511->sub_flag = vf; - return 0; - } - case VIDIOCSCAPTURE: - { - struct video_capture vc; - - if (copy_from_user(&vc, arg, sizeof(vc))) - return -EFAULT; - if (vc.flags) - return -EINVAL; - if (vc.decimation) - return -EINVAL; - vc.x /= 4; - vc.x *= 4; - vc.y /= 2; - vc.y *= 2; - vc.width /= 32; - vc.width *= 32; - if (vc.width == 0) vc.width = 32; - vc.height /= 16; - vc.height *= 16; - if (vc.height == 0) vc.height = 16; - - ov511->subx = vc.x; - ov511->suby = vc.y; - ov511->subw = vc.width; - ov511->subh = vc.height; - - return 0; - } - case VIDIOCSWIN: - { - struct video_window vw; - - if (copy_from_user(&vw, arg, sizeof(vw))) - return -EFAULT; - if (vw.flags) - return -EINVAL; - if (vw.clipcount) - return -EINVAL; - if (vw.height != DEFAULT_HEIGHT) - return -EINVAL; - if (vw.width != DEFAULT_WIDTH) - return -EINVAL; + if (ov7610_set_picture(ov511, &p)) + return -EIO; - ov511->compress = 0; + return 0; + } + case VIDIOCGCAPTURE: + { + int vf; + if (copy_from_user(&vf, arg, sizeof(vf))) + return -EFAULT; + ov511->sub_flag = vf; + return 0; + } + case VIDIOCSCAPTURE: + { + struct video_capture vc; + + if (copy_from_user(&vc, arg, sizeof(vc))) + return -EFAULT; + if (vc.flags) + return -EINVAL; + if (vc.decimation) + return -EINVAL; + vc.x /= 4; + vc.x *= 4; + vc.y /= 2; + vc.y *= 2; + vc.width /= 32; + vc.width *= 32; + if (vc.width == 0) vc.width = 32; + vc.height /= 16; + vc.height *= 16; + if (vc.height == 0) vc.height = 16; + + ov511->subx = vc.x; + ov511->suby = vc.y; + ov511->subw = vc.width; + ov511->subh = vc.height; - return 0; - } - case VIDIOCGWIN: - { - struct video_window vw; + return 0; + } + case VIDIOCSWIN: + { + struct video_window vw; + + if (copy_from_user(&vw, arg, sizeof(vw))) + return -EFAULT; + if (vw.flags) + return -EINVAL; + if (vw.clipcount) + return -EINVAL; + if (vw.height != DEFAULT_HEIGHT) + return -EINVAL; + if (vw.width != DEFAULT_WIDTH) + return -EINVAL; - vw.x = 0; - vw.y = 0; - vw.width = DEFAULT_WIDTH; - vw.height = DEFAULT_HEIGHT; - vw.chromakey = 0; - vw.flags = 30; + ov511->compress = 0; - if (copy_to_user(arg, &vw, sizeof(vw))) - return -EFAULT; + return 0; + } + case VIDIOCGWIN: + { + struct video_window vw; + + vw.x = 0; + vw.y = 0; + vw.width = DEFAULT_WIDTH; + vw.height = DEFAULT_HEIGHT; + vw.chromakey = 0; + vw.flags = 30; - return 0; - } - case VIDIOCGMBUF: - { - struct video_mbuf vm; + if (copy_to_user(arg, &vw, sizeof(vw))) + return -EFAULT; - memset(&vm, 0, sizeof(vm)); - vm.size = 2 * MAX_DATA_SIZE; - vm.frames = 2; - vm.offsets[0] = 0; - vm.offsets[1] = MAX_FRAME_SIZE + sizeof (struct timeval); + return 0; + } + case VIDIOCGMBUF: + { + struct video_mbuf vm; + + memset(&vm, 0, sizeof(vm)); + vm.size = 2 * MAX_DATA_SIZE; + vm.frames = 2; + vm.offsets[0] = 0; + vm.offsets[1] = MAX_FRAME_SIZE + sizeof (struct timeval); - if (copy_to_user((void *)arg, (void *)&vm, sizeof(vm))) - return -EFAULT; + if (copy_to_user((void *)arg, (void *)&vm, sizeof(vm))) + return -EFAULT; - return 0; - } - case VIDIOCMCAPTURE: - { - struct video_mmap vm; + return 0; + } + case VIDIOCMCAPTURE: + { + struct video_mmap vm; + + if (copy_from_user((void *)&vm, (void *)arg, sizeof(vm))) + return -EFAULT; + + PDEBUG(4, "MCAPTURE"); + PDEBUG(4, "frame: %d, size: %dx%d, format: %d", + vm.frame, vm.width, vm.height, vm.format); - if (copy_from_user((void *)&vm, (void *)arg, sizeof(vm))) - return -EFAULT; + if (vm.format != VIDEO_PALETTE_RGB24 && + vm.format != VIDEO_PALETTE_GREY) + return -EINVAL; - PDEBUG(4, "MCAPTURE"); - PDEBUG(4, "frame: %d, size: %dx%d, format: %d", - vm.frame, vm.width, vm.height, vm.format); + if ((vm.frame != 0) && (vm.frame != 1)) + return -EINVAL; + + if (ov511->frame[vm.frame].grabstate == FRAME_GRABBING) + return -EBUSY; - if (vm.format != VIDEO_PALETTE_RGB24 && - vm.format != VIDEO_PALETTE_GREY) - return -EINVAL; + /* Don't compress if the size changed */ + if ((ov511->frame[vm.frame].width != vm.width) || + (ov511->frame[vm.frame].height != vm.height) || + (ov511->frame[vm.frame].format != vm.format) || + (ov511->frame[vm.frame].sub_flag != + ov511->sub_flag)) { + /* If we're collecting previous frame wait + before changing modes */ + interruptible_sleep_on(&ov511->wq); + if (signal_pending(current)) return -EINTR; + ov511_mode_init_regs(ov511, + vm.width, vm.height, + vm.format, ov511->sub_flag); + } + + ov511->frame[vm.frame].width = vm.width; + ov511->frame[vm.frame].height = vm.height; + ov511->frame[vm.frame].format = vm.format; + ov511->frame[vm.frame].sub_flag = ov511->sub_flag; + ov511->frame[vm.frame].segsize = + vm.format == VIDEO_PALETTE_RGB24 ? 384 : 256; + ov511->frame[vm.frame].depth = + vm.format == VIDEO_PALETTE_RGB24 ? 3 : 1; + + /* Mark it as ready */ + ov511->frame[vm.frame].grabstate = FRAME_READY; + + return ov511_new_frame(ov511, vm.frame); + } + case VIDIOCSYNC: + { + int frame; - if ((vm.frame != 0) && (vm.frame != 1)) - return -EINVAL; - - if (ov511->frame[vm.frame].grabstate == FRAME_GRABBING) - return -EBUSY; + if (copy_from_user((void *)&frame, arg, sizeof(int))) + return -EFAULT; - /* Don't compress if the size changed */ - if ((ov511->frame[vm.frame].width != vm.width) || - (ov511->frame[vm.frame].height != vm.height) || - (ov511->frame[vm.frame].format != vm.format) || - (ov511->frame[vm.frame].sub_flag != - ov511->sub_flag)) { - /* If we're collecting previous frame wait - before changing modes */ - interruptible_sleep_on(&ov511->wq); - if (signal_pending(current)) return -EINTR; - ov511_mode_init_regs(ov511, - vm.width, vm.height, - vm.format, ov511->sub_flag); - } + PDEBUG(4, "syncing to frame %d, grabstate = %d", frame, + ov511->frame[frame].grabstate); - ov511->frame[vm.frame].width = vm.width; - ov511->frame[vm.frame].height = vm.height; - ov511->frame[vm.frame].format = vm.format; - ov511->frame[vm.frame].sub_flag = ov511->sub_flag; - ov511->frame[vm.frame].segsize = - vm.format == VIDEO_PALETTE_RGB24 ? 384 : 256; - ov511->frame[vm.frame].depth = - vm.format == VIDEO_PALETTE_RGB24 ? 3 : 1; - - /* Mark it as ready */ - ov511->frame[vm.frame].grabstate = FRAME_READY; - - return ov511_new_frame(ov511, vm.frame); - } - case VIDIOCSYNC: - { - int frame; - - if (copy_from_user((void *)&frame, arg, sizeof(int))) - return -EFAULT; - - PDEBUG(4, "syncing to frame %d, grabstate = %d", frame, - ov511->frame[frame].grabstate); - - switch (ov511->frame[frame].grabstate) { - case FRAME_UNUSED: - return -EINVAL; - case FRAME_READY: - case FRAME_GRABBING: - case FRAME_ERROR: + switch (ov511->frame[frame].grabstate) { + case FRAME_UNUSED: + return -EINVAL; + case FRAME_READY: + case FRAME_GRABBING: + case FRAME_ERROR: redo: - if (!ov511->dev) - return -EIO; + if (!ov511->dev) + return -EIO; - do { + do { #if 0 - init_waitqueue_head(&ov511->frame[frame].wq); + init_waitqueue_head(&ov511->frame[frame].wq); #endif - interruptible_sleep_on(&ov511->frame[frame].wq); - if (signal_pending(current)) - return -EINTR; - } while (ov511->frame[frame].grabstate == FRAME_GRABBING); - - if (ov511->frame[frame].grabstate == FRAME_ERROR) { - int ret; - - if ((ret = ov511_new_frame(ov511, frame)) < 0) - return ret; - goto redo; - } - case FRAME_DONE: - ov511->frame[frame].grabstate = FRAME_UNUSED; - break; - } + interruptible_sleep_on(&ov511->frame[frame].wq); + if (signal_pending(current)) + return -EINTR; + } while (ov511->frame[frame].grabstate == FRAME_GRABBING); + + if (ov511->frame[frame].grabstate == FRAME_ERROR) { + int ret; + + if ((ret = ov511_new_frame(ov511, frame)) < 0) + return ret; + goto redo; + } + case FRAME_DONE: + ov511->frame[frame].grabstate = FRAME_UNUSED; + break; + } + + ov511->frame[frame].grabstate = FRAME_UNUSED; + + /* Reset the hardware snapshot button */ + /* FIXME - Is this the best place for this? */ + if ((ov511->snap_enabled) && + (ov511->frame[frame].snapshot)) { + ov511->frame[frame].snapshot = 0; + ov511_reg_write(ov511->dev, 0x52, 0x01); + ov511_reg_write(ov511->dev, 0x52, 0x03); + ov511_reg_write(ov511->dev, 0x52, 0x01); + } - ov511->frame[frame].grabstate = FRAME_UNUSED; + return 0; + } + case VIDIOCGFBUF: + { + struct video_buffer vb; - /* Reset the hardware snapshot button */ - /* FIXME - Is this the best place for this? */ - if ((ov511->snap_enabled) && - (ov511->frame[frame].snapshot)) { - ov511->frame[frame].snapshot = 0; - ov511_reg_write(ov511->dev, 0x52, 0x01); - ov511_reg_write(ov511->dev, 0x52, 0x03); - ov511_reg_write(ov511->dev, 0x52, 0x01); - } + memset(&vb, 0, sizeof(vb)); + vb.base = NULL; /* frame buffer not supported, not used */ - return 0; - } - case VIDIOCGFBUF: - { - struct video_buffer vb; - - memset(&vb, 0, sizeof(vb)); - vb.base = NULL; /* frame buffer not supported, not used */ - - if (copy_to_user((void *)arg, (void *)&vb, sizeof(vb))) - return -EFAULT; - - return 0; - } - case VIDIOCKEY: - return 0; - case VIDIOCCAPTURE: - return -EINVAL; - case VIDIOCSFBUF: - return -EINVAL; - case VIDIOCGTUNER: - case VIDIOCSTUNER: - return -EINVAL; - case VIDIOCGFREQ: - case VIDIOCSFREQ: - return -EINVAL; - case VIDIOCGAUDIO: - case VIDIOCSAUDIO: - return -EINVAL; - default: - return -ENOIOCTLCMD; + if (copy_to_user((void *)arg, (void *)&vb, sizeof(vb))) + return -EFAULT; + + return 0; } + case VIDIOCKEY: + return 0; + case VIDIOCCAPTURE: + return -EINVAL; + case VIDIOCSFBUF: + return -EINVAL; + case VIDIOCGTUNER: + case VIDIOCSTUNER: + return -EINVAL; + case VIDIOCGFREQ: + case VIDIOCSFREQ: + return -EINVAL; + case VIDIOCGAUDIO: + case VIDIOCSAUDIO: + return -EINVAL; + default: + return -ENOIOCTLCMD; + } /* End switch(cmd) */ + return 0; }