patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Stephen Boyd <swboyd@chromium.org>
To: chrome-platform@lists.linux.dev
Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-arm-msm@vger.kernel.org,
	Douglas Anderson <dianders@chromium.org>,
	Pin-yen Lin <treapking@chromium.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Matthias Kaehlcke <mka@chromium.org>,
	linux-usb@vger.kernel.org, maciek swiech <drmasquatch@google.com>
Subject: [PATCH 04/22] usb: core: Set connect_type of ports based on DT node
Date: Fri,  9 Feb 2024 23:09:15 -0800	[thread overview]
Message-ID: <20240210070934.2549994-5-swboyd@chromium.org> (raw)
In-Reply-To: <20240210070934.2549994-1-swboyd@chromium.org>

When a USB hub is described in DT, such as any device that matches the
onboard-hub driver, the connect_type is set to "unknown" or
USB_PORT_CONNECT_TYPE_UNKNOWN. This makes any device plugged into that
USB port report their 'removable' device attribute as "unknown". Improve
the connect_type attribute for ports, and in turn the removable
attribute for USB devices, by looking for child devices with a reg
property or an OF graph when the device is described in DT.

If the graph exists, endpoints that are connected to a remote node must
be something like a usb-{a,b,c}-connector compatible node, or an
intermediate node like a redriver, and not a hardwired USB device on the
board. Set the connect_type to USB_PORT_CONNECT_TYPE_HOT_PLUG in this
case because the device is going to be plugged in. Set the connect_type
to USB_PORT_CONNECT_TYPE_HARD_WIRED if there's a child node for the port
like 'device@2' for port2. Set the connect_type to USB_PORT_NOT_USED if
there isn't an endpoint or child node corresponding to the port number.

To make sure things don't change, only set the port to not used if
there are child nodes. This way an onboard hub connect_type doesn't
change until ports are added or child nodes are added to describe
hardwired devices. It's assumed that all ports or no ports will be
described for a device.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Matthias Kaehlcke <mka@chromium.org>
Cc: <linux-usb@vger.kernel.org>
Cc: <devicetree@vger.kernel.org>
Cc: Pin-yen Lin <treapking@chromium.org>
Cc: maciek swiech <drmasquatch@google.com>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 drivers/usb/core/port.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index c628c1abc907..622b8ada157c 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -9,6 +9,8 @@
 
 #include <linux/kstrtox.h>
 #include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_graph.h>
 #include <linux/pm_qos.h>
 #include <linux/component.h>
 
@@ -696,7 +698,10 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
 {
 	struct usb_port *port_dev;
 	struct usb_device *hdev = hub->hdev;
+	struct device_node *np, *child, *ep, *remote_np, *port_np;
 	int retval;
+	enum usb_port_connect_type connect_type = USB_PORT_CONNECT_TYPE_UNKNOWN;
+	u32 reg;
 
 	port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL);
 	if (!port_dev)
@@ -708,6 +713,38 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
 		return -ENOMEM;
 	}
 
+	np = hdev->dev.of_node;
+	/* Only set connect_type if binding has ports/hardwired devices. */
+	if (of_get_child_count(np))
+		connect_type = USB_PORT_NOT_USED;
+
+	/* Hotplug ports are connected and available in the OF graph. */
+	if (of_graph_is_present(np)) {
+		port_np = of_graph_get_port_by_id(np, port1);
+		if (port_np) {
+			ep = of_graph_get_endpoint_by_regs(np, port1, -1);
+			if (ep) {
+				remote_np = of_graph_get_remote_port_parent(ep);
+				of_node_put(ep);
+				if (of_device_is_available(remote_np))
+					connect_type = USB_PORT_CONNECT_TYPE_HOT_PLUG;
+				of_node_put(remote_np);
+			}
+		}
+		of_node_put(port_np);
+	}
+
+	/*
+	 * Hard-wired ports are child nodes with a reg property corresponding
+	 * to the port number.
+	 */
+	for_each_available_child_of_node(np, child) {
+		if (!of_property_read_u32(child, "reg", &reg) && reg == port1)
+			connect_type = USB_PORT_CONNECT_TYPE_HARD_WIRED;
+	}
+
+	port_dev->connect_type = connect_type;
+
 	hub->ports[port1 - 1] = port_dev;
 	port_dev->portnum = port1;
 	set_bit(port1, hub->power_bits);
