Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp783453imw; Fri, 8 Jul 2022 11:37:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vRo0xOIBNDhS2Ff+qWmbMAHyrYuT0A3+QPhodKHxCBSvY/2he/J2s9qdbwMaIw+B2g4rgl X-Received: by 2002:a63:480b:0:b0:40d:d4d1:7daf with SMTP id v11-20020a63480b000000b0040dd4d17dafmr4427423pga.512.1657305444607; Fri, 08 Jul 2022 11:37:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657305444; cv=none; d=google.com; s=arc-20160816; b=Tl7pVbn7nIdYOzpRfdxeXjiPVCEknSE41cToDNKgqSaiEuP/Ll1E3ajsByPi/DZ5UZ 025IOkLLP7rT+UIAmBY0+vogM9mf/CkIuqaHgXUJte5ZAlHndTbjSi7NLwowGuwGFe9r RFiO24mSzfGFAJh7tsgruIKwZMiRX7X76lGsjyyeWtFfuYePu3v2+Tt/hEDsw6dvsSag iZEo8SJ46uWei7cmo++jF6cg8xqweSU+QgNUuR3IalOlbF/2MYEDZG2CcR78FeLm4+H5 kQhffsEhI0hxY7aSebQxk9BL+OcG6TTNffa2C9RMejG9ySP+KWMKEfJeqy4jX/l9TtxW xGsQ== 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; bh=C6OUwr3uvvgNxGrACOpE1cjPQWPHB111ebNdrcZRR6A=; b=mhHgVVdW+F+AP5XxwrwxjJjkCCAo8VSYDzUT7QQpaeT6f24186NGvDMAWQGcyUACVV qI0znxadg3Y7wdGmZhHCC9e1fbgronRieM24YbdVh998hwWtMW4ttdVMVPMKdgfBE3xp zwqGU9ZzScvRTn0zO5zRhgg/flOl1HnesWV5csvCamAXIsc6LqOLexdnD8rzrWFNYOk4 NFB2a655+1jLAMTPwy8aPAeTDhAMPl4LId1Z8poJ8yl5xldSYx9KAOxeZulHPBfFnfs0 88/6eOAwFJIWJoMGSRyDOPIpyp8eCMuGQaUVo05/og9JfIxVrzaqIAIcU/uovclk/son 1loQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ru17-20020a17090b2bd100b001ed40b70436si3104809pjb.155.2022.07.08.11.37.08; Fri, 08 Jul 2022 11:37:24 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239323AbiGHSVx (ORCPT + 99 others); Fri, 8 Jul 2022 14:21:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238842AbiGHSVQ (ORCPT ); Fri, 8 Jul 2022 14:21:16 -0400 Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F004882395 for ; Fri, 8 Jul 2022 11:21:10 -0700 (PDT) Received: from ramsan.of.borg ([84.195.186.194]) by michel.telenet-ops.be with bizsmtp id siM72700Q4C55Sk06iM7fm; Fri, 08 Jul 2022 20:21:08 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o9sbD-002fGc-0Q; Fri, 08 Jul 2022 20:21:07 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1o9sbC-00BtJ7-8Y; Fri, 08 Jul 2022 20:21:06 +0200 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven , Javier Martinez Canillas Subject: [PATCH v3 01/10] drm/fourcc: Add drm_format_info_bpp() helper Date: Fri, 8 Jul 2022 20:20:46 +0200 Message-Id: <1cae5ebc28513ec1c91c66b00647ce3ca23bfba7.1657294931.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Add a helper to retrieve the actual number of bits per pixel for a plane, taking into account the number of characters and pixels per block for tiled formats. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas --- v3: - Add Reviewed-by, v2: - Move up. --- drivers/gpu/drm/drm_fourcc.c | 19 +++++++++++++++++++ include/drm/drm_fourcc.h | 1 + 2 files changed, 20 insertions(+) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index 07741b678798b0f1..cf48ea0b2cb70ba8 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -370,6 +370,25 @@ unsigned int drm_format_info_block_height(const struct drm_format_info *info, } EXPORT_SYMBOL(drm_format_info_block_height); +/** + * drm_format_info_bpp - number of bits per pixel + * @info: pixel format info + * @plane: plane index + * + * Returns: + * The actual number of bits per pixel, depending on the plane index. + */ +unsigned int drm_format_info_bpp(const struct drm_format_info *info, int plane) +{ + if (!info || plane < 0 || plane >= info->num_planes) + return 0; + + return info->char_per_block[plane] * 8 / + (drm_format_info_block_width(info, plane) * + drm_format_info_block_height(info, plane)); +} +EXPORT_SYMBOL(drm_format_info_bpp); + /** * drm_format_info_min_pitch - computes the minimum required pitch in bytes * @info: pixel format info diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index 22aa64d07c7905e2..3800a7ad7f0cda7a 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -313,6 +313,7 @@ unsigned int drm_format_info_block_width(const struct drm_format_info *info, int plane); unsigned int drm_format_info_block_height(const struct drm_format_info *info, int plane); +unsigned int drm_format_info_bpp(const struct drm_format_info *info, int plane); uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, int plane, unsigned int buffer_width); -- 2.25.1