From patchwork Tue May 2 08:16: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: 89278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp444888vqo; Tue, 2 May 2023 01:33:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5d486PDyO/IO4yViKBP5adKGqsv1gf9dFlTQwx+zHWv9DD4A70B+briiLsh01YqzRglT/R X-Received: by 2002:a05:6a20:7f82:b0:f5:c6e5:e65 with SMTP id d2-20020a056a207f8200b000f5c6e50e65mr19769504pzj.7.1683016414384; Tue, 02 May 2023 01:33:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683016414; cv=none; d=google.com; s=arc-20160816; b=xebdl6sIR4lYSLTtdjsKqq10fvvwaxRNF/6NkVqOSjFoZVahSgVT9eZuJH/jqRaZah mNpK1ayk/vIsV6tcUJj9N70Wd/pG1LL/tcwZIvzM0IUIQ5dkB9Za6eX5JfwIpnsaxsG5 /tIVdwN76lIEhOB7wkXaRjKNDhdXPgnf43NXMWL9lk9tdXgi63/BJLR8t8shtyVUqMgg qEBksUHThbuFc2fxz3hbsE7Il2vbr9CI5zvKQ+J8QI8DKlX189RcK0/YO1kwUXxW+7/l 4bwADxlqOv7S1r16oR9IfezPLgy9Iis6o1w1sCuqqfGSVY3rFakeEooruFpizHYAhR1j 8z3w== 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=VHwy78X/RBr6yo9tCXKDwqCT0V9kqllI0HmjS8JdXAE=; b=R//4E/P1OOmufcA5lK4IQjxOJhKo6bJn2IdHPWPE/vpY+mysTNz95/NBFxo759RiOs qekH0ZwK9RzuC/UR+C7+vSVH+nYe9BsadgExC20tsy0jbLCJ7JR7nbDjcMK6yc6x4YuQ YE2r/eIH69ttAIkggm9tfN8slVKIp2BDdI7nWhafhbOCnXpR4VG6CauN7qOriHCsIocH Z9VoCQcVzPMXsSCMx0dFlm00CpyyqyOOPlgYZkg2XY1rVwzq0AvM3q2S0lA9iLDNDuxU 3Spd/IOLwJKPNxgYr5sgmhRaOFU9DIxTOcxdY54SMHS1MgaVhMduJV4ITY4ro/z4wMmR 05gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XVkCI8CW; 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 z11-20020a6552cb000000b0051b0df691aesi28615443pgp.771.2023.05.02.01.33.19; Tue, 02 May 2023 01:33:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XVkCI8CW; 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 S233730AbjEBIRX (ORCPT + 99 others); Tue, 2 May 2023 04:17:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233682AbjEBIRH (ORCPT ); Tue, 2 May 2023 04:17:07 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41BCA4C07 for ; Tue, 2 May 2023 01:17: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 2AF3B66056C4; Tue, 2 May 2023 09:17:03 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1683015424; bh=JapbrLaTIM70PHLJVtIa1Pf4tXZK2Gzc3i8h5L4HFo0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XVkCI8CW5kGnKTHD2moBwvbSgE1jqyKi+mmED8FFQgS83jtGGhqueSAZOowVxtUlZ juQLbouJMl65VVN5TcxV78nUcG7e6BzratqPXUR3R8kD6/7rA6gRCjAIjnZJaUbiGd oCHGTMaS+Y2oOUWaeZc1mG3rQSJSKMZQQkNXlk/+5Y7pG6LjJ4SVYj+fYnhU2rnAI7 iqGJU8TgiWKEmtizHbPNBblInnu3uxBFrH2XLNmRri216NA/6C3cGpDpTTMS/UKzC6 2XBkLhxNRMJ0Z5UNPDkDPnCpzBiluiKniCfHW4EKf09PYbhCVYs2dW47sw1M1989DT f5yFHsFFr14Ug== 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 08/11] drm/mediatek: gamma: Support multi-bank gamma LUT Date: Tue, 2 May 2023 10:16:47 +0200 Message-Id: <20230502081650.25947-9-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230502081650.25947-1-angelogioacchino.delregno@collabora.com> References: <20230502081650.25947-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?1764770619590207109?= X-GMAIL-MSGID: =?utf-8?q?1764770619590207109?= 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 | 76 +++++++++++++++-------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index 320a7e36d9c5..8e9e8317ff81 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) @@ -37,6 +39,7 @@ struct mtk_disp_gamma_data { bool has_dither; bool lut_diff; + u16 lut_bank_size; u16 lut_size; u8 lut_bits; }; @@ -83,9 +86,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) @@ -93,43 +97,61 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt if (gamma && gamma->data) { lut_diff = gamma->data->lut_diff; + lut_bank_size = gamma->data->lut_bank_size; lut_bits = gamma->data->lut_bits; lut_size = gamma->data->lut_size; } else { lut_diff = false; + lut_bank_size = 0; lut_bits = LUT_BITS_DEFAULT; lut_size = LUT_SIZE_DEFAULT; } + if (lut_bank_size) + num_lut_banks = lut_size / lut_bank_size; + else + num_lut_banks = 1; + cfg_val = readl(regs + DISP_GAMMA_CFG); lut_base = regs + DISP_GAMMA_LUT; lut = (struct drm_color_lut *)state->gamma_lut->data; - for (i = 0; i < lut_size; i++) { - struct drm_color_lut diff, hwlut; - - hwlut.red = drm_color_lut_extract(lut[i].red, lut_bits); - hwlut.green = drm_color_lut_extract(lut[i].green, lut_bits); - hwlut.red = 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 (lut_bank_size) { + lbank_val = FIELD_PREP(DISP_GAMMA_BANK_BANK, cur_bank); + writel(lbank_val, regs + DISP_GAMMA_BANK); + } + + for (i = 0; i < lut_size; i++) { + int n = (cur_bank * (bank_size - 1)) + 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.red = 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 */