Message ID | 1685544074-17337-1-git-send-email-quic_prashk@quicinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> 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 <rfc822;andrewvogler123@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <quic_prashk@quicinc.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, "AngeloGioacchino Del Regno" <angelogioacchino.delregno@collabora.com> CC: Matthias Brugger <matthias.bgg@gmail.com>, <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>, Prashanth K <quic_prashk@quicinc.com> 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: <linux-kernel.vger.kernel.org> 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?= |
Series |
[v7] usb: common: usb-conn-gpio: Set last role to unknown before initial detection
|
|
Commit Message
Prashanth K
May 31, 2023, 2:41 p.m. UTC
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 <quic_prashk@quicinc.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> --- 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(+)
Comments
On 31-05-23 08:11 pm, Prashanth K wrote: > > 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, Hi Greg, I have fixed the drivers that doesn't have default case while using usb_role enum. Added the same on intel-xhci-usb-role-switch.c & musb/jz4740.c files. I was able to compile successfully. Please check once if this fixed the build issue. Thanks in advance, Prashanth K
On Wed, May 31, 2023 at 08:17:23PM +0530, Prashanth K wrote: > > > On 31-05-23 08:11 pm, Prashanth K wrote: > > 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, > > Hi Greg, I have fixed the drivers that doesn't have default case while using > usb_role enum. Added the same on intel-xhci-usb-role-switch.c & > musb/jz4740.c files. I was able to compile successfully. Please check once > if this fixed the build issue. Looks good, thanks! greg k-h
Hi, On Wed, May 31, 2023 at 08:11:14PM +0530, Prashanth K wrote: > 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. So why can't you fix this by just always setting the role unconditionally to USB_ROLE_NONE in your probe function before the 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 <quic_prashk@quicinc.com> > Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> > --- > 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
On 13-06-23 04:40 pm, Heikki Krogerus wrote: > Hi, > > On Wed, May 31, 2023 at 08:11:14PM +0530, Prashanth K wrote: >> 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. > > So why can't you fix this by just always setting the role > unconditionally to USB_ROLE_NONE in your probe function before the > initial detection? > Hi Heikki, thats exactly what we are doing here. + /* 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); Thanks, Prashanth K
On Wed, Jun 14, 2023 at 09:55:10AM +0530, Prashanth K wrote: > > > On 13-06-23 04:40 pm, Heikki Krogerus wrote: > > Hi, > > > > On Wed, May 31, 2023 at 08:11:14PM +0530, Prashanth K wrote: > > > 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. > > > > So why can't you fix this by just always setting the role > > unconditionally to USB_ROLE_NONE in your probe function before the > > initial detection? > > > Hi Heikki, thats exactly what we are doing here. > > + /* Set last role to unknown before performing the initial detection */ > + info->last_role = USB_ROLE_UNKNOWN; No, I'm asking why can't you just call set_role(USB_ROLE_NONE) (together with any other steps that you need to take in order to fix you issue) directly from your probe function? That USB_ROLE_UNKNOWN as a global is not acceptable - there is no difference between USB_ROLE_UNKNOWN and USB_ROLE_NONE from the role switch PoW. So if you want to use something like that, you have to confine it to your driver. But I honestly don't think you need it at all. You should be able to refactor your driver in order to solve the issue described in the commit message without any need for it. Note! I just realised that you are not modifying drivers/usb/roles/class.c, so this patch is actually broken. thanks,
On Wed, May 31, 2023 at 08:11:14PM +0530, Prashanth K wrote: > 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 <quic_prashk@quicinc.com> > Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> > --- > 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(+) Just to be clear to everybody, that USB_ROLE_UNKNOWN is not handled in drivers/usb/roles/class.c, so this patch is broken. But the whole approach is wrong. That USB_ROLE_UNKNOWN is clearly a flag where the other values in enum usb_role are actual switch states. So it does not belong there. In general, adding globals states like that just in order to work around issues in single drivers is never a good idea IMO. thanks,
On Wed, Jun 14, 2023 at 12:14:08PM +0300, Heikki Krogerus wrote: > On Wed, May 31, 2023 at 08:11:14PM +0530, Prashanth K wrote: > > 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 <quic_prashk@quicinc.com> > > Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> > > --- > > 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(+) > > Just to be clear to everybody, that USB_ROLE_UNKNOWN is not handled in > drivers/usb/roles/class.c, so this patch is broken. > > But the whole approach is wrong. That USB_ROLE_UNKNOWN is clearly a > flag where the other values in enum usb_role are actual switch states. > So it does not belong there. > > In general, adding globals states like that just in order to work > around issues in single drivers is never a good idea IMO. Ok, let me go revert this from my tree, thanks for the review. greg k-h
On 15-06-23 03:00 pm, Greg Kroah-Hartman wrote: > On Wed, Jun 14, 2023 at 12:14:08PM +0300, Heikki Krogerus wrote: >> On Wed, May 31, 2023 at 08:11:14PM +0530, Prashanth K wrote: >>> 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 <quic_prashk@quicinc.com> >>> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> >>> --- >>> 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(+) >> >> Just to be clear to everybody, that USB_ROLE_UNKNOWN is not handled in >> drivers/usb/roles/class.c, so this patch is broken. >> >> But the whole approach is wrong. That USB_ROLE_UNKNOWN is clearly a >> flag where the other values in enum usb_role are actual switch states. >> So it does not belong there. >> >> In general, adding globals states like that just in order to work >> around issues in single drivers is never a good idea IMO. > > Ok, let me go revert this from my tree, thanks for the review. > > greg k-h In that case, can I resubmit v1 of this patch again, where I have used a macro in usb-conn-gpio driver ? something like this. @@ -27,6 +27,8 @@ #define USB_CONN_IRQF \ (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT) +#define USB_ROLE_UNKNOWN (USB_ROLE_NONE -1) + struct usb_conn_info { struct device *dev; struct usb_role_switch *role_sw; @@ -257,6 +259,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); Thanks, Prashanth K
On Thu, Jun 15, 2023 at 07:52:32PM +0530, Prashanth K wrote: > > > On 15-06-23 03:00 pm, Greg Kroah-Hartman wrote: > > On Wed, Jun 14, 2023 at 12:14:08PM +0300, Heikki Krogerus wrote: > > > On Wed, May 31, 2023 at 08:11:14PM +0530, Prashanth K wrote: > > > > 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 <quic_prashk@quicinc.com> > > > > Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> > > > > --- > > > > 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(+) > > > > > > Just to be clear to everybody, that USB_ROLE_UNKNOWN is not handled in > > > drivers/usb/roles/class.c, so this patch is broken. > > > > > > But the whole approach is wrong. That USB_ROLE_UNKNOWN is clearly a > > > flag where the other values in enum usb_role are actual switch states. > > > So it does not belong there. > > > > > > In general, adding globals states like that just in order to work > > > around issues in single drivers is never a good idea IMO. > > > > Ok, let me go revert this from my tree, thanks for the review. > > > > greg k-h > > In that case, can I resubmit v1 of this patch again, where I have used a > macro in usb-conn-gpio driver ? something like this. > > @@ -27,6 +27,8 @@ > #define USB_CONN_IRQF \ > (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT) > > +#define USB_ROLE_UNKNOWN (USB_ROLE_NONE -1) Are you referencing an existing enum here and assuming it is a specific value? For obvious reasons, that can never work :) thanks, greg k-h
On 15-06-23 08:06 pm, Greg Kroah-Hartman wrote: > On Thu, Jun 15, 2023 at 07:52:32PM +0530, Prashanth K wrote: >> >> In that case, can I resubmit v1 of this patch again, where I have used a >> macro in usb-conn-gpio driver ? something like this. >> >> @@ -27,6 +27,8 @@ >> #define USB_CONN_IRQF \ >> (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT) >> >> +#define USB_ROLE_UNKNOWN (USB_ROLE_NONE -1) > > Are you referencing an existing enum here and assuming it is a specific > value? I' not assuming UBS_ROLE_NONE to be a specific value, but I want an integer (for macro) which is not equal to USB_ROLE_NONE/DEVICE/HOST, that's why I'm using (USB_ROLE_NONE - 1), assuming enumerators NONE, DEVICE & HOST will be having adjacent integer values. Wouldn't that help? Thanks, Prashanth K
On Thu, Jun 15, 2023 at 08:28:13PM +0530, Prashanth K wrote: > > > On 15-06-23 08:06 pm, Greg Kroah-Hartman wrote: > > On Thu, Jun 15, 2023 at 07:52:32PM +0530, Prashanth K wrote: > > > > > > In that case, can I resubmit v1 of this patch again, where I have used a > > > macro in usb-conn-gpio driver ? something like this. > > > > > > @@ -27,6 +27,8 @@ > > > #define USB_CONN_IRQF \ > > > (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT) > > > > > > +#define USB_ROLE_UNKNOWN (USB_ROLE_NONE -1) > > > > Are you referencing an existing enum here and assuming it is a specific > > value? > > I' not assuming UBS_ROLE_NONE to be a specific value, but I want an integer > (for macro) which is not equal to USB_ROLE_NONE/DEVICE/HOST, that's why I'm > using (USB_ROLE_NONE - 1), assuming enumerators NONE, DEVICE & HOST will be > having adjacent integer values. Wouldn't that help? You can't do "math" on an enumerated type and expect the result to be anything constant over time. And yes, you can hope that enumerated types are sequential, and the spec says so, but please never rely on that as what happens if someone adds a new one in the list without you ever noticing it. Pleasae treat enumerated types as an opaque thing that you never know the real value of, it's a symbol only. thanks, greg k-h
On 15-06-23 08:35 pm, Greg Kroah-Hartman wrote: > On Thu, Jun 15, 2023 at 08:28:13PM +0530, Prashanth K wrote: >> >> >> On 15-06-23 08:06 pm, Greg Kroah-Hartman wrote: >>> On Thu, Jun 15, 2023 at 07:52:32PM +0530, Prashanth K wrote: >>>> >>>> In that case, can I resubmit v1 of this patch again, where I have used a >>>> macro in usb-conn-gpio driver ? something like this. >>>> >>>> @@ -27,6 +27,8 @@ >>>> #define USB_CONN_IRQF \ >>>> (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT) >>>> >>>> +#define USB_ROLE_UNKNOWN (USB_ROLE_NONE -1) >>> >>> Are you referencing an existing enum here and assuming it is a specific >>> value? >> >> I' not assuming UBS_ROLE_NONE to be a specific value, but I want an integer >> (for macro) which is not equal to USB_ROLE_NONE/DEVICE/HOST, that's why I'm >> using (USB_ROLE_NONE - 1), assuming enumerators NONE, DEVICE & HOST will be >> having adjacent integer values. Wouldn't that help? > > You can't do "math" on an enumerated type and expect the result to be > anything constant over time. > > And yes, you can hope that enumerated types are sequential, and the spec > says so, but please never rely on that as what happens if someone adds a > new one in the list without you ever noticing it. > > Pleasae treat enumerated types as an opaque thing that you never know > the real value of, it's a symbol only. > > thanks, > > greg k-h Then we can go ahead a different approach using a flag. But that would require us to add a new member to usb_conn_info struct. What do you suggest? @@ -42,6 +42,7 @@ struct usb_conn_info { struct power_supply_desc desc; struct power_supply *charger; + bool initial_det; }; /* @@ -86,11 +87,13 @@ static void usb_conn_detect_cable(struct work_struct *work) dev_dbg(info->dev, "role %s -> %s, gpios: id %d, vbus %d\n", usb_role_string(info->last_role), usb_role_string(role), id, vbus); - if (info->last_role == role) { + if (!info->initial_det && (info->last_role == role)) { dev_warn(info->dev, "repeated role: %s\n", usb_role_string(role)); return; } + info->initial_det = false; + if (info->last_role == USB_ROLE_HOST && info->vbus) regulator_disable(info->vbus); @@ -258,6 +261,7 @@ static int usb_conn_probe(struct platform_device *pdev) device_set_wakeup_capable(&pdev->dev, true); /* Perform initial detection */ + info->initial_det = true; usb_conn_queue_dwork(info, 0); Regards, Prashanth K
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,