From patchwork Thu Jun 1 12:10:15 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: 101913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp272168vqr; Thu, 1 Jun 2023 05:12:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7eiYJQdCU/Ly5COKzZP3twhNkC3ndTQCVQ1RAbaypxG41l7ONvf5YjNeoaTr/G+7bZvVJR X-Received: by 2002:a05:6358:897:b0:127:76ee:8d95 with SMTP id m23-20020a056358089700b0012776ee8d95mr3266990rwj.8.1685621574860; Thu, 01 Jun 2023 05:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685621574; cv=none; d=google.com; s=arc-20160816; b=weCVLXIeA1tCQAj1MNshSKLKiMNWQteDelezUMis3m0+Xnzd/A132LY5m6NqY5AEA3 VUQYECG09gSkukPphnm0ZhWYwk9g2eqxIQtVBqoFwPTNOAJSINWp3ULuWQRkiaAnC8em LtdnjQtbxS3fMB6hTdxQz6NDhLEWJw3GmqZ0fKxvcwc3ATtuHxdu51TBKTYZ9CX5Ykmb uw7dFXehigaLa3+pVCqJn8zt4NnA+/ta1lR4J78u+4nqLTWbH+qaAJszfocCP/rg0NbK fQslQiwLM7ApRC72VTAZpgqEaNTXAz/U8ezEwvKzj0KldWITnVp5yygDFz60BA2DuvLC UjXA== 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=E/n8sXEg57aYMiLUIgXwzUi32tgQy5GmlXHgWvfvEqQ2+8R8P9e5JYy+z+eDsdrkOy wzKXL8IC2wD9H+Fz7V8VleJVI4xDLDp0hrRjyjkDD3klEHrCqRaIc8eKadPXLlqqVnKu +hmgmhkta1cXXBLyaZHDikZoTDQv1KNN/mvCrAxhFOv4R0AlBsiHqLhj9aXhjUOJIMYg SAgR+8NmtMYnF0TpHruxyMQKzgV192j4kVmA+19+asnM6vsugHngGF9eE6okdq3nKFCo xpVGsSLrXlBuxycwZd3CF0SihyNr3c35UvZe5voEi+Mc16moqsToGLLgGjyM0n8+qnZq PD4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=OkF7uol3; 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 l190-20020a6391c7000000b005349008e6c1si2841724pge.264.2023.06.01.05.12.42; Thu, 01 Jun 2023 05:12:54 -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=OkF7uol3; 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 S232180AbjFAMLD (ORCPT + 99 others); Thu, 1 Jun 2023 08:11:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233247AbjFAMKp (ORCPT ); Thu, 1 Jun 2023 08:10:45 -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 A597C194 for ; Thu, 1 Jun 2023 05:10:32 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:a962:cd4d:a84:1eab]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 4A3116606EC6; Thu, 1 Jun 2023 13:10:30 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1685621431; bh=JI4lc9a8QXR5NBTwDSozQ6dg2sDhEor4ZM5gg2fngeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OkF7uol3xtv6g3BnVV1WKL9QfZWHq4DDRAOwg5aIm1B4M8lEFjLjodUu6yymWYrvt 9m0nYMi5JXYwu+t0y91igKmR3ccdmeoqDpP8DnYQJJMmpxuumWgR3Vz1TZrt/3pPqn kHTvEK1hCXzuN5AG6mHkK3IW5G+NYM49E6h4f1fRD1+rjFC3HXANNH76idBD8vns6V ItVXXGQrU9yMKXqeM7zzY7KGPEIHu1RQZw8sLGfU8aPqv1VVJDrZJZKQnKkx48Hg30 uJV++uX5NXAPgB3hVmAW1eXnSCBAEFJKMXTas2Z753gyIleg+LXG0WTkqkmchsk10b k2ExlGGXhwngQ== 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 v5 04/11] drm/mediatek: gamma: Improve and simplify HW LUT calculation Date: Thu, 1 Jun 2023 14:10:15 +0200 Message-Id: <20230601121022.2401844-5-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601121022.2401844-1-angelogioacchino.delregno@collabora.com> References: <20230601121022.2401844-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?1767502328310540519?= X-GMAIL-MSGID: =?utf-8?q?1767502328310540519?= 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)); }