From patchwork Tue Oct 31 13:47:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 117632 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3938811qgn; Tue, 31 Oct 2017 06:47:52 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Rp+ozb59Ro9RPhhF1zdBP4NnlvdlRV5t8wiFTaOZVLbL2Tdd67/oG3uL1ppeNHHtdxhEe9 X-Received: by 10.84.132.76 with SMTP id 70mr1963896ple.135.1509457672337; Tue, 31 Oct 2017 06:47:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509457672; cv=none; d=google.com; s=arc-20160816; b=SoB43ciGKyv7mbJcXKJFUWrUldmGRZO/2zB8TuIMQmBKDDYGNqNq1vbxMH4ikB1hlk Nqgs5ZmnMU6Ur0t/2MX5IK/9kSBojj5w7v45EvQh2t2e4ytHRsuwUP7ZyiIva6OidId/ DTMCQO84jOiJsyBW857Yd+zTfmH5/D344gd0RzcYJVuju8aOBmgWdMQQXKJk5tmRe5Z/ 5gqRh3q7GQH1SKKi6Y39SW1m8iqSMuHhqFHTvGvHu40DdcxZzfV959jdRAiR0LhojLxr 1P+NddGqUC6Wn5oZhrarTKzUafCCa6qd0XvmBHSiZ3GE+HkX6CwL2U3jGjjhu8dWZlNy NV1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=q8TSfkrjh/LeK6dfbWIyrvPFbqQEVt9x0KaYtArxyjA=; b=x73Q0nFv//MZ/F3D01/bTu2lpb35SiXffqdfqMA7eAQaBDsC8D2WTOM1uBjcaAi8EE osstj5sPXKpcZzGn5Ls4uNr1sToMOPf3hdHfHtnLhPEXUq1XKverzKsUmzkeSFEaXGxs UHPnuvjznLFEFhD3JHuz85C5HbXAOKIEs7fPINlfuCLdR6goVqO19tIXaitbWMYvMUaW 7NsWFjPE+vQNk/TTxs6/9oySkcwb5co8fd/jeXklaq+RMCD2y3TjadXlkBOGLd2ea0yC sN/51mXkpypSpErgvzHZ+qE/Gyj90kYFgGp8kXI5MQ9B6K+rGw8HO96BX8LE2xYlgapG y2Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=jVMupkKe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o9si1673109pls.437.2017.10.31.06.47.51; Tue, 31 Oct 2017 06:47:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=jVMupkKe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753292AbdJaNrt (ORCPT + 27 others); Tue, 31 Oct 2017 09:47:49 -0400 Received: from fllnx209.ext.ti.com ([198.47.19.16]:59345 "EHLO fllnx209.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751926AbdJaNrs (ORCPT ); Tue, 31 Oct 2017 09:47:48 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id v9VDlFRj008382; Tue, 31 Oct 2017 08:47:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1509457635; bh=e0PRAb8pLUtnbirXNsmIxeiaKQ23wAPMaHSeqsZ7qO0=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=jVMupkKeNiZOJltwjZi6ORo4Txv5xXUItxOmwvJ1jpBmWxbpCpCROy8Q1cKz3w0G1 8dc4SWL7F28bDMQLPpwXee0d1DnACIWzfDuQShHFidAQ/dERwBQVaOPEqEl0+cJYV8 lIwJwRX+iJh8cHLTeu98dNJ6bseQJUSrD3elWDC8= Received: from DFLE106.ent.ti.com (dfle106.ent.ti.com [10.64.6.27]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v9VDlAvQ009733; Tue, 31 Oct 2017 08:47:10 -0500 Received: from DFLE106.ent.ti.com (10.64.6.27) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.845.34; Tue, 31 Oct 2017 08:47:10 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.845.34 via Frontend Transport; Tue, 31 Oct 2017 08:47:10 -0500 Received: from dlelxv97.itg.ti.com (dlelxv97.itg.ti.com [172.17.2.193]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id v9VDlAak015665; Tue, 31 Oct 2017 08:47:10 -0500 Received: from [192.168.2.6] (vboxa0400828d.emea.dhcp.ti.com [172.22.234.209]) by dlelxv97.itg.ti.com (8.14.3/8.13.8) with ESMTP id v9VDl8lW017704; Tue, 31 Oct 2017 08:47:08 -0500 Subject: [PATCH v2] usb: dwc3: gadget: Fix .udc_set_speed() To: CC: , , , "# v4 . 13+" , References: <1509454904-4966-1-git-send-email-rogerq@ti.com> From: Roger Quadros Message-ID: <3773d6f2-113b-862e-3365-d47efa3a77ed@ti.com> Date: Tue, 31 Oct 2017 15:47:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <1509454904-4966-1-git-send-email-rogerq@ti.com> Content-Language: en-GB X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently UDC core calls ->udc_set_speed() with the speed parameter containing the maximum speed supported by the gadget function driver. This might very well be more than that supported by the UDC controller driver. Select the lesser of the 2 speeds so both UDC and gadget function driver are operating within limits. This fixes PHY Erratic errors and 2 second enumeration delay on TI's AM437x platforms. Fixes: 6099eca796ae ("usb: gadget: core: introduce ->udc_set_speed() method") Cc: # v4.13+ Reported-by: Dylan Howey Signed-off-by: Roger Quadros --- v2: - Move speed limiting code to UDC core. drivers/usb/gadget/udc/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- cheers, -roger Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index d41d07a..def1b05 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -1080,8 +1080,12 @@ static inline void usb_gadget_udc_stop(struct usb_udc *udc) static inline void usb_gadget_udc_set_speed(struct usb_udc *udc, enum usb_device_speed speed) { - if (udc->gadget->ops->udc_set_speed) - udc->gadget->ops->udc_set_speed(udc->gadget, speed); + if (udc->gadget->ops->udc_set_speed) { + enum usb_device_speed s; + + s = min(speed, udc->gadget->max_speed); + udc->gadget->ops->udc_set_speed(udc->gadget, s); + } } /**