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