From patchwork Wed Aug 3 15:38:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Kemnade X-Patchwork-Id: 9261613 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 6D89160865 for ; Wed, 3 Aug 2016 16:44:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F62127FA9 for ; Wed, 3 Aug 2016 16:44:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 542E1280F4; Wed, 3 Aug 2016 16:44:56 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9FC127FA9 for ; Wed, 3 Aug 2016 16:44:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758166AbcHCQo3 (ORCPT ); Wed, 3 Aug 2016 12:44:29 -0400 Received: from glaubenleben.de ([85.214.105.140]:52846 "EHLO glaubenleben.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758121AbcHCQnp (ORCPT ); Wed, 3 Aug 2016 12:43:45 -0400 Received: from p5dcc3d40.dip0.t-ipconnect.de ([93.204.61.64] helo=aktux.fritz.box) by glaubenleben.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1bUyGH-0001l3-NJ; Wed, 03 Aug 2016 17:39:13 +0200 From: Andreas Kemnade To: Bin Liu , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, Tony Lindgren , letux-kernel@openphoenux.org Cc: Andreas Kemnade Subject: [PATCH v2] musb: omap2430: do not assume balanced enable()/disable() Date: Wed, 3 Aug 2016 17:38:51 +0200 Message-Id: <1470238731-32358-1-git-send-email-andreas@kemnade.info> X-Mailer: git-send-email 2.1.4 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The code assumes that omap2430_musb_enable() and omap2430_musb_disable() are called in a balanced way. That fact is broken by the fact that musb_init_controller() calls musb_platform_disable() to switch from unknown state to off state on initialisation. That means that phy_power_off() is called first so that phy->power_count gets -1 and the phy is not enabled on phy_power_on(). So when usb gadget is started the phy is not powered on. Depending on the phy used that caused various problems. Besides of causing usb problems, that can also have side effects. In the case of using the phy_twl4030, that prevents also charging the battery via usb (using twl4030_charger) and so makes further kernel debugging hard. The problem was seen with 4.7 on an openphoenux gta04. It has a DM3730 SoC and a TPS65950 companion. phy->power never became 1 and so the usb did get powered on. The patch prevents phy_power_off() from being called when it is already off. Signed-off-by: Andreas Kemnade Tested-by: Laurent Pinchart --- changes in v2: improved commit message drivers/usb/musb/omap2430.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index 0b4cec9..c1a2b7b 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c @@ -413,9 +413,10 @@ static void omap2430_musb_disable(struct musb *musb) struct device *dev = musb->controller; struct omap2430_glue *glue = dev_get_drvdata(dev->parent); - if (!WARN_ON(!musb->phy)) - phy_power_off(musb->phy); - + if (glue->enabled) { + if (!WARN_ON(!musb->phy)) + phy_power_off(musb->phy); + } if (glue->status != MUSB_UNKNOWN) omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DISCONNECT);