From patchwork Fri Jan 20 18:50:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 9529275 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 2325E60434 for ; Fri, 20 Jan 2017 18:54:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17A312040D for ; Fri, 20 Jan 2017 18:54:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B836286A2; Fri, 20 Jan 2017 18:54:09 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no 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 9D5C32040D for ; Fri, 20 Jan 2017 18:54:08 +0000 (UTC) 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 1cUeK4-0004L3-4R; Fri, 20 Jan 2017 18:54:04 +0000 Received: from mail-pg0-f52.google.com ([74.125.83.52]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cUeIQ-0001zc-Je for linux-arm-kernel@lists.infradead.org; Fri, 20 Jan 2017 18:52:26 +0000 Received: by mail-pg0-f52.google.com with SMTP id t6so25585037pgt.3 for ; Fri, 20 Jan 2017 10:52:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LSF8wmYZeZ1EtDEzeK0K+D7OAW9TSjZGln9gDKva/TY=; b=Eom+w7RQgzkoNNqrHansobhnDAaVP27Z685+ZiHYGEl6W7lLOqyUpUi804CIeNbnZV hceMkFaxRd1iq1FenvnBZiXrg+dJQ2jA9xjljIScZ07IKLHWh56dKVaf11pCofb8PEkx k+n4NSodbIUmbR8Db4WGs3usFRpdDQ4BGXmlY= 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:in-reply-to :references; bh=LSF8wmYZeZ1EtDEzeK0K+D7OAW9TSjZGln9gDKva/TY=; b=tVdT+PRJdaaUf/JxnW4tsIwVHgmBapzS3DqfXb9OfWnmGSCibpOb/xQs29HyFCzCcs o0QTCo83UdNv0n/Pe30YruVOT1nsy5ygNPdzzN3S/4SDm0WAJP9ltx01hTFAvMNuwjb5 TaJ6ukDo4sNEe7UiDjGyz37N8RS26ch+c6dILSRjqiJTx1vusq8uenaosh9UDFP+kHN3 otOXuUVcQTJicQWoTXnZho+nKPhmh5Cv1qFrEe7Ch+VDGMf1OC6hOxNGED9B/WD/xXgI MFxfh4cnvDHBQHYtks0mED2s/5Ho72x5yDn+OnDLi7RDn777MZr9hAbdVGayg2XCciqi BTnQ== X-Gm-Message-State: AIkVDXJ9e84N81GTwHWPDUwQvPY9gIlAC9OijTnsuwbHy83ACxqVzUnAWtr670pyYeenW5ve X-Received: by 10.99.170.70 with SMTP id x6mr18423389pgo.14.1484938261867; Fri, 20 Jan 2017 10:51:01 -0800 (PST) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id j78sm18574274pfk.39.2017.01.20.10.51.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 20 Jan 2017 10:51:01 -0800 (PST) From: Stephen Boyd To: Peter Chen , Kishon Vijay Abraham I Subject: [PATCH v7 2/5] usb: chipidea: msm: Configure phy for appropriate mode Date: Fri, 20 Jan 2017 10:50:54 -0800 Message-Id: <20170120185057.16206-3-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20170120185057.16206-1-stephen.boyd@linaro.org> References: <20170120185057.16206-1-stephen.boyd@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170120_105222_689715_BEE916DD X-CRM114-Status: GOOD ( 15.02 ) 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: Felipe Balbi , Arnd Bergmann , Neil Armstrong , linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson , Greg Kroah-Hartman , Andy Gross , 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 When the qcom chipidea controller is used with an extcon, we need to signal device mode or host mode to the phy so it can configure itself for the correct mode. This should be done after the phy is powered up, so that the register writes work correctly. Add in the appropriate phy_set_mode() call here. To signal the correct state to the qcom glue driver we need to change the ci->role before we do the role switch. Make sure to undo the change if the role switch fails, but otherwise update the state before calling the role start function so that the glue driver knows what state to configure for. Cc: Greg Kroah-Hartman Signed-off-by: Stephen Boyd --- Made this msm specific because of how msm handles phy powerup. drivers/usb/chipidea/ci.h | 7 +++++-- drivers/usb/chipidea/ci_hdrc_msm.c | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index 59e22389c10b..18348b0529af 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -268,6 +268,7 @@ static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci) static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role) { int ret; + enum ci_role prev_role; if (role >= CI_ROLE_END) return -EINVAL; @@ -275,9 +276,11 @@ static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role) if (!ci->roles[role]) return -ENXIO; + prev_role = ci->role; + ci->role = role; ret = ci->roles[role]->start(ci); - if (!ret) - ci->role = role; + if (ret) + ci->role = prev_role; return ret; } diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c b/drivers/usb/chipidea/ci_hdrc_msm.c index f1ede7909f54..9c58d13970ca 100644 --- a/drivers/usb/chipidea/ci_hdrc_msm.c +++ b/drivers/usb/chipidea/ci_hdrc_msm.c @@ -125,6 +125,10 @@ static int ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event) hw_write(ci, OP_USBCMD, HSPHY_SESS_VLD_CTRL, HSPHY_SESS_VLD_CTRL); + if (ci->role == CI_ROLE_GADGET) + phy_set_mode(ci->phy, PHY_MODE_USB_DEVICE); + else if (ci->role == CI_ROLE_HOST) + phy_set_mode(ci->phy, PHY_MODE_USB_HOST); } break; case CI_HDRC_CONTROLLER_STOPPED_EVENT: