static int vidioc_querybuf(struct file *file, void *__fh, struct v4l2_buffer *buf)
{
	struct saa7146_fh *fh = __fh;

	if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
		return videobuf_querybuf(&fh->video_q, buf);
	if (buf->type == V4L2_BUF_TYPE_VBI_CAPTURE)
		return videobuf_querybuf(&fh->vbi_q, buf);
	return -EINVAL;
}
static int empress_querybuf(struct file *file, void *priv,
					struct v4l2_buffer *b)
{
	struct saa7134_dev *dev = file->private_data;

	return videobuf_querybuf(&dev->empress_tsq, b);
}
Пример #3
0
static int vidioc_querybuf(struct file *file, void *fh,
			   struct v4l2_buffer *b)
{
	struct omap24xxcam_fh *ofh = fh;

	return videobuf_querybuf(&ofh->vbq, b);
}
Пример #4
0
static int solo_querybuf(struct file *file, void *priv,
			 struct v4l2_buffer *buf)
{
	struct solo_filehandle *fh = priv;

	return videobuf_querybuf(&fh->vidq, buf);
}
static int atomisp_querybuf_file(struct file *file, void *fh,
				struct v4l2_buffer *buf)
{
	struct video_device *vdev = video_devdata(file);
	struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);

	return videobuf_querybuf(&pipe->outq, buf);
}
Пример #6
0
static int empress_querybuf(struct file *file, void *priv,
					struct v4l2_buffer *b)
{
	struct saa7134_fh *fh = priv;
	struct saa7134_dev *dev = fh->dev;

	return videobuf_querybuf(&dev->empress_tsq, b);
}
Пример #7
0
static int fimc_cap_querybuf(struct file *file, void *priv,
			   struct v4l2_buffer *buf)
{
	struct fimc_ctx *ctx = priv;
	struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap;

	if (fimc_capture_active(ctx->fimc_dev))
		return -EBUSY;

	return videobuf_querybuf(&cap->vbq, buf);
}
Пример #8
0
static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
{
	int ret;
	struct marucam_device *dev = priv;

	ret = videobuf_querybuf(&dev->vb_vidq, p);
	if (ret) {
		marucam_err("Failed to query the video buffer\n");
	}

	return ret;
}
Пример #9
0
static int vpif_querybuf(struct file *file, void *priv,
				struct v4l2_buffer *tbuf)
{
	struct vpif_fh *fh = priv;
	struct channel_obj *ch = fh->channel;
	struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];

	if (common->fmt.type != tbuf->type)
		return -EINVAL;

	return videobuf_querybuf(&common->buffer_queue, tbuf);
}
Пример #10
0
/**
 * vpif_querybuf() - query buffer handler
 * @file: file ptr
 * @priv: file handle
 * @buf: v4l2 buffer structure ptr
 */
