From patchwork Wed Dec 14 12:58:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 2552 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id F2A633F0FB for ; Wed, 14 Dec 2022 13:59:39 +0100 (CET) Received: by mail-pg1-f198.google.com with SMTP id 7-20020a631547000000b00478959ba320sf1770105pgv.19 for ; Wed, 14 Dec 2022 04:59:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1671022778; cv=pass; d=google.com; s=arc-20160816; b=eS9GJ1v38o/krz2M5WeH0WupMYSlNLLJyRDRJyWR5E5qiaTAJHT6+NXwCWjUpMiOip BJbNfWjAiWb5FYZ7N7etZa5cTdWN7IQR4LUV1KdpSsp8Dz3bVbiUJruZeIE2227VFw6/ ib2taba3NWTNjfPmNl2eDShSO64qBxpQS0nI9w3F3Mixu4A5o9DaWXO7byvAp/4UVVzz KFd/V7iZgo26QrAhNgbtMVMCfR1Yr15d5mpoqgejkMsKPv97x0NpByDb7alJDe7XORch fAWl59rebZctZrfqFjdIo+UZfVgInor3xMHigM0AC8YaKSnzmBNFUNCLd+HH5apK2BMk x3Uw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=GpdH6IiKQVcGCXPPgrfylAYaua98vTMacq4Xy8UCW3o=; b=mGNxItVSpUg+9auag8UQ0ZOwutWdEA+vci9X8lMsGjkoI5XQ+jphjGREaZIdkPM95M mhtd0/eRtp3sArLLbgrllVvgIuPlhrdmzbH8BDrN+j1UfwT0hQQXQHJR9Gi6HgkxzeD5 EBoqVrnMGuI5wlIdJaF1/Zd0Rosi6VRjNOVqqFJp6p04opn5yumwRswnlnV7Tgdy6vD3 U2W+I8HdUVEObl4TRXakhq28OfbHJ/tESMTLNF5no/eGnjqin+MVlZRKd+hY3BqMB94/ b9ZsVXmGQZ4kmMfuWkAgngyQptsq3IBJpHTfc3muKuV72rk56k+6XBbxgb2A2UEv2Ci+ VUSg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XF6NiO27; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=GpdH6IiKQVcGCXPPgrfylAYaua98vTMacq4Xy8UCW3o=; b=YeyiG4UZjMYXPisMI71hUCv+LBi61D9amTSTU28HqwrOTgajj5FALBqt2BXsWCpHnD qICwH35N4eznTPXo6XiCwiHqDHOWyig5lRvWzRQ/BSEHlVRtapvhJC6LkuGIsfGlZ/O1 /pM3urp0z9DVfG6xT6ylnCMFIUabKdKZ8FyVE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GpdH6IiKQVcGCXPPgrfylAYaua98vTMacq4Xy8UCW3o=; b=w80Pa+hYtPYblo1PPgf/qWIPswmBmx8ABXvbsfLB2VUMNOOCvjUfwQsSvI+FAF0Eql QEhKZAHKPge4opITYvzUB3AvJ0xEb6EKVaSKKuaMnjoJtIagrGWWho9z5UMrKD6/gXa5 6SJUTjc8dBj1UzOQH5+DSs4TAeNoAITbOpBs8FQKziZ1NgPEinW+xVEtAwmMxrhwrq2j 3n8yEX1CxDlX3/IKeiwvfdPhqa5rxWuiFNalSBjw5eem9Hr37yr41BVr6Efc1aRErw1/ ldEAw8Ev4SsufpmWvVVNnZSu9OrZCk9eF021N6Q/h9AtjI3eLEq35pjeQOdaNmDsKyO3 4ZEg== X-Gm-Message-State: ANoB5pnig2L3OC5lcbmjOPb9dRbqhxzA7ftAjEiyRmxO/5b0LwAACf8y OLrviJ/T58xuvf9SInM6kFlKQzYZ X-Google-Smtp-Source: AA0mqf7CyARbgOVIRyENmsRx8FQN70y1EqbgT/FFJHy4yjOEAMxAdC73Pxzy420YMg362N62wygsqA== X-Received: by 2002:a05:6a00:2403:b0:572:698b:5f69 with SMTP id z3-20020a056a00240300b00572698b5f69mr83395831pfh.54.1671022778453; Wed, 14 Dec 2022 04:59:38 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:7b86:b0:188:62b8:814f with SMTP id w6-20020a1709027b8600b0018862b8814fls22270271pll.1.-pod-prod-gmail; Wed, 14 Dec 2022 04:59:37 -0800 (PST) X-Received: by 2002:a17:902:b08b:b0:188:6ab3:20c with SMTP id p11-20020a170902b08b00b001886ab3020cmr24614426plr.34.1671022777484; Wed, 14 Dec 2022 04:59:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671022777; cv=none; d=google.com; s=arc-20160816; b=mbZAjshu1ip5jnGES2E+H/ZQzB/hcT8LJNua1CnkET0pAhGqawIcNZypUTb5aC6Enj oCc6vTgOf7fyHuwd8kN5tRaVbG3zf3YplrDkUdvU10ntm9MLHuY2E5HfL6hz3DsQSGED H8obBxYWY9oi7sn4woNEfeRhCMdZQ8BHCOjL+/LchWrPx0RA6ZPtYBpO52AAQKPV5LPu WXgMeMex7i0Nh/2On6CSI+PiyFt9Ia9tSh4X/9UFtzutEjP7a+6z/AwqLKeChYz2QDUZ 0vjqKxLIgvdBqNDzHKWNAby0+6i+JxGrdUrqdv6E3fkdc8Hmn7LnN4T8B7OJnXPdJe6M V7ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=8ndEKJEU9XRDwvy5hojvuVFbU65Mj9YqYATSCh2JuDY=; b=RAAYmZeWVu0Cdq50ryoiVqq9MV4rJDGy+IO8eaTOYYMPAk7OdGSOvpD3Md5jdH7FA1 /hZ0sY59Dfe+FoPwVTM8qgCm4LFFdbqO8kbK2uwBNZ2rTFk8wwgcudtStHdF9CIA3CVQ TAEvgNuKCZF+VzvERwpr5DZqbetnEN3yVV9b5lhkoLOAn2YqBOIMoA3g/wUAIFltgIHW YeAmzE6J8X4YIb04xLqYODHjC1xo5mncM4TSpJ3+QEiMfprV6Qj7B29/4a0luAPbiAMo Hk3nL15SfhH/8+jZvwiGAFcS1i3hGjACeXtoNQy7+aXLnQPxaVrzlsX/DHyuPR3kMr6a JAlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XF6NiO27; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id e7-20020a170902b78700b001865ef88280sor1527786pls.3.2022.12.14.04.59.37 for (Google Transport Security); Wed, 14 Dec 2022 04:59:37 -0800 (PST) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:902:bf49:b0:189:e360:ce5 with SMTP id u9-20020a170902bf4900b00189e3600ce5mr24920364pls.12.1671022777128; Wed, 14 Dec 2022 04:59:37 -0800 (PST) Received: from localhost.localdomain ([2405:201:c00a:a809:5e03:faf:846e:352d]) by smtp.gmail.com with ESMTPSA id ix17-20020a170902f81100b001895f7c8a71sm1838651plb.97.2022.12.14.04.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 04:59:36 -0800 (PST) From: Jagan Teki To: Andrzej Hajda , Inki Dae , Marek Szyprowski , Joonyoung Shim , Seung-Woo Kim , Kyungmin Park , Frieder Schrempf , Fancy Fang , Tim Harvey , Michael Nazzareno Trimarchi , Adam Ford , Neil Armstrong , Robert Foss , Laurent Pinchart , Tommaso Merciai , Marek Vasut Cc: Matteo Lisi , dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, NXP Linux Team , linux-amarula , Jagan Teki , Maxime Ripard , Linus Walleij , Maarten Lankhorst Subject: [PATCH v10 01/18] drm: of: Lookup if child node has DSI panel or bridge Date: Wed, 14 Dec 2022 18:28:50 +0530 Message-Id: <20221214125907.376148-2-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221214125907.376148-1-jagan@amarulasolutions.com> References: <20221214125907.376148-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XF6NiO27; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Devices can also be child nodes when we also control that device through the upstream device (ie, MIPI-DCS for a MIPI-DSI device). Unlike the drm_of_find_panel_or_bridge helper it requires a special case to lookup a child node of the given parent that isn't either port or ports. Lookup for a child DSI node of the given parent that isn't either port or ports. If it is found then it will directly find the panel or bridge otherwise lookup for the child node with a given port and endpoint number as drm_of_find_panel_or_bridge does. Supporting this feature via existing drm_of_find_panel_or_bridge found several issues while handling usecases. Here is the previously failed attempt of similar and the same has been reverted later. commit <80253168dbfd> ("drm: of: Lookup if child node has panel or bridge") So, add a separate helper to handle this DSI use case. Example OF graph representation of DSI host, which has port but not has ports and has child panel node. dsi { compatible = "allwinner,sun6i-a31-mipi-dsi"; #address-cells = <1>; #size-cells = <0>; port { dsi_in_tcon0: endpoint { remote-endpoint = ; }; panel@0 { reg = <0>; }; }; Example OF graph representation of DSI host, which has ports but not has port and has child panel node. dsi { compatible = "samsung,exynos5433-mipi-dsi"; #address-cells = <1>; #size-cells = <0>; ports { #address-cells = <1>; #size-cells = <0>; port@0 { reg = <0>; dsi_to_mic: endpoint { remote-endpoint = <&mic_to_dsi>; }; }; }; panel@0 { reg = <0>; }; }; Example OF graph representation of DSI host, which has neither a port nor a ports but has child panel node. dsi0 { compatible = "ste,mcde-dsi"; #address-cells = <1>; #size-cells = <0>; panel@0 { reg = <0>; }; }; Cc: Maxime Ripard Cc: Laurent Pinchart Cc: Linus Walleij Cc: Maarten Lankhorst Signed-off-by: Jagan Teki --- Changes for v10: - new patch drivers/gpu/drm/drm_of.c | 113 ++++++++++++++++++++++++++++++++------- include/drm/drm_of.h | 12 +++++ 2 files changed, 105 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c index 7bbcb999bb75..020457444dfe 100644 --- a/drivers/gpu/drm/drm_of.c +++ b/drivers/gpu/drm/drm_of.c @@ -216,6 +216,36 @@ int drm_of_encoder_active_endpoint(struct device_node *node, } EXPORT_SYMBOL_GPL(drm_of_encoder_active_endpoint); +static int of_drm_find_panel_or_bridge(struct device_node *remote, + struct drm_panel **panel, + struct drm_bridge **bridge) +{ + int ret = -EPROBE_DEFER; + + 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; + } + + } + + of_node_put(remote); + return ret; +} + /** * drm_of_find_panel_or_bridge - return connected panel or bridge device * @np: device tree node containing encoder output ports @@ -238,7 +268,6 @@ 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; if (!panel && !bridge) @@ -259,30 +288,74 @@ int drm_of_find_panel_or_bridge(const struct device_node *np, if (!remote) return -ENODEV; - if (panel) { - *panel = of_drm_find_panel(remote); - if (!IS_ERR(*panel)) - ret = 0; - else - *panel = NULL; - } + return of_drm_find_panel_or_bridge(remote, panel, bridge); +} +EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge); - /* 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; - } +/** + * drm_of_dsi_find_panel_or_bridge - return connected DSI panel or bridge device + * @np: device tree node containing encoder output ports + * @port: port in the device tree node + * @endpoint: endpoint in the device tree node + * @panel: pointer to hold returned drm_panel + * @bridge: pointer to hold returned drm_bridge + * + * Lookup for a child DSI node of the given parent that isn't either port + * or ports. If it is found then it will directly find the panel or bridge + * otherwise lookup for the child node with a given port and endpoint number + * as drm_of_find_panel_or_bridge does. + * + * Lookup a given child DSI node or a DT node's port and endpoint number, + * find the connected node and return either the associated struct drm_panel + * or drm_bridge device. Either @panel or @bridge must not be NULL. + * + * Returns zero if successful, or one of the standard error codes if it fails. + */ +int drm_of_dsi_find_panel_or_bridge(const struct device_node *np, + int port, int endpoint, + struct drm_panel **panel, + struct drm_bridge **bridge) +{ + struct device_node *remote; + + 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; } - of_node_put(remote); - return ret; + /* + * 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; + + return of_drm_find_panel_or_bridge(remote, panel, bridge); } -EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge); +EXPORT_SYMBOL_GPL(drm_of_dsi_find_panel_or_bridge); enum drm_of_lvds_pixels { DRM_OF_LVDS_EVEN = BIT(0), diff --git a/include/drm/drm_of.h b/include/drm/drm_of.h index 10ab58c40746..7a97157c1fa0 100644 --- a/include/drm/drm_of.h +++ b/include/drm/drm_of.h @@ -47,6 +47,10 @@ 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_dsi_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_data_mapping(const struct device_node *port); @@ -99,6 +103,14 @@ static inline int drm_of_find_panel_or_bridge(const struct device_node *np, return -EINVAL; } +static inline int drm_of_dsi_find_panel_or_bridge(const struct device_node *np, + int port, int endpoint, + struct drm_panel **panel, + struct drm_bridge **bridge) +{ + return -EINVAL; +} + static inline int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, const struct device_node *port2)