brcm2708: add kernel 4.14 support
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.14 / 950-0326-tc358743-fix-connected-active-CSI-2-lane-reporting.patch
1 From 39770203c368829b4ddb8b01a68870cc336abc41 Mon Sep 17 00:00:00 2001
2 From: Philipp Zabel <p.zabel@pengutronix.de>
3 Date: Thu, 21 Sep 2017 17:30:24 +0200
4 Subject: [PATCH 326/454] tc358743: fix connected/active CSI-2 lane reporting
5
6 g_mbus_config was supposed to indicate all supported lane numbers, not
7 only the number of those currently in active use. Since the TC358743
8 can dynamically reduce the number of active lanes if the required
9 bandwidth allows for it, report all lane numbers up to the connected
10 number of lanes as supported in pdata mode.
11 In device tree mode, do not report lane count and clock mode at all, as
12 the receiver driver can determine these from the device tree.
13
14 To allow communicating the number of currently active lanes, add a new
15 bitfield to the v4l2_mbus_config flags. This is a temporary fix, to be
16 used only until a better solution is found.
17
18 Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
19 ---
20 drivers/media/i2c/tc358743.c | 30 ++++++++++++++++--------------
21 include/media/v4l2-mediabus.h | 8 ++++++++
22 2 files changed, 24 insertions(+), 14 deletions(-)
23
24 --- a/drivers/media/i2c/tc358743.c
25 +++ b/drivers/media/i2c/tc358743.c
26 @@ -1458,28 +1458,29 @@ static int tc358743_g_mbus_config(struct
27 struct v4l2_mbus_config *cfg)
28 {
29 struct tc358743_state *state = to_state(sd);
30 + const u32 mask = V4L2_MBUS_CSI2_LANE_MASK;
31 +
32 + if (state->csi_lanes_in_use > state->bus.num_data_lanes)
33 + return -EINVAL;
34
35 cfg->type = V4L2_MBUS_CSI2;
36 + cfg->flags = (state->csi_lanes_in_use << __ffs(mask)) & mask;
37 +
38 + /* In DT mode, only report the number of active lanes */
39 + if (sd->dev->of_node)
40 + return 0;
41
42 - /* Support for non-continuous CSI-2 clock is missing in the driver */
43 - cfg->flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
44 + /* Support for non-continuous CSI-2 clock is missing in pdata mode */
45 + cfg->flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
46
47 - switch (state->csi_lanes_in_use) {
48 - case 1:
49 + if (state->bus.num_data_lanes > 0)
50 cfg->flags |= V4L2_MBUS_CSI2_1_LANE;
51 - break;
52 - case 2:
53 + if (state->bus.num_data_lanes > 1)
54 cfg->flags |= V4L2_MBUS_CSI2_2_LANE;
55 - break;
56 - case 3:
57 + if (state->bus.num_data_lanes > 2)
58 cfg->flags |= V4L2_MBUS_CSI2_3_LANE;
59 - break;
60 - case 4:
61 + if (state->bus.num_data_lanes > 3)
62 cfg->flags |= V4L2_MBUS_CSI2_4_LANE;
63 - break;
64 - default:
65 - return -EINVAL;
66 - }
67
68 return 0;
69 }
70 @@ -1885,6 +1886,7 @@ static int tc358743_probe(struct i2c_cli
71 if (pdata) {
72 state->pdata = *pdata;
73 state->bus.flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
74 + state->bus.num_data_lanes = 4;
75 } else {
76 err = tc358743_probe_of(state);
77 if (err == -ENODEV)
78 --- a/include/media/v4l2-mediabus.h
79 +++ b/include/media/v4l2-mediabus.h
80 @@ -63,6 +63,14 @@
81 V4L2_MBUS_CSI2_3_LANE | V4L2_MBUS_CSI2_4_LANE)
82 #define V4L2_MBUS_CSI2_CHANNELS (V4L2_MBUS_CSI2_CHANNEL_0 | V4L2_MBUS_CSI2_CHANNEL_1 | \
83 V4L2_MBUS_CSI2_CHANNEL_2 | V4L2_MBUS_CSI2_CHANNEL_3)
84 +/*
85 + * Number of lanes in use, 0 == use all available lanes (default)
86 + *
87 + * This is a temporary fix for devices that need to reduce the number of active
88 + * lanes for certain modes, until g_mbus_config() can be replaced with a better
89 + * solution.
90 + */
91 +#define V4L2_MBUS_CSI2_LANE_MASK (0xf << 10)
92
93 /**
94 * enum v4l2_mbus_type - media bus type