Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6b8ef71c authored by taojiang's avatar taojiang Committed by Gerrit - the friendly Code Review server
Browse files

msm: camera: sensor: add ref count logic for camera sensor subdev



some 3rd-part APP such as Gstreamer will cause sensor probe status
not correct and therefor camera App failed to open camera.
Add v4l2_subdev_intenal_ops open function for camera sensor
for open counter,Do not call internal_ops->close() every time
when call cam_req_mgr_close() so that open/close count for sensor
sub_dev driver can match each other.

CRs-Fixed: 2688114
Change-Id: I46318251e7ce1ed513bb57e0d72f95dfea22a77b
Signed-off-by: default avatartaojiang <taojiang@codeaurora.org>
parent 7a7d224f
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
 */

#include <linux/module.h>
@@ -116,6 +116,7 @@ static int cam_req_mgr_open(struct file *filep)
	spin_unlock_bh(&g_dev.cam_eventq_lock);

	g_dev.open_cnt++;
	CAM_DBG(CAM_CRM, " CRM open cnt %d", g_dev.open_cnt);
	rc = cam_mem_mgr_init();
	if (rc) {
		g_dev.open_cnt--;
@@ -157,13 +158,21 @@ static int cam_req_mgr_close(struct file *filep)

	CAM_WARN(CAM_CRM,
		"release invoked associated userspace process has died");
	mutex_lock(&g_dev.cam_lock);

	mutex_lock(&g_dev.cam_lock);
	if (g_dev.open_cnt <= 0) {
		mutex_unlock(&g_dev.cam_lock);
		return -EINVAL;
	}

	g_dev.open_cnt--;
	CAM_DBG(CAM_CRM, "CRM open_cnt %d", g_dev.open_cnt);

	if (g_dev.open_cnt > 0) {
		mutex_unlock(&g_dev.cam_lock);
		return 0;
	}

	cam_req_mgr_handle_core_shutdown();

	list_for_each_entry(sd, &g_dev.v4l2_dev->subdevs, list) {
@@ -176,7 +185,6 @@ static int cam_req_mgr_close(struct file *filep)
		}
	}

	g_dev.open_cnt--;
	v4l2_fh_release(filep);

	spin_lock_bh(&g_dev.cam_eventq_lock);
+2 −2
Original line number Diff line number Diff line
@@ -817,8 +817,8 @@ int32_t cam_sensor_driver_cmd(struct cam_sensor_ctrl_t *s_ctrl,
		if ((s_ctrl->is_probe_succeed == 0) ||
			(s_ctrl->sensor_state != CAM_SENSOR_INIT)) {
			CAM_WARN(CAM_SENSOR,
				"Not in right state to aquire %d",
				s_ctrl->sensor_state);
				"Not in right state to aquire %d, probe %d",
				s_ctrl->sensor_state, s_ctrl->is_probe_succeed);
			rc = -EINVAL;
			goto release_mutex;
		}
+34 −2
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
 */

#include "cam_sensor_dev.h"
@@ -27,6 +27,26 @@ static long cam_sensor_subdev_ioctl(struct v4l2_subdev *sd,
	return rc;
}

static int cam_sensor_subdev_open(struct v4l2_subdev *sd,
	struct v4l2_subdev_fh *fh)
{
	struct cam_sensor_ctrl_t *s_ctrl =
		v4l2_get_subdevdata(sd);

	if (!s_ctrl) {
		CAM_ERR(CAM_SENSOR, "s_ctrl ptr is NULL");
		return -EINVAL;
	}

	mutex_lock(&(s_ctrl->cam_sensor_mutex));
	s_ctrl->open_cnt++;
	mutex_unlock(&(s_ctrl->cam_sensor_mutex));

	CAM_DBG(CAM_SENSOR, "sensor Subdev open count %d", s_ctrl->open_cnt);

	return 0;
}

static int cam_sensor_subdev_close(struct v4l2_subdev *sd,
	struct v4l2_subdev_fh *fh)
{
@@ -39,6 +59,15 @@ static int cam_sensor_subdev_close(struct v4l2_subdev *sd,
	}

	mutex_lock(&(s_ctrl->cam_sensor_mutex));
	if (s_ctrl->open_cnt <= 0) {
		mutex_unlock(&(s_ctrl->cam_sensor_mutex));
		return -EINVAL;
	}

	s_ctrl->open_cnt--;
	CAM_DBG(CAM_SENSOR, "sensor Subdev open count %d", s_ctrl->open_cnt);

	if (s_ctrl->open_cnt == 0)
		cam_sensor_shutdown(s_ctrl);
	mutex_unlock(&(s_ctrl->cam_sensor_mutex));

@@ -97,6 +126,7 @@ static struct v4l2_subdev_ops cam_sensor_subdev_ops = {
};

static const struct v4l2_subdev_internal_ops cam_sensor_internal_ops = {
	.open  = cam_sensor_subdev_open,
	.close = cam_sensor_subdev_close,
};

@@ -155,6 +185,7 @@ static int32_t cam_sensor_driver_i2c_probe(struct i2c_client *client,
	s_ctrl->of_node = client->dev.of_node;
	s_ctrl->io_master_info.master_type = I2C_MASTER;
	s_ctrl->is_probe_succeed = 0;
	s_ctrl->open_cnt = 0;
	s_ctrl->last_flush_req = 0;

	rc = cam_sensor_parse_dt(s_ctrl);
@@ -283,6 +314,7 @@ static int32_t cam_sensor_driver_platform_probe(
	/* Initialize sensor device type */
	s_ctrl->of_node = pdev->dev.of_node;
	s_ctrl->is_probe_succeed = 0;
	s_ctrl->open_cnt = 0;
	s_ctrl->last_flush_req = 0;

	/*fill in platform device*/
+2 −1
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
 */

#ifndef _CAM_SENSOR_DEV_H_
@@ -111,6 +111,7 @@ struct cam_sensor_ctrl_t {
	bool bob_pwm_switch;
	uint32_t last_flush_req;
	uint16_t pipeline_delay;
	int32_t open_cnt;
};

#endif /* _CAM_SENSOR_DEV_H_ */