static int camera_v4l2_close(struct file *filep)
{
	int rc = 0;
/*                                                                                        */
	int ret = 0;
/*                                                                                        */
	struct v4l2_event event;
	struct msm_video_device *pvdev = video_drvdata(filep);
	struct camera_v4l2_private *sp = fh_to_private(filep->private_data);
	//                                                                                            

	atomic_sub_return(1, &pvdev->opened);

	if (atomic_read(&pvdev->opened) == 0) {

		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);

		/* Donot wait, imaging server may have crashed */
/*                                                                                        */
		ret = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if(ret < 0){
			pr_err("%s:%d camera_v4l2_close_1 failed\n", __func__, __LINE__);
		}
/*                                                                                        */

		camera_pack_event(filep, MSM_CAMERA_DEL_SESSION, 0, -1, &event);

		/* Donot wait, imaging server may have crashed */
		msm_post_event(&event, -1);
		msm_delete_command_ack_q(pvdev->vdev->num, 0);

		/* This should take care of both normal close
		 * and application crashes */
		msm_destroy_session(pvdev->vdev->num);
		pm_relax(&pvdev->vdev->dev);
		atomic_set(&pvdev->stream_cnt, 0);

	} else {
		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);

		/* Donot wait, imaging server may have crashed */
/*                                                                                        */
		ret = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if(ret < 0){
			pr_err("%s:%d camera_v4l2_close_2 failed\n", __func__, __LINE__);
		}
/*                                                                                        */
		msm_delete_command_ack_q(pvdev->vdev->num,
			sp->stream_id);

		msm_delete_stream(pvdev->vdev->num, sp->stream_id);
	}

	camera_v4l2_vb2_q_release(filep);
	camera_v4l2_fh_release(filep);

	return rc;
}
static int camera_v4l2_close(struct file *filep)
{
	int rc = 0;
	struct v4l2_event event;
	struct msm_video_device *pvdev = video_drvdata(filep);
	struct camera_v4l2_private *sp = fh_to_private(filep->private_data);
	BUG_ON(!pvdev);

	atomic_sub_return(1, &pvdev->opened);

	if (atomic_read(&pvdev->opened) == 0) {

        if(1 == cam_wakelock_init && !wake_lock_active(&cam_wakelock))
        {
            hw_camera_log_info("%s: start camera wake_lock_timeout!\n",__func__);
            //wake lock 500ms for camera exit
            wake_lock_timeout(&cam_wakelock, HZ/2);
        }
        else
        {
            hw_camera_log_info("%s: do not need wake_lock now, cam_wakelock_init = %d\n",
				__func__, cam_wakelock_init);
        }
        
		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);

		/* Donot wait, imaging server may have crashed */
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);

		camera_pack_event(filep, MSM_CAMERA_DEL_SESSION, 0, -1, &event);

		/* Donot wait, imaging server may have crashed */
		msm_post_event(&event, -1);
		msm_delete_command_ack_q(pvdev->vdev->num, 0);

		/* This should take care of both normal close
		 * and application crashes */
		msm_destroy_session(pvdev->vdev->num);
		pm_relax(&pvdev->vdev->dev);
		atomic_set(&pvdev->stream_cnt, 0);

	} else {
		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);

		/* Donot wait, imaging server may have crashed */
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		msm_delete_command_ack_q(pvdev->vdev->num,
			sp->stream_id);

		msm_delete_stream(pvdev->vdev->num, sp->stream_id);
	}

	camera_v4l2_vb2_q_release(filep);
	camera_v4l2_fh_release(filep);

	return rc;
}
static int camera_v4l2_close(struct file *filep)
{
	int rc = 0;
	struct v4l2_event event;
	struct msm_video_device *pvdev = video_drvdata(filep);
	struct camera_v4l2_private *sp = fh_to_private(filep->private_data);
	unsigned int opn_idx, mask;
	BUG_ON(!pvdev);

	opn_idx = atomic_read(&pvdev->opened);
	pr_debug("%s: close stream_id=%d\n", __func__, sp->stream_id);
	mask = (1 << sp->stream_id);
	opn_idx &= ~mask;
	atomic_set(&pvdev->opened, opn_idx);

	if (atomic_read(&pvdev->opened) == 0) {

		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);

		/* Donot wait, imaging server may have crashed */
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);

		camera_pack_event(filep, MSM_CAMERA_DEL_SESSION, 0, -1, &event);

		/* Donot wait, imaging server may have crashed */
		msm_post_event(&event, -1);
		msm_delete_command_ack_q(pvdev->vdev->num, 0);

		/* This should take care of both normal close
		 * and application crashes */
		msm_destroy_session(pvdev->vdev->num);

		/* Enable power collapse latency */
		msm_pm_qos_update_request(CAMERA_ENABLE_PC_LATENCY);

		pm_relax(&pvdev->vdev->dev);
	} else {
		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);

		/* Donot wait, imaging server may have crashed */
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		msm_delete_command_ack_q(pvdev->vdev->num,
			sp->stream_id);

		msm_delete_stream(pvdev->vdev->num, sp->stream_id);
	}

	camera_v4l2_vb2_q_release(filep);
	camera_v4l2_fh_release(filep);

	return rc;
}
Exemplo n.º 4
0
static int camera_v4l2_close(struct file *filep)
{
	int rc = 0;
	struct v4l2_event event;
	struct msm_video_device *pvdev = video_drvdata(filep);
	struct camera_v4l2_private *sp = fh_to_private(filep->private_data);

	BUG_ON(!pvdev);

	atomic_sub_return(1, &pvdev->opened);

	if (atomic_read(&pvdev->opened) == 0) {

		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
				  MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);

		/* Donot wait, imaging server may have crashed */
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);

		camera_pack_event(filep, MSM_CAMERA_DEL_SESSION, 0, -1, &event);

		/* Donot wait, imaging server may have crashed */
