@@ -417,15 +417,18 @@ static void max96712_mipi_configure(struct max96712_priv *priv)
max96712_update_bits(priv, MAX96712_MIPI_PHY_2, PHY_STDBY_N_MASK, PHY0_EN | PHY1_EN);
}
-static void max96712_pattern_enable(struct max96712_priv *priv, bool enable)
+static void max96712_pattern_enable(struct max96712_priv *priv, struct v4l2_subdev_state *state,
+ bool enable)
{
- const u32 h_active = 1920;
+ struct v4l2_mbus_framefmt *fmt = v4l2_subdev_state_get_format(state, MAX96712_VPG_PAD);
+
+ const u32 h_active = fmt->width;
const u32 h_fp = 88;
const u32 h_sw = 44;
const u32 h_bp = 148;
const u32 h_tot = h_active + h_fp + h_sw + h_bp;
- const u32 v_active = 1080;
+ const u32 v_active = fmt->height;
const u32 v_fp = 4;
const u32 v_sw = 5;
const u32 v_bp = 36;
@@ -608,7 +611,7 @@ static int max96712_enable_streams(struct v4l2_subdev *sd,
{
struct max96712_priv *priv = v4l2_get_subdevdata(sd);
- max96712_pattern_enable(priv, true);
+ max96712_pattern_enable(priv, state, true);
max96712_mipi_enable(priv, true);
return 0;
@@ -621,7 +624,7 @@ static int max96712_disable_streams(struct v4l2_subdev *sd,
struct max96712_priv *priv = v4l2_get_subdevdata(sd);
max96712_mipi_enable(priv, false);
- max96712_pattern_enable(priv, false);
+ max96712_pattern_enable(priv, state, false);
return 0;
}
@@ -663,6 +666,48 @@ static int max96712_set_routing(struct v4l2_subdev *sd, struct v4l2_subdev_state
return _max96712_set_routing(sd, state, routing);
}
+static int max96712_set_fmt(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_format *format)
+{
+ struct v4l2_mbus_framefmt *fmt;
+ int i;
+
+ if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE && media_entity_is_streaming(&sd->entity))
+ return -EBUSY;
+
+ /* No transcoding, source and sink formats must match. */
+ if (max96712_pad_is_source(format->pad))
+ return v4l2_subdev_get_fmt(sd, state, format);
+
+ /* Validate the format. */
+ for (i = 0; i < ARRAY_SIZE(max96712_formats); ++i) {
+ if (max96712_formats[i].code == format->format.code)
+ break;
+ }
+
+ if (i == ARRAY_SIZE(max96712_formats))
+ format->format.code = max96712_formats[12].code;
+
+ if (format->pad == MAX96712_VPG_PAD && format->format.code != MEDIA_BUS_FMT_RGB888_1X24)
+ return -EINVAL;
+
+ fmt = v4l2_subdev_state_get_format(state, format->pad, format->stream);
+ if (!fmt)
+ return -EINVAL;
+
+ *fmt = format->format;
+
+ fmt = v4l2_subdev_state_get_opposite_stream_format(state, format->pad,
+ format->stream);
+ if (!fmt)
+ return -EINVAL;
+
+ *fmt = format->format;
+
+ return 0;
+}
+
static int max96712_init_state(struct v4l2_subdev *sd,
struct v4l2_subdev_state *state)
{
@@ -690,7 +735,7 @@ static const struct v4l2_subdev_internal_ops max96712_internal_ops = {
static const struct v4l2_subdev_pad_ops max96712_pad_ops = {
.enum_mbus_code = max96712_enum_mbus_code,
.get_fmt = v4l2_subdev_get_fmt,
- .set_fmt = v4l2_subdev_get_fmt,
+ .set_fmt = max96712_set_fmt,
.enable_streams = max96712_enable_streams,
.disable_streams = max96712_disable_streams,
.set_routing = max96712_set_routing,
Allow apps to change the format of the pads. Also, use the provided width and height when generating the test pattern. Signed-off-by: Laurentiu Palcu <laurentiu.palcu@oss.nxp.com> --- drivers/staging/media/max96712/max96712.c | 57 ++++++++++++++++++++--- 1 file changed, 51 insertions(+), 6 deletions(-)