From patchwork Fri Dec 17 13:51:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 12696660 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 64E46C433F5 for ; Fri, 17 Dec 2021 13:54:10 +0000 (UTC) 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=Q1eKhq2bqrV9lsdOLqCo+PHZ3P8K0YCIKd4ebTTXktk=; b=fyVtZc/WsQPgfq ctTdP1854fL0mS2hleS4ykZyWHYRGBcoFy1A+EtBvzbFnLV5v+4DrvncsETaaHoXpLoV9LMZDN0Qt kyfhcq9Iie8jdzOCo/LxXkx2nFoHzdpHoaSjBJmbpraYcMTAWPY/wmu9f3ZNHnOBAFB3AOsOkGMIM VO5DtsIbcDxKOZEQ30eRdEMwxWbirLl1jk3caALHtOmmOnFOGFSr0X8drcEpVZ96jsMGLVVpnvYR8 9KeBOX+BLAuRjtIJQgbhxsAxAiOt9PF3XbYd8mVoS33ZepmWccw6y9duq0rJgwvWS6lj92KvSXI6K C977IJh/GMT9+TM8qb8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1myDf3-00ATfz-P0; Fri, 17 Dec 2021 13:52:37 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1myDdy-00AT9r-9v for linux-arm-kernel@lists.infradead.org; Fri, 17 Dec 2021 13:51:32 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 97B1D5C00D5; Fri, 17 Dec 2021 08:51:27 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 17 Dec 2021 08:51:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=7rP08aPs+xkew nuaJ6Ep4THyh1QpRjJ5GUE1j3GW0Os=; b=Ucopgy+oR+slJ3z7TBPhcOuK1RM1t iM7qU/m8XOqQA1u+Rr9qj+LV619LrYKBDPcHizSNbdGLstvgyfsHzAP6p6lnE75o s5LyYNZMeR7WGRoO4kE6AAmS5OTIwK1KctLWpg8aEEvVKskzdjnYcjfLhEZw3H5I 1dX1DBfIG5F19Xjqlhuib9KBmpyH66QmO/q6q48pXyWzUGFcoaSq/Gz8rkd/s8XC pJG+QsjifbqQNBw3ltbX4wk+a0MuauPGmXprq4zW3CJQ5kV72HPVlUC2jnBev11x XpT2+NDfDjDPC9RNZOkINZ5GStmCrvpEJR0cAXor2DZYZiqZMnvYI6fmw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=7rP08aPs+xkewnuaJ6Ep4THyh1QpRjJ5GUE1j3GW0Os=; b=bgEwdLoF ox51bq0tsX8ATQqKz0rsOKzJzvOgWY+ih+Hq5g8hVJ3tVKfIc0xAN1Gr4zWJ1rzp gsixarMvMzV8UpERiNN6QJDhONqfZK2qnq44CDkdqqZ65Pt6NUA7PVL/+8FwEWvh Xk+rX/y+3AwTfeeIrzWdbDZp3bx0Og2ULq9TTX2/PqyPcxLTQ+QD2TkvxamciHgs 1TLvUwezSVed+viOH1gDQ10JJekyuCmr4Lw2y5MSgUvPB+gqrUNAVxKKthLERW/+ HzEmDc1bvxMt0EB+rHGbNRPEiifo/3oZ87c5/DZZ5/BTCL5i9NmQ3cELgCIm7IIw JtoJOceSN0dZPQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrleeigdehkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrgihimhgv ucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtffrrghtth gvrhhnpedvkeelveefffekjefhffeuleetleefudeifeehuddugffghffhffehveevheeh vdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrg igihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 Dec 2021 08:51:26 -0500 (EST) From: Maxime Ripard To: Daniel Vetter , David Airlie , Rob Herring , Frank Rowand , Laurent Pinchart , Chen-Yu Tsai , Maxime Ripard , =?utf-8?q?Jernej_=C5=A0krabec?= Cc: linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org Subject: [PATCH v6 2/7] drm/of: Change the prototype of drm_of_lvds_get_dual_link_pixel_order Date: Fri, 17 Dec 2021 14:51:14 +0100 Message-Id: <20211217135119.316781-3-maxime@cerno.tech> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211217135119.316781-1-maxime@cerno.tech> References: <20211217135119.316781-1-maxime@cerno.tech> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211217_055130_578959_40DC3DA2 X-CRM114-Status: GOOD ( 25.31 ) 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 The drm_of_lvds_get_dual_link_pixel_order() function took so far the device_node of the two ports used together to make up a dual-link LVDS output. This assumes that a binding would use an entire port for the LVDS output. However, some bindings have used endpoints instead and thus we need to operate at the endpoint level. Change slightly the arguments to allow that. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/bridge/ti-sn65dsi83.c | 9 +- drivers/gpu/drm/drm_of.c | 138 ++++++++++++++++++++------ drivers/gpu/drm/rcar-du/rcar_lvds.c | 8 +- include/drm/drm_of.h | 16 ++- 4 files changed, 123 insertions(+), 48 deletions(-) diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi83.c b/drivers/gpu/drm/bridge/ti-sn65dsi83.c index 945f08de45f1..763be3a43565 100644 --- a/drivers/gpu/drm/bridge/ti-sn65dsi83.c +++ b/drivers/gpu/drm/bridge/ti-sn65dsi83.c @@ -568,15 +568,10 @@ static int sn65dsi83_parse_dt(struct sn65dsi83 *ctx, enum sn65dsi83_model model) ctx->lvds_dual_link = false; ctx->lvds_dual_link_even_odd_swap = false; if (model != MODEL_SN65DSI83) { - struct device_node *port2, *port3; int dual_link; - port2 = of_graph_get_port_by_id(dev->of_node, 2); - port3 = of_graph_get_port_by_id(dev->of_node, 3); - dual_link = drm_of_lvds_get_dual_link_pixel_order(port2, port3); - of_node_put(port2); - of_node_put(port3); - + dual_link = drm_of_lvds_get_dual_link_pixel_order(dev->of_node, 2, -1, + dev->of_node, 3, -1); if (dual_link == DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS) { ctx->lvds_dual_link = true; /* Odd pixels to LVDS Channel A, even pixels to B */ diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c index 59d368ea006b..0759fff201ef 100644 --- a/drivers/gpu/drm/drm_of.c +++ b/drivers/gpu/drm/drm_of.c @@ -303,13 +303,35 @@ static int drm_of_lvds_get_port_pixels_type(struct device_node *port_node) (odd_pixels ? DRM_OF_LVDS_ODD : 0); } -static int drm_of_lvds_get_remote_pixels_type( - const struct device_node *port_node) +static int drm_of_lvds_get_remote_pixels_type(const struct device_node *endpoint) { - struct device_node *endpoint = NULL; - int pixels_type = -EPIPE; + struct device_node *remote_port; + int pixels_type; - for_each_child_of_node(port_node, endpoint) { + remote_port = of_graph_get_remote_port(endpoint); + if (!remote_port) + return -EPIPE; + + pixels_type = drm_of_lvds_get_port_pixels_type(remote_port); + of_node_put(remote_port); + + if (pixels_type < 0) + return -EPIPE; + + return pixels_type; +} + +static int drm_of_lvds_check_remote_port(const struct device_node *dev, int id) +{ + struct device_node *endpoint; + struct device_node *port; + int previous_pt = -EPIPE; + + port = of_graph_get_port_by_id(dev, id); + if (!port) + return -EINVAL; + + for_each_child_of_node(port, endpoint) { struct device_node *remote_port; int current_pt; @@ -318,14 +340,19 @@ static int drm_of_lvds_get_remote_pixels_type( remote_port = of_graph_get_remote_port(endpoint); if (!remote_port) { - of_node_put(endpoint); + of_node_put(port); return -EPIPE; } current_pt = drm_of_lvds_get_port_pixels_type(remote_port); of_node_put(remote_port); - if (pixels_type < 0) - pixels_type = current_pt; + if (!current_pt) { + of_node_put(port); + return -EINVAL; + } + + if (previous_pt < 0) + previous_pt = current_pt; /* * Sanity check, ensure that all remote endpoints have the same @@ -334,19 +361,26 @@ static int drm_of_lvds_get_remote_pixels_type( * configurations by passing the endpoints explicitly to * drm_of_lvds_get_dual_link_pixel_order(). */ - if (!current_pt || pixels_type != current_pt) { - of_node_put(endpoint); + if (previous_pt != current_pt) { + of_node_put(port); return -EINVAL; } + + previous_pt = current_pt; } - return pixels_type; + of_node_put(port); + return previous_pt < 0 ? previous_pt : 0; } /** * drm_of_lvds_get_dual_link_pixel_order - Get LVDS dual-link pixel order - * @port1: First DT port node of the Dual-link LVDS source - * @port2: Second DT port node of the Dual-link LVDS source + * @dev1: First DT device node of the Dual-Link LVDS source + * @port1_id: ID of the first DT port node of the Dual-Link LVDS source + * @endpoint1_id: ID of the first DT port node of the Dual-Link LVDS source + * @dev2: Second DT device node of the Dual-Link LVDS source + * @port2_id: ID of the second DT port node of the Dual-Link LVDS source + * @endpoint2_id: ID of the second DT port node of the Dual-Link LVDS source * * An LVDS dual-link connection is made of two links, with even pixels * transitting on one link, and odd pixels on the other link. This function @@ -360,43 +394,85 @@ static int drm_of_lvds_get_remote_pixels_type( * * If either port is not connected, this function returns -EPIPE. * - * @port1 and @port2 are typically DT sibling nodes, but may have different - * parents when, for instance, two separate LVDS encoders carry the even and odd - * pixels. + * @port1_id and @port2_id are typically DT sibling nodes, but may have + * different parents when, for instance, two separate LVDS encoders carry the + * even and odd pixels. + * + * If @port1_id, @port2_id, @endpoint1_id or @endpoint2_id are set to -1, their + * value is going to be ignored and the first port or endpoint will be used. * * Return: - * * DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS - @port1 carries even pixels and @port2 - * carries odd pixels - * * DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS - @port1 carries odd pixels and @port2 - * carries even pixels - * * -EINVAL - @port1 and @port2 are not connected to a dual-link LVDS sink, or - * the sink configuration is invalid - * * -EPIPE - when @port1 or @port2 are not connected + * * DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS - @endpoint1_id carries even pixels and + * @endpoint2_id carries odd pixels + * * DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS - @endpoint1_id carries odd pixels and + * @endpoint2_id carries even pixels + * * -EINVAL - @endpoint1_id and @endpoint2_id are not connected to a dual-link + * LVDS sink, or the sink configuration is invalid + * * -EPIPE - when @endpoint1_id or @endpoint2_id are not connected */ -int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, - const struct device_node *port2) +int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1, + int port1_id, + int endpoint1_id, + const struct device_node *dev2, + int port2_id, + int endpoint2_id) { + struct device_node *endpoint1, *endpoint2; int remote_p1_pt, remote_p2_pt; + int ret; - if (!port1 || !port2) + if (!dev1 || !dev2) return -EINVAL; - remote_p1_pt = drm_of_lvds_get_remote_pixels_type(port1); - if (remote_p1_pt < 0) + if (endpoint1_id == -1) { + ret = drm_of_lvds_check_remote_port(dev1, port1_id); + if (ret) + return ret; + } + + if (endpoint2_id == -1) { + ret = drm_of_lvds_check_remote_port(dev2, port2_id); + if (ret) + return ret; + } + + endpoint1 = of_graph_get_endpoint_by_regs(dev1, port1_id, endpoint1_id); + if (!endpoint1) + return -EINVAL; + + endpoint2 = of_graph_get_endpoint_by_regs(dev2, port2_id, endpoint2_id); + if (!endpoint2) { + of_node_put(endpoint1); + return -EINVAL; + } + + remote_p1_pt = drm_of_lvds_get_remote_pixels_type(endpoint1); + if (remote_p1_pt < 0) { + of_node_put(endpoint2); + of_node_put(endpoint1); return remote_p1_pt; + } - remote_p2_pt = drm_of_lvds_get_remote_pixels_type(port2); - if (remote_p2_pt < 0) + remote_p2_pt = drm_of_lvds_get_remote_pixels_type(endpoint2); + if (remote_p2_pt < 0) { + of_node_put(endpoint2); + of_node_put(endpoint1); return remote_p2_pt; + } /* * A valid dual-lVDS bus is found when one remote port is marked with * "dual-lvds-even-pixels", and the other remote port is marked with * "dual-lvds-odd-pixels", bail out if the markers are not right. */ - if (remote_p1_pt + remote_p2_pt != DRM_OF_LVDS_EVEN + DRM_OF_LVDS_ODD) + if (remote_p1_pt + remote_p2_pt != DRM_OF_LVDS_EVEN + DRM_OF_LVDS_ODD) { + of_node_put(endpoint2); + of_node_put(endpoint1); return -EINVAL; + } + of_node_put(endpoint2); + of_node_put(endpoint1); return remote_p1_pt == DRM_OF_LVDS_EVEN ? DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS : DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS; diff --git a/drivers/gpu/drm/rcar-du/rcar_lvds.c b/drivers/gpu/drm/rcar-du/rcar_lvds.c index 72a272cfc11e..09a43c2bb0ad 100644 --- a/drivers/gpu/drm/rcar-du/rcar_lvds.c +++ b/drivers/gpu/drm/rcar-du/rcar_lvds.c @@ -617,7 +617,6 @@ static int rcar_lvds_parse_dt_companion(struct rcar_lvds *lvds) { const struct of_device_id *match; struct device_node *companion; - struct device_node *port0, *port1; struct rcar_lvds *companion_lvds; struct device *dev = lvds->dev; int dual_link; @@ -645,11 +644,8 @@ static int rcar_lvds_parse_dt_companion(struct rcar_lvds *lvds) * connected to, if they are marked as expecting even pixels and * odd pixels than we need to enable vertical stripe output. */ - port0 = of_graph_get_port_by_id(dev->of_node, 1); - port1 = of_graph_get_port_by_id(companion, 1); - dual_link = drm_of_lvds_get_dual_link_pixel_order(port0, port1); - of_node_put(port0); - of_node_put(port1); + dual_link = drm_of_lvds_get_dual_link_pixel_order(dev->of_node, 1, -1, + companion, 1, -1); switch (dual_link) { case DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS: diff --git a/include/drm/drm_of.h b/include/drm/drm_of.h index 99f79ac8b4cd..fb0213085db3 100644 --- a/include/drm/drm_of.h +++ b/include/drm/drm_of.h @@ -47,8 +47,12 @@ int drm_of_find_panel_or_bridge(const struct device_node *np, int port, int endpoint, struct drm_panel **panel, struct drm_bridge **bridge); -int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, - const struct device_node *port2); +int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1, + int port1_id, + int endpoint1_id, + const struct device_node *dev2, + int port2_id, + int endpoint2_id); int drm_of_lvds_get_data_mapping(const struct device_node *port); #else static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev, @@ -94,8 +98,12 @@ static inline int drm_of_find_panel_or_bridge(const struct device_node *np, } static inline int -drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, - const struct device_node *port2) +drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1, + int port1_id, + int endpoint1_id, + const struct device_node *dev2, + int port2_id, + int endpoint2_id) { return -EINVAL; }