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: 9529259 X-Patchwork-Delegate: agross@codeaurora.org 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 5BFA360434 for ; Fri, 20 Jan 2017 18:52:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 517682040D for ; Fri, 20 Jan 2017 18:52:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4637E286A2; Fri, 20 Jan 2017 18:52:19 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable 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 C8F0D2040D for ; Fri, 20 Jan 2017 18:52:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753259AbdATSvy (ORCPT ); Fri, 20 Jan 2017 13:51:54 -0500 Received: from mail-pg0-f51.google.com ([74.125.83.51]:35142 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752852AbdATSvC (ORCPT ); Fri, 20 Jan 2017 13:51:02 -0500 Received: by mail-pg0-f51.google.com with SMTP id 194so25576614pgd.2 for ; Fri, 20 Jan 2017 10:51: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=EUusOQDkk2Hmh+9eTSh+mhdptbHa40r+pFpQxW/K+xG9yALS5URs7dCuiEmDSRAAQs 85jju0Wm3hkNvuiYh0THR62vY4VxtvhXCEB4wEiRu1mzZ6/aWM/xGysnKWsfBzkl8V8V fu4MduHNda8wvwk4JBWa6CZz1SBatmecmeA7HM/mzHxuTubSp2sQNAM90qnKJQ8sZoqt mCBDofpdOHFOF6qTVsADwkzn626Ip+7HyT1FNt2E9Yt127jvyUb+46Mwc8lU1razmFwm OgwVmm0VYLp+4RJV1TBnvfps/k8n5SMzyUrW2rbmhJFFeO6MnOJZhpkrNeFOh6bGyO+e AQFw== X-Gm-Message-State: AIkVDXI0mJPFNuudUZ/T20B9kIOvT3zQz+9GZetP0cKmvuCArgSHNW57DdSIN5zYYf+6zu54 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 Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Andy Gross , Bjorn Andersson , Neil Armstrong , Arnd Bergmann , Felipe Balbi , linux-usb@vger.kernel.org, Greg Kroah-Hartman 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> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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: