From patchwork Tue Aug 1 11:58: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: 129261 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2637888vqg; Tue, 1 Aug 2023 05:37:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlF0Enz/+fzO6jcwmAM/wrbgJRHP9c4hiM0MDXtOngVhAMyY0k1Bk07X0UsYqAtokF9Y0Atp X-Received: by 2002:a05:6402:345c:b0:522:3081:ddb4 with SMTP id l28-20020a056402345c00b005223081ddb4mr2256309edc.20.1690893472649; Tue, 01 Aug 2023 05:37:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690893472; cv=none; d=google.com; s=arc-20160816; b=vIVs/0SdGXG2oG82zlBdeSH0BZ+sDdzrzqus3CrQ11DMTmx/W2q91jyAPqNEVoX1Tc M3KwJQfwxGq3jAk8D7Uvlv5c+SobtQTX8X3z8IfeiokmpTx2qDG4SeT7XiLL0CeQ91Ek eoUbG4S+LifdKQuB0YrBjbI+B314HnoR1ZJDvDuQlx+BxOmMMj7lH974QhitLYj8TPkO v5pnsaPjnMWtIzXyANLC+dTk6dMDhouOU/UQkVEqIUCzfe6uEkFdJcPFiBWdIdDJZdG9 1LBc0nW7Tb6HhvhImE0N9NKJ1Rcw9kNexmTL0+fu5M17uFcLc++HDLXEWS9s/CMG1IzU mhoA== 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=1KFqqtYMUx6OFXWApfzEJwnhOHG6dnbWO1x87t86gmw=; fh=wVZEQimxp/UyE4Mf0Sn+nsZcfrBLHvkvU7kacOC/59o=; b=CyXo05hF87+CHwP2r9BavScZZNUCvwkzZK6Ppa8nQ6vo2LJfZ+ZnebZNdNAO71JMEl uUBcMbGqT1xa+cN8cQs5TSGKVHk+dA61W4uea6DQlZy+04iUiI82vD2nxb3zy9HuC2Gk yLqCfHFkngJJlwzLiTqrRAAcaAAFKT63GIlVcWbHyVPvLy8XQJK+nNs2rPP9ZTWEEpWp ZsXjNyBKxNdog7jTNkjs0KkqF3PThAOyaBlzUZvItsOtJ5jP0DsJiCeuPfnsXfRo0PcG DlMvABa5z5N73ylm7CcuFLMzt1ny1Fqd7qexUeizuhWDv/nJfuso+vfVL3DMfv+ozpbm le8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ImLMGSWt; 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 a8-20020aa7cf08000000b0052255bf21b5si8432491edy.436.2023.08.01.05.37.28; Tue, 01 Aug 2023 05:37: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=ImLMGSWt; 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 S234443AbjHAL7a (ORCPT + 99 others); Tue, 1 Aug 2023 07:59:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234046AbjHAL7O (ORCPT ); Tue, 1 Aug 2023 07:59:14 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 428181736 for ; Tue, 1 Aug 2023 04:59:09 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 6180C6607199; Tue, 1 Aug 2023 12:59:07 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1690891148; bh=TVDX6Wbe4BzuqQdeWe8CTawxJUw/+TZsfYlFuzshf40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ImLMGSWtV2Rahsx3JNsQDlJaHBnvDu4+tJWoqRbUuLmyqS0SdbEoWK3Kg2HWfQMIa 0smgExm89ckBFESoU26KfOSCQW2mK55NLSAIqp3XxSj/ZNBbjcV9EDTOmvnx0Mg3eQ k1rNiHW9PdJk3ewIi8AC2/E680z8tHZdthiyjrFE4Uuf0jfmEg57YNTAvGiWqJ2BF9 5eTW6wrUdlo5/lRcWCzsxWyhRp7ExjhqreNGooe7rk/XM65PVHpjF4PyP4rVvYXXyg jECuSeLVAtw7FyUZWRxPg0Zc1xjvmwl0g++FEn1q67tgYFl3qfXyVvjlMAOIcoirz0 xIyKzLia1QZOw== From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Cc: p.zabel@pengutronix.de, airlied@gmail.com, daniel@ffwll.ch, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, wenst@chromium.org, kernel@collabora.com, ehristev@collabora.com, "Jason-JH . Lin" , Alexandre Mergnat Subject: [PATCH v8 08/13] drm/mediatek: gamma: Support multi-bank gamma LUT Date: Tue, 1 Aug 2023 13:58:49 +0200 Message-ID: <20230801115854.150346-9-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801115854.150346-1-angelogioacchino.delregno@collabora.com> References: <20230801115854.150346-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773030314063348825 X-GMAIL-MSGID: 1773030314063348825 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 Reviewed-by: Alexandre Mergnat --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 73 +++++++++++++++-------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index a6f7af1a9e8e..fb7c3650a9f7 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -24,6 +24,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) @@ -32,10 +34,12 @@ #define LUT_10BIT_MASK 0x03ff #define LUT_BITS_DEFAULT 10 +#define LUT_BANK_SIZE_DEFAULT 512 struct mtk_disp_gamma_data { bool has_dither; bool lut_diff; + u16 lut_bank_size; u16 lut_size; u8 lut_bits; }; @@ -80,7 +84,9 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, void __iomem *lut_base; bool lut_diff; u8 lut_bits; - u32 cfg_val, word; + u16 lut_bank_size; + 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) @@ -91,41 +97,54 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, if (gamma && gamma->data) { lut_diff = gamma->data->lut_diff; + lut_bank_size = gamma->data->lut_bank_size; lut_bits = gamma->data->lut_bits; } else { lut_diff = false; + lut_bank_size = LUT_BANK_SIZE_DEFAULT; lut_bits = LUT_BITS_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 */ @@ -236,11 +255,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,