1 From 94d77466473f3abcf799ac44b8038766ab32f27c Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Wed, 16 Oct 2019 18:53:06 +0100
4 Subject: [PATCH] media: bcm2835-unicam: Fix one-to-many mapping for
7 V4L2 format V4L2_PIX_FMT_YUYV maps to both MEDIA_BUS_FMT_YUYV8_2X8
8 and MEDIA_BUS_FMT_YUYV8_1X16. The change to not cache the active
9 formats also meant that we only ever found the first variant of
10 the mediabus format when trying to setup the device.
12 Flag the formats that have other representations, and ensure
13 that the format conversion checks whether the found format
14 matches one supported by the sensor before returning it.
16 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
18 .../media/platform/bcm2835/bcm2835-unicam.c | 45 ++++++++++++++++---
19 1 file changed, 39 insertions(+), 6 deletions(-)
21 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
22 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
23 @@ -136,6 +136,8 @@ MODULE_PARM_DESC(debug, "Debug level 0-3
24 * @code: V4L2 media bus format code.
25 * @depth: Bits per pixel as delivered from the source.
26 * @csi_dt: CSI data type.
27 + * @check_variants: Flag to denote that there are multiple mediabus formats
28 + * still in the list that could match this V4L2 format.
32 @@ -143,6 +145,7 @@ struct unicam_fmt {
39 static const struct unicam_fmt formats[] = {
40 @@ -152,21 +155,25 @@ static const struct unicam_fmt formats[]
41 .code = MEDIA_BUS_FMT_YUYV8_2X8,
44 + .check_variants = 1,
46 .fourcc = V4L2_PIX_FMT_UYVY,
47 .code = MEDIA_BUS_FMT_UYVY8_2X8,
50 + .check_variants = 1,
52 .fourcc = V4L2_PIX_FMT_YVYU,
53 .code = MEDIA_BUS_FMT_YVYU8_2X8,
56 + .check_variants = 1,
58 .fourcc = V4L2_PIX_FMT_VYUY,
59 .code = MEDIA_BUS_FMT_VYUY8_2X8,
62 + .check_variants = 1,
64 .fourcc = V4L2_PIX_FMT_YUYV,
65 .code = MEDIA_BUS_FMT_YUYV8_1X16,
66 @@ -489,14 +496,40 @@ static const struct unicam_fmt *find_for
70 -static const struct unicam_fmt *find_format_by_pix(u32 pixelformat)
71 +static int check_mbus_format(struct unicam_device *dev,
72 + const struct unicam_fmt *format)
74 + struct v4l2_subdev_mbus_code_enum mbus_code;
78 + for (i = 0; !ret && i < MAX_ENUM_MBUS_CODE; i++) {
79 + memset(&mbus_code, 0, sizeof(mbus_code));
80 + mbus_code.index = i;
82 + ret = v4l2_subdev_call(dev->sensor, pad, enum_mbus_code,
85 + if (!ret && mbus_code.code == format->code)
92 +static const struct unicam_fmt *find_format_by_pix(struct unicam_device *dev,
97 for (k = 0; k < ARRAY_SIZE(formats); k++) {
98 if (formats[k].fourcc == pixelformat ||
99 - formats[k].repacked_fourcc == pixelformat)
100 + formats[k].repacked_fourcc == pixelformat) {
101 + if (formats[k].check_variants &&
102 + !check_mbus_format(dev, &formats[k]))
109 @@ -832,7 +865,7 @@ static int unicam_try_fmt_vid_cap(struct
110 struct v4l2_mbus_framefmt *mbus_fmt = &sd_fmt.format;
113 - fmt = find_format_by_pix(f->fmt.pix.pixelformat);
114 + fmt = find_format_by_pix(dev, f->fmt.pix.pixelformat);
116 /* Pixel format not supported by unicam. Choose the first
117 * supported format, and let the sensor choose something else.
118 @@ -917,7 +950,7 @@ static int unicam_s_fmt_vid_cap(struct f
122 - fmt = find_format_by_pix(f->fmt.pix.pixelformat);
123 + fmt = find_format_by_pix(dev, f->fmt.pix.pixelformat);
125 /* Unknown pixel format - adopt a default.
126 * This shouldn't happen as try_fmt should have resolved any
127 @@ -1540,7 +1573,7 @@ static int unicam_enum_framesizes(struct
130 /* check for valid format */
131 - fmt = find_format_by_pix(fsize->pixel_format);
132 + fmt = find_format_by_pix(dev, fsize->pixel_format);
134 unicam_dbg(3, dev, "Invalid pixel code: %x\n",
135 fsize->pixel_format);
136 @@ -1579,7 +1612,7 @@ static int unicam_enum_frameintervals(st
140 - fmt = find_format_by_pix(fival->pixel_format);
141 + fmt = find_format_by_pix(dev, fival->pixel_format);