Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3235030rwo; Fri, 4 Aug 2023 01:18:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFYH+JmUVmTBLd5ashZyjauVuSm2foDLenmFl9L3fQuIqEAQkBvUQ4Ch08AjEy96371fa+M X-Received: by 2002:a05:6358:9206:b0:135:3f5c:9675 with SMTP id d6-20020a056358920600b001353f5c9675mr1312941rwb.19.1691137080759; Fri, 04 Aug 2023 01:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691137080; cv=none; d=google.com; s=arc-20160816; b=yHwQyTydQbyGoqRfPq2nAigZIjjseKYwrthMGWdcmOS6PrrQ6MbXBV6Z3RsVEtijzr 9e1+fN6L/7BwwhQ9tFQRoBIHwg1tgyVZgA1o5I9pPpoNJmNTGbGyvZdGGiGyufB3YDXc LHQEw9JN33fE9fcIB36/B8eKWsMYnUTCpehO08NlkeN0zIrnCfefoYQXIYKe6WqnJfaz YDlyWNBIAFl1bc2usew/j0URwugLVm9s6Z4y5zicrhYlLWyHY1Mi34Hd/cVp7CLxTrxt njYlelGoKrv/0a8dtd03LuA2YR9JC9TrP/PkyeWtUM1faCYQKawbraBfRHJQpBGqDOsW e/Ng== 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=KrhrYJjj0iCkUTzbVZgmlZw0Jyqjtlkt8XtUKAvHtdo=; fh=wVZEQimxp/UyE4Mf0Sn+nsZcfrBLHvkvU7kacOC/59o=; b=tObqDfMyK+zbzZs2koEYT34gzMrIrh67dV7xbZgtUmjkHK4hIFQCA2PEp5xBSenIOS kwv6FFHz8cdTHSam8IpdJnkBDBjYmQ51vHSgDA48PbsE4uGI+5mMryoVEaUoXtu0kdIP BraiBXU9B4WtRFk2PfMVMDhyPXoAiqOHmte5efFABOQoN8WHbNcSjOVtr7qRULuJvM3/ vL8NXV0MvvO30MZhFx7fve2O2wzcEvRJX26Z4LdfpLPjW9BGU8fZ022URrlhjjBz96Hc Hxo5IB4R5mfswF6lajYEyNcNgsvm08Uu6XIynaTi9JRJR/ncwywmgV6q7kGb9rtykN0V iqCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=OsX9MPNA; 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 e62-20020a636941000000b00563aa631e7esi1343525pgc.34.2023.08.04.01.17.48; Fri, 04 Aug 2023 01:18:00 -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=OsX9MPNA; 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 S230261AbjHDH3y (ORCPT + 99 others); Fri, 4 Aug 2023 03:29:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234182AbjHDH3K (ORCPT ); Fri, 4 Aug 2023 03:29:10 -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 A6C773ABA for ; Fri, 4 Aug 2023 00:29:09 -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 C8B1466071CB; Fri, 4 Aug 2023 08:29:07 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1691134148; bh=Xw0ZEaJZnUUVzop6jWBNiSdfQOZObWFWliMoyYC7chw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OsX9MPNAZbTa5XIyyWo/RqHN2N2WUvFMSp6q28yLZBH2WIC4ARPTUAcEBpbYaBz9Q yC7GqT8adcDIUmbS6xVO3sSqbMxU840Sz/Tm3VQ4+8HUZ1jO/oHURdInQLc8Js7sZc xsyEROIAieg1X83xcjHz5MEts5Q1ztdWA7rsXchne/LtAKg/wn1qkytFj03zS6W3mx S8enzxilUOHUfpBuHAFJRyfHrHiWaZkJzQVAXA1xhXnm64dGXdzH8sYudHqdFA2Jcm Z/qYpJ2xlgg+JhnK7LS0LE9esiEYxZnZzzywhUGEAWKoz4WwsMLg3EozbcSWnm4qWR afxt8uV61qqlQ== 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 v10 13/16] drm/mediatek: gamma: Program gamma LUT type for descending or rising Date: Fri, 4 Aug 2023 09:28:47 +0200 Message-ID: <20230804072850.89365-14-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230804072850.89365-1-angelogioacchino.delregno@collabora.com> References: <20230804072850.89365-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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,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 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index fbff9f97b737..d9a70238d524 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) @@ -86,6 +87,17 @@ unsigned int mtk_gamma_get_lut_size(struct device *dev) return LUT_SIZE_DEFAULT; } +static bool mtk_gamma_lut_is_descending(struct drm_color_lut *lut, u32 lut_size) +{ + u64 first, last; + int last_entry = lut_size - 1; + + first = lut[0].red + lut[0].green + lut[0].blue; + last = lut[last_entry].red + lut[last_entry].green + lut[last_entry].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 @@ -175,6 +187,14 @@ void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state) } } + if (!gamma->data->has_dither) { + /* Descending or Rising LUT */ + if (mtk_gamma_lut_is_descending(lut, gamma->data->lut_size - 1)) + 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.41.0