Commit 9ace178d authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab
Browse files

media: atomisp: atomisp_ioctl.c: get rid of a ISP2400/ISP2401 dependency



Replace #ifdef occurrences there with runtime checks.

Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 643405b0
Loading
Loading
Loading
Loading
+138 −167
Original line number Diff line number Diff line
@@ -574,6 +574,7 @@ static int atomisp_enum_input(struct file *file, void *fh,
	struct video_device *vdev = video_devdata(file);
	struct atomisp_device *isp = video_get_drvdata(vdev);
	int index = input->index;
	struct v4l2_subdev *motor;

	if (index >= isp->input_cnt)
		return -EINVAL;
@@ -591,24 +592,19 @@ static int atomisp_enum_input(struct file *file, void *fh,
	 * ioctl is the only way to enum inputs + possible external actuators
	 * for 3A tuning purpose.
	 */
#ifndef ISP2401
	if (isp->inputs[index].motor &&
	    strlen(isp->inputs[index].motor->name) > 0) {
#else
	if (isp->motor &&
	    strlen(isp->motor->name) > 0) {
#endif
	if (!atomisp_hw_is_isp2401)
		motor = isp->inputs[index].motor;
	else
		motor = isp->motor;

	if (motor && strlen(motor->name) > 0) {
		const int cur_len = strlen(input->name);
		const int max_size = sizeof(input->name) - cur_len - 1;

		if (max_size > 1) {
			input->name[cur_len] = '+';
			strncpy(&input->name[cur_len + 1],
#ifndef ISP2401
				isp->inputs[index].motor->name, max_size - 1);
#else
				isp->motor->name, max_size - 1);
#endif
				motor->name, max_size - 1);
		}
	}

@@ -677,6 +673,7 @@ static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
	struct atomisp_device *isp = video_get_drvdata(vdev);
	struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
	struct v4l2_subdev *camera = NULL;
	struct v4l2_subdev *motor;
	int ret;

	rt_mutex_lock(&isp->mutex);
@@ -745,17 +742,16 @@ static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
		goto error;
	}

#ifndef ISP2401
	if (!isp->sw_contex.file_input && isp->inputs[input].motor)
		ret = v4l2_subdev_call(isp->inputs[input].motor, core,
				       init, 1);
#else
	if (isp->motor)
		ret = v4l2_subdev_call(isp->motor, core, s_power, 1);
	if (!atomisp_hw_is_isp2401) {
		motor = isp->inputs[input].motor;
	} else {
		motor = isp->motor;
		if (motor)
			ret = v4l2_subdev_call(motor, core, s_power, 1);
	}

	if (!isp->sw_contex.file_input && isp->motor)
		ret = v4l2_subdev_call(isp->motor, core, init, 1);
#endif
	if (!isp->sw_contex.file_input && motor)
		ret = v4l2_subdev_call(motor, core, init, 1);

	asd->input_curr = input;
	/* mark this camera is used by the current stream */
@@ -1218,12 +1214,13 @@ static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
		}

		attributes.pgnr = pgnr;
		attributes.type = HRT_USR_PTR;
#ifdef CONFIG_ION
#ifndef ISP2401
		attributes.type = buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_ION
				  ? HRT_USR_ION : HRT_USR_PTR;
#else
		if (buf->reserved & ATOMISP_BUFFER_TYPE_IS_ION) {
		if (!atomisp_hw_is_isp2401) {
			if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_ION)
					attributes.type = HRT_USR_ION;
		} else {
			if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_ION) {
				attributes.type = HRT_USR_ION;
				if (asd->ion_dev_fd->val !=  ION_FD_UNSET) {
					dev_dbg(isp->dev, "ION buffer queued, share_fd=%lddev_fd=%d.\n",
@@ -1249,12 +1246,8 @@ static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
					ret = -EINVAL;
					goto error;
				}
		} else {
			attributes.type = HRT_USR_PTR;
			}
#endif
#else
		attributes.type = HRT_USR_PTR;
		}
