Take a reference on the dw-hdmi bridge during bind and drop it again
from unbind to ensure the bridge is kept alive for the lifetime of the
encoder component.

Signed-off-by: Jonas Karlman <[email protected]>
---
v2: Use dw_hdmi_unbind() and adjust the error message
---
 drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c 
b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
index 8c26223b70b5..538906e342d2 100644
--- a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
+++ b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
@@ -79,6 +79,7 @@ struct rockchip_hdmi {
        struct clk *hdmiphy_clk;
        struct clk *ref_clk;
        struct clk *grf_clk;
+       struct drm_bridge *bridge;
        struct dw_hdmi *hdmi;
        struct phy *phy;
 };
@@ -609,6 +610,13 @@ static int dw_hdmi_rockchip_bind(struct device *dev, 
struct device *master,
                return dev_err_probe(dev, PTR_ERR(hdmi->hdmi),
                                     "failed to probe dw-hdmi bridge\n");
 
+       hdmi->bridge = of_drm_find_and_get_bridge(np);
+       if (!hdmi->bridge) {
+               dw_hdmi_unbind(hdmi->hdmi);
+               return dev_err_probe(dev, -ENODEV,
+                                    "failed to find dw-hdmi bridge\n");
+       }
+
        return 0;
 }
 
@@ -617,6 +625,7 @@ static void dw_hdmi_rockchip_unbind(struct device *dev, 
struct device *master,
 {
        struct rockchip_hdmi *hdmi = dev_get_drvdata(dev);
 
+       drm_bridge_put(hdmi->bridge);
        dw_hdmi_unbind(hdmi->hdmi);
 }
 
-- 
2.54.0

Reply via email to