From nobody Mon Feb 9 03:20:04 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 299051DEFFE; Mon, 5 May 2025 17:27:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746466049; cv=pass; b=IcKXtprP7B6XCqtUbzGzGrNgiv8HLdeqGmxqKH568Aq1xsfzRqCEttHtgPtSMiefBGPn8PP2exnaPn6QWWze1gjnJgiqOhAXVRlnXPr4BwiOqzC/XfMprN81dgGmEDaaatGBf/cj3hcaRWCZjOVLSfh1oxXraNPtKRdRpZEud48= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746466049; c=relaxed/simple; bh=suBvb1buuYMhohUMIqerKRu8jOXJRpZNklfTSfXFeV8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=stfdZDNhOCjYL7+Hf2XMWb7zFFM4F1DOCssQsRI5IsmRWXY2uMDHMZ+39erbLDtSwQq6p+Q8xi3H/8rYz7M4zS76wKdjrFX1HKeL/mwgmCs82n+9344PJvygES9ISpSH5LiKoIQZopjXACp7VQIEU0vXWO0u26P5W0twTAZ3BTE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=Nc3e+E27; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="Nc3e+E27" ARC-Seal: i=1; a=rsa-sha256; t=1746466020; cv=none; d=zohomail.com; s=zohoarc; b=ctbdMvRigOOohtiooqQ6ZJ3beXX0opnVdvw+za+SKdk6Ln+QPErm8WoFowNaoN0ck1s0OwVlbavgO6RdF2ps7z4I4bC3QSeETJ4ZnejXii6na5Kxaxbsik6+HBrnAEXK58YNbLtek4U3cu7Hp2JZsDXmYzA51IafS3kJjFvaS/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746466020; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=MaDkGjhQDSPYsuzM9uRxkmARdK9P5jYEAGbm91UNP7U=; b=FPpsSBVnoyVacN2Q/j8+tNbgODhJkV0Es9X5N90dBeh4uCNhkiaYk0sE8YJ5TPNO6IzWjQKeDXmmrzoukOb0v3KwUZVSJWAAvuhHr4waoIyZNPYChnXT0Ot7Y0FlkBzhUKmBCywPw0aoFXEFZmbkGO7h49S7W6XNV5giWtQ0TCQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1746466020; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=MaDkGjhQDSPYsuzM9uRxkmARdK9P5jYEAGbm91UNP7U=; b=Nc3e+E27YJsgWN81HBtqPNG1jzVBDMwxFL02NhDzhIO2MlE936BmwzwiuQgHKfdn k1tlvzlCeH4sejWIXbmvHhNhqjEcKseHHZk0smHL9vn38wt67XBg+Vf3OirRGJJmfXS XNaVZktLDAWZHDra1lklT6cpMTHSSbwN1Quhi6GE= Received: by mx.zohomail.com with SMTPS id 1746466018698847.2650646063497; Mon, 5 May 2025 10:26:58 -0700 (PDT) From: Nicolas Frattaroli Date: Mon, 05 May 2025 19:26:36 +0200 Subject: [PATCH v2 1/5] phy: rockchip: inno-usb2: add soft vbusvalid control 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: <20250505-rk3576-sige5-usb-v2-1-d5ba4305f3be@collabora.com> References: <20250505-rk3576-sige5-usb-v2-0-d5ba4305f3be@collabora.com> In-Reply-To: <20250505-rk3576-sige5-usb-v2-0-d5ba4305f3be@collabora.com> To: Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiko Stuebner , Kever Yang , Frank Wang Cc: Sebastian Reichel , kernel@collabora.com, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Nicolas Frattaroli X-Mailer: b4 0.14.2 With USB type C connectors, the vbus detect pin of the OTG controller attached to it is pulled high by a USB Type C controller chip such as the fusb302. This means USB enumeration on Type-C ports never works, as the vbus is always seen as high. Rockchip added some GRF register flags to deal with this situation. The RK3576 TRM calls these "soft_vbusvalid_bvalid" (con0 bit index 15) and "soft_vbusvalid_bvalid_sel" (con0 bit index 14). Downstream introduces a new vendor property which tells the USB 2 PHY that it's connected to a type C port, but we can do better. Since in such an arrangement, we'll have an OF graph connection from the USB controller to the USB connector anyway, we can walk said OF graph and check the connector's compatible to determine this without adding any further vendor properties. Do keep in mind that the usbdp PHY driver seemingly fiddles with these register fields as well, but what it does doesn't appear to be enough for us to get working USB enumeration, presumably because the whole vbus_attach logic needs to be adjusted as well either way. Signed-off-by: Nicolas Frattaroli --- drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 113 ++++++++++++++++++++++= +++- 1 file changed, 109 insertions(+), 4 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/ro= ckchip/phy-rockchip-inno-usb2.c index b5e6a864deebbcb33375001fc6ed67b2dfee6954..07be9c033c772d4157c7bf438fc= a9b9219a68c9d 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -114,6 +115,8 @@ struct rockchip_chg_det_reg { /** * struct rockchip_usb2phy_port_cfg - usb-phy port configuration. * @phy_sus: phy suspend register. + * @svbus_en: soft vbus bvalid enable register. + * @svbus_sel: soft vbus bvalid selection register. * @bvalid_det_en: vbus valid rise detection enable register. * @bvalid_det_st: vbus valid rise detection status register. * @bvalid_det_clr: vbus valid rise detection clear register. @@ -140,6 +143,8 @@ struct rockchip_chg_det_reg { */ struct rockchip_usb2phy_port_cfg { struct usb2phy_reg phy_sus; + struct usb2phy_reg svbus_en; + struct usb2phy_reg svbus_sel; struct usb2phy_reg bvalid_det_en; struct usb2phy_reg bvalid_det_st; struct usb2phy_reg bvalid_det_clr; @@ -203,6 +208,7 @@ struct rockchip_usb2phy_cfg { * @event_nb: hold event notification callback. * @state: define OTG enumeration states before device reset. * @mode: the dr_mode of the controller. + * @typec_vbus_det: whether to apply Type C logic to OTG vbus detection. */ struct rockchip_usb2phy_port { struct phy *phy; @@ -222,6 +228,7 @@ struct rockchip_usb2phy_port { struct notifier_block event_nb; enum usb_otg_state state; enum usb_dr_mode mode; + bool typec_vbus_det; }; =20 /** @@ -495,6 +502,13 @@ static int rockchip_usb2phy_init(struct phy *phy) mutex_lock(&rport->mutex); =20 if (rport->port_id =3D=3D USB2PHY_PORT_OTG) { + if (rport->typec_vbus_det) { + if (rport->port_cfg->svbus_en.enable && + rport->port_cfg->svbus_sel.enable) { + property_enable(rphy->grf, &rport->port_cfg->svbus_en, true); + property_enable(rphy->grf, &rport->port_cfg->svbus_sel, true); + } + } if (rport->mode !=3D USB_DR_MODE_HOST && rport->mode !=3D USB_DR_MODE_UNKNOWN) { /* clear bvalid status and enable bvalid detect irq */ @@ -535,8 +549,7 @@ static int rockchip_usb2phy_init(struct phy *phy) if (ret) goto out; =20 - schedule_delayed_work(&rport->otg_sm_work, - OTG_SCHEDULE_DELAY * 3); + schedule_delayed_work(&rport->otg_sm_work, 0); } else { /* If OTG works in host only mode, do nothing. */ dev_dbg(&rport->phy->dev, "mode %d\n", rport->mode); @@ -666,8 +679,17 @@ static void rockchip_usb2phy_otg_sm_work(struct work_s= truct *work) unsigned long delay; bool vbus_attach, sch_work, notify_charger; =20 - vbus_attach =3D property_enabled(rphy->grf, - &rport->port_cfg->utmi_bvalid); + if (rport->port_cfg->svbus_en.enable && rport->typec_vbus_det) { + if (property_enabled(rphy->grf, &rport->port_cfg->svbus_en) && + property_enabled(rphy->grf, &rport->port_cfg->svbus_sel)) { + vbus_attach =3D true; + } else { + vbus_attach =3D false; + } + } else { + vbus_attach =3D property_enabled(rphy->grf, + &rport->port_cfg->utmi_bvalid); + } =20 sch_work =3D false; notify_charger =3D false; @@ -1276,6 +1298,83 @@ static int rockchip_otg_event(struct notifier_block = *nb, return NOTIFY_DONE; } =20 +static const char *const rockchip_usb2phy_typec_cons[] =3D { + "usb-c-connector", + NULL, +}; + +static struct device_node *rockchip_usb2phy_to_controller(struct rockchip_= usb2phy *rphy) +{ + struct device_node *np; + struct device_node *parent; + + for_each_node_with_property(np, "phys") { + struct of_phandle_iterator it; + int ret; + + of_for_each_phandle(&it, ret, np, "phys", NULL, 0) { + parent =3D of_get_parent(it.node); + if (it.node !=3D rphy->dev->of_node && rphy->dev->of_node !=3D parent) { + if (parent) + of_node_put(parent); + continue; + } + + /* + * Either the PHY phandle we're iterating or its parent + * matched, we don't care about which out of the two in + * particular as we just need to know it's the right + * USB controller for this PHY. + */ + of_node_put(it.node); + of_node_put(parent); + return np; + } + } + + return NULL; +} + +static bool rockchip_usb2phy_otg_is_type_c(struct rockchip_usb2phy *rphy) +{ + struct device_node *controller =3D rockchip_usb2phy_to_controller(rphy); + struct device_node *ports; + struct device_node *ep =3D NULL; + struct device_node *parent; + + if (!controller) + return false; + + ports =3D of_get_child_by_name(controller, "ports"); + if (ports) { + of_node_put(controller); + controller =3D ports; + } + + for_each_of_graph_port(controller, port) { + ep =3D of_get_child_by_name(port, "endpoint"); + if (!ep) + continue; + + parent =3D of_graph_get_remote_port_parent(ep); + of_node_put(ep); + if (!parent) + continue; + + if (of_device_compatible_match(parent, rockchip_usb2phy_typec_cons)) { + of_node_put(parent); + of_node_put(controller); + return true; + } + + of_node_put(parent); + } + + of_node_put(controller); + + return false; +} + static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, struct rockchip_usb2phy_port *rport, struct device_node *child_np) @@ -1297,6 +1396,8 @@ static int rockchip_usb2phy_otg_port_init(struct rock= chip_usb2phy *rphy, =20 mutex_init(&rport->mutex); =20 + rport->typec_vbus_det =3D rockchip_usb2phy_otg_is_type_c(rphy); + rport->mode =3D of_usb_get_dr_mode_by_phy(child_np, -1); if (rport->mode =3D=3D USB_DR_MODE_HOST || rport->mode =3D=3D USB_DR_MODE_UNKNOWN) { @@ -1971,6 +2072,8 @@ static const struct rockchip_usb2phy_cfg rk3576_phy_c= fgs[] =3D { .port_cfgs =3D { [USB2PHY_PORT_OTG] =3D { .phy_sus =3D { 0x0000, 8, 0, 0, 0x1d1 }, + .svbus_en =3D { 0x0000, 15, 15, 0, 1 }, + .svbus_sel =3D { 0x0000, 14, 14, 0, 1 }, .bvalid_det_en =3D { 0x00c0, 1, 1, 0, 1 }, .bvalid_det_st =3D { 0x00c4, 1, 1, 0, 1 }, .bvalid_det_clr =3D { 0x00c8, 1, 1, 0, 1 }, @@ -2008,6 +2111,8 @@ static const struct rockchip_usb2phy_cfg rk3576_phy_c= fgs[] =3D { .port_cfgs =3D { [USB2PHY_PORT_OTG] =3D { .phy_sus =3D { 0x2000, 8, 0, 0, 0x1d1 }, + .svbus_en =3D { 0x2000, 15, 15, 0, 1 }, + .svbus_sel =3D { 0x2000, 14, 14, 0, 1 }, .bvalid_det_en =3D { 0x20c0, 1, 1, 0, 1 }, .bvalid_det_st =3D { 0x20c4, 1, 1, 0, 1 }, .bvalid_det_clr =3D { 0x20c8, 1, 1, 0, 1 }, --=20 2.49.0 From nobody Mon Feb 9 03:20:04 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 EEA9F26738B; Mon, 5 May 2025 17:27:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746466049; cv=pass; b=qgJCg7MEHXbJLWrLqK6G1u9AUVtM0nXMG8KT3+8mALzJ0JJN3ZVnR6oxs308BNXn4zYN8D5N4LrUFM13ntGWbZWwFp+F77b/CFDm/PkW+KMI5GKCWJIOLjujpemB48Cj2MbUcog3lHo+lixXarMxY1p0ETFN6ro3Z7MyrEzfhcw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746466049; c=relaxed/simple; bh=uJMB3RmoFmNJqBV7ekNdfelHXQHZizUIa4ub+tYRYMc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BBwOTxRRM8Sjytb5okz1HdIMAYNmlUdPyCY6kDOIhGBBaZ8Wfxn4u0KH1wpmgvVAe+3k3ie5W3rxrFtwYnEToBA1w11X76o1/Uy0Hel6qa73hOhE3hJvtFelEULSKflEL6QzXVwWueomyjCxhWHFNw6lslsmm0juXYRMW1FLrlY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=OUrrSne5; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="OUrrSne5" ARC-Seal: i=1; a=rsa-sha256; t=1746466024; cv=none; d=zohomail.com; s=zohoarc; b=fmdldmq8dsLmVPIYQxY161qfznq7mmrK8ujgoFnjIkPzEUJPSVMYY8y5ut+Yq4vXdqkP7SKZwhP5Wzyxjbfh23I44QYTp86SllgnvqLBSe8GpGFEIykN0WimXb520kO/YGOZ3b+ekHfa4G2XZ6i9Zyqt9/BSN7dbMWLD/wrZW/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746466024; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=j1pxA+bc+vNKzjIaRT1KaTq/RuyMnrlK34dQ5cfd5BU=; b=H/LgMSug9gBuSTlAAoH89EXEnXLoIAxQxgP849j+D/LKlY5Q9uHQD6StWX71fuu7j6GqLOaXDO+Jdb7zwLk80/AES7sltnb449RnuCwoPZxPzoZT3MWTb1fewhU88Ft4YcCPajAFM4AIohIiFq6Yr53LcvQIFu3tZoN7/PAtPtU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1746466024; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=j1pxA+bc+vNKzjIaRT1KaTq/RuyMnrlK34dQ5cfd5BU=; b=OUrrSne5KQrgU8ndZn2XgYB7UVCtE6WukeUoqU9i2h8TpUfJ/GRmK3mGzruZLOa0 jHVIZbquQBl2aWBB3hos/Jc7xVACAr5a/VaHz9O1rjwyVtjoKU7AGUXj7gpnksa99cV KN1nwhKSyjBK54FljqgddZXFRsw1fQcTs6BKIx90= Received: by mx.zohomail.com with SMTPS id 1746466022200140.16841011130168; Mon, 5 May 2025 10:27:02 -0700 (PDT) From: Nicolas Frattaroli Date: Mon, 05 May 2025 19:26:37 +0200 Subject: [PATCH v2 2/5] phy: rockchip: usbdp: move orientation handling further down 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: <20250505-rk3576-sige5-usb-v2-2-d5ba4305f3be@collabora.com> References: <20250505-rk3576-sige5-usb-v2-0-d5ba4305f3be@collabora.com> In-Reply-To: <20250505-rk3576-sige5-usb-v2-0-d5ba4305f3be@collabora.com> To: Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiko Stuebner , Kever Yang , Frank Wang Cc: Sebastian Reichel , kernel@collabora.com, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Nicolas Frattaroli X-Mailer: b4 0.14.2 The orientation handling code isn't referenced until very far down the driver code. Move it down some ways so it can later reference other driver functions without needing forward declarations. Signed-off-by: Nicolas Frattaroli --- drivers/phy/rockchip/phy-rockchip-usbdp.c | 100 +++++++++++++++-----------= ---- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockch= ip/phy-rockchip-usbdp.c index c066cc0a7b4f10fc3cd8779323c369360893520d..fff54900feea601c8fe6bf4c712= 3dfebc5661a15 100644 --- a/drivers/phy/rockchip/phy-rockchip-usbdp.c +++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c @@ -651,56 +651,6 @@ static void rk_udphy_set_typec_default_mapping(struct = rk_udphy *udphy) udphy->mode =3D UDPHY_MODE_DP_USB; } =20 -static int rk_udphy_orien_sw_set(struct typec_switch_dev *sw, - enum typec_orientation orien) -{ - struct rk_udphy *udphy =3D typec_switch_get_drvdata(sw); - - mutex_lock(&udphy->mutex); - - if (orien =3D=3D TYPEC_ORIENTATION_NONE) { - gpiod_set_value_cansleep(udphy->sbu1_dc_gpio, 0); - gpiod_set_value_cansleep(udphy->sbu2_dc_gpio, 0); - /* unattached */ - rk_udphy_usb_bvalid_enable(udphy, false); - goto unlock_ret; - } - - udphy->flip =3D (orien =3D=3D TYPEC_ORIENTATION_REVERSE) ? true : false; - rk_udphy_set_typec_default_mapping(udphy); - rk_udphy_usb_bvalid_enable(udphy, true); - -unlock_ret: - mutex_unlock(&udphy->mutex); - return 0; -} - -static void rk_udphy_orien_switch_unregister(void *data) -{ - struct rk_udphy *udphy =3D data; - - typec_switch_unregister(udphy->sw); -} - -static int rk_udphy_setup_orien_switch(struct rk_udphy *udphy) -{ - struct typec_switch_desc sw_desc =3D { }; - - sw_desc.drvdata =3D udphy; - sw_desc.fwnode =3D dev_fwnode(udphy->dev); - sw_desc.set =3D rk_udphy_orien_sw_set; - - udphy->sw =3D typec_switch_register(udphy->dev, &sw_desc); - if (IS_ERR(udphy->sw)) { - dev_err(udphy->dev, "Error register typec orientation switch: %ld\n", - PTR_ERR(udphy->sw)); - return PTR_ERR(udphy->sw); - } - - return devm_add_action_or_reset(udphy->dev, - rk_udphy_orien_switch_unregister, udphy); -} - static int rk_udphy_refclk_set(struct rk_udphy *udphy) { unsigned long rate; @@ -1451,6 +1401,56 @@ static struct phy *rk_udphy_phy_xlate(struct device = *dev, const struct of_phandl return ERR_PTR(-EINVAL); } =20 +static int rk_udphy_orien_sw_set(struct typec_switch_dev *sw, + enum typec_orientation orien) +{ + struct rk_udphy *udphy =3D typec_switch_get_drvdata(sw); + + mutex_lock(&udphy->mutex); + + if (orien =3D=3D TYPEC_ORIENTATION_NONE) { + gpiod_set_value_cansleep(udphy->sbu1_dc_gpio, 0); + gpiod_set_value_cansleep(udphy->sbu2_dc_gpio, 0); + /* unattached */ + rk_udphy_usb_bvalid_enable(udphy, false); + goto unlock_ret; + } + + udphy->flip =3D (orien =3D=3D TYPEC_ORIENTATION_REVERSE) ? true : false; + rk_udphy_set_typec_default_mapping(udphy); + rk_udphy_usb_bvalid_enable(udphy, true); + +unlock_ret: + mutex_unlock(&udphy->mutex); + return 0; +} + +static void rk_udphy_orien_switch_unregister(void *data) +{ + struct rk_udphy *udphy =3D data; + + typec_switch_unregister(udphy->sw); +} + +static int rk_udphy_setup_orien_switch(struct rk_udphy *udphy) +{ + struct typec_switch_desc sw_desc =3D { }; + + sw_desc.drvdata =3D udphy; + sw_desc.fwnode =3D dev_fwnode(udphy->dev); + sw_desc.set =3D rk_udphy_orien_sw_set; + + udphy->sw =3D typec_switch_register(udphy->dev, &sw_desc); + if (IS_ERR(udphy->sw)) { + dev_err(udphy->dev, "Error register typec orientation switch: %ld\n", + PTR_ERR(udphy->sw)); + return PTR_ERR(udphy->sw); + } + + return devm_add_action_or_reset(udphy->dev, + rk_udphy_orien_switch_unregister, udphy); +} + static int rk_udphy_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; --=20 2.49.0 From nobody Mon Feb 9 03:20:04 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 9066926B96A; Mon, 5 May 2025 17:27:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746466051; cv=pass; b=snCOlEMWhjk/Ybz7H8iBqtEmcTQcX2W7JJPAk4k2tftL5MXP+9muYcF6p/884ZhkOx58JkSwwND5Gk+sgsvtAvwaAEZur0B7yxM8/5y/diAa1XqNxFclyEM0kc2iBhXlEZewabwlEigPYD/6APz0rAGCz2PUJVxb270BwFu4KFM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746466051; c=relaxed/simple; bh=VW4aB7Eci+66CKEdrWizM7NfU5WhMJaGMzLxapw8WDg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KaDvehJiUVZ8KqpUKE1u+S91M1flr8/Sc1RlQyK+l1Y6FOxg8rzwV6vb8xmEM6butlKPTraa2mqNTJ3XNCn22MkIsPRHqRWHhFzYWFdk791D13itolEWlRSrSHP/K6ObWD294wvQJFeU0duK2DcnHzycxUM8AmSpjpn4Og3Y46E= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=NVgBDJD4; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="NVgBDJD4" ARC-Seal: i=1; a=rsa-sha256; t=1746466026; cv=none; d=zohomail.com; s=zohoarc; b=Ol31He9KAL0nNR6mrsX3AZ2MxA+Wl9fmVjaFdtr2X6b3p9kZUUcUnli2/A3VKUwvOGnjajwEloSZlxLpNSbYrmC9QTczIDf/CG+MnFvle1K7VU/iRvTjwNtCqoDA+aUvSGCRceC14q6ralKJPTLFJTFFjK0MqtX/SKIwA9zjNAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746466026; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=JTB3v+x8w/FUL8jly8m0hmcJty/2pFiwNyr1NhvSBfc=; b=SootE5B4uevjjwWtjMCOr4q0r9dxYEN9jcsG5xg7FmBNfA0T/b08f+gDKR4Zd5dCsLf/mgicaXxHu7oiTGeJo4ae/nYirpALLvNYjiLpFmrRXnsDaSGnz9bTwTrdCwp2BDoM9a/Fmr4ypERR+4oxoKCgD/YhzKJhHUtbp5jKv/8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1746466026; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=JTB3v+x8w/FUL8jly8m0hmcJty/2pFiwNyr1NhvSBfc=; b=NVgBDJD4k+kVVdTnSKAaohwAkP3qAaSP3SplomwfKDGHL/giP/YqllFtRQlCk+95 M1cae3oN7CIMuPqtvKBjBWsl1/99RVIL1yHVaGNWPxRqX4dR9m3bFxeZAc2vmKIpI62 /NikEepQk1v2b+rq6pPeGRKWwT2sEtzF4758WSlw= Received: by mx.zohomail.com with SMTPS id 1746466025536483.6514707684531; Mon, 5 May 2025 10:27:05 -0700 (PDT) From: Nicolas Frattaroli Date: Mon, 05 May 2025 19:26:38 +0200 Subject: [PATCH v2 3/5] phy: rockchip: usbdp: reset USB3 and reinit on orientation switch 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: <20250505-rk3576-sige5-usb-v2-3-d5ba4305f3be@collabora.com> References: <20250505-rk3576-sige5-usb-v2-0-d5ba4305f3be@collabora.com> In-Reply-To: <20250505-rk3576-sige5-usb-v2-0-d5ba4305f3be@collabora.com> To: Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiko Stuebner , Kever Yang , Frank Wang Cc: Sebastian Reichel , kernel@collabora.com, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Nicolas Frattaroli X-Mailer: b4 0.14.2 Until now, super speed on Type-C only worked in one orientation. This is because on an orientation switch, the UDPHY was never reinitialised. Heiko presented a patch to do this[1], but there were concerns over the correctness of it[2]. Experimentally using Heiko's patch on RK3576 did make me run into issues, though they seemed to be related to the orientation switch actually happening while a clock driving a GRF register was disabled. The key issue is that the hardware wants the USB 3 controller to be held in reset while the PHY is being reconfigured, otherwise we may run into hard-to-catch race conditions. Either way, this patch implements the required ordering in a somewhat unpleasant way: we get the USB 3 controller from the DT, and use runtime power management to forcibly suspend it while the UDPHY is being reconfigured, and then forcibly resume it later. As an added pain in the rear, the suspend/resume of the USB 3 controller also tries fiddling with the USB 3 PHY part of the UDPHY, which means we introduce an atomic flag to skip suspending/resuming the UDPHY if we're resetting the USB 3 controller. We may just need to skip trying to acquire the mutex again, but both ways work for me in practice. This solution may in fact be complete rubbish, but it works to get USB 3 Super Speed working in both cable orientations on my board. Link: https://lore.kernel.org/all/20250226103810.3746018-3-heiko@sntech.de/= [1] Link: https://lore.kernel.org/linux-rockchip/h57ok2hw6os7bcafqkrqknfvm7hnu2= 5m2oe54qmrsuzdwqlos3@m4och2fcdm7s/ [2] Signed-off-by: Nicolas Frattaroli --- drivers/phy/rockchip/phy-rockchip-usbdp.c | 54 +++++++++++++++++++++++++++= ++++ 1 file changed, 54 insertions(+) diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockch= ip/phy-rockchip-usbdp.c index fff54900feea601c8fe6bf4c7123dfebc5661a15..5cd6bbc367f69bca15c2a94a07e= 72f850b381ae3 100644 --- a/drivers/phy/rockchip/phy-rockchip-usbdp.c +++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c @@ -200,6 +200,10 @@ struct rk_udphy { /* PHY devices */ struct phy *phy_dp; struct phy *phy_u3; + + /* USB 3 controller device */ + struct device *ctrl_u3; + atomic_t ctrl_resetting; }; =20 static const struct rk_udphy_dp_tx_drv_ctrl rk3588_dp_tx_drv_ctrl_rbr_hbr[= 4][4] =3D { @@ -1255,6 +1259,9 @@ static int rk_udphy_usb3_phy_init(struct phy *phy) struct rk_udphy *udphy =3D phy_get_drvdata(phy); int ret =3D 0; =20 + if (atomic_read(&udphy->ctrl_resetting)) + return 0; + mutex_lock(&udphy->mutex); /* DP only or high-speed, disable U3 port */ if (!(udphy->mode & UDPHY_MODE_USB) || udphy->hs) { @@ -1273,6 +1280,9 @@ static int rk_udphy_usb3_phy_exit(struct phy *phy) { struct rk_udphy *udphy =3D phy_get_drvdata(phy); =20 + if (atomic_read(&udphy->ctrl_resetting)) + return 0; + mutex_lock(&udphy->mutex); /* DP only or high-speed */ if (!(udphy->mode & UDPHY_MODE_USB) || udphy->hs) @@ -1401,10 +1411,31 @@ static struct phy *rk_udphy_phy_xlate(struct device= *dev, const struct of_phandl return ERR_PTR(-EINVAL); } =20 +static struct device_node *rk_udphy_to_controller(struct rk_udphy *udphy) +{ + struct device_node *np; + + for_each_node_with_property(np, "phys") { + struct of_phandle_iterator it; + int ret; + + of_for_each_phandle(&it, ret, np, "phys", NULL, 0) { + if (it.node !=3D udphy->dev->of_node) + continue; + + of_node_put(it.node); + return np; + } + } + + return NULL; +} + static int rk_udphy_orien_sw_set(struct typec_switch_dev *sw, enum typec_orientation orien) { struct rk_udphy *udphy =3D typec_switch_get_drvdata(sw); + int ret; =20 mutex_lock(&udphy->mutex); =20 @@ -1420,6 +1451,18 @@ static int rk_udphy_orien_sw_set(struct typec_switch= _dev *sw, rk_udphy_set_typec_default_mapping(udphy); rk_udphy_usb_bvalid_enable(udphy, true); =20 + if (udphy->status !=3D UDPHY_MODE_NONE && udphy->ctrl_u3) { + atomic_set(&udphy->ctrl_resetting, 1); + pm_runtime_force_suspend(udphy->ctrl_u3); + + ret =3D rk_udphy_setup(udphy); + if (!ret) + clk_bulk_disable_unprepare(udphy->num_clks, udphy->clks); + + pm_runtime_force_resume(udphy->ctrl_u3); + atomic_set(&udphy->ctrl_resetting, 0); + } + unlock_ret: mutex_unlock(&udphy->mutex); return 0; @@ -1430,12 +1473,22 @@ static void rk_udphy_orien_switch_unregister(void *= data) struct rk_udphy *udphy =3D data; =20 typec_switch_unregister(udphy->sw); + put_device(udphy->ctrl_u3); } =20 static int rk_udphy_setup_orien_switch(struct rk_udphy *udphy) { + struct device_node *ctrl =3D rk_udphy_to_controller(udphy); struct typec_switch_desc sw_desc =3D { }; =20 + if (ctrl) { + udphy->ctrl_u3 =3D bus_find_device_by_of_node(udphy->dev->bus, ctrl); + of_node_put(ctrl); + } + + if (!udphy->ctrl_u3) + dev_info(udphy->dev, "couldn't find this PHY's USB3 controller\n"); + sw_desc.drvdata =3D udphy; sw_desc.fwnode =3D dev_fwnode(udphy->dev); sw_desc.set =3D rk_udphy_orien_sw_set; @@ -1499,6 +1552,7 @@ static int rk_udphy_probe(struct platform_device *pde= v) return ret; =20 mutex_init(&udphy->mutex); + atomic_set(&udphy->ctrl_resetting, 0); platform_set_drvdata(pdev, udphy); =20 if (device_property_present(dev, "orientation-switch")) { --=20 2.49.0 From nobody Mon Feb 9 03:20:04 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 6B4D126738B; Mon, 5 May 2025 17:27:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746466055; cv=pass; b=e4GFUL81MiMrRAuDBz+R73CC3sie6k4hROm5tSwMjMlU7QvwXdKn+1M6WIqjFAbQEg+8+znh7yGxwKF0gKFM4B1GmNi/amC1A/p6qSvYjDkY5rTwFyeBHPoSr4hHbLmV44rMTFAde7QXV1eP6KNKkGMNldFm6winG/dbDhTFqR4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746466055; c=relaxed/simple; bh=0WG5gBv1ouv+Qppldc/xgflGBc5hmN+2I748LvBpyz0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gpzn/Ljp2zyfPGCG+GKxoj4iAWf+peVeu3Ruwd/Letsx1tURnbBU3pdJ7WplIg+zMMzlPqx1l3g+LKD6QcBBQyGB1Jy3krl1XNSleLWVkOfeeltVxoh+r4qMz9CW4uC3h2q+HkWuA+MoNt/7ffcaMK8hMat2cj4z/xxX6FYQBE0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=I8LC2Pmu; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="I8LC2Pmu" ARC-Seal: i=1; a=rsa-sha256; t=1746466030; cv=none; d=zohomail.com; s=zohoarc; b=WvaUuOHozLTxBreRVoRUZHIAEzPFGeRQMg4uBRsLda4UXmjGVA5cd0lSmJZVK1mmoHrEgX5EVsPj7yUqQ2VI+yFQJ1tlKUNSPbfuxsRYNx5hAN8LdngVVVcI2RbqUR5Avbw2x1279vvM49DbDT2Bx27InOsLU40h+muwSJDFVqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746466030; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=UXMkSRINNwBaxu50t98o2g6F0hiutN+78b6vZXXpk4k=; b=i8/fed4EofhbKDyh8FRlPRZPRnvt/opLboTCojBOcJwnxBVvA6tVK2VzfmB34vzFJE+ILd8FSCRqfnGfnjW1jrSwhGEZT5XdMYHu+la1oK8Z8grseOlTVTEB9Y+x+P6k8rIyf7scxe3E/9orTlsgMiD3lhHfQkHpl4BKFaillzY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1746466030; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=UXMkSRINNwBaxu50t98o2g6F0hiutN+78b6vZXXpk4k=; b=I8LC2PmuD2lmjAGTQ7BwExEaZ4rARrEE+97Y4X5x4ugO4oq9Hok6tyxmSEJWTbJC otXtmma8ij4MUFJLrYWgzLT+5yHmOygsvCBUsBLO43pt7iUADP0hycYAmqDBL16uvam ae9+iAgMsYJp9QGcOv2zU1HIk2FiV8YAhvFzDm/g= Received: by mx.zohomail.com with SMTPS id 1746466028949626.5537082120404; Mon, 5 May 2025 10:27:08 -0700 (PDT) From: Nicolas Frattaroli Date: Mon, 05 May 2025 19:26:39 +0200 Subject: [PATCH v2 4/5] arm64: dts: rockchip: reference u2phy1 as clock on RK3576 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: <20250505-rk3576-sige5-usb-v2-4-d5ba4305f3be@collabora.com> References: <20250505-rk3576-sige5-usb-v2-0-d5ba4305f3be@collabora.com> In-Reply-To: <20250505-rk3576-sige5-usb-v2-0-d5ba4305f3be@collabora.com> To: Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiko Stuebner , Kever Yang , Frank Wang Cc: Sebastian Reichel , kernel@collabora.com, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Nicolas Frattaroli X-Mailer: b4 0.14.2 The rockchip,dwc3 binding states that the utmi clock may be referenced by the controller. Until now, the u2phy1's clock output had no references to it in the SoC device tree. It's not known if this caused any real-world issues, but it may have allowed the USB controller to potentially do operations that depend on the utmi clock while it is not enabled, leading to hard-to-reproduce race conditions during bootup. Reference the u2phy1 output clock in its corresponding USB controller as an utmi clock. This effectively increases the enable count of the usb480m_phy1 clock in Linux on my system from a deviceless 1 to a 2 with the USB controller as a named user. Fixes: 23ec57a32da4 ("arm64: dts: rockchip: add usb related nodes for rk357= 6") Signed-off-by: Nicolas Frattaroli --- arch/arm64/boot/dts/rockchip/rk3576.dtsi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/rockchip/rk3576.dtsi b/arch/arm64/boot/dts= /rockchip/rk3576.dtsi index ddc92ccc530d6757660971f0a609b5127784bb04..fa4ff44ec48b4b8759b7d4d1c75= 2afd3333fd43d 100644 --- a/arch/arm64/boot/dts/rockchip/rk3576.dtsi +++ b/arch/arm64/boot/dts/rockchip/rk3576.dtsi @@ -480,8 +480,9 @@ usb_drd1_dwc3: usb@23400000 { reg =3D <0x0 0x23400000 0x0 0x400000>; clocks =3D <&cru CLK_REF_USB3OTG1>, <&cru CLK_SUSPEND_USB3OTG1>, - <&cru ACLK_USB3OTG1>; - clock-names =3D "ref_clk", "suspend_clk", "bus_clk"; + <&cru ACLK_USB3OTG1>, + <&u2phy1>; + clock-names =3D "ref_clk", "suspend_clk", "bus_clk", "utmi"; interrupts =3D ; power-domains =3D <&power RK3576_PD_PHP>; resets =3D <&cru SRST_A_USB3OTG1>; --=20 2.49.0 From nobody Mon Feb 9 03:20:04 2026 Received: from sender3-pp-f112.zoho.com (sender3-pp-f112.zoho.com [136.143.184.112]) (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 973E326738B; Mon, 5 May 2025 17:27:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.184.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746466060; cv=pass; b=XRfRLtKsghZKjXx3zOKAvehQHgsPeKkAMmB0QvpzBhupxLGKbH6aTIt7Kimopn+O415x44Yz90eBie6gOFyZ/0V1b/3IIREqwporZrmW/jp/7ZUDEBj05XQdJD9EPFPjL/pAg++nsI5hlMvO830SLRN1psj/kWmKsZdngkG/ecQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746466060; c=relaxed/simple; bh=MTAb9rz5IjDPFHU4fcHQ4VBXXcHmzG1zGNQI2Arg+5s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hlsUHwbyq2FAd+3Z8nw/iK3cXVVx7W72yorjh24XwgkzhdaD9pnF2j7pTWpW0hDkjwhDRnRw0po2k5Kuo/XppAvwgxZRQTVohimjIXEr7zjdF9P4zU8ZOh6pK2XjjBnYmce6ly8uO5IV+2mEbWUvbRRyQOtOBpbV706FQbQ/jBw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=W9Dgp/QS; arc=pass smtp.client-ip=136.143.184.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="W9Dgp/QS" ARC-Seal: i=1; a=rsa-sha256; t=1746466034; cv=none; d=zohomail.com; s=zohoarc; b=YmTPam7tpVAKD45xt31fgShDnXINa0O32EkPC7H5Tn8fmRFmHpT5V5LrGtg/D2MDY442xfCEwSFEEfGNh58gq1ug9nnbtJY2g7Y2HT4tIrzsAqUZKznlryskiYnWQvZxpn2mhQ56O5WqzeHNnAiToqJnLnTwiriyrQp+JtUvgyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746466034; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=n/b63KH5NJPUOPZ1g1cKRKHd1zEwEqpry3HADn6QvTM=; b=Suzrubk5m7ptBGoGc9gHO/sKbRiNHs+frM4DTP/6PulMwEXgT3wu8TVyfg8xxGqquSev+sKtp+0uxU1jwk0ombh4zuWFU33jsxjA3PH/qdMWZO5ajRNubb4kFFGRApv9vLXuphQEc5GlSi6NCQLIKTqNVkCwCyRNKnv890njbtw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1746466034; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=n/b63KH5NJPUOPZ1g1cKRKHd1zEwEqpry3HADn6QvTM=; b=W9Dgp/QSk+ExhivScubIaGPdIny68qD37wa+6VXC4qUhxOqiOHVK5wCGgkLABUjU L879vi3M/bCDK0L5X80TbfkUx/yeT0AXxGczAU1OjzJqo7NOVhJMCpCGgVZ/beu+aas 5HqpiPIBx9HlddF94r4Cc8PZauhQm9mw8SVhDDrI= Received: by mx.zohomail.com with SMTPS id 1746466032351288.12522507198184; Mon, 5 May 2025 10:27:12 -0700 (PDT) From: Nicolas Frattaroli Date: Mon, 05 May 2025 19:26:40 +0200 Subject: [PATCH v2 5/5] arm64: dts: rockchip: enable USB on Sige5 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: <20250505-rk3576-sige5-usb-v2-5-d5ba4305f3be@collabora.com> References: <20250505-rk3576-sige5-usb-v2-0-d5ba4305f3be@collabora.com> In-Reply-To: <20250505-rk3576-sige5-usb-v2-0-d5ba4305f3be@collabora.com> To: Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiko Stuebner , Kever Yang , Frank Wang Cc: Sebastian Reichel , kernel@collabora.com, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Nicolas Frattaroli X-Mailer: b4 0.14.2 The ArmSoM Sige5 has several USB ports: a Type-A USB 3 port (USB2 lines going through a hub), a Type-A USB 2.0 port (also going through a hub), a Type-C DC input port that has absolutely no USB data connection and a Type-C port with USB3.2 Gen1x1 that's also the maskrom programming port. Enable these ports, and set the device role to be host for the host ports. The data capable Type-C USB port uses a fusb302 for data role switching. Signed-off-by: Nicolas Frattaroli --- .../boot/dts/rockchip/rk3576-armsom-sige5.dts | 160 +++++++++++++++++= ++++ 1 file changed, 160 insertions(+) diff --git a/arch/arm64/boot/dts/rockchip/rk3576-armsom-sige5.dts b/arch/ar= m64/boot/dts/rockchip/rk3576-armsom-sige5.dts index 570252c4c0bfe56a3c269e47d81fca7676e61787..74de0fc77fefeffb8a90dd6dd93= 27ddb0083a146 100644 --- a/arch/arm64/boot/dts/rockchip/rk3576-armsom-sige5.dts +++ b/arch/arm64/boot/dts/rockchip/rk3576-armsom-sige5.dts @@ -177,6 +177,33 @@ vcc_3v3_ufs_s0: regulator-vcc-ufs-s0 { regulator-max-microvolt =3D <3300000>; vin-supply =3D <&vcc_5v0_sys>; }; + + vcc_5v0_typec0: regulator-vcc-5v0-typec0 { + compatible =3D "regulator-fixed"; + enable-active-high; + gpios =3D <&gpio4 RK_PA6 GPIO_ACTIVE_HIGH>; + pinctrl-names =3D "default"; + pinctrl-0 =3D <&usb_otg0_pwren>; + regulator-name =3D "vcc_5v0_typec0"; + regulator-min-microvolt =3D <5000000>; + regulator-max-microvolt =3D <5000000>; + vin-supply =3D <&vcc_5v0_device>; + }; + vcc_5v0_usbhost: regulator-vcc-5v0-usbhost { + compatible =3D "regulator-fixed"; + enable-active-high; + gpios =3D <&gpio4 RK_PA4 GPIO_ACTIVE_HIGH>; + pinctrl-names =3D "default"; + pinctrl-0 =3D <&usb_host_pwren>; + regulator-name =3D "vcc_5v0_usbhost"; + regulator-min-microvolt =3D <5000000>; + regulator-max-microvolt =3D <5000000>; + vin-supply =3D <&vcc_5v0_device>; + }; +}; + +&combphy1_psu { + status =3D "okay"; }; =20 &combphy0_ps { @@ -611,6 +638,58 @@ regulator-state-mem { &i2c2 { status =3D "okay"; =20 + usbc0: typec-portc@22 { + compatible =3D "fcs,fusb302"; + reg =3D <0x22>; + interrupt-parent =3D <&gpio0>; + interrupts =3D ; + pinctrl-names =3D "default"; + pinctrl-0 =3D <&usbc0_interrupt>; + vbus-supply =3D <&vcc_5v0_typec0>; + + connector { + compatible =3D "usb-c-connector"; + label =3D "USB-C"; + data-role =3D "dual"; + /* fusb302 supports PD Rev 2.0 Ver 1.2 */ + pd-revision =3D /bits/ 8 <0x2 0x0 0x1 0x2>; + power-role =3D "source"; + source-pdos =3D ; + + altmodes { + displayport { + svid =3D /bits/ 16 <0xff01>; + vdo =3D <0xffffffff>; + }; + }; + + ports { + #address-cells =3D <1>; + #size-cells =3D <0>; + + port@0 { + reg =3D <0>; + usbc0_hs_ep: endpoint { + remote-endpoint =3D <&usb_drd0_hs_ep>; + }; + }; + port@1 { + reg =3D <1>; + usbc0_ss_ep: endpoint { + remote-endpoint =3D <&usb_drd0_ss_ep>; + }; + }; + port@2 { + reg =3D <2>; + usbc0_dp_ep: endpoint { + remote-endpoint =3D <&usbdp_phy_ep>; + }; + }; + }; + }; + }; + hym8563: rtc@51 { compatible =3D "haoyu,hym8563"; reg =3D <0x51>; @@ -678,6 +757,24 @@ pcie_reset: pcie-reset { rockchip,pins =3D <2 RK_PB4 RK_FUNC_GPIO &pcfg_pull_up>; }; }; + + usb { + usb_host_pwren: usb-host-pwren { + rockchip,pins =3D <4 RK_PA4 RK_FUNC_GPIO &pcfg_pull_none>; + }; + usb_otg0_pwren: usb-otg0-pwren { + rockchip,pins =3D <4 RK_PA6 RK_FUNC_GPIO &pcfg_pull_none>; + }; + usbc0_interrupt: usbc0-interrupt { + rockchip,pins =3D <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_up>; + }; + usbc0_sbu1: usbc0-sbu1 { + rockchip,pins =3D <2 RK_PA6 RK_FUNC_GPIO &pcfg_pull_down>; + }; + usbc0_sbu2: usbc0-sbu2 { + rockchip,pins =3D <2 RK_PA7 RK_FUNC_GPIO &pcfg_pull_down>; + }; + }; }; =20 &sdhci { @@ -706,11 +803,74 @@ &sdmmc { status =3D "okay"; }; =20 +&u2phy0 { + status =3D "okay"; +}; + +&u2phy0_otg { + status =3D "okay"; +}; + +&u2phy1 { + status =3D "okay"; +}; + +&u2phy1_otg { + phy-supply =3D <&vcc_5v0_usbhost>; + status =3D "okay"; +}; + &uart0 { pinctrl-0 =3D <&uart0m0_xfer>; status =3D "okay"; }; =20 +&usb_drd0_dwc3 { + usb-role-switch; + dr_mode =3D "otg"; + status =3D "okay"; + + ports { + #address-cells =3D <1>; + #size-cells =3D <0>; + + port@0 { + reg =3D <0>; + usb_drd0_hs_ep: endpoint { + remote-endpoint =3D <&usbc0_hs_ep>; + }; + }; + + port@1 { + reg =3D <1>; + usb_drd0_ss_ep: endpoint { + remote-endpoint =3D <&usbc0_ss_ep>; + }; + }; + }; +}; + +&usb_drd1_dwc3 { + dr_mode =3D "host"; + status =3D "okay"; +}; + +&usbdp_phy { + mode-switch; + orientation-switch; + pinctrl-names =3D "default"; + pinctrl-0 =3D <&usbc0_sbu1 &usbc0_sbu2>; + sbu1-dc-gpios =3D <&gpio2 RK_PA6 GPIO_ACTIVE_HIGH>; + sbu2-dc-gpios =3D <&gpio2 RK_PA7 GPIO_ACTIVE_HIGH>; + status =3D "okay"; + + port { + usbdp_phy_ep: endpoint { + remote-endpoint =3D <&usbc0_dp_ep>; + }; + }; +}; + &vop { status =3D "okay"; }; --=20 2.49.0