1 From 2ccd080392adfb1f077f2f4d289651b6b15e0951 Mon Sep 17 00:00:00 2001
2 From: Kevin Quigley <kevin@kquigley.co.uk>
3 Date: Mon, 24 Sep 2018 18:09:52 +0000
4 Subject: [PATCH 3/4] drm/vc4: Set up the DSI host at pdev probe time, not
5 component bind. bring https://patchwork.kernel.org/patch/9902623/ to Linux
8 We need the following things to happen in sequence:
11 DSI device creation in the panel driver (needs DSI host)
12 DSI device attach from panel to host.
15 DSI encoder's DRM panel/bridge attach
17 Unless we allow device creation while the host isn't up yet, we need
18 to break the -EPROBE_DEFER deadlock between the panel driver looking
19 up the host and the host driver looking up the panel. We can do so by
20 moving the DSI host creation outside of the component bind loop, and
21 the panel/bridge lookup/attach into the component bind process.
23 drivers/gpu/drm/vc4/vc4_dsi.c | 93 ++++++++++++++++++++---------------
24 1 file changed, 53 insertions(+), 40 deletions(-)
26 diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
27 index 3fa2db18d70f..faf38f17ec26 100644
28 --- a/drivers/gpu/drm/vc4/vc4_dsi.c
29 +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
31 #include <drm/drm_crtc_helper.h>
32 #include <drm/drm_edid.h>
33 #include <drm/drm_mipi_dsi.h>
34 +#include <drm/drm_of.h>
35 #include <drm/drm_panel.h>
36 #include <linux/clk.h>
37 #include <linux/clk-provider.h>
38 @@ -504,7 +505,6 @@ struct vc4_dsi {
39 struct mipi_dsi_host dsi_host;
40 struct drm_encoder *encoder;
41 struct drm_bridge *bridge;
42 - bool is_panel_bridge;
46 @@ -1300,7 +1300,6 @@ static int vc4_dsi_host_attach(struct mipi_dsi_host *host,
47 struct mipi_dsi_device *device)
49 struct vc4_dsi *dsi = host_to_dsi(host);
52 dsi->lanes = device->lanes;
53 dsi->channel = device->channel;
54 @@ -1335,33 +1334,12 @@ static int vc4_dsi_host_attach(struct mipi_dsi_host *host,
58 - dsi->bridge = of_drm_find_bridge(device->dev.of_node);
60 - struct drm_panel *panel =
61 - of_drm_find_panel(device->dev.of_node);
63 - dsi->bridge = drm_panel_bridge_add(panel,
64 - DRM_MODE_CONNECTOR_DSI);
65 - if (IS_ERR(dsi->bridge)) {
66 - ret = PTR_ERR(dsi->bridge);
70 - dsi->is_panel_bridge = true;
73 - return drm_bridge_attach(dsi->encoder, dsi->bridge, NULL);
77 static int vc4_dsi_host_detach(struct mipi_dsi_host *host,
78 struct mipi_dsi_device *device)
80 - struct vc4_dsi *dsi = host_to_dsi(host);
82 - if (dsi->is_panel_bridge) {
83 - drm_panel_bridge_remove(dsi->bridge);
89 @@ -1525,16 +1503,13 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
90 struct platform_device *pdev = to_platform_device(dev);
91 struct drm_device *drm = dev_get_drvdata(master);
92 struct vc4_dev *vc4 = to_vc4_dev(drm);
93 - struct vc4_dsi *dsi;
94 + struct vc4_dsi *dsi = dev_get_drvdata(dev);
95 struct vc4_dsi_encoder *vc4_dsi_encoder;
96 + struct drm_panel *panel;
97 const struct of_device_id *match;
98 dma_cap_mask_t dma_mask;
101 - dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
105 match = of_match_device(vc4_dsi_dt_match, dev);
108 @@ -1549,7 +1524,6 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
109 vc4_dsi_encoder->dsi = dsi;
110 dsi->encoder = &vc4_dsi_encoder->base.base;
113 dsi->regs = vc4_ioremap_regs(pdev, 0);
114 if (IS_ERR(dsi->regs))
115 return PTR_ERR(dsi->regs);
116 @@ -1637,6 +1611,18 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
120 + ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0,
121 + &panel, &dsi->bridge);
126 + dsi->bridge = devm_drm_panel_bridge_add(dev, panel,
127 + DRM_MODE_CONNECTOR_DSI);
128 + if (IS_ERR(dsi->bridge))
129 + return PTR_ERR(dsi->bridge);
132 /* The esc clock rate is supposed to always be 100Mhz. */
133 ret = clk_set_rate(dsi->escape_clock, 100 * 1000000);
135 @@ -1655,13 +1641,6 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
136 DRM_MODE_ENCODER_DSI, NULL);
137 drm_encoder_helper_add(dsi->encoder, &vc4_dsi_encoder_helper_funcs);
139 - dsi->dsi_host.ops = &vc4_dsi_host_ops;
140 - dsi->dsi_host.dev = dev;
142 - mipi_dsi_host_register(&dsi->dsi_host);
144 - dev_set_drvdata(dev, dsi);
146 ret = drm_bridge_attach(dsi->encoder, dsi->bridge, NULL);
148 dev_err(dev, "bridge attach failed: %d\n", ret);
149 @@ -1672,6 +1651,7 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
150 * from our driver, since we need to sequence them within the
151 * encoder's enable/disable paths.
154 dsi->encoder->bridge = NULL;
156 pm_runtime_enable(dev);
157 @@ -1690,8 +1670,6 @@ static void vc4_dsi_unbind(struct device *dev, struct device *master,
159 vc4_dsi_encoder_destroy(dsi->encoder);
161 - mipi_dsi_host_unregister(&dsi->dsi_host);
166 @@ -1703,12 +1681,47 @@ static const struct component_ops vc4_dsi_ops = {
168 static int vc4_dsi_dev_probe(struct platform_device *pdev)
170 - return component_add(&pdev->dev, &vc4_dsi_ops);
171 + struct device *dev = &pdev->dev;
172 + struct vc4_dsi *dsi;
175 + dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
178 + dev_set_drvdata(dev, dsi);
182 + /* Note, the initialization sequence for DSI and panels is
183 + * tricky. The component bind above won't get past its
184 + * -EPROBE_DEFER until the panel/bridge probes. The
185 + * panel/bridge will return -EPROBE_DEFER until it has a
186 + * mipi_dsi_host to register its device to. So, we register
187 + * the host during pdev probe time, so vc4 as a whole can then
188 + * -EPROBE_DEFER its component bind process until the panel
189 + * successfully attaches.
191 + dsi->dsi_host.ops = &vc4_dsi_host_ops;
192 + dsi->dsi_host.dev = dev;
193 + mipi_dsi_host_register(&dsi->dsi_host);
195 + ret = component_add(&pdev->dev, &vc4_dsi_ops);
197 + mipi_dsi_host_unregister(&dsi->dsi_host);
204 static int vc4_dsi_dev_remove(struct platform_device *pdev)
206 + struct device *dev = &pdev->dev;
207 + struct vc4_dsi *dsi = dev_get_drvdata(dev);
209 component_del(&pdev->dev, &vc4_dsi_ops);
210 + mipi_dsi_host_unregister(&dsi->dsi_host);