From patchwork Wed Apr 11 20:49:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schake X-Patchwork-Id: 10337301 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 9F1686053B for ; Wed, 11 Apr 2018 20:49:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FA5526E54 for ; Wed, 11 Apr 2018 20:49:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 840DA27FB1; Wed, 11 Apr 2018 20:49:42 +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=-5.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 33C8326E54 for ; Wed, 11 Apr 2018 20:49:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0FBA76E703; Wed, 11 Apr 2018 20:49:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 135B36E703 for ; Wed, 11 Apr 2018 20:49:37 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id g8so6887229wmd.2 for ; Wed, 11 Apr 2018 13:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MbYy/ACkg3UcTKVU58UP06tQbSEnQAj1LO0qJwQ/wxE=; b=rp6VJsT60o0ZqbNd86bXZraHq69xNK+VjT7S7jpIOM9pVWxmpTYdeWXZO79M/9ea3s z12ZMkh0PQJQ8UKwF3oCFuvYp0J3XR/LXHqlbu26XjxdQASAc2kD2X6+IiC+zN4ubJFd 7HvfjEkQKJOn9j5QccpfZJQMI+Kixs6uhpq/C9aYN37HMNoUK7eBRyAQTNl6U/+ZsZPE v0Ft8ZAeb0GNlJk6vtt9XW5ZuDJSrMZN0jR4sRZMEpvLUkDHjcHGVJh8l2Y02AlEfpeI lI9k7rk+o7QlTBRhTtO9N0fyZewyzNTRSfixoggXaySy8V6j+VyXSRxyszO647jdaSPr 8xpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MbYy/ACkg3UcTKVU58UP06tQbSEnQAj1LO0qJwQ/wxE=; b=S5CIxk8RyiwgICnsnsA9KuRwIDJfR1iwE5/JHl0yojykn9Ba1OGkE1dArzGrAO5nHl txkCBjxh80cJgYF5kyXvO/3wJ/cRlOFp5pw8JvN7Ucz0EPI0YVkt97hz842GwUbGnsdZ AdbR4F962pvMtQJ5YXMyYgVLHhY9mx2nHNsZy079KfJACZZI1w+n2J4mzbV0NZHHLEfs kqkDoWTCjTptxVNx5Z+uqvv3TrTuSJA472G5JrOtq4JYUXE6N9D1O1yOhiat3NRJDEPG kV0BvCpDUwYD0sUcqo9KbGK/r7/jpPAGx+xmieJWlj8YX5wx0buH13NNknuOU7aOiRmU 8nyA== X-Gm-Message-State: ALQs6tDF5ylrCZ4XCEQ+4Zt7TTAheZZc+YLoTVGCTWRlfZrIu2eRPrtz zXOvocSemKcyr3HbvoMW/gM= X-Google-Smtp-Source: AIpwx49NPalajl9DzbWSFCJ3kfTWW0Dcyafq57Wzyena/Q5rGg5dKAv+ye2YcBhDZfYKCV5+ac2qQw== X-Received: by 10.28.101.6 with SMTP id z6mr3352228wmb.110.1523479775498; Wed, 11 Apr 2018 13:49:35 -0700 (PDT) Received: from localhost.localdomain (x4db52ef0.dyn.telefonica.de. [77.181.46.240]) by smtp.gmail.com with ESMTPSA id 10sm2710816wrz.58.2018.04.11.13.49.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Apr 2018 13:49:34 -0700 (PDT) From: Stefan Schake To: eric@anholt.net Subject: [PATCH v3 2/4] drm/vc4: Expose gamma as atomic property Date: Wed, 11 Apr 2018 22:49:13 +0200 Message-Id: <1523479755-20812-3-git-send-email-stschake@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523479755-20812-1-git-send-email-stschake@gmail.com> References: <1523479755-20812-1-git-send-email-stschake@gmail.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: airlied@linux.ie, linux-rpi-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, Stefan Schake MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP We are an atomic driver so the gamma LUT should also be exposed as a CRTC property through the DRM atomic color management. This will also take care of the legacy path for us. Signed-off-by: Stefan Schake --- v2: Use drm_color_lut_size for LUT length v3: Disable gamma lut when gamma_lut is NULL (Eric) drivers/gpu/drm/vc4/vc4_crtc.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c index bf46674..285f88d 100644 --- a/drivers/gpu/drm/vc4/vc4_crtc.c +++ b/drivers/gpu/drm/vc4/vc4_crtc.c @@ -298,23 +298,21 @@ vc4_crtc_lut_load(struct drm_crtc *crtc) HVS_WRITE(SCALER_GAMDATA, vc4_crtc->lut_b[i]); } -static int -vc4_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, - uint32_t size, - struct drm_modeset_acquire_ctx *ctx) +static void +vc4_crtc_update_gamma_lut(struct drm_crtc *crtc) { struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc); + struct drm_color_lut *lut = crtc->state->gamma_lut->data; + u32 length = drm_color_lut_size(crtc->state->gamma_lut); u32 i; - for (i = 0; i < size; i++) { - vc4_crtc->lut_r[i] = r[i] >> 8; - vc4_crtc->lut_g[i] = g[i] >> 8; - vc4_crtc->lut_b[i] = b[i] >> 8; + for (i = 0; i < length; i++) { + vc4_crtc->lut_r[i] = drm_color_lut_extract(lut[i].red, 8); + vc4_crtc->lut_g[i] = drm_color_lut_extract(lut[i].green, 8); + vc4_crtc->lut_b[i] = drm_color_lut_extract(lut[i].blue, 8); } vc4_crtc_lut_load(crtc); - - return 0; } static u32 vc4_get_fifo_full_level(u32 format) @@ -699,6 +697,22 @@ static void vc4_crtc_atomic_flush(struct drm_crtc *crtc, if (crtc->state->active && old_state->active) vc4_crtc_update_dlist(crtc); + if (crtc->state->color_mgmt_changed) { + u32 dispbkgndx = HVS_READ(SCALER_DISPBKGNDX(vc4_crtc->channel)); + + if (crtc->state->gamma_lut) { + vc4_crtc_update_gamma_lut(crtc); + dispbkgndx |= SCALER_DISPBKGND_GAMMA; + } else { + /* Unsetting DISPBKGND_GAMMA skips the gamma lut step + * in hardware, which is the same as a linear lut that + * DRM expects us to use in absence of a user lut. + */ + dispbkgndx &= ~SCALER_DISPBKGND_GAMMA; + } + HVS_WRITE(SCALER_DISPBKGNDX(vc4_crtc->channel), dispbkgndx); + } + if (debug_dump_regs) { DRM_INFO("CRTC %d HVS after:\n", drm_crtc_index(crtc)); vc4_hvs_dump_state(dev); @@ -909,7 +923,7 @@ static const struct drm_crtc_funcs vc4_crtc_funcs = { .reset = vc4_crtc_reset, .atomic_duplicate_state = vc4_crtc_duplicate_state, .atomic_destroy_state = vc4_crtc_destroy_state, - .gamma_set = vc4_crtc_gamma_set, + .gamma_set = drm_atomic_helper_legacy_gamma_set, .enable_vblank = vc4_enable_vblank, .disable_vblank = vc4_disable_vblank, }; @@ -1035,6 +1049,7 @@ static int vc4_crtc_bind(struct device *dev, struct device *master, void *data) primary_plane->crtc = crtc; vc4_crtc->channel = vc4_crtc->data->hvs_channel; drm_mode_crtc_set_gamma_size(crtc, ARRAY_SIZE(vc4_crtc->lut_r)); + drm_crtc_enable_color_mgmt(crtc, 0, false, crtc->gamma_size); /* Set up some arbitrary number of planes. We're not limited * by a set number of physical registers, just the space in