#endif
		ret = atomisp_css_frame_map(&handle, &frame_info,
					    (void __user *)buf->m.userptr,
@@ -1315,14 +1308,14 @@ static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
		} else {
			atomisp_qbuffers_to_css(asd);

#ifndef ISP2401
			if (!atomisp_hw_is_isp2401) {
				if (!atomisp_is_wdt_running(asd) && atomisp_buffers_queued(asd))
					atomisp_wdt_start(asd);
#else
			} else {
				if (!atomisp_is_wdt_running(pipe) &&
				    atomisp_buffers_queued_pipe(pipe))
				atomisp_wdt_start(pipe);
#endif
					atomisp_wdt_start_pipe(pipe);
			}
		}
	}

@@ -1339,10 +1332,10 @@ static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
	    pipe->capq.streaming &&
	    !asd->enable_raw_buffer_lock->val &&
	    asd->params.offline_parm.num_captures == 1) {
#ifndef ISP2401
		if (!atomisp_hw_is_isp2401) {
			asd->pending_capture_request++;
			dev_dbg(isp->dev, "Add one pending capture request.\n");
#else
		} else {
			if (asd->re_trigger_capture) {
				ret = atomisp_css_offline_capture_configure(asd,
					asd->params.offline_parm.num_captures,
@@ -1357,7 +1350,7 @@ static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
				asd->re_trigger_capture = false;
				dev_dbg(isp->dev, "Add one pending capture request.\n");
			}
#endif
		}
	}
	rt_mutex_unlock(&isp->mutex);

@@ -1612,22 +1605,21 @@ int atomisp_stream_on_master_slave_sensor(struct atomisp_device *isp,
	return 0;
}

/* FIXME! */
#ifndef ISP2401
/* FIXME! ISP2400 */
static void __wdt_on_master_slave_sensor(struct atomisp_device *isp,
				         unsigned int wdt_duration)
#else
static void __wdt_on_master_slave_sensor(struct atomisp_video_pipe *pipe,
	unsigned int wdt_duration,
	bool enable)
#endif
{
#ifndef ISP2401
	if (atomisp_buffers_queued(&isp->asd[0]))
		atomisp_wdt_refresh(&isp->asd[0], wdt_duration);
	if (atomisp_buffers_queued(&isp->asd[1]))
		atomisp_wdt_refresh(&isp->asd[1], wdt_duration);
#else
}

/* FIXME! ISP2401 */
static void __wdt_on_master_slave_sensor_pipe(struct atomisp_video_pipe *pipe,
					      unsigned int wdt_duration,
					      bool enable)
{
	static struct atomisp_video_pipe *pipe0;

	if (enable) {
@@ -1638,7 +1630,6 @@ static void __wdt_on_master_slave_sensor(struct atomisp_video_pipe *pipe,
	} else {
		pipe0 = pipe;
	}
#endif
}

static void atomisp_pause_buffer_event(struct atomisp_device *isp)
@@ -1739,9 +1730,8 @@ static int atomisp_streamon(struct file *file, void *fh,

	/* Reset pending capture request count. */
	asd->pending_capture_request = 0;
#ifdef ISP2401
	if (atomisp_hw_is_isp2401)
		asd->re_trigger_capture = false;
#endif

	if ((atomisp_subdev_streaming_count(asd) > sensor_start_stream) &&
	    (!isp->inputs[asd->input_curr].camera_caps->multi_stream_ctrl)) {
@@ -1882,17 +1872,16 @@ static int atomisp_streamon(struct file *file, void *fh,
			dev_err(isp->dev, "master slave sensor stream on failed!\n");
			goto out;
		}
#ifndef ISP2401
		if (!atomisp_hw_is_isp2401) {
			__wdt_on_master_slave_sensor(isp, wdt_duration);
#else
		__wdt_on_master_slave_sensor(pipe, wdt_duration, true);
#endif
		} else {
			__wdt_on_master_slave_sensor_pipe(pipe, wdt_duration, true);
		}
		goto start_delay_wq;
	} else if (asd->depth_mode->val && (atomisp_streaming_count(isp) <
					    ATOMISP_DEPTH_SENSOR_STREAMON_COUNT)) {
#ifdef ISP2401
		__wdt_on_master_slave_sensor(pipe, wdt_duration, false);
#endif
		if (atomisp_hw_is_isp2401)
			__wdt_on_master_slave_sensor_pipe(pipe, wdt_duration, false);
		goto start_delay_wq;
	}

@@ -1913,13 +1902,13 @@ static int atomisp_streamon(struct file *file, void *fh,
		goto out;
	}

#ifndef ISP2401
	if (!atomisp_hw_is_isp2401) {
		if (atomisp_buffers_queued(asd))
			atomisp_wdt_refresh(asd, wdt_duration);
#else
	} else {
		if (atomisp_buffers_queued_pipe(pipe))
			atomisp_wdt_refresh_pipe(pipe, wdt_duration);
#endif
	}

start_delay_wq:
	if (asd->continuous_mode->val) {
@@ -2372,16 +2361,16 @@ static int atomisp_queryctl(struct file *file, void *fh,
	case V4L2_CID_FOCUS_ABSOLUTE:
	case V4L2_CID_FOCUS_RELATIVE:
	case V4L2_CID_FOCUS_STATUS:
#ifndef ISP2401
		if (!atomisp_hw_is_isp2401) {
			return v4l2_queryctrl(isp->inputs[asd->input_curr].camera->
					    ctrl_handler, qc);
#else
		}
		/* ISP2401 */
		if (isp->motor)
			return v4l2_queryctrl(isp->motor->ctrl_handler, qc);
		else
			return v4l2_queryctrl(isp->inputs[asd->input_curr].
					      camera->ctrl_handler, qc);
#endif
	}

	if (qc->id & V4L2_CTRL_FLAG_NEXT_CTRL)
@@ -2408,10 +2397,16 @@ static int atomisp_camera_g_ext_ctrls(struct file *file, void *fh,
	struct video_device *vdev = video_devdata(file);
	struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
	struct atomisp_device *isp = video_get_drvdata(vdev);
	struct v4l2_subdev *motor;
	struct v4l2_control ctrl;
	int i;
	int ret = 0;

	if (!atomisp_hw_is_isp2401)
		motor = isp->inputs[asd->input_curr].motor;
	else
		motor = isp->motor;

	for (i = 0; i < c->count; i++) {
		ctrl.id = c->controls[i].id;
		ctrl.value = c->controls[i].value;
@@ -2440,23 +2435,8 @@ static int atomisp_camera_g_ext_ctrls(struct file *file, void *fh,
		case V4L2_CID_FOCUS_RELATIVE:
		case V4L2_CID_FOCUS_STATUS:
		case V4L2_CID_FOCUS_AUTO:
#ifndef ISP2401
			if (isp->inputs[asd->input_curr].motor)
#else
			if (isp->motor)
#endif
				ret =
#ifndef ISP2401
				    v4l2_g_ctrl(isp->inputs[asd->input_curr].
						motor->ctrl_handler, &ctrl);
#else
				    v4l2_g_ctrl(isp->motor->ctrl_handler,
						&ctrl);
#endif
			else
				ret =
				    v4l2_g_ctrl(isp->inputs[asd->input_curr].
						camera->ctrl_handler, &ctrl);
			if (motor)
				ret = v4l2_g_ctrl(motor->ctrl_handler, &ctrl);
			break;
		case V4L2_CID_FLASH_STATUS:
		case V4L2_CID_FLASH_INTENSITY:
@@ -2526,10 +2506,17 @@ static int atomisp_camera_s_ext_ctrls(struct file *file, void *fh,
	struct video_device *vdev = video_devdata(file);
	struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
	struct atomisp_device *isp = video_get_drvdata(vdev);
	struct v4l2_subdev *motor;
	struct v4l2_control ctrl;
	int i;
	int ret = 0;


	if (!atomisp_hw_is_isp2401)
		motor = isp->inputs[asd->input_curr].motor;
	else
		motor = isp->motor;

	for (i = 0; i < c->count; i++) {
		struct v4l2_ctrl *ctr;

@@ -2557,19 +2544,9 @@ static int atomisp_camera_s_ext_ctrls(struct file *file, void *fh,
		case V4L2_CID_FOCUS_RELATIVE:
		case V4L2_CID_FOCUS_STATUS:
		case V4L2_CID_FOCUS_AUTO:
#ifndef ISP2401
			if (isp->inputs[asd->input_curr].motor)
#else
			if (isp->motor)
#endif
				ret = v4l2_s_ctrl(NULL,
#ifndef ISP2401
						  isp->inputs[asd->input_curr].
						  motor->ctrl_handler, &ctrl);
#else
						  isp->motor->ctrl_handler,
			if (motor)
				ret = v4l2_s_ctrl(NULL, motor->ctrl_handler,
						  &ctrl);
#endif
			else
				ret = v4l2_s_ctrl(NULL,
						  isp->inputs[asd->input_curr].
@@ -2754,6 +2731,7 @@ static long atomisp_vidioc_default(struct file *file, void *fh,
	struct video_device *vdev = video_devdata(file);
	struct atomisp_device *isp = video_get_drvdata(vdev);
	struct atomisp_sub_device *asd;
	struct v4l2_subdev *motor;
	bool acc_node;
	int err;

@@ -2763,6 +2741,11 @@ static long atomisp_vidioc_default(struct file *file, void *fh,
	else
		asd = atomisp_to_video_pipe(vdev)->asd;

	if (!atomisp_hw_is_isp2401)
		motor = isp->inputs[asd->input_curr].motor;
	else
		motor = isp->motor;

	switch (cmd) {
	case ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA:
	case ATOMISP_IOC_S_EXPOSURE:
@@ -2774,9 +2757,7 @@ static long atomisp_vidioc_default(struct file *file, void *fh,
	case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
	case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
	case ATOMISP_IOC_S_SENSOR_EE_CONFIG:
#ifdef ISP2401
	case ATOMISP_IOC_G_UPDATE_EXPOSURE:
#endif
		/* we do not need take isp->mutex for these IOCTLs */
		break;
	default:
@@ -2784,12 +2765,13 @@ static long atomisp_vidioc_default(struct file *file, void *fh,
		break;
	}
	switch (cmd) {
#ifdef ISP2401
	case ATOMISP_IOC_S_SENSOR_RUNMODE:
		if (atomisp_hw_is_isp2401)
			err = atomisp_set_sensor_runmode(asd, arg);
		else
			err = -EINVAL;
		break;

#endif
	case ATOMISP_IOC_G_XNR:
		err = atomisp_xnr(asd, 0, arg);
		break;
@@ -2941,23 +2923,10 @@ static long atomisp_vidioc_default(struct file *file, void *fh,
		break;

	case ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA:
#ifndef ISP2401
		if (isp->inputs[asd->input_curr].motor)
#else
		if (isp->motor)
#endif
#ifndef ISP2401
			err = v4l2_subdev_call(
				  isp->inputs[asd->input_curr].motor,
				  core, ioctl, cmd, arg);
#else
			err = v4l2_subdev_call(
				  isp->motor,
				  core, ioctl, cmd, arg);
#endif
		if (motor)
			err = v4l2_subdev_call(motor, core, ioctl, cmd, arg);
		else
			err = v4l2_subdev_call(
				  isp->inputs[asd->input_curr].camera,
			err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
					       core, ioctl, cmd, arg);
		break;

@@ -2968,11 +2937,15 @@ static long atomisp_vidioc_default(struct file *file, void *fh,
	case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_MODE:
	case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
	case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
#ifdef ISP2401
		err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
				       core, ioctl, cmd, arg);
		break;
	case ATOMISP_IOC_G_UPDATE_EXPOSURE:
#endif
		if (atomisp_hw_is_isp2401)
			err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
					       core, ioctl, cmd, arg);
		else
			err = -EINVAL;
		break;

	case ATOMISP_IOC_ACC_LOAD:
@@ -3085,9 +3058,7 @@ static long atomisp_vidioc_default(struct file *file, void *fh,
	case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_MODE:
	case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
	case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
#ifdef ISP2401
	case ATOMISP_IOC_G_UPDATE_EXPOSURE:
#endif
		break;
	default:
		rt_mutex_unlock(&isp->mutex);
+5 −9
Original line number Diff line number Diff line
@@ -27,15 +27,11 @@ struct atomisp_video_pipe;

extern const struct atomisp_format_bridge atomisp_output_fmts[];

const struct atomisp_format_bridge *atomisp_get_format_bridge(
    unsigned int pixelformat);
#ifndef ISP2401
const struct atomisp_format_bridge *atomisp_get_format_bridge_from_mbus(
    u32 mbus_code);
#else
const struct atomisp_format_bridge *atomisp_get_format_bridge_from_mbus(u32
	mbus_code);
#endif
const struct
atomisp_format_bridge *atomisp_get_format_bridge(unsigned int pixelformat);

const struct
atomisp_format_bridge *atomisp_get_format_bridge_from_mbus(u32 mbus_code);

int atomisp_alloc_css_stat_bufs(struct atomisp_sub_device *asd,
				uint16_t stream_id);