The size of the format on the source pad of the pixel array, and on the source pad of the sub-device that is the source of the CSI-2 bus, is that of the crop rectangle on the same pad: the analogue crop of the pixel array and the digital crop at the end of the pipeline, respectively. The format was only initialised from the pixel array size or the compose rectangle and never updated when the crop was set, so after setting such a crop the format did not match what the sensor outputs. As the format of a source pad can not be set from user space, and the format of the sink pad it is linked to has to match it, link validation fails with -EPIPE for any crop other than the full area. Update the size of the format when the crop is set. As the size of the pixel array format is then no longer its native size, use the native size as the bounds for its crop. Fixes: d8bca3ed1d70 ("media: ccs: Use sub-device active state") Cc: stable@vger.kernel.org Signed-off-by: Gianluca Boiano --- drivers/media/i2c/ccs/ccs-core.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/ccs/ccs-core.c b/drivers/media/i2c/ccs/ccs-core.c index a4af27de5..acea07d90 100644 --- a/drivers/media/i2c/ccs/ccs-core.c +++ b/drivers/media/i2c/ccs/ccs-core.c @@ -2541,6 +2541,14 @@ static int ccs_sel_supported(struct v4l2_subdev *subdev, } } +static void ccs_get_native_size(struct ccs_subdev *ssd, struct v4l2_rect *r) +{ + r->top = 0; + r->left = 0; + r->width = CCS_LIM(ssd->sensor, X_ADDR_MAX) + 1; + r->height = CCS_LIM(ssd->sensor, Y_ADDR_MAX) + 1; +} + static int ccs_set_crop(struct v4l2_subdev *subdev, const struct v4l2_subdev_client_info *ci, struct v4l2_subdev_state *sd_state, @@ -2556,7 +2564,9 @@ static int ccs_set_crop(struct v4l2_subdev *subdev, comp = v4l2_subdev_state_get_compose(sd_state, ssd->sink_pad, CCS_STREAM_PIXEL); - if (sel->pad == ssd->sink_pad) { + if (ssd == sensor->pixel_array) { + ccs_get_native_size(ssd, &src_size); + } else if (sel->pad == ssd->sink_pad) { struct v4l2_mbus_framefmt *mfmt = v4l2_subdev_state_get_format(sd_state, sel->pad); @@ -2579,20 +2589,21 @@ static int ccs_set_crop(struct v4l2_subdev *subdev, *crop = sel->r; - if (ssd != sensor->pixel_array && sel->pad == CCS_PAD_SINK) + if (sel->pad == ssd->source_pad) { + struct v4l2_mbus_framefmt *fmt = + v4l2_subdev_state_get_format(sd_state, sel->pad, + CCS_STREAM_PIXEL); + + /* The size of the source pad format is that of the crop. */ + fmt->width = crop->width; + fmt->height = crop->height; + } else { ccs_propagate(subdev, sd_state, V4L2_SEL_TGT_CROP); + } return 0; } -static void ccs_get_native_size(struct ccs_subdev *ssd, struct v4l2_rect *r) -{ - r->top = 0; - r->left = 0; - r->width = CCS_LIM(ssd->sensor, X_ADDR_MAX) + 1; - r->height = CCS_LIM(ssd->sensor, Y_ADDR_MAX) + 1; -} - static int ccs_get_selection(struct v4l2_subdev *subdev, const struct v4l2_subdev_client_info *ci, struct v4l2_subdev_state *sd_state, -- 2.56.1