Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4252015ybp; Mon, 7 Oct 2019 05:48:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxjo1+ST63JF2CNcu2Gl3IjT+QQinD/ALaoGJSFfptTvGyv91b7H7tBe52xUK0YbkQ/WbZ X-Received: by 2002:a50:d090:: with SMTP id v16mr28836541edd.176.1570452509377; Mon, 07 Oct 2019 05:48:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570452509; cv=none; d=google.com; s=arc-20160816; b=vMyzQGP1ILKWktUrVPTL7ypWjok45UmDsdswyZpITlLttahtYj5tfbqcPMNl8oYrUv 3NIiZFYnVTJMQ3pUYzfXHFlM7VLGJ8DEnDugN8YkyLhwmc9guxe/xOxPbKEmJfsVBC4r 09HH0+LeHypwdONgAmGrz60mJpl6KWUHEtCgLLFaCs/dESaNdPe8+CQYn57ZOkUpHKBY UAMthFONXwldDqGz5RbcRUHEfQtulQ69zDSsMYrMYLnDmsR503xoJ0arVwbCDgSuaGbw butxd09vXfO80HSl6pC8WMHuyVbFNcpIfTMZxHOjg5DtkSkECwgy+h+07v584SrI5jHo 1FWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=dE5Pbudcp01GEPyoenTGG4iUJBJux2YKczE2k0btNjU=; b=l6nMtwU4dP7Wr5JQ+ObNsO5dP4fFvor2VkgB+ra1wB2v4YiMxJ/sjNrd7b/DEcFRnL g6hnE3f8iqw0Gp2o8rppLXnICkhbGSl+3KcVYTXrKnp+1alW0esIFa9yurj11WdhD24B TYB0HwPjPBhtkYnBO0GUAZPg6++5GxkyUrAZ7UcK4LwUW3e48MUds6xgbkI+NJNt+kMs A2c8to0mE67n8mLJPX7ESMduiWf4yRx1d5VcVkNg3HGm/N7gHHH69OQsne/PBdn28f0S viEANvjPEypAanHE3askxUCAP+yhYYBBjVmy7s/9GCvBZQpwBgJldCG6BSf/UkECm/sM Mkxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q2EIKM8D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si7848625edx.223.2019.10.07.05.48.06; Mon, 07 Oct 2019 05:48:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q2EIKM8D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728055AbfJGMrn (ORCPT + 99 others); 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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; -- 2.17.1