From a15cb334ee1e810f417f1ae5390e4404475e41c8 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Mon, 2 May 2016 13:26:15 -0700 Subject: [PATCH 1/2] usb: gadget: f_accessory: Make RX buffer size aligned to EP's MTU Synopsys USB3 Controller (DWC3) has a restriction where size of OUT requests (TRB) queued to the controller must be aligned with the endpoint's max packet size. Generally, accessory userspace module submits RX requests not aligned to endpoint's max packet size. Hence to overcome this, align the size of RX request buffer to endpoint's max packet while submitting to DCD as the buffers are already allocated with the size of 16KB. Change-Id: I3acdfc055d0c6a79a0aa65a715bae06dc475d078 Signed-off-by: Vijayavardhan Vennapusa Signed-off-by: Hemant Kumar --- drivers/usb/gadget/function/f_accessory.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/function/f_accessory.c b/drivers/usb/gadget/function/f_accessory.c index 908cfb33bf99..381443cc06f1 100644 --- a/drivers/usb/gadget/function/f_accessory.c +++ b/drivers/usb/gadget/function/f_accessory.c @@ -609,8 +609,7 @@ static ssize_t acc_read(struct file *fp, char __user *buf, { struct acc_dev *dev = fp->private_data; struct usb_request *req; - ssize_t r = count; - unsigned xfer; + ssize_t r = count, xfer, len; int ret = 0; pr_debug("acc_read(%zu)\n", count); @@ -623,6 +622,8 @@ static ssize_t acc_read(struct file *fp, char __user *buf, if (count > BULK_BUFFER_SIZE) count = BULK_BUFFER_SIZE; + len = ALIGN(count, dev->ep_out->maxpacket); + /* we will block until we're online */ pr_debug("acc_read: waiting for online\n"); ret = wait_event_interruptible(dev->read_wq, dev->online); @@ -640,7 +641,7 @@ static ssize_t acc_read(struct file *fp, char __user *buf, requeue_req: /* queue a request */ req = dev->rx_req[0]; - req->length = count; + req->length = len; dev->rx_done = 0; ret = usb_ep_queue(dev->ep_out, req, GFP_KERNEL); if (ret < 0) { From 239e2be709b74d2bbcdbb8c37c9d1842837ef391 Mon Sep 17 00:00:00 2001 From: Vijayavardhan Vennapusa Date: Mon, 28 Sep 2015 13:10:19 +0530 Subject: [PATCH 2/2] USB: f_accessory: set manufacturer and model string to default value Currently USB driver is resetting strings like manufacturer, model to zero as part of handling control request for protocol version. Some accessory docks may not send manufacturer and model strings before sending control request to enable audiosource USB composition. This results in userspace enabling audio source composition without accessory interface. If accessory dock is connected during bootup, accessory timeouts in configuring android device and results in detection failure. Userspace does have recovery mechanism if incase accessory dock timeouts to configure android device in accessory composition. Hence set manufacturer and model strings to default value so that userspace enables accessory + audiosource composition for userspace recovery to be working and detecting accessory dock successfully during bootup. Change-Id: Ibe4dd9d951a9615ae100e68dc15b3614e9834848 Signed-off-by: Vijayavardhan Vennapusa --- drivers/usb/gadget/function/f_accessory.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/gadget/function/f_accessory.c b/drivers/usb/gadget/function/f_accessory.c index 381443cc06f1..028bde7b0241 100644 --- a/drivers/usb/gadget/function/f_accessory.c +++ b/drivers/usb/gadget/function/f_accessory.c @@ -937,6 +937,8 @@ int acc_ctrlrequest(struct usb_composite_dev *cdev, memset(dev->serial, 0, sizeof(dev->serial)); dev->start_requested = 0; dev->audio_mode = 0; + strlcpy(dev->manufacturer, "Android", ACC_STRING_SIZE); + strlcpy(dev->model, "Android", ACC_STRING_SIZE); } }