-- 
https://chromeos.dev


  parent reply	other threads:[~2024-02-10  7:09 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-10  7:09 [PATCH 00/22] platform/chrome: Add DT USB/DP muxing/topology to Trogdor Stephen Boyd
2024-02-10  7:09 ` [PATCH 01/22] dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller Stephen Boyd
2024-02-11 13:26   ` Krzysztof Kozlowski
2024-02-15  0:44     ` Stephen Boyd
2024-02-15 14:06   ` Rob Herring
2024-02-15 22:00     ` Stephen Boyd
2024-02-10  7:09 ` [PATCH 02/22] gpio: Add ChromeOS EC GPIO driver Stephen Boyd
2024-02-13 17:57   ` Linus Walleij
2024-02-10  7:09 ` [PATCH 03/22] dt-bindings: usb: Add downstream facing ports to realtek binding Stephen Boyd
2024-02-10 11:29   ` Rob Herring
2024-02-10  7:09 ` Stephen Boyd [this message]
2024-02-14  0:03   ` [PATCH 04/22] usb: core: Set connect_type of ports based on DT node Doug Anderson
2024-02-14 23:51     ` Stephen Boyd
2024-02-10  7:09 ` [PATCH 05/22] drm/atomic-helper: Introduce lane remapping support to bridges Stephen Boyd
2024-02-10  7:09 ` [PATCH 06/22] drm/bridge: Verify lane assignment is going to work during atomic_check Stephen Boyd
2024-02-10  7:09 ` [PATCH 07/22] device property: Add remote endpoint to devcon matcher Stephen Boyd
2024-02-10  7:09 ` [PATCH 08/22] platform/chrome: cros_ec_typec: Purge blocking switch devlinks Stephen Boyd
2024-02-10  7:09 ` [PATCH 09/22] platform/chrome: cros_typec_switch: Use read_poll_timeout helper Stephen Boyd
2024-02-10  7:09 ` [PATCH 10/22] platform/chrome: cros_typec_switch: Move port creation code to sub-function Stephen Boyd
2024-02-10  7:09 ` [PATCH 11/22] platform/chrome: cros_typec_switch: Use fwnode instead of ACPI APIs Stephen Boyd
2024-02-10  7:09 ` [PATCH 12/22] platform/chrome: cros_typec_switch: Use dev_err_probe() Stephen Boyd
2024-02-10  7:09 ` [PATCH 13/22] dt-bindings: chrome: Add google,cros-ec-typec-switch binding Stephen Boyd
2024-02-11 13:34   ` Krzysztof Kozlowski
2024-02-15  1:52     ` Stephen Boyd
2024-02-15  8:34       ` Krzysztof Kozlowski
2024-02-11 13:35   ` Krzysztof Kozlowski
2024-02-10  7:09 ` [PATCH 14/22] platform/chrome: cros_typec_switch: Add support for signaling HPD to drm_bridge Stephen Boyd
2024-02-10 14:10   ` Dmitry Baryshkov
2024-02-11  8:52     ` Stephen Boyd
2024-02-11  9:00       ` Dmitry Baryshkov
2024-02-10  7:09 ` [PATCH 15/22] platform/chrome: cros_typec_switch: Support DP muxing via DRM lane assignment Stephen Boyd
2024-02-10  7:09 ` [PATCH 16/22] platform/chrome: cros_typec_switch: Support orientation-switch Stephen Boyd
2024-02-10  7:09 ` [PATCH 17/22] platform/chrome: cros_typec_switch: Handle lack of HPD information Stephen Boyd
2024-02-10  7:09 ` [PATCH 18/22] dt-bindings: chrome: Add binding for ChromeOS Pogo pin connector Stephen Boyd
2024-02-11 13:39   ` Krzysztof Kozlowski
2024-02-15  0:07     ` Stephen Boyd
2024-02-15  8:39       ` Krzysztof Kozlowski
2024-02-14  1:17   ` Doug Anderson
2024-02-15  0:10     ` Stephen Boyd
2024-02-10  7:09 ` [PATCH 19/22] arm64: dts: qcom: sc7180: quackingstick: Disable instead of delete usb_c1 Stephen Boyd
2024-02-10 11:51   ` Dmitry Baryshkov
2024-02-13 23:24   ` Doug Anderson
2024-02-10  7:09 ` [PATCH 20/22] arm64: dts: qcom: sc7180: pazquel: Add missing comment header Stephen Boyd
2024-02-10 11:51   ` Dmitry Baryshkov
2024-02-13 23:24   ` Doug Anderson
2024-02-10  7:09 ` [PATCH 21/22] arm64: dts: qcom: sc7180-trogdor: Make clamshell/detachable fragments Stephen Boyd
2024-02-10 11:53   ` Dmitry Baryshkov
2024-02-13 23:34   ` Doug Anderson
2024-02-15  0:35     ` Stephen Boyd
2024-02-15  0:39       ` Doug Anderson
2024-02-10  7:09 ` [PATCH 22/22] arm64: dts: qcom: sc7180-trogdor: Wire up USB and DP to usb-c-connectors Stephen Boyd

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240210070934.2549994-5-swboyd@chromium.org \
    --to=swboyd@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=devicetree@vger.kernel.org \
    --cc=dianders@chromium.org \
    --cc=drmasquatch@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mka@chromium.org \
    --cc=patches@lists.linux.dev \
    --cc=treapking@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).