From patchwork Tue Aug 1 11:58:45 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: 129292 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2651110vqg; Tue, 1 Aug 2023 06:02:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlEKdHVcA8xinz2ew6iycppwx+X7S/gMjuvRsyOfTxDyQ7PV3/NT68t+iNVgf7mzZGm8Pzd2 X-Received: by 2002:a17:902:d382:b0:1bb:aa83:f848 with SMTP id e2-20020a170902d38200b001bbaa83f848mr12507712pld.43.1690894969524; Tue, 01 Aug 2023 06:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690894969; cv=none; d=google.com; s=arc-20160816; b=OvpUIy2j0pHo5+D7WKDVp8XCLcgbj6QKWEXySYGjRdzROQE/xXs2fOL3v1PTAQQX6w HY8+/anP4LAFmSrG/bfgHGDTNqDW8aLSmDwINz4gQoELSaN5wyJKH3DYIHso2AjWzCfx +MMTFXmfyE4ZSScaUw8KnQuXH12TZcG8qJpqP+G6DanPtRwimAh+SxYiWcEUNokjrcTU 4nPtgC/KhthTRehOpcad7I5mY3//N9OWiXRofSwySAO/5fnziULnxwUPEFYUT8caIjO3 TsiDt/ZqjYh8V1JvM/iG3M16Ck6N1QCZ+TFa9ECZd0QkUb1gegAp2+bVmlArKaiWdFRl IPTg== 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=8NCzE0oubY8HvvTCXgWwCuiASwNVA9mpyL9XoQwwyKw=; fh=wVZEQimxp/UyE4Mf0Sn+nsZcfrBLHvkvU7kacOC/59o=; b=tVcNsiDGAF/q44BY3zhIZePYn7UxmEy76xGOMP8QtEJ0CvP802IyD6ql/PPbD+AI3k s8jSDvekFoxRXehfjFruC0BO8R0elKec8Z7qO+uu6miJLakoUNzM7O1aIVKp6+yh3hmA KMJSu1CLiJ/dSN+bQK3BvxSLM4TiADDf2xayKp71G2oRF3N+sTT8pFK6X8Ouw/GV/PyR EoH4xU4H6rlWIqfhYujHJiWY2iNvHMMTW75ES1o1darknDJC4tlbA3UJSR5ZLz4KV/kb 1RmJb8ySr2/64WXcGOfgU8M5vmQ4jXvX21WQxKcaOMiH4VhE7YmFn8I8J/ri9iWpakep 1cnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ZFsIaeGO; 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 w20-20020a170902d11400b001b25ade9ea3si1644154plw.337.2023.08.01.06.02.34; Tue, 01 Aug 2023 06:02:49 -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=ZFsIaeGO; 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 S234039AbjHAL7P (ORCPT + 99 others); Tue, 1 Aug 2023 07:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233752AbjHAL7H (ORCPT ); Tue, 1 Aug 2023 07:59:07 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A44811718 for ; Tue, 1 Aug 2023 04:59:05 -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 C720A660718C; Tue, 1 Aug 2023 12:59:03 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1690891144; bh=300Y5h80g46COpGlx0H6hu4Nbeunl/5bqJFtVyc6tvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZFsIaeGOaGgR2WFlvXKzdjA8WLoqx2wu+PFLk+pSwwz7GEvhUY6GqkYhrAQ43a+Gr UxW6OP9qgDGqgo8jgHZt9PQjvEtm3s3InMzSyD7PGmsnny5L0/pemcOjJHnpqFOGLL lPSWTgFs0/8VUQgoljCU52jxqFHSSizfhbL8FBf9IJhvwyO32CTO+g6B5/DsevXdRL +SLPGlfOUpP4qp97K0B72LBNma2myhViGKf4IHNAM79HdRhirifBZi3SC58W4jsrRn O4ZPx0owPi1leyS9K4/Xv1kRLjI8p6TkoNMP6EMPWUB/cML4qN2WKNk+zSp/JRsnrL Qw3bXRvvKmeTw== 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 04/13] drm/mediatek: gamma: Improve and simplify HW LUT calculation Date: Tue, 1 Aug 2023 13:58:45 +0200 Message-ID: <20230801115854.150346-5-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: 1773031883899897523 X-GMAIL-MSGID: 1773031883899897523 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 bfdecb278b45..1e21dd92c88b 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -71,7 +71,6 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, void __iomem *lut_base; bool lut_diff; u32 word; - u32 diff[3] = {0}; /* If there's no gamma lut there's nothing to do here. */ if (!state->gamma_lut) @@ -91,18 +90,29 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, 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)); }