Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2113181pxb; Fri, 5 Mar 2021 07:34:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3DgqWle7XNiIKyRn6w+mFRfQZ9ScftpTgFwxs0jr/wmNBqNJmqaBCxICaxRKxlPZZWZy8 X-Received: by 2002:a17:906:1d55:: with SMTP id o21mr2686450ejh.485.1614958491949; Fri, 05 Mar 2021 07:34:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614958491; cv=none; d=google.com; s=arc-20160816; b=T9ZaGWFT92k5H0sC2ypL0SAE6Mm00tJ5f/+UUg3JsKlvmzIF3TUDrsMEmTAEW/Wo7x O7cp/kXhht0imR4S3ssJfMMDKC48PFdQe7H8Lh7TMe8XKh3BQhZsij5BEnIRhF3bBSER GxvltkSopXuaamzpSVpBKR/lnFVV4J3LyUrRUcQkJ7N8r2AID0BwnAsrbsGLpP9Wvgqo C3aUs/F/TlBe32KiUNEpyuNiKqeznWYFZ8mHcjaiJu1+SCi7UD+6tgCSIoC5jh8V1Bwl yYi3q1y0VgBHayZVZ0knY8kPsnzU8/y+Tub00NWmUZ1ZB9cJojcrPBkp217EAT8LXNFt Ts5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=x9euBzS4cARYzKzAmXUFSgvTNLh0GiuSaCy6CcMts5I=; b=C4iKDTLQwjhtOmrPdXbV950fkoSdkUd/SudHlRXSN7sWJhQP7DHKlafwAX4NlD14by l9v1s09M9Bd1gw/FYf6PdYP4k5pIMaeNIeFzPf0fAk/N3a4WdE1I4evWqtj+2AVIgXKm lnFTJ6VzjU+EF0rgQE4u0xobgjD2FxfRqGTS+86Coc3frVQJ5JYLTHTTFf179kfAcYZx fFJYZhN/tbktSCOhVktkzKw5Q0FntVCibUXho/vXKoBPwbLuonT2/KEMI9yuzykdnJkt P/voWPkL5ewFKpgVJP1wDOHZR7w27MDetJ89496LbffpEHEtB8gdVAwqLGoOtC5aSkxj J57g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g15si1459655ejm.630.2021.03.05.07.34.28; Fri, 05 Mar 2021 07:34:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230093AbhCEPdd (ORCPT + 99 others); Fri, 5 Mar 2021 10:33:33 -0500 Received: from netrider.rowland.org ([192.131.102.5]:42317 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S230109AbhCEPdN (ORCPT ); Fri, 5 Mar 2021 10:33:13 -0500 Received: (qmail 39139 invoked by uid 1000); 5 Mar 2021 10:33:12 -0500 Date: Fri, 5 Mar 2021 10:33:12 -0500 From: Alan Stern To: Chunfeng Yun Cc: Mathias Nyman , Greg Kroah-Hartman , Ikjoon Jang , Matthias Brugger , linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Nicolas Boichat , Eddie Hung Subject: Re: [PATCH 16/17] usb: common: add function to get interval expressed in us unit Message-ID: <20210305153312.GA38200@rowland.harvard.edu> References: <1614934975-15188-1-git-send-email-chunfeng.yun@mediatek.com> <1614934975-15188-16-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1614934975-15188-16-git-send-email-chunfeng.yun@mediatek.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 05, 2021 at 05:02:54PM +0800, Chunfeng Yun wrote: > Add a new function to convert bInterval into the time expressed > in 1us unit. > > Signed-off-by: Chunfeng Yun > --- > --- a/drivers/usb/common/common.c > +++ b/drivers/usb/common/common.c > @@ -165,6 +165,39 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev) > } > EXPORT_SYMBOL_GPL(usb_get_dr_mode); > > +unsigned int usb_decode_interval(const struct usb_endpoint_descriptor *epd, > + enum usb_device_speed speed) > +{ > + unsigned int interval = 0; > + > + switch (usb_endpoint_type(epd)) { > + case USB_ENDPOINT_XFER_CONTROL: > + /* uframes per NAK */ > + if (speed == USB_SPEED_HIGH) > + interval = epd->bInterval; > + break; > + case USB_ENDPOINT_XFER_ISOC: > + interval = 1 << (epd->bInterval - 1); > + break; > + case USB_ENDPOINT_XFER_BULK: > + /* uframes per NAK */ > + if (speed == USB_SPEED_HIGH && usb_endpoint_dir_out(epd)) > + interval = epd->bInterval; > + break; > + case USB_ENDPOINT_XFER_INT: > + if (speed >= USB_SPEED_HIGH) > + interval = 1 << (epd->bInterval - 1); > + else > + interval = epd->bInterval; > + break; > + } > + > + interval *= (speed >= USB_SPEED_HIGH) ? 125 : 1000; > + > + return interval; > +} > +EXPORT_SYMBOL_GPL(usb_decode_interval); > --- a/include/linux/usb/ch9.h > +++ b/include/linux/usb/ch9.h > @@ -90,6 +90,17 @@ extern enum usb_ssp_rate usb_get_maximum_ssp_rate(struct device *dev); > */ > extern const char *usb_state_string(enum usb_device_state state); > > +/** > + * usb_decode_interval - Decode bInterval into the time expressed in 1us unit > + * @epd: The descriptor of the endpoint > + * @speed: The speed that the endpoint works as > + * > + * Function returns the interval expressed in 1us unit for servicing > + * endpoint for data transfers. > + */ > +unsigned int usb_decode_interval(const struct usb_endpoint_descriptor *epd, > + enum usb_device_speed speed); As a general rule, I believe people expect to find the kerneldoc for a function next to the function's definition, not next to the declaration in a header file. Alan Stern