From patchwork Wed May 31 14:41:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashanth K X-Patchwork-Id: 101513 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2958696vqr; Wed, 31 May 2023 08:19:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ63mxYpuWJP8FChKCM5Wuk5xjHYtkYpD775lH7y2wBlDs0klv+CTJWaTwj6HM6gZPoEZcYu X-Received: by 2002:a17:902:6b09:b0:1b1:80ba:39d2 with SMTP id o9-20020a1709026b0900b001b180ba39d2mr600916plk.58.1685546355391; Wed, 31 May 2023 08:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685546355; cv=none; d=google.com; s=arc-20160816; b=mmnl8uciWBEQLpUoDW2JKMrwDS+o2v9cV1TTaZN4G7Nz0W6kIpaDIhWx/kdGE5KzfZ A8ev5j9h7c1YILO/a60G6E/GTCO+PSEG11blanJChx79JDiKUYUzTUV2ishLwdiu4Ezg QelHo8GCA9e0jnc94fjoIlU1/XkDEfGaFFramcrx+lgCUbH50JDQdGboc9dmKkDYl/lD wIFr3Bd3Yy734yaxHn53yS4sK4yb1TldNNCVGECZ0rCTnEouEd6hXWvp15PLk9U4+nhv 6pjx/jzxXi8IQe8TkcqSd3XOJEEQPZYDA5TFRjt2it7HLyzokkjBxUM29K4F4RIuUlqE Vliw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jh19-20020a170903329300b001aadb1147e4si1010173plb.456.2023.05.31.08.19.03; Wed, 31 May 2023 08:19:15 -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 S232134AbjEaOlr (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767423455455055867?= X-GMAIL-MSGID: =?utf-8?q?1767423455455055867?= 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,