From patchwork Tue Aug 1 11:58:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 129335 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2731701vqg; Tue, 1 Aug 2023 08:06:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlEcVnXL38MCKxDPUEhK9hAN2ZxIPEhL4edP8oEYq8bo/lWukJl0/dk3U+RZsrjNYVAuQfdF X-Received: by 2002:a05:6a20:394d:b0:134:a4e2:4ac8 with SMTP id r13-20020a056a20394d00b00134a4e24ac8mr13674493pzg.39.1690902407055; Tue, 01 Aug 2023 08:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690902406; cv=none; d=google.com; s=arc-20160816; b=ZcGFxGfP1AIQefhlnBX8WQ1phycBPV6YRmX8fI9onphuyMm0OUmk+inLHjoJ7bUZg/ HSHQdjGYkVIdJ9DuEcW/lRD93a6zSvk7gBvTU5eXLmhJkATn57WHqJ1PcRLiuts8gBSc W1ERvUrZmeYInQRrmwNGvhDe39vCS2cgrkoYTIO7SV3n1QlfUNrFUYYhWl2DtTyf69EQ IwcjgrP6qdDgmpWKzdIGoXYCAzEqiXqDmWQc2bZfV13f8iuu8qrPC3WqCQvl0DPi+r7M VaAe54SFi3UZjCTx7tRnqIxPDUW3PTORKJktr5LQK8mdfBYE5LVF9x1MGGNP3aPs7TGU YzAQ== 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=UNihVARbpmZ5nC9MOnplVf6/4JU0g8pcltwHqI+PhG8=; fh=wVZEQimxp/UyE4Mf0Sn+nsZcfrBLHvkvU7kacOC/59o=; b=fzj5Ybz8ArGjwWLT2t+YN76LnzNZxugEaVndvHHGrT9Ho2KDhAy7oGIn0qfgP78p69 eamKHcyypZKVcpWm8hxA9ia4qvjJzRjmbW9ltm7V/WGVychk8hd6afJgMgpstVgVrm7E wJDT1HQpoehD+awO2GrY2JNhEdBnsv5/9tlET4GMyA+xT1TseEgIhZu7yanZOUW4OIKe Am2wEE1E7NwqQzR86JZyDxCyVePQxZ5h097MrRxNhjcZH3BrRzaZKwuNi4781tqAGlQU IhMZxYNDKLGfrqMk7EovoeqfKIqKex03vIb4kMUF+TWN4XC3TIO9sDDuY9H5lcyEsKHQ QY5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=hI5DV91Y; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ct20-20020a056a000f9400b006870ad022d2si839028pfb.34.2023.08.01.08.06.16; Tue, 01 Aug 2023 08:06:46 -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=hI5DV91Y; 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 S234457AbjHAL7i (ORCPT + 99 others); Tue, 1 Aug 2023 07:59:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234420AbjHAL7X (ORCPT ); Tue, 1 Aug 2023 07:59:23 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47A2C1BD3 for ; Tue, 1 Aug 2023 04:59:12 -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 189EE6607187; Tue, 1 Aug 2023 12:59:10 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1690891150; bh=UAAO2HoKPXD+qG8ixrf5L5LtVEeyeVBuoZsSD3TuWEI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hI5DV91YdjAsWDodW5XhndupE/+dPYBgPFyZXjRaTtIt34+OT4Kst9HhWTcnAnRqQ Tc4ibpxhIspeMPekDJk1UnEwnam3guR4KpDcWhzZJ0p8vGo14x3bbI8B7a5PegtzBD AkdFFCO0QihXrwAqDBpxaB41ohzynYyxqdDvjvA3yYECcj2oqsWcByS7ID/767u+fF 2kW5gllIV5kIsS9SpuuIxprMs+h4ZqzEdodKmFsIb2ZnAezEIyUYTafJWo2DrpZ5BZ 4Uk1gnA85rPYlgAVqFW332nCfG696JN0v4Pd4G1M46ctE4cZhSsVLoEb4vVmmPhxyV fw9GGQHKDgTFw== 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" , Alexandre Mergnat Subject: [PATCH v8 11/13] drm/mediatek: gamma: Program gamma LUT type for descending or rising Date: Tue, 1 Aug 2023 13:58:52 +0200 Message-ID: <20230801115854.150346-12-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801115854.150346-1-angelogioacchino.delregno@collabora.com> References: <20230801115854.150346-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 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,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773039682264726789 X-GMAIL-MSGID: 1773039682264726789 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 Reviewed-by: Alexandre Mergnat --- 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 6591797ed10c..c6b77ca3e655 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -22,6 +22,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) @@ -84,6 +85,16 @@ unsigned int mtk_gamma_get_lut_size(struct device *dev) return gamma->data->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); +} + /* * SoCs supporting 12-bits LUTs are using a new register layout that does * always support (by HW) both 12-bits and 10-bits LUT but, on those, we @@ -190,6 +201,14 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, } } + 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);