@@ -468,7 +468,8 @@ static const struct mt9m114_format_info mt9m114_format_infos[] = {
/* Keep the format compatible with the IFP sink pad last. */
.code = MEDIA_BUS_FMT_SGRBG10_1X10,
.output_format = MT9M114_CAM_OUTPUT_FORMAT_BAYER_FORMAT_RAWR10
- | MT9M114_CAM_OUTPUT_FORMAT_FORMAT_BAYER,
+ | MT9M114_CAM_OUTPUT_FORMAT_FORMAT_BAYER
+ | MT9M114_CAM_OUTPUT_FORMAT_BT656_CROP_SCALE_DISABLE,
.flags = MT9M114_FMT_FLAG_PARALLEL | MT9M114_FMT_FLAG_CSI2,
}
};
@@ -796,7 +797,7 @@ static int mt9m114_configure(struct mt9m114 *sensor,
const struct v4l2_mbus_framefmt *ifp_format;
const struct v4l2_rect *ifp_crop;
const struct v4l2_rect *ifp_compose;
- unsigned int hratio, vratio;
+ unsigned int border, hratio, vratio;
u64 output_format;
u64 read_mode;
int ret = 0;
@@ -856,10 +857,12 @@ static int mt9m114_configure(struct mt9m114 *sensor,
* by demosaicing that are taken into account in the crop rectangle but
* not in the hardware.
*/
+ border = (ifp_format->code == MEDIA_BUS_FMT_SGRBG10_1X10) ? 0 : 4;
+
cci_write(sensor->regmap, MT9M114_CAM_CROP_WINDOW_XOFFSET,
- ifp_crop->left - 4, &ret);
+ ifp_crop->left - border, &ret);
cci_write(sensor->regmap, MT9M114_CAM_CROP_WINDOW_YOFFSET,
- ifp_crop->top - 4, &ret);
+ ifp_crop->top - border, &ret);
cci_write(sensor->regmap, MT9M114_CAM_CROP_WINDOW_WIDTH,
ifp_crop->width, &ret);
cci_write(sensor->regmap, MT9M114_CAM_CROP_WINDOW_HEIGHT,
@@ -898,7 +901,8 @@ static int mt9m114_configure(struct mt9m114 *sensor,
MT9M114_CAM_OUTPUT_FORMAT_BAYER_FORMAT_MASK |
MT9M114_CAM_OUTPUT_FORMAT_FORMAT_MASK |
MT9M114_CAM_OUTPUT_FORMAT_SWAP_BYTES |
- MT9M114_CAM_OUTPUT_FORMAT_SWAP_RED_BLUE);
+ MT9M114_CAM_OUTPUT_FORMAT_SWAP_RED_BLUE |
+ MT9M114_CAM_OUTPUT_FORMAT_BT656_CROP_SCALE_DISABLE);
output_format |= ifp_info->output_format;
cci_write(sensor->regmap, MT9M114_CAM_OUTPUT_FORMAT,
@@ -1805,6 +1809,7 @@ static int mt9m114_ifp_set_fmt(struct v4l2_subdev *sd,
{
struct mt9m114 *sensor = ifp_to_mt9m114(sd);
struct v4l2_mbus_framefmt *format;
+ struct v4l2_rect *crop;
format = v4l2_subdev_state_get_format(state, fmt->pad);
@@ -1825,8 +1830,15 @@ static int mt9m114_ifp_set_fmt(struct v4l2_subdev *sd,
format->code = info->code;
/* If the output format is RAW10, bypass the scaler. */
- if (format->code == MEDIA_BUS_FMT_SGRBG10_1X10)
+ if (format->code == MEDIA_BUS_FMT_SGRBG10_1X10) {
*format = *v4l2_subdev_state_get_format(state, 0);
+ crop = v4l2_subdev_state_get_crop(state, 0);
+ crop->left = 0;
+ crop->top = 0;
+ crop->width = format->width;
+ crop->height = format->height;
+ *v4l2_subdev_state_get_compose(state, 0) = *crop;
+ }
}
fmt->format = *format;
@@ -1846,6 +1858,10 @@ static int mt9m114_ifp_get_selection(struct v4l2_subdev *sd,
if (sel->pad != 0)
return -EINVAL;
+ /* Crop and compose are not supported when bypassing the scaler */
+ if (v4l2_subdev_state_get_format(state, 1)->code == MEDIA_BUS_FMT_SGRBG10_1X10)
+ return -EINVAL;
+
switch (sel->target) {
case V4L2_SEL_TGT_CROP:
sel->r = *v4l2_subdev_state_get_crop(state, 0);
@@ -1906,6 +1922,10 @@ static int mt9m114_ifp_set_selection(struct v4l2_subdev *sd,
if (sel->pad != 0)
return -EINVAL;
+ /* Crop and compose cannot be changed when bypassing the scaler */
+ if (v4l2_subdev_state_get_format(state, 1)->code == MEDIA_BUS_FMT_SGRBG10_1X10)
+ return -EINVAL;
+
format = v4l2_subdev_state_get_format(state, 0);
crop = v4l2_subdev_state_get_crop(state, 0);
compose = v4l2_subdev_state_get_compose(state, 0);
As indicated by the comment in mt9m114_ifp_set_fmt(): /* If the output format is RAW10, bypass the scaler. */ if (format->code == MEDIA_BUS_FMT_SGRBG10_1X10) ... The intend of the driver is that the scalar is bypassed when the ISP source/output pad's pixel-format is set to MEDIA_BUS_FMT_SGRBG10_1X10. This patch makes 2 changes which are required to get this to work properly: 1. Set the MT9M114_CAM_OUTPUT_FORMAT_BT656_CROP_SCALE_DISABLE bit in the MT9M114_CAM_OUTPUT_FORMAT register. 2. Disable cropping/composing by setting crop and compose selections on the ISP sink/input format to the format widthxheight @ 0x0. Signed-off-by: Hans de Goede <hdegoede@redhat.com> --- drivers/media/i2c/mt9m114.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)