From patchwork Tue Feb 15 16:52:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 543511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20ABAC4332F for ; Tue, 15 Feb 2022 16:52:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233641AbiBOQw5 (ORCPT ); Tue, 15 Feb 2022 11:52:57 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241901AbiBOQwr (ORCPT ); Tue, 15 Feb 2022 11:52:47 -0500 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 6A9759E9DD for ; Tue, 15 Feb 2022 08:52:34 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:7534:e0be:5adf:2691]) by michel.telenet-ops.be with bizsmtp id vUsV2600618GbK106UsVDJ; Tue, 15 Feb 2022 17:52:31 +0100 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 1nK140-000tUm-Kf; Tue, 15 Feb 2022 17:52:28 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nK140-00BURd-0H; Tue, 15 Feb 2022 17:52:28 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Helge Deller , Javier Martinez Canillas Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 3/8] drm/fourcc: Add drm_format_info_bpp() helper Date: Tue, 15 Feb 2022 17:52:21 +0100 Message-Id: <20220215165226.2738568-4-geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215165226.2738568-1-geert@linux-m68k.org> References: <20220215165226.2738568-1-geert@linux-m68k.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@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 --- 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 60ce63d728b8e308..5c77ce10f53e3a64 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -388,6 +388,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);