From patchwork Tue Sep 6 04:02:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Agner X-Patchwork-Id: 9315475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 64A0E60760 for ; Tue, 6 Sep 2016 04:02:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5614828B34 for ; Tue, 6 Sep 2016 04:02:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4ADA928B3D; Tue, 6 Sep 2016 04:02:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E5CFB28B34 for ; Tue, 6 Sep 2016 04:02:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CB2CE6E2AC; Tue, 6 Sep 2016 04:02:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.kmu-office.ch (mail.kmu-office.ch [IPv6:2a02:418:6a02::a2]) by gabe.freedesktop.org (Postfix) with ESMTPS id B346E6E525 for ; Tue, 6 Sep 2016 04:02:48 +0000 (UTC) Received: from trochilidae.lan (unknown [IPv6:2601:602:8802:504f:3e97:eff:fe92:db3b]) by mail.kmu-office.ch (Postfix) with ESMTPSA id C03A45C0BE5; Tue, 6 Sep 2016 05:57:35 +0200 (CEST) From: Stefan Agner To: dri-devel@lists.freedesktop.org, meng.yi@nxp.com Subject: [PATCH 1/4] drm/fsl-dcu: support overlay and cursor planes Date: Mon, 5 Sep 2016 21:02:30 -0700 Message-Id: <20160906040233.32471-2-stefan@agner.ch> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160906040233.32471-1-stefan@agner.ch> References: <20160906040233.32471-1-stefan@agner.ch> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1473134257; bh=ZVU1EDofISls7CvfCMTu7uegIHRIK5hxSPs3knk4js8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=pp5LcB1NibbCM0O8iMi0RcY1qAYoTHeEQvN5DsLWFyOmpZG3PHIf+7XSjQVNuekjnKiYMqjUtoay1KHLgznllv4dAc/Z/KKb1RqKwINJ9Q3kojKcil432AuhzR2Aj5qGXX/zTCNoWIHDDC1BkZa3NY/iN2vEeOXXpkvXi/Azp2o= Cc: jianwei.wang.chn@gmail.com, linux-kernel@vger.kernel.org, alison.wang@freescale.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add support for overlay plane and a cursor plane. The driver uses the topmost plane as cursor plane. The DCU IP would have dedicated cursor support, but that lacks proper color support and hence is not practical to use for Linux systems. Signed-off-by: Stefan Agner --- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c | 47 ++++++++++++++++++++++++----- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c | 37 ++++++++++++----------- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.h | 3 +- 3 files changed, 60 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c index 3371635..d30b61e 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c @@ -139,20 +139,51 @@ static const struct drm_crtc_funcs fsl_dcu_drm_crtc_funcs = { int fsl_dcu_drm_crtc_create(struct fsl_dcu_drm_device *fsl_dev) { - struct drm_plane *primary; + struct drm_device *drm = fsl_dev->drm; + struct drm_plane *primary, *cursor; struct drm_crtc *crtc = &fsl_dev->crtc; - int ret; + int total_layer = fsl_dev->soc->total_layer; + int ret, i; - fsl_dcu_drm_init_planes(fsl_dev->drm); + fsl_dcu_drm_init_planes(drm); - primary = fsl_dcu_drm_primary_create_plane(fsl_dev->drm); - if (!primary) - return -ENOMEM; + primary = fsl_dcu_drm_create_plane(drm, DRM_PLANE_TYPE_PRIMARY); + if (IS_ERR(primary)) { + dev_err(fsl_dev->dev, "failed to construct primary plane\n"); + ret = PTR_ERR(primary); + return ret; + } + + /* + * Initialize overlay layers. The hardware does not have specific + * layer types, we just happen to use one layer as primary layer + * and one layer as cursor layer, hence total_layer - 2 = overlays. + */ + for (i = 0; i < total_layer - 2; i++) { + struct drm_plane *plane = + fsl_dcu_drm_create_plane(drm, DRM_PLANE_TYPE_OVERLAY); + + if (IS_ERR(plane)) + continue; + } - ret = drm_crtc_init_with_planes(fsl_dev->drm, crtc, primary, NULL, + cursor = fsl_dcu_drm_create_plane(drm, DRM_PLANE_TYPE_CURSOR); + if (IS_ERR(cursor)) { + dev_warn(fsl_dev->dev, "failed to construct cursor plane\n"); + cursor = NULL; + } + + /* + * Initialize cursor plane after overlay planes since the initialization + * order is crucial to the layer id (and hence layer stacking order). + */ + ret = drm_crtc_init_with_planes(drm, crtc, primary, cursor, &fsl_dcu_drm_crtc_funcs, NULL); if (ret) { - primary->funcs->destroy(primary); + struct drm_plane *plane; + + list_for_each_entry(plane, &drm->mode_config.plane_list, head) + drm_plane_cleanup(plane); return ret; } diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c index a7e5486..a6af3d9 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c @@ -178,7 +178,6 @@ static const struct drm_plane_helper_funcs fsl_dcu_drm_plane_helper_funcs = { static void fsl_dcu_drm_plane_destroy(struct drm_plane *plane) { drm_plane_cleanup(plane); - kfree(plane); } static const struct drm_plane_funcs fsl_dcu_drm_plane_funcs = { @@ -218,28 +217,30 @@ void fsl_dcu_drm_init_planes(struct drm_device *dev) DCU_UPDATE_MODE_READREG); } -struct drm_plane *fsl_dcu_drm_primary_create_plane(struct drm_device *dev) +struct drm_plane *fsl_dcu_drm_create_plane(struct drm_device *dev, + enum drm_plane_type type) { - struct drm_plane *primary; + struct drm_plane *plane; int ret; - primary = kzalloc(sizeof(*primary), GFP_KERNEL); - if (!primary) { - DRM_DEBUG_KMS("Failed to allocate primary plane\n"); - return NULL; - } + plane = devm_kzalloc(dev->dev, sizeof(struct drm_plane), + GFP_KERNEL); + if (!plane) + return ERR_PTR(-ENOMEM); - /* possible_crtc's will be filled in later by crtc_init */ - ret = drm_universal_plane_init(dev, primary, 0, - &fsl_dcu_drm_plane_funcs, + ret = drm_universal_plane_init(dev, plane, 1, &fsl_dcu_drm_plane_funcs, fsl_dcu_drm_plane_formats, ARRAY_SIZE(fsl_dcu_drm_plane_formats), - DRM_PLANE_TYPE_PRIMARY, NULL); - if (ret) { - kfree(primary); - primary = NULL; - } - drm_plane_helper_add(primary, &fsl_dcu_drm_plane_helper_funcs); + type, NULL); + if (ret) + goto err_cleanup_plane; + + drm_plane_helper_add(plane, &fsl_dcu_drm_plane_helper_funcs); + + return plane; + +err_cleanup_plane: + drm_plane_cleanup(plane); - return primary; + return ERR_PTR(ret); } diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.h b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.h index 8ee45f8..bd36166 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.h +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.h @@ -13,6 +13,7 @@ #define __FSL_DCU_DRM_PLANE_H__ void fsl_dcu_drm_init_planes(struct drm_device *dev); -struct drm_plane *fsl_dcu_drm_primary_create_plane(struct drm_device *dev); +struct drm_plane *fsl_dcu_drm_create_plane(struct drm_device *dev, + enum drm_plane_type type); #endif /* __FSL_DCU_DRM_PLANE_H__ */