em28xx_videodbg("VIDIOC_G_FMT: %dx%d", dev->width, 
em28xx_videodbg("VIDIOC_G_FMT: %dx%d\n", dev->width, 
static int em28xx_video_do_ioctl(struct inode *inode, struct file *filp,				 unsigned int cmd, void *arg){	struct em28xx *dev = filp->private_data;	if (!dev)		return -ENODEV;	if (video_debug > 1)		em28xx_print_ioctl(dev->name,cmd);	switch (cmd) {		/* --- capabilities ------------------------------------------ */	case VIDIOC_QUERYCAP:		{			struct v4l2_capability *cap = arg;			memset(cap, 0, sizeof(*cap));			strlcpy(cap->driver, "em28xx", sizeof(cap->driver));			strlcpy(cap->card, em28xx_boards[dev->model].name,				sizeof(cap->card));			strlcpy(cap->bus_info, dev->udev->dev.bus_id,				sizeof(cap->bus_info));			cap->version = EM28XX_VERSION_CODE;			cap->capabilities =			    V4L2_CAP_VIDEO_CAPTURE |			    V4L2_CAP_AUDIO |			    V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;			if (dev->has_tuner)				cap->capabilities |= V4L2_CAP_TUNER;			return 0;		}		/* --- capture ioctls ---------------------------------------- */	case VIDIOC_ENUM_FMT:		{			struct v4l2_fmtdesc *fmtd = arg;			if (fmtd->index != 0)				return -EINVAL;			memset(fmtd, 0, sizeof(*fmtd));			fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;			strcpy(fmtd->description, "Packed YUY2");			fmtd->pixelformat = V4L2_PIX_FMT_YUYV;			memset(fmtd->reserved, 0, sizeof(fmtd->reserved));			return 0;		}	case VIDIOC_G_FMT:		{			struct v4l2_format *format = arg;			em28xx_videodbg("VIDIOC_G_FMT: type=%s",				 format->type ==				 V4L2_BUF_TYPE_VIDEO_CAPTURE ?				 "V4L2_BUF_TYPE_VIDEO_CAPTURE" : format->type ==				 V4L2_BUF_TYPE_VBI_CAPTURE ?				 "V4L2_BUF_TYPE_VBI_CAPTURE " :				 "not supported");			if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)				return -EINVAL;			format->fmt.pix.width = dev->width;			format->fmt.pix.height = dev->height;			format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;			format->fmt.pix.bytesperline = dev->bytesperline;			format->fmt.pix.sizeimage = dev->frame_size;			format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;			format->fmt.pix.field = dev->interlaced ? V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;	/* FIXME: TOP? NONE? BOTTOM? ALTENATE? */			em28xx_videodbg("VIDIOC_G_FMT: %dx%d", dev->width,				 dev->height);			return 0;		}	case VIDIOC_TRY_FMT:	case VIDIOC_S_FMT:		{			struct v4l2_format *format = arg;			u32 i;			int ret = 0;			int width = format->fmt.pix.width;			int height = format->fmt.pix.height;			unsigned int hscale, vscale;			unsigned int maxh, maxw;			maxw = norm_maxw(dev);			maxh = norm_maxh(dev);/*		int both_fields; */			em28xx_videodbg("%s: type=%s",				 cmd ==				 VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :				 "VIDIOC_S_FMT",				 format->type ==				 V4L2_BUF_TYPE_VIDEO_CAPTURE ?				 "V4L2_BUF_TYPE_VIDEO_CAPTURE" : format->type ==				 V4L2_BUF_TYPE_VBI_CAPTURE ?				 "V4L2_BUF_TYPE_VBI_CAPTURE " :				 "not supported");			if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)				return -EINVAL;			em28xx_videodbg("%s: requested %dx%d",				 cmd ==				 VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :				 "VIDIOC_S_FMT", format->fmt.pix.width,				 format->fmt.pix.height);			/* FIXME: Move some code away from here */			/* width must even because of the YUYV format */			/* height must be even because of interlacing */			height &= 0xfffe;			width &= 0xfffe;			if (height < 32)				height = 32;			if (height > maxh)				height = maxh;			if (width < 48)				width = 48;			if (width > maxw)				width = maxw;			if(dev->is_em2800){				/* the em2800 can only scale down to 50% */				if(height % (maxh / 2))					height=maxh;				if(width % (maxw / 2))					width=maxw;				/* according to empiatech support */				/* the MaxPacketSize is to small to support */				/* framesizes larger than 640x480 @ 30 fps */				/* or 640x576 @ 25 fps. As this would cut */				/* of a part of the image we prefer */				/* 360x576 or 360x480 for now */				if(width == maxw && height == maxh)					width /= 2;			}			if ((hscale =			     (((unsigned long)maxw) << 12) / width - 4096L) >=			    0x4000)				hscale = 0x3fff;			width =			    (((unsigned long)maxw) << 12) / (hscale + 4096L);			if ((vscale =			     (((unsigned long)maxh) << 12) / height - 4096L) >=			    0x4000)				vscale = 0x3fff;			height =			    (((unsigned long)maxh) << 12) / (vscale + 4096L);			format->fmt.pix.width = width;			format->fmt.pix.height = height;			format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;			format->fmt.pix.bytesperline = width * 2;			format->fmt.pix.sizeimage = width * 2 * height;			format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;			format->fmt.pix.field = V4L2_FIELD_INTERLACED;			em28xx_videodbg("%s: returned %dx%d (%d, %d)",				 cmd ==				 VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :				 "VIDIOC_S_FMT", format->fmt.pix.width,				 format->fmt.pix.height, hscale, vscale);			if (cmd == VIDIOC_TRY_FMT)				return 0;			for (i = 0; i < dev->num_frames; i++)				if (dev->frame[i].vma_use_count) {					em28xx_videodbg("VIDIOC_S_FMT failed. "						"Unmap the buffers first.");					return -EINVAL;				}			/* stop io in case it is already in progress */			if (dev->stream == STREAM_ON) {				em28xx_videodbg("VIDIOC_SET_FMT: interupting stream");				if ((ret = em28xx_stream_interrupt(dev)))					return ret;			}			em28xx_release_buffers(dev);			dev->io = IO_NONE;			/* set new image size */			dev->width = width;			dev->height = height;			dev->frame_size = dev->width * dev->height * 2;			dev->field_size = dev->frame_size >> 1;	/*both_fileds ? dev->frame_size>>1 : dev->frame_size; */			dev->bytesperline = dev->width * 2;			dev->hscale = hscale;			dev->vscale = vscale;/*			dev->both_fileds = both_fileds; */			em28xx_uninit_isoc(dev);			em28xx_set_alternate(dev);			em28xx_capture_start(dev, 1);			em28xx_resolution_set(dev);			em28xx_init_isoc(dev);			return 0;		}		/* --- streaming capture ------------------------------------- */	case VIDIOC_REQBUFS:		{			struct v4l2_requestbuffers *rb = arg;			u32 i;			int ret;			if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||			    rb->memory != V4L2_MEMORY_MMAP)				return -EINVAL;			if (dev->io == IO_READ) {				em28xx_videodbg ("method is set to read;"					" close and open the device again to"					" choose the mmap I/O method");				return -EINVAL;			}			for (i = 0; i < dev->num_frames; i++)				if (dev->frame[i].vma_use_count) {					em28xx_videodbg ("VIDIOC_REQBUFS failed; previous buffers are still mapped");					return -EINVAL;				}			if (dev->stream == STREAM_ON) {				em28xx_videodbg("VIDIOC_REQBUFS: interrupting stream");				if ((ret = em28xx_stream_interrupt(dev)))					return ret;			}			em28xx_empty_framequeues(dev);			em28xx_release_buffers(dev);			if (rb->count)				rb->count =				    em28xx_request_buffers(dev, rb->count);			dev->frame_current = NULL;			em28xx_videodbg ("VIDIOC_REQBUFS: setting io method to mmap: num bufs %i",						     rb->count);			dev->io = rb->count ? IO_MMAP : IO_NONE;			return 0;		}	case VIDIOC_QUERYBUF:		{			struct v4l2_buffer *b = arg;			if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||			    b->index >= dev->num_frames || dev->io != IO_MMAP)				return -EINVAL;			memcpy(b, &dev->frame[b->index].buf, sizeof(*b));			if (dev->frame[b->index].vma_use_count) {				b->flags |= V4L2_BUF_FLAG_MAPPED;			}			if (dev->frame[b->index].state == F_DONE)				b->flags |= V4L2_BUF_FLAG_DONE;			else if (dev->frame[b->index].state != F_UNUSED)				b->flags |= V4L2_BUF_FLAG_QUEUED;			return 0;		}	case VIDIOC_QBUF:		{			struct v4l2_buffer *b = arg;			unsigned long lock_flags;			if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||			    b->index >= dev->num_frames || dev->io != IO_MMAP) {				return -EINVAL;			}			if (dev->frame[b->index].state != F_UNUSED) {				return -EAGAIN;			}			dev->frame[b->index].state = F_QUEUED;			/* add frame to fifo */			spin_lock_irqsave(&dev->queue_lock, lock_flags);			list_add_tail(&dev->frame[b->index].frame,				      &dev->inqueue);			spin_unlock_irqrestore(&dev->queue_lock, lock_flags);			return 0;		}	case VIDIOC_DQBUF:		{			struct v4l2_buffer *b = arg;			struct em28xx_frame_t *f;			unsigned long lock_flags;			int ret = 0;			if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE			    || dev->io != IO_MMAP)				return -EINVAL;			if (list_empty(&dev->outqueue)) {				if (dev->stream == STREAM_OFF)					return -EINVAL;				if (filp->f_flags & O_NONBLOCK)					return -EAGAIN;				ret = wait_event_interruptible				    (dev->wait_frame,				     (!list_empty(&dev->outqueue)) ||				     (dev->state & DEV_DISCONNECTED));				if (ret)					return ret;				if (dev->state & DEV_DISCONNECTED)					return -ENODEV;			}			spin_lock_irqsave(&dev->queue_lock, lock_flags);			f = list_entry(dev->outqueue.next,				       struct em28xx_frame_t, frame);			list_del(dev->outqueue.next);			spin_unlock_irqrestore(&dev->queue_lock, lock_flags);			f->state = F_UNUSED;			memcpy(b, &f->buf, sizeof(*b));			if (f->vma_use_count)				b->flags |= V4L2_BUF_FLAG_MAPPED;			return 0;		}	default:		return em28xx_do_ioctl(inode, filp, dev, cmd, arg,				       em28xx_video_do_ioctl);	}	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/eac94356c8f9f7d3854ed0290a406b13bfe8df4c/em28xx-video.c/buggy/drivers/media/video/em28xx/em28xx-video.c