From patchwork Tue May 30 04:44:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashanth K X-Patchwork-Id: 100536 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1951419vqr; Mon, 29 May 2023 22:40:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4LfLfUqTwea9yHw1ewju8L1Hw2zm7DQL6QVaju1Rk6bM6WO0k2X/yXn5b5zNdPiz1Nmdw4 X-Received: by 2002:a17:90b:b17:b0:255:d628:c69b with SMTP id bf23-20020a17090b0b1700b00255d628c69bmr1271441pjb.6.1685425204437; Mon, 29 May 2023 22:40:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685425204; cv=none; d=google.com; s=arc-20160816; b=03WN7WegNUiW8bhYBY3DoC/upfN/vH8CruhtnZDVVVk45ImWoGjxuukmJX7YOa8mPU 1NgDRzEIsQT1P+DBYgarv00uEOuQj1LNWzg/MidSVyyat7SbqzXvxusijcm6ekBV5IKa 3WhBXgi09/DSp2/eKifk3LeSuo05plkwEf+jBi7SVeFsxv99ycmpLzKEKdimYoptwaSb 6xrNnFoYRXJ1EapN/htVqUOsUCtWswh1BHeBivIdSA+YBsVDCdKRB1bQEaSgJubKxiGq vNucJU60dNJdIVegG1NHQ8FAiOYP9vU7z/gSqR2eefa5wWxQjwAN8sgrDYP9/uRJxGLZ S/HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=ARpI1vp8nkCFJtP0O5zGcbQNQXbYtxd1j/fx2C1yJ54=; b=Npu663F4qbjqAQz14QzBaKLlq2rXGv1P/PoRVaJq9//Ppa5/1d/BZvI8V2lJZGIx0z nvB8eSGiRcqQnykpRo/0OzKtEqHo72kFFyevbGkjRQzs7KmMeWISUNarOBeUgr0A9HWz AhpKzoMtBxahtSBX8gPwWo3zjTJb+qC1Br0HH6jPgP6q7vqNKjNvvCAEDtRGv898MgzW 6/ruz8epgFTlTKq3WujCt1rwXJxNrVT5L+/igr8NHpfAQ7TEBjAP1OOKAotCk9WDK9Kn SRWU7vbruf/DHdTnl+MZxks0+xJRJ0zbFsAKDJniC/6dKczpdMcW6W9QwUFNj7pCbyKf hCcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=nHlMwoqo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o21-20020a17090a9f9500b00250a2c9a793si3977333pjp.152.2023.05.29.22.39.52; Mon, 29 May 2023 22:40:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=nHlMwoqo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230060AbjE3EpC (ORCPT + 99 others); Tue, 30 May 2023 00:45:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229749AbjE3Eo7 (ORCPT ); Tue, 30 May 2023 00:44:59 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88EABEA; Mon, 29 May 2023 21:44:56 -0700 (PDT) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34U3f17d022534; Tue, 30 May 2023 04:44:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=qcppdkim1; bh=ARpI1vp8nkCFJtP0O5zGcbQNQXbYtxd1j/fx2C1yJ54=; b=nHlMwoqoWdGtYK/+1myvOzbG3wfYbtN8KPBTVBVuiCG6MfvOc0G+NdRLpRqgpCKcjm39 98tVhBEeQtP+jdz5yKEt7H1ciaaftDUW3Q4/QTITbM5MoWwljP13RNe4yYAYCqirXc+F Ofc9GtUlvg5/zfZfRVwdXQN4WJepiJZ+H5WltGTmECwRiFkFbfEXK3ajZLEcS/m8U7I9 haPhuTFBxNqJ28TKDY28DgWrY/fs+/3aX8tAGmV2ljDv1r+IG+7MWJDRYWwJFLsmHdsw jnHJVEqQgz4Jd3Damwtp06giCeUMazojJ5qsXbfT2xhJcXtAYpvO7X4YdJopUsfQh7a3 Bw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qub56vs9u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 May 2023 04:44:53 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 34U4iqh5016807 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 May 2023 04:44:52 GMT Received: from hu-prashk-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 29 May 2023 21:44:49 -0700 From: Prashanth K To: Greg Kroah-Hartman , Matthias Brugger CC: AngeloGioacchino Del Regno , , , Prashanth K Subject: [PATCH v6] usb: common: usb-conn-gpio: Set last role to unknown before initial detection Date: Tue, 30 May 2023 10:14:31 +0530 Message-ID: <1685421871-25391-1-git-send-email-quic_prashk@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: eojhkxHtQg3dSMoAGFNQHSDRD2_Go3qh X-Proofpoint-ORIG-GUID: eojhkxHtQg3dSMoAGFNQHSDRD2_Go3qh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-30_02,2023-05-29_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1015 mlxscore=0 suspectscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305300037 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766766285470192139?= X-GMAIL-MSGID: =?utf-8?q?1767296418963715375?= Currently if we bootup a device without cable connected, then usb-conn-gpio won't call set_role() since last_role is same as current role. This happens because during probe last_role gets initialised to zero. To avoid this, added a new constant in enum usb_role, last_role is set to USB_ROLE_UNKNOWN before performing initial detection. While at it, also handle default case for the usb_role switch in cdns3 to avoid build warnings. Fixes: 4602f3bff266 ("usb: common: add USB GPIO based connection detection driver") Signed-off-by: Prashanth K Reviewed-by: AngeloGioacchino Del Regno --- v6: Moved USB_ROLE_UNKNOWN towards the end of enum usb_role. v5: Update commit text to mention the changes made in cdns3 driver. v4: Added Reviewed-by tag. v3: Added a default case in drivers/usb/cdns3/core.c as pointed out by the test robot. v2: Added USB_ROLE_UNKNWON to enum usb_role. drivers/usb/cdns3/core.c | 2 ++ drivers/usb/common/usb-conn-gpio.c | 3 +++ include/linux/usb/role.h | 1 + 3 files changed, 6 insertions(+) diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index dbcdf3b..69d2921 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -252,6 +252,8 @@ static enum usb_role cdns_hw_role_state_machine(struct cdns *cdns) if (!vbus) role = USB_ROLE_NONE; break; + default: + break; } dev_dbg(cdns->dev, "role %d -> %d\n", cdns->role, role); diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c index e20874c..30bdb81 100644 --- a/drivers/usb/common/usb-conn-gpio.c +++ b/drivers/usb/common/usb-conn-gpio.c @@ -257,6 +257,9 @@ static int usb_conn_probe(struct platform_device *pdev) platform_set_drvdata(pdev, info); device_set_wakeup_capable(&pdev->dev, true); + /* Set last role to unknown before performing the initial detection */ + info->last_role = USB_ROLE_UNKNOWN; + /* Perform initial detection */ usb_conn_queue_dwork(info, 0); diff --git a/include/linux/usb/role.h b/include/linux/usb/role.h index b5deafd..65e790a 100644 --- a/include/linux/usb/role.h +++ b/include/linux/usb/role.h @@ -11,6 +11,7 @@ enum usb_role { USB_ROLE_NONE, USB_ROLE_HOST, USB_ROLE_DEVICE, + USB_ROLE_UNKNOWN, }; typedef int (*usb_role_switch_set_t)(struct usb_role_switch *sw,