1 From 51f5523151d8de2b1476482e575bb5989e55ba16 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Tue, 6 Jul 2021 18:53:28 +0100
4 Subject: [PATCH] drm/vc4: Release workaround buffer and DMA in error
7 On Pi0-3 the driver allocates a buffer and requests a DMA channel
8 because the ARM can't write to DSI1's registers directly.
9 However unbind and the error paths in bind don't release the buffer or
12 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
14 drivers/gpu/drm/vc4/vc4_dsi.c | 51 ++++++++++++++++++++++++++---------
15 1 file changed, 39 insertions(+), 12 deletions(-)
17 --- a/drivers/gpu/drm/vc4/vc4_dsi.c
18 +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
19 @@ -1612,7 +1612,7 @@ static int vc4_dsi_bind(struct device *d
20 if (ret != -EPROBE_DEFER)
21 DRM_ERROR("Failed to get DMA channel: %d\n",
24 + goto err_free_dma_mem;
27 /* Get the physical address of the device's registers. The
28 @@ -1641,7 +1641,7 @@ static int vc4_dsi_bind(struct device *d
30 if (ret != -EPROBE_DEFER)
31 dev_err(dev, "Failed to get interrupt: %d\n", ret);
36 dsi->escape_clock = devm_clk_get(dev, "escape");
37 @@ -1649,7 +1649,7 @@ static int vc4_dsi_bind(struct device *d
38 ret = PTR_ERR(dsi->escape_clock);
39 if (ret != -EPROBE_DEFER)
40 dev_err(dev, "Failed to get escape clock: %d\n", ret);
45 dsi->pll_phy_clock = devm_clk_get(dev, "phy");
46 @@ -1657,7 +1657,7 @@ static int vc4_dsi_bind(struct device *d
47 ret = PTR_ERR(dsi->pll_phy_clock);
48 if (ret != -EPROBE_DEFER)
49 dev_err(dev, "Failed to get phy clock: %d\n", ret);
54 dsi->pixel_clock = devm_clk_get(dev, "pixel");
55 @@ -1665,7 +1665,7 @@ static int vc4_dsi_bind(struct device *d
56 ret = PTR_ERR(dsi->pixel_clock);
57 if (ret != -EPROBE_DEFER)
58 dev_err(dev, "Failed to get pixel clock: %d\n", ret);
63 ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0,
64 @@ -1680,33 +1680,37 @@ static int vc4_dsi_bind(struct device *d
73 dsi->bridge = devm_drm_panel_bridge_add_typed(dev, panel,
74 DRM_MODE_CONNECTOR_DSI);
75 - if (IS_ERR(dsi->bridge))
76 - return PTR_ERR(dsi->bridge);
77 + if (IS_ERR(dsi->bridge)) {
78 + ret = PTR_ERR(dsi->bridge);
83 /* The esc clock rate is supposed to always be 100Mhz. */
84 ret = clk_set_rate(dsi->escape_clock, 100 * 1000000);
86 dev_err(dev, "Failed to set esc clock: %d\n", ret);
91 ret = vc4_dsi_init_phy_clocks(dsi);
96 drm_simple_encoder_init(drm, dsi->encoder, DRM_MODE_ENCODER_DSI);
97 drm_encoder_helper_add(dsi->encoder, &vc4_dsi_encoder_helper_funcs);
99 ret = drm_bridge_attach(dsi->encoder, dsi->bridge, NULL, 0);
103 + dev_err(dev, "bridge attach failed: %d\n", ret);
106 /* Disable the atomic helper calls into the bridge. We
107 * manually call the bridge pre_enable / enable / etc. calls
108 * from our driver, since we need to sequence them within the
109 @@ -1719,6 +1723,19 @@ static int vc4_dsi_bind(struct device *d
110 pm_runtime_enable(dev);
115 + if (dsi->reg_dma_chan) {
116 + dma_release_channel(dsi->reg_dma_chan);
117 + dsi->reg_dma_chan = NULL;
120 + if (dsi->reg_dma_mem) {
121 + dma_free_coherent(dev, 4, dsi->reg_dma_mem, dsi->reg_dma_paddr);
122 + dsi->reg_dma_mem = NULL;
128 static void vc4_dsi_unbind(struct device *dev, struct device *master,
129 @@ -1735,6 +1752,16 @@ static void vc4_dsi_unbind(struct device
131 list_splice_init(&dsi->bridge_chain, &dsi->encoder->bridge_chain);
132 drm_encoder_cleanup(dsi->encoder);
134 + if (dsi->reg_dma_chan) {
135 + dma_release_channel(dsi->reg_dma_chan);
136 + dsi->reg_dma_chan = NULL;
139 + if (dsi->reg_dma_mem) {
140 + dma_free_coherent(dev, 4, dsi->reg_dma_mem, dsi->reg_dma_paddr);
141 + dsi->reg_dma_mem = NULL;
145 static const struct component_ops vc4_dsi_ops = {