Fix rpi touchscreen support on master
[AGL/meta-agl.git] / meta-agl-bsp / meta-raspberrypi / recipes-kernel / linux / linux-raspberrypi / dsi / 0003-drm-vc4-Set-up-the-DSI-host-at-pdev-probe-time-not-c.patch
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
6  4.14.y
7
8 We need the following things to happen in sequence:
9
10 DSI host creation
11 DSI device creation in the panel driver (needs DSI host)
12 DSI device attach from panel to host.
13 DSI drm_panel_add()
14 DSI encoder creation
15 DSI encoder's DRM panel/bridge attach
16
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.
22 ---
23  drivers/gpu/drm/vc4/vc4_dsi.c | 93 ++++++++++++++++++++---------------
24  1 file changed, 53 insertions(+), 40 deletions(-)
25
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
30 @@ -33,6 +33,7 @@
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;
43  
44         void __iomem *regs;
45  
46 @@ -1300,7 +1300,6 @@ static int vc4_dsi_host_attach(struct mipi_dsi_host *host,
47                                struct mipi_dsi_device *device)
48  {
49         struct vc4_dsi *dsi = host_to_dsi(host);
50 -       int ret = 0;
51  
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,
55                 return 0;
56         }
57  
58 -       dsi->bridge = of_drm_find_bridge(device->dev.of_node);
59 -       if (!dsi->bridge) {
60 -               struct drm_panel *panel =
61 -                       of_drm_find_panel(device->dev.of_node);
62 -
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);
67 -                       dsi->bridge = NULL;
68 -                       return ret;
69 -               }
70 -               dsi->is_panel_bridge = true;
71 -       }
72 -
73 -       return drm_bridge_attach(dsi->encoder, dsi->bridge, NULL);
74 +       return 0;
75  }
76  
77  static int vc4_dsi_host_detach(struct mipi_dsi_host *host,
78                                struct mipi_dsi_device *device)
79  {
80 -       struct vc4_dsi *dsi = host_to_dsi(host);
81 -
82 -       if (dsi->is_panel_bridge) {
83 -               drm_panel_bridge_remove(dsi->bridge);
84 -               dsi->bridge = NULL;
85 -       }
86  
87         return 0;
88  }
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;
99         int ret;
100  
101 -       dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
102 -       if (!dsi)
103 -               return -ENOMEM;
104 -
105         match = of_match_device(vc4_dsi_dt_match, dev);
106         if (!match)
107                 return -ENODEV;
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;
111  
112 -       dsi->pdev = pdev;
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)
117                 return ret;
118         }
119  
120 +       ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0,
121 +                                         &panel, &dsi->bridge);
122 +       if (ret)
123 +               return ret;
124 +
125 +       if (panel) {
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);
130 +       }
131 +
132         /* The esc clock rate is supposed to always be 100Mhz. */
133         ret = clk_set_rate(dsi->escape_clock, 100 * 1000000);
134         if (ret) {
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);
138  
139 -       dsi->dsi_host.ops = &vc4_dsi_host_ops;
140 -       dsi->dsi_host.dev = dev;
141 -
142 -       mipi_dsi_host_register(&dsi->dsi_host);
143 -
144 -       dev_set_drvdata(dev, dsi);
145 -
146         ret = drm_bridge_attach(dsi->encoder, dsi->bridge, NULL);
147         if (ret) {
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.
152          */
153 +
154         dsi->encoder->bridge = NULL;
155  
156         pm_runtime_enable(dev);
157 @@ -1690,8 +1670,6 @@ static void vc4_dsi_unbind(struct device *dev, struct device *master,
158  
159         vc4_dsi_encoder_destroy(dsi->encoder);
160  
161 -       mipi_dsi_host_unregister(&dsi->dsi_host);
162 -
163         if (dsi->port == 1)
164                 vc4->dsi1 = NULL;
165  }
166 @@ -1703,12 +1681,47 @@ static const struct component_ops vc4_dsi_ops = {
167  
168  static int vc4_dsi_dev_probe(struct platform_device *pdev)
169  {
170 -       return component_add(&pdev->dev, &vc4_dsi_ops);
171 +       struct device *dev = &pdev->dev;
172 +       struct vc4_dsi *dsi;
173 +       int ret;
174 +
175 +       dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
176 +       if (!dsi)
177 +               return -ENOMEM;
178 +       dev_set_drvdata(dev, dsi);
179 +
180 +       dsi->pdev = pdev;
181 +
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.
190 +        */
191 +       dsi->dsi_host.ops = &vc4_dsi_host_ops;
192 +       dsi->dsi_host.dev = dev;
193 +       mipi_dsi_host_register(&dsi->dsi_host);
194 +
195 +       ret = component_add(&pdev->dev, &vc4_dsi_ops);
196 +       if (ret) {
197 +               mipi_dsi_host_unregister(&dsi->dsi_host);
198 +               return ret;
199 +       }
200 +
201 +       return 0;
202  }
203  
204  static int vc4_dsi_dev_remove(struct platform_device *pdev)
205  {
206 +       struct device *dev = &pdev->dev;
207 +       struct vc4_dsi *dsi = dev_get_drvdata(dev);
208 +
209         component_del(&pdev->dev, &vc4_dsi_ops);
210 +       mipi_dsi_host_unregister(&dsi->dsi_host);
211 +
212         return 0;
213  }
214  
215 -- 
216 2.21.0
217