1 From 04a0aa6bc230d50a393db7bf4449ddb0c4813212 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Fri, 29 Jul 2022 17:46:49 +0100
4 Subject: [PATCH 0386/1085] media: video-mux: Read CSI2 config from FW, and
7 There is no obligation for all source devices on a video-mux to
8 require the same bus configuration, so read the configuration
9 from the sink ports, and relay via get_mbus_config on the source
11 If the sources support get_mbus_config, then call that first.
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
15 drivers/media/platform/video-mux.c | 73 ++++++++++++++++++++++++++++--
16 1 file changed, 69 insertions(+), 4 deletions(-)
18 --- a/drivers/media/platform/video-mux.c
19 +++ b/drivers/media/platform/video-mux.c
21 #include <media/v4l2-mc.h>
22 #include <media/v4l2-subdev.h>
24 +struct video_mux_asd {
25 + struct v4l2_async_connection base;
29 +static inline struct video_mux_asd *to_video_mux_asd(struct v4l2_async_connection *asd)
31 + return container_of(asd, struct video_mux_asd, base);
34 +struct video_mux_pad_cfg {
35 + unsigned int num_lanes;
36 + bool non_continuous;
37 + struct v4l2_subdev *source;
41 struct v4l2_subdev subdev;
42 struct v4l2_async_notifier notifier;
43 struct media_pad *pads;
44 + struct video_mux_pad_cfg *cfg;
45 struct mux_control *mux;
48 @@ -301,10 +318,34 @@ static int video_mux_init_cfg(struct v4l
52 +static int video_mux_get_mbus_config(struct v4l2_subdev *sd,
54 + struct v4l2_mbus_config *cfg)
56 + struct video_mux *vmux = v4l2_subdev_to_video_mux(sd);
59 + ret = v4l2_subdev_call(vmux->cfg[vmux->active].source, pad, get_mbus_config,
62 + if (ret != -ENOIOCTLCMD)
65 + cfg->type = V4L2_MBUS_CSI2_DPHY;
66 + cfg->bus.mipi_csi2.num_data_lanes = vmux->cfg[vmux->active].num_lanes;
68 + /* Support for non-continuous CSI-2 clock is missing in pdate mode */
69 + if (vmux->cfg[vmux->active].non_continuous)
70 + cfg->bus.mipi_csi2.flags |= V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
75 static const struct v4l2_subdev_pad_ops video_mux_pad_ops = {
76 .init_cfg = video_mux_init_cfg,
77 .get_fmt = v4l2_subdev_get_fmt,
78 .set_fmt = video_mux_set_format,
79 + .get_mbus_config = video_mux_get_mbus_config,
82 static const struct v4l2_subdev_ops video_mux_subdev_ops = {
83 @@ -317,6 +358,9 @@ static int video_mux_notify_bound(struct
84 struct v4l2_async_connection *asd)
86 struct video_mux *vmux = notifier_to_video_mux(notifier);
87 + unsigned int port = to_video_mux_asd(asd)->port;
89 + vmux->cfg[port].source = sd;
91 return v4l2_create_fwnode_links(sd, &vmux->subdev);
93 @@ -334,7 +378,7 @@ static int video_mux_async_register(stru
94 v4l2_async_subdev_nf_init(&vmux->notifier, &vmux->subdev);
96 for (i = 0; i < num_input_pads; i++) {
97 - struct v4l2_async_connection *asd;
98 + struct video_mux_asd *asd;
99 struct fwnode_handle *ep, *remote_ep;
101 ep = fwnode_graph_get_endpoint_by_id(
102 @@ -352,8 +396,7 @@ static int video_mux_async_register(stru
103 fwnode_handle_put(remote_ep);
105 asd = v4l2_async_nf_add_fwnode_remote(&vmux->notifier, ep,
106 - struct v4l2_async_connection);
108 + struct video_mux_asd);
109 fwnode_handle_put(ep);
112 @@ -362,6 +405,8 @@ static int video_mux_async_register(stru
120 vmux->notifier.ops = &video_mux_notify_ops;
121 @@ -387,6 +432,9 @@ static int video_mux_probe(struct platfo
123 struct device_node *np = pdev->dev.of_node;
124 struct device *dev = &pdev->dev;
125 + struct v4l2_fwnode_endpoint fwnode_ep = {
126 + .bus_type = V4L2_MBUS_CSI2_DPHY
128 struct device_node *ep;
129 struct video_mux *vmux;
130 unsigned int num_pads = 0;
131 @@ -433,10 +481,27 @@ static int video_mux_probe(struct platfo
135 - for (i = 0; i < num_pads; i++)
136 + vmux->cfg = devm_kcalloc(dev, num_pads, sizeof(*vmux->cfg), GFP_KERNEL);
140 + for (i = 0; i < num_pads; i++) {
141 vmux->pads[i].flags = (i < num_pads - 1) ? MEDIA_PAD_FL_SINK
142 : MEDIA_PAD_FL_SOURCE;
144 + ep = of_graph_get_endpoint_by_regs(pdev->dev.of_node, i, 0);
146 + ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &fwnode_ep);
148 + /* Get number of data lanes */
149 + vmux->cfg[i].num_lanes = fwnode_ep.bus.mipi_csi2.num_data_lanes;
150 + vmux->cfg[i].non_continuous = fwnode_ep.bus.mipi_csi2.flags &
151 + V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
157 vmux->subdev.entity.function = MEDIA_ENT_F_VID_MUX;
158 ret = media_entity_pads_init(&vmux->subdev.entity, num_pads,