From nobody Thu Oct 9 08:16:05 2025 Received: from finn.localdomain (finn.gateworks.com [108.161.129.64]) (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 7FDC828682 for ; Wed, 18 Jun 2025 21:50:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=108.161.129.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750283406; cv=none; b=Os4Hc88U0Euudi+5cbzj9uIXfE3Q+MAPDmbAZXjxzJzudXy9qy7Dyn2tHH0U134I8BacpdQ6Gp0ujc3qlLP3nMm8s4xUP8CKcVcTt3SCofK5xPv6jv6yg2Cft0IeMvyDrdfreNxm9vY0Q1aD9vpKr9D+nAeoCqE5qsUajpcgIIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750283406; c=relaxed/simple; bh=lmytkayaHXHHnnkVZO//4fm3YitzDT4IQzdaHgfv6qM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FOafzYsHHsndgPztYqVw3HGd0wfcTsp50xdzMLoGDowtWjnDmSUCgt6VLZK9e/JXV+uPNqrJH+rajf6LTKlv5kPG71/WfduQcGi+8ILNkCLfWy4HEngMeORyBkpX85WKCXs14cUj0jHiKdwSUI96HzH4rtFO/635Qyv6Cgs38IQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gateworks.com; spf=pass smtp.mailfrom=gateworks.com; arc=none smtp.client-ip=108.161.129.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gateworks.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gateworks.com Received: from syn-068-189-091-139.biz.spectrum.com ([68.189.91.139] helo=tharvey.pdc.gateworks.com) by finn.localdomain with esmtp (Exim 4.95) (envelope-from ) id 1uS0Do-007yeJ-8r; Wed, 18 Jun 2025 21:21:28 +0000 From: Tim Harvey To: Stefano Babic , Fabio Estevam , "NXP i.MX U-Boot Team" , Tim Harvey , Tom Rini , Marek Vasut , u-boot@lists.denx.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/2] usb: common: allow dr_mode to come from gpio-id based usb-connector Date: Wed, 18 Jun 2025 14:21:19 -0700 Message-Id: <20250618212120.1548575-2-tharvey@gateworks.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250618212120.1548575-1-tharvey@gateworks.com> References: <20250618212120.1548575-1-tharvey@gateworks.com> 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" If a usb host with dr_mode of "otg" has a usb-connector using a GPIO ID pin use this to determine host vs peripheral. Signed-off-by: Tim Harvey --- drivers/usb/common/common.c | 96 ++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index 13e9a61072a9..1e5f9620e6b1 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -8,6 +8,7 @@ =20 #include #include +#include #include #include #include @@ -22,6 +23,99 @@ static const char *const usb_dr_modes[] =3D { [USB_DR_MODE_OTG] =3D "otg", }; =20 +/** + * get_remote_node_from_graph - Resolve the remote node from a graph bindi= ng + * @node: Starting ofnode (e.g., connector) + * @port_id: Port unit address (e.g., 0 for port@0, or -1 for first port) + * @endpoint_id: Endpoint unit address (e.g., 0 for endpoint@0, or -1 for = first endpoint) + * Return: ofnode of the remote node, or ofnode_null() on failure + */ +static ofnode get_remote_node_from_graph(ofnode node, int port_id, int end= point_id) +{ + ofnode port_node, endpoint_node, remote_node; + u32 phandle_value; + char port_name[16]; + char endpoint_name[16]; + + /* Validate the starting node */ + if (!ofnode_valid(node)) { + printf("Invalid starting node\n"); + return ofnode_null(); + } + + /* Construct port name (e.g., "port" or "port@0") */ + if (port_id =3D=3D -1) + strcpy(port_name, "port"); + else + snprintf(port_name, sizeof(port_name), "port@%d", port_id); + + /* Find the port node */ + port_node =3D ofnode_find_subnode(node, port_name); + if (!ofnode_valid(port_node)) { + printf("No '%s' node found\n", port_name); + return ofnode_null(); + } + + /* Construct endpoint name (e.g., "endpoint" or "endpoint@0") */ + if (endpoint_id =3D=3D -1) + strcpy(endpoint_name, "endpoint"); + else + snprintf(endpoint_name, sizeof(endpoint_name), "endpoint@%d", endpoint_i= d); + + /* Find the endpoint node */ + endpoint_node =3D ofnode_find_subnode(port_node, endpoint_name); + if (!ofnode_valid(endpoint_node)) { + printf("No '%s' node found under '%s'\n", endpoint_name, port_name); + return ofnode_null(); + } + + /* Read the remote-endpoint phandle */ + phandle_value =3D ofnode_read_u32_default(endpoint_node, "remote-endpoint= ", 0); + if (phandle_value =3D=3D 0) { + printf("No valid 'remote-endpoint' phandle in '%s'\n", endpoint_name); + return ofnode_null(); + } + + /* Resolve the phandle to the remote node */ + remote_node =3D ofnode_get_by_phandle(phandle_value); + if (!ofnode_valid(remote_node)) { + printf("Failed to resolve phandle %u\n", phandle_value); + return ofnode_null(); + } + + return remote_node; +} + +static enum usb_dr_mode get_connector_drmode(ofnode node) +{ + struct gpio_desc id; + enum usb_dr_mode dr_mode =3D USB_DR_MODE_OTG; + ofnode conn; + + /* get remote endpoint */ + conn =3D get_remote_node_from_graph(node, -1, -1); + /* get port endpoint */ + if (ofnode_valid(conn)) + conn =3D ofnode_get_parent(conn); + /* get connector */ + if (ofnode_valid(conn)) + conn =3D ofnode_get_parent(conn); + if (ofnode_valid(conn) && + ofnode_device_is_compatible(conn, "gpio-usb-b-connector") && + !gpio_request_by_name_nodev(conn, "id-gpios", 0, &id, GPIOD_IS_IN)) { + if (dm_gpio_get_value(&id)) + dr_mode =3D USB_DR_MODE_PERIPHERAL; + else + dr_mode =3D USB_DR_MODE_HOST; + gpio_free_list_nodev(&id, 1); + pr_debug("%s got dr_mode from connector %s dr_mode=3D%s\n", __func__, + ofnode_get_name(node), + dr_mode =3D=3D USB_DR_MODE_HOST ? "host" : "peripheral"); + } + + return dr_mode; +} + enum usb_dr_mode usb_get_dr_mode(ofnode node) { const char *dr_mode; @@ -35,7 +129,7 @@ enum usb_dr_mode usb_get_dr_mode(ofnode node) =20 for (i =3D 0; i < ARRAY_SIZE(usb_dr_modes); i++) if (!strcmp(dr_mode, usb_dr_modes[i])) - return i; + return (i =3D=3D USB_DR_MODE_OTG) ? get_connector_drmode(node) : i; =20 return USB_DR_MODE_UNKNOWN; } --=20 2.25.1 From nobody Thu Oct 9 08:16:05 2025 Received: from finn.localdomain (finn.gateworks.com [108.161.129.64]) (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 B56A927F00E for ; Wed, 18 Jun 2025 21:50:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=108.161.129.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750283411; cv=none; b=ANxgqd/Pxt7fJ0B3mIHRuR3b63y3Wsn5Ux69a1HY+1FxkgAAy3BZqeKAsrthpne83WQbqLxLPZ4ZPuvDoFTVoOf9ndwl0l9PkcigaKsTAAK0F8e7M6BTtAE2CpYS6gPYA8hdeQ0sSAKX9IAPf/5Ah6FtxH+4TdvwnWbQN3T5srI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750283411; c=relaxed/simple; bh=dtSUcDXA9gLdrVobI3l+4mncrd5DHqbn5H1MnslcNw4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TNVKZ4R96YW+ohmcRaHQIM8GnDRt2KDGaxxyHhl0SOEG6uBo1KGHcL4uXhUz/urgPjb9NARplxWWVhVnM8xuo4hZ4y5O96roqEXYiK87n/eN1dhbOBwWdnFNYygqtJLognWgn4XGi2G0P2AzCq7OpEUxVMepQ1oM2nPwTWWNjU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gateworks.com; spf=pass smtp.mailfrom=gateworks.com; arc=none smtp.client-ip=108.161.129.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gateworks.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gateworks.com Received: from syn-068-189-091-139.biz.spectrum.com ([68.189.91.139] helo=tharvey.pdc.gateworks.com) by finn.localdomain with esmtp (Exim 4.95) (envelope-from ) id 1uS0Do-007yeJ-UB; Wed, 18 Jun 2025 21:21:29 +0000 From: Tim Harvey To: Stefano Babic , Fabio Estevam , "NXP i.MX U-Boot Team" , Tim Harvey , Tom Rini , Marek Vasut , u-boot@lists.denx.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/2] imx8mp-venice: enable USB device mode Date: Wed, 18 Jun 2025 14:21:20 -0700 Message-Id: <20250618212120.1548575-3-tharvey@gateworks.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250618212120.1548575-1-tharvey@gateworks.com> References: <20250618212120.1548575-1-tharvey@gateworks.com> 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" Now that we can determine device role via a usb-connector ID pin, remove the host-only mode dt override and enable additional USB device mode support. Signed-off-by: Tim Harvey --- arch/arm/dts/imx8mp-venice-gw71xx-2x-u-boot.dtsi | 5 ----- arch/arm/dts/imx8mp-venice-gw72xx-2x-u-boot.dtsi | 5 ----- arch/arm/dts/imx8mp-venice-gw73xx-2x-u-boot.dtsi | 5 ----- arch/arm/dts/imx8mp-venice-gw74xx-u-boot.dtsi | 5 ----- configs/imx8mp_venice_defconfig | 7 +++++++ 5 files changed, 7 insertions(+), 20 deletions(-) diff --git a/arch/arm/dts/imx8mp-venice-gw71xx-2x-u-boot.dtsi b/arch/arm/dt= s/imx8mp-venice-gw71xx-2x-u-boot.dtsi index a291b7abab62..c1d21e51c4e6 100644 --- a/arch/arm/dts/imx8mp-venice-gw71xx-2x-u-boot.dtsi +++ b/arch/arm/dts/imx8mp-venice-gw71xx-2x-u-boot.dtsi @@ -54,8 +54,3 @@ line-name =3D "pci_wdis#"; }; }; - -/* gpio-usb-con not supported yet in U-Boot so make this a host for now */ -&usb_dwc3_0 { - dr_mode =3D "host"; -}; diff --git a/arch/arm/dts/imx8mp-venice-gw72xx-2x-u-boot.dtsi b/arch/arm/dt= s/imx8mp-venice-gw72xx-2x-u-boot.dtsi index bdf5370fcdf6..9f6d05fdae0c 100644 --- a/arch/arm/dts/imx8mp-venice-gw72xx-2x-u-boot.dtsi +++ b/arch/arm/dts/imx8mp-venice-gw72xx-2x-u-boot.dtsi @@ -89,8 +89,3 @@ line-name =3D "pci_wdis#"; }; }; - -/* gpio-usb-con not supported yet in U-Boot so make this a host for now */ -&usb_dwc3_0 { - dr_mode =3D "host"; -}; diff --git a/arch/arm/dts/imx8mp-venice-gw73xx-2x-u-boot.dtsi b/arch/arm/dt= s/imx8mp-venice-gw73xx-2x-u-boot.dtsi index 7e6f66bd9dd9..3b23802e9a7d 100644 --- a/arch/arm/dts/imx8mp-venice-gw73xx-2x-u-boot.dtsi +++ b/arch/arm/dts/imx8mp-venice-gw73xx-2x-u-boot.dtsi @@ -95,8 +95,3 @@ line-name =3D "pci_wdis#"; }; }; - -/* gpio-usb-con not supported yet in U-Boot so make this a host for now */ -&usb_dwc3_0 { - dr_mode =3D "host"; -}; diff --git a/arch/arm/dts/imx8mp-venice-gw74xx-u-boot.dtsi b/arch/arm/dts/i= mx8mp-venice-gw74xx-u-boot.dtsi index 95f5f15e742a..a82ce5a19788 100644 --- a/arch/arm/dts/imx8mp-venice-gw74xx-u-boot.dtsi +++ b/arch/arm/dts/imx8mp-venice-gw74xx-u-boot.dtsi @@ -250,8 +250,3 @@ &wdog1 { bootph-pre-ram; }; - -/* gpio-usb-con not supported yet in U-Boot so make this a host for now */ -&usb_dwc3_0 { - dr_mode =3D "host"; -}; diff --git a/configs/imx8mp_venice_defconfig b/configs/imx8mp_venice_defcon= fig index 158ce4327488..2c9c6e5564fc 100644 --- a/configs/imx8mp_venice_defconfig +++ b/configs/imx8mp_venice_defconfig @@ -70,6 +70,7 @@ CONFIG_CMD_I2C=3Dy CONFIG_CMD_MMC=3Dy CONFIG_CMD_PCI=3Dy CONFIG_CMD_USB=3Dy +CONFIG_CMD_USB_MASS_STORAGE=3Dy CONFIG_CMD_CAT=3Dy CONFIG_CMD_SETEXPR_FMT=3Dy CONFIG_CMD_XXD=3Dy @@ -163,6 +164,7 @@ CONFIG_IMX_TMU=3Dy # CONFIG_TPM_V1 is not set CONFIG_TPM2_TIS_SPI=3Dy CONFIG_USB=3Dy +CONFIG_DM_USB_GADGET=3Dy CONFIG_USB_XHCI_HCD=3Dy CONFIG_USB_XHCI_DWC3=3Dy CONFIG_USB_XHCI_DWC3_OF_SIMPLE=3Dy @@ -178,6 +180,11 @@ CONFIG_USB_ETHER_LAN78XX=3Dy CONFIG_USB_ETHER_MCS7830=3Dy CONFIG_USB_ETHER_RTL8152=3Dy CONFIG_USB_ETHER_SMSC95XX=3Dy +CONFIG_USB_GADGET=3Dy +CONFIG_USB_GADGET_MANUFACTURER=3D"Gateworks" +CONFIG_USB_GADGET_VENDOR_NUM=3D0x0525 +CONFIG_USB_GADGET_PRODUCT_NUM=3D0xa4a5 +CONFIG_USB_GADGET_DOWNLOAD=3Dy CONFIG_IMX_WATCHDOG=3Dy CONFIG_TPM=3Dy # CONFIG_SPL_SHA512 is not set --=20 2.25.1