#if 1           // wait for signal
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
#else
		msm_post_event(&event, -1);
#endif

		msm_delete_command_ack_q(pvdev->vdev->num, 0);
		/* This should take care of both normal close
		 * and application crashes */
		msm_destroy_session(pvdev->vdev->num);

	} else {
		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
				  MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);

		/* Donot wait, imaging server may have crashed */
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);

		msm_delete_command_ack_q(pvdev->vdev->num,
					 sp->stream_id);

		msm_delete_stream(pvdev->vdev->num, sp->stream_id);
	}

	camera_v4l2_vb2_q_release(filep);
	camera_v4l2_fh_release(filep);

	return rc;
}
Exemplo n.º 5
0
static int camera_v4l2_g_ctrl(struct file *filep, void *fh,
	struct v4l2_control *ctrl)
{
	int rc = 0;
	struct v4l2_event event;
	struct msm_video_device *pvdev = video_drvdata(filep);
	unsigned int session_id = pvdev->vdev->num;

	if (ctrl->id >= V4L2_CID_PRIVATE_BASE) {
		if (ctrl->id == MSM_CAMERA_PRIV_G_SESSION_ID) {
			ctrl->value = session_id;
		} else {
			camera_pack_event(filep, MSM_CAMERA_GET_PARM,
					ctrl->id, -1, &event);

			rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
			if (rc < 0)
				return rc;

			rc = camera_check_event_status(&event);
		}
	}

	return rc;
}
static int camera_v4l2_s_parm(struct file *filep, void *fh,
	struct v4l2_streamparm *parm)
{
	int rc = 0;
	struct v4l2_event event;
	struct msm_v4l2_event_data *event_data =
		(struct msm_v4l2_event_data *)&event.u.data[0];
	struct camera_v4l2_private *sp = fh_to_private(fh);

	camera_pack_event(filep, MSM_CAMERA_SET_PARM,
		MSM_CAMERA_PRIV_NEW_STREAM, -1, &event);

	rc = msm_create_stream(event_data->session_id,
		event_data->stream_id, &sp->vb2_q);
	if (rc < 0)
		return rc;

	rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
	if (rc < 0)
		goto error;

	rc = camera_check_event_status(&event);
	if (rc < 0)
		goto error;

	/* use stream_id as stream index */
	parm->parm.capture.extendedmode = sp->stream_id;

