6f876c4248e828f0221be4ed1574d3933145cfde
[openwrt/staging/rmilecki.git] /
1 From 5bc5749e4350a09d7b76c84513908f35455b25f1 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] 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 | 14 ++++++++++++--
22 include/media/v4l2-mediabus.h | 8 ++++++++
23 2 files changed, 20 insertions(+), 2 deletions(-)
24
25 --- a/drivers/media/i2c/tc358743.c
26 +++ b/drivers/media/i2c/tc358743.c
27 @@ -1609,11 +1609,20 @@ static int tc358743_get_mbus_config(stru
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_DPHY;
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 pdate mode */
46 + cfg->flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
47
48 switch (state->csi_lanes_in_use) {
49 case 1:
50 @@ -2056,6 +2065,7 @@ static int tc358743_probe(struct i2c_cli
51 if (pdata) {
52 state->pdata = *pdata;
53 state->bus.flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
54 + state->bus.num_data_lanes = 4;
55 } else {
56 err = tc358743_probe_of(state);
57 if (err == -ENODEV)
58 --- a/include/media/v4l2-mediabus.h
59 +++ b/include/media/v4l2-mediabus.h
60 @@ -92,6 +92,14 @@
61 V4L2_MBUS_CSI2_CHANNEL_1 | \
62 V4L2_MBUS_CSI2_CHANNEL_2 | \
63 V4L2_MBUS_CSI2_CHANNEL_3)
64 +/*
65 + * Number of lanes in use, 0 == use all available lanes (default)
66 + *
67 + * This is a temporary fix for devices that need to reduce the number of active
68 + * lanes for certain modes, until g_mbus_config() can be replaced with a better
69 + * solution.
70 + */
71 +#define V4L2_MBUS_CSI2_LANE_MASK (0xf << 10)
72
73 /**
74 * enum v4l2_mbus_type - media bus type