From patchwork Tue Jun 27 11:03:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 697189 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4662AEB64DC for ; Tue, 27 Jun 2023 11:00:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230432AbjF0LA3 (ORCPT ); Tue, 27 Jun 2023 07:00:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbjF0LA1 (ORCPT ); Tue, 27 Jun 2023 07:00:27 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2077.outbound.protection.outlook.com [40.107.22.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 720941BE7 for ; Tue, 27 Jun 2023 04:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hd07ga6IUftVho3Ia/5zoo4S4bvlH++8p+clo3pHAndcVUL3xmLVXwqjcQg00TkwDGcnTWHv1BAuLoP5ntHkNB8EucDFTSkKJgt6/oyflssH3oyNRFT6tDzsWCngVHP/33mIWRomCkKlZVJnXhez/AztC0eGj1vLIJRgG8sFSPYtFMRoHL2Xpfq9S34GGIHyFdhOn1IDNOwxZM8dWYyr2lR2ETJQS3T+g7qe7WqLtHLE9CCCTDtketev4ClRpRwkbs9zaTtEGgV30PHY8+gGSvWd6lIZKgtFw1CxkKYwTB3gWGDvU4JjAZ8vZad1GDWrevj6k79/i+Zl8XC9b7sNmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jhXuCDUG8dJxI/URKLPtltDnGXmnWRs3uNRkTKqFwZM=; b=GrL25z6vmgrmRGILT7Tk5iHRDssD3d6ZWTkdYk+fDiW8bASN8Vmgm1vkL5UqZSRFaGmzrzDqy037dsG7KJZPKkGhRDJ/x710Ez91y4KUmcLIzQ0pqaKBmyZSCnNp0kOHM/henWdqfdF729CkrFU0UZrJW1G2J+lkX9v35bQmyBYuSbrvqJJbeS8rO0q7Un14AFQl8U0H1I2bUofLPEplDySsZo12J0vtiS0JD17vcOdhoDWTBJJEBGgOduyoPM4Oyd4yC7IgSeS7AbPqG+og0ONfstvNPXssQH3F1lTtw6E9XJa7QzyPScx25OWgkYm3Scjq4oXI6ke8z1sA6CIaOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jhXuCDUG8dJxI/URKLPtltDnGXmnWRs3uNRkTKqFwZM=; b=PqbSDQdhmV/pxUgXUirx08KkXiEIos3ZSyVNSYAgpN8AC3YqKXuDZrX/p7Qds2Gucjl1QstQA5A7Fc8oj3T5mLRON+/sz61KLLhMyzpt2YhWzagrWHbr5KkrRCBJw+0sNMqEVq5z0AjNHkzZsTnXfbmO0hK+onZ67fg8DebKrQA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) by AM9PR04MB8114.eurprd04.prod.outlook.com (2603:10a6:20b:3b7::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Tue, 27 Jun 2023 11:00:24 +0000 Received: from DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4]) by DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4%7]) with mapi id 15.20.6521.024; Tue, 27 Jun 2023 11:00:23 +0000 From: Xu Yang To: peter.chen@kernel.org, gregkh@linuxfoundation.org, shawnguo@kernel.org, s.hauer@pengutronix.de Cc: kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, balbi@ti.com, linux-usb@vger.kernel.org, jun.li@nxp.com, xu.yang_2@nxp.com Subject: [PATCH 1/3] usb: chipidea: add USB PHY event Date: Tue, 27 Jun 2023 19:03:51 +0800 Message-Id: <20230627110353.1879477-1-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI1PR02CA0042.apcprd02.prod.outlook.com (2603:1096:4:1f6::17) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|AM9PR04MB8114:EE_ X-MS-Office365-Filtering-Correlation-Id: 766e6fcf-6fb9-4c6f-3ee7-08db76fdb4cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CG5FDUycdmbFZbdCVItgAkZ+iulDNvZNpIPWn0qPsmbLr+ld9Q8zTokAyFtX/XKzSFvURzbFbQ8PQCQzgfpuhd8BiaPtrh172ySsSO9VWqTZ34XoickkvrWA43KvuGPqFSPaX3y/5l5z/eM/Wkgr9tHOC3dQavgaWuRMMtx/Bor2toR/KRUNrs+ZLg2Fjtx2V1IwqrdHt/ciQCE3F29gImAp3f/haj7sEiD/pp+t8qzm6yZQeLyIGG2MluA1vHN9MwrZC6g8b9m4gJbvuWiYw3W2mviHGjJG1r2YeK2gU7b7LnFP8bXppmTBnOWtJsY9CiUP8RDWt8cQ7GfRuFzsPVoTT4PTrH04C/pRL7pFZ3cmiO4yTCmZd/qmE5LdqPv4ZKD6eIxOkn5fF4PE8Niofbu3J9gM2gD3vkt+HgW8YKl+T+ifszja8TFBr9R8xHXtakTgnaAU+3twzFLAH9heLLo9zn2YqIUkTEuzPUgGkLjJQ5CylAgrf1yTyrjlnYhMe/7/qBBYQN6AmdZSZMBL6n4RykB9awHiEIlOp1CNZQJQ/aKkLVbPKmy3KErfu1+dq13Xf5eCh46g7O6ZqYAKXyCGFyyX2YeD6SruXrTDaw/FxjOBKT+AbTh/7WgadX+w X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR04MB4505.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(346002)(396003)(376002)(136003)(39860400002)(366004)(451199021)(6506007)(36756003)(6486002)(478600001)(52116002)(2616005)(6666004)(83380400001)(2906002)(26005)(6512007)(186003)(1076003)(5660300002)(316002)(86362001)(66476007)(38100700002)(66946007)(38350700002)(41300700001)(8936002)(4326008)(8676002)(66556008)(66899021); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TSGZk81sleGF1AIX0XbUsiYbnqC6o/Jo9PmD/HzOgxPqW8Q2nrQcJYgny3oGOZoHqcao8iBM8D2clV54SCzjkk8k3EdZiW/UwHnZgQ7/os36LhgKYvQAwMiUnnoUaeDjxdQKzid8K/afzEjNjE741HRg5M1HDNZYfVKyZSdwP9xua4SB7buya1lVN7HU/3VyeJ+B6sY3Sx5J2MceNsaDD0mX5MY3BAe12qsdlK7l9vMP+AbSU0gXKSco9RvtrAhoBN6tmFd3O4mXEfXsECaasEiZG3WzmaVLTr5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Hiw9mbygD+EnROkvUffpTselOP+gIa6I8TvpSXfPp1yS+A0k0rwvqNwI66Envbe03zAl119DLfEPP40+jJ5tQwOIpemtP8u0qRgkmWrTfOFu1O7BhS80yeEj42q4yhWy0Nhn0CmL8egUuIoIcw/vSRjgBRk6JwsO/NU/Gbs9U0mWd+BG6R/Tf9Bs4oyrKX/pREZ8kYNIlGDxgXfxCzBPtfmQnL+8iWBCASHWrgvviTE/AQic8bg X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 766e6fcf-6fb9-4c6f-3ee7-08db76fdb4cd X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2023 11:00:23.8060 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BTrMkkl0pWy6aQE8SZ7Qkx2RmYboJpVI+C8JU/pcV8xE4nUWhxHnK/m86KEKvUiGTaiwUAjuAXvy6FM2qzRVhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8114 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add USB PHY event for below situation: - usb role changed - vbus connect - vbus disconnect - gadget driver is enumerated USB PHY driver can get the last event after above situation occurs and deal with different situations. Signed-off-by: Xu Yang Acked-by: Peter Chen --- drivers/usb/chipidea/ci.h | 18 ++++++++++++++++-- drivers/usb/chipidea/udc.c | 10 ++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index f210b7489fd5..d262b9df7b3d 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -281,8 +281,19 @@ 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; + if (ret) + return ret; + + ci->role = role; + + if (ci->usb_phy) { + if (role == CI_ROLE_HOST) + usb_phy_set_event(ci->usb_phy, USB_EVENT_ID); + else + /* in device mode but vbus is invalid*/ + usb_phy_set_event(ci->usb_phy, USB_EVENT_NONE); + } + return ret; } @@ -296,6 +307,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_event(ci->usb_phy, USB_EVENT_NONE); } static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci) diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 54c09245ad05..d58355427eeb 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -1718,6 +1718,13 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active) ret = ci->platdata->notify_event(ci, CI_HDRC_CONTROLLER_VBUS_EVENT); + if (ci->usb_phy) { + if (is_active) + usb_phy_set_event(ci->usb_phy, USB_EVENT_VBUS); + else + usb_phy_set_event(ci->usb_phy, USB_EVENT_NONE); + } + if (ci->driver) ci_hdrc_gadget_connect(_gadget, is_active); @@ -2034,6 +2041,9 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci) if (USBi_PCI & intr) { ci->gadget.speed = hw_port_is_high_speed(ci) ? USB_SPEED_HIGH : USB_SPEED_FULL; + if (ci->usb_phy) + usb_phy_set_event(ci->usb_phy, + USB_EVENT_ENUMERATED); if (ci->suspended) { if (ci->driver->resume) { spin_unlock(&ci->lock); From patchwork Tue Jun 27 11:03:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 697888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67625EB64D9 for ; Tue, 27 Jun 2023 11:00:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231296AbjF0LAc (ORCPT ); Tue, 27 Jun 2023 07:00:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbjF0LAb (ORCPT ); Tue, 27 Jun 2023 07:00:31 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2082.outbound.protection.outlook.com [40.107.22.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA65E1BE7 for ; Tue, 27 Jun 2023 04:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cFIaf7HfNvX4M2/MWUn5yrXw9k4fVjXk4x5cvh0BHzcjiPbHAQ4vp3sxMB9VjJwt4wbhNg3WqD1hZrMKTosGzovvama1kPHapo66FhvYjS1avZ6PA6bdbZ7VsCD/ms1wl8GuucatWIylkhcGVG/+NU0lBZcd3E2II4o7WbhNwxSDwwygXohMjZNzqddhdJEce90WklClrPCzFKcdXd0HQEmtDPSNKFaNSNv9YEXd1DPoYhV1yzEuIV0+Oo8cMqzUTaB99fOi5kVkYpVLP6nQry8HLd5nJ7wzNlWw8si/Yx9zK/xiMqTxWXfRj09iTMBfwDlzBFIke6UFo+xdb4Lo1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bsYFdjrcHtYHzQ8neQAN8l5BSoE3sWA/soa+z3A5mfM=; b=ECDPCw9oGZ/P6h+KQDYXo6GaQd5qonADcP46z3PgEj18b+b9q6C2+1R/s24Y4rLomSE9YsFqQrJOAOciy9UAhGSXG9el0rcK8WwWQZHRIVnDcKyNGQRhsDOkaPZj+JgPwRHcPtjANBk4qhqV/yF9dnHo6NbcDyzR0YUYC9il47AVg7iHc74d8dsN1b69YHXKS1Vs6auDZ7L+kQDZZ57d+HrtUI56mLd7VPj+7om+9ctwt4FCHrpi6qJwK8wPhmCi1pkspn5SjkggZGZSxHsokpc8ZQ6P/OW0Jra2scpEOxFHGYQxHMN189NjPWN1Tmkp0MsOBdwIfWEszRwMYQiQQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bsYFdjrcHtYHzQ8neQAN8l5BSoE3sWA/soa+z3A5mfM=; b=pcNaE/dYCj6nHybqZdCl7hdyoICRsCHvUjZUJnEswVO9k/1MbyNKdwNxdTadvza67N5ORzsmBHE1OrANijCIoMqntJt+MbMxUY0s0Vv8PMNcsRSH0q0jdhQaCDWiQ8LgVnqvnZyvo5sHTbHNqtmmWPX9AkNTpcA6rOAhN79JAI8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) by AM9PR04MB8114.eurprd04.prod.outlook.com (2603:10a6:20b:3b7::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Tue, 27 Jun 2023 11:00:27 +0000 Received: from DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4]) by DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4%7]) with mapi id 15.20.6521.024; Tue, 27 Jun 2023 11:00:27 +0000 From: Xu Yang To: peter.chen@kernel.org, gregkh@linuxfoundation.org, shawnguo@kernel.org, s.hauer@pengutronix.de Cc: kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, balbi@ti.com, linux-usb@vger.kernel.org, jun.li@nxp.com, xu.yang_2@nxp.com Subject: [PATCH 2/3] usb: phy: mxs: fix getting wrong state with mxs_phy_is_otg_host() Date: Tue, 27 Jun 2023 19:03:52 +0800 Message-Id: <20230627110353.1879477-2-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230627110353.1879477-1-xu.yang_2@nxp.com> References: <20230627110353.1879477-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SI1PR02CA0042.apcprd02.prod.outlook.com (2603:1096:4:1f6::17) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|AM9PR04MB8114:EE_ X-MS-Office365-Filtering-Correlation-Id: 2faf6665-def9-4a9b-a42c-08db76fdb704 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FJWemdONSQFkdX8hh1bhp9XHi06cOiYanzVgzjdXEjVuLacr4BUf3uYCe5mH5q5Z7ZwkxrnTa7MKOgE21BoeSiPCP1eCHzh38BwiAqW46N2vYHTotbZVyiYcq1giwx1wJOyU6XfdnGhssE7fJqOzpiVN1385BVyLsuWYblqc41kfNgOUn8yMV8F2V25o3MMs6Hy6fjov9xbHlVkOJEvN86Snt1gidhG0Al9f+OIyq4E+joKdtOJ+43/S8+Hq2gf0NMl3tJyMScj/guQHmS7iHadzSO5cbD7H0kgt7kVlC4e66KiQfcVIisOs4og5ULy3+BpfLk5UvttPiz5MTP6dTjNilEig6bRN4OOAUJTutFHCqF2eoPppomgxbJ7h64DfzWc8wGPlGWQGJvsknm7aZBQLV0zzAg+97X1YcD9znGaHDpQ5FM0g3kNWwwBE7ozuWguWmF0v2RPCqRPo98UybZMLVxsoRpDxfrlR5n2Whyxyvn/wTZtkpIYPWjcd7v864vNwzzY5LkL+vmXZ9nqLBDJjWmIYHmoMRGKJASLr2DiNLGeJSJlV1oKfDZV+Lu1v7RUL8vROS4P3x9ASEU11RrHJsN5QwUCV0nfv4vJ1Th7y0lsbVfHguFY5q6ZQ1hOZ X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR04MB4505.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(346002)(396003)(376002)(136003)(39860400002)(366004)(451199021)(6506007)(36756003)(6486002)(478600001)(52116002)(2616005)(6666004)(83380400001)(2906002)(26005)(6512007)(186003)(1076003)(5660300002)(316002)(86362001)(66476007)(38100700002)(66946007)(38350700002)(41300700001)(8936002)(4326008)(8676002)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0TzAiqB5vSuQ7GK1BYsWjSFX4OIHUh1S+fLIZapt1enrgI2A84mV7OFgt9rSjruKuR2sdZfAi8qu/aoJ+iaT61I8EiqDo80txRZ9rvKSHkeB7ahxLgjkqR+yJt0729x9zj8EqQYvPovvEZzi+O3Ce/Hl+cwcdxaxwT0/f8EnKMu2Lkyf1/97TFRu0z5nvmO7rTGHH86cvddnriSLrsAlb8GBReM12S4Y1/UbMDrXPq80Ti3EU7Lh6ETIrN6R+fLiXRWx5onFEHfoKB/d98fMRUEeEIqQzwRakAY/xmOLYUB91EymTel8H3LTEE2q9N9VqJBRh7eMDkm1sSayxgYgqHp64aLZWCjWQ6kkcmTiCDc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9BvvgVuAExNsIfHfUpWsQHPJr1Gi8RdQMwrmp2wxtrhSTbKm7Xgn/5DIW8lih/dw63INTkg+ZP+fqREZKr+fxExfVSA/4sunpT5lDacw1Zbn1B7RUqFIQwwq/cGGnn7+sMSKA4B7G1gSv7+ZMgV/CJ4N6xmR X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2faf6665-def9-4a9b-a42c-08db76fdb704 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2023 11:00:27.4460 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: O1RjcM5st2/bioTsbAr814jjszY8prxmYepTU51gW0ZWLlsi4IwG3PnQui2ArGISyAFxBoINWo/OhH6FCbpx7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8114 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The function mxs_phy_is_otg_host() will return true if OTG_ID_VALUE is 0 at USBPHY_CTRL register. However, OTG_ID_VALUE will not reflect the real state if the ID pin is float, such as Host-only or Type-C cases. The value of OTG_ID_VALUE is always 1 which means device mode. This patch will fix the issue by judging the current mode based on last_event. The controller will update last_event in time. Fixes: 7b09e67639d6 ("usb: phy: mxs: refine mxs_phy_disconnect_line") Signed-off-by: Xu Yang --- drivers/usb/phy/phy-mxs-usb.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c index 036bb58a3a71..f484c79efa6c 100644 --- a/drivers/usb/phy/phy-mxs-usb.c +++ b/drivers/usb/phy/phy-mxs-usb.c @@ -388,14 +388,8 @@ static void __mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool disconnect) 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; + return IS_ENABLED(CONFIG_USB_OTG) && + mxs_phy->phy.last_event == USB_EVENT_ID; } static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on) From patchwork Tue Jun 27 11:03:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 697188 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F14C2EB64D9 for ; Tue, 27 Jun 2023 11:00:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230189AbjF0LAg (ORCPT ); Tue, 27 Jun 2023 07:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbjF0LAe (ORCPT ); Tue, 27 Jun 2023 07:00:34 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2048.outbound.protection.outlook.com [40.107.22.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ACC21BE7 for ; Tue, 27 Jun 2023 04:00:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KY7E56gb31xjVnbPV1YA9U5APi6nF5woVQ+nM+OFZp9kLJyXm997ZkYAdTt9nqgNuazdi+DRu7Yk2tvB4R3JUY54uB/RdtneIZ66ujDY45vPxrGTQ/n+8p1i8aoqHH3EUuXjZ1VXT/QARO9r0H10qrt7jRcr6FN2s3HxKrLdeqXGDF8jCt7+hkHTRSstNFQgFjNSdwYFXB+OhwAZyFkryUpsFbG0PhqF9l5hvzF/7gflvYKLtd+Ia/n2RvYC8fD8gmUbg3dQH1eUcpdXweYtdtVf9iOU8eBxb06uAW1G1HNoDJX5YGeTLPZfz66Dret6Mlqx7tFsYpgbqE4Zx9zAtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pwtTg9lUeUL0GzdtrGKTRgC1V6L7j/8aRaZuAWgty88=; b=oKHifpML5TcbQrU925roBrNQpe9fYZaQBofI++D0UeGv7z5nZ8u2EqaNf2zGHOlb+arCuNnBmZ/7NgE5z4lOQAwrHo/5fBbPoWx8Zkdp1hceV+dC86/9vYQWbZS5od3ZQ4CcT2FwqJqeIvfCj+yDlFPgTv+3LsZ8VobTNUIl7Mb8xGTqE16dXZCGrtSxWZDjxjZYpa6Ffmu8eEcwRaqZDzd76Ep2G/j2szquDLlIQLY3s6toVXwjqeqelzbBOMR7sktEFoVRdTPw1iUlgQ3xdpJ+kj6WeHXwqj1HAmBlhJDevtfdfT4YyeY6lHvwmA8sKj4QM8FArZivLSLLS0t+YQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pwtTg9lUeUL0GzdtrGKTRgC1V6L7j/8aRaZuAWgty88=; b=iarUTZdzjnZXcgxDANTTD8DbmfDsZDOwx2SVcTxgTMxlEU++WneKlE9xg0L8/H5WrWEFuFt0Rm/xrj9lEqdKxviBLHBAQUD0IEpq6kV8YxL74GCD4k6jQaB2N9Mqe2F/Sc/fCI3Fep4XyS+WxUS4c2pBGrEBcE7iCWdvfJ5rZTs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) by AM9PR04MB8114.eurprd04.prod.outlook.com (2603:10a6:20b:3b7::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Tue, 27 Jun 2023 11:00:31 +0000 Received: from DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4]) by DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4%7]) with mapi id 15.20.6521.024; Tue, 27 Jun 2023 11:00:31 +0000 From: Xu Yang To: peter.chen@kernel.org, gregkh@linuxfoundation.org, shawnguo@kernel.org, s.hauer@pengutronix.de Cc: kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, balbi@ti.com, linux-usb@vger.kernel.org, jun.li@nxp.com, xu.yang_2@nxp.com Subject: [PATCH 3/3] usb: phy: mxs: disconnect line when USB charger is attached Date: Tue, 27 Jun 2023 19:03:53 +0800 Message-Id: <20230627110353.1879477-3-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230627110353.1879477-1-xu.yang_2@nxp.com> References: <20230627110353.1879477-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SI1PR02CA0042.apcprd02.prod.outlook.com (2603:1096:4:1f6::17) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|AM9PR04MB8114:EE_ X-MS-Office365-Filtering-Correlation-Id: f5a90d7b-240d-4c36-f6f6-08db76fdb928 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DgKGNnyUvJANVhUyQmdbvytJxt2jPHMCtKRN8gXniYxMHC7QpmVn5V9PxD1BWvD1KLJICqHtmh7CPPib5SDnEx6bhXHgRzc9Pmq7btW1Zv/zJti0ws5r0I7HJ17snnc5AfpIaYaJypzhYZMRGHxLwzuc4WrJ1aFCIhTJTj1hcarx25hTa4r5Tup43SmkAxjwzv31eLBo62x36bnLr5NLejno67t+tYAVBT8mhmseGoonImfKLgpHzKQJdinNC55yFHzghV2nRyfbBzL/6+kouV3Rf24/NVl7b0c0gakAwWXURJ/TYFZaeHjmUT2pdZJypX9Rir5iKphm+kE1XnCIg9Gv3hBuXQoFdY9IGrB0yF8WZmVrLszAg/LyVDzv9M6MkUsgNPnbMamxbMQH2u7kbSHOTHw8Va1iBa2vxxnJVd/HdSACpkwPBHyFXLTD/yLRG805m5TTMkgxkNY1n0t2b5/QVmJTmNHgX33PmQdXfj9GobzGpwloyDdTccVxRXqbywXZA/IBqRAAnLjvDKlNecWhiBx0o/wNEnug9RM9l/gKV2hJyEUnXLyAbX+OYBFTa+sepNaA8HyUm9imt0J+Wvlei+RNRr4/5wFnCR0NzuoSzB5iqbYtOLFeAu6HUhA9 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR04MB4505.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(346002)(396003)(376002)(136003)(39860400002)(366004)(451199021)(6506007)(36756003)(6486002)(478600001)(52116002)(2616005)(6666004)(83380400001)(2906002)(26005)(6512007)(186003)(1076003)(5660300002)(316002)(86362001)(66476007)(38100700002)(66946007)(38350700002)(41300700001)(8936002)(4326008)(8676002)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: E4sHUjXFe3LReTY8jiuuhRnz9yoXPMsCWHv/K1i69TScjfw0+KiuIYW226EiyZytMB+lGlqz8itmlWmyL6OstDKfJ6hufCGVrw+6op3M+azcMybXJdWU7TpMzBBD2YdrLOeAWieVaTNPopwL9SoJhDcVoC+ay0wzFAxuPSdPyfnNAHv3iAbabuaTJhiGY9LNJni7EsxkSYvB4nzy8OdYKeC5OCgk1P2d65glXKV936M3pDMm0yleFc91JThzeIHwAFPhfr+9MMExgwkewRD+AjmzMi4EjSOXmnJZokiJO3s4NBAbXM1XZTxC9gf6PKhbQXV+HlzNePbUS4UO1VAC/kG57/aMYCJLQ81K5B49bclPkGjnV5OL/cJmjvBwpGPx4BRjLOS0QeyiAZbVj5o6fVjKIiOi9Xu7q0NV8yhtL5EINTA+923ic0Ik2fuxkrnXjOCGtiK0Rm1941BkzNmF1SbHIYlNMyN8xjTTwxDM82434NGFAbFq/1EFi3eOTfclGMJ1+oWyM8OBydCtSJU/jqSU93Szla3hqbK+Jw+0Xv9bSu1IOtLk8F8mL7IbnCzHWtO3P0mRL1ZSc+IAab8gF8ocukRYcR0jINHjuZ6E58AODjrwpn2eU6mbQffc0Pg1oRckvnZhVV4gI18f7ELLh7vEHdqfdGVXhpWNXDS6uZKmT996jEMXB6imPh3pnM2jfG6gJTX95zdxEXo4lvaWSF395+iEYnjygYJgv1l6YFbu7wcBCc0G/POTd0XoRaf4Rb/dCfFztuNzXmQ7p7weFQvc1uBt2LYAJ3IgiFKZV0kK/kHYp3RaQ5oRN7T6R0UlZiJp2vTjhLBhjNffGSzHSyTqcNaFD4MpTqlEd0ZsVKG0Lt9cn31BepFj9xVbqFC42yiETVMmQ6ra7eQkmM9XbciVjVO1xRFLIcfKFe43mVaqHcNxQ+gj18m7TqMdtbN9sEXFPqs6Eg1JnlcVddhFJuoPnzVLQZCzSUw5+x+GXP4KumCErAlT0jKsbZz2Im8HjVfk0M+qomsG6+3jcJJAc4e45U74M1YOaR3soBugWmcgnkjukATFz/HfXAdxz2T3y4TtHchyjJDKXgPcDTRXe77/3JthAuGfBh0DEi8D00oCpwAdOJJYZq1zS22ouN+MwyZZcCB2TzNWl/JJHu9zhSjnVd/Q7sOMc1Sco4xY3PAW6aFvySqhnNQarfcW7KqkaepNPenumR+9xXaXs/p7MMWGMkoFZTyGzJbfvz0Cd6LNyo8XfDvIz45BltIrQPZM3UzXtCTSen6HYL8NqyvwcvuUS+/Ulk7MPcG3xtW/q8xVb+UkCAMDD76/Diy+a715FexjGYCYi10NhcSBB8yWBODLjIrL517U8SMxdW4f/uuuBXm9uudWDT837na9Q2T5HFB1sW2Tg3ucEjjDuxLXoIripTq8IfFzICa5OnacMiGum6AtkYh9XMPFJT7UKueEvaMD5YBuHIcw8UcSxPVZPnFDI5E9dPTCImavUAQ7RktXqXRGqunp6R9WaT/xggODaY/38ken7v2st3kRaYhYs2P1/VF7Y060iAKYIjzw5OubFQE164QYyPyIN5Gb8HzW X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5a90d7b-240d-4c36-f6f6-08db76fdb928 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2023 11:00:31.0336 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5PRYGIYMIQdFiGSrAR011qiEYoNNzSwY6bL6eIIEQAaFmv3mbTO1IYocfRvBciGZgi9JCS2xlAkDMnp4Qn3TMg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8114 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org For mxs PHY, if there is a vbus but the bus is not enumerated, we need to force the dp/dm as SE0 from the controller side. If not, there is possible USB wakeup due to unstable dp/dm, since there is possible no pull on dp/dm, such as there is a USB charger on the port. Signed-off-by: Xu Yang Acked-by: Peter Chen --- drivers/usb/phy/phy-mxs-usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c index f484c79efa6c..619411aab86c 100644 --- a/drivers/usb/phy/phy-mxs-usb.c +++ b/drivers/usb/phy/phy-mxs-usb.c @@ -395,6 +395,7 @@ static bool mxs_phy_is_otg_host(struct mxs_phy *mxs_phy) static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on) { bool vbus_is_on = false; + enum usb_phy_events last_event = mxs_phy->phy.last_event; /* If the SoCs don't need to disconnect line without vbus, quit */ if (!(mxs_phy->data->flags & MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS)) @@ -406,7 +407,8 @@ 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_is_otg_host(mxs_phy)) + || (last_event == USB_EVENT_VBUS))) __mxs_phy_disconnect_line(mxs_phy, true); else __mxs_phy_disconnect_line(mxs_phy, false);