drm: kirin: Add register connect helper functions in drm init
authorXu YiPing <xuyiping@hisilicon.com>
Tue, 20 Aug 2019 23:06:20 +0000 (23:06 +0000)
committerSam Ravnborg <sam@ravnborg.org>
Wed, 21 Aug 2019 17:15:42 +0000 (19:15 +0200)
As part of refactoring the kirin driver to better support
different hardware revisions, this patch adds a flag to the
device specific driver data so that we can conditionally
register the connectors at init.

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-20-john.stultz@linaro.org
drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h

index 21c5d457a97dc5de428f591232142c782d4cbc4a..89bdc0388138856a16b73f930447ca14b1c5bc47 100644 (file)
@@ -1073,6 +1073,7 @@ static struct drm_driver ade_driver = {
 };
 
 struct kirin_drm_data ade_driver_data = {
+       .register_connects = false,
        .num_planes = ADE_CH_NUM,
        .prim_plane = ADE_CH1,
        .channel_formats = channel_formats,
index c9faaa848cc669a5f63e4c98b40957283c16146b..68de8838da3c0c17e4a72820824d6a8fac97a72f 100644 (file)
@@ -98,6 +98,40 @@ static int compare_of(struct device *dev, void *data)
        return dev->of_node == data;
 }
 
+static int kirin_drm_connectors_register(struct drm_device *dev)
+{
+       struct drm_connector *connector;
+       struct drm_connector *failed_connector;
+       struct drm_connector_list_iter conn_iter;
+       int ret;
+
+       mutex_lock(&dev->mode_config.mutex);
+       drm_connector_list_iter_begin(dev, &conn_iter);
+       drm_for_each_connector_iter(connector, &conn_iter) {
+               ret = drm_connector_register(connector);
+               if (ret) {
+                       failed_connector = connector;
+                       goto err;
+               }
+       }
+       drm_connector_list_iter_end(&conn_iter);
+       mutex_unlock(&dev->mode_config.mutex);
+
+       return 0;
+
+err:
+       drm_connector_list_iter_begin(dev, &conn_iter);
+       drm_for_each_connector_iter(connector, &conn_iter) {
+               if (failed_connector == connector)
+                       break;
+               drm_connector_unregister(connector);
+       }
+       drm_connector_list_iter_end(&conn_iter);
+       mutex_unlock(&dev->mode_config.mutex);
+
+       return ret;
+}
+
 static int kirin_drm_bind(struct device *dev)
 {
        struct drm_device *drm_dev;
@@ -117,8 +151,17 @@ static int kirin_drm_bind(struct device *dev)
 
        drm_fbdev_generic_setup(drm_dev, 32);
 
+       /* connectors should be registered after drm device register */
+       if (driver_data->register_connects) {
+               ret = kirin_drm_connectors_register(drm_dev);
+               if (ret)
+                       goto err_drm_dev_unregister;
+       }
+
        return 0;
 
+err_drm_dev_unregister:
+       drm_dev_unregister(drm_dev);
 err_kms_cleanup:
        kirin_drm_kms_cleanup(drm_dev);
 err_drm_dev_put:
index fdbfc4a90f22a6e965ba3c677764e2d201b485a6..95f56c9960d59c0d1a3a93e27b4feac631dc72d0 100644 (file)
@@ -39,6 +39,7 @@ struct kirin_drm_data {
        u32 channel_formats_cnt;
        int config_max_width;
        int config_max_height;
+       bool register_connects;
        u32 num_planes;
        u32 prim_plane;