drm/bridge/synopsys: stop clobbering drvdata
authorBrian Norris <briannorris@chromium.org>
Tue, 28 Nov 2017 01:05:38 +0000 (17:05 -0800)
committerAndrzej Hajda <a.hajda@samsung.com>
Tue, 9 Jan 2018 13:34:38 +0000 (14:34 +0100)
Bridge drivers/helpers shouldn't be clobbering the drvdata, since a
parent driver might need to own this. Instead, let's return our
'dw_mipi_dsi' object and have callers pass that back to us for removal.

Signed-off-by: Brian Norris <briannorris@chromium.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Archit Taneja <architt@codeaurora.org>
Acked-by: Philippe Cornu <philippe.cornu@st.com>
Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20171128010538.119114-1-briannorris@chromium.org
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c
drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
include/drm/bridge/dw_mipi_dsi.h

index d9cca4fd66ecd1a945e03b87009870bae91021b2..c39c7dce20ed231f7f8e9bda776ebeb7762d21e5 100644 (file)
@@ -922,8 +922,6 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
        dsi->bridge.of_node = pdev->dev.of_node;
 #endif
 
-       dev_set_drvdata(dev, dsi);
-
        return dsi;
 }
 
@@ -935,23 +933,16 @@ static void __dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi)
 /*
  * Probe/remove API, used from platforms based on the DRM bridge API.
  */
-int dw_mipi_dsi_probe(struct platform_device *pdev,
-                     const struct dw_mipi_dsi_plat_data *plat_data)
+struct dw_mipi_dsi *
+dw_mipi_dsi_probe(struct platform_device *pdev,
+                 const struct dw_mipi_dsi_plat_data *plat_data)
 {
-       struct dw_mipi_dsi *dsi;
-
-       dsi = __dw_mipi_dsi_probe(pdev, plat_data);
-       if (IS_ERR(dsi))
-               return PTR_ERR(dsi);
-
-       return 0;
+       return __dw_mipi_dsi_probe(pdev, plat_data);
 }
 EXPORT_SYMBOL_GPL(dw_mipi_dsi_probe);
 
-void dw_mipi_dsi_remove(struct platform_device *pdev)
+void dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi)
 {
-       struct dw_mipi_dsi *dsi = platform_get_drvdata(pdev);
-
        mipi_dsi_host_unregister(&dsi->dsi_host);
 
        __dw_mipi_dsi_remove(dsi);
@@ -961,31 +952,30 @@ EXPORT_SYMBOL_GPL(dw_mipi_dsi_remove);
 /*
  * Bind/unbind API, used from platforms based on the component framework.
  */
-int dw_mipi_dsi_bind(struct platform_device *pdev, struct drm_encoder *encoder,
-                    const struct dw_mipi_dsi_plat_data *plat_data)
+struct dw_mipi_dsi *
+dw_mipi_dsi_bind(struct platform_device *pdev, struct drm_encoder *encoder,
+                const struct dw_mipi_dsi_plat_data *plat_data)
 {
        struct dw_mipi_dsi *dsi;
        int ret;
 
        dsi = __dw_mipi_dsi_probe(pdev, plat_data);
        if (IS_ERR(dsi))
-               return PTR_ERR(dsi);
+               return dsi;
 
        ret = drm_bridge_attach(encoder, &dsi->bridge, NULL);
        if (ret) {
-               dw_mipi_dsi_remove(pdev);
+               dw_mipi_dsi_remove(dsi);
                DRM_ERROR("Failed to initialize bridge with drm\n");
-               return ret;
+               return ERR_PTR(ret);
        }
 
-       return 0;
+       return dsi;
 }
 EXPORT_SYMBOL_GPL(dw_mipi_dsi_bind);
 
-void dw_mipi_dsi_unbind(struct device *dev)
+void dw_mipi_dsi_unbind(struct dw_mipi_dsi *dsi)
 {
-       struct dw_mipi_dsi *dsi = dev_get_drvdata(dev);
-
        __dw_mipi_dsi_remove(dsi);
 }
 EXPORT_SYMBOL_GPL(dw_mipi_dsi_unbind);
index fd02506274dab996a08e70e1e04db3cd5af0d18c..0ba8635d738a1e4368cd13c7ae68d995270bb9de 100644 (file)
@@ -65,6 +65,7 @@ enum dsi_color {
 struct dw_mipi_dsi_stm {
        void __iomem *base;
        struct clk *pllref_clk;
+       struct dw_mipi_dsi *dsi;
 };
 
 static inline void dsi_write(struct dw_mipi_dsi_stm *dsi, u32 reg, u32 val)
@@ -312,21 +313,24 @@ static int dw_mipi_dsi_stm_probe(struct platform_device *pdev)
        dw_mipi_dsi_stm_plat_data.base = dsi->base;
        dw_mipi_dsi_stm_plat_data.priv_data = dsi;
 
-       ret = dw_mipi_dsi_probe(pdev, &dw_mipi_dsi_stm_plat_data);
-       if (ret) {
+       platform_set_drvdata(pdev, dsi);
+
+       dsi->dsi = dw_mipi_dsi_probe(pdev, &dw_mipi_dsi_stm_plat_data);
+       if (IS_ERR(dsi->dsi)) {
                DRM_ERROR("Failed to initialize mipi dsi host\n");
                clk_disable_unprepare(dsi->pllref_clk);
+               return PTR_ERR(dsi->dsi);
        }
 
-       return ret;
+       return 0;
 }
 
 static int dw_mipi_dsi_stm_remove(struct platform_device *pdev)
 {
-       struct dw_mipi_dsi_stm *dsi = dw_mipi_dsi_stm_plat_data.priv_data;
+       struct dw_mipi_dsi_stm *dsi = platform_get_drvdata(pdev);
 
        clk_disable_unprepare(dsi->pllref_clk);
-       dw_mipi_dsi_remove(pdev);
+       dw_mipi_dsi_remove(dsi->dsi);
 
        return 0;
 }
index 9b30fec302c8cd84e0621b20e4c0ccc92cf24165..d9c6d549f9711ad7c9a3d484ad606a70590ce135 100644 (file)
@@ -10,6 +10,8 @@
 #ifndef __DW_MIPI_DSI__
 #define __DW_MIPI_DSI__
 
+struct dw_mipi_dsi;
+
 struct dw_mipi_dsi_phy_ops {
        int (*init)(void *priv_data);
        int (*get_lane_mbps)(void *priv_data, struct drm_display_mode *mode,
@@ -29,11 +31,14 @@ struct dw_mipi_dsi_plat_data {
        void *priv_data;
 };
 
-int dw_mipi_dsi_probe(struct platform_device *pdev,
-                     const struct dw_mipi_dsi_plat_data *plat_data);
-void dw_mipi_dsi_remove(struct platform_device *pdev);
-int dw_mipi_dsi_bind(struct platform_device *pdev, struct drm_encoder *encoder,
-                    const struct dw_mipi_dsi_plat_data *plat_data);
-void dw_mipi_dsi_unbind(struct device *dev);
+struct dw_mipi_dsi *dw_mipi_dsi_probe(struct platform_device *pdev,
+                                     const struct dw_mipi_dsi_plat_data
+                                     *plat_data);
+void dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi);
+struct dw_mipi_dsi *dw_mipi_dsi_bind(struct platform_device *pdev,
+                                    struct drm_encoder *encoder,
+                                    const struct dw_mipi_dsi_plat_data
+                                    *plat_data);
+void dw_mipi_dsi_unbind(struct dw_mipi_dsi *dsi);
 
 #endif /* __DW_MIPI_DSI__ */