From patchwork Wed Oct 20 18:18:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Ravnborg X-Patchwork-Id: 12572939 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CB6EC433F5 for ; Wed, 20 Oct 2021 18:21:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DB83060F6E for ; Wed, 20 Oct 2021 18:21:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DB83060F6E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ravnborg.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nUfJkor14fsXWWWM7LX7f0mHaOs0+5uBFEjaABjLwjM=; b=vIqlTTP8ScJRGs icd3y9UfNixb/Rcb7uda05Ltfw6EpGKH32YbkUi3zcVJT3lW/mYNfQvP+WduQWFGHeI99HPkpCLM9 Pk7UUrBl9IywuzKWqKMR7zjhr3tRQsy7oqXhD+4YhC/aVxzYGtMnf5zE/jzYgKiDpYd8nSds2egiw VEHLYRlrHSppNGshFXFWdasgZZ7JPshb5ZZZw4iS/c6sRNAVsj7iQOjBEVoPPeQcYQbkgZPOdqir9 o/JYaKnHnvt18n9nJWzFR/NjI+5zFan/rkZLzdn9jvuPIug2m8seiARunTXcHra7F1Z5AOZpRCkk4 0N14ImNjZXXrfQ09r7ZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdGCH-005PVj-84; Wed, 20 Oct 2021 18:20:17 +0000 Received: from mx2.smtp.larsendata.com ([91.221.196.228]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdGBM-005P3h-RK for linux-arm-kernel@lists.infradead.org; Wed, 20 Oct 2021 18:19:23 +0000 Received: from mail01.mxhotel.dk (mail01.mxhotel.dk [91.221.196.236]) by mx2.smtp.larsendata.com (Halon) with ESMTPS id 446a2974-31d2-11ec-ac3c-0050568cd888; Wed, 20 Oct 2021 18:19:30 +0000 (UTC) Received: from saturn.localdomain (80-162-45-141-cable.dk.customer.tdc.net [80.162.45.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sam@ravnborg.org) by mail01.mxhotel.dk (Postfix) with ESMTPSA id 1D569194B68; Wed, 20 Oct 2021 20:19:17 +0200 (CEST) X-Report-Abuse-To: abuse@mxhotel.dk From: Sam Ravnborg To: dri-devel@lists.freedesktop.org Cc: Andrzej Hajda , Chun-Kuang Hu , Dafna Hirschfeld , Daniel Vetter , David Airlie , Enric Balletbo i Serra , Jernej Skrabec , Jitao Shi , Jonas Karlman , Laurent Pinchart , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Maarten Lankhorst , Matthias Brugger , Maxime Ripard , Neil Armstrong , Philip Chen , Philipp Zabel , Robert Foss , Thomas Zimmermann , Sam Ravnborg , Andrzej Hajda Subject: [PATCH v2 3/7] drm/bridge: Add drm_atomic_get_new_crtc_for_bridge() helper Date: Wed, 20 Oct 2021 20:18:57 +0200 Message-Id: <20211020181901.2114645-4-sam@ravnborg.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211020181901.2114645-1-sam@ravnborg.org> References: <20211020181901.2114645-1-sam@ravnborg.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211020_111921_256639_CA36C750 X-CRM114-Status: GOOD ( 19.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org drm_atomic_get_new_crtc_for_bridge() will be used by bridge drivers to provide easy access to the mode from the drm_bridge_funcs operations. The helper will be useful in the conversion to the atomic operations of struct drm_bridge_funcs. v2: - Renamed to drm_atomic_get_new_crtc_for_bridge (Maxime) - Use atomic_state, not bridge_State (Maxime) - Drop WARN on crtc_state as it is a valid case (Maxime) - Added small code snip to help readers - Updated description, fixed kernel-doc and exported the symbol Signed-off-by: Sam Ravnborg Suggested-by: Laurent Pinchart Cc: Laurent Pinchart Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: Andrzej Hajda Cc: Neil Armstrong Cc: Robert Foss Cc: Daniel Vetter --- drivers/gpu/drm/drm_atomic.c | 42 ++++++++++++++++++++++++++++++++++++ include/drm/drm_atomic.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index ff1416cd609a..8b107194b157 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1134,6 +1134,48 @@ drm_atomic_get_new_bridge_state(struct drm_atomic_state *state, } EXPORT_SYMBOL(drm_atomic_get_new_bridge_state); +/** + * drm_atomic_get_new_crtc_for_bridge - get new crtc_state for the bridge + * @state: state of the bridge + * @bridge: bridge object + * + * This function is often used in the &struct drm_bridge_funcs operations + * to provide easy access to the mode like this: + * + * .. code-block:: c + * + * crtc_state = drm_atomic_get_new_crtc_for_bridge(old_bridge_state->base.state, + * bridge); + * if (crtc_state) { + * mode = &crtc_state->mode; + * ... + * + * If no connector can be looked up or if no connector state is available + * then this will be logged using WARN(). + * + * Returns: + * The &struct drm_crtc_state for the given bridge/state, or NULL + * if no crtc_state could be looked up. + */ +const struct drm_crtc_state * +drm_atomic_get_new_crtc_for_bridge(struct drm_atomic_state *state, + struct drm_bridge *bridge) +{ + const struct drm_connector_state *conn_state; + struct drm_connector *connector; + + connector = drm_atomic_get_new_connector_for_encoder(state, bridge->encoder); + if (WARN_ON(!connector)) + return NULL; + + conn_state = drm_atomic_get_new_connector_state(state, connector); + if (WARN_ON(!conn_state || !conn_state->crtc)) + return NULL; + + return drm_atomic_get_new_crtc_state(state, conn_state->crtc); +} +EXPORT_SYMBOL(drm_atomic_get_new_crtc_for_bridge); + /** * drm_atomic_add_encoder_bridges - add bridges attached to an encoder * @state: atomic state diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h index 1701c2128a5c..f861d73296cc 100644 --- a/include/drm/drm_atomic.h +++ b/include/drm/drm_atomic.h @@ -1119,5 +1119,8 @@ drm_atomic_get_old_bridge_state(struct drm_atomic_state *state, struct drm_bridge_state * drm_atomic_get_new_bridge_state(struct drm_atomic_state *state, struct drm_bridge *bridge); +const struct drm_crtc_state * +drm_atomic_get_new_crtc_for_bridge(struct drm_atomic_state *state, + struct drm_bridge *bridge); #endif /* DRM_ATOMIC_H_ */