	return rc;

error:
	msm_delete_stream(event_data->session_id,
		event_data->stream_id);
	return rc;
}
Exemplo n.º 7
0
static int camera_v4l2_open(struct file *filep)
{
	int rc = 0;
	struct v4l2_event event;
	struct msm_video_device *pvdev = video_drvdata(filep);
	BUG_ON(!pvdev);

	rc = camera_v4l2_fh_open(filep);
	if (rc < 0)
		goto fh_open_fail;

	/* every stream has a vb2 queue */
	rc = camera_v4l2_vb2_q_init(filep);
	if (rc < 0)
		goto vb2_q_fail;

	if (!atomic_read(&pvdev->opened)) {

		/* create a new session when first opened */
		rc = msm_create_session(pvdev->vdev->num, pvdev->vdev);
		if (rc < 0)
			goto session_fail;
		rc = msm_create_command_ack_q(pvdev->vdev->num, 0);
		if (rc < 0)
			goto command_ack_q_fail;

		camera_pack_event(filep, MSM_CAMERA_NEW_SESSION, 0, -1, &event);
		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if (rc < 0)
			goto post_fail;

		rc = camera_check_event_status(&event);
		if (rc < 0)
			goto post_fail;
	} else {
		rc = msm_create_command_ack_q(pvdev->vdev->num,
			atomic_read(&pvdev->stream_cnt));
		if (rc < 0)
			goto session_fail;
	}

	atomic_add(1, &pvdev->opened);
	atomic_add(1, &pvdev->stream_cnt);
	return rc;

post_fail:
	msm_delete_command_ack_q(pvdev->vdev->num, 0);
command_ack_q_fail:
	msm_destroy_session(pvdev->vdev->num);
session_fail:
	camera_v4l2_vb2_q_release(filep);
vb2_q_fail:
	camera_v4l2_fh_release(filep);
fh_open_fail:
	return rc;
}
static int camera_v4l2_s_fmt_vid_cap_mplane(struct file *filep, void *fh,
	struct v4l2_format *pfmt)
{
	int rc = 0;
	int i = 0;
	struct v4l2_event event;
	struct camera_v4l2_private *sp = fh_to_private(fh);
	struct msm_v4l2_format_data *user_fmt;

	if (pfmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {

		if (WARN_ON(!sp->vb2_q.drv_priv))
			return -ENOMEM;

		memcpy(sp->vb2_q.drv_priv, pfmt->fmt.raw_data,
			sizeof(struct msm_v4l2_format_data));
		user_fmt = (struct msm_v4l2_format_data *)sp->vb2_q.drv_priv;

		pr_debug("%s: num planes :%c\n", __func__,
					user_fmt->num_planes);
		/*num_planes need to bound checked, otherwise for loop
		can execute forever */
		if (WARN_ON(user_fmt->num_planes > VIDEO_MAX_PLANES))
			return -EINVAL;
		for (i = 0; i < user_fmt->num_planes; i++)
			pr_debug("%s: plane size[%d]\n", __func__,
					user_fmt->plane_sizes[i]);

		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_S_FMT, -1, &event);

		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
/*                                                                                        */
		if (rc < 0){
			pr_err("%s:%d camera_v4l2_s_fmt_vid_cap_mplane failed\n", __func__, __LINE__);
			goto set_fmt_fail;
		}
/*                                                                                        */

		rc = camera_check_event_status(&event);
		if (rc < 0)
			goto set_fmt_fail;
		sp->is_vb2_valid = 1;
	}

	return rc;

set_fmt_fail:
	kzfree(sp->vb2_q.drv_priv);
	sp->vb2_q.drv_priv = NULL;
	return rc;
}
static int camera_v4l2_streamoff(struct file *filep, void *fh,
		enum v4l2_buf_type buf_type)
{
	struct v4l2_event event;
	int rc;
	struct camera_v4l2_private *sp = fh_to_private(fh);

	camera_pack_event(filep, MSM_CAMERA_SET_PARM,
		MSM_CAMERA_PRIV_STREAM_OFF, -1, &event);

	rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
	if (rc < 0)
		return rc;