static int vpif_querybuf(struct file *file, void *priv,
				struct v4l2_buffer *buf)
{
	struct vpif_fh *fh = priv;
	struct channel_obj *ch = fh->channel;
	struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];

	vpif_dbg(2, debug, "vpif_querybuf\n");

	if (common->fmt.type != buf->type)
		return -EINVAL;

	if (common->memory != V4L2_MEMORY_MMAP) {
		vpif_dbg(1, debug, "Invalid memory\n");
		return -EINVAL;
	}

	return videobuf_querybuf(&common->buffer_queue, buf);
}
int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *arg)
{
	struct saa7146_fh *fh  = file->private_data;
	struct saa7146_dev *dev = fh->dev;
	struct saa7146_vv *vv = dev->vv_data;

	int err = 0, result = 0, ee = 0;

	struct saa7146_use_ops *ops;
	struct videobuf_queue *q;

	/* check if extension handles the command */
	for(ee = 0; dev->ext_vv_data->ioctls[ee].flags != 0; ee++) {
		if( cmd == dev->ext_vv_data->ioctls[ee].cmd )
			break;
	}

	if( 0 != (dev->ext_vv_data->ioctls[ee].flags & SAA7146_EXCLUSIVE) ) {
		DEB_D(("extension handles ioctl exclusive.\n"));
		result = dev->ext_vv_data->ioctl(fh, cmd, arg);
		return result;
	}
	if( 0 != (dev->ext_vv_data->ioctls[ee].flags & SAA7146_BEFORE) ) {
		DEB_D(("extension handles ioctl before.\n"));
		result = dev->ext_vv_data->ioctl(fh, cmd, arg);
		if( -EAGAIN != result ) {
			return result;
		}
	}

	/* fixme: add handle "after" case (is it still needed?) */

	switch (fh->type) {
	case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
		ops = &saa7146_video_uops;
		q = &fh->video_q;
		break;
		}
	case V4L2_BUF_TYPE_VBI_CAPTURE: {
		ops = &saa7146_vbi_uops;
		q = &fh->vbi_q;
		break;
		}
	default:
		BUG();
		return 0;
	}

	switch (cmd) {
	case VIDIOC_QUERYCAP:
	{
		struct v4l2_capability *cap = arg;
		memset(cap,0,sizeof(*cap));

		DEB_EE(("VIDIOC_QUERYCAP\n"));

		strcpy(cap->driver, "saa7146 v4l2");
		strlcpy(cap->card, dev->ext->name, sizeof(cap->card));
		sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
		cap->version = SAA7146_VERSION_CODE;
		cap->capabilities =
			V4L2_CAP_VIDEO_CAPTURE |
			V4L2_CAP_VIDEO_OVERLAY |
			V4L2_CAP_READWRITE |
			V4L2_CAP_STREAMING;
		cap->capabilities |= dev->ext_vv_data->capabilities;
		return 0;
	}
	case VIDIOC_G_FBUF:
	{
		struct v4l2_framebuffer *fb = arg;

		DEB_EE(("VIDIOC_G_FBUF\n"));

		*fb = vv->ov_fb;
		fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
		return 0;
	}
	case VIDIOC_S_FBUF:
	{
		struct v4l2_framebuffer *fb = arg;
		struct saa7146_format *fmt;

		DEB_EE(("VIDIOC_S_FBUF\n"));

		if(!capable(CAP_SYS_ADMIN) &&
		   !capable(CAP_SYS_RAWIO))
			return -EPERM;

		/* check args */
		fmt = format_by_fourcc(dev,fb->fmt.pixelformat);
		if (NULL == fmt) {
			return -EINVAL;
		}

		/* planar formats are not allowed for overlay video, clipping and video dma would clash */
		if (0 != (fmt->flags & FORMAT_IS_PLANAR)) {
			DEB_S(("planar pixelformat '%4.4s' not allowed for overlay\n",(char *)&fmt->pixelformat));
		}

		/* check if overlay is running */
		if (IS_OVERLAY_ACTIVE(fh) != 0) {
			if (vv->video_fh != fh) {
				DEB_D(("refusing to change framebuffer informations while overlay is active in another open.\n"));
				return -EBUSY;
			}
		}

		down(&dev->lock);

		/* ok, accept it */
		vv->ov_fb = *fb;
		vv->ov_fmt = fmt;
		if (0 == vv->ov_fb.fmt.bytesperline)
			vv->ov_fb.fmt.bytesperline =
				vv->ov_fb.fmt.width*fmt->depth/8;

		up(&dev->lock);

		return 0;
	}
	case VIDIOC_ENUM_FMT:
	{
		struct v4l2_fmtdesc *f = arg;
		int index;

		switch (f->type) {
		case V4L2_BUF_TYPE_VIDEO_CAPTURE:
		case V4L2_BUF_TYPE_VIDEO_OVERLAY: {
			index = f->index;
			if (index < 0 || index >= NUM_FORMATS) {
				return -EINVAL;
			}
			memset(f,0,sizeof(*f));
			f->index = index;
			strlcpy(f->description,formats[index].name,sizeof(f->description));
			f->pixelformat = formats[index].pixelformat;
			break;
		}
		default:
			return -EINVAL;
		}

		DEB_EE(("VIDIOC_ENUM_FMT: type:%d, index:%d\n",f->type,f->index));
		return 0;
	}
	case VIDIOC_QUERYCTRL:
	{
		const struct v4l2_queryctrl *ctrl;
		struct v4l2_queryctrl *c = arg;

		if ((c->id <  V4L2_CID_BASE ||
		     c->id >= V4L2_CID_LASTP1) &&
		    (c->id <  V4L2_CID_PRIVATE_BASE ||
		     c->id >= V4L2_CID_PRIVATE_LASTP1))
			return -EINVAL;

		ctrl = ctrl_by_id(c->id);
		if( NULL == ctrl ) {
			return -EINVAL;
/*
			c->flags = V4L2_CTRL_FLAG_DISABLED;
			return 0;
*/
		}

		DEB_EE(("VIDIOC_QUERYCTRL: id:%d\n",c->id));
		*c = *ctrl;
		return 0;
	}
	case VIDIOC_G_CTRL: {
		DEB_EE(("VIDIOC_G_CTRL\n"));
		return get_control(fh,arg);
	}
	case VIDIOC_S_CTRL:
	{
		DEB_EE(("VIDIOC_S_CTRL\n"));
		err = set_control(fh,arg);
		return err;
	}
	case VIDIOC_G_PARM:
	{
		struct v4l2_streamparm *parm = arg;
		if( parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ) {
			return -EINVAL;
		}
		memset(&parm->parm.capture,0,sizeof(struct v4l2_captureparm));
		parm->parm.capture.readbuffers = 1;
		// fixme: only for PAL!
		parm->parm.capture.timeperframe.numerator = 1;
		parm->parm.capture.timeperframe.denominator = 25;
		return 0;
	}
	case VIDIOC_G_FMT:
	{
		struct v4l2_format *f = arg;
		DEB_EE(("VIDIOC_G_FMT\n"));
		return g_fmt(fh,f);
	}
	case VIDIOC_S_FMT:
	{
		struct v4l2_format *f = arg;
		DEB_EE(("VIDIOC_S_FMT\n"));
		return s_fmt(fh,f);
	}
	case VIDIOC_TRY_FMT:
	{
		struct v4l2_format *f = arg;
		DEB_EE(("VIDIOC_TRY_FMT\n"));
		return try_fmt(fh,f);
	}
	case VIDIOC_G_STD:
	{
		v4l2_std_id *id = arg;
		DEB_EE(("VIDIOC_G_STD\n"));
		*id = vv->standard->id;
		return 0;
	}
	/* the saa7146 supfhrts (used in conjunction with the saa7111a for example)
	   PAL / NTSC / SECAM. if your hardware does not (or does more)
	   -- override this function in your extension */
	case VIDIOC_ENUMSTD:
	{
		struct v4l2_standard *e = arg;
		if (e->index < 0 )
			return -EINVAL;
		if( e->index < dev->ext_vv_data->num_stds ) {
			DEB_EE(("VIDIOC_ENUMSTD: index:%d\n",e->index));
			v4l2_video_std_construct(e, dev->ext_vv_data->stds[e->index].id, dev->ext_vv_data->stds[e->index].name);
			return 0;
		}
		return -EINVAL;
	}
	case VIDIOC_S_STD:
	{
		v4l2_std_id *id = arg;
		int found = 0;
		int i, err;

		DEB_EE(("VIDIOC_S_STD\n"));

		if ((vv->video_status & STATUS_CAPTURE) == STATUS_CAPTURE) {
			DEB_D(("cannot change video standard while streaming capture is active\n"));
			return -EBUSY;
		}

		if ((vv->video_status & STATUS_OVERLAY) != 0) {
			vv->ov_suspend = vv->video_fh;
			err = saa7146_stop_preview(vv->video_fh); /* side effect: video_status is now 0, video_fh is NULL */
			if (0 != err) {
				DEB_D(("suspending video failed. aborting\n"));
				return err;
			}
		}

		down(&dev->lock);

		for(i = 0; i < dev->ext_vv_data->num_stds; i++)
			if (*id & dev->ext_vv_data->stds[i].id)
				break;
		if (i != dev->ext_vv_data->num_stds) {
			vv->standard = &dev->ext_vv_data->stds[i];
			if( NULL != dev->ext_vv_data->std_callback )
				dev->ext_vv_data->std_callback(dev, vv->standard);
			found = 1;
		}

		up(&dev->lock);

		if (vv->ov_suspend != NULL) {
			saa7146_start_preview(vv->ov_suspend);
			vv->ov_suspend = NULL;
		}

		if( 0 == found ) {
			DEB_EE(("VIDIOC_S_STD: standard not found.\n"));
			return -EINVAL;
		}

		DEB_EE(("VIDIOC_S_STD: set to standard to '%s'\n",vv->standard->name));
		return 0;
	}
	case VIDIOC_OVERLAY:




	{
		int on = *(int *)arg;
		int err = 0;

		DEB_D(("VIDIOC_OVERLAY on:%d\n",on));
		if (on != 0) {
			err = saa7146_start_preview(fh);
		} else {
			err = saa7146_stop_preview(fh);
		}
		return err;
	}
	case VIDIOC_REQBUFS: {
		struct v4l2_requestbuffers *req = arg;
		DEB_D(("VIDIOC_REQBUFS, type:%d\n",req->type));
		return videobuf_reqbufs(q,req);
	}
	case VIDIOC_QUERYBUF: {
		struct v4l2_buffer *buf = arg;
		DEB_D(("VIDIOC_QUERYBUF, type:%d, offset:%d\n",buf->type,buf->m.offset));
		return videobuf_querybuf(q,buf);
	}
	case VIDIOC_QBUF: {
		struct v4l2_buffer *buf = arg;
		int ret = 0;
		ret = videobuf_qbuf(q,buf);
		DEB_D(("VIDIOC_QBUF: ret:%d, index:%d\n",ret,buf->index));
		return ret;
	}
	case VIDIOC_DQBUF: {
		struct v4l2_buffer *buf = arg;
		int ret = 0;
		ret = videobuf_dqbuf(q,buf,file->f_flags & O_NONBLOCK);
		DEB_D(("VIDIOC_DQBUF: ret:%d, index:%d\n",ret,buf->index));
		return ret;
	}
	case VIDIOC_STREAMON: {
		int *type = arg;
		DEB_D(("VIDIOC_STREAMON, type:%d\n",*type));

		err = video_begin(fh);
		if( 0 != err) {
			return err;
		}
		err = videobuf_streamon(q);
		return err;
	}
	case VIDIOC_STREAMOFF: {
		int *type = arg;

		DEB_D(("VIDIOC_STREAMOFF, type:%d\n",*type));

		/* ugly: we need to copy some checks from video_end(),
		   because videobuf_streamoff() relies on the capture running.
		   check and fix this */
		if ((vv->video_status & STATUS_CAPTURE) != STATUS_CAPTURE) {
			DEB_S(("not capturing.\n"));
			return 0;
		}

		if (vv->video_fh != fh) {
			DEB_S(("capturing, but in another open.\n"));
			return -EBUSY;
		}

		err = videobuf_streamoff(q);
		if (0 != err) {
			DEB_D(("warning: videobuf_streamoff() failed.\n"));
			video_end(fh, file);
		} else {
			err = video_end(fh, file);
		}
		return err;
	}
	case VIDIOCGMBUF:
	{
		struct video_mbuf *mbuf = arg;
		struct videobuf_queue *q;
		int i;

		/* fixme: number of capture buffers and sizes for v4l apps */
		int gbuffers = 2;
		int gbufsize = 768*576*4;

		DEB_D(("VIDIOCGMBUF \n"));

		q = &fh->video_q;
		down(&q->lock);
		err = videobuf_mmap_setup(q,gbuffers,gbufsize,
					  V4L2_MEMORY_MMAP);
		if (err < 0) {
			up(&q->lock);
			return err;
		}
		memset(mbuf,0,sizeof(*mbuf));
		mbuf->frames = gbuffers;
		mbuf->size   = gbuffers * gbufsize;
		for (i = 0; i < gbuffers; i++)
			mbuf->offsets[i] = i * gbufsize;
		up(&q->lock);
		return 0;
	}
	default:
		return v4l_compat_translate_ioctl(inode,file,cmd,arg,
						  saa7146_video_do_ioctl);
	}
	return 0;
}
Пример #12
0
/**
 * previewer_ioctl - I/O control function for Preview Wrapper
 * @inode: Inode structure associated with the Preview Wrapper.
 * @file: File structure associated with the Preview Wrapper.
 * @cmd: Type of command to execute.
 * @arg: Argument to send to requested command.
 *
 * Returns 0 if successful, -1 if bad command passed or access is denied,
 * -EFAULT if copy_from_user() or copy_to_user() fails, -EINVAL if parameter
 * validation fails or parameter structure is not present
 **/
