Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp358301pxb; Tue, 15 Feb 2022 15:19:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLigPFcTco6N7oRKGOjl+mLppregkaoRIE9IBElSPu/EHsImfcVQaRGK/BOYnO+AuLh48m X-Received: by 2002:a63:286:: with SMTP id 128mr994401pgc.216.1644967173156; Tue, 15 Feb 2022 15:19:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644967173; cv=none; d=google.com; s=arc-20160816; b=L+Q0apoyVhNvTrRPJ4ckOvV38APP0xsjkUfpfZ4/8UMHaQoIHQwE0xVPm1ABWN9AGK D6E+1F5mgthFNF8Bu8hxDjR3mal7ToERq0J6KO6piMc2VfI4Axs6cUTEVW2tHx3H97VG m7DCV7ftiyEgS5Q9czjwthtpaVhj1kqnYMwLgniDusJYLF+TYo5nr0DUQM260yB+8r// sRA6f5L10a2d2p72mSMEqzInpuvfKqC2JbFdrFwFsHb7A0ECv89kyVzpNL10aZ5Zi3Wb 24Jas/WDLYAIFy4DJxA3JVtm85W+9xYYvjxab8Z9lDoeTrBIIErl6lNcePYtXxm5kA/w A89A== 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=QhrnAiyxU3JjUkNKNvrr88MMa0er7SfWV9USVS9Zgrs=; b=t14UpQSLwtBiBRv8SDvf2VHwL4L7JFtKHfU2aa/ekAG+EqEkHqKzv+NKgQkxEh3ljq wmNEHBdjhlIaTHSIw6EVVxG7rRZOdSZfjkqjc3Km3kJZD1w5GSzMUw69F4ZiSNPmXywM zEHjbbIQnEY5EJXH1S9qcoGBdKWBsEqSIjlXdB+p+U39uQBgWwF+glIrhn4RlLUUT/Vb SL/8OIDRxdRxrjsbh1ID/RI5088q0mG0LrK7sqIjW/ZE0vIYxyO7KDc53ncMngJwJgi7 4J3/4ytau8+vMpVsyKf52fewdLy2A3eIypGgTZCjQjZ1R1ZIbeMrjttEAfl75Uj4Pe7l XjOA== 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 r13si15199675pjp.79.2022.02.15.15.19.17; Tue, 15 Feb 2022 15:19:32 -0800 (PST) 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 S241928AbiBOQxC (ORCPT + 99 others); Tue, 15 Feb 2022 11:53:02 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241897AbiBOQwq (ORCPT ); Tue, 15 Feb 2022 11:52:46 -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 6A6B19E565 for ; Tue, 15 Feb 2022 08:52:33 -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 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 --- 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); -- 2.25.1