drm/mediatek: Refactor plane init
authorSean Paul <seanpaul@chromium.org>
Tue, 5 Nov 2019 21:10:18 +0000 (16:10 -0500)
committerCK Hu <ck.hu@mediatek.com>
Wed, 6 Nov 2019 08:00:44 +0000 (16:00 +0800)
Add a couple of functions which enumerate the number of planes for a
component and initialize the planes for a component.

No functional changes in this patch, but it will allow us to selectively
support rotation if the component supports it.

Signed-off-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: CK Hu <ck.hu@mediatek.com>
drivers/gpu/drm/mediatek/mtk_drm_crtc.c

index b841d3706d8bad78a20a17f27f8f17de2acea4b1..7d0f50da8e404150b9da9acd6e5f214b304f2ecd 100644 (file)
@@ -543,14 +543,63 @@ void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *comp)
        mtk_drm_finish_page_flip(mtk_crtc);
 }
 
+static int mtk_drm_crtc_num_comp_planes(struct mtk_drm_crtc *mtk_crtc,
+                                       int comp_idx)
+{
+       struct mtk_ddp_comp *comp;
+
+       if (comp_idx > 1)
+               return 0;
+
+       comp = mtk_crtc->ddp_comp[comp_idx];
+       if (!comp->funcs)
+               return 0;
+
+       if (comp_idx == 1 && !comp->funcs->bgclr_in_on)
+               return 0;
+
+       return mtk_ddp_comp_layer_nr(comp);
+}
+
+static inline
+enum drm_plane_type mtk_drm_crtc_plane_type(unsigned int plane_idx)
+{
+       if (plane_idx == 0)
+               return DRM_PLANE_TYPE_PRIMARY;
+       else if (plane_idx == 1)
+               return DRM_PLANE_TYPE_CURSOR;
+       else
+               return DRM_PLANE_TYPE_OVERLAY;
+
+}
+
+static int mtk_drm_crtc_init_comp_planes(struct drm_device *drm_dev,
+                                        struct mtk_drm_crtc *mtk_crtc,
+                                        int comp_idx, int pipe)
+{
+       int num_planes = mtk_drm_crtc_num_comp_planes(mtk_crtc, comp_idx);
+       int i, ret;
+
+       for (i = 0; i < num_planes; i++) {
+               ret = mtk_plane_init(drm_dev,
+                               &mtk_crtc->planes[mtk_crtc->layer_nr],
+                               BIT(pipe),
+                               mtk_drm_crtc_plane_type(mtk_crtc->layer_nr));
+               if (ret)
+                       return ret;
+
+               mtk_crtc->layer_nr++;
+       }
+       return 0;
+}
+
 int mtk_drm_crtc_create(struct drm_device *drm_dev,
                        const enum mtk_ddp_comp_id *path, unsigned int path_len)
 {
        struct mtk_drm_private *priv = drm_dev->dev_private;
        struct device *dev = drm_dev->dev;
        struct mtk_drm_crtc *mtk_crtc;
-       enum drm_plane_type type;
-       unsigned int zpos;
+       unsigned int num_comp_planes = 0;
        int pipe = priv->num_pipes;
        int ret;
        int i;
@@ -606,23 +655,15 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
                mtk_crtc->ddp_comp[i] = comp;
        }
 
-       mtk_crtc->layer_nr = mtk_ddp_comp_layer_nr(mtk_crtc->ddp_comp[0]);
-       if (mtk_crtc->ddp_comp_nr > 1) {
-               struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[1];
+       for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
+               num_comp_planes += mtk_drm_crtc_num_comp_planes(mtk_crtc, i);
+
+       mtk_crtc->planes = devm_kcalloc(dev, num_comp_planes,
+                                       sizeof(struct drm_plane), GFP_KERNEL);
 
-               if (comp->funcs->bgclr_in_on)
-                       mtk_crtc->layer_nr += mtk_ddp_comp_layer_nr(comp);
-       }
-       mtk_crtc->planes = devm_kcalloc(dev, mtk_crtc->layer_nr,
-                                       sizeof(struct drm_plane),
-                                       GFP_KERNEL);
-
-       for (zpos = 0; zpos < mtk_crtc->layer_nr; zpos++) {
-               type = (zpos == 0) ? DRM_PLANE_TYPE_PRIMARY :
-                               (zpos == 1) ? DRM_PLANE_TYPE_CURSOR :
-                                               DRM_PLANE_TYPE_OVERLAY;
-               ret = mtk_plane_init(drm_dev, &mtk_crtc->planes[zpos],
-                                    BIT(pipe), type);
+       for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
+               ret = mtk_drm_crtc_init_comp_planes(drm_dev, mtk_crtc, i,
+                                                   pipe);
                if (ret)
                        return ret;
        }