drm: kirin: Make driver_data variable non-global
authorXu YiPing <xuyiping@hisilicon.com>
Tue, 20 Aug 2019 23:06:23 +0000 (23:06 +0000)
committerSam Ravnborg <sam@ravnborg.org>
Wed, 21 Aug 2019 17:15:44 +0000 (19:15 +0200)
As part of refactoring the kirin driver to better support
different hardware revisions, this patch changes the driver_data
value to not be a global variable. Instead the driver_data value
is accessed via the of_device_get_match_data() when needed.

Cc: Rongrong Zou <zourongrong@gmail.com>
Cc: Xinliang Liu <z.liuxinliang@hisilicon.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel <dri-devel@lists.freedesktop.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Acked-by: Xinliang Liu <z.liuxinliang@hisilicon.com>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Xu YiPing <xuyiping@hisilicon.com>
[jstultz: Reworded commit message]
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190820230626.23253-23-john.stultz@linaro.org
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c

index 7f8d4539b1a970c98c84d6c77df673eb0c330319..f5df88378591e0e937a80d8cddb1b8553b1bdb75 100644 (file)
 
 #include "kirin_drm_drv.h"
 
-static struct kirin_drm_data *driver_data;
 
-static int kirin_drm_kms_cleanup(struct drm_device *dev)
-{
-       drm_kms_helper_poll_fini(dev);
-       driver_data->cleanup(to_platform_device(dev->dev));
-       drm_mode_config_cleanup(dev);
-
-       return 0;
-}
-
-static int kirin_drm_kms_init(struct drm_device *dev)
+static int kirin_drm_kms_init(struct drm_device *dev,
+                             const struct kirin_drm_data *driver_data)
 {
        int ret;
 
@@ -96,6 +87,21 @@ static int compare_of(struct device *dev, void *data)
        return dev->of_node == data;
 }
 
+static int kirin_drm_kms_cleanup(struct drm_device *dev)
+{
+       const struct kirin_drm_data *driver_data;
+
+       drm_kms_helper_poll_fini(dev);
+
+       driver_data = of_device_get_match_data(dev->dev);
+       if (driver_data->cleanup)
+               driver_data->cleanup(to_platform_device(dev->dev));
+
+       drm_mode_config_cleanup(dev);
+
+       return 0;
+}
+
 static int kirin_drm_connectors_register(struct drm_device *dev)
 {
        struct drm_connector *connector;
@@ -132,15 +138,21 @@ err:
 
 static int kirin_drm_bind(struct device *dev)
 {
+       struct kirin_drm_data *driver_data;
        struct drm_device *drm_dev;
        int ret;
 
+       driver_data = (struct kirin_drm_data *)of_device_get_match_data(dev);
+       if (!driver_data)
+               return -EINVAL;
+
        drm_dev = drm_dev_alloc(driver_data->driver, dev);
        if (IS_ERR(drm_dev))
                return PTR_ERR(drm_dev);
        dev_set_drvdata(dev, drm_dev);
 
-       ret = kirin_drm_kms_init(drm_dev);
+       /* display controller init */
+       ret = kirin_drm_kms_init(drm_dev, driver_data);
        if (ret)
                goto err_drm_dev_put;
 
@@ -190,12 +202,6 @@ static int kirin_drm_platform_probe(struct platform_device *pdev)
        struct component_match *match = NULL;
        struct device_node *remote;
 
-       driver_data = (struct kirin_drm_data *)of_device_get_match_data(dev);
-       if (!driver_data) {
-               DRM_ERROR("failed to get dt id data\n");
-               return -EINVAL;
-       }
-
        remote = of_graph_get_remote_node(np, 0, 0);
        if (!remote)
                return -ENODEV;
@@ -209,7 +215,6 @@ static int kirin_drm_platform_probe(struct platform_device *pdev)
 static int kirin_drm_platform_remove(struct platform_device *pdev)
 {
        component_master_del(&pdev->dev, &kirin_drm_ops);
-       driver_data = NULL;
        return 0;
 }