From patchwork Mon Jun 12 09:01: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: 106402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2469265vqr; Mon, 12 Jun 2023 02:56:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ53f2ikiMF/GSn27Xi9Jt1yYQDI9rfAnOr2FcY/e/6Rjssv4I/N9zyKU0CT7/8byEdrWT/I X-Received: by 2002:a17:906:fd84:b0:977:bf09:279 with SMTP id xa4-20020a170906fd8400b00977bf090279mr8879446ejb.41.1686563777916; Mon, 12 Jun 2023 02:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686563777; cv=none; d=google.com; s=arc-20160816; b=IaenAChO93N86p0F5lOGMhUp4yQjPE0d0hc97St2IRwVkqBu+ql+dYQzsqFXIgdMyg u/+GJ9y2jCmcOwWtBeyYFs1HrkPKs/ra+XCjrEHcuwn2WtbPhjNfVTel8EmcA3f5I3Uj cs2l2E4Qt97m9mY9SGD4Eiz/ecrkuy/pnV/2rAyklL5IFpq3jsAcK4brkwZRH1otzaE3 9giMInwxODK4tW6p4EPsKGEEw5pRYvJNKpQnJaa7DjoBcPcljOZI6BVVGmmmDD13yVRt Vv3jcTAMADG3zMkBoR9dE4aNetQABn+WIcES0xnG2jbS/ClWd295guuvIUe2DS07nZ8S y/AA== 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=t2sbLtMfb1fKK9bebnxLGZEhsUXRhU99CGCJpSyXWi6T6gB4xQAje6f4kMuCiHnSKV iBYFSSQNx5pWNfsVEO+TfAhF7bVAdDZCAtTJlGSR86y5lp11idtBS/mPybtonK0nrGnh s7L/oN1FXCSew4CZDCbgBcm6erxUhSwPO0fwPl5uo6nUueHW9b7vTX4xyganug3mpk1n gJ9vw3VXIQizc7wegRbyKc5GYnV+rNMtaDErWE73eLBNQ7/MUR9xw6jSd+yol0zWcsRr Edr4XSZRWc79GJESxCeDoIQf8QnxV6d/DcFWTmiClLWd2madiAagdjS03Cbb0Mv3DXiW gj/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=M+g8uCwR; 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 jx6-20020a170906ca4600b009617ad9d89dsi5026162ejb.38.2023.06.12.02.55.49; Mon, 12 Jun 2023 02:56:17 -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=M+g8uCwR; 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 S232666AbjFLJF4 (ORCPT + 99 others); Mon, 12 Jun 2023 05:05:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232029AbjFLJFX (ORCPT ); Mon, 12 Jun 2023 05:05:23 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45E313C03 for ; Mon, 12 Jun 2023 02:02:04 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 A694D66058B2; Mon, 12 Jun 2023 10:02:02 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686560523; bh=fWabP2S9MKC6+Yi0YWqUcPZxSafl399il5KPixyXdlw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M+g8uCwRld+dEIgLpeT51k38xPkIwZ517PJ1IwwI3HjXA3biUFFsqhVM+0kXSOsCY jp3sGEQStYgWLdwzB7UW5gQ+rxTyrVOHH/Hp1XRl6rPCA6msNG8ogbCYBfT5lWc449 R4LthY1KY1lfj+mxQXwex2ZMYO7nkTc84SQeSCH3NzK0Xebo+7m9P9zL19Itu+UVFa LE5A3bREWcVtq/4J8lBhB+mnpIQ+lUO6rjeNZ0XdUlxQ/2R3VzYboeht2lKeov3EIn OnZTH5RSnTyQbEtEFb8kgZEeSAel0eqLCctjeEY9ujefARO55cl2u80ybpU096VNIo mOHxluPFzqXPQ== 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 v6 01/11] drm/mediatek: gamma: Adjust mtk_drm_gamma_set_common parameters Date: Mon, 12 Jun 2023 11:01:47 +0200 Message-Id: <20230612090157.68205-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612090157.68205-1-angelogioacchino.delregno@collabora.com> References: <20230612090157.68205-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?1768490299849825305?= X-GMAIL-MSGID: =?utf-8?q?1768490299849825305?= 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 Mon Jun 12 09:01: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: 106387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2467226vqr; Mon, 12 Jun 2023 02:50:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6zB5QevZ++KQk+dxiBqO4rymCUoOd2//O+YrbrJs/0H3MgJUkshIaZ2C1K8C6Q8ETy9p4h X-Received: by 2002:a17:903:1103:b0:1af:e302:123 with SMTP id n3-20020a170903110300b001afe3020123mr7740834plh.3.1686563452265; Mon, 12 Jun 2023 02:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686563452; cv=none; d=google.com; s=arc-20160816; b=qD1mbJBdNsy+3c+V9qhgkTknEZAB7ZgXTACVA+FNfvhWXepIUMA6+ojfhK0/9JCjlu QSpuSaNAu2GulbB2OGR+Qb9/qp/Bin8RBr/+uJLeOCYDA/IpxWUo6vk9uy9wuKrSiu01 cWouiiyZEAj9i2OwNHaRJrWRrNwGFAhxKyuXyHhFb9/y+qxq88xHDC0/yTDajm6qOzDi amBcyP2LZhblB/dw+wquuGS72wxcWyt8UcfOm5an6y59MAypud5UNVxW4hOKvGLTFEYO yVJ1BetgnawwLX0xquxkSG86e22Qy5izReD/fWQw74Bi5s5TbhpbcKcmTVMSpKiIQyN4 +Vtg== 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=yksfaOjVMklLhRXQ+tpPz9BPYCermNiGNvvq6E1y1akmx4R3IxRj5sKzC0LSw/z92g V9nqhlAc5qVM5Uz6RiXpMTbvvPRhoNsWNYC0Mi7w7NsDBf3NxY3xkQcx+SX0pOeJyrIB uNdqB9frLu3hxCSuAsyxoctUW5/PIyi8anFkl02Bfw+MDNNisQTeAGYf9Odyzc27Zh2f 7XYSRygx7snfUMguJ88+ZUYO02owVABP1+Zx0kf6BneM2j7xS+9ZlMFiIuRLpJbvxjgR U/nRlvY118OBapuKnhF5phgN5aGDvaKr2M/hrdiSSDJh3gGEbEMh0qyVkKXbUvaiahOZ pFLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=aY658Q+0; 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 e6-20020a170902cf4600b001b2085066d9si2888986plg.584.2023.06.12.02.50.40; Mon, 12 Jun 2023 02:50:52 -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=aY658Q+0; 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 S233174AbjFLJGA (ORCPT + 99 others); Mon, 12 Jun 2023 05:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232978AbjFLJFZ (ORCPT ); Mon, 12 Jun 2023 05:05:25 -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 A791E3C0E for ; Mon, 12 Jun 2023 02:02:05 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 9DC226606E98; Mon, 12 Jun 2023 10:02:03 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686560524; bh=H1IjE6ks2/tQ62I5k+mdDy0LWtBtFX34NVlBCrVhdQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aY658Q+0Pi1xzDSNlEuUHVLmbLxgSQzTuQ1rn4R9okTSDsKzZcjtMgyKxKNrxIBmb SeL9adZxHbCIHp4YIplc2SBlGGUSJrIF4vWoHTBwD7XpoSyNJSShL/byRlgLFwFCJt q/1HHD8rdCMbbGAWSw2PVb835Nf2G1J4s1L+sgz0iEZm8XMUEksUod6dUo+JwI3kVL eKIEbITYzKrz3e7D3LOPTXOcQEVGtoBSrTaFBG9mpf+W33lMs4A5ZPS1c13lpFK/EH X3VRzfq6ly881hcHDyemwEXJadguxj2ONDcOIpHSdlOu5iSp9i2r5bT3xPWKR/kzJL KvqSS5oVCJLOw== 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 v6 02/11] drm/mediatek: gamma: Reduce indentation in mtk_gamma_set_common() Date: Mon, 12 Jun 2023 11:01:48 +0200 Message-Id: <20230612090157.68205-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612090157.68205-1-angelogioacchino.delregno@collabora.com> References: <20230612090157.68205-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?1768489958307676650?= X-GMAIL-MSGID: =?utf-8?q?1768489958307676650?= 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 Mon Jun 12 09:01: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: 106397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2469026vqr; Mon, 12 Jun 2023 02:55:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ74xLN02CuFtbiDvr8qYAmwdlPZedHYViWH0dPudnIYPGxK9VPbhpVTu4y1iqSmC+L7SNi+ X-Received: by 2002:a2e:a306:0:b0:2b1:b301:e63f with SMTP id l6-20020a2ea306000000b002b1b301e63fmr2544094lje.2.1686563743799; Mon, 12 Jun 2023 02:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686563743; cv=none; d=google.com; s=arc-20160816; b=vv9iEK9y1IZG/i9/MUGBb/GzKj6V9en892Z1He89sOqTNmQLkWR6rJxYWB4OFskkVQ oWdoW1OqSrwguCQq+Q31a/YT66YmRS8zASEXIIrEuZQ2RNoHkKzu1k/jmLV/J/Tmw7eb nVDbz5iQ1CDbZUSaS2dJwPxUXlnCyisgHoS/5GZTitkQZy7Qi0oFZxzRV3ocKrxIwyjS hDJMnGvReXHE7i91L8tU2YwFFOHZzfSy0TUIjIm41/3qTvfq7OBGPP+8zqR20H7AsZLy YjpCpxsV2SfE08Ro27yR8n+21+m6xmAmg3j+MTyeDvcPe7/rXJf2iXJzn6V++l133i+J OrSA== 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=PlsKd1xRujfpIYovDuZ/xowCpeEy76JvOwFCL04G64Q=; b=DWEQO0olEyi9Gjgk8X9FvOHdoN1pMUh0bOuNM5Oxv1Jek0vdOYMwwkCODk8yuLHomj EWuFpiIkgEk9CTkMNPX5RfnSyZsu/Um0OmmpIYKFy/nWwznR5s/bNXF0yic7Bj+MLMoB YPz7767Go+FsNpVQ66T0llLoD3bLJwU9uBQHMOibieOMxgx4+iZYZEObZArTpgTcPViQ iWeONZZrUM9Achnxo8CgA5m0BnJcRkAC5z/1UltHv5CShd566VOusVeKMBPQG+Z1KFUe FR2hos6IvzCV2KA216OhfZ47CTgTeKwZ6TOScxzeHyYt4CC/KdoEMdBEqw27E9v3N8qD P83g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Kf1in0PV; 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 ay1-20020a056402202100b00514b8d2b1e2si5654595edb.260.2023.06.12.02.55.19; Mon, 12 Jun 2023 02:55: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=Kf1in0PV; 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 S233964AbjFLJGE (ORCPT + 99 others); Mon, 12 Jun 2023 05:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233006AbjFLJFZ (ORCPT ); Mon, 12 Jun 2023 05:05:25 -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 8DC633C12 for ; Mon, 12 Jun 2023 02:02:06 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 8F67F6606E8A; Mon, 12 Jun 2023 10:02:04 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686560525; bh=uez5eoRMhsgOOXOBI1JFSa4MIzsNoJQ/JLxh/1eaBjc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kf1in0PVgibpp6kMU+DotdjTYPuyGy1jnjIQCqtDyGf2mn4jBFeQNhGTrUfWCWYZA QBe0nCeoxwROcl1h2SDuK0v8g/ZMx3MgnmHR1xk1h2h0To8lSo3eOITSZOcbgGRUrO LYY+4v3Dn1KFs88zX34klHkU2qho4Jo/F7WlHljbfJnsEWMEi8tvnwxxWyZlE5bgww XfqJT7YSZng5DpMddJvlfYEy2QZTCBmP65n14tlf9lMF54j+FeQFjEz94kWkZEPTJo dFVm8y2kSPaEjPjLftlazocew7FAXFIyRERFMl5N7rG//arSbB3G8EdtTnGE/ZI2Mo RMM3yNmxquaQA== 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 v6 03/11] drm/mediatek: gamma: Support SoC specific LUT size Date: Mon, 12 Jun 2023 11:01:49 +0200 Message-Id: <20230612090157.68205-4-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612090157.68205-1-angelogioacchino.delregno@collabora.com> References: <20230612090157.68205-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?1768490264265335332?= X-GMAIL-MSGID: =?utf-8?q?1768490264265335332?= 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..b25ba209e7a4 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 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 Mon Jun 12 09:01: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: 106352 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2459198vqr; Mon, 12 Jun 2023 02:31:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5+/kz8fSuZa9ct06LykjqofgJR5YLpOU9bAoIjWHNUndmgLMubYmcsaBQmkgPZkGkJTVgk X-Received: by 2002:a17:907:60d6:b0:974:6026:a315 with SMTP id hv22-20020a17090760d600b009746026a315mr9508707ejc.44.1686562280484; Mon, 12 Jun 2023 02:31:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686562280; cv=none; d=google.com; s=arc-20160816; b=xOs4QITbiT0jMKzeUXHf6hmGpB9Dxq5zmD9+Ici0YAL+j8Rcl5aZL8yRI0viR4/wVD p10UVUqBQJupGbUbIEyvOzCkZFj6Z7DuD9ZccMA8VkEtSoymjTsUdq/+oBhbuf6weVI1 9Fx9MaAnEs9CUil3FSOVAd1Mdx0MV32YV/ubHrP+SpCRdPp0uQB7aZusCWZ81MqtahBh 6I91uygbSpfKvgAQaMK9gO2gM7HHsyp2OpWQukXY4tbZ1TiHD3xPPtHNgGNCfxErOXHw Bui2dItxOUlvIK4o9i4Jp9X41MSDX2wbPbshoI1/q1Y8T0E96oj/sEoyUtOmKgtOqKT7 l2HQ== 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=iHhX0XvZgB1OW33tzIICVbNRWgZsRwTViJPHbqUqlt8=; b=YmUNnSfODjG8J5q5aMxTasDMPL+rcjfo35Rww0/W3guUDtXnH7ZkHouJKgY4xfm+m3 hLv5Jdqn+Me3vEK2IngE7kBl16ouhFZvFfD+ZIqRw4sqryCMUkga+q0DNSzsFbYYaqkc xRvModq0DpBQWqIMuQD2BNSmP1SnpkLr44xNda38XiwaS184XpyBCROr/Ed/kQcI5mJ6 +X45NkNuduzhLPbMHnkux3Wx9vtQ85VqwMYbcsRJKxzF5AHvJDUm28ldxrFpjm8QqGzd K/8cTjLieTrkMbetoixa5UkwO6k8PNiJxcNmPMZY1Ppr4L9860ASHVT91B46baoEj9lR y3oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=gKQFxjdn; 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 u15-20020a170906950f00b00978acf8b44esi4844905ejx.707.2023.06.12.02.30.56; Mon, 12 Jun 2023 02:31: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=gKQFxjdn; 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 S233243AbjFLJGG (ORCPT + 99 others); Mon, 12 Jun 2023 05:06:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233067AbjFLJFZ (ORCPT ); Mon, 12 Jun 2023 05:05:25 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70D873C15 for ; Mon, 12 Jun 2023 02:02:07 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 84B636605907; Mon, 12 Jun 2023 10:02:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686560526; bh=JI4lc9a8QXR5NBTwDSozQ6dg2sDhEor4ZM5gg2fngeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gKQFxjdnH+vl70AlE44leMWTR2HIoRGjg1Oz2C9D8tXWCbGNiKIHuwHjJP78Wpl3t zf9Wu4CR22LvV5JYJGtLuCcO7xqRI6s2nc+b3kdppAVZ20gHUOGSsC3Qtg3gj6do3c 6pciq9MW4DrH905coZp1e0GXtDCEqmR6xv98wfYZzgydVEpRXvBbij17X+1g5y3BMP CA9YLG8zm5Yy6XSps/c5+yzQCYU6Tfx4bhF4tgZ9EGV+t7mcvFp6Y/z4fjPL5+HuhM NMg4I7wxlKEFT9pC1eddEkdHzL+fQeBMmC9/Q5FJrvLM1juWtlKafTqgQ5KkcdECQG rT5xCXXiW/+3A== 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 v6 04/11] drm/mediatek: gamma: Improve and simplify HW LUT calculation Date: Mon, 12 Jun 2023 11:01:50 +0200 Message-Id: <20230612090157.68205-5-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612090157.68205-1-angelogioacchino.delregno@collabora.com> References: <20230612090157.68205-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?1768488730307601280?= X-GMAIL-MSGID: =?utf-8?q?1768488730307601280?= 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 b25ba209e7a4..204a1aa7bfc9 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 Mon Jun 12 09:01: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: 106347 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2457984vqr; Mon, 12 Jun 2023 02:28:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7KwYOTwe3C02cN7DHi0koifKjYvF7gVO3XC5Z0ZEWlCsF6p4sjmmo/MYaGF7csxt+ODDlo X-Received: by 2002:a17:90a:f691:b0:25b:f4a2:b541 with SMTP id cl17-20020a17090af69100b0025bf4a2b541mr748547pjb.39.1686562113402; Mon, 12 Jun 2023 02:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686562113; cv=none; d=google.com; s=arc-20160816; b=g49mG6z9Bc9yjtGG8E+2wtqVWwAXBDmtKQKkeZ3AdPUmO6r2ZcaSeVHXn7vDtqCaHC tQ2efS6Qi3RXUZ9V0Uh+Ng5Ca0+Ki1fUkjkcAVf8FXN4tM/PoK3zL7sH+eLXr6eL515Y gwfmhk5dyotewoMmxcH1PuiPUqymVDG/8e2m4B4O7P365mfvTxxG7H3lkaVvVoUdzifN S3mmfDgbPGkq87s1QIFf0qbnLoQNFH9i2sRy7qgNvedjv+9RipmJkQWFEzRHxP+W+qJ7 0g+I3HRoh2BOQmPZhr7hmWGt/oVpsMf1Jx5WFXDheuUmfUAXzMLwISRnFk9FQPRAZYC6 Pl1A== 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=B1lo3slqA2jkb8lxv13avUe75yDHWW3lfw5fd2eIIik=; b=cs3LLB/7wF5IE1cfav5SvvCZAOKTNKUqfvfAT0tzn+AFk4XIaUw8RXtgkSztsvJrib cV3zzY7IraNsGWRZin71wbNJhkU5/kx9DjRegmHAgbmu7fffz+o3cXrHRASBbORy5K0x nNh5MRcqNVWxWaSCbwdmejYAOPS2Wphk8aWpLWg+mNMz7yykc/IkX/6YsC3qgpsiZ2jX pgJrN3uxfj1nzSzWGG2Bl/1vtQ2Rlfoo0QkV/saWKKGvfdDDAJQwu/rdWAF2r8bEVn+z WmoZheHG5lM3Fsx5KlRCaFQjOz7z7xavynbijtLqNrTRLfTTIz7poo10eyTPecXVswDK sNIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=fOZ+cMvl; 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 h10-20020a170902f54a00b001b23d02a0c7si7226911plf.272.2023.06.12.02.28.20; Mon, 12 Jun 2023 02:28:33 -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=fOZ+cMvl; 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 S233373AbjFLJGN (ORCPT + 99 others); Mon, 12 Jun 2023 05:06:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233303AbjFLJFb (ORCPT ); Mon, 12 Jun 2023 05:05:31 -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 6750146BF for ; Mon, 12 Jun 2023 02:02:11 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 79CF36606E9D; Mon, 12 Jun 2023 10:02:06 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686560527; bh=IbtbZnmCWfYYE0XVFaNK/WT77zqaqxGqnAMw0WmBnlE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fOZ+cMvlC7LPQw3IUHgrca2Y3UJFFHIarko5dKxkeZvwQluJ9V64iPkSJ12/fft+w fp2sC69cArZ4zyPdrMnAlu0b7QQZt+uwFICPBiuEJEzSjixccZgepcel6tgUUbvNv7 9tzJTLPZnDJ4zEa4uIb1eqlv3waE2CRqRt7tPFEH5ref61MAeWmfSgonA+QDijzzeB /YlCm/HD3jtN3Cr2GJ4ei0mQQZdGlpyJr+AdoPAM8SqU8zQ/QOz7SYSKR5v4p6Ek8n bQCkPMQguRwkA6vlvaEkvOsLo+S+JavwxiBg+A7oo0tnJCJA8C0EBlHgmaBT2niT6q 0EvVJV2W6vRGA== 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 v6 05/11] drm/mediatek: gamma: Enable the Gamma LUT table only after programming Date: Mon, 12 Jun 2023 11:01:51 +0200 Message-Id: <20230612090157.68205-6-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612090157.68205-1-angelogioacchino.delregno@collabora.com> References: <20230612090157.68205-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?1768488554313510039?= X-GMAIL-MSGID: =?utf-8?q?1768488554313510039?= 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. Note: GAMMA should get enabled in between vblanks, but this requires many efforts in order to make this happen, as that requires migrating all of the writes to make use of CMDQ instead of cpu writes and that's not trivial. For this reason, this patch only moves the LUT enable. The CMDQ rework will come at a later time. 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 204a1aa7bfc9..b75a77af5205 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 Mon Jun 12 09:01: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: 106382 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2463845vqr; Mon, 12 Jun 2023 02:42:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45kN2X7i6wX1GEGHMGRHp+jmqcaQDZt3EjwFdc7XZkjnwzNLd1F3pe/8K4a9xBUvT29EwW X-Received: by 2002:a05:6359:c29:b0:129:ca90:3b6c with SMTP id gn41-20020a0563590c2900b00129ca903b6cmr3812414rwb.17.1686562945565; Mon, 12 Jun 2023 02:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686562945; cv=none; d=google.com; s=arc-20160816; b=XGjNT9sq5UoOMySHCWISbp8kVrSCffgQoZ8CJT/U1t/0G8q12buuymi1o2SdCjFW/+ o7CvVpcPgBt1iOc/s/iTgHzZhUs3a4FrsqFkugV07aZnnXpgRDrR26bYJ+Vn/VRTzip9 rI9XD/tIcfkkVZJWSqU8IkoLqvgnTvqeu43w74eCzypkARE0aupLfnc+FUBu+sJlFJ1s ttcb8BZxC8LyxXPQXxJSa/OpxlAK0oUPmYOj5FK1FdskfNpXXrol/8C82Zk/AqaMynGf qulSt3JxZR8OLA2t5poUI5zNUidjHnhAyA2iTVmQRrf7jprrEc9K2k4k01+n/JwzQrg6 bAyg== 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=fRr+Glj9klTlm3ifugQCCLZOWLlw8cR80fnWjkhBVNI=; b=ttOFC3lpm51XU1qjCRi6YR2eFE+zS1c8YfE7fE9B/GuEty5xdIbeSmpH8wfkBn7pcR 7Wre1qEhvrVcKBxptNHfKfhNt71Nj3YqhvjWLIbMtjXo1GTsLzUs/Q+EkN0Iic3MyGlq zE8QzIMvqDm1+7Ek9eNq0yRAkmxvc2Sjf9zNTzLlNrzPgIr+GilhKn0o6orN0Hql2M+3 Sh35WeyeMzowMlK4CgPvM/sv09k/8MQ1/dWA/uz3BZRZd7RK8qfZZh3lQjuj9CT3Tgcn w+jLFjsLA62QanlgxMbR3OfY+qLf1EMwFxhH8B22nIYLtxRNFhUrXr6LjY2q9HJCiwqz Smgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Q1ZVmr4Q; 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 t24-20020a63b258000000b0053ff2b1be3dsi3536073pgo.20.2023.06.12.02.42.11; Mon, 12 Jun 2023 02:42: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=Q1ZVmr4Q; 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 S234045AbjFLJGR (ORCPT + 99 others); Mon, 12 Jun 2023 05:06:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231226AbjFLJFe (ORCPT ); Mon, 12 Jun 2023 05:05:34 -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 67F2F49C0 for ; Mon, 12 Jun 2023 02:02:11 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 700816606ED2; Mon, 12 Jun 2023 10:02:07 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686560528; bh=3I8Rjj9QMcA+JJ4/+HINgDnaxJetoJetOg2mGldS5tI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q1ZVmr4QWzTgS/c59kIyXplHTw+DXWxI6hFZzl41u2TZOGULyoJqszbwZsb8WQgOc hUb166ryYV7qjHj9yz2FJJGmhOwx8oCyfsGd/Bv23WU1JxRuVRDIWU8xrmJGcQz0Eq 0gFF6Qd/Z/Gu3jHNaTxQKS2e3m5/US0wnji/03VG6RVAN1YtZPlXX7JHUzKD94NM0Z xBXC1GXeXg4ZAGaT2bmzz1T1m12cEOyJ+EYd/61gZVdcTEZldP9jLE30pg26zJTDQi Op0ZSln2jr41EhXmv7H56TQSvdf7QEuUZwdjTPUzuSdYOqDXeEa0ZUa+BciqmZWzL8 jtsEvulcOAJOQ== 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 v6 06/11] drm/mediatek: gamma: Use bitfield macros Date: Mon, 12 Jun 2023 11:01:52 +0200 Message-Id: <20230612090157.68205-7-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612090157.68205-1-angelogioacchino.delregno@collabora.com> References: <20230612090157.68205-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?1768489427054006777?= X-GMAIL-MSGID: =?utf-8?q?1768489427054006777?= 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 b75a77af5205..f4bf5b37992c 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 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 Mon Jun 12 09:01: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: 106396 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2468933vqr; Mon, 12 Jun 2023 02:55:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6C0M8BMfpvDtAuKgvPIqSgBNbomQzbWvWAoonLAsCLtgya9ZNQhZUZuDiKQ6Elf3bAYEo+ X-Received: by 2002:a17:902:e808:b0:1b2:4b28:794c with SMTP id u8-20020a170902e80800b001b24b28794cmr6673826plg.6.1686563730361; Mon, 12 Jun 2023 02:55:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686563730; cv=none; d=google.com; s=arc-20160816; b=ruKPIlTF1Ky5I+iyD4o0LoeR69I4hPItmaUWKqrWdFFWwgPkq8QjcQZ5kviC5bI/yX S8w8gnFfvnut74RAq49gmBkw9xJOVL3hTkGKprUbTTMNev1A4JO2qSKx+3piryRHNJUg s1oShmq/Uq0k00RCUa32pjURl0cwlB+faBG84wreBJm7bUqPYitsxPp7373fUzEAPku7 IGulnNXlpMtVp1h/HGyJYuWBaCV4yjaxvMfudd7EIfcD6l331ZIKGlKRxUALbH6HoFze j4z3ZZjLXDnGcj37IV/K+bpYDw1cXNnTb0EC4FtpR6t7kiJGJyv54k0eA7PJ2L4pUWAg Y5CQ== 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=8z/MAQtUsbNTAMbiwZWgqELq9f/TdOpSaH556EXDWRY=; b=wm1l9ylI61eIwSUbDewfkIKpjjztXHLDCRpI27tEcPgcbVLsd2GnISHbUaeewdc2kw cScW/fRfuCDAS6oO2C50DJNo8q4gBTf7sTluWkmYwXSBB4syuiFmaTX+gqgWe6995pBD cMva7F4+YHwrJDXCAp4qX5joZyhv0ffgC7l7GielevOSdQWg32gcpVO6J9yLL4UCC3BR mM0A3JK5NzjzFjEkUOvSOmC2S3xEXFSVKGs8V19FIidyUGjqW5Eo9qhFihK6x2RBjTB0 TP3RBY9QqCXkA1dZb3qgBvtteslkvjAUj/AiVwPbCGHBrqX+koIVa2MCnmE8HlkwEcCd 1nOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=JiZHDK5a; 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 c9-20020a170902d48900b001b075e2e994si7244762plg.575.2023.06.12.02.55.17; Mon, 12 Jun 2023 02:55:30 -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=JiZHDK5a; 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 S231145AbjFLJG3 (ORCPT + 99 others); Mon, 12 Jun 2023 05:06:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232409AbjFLJFh (ORCPT ); Mon, 12 Jun 2023 05:05:37 -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 E141D49C4 for ; Mon, 12 Jun 2023 02:02:11 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 655CB6606EE6; Mon, 12 Jun 2023 10:02:08 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686560529; bh=wvL8C41awqGUjG6vSxsIBQRXHZy+wyE4bNAhpHhiqhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JiZHDK5audELU5OV915FxpbKTQp+LEuX/+WPIiSMVvoHa2Joh+Wz9jNDdcVky5Hnw TwS+PLkD9A1SBtgpwI0KkE+bHE/r6aF178gJYMR4Gsd0arU7lPLiSQODgIp9xnegwf f8gdffORlZKBRYkh9mpT2UnIIcIsy2DfzxVMiE78wfUR9ZPfOWoWbvIsRgX0108UEW jp+e1XHupyDxBASZm/DOCmXKr8cOuJHoVRrbYOX3enq3V1EdOMOfJSuWo01A6FwbT8 k29JtLtlK23fGK2BzWhHPaw7VnSGLM7MTmn6gsAtnNnSeuCbh5lS533vCOGHZN9bCr 4VvxNpyfNButg== 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 v6 07/11] drm/mediatek: gamma: Support specifying number of bits per LUT component Date: Mon, 12 Jun 2023 11:01:53 +0200 Message-Id: <20230612090157.68205-8-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612090157.68205-1-angelogioacchino.delregno@collabora.com> References: <20230612090157.68205-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?1768490249689189722?= X-GMAIL-MSGID: =?utf-8?q?1768490249689189722?= 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 f4bf5b37992c..407fb0264b80 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 Mon Jun 12 09:01: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: 106355 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2459715vqr; Mon, 12 Jun 2023 02:32:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6iKfsefcJuB4ZElZPNKTXcY0eiaf8ut6qB+tUCjVjBLOFbBClGuWWB6VJEw0O2nEpyGHzw X-Received: by 2002:a17:907:3da3:b0:971:eb29:a086 with SMTP id he35-20020a1709073da300b00971eb29a086mr9823969ejc.75.1686562334987; Mon, 12 Jun 2023 02:32:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686562334; cv=none; d=google.com; s=arc-20160816; b=0sRb6rmwUcFAqYBeMlFYrXe2s0jKBZpxdezLxlumhnn6TrKcaA5EOy6BApf7kTnWE1 sVsD6iqnRq2vMAN+LJBy0lzcmGHe81moLpTwAner4HCSaDLY3S3lN034Mu/8DnOcRvMw GOnpFuaRYzenDkVMWiS/856YPpjxPsxvOSWCrPIqOvR44HFpXruHkvIbeKQUaVXGskU3 YMKHHthx4U0gBJdyFr3HmQSDe4BTANsKX85XmG7+H0y0dyGQtMsB8oMDzrJwTKt88ix/ fXjpP8zsinGRj4xZHkypYK+9KDeNPzE/iVYDEdBUkOxk+pjHBBP2CpDCSxa9yb4fyklH GW4w== 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=4Jy7z9ahOeHw8W5iZzBES06RFrJUM0A8E3pIWleulkY=; b=o87J2fx/ebK4jxUsGXweBHI8IA4tm7v6KQi8olEiyJ8Kqx+lZp2Vd9vWPKqOv/i8V2 oUWlrJMZ9wrBOaVo2DggbVci2KQf/6CVCrw61+lAHIqFDknMSiy7UKngZVZ61JHDyIB9 npyzssdLe/qhd2T1v0Uup90s6ORALwFJztseFa7Jj54hD5iM4k1yWZ6oCxhQfDPUk/EL WDjlHUEzj5aa+Eg31Sbdc69/MfLH/vJ1yP2JNTk3Dvww1b+ffPDjjbwubikXWcaow6tm omuZAZ62ilVdlyL/KbON2fzTtXnhoG4ho2iXkjWnfTo8Z/8IwWmmCCvS036YRM7biSrc CnJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lStdLUtm; 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 v25-20020a170906339900b00978891ba8c4si4516069eja.96.2023.06.12.02.31.50; Mon, 12 Jun 2023 02:32:14 -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=lStdLUtm; 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 S233727AbjFLJGU (ORCPT + 99 others); Mon, 12 Jun 2023 05:06:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbjFLJFg (ORCPT ); Mon, 12 Jun 2023 05:05:36 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E109249C3 for ; Mon, 12 Jun 2023 02:02:11 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 50BF46606EF5; Mon, 12 Jun 2023 10:02:09 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686560530; bh=jXr0wGpGehE+iesVyt9aBsjAnzI1CbtR4qvojrtKsGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lStdLUtm4BayIHOLsZjjeC/LghAJ+jsTxVJYd98OD0cXJMhvJV3E0oR2mEP7KJnoo 59JqDmjDebS9cClrzNKRuH/4g9n+4co3nbJQogoDDNlgbdKTGaWHfrVf3CIF/7XNd8 TQpgiCzz5aUM2A13d/gOPsExcTirIR6plzLJsN3Ex0PWUzAtTuTZOvwkv/YRk/azaR IFVKhPeS5ypHBzn9KofbrW4jQF9SFVd5HHtHjmZ4lrZB+z8WJaGz8V8COCVyrFooOb d2hpodGORfTi6tFEYQL26tK58TfO9ddJeiqyWohcHm3BBIZnatI+K8Hz6fJ+c71P1t 4No80H6qegK2Q== 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 v6 08/11] drm/mediatek: gamma: Support multi-bank gamma LUT Date: Mon, 12 Jun 2023 11:01:54 +0200 Message-Id: <20230612090157.68205-9-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612090157.68205-1-angelogioacchino.delregno@collabora.com> References: <20230612090157.68205-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?1768488786798487323?= X-GMAIL-MSGID: =?utf-8?q?1768488786798487323?= 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 | 74 ++++++++++++++--------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index 407fb0264b80..f1a0b18b6c1a 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,57 @@ 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; } + num_lut_banks = lut_size / lut_bank_size; 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 +259,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 Mon Jun 12 09:01: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: 106391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2467797vqr; Mon, 12 Jun 2023 02:52:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6CrPBkDBOYGR2V6v0usEGzOQgfTeZk2pNYOc0HJqKsrjamr+VfS9Ks48cQnRbVeW+O0v1M X-Received: by 2002:a05:6a20:4416:b0:118:b72c:2924 with SMTP id ce22-20020a056a20441600b00118b72c2924mr10080367pzb.60.1686563540345; Mon, 12 Jun 2023 02:52:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686563540; cv=none; d=google.com; s=arc-20160816; b=e4q3i/xykf8inO+VxnvNSw7KBSY/ahQH2lQLlBVB7B3M5yZ77kOhuFEcFICYN0heK3 /6D9UospNY/cN3fYYakEUEVw6F9w7KnwuI88vh6511FWSoDQgXCct6w5ElxsVS76YTcH zYoGhUVK+5moldBHIHT98o9DrR533X0NbxVEBPKHjTbNeUZyq9G315WYLWFibf97oHd5 mt0ci9W41VahC9+KdSn+ftKT6PlLaGMMXIPY6ndgyr+j9rwDcYxhSSNdYKzMNh3WrJA6 bqMdzbYkeS2Pef/Uqq7AR8N7q61/fvj/h7pDQrYb5eItQ8dz6h3ySVS7K/QstzirCV4Z LahA== 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=o02I/TZKnYlBNzxMnEO8uU6MTqI5pIFTPzJLGfJMunQ=; b=CKBn8O5XKgL8Me6TsrkTdhhCcXAiVKwz31M4SoiS31MJ6O3/6TAh22VjyES3wNwdkd XUCa+9+WLDSlaYpedhbhS2Z4isD7Xvus3ObNoU+nYi3SBBoBVt8drvbnec2atS/IuGjS ksOB4VhlRHqBGYXzepKleI4deoTU0yVg2/cHS9nEpxBwWWJ4zuSmbbfXmGh7LSP1p5PL jHc3wFLShH95mDrM/RxsmHZrk2+vvCPrUuCHREk0Cg5maN8zvMyNlxGmMtTxdtV1zPJl RT7m+2J58vFhsEM0iLeTYSNYcTyI3Sh7/DlzgyfY3fABcRL7WwQNqhbbX20hy4Eac6sc EPjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oPPAmp1r; 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 c145-20020a624e97000000b0063b731e3938si6488012pfb.2.2023.06.12.02.52.08; Mon, 12 Jun 2023 02:52: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=oPPAmp1r; 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 S229699AbjFLJGg (ORCPT + 99 others); Mon, 12 Jun 2023 05:06:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233614AbjFLJFi (ORCPT ); Mon, 12 Jun 2023 05:05:38 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09DD649C8 for ; Mon, 12 Jun 2023 02:02:12 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 4340D6606E9A; Mon, 12 Jun 2023 10:02:10 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686560531; bh=LhMeyPcFgIwAH9sbt0vvYI5UK8ayi4irA8hzAUP7wm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oPPAmp1rJJ/vKwjWFh0Rh07j+YqqmYWGrOSGiSSByBqhUTuVsY4OqdbM6vIrNy4IC zLKLw0ZAyhJim6uLIeOFSRlWKHaCDMTruLOb/5Oa56Kp4smOXilrPZLch2evevFAAX 3VNew/cnRp2aP8tepYRxtKaQzrtPwfgpm2g0fgi7fie4Kuz79KA+GUBGl88gEA8LB8 +NoAFTA6Zuzl0jghePpqRSVk8P+EwwlyAsvngZbtf2YJifXkkqPHrlmh8NZCcgF0g5 5hAMbgKJWm+hwZo5Ra2pywma5hmQgVn9Ta5utre+a+JrdMJwngNDsdHjWVHKsl/lDr WnCBbcD7q7vwA== 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 v6 09/11] drm/mediatek: gamma: Add support for 12-bit LUT and MT8195 Date: Mon, 12 Jun 2023 11:01:55 +0200 Message-Id: <20230612090157.68205-10-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612090157.68205-1-angelogioacchino.delregno@collabora.com> References: <20230612090157.68205-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?1768490050914928320?= X-GMAIL-MSGID: =?utf-8?q?1768490050914928320?= 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 f1a0b18b6c1a..e0e2d2bdbf59 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 @@ -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) @@ -110,14 +119,17 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt num_lut_banks = lut_size / lut_bank_size; 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); } @@ -130,9 +142,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); @@ -143,11 +161,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)); } } @@ -271,11 +297,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 Mon Jun 12 09:01: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: 106392 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2468170vqr; Mon, 12 Jun 2023 02:53:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5wndmCk92RFISSsQu2g2uGJ/N6c2bPhLMEbM7Us9R/Zeeo67vl+bGN6WK+dWXzSAjV4qY8 X-Received: by 2002:a17:907:3f05:b0:977:d020:53d6 with SMTP id hq5-20020a1709073f0500b00977d02053d6mr7249739ejc.44.1686563592250; Mon, 12 Jun 2023 02:53:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686563592; cv=none; d=google.com; s=arc-20160816; b=p5a1RNadzmBS7khZRyPASTa8faUmUy1LofwAuai5q3iX2sxtlqZdE6vw1n/VA+NP3/ zCJ+3ht/3T5q7yzJfbAmnmcbhdV3r2ecDqB7zCneK9zJT5aG2+VkjY98C+ztR26HdXbm N+r9lGN3G+V6SW8ZvSq6rq3ja9C8TkEperhDLMsP1aH3pBiohyr+9L1jVMg0bNpkPm66 8VTcagUVaLv/4/mLGfe48ulfD9bXUfzEQ7PPyCJsKXjiEaQC7Nnmpz6kuHl0hq7rY4jt MHrjdOWRGHt40nJMYFP2BoBX1OVu+56ip2L9LLOpGxaeoKMdFsrXjot3Asap8KZgLCnj D90g== 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=GUl62F0yXmRhO/8nxFkuhQdVGSkdKVrP24aIAVxWSpg=; b=ghALlwtGuZlriwsTqBPLupVmL8dT9OPo9Ht8nHYDzBFCCkFNr5IGwYoe/B4RYieYHL gJzix52FBbaRAW9kD9VWBvBIujS6wU5vk+BQi8yNhw3L2vpVAvR3CP9bDRBDqklyyv9r Ylj8kubjTU/lgoujJNaXTZBzirAZ1eycBi5ZYP5n9jimQ9uqWfAd7QdMwDBKK8aUbvEj Cc/pyiaTWt1U4SoLYQ3kFqYTAnGqYWUas9fZEK/GEap/Kqw/atSuY0Mssz9iIxIGSdvt C+d7AGcVeuyVdVE38HWAJRSbDsXRAuxCdinrFRqXKqFvP0qO0witThKRwp4m3qDTFa4L XkxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=n2IiMBIx; 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 j20-20020a1709064b5400b0094f59407d46si1838446ejv.522.2023.06.12.02.52.47; Mon, 12 Jun 2023 02:53:12 -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=n2IiMBIx; 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 S229609AbjFLJGd (ORCPT + 99 others); Mon, 12 Jun 2023 05:06:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233630AbjFLJFi (ORCPT ); Mon, 12 Jun 2023 05:05:38 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30E8B49CB for ; Mon, 12 Jun 2023 02:02:13 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 3360F66056AA; Mon, 12 Jun 2023 10:02:11 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686560531; bh=h6f7psRee+vgHmJfxJWJCr98AHCwupGoqyn4DcinahM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n2IiMBIxHLe63zm/clp9XFbDlNVwIDlgISj+BAW3ggFcAS700c9b+WwgifPTQVQJK 3dBAFBTf+8PBDoK8zAVCggsElh1qfxs/Z/fu5VtzY3cwplaW+OZxrmkSgalVpn4QSc 27dwhOrJTq8gschHWvEB9W/SD4GgahR3+ctvMF2wESmXGwm3SsHXGZVJzlZ4rX/Qeg LJYpJvbElaR0A2Pitk09q2kB4e5UJH03+W0H+Mi0E9MwkwgD5PpWCDuCC5hMdfxNWt Nqnl9TWBsFoU7DDLA7LhSTfpedPUAh/LRBvTv1KniW+7WrO6WSALUNsw9Lc5O4cbJR +LccmSfM94puA== 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 v6 10/11] drm/mediatek: gamma: Make sure relay mode is disabled Date: Mon, 12 Jun 2023 11:01:56 +0200 Message-Id: <20230612090157.68205-11-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612090157.68205-1-angelogioacchino.delregno@collabora.com> References: <20230612090157.68205-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?1768490105329588382?= X-GMAIL-MSGID: =?utf-8?q?1768490105329588382?= 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 e0e2d2bdbf59..e9655b661364 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 @@ -180,6 +181,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 Mon Jun 12 09:01: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: 106350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2458892vqr; Mon, 12 Jun 2023 02:30:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Q6kBNpOxtDL+PbAYxZydtfpSvAqV5FVqDl6D2Sp9g21DU6yqZey2jSWptjg7AYsWZrdl6 X-Received: by 2002:a17:907:6d16:b0:96f:a412:8b03 with SMTP id sa22-20020a1709076d1600b0096fa4128b03mr8381651ejc.5.1686562245088; Mon, 12 Jun 2023 02:30:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686562245; cv=none; d=google.com; s=arc-20160816; b=pBu+dA3FxAIGudNNdK5uGaCjTKqq4SB9Wsxp8kmSvhE6+NQijEyM+ATOEhgiiwqXIh dZ+176jyVk/ed5F9DEtuemIfdFKY+ESF74J0e4bl9iD4PQ9dG80qCEZiM3fIpjlVlMLr bYAYBs9abbdMoM2tKMd8h5qc44cQqseIEImN+BDA2gH0Z/KeIABQ3ZurhKgvK8s2m8bC yMzAKkEpI6gNLBRaDhwiUx2759S4t/x4o9s0LwtuEQL8IJYNVfECuzM8YgyiEFS8Tw+G 7+1vKro4h2Z8dgl5Y4NhLVqB0q8/Co0FPUh8yAnE2U9lsBAaSv2U+/h12imwjFE8o0YF +Z2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HOJPDAsDAzPJAXrk5OeI7BM1OcqzDQiFMWcf16Njpok=; b=cVGVtPP89lYgb7z/uiDnQQmnnu/rYZHDTALppWNGiq5O8wBVz/Rhn3Nv3QPLpmVfgg 1EORCNvLGKP9jjVE8vA7VvEoLGpQsjE8OP2EkXai8R14ylyOiBmNTd0qCMjvnlRDcEPF or/YEC2K5GQ5lCOtDTOibhCzbjXJx11SveU/YL3olEdEQmehUOCP+fz7LdAyBj79wA50 S2Bj0IvI+UwBPZpJcKZDqnKmn7RNkVy9teesy3Zs2BAxtSmBR0Oddg5r33P179YdqH21 68LqL9Yhdz7vq/ygYaBBDTttE/j8yzxOVqJgnKwNM9jJ/lvBMsSOwGS9bc5dUL5vmt2d jEew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XxN0owsx; 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 v25-20020a170906339900b00978891ba8c4si4516069eja.96.2023.06.12.02.30.18; Mon, 12 Jun 2023 02:30:45 -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=XxN0owsx; 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 S229823AbjFLJGj (ORCPT + 99 others); Mon, 12 Jun 2023 05:06:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbjFLJFi (ORCPT ); Mon, 12 Jun 2023 05:05:38 -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 180BF49CF for ; Mon, 12 Jun 2023 02:02:14 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 2334166058B2; Mon, 12 Jun 2023 10:02:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686560532; bh=0Iha/JOTYyfiitNl2/tF672JZIUVhHcbx0vgBiZKTc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XxN0owsxdLvnbN1JSRZbDE/V3atzoEBxyKuBTOte+rVkDAZ6E0v5rAaXs2a2xErnt YiU0ebC7R1m5vtyyZirzCmyyRB5m08HS+eL1r+xJmBQsgs2UL/ZGb9Ubbk7WZZc8Dh VyAlC40CxKfG36v5tnlqSIKcoXf/HWub0JLU6CBQP6M8nbhVkEpAchFG1WZetLsMrj w3DlAoYnviYpV+l51EbTKR00cXoHotVohu86ASwa08PemA9lZHjsEMRBf2D1K/qt8E OASxi1Bnp7Pinr7c3mX9fDK15Wr3kKDMzLiARWQTvF0zYgvifs/tZwxEHiFgHnJvmU YVfUSfOZsOrTQ== 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 v6 11/11] drm/mediatek: gamma: Program gamma LUT type for descending or rising Date: Mon, 12 Jun 2023 11:01:57 +0200 Message-Id: <20230612090157.68205-12-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612090157.68205-1-angelogioacchino.delregno@collabora.com> References: <20230612090157.68205-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?1768488692600607050?= X-GMAIL-MSGID: =?utf-8?q?1768488692600607050?= All of the SoCs that don't have dithering control in the gamma IP have got a GAMMA_LUT_TYPE bit that tells to the IP if the LUT is "descending" (bit set) or "rising" (bit cleared): make sure to set it correctly after programming the LUT. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Jason-JH.Lin --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index e9655b661364..020755ae0ec0 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -23,6 +23,7 @@ #define GAMMA_RELAY_MODE BIT(0) #define GAMMA_LUT_EN BIT(1) #define GAMMA_DITHERING BIT(2) +#define GAMMA_LUT_TYPE BIT(2) #define DISP_GAMMA_SIZE 0x0030 #define DISP_GAMMA_SIZE_HSIZE GENMASK(28, 16) #define DISP_GAMMA_SIZE_VSIZE GENMASK(12, 0) @@ -89,6 +90,16 @@ unsigned int mtk_gamma_get_lut_size(struct device *dev) return lut_size; } +static bool mtk_gamma_lut_is_descending(struct drm_color_lut *lut, u32 lut_size) +{ + u64 first, last; + + first = lut[0].red + lut[0].green + lut[0].blue; + last = lut[lut_size].red + lut[lut_size].green + lut[lut_size].blue; + + return !!(first > last); +} + void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crtc_state *state) { struct mtk_disp_gamma *gamma = dev_get_drvdata(dev); @@ -178,6 +189,14 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt } } + if (gamma && gamma->data && !gamma->data->has_dither) { + /* Descending or Rising LUT */ + if (mtk_gamma_lut_is_descending(lut, lut_size)) + cfg_val |= FIELD_PREP(GAMMA_LUT_TYPE, 1); + else + cfg_val &= ~GAMMA_LUT_TYPE; + } + /* Enable the gamma table */ cfg_val |= FIELD_PREP(GAMMA_LUT_EN, 1);