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: 10105835 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 50EF560752 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 4E6CA29915 for ; Mon, 11 Dec 2017 21:46:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 432DC2991E; Mon, 11 Dec 2017 21:46:55 +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 E96D029915 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=EMMlnq5RwvNfAI4f1+gyVOEjKvc4l+OMVnart+4SzTY=; b=hOK zuLp1/gJIHM7KtyySl+TCFxyZRReQeok7sScIokDZCyAAjwKyuGFlWccbtMKJ7gKj9lbuGPF+Z7ya b5f7PW8gnrcxiv1UwG36GMLNUNclVJI4UHfV0kGKirNSysJknut0S6AQfwpaegZ0isjXoLxsGV+a7 Z4AtRMKjG0WNwNrmIBiXnv5HfinpumKfESWrDCYuZpsdg9sS0t5BervnCXcOgdvIUhMNXzkBbF2Y9 SS65MtJIbOxPisD0HxQ9sDiOhUC/rR3JnDHtp1ZahFbDPieolR+30HXAIGgMZGiwn/aVHyR6acu7O Y2qKFCicr4UjHVV42eg2kZdBQJxe0Jw==; 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 1eOVuY-0006yN-FQ; Mon, 11 Dec 2017 21:46:54 +0000 Received: from mail-it0-x241.google.com ([2607:f8b0:4001:c0b::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eOVuT-0006tW-EW for linux-arm-kernel@lists.infradead.org; Mon, 11 Dec 2017 21:46:51 +0000 Received: by mail-it0-x241.google.com with SMTP id x28so19591033ita.0 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=lr4wwA/W0DL9sQj1D4nWkrdYBqEjXanrEYjEN+tdEeNaBeRRd1t6DDZrZXM16zvl9r FX8KYtKkS6QqCoNncdkXMysiNBeQZFwgyCvX88mjieZE6Tdz8tu6+2DmKiTA6QihbCwK P5HsPd+obnMBvubSk/UV7eZ3VJRepDEUc+KjbWM8eQwLiQi+HMoNB/lN/3BEb0/clXuJ YFO/Ru6y2lJYle2QKUNmWsKVe7Ierbj/9NDFNmSMzsx8xGrRJxnFf+NzD5Ah2paDMLgH Ty9SKdnFklV961cW8PU9iv9hHWgUg92ehXkIpr3C+85IP1ejHlSGv+60paPuV5BZp/L5 wzEg== X-Gm-Message-State: AKGB3mJfpY2q3rmeX3CCwLdZ93XLJ/b7lBrvZJ2kb3pYW8LY3uHXPsOg 6QgJdlBIzyuTdAmIn1mv4N7cBg== 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_567987_5659EEE3 X-CRM114-Status: GOOD ( 18.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: 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-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=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);