From patchwork Tue Aug 14 10:26:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 10565255 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 881E01057 for ; Tue, 14 Aug 2018 10:27:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74C4C28EA5 for ; Tue, 14 Aug 2018 10:27:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 685012964E; Tue, 14 Aug 2018 10:27:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1D35228EA5 for ; Tue, 14 Aug 2018 10:27:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CA9626E060; Tue, 14 Aug 2018 10:27:06 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E8D76E060 for ; Tue, 14 Aug 2018 10:27:05 +0000 (UTC) Received: from wd0180.dip.tu-dresden.de ([141.76.108.180] helo=phil.dip.tu-dresden.de) by gloria.sntech.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1fpWXW-0006yF-4Y; Tue, 14 Aug 2018 12:27:02 +0200 From: Heiko Stuebner To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 6/8] drm/dsi: add helper function to find the second host in a dual-dsi setup Date: Tue, 14 Aug 2018 12:26:52 +0200 Message-Id: <20180814102654.29113-7-heiko@sntech.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180814102654.29113-1-heiko@sntech.de> References: <20180814102654.29113-1-heiko@sntech.de> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, briannorris@chromium.org, hoegsberg@gmail.com, philippe.cornu@st.com, yannick.fertre@st.com, linux-rockchip@lists.infradead.org, nickey.yang@rock-chips.com, robh+dt@kernel.org, thierry.reding@gmail.com, laurent.pinchart@ideasonboard.com, mka@chromium.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From a specified output port of one dsi controller this function allows to iterate over the list of registered dsi controllers trying to find a second instance connected to the same display, like it is used in dual-dsi setups. Signed-off-by: Heiko Stuebner --- drivers/gpu/drm/drm_mipi_dsi.c | 56 ++++++++++++++++++++++++++++++++++ include/drm/drm_mipi_dsi.h | 2 ++ 2 files changed, 58 insertions(+) diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c index bc73b7f5b9fc..0c3c9c7aa3b8 100644 --- a/drivers/gpu/drm/drm_mipi_dsi.c +++ b/drivers/gpu/drm/drm_mipi_dsi.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -282,6 +283,61 @@ struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node) } EXPORT_SYMBOL(of_find_mipi_dsi_host_by_node); +struct device_node *of_mipi_dsi_find_second_host(struct device_node *first_np, + int port, int endpoint) +{ + struct mipi_dsi_host *first, *host; + struct device_node *remote, *np, *second_np = NULL; + int num = 0; + + first = of_find_mipi_dsi_host_by_node(first_np); + if (!first) { + pr_err("no dsi-host for node %s\n", first_np->full_name); + return ERR_PTR(-ENODEV); + } + + /* output-node of the known dsi-host */ + remote = of_graph_get_remote_node(first_np, port, endpoint); + if (!remote) { + dev_err(first->dev, "no output node found\n"); + return ERR_PTR(-ENODEV); + } + + mutex_lock(&host_lock); + + list_for_each_entry(host, &host_list, list) { + np = of_graph_get_remote_node(host->dev->of_node, + port, endpoint); + + /* found a host connected to this panel */ + if (np == remote) + num++; + + /* found one second host */ + if (host->dev->of_node != first_np) + second_np = host->dev->of_node; + + of_node_put(np); + } + + /* of_node_get the node under host_lock */ + if (num == 2) + of_node_get(second_np); + + mutex_unlock(&host_lock); + + of_node_put(remote); + + if (num > 2) { + dev_err(first->dev, + "too many DSI links for output: %d links\n", num); + return ERR_PTR(-EINVAL); + } + + return second_np; +} +EXPORT_SYMBOL(of_mipi_dsi_find_second_host); + int mipi_dsi_host_register(struct mipi_dsi_host *host) { struct device_node *node; diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h index 4fef19064b0f..89532ae69c91 100644 --- a/include/drm/drm_mipi_dsi.h +++ b/include/drm/drm_mipi_dsi.h @@ -107,6 +107,8 @@ struct mipi_dsi_host { int mipi_dsi_host_register(struct mipi_dsi_host *host); void mipi_dsi_host_unregister(struct mipi_dsi_host *host); struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node); +struct device_node *of_mipi_dsi_find_second_host(struct device_node *first_np, + int port, int endpoint); /* DSI mode flags */