Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2164170rwb; Thu, 27 Jul 2023 03:10:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlF475pdx0dgMiXX6rlBr5dGpvD1qc/7TgVi6+UTdckSbHSpNKmRn1R6hM3fibkcZylfi86W X-Received: by 2002:a05:6808:218c:b0:3a4:1b66:5494 with SMTP id be12-20020a056808218c00b003a41b665494mr3358075oib.44.1690452651340; Thu, 27 Jul 2023 03:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690452651; cv=none; d=google.com; s=arc-20160816; b=uoSF1Rlm9iOU3ZKORgI0Xn2Ijgq2XtPETrcjQPmyJmYqNoCAXuObt9VeHmF1T4uykE eEFcf2oCJKM1gNEo8f0Ges3of0Bb8n5G6iBxnayDv63sqMxdYFJ3au260U1eA1hKEnVB r24iYmqSjVM16tjK8tm6NKXCDS6WMfu3ZIGOO1K0XERT4sZH8rqsyAZE3qapQYTM61Kt 0VI6MJfaKh7JSsim88g9Va0m9Xv0uCkzgkSRWAmbhEtYC0uwp5yPiGLJZRefpER3xoQu nhQuLGa6ILeLZaspDpKbUi7bKjqgbvrNDwy+maeTahJtvWWkCk+ydyc8fAd1rUJaJDq5 Chag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HOJPDAsDAzPJAXrk5OeI7BM1OcqzDQiFMWcf16Njpok=; fh=djell8ixvcyqU/mJ6veJqcbgRwD4nTeRiXMTlgu2sHI=; b=aw4UtUNlm4moiYe+hTL3XLykF/IGjR5M54jJ0YNThUC7ZrVIhi7dkOoRYCM6GnqZJ9 sSIjMYO4vkzHRvSSGpbL9WXCKHn67Zgu3YIByVBGu1gT36NTbjnjm/nXmUUiT8Xaag6r 6Y1hmL9YVB8417DeCjMbLCWqWCQDwmFy3NkaMPo4Lmhbc5Xy1ttTxhgud9/p5JA/C09d Tk4zzV3SAByVDWpO6Y0miVgnX57JeUfmaaKjgB1NHWjOZvTYj8xhFR90Tur7tVLv7ZG+ ThnO0Y6PV9O/GSq1mhfjJ2CfQBlHg9cXIanAB6UXvLWmZJGh7XV7Cmvtbmzw/u/KUWeG yxfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=hRUYCKLi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a63de0a000000b0055ab9bf1e3csi1032608pgg.738.2023.07.27.03.10.39; Thu, 27 Jul 2023 03:10:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=hRUYCKLi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233064AbjG0Jrh (ORCPT + 99 others); Thu, 27 Jul 2023 05:47:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233142AbjG0Jqy (ORCPT ); Thu, 27 Jul 2023 05:46:54 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7830111D for ; Thu, 27 Jul 2023 02:46:49 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 9A9676607175; Thu, 27 Jul 2023 10:46:47 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1690451208; bh=0Iha/JOTYyfiitNl2/tF672JZIUVhHcbx0vgBiZKTc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hRUYCKLiNNMNeaZ6LtmbttbslYB06NAh6Ow5BUdEJcf5qkFsiEQ4wVF63i44gy7XQ C/4pA+yG0SDMdgseo6EXuzk1b9S4s1cUHw0eLcsNJEwlAwbS8GAfB8Wleuaxkq+NKP zCQWBi4c5aR6bTrFr6u1XaicI9C6iCSZoJUggrMl6cJWqvYsstmZVM3bb2gVKlG6SK q+yYPqt5I+DkoYV0Urv3VABn6n+TZK16pEv4L6PfdrQEAMEpPOBV6tnq/Vanjf064F dkh3gXR4ERN3v/o+otO6qSu9fhfprCPjshYWzkgzARI8VFbZymJlFmAcRlXGDHx6EH Kj2+jl03e9YWQ== From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Cc: p.zabel@pengutronix.de, airlied@gmail.com, daniel@ffwll.ch, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, wenst@chromium.org, kernel@collabora.com, ehristev@collabora.com, "Jason-JH . Lin" Subject: [PATCH RESEND v6 11/11] drm/mediatek: gamma: Program gamma LUT type for descending or rising Date: Thu, 27 Jul 2023 11:46:33 +0200 Message-ID: <20230727094633.22505-12-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727094633.22505-1-angelogioacchino.delregno@collabora.com> References: <20230727094633.22505-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org All of the SoCs that don't have dithering control in the gamma IP have got a GAMMA_LUT_TYPE bit that tells to the IP if the LUT is "descending" (bit set) or "rising" (bit cleared): make sure to set it correctly after programming the LUT. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Jason-JH.Lin --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index e9655b661364..020755ae0ec0 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -23,6 +23,7 @@ #define GAMMA_RELAY_MODE BIT(0) #define GAMMA_LUT_EN BIT(1) #define GAMMA_DITHERING BIT(2) +#define GAMMA_LUT_TYPE BIT(2) #define DISP_GAMMA_SIZE 0x0030 #define DISP_GAMMA_SIZE_HSIZE GENMASK(28, 16) #define DISP_GAMMA_SIZE_VSIZE GENMASK(12, 0) @@ -89,6 +90,16 @@ unsigned int mtk_gamma_get_lut_size(struct device *dev) return lut_size; } +static bool mtk_gamma_lut_is_descending(struct drm_color_lut *lut, u32 lut_size) +{ + u64 first, last; + + first = lut[0].red + lut[0].green + lut[0].blue; + last = lut[lut_size].red + lut[lut_size].green + lut[lut_size].blue; + + return !!(first > last); +} + void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crtc_state *state) { struct mtk_disp_gamma *gamma = dev_get_drvdata(dev); @@ -178,6 +189,14 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt } } + if (gamma && gamma->data && !gamma->data->has_dither) { + /* Descending or Rising LUT */ + if (mtk_gamma_lut_is_descending(lut, lut_size)) + cfg_val |= FIELD_PREP(GAMMA_LUT_TYPE, 1); + else + cfg_val &= ~GAMMA_LUT_TYPE; + } + /* Enable the gamma table */ cfg_val |= FIELD_PREP(GAMMA_LUT_EN, 1); -- 2.40.1