From patchwork Tue Oct 31 13:56:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 117633 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3947935qgn; Tue, 31 Oct 2017 06:56:38 -0700 (PDT) X-Google-Smtp-Source: ABhQp+S6SbU2K/as7e1p7iEfKZ+uknn9sVBPAXqnHn/FCDm3V/HeQ5hsHTrg/HJXV6d4mQokHcVq X-Received: by 10.98.34.79 with SMTP id i76mr2192691pfi.42.1509458198397; Tue, 31 Oct 2017 06:56:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509458198; cv=none; d=google.com; s=arc-20160816; b=cX7BAkg4iULRGxPi8nCTjJarApnKysDD4xF2zTYz6qNcM+06jt3e+l5rnsuMpSP6Ae 7JIz/ZRgu7fgkpy/pRCcRlc2pSRDSAZGssOHqbg+Q7CDcXHCA896vO5KyZZRyFl99Wf5 ThSrccovSve9Fch4tCjY+xyHqtuKayZL6BPyfRZzVL9MCBPVocaA5sn7aHaAsLoNkUbB jXBoyieQESMv1fn+HIERN/j8f2nXfp0d2K+dkaf0GhGYRocQS0xT26eMPju9H7N4uVZG uV9/AigWKaHOBOk2yil1iyJjndH8VrHrUcZ19YwnhcvPFrVASZ/Nhw5E6ktK6NgWpLbU 9EzA== 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=FOkdNAXJ82tQHylisVvoVj5mpWNUBM5x4fJrEpWsAplNmFfxbQbBBti9HEZbIC53uG 33U0PmcomyQED+NUco0Rvj7SXBLvTcN1QFtb6Edl7Sou7hGmpx8McESiTybGuZ0cQAiU oAQehspyaSV2NmJVL9MZP7EXi5z9whXSLFKoEkLIhVAkSdn3gJl+Idw0blLsKsz4Oy8H Fd89NywNTD+N0vupSeUZCcg4I6csmXGQR3hN1MRY9AI9AyxlRLGZjYawGyC+UHRE+2zN gp5pV7OcuywK8uVJOMFMkEjUb819yX5BweVaoWwo5doSNe7M6zjS0oK7xGwHKTdzDjYf Rarw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=FBxHSwMm; 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 m6si1739619pff.584.2017.10.31.06.56.38; Tue, 31 Oct 2017 06:56:38 -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=FBxHSwMm; 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 S1753473AbdJaN4g (ORCPT + 27 others); Tue, 31 Oct 2017 09:56:36 -0400 Received: from lelnx193.ext.ti.com ([198.47.27.77]:49838 "EHLO lelnx193.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751172AbdJaN4e (ORCPT ); Tue, 31 Oct 2017 09:56:34 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx193.ext.ti.com (8.15.1/8.15.1) with ESMTP id v9VDuV20020329; Tue, 31 Oct 2017 08:56:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1509458191; bh=e0PRAb8pLUtnbirXNsmIxeiaKQ23wAPMaHSeqsZ7qO0=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=FBxHSwMmD5VQZUESXmCb47e93PX97fZ1Sei5zX1zjTkDw+4zIMCNLnfJ1qUxJu/8y jaYph5wLpCg3jsfK8lp2HhNDRqAmAJuWIm3sTlqvxCiacQUUf4YL6kNX0qVWxXZ3b0 iMQaBpTzI3mWJeWGb34sGIJgvcaC6xt7WPzVslk8= Received: from DLEE101.ent.ti.com (dlee101.ent.ti.com [157.170.170.31]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v9VDuVcW022797; Tue, 31 Oct 2017 08:56:31 -0500 Received: from DLEE114.ent.ti.com (157.170.170.25) by DLEE101.ent.ti.com (157.170.170.31) 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:56:31 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE114.ent.ti.com (157.170.170.25) 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:56:31 -0500 Received: from dlelxv97.itg.ti.com (dlelxv97.itg.ti.com [172.17.2.193]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v9VDuVHl019703; Tue, 31 Oct 2017 08:56:31 -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 v9VDuTgh018261; Tue, 31 Oct 2017 08:56:30 -0500 Subject: [PATCH v2][RESEND] usb: gadget: core: Fix ->udc_set_speed() speed handling To: CC: , , , "# v4 . 13+" , References: <1509454904-4966-1-git-send-email-rogerq@ti.com> From: Roger Quadros Message-ID: Date: Tue, 31 Oct 2017 15:56:29 +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); + } } /**