	rc = camera_check_event_status(&event);
	vb2_streamoff(&sp->vb2_q, buf_type);
	return rc;
}
static int camera_v4l2_querycap(struct file *filep, void *fh,
	struct v4l2_capability *cap)
{
	int rc;
	struct v4l2_event event;

	/* can use cap->driver to make differentiation */
	camera_pack_event(filep, MSM_CAMERA_GET_PARM,
		MSM_CAMERA_PRIV_QUERY_CAP, -1, &event);

	rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
	if (rc < 0)
		return rc;

	rc = camera_check_event_status(&event);

	return rc;
}
static int camera_v4l2_g_crop(struct file *filep, void *fh,
	struct v4l2_crop *crop)
{
	int rc = 0;
	struct v4l2_event event;

	if (crop->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
		camera_pack_event(filep, MSM_CAMERA_GET_PARM,
			MSM_CAMERA_PRIV_G_CROP, -1, &event);

		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if (rc < 0)
			return rc;

		rc = camera_check_event_status(&event);
	}

	return rc;
}
static int camera_v4l2_g_ctrl(struct file *filep, void *fh,
	struct v4l2_control *ctrl)
{
	int rc = 0;
	struct v4l2_event event;

	if (ctrl->id >= V4L2_CID_PRIVATE_BASE) {
		camera_pack_event(filep, MSM_CAMERA_GET_PARM, ctrl->id, -1,
			&event);

		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if (rc < 0)
			return rc;

		rc = camera_check_event_status(&event);
	}

	return rc;
}
Exemplo n.º 13
0
static int camera_v4l2_streamon(struct file *filep, void *fh,
	enum v4l2_buf_type buf_type)
{
	struct v4l2_event event;
	int rc;
	struct camera_v4l2_private *sp = fh_to_private(fh);

	rc = vb2_streamon(&sp->vb2_q, buf_type);
	camera_pack_event(filep, MSM_CAMERA_SET_PARM,
		MSM_CAMERA_PRIV_STREAM_ON, -1, &event);

	rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
	if (rc < 0) {
	    pr_err("%s : msm_post_event failed!", __FUNCTION__);
	    return rc;
	}

	rc = camera_check_event_status(&event);
	return rc;
}
static int camera_v4l2_queryctrl(struct file *filep, void *fh,
	struct v4l2_queryctrl *ctrl)
{
	int rc = 0;
	struct v4l2_event event;

	if (ctrl->type == V4L2_CTRL_TYPE_MENU) {

		camera_pack_event(filep, MSM_CAMERA_GET_PARM,
			ctrl->id, -1, &event);

		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if (rc < 0)
			return rc;

		rc = camera_check_event_status(&event);
	}

	return rc;
}
static int camera_v4l2_g_fmt_vid_cap_mplane(struct file *filep, void *fh,
	struct v4l2_format *pfmt)
{
	int rc = -EINVAL;

	if (pfmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
		struct v4l2_event event;

		camera_pack_event(filep, MSM_CAMERA_GET_PARM,
			MSM_CAMERA_PRIV_G_FMT, -1, &event);

		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if (rc < 0)
			return rc;

		rc = camera_check_event_status(&event);
	}

	return rc;
}
static int camera_v4l2_s_ctrl(struct file *filep, void *fh,
	struct v4l2_control *ctrl)
{
	int rc = 0;
	struct v4l2_event event;
	struct msm_v4l2_event_data *event_data;
	if (ctrl->id >= V4L2_CID_PRIVATE_BASE) {
		camera_pack_event(filep, MSM_CAMERA_SET_PARM, ctrl->id,
		ctrl->value, &event);

		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if (rc < 0)
			return rc;
		event_data = (struct msm_v4l2_event_data *)event.u.data;
		ctrl->value = event_data->ret_value;
		rc = camera_check_event_status(&event);
	}

	return rc;
}
Exemplo n.º 17
0
static int camera_v4l2_s_crop(struct file *filep, void *fh,
	const struct v4l2_crop *crop)
{
	int rc = 0;
	struct v4l2_event event;

	if (crop->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {

		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_S_CROP, -1, &event);

		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if (rc < 0) {
		    pr_err("%s : msm_post_event failed!", __FUNCTION__);
		    return rc;
		}

		rc = camera_check_event_status(&event);
	}

	return rc;
}
static int camera_v4l2_g_ctrl(struct file *filep, void *fh,
	struct v4l2_control *ctrl)
{
	int rc = 0;
	struct v4l2_event event;

