From patchwork Mon Dec 11 21:45:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10105833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 054A660751 for ; Mon, 11 Dec 2017 21:46:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F31BA29919 for ; Mon, 11 Dec 2017 21:46:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7BCF2991E; Mon, 11 Dec 2017 21:46:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 967C729915 for ; Mon, 11 Dec 2017 21:46:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=IoRvU5c1+1Isqp1UM37pagiNepmz9xu6NvbsCmNU8To=; b=SFV P4fN+hIUdnhLrg3UlN54M+1SExVFikux1tnMFIDgVMpSsL+ZLrGFl+t5jP5z0eHsttPSbXrgY6hYb UArYhct8ds184MLbWTBtQdyBo2gsoRxVHLRhfzxcgBJAwj563jaPyIUtj11/tiDhpkxmmdUh15K+V Z/fKikeuz9yAZvmI9K98xWosVvbQIZmRANFBoXlai5+gOhJT7s3pry2ORllmvWGqhI/dAiYWJfh3B aOKRvvbRiYKBHyHfFaGrs4q8oyVWl2WbyNePBX58L0L+JKJ9753HBhJMCstSN7WG3fzjsLu9XVSnZ WxlHOjZylsf+2OcJl47CrIsF7TeHidw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eOVuX-0006xf-7j; Mon, 11 Dec 2017 21:46:53 +0000 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eOVuT-0006tV-EX for linux-rockchip@lists.infradead.org; Mon, 11 Dec 2017 21:46:51 +0000 Received: by mail-it0-x244.google.com with SMTP id p139so19568597itb.1 for ; Mon, 11 Dec 2017 13:46:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=WkrMHrOiFnG7Ui9/eY9UdwK93dA1JUo0mTs7JS3Ftfk=; b=HDGLvDAFb7K2prg6S0M1ANdVNXFiEu1mIi9DKZL+FNJaNGzKP/DWIxrTo2LABuP4gp TBXS0F3PwCAbFCmnUYzBsotVLMv3toRscwQT811wCqyiekZjtCM7Sum90W00MbrH5NkO l+Ffif5C8q4rwruGrYQYLuNVTk8X43+AIqZAg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WkrMHrOiFnG7Ui9/eY9UdwK93dA1JUo0mTs7JS3Ftfk=; b=GiWaVztC9Z54cH3bIWlFLOtAF518fdZN/+zNbBQ+PYZcqSkfNDAohrBONma84sXFqx mJJ7EchEPXf3At5Hwvh+LB3ekdP4TbHAgf2eO94UtrrJAavqcTrjyueFAWonLKo43Ac8 C4mz8xyBnPP1Sloqc3+kFX2XlZGZn3QAIJJQLw1JqWZMX7CTSYJXKyRBaOpdYJb33exi 2S/VM9UwOBbt0tHgftIyUUFizsevhzCeKT7GME3Zcr+GrmKQ46qUQas75F5x7KecPVh4 eRu6n54lOk9rJukg7nUoxVqIO5ZfLGWzooG/bTvpDzyUcsbY55RUQewh/eU37mHgLuER qDsw== X-Gm-Message-State: AKGB3mLfM34hLSUb6G6yKGr0HSuL2hD6nlDslEORMdwQYKZt/QbMp/re LX9hxZI1pGSFZ9opxXUN1zXs9A== X-Google-Smtp-Source: ACJfBou/tfHRbfHzHHkeUdcsE1XHwh2MWwm5/hMK6/A8e3iRB1+/illurPyoLbWEHvieMYQgEsfvtA== X-Received: by 10.36.83.133 with SMTP id n127mr3236236itb.60.1513028786966; Mon, 11 Dec 2017 13:46:26 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:0:1000:1600:d6c3:e876:3156:493b]) by smtp.gmail.com with ESMTPSA id v65sm4201715itb.30.2017.12.11.13.46.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Dec 2017 13:46:25 -0800 (PST) From: Douglas Anderson To: kishon@ti.com Subject: [PATCH] phy: rockchip-typec: Try to turn the PHY on several times Date: Mon, 11 Dec 2017 13:45:53 -0800 Message-Id: <20171211214553.118337-1-dianders@chromium.org> X-Mailer: git-send-email 2.15.1.424.g9478a66081-goog X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171211_134649_572987_0EC5D0EF X-CRM114-Status: GOOD ( 17.20 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: balbi@kernel.org, linux-usb@vger.kernel.org, Heiko Stuebner , linux-rockchip@lists.infradead.org, zyw@rock-chips.com, briannorris@chromium.org, Douglas Anderson , linux-kernel@vger.kernel.org, groeck@chromium.org, mka@chromium.org, enric.balletbo@collabora.com, wulf@rock-chips.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Bind / unbind stress testing of the USB controller on rk3399 found that we'd often end up with lots of failures that looked like this: phy phy-ff800000.phy.9: phy poweron failed --> -110 dwc3 fe900000.dwc3: failed to initialize core dwc3: probe of fe900000.dwc3 failed with error -110 Those errors were sometimes seen at bootup too, in which case USB peripherals wouldn't work until unplugged and re-plugged in. I spent some time trying to figure out why the PHY was failing to power on but I wasn't able to. Possibly this has to do with the fact that the PHY docs say that the USB controller "needs to be held in reset to hold pipe power state in P2 before initializing the Type C PHY" but that doesn't appear to be easy to do with the dwc3 driver today. Messing around with the ordering of the reset vs. the PHY initialization in the dwc3 driver didn't seem to fix things. I did, however, find that if I simply retry the power on it seems to have a good chance of working. So let's add some retries. I ran a pretty tight bind/unbind loop overnight. When I did so, I found that I need to retry between 1% and 2% of the time. Overnight I found only a small handful of times where I needed 2 retries. I never found a case where I needed 3 retries. I'm completely aware of the fact that this is quite an ugly hack and I wish I didn't have to resort to it, but I have no other real idea how to make this hardware reliable. If Rockchip in the future can come up with a solution we can always revert this hack. Until then, let's at least have something that works. This patch is tested atop Enric's latest dwc3 patch series ending at: https://patchwork.kernel.org/patch/10095527/ ...but it could be applied independently of that series without any bad effects. For some more details on this bug, you can refer to: https://bugs.chromium.org/p/chromium/issues/detail?id=783464 Signed-off-by: Douglas Anderson --- drivers/phy/rockchip/phy-rockchip-typec.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-typec.c b/drivers/phy/rockchip/phy-rockchip-typec.c index ee85fa0ca4b0..5c2157156ce1 100644 --- a/drivers/phy/rockchip/phy-rockchip-typec.c +++ b/drivers/phy/rockchip/phy-rockchip-typec.c @@ -349,6 +349,8 @@ #define MODE_DFP_USB BIT(1) #define MODE_DFP_DP BIT(2) +#define POWER_ON_TRIES 5 + struct usb3phy_reg { u32 offset; u32 enable_bit; @@ -818,9 +820,8 @@ static int tcphy_get_mode(struct rockchip_typec_phy *tcphy) return mode; } -static int rockchip_usb3_phy_power_on(struct phy *phy) +static int _rockchip_usb3_phy_power_on(struct rockchip_typec_phy *tcphy) { - struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy); struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs; const struct usb3phy_reg *reg = &cfg->pipe_status; int timeout, new_mode, ret = 0; @@ -867,6 +868,25 @@ static int rockchip_usb3_phy_power_on(struct phy *phy) return ret; } +static int rockchip_usb3_phy_power_on(struct phy *phy) +{ + struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy); + int ret; + int tries; + + for (tries = 0; tries < POWER_ON_TRIES; tries++) { + ret = _rockchip_usb3_phy_power_on(tcphy); + if (!ret) + break; + } + + if (tries && !ret) + dev_info(tcphy->dev, "Needed %d loops to turn on\n", tries); + + return ret; +} + + static int rockchip_usb3_phy_power_off(struct phy *phy) { struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy);