1 From 214e8134842a338215831f2efa6d730f413c5ec4 Mon Sep 17 00:00:00 2001
2 From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
3 Date: Fri, 29 Sep 2023 17:15:20 +0300
4 Subject: [PATCH] media: rp1: fe: Fix pisp_fe_pad_set_fmt()
6 pisp_fe_pad_set_fmt() allows setting the pad formats quite freely. This
7 is not correct, and the function should only allow formats as supported
8 by the hardware. Fix this by:
10 Allow no format changes for FE_CONFIG_PAD and FE_STATS_PAD. They should
11 always be the hardcoded initial ones.
13 Allow setting FE_STREAM_PAD freely (but the mbus code must be
14 supported), and propagate the format to the FE_OUTPUT0_PAD and
17 Allow changing the mbus code for FE_OUTPUT0_PAD and FE_OUTPUT1_PAD pads
18 only if the mbus code is the compressed version of the sink side code.
20 TODO: FE supports scaling and cropping. This should be represented here
23 Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
25 .../platform/raspberrypi/rp1_cfe/pisp_fe.c | 59 +++++++++++++++----
26 1 file changed, 48 insertions(+), 11 deletions(-)
28 --- a/drivers/media/platform/raspberrypi/rp1_cfe/pisp_fe.c
29 +++ b/drivers/media/platform/raspberrypi/rp1_cfe/pisp_fe.c
30 @@ -433,26 +433,63 @@ static int pisp_fe_pad_set_fmt(struct v4
32 switch (format->pad) {
34 - case FE_OUTPUT0_PAD:
35 - case FE_OUTPUT1_PAD:
36 cfe_fmt = find_format_by_code(format->format.code);
37 if (!cfe_fmt || !(cfe_fmt->flags & CFE_FORMAT_FLAG_FE_OUT))
38 cfe_fmt = find_format_by_code(MEDIA_BUS_FMT_SRGGB16_1X16);
40 format->format.code = cfe_fmt->code;
41 + format->format.field = V4L2_FIELD_NONE;
44 + fmt = v4l2_subdev_get_pad_format(sd, state, FE_STREAM_PAD);
45 + *fmt = format->format;
49 - format->format.code = MEDIA_BUS_FMT_FIXED;
52 + fmt = v4l2_subdev_get_pad_format(sd, state, FE_OUTPUT0_PAD);
53 + *fmt = format->format;
55 + fmt = v4l2_subdev_get_pad_format(sd, state, FE_OUTPUT1_PAD);
56 + *fmt = format->format;
60 - fmt = v4l2_subdev_get_pad_format(sd, state, format->pad);
61 - *fmt = format->format;
62 + case FE_OUTPUT0_PAD:
63 + case FE_OUTPUT1_PAD: {
65 + * TODO: we should allow scaling and cropping by allowing the
66 + * user to set the size here.
68 + struct v4l2_mbus_framefmt *sink_fmt, *source_fmt;
72 + sink_fmt = v4l2_subdev_get_pad_format(sd, state, FE_STREAM_PAD);
76 + source_fmt = v4l2_subdev_get_pad_format(sd, state, format->pad);
80 + sink_code = sink_fmt->code;
81 + code = format->format.code;
84 + * If the source code from the user does not match the code in
85 + * the sink pad, check that the source code matches the
86 + * compressed version of the sink code.
89 + if (code != sink_code &&
90 + code == cfe_find_compressed_code(sink_code))
91 + source_fmt->code = code;
100 + return v4l2_subdev_get_fmt(sd, state, format);
104 static int pisp_fe_link_validate(struct v4l2_subdev *sd,