Inline drm_crtc_init() into radeon CRTC initialization. The helper is
only used by radeon to implement legacy mode setting.

As in drm_crtc_init(), create a primary plane for the CRTC. Use the same
formats as with drm_crtc_init(). Format modifiers are still marked as
unsupported and handled internally by the plane. For the CRTC, call
drm_crtc_init_with_planes() for initialization. Clean up on errors.

Radeon does not support DRM panic helpers. Therefore do not initialize
the primary plane's panic-helper callbacks.

v3:
- keep plane->format_default for now
v2:
- add missing formats for primary plane

Signed-off-by: Thomas Zimmermann <[email protected]>
Acked-by: Maxime Ripard <[email protected]>
---
 drivers/gpu/drm/radeon/radeon_display.c | 53 +++++++++++++++++++++----
 1 file changed, 46 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_display.c 
b/drivers/gpu/drm/radeon/radeon_display.c
index aac6733ddd82..2bc66b9ad121 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -38,6 +38,7 @@
 #include <drm/drm_framebuffer.h>
 #include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_modeset_helper.h>
+#include <drm/drm_plane_helper.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_vblank.h>
 #include <drm/radeon_drm.h>
@@ -47,6 +48,17 @@
 #include "radeon.h"
 #include "radeon_kms.h"
 
+static const u32 radeon_primary_plane_formats[] = {
+       DRM_FORMAT_XRGB8888,
+       DRM_FORMAT_ARGB8888,
+};
+
+static const struct drm_plane_funcs radeon_primary_plane_funcs = {
+       .update_plane = drm_plane_helper_update_primary,
+       .disable_plane = drm_plane_helper_disable_primary,
+       .destroy = drm_plane_helper_destroy,
+};
+
 static void avivo_crtc_load_lut(struct drm_crtc *crtc)
 {
        struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
@@ -680,20 +692,37 @@ static const struct drm_crtc_funcs radeon_crtc_funcs = {
 static void radeon_crtc_init(struct drm_device *dev, int index)
 {
        struct radeon_device *rdev = dev->dev_private;
+       struct drm_plane *primary;
        struct radeon_crtc *radeon_crtc;
+       int ret;
 
-       radeon_crtc = kzalloc_obj(*radeon_crtc);
-       if (radeon_crtc == NULL)
+       primary = __drm_universal_plane_alloc(dev, sizeof(*primary), 0, 0,
+                                             &radeon_primary_plane_funcs,
+                                             radeon_primary_plane_formats,
+                                             
ARRAY_SIZE(radeon_primary_plane_formats),
+                                             NULL, DRM_PLANE_TYPE_PRIMARY, 
NULL);
+       if (IS_ERR(primary))
                return;
 
+       /*
+        * TODO: Announce the correct formats and remove the format_default
+        *       field from struct drm_plane.
+        */
+       primary->format_default = true;
+
+       radeon_crtc = kzalloc_obj(*radeon_crtc);
+       if (!radeon_crtc)
+               goto err_drm_plane_cleanup;
+
        radeon_crtc->flip_queue = alloc_workqueue("radeon-crtc",
                                                  WQ_HIGHPRI | WQ_PERCPU, 0);
-       if (!radeon_crtc->flip_queue) {
-               kfree(radeon_crtc);
-               return;
-       }
+       if (!radeon_crtc->flip_queue)
+               goto err_kfree;
 
-       drm_crtc_init(dev, &radeon_crtc->base, &radeon_crtc_funcs);
+       ret = drm_crtc_init_with_planes(dev, &radeon_crtc->base, primary, NULL,
+                                       &radeon_crtc_funcs, NULL);
+       if (ret)
+               goto err_destroy_workqueue;
 
        drm_mode_crtc_set_gamma_size(&radeon_crtc->base, 256);
        radeon_crtc->crtc_id = index;
@@ -713,6 +742,16 @@ static void radeon_crtc_init(struct drm_device *dev, int 
index)
                radeon_atombios_init_crtc(dev, radeon_crtc);
        else
                radeon_legacy_init_crtc(dev, radeon_crtc);
+
+       return;
+
+err_destroy_workqueue:
+       destroy_workqueue(radeon_crtc->flip_queue);
+err_kfree:
+       kfree(radeon_crtc);
+err_drm_plane_cleanup:
+       drm_plane_cleanup(primary);
+       kfree(primary);
 }
 
 static const char *encoder_names[38] = {
-- 
2.56.0

Reply via email to