From nobody Thu Apr 2 09:18:57 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A22A134E75E for ; Mon, 23 Feb 2026 11:27:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771846067; cv=none; b=BG9TRQPRcwGj1prG0E3Hj+wbAxzaQmwwqMKy7TYRkA3BWlgqvOBtQvmyLtv1fEijwU34gM4jcvt4IlpDQ21IdBfadMUJdcEFBMC81vueVcbESeX81e5vsMLMNVdiYpr4uDDzuIncw32lI1T0H1sozkUi3OyGBQCx58pWOQGBiK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771846067; c=relaxed/simple; bh=lpw5HGx1Ps1o3mWsL+UrALhOcYvde4wFeFOH4IdFpmU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qYxYvavexkLoocbtZI/G67grKoMd+4Bzj9RxhfFefFVqdAPHpQJwE6KQ+QQWXy36C5cUlkxsyowaRMqdyf9TbvmoDVnR+ckTMhe+PjFg+QcENZiQgQV1WIeHwsUIOhENGYIc/zhh/9ZJJ1cU07RPrNy6+NsNpjr68+y6LXYEUj4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vuU6C-0007VH-6E; Mon, 23 Feb 2026 12:27:36 +0100 From: Marco Felsch Date: Mon, 23 Feb 2026 12:27:34 +0100 Subject: [PATCH v5 1/4] usb: port: track the disabled state Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260223-v6-16-topic-usb-onboard-dev-v5-1-28d3018a8026@pengutronix.de> References: <20260223-v6-16-topic-usb-onboard-dev-v5-0-28d3018a8026@pengutronix.de> In-Reply-To: <20260223-v6-16-topic-usb-onboard-dev-v5-0-28d3018a8026@pengutronix.de> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Fabio Estevam , Matthias Kaehlcke , Liam Girdwood , Mark Brown Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, Marco Felsch X-Mailer: b4 0.14.2 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org The disable state isn't tracked at the moment, instead the state is directly passed to the hub driver. Change this behavior to only trigger the hub if a state change happened. Exit early in case of no state changes but don't return an error. Signed-off-by: Marco Felsch Tested-by: Ze Huang --- drivers/usb/core/hub.h | 2 ++ drivers/usb/core/port.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 9ebc5ef54a325d63e01b0deb59a1853d2b13c8d5..297adf2c6078809ca582104f228= e5222c464f999 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h @@ -97,6 +97,7 @@ struct usb_hub { * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted. * @early_stop: whether port initialization will be stopped earlier. * @ignore_event: whether events of the port are ignored. + * @disabled: whether the port is disabled */ struct usb_port { struct usb_device *child; @@ -118,6 +119,7 @@ struct usb_port { unsigned int is_superspeed:1; unsigned int usb3_lpm_u1_permit:1; unsigned int usb3_lpm_u2_permit:1; + unsigned int disabled:1; }; =20 #define to_usb_port(_dev) \ diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index 44e38f922bc553adee64b35c536dfd4154a42d8a..86e9d6d0c0f505782569565fde8= e4a46b06b8b4d 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -117,6 +117,10 @@ static ssize_t disable_store(struct device *dev, struc= t device_attribute *attr, if (rc) return rc; =20 + /* Early quit if no change was detected */ + if (port_dev->disabled =3D=3D disabled) + return count; + hub_get(hub); rc =3D usb_autopm_get_interface(intf); if (rc < 0) @@ -148,6 +152,8 @@ static ssize_t disable_store(struct device *dev, struct= device_attribute *attr, usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_ENABLE); } =20 + port_dev->disabled =3D disabled; + if (!rc) rc =3D count; =20 --=20 2.47.3 From nobody Thu Apr 2 09:18:57 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2707435B65F for ; Mon, 23 Feb 2026 11:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771846068; cv=none; b=MeEq/S8X/gedmKtqVChaKI86Ey7B9jIChcsMoZxDeoPGrGltV33gkpdBJmO7uDLFuApRHWvC5AuZYeDQICFIw1uHtAkUbGeZJ2WydTn80TcCngbU2CqYK4nbSla/hf07fWUFHmLgQcudB4mtBk4EBh0CB62CGTy6OHbdE+hJ6Jo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771846068; c=relaxed/simple; bh=iiju3CLfKh8GuTQUBQJ/jbKACfrd1x+FVzb9ZYuX1+Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DEhBB2gtg4SGJ5jAK2wneXRNBFFlAw5tRH+tsqTHKTHDKQu+TU8WQRaIs4Jg01oqH36VF4l/2md6sUIojh7beb3z5NVvI7lrdrRZuaxUSeB6gK8nYCk6jJaXvKDjEl2hN04ZmvlZnU5UvyWB7lQXN7V4MpL4Khsi3yGTWNiKF+Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vuU6C-0007VH-89; Mon, 23 Feb 2026 12:27:36 +0100 From: Marco Felsch Date: Mon, 23 Feb 2026 12:27:35 +0100 Subject: [PATCH v5 2/4] usb: hub: add infrastructure to pass onboard_dev port features Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260223-v6-16-topic-usb-onboard-dev-v5-2-28d3018a8026@pengutronix.de> References: <20260223-v6-16-topic-usb-onboard-dev-v5-0-28d3018a8026@pengutronix.de> In-Reply-To: <20260223-v6-16-topic-usb-onboard-dev-v5-0-28d3018a8026@pengutronix.de> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Fabio Estevam , Matthias Kaehlcke , Liam Girdwood , Mark Brown Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, Marco Felsch X-Mailer: b4 0.14.2 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org On board devices may require special handling for en-/disable port features due to PCB design decisions e.g. enable/disable the VBUS power on the port via a host controlled regulator or GPIO. This commit adds the necessary infrastructure to prepare the common code base for such use-cases. Signed-off-by: Marco Felsch Tested-by: Ze Huang --- drivers/usb/core/hub.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++= ++-- drivers/usb/core/hub.h | 2 ++ include/linux/usb.h | 3 +++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 24960ba9caa915f12a4f5582269808fdebd1ee11..9fdfd2f0aacc9b1994cd3761330= 968e052167c67 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -453,9 +453,19 @@ static int clear_hub_feature(struct usb_device *hdev, = int feature) */ int usb_clear_port_feature(struct usb_device *hdev, int port1, int feature) { - return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), + struct usb_hub *hub =3D usb_hub_to_struct_hub(hdev); + int ret; + + ret =3D usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port1, NULL, 0, 1000); + if (ret) + return ret; + + if (hub->onboard_hub_clear_port_feature) + ret =3D hub->onboard_hub_clear_port_feature(hdev, feature, port1); + + return ret; } =20 /* @@ -463,9 +473,19 @@ int usb_clear_port_feature(struct usb_device *hdev, in= t port1, int feature) */ static int set_port_feature(struct usb_device *hdev, int port1, int featur= e) { - return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), + struct usb_hub *hub =3D usb_hub_to_struct_hub(hdev); + int ret; + + ret =3D usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), USB_REQ_SET_FEATURE, USB_RT_PORT, feature, port1, NULL, 0, 1000); + if (ret) + return ret; + + if (hub->onboard_hub_set_port_feature) + ret =3D hub->onboard_hub_set_port_feature(hdev, feature, port1); + + return ret; } =20 static char *to_led_name(int selector) @@ -6545,6 +6565,37 @@ void usb_hub_adjust_deviceremovable(struct usb_devic= e *hdev, } } =20 +/** + * usb_hub_register_port_feature_hooks - Register port set/get feature hoo= ks + * @hdev: USB device belonging to the usb hub + * @set_port_feature: set_feature hook which gets called by the hub core + * @clear_port_feature: clear_feature hook which gets called by the hub co= re + * + * Register set/get_port_feature hooks for a onboard_dev hub. + */ +void usb_hub_register_port_feature_hooks(struct usb_device *hdev, + int (*set_port_feature)(struct usb_device *, int, int), + int (*clear_port_feature)(struct usb_device *, int, int)) +{ + struct usb_hub *hub =3D usb_hub_to_struct_hub(hdev); + + if (WARN_ON_ONCE(is_root_hub(hdev) || !hub)) + return; + + if (set_port_feature) + hub->onboard_hub_set_port_feature =3D set_port_feature; + if (clear_port_feature) + hub->onboard_hub_clear_port_feature =3D clear_port_feature; + + /* + * Keep it simple for now. Just check the power state and re-sync it + * after adding the hooks since the onboard-dev may do some additional + * logic e.g. controlling regulators. + */ + hub_power_on(hub, false); +} +EXPORT_SYMBOL_GPL(usb_hub_register_port_feature_hooks); + #ifdef CONFIG_ACPI /** * usb_get_hub_port_acpi_handle - Get the usb port's acpi handle diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 297adf2c6078809ca582104f228e5222c464f999..31800b5922ba896dc7cac5f9e3e= d1a77e7c5a801 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h @@ -76,6 +76,8 @@ struct usb_hub { struct timer_list irq_urb_retry; struct usb_port **ports; struct list_head onboard_devs; + int (*onboard_hub_set_port_feature)(struct usb_device *udev, int feature,= int port1); + int (*onboard_hub_clear_port_feature)(struct usb_device *udev, int featur= e, int port1); }; =20 /** diff --git a/include/linux/usb.h b/include/linux/usb.h index fbfcc70b07fbe5dbaa1ca1be55af127c62294cf7..5f68a066029ea0508fad461daf7= ebe6f534778d2 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -946,6 +946,9 @@ int usb_hub_claim_port(struct usb_device *hdev, unsigne= d port1, struct usb_dev_state *owner); int usb_hub_release_port(struct usb_device *hdev, unsigned port1, struct usb_dev_state *owner); +void usb_hub_register_port_feature_hooks(struct usb_device *hdev, + int (*set_port_feature)(struct usb_device *, int, int), + int (*clear_port_feature)(struct usb_device *, int, int)); =20 /** * usb_make_path - returns stable device path in the usb tree --=20 2.47.3 From nobody Thu Apr 2 09:18:57 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F99134DCCC for ; Mon, 23 Feb 2026 11:27:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771846067; cv=none; b=jARb2A0BhkJ+wmGrpnIi4P5BekcL/u9iSjoYnBGHCy0yvtzN2uE7nqwjCOHtkbD++FovPIeLOZkwaYMr7R7SDDG0MFQaH72a4c2XS3oXbwlCFPxYMIDf6IJWUKy4grEegsjOyjKe661kozt/KVtncWZNGHbLZe2GTc/HaTMOcQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771846067; c=relaxed/simple; bh=X99J4EYETaDcZTtHLmSJ/pCmG96o3v4GJbDAz+8Lxno=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kgPLJ58EA0ZBaEj1l8XGvkY3CrrbT74c+babUcolZTIJ3pyhxAdLJf90NhKADSC9zgCH+FkEFCnNph7nnn8g1o6sahaob1pZ3jiE1Bfz4ci4AkZwYL4ate95M1T67DS7uyf/VXbUxurLT1y5F2QSulKqfBqNo45OXhwyWv7KaTE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vuU6C-0007VH-9v; Mon, 23 Feb 2026 12:27:36 +0100 From: Marco Felsch Date: Mon, 23 Feb 2026 12:27:36 +0100 Subject: [PATCH v5 3/4] dt-bindings: usb: usb-device: add usb hub port vbus-supply suppport Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260223-v6-16-topic-usb-onboard-dev-v5-3-28d3018a8026@pengutronix.de> References: <20260223-v6-16-topic-usb-onboard-dev-v5-0-28d3018a8026@pengutronix.de> In-Reply-To: <20260223-v6-16-topic-usb-onboard-dev-v5-0-28d3018a8026@pengutronix.de> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Fabio Estevam , Matthias Kaehlcke , Liam Girdwood , Mark Brown Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, Marco Felsch X-Mailer: b4 0.14.2 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Some PCB designs don't use the dedicated USB hub port power control GPIO to control the port VBUS supply. Instead host managed GPIOs are used to control the VBUS supply. Signed-off-by: Marco Felsch Reviewed-by: Rob Herring (Arm) Tested-by: Ze Huang --- Documentation/devicetree/bindings/usb/usb-device.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/usb-device.yaml b/Docume= ntation/devicetree/bindings/usb/usb-device.yaml index 09fceb469f10525e9dcdb91435b142b0d21964b8..c9abdbea0e5348dc25f8f948414= 2089cf60bd514 100644 --- a/Documentation/devicetree/bindings/usb/usb-device.yaml +++ b/Documentation/devicetree/bindings/usb/usb-device.yaml @@ -53,6 +53,12 @@ properties: "#size-cells": const: 0 =20 + vbus-supply: + description: USB hub port VBUS supply. + The host managed regulator which controls the USB hub port VBUS. This + regulator is only required if the hub internal control signals aren't + used to control the VBUS regulators. + patternProperties: "^interface@[0-9a-f]{1,2}(,[0-9a-f]{1,2})$": type: object @@ -85,6 +91,7 @@ additionalProperties: true =20 examples: # hub connected to port 1 + # device connected to hub port 2, vbus controlled by ext. regulator # device connected to port 2 # device connected to port 3 # interface 0 of configuration 1 @@ -99,6 +106,14 @@ examples: hub@1 { compatible =3D "usb5e3,608"; reg =3D <1>; + #address-cells =3D <1>; + #size-cells =3D <0>; + + device@2 { + compatible =3D "usb123,4321"; + reg =3D <2>; + vbus-supply =3D <®_5v0_vbus>; + }; }; =20 device@2 { --=20 2.47.3 From nobody Thu Apr 2 09:18:57 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F7AD3612DD for ; Mon, 23 Feb 2026 11:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771846068; cv=none; b=jkdzUbQHsX3L7n721WRpbHF74ysRI2UCf3hijGTrBIPA5/rReHxkYGMHjX0l/9XWrtex6nPGNLCA8+MURAydyE0QGC1CHq8XdSfhAUX9TEAynDpyZQh2sy35U8sqOXns8WGBZ2vqWY8/w4AWSg7layTqdIwnjyZUpq15lT7hSkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771846068; c=relaxed/simple; bh=/rPohQ6TXJYWjnUd8ydj76Hnm4lZ3mw82jkARppAjUw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WddeesjPgBYLZT+VcLycF629hl3u1jOr78KqJKTRjnw3+s7/78S6QAvnQSjfWXZp/YMyClYk2cg6cUBIbCJwXK3QbvguG8KbU47vE/E3gNTJy7jDmsORx0o0tu0nhRcX46mBnAwFRPSKDcD2fmYmq5LoaJK9o60whktFiPQYvLs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vuU6C-0007VH-Be; Mon, 23 Feb 2026 12:27:36 +0100 From: Marco Felsch Date: Mon, 23 Feb 2026 12:27:37 +0100 Subject: [PATCH v5 4/4] usb: misc: onboard_dev: add hub downstream port host vbus-supply handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260223-v6-16-topic-usb-onboard-dev-v5-4-28d3018a8026@pengutronix.de> References: <20260223-v6-16-topic-usb-onboard-dev-v5-0-28d3018a8026@pengutronix.de> In-Reply-To: <20260223-v6-16-topic-usb-onboard-dev-v5-0-28d3018a8026@pengutronix.de> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Fabio Estevam , Matthias Kaehlcke , Liam Girdwood , Mark Brown Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, Marco Felsch X-Mailer: b4 0.14.2 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Some PCB designs don't use the dedicated USB hub port power GPIOs. Instead they route the signals to the host. So the host is in charge to power the VBUS supplies. As first step the USB hub OF information is parsed and possible optional vbus-supply regulators are added. This is done during the platform driver probe() function. Afterwards, during the usb driver probe() function and in case this is an USB hub, the set/clear features hooks are registered via the new usb_hub_register_port_feature_hooks(). After this registration all generic usb hub set/clear features calls are passed to the onboard_dev driver too. This allows the driver to en-/disable the regulators. Signed-off-by: Marco Felsch Tested-by: Ze Huang --- drivers/usb/misc/onboard_usb_dev.c | 117 +++++++++++++++++++++++++++++++++= ++++ 1 file changed, 117 insertions(+) diff --git a/drivers/usb/misc/onboard_usb_dev.c b/drivers/usb/misc/onboard_= usb_dev.c index ba37eb99efbaf5237d4998a0fdb1c65b56628f2b..41274e0fdfa3e4da53ebef58e58= 5d0aeb9cbab08 100644 --- a/drivers/usb/misc/onboard_usb_dev.c +++ b/drivers/usb/misc/onboard_usb_dev.c @@ -54,6 +54,12 @@ struct usbdev_node { struct list_head list; }; =20 +struct onboard_dev_port_regulator { + struct regulator *vbus_supply; + unsigned int port; + struct list_head list; +}; + struct onboard_dev { struct regulator_bulk_data supplies[MAX_SUPPLIES]; struct device *dev; @@ -65,6 +71,7 @@ struct onboard_dev { struct list_head udev_list; struct mutex lock; struct clk *clk; + struct list_head ext_vbus_supplies; }; =20 static int onboard_dev_get_regulators(struct onboard_dev *onboard_dev) @@ -226,6 +233,71 @@ static int onboard_dev_add_usbdev(struct onboard_dev *= onboard_dev, return err; } =20 +static int onboard_dev_port_power(struct onboard_dev *onboard_dev, int por= t1, + bool enable) +{ + struct onboard_dev_port_regulator *regulator; + struct regulator *vbus_supply =3D NULL; + + list_for_each_entry(regulator, &onboard_dev->ext_vbus_supplies, list) { + if (regulator->port =3D=3D port1) { + vbus_supply =3D regulator->vbus_supply; + break; + } + } + + /* External supplies are optional, return no error */ + if (!vbus_supply) + return 0; + + if (enable) + return regulator_enable(vbus_supply); + + return regulator_disable(vbus_supply); +} + +static int onboard_dev_add_ext_vbus_supplies(struct onboard_dev *onboard_d= ev) +{ + struct device *dev =3D onboard_dev->dev; + + if (!onboard_dev->pdata->is_hub) + return 0; + + INIT_LIST_HEAD(&onboard_dev->ext_vbus_supplies); + + for_each_child_of_node_scoped(dev->of_node, child) { + struct onboard_dev_port_regulator *regulator; + struct regulator *port_supply; + u32 port; + + port_supply =3D devm_of_regulator_get_optional(dev, child, "vbus"); + if (IS_ERR(port_supply)) { + if (PTR_ERR(port_supply) =3D=3D -ENODEV) + continue; + return PTR_ERR(port_supply); + } + + /* + * The VBUS of this downstream port is controlled by a host + * managed regulator + */ + if (of_property_read_u32(child, "reg", &port)) { + dev_err(dev, "Failed to parse USB device reg property\n"); + return -EINVAL; + } + + regulator =3D devm_kzalloc(dev, sizeof(*regulator), GFP_KERNEL); + if (!regulator) + return -ENOMEM; + + regulator->vbus_supply =3D port_supply; + regulator->port =3D port; + list_add(®ulator->list, &onboard_dev->ext_vbus_supplies); + } + + return 0; +} + static void onboard_dev_remove_usbdev(struct onboard_dev *onboard_dev, const struct usb_device *udev) { @@ -460,6 +532,10 @@ static int onboard_dev_probe(struct platform_device *p= dev) return dev_err_probe(dev, PTR_ERR(onboard_dev->reset_gpio), "failed to get reset GPIO\n"); =20 + err =3D onboard_dev_add_ext_vbus_supplies(onboard_dev); + if (err) + return dev_err_probe(dev, err, "failed to parse port vbus supplies\n"); + mutex_init(&onboard_dev->lock); INIT_LIST_HEAD(&onboard_dev->udev_list); =20 @@ -574,6 +650,44 @@ static struct platform_driver onboard_dev_driver =3D { #define VENDOR_ID_VIA 0x2109 #define VENDOR_ID_XMOS 0x20B1 =20 +static int onboard_dev_port_feature(struct usb_device *udev, bool set, + int feature, int port1) +{ + struct device *dev =3D &udev->dev; + struct onboard_dev *onboard_dev =3D dev_get_drvdata(dev); + + /* + * Check usb_hub_register_port_feature_hooks() if you want to extent + * the list of handled features. At the moment only power is synced + * after adding the hook. + */ + switch (feature) { + case USB_PORT_FEAT_POWER: + return onboard_dev_port_power(onboard_dev, port1, set); + default: + return 0; + } +} + +static int +onboard_dev_set_port_feature(struct usb_device *udev, int feature, int por= t1) +{ + return onboard_dev_port_feature(udev, true, feature, port1); +} + +static int +onboard_dev_clear_port_feature(struct usb_device *udev, int feature, int p= ort1) +{ + return onboard_dev_port_feature(udev, false, feature, port1); +} + +static void +onboard_dev_register_hub_hooks(struct usb_device *udev) +{ + usb_hub_register_port_feature_hooks(udev, onboard_dev_set_port_feature, + onboard_dev_clear_port_feature); +} + /* * Returns the onboard_dev platform device that is associated with the USB * device passed as parameter. @@ -633,6 +747,9 @@ static int onboard_dev_usbdev_probe(struct usb_device *= udev) =20 dev_set_drvdata(dev, onboard_dev); =20 + if (onboard_dev->pdata->is_hub) + onboard_dev_register_hub_hooks(udev); + err =3D onboard_dev_add_usbdev(onboard_dev, udev); if (err) return err; --=20 2.47.3