From patchwork Thu Jul 27 09:46:26 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: 126900 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1007752vqo; Thu, 27 Jul 2023 03:49:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlFH/mRfb67c2yKg1GR+yNzC4FNhI7btFI1kT9uyCSlpuqefxTwiIn826YDoGQ6hSOfg+pCU X-Received: by 2002:a05:6e02:1544:b0:348:f3b3:164f with SMTP id j4-20020a056e02154400b00348f3b3164fmr2307866ilu.12.1690454963008; Thu, 27 Jul 2023 03:49:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690454962; cv=none; d=google.com; s=arc-20160816; b=QPP5ZQ2uEee5cWhdgW2MWGfRpDVMMzvtqxd92EHuBLfJUTIqiB6XBxQZa3yDHOWN02 sIju5DnYw1KzULnILE0FsMM27v648uDZ/wxBb1AGWjalyeO0lKyJl16r5cK/gQa9Kvdg //CcGI6CGVewTzmR3XXtRRhX3Gje12cC06jTaURqjEL3Lz/xTC3uMJYY+zi7Nw77+yWG PZP3NGyIDXhKnGURXXC0jBWH7cf2GK8hvCSAF+LnSerVJNs2/zCLUcK9yV/8F/3Jh21s fCpGUm7WnJitc+gJe7MEY2hFTbd88nSXFKk1CEc6O0+RAzsAbPxERjbCWkUS2nFqTEYs Yptw== 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=; fh=djell8ixvcyqU/mJ6veJqcbgRwD4nTeRiXMTlgu2sHI=; b=OIaLFxBwCM9eWxLDwRp9y6xynidaAttt1Kk+ZkClPV+NUgnNwl7iye/OQ+77D2N/wr eXpWN133zrGOCY0IJh0s+wJ2T0FLNJJ52HUhfSwv/vjr3vuBRvuueTUlCfBokPVJIWkL 2CZge/eBf9yzzPrcmy4Q9AXZDc+gTpZbOCI+hcsSC+37TG2YmxaEPBO7NwOTulllQuDV hRKseNt97Z3Lr47QdDR0u5IytO5j/3wRq89eCpNyswONkpuCGCigSBVtesg+rXLbOKlX O34liYNjvLjOk0mjS1WNj5l8NvAEeZ3no2vLUeI/iIxx5X+zjBTniENxWHhblQ3gngEO PMTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=PnfsL2E1; 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 w64-20020a638243000000b0055c868268f9si1050160pgd.462.2023.07.27.03.49.09; Thu, 27 Jul 2023 03:49:22 -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=PnfsL2E1; 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 S233418AbjG0JrI (ORCPT + 99 others); Thu, 27 Jul 2023 05:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232692AbjG0Jqt (ORCPT ); Thu, 27 Jul 2023 05:46:49 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AC209B for ; Thu, 27 Jul 2023 02:46:43 -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 247C66607136; Thu, 27 Jul 2023 10:46:41 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1690451201; bh=JI4lc9a8QXR5NBTwDSozQ6dg2sDhEor4ZM5gg2fngeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PnfsL2E1I/wOk2GWMINDAp4nFlkIVPoaOW9ZHJVz5BLZNVijBod/CqaaLgFcMYciG nxQ3x9weoOFqdLoC/RUPd2O+K/913vFUb9Ioj/x2uxm0m0Ce+x2moudVhm3xs5AZEi IgIs3tgwSpW+fgB7QF/1KYz+Q8mrj6XELTjGwsxQB3FUkyhd62H5EgBupWiR1hT+OR odKwadKxG4FBASFQE6K5G0nmjOa7NSQTvY3CI7ZaW/mO/xKZG44W9IpXef4vO4L0D9 UxYMrVDS4f/10iG8+V275KAi6kEFiRLKZH/kE7LFGoKtkagpWQ2puXJCG2H39rJa0m OAfofmpoqb4lQ== 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" Subject: [PATCH RESEND v6 04/11] drm/mediatek: gamma: Improve and simplify HW LUT calculation Date: Thu, 27 Jul 2023 11:46:26 +0200 Message-ID: <20230727094633.22505-5-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727094633.22505-1-angelogioacchino.delregno@collabora.com> References: <20230727094633.22505-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: INBOX X-GMAIL-THRID: 1772570503407181503 X-GMAIL-MSGID: 1772570503407181503 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 Reviewed-by: Alexandre Mergnat --- 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)); }