static int previewer_ioctl(struct inode *inode, struct file *file,
                           unsigned int cmd, unsigned long arg)
{
    int ret = 0;
    struct prev_params params;
    struct prev_fh *fh = file->private_data;
    struct prev_device *device = fh->device;

    dev_dbg(prev_dev, "Entering previewer_ioctl()\n");

    if ((_IOC_TYPE(cmd) != PREV_IOC_BASE)
            || (_IOC_NR(cmd) > PREV_IOC_MAXNR)) {
        dev_err(prev_dev, "Bad command Value \n");
        goto err_minusone;
    }

    if (_IOC_DIR(cmd) & _IOC_READ)
        ret = !access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd));
    else if (_IOC_DIR(cmd) & _IOC_WRITE)
        ret = !access_ok(VERIFY_READ, (void *)arg, _IOC_SIZE(cmd));
    if (ret) {
        dev_err(prev_dev, "access denied\n");
        goto err_minusone;
    }

    switch (cmd) {
    case PREV_REQBUF:
    {
        struct v4l2_requestbuffers *req;

        if (mutex_lock_interruptible(&device->prevwrap_mutex))
            goto err_eintr;

        req = (struct v4l2_requestbuffers *) arg;

        if (req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
            ret = videobuf_reqbufs(&fh->inout_vbq, (void *) arg);
        else if (req->type == V4L2_BUF_TYPE_PRIVATE)
            ret = videobuf_reqbufs(&fh->lsc_vbq, (void *) arg);
        else
            ret = -EINVAL;

        mutex_unlock(&device->prevwrap_mutex);
        break;
    }

    case PREV_QUERYBUF:
    {
        struct v4l2_buffer *b;

        if (mutex_lock_interruptible(&device->prevwrap_mutex))
            goto err_eintr;
        b = (struct v4l2_buffer *) arg;

        if (b->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
            ret = videobuf_querybuf(&fh->inout_vbq, (void *) arg);
        else if (b->type == V4L2_BUF_TYPE_PRIVATE)
            ret = videobuf_querybuf(&fh->lsc_vbq, (void *) arg);
        else
            ret = -EINVAL;

        mutex_unlock(&device->prevwrap_mutex);
        break;
    }

    case PREV_QUEUEBUF:
    {
        struct v4l2_buffer *b;

        if (mutex_lock_interruptible(&device->prevwrap_mutex))
            goto err_eintr;

        b = (struct v4l2_buffer *) arg;
        if (b->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
            ret = videobuf_qbuf(&fh->inout_vbq, (void *) arg);
        else if (b->type == V4L2_BUF_TYPE_PRIVATE)
            ret = videobuf_qbuf(&fh->lsc_vbq, (void *) arg);
        else
            ret = -EINVAL;

        mutex_unlock(&device->prevwrap_mutex);
        break;
    }

    case PREV_SET_PARAM:
        if (mutex_lock_interruptible(&device->prevwrap_mutex))
            goto err_eintr;
        DPRINTK_PREVIEWER("%s PREV_SET_PARAMS before copy from user:\n",
                          __func__);
        if (copy_from_user(&params, (struct prev_params *)arg,
                           sizeof(struct prev_params))) {
            mutex_unlock(&device->prevwrap_mutex);
            return -EFAULT;
        }
        DPRINTK_PREVIEWER("%s PREV_SET_PARAMS before prev validate "
                          "params:\n", __func__);
        ret = prev_validate_params(&params);
        if (ret < 0) {
            dev_err(prev_dev, "Error validating parameters!\n");
            mutex_unlock(&device->prevwrap_mutex);
            goto out;
        }
        DPRINTK_PREVIEWER("%s PREV_SET_PARAMSbefore memcopy:\n",
                          __func__);
        if (device->params)
            memcpy(device->params, &params,
                   sizeof(struct prev_params));
        else {
            mutex_unlock(&device->prevwrap_mutex);
            return -EINVAL;
        }

        /* ret = prev_hw_setup(device->params); */
        mutex_unlock(&device->prevwrap_mutex);
        break;

    case PREV_GET_PARAM:
        if (copy_to_user((struct prev_params *)arg, device->params,
                         sizeof(struct prev_params)))
            ret = -EFAULT;
        break;

    case PREV_GET_STATUS:
        ret = prev_get_status((struct prev_status *)arg);
        break;

    case PREV_PREVIEW:
        if (mutex_lock_interruptible(&device->prevwrap_mutex))
            goto err_eintr;
        ret = prev_do_preview(device, (int *)arg);
        mutex_unlock(&device->prevwrap_mutex);
        break;

    case PREV_GET_CROPSIZE:
    {
        struct prev_cropsize outputsize;
        prev_calculate_crop(device, &outputsize);
        if (copy_to_user((struct prev_cropsize *)arg, &outputsize,
                         sizeof(struct prev_cropsize)))
            ret = -EFAULT;
    }
    break;

    default:
        dev_err(prev_dev, "previewer_ioctl: Invalid Command Value\n");
        ret = -EINVAL;
    }
out:
    return ret;
err_minusone:
    return -1;
err_eintr:
    return -EINTR;
}
Пример #13
0
static int
camera_core_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
                     void *arg)
{
    struct camera_fh *fh  = file->private_data;
    struct camera_device *cam = fh->cam;
    int err;
    switch (cmd) {
    case VIDIOC_ENUMINPUT:
    {
        /* default handler assumes 1 video input (the camera) */
        struct v4l2_input *input = (struct v4l2_input *)arg;
        int index = input->index;

        memset(input, 0, sizeof(*input));
        input->index = index;

        if (index > 0)
            return -EINVAL;

        strlcpy(input->name, "camera", sizeof(input->name));
        input->type = V4L2_INPUT_TYPE_CAMERA;

        return 0;
    }

    case VIDIOC_G_INPUT:
    {
        unsigned int *input = arg;
        *input = 0;

        return 0;
    }

    case VIDIOC_S_INPUT:
    {
        unsigned int *input = arg;

        if (*input > 0)
            return -EINVAL;

        return 0;
    }

    case VIDIOC_ENUM_FMT:
    {
        struct v4l2_fmtdesc *fmt = arg;
        return cam->cam_sensor->enum_pixformat(fmt, cam->sensor_data);
    }

    case VIDIOC_TRY_FMT:
    {
        struct v4l2_format *fmt = arg;
        return cam->cam_sensor->try_format(&fmt->fmt.pix, cam->sensor_data);

    }

    case VIDIOC_G_FMT:
    {
        struct v4l2_format *fmt = arg;

        /* get the current format */
        memset(&fmt->fmt.pix, 0, sizeof (fmt->fmt.pix));
        fmt->fmt.pix = cam->pix;

        return 0;
    }

    case VIDIOC_S_FMT:
    {
        struct v4l2_format *fmt = arg;
        unsigned int temp_sizeimage = 0;

        temp_sizeimage = cam->pix.sizeimage;
        cam->cam_sensor->try_format(&fmt->fmt.pix, cam->sensor_data);
        cam->pix = fmt->fmt.pix;

        cam->xclk = cam->cam_sensor->calc_xclk(&cam->pix,
                                               &cam->nominal_timeperframe, cam->sensor_data);
        cam->cparm.timeperframe = cam->nominal_timeperframe;
        cam->xclk = cam->cam_hardware->set_xclk(cam->xclk, cam->hardware_data);
        return cam->cam_sensor->configure(&cam->pix, cam->xclk,
                                          &cam->cparm.timeperframe, cam->sensor_data);
    }

    case VIDIOC_QUERYCTRL:
    {
        struct v4l2_queryctrl *qc = arg;
        return cam->cam_sensor->query_control(qc, cam->sensor_data);
    }

    case VIDIOC_G_CTRL:
    {
        struct v4l2_control *vc = arg;
        return cam->cam_sensor->get_control(vc, cam->sensor_data);
    }

    case VIDIOC_S_CTRL:
    {
        struct v4l2_control *vc = arg;
        return cam->cam_sensor->set_control(vc, cam->sensor_data);
    }

    case VIDIOC_QUERYCAP:
    {
        struct v4l2_capability *cap =
            (struct v4l2_capability *) arg;

        memset(cap, 0, sizeof(*cap));
        strlcpy(cap->driver, CAM_NAME, sizeof(cap->driver));
        strlcpy(cap->card, cam->vfd->name, sizeof(cap->card));
        cap->bus_info[0] = '\0';
        cap->version = KERNEL_VERSION(0, 0, 0);
        cap->capabilities =
            V4L2_CAP_VIDEO_CAPTURE |
            V4L2_CAP_VIDEO_OVERLAY |
            V4L2_CAP_READWRITE |
            V4L2_CAP_STREAMING;
        return 0;
    }

    case VIDIOC_G_FBUF: /* Get the frame buffer parameters */
    {
        struct v4l2_framebuffer *fbuf =
            (struct v4l2_framebuffer *) arg;

        spin_lock(&cam->img_lock);
        *fbuf = cam->fbuf;
        spin_unlock(&cam->img_lock);
        return 0;
    }

    case VIDIOC_S_FBUF: /* set the frame buffer parameters */
    {
        struct v4l2_framebuffer *fbuf =
            (struct v4l2_framebuffer *) arg;

        spin_lock(&cam->img_lock);
        if (cam->previewing) {
            spin_unlock(&cam->img_lock);
            return -EBUSY;
        }
        cam->fbuf.base = fbuf->base;
        cam->fbuf.fmt = fbuf->fmt;

        spin_unlock(&cam->img_lock);
        return 0;
    }

    case VIDIOC_OVERLAY:
    {
        int enable = *((int *) arg);

        /*
         * check whether the capture format and
         ** the display format matches
         * return failure if they are different
         */
        if (cam->pix.pixelformat != cam->fbuf.fmt.pixelformat)
        {
            return -EINVAL;
        }

        /* If the camera image size is greater
        ** than LCD size return failure */
        if ((cam->pix.width > cam->fbuf.fmt.height) ||
                (cam->pix.height > cam->fbuf.fmt.width))
        {
            return -EINVAL;
        }

        if (!cam->previewing && enable)
        {
            cam->previewing = fh;
            cam->overlay_cnt = 0;
            camera_core_start_overlay(cam);
        }
        else if (!enable)
        {
            cam->previewing = NULL;
        }

        return 0;
    }

    case VIDIOC_REQBUFS:
        return videobuf_reqbufs(&fh->vbq, arg);

    case VIDIOC_QUERYBUF:
        return videobuf_querybuf(&fh->vbq, arg);

    case VIDIOC_QBUF:
        return videobuf_qbuf(&fh->vbq, arg);

    case VIDIOC_DQBUF:
        return videobuf_dqbuf(&fh->vbq, arg, file->f_flags & O_NONBLOCK);

    case VIDIOC_STREAMON:
    {
        spin_lock(&cam->img_lock);
        if (cam->streaming || cam->reading) {
            spin_unlock(&cam->img_lock);

            return -EBUSY;
        }
        else {
            cam->streaming = fh;
            /* FIXME: start camera interface */
        }

        spin_unlock(&cam->img_lock);

        /* Allocate dummy buffer. We will use this buffer then no
         * videobufs available to prevent FIFO_FULL. Use the same
         * field of camera_device structure as in 'read()' function
         * (capture_base_phys and capture_base)
         */

        if (!cam->capture_base) {
            cam->capture_base = (unsigned long)dma_alloc_coherent(NULL, cam->pix.sizeimage,
                                (dma_addr_t *) &cam->capture_base_phys, GFP_KERNEL | GFP_DMA);
        }
        if (!cam->capture_base) {
            printk(KERN_ERR CAM_NAME ": cannot allocate dummy buffer\n");
            spin_lock(&cam->img_lock);
            cam->streaming = NULL;
            spin_unlock(&cam->img_lock);
            return -ENOMEM;
        }

        return videobuf_streamon(&fh->vbq);
    }
    case VIDIOC_STREAMOFF:
    {
        struct videobuf_queue *q = &fh->vbq;
        int i;

        /* video-buf lib has trouble to turn off streaming while
         * any buffer is still in QUEUED state. Let's wait until
         * all queued buffers are filled.
         * */
        for (i = 0; i < VIDEO_MAX_FRAME; i++) {
            if (NULL == q->bufs[i])
                continue;
            while (q->bufs[i]->state == STATE_QUEUED) {
                schedule();
            }
        }

        err = videobuf_streamoff(&fh->vbq);
        if (err < 0)
            return err;

        spin_lock(&cam->img_lock);
        if (cam->streaming == fh) {
            cam->streaming = NULL;
        }
        spin_unlock(&cam->img_lock);

        /* Wait for dma finished and remove dummy buffer */

        cam->cam_hardware->finish_dma(cam->hardware_data);

        if (cam->capture_base) {
            dma_free_coherent(NULL, cam->pix.sizeimage,
                              (void *)cam->capture_base,
                              cam->capture_base_phys);
            cam->capture_base = 0;
            cam->capture_base_phys = 0;
        }

        return 0;
    }
    case VIDIOC_ENUMSTD:
    case VIDIOC_G_STD:
    case VIDIOC_S_STD:
    case VIDIOC_QUERYSTD:
    {
        /* Digital cameras don't have an analog video standard,
         * so we don't need to implement these ioctls.
         */
        return -EINVAL;
    }
    case VIDIOC_G_AUDIO:
    case VIDIOC_S_AUDIO:
    case VIDIOC_G_AUDOUT:
    case VIDIOC_S_AUDOUT:
    {
        /* we don't have any audio inputs or outputs */
        return -EINVAL;
    }

    case VIDIOC_G_JPEGCOMP:
    case VIDIOC_S_JPEGCOMP:
    {
        /* JPEG compression is not supported */
        return -EINVAL;
    }

    case VIDIOC_G_TUNER:
    case VIDIOC_S_TUNER:
    case VIDIOC_G_MODULATOR:
    case VIDIOC_S_MODULATOR:
    case VIDIOC_G_FREQUENCY:
    case VIDIOC_S_FREQUENCY:
    {
        /* we don't have a tuner or modulator */
        return -EINVAL;
    }

    case VIDIOC_ENUMOUTPUT:
    case VIDIOC_G_OUTPUT:
    case VIDIOC_S_OUTPUT:
    {
        /* we don't have any video outputs */
        return -EINVAL;
    }

    default:
    {
        /* unrecognized ioctl */
        return -ENOIOCTLCMD;
    }
    }
    return 0;
}
Пример #14
0
static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
{
  struct unicorn_fh *fh = priv;
  return videobuf_querybuf(&fh->vidq, p);
}
Пример #15
0
static int myvivi_vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
{
	return (videobuf_querybuf(&myvivi_vb_vidquene, p));
}
Пример #16
0
/**
 * prev2resz_ioctl - I/O control function for device
 */
static int prev2resz_ioctl(struct inode *inode, struct file *file,
			   unsigned int cmd, unsigned long arg)
{
	struct prev2resz_fhdl *fh = file->private_data;
	long rval = 0;

	if ((_IOC_TYPE(cmd) != PREV2RESZ_IOC_BASE) && (_IOC_TYPE(cmd) != 'M') &&
	    (cmd < BASE_VIDIOC_PRIVATE)) {
		dev_err(p2r_device, "Bad command value.\n");
		return -EFAULT;
	}

	if (_IOC_DIR(cmd) & _IOC_READ)
		rval = !access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd));
	else if (_IOC_DIR(cmd) & _IOC_WRITE)
		rval = !access_ok(VERIFY_READ, (void *)arg, _IOC_SIZE(cmd));

	if (rval) {
		dev_err(p2r_device, "Access denied\n");
		return -EFAULT;
	}

	switch (cmd) {
	case PREV2RESZ_REQBUF:
	{
		struct v4l2_requestbuffers v4l2_req;
		if (copy_from_user(&v4l2_req, (void *)arg,
				   sizeof(struct v4l2_requestbuffers)))
			return -EIO;
		if (v4l2_req.type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
			if (videobuf_reqbufs(&fh->src_vbq, &v4l2_req) < 0)
				return -EINVAL;
		} else if (v4l2_req.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
			if (videobuf_reqbufs(&fh->dst_vbq, &v4l2_req) < 0)
				return -EINVAL;
		}
		if (copy_to_user((void *)arg, &v4l2_req,
				 sizeof(struct v4l2_requestbuffers)))
			return -EIO;
		break;
	}
	case PREV2RESZ_QUERYBUF:
	{
		struct v4l2_buffer v4l2_buf;
		if (copy_from_user(&v4l2_buf, (void *)arg,
				   sizeof(struct v4l2_buffer)))
			return -EIO;
		if (v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
			if (videobuf_querybuf(&fh->src_vbq, &v4l2_buf) < 0)
				return -EINVAL;
		} else if (v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
			if (videobuf_querybuf(&fh->dst_vbq, &v4l2_buf) < 0)
				return -EINVAL;
		}
		if (copy_to_user((void *)arg, &v4l2_buf,
				 sizeof(struct v4l2_buffer)))
			return -EIO;
		break;
	}
	case PREV2RESZ_QUEUEBUF:
	{
		struct v4l2_buffer v4l2_buf;
		if (copy_from_user(&v4l2_buf, (void *)arg,
				   sizeof(struct v4l2_buffer)))
			return -EIO;
		if (v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
			if (videobuf_qbuf(&fh->src_vbq, &v4l2_buf) < 0)
				return -EINVAL;
		} else if (v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
			if (videobuf_qbuf(&fh->dst_vbq, &v4l2_buf) < 0)
				return -EINVAL;
		}
		if (copy_to_user((void *)arg, &v4l2_buf,
				 sizeof(struct v4l2_buffer)))
			return -EIO;
		break;
	}
	case PREV2RESZ_SET_CONFIG:
		if (copy_from_user(&fh->pipe, (void *)arg,
				   sizeof(fh->pipe)))
			return -EIO;
		if (prev2resz_ioc_set_config(fh) < 0)
			return -EINVAL;
		if (copy_to_user((void *)arg, &fh->pipe,
				 sizeof(fh->pipe)))
			return -EIO;
		break;

	case PREV2RESZ_GET_CONFIG:
		if (copy_to_user((void *)arg, &fh->pipe,
				 sizeof(fh->pipe)))
			return -EIO;
		break;

	case PREV2RESZ_RUN_ENGINE:
		if (file->f_flags & O_NONBLOCK) {
			if (isppreview_busy(fh->isp_prev))
				return -EBUSY;
			if (ispresizer_busy(fh->isp_resz))
				return -EBUSY;
		}
		if (prev2resz_ioc_run_engine(fh) < 0)
			return -EINVAL;
		break;

	case PREV2RESZ_GET_STATUS:
	{
		struct prev2resz_status *status =
			(struct prev2resz_status *)arg;
		status->prv_busy = isppreview_busy(fh->isp_prev);
		status->rsz_busy = ispresizer_busy(fh->isp_resz);
		break;
	}
	case VIDIOC_QUERYCAP:
	{
		struct v4l2_capability v4l2_cap;
		if (copy_from_user(&v4l2_cap, (void *)arg,
				   sizeof(struct v4l2_capability)))
			return -EIO;

		strcpy(v4l2_cap.driver, "omap3wrapper");
		strcpy(v4l2_cap.card, "omap3wrapper/prev-resz");
		v4l2_cap.version	= 1.0;;
		v4l2_cap.capabilities	= V4L2_CAP_VIDEO_CAPTURE |
					  V4L2_CAP_READWRITE;

		if (copy_to_user((void *)arg, &v4l2_cap,
				 sizeof(struct v4l2_capability)))
			return -EIO;
		break;
	}
	case VIDIOC_PRIVATE_ISP_PRV_CFG:
		if (isppreview_config(fh->isp_prev, (void *)arg))
			return -EIO;
		break;

	default:
		dev_err(p2r_device, "IOC: Invalid Command Value!\n");
		return -EINVAL;
	}

	return 0;
}