From patchwork Thu Feb 23 12:42:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashanth K X-Patchwork-Id: 13150231 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 79C81C64ED6 for ; Thu, 23 Feb 2023 12:42:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234035AbjBWMmU (ORCPT ); Thu, 23 Feb 2023 07:42:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234021AbjBWMmT (ORCPT ); Thu, 23 Feb 2023 07:42:19 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D06A113E0; Thu, 23 Feb 2023 04:42:18 -0800 (PST) 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 31NB5ln8017967; Thu, 23 Feb 2023 12:42:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=NjY00UcLF5Tg2ubWKuLj92kmkGy6Av+56YP17HzFbUI=; b=khuFKp48Ntl56ZorWBNEDrJCbIYnztiXpI/YJNsbeFdDLMHZ7FwzbMiDYRGmZ2PGf1m4 LWEwbvUmUOaEqRkpm7CjDdfnhSak+g78KLuY9cv5DwN6kzGquc/Ma/jK6DvRgHFVuYdo DhGWhnvy9fubFHx8IyLoOy99sn8Asw3HE8x0rA4Jw7wXTyWPksQlrJCqGPj1NK0QMUzd iE08A6AqODQFUyFNY8SRaXKS8qdW7oIxATQWdSvzVtSO+GRFeIbgZM8hNWRmzD9dQVhr bTMMkgtGSCALzQwtL3DGVqwVHDokbwhoN/j3/x7psZTBIHmue4AcfsJWvMzyMv4vmajN PA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3nwyc5hams-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Feb 2023 12:42:15 +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 31NCgDAY016130 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Feb 2023 12:42:13 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.41; Thu, 23 Feb 2023 04:42:10 -0800 From: Prashanth K To: Greg Kroah-Hartman , Thinh Nguyen , Jakob Koschel , =?utf-8?b?SsOzIMOBZ2lsYSBCaXRzY2g=?= , Alan Stern CC: Pratham Pratap , Jack Pham , , , Prashanth K Subject: [PATCH v3 1/2] usb: dwc3: gadget: Change condition for processing suspend event Date: Thu, 23 Feb 2023 18:12:00 +0530 Message-ID: <1677156121-30364-2-git-send-email-quic_prashk@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1677156121-30364-1-git-send-email-quic_prashk@quicinc.com> References: <1677156121-30364-1-git-send-email-quic_prashk@quicinc.com> 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-ORIG-GUID: 1qbod9bMAE7bwKrgG1x2DiKu9T7C9c7d X-Proofpoint-GUID: 1qbod9bMAE7bwKrgG1x2DiKu9T7C9c7d X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-23_06,2023-02-23_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 phishscore=0 spamscore=0 mlxlogscore=634 bulkscore=0 adultscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302230103 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Currently we process the suspend interrupt event only if the device is in configured state. Consider a case where device is not configured and got suspend interrupt, in that case our gadget will still use 100mA as composite_suspend didn't happen. But battery charging specification (BC1.2) expects a downstream device to draw less than 2.5mA when unconnected OR suspended. Fix this by removing the condition for processing suspend event, and thus composite_resume would set vbus draw to 2. Fixes: 72704f876f50 ("dwc3: gadget: Implement the suspend entry event handler") Signed-off-by: Prashanth K Acked-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 89dcfac..a83f34e 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -4241,15 +4241,8 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc, break; case DWC3_DEVICE_EVENT_SUSPEND: /* It changed to be suspend event for version 2.30a and above */ - if (!DWC3_VER_IS_PRIOR(DWC3, 230A)) { - /* - * Ignore suspend event until the gadget enters into - * USB_STATE_CONFIGURED state. - */ - if (dwc->gadget->state >= USB_STATE_CONFIGURED) - dwc3_gadget_suspend_interrupt(dwc, - event->event_info); - } + if (!DWC3_VER_IS_PRIOR(DWC3, 230A)) + dwc3_gadget_suspend_interrupt(dwc, event->event_info); break; case DWC3_DEVICE_EVENT_SOF: case DWC3_DEVICE_EVENT_ERRATIC_ERROR: From patchwork Thu Feb 23 12:42:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashanth K X-Patchwork-Id: 13150232 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 54454C61DA4 for ; Thu, 23 Feb 2023 12:42:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234067AbjBWMm2 (ORCPT ); Thu, 23 Feb 2023 07:42:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234073AbjBWMm0 (ORCPT ); Thu, 23 Feb 2023 07:42:26 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8876954A3E; Thu, 23 Feb 2023 04:42:22 -0800 (PST) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31NCO52u019294; Thu, 23 Feb 2023 12:42:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=MM0qQty+voAnaENBBVdRbuianxgy+a6YzP501pjWE/8=; b=Fsvtn6blOcOlLdJwdm0eECdRKGcn6pKPvTWxxQepjdEqqayFU9u8jQuL23M0aATavvPA DuWLmvJEkhux1H2ZR7mgDfWnL6zPILSffIKFG0gKpLA9Mu2EMlcKnBsDujP7hqy3D+L9 HEOOZGUkjy/3KlmrbIZd5x1sytF9L+cVKON7XCp2tGSggH1NPSfh8jGSckq1LtolwPQm ABJqueTtnlGkJoFMLGsqjw/erJ1qVU9VeQYeMUhXFChGWbIIqSU8o60WUdUUVXjWmgv5 3OFeKjMcYf0C6Pp9TcBWfRUQAaeYzgKlyAWYQ61wiAyf5X7BbXLFa/evXu2ZXuyvM/Bk vQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3nwy9gha7q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Feb 2023 12:42:18 +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 31NCgHuT016399 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Feb 2023 12:42:17 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.41; Thu, 23 Feb 2023 04:42:13 -0800 From: Prashanth K To: Greg Kroah-Hartman , Thinh Nguyen , Jakob Koschel , =?utf-8?b?SsOzIMOBZ2lsYSBCaXRzY2g=?= , Alan Stern CC: Pratham Pratap , Jack Pham , , , Prashanth K Subject: [PATCH v3 2/2] usb: gadget: composite: Draw 100mA current if not configured Date: Thu, 23 Feb 2023 18:12:01 +0530 Message-ID: <1677156121-30364-3-git-send-email-quic_prashk@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1677156121-30364-1-git-send-email-quic_prashk@quicinc.com> References: <1677156121-30364-1-git-send-email-quic_prashk@quicinc.com> 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: arqHJS_I9qyKZNVlz-FYHgcn3QxI3bSO X-Proofpoint-ORIG-GUID: arqHJS_I9qyKZNVlz-FYHgcn3QxI3bSO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-23_07,2023-02-23_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=646 spamscore=0 malwarescore=0 adultscore=0 impostorscore=0 mlxscore=0 suspectscore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302230103 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Currently we don't change the current value if device isn't in configured state. But the battery charging specification says, device can draw up to 100mA of current if its in unconfigured state. Hence add a Vbus_draw work in composite_resume to draw 100mA if the device isn't configured. Signed-off-by: Prashanth K --- drivers/usb/gadget/composite.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 403563c..386140f 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -2449,6 +2449,10 @@ void composite_resume(struct usb_gadget *gadget) usb_gadget_clear_selfpowered(gadget); usb_gadget_vbus_draw(gadget, maxpower); + } else { + maxpower = CONFIG_USB_GADGET_VBUS_DRAW; + maxpower = min(maxpower, 100U); + usb_gadget_vbus_draw(gadget, maxpower); } cdev->suspended = 0;