bcm27xx: update 6.1 patches to latest version
[openwrt/staging/dangole.git] / target / linux / bcm27xx / patches-6.1 / 950-1205-media-rp1-fe-Fix-pisp_fe_pad_set_fmt.patch
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()
5
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:
9
10 Allow no format changes for FE_CONFIG_PAD and FE_STATS_PAD. They should
11 always be the hardcoded initial ones.
12
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
15 FE_OUTPUT1_PAD pads.
16
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.
19
20 TODO: FE supports scaling and cropping. This should be represented here
21 too?
22
23 Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
24 ---
25 .../platform/raspberrypi/rp1_cfe/pisp_fe.c | 59 +++++++++++++++----
26 1 file changed, 48 insertions(+), 11 deletions(-)
27
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
31
32 switch (format->pad) {
33 case FE_STREAM_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);
39
40 format->format.code = cfe_fmt->code;
41 + format->format.field = V4L2_FIELD_NONE;
42
43 - break;
44 + fmt = v4l2_subdev_get_pad_format(sd, state, FE_STREAM_PAD);
45 + *fmt = format->format;
46
47 - case FE_STATS_PAD:
48 - case FE_CONFIG_PAD:
49 - format->format.code = MEDIA_BUS_FMT_FIXED;
50 - break;
51 - }
52 + fmt = v4l2_subdev_get_pad_format(sd, state, FE_OUTPUT0_PAD);
53 + *fmt = format->format;
54 +
55 + fmt = v4l2_subdev_get_pad_format(sd, state, FE_OUTPUT1_PAD);
56 + *fmt = format->format;
57 +
58 + return 0;
59
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: {
64 + /*
65 + * TODO: we should allow scaling and cropping by allowing the
66 + * user to set the size here.
67 + */
68 + struct v4l2_mbus_framefmt *sink_fmt, *source_fmt;
69 + u32 sink_code;
70 + u32 code;
71 +
72 + sink_fmt = v4l2_subdev_get_pad_format(sd, state, FE_STREAM_PAD);
73 + if (!sink_fmt)
74 + return -EINVAL;
75 +
76 + source_fmt = v4l2_subdev_get_pad_format(sd, state, format->pad);
77 + if (!source_fmt)
78 + return -EINVAL;
79 +
80 + sink_code = sink_fmt->code;
81 + code = format->format.code;
82 +
83 + /*
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.
87 + */
88 +
89 + if (code != sink_code &&
90 + code == cfe_find_compressed_code(sink_code))
91 + source_fmt->code = code;
92 +
93 + return 0;
94 + }
95
96 - return 0;
97 + case FE_CONFIG_PAD:
98 + case FE_STATS_PAD:
99 + default:
100 + return v4l2_subdev_get_fmt(sd, state, format);
101 + }
102 }
103
104 static int pisp_fe_link_validate(struct v4l2_subdev *sd,