	if (ctrl->id >= V4L2_CID_PRIVATE_BASE) {
		camera_pack_event(filep, MSM_CAMERA_GET_PARM, ctrl->id, -1,
			&event);

		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
/*                                                                                        */
		if (rc < 0){
			pr_err("%s:%d camera_v4l2_g_ctrl failed\n", __func__, __LINE__);
			return rc;
		}
/*                                                                                        */

		rc = camera_check_event_status(&event);
	}

	return rc;
}
Exemplo n.º 19
0
static int camera_v4l2_open(struct file *filep)
{
	int rc = 0;
	struct v4l2_event event;
	struct msm_video_device *pvdev = video_drvdata(filep);

	BUG_ON(!pvdev);

	rc = camera_v4l2_fh_open(filep);
	if (rc < 0) {
		pr_err("%s : camera_v4l2_fh_open", __func__);
		goto fh_open_fail;
	}

	/* every stream has a vb2 queue */
	rc = camera_v4l2_vb2_q_init(filep);
	if (rc < 0) {
		pr_err("%s : camera_v4l2_vb2_q_init", __func__);
		goto vb2_q_fail;
	}

	if (!atomic_read(&pvdev->opened)) {

		/* create a new session when first opened */
		rc = msm_create_session(pvdev->vdev->num, pvdev->vdev);
		if (rc < 0) {
			pr_err("%s : msm_create_session", __func__);
			goto session_fail;
		}

		rc = msm_create_command_ack_q(pvdev->vdev->num, 0);
		if (rc < 0) {
			pr_err("%s : msm_create_command_ack_q", __func__);
			goto command_ack_q_fail;
		}

		camera_pack_event(filep, MSM_CAMERA_NEW_SESSION, 0, -1, &event);
		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if (rc < 0) {
			pr_err("%s, __dbg: post fail \n", __func__);
			if (qdaemon_task) {
				if (!strncmp(qdaemon_task->comm, QDAEMON, strlen(QDAEMON))) {
					pr_err("%s, kill daemon", __func__);
					send_sig(SIGKILL, qdaemon_task, 0);
					pr_err("%s, kill this", __func__);
					send_sig(SIGKILL, current, 0);
				} else
					pr_err("%s, now (%s : %d)", __func__,
					   qdaemon_task->comm, task_pid_nr(qdaemon_task));
			} else
				pr_err("error!! can't look for daemon");
			goto post_fail;
		}
		rc = camera_check_event_status(&event);
		if (rc < 0) {
			pr_err("%s : camera_check_event_status", __func__);
			goto post_fail;
		}
	} else {
		rc = msm_create_command_ack_q(pvdev->vdev->num,
					      atomic_read(&pvdev->opened));
		if (rc < 0) {
			pr_err("%s : msm_create_command_ack_q", __func__);
			goto session_fail;
		}
	}

	atomic_add(1, &pvdev->opened);
	return rc;

 post_fail:
	msm_delete_command_ack_q(pvdev->vdev->num, 0);
 command_ack_q_fail:
	msm_destroy_session(pvdev->vdev->num);
 session_fail:
	camera_v4l2_vb2_q_release(filep);
 vb2_q_fail:
	camera_v4l2_fh_release(filep);
 fh_open_fail:
	return rc;
}
static int camera_v4l2_open(struct file *filep)
{
	int rc = 0;
	struct v4l2_event event;
	struct msm_video_device *pvdev = video_drvdata(filep);
	BUG_ON(!pvdev);

	rc = camera_v4l2_fh_open(filep);

	if (rc < 0) {
		pr_err("%s : camera_v4l2_fh_open failed Line %d rc %d\n",
				__func__, __LINE__, rc);
		goto fh_open_fail;
	}
	/* every stream has a vb2 queue */
	rc = camera_v4l2_vb2_q_init(filep);

	if (rc < 0) {
		pr_err("%s : vb2 queue init fails Line %d rc %d\n",
				__func__, __LINE__, rc);
		goto vb2_q_fail;
	}
	if (!atomic_read(&pvdev->opened)) {
		pm_stay_awake(&pvdev->vdev->dev);

		/* create a new session when first opened */
		rc = msm_create_session(pvdev->vdev->num, pvdev->vdev);
		if (rc < 0) {
			pr_err("%s : session creation failed Line %d rc %d\n",
					__func__, __LINE__, rc);
			goto session_fail;
		}
		rc = msm_create_command_ack_q(pvdev->vdev->num, 0);

		if (rc < 0) {
			pr_err("%s : creation of command_ack queue failed\n",
					__func__);
			pr_err("%s : Line %d rc %d\n", __func__, __LINE__, rc);
			goto command_ack_q_fail;
		}
		camera_pack_event(filep, MSM_CAMERA_NEW_SESSION, 0, -1, &event);
		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if (rc < 0) {
			pr_err("%s : posting of NEW_SESSION event failed\n",
					__func__);
			pr_err("%s : Line %d rc %d\n", __func__, __LINE__, rc);
			goto post_fail;
		}
		rc = camera_check_event_status(&event);
		if (rc < 0) {
			pr_err("%s : checking event status fails Line %d rc %d\n",
					__func__, __LINE__, rc);
			goto post_fail;
		}
	} else {
		rc = msm_create_command_ack_q(pvdev->vdev->num,
			atomic_read(&pvdev->stream_cnt));
		if (rc < 0) {
			pr_err("%s : creation of command_ack queue failed Line %d rc %d\n",
					__func__, __LINE__, rc);
			goto session_fail;
		}
	}

	atomic_add(1, &pvdev->opened);
	atomic_add(1, &pvdev->stream_cnt);
	return rc;

post_fail:
	msm_delete_command_ack_q(pvdev->vdev->num, 0);
command_ack_q_fail:
	msm_destroy_session(pvdev->vdev->num);
session_fail:
	pm_relax(&pvdev->vdev->dev);
	camera_v4l2_vb2_q_release(filep);
vb2_q_fail:
	camera_v4l2_fh_release(filep);
fh_open_fail:
	return rc;
}
static int camera_v4l2_open(struct file *filep)
{
	int rc = 0;
	struct v4l2_event event;
	struct msm_video_device *pvdev = video_drvdata(filep);
	unsigned int opn_idx, idx;
	BUG_ON(!pvdev);

	rc = camera_v4l2_fh_open(filep);
	if (rc < 0) {
		pr_err("%s : camera_v4l2_fh_open failed Line %d rc %d\n",
				__func__, __LINE__, rc);
		goto fh_open_fail;
	}

	opn_idx = atomic_read(&pvdev->opened);
	idx = opn_idx;
	/* every stream has a vb2 queue */
	rc = camera_v4l2_vb2_q_init(filep);
	if (rc < 0) {
		pr_err("%s : vb2 queue init fails Line %d rc %d\n",
				__func__, __LINE__, rc);
		goto vb2_q_fail;
	}

	if (!atomic_read(&pvdev->opened)) {
		pm_stay_awake(&pvdev->vdev->dev);

		/* Disable power collapse latency */
		msm_pm_qos_update_request(CAMERA_DISABLE_PC_LATENCY);

		/* create a new session when first opened */
		rc = msm_create_session(pvdev->vdev->num, pvdev->vdev);
		if (rc < 0) {
			pr_err("%s : session creation failed Line %d rc %d\n",
					__func__, __LINE__, rc);
			goto session_fail;
		}

		rc = msm_create_command_ack_q(pvdev->vdev->num,
			find_first_zero_bit((const unsigned long *)&opn_idx,
				MSM_CAMERA_STREAM_CNT_BITS));
		if (rc < 0) {
			pr_err("%s : creation of command_ack queue failed\n",
					__func__);
			pr_err("%s : Line %d rc %d\n", __func__, __LINE__, rc);
			goto command_ack_q_fail;
		}

		camera_pack_event(filep, MSM_CAMERA_NEW_SESSION, 0, -1, &event);
		rc = msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		if (rc < 0) {
			pr_err("%s : posting of NEW_SESSION event failed\n",
					__func__);
			pr_err("%s : Line %d rc %d\n", __func__, __LINE__, rc);
			goto post_fail;
		}

		rc = camera_check_event_status(&event);
		if (rc < 0) {
			pr_err("%s : checking event status fails Line %d rc %d\n",
					__func__, __LINE__, rc);
			goto post_fail;
		}
	} else {
		rc = msm_create_command_ack_q(pvdev->vdev->num,
			find_first_zero_bit((const unsigned long *)&opn_idx,
				MSM_CAMERA_STREAM_CNT_BITS));
		if (rc < 0) {
			pr_err("%s : creation of command_ack queue failed Line %d rc %d\n",
					__func__, __LINE__, rc);
			goto session_fail;
		}
	}
	idx |= (1 << find_first_zero_bit((const unsigned long *)&opn_idx,
				MSM_CAMERA_STREAM_CNT_BITS));
	atomic_cmpxchg(&pvdev->opened, opn_idx, idx);
	return rc;

post_fail:
	msm_delete_command_ack_q(pvdev->vdev->num, 0);
command_ack_q_fail:
	msm_destroy_session(pvdev->vdev->num);
session_fail:
	pm_relax(&pvdev->vdev->dev);
	camera_v4l2_vb2_q_release(filep);
vb2_q_fail:
	camera_v4l2_fh_release(filep);
fh_open_fail:
	return rc;
}
Exemplo n.º 22
0
static int camera_v4l2_close(struct file *filep)
{
	int rc = 0;
	struct v4l2_event event;
	struct msm_video_device *pvdev = video_drvdata(filep);
	struct camera_v4l2_private *sp = fh_to_private(filep->private_data);
	unsigned int opn_idx, mask;
        struct msm_session *session;
	BUG_ON(!pvdev);
        session = msm_session_find(pvdev->vdev->num);
        if (WARN_ON(!session))
                return -EIO;

	opn_idx = atomic_read(&pvdev->opened);
	pr_info("[CAM]%s: close stream_id=%d +\n", __func__, sp->stream_id); 
	pr_debug("%s: close stream_id=%d\n", __func__, sp->stream_id);
	mask = (1 << sp->stream_id);
	opn_idx &= ~mask;
	atomic_set(&pvdev->opened, opn_idx);

	if (atomic_read(&pvdev->opened) == 0) {

                mutex_lock(&session->close_lock);
		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);
		pr_info("[CAM]%s: + MSM_CAMERA_PRIV_DEL_STREAM 1\n", __func__); 
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		pr_info("[CAM]%s: -\n", __func__); 

		camera_pack_event(filep, MSM_CAMERA_DEL_SESSION, 0, -1, &event);
		pr_info("[CAM]%s: + MSM_CAMERA_DEL_SESSION 2\n", __func__); 
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		pr_info("[CAM]%s: -\n", __func__); 

		msm_delete_command_ack_q(pvdev->vdev->num, 0);
                mutex_unlock(&session->close_lock);
		pr_info("[CAM]%s: msm_delete_command_ack_q done\n", __func__); 
		camera_v4l2_vb2_q_release(filep);
		pr_info("[CAM]%s: camera_v4l2_vb2_q_release done\n", __func__); 
		msm_destroy_session(pvdev->vdev->num);
		pr_info("[CAM]%s: msm_destroy_session done\n", __func__); 
		pm_relax(&pvdev->vdev->dev);
		pr_info("[CAM]%s: pm_relax done\n", __func__); 
	} else {
                mutex_lock(&session->close_lock);
		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);
		pr_info("[CAM]%s: + MSM_CAMERA_PRIV_DEL_STREAM\n", __func__); 
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
		pr_info("[CAM]%s: -\n", __func__); 

		msm_delete_command_ack_q(pvdev->vdev->num,
			sp->stream_id);
		camera_v4l2_vb2_q_release(filep);
		msm_delete_stream(pvdev->vdev->num, sp->stream_id);
                mutex_unlock(&session->close_lock);
	}

	camera_v4l2_fh_release(filep);
	pr_info("[CAM]%s: close -\n", __func__); 
	return rc;
}