From patchwork Wed Dec 7 03:14:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 631853 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 1C0C8C352A1 for ; Wed, 7 Dec 2022 03:14:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229684AbiLGDO2 (ORCPT ); Tue, 6 Dec 2022 22:14:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbiLGDO1 (ORCPT ); Tue, 6 Dec 2022 22:14:27 -0500 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on060f.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::60f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CDF153ECB for ; Tue, 6 Dec 2022 19:14:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RYdgeifHRR7ZrhlbTeQCT4eh06aT7t+dJhZYT/k5lvTYdOHkfqhsmMsay7HeKkttjz3Rsl2PO6dz+ge5wXJIIhBq1tR6ELbX2jyCux0Gh9k07CNRO1i3cV6dqpr8rAvVXNUq4oet55IvS/nba5u4uvFQtidv+o5bXYXR+DOkCzdJSzB+Xy1ao/3vyr85XXkg74SpZAbRfyxgp1VdF7ZwIEakXHRtIM70s+jiR+YBLRz6Svt2N7b6tluXCA/7TzQZnYhPXJirTScYJC2qybPUZJUJTYswyJJuZhiOtA96Z2Hq4rs4Kqg2wuO93q8Sau/H/NKwh0R644lIjYYLuD9dDA== 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=XxPZEZ1uEcl462LpQiCFgxX750AmDv2yyxJmFyVD51Y=; b=G2/XA8hcmwD9jwx+7zSX2/3mdU10yVoyZO5nj8kIjoUqW+mGc+/Jt9HA5Rhx9wHxwYkwgOiDQh464STlf9AwPegH7k4q9rQbGu+fK3wMQe1+OnvH5UV7Mz1p0NNuMWYjswG+/rnvH6+5a04N9RHDOC6okUbGXTF/ISZzJA8HqQizzes7UYzTTQPUr1e8tKCB83ve0YkC/BOlBYPKMSytFCSQro8TYwV03W8gkJEyQRFfXoel2VQYwTB/Xql7kcLdzNixyROWhR+yj/1qVjuloMCosUU58dGYdNcIntDfiMeDiEE0BF/UBECnpAh/hroZeEwDTRXeSfkiCiRBFiYKuw== 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=XxPZEZ1uEcl462LpQiCFgxX750AmDv2yyxJmFyVD51Y=; b=KqazxIHsfyR9NiyBgVW6lIUe1D4iCfkjb8nbI3nmIvchUau1yJ4L/t1dumdNQdHpel/UHVOG5US9AUDnniO58Djc/TQmabqRHXwKeUOb5ELHehzg7/4KeD8DGr41Zs59dDCiM+fukOLASiuUhKrCtLCANhzupp6A0IfeO7RNvJg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PA4PR04MB9591.eurprd04.prod.outlook.com (2603:10a6:102:270::18) by DB9PR04MB9473.eurprd04.prod.outlook.com (2603:10a6:10:369::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.13; Wed, 7 Dec 2022 03:14:21 +0000 Received: from PA4PR04MB9591.eurprd04.prod.outlook.com ([fe80::8184:d5e2:3c61:b493]) by PA4PR04MB9591.eurprd04.prod.outlook.com ([fe80::8184:d5e2:3c61:b493%6]) with mapi id 15.20.5880.013; Wed, 7 Dec 2022 03:14:21 +0000 From: Xu Yang To: peter.chen@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-imx@nxp.com, jun.li@nxp.com, xu.yang_2@nxp.com Subject: [PATCH] usb: chipidea: otg: handle vbus change for udc iff it's in device mode Date: Wed, 7 Dec 2022 11:14:48 +0800 Message-Id: <20221207031448.336080-1-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI1PR02CA0044.apcprd02.prod.outlook.com (2603:1096:4:1f6::6) To PA4PR04MB9591.eurprd04.prod.outlook.com (2603:10a6:102:270::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PA4PR04MB9591:EE_|DB9PR04MB9473:EE_ X-MS-Office365-Filtering-Correlation-Id: c9856800-ab20-4a69-f4cf-08dad8012287 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k/rZ2tcvD6iEP3kuDnurqpgpnv8v+J7ugOTlcRjNG3SjEFeB/krWU+aBulARc4GT9yLDs9xieQxcSpE1oMoShJCvg7mMl/hJokP98Ddl7aEzkiSAUm5wVTY6UkZB/swwXIZM1F5JSHzkkNBKTx+EZBYvxDzzGwcaeq45dYkCwkixxZ1Tqi8jVWdy2v0cah3TSpxn1s8UjMMwDI/QdOy+KDBnHgYO/1bnOxlFMNJn+wYao0eAVkXUWwACAhoiKqwOfnlwwNWeLbhPCYk9XHrfu8liGflDf+TJ5hQzkinDJAeTJyx/ZGq4SfMQZLoaHy6V97BK7kdVgk4XdSBrVuPPgGEyP/fzPG+1S9R3yMZPezTT9/a6wBoiEmre5CQRsZFmFe/kLqQAlD2kdJMn8bAG45dhLLm3dy/2ryF9b/LCqU4dkOzRcTESJ27zlhOdDn/hMge0KNCFxLWsciNieIVwdvHvq3UvTLYAbg4+TEl3BgP/UM487rnga078QIhOQwVhRLlT+hBgTDuzN59j27B1scrS6U93j0t/fr3ehEGILhgJgOQEgS42nh5pqgb09PYsrd4jsOvBZpv0d1x+dv946Ips/SzhEq92vSqTp6xJYapdLV5QVHjvCG5D42XBlTZj03NcTq+ejlCVXl2DFAZV35BzwM5BfeCGZhdW73VSh38r0fkWH2zmWtrjKBp30EAs X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR04MB9591.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(136003)(376002)(346002)(396003)(39860400002)(366004)(451199015)(38100700002)(36756003)(478600001)(86362001)(6486002)(2906002)(26005)(5660300002)(6506007)(8676002)(66476007)(6666004)(6512007)(186003)(8936002)(41300700001)(316002)(6916009)(4326008)(66556008)(66946007)(2616005)(52116002)(38350700002)(1076003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lrvFn+KQeNpKdZHfo1AVX+nnqPewYpE2+ufW2M0gy9n2ReLe788RZfFHw/W47M/VBYFyAKkAXys6i/wd9PO9P8cLqVLgGe0RcYVD4r40MbrDT7Lr5pfdHaHvpP2KAQmazGnyz1dDYzBlEh2XFzuxHInPz5LJs295FsPfqTuv11i5jVp46ufSuz3OXyDPfpSgqyPekS87U60uh0gfmrapIrN1147XVPC44/MUcV2/qjj/1icFRjOBoDJMN9qEnfy+Cv+4wcaXluYaRiWic/uc1Ut19rZeZYh4nnj2PA2djlb6goBG94ZH+ZzC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+WSsq4NbFZBHZcCk1FerIN4oY6AtqBPGyU/Hz+27Pg/ZrH/+XMM7MyHT1wLuB4E2+nruF79+KcksujwP2TGHpJaNSCujJoxHcZSPKbONBiiTK2YhqJZhJjGlsULOPiYRVzrfJtEwormcrt6Qnq2uM+mb+HM4gGzoyOlUXmt6lsADfW0Hgk2iQt96mVvraijD1zssG9HV94K+OyUOdHY4apnr X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c9856800-ab20-4a69-f4cf-08dad8012287 X-MS-Exchange-CrossTenant-AuthSource: PA4PR04MB9591.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 03:14:21.5216 (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: Leojhb73ff2vjBRBfWIozIw+riBdGNrE5PZBWsI2yGNJSPaDnbO2NgN//Xw7nj2fAFJ9kHA0OiX7kIXZvtLlRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9473 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When in device mode at first (BSVIE is set), OTGSC will assert both BSVIS and IDIS bit if changed to host mode. ID event will be handled in the first interrupt. Depends on whether BSVIE is cleared when call ci_role_stop() for udc, the 2rd interrupt may be asserted after a specific interrupt period (BSVIE and BSVIS is still 1). If it is, the driver will continue to handle VBUS change for udc. We should avoid this manner since the controller is not in device mode and the worser is gadget related code may be executed if a gadget driver is attached. Fixes: a107f8c505cd ("usb: chipidea: add vbus interrupt handler") cc: Signed-off-by: Xu Yang --- drivers/usb/chipidea/otg.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c index f5490f2a5b6b..31c38a3ab990 100644 --- a/drivers/usb/chipidea/otg.c +++ b/drivers/usb/chipidea/otg.c @@ -133,6 +133,9 @@ void ci_handle_vbus_change(struct ci_hdrc *ci) if (!ci->is_otg) return; + if (ci_otg_role(ci) != CI_ROLE_GADGET) + return; + if (hw_read_otgsc(ci, OTGSC_BSV) && !ci->vbus_active) usb_gadget_vbus_connect(&ci->gadget); else if (!hw_read_otgsc(ci, OTGSC_BSV) && ci->vbus_active)