From patchwork Thu Oct 12 09:57:24 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: 151883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1104819vqb; Thu, 12 Oct 2023 02:58:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxV1BpuSZvvzK6GR9JENRtDTMggzeF5MO82GKbyERjMPB3OwdU6DY2p231AESQ+7bIzst+ X-Received: by 2002:a05:6830:3109:b0:6b9:db20:4d25 with SMTP id b9-20020a056830310900b006b9db204d25mr34214116ots.1.1697104704810; Thu, 12 Oct 2023 02:58:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697104704; cv=none; d=google.com; s=arc-20160816; b=DGqzktSdKKQG2mep2gEjcti63ozznnv+0aPo0p1uo7N00neBKyWBu2d1akMBpyK8cr fC049MeXKzcoSL1fKx3w6H78wwvbO/nwRJpx+pb9vctl9ySDNxYTZl2SHY35I0Izu72K EBP6CCy7C0C5C4Y5w/tzWnsWDjJ99F3p+x8Z5RAmt4cyWfpDXVul/4zTJp8tnfW3ZVkJ eW/3Uq2w92FiiFUl5cxpSThrqUcehFYhJgoe3KJ+2n/NLChD3wUXttmgYC0EAs0G8hZ9 +X3uJ+oL4G77FaAPtZZVrzqg+88gkG+TaH1SHB2jP4+0/oOdKiw0Ft3mKhq0r1ydeS2V uJBQ== 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=EzfvHWSEYSMH15o/vMdT/4n8ZkRHAJYsHair1rvPhrc=; fh=KhamMcu+afW+JcycbJwsIN7GCvQjQBx356VRODtXooA=; b=pz65bd5IxpQsl279j6ORrQzzHxMwGmQcC5mc9ElFDVe6jtvQ1jG/RNjHvTH1SeYTOI l22YeHt6TBYG78GqiKuniyv7izeKffyg9TCypRzTzV+y4fGHNtNPKpS2q+AhESzHElnq D/xF1U81rjZjdLdAL7FHdhZ4kj/IUGAsJ3uYVrnUG7xFn3f+gZqu5jFqcQgBHzR6c9s5 NTR8JPP3tiXCfePdwyYwdnE7rYjjdNpOWuKFAb/+t2ndliDYxFjmKpsL1VRbZlyzBwiS 2vpf7JAWHO5Yy/4oTvd5dl7gS2H4OCZWbbwYufpI3dVgTARTqQR9st1TEillMEzslMMc HbDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=dtX10vzI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id y70-20020a638a49000000b00564f4a7f70asi1927989pgd.412.2023.10.12.02.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 02:58:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=dtX10vzI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3D6D7818B814; Thu, 12 Oct 2023 02:58:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235676AbjJLJ6L (ORCPT + 19 others); Thu, 12 Oct 2023 05:58:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235594AbjJLJ5u (ORCPT ); Thu, 12 Oct 2023 05:57:50 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB583B7 for ; Thu, 12 Oct 2023 02:57:47 -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 CFAAD660734B; Thu, 12 Oct 2023 10:57:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697104666; bh=skAu7ZS20gD3ZXT+OV72kM7TJ+5GEtjNjK2WnVYj0aA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dtX10vzIdQ7pXXAttUPQR1RzBhy9peMo6gqfWewec4zrCLJErj7h8pfOfmFBNAiiZ LCBST07K7i4jzbnmXB+poEcJnyzwit8b8XIfmM9yLL+sL2Bt7O+2f/H+/2BrEhUgrq Avf3BJkgViZ+0upe7ibFiavIsUqPYOV+bPh6+2lrRvLbZgraJhRqlE+PZ7j49Cz3tB zkGcPQpNSPzkFk07yk6nG9ABQTHSVkHFIBOhhGkHpwFQxI2sTG3JQ9XboZ1iWTTMVU M26P/Q3GjTQNMU6+gVdbu5Wce+5IGBDZn6Q19Mv1KY6SUmkOKtg6rCuyzQ/KvbM/ke EQuWG+sRvFVBw== 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, nfraprado@collabora.com, "Jason-JH . Lin" , Alexandre Mergnat , CK Hu Subject: [PATCH v11 04/16] drm/mediatek: gamma: Improve and simplify HW LUT calculation Date: Thu, 12 Oct 2023 11:57:24 +0200 Message-ID: <20231012095736.100784-5-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231012095736.100784-1-angelogioacchino.delregno@collabora.com> References: <20231012095736.100784-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 12 Oct 2023 02:58:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779543262790815269 X-GMAIL-MSGID: 1779543262790815269 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. Reviewed-by: Jason-JH.Lin Reviewed-by: Alexandre Mergnat Reviewed-by: CK Hu Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 32 ++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index bb237523d4b7..8506b9a0a811 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -23,8 +23,6 @@ #define DISP_GAMMA_SIZE 0x0030 #define DISP_GAMMA_LUT 0x0700 -#define LUT_10BIT_MASK 0x03ff - struct mtk_disp_gamma_data { bool has_dither; bool lut_diff; @@ -73,7 +71,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) @@ -96,18 +93,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)); }