From patchwork Mon Mar 11 08:56:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13588384 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 B925EC5475B for ; Mon, 11 Mar 2024 08:58:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0262E1121A3; Mon, 11 Mar 2024 08:58:18 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="mDOFhb/y"; dkim-atps=neutral Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4E6C010FD11 for ; Mon, 11 Mar 2024 08:58:17 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710147495; 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: in-reply-to:in-reply-to:references:references; bh=ACbuVzqDGeY5B8aCLo+ycEpWur4XOQkFda8KsYe8re8=; b=mDOFhb/yw0YS3Ov2WeSr5X2tbx1OeqfTi2ChwZG6hVJkDe1Y6dHnlkgV2jMsRtt9eYSzEJ WOV922L0kD/7C4rj7Tpbmpjd6CiPFXdE1uPdyMGyLM923hkkK/oPTYVDP7lxdsYjMjSxfq +WPpEThoM1RvRsfRKpYmecZHLPZfJmk= From: Sui Jingfeng To: Andrzej Hajda Cc: Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Phong LE , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [PATCH v3 1/5] drm/bridge: Allow using fwnode API to get the next bridge Date: Mon, 11 Mar 2024 16:56:55 +0800 Message-Id: <20240311085659.244043-2-sui.jingfeng@linux.dev> In-Reply-To: <20240311085659.244043-1-sui.jingfeng@linux.dev> References: <20240311085659.244043-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently, the various drm bridge drivers relay on OF infrastructures to works very well. Yet there are platforms and/or devices absence of OF support. Such as virtual display drivers, USB display apapters and ACPI based systems etc. Add fwnode based helpers to fill the niche, this allows part of the drm display bridge drivers to work across systems. As the fwnode based API has wider coverage than DT and the fwnode graphs are compatible with the OF graph, so the provided helpers can be used on all systems in theory. Assumed that the system has valid fwnode graphs established before the drm bridge driver is probed, and there is a fwnode assigned to the instance of specific drm bridge driver. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/drm_bridge.c | 72 ++++++++++++++++++++++++++++++++++++ include/drm/drm_bridge.h | 16 ++++++++ 2 files changed, 88 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index 28abe9aa99ca..ffc6162e2517 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -1368,6 +1368,78 @@ struct drm_bridge *of_drm_find_bridge(struct device_node *np) EXPORT_SYMBOL(of_drm_find_bridge); #endif +/** + * drm_bridge_find_by_fwnode - Find the bridge corresponding to the fwnode + * + * @fwnode: fwnode for which to find the matching drm_bridge + * + * This function looks up a drm_bridge in the global bridge list, based on + * its associated fwnode. Drivers who want to use this function should has + * fwnode handle assigned to the fwnode member of the struct drm_bridge + * instance. + * + * Return: + * A reference to the drm_bridge if found, return NULL otherwise. + */ +struct drm_bridge *drm_bridge_find_by_fwnode(struct fwnode_handle *fwnode) +{ + struct drm_bridge *ret = NULL; + struct drm_bridge *bridge; + + if (!fwnode) + return NULL; + + mutex_lock(&bridge_lock); + + list_for_each_entry(bridge, &bridge_list, list) { + if (bridge->fwnode == fwnode) { + ret = bridge; + break; + } + } + + mutex_unlock(&bridge_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(drm_bridge_find_by_fwnode); + +/** + * drm_bridge_find_next_bridge_by_fwnode - Find the next bridge by fwnode + * @fwnode: fwnode pointer to the current device. + * @port: identifier of the port node of the next bridge is connected. + * + * This function find the next bridge at the current node, it assumed that + * that there has valid fwnode graph established. + * + * Return: + * A reference to the drm_bridge if found. + * %NULL if not found or the next bridge is not finish probe yet. + * A negative error code otherwise. + */ +struct drm_bridge * +drm_bridge_find_next_bridge_by_fwnode(struct fwnode_handle *fwnode, u32 port) +{ + struct drm_bridge *bridge; + struct fwnode_handle *ep; + struct fwnode_handle *remote; + + ep = fwnode_graph_get_endpoint_by_id(fwnode, port, 0, 0); + if (!ep) + return ERR_PTR(-EINVAL); + + remote = fwnode_graph_get_remote_port_parent(ep); + fwnode_handle_put(ep); + if (!remote) + return ERR_PTR(-ENODEV); + + bridge = drm_bridge_find_by_fwnode(remote); + fwnode_handle_put(remote); + + return bridge; +} +EXPORT_SYMBOL_GPL(drm_bridge_find_next_bridge_by_fwnode); + MODULE_AUTHOR("Ajay Kumar "); MODULE_DESCRIPTION("DRM bridge infrastructure"); MODULE_LICENSE("GPL and additional rights"); diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index 3606e1a7f965..d4c95afdd662 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -721,6 +722,8 @@ struct drm_bridge { struct list_head chain_node; /** @of_node: device node pointer to the bridge */ struct device_node *of_node; + /** @fwnode: fwnode pointer to the bridge */ + struct fwnode_handle *fwnode; /** @list: to keep track of all added bridges */ struct list_head list; /** @@ -788,6 +791,13 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, struct drm_bridge *previous, enum drm_bridge_attach_flags flags); +static inline void +drm_bridge_set_node(struct drm_bridge *bridge, struct fwnode_handle *fwnode) +{ + bridge->fwnode = fwnode; + bridge->of_node = to_of_node(fwnode); +} + #ifdef CONFIG_OF struct drm_bridge *of_drm_find_bridge(struct device_node *np); #else @@ -797,6 +807,12 @@ static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np) } #endif +struct drm_bridge * +drm_bridge_find_by_fwnode(struct fwnode_handle *fwnode); + +struct drm_bridge * +drm_bridge_find_next_bridge_by_fwnode(struct fwnode_handle *fwnode, u32 port); + /** * drm_bridge_get_next_bridge() - Get the next bridge in the chain * @bridge: bridge object From patchwork Mon Mar 11 08:56:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13588385 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 EACBBC54E58 for ; Mon, 11 Mar 2024 08:58:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 119F310FD11; Mon, 11 Mar 2024 08:58:26 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="Ywxh3D3S"; dkim-atps=neutral Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0BE1D10FD11 for ; Mon, 11 Mar 2024 08:58:24 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710147503; 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: in-reply-to:in-reply-to:references:references; bh=AdzVq0hSo8fS18z5xoeY8+4STJ0X8hxCUiiSMI/5/9M=; b=Ywxh3D3SbrIHx8AEv7gkKxSf5+SpuEuijnz6eh4LyUC/DpETfJQ2PqNRZK5hpW4G+2gp2d cMpUqMBV16jezAgqshRIwG7EJiTvGdCgMlwVkKHQZgzxitnpjeaJYKXhsByZCQJg8ODzsf niiBVJt6/TS1cdn8urUBCRGpIq2Ng6Q= From: Sui Jingfeng To: Andrzej Hajda Cc: Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Phong LE , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [PATCH v3 2/5] drm/bridge: simple-bridge: Use fwnode API to acquire device properties Date: Mon, 11 Mar 2024 16:56:56 +0800 Message-Id: <20240311085659.244043-3-sui.jingfeng@linux.dev> In-Reply-To: <20240311085659.244043-1-sui.jingfeng@linux.dev> References: <20240311085659.244043-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Make this driver less DT-dependent by calling the freshly created helpers, should be no functional changes for DT based systems. But open the door for otherwise use cases. Even though there is no user emerged yet, this still do no harms. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/bridge/simple-bridge.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/bridge/simple-bridge.c b/drivers/gpu/drm/bridge/simple-bridge.c index 5813a2c4fc5e..3b09bdd5ad4d 100644 --- a/drivers/gpu/drm/bridge/simple-bridge.c +++ b/drivers/gpu/drm/bridge/simple-bridge.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -169,33 +168,32 @@ static const struct drm_bridge_funcs simple_bridge_bridge_funcs = { static int simple_bridge_probe(struct platform_device *pdev) { + struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev); struct simple_bridge *sbridge; - struct device_node *remote; + int ret; sbridge = devm_kzalloc(&pdev->dev, sizeof(*sbridge), GFP_KERNEL); if (!sbridge) return -ENOMEM; platform_set_drvdata(pdev, sbridge); - sbridge->info = of_device_get_match_data(&pdev->dev); + sbridge->info = device_get_match_data(&pdev->dev); /* Get the next bridge in the pipeline. */ - remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1); - if (!remote) - return -EINVAL; - - sbridge->next_bridge = of_drm_find_bridge(remote); - of_node_put(remote); - + sbridge->next_bridge = drm_bridge_find_next_bridge_by_fwnode(fwnode, 1); if (!sbridge->next_bridge) { dev_dbg(&pdev->dev, "Next bridge not found, deferring probe\n"); return -EPROBE_DEFER; + } else if (IS_ERR(sbridge->next_bridge)) { + ret = PTR_ERR(sbridge->next_bridge); + dev_err(&pdev->dev, "Error on finding the next bridge: %d\n", ret); + return ret; } /* Get the regulator and GPIO resources. */ sbridge->vdd = devm_regulator_get_optional(&pdev->dev, "vdd"); if (IS_ERR(sbridge->vdd)) { - int ret = PTR_ERR(sbridge->vdd); + ret = PTR_ERR(sbridge->vdd); if (ret == -EPROBE_DEFER) return -EPROBE_DEFER; sbridge->vdd = NULL; @@ -210,9 +208,9 @@ static int simple_bridge_probe(struct platform_device *pdev) /* Register the bridge. */ sbridge->bridge.funcs = &simple_bridge_bridge_funcs; - sbridge->bridge.of_node = pdev->dev.of_node; sbridge->bridge.timings = sbridge->info->timings; + drm_bridge_set_node(&sbridge->bridge, fwnode); drm_bridge_add(&sbridge->bridge); return 0; From patchwork Mon Mar 11 08:56:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13588386 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 EB250C54E58 for ; Mon, 11 Mar 2024 08:58:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 00EAC1121F3; Mon, 11 Mar 2024 08:58:31 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="o7SpAZM2"; dkim-atps=neutral Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) by gabe.freedesktop.org (Postfix) with ESMTPS id B8A371126BA for ; Mon, 11 Mar 2024 08:58:29 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710147507; 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: in-reply-to:in-reply-to:references:references; bh=Aep+0Bx5dDl+omojFo37hiW07MeWApSc10wBdc6QHoM=; b=o7SpAZM20vIWA1feEu6Qmid7aZHNi34FMD0eBo819WVjEfZDH/7z2Ki4n50utYq2lw4Bw4 JV0JLLp48M/TehOzS2WavoDaWfiba0/hR8DhKnL/D4fBdHWbr3sggprk2UWWBapGe1UanY 6moYpT4qpUqeOh6JOqSTAh//Ko7PJSk= From: Sui Jingfeng To: Andrzej Hajda Cc: Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Phong LE , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [PATCH v3 3/5] drm-bridge: display-connector: Use fwnode API to acquire device properties Date: Mon, 11 Mar 2024 16:56:57 +0800 Message-Id: <20240311085659.244043-4-sui.jingfeng@linux.dev> In-Reply-To: <20240311085659.244043-1-sui.jingfeng@linux.dev> References: <20240311085659.244043-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Make this driver less DT-dependent by using the fwnode helper function, should be no functional changes for DT based systems. Do the necessary works before it can be truely subsystem independent, even though there is no user yet, this still do no harms. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/bridge/display-connector.c | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/bridge/display-connector.c b/drivers/gpu/drm/bridge/display-connector.c index ab8e00baf3f1..d80cb7bc59e6 100644 --- a/drivers/gpu/drm/bridge/display-connector.c +++ b/drivers/gpu/drm/bridge/display-connector.c @@ -204,6 +204,7 @@ static int display_connector_get_supply(struct platform_device *pdev, static int display_connector_probe(struct platform_device *pdev) { + struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev); struct display_connector *conn; unsigned int type; const char *label = NULL; @@ -215,15 +216,15 @@ static int display_connector_probe(struct platform_device *pdev) platform_set_drvdata(pdev, conn); - type = (uintptr_t)of_device_get_match_data(&pdev->dev); + type = (uintptr_t)device_get_match_data(&pdev->dev); /* Get the exact connector type. */ switch (type) { case DRM_MODE_CONNECTOR_DVII: { bool analog, digital; - analog = of_property_read_bool(pdev->dev.of_node, "analog"); - digital = of_property_read_bool(pdev->dev.of_node, "digital"); + analog = fwnode_property_present(fwnode, "analog"); + digital = fwnode_property_present(fwnode, "digital"); if (analog && !digital) { conn->bridge.type = DRM_MODE_CONNECTOR_DVIA; } else if (!analog && digital) { @@ -240,8 +241,7 @@ static int display_connector_probe(struct platform_device *pdev) case DRM_MODE_CONNECTOR_HDMIA: { const char *hdmi_type; - ret = of_property_read_string(pdev->dev.of_node, "type", - &hdmi_type); + ret = fwnode_property_read_string(fwnode, "type", &hdmi_type); if (ret < 0) { dev_err(&pdev->dev, "HDMI connector with no type\n"); return -EINVAL; @@ -271,7 +271,7 @@ static int display_connector_probe(struct platform_device *pdev) conn->bridge.interlace_allowed = true; /* Get the optional connector label. */ - of_property_read_string(pdev->dev.of_node, "label", &label); + fwnode_property_read_string(fwnode, "label", &label); /* * Get the HPD GPIO for DVI, HDMI and DP connectors. If the GPIO can provide @@ -309,12 +309,12 @@ static int display_connector_probe(struct platform_device *pdev) if (type == DRM_MODE_CONNECTOR_DVII || type == DRM_MODE_CONNECTOR_HDMIA || type == DRM_MODE_CONNECTOR_VGA) { - struct device_node *phandle; + struct fwnode_handle *phandle; - phandle = of_parse_phandle(pdev->dev.of_node, "ddc-i2c-bus", 0); - if (phandle) { - conn->bridge.ddc = of_get_i2c_adapter_by_node(phandle); - of_node_put(phandle); + phandle = fwnode_find_reference(fwnode, "ddc-i2c-bus", 0); + if (!IS_ERR_OR_NULL(phandle)) { + conn->bridge.ddc = i2c_get_adapter_by_fwnode(phandle); + fwnode_handle_put(phandle); if (!conn->bridge.ddc) return -EPROBE_DEFER; } else { @@ -358,7 +358,7 @@ static int display_connector_probe(struct platform_device *pdev) } conn->bridge.funcs = &display_connector_bridge_funcs; - conn->bridge.of_node = pdev->dev.of_node; + drm_bridge_set_node(&conn->bridge, fwnode); if (conn->bridge.ddc) conn->bridge.ops |= DRM_BRIDGE_OP_EDID From patchwork Mon Mar 11 08:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13588387 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 8E5F8C54E58 for ; Mon, 11 Mar 2024 08:58:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E1154112282; Mon, 11 Mar 2024 08:58:38 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="Q1a9WOJM"; dkim-atps=neutral Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) by gabe.freedesktop.org (Postfix) with ESMTPS id 16D46112282 for ; Mon, 11 Mar 2024 08:58:38 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710147516; 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: in-reply-to:in-reply-to:references:references; bh=qpFxJ3SaUbuEjaQuODo+eOlkZ4g0ImTCeEIwDGa1hhA=; b=Q1a9WOJMkc6IbEnTNssVw0C/c+fyjJxbDseLI6wW8C0ScFVC3LHPQL2pRsybyFCO6kZuG3 mUGJoDd7l3sI18d1hohdqwH/upk833TzmPftgrcXzlvbljTiJu3tledqhM1kfpd9bVQ4pZ 4Zw9aruiMISUP9qQVBd/TUtAGUtFeXw= From: Sui Jingfeng To: Andrzej Hajda Cc: Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Phong LE , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [PATCH v3 4/5] drm-bridge: it66121: Use fwnode API to acquire device properties Date: Mon, 11 Mar 2024 16:56:58 +0800 Message-Id: <20240311085659.244043-5-sui.jingfeng@linux.dev> In-Reply-To: <20240311085659.244043-1-sui.jingfeng@linux.dev> References: <20240311085659.244043-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Make this driver less DT-dependent by calling the freshly created helpers, should be no functional changes for DT based systems. But open the door for otherwise use cases. Even though there is no user emerged yet, this still do no harms. In fact, we reduce boilerplate across drm bridge drivers. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/bridge/ite-it66121.c | 63 +++++++++++++++------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it66121.c b/drivers/gpu/drm/bridge/ite-it66121.c index 1c3433b5e366..a04d755fed4c 100644 --- a/drivers/gpu/drm/bridge/ite-it66121.c +++ b/drivers/gpu/drm/bridge/ite-it66121.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -1480,7 +1479,7 @@ static int it66121_audio_codec_init(struct it66121_ctx *ctx, struct device *dev) dev_dbg(dev, "%s\n", __func__); - if (!of_property_read_bool(dev->of_node, "#sound-dai-cells")) { + if (!fwnode_property_present(dev_fwnode(dev), "#sound-dai-cells")) { dev_info(dev, "No \"#sound-dai-cells\", no audio\n"); return 0; } @@ -1503,13 +1502,36 @@ static const char * const it66121_supplies[] = { "vcn33", "vcn18", "vrf12" }; +static int it66121_read_bus_width(struct fwnode_handle *fwnode, u32 *bus_width) +{ + struct fwnode_handle *endpoint; + u32 val; + int ret; + + endpoint = fwnode_graph_get_endpoint_by_id(fwnode, 0, 0, 0); + if (!endpoint) + return -EINVAL; + + ret = fwnode_property_read_u32(endpoint, "bus-width", &val); + fwnode_handle_put(endpoint); + if (ret) + return ret; + + if (val != 12 && val != 24) + return -EINVAL; + + *bus_width = val; + + return 0; +} + static int it66121_probe(struct i2c_client *client) { u32 revision_id, vendor_ids[2] = { 0 }, device_ids[2] = { 0 }; - struct device_node *ep; int ret; struct it66121_ctx *ctx; struct device *dev = &client->dev; + struct fwnode_handle *fwnode = dev_fwnode(dev); if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { dev_err(dev, "I2C check functionality failed.\n"); @@ -1520,35 +1542,20 @@ static int it66121_probe(struct i2c_client *client) if (!ctx) return -ENOMEM; - ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0); - if (!ep) - return -EINVAL; - ctx->dev = dev; ctx->client = client; ctx->info = i2c_get_match_data(client); - of_property_read_u32(ep, "bus-width", &ctx->bus_width); - of_node_put(ep); - - if (ctx->bus_width != 12 && ctx->bus_width != 24) - return -EINVAL; - - ep = of_graph_get_remote_node(dev->of_node, 1, -1); - if (!ep) { - dev_err(ctx->dev, "The endpoint is unconnected\n"); - return -EINVAL; - } - - if (!of_device_is_available(ep)) { - of_node_put(ep); - dev_err(ctx->dev, "The remote device is disabled\n"); - return -ENODEV; - } + ret = it66121_read_bus_width(fwnode, &ctx->bus_width); + if (ret) + return ret; - ctx->next_bridge = of_drm_find_bridge(ep); - of_node_put(ep); - if (!ctx->next_bridge) { + ctx->next_bridge = drm_bridge_find_next_bridge_by_fwnode(fwnode, 1); + if (IS_ERR(ctx->next_bridge)) { + ret = PTR_ERR(ctx->next_bridge); + dev_err(dev, "Error in founding the next bridge: %d\n", ret); + return ret; + } else if (!ctx->next_bridge) { dev_dbg(ctx->dev, "Next bridge not found, deferring probe\n"); return -EPROBE_DEFER; } @@ -1584,9 +1591,9 @@ static int it66121_probe(struct i2c_client *client) } ctx->bridge.funcs = &it66121_bridge_funcs; - ctx->bridge.of_node = dev->of_node; ctx->bridge.type = DRM_MODE_CONNECTOR_HDMIA; ctx->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID | DRM_BRIDGE_OP_HPD; + drm_bridge_set_node(&ctx->bridge, fwnode); ret = devm_request_threaded_irq(dev, client->irq, NULL, it66121_irq_threaded_handler, IRQF_ONESHOT, dev_name(dev), ctx); From patchwork Mon Mar 11 08:56:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13588388 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 E697EC5475B for ; Mon, 11 Mar 2024 08:58:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 64774112336; Mon, 11 Mar 2024 08:58:52 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="H5W5gdBz"; dkim-atps=neutral Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1C186112336 for ; Mon, 11 Mar 2024 08:58:51 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710147529; 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: in-reply-to:in-reply-to:references:references; bh=4b98mQ6/x2oKxbObSJohHOWilmFrNjMixYwuxRZhnBI=; b=H5W5gdBzclG7JRWEXS3Qd7t87sa1RvPbJpMA4lC5CaIbf4KeVaTIEaqi1lI+z7RUwzM4CH sZkJ/4Z6PWcCGgsMCrE/ePEGWLRyzO1LOMXRDVRPLU5Kog9VZyNK0pNFXY9RkE20n5myrJ haXbdXiLI0HtZ9DTuSWbQKAUrxQjkaA= From: Sui Jingfeng To: Andrzej Hajda Cc: Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Phong LE , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [PATCH v3 5/5] drm-bridge: sii902x: Use fwnode API to acquire device properties Date: Mon, 11 Mar 2024 16:56:59 +0800 Message-Id: <20240311085659.244043-6-sui.jingfeng@linux.dev> In-Reply-To: <20240311085659.244043-1-sui.jingfeng@linux.dev> References: <20240311085659.244043-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Make this driver less DT-dependent by calling the freshly created helpers and other manually improve. Should be no functional changes for DT based systems, but do helps to reduce boilerplate. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/bridge/sii902x.c | 43 +++++++++++--------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/drm/bridge/sii902x.c b/drivers/gpu/drm/bridge/sii902x.c index 8f84e98249c7..04436f318c7f 100644 --- a/drivers/gpu/drm/bridge/sii902x.c +++ b/drivers/gpu/drm/bridge/sii902x.c @@ -827,20 +827,19 @@ static int sii902x_audio_codec_init(struct sii902x *sii902x, .spdif = 0, .max_i2s_channels = 0, }; + struct fwnode_handle *fwnode = dev_fwnode(dev); u8 lanes[4]; int num_lanes, i; - if (!of_property_read_bool(dev->of_node, "#sound-dai-cells")) { + if (!fwnode_property_present(fwnode, "#sound-dai-cells")) { dev_dbg(dev, "%s: No \"#sound-dai-cells\", no audio\n", __func__); return 0; } - num_lanes = of_property_read_variable_u8_array(dev->of_node, - "sil,i2s-data-lanes", - lanes, 1, - ARRAY_SIZE(lanes)); - + num_lanes = fwnode_property_read_u8_array(fwnode, + "sil,i2s-data-lanes", + lanes, ARRAY_SIZE(lanes)); if (num_lanes == -EINVAL) { dev_dbg(dev, "%s: No \"sil,i2s-data-lanes\", use default <0>\n", @@ -1097,13 +1096,13 @@ static int sii902x_init(struct sii902x *sii902x) goto err_unreg_audio; sii902x->bridge.funcs = &sii902x_bridge_funcs; - sii902x->bridge.of_node = dev->of_node; sii902x->bridge.timings = &default_sii902x_timings; sii902x->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID; if (sii902x->i2c->irq > 0) sii902x->bridge.ops |= DRM_BRIDGE_OP_HPD; + drm_bridge_set_node(&sii902x->bridge, dev_fwnode(dev)); drm_bridge_add(&sii902x->bridge); return 0; @@ -1118,7 +1117,6 @@ static int sii902x_init(struct sii902x *sii902x) static int sii902x_probe(struct i2c_client *client) { struct device *dev = &client->dev; - struct device_node *endpoint; struct sii902x *sii902x; static const char * const supplies[] = {"iovcc", "cvcc12"}; int ret; @@ -1147,27 +1145,14 @@ static int sii902x_probe(struct i2c_client *client) return PTR_ERR(sii902x->reset_gpio); } - endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 1, -1); - if (endpoint) { - struct device_node *remote = of_graph_get_remote_port_parent(endpoint); - - of_node_put(endpoint); - if (!remote) { - dev_err(dev, "Endpoint in port@1 unconnected\n"); - return -ENODEV; - } - - if (!of_device_is_available(remote)) { - dev_err(dev, "port@1 remote device is disabled\n"); - of_node_put(remote); - return -ENODEV; - } - - sii902x->next_bridge = of_drm_find_bridge(remote); - of_node_put(remote); - if (!sii902x->next_bridge) - return dev_err_probe(dev, -EPROBE_DEFER, - "Failed to find remote bridge\n"); + sii902x->next_bridge = drm_bridge_find_next_bridge_by_fwnode(dev_fwnode(dev), 1); + if (!sii902x->next_bridge) { + return dev_err_probe(dev, -EPROBE_DEFER, + "Failed to find the next bridge\n"); + } else if (IS_ERR(sii902x->next_bridge)) { + ret = PTR_ERR(sii902x->next_bridge); + dev_err(dev, "Error on find the next bridge: %d\n", ret); + return ret; } mutex_init(&sii902x->mutex);