Commit 1e8c2aa9 authored by Hans de Goede's avatar Hans de Goede Committed by Mauro Carvalho Chehab
Browse files

media: atomisp: Add support for sensors with a separate ISP v4l2_subdev



Some sensors have an ISP inside the sensor which the sensor driver models
as a separate v4l2-subdev, like the mt9m114 sensor-driver does.

Since the atomisp driver emulates a standard /dev/video# v4l2-device
without requiring the application to be aware of media-controller centric
/dev/video# devices this requires some special handling in the driver.

Add support for this setup to the atomisp driver.

Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Reviewed-by: default avatarAndy Shevchenko <andy@kernel.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent bceff719
Loading
Loading
Loading
Loading
+31 −5
Original line number Diff line number Diff line
@@ -881,7 +881,8 @@ void atomisp_assert_recovery_work(struct work_struct *work)
	spin_unlock_irqrestore(&isp->lock, flags);

	/* stream off sensor */
	ret = v4l2_subdev_call(isp->inputs[isp->asd.input_curr].sensor, video, s_stream, 0);
	ret = v4l2_subdev_call(isp->inputs[isp->asd.input_curr].csi_remote_source,
			       video, s_stream, 0);
	if (ret)
		dev_warn(isp->dev, "Stopping sensor stream failed: %d\n", ret);

@@ -936,7 +937,8 @@ void atomisp_assert_recovery_work(struct work_struct *work)
	/* Requeue unprocessed per-frame parameters. */
	atomisp_recover_params_queue(&isp->asd.video_out);

	ret = v4l2_subdev_call(isp->inputs[isp->asd.input_curr].sensor, video, s_stream, 1);
	ret = v4l2_subdev_call(isp->inputs[isp->asd.input_curr].csi_remote_source,
			       video, s_stream, 1);
	if (ret)
		dev_err(isp->dev, "Starting sensor stream failed: %d\n", ret);

@@ -3677,7 +3679,7 @@ void atomisp_setup_input_links(struct atomisp_device *isp)
		 * will end up calling atomisp_link_setup() which calls this
		 * function again leading to endless recursion.
		 */
		if (isp->sensor_subdevs[i] == isp->inputs[isp->asd.input_curr].sensor)
		if (isp->sensor_subdevs[i] == isp->inputs[isp->asd.input_curr].csi_remote_source)
			link->flags |= MEDIA_LNK_FL_ENABLED;
		else
			link->flags &= ~MEDIA_LNK_FL_ENABLED;
@@ -3746,14 +3748,38 @@ static int atomisp_set_sensor_crop_and_fmt(struct atomisp_device *isp,
			sel.r.left, sel.r.top, sel.r.width, sel.r.height, ret);

