1 From 1745cb8447123a894db6c0b579259ec5d976808f Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Thu, 22 Nov 2018 17:31:06 +0000
4 Subject: [PATCH] media: tc358743: Return an appropriate colorspace from
7 When calling tc358743_set_fmt, the code was calling tc358743_get_fmt
8 to choose a valid format. However that sets the colorspace
9 based on what was read back from the chip. When you set the format,
10 then the driver would choose and program the colorspace based
13 The result was that if you called try or set format for UYVY
14 when the current format was RGB3 then you would get told sRGB,
15 and try RGB3 when current was UYVY and you would get told
18 The value programmed into the chip is determined by this driver,
19 therefore there is no need to read back the value. Return the
20 colorspace based on the format set/tried instead.
22 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
24 media: i2c: tc358743: Only allow supported pixel fmts in set_fmt
26 Fix commit "media: tc358743: Return an appropriate colorspace from
27 tc358743_set_fmt" to ensure that the format passed in to set_fmt
28 is checked to be valid, and reset to the current format if not.
30 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
32 drivers/media/i2c/tc358743.c | 44 ++++++++++++++----------------------
33 1 file changed, 17 insertions(+), 27 deletions(-)
35 --- a/drivers/media/i2c/tc358743.c
36 +++ b/drivers/media/i2c/tc358743.c
37 @@ -1677,12 +1677,23 @@ static int tc358743_enum_mbus_code(struc
41 +static u32 tc358743_g_colorspace(u32 code)
44 + case MEDIA_BUS_FMT_RGB888_1X24:
45 + return V4L2_COLORSPACE_SRGB;
46 + case MEDIA_BUS_FMT_UYVY8_1X16:
47 + return V4L2_COLORSPACE_SMPTE170M;
53 static int tc358743_get_fmt(struct v4l2_subdev *sd,
54 struct v4l2_subdev_state *sd_state,
55 struct v4l2_subdev_format *format)
57 struct tc358743_state *state = to_state(sd);
58 - u8 vi_rep = i2c_rd8(sd, VI_REP);
62 @@ -1692,23 +1703,7 @@ static int tc358743_get_fmt(struct v4l2_
63 format->format.height = state->timings.bt.height;
64 format->format.field = V4L2_FIELD_NONE;
66 - switch (vi_rep & MASK_VOUT_COLOR_SEL) {
67 - case MASK_VOUT_COLOR_RGB_FULL:
68 - case MASK_VOUT_COLOR_RGB_LIMITED:
69 - format->format.colorspace = V4L2_COLORSPACE_SRGB;
71 - case MASK_VOUT_COLOR_601_YCBCR_LIMITED:
72 - case MASK_VOUT_COLOR_601_YCBCR_FULL:
73 - format->format.colorspace = V4L2_COLORSPACE_SMPTE170M;
75 - case MASK_VOUT_COLOR_709_YCBCR_FULL:
76 - case MASK_VOUT_COLOR_709_YCBCR_LIMITED:
77 - format->format.colorspace = V4L2_COLORSPACE_REC709;
80 - format->format.colorspace = 0;
83 + format->format.colorspace = tc358743_g_colorspace(format->format.code);
87 @@ -1722,19 +1717,14 @@ static int tc358743_set_fmt(struct v4l2_
88 u32 code = format->format.code; /* is overwritten by get_fmt */
89 int ret = tc358743_get_fmt(sd, sd_state, format);
91 - format->format.code = code;
92 + if (code == MEDIA_BUS_FMT_RGB888_1X24 ||
93 + code == MEDIA_BUS_FMT_UYVY8_1X16)
94 + format->format.code = code;
95 + format->format.colorspace = tc358743_g_colorspace(format->format.code);
101 - case MEDIA_BUS_FMT_RGB888_1X24:
102 - case MEDIA_BUS_FMT_UYVY8_1X16:
108 if (format->which == V4L2_SUBDEV_FORMAT_TRY)