From patchwork Mon Feb 27 17:32:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 2759 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 46326414AC for ; Mon, 27 Feb 2023 18:33:00 +0100 (CET) Received: by mail-pf1-f200.google.com with SMTP id 202-20020a6218d3000000b005a89856900esf3729214pfy.14 for ; Mon, 27 Feb 2023 09:33:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1677519179; cv=pass; d=google.com; s=arc-20160816; b=S2IGc3Y6G37farVXRcPVIFXApFuxlte6zOsLoII0n7li6e3yBC+ESkCCfsmTLs6wsV 0587YAIG307GS9VZ44SKUZa9PKr2EeumfvVGZGCSjToPs3Y2ywPlOVY9PEXZvPRGc7QE zbqySXM0caX2s2XFy+Dbqx3A47JPqKi0LPgJjOpn0BFCcVZdCytnHnD+LdWflKJyVdGo N4eiYHvZAm7zVZjM5AevNOetug6vhNZo4ZaPBLCdMCd/BkCo8SehBuIK3W824ibNO5I0 TANFxXIU7brxnN3tQU2YLjG+NyIam5d0sBPVRyFssnXZ8d/FnZXYR8w/WaKVqS5Yl5tD Uqbw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=H8A/zbZ70s0XxT47OzIKEN2Akmt1QZpCoHKxibnFNj0=; b=gaGAsxe4WM+6et4MHwu/kirHD13sPbdmLpBaAl30LBB80jloeUJ3zl4ezFXGU5KOq2 8jB7ckcGOjXz97cg5aBOXKzPpwIkjILcUiqNesKRJ3zxoOlySn5VsS2wyWAJJJraXuX4 mZHGB03C+7tyZlfCfBTpVLs0EJ0uRBhSWKhn/oaSu1VfU62sBDNio3vTRkTajESMdy7J UNbXY0rMtY1Rblill6GVHTgpvEWvQh7BPtz04SUo12JqBHfWopZMzM7WxcsRDPiRSMtb DfYogSrnVN27iPzhvWsGTvPgfC3KzFb6UcLYc1eLfhoQ5kNV2KTud2LF9EFM8hMCD29I qAKg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=FZHhI6h2; 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:message-id:date:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=H8A/zbZ70s0XxT47OzIKEN2Akmt1QZpCoHKxibnFNj0=; b=n5HxNUZ+5N8/G19UuiR/70AaqV3U7pWLOJBdiy3Z/uoumkK6JlwmwBCnqkbDkpRcy3 hJmiTUPpL7MH7spdFpUJihZ55rps+50Jow0jLYsZcMeeKdfihgTPEQNB5qQYLsSoVIsF I/vTR5A1/WnmYmvLc4m8V9zMAqg1+Tz8bwihA= 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 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H8A/zbZ70s0XxT47OzIKEN2Akmt1QZpCoHKxibnFNj0=; b=btiuvZUdpSiWqBWeNgZOa+tT84x1y2k1QOquCjIIEIyqjZeaVDDAVgFvWSUt8XEhjz NqXd29Vcj9H5wkKQK/Enspz1hE4RIwJZTgSBrtxSRxFLX1X4Go5vEl5xWgS33IoqXbGO 1UIozzjSpzYxdWy9FzyOvFizi4OZIsCH41U2ewabPltRGRGqM6pILQprscwnwEQjk2pU HwjtS8p3ONUsoSLmOdam6RDQVwDlsMn+3x8+CmRHdsUQ70htGymHWxbRyMaI0b49LkL6 h4PG+C4ZXae/QUHZnrsv1h6HHqNoIVdS1X3GZqgN+P8HPtUE8fR8daaTILq00jvgbVNe HSOQ== X-Gm-Message-State: AO0yUKWPMZOWQJmKIR4waZnb7VEldYbjwm5yBQh2lK9TXNU09vQ6DaYN B6FWNXfyEJQHqq79ELhss+EvKZyD X-Google-Smtp-Source: AK7set8Xx1SQ48SqxgCUq/SOombixQiPnv83SbP+e6qFURmIeECb3M+PbSj6Rc01Fbc9QSoS/Zyyow== X-Received: by 2002:a17:90b:3c08:b0:235:1fb7:393c with SMTP id pb8-20020a17090b3c0800b002351fb7393cmr5506814pjb.1.1677519178919; Mon, 27 Feb 2023 09:32:58 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90b:224d:b0:233:cf4f:61f4 with SMTP id hk13-20020a17090b224d00b00233cf4f61f4ls15277863pjb.1.-pod-canary-gmail; Mon, 27 Feb 2023 09:32:58 -0800 (PST) X-Received: by 2002:a17:902:ceca:b0:19c:fa22:e98a with SMTP id d10-20020a170902ceca00b0019cfa22e98amr7365896plg.8.1677519177922; Mon, 27 Feb 2023 09:32:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677519177; cv=none; d=google.com; s=arc-20160816; b=y6iZFfnf/V2Bz6pFiIwc4+XCRyM9Wg5iC12OpTOLSJh/ViP94dyFBx7ETp4+EOXGUa SlbFgF23vtp2SEQvr0hfA1hmgdtrWmPDJVJTVeDzCgyruVJbsMP3qYgo+q2CK/dIQzUB 1ypKNKHmd6caBTyjEVdWXcwgSgLfrSsPMFNO3NwEBuDLV2nIX5okse9FRaQvDeNThBVC iedB1GzVoGG35Jg07BmIXAKMaGAoG9u5ywd/0UAi3twv/SwDmwWwh4Qhf2K7ChWnxZVU yQCqeiYQOP3Mon/irWvrOmwugyQMjr6rbXjsQRO8wykrz6SVU5voys2UqaZuVR1clT+W kzvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=H0PG1U4rnB+Ux7NI0bDnLcmfUpG6Dhmd6/T4JTeOSQk=; b=QPyNLQ/Ld6QZu0l3iZBv8bGJvhK+mQlYOAvyBw7N41X/mr/uBDQZCeVGbigmZoyNsR VlXQwOKL5/PCaAobGUkmEWPdW1VPbAn8binAXpsaxbRklYXRGiwszEHoTFO+Zte0I0rE 0TEXIdDh3LDBMLqDMUeRrOwmMB2WV1y9fp6oV98Rj+UhmkclCeclZwqqOWbVOYSanltT Ht9KLv+SDNRl/6zBt+pAhxFKhEd6oAMv5QgkqKm4RJxx3nSpkDY61f5/q73DL9B5Q5z+ d4ffKr3dicKyl+Xxsf8gdNCIw2L1WgXNuJBMt8we55Nw3IkK7LAj1OwRSmmDgK95i4rH Q+Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=FZHhI6h2; 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 z15-20020a1709027e8f00b0019c91d0cc35sor3024777pla.174.2023.02.27.09.32.57 for (Google Transport Security); Mon, 27 Feb 2023 09:32:57 -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:a05:6a20:728c:b0:cc:ce95:7daf with SMTP id o12-20020a056a20728c00b000ccce957dafmr111718pzk.53.1677519177518; Mon, 27 Feb 2023 09:32:57 -0800 (PST) Received: from localhost.localdomain ([2405:201:c00a:a1ce:9be1:7461:c30:b70a]) by smtp.gmail.com with ESMTPSA id a63-20020a639042000000b004fbb48e3e5csm4308881pge.77.2023.02.27.09.32.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 09:32:56 -0800 (PST) From: Jagan Teki To: Maxime Ripard , Maarten Lankhorst , Andrzej Hajda , Neil Armstrong , Laurent Pinchart , Marek Vasut Cc: dri-devel@lists.freedesktop.org, linux-amarula , Jagan Teki , Linus Walleij Subject: [PATCH v14 1/3] drm: of: Lookup if child node has DSI panel or bridge Date: Mon, 27 Feb 2023 23:02:29 +0530 Message-Id: <20230227173231.950107-1-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 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=FZHhI6h2; 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 v14, v13, v12: - none Changes for v11: - drop extra line Changes for v10: - new patch drivers/gpu/drm/drm_of.c | 112 ++++++++++++++++++++++++++++++++------- include/drm/drm_of.h | 12 +++++ 2 files changed, 104 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c index 7bbcb999bb75..e165951e3545 100644 --- a/drivers/gpu/drm/drm_of.c +++ b/drivers/gpu/drm/drm_of.c @@ -216,6 +216,35 @@ 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 +267,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 +287,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)