From nobody Sun Feb 8 09:26:54 2026 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (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 87C90AD5A for ; Fri, 23 Feb 2024 00:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708649911; cv=none; b=bvtYUFPPqtDQu88J7cccgRqruNTu/rqdXnxWG2PyHCeUu0Co7lLRNl8alzT9GlwO9nPuPpm9qe8NF1wgM8Qta3n78MeGuzuX1G/3KLslAJwc1gB/P+GQpqTwJ8JR2MoC0TA1qMyEYHYNZsmvBsuG/FiDjVWbbdbSS2ZCh+m+7gs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708649911; c=relaxed/simple; bh=O1sCSpMrQuVP4Z+oTQDMovl4p0LxmLa8st/+UmNeCw0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nWovj9Cbam4FVW95qkXqT/XdVocEqAUwfIizA0X/kZ1yEKvEGH9AvpFCeUAQd4HZLBvf/h7XWkxgbjsTSMexTocP9c7Vr8dsDYPr3sX0tDOVXKmYZzTDpCw3IjsjzcTyDxZHaI0xRhfhVZAssXSU+0eN7xVk3kxy3f8JsjmwnLM= 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=CAFwyX3f; arc=none smtp.client-ip=209.85.219.171 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="CAFwyX3f" Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-dccb1421bdeso379578276.1 for ; Thu, 22 Feb 2024 16:58:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1708649907; x=1709254707; 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=zUukn0iRYfq5PWEhEP7nadIeFb7HXOkHlZH9C2/kzss=; b=CAFwyX3fxgveUxR6RRagHZ0b5uYjW3EJcZI7PhECpmON6zPyrEAVevDtujCj/Skgig 03ocYUmFJfQTcEnYMryirpfeHbgy4xOFT9nDbnejihvG5tqyiOvLcs4MtwHshsGDGxVd Cm/UO3BoivmdSODWec8kjMKY5G2z9zgivCEVY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708649907; x=1709254707; 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=zUukn0iRYfq5PWEhEP7nadIeFb7HXOkHlZH9C2/kzss=; b=mjxQaeRd/wWvKJD9rucVRogYVuS3Yh4sIijUrj2YkgV0H/77od5VPiEpee+f1oRfE1 ipEsQ1BoAOeomc21x8gCYauyRBqDGGaSOwK4P2K23QuDPwed3vQ9VQv1WLgBTtz2nLrj FksOXNpqfXIHf9uciOk2IFdQv2E/rfsijxjc9/0BZ2PJY15wLGlVSf9G3MTDrmq2U+QG 1HZvOHSKd0OR3yUXFcVw0EzaCq5cUf2NHst3l6Nt7hgpvs+HxdY/M/TXmWT9poyvvFZi oFyXy1YZKVutvhG8Zs6t6QfsS6hDplxJ5BReuB5iAz08z1m6PwqDV1wk8E4ds/g0YLQI mWmQ== X-Gm-Message-State: AOJu0Yw4JfsDfeNlEr8+/mNxhSgNqDH1nzeOWG3hHBw0d/E+3i9n64Q/ FZH7nWM7z7Om7KJ2tGhZBX6zGT1WsVxu+aMvP5FQQTKFwPdabvBO+D54f0MeSQ== X-Google-Smtp-Source: AGHT+IG7cIldAux1KCpcOyUTRGVAfY4OuwFGQoFyysr4Ky17iN4jW+0w6szCAWKEExF3w960f89FHg== X-Received: by 2002:a25:c244:0:b0:dc6:a8c6:c9e5 with SMTP id s65-20020a25c244000000b00dc6a8c6c9e5mr877740ybf.26.1708649907539; Thu, 22 Feb 2024 16:58:27 -0800 (PST) Received: from localhost (175.199.125.34.bc.googleusercontent.com. [34.125.199.175]) by smtp.gmail.com with UTF8SMTPSA id p14-20020a056a0026ce00b006e4887b13ffsm4820031pfw.1.2024.02.22.16.58.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Feb 2024 16:58:27 -0800 (PST) From: Stephen Boyd To: Greg Kroah-Hartman , Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Herve Codina , Alan Stern , Heikki Krogerus , Roy Luo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Kaehlcke , linux-usb@vger.kernel.org, maciek swiech Subject: [PATCH v2 1/2] dt-bindings: usb: Add downstream facing ports to realtek binding Date: Thu, 22 Feb 2024 16:58:20 -0800 Message-ID: <20240223005823.3074029-2-swboyd@chromium.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240223005823.3074029-1-swboyd@chromium.org> References: <20240223005823.3074029-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a graph with 4 output endpoints to this hub binding to support the scenario where a downstream facing port is connected to a device that isn't a connector or a USB device with a VID:PID. This will be used to connect downstream facing ports to USB type-c switches so the USB superspeed and high speed lanes can be put onto USB connectors. Cc: Rob Herring Cc: Krzysztof Kozlowski Cc: Conor Dooley Cc: Matthias Kaehlcke Cc: Cc: Cc: Pin-yen Lin Cc: maciek swiech Signed-off-by: Stephen Boyd Reviewed-by: Rob Herring --- .../bindings/usb/realtek,rts5411.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/realtek,rts5411.yaml b/D= ocumentation/devicetree/bindings/usb/realtek,rts5411.yaml index f0784d2e86da..0874fc21f66f 100644 --- a/Documentation/devicetree/bindings/usb/realtek,rts5411.yaml +++ b/Documentation/devicetree/bindings/usb/realtek,rts5411.yaml @@ -21,6 +21,12 @@ properties: =20 reg: true =20 + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + vdd-supply: description: phandle to the regulator that provides power to the hub. @@ -30,6 +36,36 @@ properties: description: phandle to the peer hub on the controller. =20 + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: + 1st downstream facing USB port + + port@2: + $ref: /schemas/graph.yaml#/properties/port + description: + 2nd downstream facing USB port + + port@3: + $ref: /schemas/graph.yaml#/properties/port + description: + 3rd downstream facing USB port + + port@4: + $ref: /schemas/graph.yaml#/properties/port + description: + 4th downstream facing USB port + +patternProperties: + '^.*@[1-4]$': + description: The hard wired USB devices + type: object + $ref: /schemas/usb/usb-device.yaml + required: - peer-hub - compatible @@ -50,6 +86,13 @@ examples: reg =3D <1>; vdd-supply =3D <&pp3300_hub>; peer-hub =3D <&hub_3_0>; + #address-cells =3D <1>; + #size-cells =3D <0>; + /* USB 2.0 device on port 2 */ + device@2 { + compatible =3D "usb123,4567"; + reg =3D <2>; + }; }; =20 /* 3.0 hub on port 2 */ @@ -58,5 +101,17 @@ examples: reg =3D <2>; vdd-supply =3D <&pp3300_hub>; peer-hub =3D <&hub_2_0>; + + ports { + #address-cells =3D <1>; + #size-cells =3D <0>; + /* Type-A connector on port 4 */ + port@4 { + reg =3D <4>; + endpoint { + remote-endpoint =3D <&usb_a0_ss>; + }; + }; + }; }; }; --=20 https://chromeos.dev From nobody Sun Feb 8 09:26:54 2026 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 C50E5B642 for ; Fri, 23 Feb 2024 00:58:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708649911; cv=none; b=BNDjeJVkW9C/n1TogjJsNKM+zYz8tuh7cTtb0dB5OkYRO6J56clFONXHmM17tu/+LvdLEKAq/FcziO/VshZNgdsLWIbSWiYrOcFvmOfFJtfNN7ILaZbT96/yK9GAQXo3LkfASqoLQ4gUqK1wcSYNgnYe9UD2sVr2w7vFyXH3OPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708649911; c=relaxed/simple; bh=v27iEZktilH2OnIdu1MjAvZd2ZBk3RvhRJ0/3icnfgs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CH1ZVhBhlEfWVKKlBW+UYD3j2NI4oylFS/RtWsDa4XO1A0/xZFuvf5sSZ3WMu83ooNlKWhsrqbhfnJW5ml7j/ftgcNG/4W7ZEPw+9mn1u2Tvm0ekBk2nLImEylB1PZiR0LLpN46HOxCRJCb/GcM8Oy6oyNDV4VWW5fA1gg1XN1U= 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=YQP7kBy5; arc=none smtp.client-ip=209.85.216.47 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="YQP7kBy5" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-29951f5c2e7so326770a91.1 for ; Thu, 22 Feb 2024 16:58:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1708649909; x=1709254709; 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=UFIGIcteJ9nUdBATIDe99Xci9kTl4VUk6xpdoWZYz+c=; b=YQP7kBy5Xy3MOEWlVIcw/TuOWvCiTYhxMIIqKjBK770Lm1+Bik8jBQL77HFVwQzGgN cV4F/HZg+qPmiftfWx4MQUEJYRF17FZpqhRTHFivQcOSLw07Xr4/GEbKDP/TI+J4DaQi W5ggriQwi2juyi8Q+UMWoGVrIKTcuELuVaoRc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708649909; x=1709254709; 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=UFIGIcteJ9nUdBATIDe99Xci9kTl4VUk6xpdoWZYz+c=; b=g1M4KSRJ4wdHKA00YUz7P/yZkzaLyVyOGcuiQLu7134uaiAU/8e736FpWiftHo2NOB EOERYt8y6nH5abVnEXuqW5LZNh4dn+flN/8uZzAKdRLhVGHR2MzDdP4H8ySxMj23cPhQ tLxkhRiwSQo/IOBBmNBRd7P+0lySUiIFEzmc9qDXy7xK8jnAik67t8inIBqzHbQ+aufQ zx67FttI8anbpc7ct78V1j9epo2IWmb2nCAaqhh1SozImlXw9Xk50tM5ClaQyrD32bNg MLL0dHPB1Etj/rz+gfTnwuhUOsSbXvWAH4lV55yodU/47CvP66gVEIesBHxViYrIA2D5 uNiQ== X-Gm-Message-State: AOJu0YxFXotJsz8BxlPpGidPcNBsd4ii952EFZBGhwvRzwj2d3z5wtK2 VgQ7u4HrN48m4RRespbzK3ReGW6+7hXk7LtOUafhIsB5aTQxImL6YA/C2LaIrpxPfLtK05Th3zo = X-Google-Smtp-Source: AGHT+IEBSCPkUmGUKRjkDv90CVcgR82fYuR4QpNUMg52O6n0E9LSt3G7aVY3l3oPEr/4l3QpXW0TZw== X-Received: by 2002:a17:90a:5ae2:b0:299:4397:621c with SMTP id n89-20020a17090a5ae200b002994397621cmr440115pji.43.1708649909121; Thu, 22 Feb 2024 16:58:29 -0800 (PST) Received: from localhost (175.199.125.34.bc.googleusercontent.com. [34.125.199.175]) by smtp.gmail.com with UTF8SMTPSA id m21-20020a17090ab79500b00298e11b600dsm116430pjr.27.2024.02.22.16.58.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Feb 2024 16:58:28 -0800 (PST) From: Stephen Boyd To: Greg Kroah-Hartman , Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Herve Codina , Alan Stern , Heikki Krogerus , Roy Luo , Matthias Kaehlcke , linux-usb@vger.kernel.org, maciek swiech Subject: [PATCH v2 2/2] usb: core: Set connect_type of ports based on DT node Date: Thu, 22 Feb 2024 16:58:21 -0800 Message-ID: <20240223005823.3074029-3-swboyd@chromium.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240223005823.3074029-1-swboyd@chromium.org> References: <20240223005823.3074029-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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". ChromeOS userspace would like to know if the USB device is actually removable or not so that security policies can be applied. 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: Matthias Kaehlcke Cc: Cc: Cc: Pin-yen Lin Cc: maciek swiech Signed-off-by: Stephen Boyd --- drivers/usb/core/of.c | 71 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/core/port.c | 2 ++ include/linux/usb/of.h | 7 ++++ 3 files changed, 80 insertions(+) diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c index db4ccf9ce3d9..f1a499ee482c 100644 --- a/drivers/usb/core/of.c +++ b/drivers/usb/core/of.c @@ -8,6 +8,7 @@ */ =20 #include +#include #include =20 /** @@ -75,6 +76,76 @@ bool usb_of_has_combined_node(struct usb_device *udev) } EXPORT_SYMBOL_GPL(usb_of_has_combined_node); =20 +static bool usb_of_has_devices_or_graph(const struct usb_device *hub) +{ + const struct device_node *np =3D hub->dev.of_node; + struct device_node *child; + + if (of_graph_is_present(np)) + return true; + + for_each_child_of_node(np, child) + if (of_property_present(child, "reg")) + return true; + + return false; +} + +/** + * usb_of_get_connect_type() - get a USB hub's port connect_type + * @hub: hub to which port is for @port1 + * @port1: one-based index of port + * + * Get the connect_type of @port1 based on the device node for @hub. If the + * port is described in the OF graph, the connect_type is "hotplug". If the + * @hub has a child device has with a 'reg' property equal to @port1 the + * connect_type is "hard-wired". If there isn't an OF graph or child node = at + * all then the connect_type is "unknown". Otherwise, the port is consider= ed + * "unused" because it isn't described at all. + * + * Return: A connect_type for @port1 based on the device node for @hub. + */ +enum usb_port_connect_type usb_of_get_connect_type(struct usb_device *hub,= int port1) +{ + struct device_node *np, *child, *ep, *remote_np; + enum usb_port_connect_type connect_type; + + /* Only set connect_type if binding has ports/hardwired devices. */ + if (!usb_of_has_devices_or_graph(hub)) + return USB_PORT_CONNECT_TYPE_UNKNOWN; + + /* Assume port is unused if there's a graph or a child node. */ + connect_type =3D USB_PORT_NOT_USED; + + np =3D hub->dev.of_node; + /* + * Hotplug ports are connected to an available remote node, e.g. + * usb-a-connector compatible node, in the OF graph. + */ + if (of_graph_is_present(np)) { + ep =3D of_graph_get_endpoint_by_regs(np, port1, -1); + if (ep) { + remote_np =3D of_graph_get_remote_port_parent(ep); + of_node_put(ep); + if (of_device_is_available(remote_np)) + connect_type =3D USB_PORT_CONNECT_TYPE_HOT_PLUG; + of_node_put(remote_np); + } + } + + /* + * Hard-wired ports are child nodes with a reg property corresponding + * to the port number, i.e. a usb device. + */ + child =3D usb_of_get_device_node(hub, port1); + if (of_device_is_available(child)) + connect_type =3D USB_PORT_CONNECT_TYPE_HARD_WIRED; + of_node_put(child); + + return connect_type; +} +EXPORT_SYMBOL_GPL(usb_of_get_connect_type); + /** * usb_of_get_interface_node() - get a USB interface node * @udev: USB device of interface diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index c628c1abc907..da910d3e40f6 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -11,6 +11,7 @@ #include #include #include +#include =20 #include "hub.h" =20 @@ -708,6 +709,7 @@ int usb_hub_create_port_device(struct usb_hub *hub, int= port1) return -ENOMEM; } =20 + port_dev->connect_type =3D usb_of_get_connect_type(hdev, port1); hub->ports[port1 - 1] =3D port_dev; port_dev->portnum =3D port1; set_bit(port1, hub->power_bits); diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h index 98487fd7ab11..de42f14bd280 100644 --- a/include/linux/usb/of.h +++ b/include/linux/usb/of.h @@ -6,6 +6,7 @@ #ifndef __LINUX_USB_OF_H #define __LINUX_USB_OF_H =20 +#include #include #include #include @@ -17,6 +18,7 @@ enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_= node *np, int arg0); bool of_usb_host_tpl_support(struct device_node *np); int of_usb_update_otg_caps(struct device_node *np, struct usb_otg_caps *otg_caps); +enum usb_port_connect_type usb_of_get_connect_type(struct usb_device *hub,= int port1); struct device_node *usb_of_get_device_node(struct usb_device *hub, int por= t1); bool usb_of_has_combined_node(struct usb_device *udev); struct device_node *usb_of_get_interface_node(struct usb_device *udev, @@ -37,6 +39,11 @@ static inline int of_usb_update_otg_caps(struct device_n= ode *np, { return 0; } +static inline enum usb_port_connect_type +usb_of_get_connect_type(const struct usb_device *hub, int port1) +{ + return USB_PORT_CONNECT_TYPE_UNKNOWN; +} static inline struct device_node * usb_of_get_device_node(struct usb_device *hub, int port1) { --=20 https://chromeos.dev