From patchwork Fri Oct 31 22:54:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 5207781 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 66AA0C11AD for ; Fri, 31 Oct 2014 23:57:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2632E201B9 for ; Fri, 31 Oct 2014 23:57:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 21A3A20120 for ; Fri, 31 Oct 2014 23:57:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CD1CB6E860; Fri, 31 Oct 2014 16:56:58 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pd0-f177.google.com (mail-pd0-f177.google.com [209.85.192.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 13E556E84A for ; Fri, 31 Oct 2014 15:57:27 -0700 (PDT) Received: by mail-pd0-f177.google.com with SMTP id v10so7962606pde.8 for ; Fri, 31 Oct 2014 15:57:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6KWPu5uNtEEGj30/HATxATRatEtqbruR6/RnJVJY/i4=; b=b345qzf7HPhgUgeY1E8zUE8IUtwRX25EfqZQGNMwBXguqewkHlh9ew5HbhRUm3A8p2 wTcBQZ3AhNGqbDEwTqYglb1cKsHFEzKMUUzdyz92C20LgpyzkI+1tT/BUH7ol8B9byHY DA1t9R8U9J2ohvUHSGA13H+NbIaEKWQDSxfyt5znNV+ng9uwO2ksmPshZSjVR8jlC5uG 8FjcVgWfKYBKt/5MWOM1/NtQGILLuuMAR3qVDq8JSVRbsItQoBJvZppcnuw4mvRUUovt xHYkw4UmfnNd7poIaiFfNvPhp1gSeQDijjwJioSycrqYXpQTfM7w4Yf8aDQUua59/iKO 0laQ== X-Received: by 10.68.69.76 with SMTP id c12mr27106930pbu.59.1414796246958; Fri, 31 Oct 2014 15:57:26 -0700 (PDT) Received: from mothership.mgc.mentorg.com (c-50-152-159-227.hsd1.ca.comcast.net. [50.152.159.227]) by mx.google.com with ESMTPSA id ev8sm10870656pdb.28.2014.10.31.15.57.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 15:57:26 -0700 (PDT) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: dri-devel@lists.freedesktop.org Subject: [PATCH 47/72] imx-drm: ipuv3-plane: Implement global alpha and colorkey properties Date: Fri, 31 Oct 2014 15:54:30 -0700 Message-Id: <1414796095-10107-48-git-send-email-steve_longerbeam@mentor.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1414796095-10107-1-git-send-email-steve_longerbeam@mentor.com> References: <1414796095-10107-1-git-send-email-steve_longerbeam@mentor.com> X-Mailman-Approved-At: Fri, 31 Oct 2014 16:56:32 -0700 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-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for setting global alpha and colorkey in foreground planes using plane properties. Background planes can also support these properties if the background plane is initialized as not private. Signed-off-by: Steve Longerbeam --- drivers/staging/imx-drm/ipuv3-plane.c | 144 +++++++++++++++++++++++++++++++-- drivers/staging/imx-drm/ipuv3-plane.h | 7 ++ 2 files changed, 146 insertions(+), 5 deletions(-) diff --git a/drivers/staging/imx-drm/ipuv3-plane.c b/drivers/staging/imx-drm/ipuv3-plane.c index 5818249..1572c80 100644 --- a/drivers/staging/imx-drm/ipuv3-plane.c +++ b/drivers/staging/imx-drm/ipuv3-plane.c @@ -104,6 +104,7 @@ int ipu_plane_mode_set(struct ipu_plane *ipu_plane, struct drm_crtc *crtc, uint32_t src_w, uint32_t src_h) { struct device *dev = ipu_plane->base.dev->dev; + bool is_bg = (ipu_plane->dp_flow == IPU_DP_FLOW_SYNC_BG); int ret; /* no scaling */ @@ -156,7 +157,6 @@ int ipu_plane_mode_set(struct ipu_plane *ipu_plane, struct drm_crtc *crtc, ret); return ret; } - ipu_dp_set_global_alpha(ipu_plane->dp, 1, 0, 1); break; case IPU_DP_FLOW_SYNC_FG: ipu_dp_setup_channel(ipu_plane->dp, @@ -166,6 +166,24 @@ int ipu_plane_mode_set(struct ipu_plane *ipu_plane, struct drm_crtc *crtc, break; } + if (ipu_plane->dp) { + ret = ipu_dp_set_global_alpha(ipu_plane->dp, + ipu_plane->global_alpha_en, + ipu_plane->global_alpha, is_bg); + if (ret) { + dev_err(dev, "set global alpha failed with %d\n", ret); + return ret; + } + + ret = ipu_dp_set_chroma_key(ipu_plane->dp, + ipu_plane->colorkey_en, + ipu_plane->colorkey); + if (ret) { + dev_err(dev, "set colorkey failed with %d\n", ret); + return ret; + } + } + ret = ipu_dmfc_alloc_bandwidth(ipu_plane->dmfc, calc_bandwidth(crtc_w, crtc_h, calc_vref(mode)), crtc_w, 64); @@ -329,13 +347,86 @@ static void ipu_plane_destroy(struct drm_plane *plane) kfree(ipu_plane); } +static int ipu_plane_set_global_alpha(struct ipu_plane *ipu_plane, + u32 global_alpha) +{ + bool is_bg = (ipu_plane->dp_flow == IPU_DP_FLOW_SYNC_BG); + bool global_alpha_en; + + if (!ipu_plane->dp) + return -EINVAL; + + global_alpha_en = ((global_alpha & (1 << 8)) != 0); + global_alpha &= ~(1 << 8); + + if (ipu_plane->global_alpha_en == global_alpha_en && + ipu_plane->global_alpha == global_alpha) + return 0; + + ipu_plane->global_alpha_en = global_alpha_en; + ipu_plane->global_alpha = global_alpha; + + if (!ipu_plane->enabled) + return 0; + + return ipu_dp_set_global_alpha(ipu_plane->dp, + ipu_plane->global_alpha_en, + ipu_plane->global_alpha, is_bg); +} + +static int ipu_plane_set_colorkey(struct ipu_plane *ipu_plane, + u32 colorkey) +{ + bool colorkey_en; + + if (!ipu_plane->dp) + return -EINVAL; + + colorkey_en = ((colorkey & (1 << 24)) != 0); + colorkey &= ~(1 << 24); + + if (ipu_plane->colorkey_en == colorkey_en && + ipu_plane->colorkey == colorkey) + return 0; + + ipu_plane->colorkey_en = colorkey_en; + ipu_plane->colorkey = colorkey; + + if (!ipu_plane->enabled) + return 0; + + return ipu_dp_set_chroma_key(ipu_plane->dp, + ipu_plane->colorkey_en, + ipu_plane->colorkey); +} + +static int ipu_plane_set_property(struct drm_plane *plane, + struct drm_property *property, + uint64_t value) +{ + struct ipu_plane *ipu_plane = to_ipu_plane(plane); + int ret; + + DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); + + if (property == ipu_plane->global_alpha_prop) + ret = ipu_plane_set_global_alpha(ipu_plane, value); + else if (property == ipu_plane->colorkey_prop) + ret = ipu_plane_set_colorkey(ipu_plane, value); + else + ret = -EINVAL; + + return ret; +} + static struct drm_plane_funcs ipu_plane_funcs = { .update_plane = ipu_update_plane, .disable_plane = ipu_disable_plane, .destroy = ipu_plane_destroy, + .set_property = ipu_plane_set_property, }; -struct ipu_plane *ipu_plane_init(struct drm_device *dev, struct ipu_soc *ipu, +struct ipu_plane *ipu_plane_init(struct drm_device *drm, struct ipu_soc *ipu, int dma, int dp, unsigned int possible_crtcs, bool priv) { @@ -355,15 +446,58 @@ struct ipu_plane *ipu_plane_init(struct drm_device *dev, struct ipu_soc *ipu, ipu_plane->dma = dma; ipu_plane->dp_flow = dp; - ret = drm_plane_init(dev, &ipu_plane->base, possible_crtcs, + ret = drm_plane_init(drm, &ipu_plane->base, possible_crtcs, &ipu_plane_funcs, ipu_plane_formats, ARRAY_SIZE(ipu_plane_formats), priv); if (ret) { DRM_ERROR("failed to initialize plane\n"); - kfree(ipu_plane); - return ERR_PTR(ret); + goto err_free; } + /* default global alpha is enabled and completely opaque */ + ipu_plane->global_alpha_en = true; + ipu_plane->global_alpha = 255; + + /* for private planes, skip setting up properties */ + if (priv) + return ipu_plane; + + /* + * global alpha range is 0 - 255. Bit 8 is used as a + * flag to disable or enable global alpha. + */ + ipu_plane->global_alpha_prop = drm_property_create_range(drm, 0, + "alpha", + 0, 0x1ff); + if (!ipu_plane->global_alpha_prop) { + DRM_ERROR("failed to create global alpha property\n"); + ret = -ENOMEM; + goto err_free; + } + + /* + * The color key is an RGB24 value. Bit 24 is used as a + * flag to disable or enable color keying. + */ + ipu_plane->colorkey_prop = drm_property_create_range(drm, 0, + "colorkey", + 0, 0x01ffffff); + if (!ipu_plane->colorkey_prop) { + DRM_ERROR("failed to create colorkey property\n"); + ret = -ENOMEM; + goto err_free; + } + + drm_object_attach_property(&ipu_plane->base.base, + ipu_plane->global_alpha_prop, + 0x1ff); + drm_object_attach_property(&ipu_plane->base.base, + ipu_plane->colorkey_prop, + 0); return ipu_plane; + +err_free: + kfree(ipu_plane); + return ERR_PTR(ret); } diff --git a/drivers/staging/imx-drm/ipuv3-plane.h b/drivers/staging/imx-drm/ipuv3-plane.h index c0aae5b..b4daee5 100644 --- a/drivers/staging/imx-drm/ipuv3-plane.h +++ b/drivers/staging/imx-drm/ipuv3-plane.h @@ -27,6 +27,13 @@ struct ipu_plane { int x; int y; + struct drm_property *global_alpha_prop; + struct drm_property *colorkey_prop; + bool global_alpha_en; + u32 global_alpha; + bool colorkey_en; + u32 colorkey; + bool enabled; };