Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp974996rwd; Wed, 31 May 2023 07:55:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5OdWrdTt7EBjOHUNkDzaZqZGCVrARDpMrO72CfbkZlHjaELD/gGBczT4jE24b8AhqMFvGa X-Received: by 2002:a05:6a20:43a2:b0:10a:a0e1:96fa with SMTP id i34-20020a056a2043a200b0010aa0e196famr4873091pzl.22.1685544951653; Wed, 31 May 2023 07:55:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544951; cv=none; d=google.com; s=arc-20160816; b=ooPZR/Nx1mzXKQ36Y4Uk2XL3AmZuOt31kDb8uCA+W0OCoLQvP2i1tGPhzuLAa49iY9 4CmWgVi/I5m2+hPbEb1U0rVMr5ogIdvh42H3G6V7ZOvHfrf3bgUjpXAcLE4g5j3h1Yoh C1ejdk+ZKY16uU4vGQxcc6Yq+dKq/PULn/ZTHBoSChhveK5e1HPC+O7U0pURkPrtWxos NHZjeVGoXZCUgDK9D7x4FajwV+2V3ff0k597WQIR/N5xnvjNfDtgFGRZF8rMG7vADKBG GShgytLX6ztM7Py+taaoi/0HpW/2OiM9iwPdN9QI6XzymOtR0GtBEvo3Lw2qByDSJfpz cJIQ== 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=VNEJ7nV1z3BxKPdVWitfzNaoCAssTf5Gen+kqEgfdao=; b=MPp7Rsprc+bYN83FgwJ1iiCpIBN91lXDuIk3RtWY+xVfIMZYytUMwxtE2ut5/6Uq7n KdNMc2bxxAXbEojKbfjbQ5Hv+pkj2nA17yE9i4ZQPsz0w5sH68csc/GLz7xsPCbvgAsr RHwlYWHLE+yqosoNoPzcZHfUaoqskLRbwT+W/x50zfABZn4UnDBj56TJ61M0d76ucGoa w49UxeJDvmaCxwXiL/RKp5IxbLDHlb+wUMmvJU5ogK+GgPpsvvo2Hj0oVdMZNw2vw3zF nWAmKwZln+T9BNFKjlHPNUpCp3c494zrJxjTvHsWGcisb5AD89HiM/QYzPK6LgrZfKmU DLgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=T+nOIO1M; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q5-20020aa79605000000b00643bc9d1245si508342pfg.314.2023.05.31.07.55.38; Wed, 31 May 2023 07:55:51 -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=T+nOIO1M; 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 S237056AbjEaOlr (ORCPT + 99 others); Wed, 31 May 2023 10:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231603AbjEaOlp (ORCPT ); Wed, 31 May 2023 10:41:45 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4574198; Wed, 31 May 2023 07:41:44 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34VCqEki004029; Wed, 31 May 2023 14:41:40 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=VNEJ7nV1z3BxKPdVWitfzNaoCAssTf5Gen+kqEgfdao=; b=T+nOIO1MpYxyXJnwUByVC0okxb3s4dZDBfh9TpMPNRWEgZuJ4cqTzDeQwzPqeGMXmWE2 7tQ294UR/NJNYOdiQXTOgsglE5N3TgLYMjJbiXlOO20ackQb4zRf9h0WDgalXDzE39kd /uhn+/1UuKfWqAyqrqBhYvWQA8LSJzHzp+UXn3vzKJPJE2X/Xo3kXQeAj1epZXxrNz3a hBHIXDA/n0D5qivcnbR6QutZBKsAAVKOAK33WqW4wiW5rtZKHTx8/pvex1q2rXvxQ61P p1ZuUR8KsckxnOyVRMac3uy+CSkMUXJSRw5gGuBU4lyBpNMpuA5N08Iu5RWJztcpOzyz 4w== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qx1ybrwva-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 May 2023 14:41:40 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 34VEfdBg005556 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 May 2023 14:41:39 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; Wed, 31 May 2023 07:41:37 -0700 From: Prashanth K To: Greg Kroah-Hartman , "AngeloGioacchino Del Regno" CC: Matthias Brugger , , , Prashanth K Subject: [PATCH v7] usb: common: usb-conn-gpio: Set last role to unknown before initial detection Date: Wed, 31 May 2023 20:11:14 +0530 Message-ID: <1685544074-17337-1-git-send-email-quic_prashk@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) 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: TKJhHBHmOaiH_df4S9K-nO-1hab8p-c2 X-Proofpoint-ORIG-GUID: TKJhHBHmOaiH_df4S9K-nO-1hab8p-c2 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-31_10,2023-05-31_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxlogscore=999 mlxscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 spamscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305310125 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,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 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, intel-xhci-usb-role-switch & musb/jz4740 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 --- v7: Added default case in musb/jz4740.c & intel-xhci-usb-role-switch.c to avoid build warnings. 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 +++ drivers/usb/musb/jz4740.c | 2 ++ drivers/usb/roles/intel-xhci-usb-role-switch.c | 2 ++ include/linux/usb/role.h | 1 + 5 files changed, 10 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/drivers/usb/musb/jz4740.c b/drivers/usb/musb/jz4740.c index 5aabdd7..6d880c4 100644 --- a/drivers/usb/musb/jz4740.c +++ b/drivers/usb/musb/jz4740.c @@ -95,6 +95,8 @@ static int jz4740_musb_role_switch_set(struct usb_role_switch *sw, case USB_ROLE_HOST: atomic_notifier_call_chain(&phy->notifier, USB_EVENT_ID, phy); break; + default: + break; } return 0; diff --git a/drivers/usb/roles/intel-xhci-usb-role-switch.c b/drivers/usb/roles/intel-xhci-usb-role-switch.c index 5c96e92..4d6a3dd 100644 --- a/drivers/usb/roles/intel-xhci-usb-role-switch.c +++ b/drivers/usb/roles/intel-xhci-usb-role-switch.c @@ -97,6 +97,8 @@ static int intel_xhci_usb_set_role(struct usb_role_switch *sw, val |= SW_VBUS_VALID; drd_config = DRD_CONFIG_STATIC_DEVICE; break; + default: + break; } val |= SW_IDPIN_EN; if (data->enable_sw_switch) { 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, -- 2.7.4