提交 bcb2f99c 编写于 作者: S Sebastian Andrzej Siewior 提交者: Felipe Balbi

usb: gadget: use a computation macro for INT endpoint interval

The 5+4 magic for HS tries to aim 32ms which is also what is intended
with 1 << 5 for FS. This little macro should make this easier to
understand.
Signed-off-by: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: NFelipe Balbi <balbi@ti.com>
上级 fad8deb2
...@@ -87,7 +87,7 @@ static inline struct f_acm *port_to_acm(struct gserial *p) ...@@ -87,7 +87,7 @@ static inline struct f_acm *port_to_acm(struct gserial *p)
/* notification endpoint uses smallish and infrequent fixed-size messages */ /* notification endpoint uses smallish and infrequent fixed-size messages */
#define GS_LOG2_NOTIFY_INTERVAL 5 /* 1 << 5 == 32 msec */ #define GS_NOTIFY_INTERVAL_MS 32
#define GS_NOTIFY_MAXPACKET 10 /* notification + 2 bytes */ #define GS_NOTIFY_MAXPACKET 10 /* notification + 2 bytes */
/* interface and class descriptors: */ /* interface and class descriptors: */
...@@ -167,7 +167,7 @@ static struct usb_endpoint_descriptor acm_fs_notify_desc = { ...@@ -167,7 +167,7 @@ static struct usb_endpoint_descriptor acm_fs_notify_desc = {
.bEndpointAddress = USB_DIR_IN, .bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT, .bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(GS_NOTIFY_MAXPACKET), .wMaxPacketSize = cpu_to_le16(GS_NOTIFY_MAXPACKET),
.bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL, .bInterval = GS_NOTIFY_INTERVAL_MS,
}; };
static struct usb_endpoint_descriptor acm_fs_in_desc = { static struct usb_endpoint_descriptor acm_fs_in_desc = {
...@@ -199,14 +199,13 @@ static struct usb_descriptor_header *acm_fs_function[] = { ...@@ -199,14 +199,13 @@ static struct usb_descriptor_header *acm_fs_function[] = {
}; };
/* high speed support: */ /* high speed support: */
static struct usb_endpoint_descriptor acm_hs_notify_desc = { static struct usb_endpoint_descriptor acm_hs_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE, .bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT, .bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN, .bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT, .bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(GS_NOTIFY_MAXPACKET), .wMaxPacketSize = cpu_to_le16(GS_NOTIFY_MAXPACKET),
.bInterval = GS_LOG2_NOTIFY_INTERVAL+4, .bInterval = USB_MS_TO_HS_INTERVAL(GS_NOTIFY_INTERVAL_MS),
}; };
static struct usb_endpoint_descriptor acm_hs_in_desc = { static struct usb_endpoint_descriptor acm_hs_in_desc = {
......
...@@ -91,7 +91,7 @@ static inline unsigned ecm_bitrate(struct usb_gadget *g) ...@@ -91,7 +91,7 @@ static inline unsigned ecm_bitrate(struct usb_gadget *g)
* encapsulated commands (vendor-specific, using control-OUT). * encapsulated commands (vendor-specific, using control-OUT).
*/ */
#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */ #define ECM_STATUS_INTERVAL_MS 32
#define ECM_STATUS_BYTECOUNT 16 /* 8 byte header + data */ #define ECM_STATUS_BYTECOUNT 16 /* 8 byte header + data */
...@@ -192,7 +192,7 @@ static struct usb_endpoint_descriptor fs_ecm_notify_desc = { ...@@ -192,7 +192,7 @@ static struct usb_endpoint_descriptor fs_ecm_notify_desc = {
.bEndpointAddress = USB_DIR_IN, .bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT, .bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT), .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
.bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, .bInterval = ECM_STATUS_INTERVAL_MS,
}; };
static struct usb_endpoint_descriptor fs_ecm_in_desc = { static struct usb_endpoint_descriptor fs_ecm_in_desc = {
...@@ -239,7 +239,7 @@ static struct usb_endpoint_descriptor hs_ecm_notify_desc = { ...@@ -239,7 +239,7 @@ static struct usb_endpoint_descriptor hs_ecm_notify_desc = {
.bEndpointAddress = USB_DIR_IN, .bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT, .bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT), .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, .bInterval = USB_MS_TO_HS_INTERVAL(ECM_STATUS_INTERVAL_MS),
}; };
static struct usb_endpoint_descriptor hs_ecm_in_desc = { static struct usb_endpoint_descriptor hs_ecm_in_desc = {
...@@ -288,7 +288,7 @@ static struct usb_endpoint_descriptor ss_ecm_notify_desc = { ...@@ -288,7 +288,7 @@ static struct usb_endpoint_descriptor ss_ecm_notify_desc = {
.bEndpointAddress = USB_DIR_IN, .bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT, .bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT), .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, .bInterval = USB_MS_TO_HS_INTERVAL(ECM_STATUS_INTERVAL_MS),
}; };
static struct usb_ss_ep_comp_descriptor ss_ecm_intr_comp_desc = { static struct usb_ss_ep_comp_descriptor ss_ecm_intr_comp_desc = {
......
...@@ -121,7 +121,7 @@ static struct usb_cdc_ncm_ntb_parameters ntb_parameters = { ...@@ -121,7 +121,7 @@ static struct usb_cdc_ncm_ntb_parameters ntb_parameters = {
* waste less bandwidth. * waste less bandwidth.
*/ */
#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */ #define NCM_STATUS_INTERVAL_MS 32
#define NCM_STATUS_BYTECOUNT 16 /* 8 byte header + data */ #define NCM_STATUS_BYTECOUNT 16 /* 8 byte header + data */
static struct usb_interface_assoc_descriptor ncm_iad_desc __initdata = { static struct usb_interface_assoc_descriptor ncm_iad_desc __initdata = {
...@@ -230,7 +230,7 @@ static struct usb_endpoint_descriptor fs_ncm_notify_desc __initdata = { ...@@ -230,7 +230,7 @@ static struct usb_endpoint_descriptor fs_ncm_notify_desc __initdata = {
.bEndpointAddress = USB_DIR_IN, .bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT, .bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(NCM_STATUS_BYTECOUNT), .wMaxPacketSize = cpu_to_le16(NCM_STATUS_BYTECOUNT),
.bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, .bInterval = NCM_STATUS_INTERVAL_MS,
}; };
static struct usb_endpoint_descriptor fs_ncm_in_desc __initdata = { static struct usb_endpoint_descriptor fs_ncm_in_desc __initdata = {
...@@ -275,7 +275,7 @@ static struct usb_endpoint_descriptor hs_ncm_notify_desc __initdata = { ...@@ -275,7 +275,7 @@ static struct usb_endpoint_descriptor hs_ncm_notify_desc __initdata = {
.bEndpointAddress = USB_DIR_IN, .bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT, .bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(NCM_STATUS_BYTECOUNT), .wMaxPacketSize = cpu_to_le16(NCM_STATUS_BYTECOUNT),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, .bInterval = USB_MS_TO_HS_INTERVAL(NCM_STATUS_INTERVAL_MS),
}; };
static struct usb_endpoint_descriptor hs_ncm_in_desc __initdata = { static struct usb_endpoint_descriptor hs_ncm_in_desc __initdata = {
.bLength = USB_DT_ENDPOINT_SIZE, .bLength = USB_DT_ENDPOINT_SIZE,
......
...@@ -101,7 +101,7 @@ static unsigned int bitrate(struct usb_gadget *g) ...@@ -101,7 +101,7 @@ static unsigned int bitrate(struct usb_gadget *g)
/* /*
*/ */
#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */ #define RNDIS_STATUS_INTERVAL_MS 32
#define STATUS_BYTECOUNT 8 /* 8 bytes data */ #define STATUS_BYTECOUNT 8 /* 8 bytes data */
...@@ -190,7 +190,7 @@ static struct usb_endpoint_descriptor fs_notify_desc = { ...@@ -190,7 +190,7 @@ static struct usb_endpoint_descriptor fs_notify_desc = {
.bEndpointAddress = USB_DIR_IN, .bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT, .bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
.bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, .bInterval = RNDIS_STATUS_INTERVAL_MS,
}; };
static struct usb_endpoint_descriptor fs_in_desc = { static struct usb_endpoint_descriptor fs_in_desc = {
...@@ -236,7 +236,7 @@ static struct usb_endpoint_descriptor hs_notify_desc = { ...@@ -236,7 +236,7 @@ static struct usb_endpoint_descriptor hs_notify_desc = {
.bEndpointAddress = USB_DIR_IN, .bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT, .bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, .bInterval = USB_MS_TO_HS_INTERVAL(RNDIS_STATUS_INTERVAL_MS)
}; };
static struct usb_endpoint_descriptor hs_in_desc = { static struct usb_endpoint_descriptor hs_in_desc = {
...@@ -284,7 +284,7 @@ static struct usb_endpoint_descriptor ss_notify_desc = { ...@@ -284,7 +284,7 @@ static struct usb_endpoint_descriptor ss_notify_desc = {
.bEndpointAddress = USB_DIR_IN, .bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT, .bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, .bInterval = USB_MS_TO_HS_INTERVAL(RNDIS_STATUS_INTERVAL_MS)
}; };
static struct usb_ss_ep_comp_descriptor ss_intr_comp_desc = { static struct usb_ss_ep_comp_descriptor ss_intr_comp_desc = {
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <linux/version.h> #include <linux/version.h>
#include <linux/usb/ch9.h> #include <linux/usb/ch9.h>
#include <linux/usb/gadget.h> #include <linux/usb/gadget.h>
#include <linux/log2.h>
/* /*
* USB function drivers should return USB_GADGET_DELAYED_STATUS if they * USB function drivers should return USB_GADGET_DELAYED_STATUS if they
...@@ -51,6 +52,7 @@ ...@@ -51,6 +52,7 @@
/* big enough to hold our biggest descriptor */ /* big enough to hold our biggest descriptor */
#define USB_COMP_EP0_BUFSIZ 1024 #define USB_COMP_EP0_BUFSIZ 1024
#define USB_MS_TO_HS_INTERVAL(x) (ilog2((x * 1000 / 125)) + 1)
struct usb_configuration; struct usb_configuration;
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册