From patchwork Sun Sep 1 04:06:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786260 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 689D2C54FC6 for ; Sun, 1 Sep 2024 04:07:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D97C510E17F; Sun, 1 Sep 2024 04:07:27 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="HwkPWcSi"; dkim-atps=neutral Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by gabe.freedesktop.org (Postfix) with ESMTPS id 60E9A10E17B for ; Sun, 1 Sep 2024 04:07:26 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2021c03c13aso25461255ad.1 for ; Sat, 31 Aug 2024 21:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163646; x=1725768446; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Pmo3/yU2P8LsM22CtkppGBhBN/HDkEIQ1oKrtDKPQrs=; b=HwkPWcSifcPV+hYxHtcRgoCPpGJmqlBWkeuXZRjj1pSGmdK9TEhIQZwda5f6CTuE7c NPlPNtL1HWXVnA9sTORBqEMUE0OX3qVR5s4qVq+MFQ6Qm4uXqAnImCMy2mpAQUxioATi AyUItt9Y76FyRHs9nveWRCCAG6kKUXYWRKl4A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163646; x=1725768446; h=content-transfer-encoding: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=Pmo3/yU2P8LsM22CtkppGBhBN/HDkEIQ1oKrtDKPQrs=; b=qUJ9tMKOLm+hzZy0QVtslI0eNadlF6srQh4YnYHOdery+Oxr8njZE4cpTUIrGdYmK8 AeTgqmlpdWNr+RkDV+saqkhSDCHvJZ9SrDDcEh5rmV6lkZqnGCJ5NTbVx0H9ekYvaGMz kavY1HmEe5PVMk78dSYmzYLvsn0eDdG8djM6tKK3nNagY/6Yt1GyQZzmoUYG+h9Pt3hs IJltRfe/9s/Un07JuVUXMPRRNbO/6GnHVIrtet6rNNMWfhDEzN4Kig/ea+bE1iRhMLnZ ja/bzkPqowV+qOnWsKE7qb7s6etCXZi7MO6ik1xhlRiIEAa4iZ04oXlmO/jvvephlgJx L58A== X-Forwarded-Encrypted: i=1; AJvYcCUNIYTt8rox6A0RV4oo79hjjwjn/AoiosIQFmuBWO45SgXLdSK48UTmh3EeFG1534F1nvqRb+ylcrU=@lists.freedesktop.org X-Gm-Message-State: AOJu0YyLQ/vvpAWvC+eS6wHeJ6PAfhLhEGvdon/YFXNhjF82YeYWEsU2 MxgQYp7gyllh+5afR1iFsHBrvxkXadOl7Tu3fYeBF6cxTjV0tF9hkXcMjwW+6w== X-Google-Smtp-Source: AGHT+IGkEvNKrwf9vzljH1qmOoDG+G58iNPsfXL5CyX8XTHyhIjQ2Mn1eF6oxR0BUcemUEp0so8ADQ== X-Received: by 2002:a17:903:181:b0:1fb:2ebc:d17a with SMTP id d9443c01a7336-205286bb7cemr101990685ad.23.1725163645599; Sat, 31 Aug 2024 21:07:25 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-205155338bcsm47111615ad.177.2024.08.31.21.07.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:25 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 11/18] device property: Add remote endpoint to devcon matcher Date: Sat, 31 Aug 2024 21:06:49 -0700 Message-ID: <20240901040658.157425-12-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> MIME-Version: 1.0 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" When a single DT node has a graph connected to more than one usb-c-connector node we can't differentiate which typec switch registered for the device is associated with the USB connector because the devcon matcher code assumes a 1:1 relationship between remote node and typec switch. Furthermore, we don't have a #typec-switch-cells property so there can only be one node per typec switch. Support multiple USB typec switches exposed by one node by passing the remote endpoint node in addition to the remote node to the devcon matcher function (devcon_match_fn_t). With this change, typec switch drivers can register switches with the device node pointer for a graph endpoint so that they can support more than one typec switch if necessary. Either way, a DT property like 'mode-switch' is always in the graph's parent node and not in the endpoint node. Cc: Andy Shevchenko Cc: Daniel Scally Cc: Heikki Krogerus Cc: Sakari Ailus Cc: Greg Kroah-Hartman Cc: Vinod Koul Cc: "Rafael J. Wysocki" Cc: Mika Westerberg Cc: Alexandre Belloni Cc: Ivan Orlov Cc: Rob Herring Cc: Krzysztof Kozlowski Cc: Conor Dooley Cc: Cc: Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- drivers/base/property.c | 7 +++++-- drivers/usb/roles/class.c | 4 ++-- drivers/usb/typec/mux.c | 8 ++++++++ drivers/usb/typec/retimer.c | 7 ++++++- include/linux/property.h | 11 +++++++---- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 837d77e3af2b..621de33f2956 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1284,6 +1284,7 @@ static unsigned int fwnode_graph_devcon_matches(const struct fwnode_handle *fwno { struct fwnode_handle *node; struct fwnode_handle *ep; + struct fwnode_handle *remote_ep; unsigned int count = 0; void *ret; @@ -1299,7 +1300,9 @@ static unsigned int fwnode_graph_devcon_matches(const struct fwnode_handle *fwno continue; } - ret = match(node, con_id, data); + remote_ep = fwnode_graph_get_remote_endpoint(ep); + ret = match(node, remote_ep, con_id, data); + fwnode_handle_put(remote_ep); fwnode_handle_put(node); if (ret) { if (matches) @@ -1329,7 +1332,7 @@ static unsigned int fwnode_devcon_matches(const struct fwnode_handle *fwnode, if (IS_ERR(node)) break; - ret = match(node, NULL, data); + ret = match(node, NULL, NULL, data); fwnode_handle_put(node); if (ret) { if (matches) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index d7aa913ceb8a..d8bd5071d9d8 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -121,8 +121,8 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw) } EXPORT_SYMBOL_GPL(usb_role_switch_get_role); -static void *usb_role_switch_match(const struct fwnode_handle *fwnode, const char *id, - void *data) +static void *usb_role_switch_match(const struct fwnode_handle *fwnode, const struct fwnode_handle *endpoint, + const char *id, void *data) { struct device *dev; diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index f420185e36e3..9ddb6ec54325 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -33,6 +33,7 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode) } static void *typec_switch_match(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, const char *id, void *data) { struct device *dev; @@ -55,6 +56,9 @@ static void *typec_switch_match(const struct fwnode_handle *fwnode, */ dev = class_find_device(&typec_mux_class, NULL, fwnode, switch_fwnode_match); + if (!dev) + dev = class_find_device(&typec_mux_class, NULL, endpoint, + switch_fwnode_match); return dev ? to_typec_switch_dev(dev) : ERR_PTR(-EPROBE_DEFER); } @@ -299,6 +303,7 @@ static int mux_fwnode_match(struct device *dev, const void *fwnode) } static void *typec_mux_match(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, const char *id, void *data) { struct device *dev; @@ -316,6 +321,9 @@ static void *typec_mux_match(const struct fwnode_handle *fwnode, dev = class_find_device(&typec_mux_class, NULL, fwnode, mux_fwnode_match); + if (!dev) + dev = class_find_device(&typec_mux_class, NULL, endpoint, + mux_fwnode_match); return dev ? to_typec_mux_dev(dev) : ERR_PTR(-EPROBE_DEFER); } diff --git a/drivers/usb/typec/retimer.c b/drivers/usb/typec/retimer.c index b519fcf358ca..ee4e6312c2d9 100644 --- a/drivers/usb/typec/retimer.c +++ b/drivers/usb/typec/retimer.c @@ -22,7 +22,9 @@ static int retimer_fwnode_match(struct device *dev, const void *fwnode) return is_typec_retimer(dev) && device_match_fwnode(dev, fwnode); } -static void *typec_retimer_match(const struct fwnode_handle *fwnode, const char *id, void *data) +static void *typec_retimer_match(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, + const char *id, void *data) { struct device *dev; @@ -31,6 +33,9 @@ static void *typec_retimer_match(const struct fwnode_handle *fwnode, const char dev = class_find_device(&retimer_class, NULL, fwnode, retimer_fwnode_match); + if (!dev) + dev = class_find_device(&retimer_class, NULL, endpoint, + retimer_fwnode_match); return dev ? to_typec_retimer(dev) : ERR_PTR(-EPROBE_DEFER); } diff --git a/include/linux/property.h b/include/linux/property.h index 797b1eeda7d2..72a89cd410db 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -510,22 +510,25 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, /** * devcon_match_fn_t - device connection match function * @fwnode: Remote connection's device node + * @endpoint: Remote connection's endpoint node * @con_id: Identifier for the connection * @data: Match function caller specific data * * Implement a callback with this function signature to search a fwnode's * connections for a match with a function like device_connection_find_match(). * This function will be called possibly multiple times, once for each - * connection. The match function should inspect the @fwnode to look for a - * match. The @con_id and @data provided are the same as the @con_id and @data - * arguments passed to the functions that take a devcon_match_fn_t argument. + * connection. The match function should inspect the connection's @fwnode + * and/or @endpoint to look for a match. The @con_id and @data provided are the + * same as the @con_id and @data arguments passed to the functions that take a + * devcon_match_fn_t argument. * * Note: This function can be called multiple times. * * Return: Pointer to match or NULL if no match found. */ typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, - const char *con_id, void *data); + const struct fwnode_handle *endpoint, + const char *id, void *data); void *fwnode_connection_find_match(const struct fwnode_handle *fwnode, const char *con_id, void *data,