brcm2708: add linux 4.19 support
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.19 / 950-0226-media-tc358743-Return-an-appropriate-colorspace-from.patch
1 From 8f84df14dc88580bfdce95999ab0167d3871ff7c 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 226/703] media: tc358743: Return an appropriate colorspace
5 from tc358743_set_fmt
6
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
11 on the format code.
12
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
16 SMPTE170M.
17
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.
21
22 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
23 ---
24 drivers/media/i2c/tc358743.c | 40 +++++++++++++-----------------------
25 1 file changed, 14 insertions(+), 26 deletions(-)
26
27 --- a/drivers/media/i2c/tc358743.c
28 +++ b/drivers/media/i2c/tc358743.c
29 @@ -1680,12 +1680,23 @@ static int tc358743_enum_mbus_code(struc
30 return 0;
31 }
32
33 +static u32 tc358743_g_colorspace(u32 code)
34 +{
35 + switch (code) {
36 + case MEDIA_BUS_FMT_RGB888_1X24:
37 + return V4L2_COLORSPACE_SRGB;
38 + case MEDIA_BUS_FMT_UYVY8_1X16:
39 + return V4L2_COLORSPACE_SMPTE170M;
40 + default:
41 + return 0;
42 + }
43 +}
44 +
45 static int tc358743_get_fmt(struct v4l2_subdev *sd,
46 struct v4l2_subdev_pad_config *cfg,
47 struct v4l2_subdev_format *format)
48 {
49 struct tc358743_state *state = to_state(sd);
50 - u8 vi_rep = i2c_rd8(sd, VI_REP);
51
52 if (format->pad != 0)
53 return -EINVAL;
54 @@ -1695,23 +1706,7 @@ static int tc358743_get_fmt(struct v4l2_
55 format->format.height = state->timings.bt.height;
56 format->format.field = V4L2_FIELD_NONE;
57
58 - switch (vi_rep & MASK_VOUT_COLOR_SEL) {
59 - case MASK_VOUT_COLOR_RGB_FULL:
60 - case MASK_VOUT_COLOR_RGB_LIMITED:
61 - format->format.colorspace = V4L2_COLORSPACE_SRGB;
62 - break;
63 - case MASK_VOUT_COLOR_601_YCBCR_LIMITED:
64 - case MASK_VOUT_COLOR_601_YCBCR_FULL:
65 - format->format.colorspace = V4L2_COLORSPACE_SMPTE170M;
66 - break;
67 - case MASK_VOUT_COLOR_709_YCBCR_FULL:
68 - case MASK_VOUT_COLOR_709_YCBCR_LIMITED:
69 - format->format.colorspace = V4L2_COLORSPACE_REC709;
70 - break;
71 - default:
72 - format->format.colorspace = 0;
73 - break;
74 - }
75 + format->format.colorspace = tc358743_g_colorspace(format->format.code);
76
77 return 0;
78 }
79 @@ -1726,18 +1721,11 @@ static int tc358743_set_fmt(struct v4l2_
80 int ret = tc358743_get_fmt(sd, cfg, format);
81
82 format->format.code = code;
83 + format->format.colorspace = tc358743_g_colorspace(code);
84
85 if (ret)
86 return ret;
87
88 - switch (code) {
89 - case MEDIA_BUS_FMT_RGB888_1X24:
90 - case MEDIA_BUS_FMT_UYVY8_1X16:
91 - break;
92 - default:
93 - return -EINVAL;
94 - }
95 -
96 if (format->which == V4L2_SUBDEV_FORMAT_TRY)
97 return 0;
98