set_fmt:
	if (ret == 0)
	if (ret == 0) {
		ret = v4l2_subdev_call(input->sensor, pad, set_fmt, sd_state, &format);
		dev_dbg(isp->dev, "Set sensor format ret: %d size %dx%d\n",
			ret, format.format.width, format.format.height);
	}

	if (sd_state)
		v4l2_subdev_unlock_state(sd_state);

	/* Propagate new fmt to sensor ISP */
	if (ret == 0 && which == V4L2_SUBDEV_FORMAT_ACTIVE && input->sensor_isp) {
		sd_state = v4l2_subdev_lock_and_get_active_state(input->sensor_isp);

		format.pad = SENSOR_ISP_PAD_SINK;
		ret = v4l2_subdev_call(input->sensor_isp, pad, set_fmt, sd_state, &format);
		dev_dbg(isp->dev, "Set sensor ISP sink format ret: %d size %dx%d\n",
			ret, format.format.width, format.format.height);

		if (ret == 0) {
			format.pad = SENSOR_ISP_PAD_SOURCE;
			ret = v4l2_subdev_call(input->sensor_isp, pad, set_fmt, sd_state, &format);
			dev_dbg(isp->dev, "Set sensor ISP source format ret: %d size %dx%d\n",
				ret, format.format.width, format.format.height);
		}

		if (sd_state)
			v4l2_subdev_unlock_state(sd_state);
	}

	/* Propagate new fmt to CSI port */
	if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
	if (ret == 0 && which == V4L2_SUBDEV_FORMAT_ACTIVE) {
		format.pad = CSI2_PAD_SINK;
		ret = v4l2_subdev_call(input->csi_port, pad, set_fmt, NULL, &format);
		if (ret)
			return ret;
+6 −0
Original line number Diff line number Diff line
@@ -109,6 +109,10 @@
#define DIV_NEAREST_STEP(n, d, step) \
	round_down((2 * (n) + (d) * (step)) / (2 * (d)), (step))

#define SENSOR_ISP_PAD_SINK		0
#define SENSOR_ISP_PAD_SOURCE		1
#define SENSOR_ISP_PADS_NUM		2

struct atomisp_input_subdev {
	enum atomisp_camera_port port;
	u32 code; /* MEDIA_BUS_FMT_* */
@@ -116,7 +120,9 @@ struct atomisp_input_subdev {
	bool crop_support;
	bool sensor_on;
	struct v4l2_subdev *sensor;
	struct v4l2_subdev *sensor_isp;
	struct v4l2_subdev *csi_port;
	struct v4l2_subdev *csi_remote_source;
	/* Sensor rects for sensors which support crop */
	struct v4l2_rect native_rect;
	struct v4l2_rect active_rect;
+3 −3
Original line number Diff line number Diff line
@@ -945,7 +945,7 @@ int atomisp_start_streaming(struct vb2_queue *vq, unsigned int count)
	}

	/* stream on the sensor */
	ret = v4l2_subdev_call(isp->inputs[asd->input_curr].sensor,
	ret = v4l2_subdev_call(isp->inputs[asd->input_curr].csi_remote_source,
			       video, s_stream, 1);
	if (ret) {
		dev_err(isp->dev, "Starting sensor stream failed: %d\n", ret);
@@ -1002,7 +1002,7 @@ void atomisp_stop_streaming(struct vb2_queue *vq)

	atomisp_subdev_cleanup_pending_events(asd);

	ret = v4l2_subdev_call(isp->inputs[asd->input_curr].sensor,
	ret = v4l2_subdev_call(isp->inputs[asd->input_curr].csi_remote_source,
			       video, s_stream, 0);
	if (ret)
		dev_warn(isp->dev, "Stopping sensor stream failed: %d\n", ret);
@@ -1332,7 +1332,7 @@ static int atomisp_s_parm(struct file *file, void *fh,

		fi.interval = parm->parm.capture.timeperframe;

		rval = v4l2_subdev_call_state_active(isp->inputs[asd->input_curr].sensor,
		rval = v4l2_subdev_call_state_active(isp->inputs[asd->input_curr].csi_remote_source,
						     pad, set_frame_interval, &fi);
		if (!rval)
			parm->parm.capture.timeperframe = fi.interval;
+25 −3
Original line number Diff line number Diff line
@@ -999,8 +999,9 @@ static void atomisp_init_sensor(struct atomisp_input_subdev *input)

int atomisp_register_device_nodes(struct atomisp_device *isp)
{
	struct media_pad *sensor_isp_sink, *sensor_src;
	struct atomisp_input_subdev *input;
	int i, err;
	int i, err, source_pad;

	for (i = 0; i < ATOMISP_CAMERA_NR_PORTS; i++) {
		err = media_create_pad_link(&isp->csi2_port[i].subdev.entity,
@@ -1015,12 +1016,33 @@ int atomisp_register_device_nodes(struct atomisp_device *isp)
		input = &isp->inputs[isp->input_cnt];

		input->port = i;
		input->sensor = isp->sensor_subdevs[i];
		input->csi_port = &isp->csi2_port[i].subdev;
		input->csi_remote_source = isp->sensor_subdevs[i];

		/*
		 * Special case for sensors with a ISP in the sensor modelled
		 * as a separate v4l2-subdev, like the mt9m114.
		 */
		if (isp->sensor_subdevs[i]->entity.function == MEDIA_ENT_F_PROC_VIDEO_ISP) {
			input->sensor_isp = isp->sensor_subdevs[i];
			source_pad = SENSOR_ISP_PAD_SOURCE;

			sensor_isp_sink = &input->sensor_isp->entity.pads[SENSOR_ISP_PAD_SINK];
			sensor_src = media_pad_remote_pad_first(sensor_isp_sink);
			if (!sensor_src) {
				dev_err(isp->dev, "Error could not find remote pad for sensor ISP sink\n");
				return -ENOENT;
			}

			input->sensor = media_entity_to_v4l2_subdev(sensor_src->entity);
		} else {
			input->sensor = isp->sensor_subdevs[i];
			source_pad = 0;
		}

		atomisp_init_sensor(input);

		err = media_create_pad_link(&input->sensor->entity, 0,
		err = media_create_pad_link(&isp->sensor_subdevs[i]->entity, source_pad,
					    &isp->csi2_port[i].subdev.entity,
					    CSI2_PAD_SINK,
					    MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);