From patchwork Mon Oct 7 12:46:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 11177403 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 696441747 for ; Mon, 7 Oct 2019 12:47:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4870520867 for ; Mon, 7 Oct 2019 12:47:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dy8coq+B" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727635AbfJGMrf (ORCPT ); Mon, 7 Oct 2019 08:47:35 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:37452 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727490AbfJGMrf (ORCPT ); Mon, 7 Oct 2019 08:47:35 -0400 Received: by mail-wm1-f66.google.com with SMTP id f22so12199786wmc.2; Mon, 07 Oct 2019 05:47:33 -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=AT90Kg/zRUtjsdvlXig6kf61Re1a9yGlOxg7dRhOahY=; b=dy8coq+B4djgG7XoW0kM31x7L8/pkrlMXAm4QcJzT3GxJGdjcRPIG8+AJd8nECgQ+m pSv6qL03Ct01Prjfha2nrDm+//O/Xxuu2wWq4ThMnWXx1Fcsb/tsCr+qHJJ73ciHlxeL miOXgGdtx3D/f0d/2vDBi7g7Z5EwX8EJF13O1BbGy0q5pBYKp3qbnQVc/HQ8tGBhJC79 y2loQusNna46w9WS6FdAPFLne8ruSPAa7iegJZibz1rftSxs3Dgo0amkY1/6q0krKuCx 3KO/NMJkdjfk02iNAo82YI38MYqQIPbEBwq9CTrMTCEL3dT+ykzJWXGBfR1lfDu0tFXP chIQ== 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=AT90Kg/zRUtjsdvlXig6kf61Re1a9yGlOxg7dRhOahY=; b=EXmJvk/WT0w+b9ZvWGzb4agDLRSMFCi/dUKQxmlbQH/N4KTF8BEH3v702qlpkTeWKa hSh0QmvR6aO7hCFT2Ph1z03AsgSyZ09bZwg3VYWcBd3HyyXqGP74UKjv1DNKCcOtuSOW /BdrRAVDMNONNq6nI947AkbjSiQz9uyaWqfxTIQLj8lefs74BaaiWovlQ710ULbMVI9X I24G/EJ6m36QIzzzeXkL8Fv8XamMG+I2CA3TbIx3yi7KfxbvWuL/XWPKpiPx6IcEYfPl OPsKxKUb++czYAOrIWl2q1Fwe1AXrscE+mcYjwLTR4CHR36FgQIVY4sH4/+6GXYf38tI dscw== X-Gm-Message-State: APjAAAW5OCfFceF2nLVxNSTkQemhr+9oa5StTAE4SgCq92dwbaXFqaEa z0OKjSKFKIySiVF+SxE90db8Qau2S+U= X-Google-Smtp-Source: APXvYqx70mWEwFEmfHG43cYeL+pn2QE7GLbM4OthUvaC2hktxXvef6MBklkVuZdXGxUiqauM7QgMTQ== X-Received: by 2002:a7b:cbc5:: with SMTP id n5mr21592790wmi.31.1570452452161; Mon, 07 Oct 2019 05:47:32 -0700 (PDT) Received: from localhost ([194.105.145.90]) by smtp.gmail.com with ESMTPSA id w5sm15870495wrs.34.2019.10.07.05.47.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Oct 2019 05:47:31 -0700 (PDT) From: Igor Opaniuk To: linux-usb@vger.kernel.org Cc: Marcel Ziswiler , Philippe Schenker , Stefan Agner , Max Krummenacher , Oleksandr Suvorov , Igor Opaniuk , Li Jun , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 1/3] usb: phy: add usb mode for usb_phy Date: Mon, 7 Oct 2019 15:46:05 +0300 Message-Id: <20191007124607.20618-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: Igor Opaniuk 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 --- 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..774941be77d7 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_MODE_NONE, + USB_MODE_HOST, + USB_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 Mon Oct 7 12:46:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 11177393 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 4FB5F112B for ; Mon, 7 Oct 2019 12:47:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2E85D21BE5 for ; Mon, 7 Oct 2019 12:47:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BArA0duk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727958AbfJGMrj (ORCPT ); Mon, 7 Oct 2019 08:47:39 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33688 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727904AbfJGMrj (ORCPT ); Mon, 7 Oct 2019 08:47:39 -0400 Received: by mail-wr1-f66.google.com with SMTP id b9so15174324wrs.0; Mon, 07 Oct 2019 05:47:37 -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=3+0xNKANMoqD2LM7Jb0KxrBIYqLeJsaQlJrD1LYqzho=; b=BArA0dukyOOQG0I91sTg+fEwZnhirpCntvT3S6t7//3e8XVIJPzesiuad/8zoZ9Myb BEvJFtw6zOUSdgz5WMyYito5s9Az/NqjCIRTp+dicUAyEKaJk2uxnD+sAcaN8L65nd0P iF6GD/vKVquAZcBNyStWpWjkhxEWykw0/WJCW2hoO+uUEWVvPbmhHvtby0pA9SJmNtjj 81xsfkn2lnxP73Vjd2ZqVXmuHugrrpnHsEwjmgRdFLDXawGhcin1bN/hpEdfOjCBkJyt DOkuekKS8VGEKl4z/e+V51A/r99OBNtBOJctwPp2lFx4jU31ffrFUc59tD5UCR9MWQbo KZmw== 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=3+0xNKANMoqD2LM7Jb0KxrBIYqLeJsaQlJrD1LYqzho=; b=RfkK66wgNfRgRLtLchOu5i1LVTMvo3DsTGVm/i4E6ZhCLkICgK1Uo4d6JXVDGRQjxl 8nZE0zRcr3w3WPKVKKs4xtYGTElzbeeD8raP7aYTZHRuTbe9sStKRRQ43SPylNwCafvk VuSfRlGdyRoBE1GGTSFtQpLh0uQjn7Ho/sThYQE84O9ftBHUiSG2s5AO6V27kgkWLDF/ czDjHV7iCGs3TRAmZGKt99f+kjYnkiHxESxghMIPo57tKh7y2Xo3VRRVXjhKqLtpAU2a R5LIfp6hyxxWbTZteqJLvWD16VFtJXfBpv1khBiR21tGJDwpwDlHwOyVAH5CRT4mRGwP kFsQ== X-Gm-Message-State: APjAAAWJdAzU1xOXRsy/MbrO5rxX1hzrlasX6IO1j3hyMp7RitWLHuZw SOnGgUDoZXJtiOw4yeTmUtoyH2Zf2Ec= X-Google-Smtp-Source: APXvYqwN3wNI0EhseuwoKQOqFG95vCPzBQL45WawolPwUaIlN31vWOdiUKmK1TZFmZ9zOpePr8lPFg== X-Received: by 2002:adf:f7c3:: with SMTP id a3mr9788540wrq.275.1570452456841; Mon, 07 Oct 2019 05:47:36 -0700 (PDT) Received: from localhost ([194.105.145.90]) by smtp.gmail.com with ESMTPSA id b15sm18454390wmb.28.2019.10.07.05.47.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Oct 2019 05:47:36 -0700 (PDT) From: Igor Opaniuk To: linux-usb@vger.kernel.org Cc: Marcel Ziswiler , Philippe Schenker , Stefan Agner , Max Krummenacher , Oleksandr Suvorov , Igor Opaniuk , Li Jun , Greg Kroah-Hartman , Peter Chen , linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 2/3] usb: chipidea: set mode for usb phy driver Date: Mon, 7 Oct 2019 15:46:06 +0300 Message-Id: <20191007124607.20618-2-igor.opaniuk@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191007124607.20618-1-igor.opaniuk@gmail.com> References: <20191007124607.20618-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: Igor Opaniuk After enters one specific role, notify usb phy driver. Signed-off-by: Li Jun Signed-off-by: Igor Opaniuk --- 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..a11d23910b12 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_MODE_HOST); + else + usb_phy_set_mode(ci->usb_phy, + USB_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_MODE_NONE); } static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci) From patchwork Mon Oct 7 12:46:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 11177395 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 8A63C112B for ; Mon, 7 Oct 2019 12:47:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6AA312173B for ; Mon, 7 Oct 2019 12:47:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q2EIKM8D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728047AbfJGMrn (ORCPT ); Mon, 7 Oct 2019 08:47:43 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42346 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728025AbfJGMrl (ORCPT ); Mon, 7 Oct 2019 08:47:41 -0400 Received: by mail-wr1-f68.google.com with SMTP id n14so15094963wrw.9; Mon, 07 Oct 2019 05:47:40 -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=dE5Pbudcp01GEPyoenTGG4iUJBJux2YKczE2k0btNjU=; b=Q2EIKM8DVJ7tDyl/BTGuEB31qH1AKFvkrYNn7nqDv77Leoyx0+82lXBEeKr++L5H9O BrRGB7DvSg9xr7Zkruf+e6ALndQBwT9Huktp75hqfxfqvUsxsRxpUZUOWTaiLgZhil5u TYpDIGXMBR5qkj9qfk8yxCIpmJ3LckZKklSAq2vicS+toGUwlhg09SUc1tNq9WMXVQlg Pxj8cwD795QdSHN3lJlW4CUNOFB8FyUVc/TY0EWwFRfti5oEyvmyJmTDbLlYJYqTEFO/ v5nBdBVFd7I6MhWVPD7W6V0RBrSZPZ3gJ9CeZrh3sHFUcZmUSlFT+rOG7JpJHRQbeZzh NKZA== 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=dE5Pbudcp01GEPyoenTGG4iUJBJux2YKczE2k0btNjU=; b=WACUAwejTEfbv8AYqYHZWUeWae+jkXzEvxJzhmteaypkgEWY1auCjuzZiAYNRevg4p eWnGrd54tFEVikk/kZNhmP9kpSsBmlIC2YIa5wcIhfsiAC8SNc3wOdDOgv5vREyyxk9h G3DV7ZR0HzxQ1rHgHI5B3elHSgN/kjoiPx86mLJ+tNZwbbZ8Ik6NzT7A5tGnHKrLcNIH MkzRQqWKlbapKbgMmpXGWchsU2JBl1zdllyo1dzhPicFkiuPQ50PxS6gRPEjHPJM68Zp aiP85MQEoe78RcI7fDOgArPyko/VfAvoJpyOCzS/fBo3amdgOZRVL2xnVTFMMTyOmInQ dLoA== X-Gm-Message-State: APjAAAVHBJdThL5X0GkvX871zkShmKlHnFh3BYqNLjDTpIfqeOdW3e3x fzy/4gKm0ClK/TanW/spwImXU6wHxXE= X-Google-Smtp-Source: APXvYqxfcm+mguSSud/mija7CYkDcradVYcTrMnb8M+RUUOM79viuKI65prWYSiQClaVRyLyQozQTw== X-Received: by 2002:adf:fe8b:: with SMTP id l11mr17986939wrr.23.1570452459382; Mon, 07 Oct 2019 05:47:39 -0700 (PDT) Received: from localhost ([194.105.145.90]) by smtp.gmail.com with ESMTPSA id c6sm15985051wrm.71.2019.10.07.05.47.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Oct 2019 05:47:38 -0700 (PDT) From: Igor Opaniuk To: linux-usb@vger.kernel.org Cc: Marcel Ziswiler , Philippe Schenker , Stefan Agner , Max Krummenacher , Oleksandr Suvorov , Igor Opaniuk , Li Jun , 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: [RFC PATCH v1 3/3] usb: phy: mxs: optimize disconnect line condition Date: Mon, 7 Oct 2019 15:46:07 +0300 Message-Id: <20191007124607.20618-3-igor.opaniuk@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191007124607.20618-1-igor.opaniuk@gmail.com> References: <20191007124607.20618-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: Igor Opaniuk 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. Signed-off-by: Li Jun Signed-off-by: Igor Opaniuk --- 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..d996666e09e6 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_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;