From patchwork Mon Aug 19 22:38:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 821282 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 818B81EB486 for ; Mon, 19 Aug 2024 22:38:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107141; cv=none; b=A2Kic9pCddRJOqKbghOYYbhdsV0nqUQRHleWZeyaGS1JGyVQMuyy/Tue/79V3zyv8ChICHEwayR/g2HlWumBHkJRHDc80e2PJBC6fhogjQMzR/l7vrKEuhNL6HmwPnBiFvvU2PY4XWzUbQydx2MEVv6OfhrRBTZXUMCpdLriUJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107141; c=relaxed/simple; bh=mxX0zurMaqjFAvwPTAYvbkHJDOrh+ogY61LYBsDimY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=THKRtzp2JK7N09xnW9qAZImdKUkdtlibNAQEt1ecU77StIgtbqG6/ahk0Q9IJvz1RAiE0IJCAHMwGmeo0UutI/opXvDr44eimk5oMCRibsp2NK4E+NtTCWeD7SqEDO0VENoB2vk9aCeQ1GG0TLnyEKq/g/XRa17yfk411WkQu+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=TPjbauuX; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="TPjbauuX" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fc611a0f8cso37005855ad.2 for ; Mon, 19 Aug 2024 15:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107139; x=1724711939; darn=vger.kernel.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=hC911fBOHCsJMM7xcu9tR0EWsA9wFiTFaVVHtkvUAjk=; b=TPjbauuXLwswYIfgU4XKPckbyt4bWQRplbONiBpsOocVka0VmTyWO+x5xAK289W0Ls +awtyb2eSWgtplIUIGswiOQLHRsoGKt0YxF1XoaJMm6lduI0W//W8hTz3yQG7HcgX+RC DbCe+Gg9z9fO5gHBfK4M+3Pdbg5QJTQUMHBqo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107139; x=1724711939; 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=hC911fBOHCsJMM7xcu9tR0EWsA9wFiTFaVVHtkvUAjk=; b=giqAjyaK+0kAJ62xNQfLIeuXNVZINO0eaxNBGiwsTmwwL0kbAk1XAYHF2aLI27rKtM R9+onOnA9SArtGm37cm/7eNx2n6KheWKL3FobCHLexuwyu0JuILtkF/IhRTMrDllydBH ZchjE+YUvKl/aG0hRswOaaOmIWROCy8UvYX6lRoIM/grk5hRi27xdAhYDdBmuFtgLrWl Ij+efcDXuIcU9W4G1bFt+LjQd96N8kiiqmG2aabkJFN+lSizMRDj/a030TisXXhxsuVf Z6boEqsHq0M6YEH+AT2KESeHDvx/Z3ujDyBLyTLbLU6BLuYZg+QLxFBT2C7viT8dZ08Y E3fA== X-Forwarded-Encrypted: i=1; AJvYcCUMsyYrXf2/Vvtgz9GY/FEOMR4yOeepLY2bfOWBlJ638o3/b7sSaWMsxTEk6m9GvBi1MNCpr9iWNuo=@vger.kernel.org X-Gm-Message-State: AOJu0Ywln9T1Z3aReQUPBv+1cG5P8Qc1WPwf7PPVu6j173UQg5H+ImhO YDiC2zWh/h5ehsFpTKiNhiD0FsLXjhCaj/1NwGVUz5s3pK1HfMIHt47p0ow9Mg== X-Google-Smtp-Source: AGHT+IGLjuWtpZx7vqGNlEmVLbw+/jbA0jrqk36BQ9obYmr0oT4bTrUtSNP+SOsQgfFW6VfGITSwMw== X-Received: by 2002:a17:903:4345:b0:201:f8b4:3e3c with SMTP id d9443c01a7336-20203e49439mr92807475ad.12.1724107138748; Mon, 19 Aug 2024 15:38:58 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-201f038b4e9sm66612995ad.209.2024.08.19.15.38.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:58 -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 v3 10/17] device property: Add remote endpoint to devcon matcher Date: Mon, 19 Aug 2024 15:38:24 -0700 Message-ID: <20240819223834.2049862-11-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 5 +++-- 5 files changed, 24 insertions(+), 7 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 3531ab03bac4..ab53532282ff 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); } @@ -290,6 +294,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; @@ -307,6 +312,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 61fc20e5f81f..3e27d7b76db9 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -507,8 +507,9 @@ unsigned int fwnode_graph_get_endpoint_count(const struct fwnode_handle *fwnode, int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, struct fwnode_endpoint *endpoint); -typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, const char *id, - void *data); +typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, + 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,