Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1083485pxb; Tue, 29 Mar 2022 16:49:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8T/w4gTH/xgcYpUFX2xWzpCo5o2pqq0OwmlPBDc8PkYDZFmcXFOaTyzCLg6B1owf1WHJg X-Received: by 2002:a17:902:f792:b0:153:1566:18 with SMTP id q18-20020a170902f79200b0015315660018mr32683309pln.115.1648597757261; Tue, 29 Mar 2022 16:49:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648597757; cv=none; d=google.com; s=arc-20160816; b=y+0rw3l5zMWOfAI8AgjTrO75sUt7WLofbCJqQik1x7pYrMjNGDOYYlzYz0ETHrim2z WGZ4YYbkNGHdMupVitczEV2USfiV2gmLXEMAIzZIo9HP9BoCj1/9FwV+9bPy3QpehCD9 qCi8weSGl4KAvu8B2DMF6FC/oPU7NgrCr33CXKTipvfzqWJaDteBxlsPErVrfZn35IlN +f+XLeBJ9feNhv4oSnPbsa9fBZPjBsgP+QynXkcds+4T4la4N7CrFq0RIMBXrmSQd2wd wrHfKCuYaGm+qTssEom+2p74m6JePCjGmTnVGRp5IlM1KRDsDJB3fKYSJ+eiNciknuIG r8Qg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=N2uL2iTnjVonVjgJItIcBn1T3SzQzmi/Fa83pTHnlu0=; b=WpFNwqCwyeIBoMI6lZZm+j9C/mCzmLQTiIinhXYTDaYoYIkpG+tFCsTatdufZSV5kc lGM1N75OonWdKOpn2E3X0sZbBsfQ4qwpiIX+YpvjGqxXW2Fa5T3nQyTa/pl9M/JYP7/s VnyYXNgsxib8tru/9oQaYXs/xnXKBeofZmcaGaCqkmfwKmJMEOLFD8irzJWC21XeDgcK vh8vhJKfIGN1FiSfG30Q2WB0NgbSzLsuzd6aEdeQbt6InCMYWpJGTXsRuFsFwzVpa2cN AipVVKUViYEiLQin3TCf6AyW1U8h+qLSISVJPCvmBQA7xs2Pj6V1xDsCN8xV2rOBsdDn Mv/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=TsA786HU; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v2-20020a634802000000b003829aca7f1asi18684167pga.637.2022.03.29.16.49.01; Tue, 29 Mar 2022 16:49:17 -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; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=TsA786HU; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237301AbiC2N3h (ORCPT + 99 others); Tue, 29 Mar 2022 09:29:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237281AbiC2N3d (ORCPT ); Tue, 29 Mar 2022 09:29:33 -0400 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 763101F9FD5 for ; Tue, 29 Mar 2022 06:27:49 -0700 (PDT) Received: (Authenticated sender: paul.kocialkowski@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 3D20F40010; Tue, 29 Mar 2022 13:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648560467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=N2uL2iTnjVonVjgJItIcBn1T3SzQzmi/Fa83pTHnlu0=; b=TsA786HUDRn7oGtJu7nkgILmG7pLT8+7dqjTuzxea0m4IyARXi0Wu2ck6r95WZkJh/eXMz 4ZNxq6K338MMiaCrTSlCEtWbyI3+VoqNDBSTmtSTBvSU/ebOFVcoGiEq9YFiV7y/yNo7X+ 47pphDSrJQ5PQPxSF/mVamOP9jNDzDORKtRLNh0jHkyL0t7TaV8Y1eHEOWv607v5pCiyTW 0K4X/ssETvMb13hyqt07pxQpka8hnTURhZrBM3nIfinkWzHjTi6EPRrC1nFKterP1CRDTl oY/qswOuMtgIp8O7vH/qAnHeNDV/W5nUF4F3elFnvdiKwbpInXUT+8Au/Igmjg== From: Paul Kocialkowski To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Linus Walleij , Jagan Teki , Thomas Petazzoni , Paul Kocialkowski Subject: [PATCH v3] drm: of: Properly try all possible cases for bridge/panel detection Date: Tue, 29 Mar 2022 15:27:32 +0200 Message-Id: <20220329132732.628474-1-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 While bridge/panel detection was initially relying on the usual port/ports-based of graph detection, it was recently changed to perform the lookup on any child node that is not port/ports instead when such a node is available, with no fallback on the usual way. This results in breaking detection when a child node is present but does not contain any panel or bridge node, even when the usual port/ports-based of graph is there. In order to support both situations properly, this commit reworks the logic to try both options and not just one of the two: it will only return -EPROBE_DEFER when both have failed. Signed-off-by: Paul Kocialkowski Fixes: 80253168dbfd ("drm: of: Lookup if child node has panel or bridge") --- Changes since v2: - Removed unnecessary else statement and added a comment about clearing the panel pointer on error. Changes since v1: - Renamed remote to node; - Renamed helper to find_panel_or_bridge; - Cleared bridge pointer early; - Returned early to make the code more concise; --- drivers/gpu/drm/drm_of.c | 99 ++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c index 9d90cd75c457..8716da6369a6 100644 --- a/drivers/gpu/drm/drm_of.c +++ b/drivers/gpu/drm/drm_of.c @@ -219,6 +219,29 @@ int drm_of_encoder_active_endpoint(struct device_node *node, } EXPORT_SYMBOL_GPL(drm_of_encoder_active_endpoint); +static int find_panel_or_bridge(struct device_node *node, + struct drm_panel **panel, + struct drm_bridge **bridge) +{ + if (panel) { + *panel = of_drm_find_panel(node); + if (!IS_ERR(*panel)) + return 0; + + /* Clear the panel pointer in case of error. */ + *panel = NULL; + } + + /* No panel found yet, check for a bridge next. */ + if (bridge) { + *bridge = of_drm_find_bridge(node); + if (*bridge) + return 0; + } + + return -EPROBE_DEFER; +} + /** * drm_of_find_panel_or_bridge - return connected panel or bridge device * @np: device tree node containing encoder output ports @@ -241,66 +264,44 @@ int drm_of_find_panel_or_bridge(const struct device_node *np, struct drm_panel **panel, struct drm_bridge **bridge) { - int ret = -EPROBE_DEFER; - struct device_node *remote; + struct device_node *node; + int ret; if (!panel && !bridge) return -EINVAL; + if (panel) *panel = NULL; - - /** - * Devices can also be child nodes when we also control that device - * through the upstream device (ie, MIPI-DCS for a MIPI-DSI device). - * - * Lookup for a child node of the given parent that isn't either port - * or ports. - */ - for_each_available_child_of_node(np, remote) { - if (of_node_name_eq(remote, "port") || - of_node_name_eq(remote, "ports")) - continue; - - goto of_find_panel_or_bridge; + if (bridge) + *bridge = NULL; + + /* Check for a graph on the device node first. */ + if (of_graph_is_present(np)) { + node = of_graph_get_remote_node(np, port, endpoint); + if (node) { + ret = find_panel_or_bridge(node, panel, bridge); + of_node_put(node); + + if (!ret) + return 0; + } } - /* - * of_graph_get_remote_node() produces a noisy error message if port - * node isn't found and the absence of the port is a legit case here, - * so at first we silently check whether graph presents in the - * device-tree node. - */ - if (!of_graph_is_present(np)) - return -ENODEV; - - remote = of_graph_get_remote_node(np, port, endpoint); - -of_find_panel_or_bridge: - if (!remote) - return -ENODEV; + /* Otherwise check for any child node other than port/ports. */ + for_each_available_child_of_node(np, node) { + if (of_node_name_eq(node, "port") || + of_node_name_eq(node, "ports")) + continue; - if (panel) { - *panel = of_drm_find_panel(remote); - if (!IS_ERR(*panel)) - ret = 0; - else - *panel = NULL; - } - - /* No panel found yet, check for a bridge next. */ - if (bridge) { - if (ret) { - *bridge = of_drm_find_bridge(remote); - if (*bridge) - ret = 0; - } else { - *bridge = NULL; - } + ret = find_panel_or_bridge(node, panel, bridge); + of_node_put(node); + /* Stop at the first found occurrence. */ + if (!ret) + return 0; } - of_node_put(remote); - return ret; + return -EPROBE_DEFER; } EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge); -- 2.35.1