OSDN Git Service

drm/zte: Use drm_fb_cma_fbdev_init/fini()
authorNoralf Trønnes <noralf@tronnes.org>
Wed, 15 Nov 2017 14:19:57 +0000 (15:19 +0100)
committerNoralf Trønnes <noralf@tronnes.org>
Fri, 8 Dec 2017 13:47:43 +0000 (14:47 +0100)
Use drm_fb_cma_fbdev_init() and drm_fb_cma_fbdev_fini() which relies on
the fact that drm_device holds a pointer to the drm_fb_helper structure.
This means that the driver doesn't have to keep track of that.
Also use the drm_fb_helper functions directly.

Cc: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Acked-by: Shawn Guo <shawnguo@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20171115142001.45358-19-noralf@tronnes.org
drivers/gpu/drm/zte/zx_drm_drv.c

index e8b8266..6f4205e 100644 (file)
 #include "zx_drm_drv.h"
 #include "zx_vou.h"
 
-struct zx_drm_private {
-       struct drm_fbdev_cma *fbdev;
-};
-
-static void zx_drm_fb_output_poll_changed(struct drm_device *drm)
-{
-       struct zx_drm_private *priv = drm->dev_private;
-
-       drm_fbdev_cma_hotplug_event(priv->fbdev);
-}
-
 static const struct drm_mode_config_funcs zx_drm_mode_config_funcs = {
        .fb_create = drm_gem_fb_create,
-       .output_poll_changed = zx_drm_fb_output_poll_changed,
+       .output_poll_changed = drm_fb_helper_output_poll_changed,
        .atomic_check = drm_atomic_helper_check,
        .atomic_commit = drm_atomic_helper_commit,
 };
 
-static void zx_drm_lastclose(struct drm_device *drm)
-{
-       struct zx_drm_private *priv = drm->dev_private;
-
-       drm_fbdev_cma_restore_mode(priv->fbdev);
-}
-
 DEFINE_DRM_GEM_CMA_FOPS(zx_drm_fops);
 
 static struct drm_driver zx_drm_driver = {
        .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME |
                           DRIVER_ATOMIC,
-       .lastclose = zx_drm_lastclose,
+       .lastclose = drm_fb_helper_lastclose,
        .gem_free_object_unlocked = drm_gem_cma_free_object,
        .gem_vm_ops = &drm_gem_cma_vm_ops,
        .dumb_create = drm_gem_cma_dumb_create,
@@ -83,18 +65,12 @@ static struct drm_driver zx_drm_driver = {
 static int zx_drm_bind(struct device *dev)
 {
        struct drm_device *drm;
-       struct zx_drm_private *priv;
        int ret;
 
-       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-       if (!priv)
-               return -ENOMEM;
-
        drm = drm_dev_alloc(&zx_drm_driver, dev);
        if (IS_ERR(drm))
                return PTR_ERR(drm);
 
-       drm->dev_private = priv;
        dev_set_drvdata(dev, drm);
 
        drm_mode_config_init(drm);
@@ -125,12 +101,9 @@ static int zx_drm_bind(struct device *dev)
        drm_mode_config_reset(drm);
        drm_kms_helper_poll_init(drm);
 
-       priv->fbdev = drm_fbdev_cma_init(drm, 32,
-                                        drm->mode_config.num_connector);
-       if (IS_ERR(priv->fbdev)) {
-               ret = PTR_ERR(priv->fbdev);
+       ret = drm_fb_cma_fbdev_init(drm, 32, 0);
+       if (ret) {
                DRM_DEV_ERROR(dev, "failed to init cma fbdev: %d\n", ret);
-               priv->fbdev = NULL;
                goto out_poll_fini;
        }
 
@@ -141,10 +114,7 @@ static int zx_drm_bind(struct device *dev)
        return 0;
 
 out_fbdev_fini:
-       if (priv->fbdev) {
-               drm_fbdev_cma_fini(priv->fbdev);
-               priv->fbdev = NULL;
-       }
+       drm_fb_cma_fbdev_fini(drm);
 out_poll_fini:
        drm_kms_helper_poll_fini(drm);
        drm_mode_config_cleanup(drm);
@@ -152,7 +122,6 @@ out_unbind:
        component_unbind_all(dev, drm);
 out_unregister:
        dev_set_drvdata(dev, NULL);
-       drm->dev_private = NULL;
        drm_dev_unref(drm);
        return ret;
 }
@@ -160,18 +129,13 @@ out_unregister:
 static void zx_drm_unbind(struct device *dev)
 {
        struct drm_device *drm = dev_get_drvdata(dev);
-       struct zx_drm_private *priv = drm->dev_private;
 
        drm_dev_unregister(drm);
-       if (priv->fbdev) {
-               drm_fbdev_cma_fini(priv->fbdev);
-               priv->fbdev = NULL;
-       }
+       drm_fb_cma_fbdev_fini(drm);
        drm_kms_helper_poll_fini(drm);
        drm_mode_config_cleanup(drm);
        component_unbind_all(dev, drm);
        dev_set_drvdata(dev, NULL);
-       drm->dev_private = NULL;
        drm_dev_unref(drm);
 }