Message ID | 20221229183410.683584-3-bryan.odonoghue@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2539092wrt; Thu, 29 Dec 2022 10:39:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXsuD4LfEcOd5SMaVKl69UUPPV4zrvXGTj1LV8PqH3lxlLFjysclLOd8uLAyogMAIchGnPq+ X-Received: by 2002:a05:6a20:2d23:b0:b2:6a7a:6072 with SMTP id g35-20020a056a202d2300b000b26a7a6072mr35412962pzl.14.1672339160162; Thu, 29 Dec 2022 10:39:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672339160; cv=none; d=google.com; s=arc-20160816; b=QAllVpf1AGHIpubPQa03LRIW1dISjH6G6ravt7ZnTGxLK5io/KoFXE8xG19jGagIdH qROEYEVgVtoJxyisvyN2kV0xgNsb8Iz4kKSfVVMSgvA/jvv5nEc8VdHrmgg3rKjYl0GJ noU9yUMmcfBY4thcUIa/UF/6u0RttdIHT7tbSCKxNAxAlx/TJDJkrUwgiQw4zsz91mdt P/24RHFP0GQm7xuf6JprIOFCE4sz9XzOvJu+xvEmYb7dMyIHdMchiO1HNbyiCkmBAM2V QzAQw2Ce3wPVeXaIWvBvz/L+el1eyIZ0ILwCXhfVQ9pcWnFZoqFjMmeXjKNdWn4hiKto MxGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qOwNzTdUKlF0YVErH+m4Hrlu8Y/CqgzRzrTuhq10EAc=; b=TFQEcQkXVnlNMuR6YMrwiAMf+Wl8bzDumqge8GuOX3LtqVls50hrbUbHhL6/wKRxv0 ynlHUQcuU/+3D42J22JulxR5eWDHo4J5BRNPX6vYMQRZ+rH9S9OgDnPIEK5pu4JJXAP7 UzMISffLRrKgYc6dKtP2+e8XD5+n+O6B2i2mO1FIhaFWTb+UpnAQ369vWLsVLGVXx0Vt qzybbX8if5VxSs/pjJhehKSkqfeZO6G7qObZENPLEpiS3tL7QqDP+2OFlI9Fgg+cZzT0 h2bt2RRQCqeSS4h20qa48t5AB4SQxDTK0KS8wiUSURJXRPY/HlYr60ISAaN1tOpO6J6P g7ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RpPdq2z8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r207-20020a632bd8000000b004787df29e4fsi20266331pgr.515.2022.12.29.10.39.07; Thu, 29 Dec 2022 10:39:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RpPdq2z8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234068AbiL2Sev (ORCPT <rfc822;eddaouddi.ayoub@gmail.com> + 99 others); Thu, 29 Dec 2022 13:34:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233994AbiL2SeQ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 29 Dec 2022 13:34:16 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E710FE00 for <linux-kernel@vger.kernel.org>; Thu, 29 Dec 2022 10:34:15 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id fc4so46784038ejc.12 for <linux-kernel@vger.kernel.org>; Thu, 29 Dec 2022 10:34:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qOwNzTdUKlF0YVErH+m4Hrlu8Y/CqgzRzrTuhq10EAc=; b=RpPdq2z8ewpQAJ+Pq0zFsE+golr0XOyCeAmQ8xF4SnuhD4fy8ggns0HkMbA9lvQlAp aVnP0Dxbo/eGyNh2LUIz/M06a2X1mMCyh9d/nKEIqcueDwVj1n/ADSztLB6cGDJcEtBr yeaC241RtYWYMMM2RuU3I0ONfM54CJEgGfnrvMXDiScWPqMn36xAXArGcG4uOFJO77nX zJQTj/7gPqJ+P7c++wPIcLhUk2wojbzpnIEn/Ijy4FW4RMuTMc9TxmSE+x3cP2zZ4OzF qlIkuB+/1eHikr40668fcd4xOaSd9shwA6grac+jhojdIWVB2HkgGCcn5xJSyUzLcOC9 4mzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qOwNzTdUKlF0YVErH+m4Hrlu8Y/CqgzRzrTuhq10EAc=; b=3GOBwu//Mg61NjRW64Jz7XjDyO5EpFaGYMkpvnHNbTP3zLQRbxAPwyrdMJsrPDhyUj afcNEgBV+gdOjyV058T50MlljmSIy07emH3WkpkUlL38IoRfGwhkTLZfkQNpYk7TcwO8 BXjLs/Ua5g+NrsMA68qcwCxP4SloLxALjdMiqAL74s0XAHojFIhxfTxRaN4s9Ai0Zaho wG44ZTUhPr6RMuNvdfQXPGnjvjf3Z7aeoDIDX+HnOamRloroyd7SfgVdXRT58uzoh0ut hPE/EZ47YcytU/Nf1Z0xJ9kPViYNgYLzccx+552vmgxah+3MAzDyQ6Ee7oqYtj+67KLi Wtgg== X-Gm-Message-State: AFqh2kojAyPKG+/Hca3gp+Aw1mrEDu6Wpa0rXFCdiYpVIWCrBjilvl9W tsSMsYid0t9zsTrhzdfxbZSRMg== X-Received: by 2002:a17:907:c70c:b0:81e:9027:dedc with SMTP id ty12-20020a170907c70c00b0081e9027dedcmr25356911ejc.39.1672338854528; Thu, 29 Dec 2022 10:34:14 -0800 (PST) Received: from planet9.chello.ie (2001-1c06-2302-5600-12a8-8cf4-e3f6-f90f.cable.dynamic.v6.ziggo.nl. [2001:1c06:2302:5600:12a8:8cf4:e3f6:f90f]) by smtp.gmail.com with ESMTPSA id g22-20020a1709064e5600b007c0688a68cbsm9013936ejw.176.2022.12.29.10.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 10:34:14 -0800 (PST) From: Bryan O'Donoghue <bryan.odonoghue@linaro.org> To: agross@kernel.org, andersson@kernel.org, vkoul@kernel.org, kishon@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: konrad.dybcio@linaro.org, linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, bryan.odonoghue@linaro.org Subject: [PATCH v2 2/2] phy: qcom-usb-hs: Add qcom,dp-manual-pullup logic Date: Thu, 29 Dec 2022 18:34:10 +0000 Message-Id: <20221229183410.683584-3-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221229183410.683584-1-bryan.odonoghue@linaro.org> References: <20221229183410.683584-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753574707389207899?= X-GMAIL-MSGID: =?utf-8?q?1753574707389207899?= |
Series |
qcom: Add a method to manually toggle the DP pullup on HS USB PHY
|
|
Commit Message
Bryan O'Donoghue
Dec. 29, 2022, 6:34 p.m. UTC
Downstream has a flag called qcom,dp-manual-pullup which informs the
downstream driver if it should toggle ULPI_MISC_A_VBUSVLDEXTSEL and
ULPI_MISC_A_VBUSVLDEXT.
Downstream states:
"qcom,dp-manual-pullup: If present, vbus is not routed to USB
controller/phy and controller driver therefore enables pull-up
explicitly before starting controller using usbcmd run/stop bit."
Working with a system that has both an external Type-C port controller and
an internal USB Hub results in a situation where VBUS is not connected to
the SoC.
In this case we still need to set the DP pullup.
This patch enables and disables the DP pullup on PHY power_on and power_off
respectively if the DT has declared the bool "qcom,enable-vbus-pullup"
effectively replicating the downstream logic to the same effect.
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
drivers/phy/qualcomm/phy-qcom-usb-hs.c | 36 ++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
Comments
On Thu, Dec 29, 2022 at 06:34:10PM +0000, Bryan O'Donoghue wrote: > Downstream has a flag called qcom,dp-manual-pullup which informs the > downstream driver if it should toggle ULPI_MISC_A_VBUSVLDEXTSEL and > ULPI_MISC_A_VBUSVLDEXT. > > Downstream states: > > "qcom,dp-manual-pullup: If present, vbus is not routed to USB > controller/phy and controller driver therefore enables pull-up > explicitly before starting controller using usbcmd run/stop bit." > > Working with a system that has both an external Type-C port controller and > an internal USB Hub results in a situation where VBUS is not connected to > the SoC. > > In this case we still need to set the DP pullup. > > This patch enables and disables the DP pullup on PHY power_on and power_off > respectively if the DT has declared the bool "qcom,enable-vbus-pullup" > effectively replicating the downstream logic to the same effect. > > Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> I think ideally you would add an extcon device (or equivalent, e.g. power supply) somewhere in your Type-C setup so that the VBUS state is set correctly and does not need to be forced permanently. The chipidea USB driver will also benefit from this because AFAICT it uses that information to power down the USB PHY and controller entirely when in device mode and there is no USB cable connected. But I agree that setting up a proper extcon device can be difficult, especially during early bring-up where you just want USB to work and don't care much about power saving. So I still think that making USB work without extcon (like your patch does) is a useful change. For the implementation, I think this flag should effectively emulate the logic that is currently used if you assign an extcon, except that the VBUS state is permanently forced active. Right now your qcom_usb_hs_phy_enable_dp_pullup() function kind of duplicates logic that already exists in the driver, which already has code to set VBUSVLDEXTSEL and VBUSVLDEXT. qcom_usb_hs_phy_set_mode() should be modified to use the else branch (as if vbus_edev was set), which will set VBUSVLDEXTSEL for you. Without extcon you currently use the if (!uphy->vbus_edev) branch, which will enable the internal VBUS detection in the PHY (the ULPI_INT_SESS_VALID code). This does not make any sense IMO if VBUS is not connected to the SoC. And then you basically just need to call qcom_usb_hs_phy_vbus_notifier() to set the VBUSVLDEXT forcefully (rather than relying on the extcon detection). An alternative that I've occasionally used for early bring-up is to simply use a dummy extcon driver [1] that permanently reports active VBUS. The end result is the same. While it's clearly a hack perhaps this makes it a bit more clear that ideally you really should try to assign an extcon device, to avoid keeping the USB controller and PHY on permanently. Thanks, Stephan [1]: https://github.com/msm8916-mainline/linux/commit/3d029e6d4303e125aa013c501308d2d98e3cdc89 > --- > drivers/phy/qualcomm/phy-qcom-usb-hs.c | 36 ++++++++++++++++++++++++++ > 1 file changed, 36 insertions(+) > > diff --git a/drivers/phy/qualcomm/phy-qcom-usb-hs.c b/drivers/phy/qualcomm/phy-qcom-usb-hs.c > index 53e46c220a3aa..45c94f6722c66 100644 > --- a/drivers/phy/qualcomm/phy-qcom-usb-hs.c > +++ b/drivers/phy/qualcomm/phy-qcom-usb-hs.c > @@ -37,6 +37,7 @@ struct qcom_usb_hs_phy { > struct ulpi_seq *init_seq; > struct extcon_dev *vbus_edev; > struct notifier_block vbus_notify; > + u8 enable_dp_pullup:1; > }; > > static int qcom_usb_hs_phy_set_mode(struct phy *phy, > @@ -105,6 +106,23 @@ qcom_usb_hs_phy_vbus_notifier(struct notifier_block *nb, unsigned long event, > return ulpi_write(uphy->ulpi, addr, ULPI_MISC_A_VBUSVLDEXT); > } > > +static int qcom_usb_hs_phy_enable_dp_pullup(struct ulpi *ulpi, bool enable) > +{ > + u8 addr; > + int ret; > + > + if (enable) > + addr = ULPI_SET(ULPI_MISC_A); > + else > + addr = ULPI_CLR(ULPI_MISC_A); > + > + ret = ulpi_write(ulpi, addr, ULPI_MISC_A_VBUSVLDEXTSEL); > + if (ret) > + return ret; > + > + return ulpi_write(ulpi, addr, ULPI_MISC_A_VBUSVLDEXT); > +} > + > static int qcom_usb_hs_phy_power_on(struct phy *phy) > { > struct qcom_usb_hs_phy *uphy = phy_get_drvdata(phy); > @@ -154,6 +172,12 @@ static int qcom_usb_hs_phy_power_on(struct phy *phy) > goto err_ulpi; > } > > + if (uphy->enable_dp_pullup) { > + ret = qcom_usb_hs_phy_enable_dp_pullup(ulpi, true); > + if (ret) > + goto err_ulpi; > + } > + > if (uphy->vbus_edev) { > state = extcon_get_state(uphy->vbus_edev, EXTCON_USB); > /* setup initial state */ > @@ -180,10 +204,19 @@ static int qcom_usb_hs_phy_power_on(struct phy *phy) > static int qcom_usb_hs_phy_power_off(struct phy *phy) > { > struct qcom_usb_hs_phy *uphy = phy_get_drvdata(phy); > + struct ulpi *ulpi = uphy->ulpi; > + int ret; > > if (uphy->vbus_edev) > extcon_unregister_notifier(uphy->vbus_edev, EXTCON_USB, > &uphy->vbus_notify); > + > + if (uphy->enable_dp_pullup) { > + ret = qcom_usb_hs_phy_enable_dp_pullup(ulpi, false); > + if (ret) > + return ret; > + } > + > regulator_disable(uphy->v3p3); > regulator_disable(uphy->v1p8); > clk_disable_unprepare(uphy->sleep_clk); > @@ -229,6 +262,9 @@ static int qcom_usb_hs_phy_probe(struct ulpi *ulpi) > /* NUL terminate */ > uphy->init_seq[size / 2].addr = uphy->init_seq[size / 2].val = 0; > > + if (of_property_read_bool(ulpi->dev.of_node, "qcom,dp-manual-pullup")) > + uphy->enable_dp_pullup = 1; > + > uphy->ref_clk = clk = devm_clk_get(&ulpi->dev, "ref"); > if (IS_ERR(clk)) > return PTR_ERR(clk); > -- > 2.34.1 >
On 29/12/2022 19:45, Stephan Gerhold wrote: > For the implementation, I think this flag should effectively emulate the > logic that is currently used if you assign an extcon Actually that's fine, its a better solution than pushing the pullup constantly as I just suggested in my previous email, there's also zero potential impact to existing boards this way, so, that's obviously better. --- bod
On Thu, Dec 29, 2022 at 08:45:15PM +0100, Stephan Gerhold wrote: > On Thu, Dec 29, 2022 at 06:34:10PM +0000, Bryan O'Donoghue wrote: > > Downstream has a flag called qcom,dp-manual-pullup which informs the > > downstream driver if it should toggle ULPI_MISC_A_VBUSVLDEXTSEL and > > ULPI_MISC_A_VBUSVLDEXT. > > > > Downstream states: > > > > "qcom,dp-manual-pullup: If present, vbus is not routed to USB > > controller/phy and controller driver therefore enables pull-up > > explicitly before starting controller using usbcmd run/stop bit." > > > > Working with a system that has both an external Type-C port controller and > > an internal USB Hub results in a situation where VBUS is not connected to > > the SoC. > > > > In this case we still need to set the DP pullup. > > > > This patch enables and disables the DP pullup on PHY power_on and power_off > > respectively if the DT has declared the bool "qcom,enable-vbus-pullup" > > effectively replicating the downstream logic to the same effect. > > > > Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> > [...] > > An alternative that I've occasionally used for early bring-up is to > simply use a dummy extcon driver [1] that permanently reports active > VBUS. The end result is the same. While it's clearly a hack perhaps this > makes it a bit more clear that ideally you really should try to assign > an extcon device, to avoid keeping the USB controller and PHY on > permanently. > BTW another nice trick that should work in all almost all cases is to use the state of the PMIC USB_IN pin as VBUS detection. All battery- powered devices I have seen route the USB VBUS to PM8916 USB_IN. And even many boards like DB410c seem to do that or at least permanently supply 5V there. In all these cases the &pm8916_usbin extcon will report a VBUS state that should make USB work. Have you tried using that on your MSM8939 board with the Type-C setup? &pm8916_usbin { status = "okay"; }; &usb { status = "okay"; usb-role-switch; extcon = <&pm8916_usbin>; }; &usb_hs_phy { extcon = <&pm8916_usbin>; }; Stephan
On 29/12/2022 21:02, Stephan Gerhold wrote: > On Thu, Dec 29, 2022 at 08:45:15PM +0100, Stephan Gerhold wrote: >> On Thu, Dec 29, 2022 at 06:34:10PM +0000, Bryan O'Donoghue wrote: >>> Downstream has a flag called qcom,dp-manual-pullup which informs the >>> downstream driver if it should toggle ULPI_MISC_A_VBUSVLDEXTSEL and >>> ULPI_MISC_A_VBUSVLDEXT. >>> >>> Downstream states: >>> >>> "qcom,dp-manual-pullup: If present, vbus is not routed to USB >>> controller/phy and controller driver therefore enables pull-up >>> explicitly before starting controller using usbcmd run/stop bit." >>> >>> Working with a system that has both an external Type-C port controller and >>> an internal USB Hub results in a situation where VBUS is not connected to >>> the SoC. >>> >>> In this case we still need to set the DP pullup. >>> >>> This patch enables and disables the DP pullup on PHY power_on and power_off >>> respectively if the DT has declared the bool "qcom,enable-vbus-pullup" >>> effectively replicating the downstream logic to the same effect. >>> >>> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> >> [...] >> >> An alternative that I've occasionally used for early bring-up is to >> simply use a dummy extcon driver [1] that permanently reports active >> VBUS. The end result is the same. While it's clearly a hack perhaps this >> makes it a bit more clear that ideally you really should try to assign >> an extcon device, to avoid keeping the USB controller and PHY on >> permanently. >> > > BTW another nice trick that should work in all almost all cases is to > use the state of the PMIC USB_IN pin as VBUS detection. All battery- > powered devices I have seen route the USB VBUS to PM8916 USB_IN. And > even many boards like DB410c seem to do that or at least permanently > supply 5V there. In all these cases the &pm8916_usbin extcon will > report a VBUS state that should make USB work. > > Have you tried using that on your MSM8939 board with the Type-C setup? > > &pm8916_usbin { > status = "okay"; > }; > > &usb { > status = "okay"; > usb-role-switch; > extcon = <&pm8916_usbin>; > }; > > &usb_hs_phy { > extcon = <&pm8916_usbin>; > }; > > Stephan I checked USBIN before my last email reply. Its possible its connected but its not there on the 8939 schematic I have. --- bod
On Thu, Dec 29, 2022 at 09:05:23PM +0000, Bryan O'Donoghue wrote: > On 29/12/2022 21:02, Stephan Gerhold wrote: > > On Thu, Dec 29, 2022 at 08:45:15PM +0100, Stephan Gerhold wrote: > > > On Thu, Dec 29, 2022 at 06:34:10PM +0000, Bryan O'Donoghue wrote: > > > > Downstream has a flag called qcom,dp-manual-pullup which informs the > > > > downstream driver if it should toggle ULPI_MISC_A_VBUSVLDEXTSEL and > > > > ULPI_MISC_A_VBUSVLDEXT. > > > > > > > > Downstream states: > > > > > > > > "qcom,dp-manual-pullup: If present, vbus is not routed to USB > > > > controller/phy and controller driver therefore enables pull-up > > > > explicitly before starting controller using usbcmd run/stop bit." > > > > > > > > Working with a system that has both an external Type-C port controller and > > > > an internal USB Hub results in a situation where VBUS is not connected to > > > > the SoC. > > > > > > > > In this case we still need to set the DP pullup. > > > > > > > > This patch enables and disables the DP pullup on PHY power_on and power_off > > > > respectively if the DT has declared the bool "qcom,enable-vbus-pullup" > > > > effectively replicating the downstream logic to the same effect. > > > > > > > > Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> > > > [...] > > > > > > An alternative that I've occasionally used for early bring-up is to > > > simply use a dummy extcon driver [1] that permanently reports active > > > VBUS. The end result is the same. While it's clearly a hack perhaps this > > > makes it a bit more clear that ideally you really should try to assign > > > an extcon device, to avoid keeping the USB controller and PHY on > > > permanently. > > > > > > > BTW another nice trick that should work in all almost all cases is to > > use the state of the PMIC USB_IN pin as VBUS detection. All battery- > > powered devices I have seen route the USB VBUS to PM8916 USB_IN. And > > even many boards like DB410c seem to do that or at least permanently > > supply 5V there. In all these cases the &pm8916_usbin extcon will > > report a VBUS state that should make USB work. > > > > Have you tried using that on your MSM8939 board with the Type-C setup? > > > > &pm8916_usbin { > > status = "okay"; > > }; > > > > &usb { > > status = "okay"; > > usb-role-switch; > > extcon = <&pm8916_usbin>; > > }; > > > > &usb_hs_phy { > > extcon = <&pm8916_usbin>; > > }; > > > > Stephan > > I checked USBIN before my last email reply. > > Its possible its connected but its not there on the 8939 schematic I have. > Then it doesn't seem to be a particularly complete schematic. :-) PM8916 definitely has USB_IN pads (pad # N13, P13). :-)
On 29/12/2022 21:11, Stephan Gerhold wrote: > Then it doesn't seem to be a particularly complete schematic. 😄 > PM8916 definitely has USB_IN pads (pad # N13, P13). 😄 Let me check again. No sorry USB_IN_0 and USB_IN_1 are connected to +5V in my schematic, I did check USB_IN I just forgot why it wasn't usable... +5v not VBUS is what its connected to. VBUS connects to VBUS_DET on the USB Hub - a USB2514BQFN36, there's no corresponding routing of VBUS onto a GPIO or USB_IN_x on the PMIC. I assume there's some good reason the PCB designer did it this way .. there's enough of a reason behind it that Qcom put a workaround for the case where PCBs don't route the VBUS state to the SoC or PMIC. --- bod
On Thu, Dec 29, 2022 at 09:20:03PM +0000, Bryan O'Donoghue wrote: > On 29/12/2022 21:11, Stephan Gerhold wrote: > > Then it doesn't seem to be a particularly complete schematic. 😄 > > PM8916 definitely has USB_IN pads (pad # N13, P13). 😄 > > Let me check again. > > No sorry USB_IN_0 and USB_IN_1 are connected to +5V in my schematic, I did > check USB_IN I just forgot why it wasn't usable... +5v not VBUS is what its > connected to. > That is still good enough to replace qcom,dp-manual-pullup though. If you have +5V connected to USB_IN then &pm8916_usbin should report active VBUS permanently. Set it as extcon for &usb and &usb_hs_phy and you should have VBUSVLDEXT "pulled-up" like in your patch here, without any driver changes. :-) It's a bit of a hack of course, which probably deserves a comment in the device tree. But since it should not make any functional difference compared to this patch the approach might be easier than getting this patch finalized & accepted. I leave that up to you :) Stephan
On 29/12/2022 21:41, Stephan Gerhold wrote:
> That is still good enough to replace qcom,dp-manual-pullup though.
But there's no requirement to tie USB_IN_x high if VBUS is not connected
to it.
---
bod
On Thu, Dec 29, 2022 at 11:38:04PM +0000, Bryan O'Donoghue wrote: > On 29/12/2022 21:41, Stephan Gerhold wrote: > > That is still good enough to replace qcom,dp-manual-pullup though. > > But there's no requirement to tie USB_IN_x high if VBUS is not connected to > it. > I've yet to find any device where USB_IN is not connected in a usable way. But as I said I leave it up to you - it would be nice to have a proper solution for devices where VBUS state cannot be determined at all. Those devices should be rare though so if &pm8916_usbin works in your case maybe the time would be better invested into other open problems right now. :) Thanks, Stephan
diff --git a/drivers/phy/qualcomm/phy-qcom-usb-hs.c b/drivers/phy/qualcomm/phy-qcom-usb-hs.c index 53e46c220a3aa..45c94f6722c66 100644 --- a/drivers/phy/qualcomm/phy-qcom-usb-hs.c +++ b/drivers/phy/qualcomm/phy-qcom-usb-hs.c @@ -37,6 +37,7 @@ struct qcom_usb_hs_phy { struct ulpi_seq *init_seq; struct extcon_dev *vbus_edev; struct notifier_block vbus_notify; + u8 enable_dp_pullup:1; }; static int qcom_usb_hs_phy_set_mode(struct phy *phy, @@ -105,6 +106,23 @@ qcom_usb_hs_phy_vbus_notifier(struct notifier_block *nb, unsigned long event, return ulpi_write(uphy->ulpi, addr, ULPI_MISC_A_VBUSVLDEXT); } +static int qcom_usb_hs_phy_enable_dp_pullup(struct ulpi *ulpi, bool enable) +{ + u8 addr; + int ret; + + if (enable) + addr = ULPI_SET(ULPI_MISC_A); + else + addr = ULPI_CLR(ULPI_MISC_A); + + ret = ulpi_write(ulpi, addr, ULPI_MISC_A_VBUSVLDEXTSEL); + if (ret) + return ret; + + return ulpi_write(ulpi, addr, ULPI_MISC_A_VBUSVLDEXT); +} + static int qcom_usb_hs_phy_power_on(struct phy *phy) { struct qcom_usb_hs_phy *uphy = phy_get_drvdata(phy); @@ -154,6 +172,12 @@ static int qcom_usb_hs_phy_power_on(struct phy *phy) goto err_ulpi; } + if (uphy->enable_dp_pullup) { + ret = qcom_usb_hs_phy_enable_dp_pullup(ulpi, true); + if (ret) + goto err_ulpi; + } + if (uphy->vbus_edev) { state = extcon_get_state(uphy->vbus_edev, EXTCON_USB); /* setup initial state */ @@ -180,10 +204,19 @@ static int qcom_usb_hs_phy_power_on(struct phy *phy) static int qcom_usb_hs_phy_power_off(struct phy *phy) { struct qcom_usb_hs_phy *uphy = phy_get_drvdata(phy); + struct ulpi *ulpi = uphy->ulpi; + int ret; if (uphy->vbus_edev) extcon_unregister_notifier(uphy->vbus_edev, EXTCON_USB, &uphy->vbus_notify); + + if (uphy->enable_dp_pullup) { + ret = qcom_usb_hs_phy_enable_dp_pullup(ulpi, false); + if (ret) + return ret; + } + regulator_disable(uphy->v3p3); regulator_disable(uphy->v1p8); clk_disable_unprepare(uphy->sleep_clk); @@ -229,6 +262,9 @@ static int qcom_usb_hs_phy_probe(struct ulpi *ulpi) /* NUL terminate */ uphy->init_seq[size / 2].addr = uphy->init_seq[size / 2].val = 0; + if (of_property_read_bool(ulpi->dev.of_node, "qcom,dp-manual-pullup")) + uphy->enable_dp_pullup = 1; + uphy->ref_clk = clk = devm_clk_get(&ulpi->dev, "ref"); if (IS_ERR(clk)) return PTR_ERR(clk);