From patchwork Mon Aug 19 06:10:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sherry Sun X-Patchwork-Id: 1149037 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="XrIvhO0F"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46Bk9Z3NHGz9sMr for ; Mon, 19 Aug 2019 16:12:34 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 2D87BC21E1D; Mon, 19 Aug 2019 06:11:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1EC62C21E6A; Mon, 19 Aug 2019 06:11:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 85416C21D9A; Mon, 19 Aug 2019 06:10:54 +0000 (UTC) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60076.outbound.protection.outlook.com [40.107.6.76]) by lists.denx.de (Postfix) with ESMTPS id 7F34AC21DA1 for ; Mon, 19 Aug 2019 06:10:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CXkuelk8ptp9rIZEz2TVl/2tH1zznilkU1XG2AOvBP1z7XbKD1pAJIPSVeZ+Imz9XxItr/zM585ysdrrkSkwZ0A/3HMCj0jmO5QDpdHxUKZ/e4B3/fCduXY14eQsQjBoioYpuBpQjvRnUd5VAJGc0oyXdBhjpVImsd1aK0JDFlNhn6u5rRv2EdeO7K9fHFbYy6M59dqXVzqGLr0eilJ6cu4a33oiz9yRIWa0NKu29Ia2Al2SDfulu4l0vDT/AP0QTQZwUNsAs6xzg0IxNkVAMdeREiZeJMx2uE9SsjDumx/mt/QbcPVzAX+GWI9jXRklJZnYMNS7J3HG7FFRBbeJ9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rxMxXD++LXhPoVPHWQWv7CaFzXJ8OVzkCiIKxiqzRoU=; b=HqdNcUCZT9euCWqjr6kjxh73m52lTxXPdAyeQ/za6NjYvEu5/BYTF+JrQHBeAXIqyb1sAGOg3Nwv0aN2BI5Ksre6U6+f7E2J5VSnyalna0Zn4Hr/za/OiqKC38kxiF9dONpvhR5tl9MhUs+OBRN/DfqzGmx3h1G9q+Hstfi4Dxa6ayMhVp9D6JAAd8p7V2e81I4aPlGrSiPL04lxZV0z/zhV4d6t6stYNTh+O/AtmWU/AV95cGctEnpJ4nlofFZuO1RDSDp72Y3ggN3P3w5tX1zUj8iY8YEOvAYj+f7SmgUFWGl3oQ5FSvG0dYlsodlgZ3hDIcg2XOyo8ZTDPCwdug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rxMxXD++LXhPoVPHWQWv7CaFzXJ8OVzkCiIKxiqzRoU=; b=XrIvhO0FF2AZkjHPfMA+kyTNGSLgIUugXjIMdvN0mvobaOvN6oerGf6I8rdyP2Y/7+WHChpwO+m5z12OhKfm8643+0uDAS6sjv8kazHT01STmnYStYPBdaLPnvJiC+AC/Nz/JKvRhqM9pJ+b4tdqSnmjFs3eE3iZ69BGR6vdQYQ= Received: from AM0PR04MB6436.eurprd04.prod.outlook.com (20.179.252.146) by AM0PR04MB6036.eurprd04.prod.outlook.com (20.179.35.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.18; Mon, 19 Aug 2019 06:10:53 +0000 Received: from AM0PR04MB6436.eurprd04.prod.outlook.com ([fe80::5d9d:1811:f920:3ec2]) by AM0PR04MB6436.eurprd04.prod.outlook.com ([fe80::5d9d:1811:f920:3ec2%5]) with mapi id 15.20.2178.018; Mon, 19 Aug 2019 06:10:53 +0000 From: Sherry Sun To: "marex@denx.de" , "lukma@denx.de" , "bmeng.cn@gmail.com" Thread-Topic: [PATCH v4 4/4] USB: gadget: core: introduce ->udc_set_speed() method Thread-Index: AQHVVlTbz+aGBkVWz0uktI87W6Xw5g== Date: Mon, 19 Aug 2019 06:10:53 +0000 Message-ID: <20190819180909.16638-5-sherry.sun@nxp.com> References: <20190819180909.16638-1-sherry.sun@nxp.com> In-Reply-To: <20190819180909.16638-1-sherry.sun@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SG2PR06CA0181.apcprd06.prod.outlook.com (2603:1096:4:1::13) To AM0PR04MB6436.eurprd04.prod.outlook.com (2603:10a6:208:16b::18) x-mailer: git-send-email 2.17.1 authentication-results: spf=none (sender IP is ) smtp.mailfrom=sherry.sun@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.71] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2cc68bec-d057-46cb-5e33-08d7246bfda8 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:AM0PR04MB6036; x-ms-traffictypediagnostic: AM0PR04MB6036: x-ld-processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:170; x-forefront-prvs: 0134AD334F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(136003)(39860400002)(376002)(396003)(366004)(346002)(189003)(199004)(256004)(14444005)(53936002)(81156014)(7736002)(25786009)(5660300002)(81166006)(8676002)(86362001)(4326008)(305945005)(36756003)(1076003)(66066001)(316002)(110136005)(54906003)(66476007)(64756008)(66556008)(99286004)(66446008)(2616005)(476003)(486006)(11346002)(66946007)(44832011)(446003)(2906002)(52116002)(76176011)(6116002)(3846002)(6512007)(386003)(50226002)(14454004)(8936002)(6506007)(102836004)(186003)(2501003)(26005)(6436002)(6486002)(478600001)(2201001)(71200400001)(71190400001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR04MB6036; H:AM0PR04MB6436.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: Va41h7PK/2w3htpgnx54H/OnBI21AD3cvOO3+1ICKvs7E73ZVEZbsC/Dxyddi48HiRITqHRDdM622YmIpYC70LAMwY8v4zny5K5vpKxW/7W43B/9sZxHdUbXLzAV/pyQfAR4CEh1P+J64tIsrwZNYPxAYEx+RGge+o6FCK3svoH6I957iUZB2OE5KKuu4SaH8rEfjmHvfnJhCWEMDZbiKxje5h3tlwAzv9SWTrwl5lvN6nogu1YT8iwzK9cWraGTC9Pzp3o9oeztkqlEoeLiAYaj+cw8K1SKtmKziNisQ/eaHIjl7ITmRGH5DG6HjSoKJEwnNMun5vwczcxsShR8bdeWn+M+WPLRc06+xXAe0LsWmI1xzv5OdZCGnSWlXQwl+8NVmAmq7KtJ5Iq5T0Kph62+oLwjkEKkQ7gJk5ODGB4= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2cc68bec-d057-46cb-5e33-08d7246bfda8 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Aug 2019 06:10:53.4533 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: uLAaiGZNWAmW6VQHIgjd4M0F1RHg6icTyZjAqIS/S1ONqJV0NiLQ18b40RLQzkBqqdbP3Tb29gmmQg+JbpV8kA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6036 Cc: Marcel Ziswiler , "u-boot@lists.denx.de" , dl-uboot-imx Subject: [U-Boot] [PATCH v4 4/4] USB: gadget: core: introduce ->udc_set_speed() method X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This patch was copied from kernel commit: 67fdfda4a99ed. Sometimes, the gadget driver we want to run has max_speed lower than what the UDC supports. In such situations, UDC might want to make sure we don't try to connect on speeds not supported by the gadget driver because that will just fail. So here introduce a new optional ->udc_set_speed() method which can be implemented by interested UDC drivers to achieve this purpose. Signed-off-by: Sherry Sun --- drivers/usb/gadget/udc/udc-core.c | 23 +++++++++++++++++++++++ include/linux/usb/gadget.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index 62b47781dd..8d1d90e3e3 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -267,6 +267,27 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc); /* ------------------------------------------------------------------------- */ +/** + * usb_gadget_udc_set_speed - tells usb device controller speed supported by + * current driver + * @udc: The device we want to set maximum speed + * @speed: The maximum speed to allowed to run + * + * This call is issued by the UDC Class driver before calling + * usb_gadget_udc_start() in order to make sure that we don't try to + * connect on speeds the gadget driver doesn't support. + */ +static inline void usb_gadget_udc_set_speed(struct usb_udc *udc, + enum usb_device_speed 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); + } +} + static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver) { int ret; @@ -276,6 +297,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri udc->driver = driver; + usb_gadget_udc_set_speed(udc, driver->speed); + ret = driver->bind(udc->gadget); if (ret) goto err1; diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index a34f3478f3..78e245a1b5 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -450,6 +450,8 @@ struct usb_gadget_ops { int (*match_ep)(struct usb_gadget *gadget, struct usb_ep *ep, struct usb_endpoint_descriptor *desc); + void (*udc_set_speed)(struct usb_gadget *gadget, + enum usb_device_speed); }; /**