From patchwork Thu Oct 10 13:56:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 11183649 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F034F76 for ; Thu, 10 Oct 2019 13:57:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D166D21835 for ; Thu, 10 Oct 2019 13:57:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AWRKwkWr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726132AbfJJN5L (ORCPT ); Thu, 10 Oct 2019 09:57:11 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41165 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725959AbfJJN5K (ORCPT ); Thu, 10 Oct 2019 09:57:10 -0400 Received: by mail-wr1-f65.google.com with SMTP id q9so8027192wrm.8; Thu, 10 Oct 2019 06:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=BI+X9/23+Lvr8h9vJlp7cjBXaJiIevfv3xHjpHNIvrc=; b=AWRKwkWrp/jPWpCQAuNyzR/eF5h9hIwxFlb5RXrN521n9DPGGRADph3yS+BfIGqF+Z 2P/9yq5kzVo0QKGSijDzI8HYBVVMQyiNQ8GlySyCqExxqQFMLdwMcwc3N7KRD7NcMpJH tAHV20qsYM0IC+TyFSHB4L13ZjGhdwFxYPBg1GX0BQa7eVSOo+QQXD/zHDosRM1Bs/EY QhannvF7eHGqrYp58PPhC+nREvnJ0oqjuoid3xS9+kGkgiJClwHBqlseaKYcR3mnqT+1 lpvsM2gjOKzdZyxVJJMgHZCnAjBiqp0Uf2eW7pOuc6WMvHp8VmK21T571LYOEtWD4/G3 VF9w== 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=BI+X9/23+Lvr8h9vJlp7cjBXaJiIevfv3xHjpHNIvrc=; b=JcJHeyUYQiEAKbUERbTJwdehB85jfFDdONbu2ZySyuh7gyNsX3Eam46oaGJtUY2me8 UT2aCzSII8hH8ON7rpkLYrnKr8E7goG9Osf21ZV/X6Nql5S2Mf3bD4q9kXHLq+Gah4f6 Uh5lH8Y0uF5lDJLAbvYntkpW1BMiYeppcJ33lz9KcR3TpDDea2MIohVuDfK84L2Ypw0E LqIOCg6dnuL8Cr9VETszItZB5QhZY0zci7VYLt3Xp26ysmwEAdOY7QhoGQmvaIMnciDr f1P7Zl+4KYp+bXX0Ylgq3i2RO0PHfF25Iq2ASMZ5isYOq5ukmPmXb99Bs+kjCOvzfJQp EA+Q== X-Gm-Message-State: APjAAAUl1P+Py5paYXk2Xxgo1KWsmBJ8a9Z3xq786mTIj5kOiKYun+ap IljLbr3CR8t2Wcu4lMFAUUx1CyewmEU= X-Google-Smtp-Source: APXvYqx9xZon+o/bW79wbx03uRwh314eTdqElwNEpnJLMdjcHDrL1qCZkldI2UDo81i5d1UPOHrRLw== X-Received: by 2002:a5d:6447:: with SMTP id d7mr8801561wrw.247.1570715827786; Thu, 10 Oct 2019 06:57:07 -0700 (PDT) Received: from localhost ([194.105.145.90]) by smtp.gmail.com with ESMTPSA id q15sm9125827wrg.65.2019.10.10.06.57.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Oct 2019 06:57:06 -0700 (PDT) From: Igor Opaniuk To: linux-usb@vger.kernel.org Cc: Marcel Ziswiler , Philippe Schenker , Stefan Agner , Max Krummenacher , Oleksandr Suvorov , Li Jun , Igor Opaniuk , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] usb: phy: add usb mode for usb_phy Date: Thu, 10 Oct 2019 16:56:54 +0300 Message-Id: <20191010135656.3264-1-igor.opaniuk@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Li Jun USB phy driver may need to know the current working mode of the controller, and can provide different settings according to host mode or device mode. Signed-off-by: Li Jun Signed-off-by: Igor Opaniuk --- v2: - restored original commit author - fixed build for multi_v7 include/linux/usb/phy.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index e4de6bc1f69b..d138703e3688 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -63,6 +63,13 @@ enum usb_otg_state { OTG_STATE_A_VBUS_ERR, }; +/* The usb role of phy to be working with */ +enum usb_current_mode { + USB_CURRENT_MODE_NONE, + USB_CURRENT_MODE_HOST, + USB_CURRENT_MODE_DEVICE, +}; + struct usb_phy; struct usb_otg; @@ -155,6 +162,13 @@ struct usb_phy { * manually detect the charger type. */ enum usb_charger_type (*charger_detect)(struct usb_phy *x); + + /* + * Set current working mode of the USB controller + * (device, host) + */ + int (*set_mode)(struct usb_phy *x, + enum usb_current_mode mode); }; /* for board-specific init logic */ @@ -213,6 +227,15 @@ usb_phy_vbus_off(struct usb_phy *x) return x->set_vbus(x, false); } +static inline int +usb_phy_set_mode(struct usb_phy *x, enum usb_current_mode mode) +{ + if (!x || !x->set_mode) + return 0; + + return x->set_mode(x, mode); +} + /* for usb host and peripheral controller drivers */ #if IS_ENABLED(CONFIG_USB_PHY) extern struct usb_phy *usb_get_phy(enum usb_phy_type type); From patchwork Thu Oct 10 13:56:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 11183647 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E20718B7 for ; Thu, 10 Oct 2019 13:57:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 21BE421929 for ; Thu, 10 Oct 2019 13:57:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u8Ng/a9d" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726182AbfJJN5L (ORCPT ); Thu, 10 Oct 2019 09:57:11 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:56145 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725988AbfJJN5L (ORCPT ); Thu, 10 Oct 2019 09:57:11 -0400 Received: by mail-wm1-f68.google.com with SMTP id a6so7052543wma.5; Thu, 10 Oct 2019 06:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yJGdOYILL8kJ5SPdZdHmvJP7tXBLkUNJvrUzb6ANFWI=; b=u8Ng/a9dlF4zJDy3XWXa92ikk0qVSsuwM0N7MmOzC2RZes/uwN3t3j+e3pvzC1mdPm u7B31QUxyUx15DTYeTmifwIZGa7I0tVDGnQMOrXyLSFTsPnyPVlhbwwUofUcFrJ+tcuP Ns28G+4nKopaVXFz3SrgXEUMjFW7kqg0h5yrfCKtTNmOLEdTn6GJoO4cyJ+8n7cXZDlh /DKe29n9JbSZNqGH3KdQfZ/2JlEWU1LlcU020avuf1wwZuCl6jChuV54xZU0vrkkCt9f a8VN80sHKOB6UyWkeH0BLaOAIwv6p92f3qJs7Y9mWw8VB6X+pCLdvmVKSEd5aUetXx8f naEA== 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=yJGdOYILL8kJ5SPdZdHmvJP7tXBLkUNJvrUzb6ANFWI=; b=FFREntuLHKIcnr6smYaooAaSuErRUrMVaE/cCnmqyS18bXdeJiTsdd4icDRzZ7KKvm p7Y2nzK1oJxboVpLGgUcME970bivM5Vy5g0YSXJ7YkBP7Z+zNpF2pteoDG2ds31dvNaI 3lAK5ZD2i2CEj54e6CcyMBBr4+oPx4IIITsvWkvbJQcuLjwpNhMB2reMRenXL3h2t7pY aSQ9FfyziYMBWUIwmnogsTfb5Nf0ZwETOAItAb/28NqiZdQFuEbWLiA7EEk13sA6mfGg Qs1ILs+6KErhg06p0U83nqDTCizbnDRuP7aeleQrg8Whi6vZRG1ls4kzuJpFhaFLBigB pCPw== X-Gm-Message-State: APjAAAWGcGU+CDZKdwBnW1wzxFJ2e8LwRhObW+XxRDvu7fx+7TMS7UWk 47+IbMniDGQ0szvk8eVb7PNWcnpXZqI= X-Google-Smtp-Source: APXvYqzWaTnlpPi1sGhj49r0BCSr6EDWlbwIRn50sa+BrEd8ZxLNZ6u8GuB1eTDow9DwyhrrLzUPQQ== X-Received: by 2002:a1c:1bc5:: with SMTP id b188mr8104321wmb.88.1570715829333; Thu, 10 Oct 2019 06:57:09 -0700 (PDT) Received: from localhost ([194.105.145.90]) by smtp.gmail.com with ESMTPSA id h125sm9024318wmf.31.2019.10.10.06.57.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Oct 2019 06:57:08 -0700 (PDT) From: Igor Opaniuk To: linux-usb@vger.kernel.org Cc: Marcel Ziswiler , Philippe Schenker , Stefan Agner , Max Krummenacher , Oleksandr Suvorov , Li Jun , Igor Opaniuk , Greg Kroah-Hartman , Peter Chen , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] usb: chipidea: set mode for usb phy driver Date: Thu, 10 Oct 2019 16:56:55 +0300 Message-Id: <20191010135656.3264-2-igor.opaniuk@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010135656.3264-1-igor.opaniuk@gmail.com> References: <20191010135656.3264-1-igor.opaniuk@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Li Jun After enters one specific role, notify usb phy driver. Signed-off-by: Li Jun Signed-off-by: Igor Opaniuk Acked-by: Peter Chen --- v2: - restored original commit author - fixed build for multi_v7 drivers/usb/chipidea/ci.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index 6911aef500e9..cf9cc9402826 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -275,9 +275,21 @@ static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role) return -ENXIO; ret = ci->roles[role]->start(ci); - if (!ret) - ci->role = role; - return ret; + if (ret) + return ret; + + ci->role = role; + + if (ci->usb_phy) { + if (role == CI_ROLE_HOST) + usb_phy_set_mode(ci->usb_phy, + USB_CURRENT_MODE_HOST); + else + usb_phy_set_mode(ci->usb_phy, + USB_CURRENT_MODE_DEVICE); + } + + return 0; } static inline void ci_role_stop(struct ci_hdrc *ci) @@ -290,6 +302,9 @@ static inline void ci_role_stop(struct ci_hdrc *ci) ci->role = CI_ROLE_END; ci->roles[role]->stop(ci); + + if (ci->usb_phy) + usb_phy_set_mode(ci->usb_phy, USB_CURRENT_MODE_NONE); } static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci) From patchwork Thu Oct 10 13:56:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 11183645 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7709F17D4 for ; Thu, 10 Oct 2019 13:57:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58796208C3 for ; Thu, 10 Oct 2019 13:57:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hkLd84++" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726217AbfJJN5O (ORCPT ); Thu, 10 Oct 2019 09:57:14 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34693 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725959AbfJJN5N (ORCPT ); Thu, 10 Oct 2019 09:57:13 -0400 Received: by mail-wr1-f66.google.com with SMTP id j11so8054712wrp.1; Thu, 10 Oct 2019 06:57:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kKpm7XM1AgpSN1jrhyWVldr2l3miF1XGBH1EW5loxxI=; b=hkLd84++mfI8DFZArVwjpGXEap9gVCEvxtrIk2GCAec5fJlbZnrJ+fF/5b5qtRAxBN 7zu8N3Hq7k8saPoZ4+41pnq1iymTz58A9wVpJnOr3Y/VCaIBlvYrkiP6iod1wtgWphGj 8qisHK3qM0yiViWyXPI/tsulamhgLzVovb7CjWPxjkeRw1ySUyPAHqUSMVI3uszMbRGS OjfZEfFPffXnbZUYgYGiyCgBj+1igbTyVHWVLqmj4JNND6Dv525BL0Y1CgB6+2Nm/wqX 0lND4FVUjZ1UfiTpwa/MrT+MUE5UsVx5qIAwSO4UzaG9jSlgAHCAgDF4VkkUn1frOTkM GHtw== 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=kKpm7XM1AgpSN1jrhyWVldr2l3miF1XGBH1EW5loxxI=; b=RyM8G3/z93S+sFkizwS0DnOGo+3xj3WJmWMShYWNLtLFT2U/mnxnYOe/JJt/TrrGrW ycV69jQrzmBbbFrZmcM6qeVmowNUw0Ckz3Vktg3yGJUueg9k8AZkB6hIjy4bwevObBI4 3ZHfVP3ld7DN1XTZYCprqWcpN80hZbiMPvJvf3eOCDkgXfDMRG+lsHm8/FuXvX/S+QtR 9YzoElfg6MZy+JsaaVt+S+NZoIZwmB0EjGsq0zGxLhCSi8vKcfPRaSWk/tA/CABHK3zn WA/tTIGGDKTLRETqhmjvRFL+AFA2uePhlfeQPGkDMcac5itZt6nTKLU8+GL+qIs+/CY7 ykoA== X-Gm-Message-State: APjAAAXJyMR1YZnD4wopAMRzNOhAg86ejKeZAux3N5sfkvJyvY/4V5p0 quQZPBeUTJzzbpxQgWmoEGz8n6hQngQ= X-Google-Smtp-Source: APXvYqxnSQAklQr786Hn4Cib+9+4j5ERR7EwmEMJDisBGjMLS8ap04iHd53VBJcDXdLnQjFxNU2sTw== X-Received: by 2002:a5d:540e:: with SMTP id g14mr8988389wrv.177.1570715830595; Thu, 10 Oct 2019 06:57:10 -0700 (PDT) Received: from localhost ([194.105.145.90]) by smtp.gmail.com with ESMTPSA id u4sm9088089wmg.41.2019.10.10.06.57.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Oct 2019 06:57:10 -0700 (PDT) From: Igor Opaniuk To: linux-usb@vger.kernel.org Cc: Marcel Ziswiler , Philippe Schenker , Stefan Agner , Max Krummenacher , Oleksandr Suvorov , Li Jun , Igor Opaniuk , Fabio Estevam , Felipe Balbi , Greg Kroah-Hartman , NXP Linux Team , Pengutronix Kernel Team , Sascha Hauer , Shawn Guo , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] usb: phy: mxs: optimize disconnect line condition Date: Thu, 10 Oct 2019 16:56:56 +0300 Message-Id: <20191010135656.3264-3-igor.opaniuk@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010135656.3264-1-igor.opaniuk@gmail.com> References: <20191010135656.3264-1-igor.opaniuk@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Li Jun We only have below cases to disconnect line when suspend: 1. Device mode without connection to any host/charger(no vbus). 2. Device mode connect to a charger, usb suspend when system is entering suspend. This patch can fix cases, when usb phy wrongly does disconnect line in case usb host enters suspend but vbus is off. Fixes: 7b09e67639("usb: phy: mxs: refine mxs_phy_disconnect_line") Signed-off-by: Li Jun Signed-off-by: Igor Opaniuk --- v2: - restored original commit author - fixed build for multi_v7 drivers/usb/phy/phy-mxs-usb.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c index 70b8c8248caf..f58ea923c7eb 100644 --- a/drivers/usb/phy/phy-mxs-usb.c +++ b/drivers/usb/phy/phy-mxs-usb.c @@ -204,6 +204,7 @@ struct mxs_phy { int port_id; u32 tx_reg_set; u32 tx_reg_mask; + enum usb_current_mode mode; }; static inline bool is_imx6q_phy(struct mxs_phy *mxs_phy) @@ -386,17 +387,6 @@ static void __mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool disconnect) usleep_range(500, 1000); } -static bool mxs_phy_is_otg_host(struct mxs_phy *mxs_phy) -{ - void __iomem *base = mxs_phy->phy.io_priv; - u32 phyctrl = readl(base + HW_USBPHY_CTRL); - - if (IS_ENABLED(CONFIG_USB_OTG) && - !(phyctrl & BM_USBPHY_CTRL_OTG_ID_VALUE)) - return true; - - return false; -} static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on) { @@ -412,13 +402,26 @@ static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on) vbus_is_on = mxs_phy_get_vbus_status(mxs_phy); - if (on && !vbus_is_on && !mxs_phy_is_otg_host(mxs_phy)) + if (on && ((!vbus_is_on && mxs_phy->mode != USB_CURRENT_MODE_HOST))) __mxs_phy_disconnect_line(mxs_phy, true); else __mxs_phy_disconnect_line(mxs_phy, false); } +/* + * Set the usb current role for phy. + */ +static int mxs_phy_set_mode(struct usb_phy *phy, + enum usb_current_mode mode) +{ + struct mxs_phy *mxs_phy = to_mxs_phy(phy); + + mxs_phy->mode = mode; + + return 0; +} + static int mxs_phy_init(struct usb_phy *phy) { int ret; @@ -796,6 +799,7 @@ static int mxs_phy_probe(struct platform_device *pdev) mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect; mxs_phy->phy.type = USB_PHY_TYPE_USB2; mxs_phy->phy.set_wakeup = mxs_phy_set_wakeup; + mxs_phy->phy.set_mode = mxs_phy_set_mode; mxs_phy->phy.charger_detect = mxs_phy_charger_detect; mxs_phy->clk = clk;