From nobody Thu Oct 2 19:26:00 2025 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 B2B57273D6D for ; Thu, 11 Sep 2025 20:22:56 +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=1757622178; cv=none; b=hgVnF+0dLp3e2/yzoIEtJZlQgddkS36sl1tjhixz5sfsCfPMhJgj1X3kTt2Stfo19d5HmmRHreoc/gWc8oimK5ObuYUpi32pVHYNRHorRe+K0dG6Y21/r8LvNRYkU31hNyluna4CFCuE5/i6ei0VmSJVoHNTnaaUDX7pNs3L0rE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757622178; c=relaxed/simple; bh=NOqmee/dDD5cagjg4HvJgFuGnZ/TnFg8cXA8JExo+/s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Qwmxk+DMLZ/EgBVfnhkNUWPer9wLivJ+aZBYD/DvKQ+I83C6t4nt/2/QHjNXfzsbbkid0DsGDvkF/toWaj51BFdoUB256dkJx3OpaH13Bki1GO1QMsUu3DReoL3rCfxj+KBjIzIxDDOyBIYyyKNG7SSHGJgF6uQGiZSpUJmCQPc= 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 1uwnog-0005yg-JB; Thu, 11 Sep 2025 22:22:50 +0200 From: Marco Felsch Date: Thu, 11 Sep 2025 22:22:42 +0200 Subject: [PATCH v4 1/5] 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: <20250911-v6-16-topic-usb-onboard-dev-v4-1-1af288125d74@pengutronix.de> References: <20250911-v6-16-topic-usb-onboard-dev-v4-0-1af288125d74@pengutronix.de> In-Reply-To: <20250911-v6-16-topic-usb-onboard-dev-v4-0-1af288125d74@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 --- 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 f54198171b6a3fb49c5f74f4a8a303b422d099eb..cae08a9a71e65c42fb9a8f53690= 60bd82b8daebb 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 Oct 2 19:26:00 2025 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 389D2274666 for ; Thu, 11 Sep 2025 20:22:56 +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=1757622179; cv=none; b=nEwdle+tbvW86PyOdCxqyhxDwctsusnNhQ6FZPkAPHYBwDfSsTsQhljhjrEBp6cX7WTHAvBTduq6/A//0HHQ25m6rWrde4xgq3zalq94LQMh5Re5gtRNj/1bqpEl4yq3F7x8A37wZ7SeW5qgUU/3SvGg4wkg+1+ecSZ71FlligM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757622179; c=relaxed/simple; bh=mqB2Y48gPtHTzfdJ6YtGV87Inzqp8PZP5LW7ZF1aqCY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AAjhAnoKs+kUY0U5fFUjkcAxFfw0MBRxi0O+SkNAEswgP/xUhY+fd1VqGOtmpJd6ikIWoHTPhdox61MkGA0Sn/DfEyKM23aAg4ty89s2iC81swI4HiC7mcFO9gqOKsAEf4YGjeOPf8d7mAJpNollCfRO6brVIVg19DEMRYA9p/Q= 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 1uwnog-0005yg-L6; Thu, 11 Sep 2025 22:22:50 +0200 From: Marco Felsch Date: Thu, 11 Sep 2025 22:22:43 +0200 Subject: [PATCH v4 2/5] 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: <20250911-v6-16-topic-usb-onboard-dev-v4-2-1af288125d74@pengutronix.de> References: <20250911-v6-16-topic-usb-onboard-dev-v4-0-1af288125d74@pengutronix.de> In-Reply-To: <20250911-v6-16-topic-usb-onboard-dev-v4-0-1af288125d74@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 --- 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 256fe8c86828d51c33442345acdb7f3fe80a98ce..50ae500e2ad3711996609fc8480= 6803449a5bf16 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -457,9 +457,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 /* @@ -467,9 +477,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) @@ -6544,6 +6564,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 92c752f5446ff37ef09b9296f7711e1a622680ea..1415a826953ac5488619073e2f6= 59188f7988d6e 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -928,6 +928,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 Oct 2 19:26:00 2025 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 B2AEB27381E for ; Thu, 11 Sep 2025 20:22:56 +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=1757622178; cv=none; b=n2bsP++WFxa+dfllYRo93WO3GSkMZNWdpelP7xitMDUrgCnPxvgLKnwRI5MKKrT2oYkCSVBQIEhEYUQ3jGKtOHAu8Z1zIDG6vjQgbFIhIpiqEsoiaHuqn64bnbSnZuDCk0Xl78Ue4YRWAzN1gguZ6uL2RbnwsOfa7X4OO7wtJ4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757622178; c=relaxed/simple; bh=TXnmdDo5RUFYnHwQiJ5oW/Z1zuTGfz1ZHaRZcG0i0cs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GYl2+7YflH3ks836bo6CcwU+LnpEfR7LOpugObOEss0eN07f0OBmKfkQjCwBGt90kxSMJcZ762KSS4PAgDkpmwDtW9jTBSI7Llksy/uIhVp6MTW/vvlJE8h/PMs+OzQCtMLiBi41hZA9kLi62s+EOM1pOVZTJwna5UP/Nc5EaDw= 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 1uwnog-0005yg-Mv; Thu, 11 Sep 2025 22:22:50 +0200 From: Marco Felsch Date: Thu, 11 Sep 2025 22:22:44 +0200 Subject: [PATCH v4 3/5] 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: <20250911-v6-16-topic-usb-onboard-dev-v4-3-1af288125d74@pengutronix.de> References: <20250911-v6-16-topic-usb-onboard-dev-v4-0-1af288125d74@pengutronix.de> In-Reply-To: <20250911-v6-16-topic-usb-onboard-dev-v4-0-1af288125d74@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) --- Documentation/devicetree/bindings/usb/usb-device.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/usb-device.yaml b/Docume= ntation/devicetree/bindings/usb/usb-device.yaml index 09fceb469f10525e9dcdb91435b142b0d21964b8..2f891a05ab9bca095eb881c5f60= 1ac27ac63b542 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 controlls the USB hub port VBUS. Th= is + 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 --=20 2.47.3 From nobody Thu Oct 2 19:26:00 2025 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 8BDB82749C0 for ; Thu, 11 Sep 2025 20:22:57 +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=1757622179; cv=none; b=W4WVQb9s1n3Lsw7zbr1eL8KmRr/Foa0wEgYzVmVJdiEsqX8O7NbEVIKh5SrRkFgkEvZDV2nxbKoGkScn0nQKBnHnX5M7xszPtFEDBBzZIvkMrWndyhu3Z/pWNH0a0YzpvpiyNwSk4jSsv/gUd1b1ERJXxrC+JkDf4ksdfZ7UZSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757622179; c=relaxed/simple; bh=Zw3PY4gOi1NzQluz4bDnOsYHFqh5V0V48Y140HuOBmM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iCGF3f48elxhLLgHN6WEYig5jxP1/pNl5GTAkhJu4d3AiCPKMKKTDW9BYNS817agEtK1OQ3es3484kwZGnWzVXPgSanniyjp5i02zPoaksexBk1/5VuZiKXe92b7vfC8QCBdrrDyYsfn8JJ8XsG9yU38Mt7XiyYGTCcZKVQepO4= 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 1uwnog-0005yg-Oh; Thu, 11 Sep 2025 22:22:50 +0200 From: Marco Felsch Date: Thu, 11 Sep 2025 22:22:45 +0200 Subject: [PATCH v4 4/5] dt-bindings: usb: microchip,usb2514: add vbus-supply example 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: <20250911-v6-16-topic-usb-onboard-dev-v4-4-1af288125d74@pengutronix.de> References: <20250911-v6-16-topic-usb-onboard-dev-v4-0-1af288125d74@pengutronix.de> In-Reply-To: <20250911-v6-16-topic-usb-onboard-dev-v4-0-1af288125d74@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 Add an usb hub vbus-supply example to make it easier for users to understand the binding, after the usb-device.yaml gained the support for it. Signed-off-by: Marco Felsch --- Documentation/devicetree/bindings/usb/microchip,usb2514.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/microchip,usb2514.yaml b= /Documentation/devicetree/bindings/usb/microchip,usb2514.yaml index 4e3901efed3fcd4fbbd8cb777f9df4fcadf2ca00..9874bbd03e31fd7ff1c439eb860= a15617f147406 100644 --- a/Documentation/devicetree/bindings/usb/microchip,usb2514.yaml +++ b/Documentation/devicetree/bindings/usb/microchip,usb2514.yaml @@ -86,5 +86,12 @@ examples: compatible =3D "usbb95,772b"; reg =3D <1>; }; + + /* VBUS on the 2nd port is managed by the host */ + ethernet@2 { + compatible =3D "usbb95,772b"; + reg =3D <2>; + vbus-supply =3D <®_5v0_vbus>; + }; }; }; --=20 2.47.3 From nobody Thu Oct 2 19:26:00 2025 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 3B887274669 for ; Thu, 11 Sep 2025 20:22:56 +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=1757622179; cv=none; b=Arujg2rt/3/JvVdZoMJ9inzkGJKCZRs3iHGdnhxAciB8dcqQPmxeRrbHfqShuGrYPurIeFxVyfPKW7o9ORPi5+WcE9322NBpaeMV5JID2lXj8m+H/Wq1kiG1Xt5X9QxUV9cTzVFS6Q8E7gCD8Ke0Q1m+k6C/UAT0gvIpVBuvOSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757622179; c=relaxed/simple; bh=t3Qxwy3AnC9M50lFGea/MNR0jGvER4KJxcZ+31kFsDs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FXpiRafYw95PiX/dI89arcRu3vPNBuVd4yR1a66hJBh1CVKNln/x78jX4aOxI95pnEzk0cFUsxLZaCt/e7pBIh6WX6Z9fd4xaiaZKIITCzIgTO55oZrkfkHdx3TXeUhevowDFYuK8eplAc6t9rWq7v1Dm+6EhkkyT/UHPvFpeVE= 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 1uwnog-0005yg-QY; Thu, 11 Sep 2025 22:22:50 +0200 From: Marco Felsch Date: Thu, 11 Sep 2025 22:22:46 +0200 Subject: [PATCH v4 5/5] 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: <20250911-v6-16-topic-usb-onboard-dev-v4-5-1af288125d74@pengutronix.de> References: <20250911-v6-16-topic-usb-onboard-dev-v4-0-1af288125d74@pengutronix.de> In-Reply-To: <20250911-v6-16-topic-usb-onboard-dev-v4-0-1af288125d74@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 --- 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 5b481876af1b2c10ce625fcf0fb8bfbe8905aa8c..1ceea75d30d320e5d2203c768b9= 641876ebd37ad 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 @@ -573,6 +649,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. @@ -632,6 +746,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