From patchwork Thu May 18 10:48:47 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: 95770 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp399315vqo; Thu, 18 May 2023 03:59:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4yNWsMC5hf3TA5fCDjBEfG1d/XAq22VSSE5LIF2gKIB7K9ZyCsjCE64nIe+E7jyT5+c/Jh X-Received: by 2002:a05:6a00:15c1:b0:64c:ae1c:3385 with SMTP id o1-20020a056a0015c100b0064cae1c3385mr4327528pfu.32.1684407577605; Thu, 18 May 2023 03:59:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684407577; cv=none; d=google.com; s=arc-20160816; b=XWJVeVyhIyGCxnIR0YQga07fUEruyLTSeUSpnuGKmAwCyzjqdh3ifLqV+RjVKGbjyW OuQk+GxkRmSHorvARjaQvlrtm6WEaJsePW/vbHfOA8SsYq/GK6tNhCoGg2HqMK92TMYC w8TBkKD73kmR73jsZXZ/bJvbCd8GZM4F2BHPaY7vnDuJMuYx9vXl1vIeXc1cryZZT1+4 oKsSogWFTV8KHdhxoV+b0NQnDEte/9/OupfGhYMCQ3GNPny+4V3X6R9z1Xu+dwgCz4Nr C/sYxhr6bxEwRmNcEW8qbx7OB3rYZuQ70VKbu9p0UOfjX6pV7Ldt2IRkJfk+0x8CPk4K ubhA== 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=ZeueyH8CDgooMtutBLaT2Zvz13XZWzsV4aU7WjAbI+M=; b=jHH7pYLxVNgkCMi5w3vVmgodVd77OB0elz9DAedcLq/T+K+ONsPDlkSUI0hpPsM3XO M9hs+vipMyDrc41giBfgtLP13DGt9Oqnhn9EXAGH8sE4mrfsEd5eayrWNMeTkjcAPxP3 lO0jOLP13KDFPoxCqlcuD9DcQzMLpPbwvc49YjctlkiofUaEoHIqnbxN/jaXHn+zwjNX usiNrypxO1sZ9QHDyXTEPsnel4Htxi46L7nKbK8MQZMzmWrA1owrC6QveyyaFDxRIxVP ocH2+AYoF8tAOdZFG8lHMZ0LOpzQkh/Zlm7WtJ0JrwuP8jeQYTiZ/epPKDMC5fp6kSaW sj7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=VsFTRfLE; 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 p9-20020a639509000000b0053425243529si1251276pgd.323.2023.05.18.03.59.21; Thu, 18 May 2023 03:59:37 -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=VsFTRfLE; 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 S230245AbjERKtL (ORCPT + 99 others); Thu, 18 May 2023 06:49:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbjERKtF (ORCPT ); Thu, 18 May 2023 06:49:05 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A071E6E for ; Thu, 18 May 2023 03:49:04 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (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 BE5AE660595F; Thu, 18 May 2023 11:49:01 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684406942; bh=fWabP2S9MKC6+Yi0YWqUcPZxSafl399il5KPixyXdlw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VsFTRfLE5gFxHG6e7xgZNfajzDNf1zwF3d8k2C85UxBhAdmYa6wJzdgZrdKB6ofx3 Vixgf76EB7TgykgzurSAPws4gOJRmaUS/+HgmgQuLNNoMEOj0NFNZEYIpIFFSbykNu ADQOff2GvpSTiOj7JkohZ0+0lCVC3+jxob5aJ7mhjukUA2+NlybATeKfxt4igKPTjA aBACPXy+vT0/ujvgO72hRp5a4o1rO+Mvkqqx+s5logV/pn81RCg9Ux7A7R5XSDNe+g giq/iAgDbxB+8VKdvf+1j785GFyXiVDLFZSicZZKYmX8RyRo186hH2h9zYuCxaQZxc 8gaA0lxY5wq9w== 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, "Jason-JH.Lin" Subject: [PATCH v4 01/11] drm/mediatek: gamma: Adjust mtk_drm_gamma_set_common parameters Date: Thu, 18 May 2023 12:48:47 +0200 Message-Id: <20230518104857.124265-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518104857.124265-1-angelogioacchino.delregno@collabora.com> References: <20230518104857.124265-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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766229359960695171?= X-GMAIL-MSGID: =?utf-8?q?1766229359960695171?= From: "Jason-JH.Lin" Adjust the parameters in mtk_drm_gamma_set_common() - add (struct device *dev) to get lut_diff from gamma's driver data - remove (bool lut_diff) and use false as default value in the function Signed-off-by: Jason-JH.Lin Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_disp_aal.c | 2 +- drivers/gpu/drm/mediatek/mtk_disp_drv.h | 2 +- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_aal.c b/drivers/gpu/drm/mediatek/mtk_disp_aal.c index 434e8a9ce8ab..8ddf7a97e583 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_aal.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_aal.c @@ -67,7 +67,7 @@ void mtk_aal_gamma_set(struct device *dev, struct drm_crtc_state *state) struct mtk_disp_aal *aal = dev_get_drvdata(dev); if (aal->data && aal->data->has_gamma) - mtk_gamma_set_common(aal->regs, state, false); + mtk_gamma_set_common(NULL, aal->regs, state); } void mtk_aal_start(struct device *dev) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_drv.h b/drivers/gpu/drm/mediatek/mtk_disp_drv.h index 2254038519e1..75045932353e 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_drv.h +++ b/drivers/gpu/drm/mediatek/mtk_disp_drv.h @@ -54,7 +54,7 @@ void mtk_gamma_config(struct device *dev, unsigned int w, unsigned int h, unsigned int vrefresh, unsigned int bpc, struct cmdq_pkt *cmdq_pkt); void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state); -void mtk_gamma_set_common(void __iomem *regs, struct drm_crtc_state *state, bool lut_diff); +void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crtc_state *state); void mtk_gamma_start(struct device *dev); void mtk_gamma_stop(struct device *dev); diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index c844942603f7..99be515a941b 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -55,14 +55,21 @@ void mtk_gamma_clk_disable(struct device *dev) clk_disable_unprepare(gamma->clk); } -void mtk_gamma_set_common(void __iomem *regs, struct drm_crtc_state *state, bool lut_diff) +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); unsigned int i, reg; struct drm_color_lut *lut; void __iomem *lut_base; + bool lut_diff; u32 word; u32 diff[3] = {0}; + if (gamma && gamma->data) + lut_diff = gamma->data->lut_diff; + else + lut_diff = false; + if (state->gamma_lut) { reg = readl(regs + DISP_GAMMA_CFG); reg = reg | GAMMA_LUT_EN; @@ -92,12 +99,8 @@ void mtk_gamma_set_common(void __iomem *regs, struct drm_crtc_state *state, bool void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state) { struct mtk_disp_gamma *gamma = dev_get_drvdata(dev); - bool lut_diff = false; - - if (gamma->data) - lut_diff = gamma->data->lut_diff; - mtk_gamma_set_common(gamma->regs, state, lut_diff); + mtk_gamma_set_common(dev, gamma->regs, state); } void mtk_gamma_config(struct device *dev, unsigned int w, From patchwork Thu May 18 10:48:48 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: 95755 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp395579vqo; Thu, 18 May 2023 03:50:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Fy7Hz4l6U7jEPYv/a5OXBhED9d3FfEMJWusm0NXazNQ60ixeCDrAVIVj/41O7QWio9aGX X-Received: by 2002:a17:90b:1954:b0:244:9385:807f with SMTP id nk20-20020a17090b195400b002449385807fmr2106549pjb.44.1684407043123; Thu, 18 May 2023 03:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684407043; cv=none; d=google.com; s=arc-20160816; b=NxLgf0JkTp1qKgM+//dzihl7ys5EChg/P7C6BYKfR10EwhdNFEc87P7ZpWRqfw3Vyh 4wfGAlCzBoSZBJrM8yzvQ5aVoIGHZ+QEr3MH4mn/mamnhRV09SC6CfoNecUc2IpPO+fT xgaX8SNdMwBaBlvhsF+z2duMsC+Mh4/U/E18uypl+vHLMsaXX6HmkJfAxlKQwOkQMWGl mi43dxavqO0e0nKG9sa2U5kreJac8DQG2a6KUo4PGwRIKDHFCiwU8NpNfY2MYFilP5kY zFiwiKwmwdUhQmeQhwTdLFZ3c3NV80ATnEiH/DW0ZDn0f/sSMcp3inU1N9QpCAIoZj87 ChSw== 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=oDZdjfx700FCXUnExZA7N92qMxI3xpd6M2geNmql5YU=; b=I5hni7YN5AimwYo957UrnROh4qY9jiJ0d7ADbLBTuo9Zzmm5e4lTiOCilkQjHaOdKh mnWlbfhd5pvJPb/ebwZmfCfBv2Ut+GdD4G36j43AdJnm91qYl/Ca0Dx/ZGbuQ22TZ4BA vhuOjOrP31JVmxjHKFefKHR3L0gO1dHzfrMOMlqJ9nSLqI4+y+gc0Y+RFQ8vXWuExa8V VbrCGC4RBLIna//dtAX3PZAiTrGqXNgshLoct0OyQoX0p7LuzL7PyI6u4EprzkfW95Il OT8WvvlSkV8I3pIyRw24FDqgUPcK1TGpS+XexP3SFI01mn1dGHVsHEAlkuo6GJVdjB36 R1Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=FR6h7WQa; 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 g4-20020a633744000000b005303a7ca052si1122649pgn.491.2023.05.18.03.50.29; Thu, 18 May 2023 03:50:43 -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=FR6h7WQa; 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 S230305AbjERKtO (ORCPT + 99 others); Thu, 18 May 2023 06:49:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229970AbjERKtG (ORCPT ); Thu, 18 May 2023 06:49:06 -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 A429410D0 for ; Thu, 18 May 2023 03:49:04 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (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 A5BED6605960; Thu, 18 May 2023 11:49:02 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684406943; bh=H1IjE6ks2/tQ62I5k+mdDy0LWtBtFX34NVlBCrVhdQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FR6h7WQaVO2sIwUbsFA0+c3756grpjEVsL88EHnxkhl6P9XJL9cgJ4MBluG2uSH4X 5rXNALZwbdceLMCRccxLRH1E6te1KFOsIaXQKXliRL5bO5tPXsP9Jtuyn83C39cQ5N oSiqFLrTH/7aQ6F9h0qxbDCGqxyv9dOT9rAeOcWJDDzTbUnvOewkxKtBD9LheuAeys 7mcNCSW1pvbQr3jIwB7Bl2asoNJ/PhIzpvfY5WIaYApxlbGKXAyjWbVrvNnUYe56bJ VzPpm4NnUwbd3y/tWyEvJkuLfeO9JnvvKVBDSDOdUd5wgKSQZmtxqJTIWPgU+AAqHS iih6TBPsu4fVg== 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, "Jason-JH . Lin" Subject: [PATCH v4 02/11] drm/mediatek: gamma: Reduce indentation in mtk_gamma_set_common() Date: Thu, 18 May 2023 12:48:48 +0200 Message-Id: <20230518104857.124265-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518104857.124265-1-angelogioacchino.delregno@collabora.com> References: <20230518104857.124265-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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766228799913441994?= X-GMAIL-MSGID: =?utf-8?q?1766228799913441994?= Invert the check for state->gamma_lut and move it at the beginning of the function to reduce indentation: this prepares the code for keeping readability on later additions. This commit brings no functional changes. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Jason-JH.Lin --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 45 ++++++++++++----------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index 99be515a941b..ce6f2499b891 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -65,34 +65,35 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt u32 word; u32 diff[3] = {0}; + /* If there's no gamma lut there's nothing to do here. */ + if (!state->gamma_lut) + return; + if (gamma && gamma->data) lut_diff = gamma->data->lut_diff; else lut_diff = false; - if (state->gamma_lut) { - reg = readl(regs + DISP_GAMMA_CFG); - reg = reg | GAMMA_LUT_EN; - writel(reg, regs + DISP_GAMMA_CFG); - lut_base = regs + DISP_GAMMA_LUT; - lut = (struct drm_color_lut *)state->gamma_lut->data; - for (i = 0; i < MTK_LUT_SIZE; i++) { - - if (!lut_diff || (i % 2 == 0)) { - word = (((lut[i].red >> 6) & LUT_10BIT_MASK) << 20) + - (((lut[i].green >> 6) & LUT_10BIT_MASK) << 10) + - ((lut[i].blue >> 6) & LUT_10BIT_MASK); - } else { - diff[0] = (lut[i].red >> 6) - (lut[i - 1].red >> 6); - diff[1] = (lut[i].green >> 6) - (lut[i - 1].green >> 6); - diff[2] = (lut[i].blue >> 6) - (lut[i - 1].blue >> 6); - - word = ((diff[0] & LUT_10BIT_MASK) << 20) + - ((diff[1] & LUT_10BIT_MASK) << 10) + - (diff[2] & LUT_10BIT_MASK); - } - writel(word, (lut_base + i * 4)); + reg = readl(regs + DISP_GAMMA_CFG); + reg = reg | GAMMA_LUT_EN; + writel(reg, regs + DISP_GAMMA_CFG); + lut_base = regs + DISP_GAMMA_LUT; + lut = (struct drm_color_lut *)state->gamma_lut->data; + for (i = 0; i < MTK_LUT_SIZE; i++) { + if (!lut_diff || (i % 2 == 0)) { + word = (((lut[i].red >> 6) & LUT_10BIT_MASK) << 20) + + (((lut[i].green >> 6) & LUT_10BIT_MASK) << 10) + + ((lut[i].blue >> 6) & LUT_10BIT_MASK); + } else { + diff[0] = (lut[i].red >> 6) - (lut[i - 1].red >> 6); + diff[1] = (lut[i].green >> 6) - (lut[i - 1].green >> 6); + diff[2] = (lut[i].blue >> 6) - (lut[i - 1].blue >> 6); + + word = ((diff[0] & LUT_10BIT_MASK) << 20) + + ((diff[1] & LUT_10BIT_MASK) << 10) + + (diff[2] & LUT_10BIT_MASK); } + writel(word, (lut_base + i * 4)); } } From patchwork Thu May 18 10:48:49 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: 95756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp395600vqo; Thu, 18 May 2023 03:50:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4JOOKTE/iU10DPzZl/UcpnfPy34MjtPKil94jYeAQFLd1KRbZy6n9THRMZZndc1/JBdG8L X-Received: by 2002:a17:90a:e56:b0:24e:165d:8f65 with SMTP id p22-20020a17090a0e5600b0024e165d8f65mr2205878pja.5.1684407046829; Thu, 18 May 2023 03:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684407046; cv=none; d=google.com; s=arc-20160816; b=YQdg1sctborndSux/Or8JG7Mfa/3/ph1v74xLvMnToCFQPJaZ6mKQ322WdCJphGqRo Cuzm/Of+aMD9kxU99rgsy7dla2AD+8DU5LpB2z2IvOEMolPlHDR2E2fOa8yuxgeUzQrw 1/vCrWL5tDoUavdvWE2b/7HTo7uFNyjCQeHJxanL4C68u9IDaX/uCbBntN1ysvlmw0pK zzq/pmaTiB/oUVATBJ/7Y7VhUVcNRTpnFNURKfYTV71kaQre2JaEUBq9QEe8AOufxrbP CWSW3/B3FX04VBehhA73tqp4iHsqbVVJcmx6mgsX8bFsPIfNh6mnEfGdH3kBwBu12UcY HwhA== 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=9lEMbXkGSZKllwrvoHyDeV993Hdl12DKbO5H22RXtEo=; b=JNoz8tY9T/y08fhuh8WOTIfCKp2oSncr658RALODSpo7e8+ehCu8vgB1kXyO6Y6gGe 0NNuhsyXsdcLxx5wrS8r4cYh+ZUrO7+oku/uBh+cQimNXT11Vez/rr6eFRXat1/e7zC8 eQOhUJzz0x0Yv8MlSFPhNM9xqRNWBr4Whajvm51tnKuRyqr2F9laXQcr3xj+JuE3w2SC OMl3ZBVUwuxHPvomMykFqeOxCRXQWlMPKKN3tCqd837Loke8JuLh3n3sbhbGRBzgJC45 pl9NyHaak2FqUANr6racNkrGJNfbz2Q3iqG/yx3fntUaN8yg7A1mbSX+sL/vpgg9zX7f rbkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=MkbRBzZ2; 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 nm14-20020a17090b19ce00b00246f8b06125si3885675pjb.108.2023.05.18.03.50.31; Thu, 18 May 2023 03:50: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=MkbRBzZ2; 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 S230133AbjERKtR (ORCPT + 99 others); Thu, 18 May 2023 06:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229988AbjERKtH (ORCPT ); Thu, 18 May 2023 06:49:07 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 862CE10D8 for ; Thu, 18 May 2023 03:49:05 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (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 8F3E66605962; Thu, 18 May 2023 11:49:03 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684406944; bh=VUNH7xC268Wv4Z7pwW4jbyqCvfXQFP1Ez/xgKn5u584=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MkbRBzZ2qHajJ6IcPzq9cUWRYCSu/moCcfzIA8HypFmB7UVkVAdagD/G5sRS83cUv laRmx0F+DLWxUET0pTeZOiD5XlPf/7NKcaU53MymOKYqTJZZvLwenzN+a6KIXFpbr1 EZ5zGZij5OjTUKXSNUNPt2oPD1uDLvr58UbG9Eu7Xfn5RCt2sosEdtlSwrnRm2dO6Y 4e/+nDsdA2RCpKruJehPS3cHL0AZDJvL1NHTa7ufoiNPJHZm0UqSvD/SjPMgByUPW4 BQjbAQkEro3GMw2pYFx17katvNjkQ0GPht7cXiehihk2pfSk/gvWOgHVUhw2lLeHLk SUAw0epgneHwQ== 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, "Jason-JH . Lin" Subject: [PATCH v4 03/11] drm/mediatek: gamma: Support SoC specific LUT size Date: Thu, 18 May 2023 12:48:49 +0200 Message-Id: <20230518104857.124265-4-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518104857.124265-1-angelogioacchino.delregno@collabora.com> References: <20230518104857.124265-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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766228803699757782?= X-GMAIL-MSGID: =?utf-8?q?1766228803699757782?= Newer SoCs support a bigger Gamma LUT table: wire up a callback to retrieve the correct LUT size for each different Gamma IP. Co-developed-by: Jason-JH.Lin Signed-off-by: Jason-JH.Lin [Angelo: Rewritten commit message/description + porting] Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Jason-JH.Lin --- drivers/gpu/drm/mediatek/mtk_disp_drv.h | 1 + drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 25 ++++++++++++++++++--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 4 ++-- drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 1 - drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 1 + drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 9 ++++++++ 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_drv.h b/drivers/gpu/drm/mediatek/mtk_disp_drv.h index 75045932353e..e554b19f4830 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_drv.h +++ b/drivers/gpu/drm/mediatek/mtk_disp_drv.h @@ -53,6 +53,7 @@ void mtk_gamma_clk_disable(struct device *dev); void mtk_gamma_config(struct device *dev, unsigned int w, unsigned int h, unsigned int vrefresh, unsigned int bpc, struct cmdq_pkt *cmdq_pkt); +unsigned int mtk_gamma_get_lut_size(struct device *dev); void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state); void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crtc_state *state); void mtk_gamma_start(struct device *dev); diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index ce6f2499b891..d194d9bc2e2b 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -25,10 +25,12 @@ #define DISP_GAMMA_LUT 0x0700 #define LUT_10BIT_MASK 0x03ff +#define LUT_SIZE_DEFAULT 512 /* for setting gamma lut from AAL */ struct mtk_disp_gamma_data { bool has_dither; bool lut_diff; + u16 lut_size; }; /* @@ -55,6 +57,17 @@ void mtk_gamma_clk_disable(struct device *dev) clk_disable_unprepare(gamma->clk); } +unsigned int mtk_gamma_get_lut_size(struct device *dev) +{ + struct mtk_disp_gamma *gamma = dev_get_drvdata(dev); + unsigned int lut_size = LUT_SIZE_DEFAULT; + + if (gamma && gamma->data) + lut_size = gamma->data->lut_size; + + return lut_size; +} + 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); @@ -62,6 +75,7 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt struct drm_color_lut *lut; void __iomem *lut_base; bool lut_diff; + u16 lut_size; u32 word; u32 diff[3] = {0}; @@ -69,17 +83,20 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt if (!state->gamma_lut) return; - if (gamma && gamma->data) + if (gamma && gamma->data) { lut_diff = gamma->data->lut_diff; - else + lut_size = gamma->data->lut_size; + } else { lut_diff = false; + lut_size = LUT_SIZE_DEFAULT; + } reg = readl(regs + DISP_GAMMA_CFG); reg = reg | GAMMA_LUT_EN; writel(reg, regs + DISP_GAMMA_CFG); lut_base = regs + DISP_GAMMA_LUT; lut = (struct drm_color_lut *)state->gamma_lut->data; - for (i = 0; i < MTK_LUT_SIZE; i++) { + for (i = 0; i < lut_size; i++) { if (!lut_diff || (i % 2 == 0)) { word = (((lut[i].red >> 6) & LUT_10BIT_MASK) << 20) + (((lut[i].green >> 6) & LUT_10BIT_MASK) << 10) + @@ -196,10 +213,12 @@ static int mtk_disp_gamma_remove(struct platform_device *pdev) static const struct mtk_disp_gamma_data mt8173_gamma_driver_data = { .has_dither = true, + .lut_size = 512, }; static const struct mtk_disp_gamma_data mt8183_gamma_driver_data = { .lut_diff = true, + .lut_size = 512, }; static const struct of_device_id mtk_disp_gamma_driver_dt_match[] = { diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c index d40142842f85..0df62b076f49 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c @@ -958,8 +958,8 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev, mtk_crtc->ddp_comp[i] = comp; if (comp->funcs) { - if (comp->funcs->gamma_set) - gamma_lut_size = MTK_LUT_SIZE; + if (comp->funcs->gamma_set && comp->funcs->gamma_get_lut_size) + gamma_lut_size = mtk_ddp_gamma_get_lut_size(comp); if (comp->funcs->ctm_set) has_ctm = true; diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.h b/drivers/gpu/drm/mediatek/mtk_drm_crtc.h index 3e9046993d09..b2e50292e57d 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.h +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.h @@ -10,7 +10,6 @@ #include "mtk_drm_ddp_comp.h" #include "mtk_drm_plane.h" -#define MTK_LUT_SIZE 512 #define MTK_MAX_BPC 10 #define MTK_MIN_BPC 3 diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c index f114da4d36a9..c77af2e4000f 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c @@ -322,6 +322,7 @@ static const struct mtk_ddp_comp_funcs ddp_dsi = { static const struct mtk_ddp_comp_funcs ddp_gamma = { .clk_enable = mtk_gamma_clk_enable, .clk_disable = mtk_gamma_clk_disable, + .gamma_get_lut_size = mtk_gamma_get_lut_size, .gamma_set = mtk_gamma_set, .config = mtk_gamma_config, .start = mtk_gamma_start, diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h index febcaeef16a1..c1355960e195 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h @@ -67,6 +67,7 @@ struct mtk_ddp_comp_funcs { void (*layer_config)(struct device *dev, unsigned int idx, struct mtk_plane_state *state, struct cmdq_pkt *cmdq_pkt); + unsigned int (*gamma_get_lut_size)(struct device *dev); void (*gamma_set)(struct device *dev, struct drm_crtc_state *state); void (*bgclr_in_on)(struct device *dev); @@ -186,6 +187,14 @@ static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp, comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt); } +static inline unsigned int mtk_ddp_gamma_get_lut_size(struct mtk_ddp_comp *comp) +{ + if (comp->funcs && comp->funcs->gamma_get_lut_size) + return comp->funcs->gamma_get_lut_size(comp->dev); + + return 0; +} + static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp, struct drm_crtc_state *state) { From patchwork Thu May 18 10:48:50 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: 95769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp399292vqo; Thu, 18 May 2023 03:59:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4WToezbe9UlEa6jjWun5C/lgGOfGueMHCuLo+o1ChsZIaAuAPWGlxEDYxnY8KWe92isj76 X-Received: by 2002:a17:902:6505:b0:1ac:7e95:74be with SMTP id b5-20020a170902650500b001ac7e9574bemr1864469plk.28.1684407574095; Thu, 18 May 2023 03:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684407574; cv=none; d=google.com; s=arc-20160816; b=TWpiBp0oDKVstghTRtYCDmiCnlgW31bdgXRy0g9hxID2HgNY6D9vaunuvL8mt03Mx4 Q3oMts7ZWfdDl3ZXzRgMcmY9iId+ezXj2POfaEGbjnSIR5S7Z3waZGAmUSIoxDdkIGuM ilSGlvgF33el6Mpjln7W7pVCTHCAiVR+Hv6qhI8gYwZwRiNUlNT1U2zzdOnMSpNAk60+ azIw3t++0MmFSPEq62ny1EJt3XktuUU5xCBpN5lrQGc4j1VlHDns1sn0OoHKRsAJRjtb U0yLWMuiVXjbDcLtORniZkRBxpW5g0x+nOCCpM1SFvdH/+HRIAbdHOy8zwVDNXJd74Eq sedQ== 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=1JOlxQfxqkdnWZmEp4QG97ulAouhydHh4c6k5KwlpQY=; b=bg5mUNasghap5BZMaBh0dwNh7SxqrGPSIu3/Lo62KhMOHMMoDcEX4aehg+i8Aq0T+q g+OyI3mIM/rwecXqXkuEDdNYmqGplJa5XVtLKywh2dPqr8w1qoVK+QLtSa3GQiv3+ViT OQrNygC7ZNunm0VldfZ1H9toafsi715l6VI6jWMGnoJtLuusH120duxqOJ+2VMCslRuP bKCBopqOcVK+N8V8Vo7vdM/Vv8f9kfy9rThCJmvgfRMmaT1cqjiIPmvgfay2qzwFGeXZ +mGH6WlTgf+9jjqzar9q8iFCtMOdPEMNB7PxQvl1azQuvc4KUvkGmK71Kr7f44BN1D6G 5xYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=O0q5SzZV; 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 f18-20020a170902ce9200b001a6d4eab493si1116762plg.26.2023.05.18.03.59.19; Thu, 18 May 2023 03:59:34 -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=O0q5SzZV; 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 S230373AbjERKtb (ORCPT + 99 others); Thu, 18 May 2023 06:49:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbjERKtI (ORCPT ); Thu, 18 May 2023 06:49:08 -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 5985C1700 for ; Thu, 18 May 2023 03:49:06 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (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 6FEAF6605961; Thu, 18 May 2023 11:49:04 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684406945; bh=1oJWRNOrwflmI9aS9TLrWbOUSOgxjCF0qXf1ngm8Ubg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O0q5SzZV01fhZPnc64+nsglRoSlUKDhug4Mv0jNzsebpA7kwlqydBv+PJLfWQ+QwO C+gp9cUR3aOxDqvBhALNRyXwv0BYlOVoepw1eMrScevNOfThi4JJly4q1GQ0gdN1wC 4eFvEagzoZ90zgMkSe71H1kbfoO2q2GGyAM82sIFGP4q6irTBJjTED2oP/SRjRWaJj kqmuoyqrVx4jov+UeUBJCHvTHsAMS5inp2SgRVMIuDpmojB1+G5TB9xsmkhHF3WiB1 15vZKEcnD4jzAjXYI9qa/e6LDdo+IB5kwXMDaJcQGkUxEQ81bEa7COkm8rBO6ssw9E sLJyIDqCR7bZA== 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, "Jason-JH . Lin" Subject: [PATCH v4 04/11] drm/mediatek: gamma: Improve and simplify HW LUT calculation Date: Thu, 18 May 2023 12:48:50 +0200 Message-Id: <20230518104857.124265-5-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518104857.124265-1-angelogioacchino.delregno@collabora.com> References: <20230518104857.124265-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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766229356755460059?= X-GMAIL-MSGID: =?utf-8?q?1766229356755460059?= Use drm_color_lut_extract() to avoid open-coding the bits reduction calculations for each color channel and use a struct drm_color_lut to temporarily store the information instead of an array of u32. Also, slightly improve the precision of the HW LUT calculation in the LUT DIFF case by performing the subtractions on the 16-bits values and doing the 10 bits conversion later. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Jason-JH.Lin --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 30 +++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index d194d9bc2e2b..60ccea8c1e1a 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -77,7 +77,6 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt bool lut_diff; u16 lut_size; u32 word; - u32 diff[3] = {0}; /* If there's no gamma lut there's nothing to do here. */ if (!state->gamma_lut) @@ -97,18 +96,29 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt lut_base = regs + DISP_GAMMA_LUT; lut = (struct drm_color_lut *)state->gamma_lut->data; for (i = 0; i < lut_size; i++) { + struct drm_color_lut diff, hwlut; + + hwlut.red = drm_color_lut_extract(lut[i].red, 10); + hwlut.green = drm_color_lut_extract(lut[i].green, 10); + hwlut.blue = drm_color_lut_extract(lut[i].blue, 10); + if (!lut_diff || (i % 2 == 0)) { - word = (((lut[i].red >> 6) & LUT_10BIT_MASK) << 20) + - (((lut[i].green >> 6) & LUT_10BIT_MASK) << 10) + - ((lut[i].blue >> 6) & LUT_10BIT_MASK); + word = hwlut.red << 20 + + hwlut.green << 10 + + hwlut.red; } else { - diff[0] = (lut[i].red >> 6) - (lut[i - 1].red >> 6); - diff[1] = (lut[i].green >> 6) - (lut[i - 1].green >> 6); - diff[2] = (lut[i].blue >> 6) - (lut[i - 1].blue >> 6); + diff.red = lut[i].red - lut[i - 1].red; + diff.red = drm_color_lut_extract(diff.red, 10); + + diff.green = lut[i].green - lut[i - 1].green; + diff.green = drm_color_lut_extract(diff.green, 10); + + diff.blue = lut[i].blue - lut[i - 1].blue; + diff.blue = drm_color_lut_extract(diff.blue, 10); - word = ((diff[0] & LUT_10BIT_MASK) << 20) + - ((diff[1] & LUT_10BIT_MASK) << 10) + - (diff[2] & LUT_10BIT_MASK); + word = diff.blue << 20 + + diff.green << 10 + + diff.red; } writel(word, (lut_base + i * 4)); } From patchwork Thu May 18 10:48:51 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: 95771 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp399317vqo; Thu, 18 May 2023 03:59:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7RtKJAi+K8DwAfFWfNCmkGGSgGPWDeXmM5yga5RAPzyRS3YjOcTEi8FkDwPRWOJ+x2SF9r X-Received: by 2002:a05:6a21:789a:b0:105:8d42:2622 with SMTP id bf26-20020a056a21789a00b001058d422622mr2009766pzc.41.1684407577710; Thu, 18 May 2023 03:59:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684407577; cv=none; d=google.com; s=arc-20160816; b=Y2dl7aAEIX98jhMmIlvg9FYoQ13Uhpo670wy6O8n8OKou8R3PkkVurZUVDfmqy0C5w qG8S/UH2lPo+5nMkWK9u8BLoWcWgrH/gODhtFXHYk9r9U9vmI9hi9nNDw6ZkPYyDOy1D r1Qy4/TATbbGBkttqycAkHIeRSM3UjZbP63llj7JUJ6yNggbfaXJfUcEuGylSBN4PSQx ApaeyqGmfpwqMeEdw4M2YExvKWL2697iITpnuFEYQoeK3kHnstOdbfGkRVi2TKjFoceR zHaTDeTndj6AZNP9HXRNQqyMphd//7jCkdmkiE4iWb+MJMPF/9QrPBhQaMlN8dA4DFTZ J31g== 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=1eOWnkjQL7RHBWcdMDuTC+4Bn9ztmM1L5mKzuivGe+k=; b=gEymOUgzgg35ZQT8bP6Yii3Wh8OExIUCRFD4rcQTArQUcnFjWqRbJ3sQqSOgGdpCFy LNFztH8LMWMNTZERqaNNqyuA86+BwgZZYSFYL9DymcmZdBW6ChmzhOVgOxoJ+ywqOeuG Qvj3nrhNQ8A0Gvcd88xRLiOMDJMNybdSSedrX90z9xoZwUd5wmoDZkPMuNld/nv9KlUM BRwOXDq1XidiKtxsoY7zerkt35GZeOR+URfBRMsuT1xi75PC73QA7s780heIp3EDE2YY paVhPegzvPzJqzsyiahPnndq/umOeMKQ7zrouD8II3o9aoER4gZ19xV9ZcnxI4u9BbgI w27Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=k1Mz+zGC; 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 v202-20020a6361d3000000b0050bede17e7bsi1099756pgb.347.2023.05.18.03.59.22; Thu, 18 May 2023 03:59:37 -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=k1Mz+zGC; 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 S230413AbjERKt0 (ORCPT + 99 others); Thu, 18 May 2023 06:49:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230198AbjERKtI (ORCPT ); Thu, 18 May 2023 06:49:08 -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 7370B10C9 for ; Thu, 18 May 2023 03:49:07 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (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 57449660595E; Thu, 18 May 2023 11:49:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684406946; bh=UsapK5lR47Wj/X/uyrI/hv+xffw+LupSDhuQiXAKMmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k1Mz+zGCG1XzN+6Vhh9oMQXMHlpJCV2LDWlkDwqYovbVvJ35IsFAkh+w4ZR5bO3Zu WagAyqnBpOqWrzYbhE5/LKh0dF65srVQVGobJ3wVL6j1G/mjb8DtzuVOqrsqsXvtbq f/ZJei3ZehtvefOEWZAoCh1YCEFGJHrLZ8QTNfyCo0uMs98nhT0sE/EFyGXkWPjsHu wfn00PqSxJ533TJu0leST3N9hs277KPPNf1KL/dRq/Ys5ABS3vejQqpm6pTg5Fbl8e KTJk79S2HybfgsLr+xynkg4vRi3NpTAtA65zka4Ll89nEYOhParZk8O+FfTtJzVqZa BxZhK9DdesGAg== 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, "Jason-JH . Lin" Subject: [PATCH v4 05/11] drm/mediatek: gamma: Enable the Gamma LUT table only after programming Date: Thu, 18 May 2023 12:48:51 +0200 Message-Id: <20230518104857.124265-6-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518104857.124265-1-angelogioacchino.delregno@collabora.com> References: <20230518104857.124265-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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766229360143809053?= X-GMAIL-MSGID: =?utf-8?q?1766229360143809053?= Move the write to DISP_GAMMA_CFG to enable the Gamma LUT to after programming the actual table to avoid potential visual glitches during table modification. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Jason-JH.Lin --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index 60ccea8c1e1a..1592614b6de7 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -71,12 +71,12 @@ unsigned int mtk_gamma_get_lut_size(struct device *dev) 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); - unsigned int i, reg; + unsigned int i; struct drm_color_lut *lut; void __iomem *lut_base; bool lut_diff; u16 lut_size; - u32 word; + u32 cfg_val, word; /* If there's no gamma lut there's nothing to do here. */ if (!state->gamma_lut) @@ -90,9 +90,7 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt lut_size = LUT_SIZE_DEFAULT; } - reg = readl(regs + DISP_GAMMA_CFG); - reg = reg | GAMMA_LUT_EN; - writel(reg, regs + DISP_GAMMA_CFG); + cfg_val = readl(regs + DISP_GAMMA_CFG); lut_base = regs + DISP_GAMMA_LUT; lut = (struct drm_color_lut *)state->gamma_lut->data; for (i = 0; i < lut_size; i++) { @@ -122,6 +120,11 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt } writel(word, (lut_base + i * 4)); } + + /* Enable the gamma table */ + cfg_val = cfg_val | GAMMA_LUT_EN; + + writel(cfg_val, regs + DISP_GAMMA_CFG); } void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state) From patchwork Thu May 18 10:48: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: 95765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp398863vqo; Thu, 18 May 2023 03:58:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7wB7+WhrA7djqHT4N8RmRjpU11tzenqTo9hggaAH72EOOKFpI7ONx2GEfILGXeGlaecw2N X-Received: by 2002:a05:6a20:9587:b0:ee:d1b5:146f with SMTP id iu7-20020a056a20958700b000eed1b5146fmr1383419pzb.34.1684407504861; Thu, 18 May 2023 03:58:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684407504; cv=none; d=google.com; s=arc-20160816; b=z9I7DadpnpXtyIX6uFX8eGrAVWBJmLlEvqHFqnAGNyVdKf2K+uXgiQa8hFf/dvf7LO 91r7xMcJXUAAp2dC4mg9fdIXpx1IMOrwYORRkXC76i7pjwY3qHZ2yp6D/h0fTxKEmRBl L9Rb060srblMoYD7PY0sjmqs0l4kT4zFNbf3/BoNaQytsEiZyifJ6RFxlwecOomyVawj rqeV8bI6wkvOKusGRo2T+YJouYoxfBAWLUNW8B9tkAZ+hz3zk5tew5TBiCR2tDO1gFuC nTWCifpkExm+luzcHkGV1FNCTylz9kpb5dFeLJyOzxUSH85HNKfi1rW0+8QMVreMpDNC KpZg== 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=D6/KKyTN9tRe8edTrjeN+Yu9m82ifPuaAQYa8FXbqlA=; b=JEiVU8aQ3ICXJ1LRzcJV+SFKYqjdt9zsvHLz25a1N6+Z4q8pMSJZkFNO4ZUBZRLa8F zXYMCLoF5zVA8Ku4CWZiti7peAsT4qLuzrTsMopdtjc2rM9rixe6uiGlqqB3WMGNUUuP Nzl+Gjgf6fLxATR9vm1rhM0lPt6ko1fel8A8rUXZjCrSVUL1KpFLhsRZRnLy3XwvJSzS FsP+Cx80SGMp4bOqR56d0rMEE8Q1iMPlfVzhSHkKoN2/rdKO3g51f+EtgAkyZMrhUIe2 jeBF4+i9GkYQnkjM3CDw/3iEXhwSSQqVPS18QZyS7w2hCvI1psaT6oqAQ4TgCXdl5H4W bUSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=jo2KNgPo; 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 j15-20020a637a4f000000b00518db33cf17si1149262pgn.552.2023.05.18.03.58.09; Thu, 18 May 2023 03:58:24 -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=jo2KNgPo; 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 S230363AbjERKtW (ORCPT + 99 others); Thu, 18 May 2023 06:49:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbjERKtJ (ORCPT ); Thu, 18 May 2023 06:49:09 -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 6E5F81713 for ; Thu, 18 May 2023 03:49:08 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (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 7CDC96605972; Thu, 18 May 2023 11:49:06 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684406947; bh=j9V19MtLIJRUCVx9Hswg0S2tbu0fLFSl2D3yL073YFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jo2KNgPoxlE8MQB2lnxOLzBgIeiDnd4603ZZKcXNkMDUzkndqJeCvszgRIFDlzvOA yypcpuzoXk5ntT8TfrGtOHdEFnf5mCRgYEW9ruIKRdCQrMmW8X3cMEMlj28XThBDVq N8nh67fdhpxeSScFcFuh7mK+eq4hA333WxAfxBfC5gRivNgYqivVW1KPmEBWt67+Op V1kI+gAV/qjPcUrUMO+N/ga0TC0J2dq4dlWewr9Ech4zK1mSaCD9zlsoGMq/V/rSk6 qrHhWBDohrLVc4o8WnoUQfD3rvpk5k4uNF/6X7EzCOEI6gv+ufbyC/4dgWmxZdY+D4 YhAJ7mWXa6Qww== 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, "Jason-JH . Lin" Subject: [PATCH v4 06/11] drm/mediatek: gamma: Use bitfield macros Date: Thu, 18 May 2023 12:48:52 +0200 Message-Id: <20230518104857.124265-7-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518104857.124265-1-angelogioacchino.delregno@collabora.com> References: <20230518104857.124265-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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766229283511369335?= X-GMAIL-MSGID: =?utf-8?q?1766229283511369335?= Make the code more robust and improve readability by using bitfield macros instead of open coding bit operations. While at it, also add a definition for LUT_BITS_DEFAULT. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Jason-JH.Lin --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 41 ++++++++++++++--------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index 1592614b6de7..ed2aa1fb0171 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -3,6 +3,7 @@ * Copyright (c) 2021 MediaTek Inc. */ +#include #include #include #include @@ -22,9 +23,16 @@ #define GAMMA_LUT_EN BIT(1) #define GAMMA_DITHERING BIT(2) #define DISP_GAMMA_SIZE 0x0030 +#define DISP_GAMMA_SIZE_HSIZE GENMASK(28, 16) +#define DISP_GAMMA_SIZE_VSIZE GENMASK(12, 0) #define DISP_GAMMA_LUT 0x0700 +#define DISP_GAMMA_LUT_10BIT_R GENMASK(29, 20) +#define DISP_GAMMA_LUT_10BIT_G GENMASK(19, 10) +#define DISP_GAMMA_LUT_10BIT_B GENMASK(9, 0) + #define LUT_10BIT_MASK 0x03ff +#define LUT_BITS_DEFAULT 10 #define LUT_SIZE_DEFAULT 512 /* for setting gamma lut from AAL */ struct mtk_disp_gamma_data { @@ -96,33 +104,33 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt for (i = 0; i < lut_size; i++) { struct drm_color_lut diff, hwlut; - hwlut.red = drm_color_lut_extract(lut[i].red, 10); - hwlut.green = drm_color_lut_extract(lut[i].green, 10); - hwlut.blue = drm_color_lut_extract(lut[i].blue, 10); + hwlut.red = drm_color_lut_extract(lut[i].red, LUT_BITS_DEFAULT); + hwlut.green = drm_color_lut_extract(lut[i].green, LUT_BITS_DEFAULT); + hwlut.blue = drm_color_lut_extract(lut[i].blue, LUT_BITS_DEFAULT); if (!lut_diff || (i % 2 == 0)) { - word = hwlut.red << 20 + - hwlut.green << 10 + - hwlut.red; + word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, hwlut.red); + word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, hwlut.green); + word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, hwlut.blue); } else { diff.red = lut[i].red - lut[i - 1].red; - diff.red = drm_color_lut_extract(diff.red, 10); + diff.red = drm_color_lut_extract(diff.red, LUT_BITS_DEFAULT); diff.green = lut[i].green - lut[i - 1].green; - diff.green = drm_color_lut_extract(diff.green, 10); + diff.green = drm_color_lut_extract(diff.green, LUT_BITS_DEFAULT); diff.blue = lut[i].blue - lut[i - 1].blue; - diff.blue = drm_color_lut_extract(diff.blue, 10); + diff.blue = drm_color_lut_extract(diff.blue, LUT_BITS_DEFAULT); - word = diff.blue << 20 + - diff.green << 10 + - diff.red; + word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, diff.red); + word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, diff.green); + word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, diff.blue); } writel(word, (lut_base + i * 4)); } /* Enable the gamma table */ - cfg_val = cfg_val | GAMMA_LUT_EN; + cfg_val |= FIELD_PREP(GAMMA_LUT_EN, 1); writel(cfg_val, regs + DISP_GAMMA_CFG); } @@ -139,9 +147,12 @@ void mtk_gamma_config(struct device *dev, unsigned int w, unsigned int bpc, struct cmdq_pkt *cmdq_pkt) { struct mtk_disp_gamma *gamma = dev_get_drvdata(dev); + u32 sz; + + sz = FIELD_PREP(DISP_GAMMA_SIZE_HSIZE, w); + sz |= FIELD_PREP(DISP_GAMMA_SIZE_VSIZE, h); - mtk_ddp_write(cmdq_pkt, h << 16 | w, &gamma->cmdq_reg, gamma->regs, - DISP_GAMMA_SIZE); + mtk_ddp_write(cmdq_pkt, sz, &gamma->cmdq_reg, gamma->regs, DISP_GAMMA_SIZE); if (gamma->data && gamma->data->has_dither) mtk_dither_set_common(gamma->regs, &gamma->cmdq_reg, bpc, DISP_GAMMA_CFG, GAMMA_DITHERING, cmdq_pkt); From patchwork Thu May 18 10:48:53 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: 95764 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp398836vqo; Thu, 18 May 2023 03:58:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Uxp3YimzRRpjDq9UHOtbOwes1VdLFxHcLiDLr1+kv0dlzYZU9/pptqEmPenlsC2ASTCDr X-Received: by 2002:a05:6a00:841:b0:64d:1451:8233 with SMTP id q1-20020a056a00084100b0064d14518233mr3221062pfk.21.1684407500958; Thu, 18 May 2023 03:58:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684407500; cv=none; d=google.com; s=arc-20160816; b=KOwivvuCgsycfEME5ynQjCultcUCf31Y0USocg112Hq5RL55lMm1/cAQS1xUIu8Nvr +oYTj+f2AnPyJW3f1yB6VMr5jd/fEFtQFo21b42LEsrP487Jv3rGqAnlIXr4aSeSs8kj 1+/sDTdiLvB/zBdOe+uaupTIDX7rU3CWyQydR4X7vz5Uzysx/FAxjDjzGv4lznH5NqpA 6bDJaV8taPvVw9eHrCefpQa8xTSqc+J2tf29OyDFOi8H3HQRt/0dDpt5lCHNT0FwNFlM gQCf/Ovt/jcsZogBr8rIP+foO33p2q0PcQiDoyrYGGedCvT7ZebY51MqRjskO03vrAAO 2+Tg== 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=rH+UkxEi1Z7bJ3WfdYgmFShAG5H1/LHJZpi2TKTF870=; b=ZMwM3rqz2i3ooQ6a+J+LSlBLPHoQtS41FWbBfBp3EIcMPX47WDz+RgTTN+1BJY5qX1 c+b/p82dq8B6QRgD7G3cAPbdveEM0j5yb+Lq9oR+8MGAgrAqNP/mYH5xmKN2cSi7Jbmr 3pOxF9DYF865U/OyKvwyIkOTXFna53zcE19BxmZ24zHzA6eP6j3mqduyw2x7kiEUe6ma rBPacqNmfuIkirGKMcrLAZvWVp/UxFx/R0H4QHI7vohfc+Ym46wEO+108lwTtpfDMFf/ gccYFgnVKjsCQEqm1GMf/wP1gzFuQuh9jSr+R4ssPO4ZAgDvF/Ue7shb8Cs2HjrEdcM4 3x3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=CNRasjw2; 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 c6-20020a056a00008600b0063afd8a5b8dsi689623pfj.186.2023.05.18.03.58.04; Thu, 18 May 2023 03:58:20 -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=CNRasjw2; 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 S230350AbjERKth (ORCPT + 99 others); Thu, 18 May 2023 06:49:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230221AbjERKtK (ORCPT ); Thu, 18 May 2023 06:49:10 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CCADE66 for ; Thu, 18 May 2023 03:49:09 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (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 6452D660595F; Thu, 18 May 2023 11:49:07 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684406948; bh=rKgHMwiheReNnV5THzxEtK2wM9P+5w4x/hmo5YS+nus=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CNRasjw2noeeN3pOd+vRKEMuFxYOCM/8EXVfTqMvOIMx96IGOqEng1EZS6JctgUpJ bgi2FWjRbZggLFtsc1lUdVae53ei1nYI6QjtqDvZ4yBuFjLz8Lo4uUdABnrl1+VaSI DfnPQRaQyUpHcFaMy943gAgYD4LKjZoowOCgoNmQ+3JPPeK4OcJPylawN33FTNWVFk CqM73aHdJ8V35zGD8x7WTKrv3Bpmqin8nv/NzhZB5HOsN30/uqXPTQfR7qEqocsb3s 2/lb38pj3jLp6m/jQdaO39YcuJhgUdIuSnjrK9eJ2uCOiK+WUl/Z9Hu7Klu3LdNYdw htKiy4kLLPf2Q== 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, "Jason-JH . Lin" Subject: [PATCH v4 07/11] drm/mediatek: gamma: Support specifying number of bits per LUT component Date: Thu, 18 May 2023 12:48:53 +0200 Message-Id: <20230518104857.124265-8-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518104857.124265-1-angelogioacchino.delregno@collabora.com> References: <20230518104857.124265-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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766229279939007834?= X-GMAIL-MSGID: =?utf-8?q?1766229279939007834?= New SoCs, like MT8195, not only may support bigger lookup tables, but have got a different register layout to support bigger precision: support specifying the number of `lut_bits` for each SoC and use it in mtk_gamma_set_common() to perform the right calculation. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Jason-JH.Lin --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index ed2aa1fb0171..62e1e50d2671 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -39,6 +39,7 @@ struct mtk_disp_gamma_data { bool has_dither; bool lut_diff; u16 lut_size; + u8 lut_bits; }; /* @@ -84,6 +85,7 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt void __iomem *lut_base; bool lut_diff; u16 lut_size; + u8 lut_bits; u32 cfg_val, word; /* If there's no gamma lut there's nothing to do here. */ @@ -92,9 +94,11 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt if (gamma && gamma->data) { lut_diff = gamma->data->lut_diff; + lut_bits = gamma->data->lut_bits; lut_size = gamma->data->lut_size; } else { lut_diff = false; + lut_bits = LUT_BITS_DEFAULT; lut_size = LUT_SIZE_DEFAULT; } @@ -104,9 +108,9 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt for (i = 0; i < lut_size; i++) { struct drm_color_lut diff, hwlut; - hwlut.red = drm_color_lut_extract(lut[i].red, LUT_BITS_DEFAULT); - hwlut.green = drm_color_lut_extract(lut[i].green, LUT_BITS_DEFAULT); - hwlut.blue = drm_color_lut_extract(lut[i].blue, LUT_BITS_DEFAULT); + hwlut.red = drm_color_lut_extract(lut[i].red, lut_bits); + hwlut.green = drm_color_lut_extract(lut[i].green, lut_bits); + hwlut.blue = drm_color_lut_extract(lut[i].blue, lut_bits); if (!lut_diff || (i % 2 == 0)) { word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, hwlut.red); @@ -114,13 +118,13 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, hwlut.blue); } else { diff.red = lut[i].red - lut[i - 1].red; - diff.red = drm_color_lut_extract(diff.red, LUT_BITS_DEFAULT); + diff.red = drm_color_lut_extract(diff.red, lut_bits); diff.green = lut[i].green - lut[i - 1].green; - diff.green = drm_color_lut_extract(diff.green, LUT_BITS_DEFAULT); + diff.green = drm_color_lut_extract(diff.green, lut_bits); diff.blue = lut[i].blue - lut[i - 1].blue; - diff.blue = drm_color_lut_extract(diff.blue, LUT_BITS_DEFAULT); + diff.blue = drm_color_lut_extract(diff.blue, lut_bits); word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, diff.red); word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, diff.green); @@ -237,10 +241,12 @@ static int mtk_disp_gamma_remove(struct platform_device *pdev) static const struct mtk_disp_gamma_data mt8173_gamma_driver_data = { .has_dither = true, + .lut_bits = 10, .lut_size = 512, }; static const struct mtk_disp_gamma_data mt8183_gamma_driver_data = { + .lut_bits = 10, .lut_diff = true, .lut_size = 512, }; From patchwork Thu May 18 10:48:54 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: 95774 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp400226vqo; Thu, 18 May 2023 04:00:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4mA4X1izMveDg2g0/cr285qfUch7UDWuGuPZAHOyQfgoqw+MhtvtQ2xRDt1HOh8YdykInk X-Received: by 2002:a05:6a00:80d:b0:63d:5de3:b3f2 with SMTP id m13-20020a056a00080d00b0063d5de3b3f2mr4160610pfk.18.1684407656817; Thu, 18 May 2023 04:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684407656; cv=none; d=google.com; s=arc-20160816; b=LX/HXJLgbUGAN5G4K22wm/jTFTQFeo/4/XHVQUAmFrkAPkn1KWVdaZWo73SEu9bj0Y 5w+XtM+lqJRotzpaAUx+tPmVgblpiXg2C+XW6o70DBh1sjmzuUuW57Y32rGY66/B7Opn pCdjtsQw2sVgS6Sk2U+BweowfG1TZUbQ+TA6aZ+Ka91A8kykbFU/ypp+qZ3d3JU+3/dR 9EY8FaM+c4pqO2TzXRT7EC7p4yhYJFbsubpBbzu0Xa78VB0HKg1B5Aq8dnNnukzZmy9a /NRkesbaT9L4zBQoirDyrxoYYLWhRBS/VVE0SQx/53BF/DJXTQrKIQc4Zorn5LWrAnXO 0tfQ== 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=Be7m4bRvQfs02FzGdIg8G5tviMUBM3/phQe1MxIXOoc=; b=j0d0sUEHruxL42mL8m1i5Gpc12BPB7Qvz2cclULa89c6wAeohY4/48QC5CfwogQ3JX 9SVGAcqViefCy+Vn7r1ISyUf+FmBi02dJzVd0HNkuIiE4vr2Ee35s1hVrSRN46x6345Q 6Sj6SGGLQuHQrKI3R2LoLAuulVA4nn2hwk6PzPbnCuZyNq4PqwSSZFPDw+EwGevmlA33 o08V9X98DP9LY6vvqLl3sp+0qKUxUi/ms3iZJBg+1bnIqRUZhbgijEhhi8StOlj9aTJH d6unWB4qOzeH8WgpWjNfaxtWB8x47PD+jc/545+q/WUTbGNT/XAYUo2+zrC1lrkUtDYh GVeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=EZWGYPGc; 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 x16-20020aa79a50000000b006438e35303csi882026pfj.260.2023.05.18.04.00.40; Thu, 18 May 2023 04:00:56 -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=EZWGYPGc; 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 S230467AbjERKtm (ORCPT + 99 others); Thu, 18 May 2023 06:49:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230256AbjERKtM (ORCPT ); Thu, 18 May 2023 06:49:12 -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 78CB010C9 for ; Thu, 18 May 2023 03:49:10 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (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 8A4A766059A5; Thu, 18 May 2023 11:49:08 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684406949; bh=JAQLLPMkc+mUKKZA9j94i5lIpT3amMIqAM03uzJuyWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EZWGYPGcuCfa6Oi0kTjcUfvBGSpQmtvBXWH9E/h8WZu1klqbaAaYPln7meT6uh46F +3FG8tlpxeE1N6dvFHIoKDuyfJxHHli9Ale26Covbt/pqAvVUZ/dffDCzvjwj/JJf3 99rrJ2DbHdz1RQ3v9AnA6QsAX20gU3oohqp17HYZjFs8WXJlTh2GVALcUCPIukd+Lm NNNzHYCA9hGndCJVoGbPceiT04b+FJX2J0btJMSxrBYGBWc0hzpjgrRSQsK4Denfip SOZ4nPsQ+JK1bItPL2Il0oRt7+rWIuBkghVlpTq3Tf2I5C+wMIGIP+6DxtI4CKwFqm g91/AP5X0Bljg== 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, "Jason-JH . Lin" Subject: [PATCH v4 08/11] drm/mediatek: gamma: Support multi-bank gamma LUT Date: Thu, 18 May 2023 12:48:54 +0200 Message-Id: <20230518104857.124265-9-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518104857.124265-1-angelogioacchino.delregno@collabora.com> References: <20230518104857.124265-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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766229442778521784?= X-GMAIL-MSGID: =?utf-8?q?1766229442778521784?= Newer Gamma IP have got multiple LUT banks: support specifying the size of the LUT banks and handle bank-switching before programming the LUT in mtk_gamma_set_common() in preparation for adding support for MT8195 and newer SoCs. Suggested-by: Jason-JH.Lin [Angelo: Refactored original commit] Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 78 +++++++++++++++-------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index 62e1e50d2671..a05c445367ee 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -25,6 +25,8 @@ #define DISP_GAMMA_SIZE 0x0030 #define DISP_GAMMA_SIZE_HSIZE GENMASK(28, 16) #define DISP_GAMMA_SIZE_VSIZE GENMASK(12, 0) +#define DISP_GAMMA_BANK 0x0100 +#define DISP_GAMMA_BANK_BANK GENMASK(1, 0) #define DISP_GAMMA_LUT 0x0700 #define DISP_GAMMA_LUT_10BIT_R GENMASK(29, 20) @@ -38,6 +40,7 @@ struct mtk_disp_gamma_data { bool has_dither; bool lut_diff; + u16 lut_bank_size; u16 lut_size; u8 lut_bits; }; @@ -84,9 +87,10 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt struct drm_color_lut *lut; void __iomem *lut_base; bool lut_diff; - u16 lut_size; + u16 lut_bank_size, lut_size; u8 lut_bits; - u32 cfg_val, word; + u32 cfg_val, lbank_val, word; + int cur_bank, num_lut_banks; /* If there's no gamma lut there's nothing to do here. */ if (!state->gamma_lut) @@ -94,43 +98,61 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt if (gamma && gamma->data) { lut_diff = gamma->data->lut_diff; + lut_bank_size = gamma->data->lut_bank_size; lut_bits = gamma->data->lut_bits; lut_size = gamma->data->lut_size; } else { lut_diff = false; + lut_bank_size = LUT_SIZE_DEFAULT; lut_bits = LUT_BITS_DEFAULT; lut_size = LUT_SIZE_DEFAULT; } + if (lut_bank_size) + num_lut_banks = lut_size / lut_bank_size; + else + num_lut_banks = 1; + cfg_val = readl(regs + DISP_GAMMA_CFG); lut_base = regs + DISP_GAMMA_LUT; lut = (struct drm_color_lut *)state->gamma_lut->data; - for (i = 0; i < lut_size; i++) { - struct drm_color_lut diff, hwlut; - - hwlut.red = drm_color_lut_extract(lut[i].red, lut_bits); - hwlut.green = drm_color_lut_extract(lut[i].green, lut_bits); - hwlut.blue = drm_color_lut_extract(lut[i].blue, lut_bits); - - if (!lut_diff || (i % 2 == 0)) { - word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, hwlut.red); - word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, hwlut.green); - word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, hwlut.blue); - } else { - diff.red = lut[i].red - lut[i - 1].red; - diff.red = drm_color_lut_extract(diff.red, lut_bits); - - diff.green = lut[i].green - lut[i - 1].green; - diff.green = drm_color_lut_extract(diff.green, lut_bits); - - diff.blue = lut[i].blue - lut[i - 1].blue; - diff.blue = drm_color_lut_extract(diff.blue, lut_bits); - - word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, diff.red); - word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, diff.green); - word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, diff.blue); + + for (cur_bank = 0; cur_bank < num_lut_banks; cur_bank++) { + + /* Switch gamma bank and set data mode before writing LUT */ + if (num_lut_banks > 1) { + lbank_val = FIELD_PREP(DISP_GAMMA_BANK_BANK, cur_bank); + writel(lbank_val, regs + DISP_GAMMA_BANK); + } + + for (i = 0; i < lut_bank_size; i++) { + int n = (cur_bank * lut_bank_size) + i; + struct drm_color_lut diff, hwlut; + + hwlut.red = drm_color_lut_extract(lut[n].red, lut_bits); + hwlut.green = drm_color_lut_extract(lut[n].green, lut_bits); + hwlut.blue = drm_color_lut_extract(lut[n].blue, lut_bits); + + if (!lut_diff || (i % 2 == 0)) { + word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, hwlut.red); + word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, hwlut.green); + word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, hwlut.blue); + } else { + diff.red = lut[n].red - lut[n - 1].red; + diff.red = drm_color_lut_extract(diff.red, lut_bits); + + diff.green = lut[n].green - lut[n - 1].green; + diff.green = drm_color_lut_extract(diff.green, lut_bits); + + diff.blue = lut[n].blue - lut[n - 1].blue; + diff.blue = drm_color_lut_extract(diff.blue, lut_bits); + + word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, diff.red); + word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, diff.green); + word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, diff.blue); + } + writel(word, (lut_base + i * 4)); } - writel(word, (lut_base + i * 4)); } /* Enable the gamma table */ @@ -241,11 +263,13 @@ static int mtk_disp_gamma_remove(struct platform_device *pdev) static const struct mtk_disp_gamma_data mt8173_gamma_driver_data = { .has_dither = true, + .lut_bank_size = 512, .lut_bits = 10, .lut_size = 512, }; static const struct mtk_disp_gamma_data mt8183_gamma_driver_data = { + .lut_bank_size = 512, .lut_bits = 10, .lut_diff = true, .lut_size = 512, From patchwork Thu May 18 10:48:55 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: 95758 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp397002vqo; Thu, 18 May 2023 03:54:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7mE4Rx7xfB62WOOWzOCUnCgl4vS6hQOM+VwDz9+3zqKRKbU42L6eRYWqL7hdJzjPlbeq6b X-Received: by 2002:a17:90b:1947:b0:24e:4da9:6024 with SMTP id nk7-20020a17090b194700b0024e4da96024mr2005234pjb.39.1684407242273; Thu, 18 May 2023 03:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684407242; cv=none; d=google.com; s=arc-20160816; b=tnKiFscI+9vle5sTAb8etZ4ifvuYo1k4fya+jAX4lfM1zyUofo+Q+Qm5nWnc2jNz9e SPug5np35qDCxkWZYQLq1rw8T1VIRIveMU+8lk2HYkfaI93JyAeEENrmxdngskF8puVY 75VV2VWA+UtSXFY7iyqk/eZHPHzTSE3uBhvvFKAINoGJSYW4i2AfhtdSniayXXIFbAjG +0q58lzZwmUGWfdtV8cZgINpfN92uIz0KN3+JGIo1CwsxQOGNQ5UmpmETXSPZk881E4T qJ9DT3w9v/ILQ36h/Zuo9h6kwTRdy8svcbtj+arnkDnxehNINzWylXqvEg88JpvJn59F Ng8w== 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=eR/xodWjofMvePkYnrwaOYVNxtdEUKmShrHGghnMdsY=; b=RRwv/hovnP9Sd7hx8nO3SeIX2VFYmRGB35inUHPEI75XXHULSGHuRoJQueAoZrsqp5 r1qIR7wVWZu3BuBWm7QXfAALcSjZvIrBiSAhgBgGwF/0E4Dq0BSTeNu2+TjdPGh6zrsq qOT7HLvg3uLR7a6QFMCLOW/tjVRyePaIJ4damG+pHo/rxTK9cJ22nNw+ZcEoZwBuLFD9 /w+f8TclkkLxSAV8iVg6djLQYe725h+ncHfNYubNCW1646BHACovdl8lXbXE3k/dXeqT LCCCV3TCoktwyHdRsWyfYgmyTm8AOBehA88jmRTSgRK3SYqkglwhEzkaMKr2nLEv7dJ7 DX6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=M78pdpAa; 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 p2-20020a17090a2d8200b002536713c7basi1002665pjd.55.2023.05.18.03.53.50; Thu, 18 May 2023 03:54:02 -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=M78pdpAa; 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 S231163AbjERKtk (ORCPT + 99 others); Thu, 18 May 2023 06:49:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbjERKtM (ORCPT ); Thu, 18 May 2023 06:49:12 -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 4F76AE66 for ; Thu, 18 May 2023 03:49:11 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (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 7343B6605962; Thu, 18 May 2023 11:49:09 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684406950; bh=OnHuldXzfYYw/KXyKRAqozHtJCb863QWBQWMJdHX3xI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M78pdpAadPl4k2DIX+Oej/unHvgFSXgb0ub8u0stnGqVj0EHE9VuyjsJyHzWPhROz s3DE9hnQ9dwYg3iBLFuthiWBTm8EodYKFjp8/JyIE7L2sTekebrg+P+NEZbUbdZcG+ p8i4fqHsAV8xSdV9S7lNKPv29NZxkjNzCP+szo5dwWX8rXxAAtC8qh2dZzX234nCII Np9VmutoYVBLykqphv3t4y5r+6bRuYRBNPU+6rMCFjtt85oEkdY7nNF1IifjZnMVhC hzCH93WsLGYJvs7hu86qhFSnxW1cvDWbNgjRTCK5lfH4Y6pcQygKHkV6In9yYY3fVk M8EONVw3mHjtg== 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, "Jason-JH . Lin" Subject: [PATCH v4 09/11] drm/mediatek: gamma: Add support for 12-bit LUT and MT8195 Date: Thu, 18 May 2023 12:48:55 +0200 Message-Id: <20230518104857.124265-10-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518104857.124265-1-angelogioacchino.delregno@collabora.com> References: <20230518104857.124265-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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766229008644481649?= X-GMAIL-MSGID: =?utf-8?q?1766229008644481649?= Add support for 12-bit gamma lookup tables and introduce the first user for it: MT8195. While at it, also reorder the variables in mtk_gamma_set_common() and rename `lut_base` to `lut0_base` to improve readability. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Jason-JH.Lin --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 61 ++++++++++++++++++----- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index a05c445367ee..9ae08a2d7da2 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -27,12 +27,20 @@ #define DISP_GAMMA_SIZE_VSIZE GENMASK(12, 0) #define DISP_GAMMA_BANK 0x0100 #define DISP_GAMMA_BANK_BANK GENMASK(1, 0) +#define DISP_GAMMA_BANK_DATA_MODE BIT(2) #define DISP_GAMMA_LUT 0x0700 +#define DISP_GAMMA_LUT1 0x0b00 +/* For 10 bit LUT layout, R/G/B are in the same register */ #define DISP_GAMMA_LUT_10BIT_R GENMASK(29, 20) #define DISP_GAMMA_LUT_10BIT_G GENMASK(19, 10) #define DISP_GAMMA_LUT_10BIT_B GENMASK(9, 0) +/* For 12 bit LUT layout, R/G are in LUT, B is in LUT1 */ +#define DISP_GAMMA_LUT_12BIT_R GENMASK(11, 0) +#define DISP_GAMMA_LUT_12BIT_G GENMASK(23, 12) +#define DISP_GAMMA_LUT_12BIT_B GENMASK(11, 0) + #define LUT_10BIT_MASK 0x03ff #define LUT_BITS_DEFAULT 10 #define LUT_SIZE_DEFAULT 512 /* for setting gamma lut from AAL */ @@ -83,14 +91,15 @@ unsigned int mtk_gamma_get_lut_size(struct device *dev) 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); - unsigned int i; + void __iomem *lut0_base = regs + DISP_GAMMA_LUT; + void __iomem *lut1_base = regs + DISP_GAMMA_LUT1; + u32 cfg_val, data_mode, lbank_val, word[2]; + int cur_bank, num_lut_banks; + u16 lut_bank_size, lut_size; struct drm_color_lut *lut; - void __iomem *lut_base; + unsigned int i; bool lut_diff; - u16 lut_bank_size, lut_size; u8 lut_bits; - u32 cfg_val, lbank_val, word; - int cur_bank, num_lut_banks; /* If there's no gamma lut there's nothing to do here. */ if (!state->gamma_lut) @@ -114,14 +123,17 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt num_lut_banks = 1; cfg_val = readl(regs + DISP_GAMMA_CFG); - lut_base = regs + DISP_GAMMA_LUT; lut = (struct drm_color_lut *)state->gamma_lut->data; + /* Switch to 12 bits data mode if supported */ + data_mode = FIELD_PREP(DISP_GAMMA_BANK_DATA_MODE, !!(lut_bits == 12)); + for (cur_bank = 0; cur_bank < num_lut_banks; cur_bank++) { /* Switch gamma bank and set data mode before writing LUT */ if (num_lut_banks > 1) { lbank_val = FIELD_PREP(DISP_GAMMA_BANK_BANK, cur_bank); + lbank_val |= data_mode; writel(lbank_val, regs + DISP_GAMMA_BANK); } @@ -134,9 +146,15 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt hwlut.blue = drm_color_lut_extract(lut[n].blue, lut_bits); if (!lut_diff || (i % 2 == 0)) { - word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, hwlut.red); - word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, hwlut.green); - word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, hwlut.blue); + if (lut_bits == 12) { + word[0] = FIELD_PREP(DISP_GAMMA_LUT_12BIT_R, hwlut.red); + word[0] |= FIELD_PREP(DISP_GAMMA_LUT_12BIT_G, hwlut.green); + word[1] = FIELD_PREP(DISP_GAMMA_LUT_12BIT_B, hwlut.blue); + } else { + word[0] = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, hwlut.red); + word[0] |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, hwlut.green); + word[0] |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, hwlut.blue); + } } else { diff.red = lut[n].red - lut[n - 1].red; diff.red = drm_color_lut_extract(diff.red, lut_bits); @@ -147,11 +165,19 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt diff.blue = lut[n].blue - lut[n - 1].blue; diff.blue = drm_color_lut_extract(diff.blue, lut_bits); - word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, diff.red); - word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, diff.green); - word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, diff.blue); + if (lut_bits == 12) { + word[0] = FIELD_PREP(DISP_GAMMA_LUT_12BIT_R, diff.red); + word[0] |= FIELD_PREP(DISP_GAMMA_LUT_12BIT_G, diff.green); + word[1] = FIELD_PREP(DISP_GAMMA_LUT_12BIT_B, diff.blue); + } else { + word[0] = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, diff.red); + word[0] |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, diff.green); + word[0] |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, diff.blue); + } } - writel(word, (lut_base + i * 4)); + writel(word[0], (lut0_base + i * 4)); + if (lut_bits == 12) + writel(word[1], (lut1_base + i * 4)); } } @@ -275,11 +301,20 @@ static const struct mtk_disp_gamma_data mt8183_gamma_driver_data = { .lut_size = 512, }; +static const struct mtk_disp_gamma_data mt8195_gamma_driver_data = { + .lut_bank_size = 256, + .lut_bits = 12, + .lut_diff = true, + .lut_size = 1024, +}; + static const struct of_device_id mtk_disp_gamma_driver_dt_match[] = { { .compatible = "mediatek,mt8173-disp-gamma", .data = &mt8173_gamma_driver_data}, { .compatible = "mediatek,mt8183-disp-gamma", .data = &mt8183_gamma_driver_data}, + { .compatible = "mediatek,mt8195-disp-gamma", + .data = &mt8195_gamma_driver_data}, {}, }; MODULE_DEVICE_TABLE(of, mtk_disp_gamma_driver_dt_match); From patchwork Thu May 18 10:48:56 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: 95759 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp397670vqo; Thu, 18 May 2023 03:55:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4eKHAsdbYwF5ie+SPHZ+vHEmZMQloex6GKlJfeGf/vnKNj7z/49F7JV3C5mJHBsdkfU+mn X-Received: by 2002:a17:90a:c24d:b0:253:629e:dc3b with SMTP id d13-20020a17090ac24d00b00253629edc3bmr1773034pjx.44.1684407331258; Thu, 18 May 2023 03:55:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684407331; cv=none; d=google.com; s=arc-20160816; b=CycnSo13OsgWlib+Eimocnvj0QOCKGHmC5VKiJjobq+OxLR3d1nEYgAWIUbPIyQ+Dx Gqx96tYO9ROY3tn3IvEgmoogyEr+zqgcRVBx95CyGdCED3CXSofW3LZr7YmkJNPQzPEE bPJwqn+zTPlGqMlJRRAHh3NdBCohDJBQxZqxOLseRrAXdBhoTV/tnusIfSH9ShjvIIl0 mirZjKWPXp6/FjsT+4CwOr69Af7jnwEIQsBQVe0k9gbWeYgsxGBiS42aZNscctLo9y1d aE1yEPzgAPa3HIWILg5Az3Q3rDcy38L/n+5lQsZErj2ufnmzjbb5lUmrRho3+s5Snoqt JjwQ== 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=rlvJymOWGRZRk99o6Zs+tnpAttf3aWYZmWAsGXVYUDM=; b=qJth++WkP5UmRoK2AUZYMs7uWS3jcvt4RjAfa4tG/TY4aPosCVQdTlsGWtSpGob+5H P2BQNtS6C6r+FzbA6oXENEECFjzpDafdJgR4tGVrxO1DuZ2FCB85LLFimltWtcfKsUdl WAZxpQXNQ8F+C/v8I3oacvllIocGrDpmCqERVL2zVADEtv3K+tMu3CzdwtHWF6Y7Si3U TqwJyqGajk6AJvkrXn39HMuLmMxIPQwyCvbjGOP8CWia9+7pHdez4J0krKrAre2n/kV2 CSIgoVC1vmL1g2VhGvKtFAPiu4YnXg50mF9+U4rZsZBFloiTyaHF7+rCMeHMoaTX/Yps 8v6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=nUnU9DLH; 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 k8-20020a17090a3cc800b0024d7fdc4778si1477945pjd.32.2023.05.18.03.55.19; Thu, 18 May 2023 03:55:31 -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=nUnU9DLH; 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 S231204AbjERKts (ORCPT + 99 others); Thu, 18 May 2023 06:49:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbjERKtN (ORCPT ); Thu, 18 May 2023 06:49:13 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58271E6E for ; Thu, 18 May 2023 03:49:12 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (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 5E15666059A8; Thu, 18 May 2023 11:49:10 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684406951; bh=AE9iGK1lfVVDFBdwJsBq/oCrjdgmEivKNGIdMO9796U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nUnU9DLHgyjY+7bF1oLROH/6pCYSR1KrGlUHqccJoPG4gzC+SI/iRW7Qmz68TAHv3 p3sGyyREOMJh0Ct7uPkEHdjGdSEWPClXPKPvdXVrgusuNmpLsXWe5dgFNwk4jAR50I z3Hlol+Mnx+TirsI8L6kETCOXO/JKXkS6BWwvn0g5MYjxJTId00a2b2ywvLCEpglwh JWXRDih6pZp8SHlYHbgCk9Rz2Dz1ugRm8rzzM5IgpjE0SjnvYqB80SMXbjcauoy/RZ v8Wq8WuQ/KHk6vS7GC8i23mqgv6nNtGLv/EUP8c2/5OjYQ4LiZhjgHPbrD3y7V27fY Vwlp3imfz8P9A== 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, "Jason-JH . Lin" Subject: [PATCH v4 10/11] drm/mediatek: gamma: Make sure relay mode is disabled Date: Thu, 18 May 2023 12:48:56 +0200 Message-Id: <20230518104857.124265-11-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518104857.124265-1-angelogioacchino.delregno@collabora.com> References: <20230518104857.124265-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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766229101523685617?= X-GMAIL-MSGID: =?utf-8?q?1766229101523685617?= Disable relay mode at the end of LUT programming to make sure that the processed image goes through. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Jason-JH.Lin --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index 9ae08a2d7da2..ba8a0f93f184 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -20,6 +20,7 @@ #define DISP_GAMMA_EN 0x0000 #define GAMMA_EN BIT(0) #define DISP_GAMMA_CFG 0x0020 +#define GAMMA_RELAY_MODE BIT(0) #define GAMMA_LUT_EN BIT(1) #define GAMMA_DITHERING BIT(2) #define DISP_GAMMA_SIZE 0x0030 @@ -184,6 +185,9 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt /* Enable the gamma table */ cfg_val |= FIELD_PREP(GAMMA_LUT_EN, 1); + /* Disable RELAY mode to pass the processed image */ + cfg_val &= ~GAMMA_RELAY_MODE; + writel(cfg_val, regs + DISP_GAMMA_CFG); } From patchwork Thu May 18 10:48:57 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: 95757 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp396280vqo; Thu, 18 May 2023 03:52:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7rhuGYuLgejGMMmwk3eBqi4UlvY9YpMjStrOx5r6g7ZGA1wNj1+esMzmBO5FQKgKTVm6Bw X-Received: by 2002:a05:6a00:ad5:b0:64d:22db:1023 with SMTP id c21-20020a056a000ad500b0064d22db1023mr1287571pfl.22.1684407145995; Thu, 18 May 2023 03:52:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684407145; cv=none; d=google.com; s=arc-20160816; b=hdjEWCIvddwRm0cweq1rIDbqTM6/I2Ct7nTVQl1Bp6Y4reAt2cbRxQlUpZUHYHLPyI RwSGQEpSxCColrIZOagUpMYB83Ul+zyR+KsMBBe2bIq8tK/VwEHMWt5RbdStSmlP+hdo D2coKKEpp0Vn+Inmt921qJhoCeUUR4A/3/ymZnG5bHavCAnlBKE2sjGzqmhSVbU7yWhL MBrqmdDAsKk/JwzKRfKpzgXdFZpi+QgSrFgd2MRBFe+5gLFbYxnofRuvhGQtQ2J9HvoV 4sQZUsmCBjGo6QFtwhRECE2BVEfKeNHr50x94Un/fRol8Q54EkKbtVul+ZukAVha0OW0 TMBg== 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=0qBTS9COCODuqUc09i3mziTm8CG6547UjdxdMTpQ8Mc=; b=FNzz4T3WruUF1je53GpJqbuVfFSId6aAHdzV8HS9DYSGIK+BIgWDbAYr5J98JenT7k tCJkyb78IZOGBKqED8dNkjcWe3Oe5uMblDuy1VSQ1uAclpLhoVQddliasuS0TMJWxjsM 1k0iXdA1UiqSXZ+Jx7SyOG/QQ0jvdGFLYtiiczZ1txPGqlv/eWGCLO7YGcvnTeDAI4O7 /P4aoXDzlQ1yBLO1b0axUIEfaX4m7sPvWTmp2F/hJHBykImIMGwt4hr66Xnd331KNgIk 3diw1+cfqigBBdHMEXDEbe7xPdKPWhcuK8Ug96UYc8/K3npuLcGgAH/a5qaTVPUkXd0G hotA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lkLZIFCG; 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 k12-20020aa79d0c000000b006437c0538e9si1394994pfp.76.2023.05.18.03.52.13; Thu, 18 May 2023 03:52:25 -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=lkLZIFCG; 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 S231173AbjERKtp (ORCPT + 99 others); Thu, 18 May 2023 06:49:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230313AbjERKtO (ORCPT ); Thu, 18 May 2023 06:49:14 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2518710F5 for ; Thu, 18 May 2023 03:49:13 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (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 4BE586606695; Thu, 18 May 2023 11:49:11 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684406952; bh=RWhpgf+OUzqnooMeHzIKy0Ost+XIPE0wYKjrJG5E+eE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lkLZIFCGOYt1R7UMXToD+rwtwQlR0/Nny4qJHkTALk9UkGdPShz5JPzwH02cRpUnS 4cgKKPxQiUI3TLQIzPdd78Zoxa8XKhKTNnLHv+VXpRpbDDJVRYkjtIVqzxABfcSzqh 1osSWtywztQP6Jqpk7eWSAFm7Bv92DWkgGWNUkLgUcaMSppESBpmjuEtWU3W92doXE abBRfIVIbWiLK7ytyzDmlavA1DD8obIz9sL1Od9ATzADMT4iUxEGwR4zX6J09ljyWd iDEb3EIeZnanqXNLavvcbPcPoTTU4k5YN+m4AK1yQK5mj3ZTDZSibh116lEhDptkNf 0kvGQdUdwg4Bw== 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, "Jason-JH . Lin" Subject: [PATCH v4 11/11] drm/mediatek: gamma: Program gamma LUT type for descending or rising Date: Thu, 18 May 2023 12:48:57 +0200 Message-Id: <20230518104857.124265-12-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518104857.124265-1-angelogioacchino.delregno@collabora.com> References: <20230518104857.124265-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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766228907339679107?= X-GMAIL-MSGID: =?utf-8?q?1766228907339679107?= 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 ba8a0f93f184..d7c7c6ca2e97 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); @@ -182,6 +193,14 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt } } + if (gamma && !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);