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;
}
Exemplo n.º 3
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_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.º 5
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;
}
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.º 8
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;
}
Exemplo n.º 9
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;
}