aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/Kconfig26
-rw-r--r--drivers/usb/gadget/Makefile1
-rw-r--r--drivers/usb/gadget/amd5536udc.c9
-rw-r--r--drivers/usb/gadget/at91_udc.c2
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c2077
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.h352
-rw-r--r--drivers/usb/gadget/config.c2
-rw-r--r--drivers/usb/gadget/dummy_hcd.c93
-rw-r--r--drivers/usb/gadget/epautoconf.c2
-rw-r--r--drivers/usb/gadget/ether.c155
-rw-r--r--drivers/usb/gadget/file_storage.c249
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.c13
-rw-r--r--drivers/usb/gadget/gmidi.c82
-rw-r--r--drivers/usb/gadget/goku_udc.c2
-rw-r--r--drivers/usb/gadget/inode.c46
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.h2
-rw-r--r--drivers/usb/gadget/m66592-udc.c2
-rw-r--r--drivers/usb/gadget/net2280.c2
-rw-r--r--drivers/usb/gadget/omap_udc.c12
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c2
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c2
-rw-r--r--drivers/usb/gadget/serial.c174
-rw-r--r--drivers/usb/gadget/usbstring.c2
-rw-r--r--drivers/usb/gadget/zero.c239
24 files changed, 2929 insertions, 619 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 767aed5b4bea..f81d08d6538b 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -67,6 +67,17 @@ config USB_GADGET_DEBUG_FILES
67 driver on a new board. Enable these files by choosing "Y" 67 driver on a new board. Enable these files by choosing "Y"
68 here. If in doubt, or to conserve kernel memory, say "N". 68 here. If in doubt, or to conserve kernel memory, say "N".
69 69
70config USB_GADGET_DEBUG_FS
71 boolean "Debugging information files in debugfs"
72 depends on USB_GADGET && DEBUG_FS
73 help
74 Some of the drivers in the "gadget" framework can expose
75 debugging information in files under /sys/kernel/debug/.
76 The information in these files may help when you're
77 troubleshooting or bringing up a driver on a new board.
78 Enable these files by choosing "Y" here. If in doubt, or
79 to conserve kernel memory, say "N".
80
70config USB_GADGET_SELECTED 81config USB_GADGET_SELECTED
71 boolean 82 boolean
72 83
@@ -103,6 +114,20 @@ config USB_AMD5536UDC
103 default USB_GADGET 114 default USB_GADGET
104 select USB_GADGET_SELECTED 115 select USB_GADGET_SELECTED
105 116
117config USB_GADGET_ATMEL_USBA
118 boolean "Atmel USBA"
119 select USB_GADGET_DUALSPEED
120 depends on AVR32
121 help
122 USBA is the integrated high-speed USB Device controller on
123 the AT32AP700x processors from Atmel.
124
125config USB_ATMEL_USBA
126 tristate
127 depends on USB_GADGET_ATMEL_USBA
128 default USB_GADGET
129 select USB_GADGET_SELECTED
130
106config USB_GADGET_FSL_USB2 131config USB_GADGET_FSL_USB2
107 boolean "Freescale Highspeed USB DR Peripheral Controller" 132 boolean "Freescale Highspeed USB DR Peripheral Controller"
108 depends on MPC834x || PPC_MPC831x 133 depends on MPC834x || PPC_MPC831x
@@ -228,7 +253,6 @@ config USB_LH7A40X
228 default USB_GADGET 253 default USB_GADGET
229 select USB_GADGET_SELECTED 254 select USB_GADGET_SELECTED
230 255
231
232config USB_GADGET_OMAP 256config USB_GADGET_OMAP
233 boolean "OMAP USB Device Controller" 257 boolean "OMAP USB Device Controller"
234 depends on ARCH_OMAP 258 depends on ARCH_OMAP
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 1bc0f03550ce..904e57bf6112 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_USB_OMAP) += omap_udc.o
14obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o 14obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o
15obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o 15obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o
16obj-$(CONFIG_USB_AT91) += at91_udc.o 16obj-$(CONFIG_USB_AT91) += at91_udc.o
17obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
17obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o 18obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
18obj-$(CONFIG_USB_M66592) += m66592-udc.o 19obj-$(CONFIG_USB_M66592) += m66592-udc.o
19 20
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index 714156ca8fe4..1c8040602525 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -69,7 +69,7 @@
69 69
70/* gadget stack */ 70/* gadget stack */
71#include <linux/usb/ch9.h> 71#include <linux/usb/ch9.h>
72#include <linux/usb_gadget.h> 72#include <linux/usb/gadget.h>
73 73
74/* udc specific */ 74/* udc specific */
75#include "amd5536udc.h" 75#include "amd5536udc.h"
@@ -3244,7 +3244,6 @@ static int udc_pci_probe(
3244 retval = -ENOMEM; 3244 retval = -ENOMEM;
3245 goto finished; 3245 goto finished;
3246 } 3246 }
3247 memset(dev, 0, sizeof(struct udc));
3248 3247
3249 /* pci setup */ 3248 /* pci setup */
3250 if (pci_enable_device(pdev) < 0) { 3249 if (pci_enable_device(pdev) < 0) {
@@ -3286,14 +3285,12 @@ static int udc_pci_probe(
3286 3285
3287 pci_set_drvdata(pdev, dev); 3286 pci_set_drvdata(pdev, dev);
3288 3287
3289 /* chip revision */ 3288 /* chip revision for Hs AMD5536 */
3290 dev->chiprev = 0; 3289 dev->chiprev = pdev->revision;
3291 3290
3292 pci_set_master(pdev); 3291 pci_set_master(pdev);
3293 pci_set_mwi(pdev); 3292 pci_set_mwi(pdev);
3294 3293
3295 /* chip rev for Hs AMD5536 */
3296 pci_read_config_byte(pdev, PCI_REVISION_ID, (u8 *) &dev->chiprev);
3297 /* init dma pools */ 3294 /* init dma pools */
3298 if (use_dma) { 3295 if (use_dma) {
3299 retval = init_dma_pools(dev); 3296 retval = init_dma_pools(dev);
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 63d7d6568699..a6adf7e0f6f8 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -38,7 +38,7 @@
38#include <linux/proc_fs.h> 38#include <linux/proc_fs.h>
39#include <linux/clk.h> 39#include <linux/clk.h>
40#include <linux/usb/ch9.h> 40#include <linux/usb/ch9.h>
41#include <linux/usb_gadget.h> 41#include <linux/usb/gadget.h>
42 42
43#include <asm/byteorder.h> 43#include <asm/byteorder.h>
44#include <asm/hardware.h> 44#include <asm/hardware.h>
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
new file mode 100644
index 000000000000..4fb5ff469574
--- /dev/null
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -0,0 +1,2077 @@
1/*
2 * Driver for the Atmel USBA high speed USB device controller
3 *
4 * Copyright (C) 2005-2007 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/clk.h>
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/interrupt.h>
14#include <linux/io.h>
15#include <linux/device.h>
16#include <linux/dma-mapping.h>
17#include <linux/list.h>
18#include <linux/platform_device.h>
19#include <linux/usb/ch9.h>
20#include <linux/usb/gadget.h>
21#include <linux/delay.h>
22
23#include <asm/gpio.h>
24#include <asm/arch/board.h>
25
26#include "atmel_usba_udc.h"
27
28
29static struct usba_udc the_udc;
30
31#ifdef CONFIG_USB_GADGET_DEBUG_FS
32#include <linux/debugfs.h>
33#include <linux/uaccess.h>
34
35static int queue_dbg_open(struct inode *inode, struct file *file)
36{
37 struct usba_ep *ep = inode->i_private;
38 struct usba_request *req, *req_copy;
39 struct list_head *queue_data;
40
41 queue_data = kmalloc(sizeof(*queue_data), GFP_KERNEL);
42 if (!queue_data)
43 return -ENOMEM;
44 INIT_LIST_HEAD(queue_data);
45
46 spin_lock_irq(&ep->udc->lock);
47 list_for_each_entry(req, &ep->queue, queue) {
48 req_copy = kmalloc(sizeof(*req_copy), GFP_ATOMIC);
49 if (!req_copy)
50 goto fail;
51 memcpy(req_copy, req, sizeof(*req_copy));
52 list_add_tail(&req_copy->queue, queue_data);
53 }
54 spin_unlock_irq(&ep->udc->lock);
55
56 file->private_data = queue_data;
57 return 0;
58
59fail:
60 spin_unlock_irq(&ep->udc->lock);
61 list_for_each_entry_safe(req, req_copy, queue_data, queue) {
62 list_del(&req->queue);
63 kfree(req);
64 }
65 kfree(queue_data);
66 return -ENOMEM;
67}
68
69/*
70 * bbbbbbbb llllllll IZS sssss nnnn FDL\n\0
71 *
72 * b: buffer address
73 * l: buffer length
74 * I/i: interrupt/no interrupt
75 * Z/z: zero/no zero
76 * S/s: short ok/short not ok
77 * s: status
78 * n: nr_packets
79 * F/f: submitted/not submitted to FIFO
80 * D/d: using/not using DMA
81 * L/l: last transaction/not last transaction
82 */
83static ssize_t queue_dbg_read(struct file *file, char __user *buf,
84 size_t nbytes, loff_t *ppos)
85{
86 struct list_head *queue = file->private_data;
87 struct usba_request *req, *tmp_req;
88 size_t len, remaining, actual = 0;
89 char tmpbuf[38];
90
91 if (!access_ok(VERIFY_WRITE, buf, nbytes))
92 return -EFAULT;
93
94 mutex_lock(&file->f_dentry->d_inode->i_mutex);
95 list_for_each_entry_safe(req, tmp_req, queue, queue) {
96 len = snprintf(tmpbuf, sizeof(tmpbuf),
97 "%8p %08x %c%c%c %5d %c%c%c\n",
98 req->req.buf, req->req.length,
99 req->req.no_interrupt ? 'i' : 'I',
100 req->req.zero ? 'Z' : 'z',
101 req->req.short_not_ok ? 's' : 'S',
102 req->req.status,
103 req->submitted ? 'F' : 'f',
104 req->using_dma ? 'D' : 'd',
105 req->last_transaction ? 'L' : 'l');
106 len = min(len, sizeof(tmpbuf));
107 if (len > nbytes)
108 break;
109
110 list_del(&req->queue);
111 kfree(req);
112
113 remaining = __copy_to_user(buf, tmpbuf, len);
114 actual += len - remaining;
115 if (remaining)
116 break;
117
118 nbytes -= len;
119 buf += len;
120 }
121 mutex_unlock(&file->f_dentry->d_inode->i_mutex);
122
123 return actual;
124}
125
126static int queue_dbg_release(struct inode *inode, struct file *file)
127{
128 struct list_head *queue_data = file->private_data;
129 struct usba_request *req, *tmp_req;
130
131 list_for_each_entry_safe(req, tmp_req, queue_data, queue) {
132 list_del(&req->queue);
133 kfree(req);
134 }
135 kfree(queue_data);
136 return 0;
137}
138
139static int regs_dbg_open(struct inode *inode, struct file *file)
140{
141 struct usba_udc *udc;
142 unsigned int i;
143 u32 *data;
144 int ret = -ENOMEM;
145
146 mutex_lock(&inode->i_mutex);
147 udc = inode->i_private;
148 data = kmalloc(inode->i_size, GFP_KERNEL);
149 if (!data)
150 goto out;
151
152 spin_lock_irq(&udc->lock);
153 for (i = 0; i < inode->i_size / 4; i++)
154 data[i] = __raw_readl(udc->regs + i * 4);
155 spin_unlock_irq(&udc->lock);
156
157 file->private_data = data;
158 ret = 0;
159
160out:
161 mutex_unlock(&inode->i_mutex);
162
163 return ret;
164}
165
166static ssize_t regs_dbg_read(struct file *file, char __user *buf,
167 size_t nbytes, loff_t *ppos)
168{
169 struct inode *inode = file->f_dentry->d_inode;
170 int ret;
171
172 mutex_lock(&inode->i_mutex);
173 ret = simple_read_from_buffer(buf, nbytes, ppos,
174 file->private_data,
175 file->f_dentry->d_inode->i_size);
176 mutex_unlock(&inode->i_mutex);
177
178 return ret;
179}
180
181static int regs_dbg_release(struct inode *inode, struct file *file)
182{
183 kfree(file->private_data);
184 return 0;
185}
186
187const struct file_operations queue_dbg_fops = {
188 .owner = THIS_MODULE,
189 .open = queue_dbg_open,
190 .llseek = no_llseek,
191 .read = queue_dbg_read,
192 .release = queue_dbg_release,
193};
194
195const struct file_operations regs_dbg_fops = {
196 .owner = THIS_MODULE,
197 .open = regs_dbg_open,
198 .llseek = generic_file_llseek,
199 .read = regs_dbg_read,
200 .release = regs_dbg_release,
201};
202
203static void usba_ep_init_debugfs(struct usba_udc *udc,
204 struct usba_ep *ep)
205{
206 struct dentry *ep_root;
207
208 ep_root = debugfs_create_dir(ep->ep.name, udc->debugfs_root);
209 if (!ep_root)
210 goto err_root;
211 ep->debugfs_dir = ep_root;
212
213 ep->debugfs_queue = debugfs_create_file("queue", 0400, ep_root,
214 ep, &queue_dbg_fops);
215 if (!ep->debugfs_queue)
216 goto err_queue;
217
218 if (ep->can_dma) {
219 ep->debugfs_dma_status
220 = debugfs_create_u32("dma_status", 0400, ep_root,
221 &ep->last_dma_status);
222 if (!ep->debugfs_dma_status)
223 goto err_dma_status;
224 }
225 if (ep_is_control(ep)) {
226 ep->debugfs_state
227 = debugfs_create_u32("state", 0400, ep_root,
228 &ep->state);
229 if (!ep->debugfs_state)
230 goto err_state;
231 }
232
233 return;
234
235err_state:
236 if (ep->can_dma)
237 debugfs_remove(ep->debugfs_dma_status);
238err_dma_status:
239 debugfs_remove(ep->debugfs_queue);
240err_queue:
241 debugfs_remove(ep_root);
242err_root:
243 dev_err(&ep->udc->pdev->dev,
244 "failed to create debugfs directory for %s\n", ep->ep.name);
245}
246
247static void usba_ep_cleanup_debugfs(struct usba_ep *ep)
248{
249 debugfs_remove(ep->debugfs_queue);
250 debugfs_remove(ep->debugfs_dma_status);
251 debugfs_remove(ep->debugfs_state);
252 debugfs_remove(ep->debugfs_dir);
253 ep->debugfs_dma_status = NULL;
254 ep->debugfs_dir = NULL;
255}
256
257static void usba_init_debugfs(struct usba_udc *udc)
258{
259 struct dentry *root, *regs;
260 struct resource *regs_resource;
261
262 root = debugfs_create_dir(udc->gadget.name, NULL);
263 if (IS_ERR(root) || !root)
264 goto err_root;
265 udc->debugfs_root = root;
266
267 regs = debugfs_create_file("regs", 0400, root, udc, &regs_dbg_fops);
268 if (!regs)
269 goto err_regs;
270
271 regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM,
272 CTRL_IOMEM_ID);
273 regs->d_inode->i_size = regs_resource->end - regs_resource->start + 1;
274 udc->debugfs_regs = regs;
275
276 usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0));
277
278 return;
279
280err_regs:
281 debugfs_remove(root);
282err_root:
283 udc->debugfs_root = NULL;
284 dev_err(&udc->pdev->dev, "debugfs is not available\n");
285}
286
287static void usba_cleanup_debugfs(struct usba_udc *udc)
288{
289 usba_ep_cleanup_debugfs(to_usba_ep(udc->gadget.ep0));
290 debugfs_remove(udc->debugfs_regs);
291 debugfs_remove(udc->debugfs_root);
292 udc->debugfs_regs = NULL;
293 udc->debugfs_root = NULL;
294}
295#else
296static inline void usba_ep_init_debugfs(struct usba_udc *udc,
297 struct usba_ep *ep)
298{
299
300}
301
302static inline void usba_ep_cleanup_debugfs(struct usba_ep *ep)
303{
304
305}
306
307static inline void usba_init_debugfs(struct usba_udc *udc)
308{
309
310}
311
312static inline void usba_cleanup_debugfs(struct usba_udc *udc)
313{
314
315}
316#endif
317
318static int vbus_is_present(struct usba_udc *udc)
319{
320 if (udc->vbus_pin != -1)
321 return gpio_get_value(udc->vbus_pin);
322
323 /* No Vbus detection: Assume always present */
324 return 1;
325}
326
327static void copy_to_fifo(void __iomem *fifo, const void *buf, int len)
328{
329 unsigned long tmp;
330
331 DBG(DBG_FIFO, "copy to FIFO (len %d):\n", len);
332 for (; len > 0; len -= 4, buf += 4, fifo += 4) {
333 tmp = *(unsigned long *)buf;
334 if (len >= 4) {
335 DBG(DBG_FIFO, " -> %08lx\n", tmp);
336 __raw_writel(tmp, fifo);
337 } else {
338 do {
339 DBG(DBG_FIFO, " -> %02lx\n", tmp >> 24);
340 __raw_writeb(tmp >> 24, fifo);
341 fifo++;
342 tmp <<= 8;
343 } while (--len);
344 break;
345 }
346 }
347}
348
349static void copy_from_fifo(void *buf, void __iomem *fifo, int len)
350{
351 union {
352 unsigned long *w;
353 unsigned char *b;
354 } p;
355 unsigned long tmp;
356
357 DBG(DBG_FIFO, "copy from FIFO (len %d):\n", len);
358 for (p.w = buf; len > 0; len -= 4, p.w++, fifo += 4) {
359 if (len >= 4) {
360 tmp = __raw_readl(fifo);
361 *p.w = tmp;
362 DBG(DBG_FIFO, " -> %08lx\n", tmp);
363 } else {
364 do {
365 tmp = __raw_readb(fifo);
366 *p.b = tmp;
367 DBG(DBG_FIFO, " -> %02lx\n", tmp);
368 fifo++, p.b++;
369 } while (--len);
370 }
371 }
372}
373
374static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
375{
376 unsigned int transaction_len;
377
378 transaction_len = req->req.length - req->req.actual;
379 req->last_transaction = 1;
380 if (transaction_len > ep->ep.maxpacket) {
381 transaction_len = ep->ep.maxpacket;
382 req->last_transaction = 0;
383 } else if (transaction_len == ep->ep.maxpacket && req->req.zero)
384 req->last_transaction = 0;
385
386 DBG(DBG_QUEUE, "%s: submit_transaction, req %p (length %d)%s\n",
387 ep->ep.name, req, transaction_len,
388 req->last_transaction ? ", done" : "");
389
390 copy_to_fifo(ep->fifo, req->req.buf + req->req.actual, transaction_len);
391 usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
392 req->req.actual += transaction_len;
393}
394
395static void submit_request(struct usba_ep *ep, struct usba_request *req)
396{
397 DBG(DBG_QUEUE, "%s: submit_request: req %p (length %d)\n",
398 ep->ep.name, req, req->req.length);
399
400 req->req.actual = 0;
401 req->submitted = 1;
402
403 if (req->using_dma) {
404 if (req->req.length == 0) {
405 usba_ep_writel(ep, CTL_ENB, USBA_TX_PK_RDY);
406 return;
407 }
408
409 if (req->req.zero)
410 usba_ep_writel(ep, CTL_ENB, USBA_SHORT_PACKET);
411 else
412 usba_ep_writel(ep, CTL_DIS, USBA_SHORT_PACKET);
413
414 usba_dma_writel(ep, ADDRESS, req->req.dma);
415 usba_dma_writel(ep, CONTROL, req->ctrl);
416 } else {
417 next_fifo_transaction(ep, req);
418 if (req->last_transaction) {
419 usba_ep_writel(ep, CTL_DIS, USBA_TX_PK_RDY);
420 usba_ep_writel(ep, CTL_ENB, USBA_TX_COMPLETE);
421 } else {
422 usba_ep_writel(ep, CTL_DIS, USBA_TX_COMPLETE);
423 usba_ep_writel(ep, CTL_ENB, USBA_TX_PK_RDY);
424 }
425 }
426}
427
428static void submit_next_request(struct usba_ep *ep)
429{
430 struct usba_request *req;
431
432 if (list_empty(&ep->queue)) {
433 usba_ep_writel(ep, CTL_DIS, USBA_TX_PK_RDY | USBA_RX_BK_RDY);
434 return;
435 }
436
437 req = list_entry(ep->queue.next, struct usba_request, queue);
438 if (!req->submitted)
439 submit_request(ep, req);
440}
441
442static void send_status(struct usba_udc *udc, struct usba_ep *ep)
443{
444 ep->state = STATUS_STAGE_IN;
445 usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
446 usba_ep_writel(ep, CTL_ENB, USBA_TX_COMPLETE);
447}
448
449static void receive_data(struct usba_ep *ep)
450{
451 struct usba_udc *udc = ep->udc;
452 struct usba_request *req;
453 unsigned long status;
454 unsigned int bytecount, nr_busy;
455 int is_complete = 0;
456
457 status = usba_ep_readl(ep, STA);
458 nr_busy = USBA_BFEXT(BUSY_BANKS, status);
459
460 DBG(DBG_QUEUE, "receive data: nr_busy=%u\n", nr_busy);
461
462 while (nr_busy > 0) {
463 if (list_empty(&ep->queue)) {
464 usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
465 break;
466 }
467 req = list_entry(ep->queue.next,
468 struct usba_request, queue);
469
470 bytecount = USBA_BFEXT(BYTE_COUNT, status);
471
472 if (status & (1 << 31))
473 is_complete = 1;
474 if (req->req.actual + bytecount >= req->req.length) {
475 is_complete = 1;
476 bytecount = req->req.length - req->req.actual;
477 }
478
479 copy_from_fifo(req->req.buf + req->req.actual,
480 ep->fifo, bytecount);
481 req->req.actual += bytecount;
482
483 usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY);
484
485 if (is_complete) {
486 DBG(DBG_QUEUE, "%s: request done\n", ep->ep.name);
487 req->req.status = 0;
488 list_del_init(&req->queue);
489 usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
490 spin_unlock(&udc->lock);
491 req->req.complete(&ep->ep, &req->req);
492 spin_lock(&udc->lock);
493 }
494
495 status = usba_ep_readl(ep, STA);
496 nr_busy = USBA_BFEXT(BUSY_BANKS, status);
497
498 if (is_complete && ep_is_control(ep)) {
499 send_status(udc, ep);
500 break;
501 }
502 }
503}
504
505static void
506request_complete(struct usba_ep *ep, struct usba_request *req, int status)
507{
508 struct usba_udc *udc = ep->udc;
509
510 WARN_ON(!list_empty(&req->queue));
511
512 if (req->req.status == -EINPROGRESS)
513 req->req.status = status;
514
515 if (req->mapped) {
516 dma_unmap_single(
517 &udc->pdev->dev, req->req.dma, req->req.length,
518 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
519 req->req.dma = DMA_ADDR_INVALID;
520 req->mapped = 0;
521 }
522
523 DBG(DBG_GADGET | DBG_REQ,
524 "%s: req %p complete: status %d, actual %u\n",
525 ep->ep.name, req, req->req.status, req->req.actual);
526
527 spin_unlock(&udc->lock);
528 req->req.complete(&ep->ep, &req->req);
529 spin_lock(&udc->lock);
530}
531
532static void
533request_complete_list(struct usba_ep *ep, struct list_head *list, int status)
534{
535 struct usba_request *req, *tmp_req;
536
537 list_for_each_entry_safe(req, tmp_req, list, queue) {
538 list_del_init(&req->queue);
539 request_complete(ep, req, status);
540 }
541}
542
543static int
544usba_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
545{
546 struct usba_ep *ep = to_usba_ep(_ep);
547 struct usba_udc *udc = ep->udc;
548 unsigned long flags, ept_cfg, maxpacket;
549 unsigned int nr_trans;
550
551 DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep->ep.name, desc);
552
553 maxpacket = le16_to_cpu(desc->wMaxPacketSize) & 0x7ff;
554
555 if (((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != ep->index)
556 || ep->index == 0
557 || desc->bDescriptorType != USB_DT_ENDPOINT
558 || maxpacket == 0
559 || maxpacket > ep->fifo_size) {
560 DBG(DBG_ERR, "ep_enable: Invalid argument");
561 return -EINVAL;
562 }
563
564 ep->is_isoc = 0;
565 ep->is_in = 0;
566
567 if (maxpacket <= 8)
568 ept_cfg = USBA_BF(EPT_SIZE, USBA_EPT_SIZE_8);
569 else
570 /* LSB is bit 1, not 0 */
571 ept_cfg = USBA_BF(EPT_SIZE, fls(maxpacket - 1) - 3);
572
573 DBG(DBG_HW, "%s: EPT_SIZE = %lu (maxpacket = %lu)\n",
574 ep->ep.name, ept_cfg, maxpacket);
575
576 if ((desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
577 ep->is_in = 1;
578 ept_cfg |= USBA_EPT_DIR_IN;
579 }
580
581 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
582 case USB_ENDPOINT_XFER_CONTROL:
583 ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL);
584 ept_cfg |= USBA_BF(BK_NUMBER, USBA_BK_NUMBER_ONE);
585 break;
586 case USB_ENDPOINT_XFER_ISOC:
587 if (!ep->can_isoc) {
588 DBG(DBG_ERR, "ep_enable: %s is not isoc capable\n",
589 ep->ep.name);
590 return -EINVAL;
591 }
592
593 /*
594 * Bits 11:12 specify number of _additional_
595 * transactions per microframe.
596 */
597 nr_trans = ((le16_to_cpu(desc->wMaxPacketSize) >> 11) & 3) + 1;
598 if (nr_trans > 3)
599 return -EINVAL;
600
601 ep->is_isoc = 1;
602 ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_ISO);
603
604 /*
605 * Do triple-buffering on high-bandwidth iso endpoints.
606 */
607 if (nr_trans > 1 && ep->nr_banks == 3)
608 ept_cfg |= USBA_BF(BK_NUMBER, USBA_BK_NUMBER_TRIPLE);
609 else
610 ept_cfg |= USBA_BF(BK_NUMBER, USBA_BK_NUMBER_DOUBLE);
611 ept_cfg |= USBA_BF(NB_TRANS, nr_trans);
612 break;
613 case USB_ENDPOINT_XFER_BULK:
614 ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK);
615 ept_cfg |= USBA_BF(BK_NUMBER, USBA_BK_NUMBER_DOUBLE);
616 break;
617 case USB_ENDPOINT_XFER_INT:
618 ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_INT);
619 ept_cfg |= USBA_BF(BK_NUMBER, USBA_BK_NUMBER_DOUBLE);
620 break;
621 }
622
623 spin_lock_irqsave(&ep->udc->lock, flags);
624
625 if (ep->desc) {
626 spin_unlock_irqrestore(&ep->udc->lock, flags);
627 DBG(DBG_ERR, "ep%d already enabled\n", ep->index);
628 return -EBUSY;
629 }
630
631 ep->desc = desc;
632 ep->ep.maxpacket = maxpacket;
633
634 usba_ep_writel(ep, CFG, ept_cfg);
635 usba_ep_writel(ep, CTL_ENB, USBA_EPT_ENABLE);
636
637 if (ep->can_dma) {
638 u32 ctrl;
639
640 usba_writel(udc, INT_ENB,
641 (usba_readl(udc, INT_ENB)
642 | USBA_BF(EPT_INT, 1 << ep->index)
643 | USBA_BF(DMA_INT, 1 << ep->index)));
644 ctrl = USBA_AUTO_VALID | USBA_INTDIS_DMA;
645 usba_ep_writel(ep, CTL_ENB, ctrl);
646 } else {
647 usba_writel(udc, INT_ENB,
648 (usba_readl(udc, INT_ENB)
649 | USBA_BF(EPT_INT, 1 << ep->index)));
650 }
651
652 spin_unlock_irqrestore(&udc->lock, flags);
653
654 DBG(DBG_HW, "EPT_CFG%d after init: %#08lx\n", ep->index,
655 (unsigned long)usba_ep_readl(ep, CFG));
656 DBG(DBG_HW, "INT_ENB after init: %#08lx\n",
657 (unsigned long)usba_readl(udc, INT_ENB));
658
659 return 0;
660}
661
662static int usba_ep_disable(struct usb_ep *_ep)
663{
664 struct usba_ep *ep = to_usba_ep(_ep);
665 struct usba_udc *udc = ep->udc;
666 LIST_HEAD(req_list);
667 unsigned long flags;
668
669 DBG(DBG_GADGET, "ep_disable: %s\n", ep->ep.name);
670
671 spin_lock_irqsave(&udc->lock, flags);
672
673 if (!ep->desc) {
674 spin_unlock_irqrestore(&udc->lock, flags);
675 DBG(DBG_ERR, "ep_disable: %s not enabled\n", ep->ep.name);
676 return -EINVAL;
677 }
678 ep->desc = NULL;
679
680 list_splice_init(&ep->queue, &req_list);
681 if (ep->can_dma) {
682 usba_dma_writel(ep, CONTROL, 0);
683 usba_dma_writel(ep, ADDRESS, 0);
684 usba_dma_readl(ep, STATUS);
685 }
686 usba_ep_writel(ep, CTL_DIS, USBA_EPT_ENABLE);
687 usba_writel(udc, INT_ENB,
688 usba_readl(udc, INT_ENB)
689 & ~USBA_BF(EPT_INT, 1 << ep->index));
690
691 request_complete_list(ep, &req_list, -ESHUTDOWN);
692
693 spin_unlock_irqrestore(&udc->lock, flags);
694
695 return 0;
696}
697
698static struct usb_request *
699usba_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
700{
701 struct usba_request *req;
702
703 DBG(DBG_GADGET, "ep_alloc_request: %p, 0x%x\n", _ep, gfp_flags);
704
705 req = kzalloc(sizeof(*req), gfp_flags);
706 if (!req)
707 return NULL;
708
709 INIT_LIST_HEAD(&req->queue);
710 req->req.dma = DMA_ADDR_INVALID;
711
712 return &req->req;
713}
714
715static void
716usba_ep_free_request(struct usb_ep *_ep, struct usb_request *_req)
717{
718 struct usba_request *req = to_usba_req(_req);
719
720 DBG(DBG_GADGET, "ep_free_request: %p, %p\n", _ep, _req);
721
722 kfree(req);
723}
724
725static int queue_dma(struct usba_udc *udc, struct usba_ep *ep,
726 struct usba_request *req, gfp_t gfp_flags)
727{
728 unsigned long flags;
729 int ret;
730
731 DBG(DBG_DMA, "%s: req l/%u d/%08x %c%c%c\n",
732 ep->ep.name, req->req.length, req->req.dma,
733 req->req.zero ? 'Z' : 'z',
734 req->req.short_not_ok ? 'S' : 's',
735 req->req.no_interrupt ? 'I' : 'i');
736
737 if (req->req.length > 0x10000) {
738 /* Lengths from 0 to 65536 (inclusive) are supported */
739 DBG(DBG_ERR, "invalid request length %u\n", req->req.length);
740 return -EINVAL;
741 }
742
743 req->using_dma = 1;
744
745 if (req->req.dma == DMA_ADDR_INVALID) {
746 req->req.dma = dma_map_single(
747 &udc->pdev->dev, req->req.buf, req->req.length,
748 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
749 req->mapped = 1;
750 } else {
751 dma_sync_single_for_device(
752 &udc->pdev->dev, req->req.dma, req->req.length,
753 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
754 req->mapped = 0;
755 }
756
757 req->ctrl = USBA_BF(DMA_BUF_LEN, req->req.length)
758 | USBA_DMA_CH_EN | USBA_DMA_END_BUF_IE
759 | USBA_DMA_END_TR_EN | USBA_DMA_END_TR_IE;
760
761 if (ep->is_in)
762 req->ctrl |= USBA_DMA_END_BUF_EN;
763
764 /*
765 * Add this request to the queue and submit for DMA if
766 * possible. Check if we're still alive first -- we may have
767 * received a reset since last time we checked.
768 */
769 ret = -ESHUTDOWN;
770 spin_lock_irqsave(&udc->lock, flags);
771 if (ep->desc) {
772 if (list_empty(&ep->queue))
773 submit_request(ep, req);
774
775 list_add_tail(&req->queue, &ep->queue);
776 ret = 0;
777 }
778 spin_unlock_irqrestore(&udc->lock, flags);
779
780 return ret;
781}
782
783static int
784usba_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
785{
786 struct usba_request *req = to_usba_req(_req);
787 struct usba_ep *ep = to_usba_ep(_ep);
788 struct usba_udc *udc = ep->udc;
789 unsigned long flags;
790 int ret;
791
792 DBG(DBG_GADGET | DBG_QUEUE | DBG_REQ, "%s: queue req %p, len %u\n",
793 ep->ep.name, req, _req->length);
794
795 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN || !ep->desc)
796 return -ESHUTDOWN;
797
798 req->submitted = 0;
799 req->using_dma = 0;
800 req->last_transaction = 0;
801
802 _req->status = -EINPROGRESS;
803 _req->actual = 0;
804
805 if (ep->can_dma)
806 return queue_dma(udc, ep, req, gfp_flags);
807
808 /* May have received a reset since last time we checked */
809 ret = -ESHUTDOWN;
810 spin_lock_irqsave(&udc->lock, flags);
811 if (ep->desc) {
812 list_add_tail(&req->queue, &ep->queue);
813
814 if (ep->is_in || (ep_is_control(ep)
815 && (ep->state == DATA_STAGE_IN
816 || ep->state == STATUS_STAGE_IN)))
817 usba_ep_writel(ep, CTL_ENB, USBA_TX_PK_RDY);
818 else
819 usba_ep_writel(ep, CTL_ENB, USBA_RX_BK_RDY);
820 ret = 0;
821 }
822 spin_unlock_irqrestore(&udc->lock, flags);
823
824 return ret;
825}
826
827static void
828usba_update_req(struct usba_ep *ep, struct usba_request *req, u32 status)
829{
830 req->req.actual = req->req.length - USBA_BFEXT(DMA_BUF_LEN, status);
831}
832
833static int stop_dma(struct usba_ep *ep, u32 *pstatus)
834{
835 unsigned int timeout;
836 u32 status;
837
838 /*
839 * Stop the DMA controller. When writing both CH_EN
840 * and LINK to 0, the other bits are not affected.
841 */
842 usba_dma_writel(ep, CONTROL, 0);
843
844 /* Wait for the FIFO to empty */
845 for (timeout = 40; timeout; --timeout) {
846 status = usba_dma_readl(ep, STATUS);
847 if (!(status & USBA_DMA_CH_EN))
848 break;
849 udelay(1);
850 }
851
852 if (pstatus)
853 *pstatus = status;
854
855 if (timeout == 0) {
856 dev_err(&ep->udc->pdev->dev,
857 "%s: timed out waiting for DMA FIFO to empty\n",
858 ep->ep.name);
859 return -ETIMEDOUT;
860 }
861
862 return 0;
863}
864
865static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
866{
867 struct usba_ep *ep = to_usba_ep(_ep);
868 struct usba_udc *udc = ep->udc;
869 struct usba_request *req = to_usba_req(_req);
870 unsigned long flags;
871 u32 status;
872
873 DBG(DBG_GADGET | DBG_QUEUE, "ep_dequeue: %s, req %p\n",
874 ep->ep.name, req);
875
876 spin_lock_irqsave(&udc->lock, flags);
877
878 if (req->using_dma) {
879 /*
880 * If this request is currently being transferred,
881 * stop the DMA controller and reset the FIFO.
882 */
883 if (ep->queue.next == &req->queue) {
884 status = usba_dma_readl(ep, STATUS);
885 if (status & USBA_DMA_CH_EN)
886 stop_dma(ep, &status);
887
888#ifdef CONFIG_USB_GADGET_DEBUG_FS
889 ep->last_dma_status = status;
890#endif
891
892 usba_writel(udc, EPT_RST, 1 << ep->index);
893
894 usba_update_req(ep, req, status);
895 }
896 }
897
898 /*
899 * Errors should stop the queue from advancing until the
900 * completion function returns.
901 */
902 list_del_init(&req->queue);
903
904 request_complete(ep, req, -ECONNRESET);
905
906 /* Process the next request if any */
907 submit_next_request(ep);
908 spin_unlock_irqrestore(&udc->lock, flags);
909
910 return 0;
911}
912
913static int usba_ep_set_halt(struct usb_ep *_ep, int value)
914{
915 struct usba_ep *ep = to_usba_ep(_ep);
916 struct usba_udc *udc = ep->udc;
917 unsigned long flags;
918 int ret = 0;
919
920 DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep->ep.name,
921 value ? "set" : "clear");
922
923 if (!ep->desc) {
924 DBG(DBG_ERR, "Attempted to halt uninitialized ep %s\n",
925 ep->ep.name);
926 return -ENODEV;
927 }
928 if (ep->is_isoc) {
929 DBG(DBG_ERR, "Attempted to halt isochronous ep %s\n",
930 ep->ep.name);
931 return -ENOTTY;
932 }
933
934 spin_lock_irqsave(&udc->lock, flags);
935
936 /*
937 * We can't halt IN endpoints while there are still data to be
938 * transferred
939 */
940 if (!list_empty(&ep->queue)
941 || ((value && ep->is_in && (usba_ep_readl(ep, STA)
942 & USBA_BF(BUSY_BANKS, -1L))))) {
943 ret = -EAGAIN;
944 } else {
945 if (value)
946 usba_ep_writel(ep, SET_STA, USBA_FORCE_STALL);
947 else
948 usba_ep_writel(ep, CLR_STA,
949 USBA_FORCE_STALL | USBA_TOGGLE_CLR);
950 usba_ep_readl(ep, STA);
951 }
952
953 spin_unlock_irqrestore(&udc->lock, flags);
954
955 return ret;
956}
957
958static int usba_ep_fifo_status(struct usb_ep *_ep)
959{
960 struct usba_ep *ep = to_usba_ep(_ep);
961
962 return USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
963}
964
965static void usba_ep_fifo_flush(struct usb_ep *_ep)
966{
967 struct usba_ep *ep = to_usba_ep(_ep);
968 struct usba_udc *udc = ep->udc;
969
970 usba_writel(udc, EPT_RST, 1 << ep->index);
971}
972
973static const struct usb_ep_ops usba_ep_ops = {
974 .enable = usba_ep_enable,
975 .disable = usba_ep_disable,
976 .alloc_request = usba_ep_alloc_request,
977 .free_request = usba_ep_free_request,
978 .queue = usba_ep_queue,
979 .dequeue = usba_ep_dequeue,
980 .set_halt = usba_ep_set_halt,
981 .fifo_status = usba_ep_fifo_status,
982 .fifo_flush = usba_ep_fifo_flush,
983};
984
985static int usba_udc_get_frame(struct usb_gadget *gadget)
986{
987 struct usba_udc *udc = to_usba_udc(gadget);
988
989 return USBA_BFEXT(FRAME_NUMBER, usba_readl(udc, FNUM));
990}
991
992static int usba_udc_wakeup(struct usb_gadget *gadget)
993{
994 struct usba_udc *udc = to_usba_udc(gadget);
995 unsigned long flags;
996 u32 ctrl;
997 int ret = -EINVAL;
998
999 spin_lock_irqsave(&udc->lock, flags);
1000 if (udc->devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) {
1001 ctrl = usba_readl(udc, CTRL);
1002 usba_writel(udc, CTRL, ctrl | USBA_REMOTE_WAKE_UP);
1003 ret = 0;
1004 }
1005 spin_unlock_irqrestore(&udc->lock, flags);
1006
1007 return ret;
1008}
1009
1010static int
1011usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
1012{
1013 struct usba_udc *udc = to_usba_udc(gadget);
1014 unsigned long flags;
1015
1016 spin_lock_irqsave(&udc->lock, flags);
1017 if (is_selfpowered)
1018 udc->devstatus |= 1 << USB_DEVICE_SELF_POWERED;
1019 else
1020 udc->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED);
1021 spin_unlock_irqrestore(&udc->lock, flags);
1022
1023 return 0;
1024}
1025
1026static const struct usb_gadget_ops usba_udc_ops = {
1027 .get_frame = usba_udc_get_frame,
1028 .wakeup = usba_udc_wakeup,
1029 .set_selfpowered = usba_udc_set_selfpowered,
1030};
1031
1032#define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
1033{ \
1034 .ep = { \
1035 .ops = &usba_ep_ops, \
1036 .name = nam, \
1037 .maxpacket = maxpkt, \
1038 }, \
1039 .udc = &the_udc, \
1040 .queue = LIST_HEAD_INIT(usba_ep[idx].queue), \
1041 .fifo_size = maxpkt, \
1042 .nr_banks = maxbk, \
1043 .index = idx, \
1044 .can_dma = dma, \
1045 .can_isoc = isoc, \
1046}
1047
1048static struct usba_ep usba_ep[] = {
1049 EP("ep0", 0, 64, 1, 0, 0),
1050 EP("ep1in-bulk", 1, 512, 2, 1, 1),
1051 EP("ep2out-bulk", 2, 512, 2, 1, 1),
1052 EP("ep3in-int", 3, 64, 3, 1, 0),
1053 EP("ep4out-int", 4, 64, 3, 1, 0),
1054 EP("ep5in-iso", 5, 1024, 3, 1, 1),
1055 EP("ep6out-iso", 6, 1024, 3, 1, 1),
1056};
1057#undef EP
1058
1059static struct usb_endpoint_descriptor usba_ep0_desc = {
1060 .bLength = USB_DT_ENDPOINT_SIZE,
1061 .bDescriptorType = USB_DT_ENDPOINT,
1062 .bEndpointAddress = 0,
1063 .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
1064 .wMaxPacketSize = __constant_cpu_to_le16(64),
1065 /* FIXME: I have no idea what to put here */
1066 .bInterval = 1,
1067};
1068
1069static void nop_release(struct device *dev)
1070{
1071
1072}
1073
1074static struct usba_udc the_udc = {
1075 .gadget = {
1076 .ops = &usba_udc_ops,
1077 .ep0 = &usba_ep[0].ep,
1078 .ep_list = LIST_HEAD_INIT(the_udc.gadget.ep_list),
1079 .is_dualspeed = 1,
1080 .name = "atmel_usba_udc",
1081 .dev = {
1082 .bus_id = "gadget",
1083 .release = nop_release,
1084 },
1085 },
1086
1087 .lock = SPIN_LOCK_UNLOCKED,
1088};
1089
1090/*
1091 * Called with interrupts disabled and udc->lock held.
1092 */
1093static void reset_all_endpoints(struct usba_udc *udc)
1094{
1095 struct usba_ep *ep;
1096 struct usba_request *req, *tmp_req;
1097
1098 usba_writel(udc, EPT_RST, ~0UL);
1099
1100 ep = to_usba_ep(udc->gadget.ep0);
1101 list_for_each_entry_safe(req, tmp_req, &ep->queue, queue) {
1102 list_del_init(&req->queue);
1103 request_complete(ep, req, -ECONNRESET);
1104 }
1105
1106 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
1107 if (ep->desc) {
1108 spin_unlock(&udc->lock);
1109 usba_ep_disable(&ep->ep);
1110 spin_lock(&udc->lock);
1111 }
1112 }
1113}
1114
1115static struct usba_ep *get_ep_by_addr(struct usba_udc *udc, u16 wIndex)
1116{
1117 struct usba_ep *ep;
1118
1119 if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
1120 return to_usba_ep(udc->gadget.ep0);
1121
1122 list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) {
1123 u8 bEndpointAddress;
1124
1125 if (!ep->desc)
1126 continue;
1127 bEndpointAddress = ep->desc->bEndpointAddress;
1128 if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
1129 continue;
1130 if ((bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)
1131 == (wIndex & USB_ENDPOINT_NUMBER_MASK))
1132 return ep;
1133 }
1134
1135 return NULL;
1136}
1137
1138/* Called with interrupts disabled and udc->lock held */
1139static inline void set_protocol_stall(struct usba_udc *udc, struct usba_ep *ep)
1140{
1141 usba_ep_writel(ep, SET_STA, USBA_FORCE_STALL);
1142 ep->state = WAIT_FOR_SETUP;
1143}
1144
1145static inline int is_stalled(struct usba_udc *udc, struct usba_ep *ep)
1146{
1147 if (usba_ep_readl(ep, STA) & USBA_FORCE_STALL)
1148 return 1;
1149 return 0;
1150}
1151
1152static inline void set_address(struct usba_udc *udc, unsigned int addr)
1153{
1154 u32 regval;
1155
1156 DBG(DBG_BUS, "setting address %u...\n", addr);
1157 regval = usba_readl(udc, CTRL);
1158 regval = USBA_BFINS(DEV_ADDR, addr, regval);
1159 usba_writel(udc, CTRL, regval);
1160}
1161
1162static int do_test_mode(struct usba_udc *udc)
1163{
1164 static const char test_packet_buffer[] = {
1165 /* JKJKJKJK * 9 */
1166 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1167 /* JJKKJJKK * 8 */
1168 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
1169 /* JJKKJJKK * 8 */
1170 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
1171 /* JJJJJJJKKKKKKK * 8 */
1172 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1173 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1174 /* JJJJJJJK * 8 */
1175 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD,
1176 /* {JKKKKKKK * 10}, JK */
1177 0xFC, 0x7E, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0x7E
1178 };
1179 struct usba_ep *ep;
1180 struct device *dev = &udc->pdev->dev;
1181 int test_mode;
1182
1183 test_mode = udc->test_mode;
1184
1185 /* Start from a clean slate */
1186 reset_all_endpoints(udc);
1187
1188 switch (test_mode) {
1189 case 0x0100:
1190 /* Test_J */
1191 usba_writel(udc, TST, USBA_TST_J_MODE);
1192 dev_info(dev, "Entering Test_J mode...\n");
1193 break;
1194 case 0x0200:
1195 /* Test_K */
1196 usba_writel(udc, TST, USBA_TST_K_MODE);
1197 dev_info(dev, "Entering Test_K mode...\n");
1198 break;
1199 case 0x0300:
1200 /*
1201 * Test_SE0_NAK: Force high-speed mode and set up ep0
1202 * for Bulk IN transfers
1203 */
1204 ep = &usba_ep[0];
1205 usba_writel(udc, TST,
1206 USBA_BF(SPEED_CFG, USBA_SPEED_CFG_FORCE_HIGH));
1207 usba_ep_writel(ep, CFG,
1208 USBA_BF(EPT_SIZE, USBA_EPT_SIZE_64)
1209 | USBA_EPT_DIR_IN
1210 | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK)
1211 | USBA_BF(BK_NUMBER, 1));
1212 if (!(usba_ep_readl(ep, CFG) & USBA_EPT_MAPPED)) {
1213 set_protocol_stall(udc, ep);
1214 dev_err(dev, "Test_SE0_NAK: ep0 not mapped\n");
1215 } else {
1216 usba_ep_writel(ep, CTL_ENB, USBA_EPT_ENABLE);
1217 dev_info(dev, "Entering Test_SE0_NAK mode...\n");
1218 }
1219 break;
1220 case 0x0400:
1221 /* Test_Packet */
1222 ep = &usba_ep[0];
1223 usba_ep_writel(ep, CFG,
1224 USBA_BF(EPT_SIZE, USBA_EPT_SIZE_64)
1225 | USBA_EPT_DIR_IN
1226 | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK)
1227 | USBA_BF(BK_NUMBER, 1));
1228 if (!(usba_ep_readl(ep, CFG) & USBA_EPT_MAPPED)) {
1229 set_protocol_stall(udc, ep);
1230 dev_err(dev, "Test_Packet: ep0 not mapped\n");
1231 } else {
1232 usba_ep_writel(ep, CTL_ENB, USBA_EPT_ENABLE);
1233 usba_writel(udc, TST, USBA_TST_PKT_MODE);
1234 copy_to_fifo(ep->fifo, test_packet_buffer,
1235 sizeof(test_packet_buffer));
1236 usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
1237 dev_info(dev, "Entering Test_Packet mode...\n");
1238 }
1239 break;
1240 default:
1241 dev_err(dev, "Invalid test mode: 0x%04x\n", test_mode);
1242 return -EINVAL;
1243 }
1244
1245 return 0;
1246}
1247
1248/* Avoid overly long expressions */
1249static inline bool feature_is_dev_remote_wakeup(struct usb_ctrlrequest *crq)
1250{
1251 if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP))
1252 return true;
1253 return false;
1254}
1255
1256static inline bool feature_is_dev_test_mode(struct usb_ctrlrequest *crq)
1257{
1258 if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_TEST_MODE))
1259 return true;
1260 return false;
1261}
1262
1263static inline bool feature_is_ep_halt(struct usb_ctrlrequest *crq)
1264{
1265 if (crq->wValue == __constant_cpu_to_le16(USB_ENDPOINT_HALT))
1266 return true;
1267 return false;
1268}
1269
1270static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
1271 struct usb_ctrlrequest *crq)
1272{
1273 int retval = 0;;
1274
1275 switch (crq->bRequest) {
1276 case USB_REQ_GET_STATUS: {
1277 u16 status;
1278
1279 if (crq->bRequestType == (USB_DIR_IN | USB_RECIP_DEVICE)) {
1280 status = cpu_to_le16(udc->devstatus);
1281 } else if (crq->bRequestType
1282 == (USB_DIR_IN | USB_RECIP_INTERFACE)) {
1283 status = __constant_cpu_to_le16(0);
1284 } else if (crq->bRequestType
1285 == (USB_DIR_IN | USB_RECIP_ENDPOINT)) {
1286 struct usba_ep *target;
1287
1288 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
1289 if (!target)
1290 goto stall;
1291
1292 status = 0;
1293 if (is_stalled(udc, target))
1294 status |= __constant_cpu_to_le16(1);
1295 } else
1296 goto delegate;
1297
1298 /* Write directly to the FIFO. No queueing is done. */
1299 if (crq->wLength != __constant_cpu_to_le16(sizeof(status)))
1300 goto stall;
1301 ep->state = DATA_STAGE_IN;
1302 __raw_writew(status, ep->fifo);
1303 usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
1304 break;
1305 }
1306
1307 case USB_REQ_CLEAR_FEATURE: {
1308 if (crq->bRequestType == USB_RECIP_DEVICE) {
1309 if (feature_is_dev_remote_wakeup(crq))
1310 udc->devstatus
1311 &= ~(1 << USB_DEVICE_REMOTE_WAKEUP);
1312 else
1313 /* Can't CLEAR_FEATURE TEST_MODE */
1314 goto stall;
1315 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
1316 struct usba_ep *target;
1317
1318 if (crq->wLength != __constant_cpu_to_le16(0)
1319 || !feature_is_ep_halt(crq))
1320 goto stall;
1321 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
1322 if (!target)
1323 goto stall;
1324
1325 usba_ep_writel(target, CLR_STA, USBA_FORCE_STALL);
1326 if (target->index != 0)
1327 usba_ep_writel(target, CLR_STA,
1328 USBA_TOGGLE_CLR);
1329 } else {
1330 goto delegate;
1331 }
1332
1333 send_status(udc, ep);
1334 break;
1335 }
1336
1337 case USB_REQ_SET_FEATURE: {
1338 if (crq->bRequestType == USB_RECIP_DEVICE) {
1339 if (feature_is_dev_test_mode(crq)) {
1340 send_status(udc, ep);
1341 ep->state = STATUS_STAGE_TEST;
1342 udc->test_mode = le16_to_cpu(crq->wIndex);
1343 return 0;
1344 } else if (feature_is_dev_remote_wakeup(crq)) {
1345 udc->devstatus |= 1 << USB_DEVICE_REMOTE_WAKEUP;
1346 } else {
1347 goto stall;
1348 }
1349 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
1350 struct usba_ep *target;
1351
1352 if (crq->wLength != __constant_cpu_to_le16(0)
1353 || !feature_is_ep_halt(crq))
1354 goto stall;
1355
1356 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
1357 if (!target)
1358 goto stall;
1359
1360 usba_ep_writel(target, SET_STA, USBA_FORCE_STALL);
1361 } else
1362 goto delegate;
1363
1364 send_status(udc, ep);
1365 break;
1366 }
1367
1368 case USB_REQ_SET_ADDRESS:
1369 if (crq->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE))
1370 goto delegate;
1371
1372 set_address(udc, le16_to_cpu(crq->wValue));
1373 send_status(udc, ep);
1374 ep->state = STATUS_STAGE_ADDR;
1375 break;
1376
1377 default:
1378delegate:
1379 spin_unlock(&udc->lock);
1380 retval = udc->driver->setup(&udc->gadget, crq);
1381 spin_lock(&udc->lock);
1382 }
1383
1384 return retval;
1385
1386stall:
1387 printk(KERN_ERR
1388 "udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, "
1389 "halting endpoint...\n",
1390 ep->ep.name, crq->bRequestType, crq->bRequest,
1391 le16_to_cpu(crq->wValue), le16_to_cpu(crq->wIndex),
1392 le16_to_cpu(crq->wLength));
1393 set_protocol_stall(udc, ep);
1394 return -1;
1395}
1396
1397static void usba_control_irq(struct usba_udc *udc, struct usba_ep *ep)
1398{
1399 struct usba_request *req;
1400 u32 epstatus;
1401 u32 epctrl;
1402
1403restart:
1404 epstatus = usba_ep_readl(ep, STA);
1405 epctrl = usba_ep_readl(ep, CTL);
1406
1407 DBG(DBG_INT, "%s [%d]: s/%08x c/%08x\n",
1408 ep->ep.name, ep->state, epstatus, epctrl);
1409
1410 req = NULL;
1411 if (!list_empty(&ep->queue))
1412 req = list_entry(ep->queue.next,
1413 struct usba_request, queue);
1414
1415 if ((epctrl & USBA_TX_PK_RDY) && !(epstatus & USBA_TX_PK_RDY)) {
1416 if (req->submitted)
1417 next_fifo_transaction(ep, req);
1418 else
1419 submit_request(ep, req);
1420
1421 if (req->last_transaction) {
1422 usba_ep_writel(ep, CTL_DIS, USBA_TX_PK_RDY);
1423 usba_ep_writel(ep, CTL_ENB, USBA_TX_COMPLETE);
1424 }
1425 goto restart;
1426 }
1427 if ((epstatus & epctrl) & USBA_TX_COMPLETE) {
1428 usba_ep_writel(ep, CLR_STA, USBA_TX_COMPLETE);
1429
1430 switch (ep->state) {
1431 case DATA_STAGE_IN:
1432 usba_ep_writel(ep, CTL_ENB, USBA_RX_BK_RDY);
1433 usba_ep_writel(ep, CTL_DIS, USBA_TX_COMPLETE);
1434 ep->state = STATUS_STAGE_OUT;
1435 break;
1436 case STATUS_STAGE_ADDR:
1437 /* Activate our new address */
1438 usba_writel(udc, CTRL, (usba_readl(udc, CTRL)
1439 | USBA_FADDR_EN));
1440 usba_ep_writel(ep, CTL_DIS, USBA_TX_COMPLETE);
1441 ep->state = WAIT_FOR_SETUP;
1442 break;
1443 case STATUS_STAGE_IN:
1444 if (req) {
1445 list_del_init(&req->queue);
1446 request_complete(ep, req, 0);
1447 submit_next_request(ep);
1448 }
1449 usba_ep_writel(ep, CTL_DIS, USBA_TX_COMPLETE);
1450 ep->state = WAIT_FOR_SETUP;
1451 break;
1452 case STATUS_STAGE_TEST:
1453 usba_ep_writel(ep, CTL_DIS, USBA_TX_COMPLETE);
1454 ep->state = WAIT_FOR_SETUP;
1455 if (do_test_mode(udc))
1456 set_protocol_stall(udc, ep);
1457 break;
1458 default:
1459 printk(KERN_ERR
1460 "udc: %s: TXCOMP: Invalid endpoint state %d, "
1461 "halting endpoint...\n",
1462 ep->ep.name, ep->state);
1463 set_protocol_stall(udc, ep);
1464 break;
1465 }
1466
1467 goto restart;
1468 }
1469 if ((epstatus & epctrl) & USBA_RX_BK_RDY) {
1470 switch (ep->state) {
1471 case STATUS_STAGE_OUT:
1472 usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY);
1473 usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
1474
1475 if (req) {
1476 list_del_init(&req->queue);
1477 request_complete(ep, req, 0);
1478 }
1479 ep->state = WAIT_FOR_SETUP;
1480 break;
1481
1482 case DATA_STAGE_OUT:
1483 receive_data(ep);
1484 break;
1485
1486 default:
1487 usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY);
1488 usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
1489 printk(KERN_ERR
1490 "udc: %s: RXRDY: Invalid endpoint state %d, "
1491 "halting endpoint...\n",
1492 ep->ep.name, ep->state);
1493 set_protocol_stall(udc, ep);
1494 break;
1495 }
1496
1497 goto restart;
1498 }
1499 if (epstatus & USBA_RX_SETUP) {
1500 union {
1501 struct usb_ctrlrequest crq;
1502 unsigned long data[2];
1503 } crq;
1504 unsigned int pkt_len;
1505 int ret;
1506
1507 if (ep->state != WAIT_FOR_SETUP) {
1508 /*
1509 * Didn't expect a SETUP packet at this
1510 * point. Clean up any pending requests (which
1511 * may be successful).
1512 */
1513 int status = -EPROTO;
1514
1515 /*
1516 * RXRDY and TXCOMP are dropped when SETUP
1517 * packets arrive. Just pretend we received
1518 * the status packet.
1519 */
1520 if (ep->state == STATUS_STAGE_OUT
1521 || ep->state == STATUS_STAGE_IN) {
1522 usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
1523 status = 0;
1524 }
1525
1526 if (req) {
1527 list_del_init(&req->queue);
1528 request_complete(ep, req, status);
1529 }
1530 }
1531
1532 pkt_len = USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
1533 DBG(DBG_HW, "Packet length: %u\n", pkt_len);
1534 if (pkt_len != sizeof(crq)) {
1535 printk(KERN_WARNING "udc: Invalid packet length %u "
1536 "(expected %lu)\n", pkt_len, sizeof(crq));
1537 set_protocol_stall(udc, ep);
1538 return;
1539 }
1540
1541 DBG(DBG_FIFO, "Copying ctrl request from 0x%p:\n", ep->fifo);
1542 copy_from_fifo(crq.data, ep->fifo, sizeof(crq));
1543
1544 /* Free up one bank in the FIFO so that we can
1545 * generate or receive a reply right away. */
1546 usba_ep_writel(ep, CLR_STA, USBA_RX_SETUP);
1547
1548 /* printk(KERN_DEBUG "setup: %d: %02x.%02x\n",
1549 ep->state, crq.crq.bRequestType,
1550 crq.crq.bRequest); */
1551
1552 if (crq.crq.bRequestType & USB_DIR_IN) {
1553 /*
1554 * The USB 2.0 spec states that "if wLength is
1555 * zero, there is no data transfer phase."
1556 * However, testusb #14 seems to actually
1557 * expect a data phase even if wLength = 0...
1558 */
1559 ep->state = DATA_STAGE_IN;
1560 } else {
1561 if (crq.crq.wLength != __constant_cpu_to_le16(0))
1562 ep->state = DATA_STAGE_OUT;
1563 else
1564 ep->state = STATUS_STAGE_IN;
1565 }
1566
1567 ret = -1;
1568 if (ep->index == 0)
1569 ret = handle_ep0_setup(udc, ep, &crq.crq);
1570 else {
1571 spin_unlock(&udc->lock);
1572 ret = udc->driver->setup(&udc->gadget, &crq.crq);
1573 spin_lock(&udc->lock);
1574 }
1575
1576 DBG(DBG_BUS, "req %02x.%02x, length %d, state %d, ret %d\n",
1577 crq.crq.bRequestType, crq.crq.bRequest,
1578 le16_to_cpu(crq.crq.wLength), ep->state, ret);
1579
1580 if (ret < 0) {
1581 /* Let the host know that we failed */
1582 set_protocol_stall(udc, ep);
1583 }
1584 }
1585}
1586
1587static void usba_ep_irq(struct usba_udc *udc, struct usba_ep *ep)
1588{
1589 struct usba_request *req;
1590 u32 epstatus;
1591 u32 epctrl;
1592
1593 epstatus = usba_ep_readl(ep, STA);
1594 epctrl = usba_ep_readl(ep, CTL);
1595
1596 DBG(DBG_INT, "%s: interrupt, status: 0x%08x\n", ep->ep.name, epstatus);
1597
1598 while ((epctrl & USBA_TX_PK_RDY) && !(epstatus & USBA_TX_PK_RDY)) {
1599 DBG(DBG_BUS, "%s: TX PK ready\n", ep->ep.name);
1600
1601 if (list_empty(&ep->queue)) {
1602 dev_warn(&udc->pdev->dev, "ep_irq: queue empty\n");
1603 usba_ep_writel(ep, CTL_DIS, USBA_TX_PK_RDY);
1604 return;
1605 }
1606
1607 req = list_entry(ep->queue.next, struct usba_request, queue);
1608
1609 if (req->using_dma) {
1610 /* Send a zero-length packet */
1611 usba_ep_writel(ep, SET_STA,
1612 USBA_TX_PK_RDY);
1613 usba_ep_writel(ep, CTL_DIS,
1614 USBA_TX_PK_RDY);
1615 list_del_init(&req->queue);
1616 submit_next_request(ep);
1617 request_complete(ep, req, 0);
1618 } else {
1619 if (req->submitted)
1620 next_fifo_transaction(ep, req);
1621 else
1622 submit_request(ep, req);
1623
1624 if (req->last_transaction) {
1625 list_del_init(&req->queue);
1626 submit_next_request(ep);
1627 request_complete(ep, req, 0);
1628 }
1629 }
1630
1631 epstatus = usba_ep_readl(ep, STA);
1632 epctrl = usba_ep_readl(ep, CTL);
1633 }
1634 if ((epstatus & epctrl) & USBA_RX_BK_RDY) {
1635 DBG(DBG_BUS, "%s: RX data ready\n", ep->ep.name);
1636 receive_data(ep);
1637 usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY);
1638 }
1639}
1640
1641static void usba_dma_irq(struct usba_udc *udc, struct usba_ep *ep)
1642{
1643 struct usba_request *req;
1644 u32 status, control, pending;
1645
1646 status = usba_dma_readl(ep, STATUS);
1647 control = usba_dma_readl(ep, CONTROL);
1648#ifdef CONFIG_USB_GADGET_DEBUG_FS
1649 ep->last_dma_status = status;
1650#endif
1651 pending = status & control;
1652 DBG(DBG_INT | DBG_DMA, "dma irq, s/%#08x, c/%#08x\n", status, control);
1653
1654 if (status & USBA_DMA_CH_EN) {
1655 dev_err(&udc->pdev->dev,
1656 "DMA_CH_EN is set after transfer is finished!\n");
1657 dev_err(&udc->pdev->dev,
1658 "status=%#08x, pending=%#08x, control=%#08x\n",
1659 status, pending, control);
1660
1661 /*
1662 * try to pretend nothing happened. We might have to
1663 * do something here...
1664 */
1665 }
1666
1667 if (list_empty(&ep->queue))
1668 /* Might happen if a reset comes along at the right moment */
1669 return;
1670
1671 if (pending & (USBA_DMA_END_TR_ST | USBA_DMA_END_BUF_ST)) {
1672 req = list_entry(ep->queue.next, struct usba_request, queue);
1673 usba_update_req(ep, req, status);
1674
1675 list_del_init(&req->queue);
1676 submit_next_request(ep);
1677 request_complete(ep, req, 0);
1678 }
1679}
1680
1681static irqreturn_t usba_udc_irq(int irq, void *devid)
1682{
1683 struct usba_udc *udc = devid;
1684 u32 status;
1685 u32 dma_status;
1686 u32 ep_status;
1687
1688 spin_lock(&udc->lock);
1689
1690 status = usba_readl(udc, INT_STA);
1691 DBG(DBG_INT, "irq, status=%#08x\n", status);
1692
1693 if (status & USBA_DET_SUSPEND) {
1694 usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
1695 DBG(DBG_BUS, "Suspend detected\n");
1696 if (udc->gadget.speed != USB_SPEED_UNKNOWN
1697 && udc->driver && udc->driver->suspend) {
1698 spin_unlock(&udc->lock);
1699 udc->driver->suspend(&udc->gadget);
1700 spin_lock(&udc->lock);
1701 }
1702 }
1703
1704 if (status & USBA_WAKE_UP) {
1705 usba_writel(udc, INT_CLR, USBA_WAKE_UP);
1706 DBG(DBG_BUS, "Wake Up CPU detected\n");
1707 }
1708
1709 if (status & USBA_END_OF_RESUME) {
1710 usba_writel(udc, INT_CLR, USBA_END_OF_RESUME);
1711 DBG(DBG_BUS, "Resume detected\n");
1712 if (udc->gadget.speed != USB_SPEED_UNKNOWN
1713 && udc->driver && udc->driver->resume) {
1714 spin_unlock(&udc->lock);
1715 udc->driver->resume(&udc->gadget);
1716 spin_lock(&udc->lock);
1717 }
1718 }
1719
1720 dma_status = USBA_BFEXT(DMA_INT, status);
1721 if (dma_status) {
1722 int i;
1723
1724 for (i = 1; i < USBA_NR_ENDPOINTS; i++)
1725 if (dma_status & (1 << i))
1726 usba_dma_irq(udc, &usba_ep[i]);
1727 }
1728
1729 ep_status = USBA_BFEXT(EPT_INT, status);
1730 if (ep_status) {
1731 int i;
1732
1733 for (i = 0; i < USBA_NR_ENDPOINTS; i++)
1734 if (ep_status & (1 << i)) {
1735 if (ep_is_control(&usba_ep[i]))
1736 usba_control_irq(udc, &usba_ep[i]);
1737 else
1738 usba_ep_irq(udc, &usba_ep[i]);
1739 }
1740 }
1741
1742 if (status & USBA_END_OF_RESET) {
1743 struct usba_ep *ep0;
1744
1745 usba_writel(udc, INT_CLR, USBA_END_OF_RESET);
1746 reset_all_endpoints(udc);
1747
1748 if (status & USBA_HIGH_SPEED) {
1749 DBG(DBG_BUS, "High-speed bus reset detected\n");
1750 udc->gadget.speed = USB_SPEED_HIGH;
1751 } else {
1752 DBG(DBG_BUS, "Full-speed bus reset detected\n");
1753 udc->gadget.speed = USB_SPEED_FULL;
1754 }
1755
1756 ep0 = &usba_ep[0];
1757 ep0->desc = &usba_ep0_desc;
1758 ep0->state = WAIT_FOR_SETUP;
1759 usba_ep_writel(ep0, CFG,
1760 (USBA_BF(EPT_SIZE, EP0_EPT_SIZE)
1761 | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL)
1762 | USBA_BF(BK_NUMBER, USBA_BK_NUMBER_ONE)));
1763 usba_ep_writel(ep0, CTL_ENB,
1764 USBA_EPT_ENABLE | USBA_RX_SETUP);
1765 usba_writel(udc, INT_ENB,
1766 (usba_readl(udc, INT_ENB)
1767 | USBA_BF(EPT_INT, 1)
1768 | USBA_DET_SUSPEND
1769 | USBA_END_OF_RESUME));
1770
1771 if (!(usba_ep_readl(ep0, CFG) & USBA_EPT_MAPPED))
1772 dev_warn(&udc->pdev->dev,
1773 "WARNING: EP0 configuration is invalid!\n");
1774 }
1775
1776 spin_unlock(&udc->lock);
1777
1778 return IRQ_HANDLED;
1779}
1780
1781static irqreturn_t usba_vbus_irq(int irq, void *devid)
1782{
1783 struct usba_udc *udc = devid;
1784 int vbus;
1785
1786 /* debounce */
1787 udelay(10);
1788
1789 spin_lock(&udc->lock);
1790
1791 /* May happen if Vbus pin toggles during probe() */
1792 if (!udc->driver)
1793 goto out;
1794
1795 vbus = gpio_get_value(udc->vbus_pin);
1796 if (vbus != udc->vbus_prev) {
1797 if (vbus) {
1798 usba_writel(udc, CTRL, USBA_EN_USBA);
1799 usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
1800 } else {
1801 udc->gadget.speed = USB_SPEED_UNKNOWN;
1802 reset_all_endpoints(udc);
1803 usba_writel(udc, CTRL, 0);
1804 spin_unlock(&udc->lock);
1805 udc->driver->disconnect(&udc->gadget);
1806 spin_lock(&udc->lock);
1807 }
1808 udc->vbus_prev = vbus;
1809 }
1810
1811out:
1812 spin_unlock(&udc->lock);
1813
1814 return IRQ_HANDLED;
1815}
1816
1817int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1818{
1819 struct usba_udc *udc = &the_udc;
1820 unsigned long flags;
1821 int ret;
1822
1823 if (!udc->pdev)
1824 return -ENODEV;
1825
1826 spin_lock_irqsave(&udc->lock, flags);
1827 if (udc->driver) {
1828 spin_unlock_irqrestore(&udc->lock, flags);
1829 return -EBUSY;
1830 }
1831
1832 udc->devstatus = 1 << USB_DEVICE_SELF_POWERED;
1833 udc->driver = driver;
1834 udc->gadget.dev.driver = &driver->driver;
1835 spin_unlock_irqrestore(&udc->lock, flags);
1836
1837 clk_enable(udc->pclk);
1838 clk_enable(udc->hclk);
1839
1840 ret = driver->bind(&udc->gadget);
1841 if (ret) {
1842 DBG(DBG_ERR, "Could not bind to driver %s: error %d\n",
1843 driver->driver.name, ret);
1844 goto err_driver_bind;
1845 }
1846
1847 DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name);
1848
1849 udc->vbus_prev = 0;
1850 if (udc->vbus_pin != -1)
1851 enable_irq(gpio_to_irq(udc->vbus_pin));
1852
1853 /* If Vbus is present, enable the controller and wait for reset */
1854 spin_lock_irqsave(&udc->lock, flags);
1855 if (vbus_is_present(udc) && udc->vbus_prev == 0) {
1856 usba_writel(udc, CTRL, USBA_EN_USBA);
1857 usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
1858 }
1859 spin_unlock_irqrestore(&udc->lock, flags);
1860
1861 return 0;
1862
1863err_driver_bind:
1864 udc->driver = NULL;
1865 udc->gadget.dev.driver = NULL;
1866 return ret;
1867}
1868EXPORT_SYMBOL(usb_gadget_register_driver);
1869
1870int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1871{
1872 struct usba_udc *udc = &the_udc;
1873 unsigned long flags;
1874
1875 if (!udc->pdev)
1876 return -ENODEV;
1877 if (driver != udc->driver)
1878 return -EINVAL;
1879
1880 if (udc->vbus_pin != -1)
1881 disable_irq(gpio_to_irq(udc->vbus_pin));
1882
1883 spin_lock_irqsave(&udc->lock, flags);
1884 udc->gadget.speed = USB_SPEED_UNKNOWN;
1885 reset_all_endpoints(udc);
1886 spin_unlock_irqrestore(&udc->lock, flags);
1887
1888 /* This will also disable the DP pullup */
1889 usba_writel(udc, CTRL, 0);
1890
1891 driver->unbind(&udc->gadget);
1892 udc->gadget.dev.driver = NULL;
1893 udc->driver = NULL;
1894
1895 clk_disable(udc->hclk);
1896 clk_disable(udc->pclk);
1897
1898 DBG(DBG_GADGET, "unregistered driver `%s'\n", driver->driver.name);
1899
1900 return 0;
1901}
1902EXPORT_SYMBOL(usb_gadget_unregister_driver);
1903
1904static int __init usba_udc_probe(struct platform_device *pdev)
1905{
1906 struct usba_platform_data *pdata = pdev->dev.platform_data;
1907 struct resource *regs, *fifo;
1908 struct clk *pclk, *hclk;
1909 struct usba_udc *udc = &the_udc;
1910 int irq, ret, i;
1911
1912 regs = platform_get_resource(pdev, IORESOURCE_MEM, CTRL_IOMEM_ID);
1913 fifo = platform_get_resource(pdev, IORESOURCE_MEM, FIFO_IOMEM_ID);
1914 if (!regs || !fifo)
1915 return -ENXIO;
1916
1917 irq = platform_get_irq(pdev, 0);
1918 if (irq < 0)
1919 return irq;
1920
1921 pclk = clk_get(&pdev->dev, "pclk");
1922 if (IS_ERR(pclk))
1923 return PTR_ERR(pclk);
1924 hclk = clk_get(&pdev->dev, "hclk");
1925 if (IS_ERR(hclk)) {
1926 ret = PTR_ERR(hclk);
1927 goto err_get_hclk;
1928 }
1929
1930 udc->pdev = pdev;
1931 udc->pclk = pclk;
1932 udc->hclk = hclk;
1933 udc->vbus_pin = -1;
1934
1935 ret = -ENOMEM;
1936 udc->regs = ioremap(regs->start, regs->end - regs->start + 1);
1937 if (!udc->regs) {
1938 dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n");
1939 goto err_map_regs;
1940 }
1941 dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n",
1942 (unsigned long)regs->start, udc->regs);
1943 udc->fifo = ioremap(fifo->start, fifo->end - fifo->start + 1);
1944 if (!udc->fifo) {
1945 dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n");
1946 goto err_map_fifo;
1947 }
1948 dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n",
1949 (unsigned long)fifo->start, udc->fifo);
1950
1951 device_initialize(&udc->gadget.dev);
1952 udc->gadget.dev.parent = &pdev->dev;
1953 udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
1954
1955 platform_set_drvdata(pdev, udc);
1956
1957 /* Make sure we start from a clean slate */
1958 clk_enable(pclk);
1959 usba_writel(udc, CTRL, 0);
1960 clk_disable(pclk);
1961
1962 INIT_LIST_HEAD(&usba_ep[0].ep.ep_list);
1963 usba_ep[0].ep_regs = udc->regs + USBA_EPT_BASE(0);
1964 usba_ep[0].dma_regs = udc->regs + USBA_DMA_BASE(0);
1965 usba_ep[0].fifo = udc->fifo + USBA_FIFO_BASE(0);
1966 for (i = 1; i < ARRAY_SIZE(usba_ep); i++) {
1967 struct usba_ep *ep = &usba_ep[i];
1968
1969 ep->ep_regs = udc->regs + USBA_EPT_BASE(i);
1970 ep->dma_regs = udc->regs + USBA_DMA_BASE(i);
1971 ep->fifo = udc->fifo + USBA_FIFO_BASE(i);
1972
1973 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
1974 }
1975
1976 ret = request_irq(irq, usba_udc_irq, 0, "atmel_usba_udc", udc);
1977 if (ret) {
1978 dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n",
1979 irq, ret);
1980 goto err_request_irq;
1981 }
1982 udc->irq = irq;
1983
1984 ret = device_add(&udc->gadget.dev);
1985 if (ret) {
1986 dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret);
1987 goto err_device_add;
1988 }
1989
1990 if (pdata && pdata->vbus_pin != GPIO_PIN_NONE) {
1991 if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) {
1992 udc->vbus_pin = pdata->vbus_pin;
1993
1994 ret = request_irq(gpio_to_irq(udc->vbus_pin),
1995 usba_vbus_irq, 0,
1996 "atmel_usba_udc", udc);
1997 if (ret) {
1998 gpio_free(udc->vbus_pin);
1999 udc->vbus_pin = -1;
2000 dev_warn(&udc->pdev->dev,
2001 "failed to request vbus irq; "
2002 "assuming always on\n");
2003 } else {
2004 disable_irq(gpio_to_irq(udc->vbus_pin));
2005 }
2006 }
2007 }
2008
2009 usba_init_debugfs(udc);
2010 for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
2011 usba_ep_init_debugfs(udc, &usba_ep[i]);
2012
2013 return 0;
2014
2015err_device_add:
2016 free_irq(irq, udc);
2017err_request_irq:
2018 iounmap(udc->fifo);
2019err_map_fifo:
2020 iounmap(udc->regs);
2021err_map_regs:
2022 clk_put(hclk);
2023err_get_hclk:
2024 clk_put(pclk);
2025
2026 platform_set_drvdata(pdev, NULL);
2027
2028 return ret;
2029}
2030
2031static int __exit usba_udc_remove(struct platform_device *pdev)
2032{
2033 struct usba_udc *udc;
2034 int i;
2035
2036 udc = platform_get_drvdata(pdev);
2037
2038 for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
2039 usba_ep_cleanup_debugfs(&usba_ep[i]);
2040 usba_cleanup_debugfs(udc);
2041
2042 if (udc->vbus_pin != -1)
2043 gpio_free(udc->vbus_pin);
2044
2045 free_irq(udc->irq, udc);
2046 iounmap(udc->fifo);
2047 iounmap(udc->regs);
2048 clk_put(udc->hclk);
2049 clk_put(udc->pclk);
2050
2051 device_unregister(&udc->gadget.dev);
2052
2053 return 0;
2054}
2055
2056static struct platform_driver udc_driver = {
2057 .remove = __exit_p(usba_udc_remove),
2058 .driver = {
2059 .name = "atmel_usba_udc",
2060 },
2061};
2062
2063static int __init udc_init(void)
2064{
2065 return platform_driver_probe(&udc_driver, usba_udc_probe);
2066}
2067module_init(udc_init);
2068
2069static void __exit udc_exit(void)
2070{
2071 platform_driver_unregister(&udc_driver);
2072}
2073module_exit(udc_exit);
2074
2075MODULE_DESCRIPTION("Atmel USBA UDC driver");
2076MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
2077MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/atmel_usba_udc.h b/drivers/usb/gadget/atmel_usba_udc.h
new file mode 100644
index 000000000000..a68304e31a68
--- /dev/null
+++ b/drivers/usb/gadget/atmel_usba_udc.h
@@ -0,0 +1,352 @@
1/*
2 * Driver for the Atmel USBA high speed USB device controller
3 *
4 * Copyright (C) 2005-2007 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#ifndef __LINUX_USB_GADGET_USBA_UDC_H__
11#define __LINUX_USB_GADGET_USBA_UDC_H__
12
13/* USB register offsets */
14#define USBA_CTRL 0x0000
15#define USBA_FNUM 0x0004
16#define USBA_INT_ENB 0x0010
17#define USBA_INT_STA 0x0014
18#define USBA_INT_CLR 0x0018
19#define USBA_EPT_RST 0x001c
20#define USBA_TST 0x00e0
21
22/* USB endpoint register offsets */
23#define USBA_EPT_CFG 0x0000
24#define USBA_EPT_CTL_ENB 0x0004
25#define USBA_EPT_CTL_DIS 0x0008
26#define USBA_EPT_CTL 0x000c
27#define USBA_EPT_SET_STA 0x0014
28#define USBA_EPT_CLR_STA 0x0018
29#define USBA_EPT_STA 0x001c
30
31/* USB DMA register offsets */
32#define USBA_DMA_NXT_DSC 0x0000
33#define USBA_DMA_ADDRESS 0x0004
34#define USBA_DMA_CONTROL 0x0008
35#define USBA_DMA_STATUS 0x000c
36
37/* Bitfields in CTRL */
38#define USBA_DEV_ADDR_OFFSET 0
39#define USBA_DEV_ADDR_SIZE 7
40#define USBA_FADDR_EN (1 << 7)
41#define USBA_EN_USBA (1 << 8)
42#define USBA_DETACH (1 << 9)
43#define USBA_REMOTE_WAKE_UP (1 << 10)
44
45/* Bitfields in FNUM */
46#define USBA_MICRO_FRAME_NUM_OFFSET 0
47#define USBA_MICRO_FRAME_NUM_SIZE 3
48#define USBA_FRAME_NUMBER_OFFSET 3
49#define USBA_FRAME_NUMBER_SIZE 11
50#define USBA_FRAME_NUM_ERROR (1 << 31)
51
52/* Bitfields in INT_ENB/INT_STA/INT_CLR */
53#define USBA_HIGH_SPEED (1 << 0)
54#define USBA_DET_SUSPEND (1 << 1)
55#define USBA_MICRO_SOF (1 << 2)
56#define USBA_SOF (1 << 3)
57#define USBA_END_OF_RESET (1 << 4)
58#define USBA_WAKE_UP (1 << 5)
59#define USBA_END_OF_RESUME (1 << 6)
60#define USBA_UPSTREAM_RESUME (1 << 7)
61#define USBA_EPT_INT_OFFSET 8
62#define USBA_EPT_INT_SIZE 16
63#define USBA_DMA_INT_OFFSET 24
64#define USBA_DMA_INT_SIZE 8
65
66/* Bitfields in EPT_RST */
67#define USBA_RST_OFFSET 0
68#define USBA_RST_SIZE 16
69
70/* Bitfields in USBA_TST */
71#define USBA_SPEED_CFG_OFFSET 0
72#define USBA_SPEED_CFG_SIZE 2
73#define USBA_TST_J_MODE (1 << 2)
74#define USBA_TST_K_MODE (1 << 3)
75#define USBA_TST_PKT_MODE (1 << 4)
76#define USBA_OPMODE2 (1 << 5)
77
78/* Bitfields in EPT_CFG */
79#define USBA_EPT_SIZE_OFFSET 0
80#define USBA_EPT_SIZE_SIZE 3
81#define USBA_EPT_DIR_IN (1 << 3)
82#define USBA_EPT_TYPE_OFFSET 4
83#define USBA_EPT_TYPE_SIZE 2
84#define USBA_BK_NUMBER_OFFSET 6
85#define USBA_BK_NUMBER_SIZE 2
86#define USBA_NB_TRANS_OFFSET 8
87#define USBA_NB_TRANS_SIZE 2
88#define USBA_EPT_MAPPED (1 << 31)
89
90/* Bitfields in EPT_CTL/EPT_CTL_ENB/EPT_CTL_DIS */
91#define USBA_EPT_ENABLE (1 << 0)
92#define USBA_AUTO_VALID (1 << 1)
93#define USBA_INTDIS_DMA (1 << 3)
94#define USBA_NYET_DIS (1 << 4)
95#define USBA_DATAX_RX (1 << 6)
96#define USBA_MDATA_RX (1 << 7)
97/* Bits 8-15 and 31 enable interrupts for respective bits in EPT_STA */
98#define USBA_BUSY_BANK_IE (1 << 18)
99
100/* Bitfields in EPT_SET_STA/EPT_CLR_STA/EPT_STA */
101#define USBA_FORCE_STALL (1 << 5)
102#define USBA_TOGGLE_CLR (1 << 6)
103#define USBA_TOGGLE_SEQ_OFFSET 6
104#define USBA_TOGGLE_SEQ_SIZE 2
105#define USBA_ERR_OVFLW (1 << 8)
106#define USBA_RX_BK_RDY (1 << 9)
107#define USBA_KILL_BANK (1 << 9)
108#define USBA_TX_COMPLETE (1 << 10)
109#define USBA_TX_PK_RDY (1 << 11)
110#define USBA_ISO_ERR_TRANS (1 << 11)
111#define USBA_RX_SETUP (1 << 12)
112#define USBA_ISO_ERR_FLOW (1 << 12)
113#define USBA_STALL_SENT (1 << 13)
114#define USBA_ISO_ERR_CRC (1 << 13)
115#define USBA_ISO_ERR_NBTRANS (1 << 13)
116#define USBA_NAK_IN (1 << 14)
117#define USBA_ISO_ERR_FLUSH (1 << 14)
118#define USBA_NAK_OUT (1 << 15)
119#define USBA_CURRENT_BANK_OFFSET 16
120#define USBA_CURRENT_BANK_SIZE 2
121#define USBA_BUSY_BANKS_OFFSET 18
122#define USBA_BUSY_BANKS_SIZE 2
123#define USBA_BYTE_COUNT_OFFSET 20
124#define USBA_BYTE_COUNT_SIZE 11
125#define USBA_SHORT_PACKET (1 << 31)
126
127/* Bitfields in DMA_CONTROL */
128#define USBA_DMA_CH_EN (1 << 0)
129#define USBA_DMA_LINK (1 << 1)
130#define USBA_DMA_END_TR_EN (1 << 2)
131#define USBA_DMA_END_BUF_EN (1 << 3)
132#define USBA_DMA_END_TR_IE (1 << 4)
133#define USBA_DMA_END_BUF_IE (1 << 5)
134#define USBA_DMA_DESC_LOAD_IE (1 << 6)
135#define USBA_DMA_BURST_LOCK (1 << 7)
136#define USBA_DMA_BUF_LEN_OFFSET 16
137#define USBA_DMA_BUF_LEN_SIZE 16
138
139/* Bitfields in DMA_STATUS */
140#define USBA_DMA_CH_ACTIVE (1 << 1)
141#define USBA_DMA_END_TR_ST (1 << 4)
142#define USBA_DMA_END_BUF_ST (1 << 5)
143#define USBA_DMA_DESC_LOAD_ST (1 << 6)
144
145/* Constants for SPEED_CFG */
146#define USBA_SPEED_CFG_NORMAL 0
147#define USBA_SPEED_CFG_FORCE_HIGH 2
148#define USBA_SPEED_CFG_FORCE_FULL 3
149
150/* Constants for EPT_SIZE */
151#define USBA_EPT_SIZE_8 0
152#define USBA_EPT_SIZE_16 1
153#define USBA_EPT_SIZE_32 2
154#define USBA_EPT_SIZE_64 3
155#define USBA_EPT_SIZE_128 4
156#define USBA_EPT_SIZE_256 5
157#define USBA_EPT_SIZE_512 6
158#define USBA_EPT_SIZE_1024 7
159
160/* Constants for EPT_TYPE */
161#define USBA_EPT_TYPE_CONTROL 0
162#define USBA_EPT_TYPE_ISO 1
163#define USBA_EPT_TYPE_BULK 2
164#define USBA_EPT_TYPE_INT 3
165
166/* Constants for BK_NUMBER */
167#define USBA_BK_NUMBER_ZERO 0
168#define USBA_BK_NUMBER_ONE 1
169#define USBA_BK_NUMBER_DOUBLE 2
170#define USBA_BK_NUMBER_TRIPLE 3
171
172/* Bit manipulation macros */
173#define USBA_BF(name, value) \
174 (((value) & ((1 << USBA_##name##_SIZE) - 1)) \
175 << USBA_##name##_OFFSET)
176#define USBA_BFEXT(name, value) \
177 (((value) >> USBA_##name##_OFFSET) \
178 & ((1 << USBA_##name##_SIZE) - 1))
179#define USBA_BFINS(name, value, old) \
180 (((old) & ~(((1 << USBA_##name##_SIZE) - 1) \
181 << USBA_##name##_OFFSET)) \
182 | USBA_BF(name, value))
183
184/* Register access macros */
185#define usba_readl(udc, reg) \
186 __raw_readl((udc)->regs + USBA_##reg)
187#define usba_writel(udc, reg, value) \
188 __raw_writel((value), (udc)->regs + USBA_##reg)
189#define usba_ep_readl(ep, reg) \
190 __raw_readl((ep)->ep_regs + USBA_EPT_##reg)
191#define usba_ep_writel(ep, reg, value) \
192 __raw_writel((value), (ep)->ep_regs + USBA_EPT_##reg)
193#define usba_dma_readl(ep, reg) \
194 __raw_readl((ep)->dma_regs + USBA_DMA_##reg)
195#define usba_dma_writel(ep, reg, value) \
196 __raw_writel((value), (ep)->dma_regs + USBA_DMA_##reg)
197
198/* Calculate base address for a given endpoint or DMA controller */
199#define USBA_EPT_BASE(x) (0x100 + (x) * 0x20)
200#define USBA_DMA_BASE(x) (0x300 + (x) * 0x10)
201#define USBA_FIFO_BASE(x) ((x) << 16)
202
203/* Synth parameters */
204#define USBA_NR_ENDPOINTS 7
205
206#define EP0_FIFO_SIZE 64
207#define EP0_EPT_SIZE USBA_EPT_SIZE_64
208#define EP0_NR_BANKS 1
209
210/*
211 * REVISIT: Try to eliminate this value. Can we rely on req->mapped to
212 * provide this information?
213 */
214#define DMA_ADDR_INVALID (~(dma_addr_t)0)
215
216#define FIFO_IOMEM_ID 0
217#define CTRL_IOMEM_ID 1
218
219#ifdef DEBUG
220#define DBG_ERR 0x0001 /* report all error returns */
221#define DBG_HW 0x0002 /* debug hardware initialization */
222#define DBG_GADGET 0x0004 /* calls to/from gadget driver */
223#define DBG_INT 0x0008 /* interrupts */
224#define DBG_BUS 0x0010 /* report changes in bus state */
225#define DBG_QUEUE 0x0020 /* debug request queue processing */
226#define DBG_FIFO 0x0040 /* debug FIFO contents */
227#define DBG_DMA 0x0080 /* debug DMA handling */
228#define DBG_REQ 0x0100 /* print out queued request length */
229#define DBG_ALL 0xffff
230#define DBG_NONE 0x0000
231
232#define DEBUG_LEVEL (DBG_ERR)
233#define DBG(level, fmt, ...) \
234 do { \
235 if ((level) & DEBUG_LEVEL) \
236 printk(KERN_DEBUG "udc: " fmt, ## __VA_ARGS__); \
237 } while (0)
238#else
239#define DBG(level, fmt...)
240#endif
241
242enum usba_ctrl_state {
243 WAIT_FOR_SETUP,
244 DATA_STAGE_IN,
245 DATA_STAGE_OUT,
246 STATUS_STAGE_IN,
247 STATUS_STAGE_OUT,
248 STATUS_STAGE_ADDR,
249 STATUS_STAGE_TEST,
250};
251/*
252 EP_STATE_IDLE,
253 EP_STATE_SETUP,
254 EP_STATE_IN_DATA,
255 EP_STATE_OUT_DATA,
256 EP_STATE_SET_ADDR_STATUS,
257 EP_STATE_RX_STATUS,
258 EP_STATE_TX_STATUS,
259 EP_STATE_HALT,
260*/
261
262struct usba_dma_desc {
263 dma_addr_t next;
264 dma_addr_t addr;
265 u32 ctrl;
266};
267
268struct usba_ep {
269 int state;
270 void __iomem *ep_regs;
271 void __iomem *dma_regs;
272 void __iomem *fifo;
273 struct usb_ep ep;
274 struct usba_udc *udc;
275
276 struct list_head queue;
277 const struct usb_endpoint_descriptor *desc;
278
279 u16 fifo_size;
280 u8 nr_banks;
281 u8 index;
282 unsigned int can_dma:1;
283 unsigned int can_isoc:1;
284 unsigned int is_isoc:1;
285 unsigned int is_in:1;
286
287#ifdef CONFIG_USB_GADGET_DEBUG_FS
288 u32 last_dma_status;
289 struct dentry *debugfs_dir;
290 struct dentry *debugfs_queue;
291 struct dentry *debugfs_dma_status;
292 struct dentry *debugfs_state;
293#endif
294};
295
296struct usba_request {
297 struct usb_request req;
298 struct list_head queue;
299
300 u32 ctrl;
301
302 unsigned int submitted:1;
303 unsigned int last_transaction:1;
304 unsigned int using_dma:1;
305 unsigned int mapped:1;
306};
307
308struct usba_udc {
309 /* Protect hw registers from concurrent modifications */
310 spinlock_t lock;
311
312 void __iomem *regs;
313 void __iomem *fifo;
314
315 struct usb_gadget gadget;
316 struct usb_gadget_driver *driver;
317 struct platform_device *pdev;
318 int irq;
319 int vbus_pin;
320 struct clk *pclk;
321 struct clk *hclk;
322
323 u16 devstatus;
324
325 u16 test_mode;
326 int vbus_prev;
327
328#ifdef CONFIG_USB_GADGET_DEBUG_FS
329 struct dentry *debugfs_root;
330 struct dentry *debugfs_regs;
331#endif
332};
333
334static inline struct usba_ep *to_usba_ep(struct usb_ep *ep)
335{
336 return container_of(ep, struct usba_ep, ep);
337}
338
339static inline struct usba_request *to_usba_req(struct usb_request *req)
340{
341 return container_of(req, struct usba_request, req);
342}
343
344static inline struct usba_udc *to_usba_udc(struct usb_gadget *gadget)
345{
346 return container_of(gadget, struct usba_udc, gadget);
347}
348
349#define ep_is_control(ep) ((ep)->index == 0)
350#define ep_is_idle(ep) ((ep)->state == EP_STATE_IDLE)
351
352#endif /* __LINUX_USB_GADGET_USBA_UDC_H */
diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
index c6760aee1e5c..a4e54b2743f0 100644
--- a/drivers/usb/gadget/config.c
+++ b/drivers/usb/gadget/config.c
@@ -25,7 +25,7 @@
25#include <linux/device.h> 25#include <linux/device.h>
26 26
27#include <linux/usb/ch9.h> 27#include <linux/usb/ch9.h>
28#include <linux/usb_gadget.h> 28#include <linux/usb/gadget.h>
29 29
30 30
31/** 31/**
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index d008d1360a7a..9db2482bdfa2 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -46,7 +46,7 @@
46#include <linux/interrupt.h> 46#include <linux/interrupt.h>
47#include <linux/platform_device.h> 47#include <linux/platform_device.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <linux/usb_gadget.h> 49#include <linux/usb/gadget.h>
50 50
51#include <asm/byteorder.h> 51#include <asm/byteorder.h>
52#include <asm/io.h> 52#include <asm/io.h>
@@ -962,13 +962,13 @@ static struct platform_driver dummy_udc_driver = {
962 962
963static int dummy_urb_enqueue ( 963static int dummy_urb_enqueue (
964 struct usb_hcd *hcd, 964 struct usb_hcd *hcd,
965 struct usb_host_endpoint *ep,
966 struct urb *urb, 965 struct urb *urb,
967 gfp_t mem_flags 966 gfp_t mem_flags
968) { 967) {
969 struct dummy *dum; 968 struct dummy *dum;
970 struct urbp *urbp; 969 struct urbp *urbp;
971 unsigned long flags; 970 unsigned long flags;
971 int rc;
972 972
973 if (!urb->transfer_buffer && urb->transfer_buffer_length) 973 if (!urb->transfer_buffer && urb->transfer_buffer_length)
974 return -EINVAL; 974 return -EINVAL;
@@ -980,6 +980,11 @@ static int dummy_urb_enqueue (
980 980
981 dum = hcd_to_dummy (hcd); 981 dum = hcd_to_dummy (hcd);
982 spin_lock_irqsave (&dum->lock, flags); 982 spin_lock_irqsave (&dum->lock, flags);
983 rc = usb_hcd_link_urb_to_ep(hcd, urb);
984 if (rc) {
985 kfree(urbp);
986 goto done;
987 }
983 988
984 if (!dum->udev) { 989 if (!dum->udev) {
985 dum->udev = urb->dev; 990 dum->udev = urb->dev;
@@ -996,36 +1001,35 @@ static int dummy_urb_enqueue (
996 if (!timer_pending (&dum->timer)) 1001 if (!timer_pending (&dum->timer))
997 mod_timer (&dum->timer, jiffies + 1); 1002 mod_timer (&dum->timer, jiffies + 1);
998 1003
999 spin_unlock_irqrestore (&dum->lock, flags); 1004 done:
1000 return 0; 1005 spin_unlock_irqrestore(&dum->lock, flags);
1006 return rc;
1001} 1007}
1002 1008
1003static int dummy_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 1009static int dummy_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1004{ 1010{
1005 struct dummy *dum; 1011 struct dummy *dum;
1006 unsigned long flags; 1012 unsigned long flags;
1013 int rc;
1007 1014
1008 /* giveback happens automatically in timer callback, 1015 /* giveback happens automatically in timer callback,
1009 * so make sure the callback happens */ 1016 * so make sure the callback happens */
1010 dum = hcd_to_dummy (hcd); 1017 dum = hcd_to_dummy (hcd);
1011 spin_lock_irqsave (&dum->lock, flags); 1018 spin_lock_irqsave (&dum->lock, flags);
1012 if (dum->rh_state != DUMMY_RH_RUNNING && !list_empty(&dum->urbp_list)) 1019
1020 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1021 if (!rc && dum->rh_state != DUMMY_RH_RUNNING &&
1022 !list_empty(&dum->urbp_list))
1013 mod_timer (&dum->timer, jiffies); 1023 mod_timer (&dum->timer, jiffies);
1014 spin_unlock_irqrestore (&dum->lock, flags);
1015 return 0;
1016}
1017 1024
1018static void maybe_set_status (struct urb *urb, int status) 1025 spin_unlock_irqrestore (&dum->lock, flags);
1019{ 1026 return rc;
1020 spin_lock (&urb->lock);
1021 if (urb->status == -EINPROGRESS)
1022 urb->status = status;
1023 spin_unlock (&urb->lock);
1024} 1027}
1025 1028
1026/* transfer up to a frame's worth; caller must own lock */ 1029/* transfer up to a frame's worth; caller must own lock */
1027static int 1030static int
1028transfer (struct dummy *dum, struct urb *urb, struct dummy_ep *ep, int limit) 1031transfer(struct dummy *dum, struct urb *urb, struct dummy_ep *ep, int limit,
1032 int *status)
1029{ 1033{
1030 struct dummy_request *req; 1034 struct dummy_request *req;
1031 1035
@@ -1088,24 +1092,20 @@ top:
1088 * 1092 *
1089 * partially filling a buffer optionally blocks queue advances 1093 * partially filling a buffer optionally blocks queue advances
1090 * (so completion handlers can clean up the queue) but we don't 1094 * (so completion handlers can clean up the queue) but we don't
1091 * need to emulate such data-in-flight. so we only show part 1095 * need to emulate such data-in-flight.
1092 * of the URB_SHORT_NOT_OK effect: completion status.
1093 */ 1096 */
1094 if (is_short) { 1097 if (is_short) {
1095 if (host_len == dev_len) { 1098 if (host_len == dev_len) {
1096 req->req.status = 0; 1099 req->req.status = 0;
1097 maybe_set_status (urb, 0); 1100 *status = 0;
1098 } else if (to_host) { 1101 } else if (to_host) {
1099 req->req.status = 0; 1102 req->req.status = 0;
1100 if (dev_len > host_len) 1103 if (dev_len > host_len)
1101 maybe_set_status (urb, -EOVERFLOW); 1104 *status = -EOVERFLOW;
1102 else 1105 else
1103 maybe_set_status (urb, 1106 *status = 0;
1104 (urb->transfer_flags
1105 & URB_SHORT_NOT_OK)
1106 ? -EREMOTEIO : 0);
1107 } else if (!to_host) { 1107 } else if (!to_host) {
1108 maybe_set_status (urb, 0); 1108 *status = 0;
1109 if (host_len > dev_len) 1109 if (host_len > dev_len)
1110 req->req.status = -EOVERFLOW; 1110 req->req.status = -EOVERFLOW;
1111 else 1111 else
@@ -1119,9 +1119,8 @@ top:
1119 req->req.status = 0; 1119 req->req.status = 0;
1120 if (urb->transfer_buffer_length == urb->actual_length 1120 if (urb->transfer_buffer_length == urb->actual_length
1121 && !(urb->transfer_flags 1121 && !(urb->transfer_flags
1122 & URB_ZERO_PACKET)) { 1122 & URB_ZERO_PACKET))
1123 maybe_set_status (urb, 0); 1123 *status = 0;
1124 }
1125 } 1124 }
1126 1125
1127 /* device side completion --> continuable */ 1126 /* device side completion --> continuable */
@@ -1137,7 +1136,7 @@ top:
1137 } 1136 }
1138 1137
1139 /* host side completion --> terminate */ 1138 /* host side completion --> terminate */
1140 if (urb->status != -EINPROGRESS) 1139 if (*status != -EINPROGRESS)
1141 break; 1140 break;
1142 1141
1143 /* rescan to continue with any other queued i/o */ 1142 /* rescan to continue with any other queued i/o */
@@ -1248,12 +1247,12 @@ restart:
1248 u8 address; 1247 u8 address;
1249 struct dummy_ep *ep = NULL; 1248 struct dummy_ep *ep = NULL;
1250 int type; 1249 int type;
1250 int status = -EINPROGRESS;
1251 1251
1252 urb = urbp->urb; 1252 urb = urbp->urb;
1253 if (urb->status != -EINPROGRESS) { 1253 if (urb->unlinked)
1254 /* likely it was just unlinked */
1255 goto return_urb; 1254 goto return_urb;
1256 } else if (dum->rh_state != DUMMY_RH_RUNNING) 1255 else if (dum->rh_state != DUMMY_RH_RUNNING)
1257 continue; 1256 continue;
1258 type = usb_pipetype (urb->pipe); 1257 type = usb_pipetype (urb->pipe);
1259 1258
@@ -1274,7 +1273,7 @@ restart:
1274 dev_dbg (dummy_dev(dum), 1273 dev_dbg (dummy_dev(dum),
1275 "no ep configured for urb %p\n", 1274 "no ep configured for urb %p\n",
1276 urb); 1275 urb);
1277 maybe_set_status (urb, -EPROTO); 1276 status = -EPROTO;
1278 goto return_urb; 1277 goto return_urb;
1279 } 1278 }
1280 1279
@@ -1289,7 +1288,7 @@ restart:
1289 /* NOTE: must not be iso! */ 1288 /* NOTE: must not be iso! */
1290 dev_dbg (dummy_dev(dum), "ep %s halted, urb %p\n", 1289 dev_dbg (dummy_dev(dum), "ep %s halted, urb %p\n",
1291 ep->ep.name, urb); 1290 ep->ep.name, urb);
1292 maybe_set_status (urb, -EPIPE); 1291 status = -EPIPE;
1293 goto return_urb; 1292 goto return_urb;
1294 } 1293 }
1295 /* FIXME make sure both ends agree on maxpacket */ 1294 /* FIXME make sure both ends agree on maxpacket */
@@ -1307,7 +1306,7 @@ restart:
1307 w_value = le16_to_cpu(setup.wValue); 1306 w_value = le16_to_cpu(setup.wValue);
1308 if (le16_to_cpu(setup.wLength) != 1307 if (le16_to_cpu(setup.wLength) !=
1309 urb->transfer_buffer_length) { 1308 urb->transfer_buffer_length) {
1310 maybe_set_status (urb, -EOVERFLOW); 1309 status = -EOVERFLOW;
1311 goto return_urb; 1310 goto return_urb;
1312 } 1311 }
1313 1312
@@ -1337,7 +1336,7 @@ restart:
1337 if (setup.bRequestType != Dev_Request) 1336 if (setup.bRequestType != Dev_Request)
1338 break; 1337 break;
1339 dum->address = w_value; 1338 dum->address = w_value;
1340 maybe_set_status (urb, 0); 1339 status = 0;
1341 dev_dbg (udc_dev(dum), "set_address = %d\n", 1340 dev_dbg (udc_dev(dum), "set_address = %d\n",
1342 w_value); 1341 w_value);
1343 value = 0; 1342 value = 0;
@@ -1364,7 +1363,7 @@ restart:
1364 if (value == 0) { 1363 if (value == 0) {
1365 dum->devstatus |= 1364 dum->devstatus |=
1366 (1 << w_value); 1365 (1 << w_value);
1367 maybe_set_status (urb, 0); 1366 status = 0;
1368 } 1367 }
1369 1368
1370 } else if (setup.bRequestType == Ep_Request) { 1369 } else if (setup.bRequestType == Ep_Request) {
@@ -1376,7 +1375,7 @@ restart:
1376 } 1375 }
1377 ep2->halted = 1; 1376 ep2->halted = 1;
1378 value = 0; 1377 value = 0;
1379 maybe_set_status (urb, 0); 1378 status = 0;
1380 } 1379 }
1381 break; 1380 break;
1382 case USB_REQ_CLEAR_FEATURE: 1381 case USB_REQ_CLEAR_FEATURE:
@@ -1386,7 +1385,7 @@ restart:
1386 dum->devstatus &= ~(1 << 1385 dum->devstatus &= ~(1 <<
1387 USB_DEVICE_REMOTE_WAKEUP); 1386 USB_DEVICE_REMOTE_WAKEUP);
1388 value = 0; 1387 value = 0;
1389 maybe_set_status (urb, 0); 1388 status = 0;
1390 break; 1389 break;
1391 default: 1390 default:
1392 value = -EOPNOTSUPP; 1391 value = -EOPNOTSUPP;
@@ -1401,7 +1400,7 @@ restart:
1401 } 1400 }
1402 ep2->halted = 0; 1401 ep2->halted = 0;
1403 value = 0; 1402 value = 0;
1404 maybe_set_status (urb, 0); 1403 status = 0;
1405 } 1404 }
1406 break; 1405 break;
1407 case USB_REQ_GET_STATUS: 1406 case USB_REQ_GET_STATUS:
@@ -1438,7 +1437,7 @@ restart:
1438 urb->actual_length = min (2, 1437 urb->actual_length = min (2,
1439 urb->transfer_buffer_length); 1438 urb->transfer_buffer_length);
1440 value = 0; 1439 value = 0;
1441 maybe_set_status (urb, 0); 1440 status = 0;
1442 } 1441 }
1443 break; 1442 break;
1444 } 1443 }
@@ -1465,7 +1464,7 @@ restart:
1465 dev_dbg (udc_dev(dum), 1464 dev_dbg (udc_dev(dum),
1466 "setup --> %d\n", 1465 "setup --> %d\n",
1467 value); 1466 value);
1468 maybe_set_status (urb, -EPIPE); 1467 status = -EPIPE;
1469 urb->actual_length = 0; 1468 urb->actual_length = 0;
1470 } 1469 }
1471 1470
@@ -1482,7 +1481,7 @@ restart:
1482 * report random errors, to debug drivers. 1481 * report random errors, to debug drivers.
1483 */ 1482 */
1484 limit = max (limit, periodic_bytes (dum, ep)); 1483 limit = max (limit, periodic_bytes (dum, ep));
1485 maybe_set_status (urb, -ENOSYS); 1484 status = -ENOSYS;
1486 break; 1485 break;
1487 1486
1488 case PIPE_INTERRUPT: 1487 case PIPE_INTERRUPT:
@@ -1496,23 +1495,23 @@ restart:
1496 default: 1495 default:
1497 treat_control_like_bulk: 1496 treat_control_like_bulk:
1498 ep->last_io = jiffies; 1497 ep->last_io = jiffies;
1499 total = transfer (dum, urb, ep, limit); 1498 total = transfer(dum, urb, ep, limit, &status);
1500 break; 1499 break;
1501 } 1500 }
1502 1501
1503 /* incomplete transfer? */ 1502 /* incomplete transfer? */
1504 if (urb->status == -EINPROGRESS) 1503 if (status == -EINPROGRESS)
1505 continue; 1504 continue;
1506 1505
1507return_urb: 1506return_urb:
1508 urb->hcpriv = NULL;
1509 list_del (&urbp->urbp_list); 1507 list_del (&urbp->urbp_list);
1510 kfree (urbp); 1508 kfree (urbp);
1511 if (ep) 1509 if (ep)
1512 ep->already_seen = ep->setup_stage = 0; 1510 ep->already_seen = ep->setup_stage = 0;
1513 1511
1512 usb_hcd_unlink_urb_from_ep(dummy_to_hcd(dum), urb);
1514 spin_unlock (&dum->lock); 1513 spin_unlock (&dum->lock);
1515 usb_hcd_giveback_urb (dummy_to_hcd(dum), urb); 1514 usb_hcd_giveback_urb(dummy_to_hcd(dum), urb, status);
1516 spin_lock (&dum->lock); 1515 spin_lock (&dum->lock);
1517 1516
1518 goto restart; 1517 goto restart;
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 3aa46cfa66ba..f9d07108bc30 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -28,7 +28,7 @@
28#include <linux/string.h> 28#include <linux/string.h>
29 29
30#include <linux/usb/ch9.h> 30#include <linux/usb/ch9.h>
31#include <linux/usb_gadget.h> 31#include <linux/usb/gadget.h>
32 32
33#include "gadget_chips.h" 33#include "gadget_chips.h"
34 34
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index f70055473a00..9e732bff9df0 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -19,40 +19,18 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22/* #define VERBOSE_DEBUG */
22 23
23// #define DEBUG 1
24// #define VERBOSE
25
26#include <linux/module.h>
27#include <linux/kernel.h> 24#include <linux/kernel.h>
28#include <linux/delay.h>
29#include <linux/ioport.h>
30#include <linux/slab.h>
31#include <linux/errno.h>
32#include <linux/init.h>
33#include <linux/timer.h>
34#include <linux/list.h>
35#include <linux/interrupt.h>
36#include <linux/utsname.h> 25#include <linux/utsname.h>
37#include <linux/device.h> 26#include <linux/device.h>
38#include <linux/moduleparam.h>
39#include <linux/ctype.h> 27#include <linux/ctype.h>
40 28#include <linux/etherdevice.h>
41#include <asm/byteorder.h> 29#include <linux/ethtool.h>
42#include <asm/io.h>
43#include <asm/irq.h>
44#include <asm/system.h>
45#include <asm/uaccess.h>
46#include <asm/unaligned.h>
47 30
48#include <linux/usb/ch9.h> 31#include <linux/usb/ch9.h>
49#include <linux/usb/cdc.h> 32#include <linux/usb/cdc.h>
50#include <linux/usb_gadget.h> 33#include <linux/usb/gadget.h>
51
52#include <linux/random.h>
53#include <linux/netdevice.h>
54#include <linux/etherdevice.h>
55#include <linux/ethtool.h>
56 34
57#include "gadget_chips.h" 35#include "gadget_chips.h"
58 36
@@ -356,15 +334,15 @@ module_param (qmult, uint, S_IRUGO|S_IWUSR);
356#define qlen(gadget) \ 334#define qlen(gadget) \
357 (DEFAULT_QLEN*((gadget->speed == USB_SPEED_HIGH) ? qmult : 1)) 335 (DEFAULT_QLEN*((gadget->speed == USB_SPEED_HIGH) ? qmult : 1))
358 336
359/* also defer IRQs on highspeed TX */
360#define TX_DELAY qmult
361
362static inline int BITRATE(struct usb_gadget *g) 337static inline int BITRATE(struct usb_gadget *g)
363{ 338{
364 return (g->speed == USB_SPEED_HIGH) ? HS_BPS : FS_BPS; 339 return (g->speed == USB_SPEED_HIGH) ? HS_BPS : FS_BPS;
365} 340}
366 341
367#else /* full speed (low speed doesn't do bulk) */ 342#else /* full speed (low speed doesn't do bulk) */
343
344#define qmult 1
345
368#define DEVSPEED USB_SPEED_FULL 346#define DEVSPEED USB_SPEED_FULL
369 347
370#define qlen(gadget) DEFAULT_QLEN 348#define qlen(gadget) DEFAULT_QLEN
@@ -390,7 +368,7 @@ static inline int BITRATE(struct usb_gadget *g)
390 do { } while (0) 368 do { } while (0)
391#endif /* DEBUG */ 369#endif /* DEBUG */
392 370
393#ifdef VERBOSE 371#ifdef VERBOSE_DEBUG
394#define VDEBUG DEBUG 372#define VDEBUG DEBUG
395#else 373#else
396#define VDEBUG(dev,fmt,args...) \ 374#define VDEBUG(dev,fmt,args...) \
@@ -830,8 +808,6 @@ static const struct usb_descriptor_header *fs_rndis_function [] = {
830}; 808};
831#endif 809#endif
832 810
833#ifdef CONFIG_USB_GADGET_DUALSPEED
834
835/* 811/*
836 * usb 2.0 devices need to expose both high speed and full speed 812 * usb 2.0 devices need to expose both high speed and full speed
837 * descriptors, unless they only run at full speed. 813 * descriptors, unless they only run at full speed.
@@ -934,18 +910,15 @@ static const struct usb_descriptor_header *hs_rndis_function [] = {
934 910
935 911
936/* maxpacket and other transfer characteristics vary by speed. */ 912/* maxpacket and other transfer characteristics vary by speed. */
937#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs)) 913static inline struct usb_endpoint_descriptor *
938 914ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
939#else 915 struct usb_endpoint_descriptor *fs)
940
941/* if there's no high speed support, maxpacket doesn't change. */
942#define ep_desc(g,hs,fs) (((void)(g)), (fs))
943
944static inline void __init hs_subset_descriptors(void)
945{ 916{
917 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
918 return hs;
919 return fs;
946} 920}
947 921
948#endif /* !CONFIG_USB_GADGET_DUALSPEED */
949 922
950/*-------------------------------------------------------------------------*/ 923/*-------------------------------------------------------------------------*/
951 924
@@ -989,22 +962,19 @@ static struct usb_gadget_strings stringtab = {
989 * complications: class descriptors, and an altsetting. 962 * complications: class descriptors, and an altsetting.
990 */ 963 */
991static int 964static int
992config_buf (enum usb_device_speed speed, 965config_buf(struct usb_gadget *g, u8 *buf, u8 type, unsigned index, int is_otg)
993 u8 *buf, u8 type,
994 unsigned index, int is_otg)
995{ 966{
996 int len; 967 int len;
997 const struct usb_config_descriptor *config; 968 const struct usb_config_descriptor *config;
998 const struct usb_descriptor_header **function; 969 const struct usb_descriptor_header **function;
999#ifdef CONFIG_USB_GADGET_DUALSPEED 970 int hs = 0;
1000 int hs = (speed == USB_SPEED_HIGH);
1001 971
1002 if (type == USB_DT_OTHER_SPEED_CONFIG) 972 if (gadget_is_dualspeed(g)) {
1003 hs = !hs; 973 hs = (g->speed == USB_SPEED_HIGH);
974 if (type == USB_DT_OTHER_SPEED_CONFIG)
975 hs = !hs;
976 }
1004#define which_fn(t) (hs ? hs_ ## t ## _function : fs_ ## t ## _function) 977#define which_fn(t) (hs ? hs_ ## t ## _function : fs_ ## t ## _function)
1005#else
1006#define which_fn(t) (fs_ ## t ## _function)
1007#endif
1008 978
1009 if (index >= device_desc.bNumConfigurations) 979 if (index >= device_desc.bNumConfigurations)
1010 return -EINVAL; 980 return -EINVAL;
@@ -1217,7 +1187,7 @@ eth_set_config (struct eth_dev *dev, unsigned number, gfp_t gfp_flags)
1217 if (number) 1187 if (number)
1218 eth_reset_config (dev); 1188 eth_reset_config (dev);
1219 usb_gadget_vbus_draw(dev->gadget, 1189 usb_gadget_vbus_draw(dev->gadget,
1220 dev->gadget->is_otg ? 8 : 100); 1190 gadget_is_otg(dev->gadget) ? 8 : 100);
1221 } else { 1191 } else {
1222 char *speed; 1192 char *speed;
1223 unsigned power; 1193 unsigned power;
@@ -1399,24 +1369,22 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1399 value = min (wLength, (u16) sizeof device_desc); 1369 value = min (wLength, (u16) sizeof device_desc);
1400 memcpy (req->buf, &device_desc, value); 1370 memcpy (req->buf, &device_desc, value);
1401 break; 1371 break;
1402#ifdef CONFIG_USB_GADGET_DUALSPEED
1403 case USB_DT_DEVICE_QUALIFIER: 1372 case USB_DT_DEVICE_QUALIFIER:
1404 if (!gadget->is_dualspeed) 1373 if (!gadget_is_dualspeed(gadget))
1405 break; 1374 break;
1406 value = min (wLength, (u16) sizeof dev_qualifier); 1375 value = min (wLength, (u16) sizeof dev_qualifier);
1407 memcpy (req->buf, &dev_qualifier, value); 1376 memcpy (req->buf, &dev_qualifier, value);
1408 break; 1377 break;
1409 1378
1410 case USB_DT_OTHER_SPEED_CONFIG: 1379 case USB_DT_OTHER_SPEED_CONFIG:
1411 if (!gadget->is_dualspeed) 1380 if (!gadget_is_dualspeed(gadget))
1412 break; 1381 break;
1413 // FALLTHROUGH 1382 // FALLTHROUGH
1414#endif /* CONFIG_USB_GADGET_DUALSPEED */
1415 case USB_DT_CONFIG: 1383 case USB_DT_CONFIG:
1416 value = config_buf (gadget->speed, req->buf, 1384 value = config_buf(gadget, req->buf,
1417 wValue >> 8, 1385 wValue >> 8,
1418 wValue & 0xff, 1386 wValue & 0xff,
1419 gadget->is_otg); 1387 gadget_is_otg(gadget));
1420 if (value >= 0) 1388 if (value >= 0)
1421 value = min (wLength, (u16) value); 1389 value = min (wLength, (u16) value);
1422 break; 1390 break;
@@ -1585,12 +1553,12 @@ done_set_intf:
1585 && rndis_control_intf.bInterfaceNumber 1553 && rndis_control_intf.bInterfaceNumber
1586 == wIndex) { 1554 == wIndex) {
1587 u8 *buf; 1555 u8 *buf;
1556 u32 n;
1588 1557
1589 /* return the result */ 1558 /* return the result */
1590 buf = rndis_get_next_response (dev->rndis_config, 1559 buf = rndis_get_next_response(dev->rndis_config, &n);
1591 &value);
1592 if (buf) { 1560 if (buf) {
1593 memcpy (req->buf, buf, value); 1561 memcpy(req->buf, buf, n);
1594 req->complete = rndis_response_complete; 1562 req->complete = rndis_response_complete;
1595 rndis_free_response(dev->rndis_config, buf); 1563 rndis_free_response(dev->rndis_config, buf);
1596 } 1564 }
@@ -1989,8 +1957,20 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1989 } 1957 }
1990 1958
1991 spin_lock_irqsave(&dev->req_lock, flags); 1959 spin_lock_irqsave(&dev->req_lock, flags);
1960 /*
1961 * this freelist can be empty if an interrupt triggered disconnect()
1962 * and reconfigured the gadget (shutting down this queue) after the
1963 * network stack decided to xmit but before we got the spinlock.
1964 */
1965 if (list_empty(&dev->tx_reqs)) {
1966 spin_unlock_irqrestore(&dev->req_lock, flags);
1967 return 1;
1968 }
1969
1992 req = container_of (dev->tx_reqs.next, struct usb_request, list); 1970 req = container_of (dev->tx_reqs.next, struct usb_request, list);
1993 list_del (&req->list); 1971 list_del (&req->list);
1972
1973 /* temporarily stop TX queue when the freelist empties */
1994 if (list_empty (&dev->tx_reqs)) 1974 if (list_empty (&dev->tx_reqs))
1995 netif_stop_queue (net); 1975 netif_stop_queue (net);
1996 spin_unlock_irqrestore(&dev->req_lock, flags); 1976 spin_unlock_irqrestore(&dev->req_lock, flags);
@@ -2026,12 +2006,11 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
2026 2006
2027 req->length = length; 2007 req->length = length;
2028 2008
2029#ifdef CONFIG_USB_GADGET_DUALSPEED
2030 /* throttle highspeed IRQ rate back slightly */ 2009 /* throttle highspeed IRQ rate back slightly */
2031 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH) 2010 if (gadget_is_dualspeed(dev->gadget))
2032 ? ((atomic_read (&dev->tx_qlen) % TX_DELAY) != 0) 2011 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH)
2033 : 0; 2012 ? ((atomic_read(&dev->tx_qlen) % qmult) != 0)
2034#endif 2013 : 0;
2035 2014
2036 retval = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC); 2015 retval = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC);
2037 switch (retval) { 2016 switch (retval) {
@@ -2188,8 +2167,7 @@ static int eth_stop (struct net_device *net)
2188 } 2167 }
2189 2168
2190 if (rndis_active(dev)) { 2169 if (rndis_active(dev)) {
2191 rndis_set_param_medium (dev->rndis_config, 2170 rndis_set_param_medium(dev->rndis_config, NDIS_MEDIUM_802_3, 0);
2192 NDIS_MEDIUM_802_3, 0);
2193 (void) rndis_signal_disconnect (dev->rndis_config); 2171 (void) rndis_signal_disconnect (dev->rndis_config);
2194 } 2172 }
2195 2173
@@ -2443,26 +2421,28 @@ autoconf_fail:
2443 if (rndis) 2421 if (rndis)
2444 device_desc.bNumConfigurations = 2; 2422 device_desc.bNumConfigurations = 2;
2445 2423
2446#ifdef CONFIG_USB_GADGET_DUALSPEED 2424 if (gadget_is_dualspeed(gadget)) {
2447 if (rndis) 2425 if (rndis)
2448 dev_qualifier.bNumConfigurations = 2; 2426 dev_qualifier.bNumConfigurations = 2;
2449 else if (!cdc) 2427 else if (!cdc)
2450 dev_qualifier.bDeviceClass = USB_CLASS_VENDOR_SPEC; 2428 dev_qualifier.bDeviceClass = USB_CLASS_VENDOR_SPEC;
2451 2429
2452 /* assumes ep0 uses the same value for both speeds ... */ 2430 /* assumes ep0 uses the same value for both speeds ... */
2453 dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0; 2431 dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
2454 2432
2455 /* and that all endpoints are dual-speed */ 2433 /* and that all endpoints are dual-speed */
2456 hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress; 2434 hs_source_desc.bEndpointAddress =
2457 hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress; 2435 fs_source_desc.bEndpointAddress;
2436 hs_sink_desc.bEndpointAddress =
2437 fs_sink_desc.bEndpointAddress;
2458#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 2438#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
2459 if (status_ep) 2439 if (status_ep)
2460 hs_status_desc.bEndpointAddress = 2440 hs_status_desc.bEndpointAddress =
2461 fs_status_desc.bEndpointAddress; 2441 fs_status_desc.bEndpointAddress;
2462#endif 2442#endif
2463#endif /* DUALSPEED */ 2443 }
2464 2444
2465 if (gadget->is_otg) { 2445 if (gadget_is_otg(gadget)) {
2466 otg_descriptor.bmAttributes |= USB_OTG_HNP, 2446 otg_descriptor.bmAttributes |= USB_OTG_HNP,
2467 eth_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 2447 eth_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
2468 eth_config.bMaxPower = 4; 2448 eth_config.bMaxPower = 4;
@@ -2598,12 +2578,11 @@ fail0:
2598 if (rndis_set_param_dev (dev->rndis_config, dev->net, 2578 if (rndis_set_param_dev (dev->rndis_config, dev->net,
2599 &dev->stats, &dev->cdc_filter)) 2579 &dev->stats, &dev->cdc_filter))
2600 goto fail0; 2580 goto fail0;
2601 if (rndis_set_param_vendor (dev->rndis_config, vendorID, 2581 if (rndis_set_param_vendor(dev->rndis_config, vendorID,
2602 manufacturer)) 2582 manufacturer))
2603 goto fail0; 2583 goto fail0;
2604 if (rndis_set_param_medium (dev->rndis_config, 2584 if (rndis_set_param_medium(dev->rndis_config,
2605 NDIS_MEDIUM_802_3, 2585 NDIS_MEDIUM_802_3, 0))
2606 0))
2607 goto fail0; 2586 goto fail0;
2608 INFO (dev, "RNDIS ready\n"); 2587 INFO (dev, "RNDIS ready\n");
2609 } 2588 }
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 965ad7bec7b7..73726c570a6e 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * file_storage.c -- File-backed USB Storage Gadget, for USB development 2 * file_storage.c -- File-backed USB Storage Gadget, for USB development
3 * 3 *
4 * Copyright (C) 2003-2005 Alan Stern 4 * Copyright (C) 2003-2007 Alan Stern
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
@@ -217,17 +217,11 @@
217 */ 217 */
218 218
219 219
220#undef DEBUG 220/* #define VERBOSE_DEBUG */
221#undef VERBOSE 221/* #define DUMP_MSGS */
222#undef DUMP_MSGS
223
224 222
225#include <asm/system.h>
226#include <asm/uaccess.h>
227 223
228#include <linux/bitops.h>
229#include <linux/blkdev.h> 224#include <linux/blkdev.h>
230#include <linux/compiler.h>
231#include <linux/completion.h> 225#include <linux/completion.h>
232#include <linux/dcache.h> 226#include <linux/dcache.h>
233#include <linux/delay.h> 227#include <linux/delay.h>
@@ -235,18 +229,10 @@
235#include <linux/fcntl.h> 229#include <linux/fcntl.h>
236#include <linux/file.h> 230#include <linux/file.h>
237#include <linux/fs.h> 231#include <linux/fs.h>
238#include <linux/init.h>
239#include <linux/kernel.h>
240#include <linux/kref.h> 232#include <linux/kref.h>
241#include <linux/kthread.h> 233#include <linux/kthread.h>
242#include <linux/limits.h> 234#include <linux/limits.h>
243#include <linux/list.h>
244#include <linux/module.h>
245#include <linux/moduleparam.h>
246#include <linux/pagemap.h>
247#include <linux/rwsem.h> 235#include <linux/rwsem.h>
248#include <linux/sched.h>
249#include <linux/signal.h>
250#include <linux/slab.h> 236#include <linux/slab.h>
251#include <linux/spinlock.h> 237#include <linux/spinlock.h>
252#include <linux/string.h> 238#include <linux/string.h>
@@ -254,7 +240,7 @@
254#include <linux/utsname.h> 240#include <linux/utsname.h>
255 241
256#include <linux/usb/ch9.h> 242#include <linux/usb/ch9.h>
257#include <linux/usb_gadget.h> 243#include <linux/usb/gadget.h>
258 244
259#include "gadget_chips.h" 245#include "gadget_chips.h"
260 246
@@ -263,7 +249,7 @@
263 249
264#define DRIVER_DESC "File-backed Storage Gadget" 250#define DRIVER_DESC "File-backed Storage Gadget"
265#define DRIVER_NAME "g_file_storage" 251#define DRIVER_NAME "g_file_storage"
266#define DRIVER_VERSION "28 November 2005" 252#define DRIVER_VERSION "7 August 2007"
267 253
268static const char longname[] = DRIVER_DESC; 254static const char longname[] = DRIVER_DESC;
269static const char shortname[] = DRIVER_NAME; 255static const char shortname[] = DRIVER_NAME;
@@ -289,57 +275,48 @@ MODULE_LICENSE("Dual BSD/GPL");
289 275
290/*-------------------------------------------------------------------------*/ 276/*-------------------------------------------------------------------------*/
291 277
292#define xprintk(f,level,fmt,args...) \
293 dev_printk(level , &(f)->gadget->dev , fmt , ## args)
294#define yprintk(l,level,fmt,args...) \
295 dev_printk(level , &(l)->dev , fmt , ## args)
296
297#ifdef DEBUG 278#ifdef DEBUG
298#define DBG(fsg,fmt,args...) \
299 xprintk(fsg , KERN_DEBUG , fmt , ## args)
300#define LDBG(lun,fmt,args...) \ 279#define LDBG(lun,fmt,args...) \
301 yprintk(lun , KERN_DEBUG , fmt , ## args) 280 dev_dbg(&(lun)->dev , fmt , ## args)
302#define MDBG(fmt,args...) \ 281#define MDBG(fmt,args...) \
303 printk(KERN_DEBUG DRIVER_NAME ": " fmt , ## args) 282 printk(KERN_DEBUG DRIVER_NAME ": " fmt , ## args)
304#else 283#else
305#define DBG(fsg,fmt,args...) \
306 do { } while (0)
307#define LDBG(lun,fmt,args...) \ 284#define LDBG(lun,fmt,args...) \
308 do { } while (0) 285 do { } while (0)
309#define MDBG(fmt,args...) \ 286#define MDBG(fmt,args...) \
310 do { } while (0) 287 do { } while (0)
311#undef VERBOSE 288#undef VERBOSE_DEBUG
312#undef DUMP_MSGS 289#undef DUMP_MSGS
313#endif /* DEBUG */ 290#endif /* DEBUG */
314 291
315#ifdef VERBOSE 292#ifdef VERBOSE_DEBUG
316#define VDBG DBG
317#define VLDBG LDBG 293#define VLDBG LDBG
318#else 294#else
319#define VDBG(fsg,fmt,args...) \
320 do { } while (0)
321#define VLDBG(lun,fmt,args...) \ 295#define VLDBG(lun,fmt,args...) \
322 do { } while (0) 296 do { } while (0)
323#endif /* VERBOSE */ 297#endif /* VERBOSE_DEBUG */
324 298
325#define ERROR(fsg,fmt,args...) \
326 xprintk(fsg , KERN_ERR , fmt , ## args)
327#define LERROR(lun,fmt,args...) \ 299#define LERROR(lun,fmt,args...) \
328 yprintk(lun , KERN_ERR , fmt , ## args) 300 dev_err(&(lun)->dev , fmt , ## args)
329
330#define WARN(fsg,fmt,args...) \
331 xprintk(fsg , KERN_WARNING , fmt , ## args)
332#define LWARN(lun,fmt,args...) \ 301#define LWARN(lun,fmt,args...) \
333 yprintk(lun , KERN_WARNING , fmt , ## args) 302 dev_warn(&(lun)->dev , fmt , ## args)
334
335#define INFO(fsg,fmt,args...) \
336 xprintk(fsg , KERN_INFO , fmt , ## args)
337#define LINFO(lun,fmt,args...) \ 303#define LINFO(lun,fmt,args...) \
338 yprintk(lun , KERN_INFO , fmt , ## args) 304 dev_info(&(lun)->dev , fmt , ## args)
339 305
340#define MINFO(fmt,args...) \ 306#define MINFO(fmt,args...) \
341 printk(KERN_INFO DRIVER_NAME ": " fmt , ## args) 307 printk(KERN_INFO DRIVER_NAME ": " fmt , ## args)
342 308
309#define DBG(d, fmt, args...) \
310 dev_dbg(&(d)->gadget->dev , fmt , ## args)
311#define VDBG(d, fmt, args...) \
312 dev_vdbg(&(d)->gadget->dev , fmt , ## args)
313#define ERROR(d, fmt, args...) \
314 dev_err(&(d)->gadget->dev , fmt , ## args)
315#define WARN(d, fmt, args...) \
316 dev_warn(&(d)->gadget->dev , fmt , ## args)
317#define INFO(d, fmt, args...) \
318 dev_info(&(d)->gadget->dev , fmt , ## args)
319
343 320
344/*-------------------------------------------------------------------------*/ 321/*-------------------------------------------------------------------------*/
345 322
@@ -350,8 +327,8 @@ MODULE_LICENSE("Dual BSD/GPL");
350static struct { 327static struct {
351 char *file[MAX_LUNS]; 328 char *file[MAX_LUNS];
352 int ro[MAX_LUNS]; 329 int ro[MAX_LUNS];
353 int num_filenames; 330 unsigned int num_filenames;
354 int num_ros; 331 unsigned int num_ros;
355 unsigned int nluns; 332 unsigned int nluns;
356 333
357 int removable; 334 int removable;
@@ -578,7 +555,7 @@ struct lun {
578 555
579#define backing_file_is_open(curlun) ((curlun)->filp != NULL) 556#define backing_file_is_open(curlun) ((curlun)->filp != NULL)
580 557
581static inline struct lun *dev_to_lun(struct device *dev) 558static struct lun *dev_to_lun(struct device *dev)
582{ 559{
583 return container_of(dev, struct lun, dev); 560 return container_of(dev, struct lun, dev);
584} 561}
@@ -711,13 +688,13 @@ struct fsg_dev {
711 688
712typedef void (*fsg_routine_t)(struct fsg_dev *); 689typedef void (*fsg_routine_t)(struct fsg_dev *);
713 690
714static int inline exception_in_progress(struct fsg_dev *fsg) 691static int exception_in_progress(struct fsg_dev *fsg)
715{ 692{
716 return (fsg->state > FSG_STATE_IDLE); 693 return (fsg->state > FSG_STATE_IDLE);
717} 694}
718 695
719/* Make bulk-out requests be divisible by the maxpacket size */ 696/* Make bulk-out requests be divisible by the maxpacket size */
720static void inline set_bulk_out_req_length(struct fsg_dev *fsg, 697static void set_bulk_out_req_length(struct fsg_dev *fsg,
721 struct fsg_buffhd *bh, unsigned int length) 698 struct fsg_buffhd *bh, unsigned int length)
722{ 699{
723 unsigned int rem; 700 unsigned int rem;
@@ -743,50 +720,36 @@ static void close_all_backing_files(struct fsg_dev *fsg);
743static void dump_msg(struct fsg_dev *fsg, const char *label, 720static void dump_msg(struct fsg_dev *fsg, const char *label,
744 const u8 *buf, unsigned int length) 721 const u8 *buf, unsigned int length)
745{ 722{
746 unsigned int start, num, i; 723 if (length < 512) {
747 char line[52], *p; 724 DBG(fsg, "%s, length %u:\n", label, length);
748 725 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET,
749 if (length >= 512) 726 16, 1, buf, length, 0);
750 return;
751 DBG(fsg, "%s, length %u:\n", label, length);
752
753 start = 0;
754 while (length > 0) {
755 num = min(length, 16u);
756 p = line;
757 for (i = 0; i < num; ++i) {
758 if (i == 8)
759 *p++ = ' ';
760 sprintf(p, " %02x", buf[i]);
761 p += 3;
762 }
763 *p = 0;
764 printk(KERN_DEBUG "%6x: %s\n", start, line);
765 buf += num;
766 start += num;
767 length -= num;
768 } 727 }
769} 728}
770 729
771static void inline dump_cdb(struct fsg_dev *fsg) 730static void dump_cdb(struct fsg_dev *fsg)
772{} 731{}
773 732
774#else 733#else
775 734
776static void inline dump_msg(struct fsg_dev *fsg, const char *label, 735static void dump_msg(struct fsg_dev *fsg, const char *label,
777 const u8 *buf, unsigned int length) 736 const u8 *buf, unsigned int length)
778{} 737{}
779 738
780static void inline dump_cdb(struct fsg_dev *fsg) 739#ifdef VERBOSE_DEBUG
781{
782 int i;
783 char cmdbuf[3*MAX_COMMAND_SIZE + 1];
784 740
785 for (i = 0; i < fsg->cmnd_size; ++i) 741static void dump_cdb(struct fsg_dev *fsg)
786 sprintf(cmdbuf + i*3, " %02x", fsg->cmnd[i]); 742{
787 VDBG(fsg, "SCSI CDB: %s\n", cmdbuf); 743 print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE,
744 16, 1, fsg->cmnd, fsg->cmnd_size, 0);
788} 745}
789 746
747#else
748
749static void dump_cdb(struct fsg_dev *fsg)
750{}
751
752#endif /* VERBOSE_DEBUG */
790#endif /* DUMP_MSGS */ 753#endif /* DUMP_MSGS */
791 754
792 755
@@ -809,24 +772,24 @@ static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
809 772
810/* Routines for unaligned data access */ 773/* Routines for unaligned data access */
811 774
812static u16 inline get_be16(u8 *buf) 775static u16 get_be16(u8 *buf)
813{ 776{
814 return ((u16) buf[0] << 8) | ((u16) buf[1]); 777 return ((u16) buf[0] << 8) | ((u16) buf[1]);
815} 778}
816 779
817static u32 inline get_be32(u8 *buf) 780static u32 get_be32(u8 *buf)
818{ 781{
819 return ((u32) buf[0] << 24) | ((u32) buf[1] << 16) | 782 return ((u32) buf[0] << 24) | ((u32) buf[1] << 16) |
820 ((u32) buf[2] << 8) | ((u32) buf[3]); 783 ((u32) buf[2] << 8) | ((u32) buf[3]);
821} 784}
822 785
823static void inline put_be16(u8 *buf, u16 val) 786static void put_be16(u8 *buf, u16 val)
824{ 787{
825 buf[0] = val >> 8; 788 buf[0] = val >> 8;
826 buf[1] = val; 789 buf[1] = val;
827} 790}
828 791
829static void inline put_be32(u8 *buf, u32 val) 792static void put_be32(u8 *buf, u32 val)
830{ 793{
831 buf[0] = val >> 24; 794 buf[0] = val >> 24;
832 buf[1] = val >> 16; 795 buf[1] = val >> 16;
@@ -950,8 +913,6 @@ static const struct usb_descriptor_header *fs_function[] = {
950#define FS_FUNCTION_PRE_EP_ENTRIES 2 913#define FS_FUNCTION_PRE_EP_ENTRIES 2
951 914
952 915
953#ifdef CONFIG_USB_GADGET_DUALSPEED
954
955/* 916/*
956 * USB 2.0 devices need to expose both high speed and full speed 917 * USB 2.0 devices need to expose both high speed and full speed
957 * descriptors, unless they only run at full speed. 918 * descriptors, unless they only run at full speed.
@@ -1014,14 +975,14 @@ static const struct usb_descriptor_header *hs_function[] = {
1014#define HS_FUNCTION_PRE_EP_ENTRIES 2 975#define HS_FUNCTION_PRE_EP_ENTRIES 2
1015 976
1016/* Maxpacket and other transfer characteristics vary by speed. */ 977/* Maxpacket and other transfer characteristics vary by speed. */
1017#define ep_desc(g,fs,hs) (((g)->speed==USB_SPEED_HIGH) ? (hs) : (fs)) 978static struct usb_endpoint_descriptor *
1018 979ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
1019#else 980 struct usb_endpoint_descriptor *hs)
1020 981{
1021/* If there's no high speed support, always use the full-speed descriptor. */ 982 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
1022#define ep_desc(g,fs,hs) fs 983 return hs;
1023 984 return fs;
1024#endif /* !CONFIG_USB_GADGET_DUALSPEED */ 985}
1025 986
1026 987
1027/* The CBI specification limits the serial string to 12 uppercase hexadecimal 988/* The CBI specification limits the serial string to 12 uppercase hexadecimal
@@ -1053,26 +1014,22 @@ static struct usb_gadget_strings stringtab = {
1053static int populate_config_buf(struct usb_gadget *gadget, 1014static int populate_config_buf(struct usb_gadget *gadget,
1054 u8 *buf, u8 type, unsigned index) 1015 u8 *buf, u8 type, unsigned index)
1055{ 1016{
1056#ifdef CONFIG_USB_GADGET_DUALSPEED
1057 enum usb_device_speed speed = gadget->speed; 1017 enum usb_device_speed speed = gadget->speed;
1058#endif
1059 int len; 1018 int len;
1060 const struct usb_descriptor_header **function; 1019 const struct usb_descriptor_header **function;
1061 1020
1062 if (index > 0) 1021 if (index > 0)
1063 return -EINVAL; 1022 return -EINVAL;
1064 1023
1065#ifdef CONFIG_USB_GADGET_DUALSPEED 1024 if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
1066 if (type == USB_DT_OTHER_SPEED_CONFIG)
1067 speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed; 1025 speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
1068 if (speed == USB_SPEED_HIGH) 1026 if (gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH)
1069 function = hs_function; 1027 function = hs_function;
1070 else 1028 else
1071#endif
1072 function = fs_function; 1029 function = fs_function;
1073 1030
1074 /* for now, don't advertise srp-only devices */ 1031 /* for now, don't advertise srp-only devices */
1075 if (!gadget->is_otg) 1032 if (!gadget_is_otg(gadget))
1076 function++; 1033 function++;
1077 1034
1078 len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function); 1035 len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
@@ -1394,10 +1351,9 @@ static int standard_setup_req(struct fsg_dev *fsg,
1394 value = sizeof device_desc; 1351 value = sizeof device_desc;
1395 memcpy(req->buf, &device_desc, value); 1352 memcpy(req->buf, &device_desc, value);
1396 break; 1353 break;
1397#ifdef CONFIG_USB_GADGET_DUALSPEED
1398 case USB_DT_DEVICE_QUALIFIER: 1354 case USB_DT_DEVICE_QUALIFIER:
1399 VDBG(fsg, "get device qualifier\n"); 1355 VDBG(fsg, "get device qualifier\n");
1400 if (!fsg->gadget->is_dualspeed) 1356 if (!gadget_is_dualspeed(fsg->gadget))
1401 break; 1357 break;
1402 value = sizeof dev_qualifier; 1358 value = sizeof dev_qualifier;
1403 memcpy(req->buf, &dev_qualifier, value); 1359 memcpy(req->buf, &dev_qualifier, value);
@@ -1405,15 +1361,12 @@ static int standard_setup_req(struct fsg_dev *fsg,
1405 1361
1406 case USB_DT_OTHER_SPEED_CONFIG: 1362 case USB_DT_OTHER_SPEED_CONFIG:
1407 VDBG(fsg, "get other-speed config descriptor\n"); 1363 VDBG(fsg, "get other-speed config descriptor\n");
1408 if (!fsg->gadget->is_dualspeed) 1364 if (!gadget_is_dualspeed(fsg->gadget))
1409 break; 1365 break;
1410 goto get_config; 1366 goto get_config;
1411#endif
1412 case USB_DT_CONFIG: 1367 case USB_DT_CONFIG:
1413 VDBG(fsg, "get configuration descriptor\n"); 1368 VDBG(fsg, "get configuration descriptor\n");
1414#ifdef CONFIG_USB_GADGET_DUALSPEED 1369get_config:
1415 get_config:
1416#endif
1417 value = populate_config_buf(fsg->gadget, 1370 value = populate_config_buf(fsg->gadget,
1418 req->buf, 1371 req->buf,
1419 w_value >> 8, 1372 w_value >> 8,
@@ -1646,7 +1599,8 @@ static int do_read(struct fsg_dev *fsg)
1646 /* Wait for the next buffer to become available */ 1599 /* Wait for the next buffer to become available */
1647 bh = fsg->next_buffhd_to_fill; 1600 bh = fsg->next_buffhd_to_fill;
1648 while (bh->state != BUF_STATE_EMPTY) { 1601 while (bh->state != BUF_STATE_EMPTY) {
1649 if ((rc = sleep_thread(fsg)) != 0) 1602 rc = sleep_thread(fsg);
1603 if (rc)
1650 return rc; 1604 return rc;
1651 } 1605 }
1652 1606
@@ -1885,7 +1839,8 @@ static int do_write(struct fsg_dev *fsg)
1885 } 1839 }
1886 1840
1887 /* Wait for something to happen */ 1841 /* Wait for something to happen */
1888 if ((rc = sleep_thread(fsg)) != 0) 1842 rc = sleep_thread(fsg);
1843 if (rc)
1889 return rc; 1844 return rc;
1890 } 1845 }
1891 1846
@@ -2369,7 +2324,8 @@ static int pad_with_zeros(struct fsg_dev *fsg)
2369 2324
2370 /* Wait for the next buffer to be free */ 2325 /* Wait for the next buffer to be free */
2371 while (bh->state != BUF_STATE_EMPTY) { 2326 while (bh->state != BUF_STATE_EMPTY) {
2372 if ((rc = sleep_thread(fsg)) != 0) 2327 rc = sleep_thread(fsg);
2328 if (rc)
2373 return rc; 2329 return rc;
2374 } 2330 }
2375 2331
@@ -2429,7 +2385,8 @@ static int throw_away_data(struct fsg_dev *fsg)
2429 } 2385 }
2430 2386
2431 /* Otherwise wait for something to happen */ 2387 /* Otherwise wait for something to happen */
2432 if ((rc = sleep_thread(fsg)) != 0) 2388 rc = sleep_thread(fsg);
2389 if (rc)
2433 return rc; 2390 return rc;
2434 } 2391 }
2435 return 0; 2392 return 0;
@@ -2551,7 +2508,8 @@ static int send_status(struct fsg_dev *fsg)
2551 /* Wait for the next buffer to become available */ 2508 /* Wait for the next buffer to become available */
2552 bh = fsg->next_buffhd_to_fill; 2509 bh = fsg->next_buffhd_to_fill;
2553 while (bh->state != BUF_STATE_EMPTY) { 2510 while (bh->state != BUF_STATE_EMPTY) {
2554 if ((rc = sleep_thread(fsg)) != 0) 2511 rc = sleep_thread(fsg);
2512 if (rc)
2555 return rc; 2513 return rc;
2556 } 2514 }
2557 2515
@@ -2771,9 +2729,10 @@ static int do_scsi_command(struct fsg_dev *fsg)
2771 /* Wait for the next buffer to become available for data or status */ 2729 /* Wait for the next buffer to become available for data or status */
2772 bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill; 2730 bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
2773 while (bh->state != BUF_STATE_EMPTY) { 2731 while (bh->state != BUF_STATE_EMPTY) {
2774 if ((rc = sleep_thread(fsg)) != 0) 2732 rc = sleep_thread(fsg);
2733 if (rc)
2775 return rc; 2734 return rc;
2776 } 2735 }
2777 fsg->phase_error = 0; 2736 fsg->phase_error = 0;
2778 fsg->short_packet_received = 0; 2737 fsg->short_packet_received = 0;
2779 2738
@@ -3005,7 +2964,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
3005 2964
3006 /* Is the CBW meaningful? */ 2965 /* Is the CBW meaningful? */
3007 if (cbw->Lun >= MAX_LUNS || cbw->Flags & ~USB_BULK_IN_FLAG || 2966 if (cbw->Lun >= MAX_LUNS || cbw->Flags & ~USB_BULK_IN_FLAG ||
3008 cbw->Length < 6 || cbw->Length > MAX_COMMAND_SIZE) { 2967 cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
3009 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, " 2968 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
3010 "cmdlen %u\n", 2969 "cmdlen %u\n",
3011 cbw->Lun, cbw->Flags, cbw->Length); 2970 cbw->Lun, cbw->Flags, cbw->Length);
@@ -3045,9 +3004,10 @@ static int get_next_command(struct fsg_dev *fsg)
3045 /* Wait for the next buffer to become available */ 3004 /* Wait for the next buffer to become available */
3046 bh = fsg->next_buffhd_to_fill; 3005 bh = fsg->next_buffhd_to_fill;
3047 while (bh->state != BUF_STATE_EMPTY) { 3006 while (bh->state != BUF_STATE_EMPTY) {
3048 if ((rc = sleep_thread(fsg)) != 0) 3007 rc = sleep_thread(fsg);
3008 if (rc)
3049 return rc; 3009 return rc;
3050 } 3010 }
3051 3011
3052 /* Queue a request to read a Bulk-only CBW */ 3012 /* Queue a request to read a Bulk-only CBW */
3053 set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN); 3013 set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN);
@@ -3061,9 +3021,10 @@ static int get_next_command(struct fsg_dev *fsg)
3061 3021
3062 /* Wait for the CBW to arrive */ 3022 /* Wait for the CBW to arrive */
3063 while (bh->state != BUF_STATE_FULL) { 3023 while (bh->state != BUF_STATE_FULL) {
3064 if ((rc = sleep_thread(fsg)) != 0) 3024 rc = sleep_thread(fsg);
3025 if (rc)
3065 return rc; 3026 return rc;
3066 } 3027 }
3067 smp_rmb(); 3028 smp_rmb();
3068 rc = received_cbw(fsg, bh); 3029 rc = received_cbw(fsg, bh);
3069 bh->state = BUF_STATE_EMPTY; 3030 bh->state = BUF_STATE_EMPTY;
@@ -3072,9 +3033,10 @@ static int get_next_command(struct fsg_dev *fsg)
3072 3033
3073 /* Wait for the next command to arrive */ 3034 /* Wait for the next command to arrive */
3074 while (fsg->cbbuf_cmnd_size == 0) { 3035 while (fsg->cbbuf_cmnd_size == 0) {
3075 if ((rc = sleep_thread(fsg)) != 0) 3036 rc = sleep_thread(fsg);
3037 if (rc)
3076 return rc; 3038 return rc;
3077 } 3039 }
3078 3040
3079 /* Is the previous status interrupt request still busy? 3041 /* Is the previous status interrupt request still busy?
3080 * The host is allowed to skip reading the status, 3042 * The host is allowed to skip reading the status,
@@ -3595,7 +3557,8 @@ static ssize_t show_ro(struct device *dev, struct device_attribute *attr, char *
3595 return sprintf(buf, "%d\n", curlun->ro); 3557 return sprintf(buf, "%d\n", curlun->ro);
3596} 3558}
3597 3559
3598static ssize_t show_file(struct device *dev, struct device_attribute *attr, char *buf) 3560static ssize_t show_file(struct device *dev, struct device_attribute *attr,
3561 char *buf)
3599{ 3562{
3600 struct lun *curlun = dev_to_lun(dev); 3563 struct lun *curlun = dev_to_lun(dev);
3601 struct fsg_dev *fsg = dev_get_drvdata(dev); 3564 struct fsg_dev *fsg = dev_get_drvdata(dev);
@@ -3604,8 +3567,8 @@ static ssize_t show_file(struct device *dev, struct device_attribute *attr, char
3604 3567
3605 down_read(&fsg->filesem); 3568 down_read(&fsg->filesem);
3606 if (backing_file_is_open(curlun)) { // Get the complete pathname 3569 if (backing_file_is_open(curlun)) { // Get the complete pathname
3607 p = d_path(curlun->filp->f_path.dentry, curlun->filp->f_path.mnt, 3570 p = d_path(curlun->filp->f_path.dentry,
3608 buf, PAGE_SIZE - 1); 3571 curlun->filp->f_path.mnt, buf, PAGE_SIZE - 1);
3609 if (IS_ERR(p)) 3572 if (IS_ERR(p))
3610 rc = PTR_ERR(p); 3573 rc = PTR_ERR(p);
3611 else { 3574 else {
@@ -3623,7 +3586,8 @@ static ssize_t show_file(struct device *dev, struct device_attribute *attr, char
3623} 3586}
3624 3587
3625 3588
3626static ssize_t store_ro(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 3589static ssize_t store_ro(struct device *dev, struct device_attribute *attr,
3590 const char *buf, size_t count)
3627{ 3591{
3628 ssize_t rc = count; 3592 ssize_t rc = count;
3629 struct lun *curlun = dev_to_lun(dev); 3593 struct lun *curlun = dev_to_lun(dev);
@@ -3647,7 +3611,8 @@ static ssize_t store_ro(struct device *dev, struct device_attribute *attr, const
3647 return rc; 3611 return rc;
3648} 3612}
3649 3613
3650static ssize_t store_file(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 3614static ssize_t store_file(struct device *dev, struct device_attribute *attr,
3615 const char *buf, size_t count)
3651{ 3616{
3652 struct lun *curlun = dev_to_lun(dev); 3617 struct lun *curlun = dev_to_lun(dev);
3653 struct fsg_dev *fsg = dev_get_drvdata(dev); 3618 struct fsg_dev *fsg = dev_get_drvdata(dev);
@@ -3859,7 +3824,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3859 /* Find out how many LUNs there should be */ 3824 /* Find out how many LUNs there should be */
3860 i = mod_data.nluns; 3825 i = mod_data.nluns;
3861 if (i == 0) 3826 if (i == 0)
3862 i = max(mod_data.num_filenames, 1); 3827 i = max(mod_data.num_filenames, 1u);
3863 if (i > MAX_LUNS) { 3828 if (i > MAX_LUNS) {
3864 ERROR(fsg, "invalid number of LUNs: %d\n", i); 3829 ERROR(fsg, "invalid number of LUNs: %d\n", i);
3865 rc = -EINVAL; 3830 rc = -EINVAL;
@@ -3944,21 +3909,23 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3944 intf_desc.bInterfaceProtocol = mod_data.transport_type; 3909 intf_desc.bInterfaceProtocol = mod_data.transport_type;
3945 fs_function[i + FS_FUNCTION_PRE_EP_ENTRIES] = NULL; 3910 fs_function[i + FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
3946 3911
3947#ifdef CONFIG_USB_GADGET_DUALSPEED 3912 if (gadget_is_dualspeed(gadget)) {
3948 hs_function[i + HS_FUNCTION_PRE_EP_ENTRIES] = NULL; 3913 hs_function[i + HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
3949 3914
3950 /* Assume ep0 uses the same maxpacket value for both speeds */ 3915 /* Assume ep0 uses the same maxpacket value for both speeds */
3951 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket; 3916 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
3952 3917
3953 /* Assume that all endpoint addresses are the same for both speeds */ 3918 /* Assume endpoint addresses are the same for both speeds */
3954 hs_bulk_in_desc.bEndpointAddress = fs_bulk_in_desc.bEndpointAddress; 3919 hs_bulk_in_desc.bEndpointAddress =
3955 hs_bulk_out_desc.bEndpointAddress = fs_bulk_out_desc.bEndpointAddress; 3920 fs_bulk_in_desc.bEndpointAddress;
3956 hs_intr_in_desc.bEndpointAddress = fs_intr_in_desc.bEndpointAddress; 3921 hs_bulk_out_desc.bEndpointAddress =
3957#endif 3922 fs_bulk_out_desc.bEndpointAddress;
3923 hs_intr_in_desc.bEndpointAddress =
3924 fs_intr_in_desc.bEndpointAddress;
3925 }
3958 3926
3959 if (gadget->is_otg) { 3927 if (gadget_is_otg(gadget))
3960 otg_desc.bmAttributes |= USB_OTG_HNP; 3928 otg_desc.bmAttributes |= USB_OTG_HNP;
3961 }
3962 3929
3963 rc = -ENOMEM; 3930 rc = -ENOMEM;
3964 3931
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c
index d57bcfbc08a5..9bb7f64a85cd 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -35,7 +35,7 @@
35#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
36#include <linux/device.h> 36#include <linux/device.h>
37#include <linux/usb/ch9.h> 37#include <linux/usb/ch9.h>
38#include <linux/usb_gadget.h> 38#include <linux/usb/gadget.h>
39#include <linux/usb/otg.h> 39#include <linux/usb/otg.h>
40#include <linux/dma-mapping.h> 40#include <linux/dma-mapping.h>
41#include <linux/platform_device.h> 41#include <linux/platform_device.h>
@@ -1090,14 +1090,11 @@ static int fsl_vbus_session(struct usb_gadget *gadget, int is_active)
1090 */ 1090 */
1091static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA) 1091static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1092{ 1092{
1093#ifdef CONFIG_USB_OTG
1094 struct fsl_udc *udc; 1093 struct fsl_udc *udc;
1095 1094
1096 udc = container_of(gadget, struct fsl_udc, gadget); 1095 udc = container_of(gadget, struct fsl_udc, gadget);
1097
1098 if (udc->transceiver) 1096 if (udc->transceiver)
1099 return otg_set_power(udc->transceiver, mA); 1097 return otg_set_power(udc->transceiver, mA);
1100#endif
1101 return -ENOTSUPP; 1098 return -ENOTSUPP;
1102} 1099}
1103 1100
@@ -1120,7 +1117,7 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
1120 return 0; 1117 return 0;
1121} 1118}
1122 1119
1123/* defined in usb_gadget.h */ 1120/* defined in gadget.h */
1124static struct usb_gadget_ops fsl_gadget_ops = { 1121static struct usb_gadget_ops fsl_gadget_ops = {
1125 .get_frame = fsl_get_frame, 1122 .get_frame = fsl_get_frame,
1126 .wakeup = fsl_wakeup, 1123 .wakeup = fsl_wakeup,
@@ -1321,7 +1318,7 @@ static void setup_received_irq(struct fsl_udc *udc,
1321 | USB_TYPE_STANDARD)) { 1318 | USB_TYPE_STANDARD)) {
1322 /* Note: The driver has not include OTG support yet. 1319 /* Note: The driver has not include OTG support yet.
1323 * This will be set when OTG support is added */ 1320 * This will be set when OTG support is added */
1324 if (!udc->gadget.is_otg) 1321 if (!gadget_is_otg(udc->gadget))
1325 break; 1322 break;
1326 else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE) 1323 else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE)
1327 udc->gadget.b_hnp_enable = 1; 1324 udc->gadget.b_hnp_enable = 1;
@@ -1330,6 +1327,8 @@ static void setup_received_irq(struct fsl_udc *udc,
1330 else if (setup->bRequest == 1327 else if (setup->bRequest ==
1331 USB_DEVICE_A_ALT_HNP_SUPPORT) 1328 USB_DEVICE_A_ALT_HNP_SUPPORT)
1332 udc->gadget.a_alt_hnp_support = 1; 1329 udc->gadget.a_alt_hnp_support = 1;
1330 else
1331 break;
1333 rc = 0; 1332 rc = 0;
1334 } else 1333 } else
1335 break; 1334 break;
@@ -1840,10 +1839,8 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1840 if (!driver || driver != udc_controller->driver || !driver->unbind) 1839 if (!driver || driver != udc_controller->driver || !driver->unbind)
1841 return -EINVAL; 1840 return -EINVAL;
1842 1841
1843#ifdef CONFIG_USB_OTG
1844 if (udc_controller->transceiver) 1842 if (udc_controller->transceiver)
1845 (void)otg_set_peripheral(udc_controller->transceiver, 0); 1843 (void)otg_set_peripheral(udc_controller->transceiver, 0);
1846#endif
1847 1844
1848 /* stop DR, disable intr */ 1845 /* stop DR, disable intr */
1849 dr_controller_stop(udc_controller); 1846 dr_controller_stop(udc_controller);
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 1c5aa49d7432..0689189550bc 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -18,17 +18,11 @@
18 * http://www.usb.org/developers/devclass_docs/midi10.pdf 18 * http://www.usb.org/developers/devclass_docs/midi10.pdf
19 */ 19 */
20 20
21#define DEBUG 1 21/* #define VERBOSE_DEBUG */
22// #define VERBOSE
23 22
24#include <linux/module.h>
25#include <linux/kernel.h> 23#include <linux/kernel.h>
26#include <linux/delay.h>
27#include <linux/errno.h>
28#include <linux/init.h>
29#include <linux/utsname.h> 24#include <linux/utsname.h>
30#include <linux/device.h> 25#include <linux/device.h>
31#include <linux/moduleparam.h>
32 26
33#include <sound/driver.h> 27#include <sound/driver.h>
34#include <sound/core.h> 28#include <sound/core.h>
@@ -36,7 +30,7 @@
36#include <sound/rawmidi.h> 30#include <sound/rawmidi.h>
37 31
38#include <linux/usb/ch9.h> 32#include <linux/usb/ch9.h>
39#include <linux/usb_gadget.h> 33#include <linux/usb/gadget.h>
40#include <linux/usb/audio.h> 34#include <linux/usb/audio.h>
41#include <linux/usb/midi.h> 35#include <linux/usb/midi.h>
42 36
@@ -139,30 +133,16 @@ struct gmidi_device {
139static void gmidi_transmit(struct gmidi_device* dev, struct usb_request* req); 133static void gmidi_transmit(struct gmidi_device* dev, struct usb_request* req);
140 134
141 135
142#define xprintk(d,level,fmt,args...) \ 136#define DBG(d, fmt, args...) \
143 dev_printk(level , &(d)->gadget->dev , fmt , ## args) 137 dev_dbg(&(d)->gadget->dev , fmt , ## args)
144 138#define VDBG(d, fmt, args...) \
145#ifdef DEBUG 139 dev_vdbg(&(d)->gadget->dev , fmt , ## args)
146#define DBG(dev,fmt,args...) \ 140#define ERROR(d, fmt, args...) \
147 xprintk(dev , KERN_DEBUG , fmt , ## args) 141 dev_err(&(d)->gadget->dev , fmt , ## args)
148#else 142#define WARN(d, fmt, args...) \
149#define DBG(dev,fmt,args...) \ 143 dev_warn(&(d)->gadget->dev , fmt , ## args)
150 do { } while (0) 144#define INFO(d, fmt, args...) \
151#endif /* DEBUG */ 145 dev_info(&(d)->gadget->dev , fmt , ## args)
152
153#ifdef VERBOSE
154#define VDBG DBG
155#else
156#define VDBG(dev,fmt,args...) \
157 do { } while (0)
158#endif /* VERBOSE */
159
160#define ERROR(dev,fmt,args...) \
161 xprintk(dev , KERN_ERR , fmt , ## args)
162#define WARN(dev,fmt,args...) \
163 xprintk(dev , KERN_WARNING , fmt , ## args)
164#define INFO(dev,fmt,args...) \
165 xprintk(dev , KERN_INFO , fmt , ## args)
166 146
167 147
168static unsigned buflen = 256; 148static unsigned buflen = 256;
@@ -425,7 +405,7 @@ static int config_buf(struct usb_gadget *gadget,
425 return len; 405 return len;
426} 406}
427 407
428static struct usb_request* alloc_ep_req(struct usb_ep *ep, unsigned length) 408static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length)
429{ 409{
430 struct usb_request *req; 410 struct usb_request *req;
431 411
@@ -455,7 +435,7 @@ static const uint8_t gmidi_cin_length[] = {
455 * Receives a chunk of MIDI data. 435 * Receives a chunk of MIDI data.
456 */ 436 */
457static void gmidi_read_data(struct usb_ep *ep, int cable, 437static void gmidi_read_data(struct usb_ep *ep, int cable,
458 uint8_t* data, int length) 438 uint8_t *data, int length)
459{ 439{
460 struct gmidi_device *dev = ep->driver_data; 440 struct gmidi_device *dev = ep->driver_data;
461 /* cable is ignored, because for now we only have one. */ 441 /* cable is ignored, because for now we only have one. */
@@ -541,7 +521,7 @@ static int set_gmidi_config(struct gmidi_device *dev, gfp_t gfp_flags)
541{ 521{
542 int err = 0; 522 int err = 0;
543 struct usb_request *req; 523 struct usb_request *req;
544 struct usb_ep* ep; 524 struct usb_ep *ep;
545 unsigned i; 525 unsigned i;
546 526
547 err = usb_ep_enable(dev->in_ep, &bulk_in_desc); 527 err = usb_ep_enable(dev->in_ep, &bulk_in_desc);
@@ -628,7 +608,7 @@ gmidi_set_config(struct gmidi_device *dev, unsigned number, gfp_t gfp_flags)
628 608
629 if (gadget_is_sa1100(gadget) && dev->config) { 609 if (gadget_is_sa1100(gadget) && dev->config) {
630 /* tx fifo is full, but we can't clear it...*/ 610 /* tx fifo is full, but we can't clear it...*/
631 INFO(dev, "can't change configurations\n"); 611 ERROR(dev, "can't change configurations\n");
632 return -ESPIPE; 612 return -ESPIPE;
633 } 613 }
634 gmidi_reset_config(dev); 614 gmidi_reset_config(dev);
@@ -843,7 +823,7 @@ static void gmidi_disconnect(struct usb_gadget *gadget)
843static void /* __init_or_exit */ gmidi_unbind(struct usb_gadget *gadget) 823static void /* __init_or_exit */ gmidi_unbind(struct usb_gadget *gadget)
844{ 824{
845 struct gmidi_device *dev = get_gadget_data(gadget); 825 struct gmidi_device *dev = get_gadget_data(gadget);
846 struct snd_card* card; 826 struct snd_card *card;
847 827
848 DBG(dev, "unbind\n"); 828 DBG(dev, "unbind\n");
849 829
@@ -867,12 +847,12 @@ static int gmidi_snd_free(struct snd_device *device)
867 return 0; 847 return 0;
868} 848}
869 849
870static void gmidi_transmit_packet(struct usb_request* req, uint8_t p0, 850static void gmidi_transmit_packet(struct usb_request *req, uint8_t p0,
871 uint8_t p1, uint8_t p2, uint8_t p3) 851 uint8_t p1, uint8_t p2, uint8_t p3)
872{ 852{
873 unsigned length = req->length; 853 unsigned length = req->length;
854 u8 *buf = (u8 *)req->buf + length;
874 855
875 uint8_t* buf = (uint8_t*)req->buf + length;
876 buf[0] = p0; 856 buf[0] = p0;
877 buf[1] = p1; 857 buf[1] = p1;
878 buf[2] = p2; 858 buf[2] = p2;
@@ -883,8 +863,8 @@ static void gmidi_transmit_packet(struct usb_request* req, uint8_t p0,
883/* 863/*
884 * Converts MIDI commands to USB MIDI packets. 864 * Converts MIDI commands to USB MIDI packets.
885 */ 865 */
886static void gmidi_transmit_byte(struct usb_request* req, 866static void gmidi_transmit_byte(struct usb_request *req,
887 struct gmidi_in_port* port, uint8_t b) 867 struct gmidi_in_port *port, uint8_t b)
888{ 868{
889 uint8_t p0 = port->cable; 869 uint8_t p0 = port->cable;
890 870
@@ -981,10 +961,10 @@ static void gmidi_transmit_byte(struct usb_request* req,
981 } 961 }
982} 962}
983 963
984static void gmidi_transmit(struct gmidi_device* dev, struct usb_request* req) 964static void gmidi_transmit(struct gmidi_device *dev, struct usb_request *req)
985{ 965{
986 struct usb_ep* ep = dev->in_ep; 966 struct usb_ep *ep = dev->in_ep;
987 struct gmidi_in_port* port = &dev->in_port; 967 struct gmidi_in_port *port = &dev->in_port;
988 968
989 if (!ep) { 969 if (!ep) {
990 return; 970 return;
@@ -1020,14 +1000,14 @@ static void gmidi_transmit(struct gmidi_device* dev, struct usb_request* req)
1020 1000
1021static void gmidi_in_tasklet(unsigned long data) 1001static void gmidi_in_tasklet(unsigned long data)
1022{ 1002{
1023 struct gmidi_device* dev = (struct gmidi_device*)data; 1003 struct gmidi_device *dev = (struct gmidi_device *)data;
1024 1004
1025 gmidi_transmit(dev, NULL); 1005 gmidi_transmit(dev, NULL);
1026} 1006}
1027 1007
1028static int gmidi_in_open(struct snd_rawmidi_substream *substream) 1008static int gmidi_in_open(struct snd_rawmidi_substream *substream)
1029{ 1009{
1030 struct gmidi_device* dev = substream->rmidi->private_data; 1010 struct gmidi_device *dev = substream->rmidi->private_data;
1031 1011
1032 VDBG(dev, "gmidi_in_open\n"); 1012 VDBG(dev, "gmidi_in_open\n");
1033 dev->in_substream = substream; 1013 dev->in_substream = substream;
@@ -1037,13 +1017,15 @@ static int gmidi_in_open(struct snd_rawmidi_substream *substream)
1037 1017
1038static int gmidi_in_close(struct snd_rawmidi_substream *substream) 1018static int gmidi_in_close(struct snd_rawmidi_substream *substream)
1039{ 1019{
1020 struct gmidi_device *dev = substream->rmidi->private_data;
1021
1040 VDBG(dev, "gmidi_in_close\n"); 1022 VDBG(dev, "gmidi_in_close\n");
1041 return 0; 1023 return 0;
1042} 1024}
1043 1025
1044static void gmidi_in_trigger(struct snd_rawmidi_substream *substream, int up) 1026static void gmidi_in_trigger(struct snd_rawmidi_substream *substream, int up)
1045{ 1027{
1046 struct gmidi_device* dev = substream->rmidi->private_data; 1028 struct gmidi_device *dev = substream->rmidi->private_data;
1047 1029
1048 VDBG(dev, "gmidi_in_trigger %d\n", up); 1030 VDBG(dev, "gmidi_in_trigger %d\n", up);
1049 dev->in_port.active = up; 1031 dev->in_port.active = up;
@@ -1054,7 +1036,7 @@ static void gmidi_in_trigger(struct snd_rawmidi_substream *substream, int up)
1054 1036
1055static int gmidi_out_open(struct snd_rawmidi_substream *substream) 1037static int gmidi_out_open(struct snd_rawmidi_substream *substream)
1056{ 1038{
1057 struct gmidi_device* dev = substream->rmidi->private_data; 1039 struct gmidi_device *dev = substream->rmidi->private_data;
1058 1040
1059 VDBG(dev, "gmidi_out_open\n"); 1041 VDBG(dev, "gmidi_out_open\n");
1060 dev->out_substream = substream; 1042 dev->out_substream = substream;
@@ -1063,13 +1045,15 @@ static int gmidi_out_open(struct snd_rawmidi_substream *substream)
1063 1045
1064static int gmidi_out_close(struct snd_rawmidi_substream *substream) 1046static int gmidi_out_close(struct snd_rawmidi_substream *substream)
1065{ 1047{
1048 struct gmidi_device *dev = substream->rmidi->private_data;
1049
1066 VDBG(dev, "gmidi_out_close\n"); 1050 VDBG(dev, "gmidi_out_close\n");
1067 return 0; 1051 return 0;
1068} 1052}
1069 1053
1070static void gmidi_out_trigger(struct snd_rawmidi_substream *substream, int up) 1054static void gmidi_out_trigger(struct snd_rawmidi_substream *substream, int up)
1071{ 1055{
1072 struct gmidi_device* dev = substream->rmidi->private_data; 1056 struct gmidi_device *dev = substream->rmidi->private_data;
1073 1057
1074 VDBG(dev, "gmidi_out_trigger %d\n", up); 1058 VDBG(dev, "gmidi_out_trigger %d\n", up);
1075 if (up) { 1059 if (up) {
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 349b8166f34a..2ec9d196a8cf 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -37,7 +37,7 @@
37#include <linux/proc_fs.h> 37#include <linux/proc_fs.h>
38#include <linux/device.h> 38#include <linux/device.h>
39#include <linux/usb/ch9.h> 39#include <linux/usb/ch9.h>
40#include <linux/usb_gadget.h> 40#include <linux/usb/gadget.h>
41 41
42#include <asm/byteorder.h> 42#include <asm/byteorder.h>
43#include <asm/io.h> 43#include <asm/io.h>
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 173004f60fea..47ef8bd58a00 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -20,8 +20,7 @@
20 */ 20 */
21 21
22 22
23// #define DEBUG /* data to help fault diagnosis */ 23/* #define VERBOSE_DEBUG */
24// #define VERBOSE /* extra debug messages (success too) */
25 24
26#include <linux/init.h> 25#include <linux/init.h>
27#include <linux/module.h> 26#include <linux/module.h>
@@ -38,7 +37,7 @@
38#include <linux/moduleparam.h> 37#include <linux/moduleparam.h>
39 38
40#include <linux/usb/gadgetfs.h> 39#include <linux/usb/gadgetfs.h>
41#include <linux/usb_gadget.h> 40#include <linux/usb/gadget.h>
42 41
43 42
44/* 43/*
@@ -253,7 +252,7 @@ static const char *CHIP;
253 do { } while (0) 252 do { } while (0)
254#endif /* DEBUG */ 253#endif /* DEBUG */
255 254
256#ifdef VERBOSE 255#ifdef VERBOSE_DEBUG
257#define VDEBUG DBG 256#define VDEBUG DBG
258#else 257#else
259#define VDEBUG(dev,fmt,args...) \ 258#define VDEBUG(dev,fmt,args...) \
@@ -1010,11 +1009,12 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
1010 /* assume that was SET_CONFIGURATION */ 1009 /* assume that was SET_CONFIGURATION */
1011 if (dev->current_config) { 1010 if (dev->current_config) {
1012 unsigned power; 1011 unsigned power;
1013#ifdef CONFIG_USB_GADGET_DUALSPEED 1012
1014 if (dev->gadget->speed == USB_SPEED_HIGH) 1013 if (gadget_is_dualspeed(dev->gadget)
1014 && (dev->gadget->speed
1015 == USB_SPEED_HIGH))
1015 power = dev->hs_config->bMaxPower; 1016 power = dev->hs_config->bMaxPower;
1016 else 1017 else
1017#endif
1018 power = dev->config->bMaxPower; 1018 power = dev->config->bMaxPower;
1019 usb_gadget_vbus_draw(dev->gadget, 2 * power); 1019 usb_gadget_vbus_draw(dev->gadget, 2 * power);
1020 } 1020 }
@@ -1355,24 +1355,21 @@ static int
1355config_buf (struct dev_data *dev, u8 type, unsigned index) 1355config_buf (struct dev_data *dev, u8 type, unsigned index)
1356{ 1356{
1357 int len; 1357 int len;
1358#ifdef CONFIG_USB_GADGET_DUALSPEED 1358 int hs = 0;
1359 int hs;
1360#endif
1361 1359
1362 /* only one configuration */ 1360 /* only one configuration */
1363 if (index > 0) 1361 if (index > 0)
1364 return -EINVAL; 1362 return -EINVAL;
1365 1363
1366#ifdef CONFIG_USB_GADGET_DUALSPEED 1364 if (gadget_is_dualspeed(dev->gadget)) {
1367 hs = (dev->gadget->speed == USB_SPEED_HIGH); 1365 hs = (dev->gadget->speed == USB_SPEED_HIGH);
1368 if (type == USB_DT_OTHER_SPEED_CONFIG) 1366 if (type == USB_DT_OTHER_SPEED_CONFIG)
1369 hs = !hs; 1367 hs = !hs;
1368 }
1370 if (hs) { 1369 if (hs) {
1371 dev->req->buf = dev->hs_config; 1370 dev->req->buf = dev->hs_config;
1372 len = le16_to_cpu(dev->hs_config->wTotalLength); 1371 len = le16_to_cpu(dev->hs_config->wTotalLength);
1373 } else 1372 } else {
1374#endif
1375 {
1376 dev->req->buf = dev->config; 1373 dev->req->buf = dev->config;
1377 len = le16_to_cpu(dev->config->wTotalLength); 1374 len = le16_to_cpu(dev->config->wTotalLength);
1378 } 1375 }
@@ -1393,13 +1390,13 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1393 spin_lock (&dev->lock); 1390 spin_lock (&dev->lock);
1394 dev->setup_abort = 0; 1391 dev->setup_abort = 0;
1395 if (dev->state == STATE_DEV_UNCONNECTED) { 1392 if (dev->state == STATE_DEV_UNCONNECTED) {
1396#ifdef CONFIG_USB_GADGET_DUALSPEED 1393 if (gadget_is_dualspeed(gadget)
1397 if (gadget->speed == USB_SPEED_HIGH && dev->hs_config == NULL) { 1394 && gadget->speed == USB_SPEED_HIGH
1395 && dev->hs_config == NULL) {
1398 spin_unlock(&dev->lock); 1396 spin_unlock(&dev->lock);
1399 ERROR (dev, "no high speed config??\n"); 1397 ERROR (dev, "no high speed config??\n");
1400 return -EINVAL; 1398 return -EINVAL;
1401 } 1399 }
1402#endif /* CONFIG_USB_GADGET_DUALSPEED */
1403 1400
1404 dev->state = STATE_DEV_CONNECTED; 1401 dev->state = STATE_DEV_CONNECTED;
1405 dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket; 1402 dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket;
@@ -1469,13 +1466,12 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1469 // user mode expected to disable endpoints 1466 // user mode expected to disable endpoints
1470 } else { 1467 } else {
1471 u8 config, power; 1468 u8 config, power;
1472#ifdef CONFIG_USB_GADGET_DUALSPEED 1469
1473 if (gadget->speed == USB_SPEED_HIGH) { 1470 if (gadget_is_dualspeed(gadget)
1471 && gadget->speed == USB_SPEED_HIGH) {
1474 config = dev->hs_config->bConfigurationValue; 1472 config = dev->hs_config->bConfigurationValue;
1475 power = dev->hs_config->bMaxPower; 1473 power = dev->hs_config->bMaxPower;
1476 } else 1474 } else {
1477#endif
1478 {
1479 config = dev->config->bConfigurationValue; 1475 config = dev->config->bConfigurationValue;
1480 power = dev->config->bMaxPower; 1476 power = dev->config->bMaxPower;
1481 } 1477 }
diff --git a/drivers/usb/gadget/lh7a40x_udc.h b/drivers/usb/gadget/lh7a40x_udc.h
index b3fe197e1eeb..1ecfd6366b9a 100644
--- a/drivers/usb/gadget/lh7a40x_udc.h
+++ b/drivers/usb/gadget/lh7a40x_udc.h
@@ -50,7 +50,7 @@
50#include <asm/hardware.h> 50#include <asm/hardware.h>
51 51
52#include <linux/usb/ch9.h> 52#include <linux/usb/ch9.h>
53#include <linux/usb_gadget.h> 53#include <linux/usb/gadget.h>
54 54
55/* 55/*
56 * Memory map 56 * Memory map
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index 4b27d12f049d..ebc5536aa271 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -27,7 +27,7 @@
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28 28
29#include <linux/usb/ch9.h> 29#include <linux/usb/ch9.h>
30#include <linux/usb_gadget.h> 30#include <linux/usb/gadget.h>
31 31
32#include "m66592-udc.h" 32#include "m66592-udc.h"
33 33
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index c3d364ecd4f8..d5d473f8144b 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -62,7 +62,7 @@
62#include <linux/moduleparam.h> 62#include <linux/moduleparam.h>
63#include <linux/device.h> 63#include <linux/device.h>
64#include <linux/usb/ch9.h> 64#include <linux/usb/ch9.h>
65#include <linux/usb_gadget.h> 65#include <linux/usb/gadget.h>
66 66
67#include <asm/byteorder.h> 67#include <asm/byteorder.h>
68#include <asm/io.h> 68#include <asm/io.h>
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 9b0f0925dddf..87c4f50dfb61 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -38,7 +38,7 @@
38#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
39#include <linux/platform_device.h> 39#include <linux/platform_device.h>
40#include <linux/usb/ch9.h> 40#include <linux/usb/ch9.h>
41#include <linux/usb_gadget.h> 41#include <linux/usb/gadget.h>
42#include <linux/usb/otg.h> 42#include <linux/usb/otg.h>
43#include <linux/dma-mapping.h> 43#include <linux/dma-mapping.h>
44#include <linux/clk.h> 44#include <linux/clk.h>
@@ -1241,19 +1241,15 @@ static void pullup_enable(struct omap_udc *udc)
1241 udc->gadget.dev.parent->power.power_state = PMSG_ON; 1241 udc->gadget.dev.parent->power.power_state = PMSG_ON;
1242 udc->gadget.dev.power.power_state = PMSG_ON; 1242 udc->gadget.dev.power.power_state = PMSG_ON;
1243 UDC_SYSCON1_REG |= UDC_PULLUP_EN; 1243 UDC_SYSCON1_REG |= UDC_PULLUP_EN;
1244#ifndef CONFIG_USB_OTG 1244 if (!gadget_is_otg(udc->gadget) && !cpu_is_omap15xx())
1245 if (!cpu_is_omap15xx())
1246 OTG_CTRL_REG |= OTG_BSESSVLD; 1245 OTG_CTRL_REG |= OTG_BSESSVLD;
1247#endif
1248 UDC_IRQ_EN_REG = UDC_DS_CHG_IE; 1246 UDC_IRQ_EN_REG = UDC_DS_CHG_IE;
1249} 1247}
1250 1248
1251static void pullup_disable(struct omap_udc *udc) 1249static void pullup_disable(struct omap_udc *udc)
1252{ 1250{
1253#ifndef CONFIG_USB_OTG 1251 if (!gadget_is_otg(udc->gadget) && !cpu_is_omap15xx())
1254 if (!cpu_is_omap15xx())
1255 OTG_CTRL_REG &= ~OTG_BSESSVLD; 1252 OTG_CTRL_REG &= ~OTG_BSESSVLD;
1256#endif
1257 UDC_IRQ_EN_REG = UDC_DS_CHG_IE; 1253 UDC_IRQ_EN_REG = UDC_DS_CHG_IE;
1258 UDC_SYSCON1_REG &= ~UDC_PULLUP_EN; 1254 UDC_SYSCON1_REG &= ~UDC_PULLUP_EN;
1259} 1255}
@@ -1390,7 +1386,7 @@ static void update_otg(struct omap_udc *udc)
1390{ 1386{
1391 u16 devstat; 1387 u16 devstat;
1392 1388
1393 if (!udc->gadget.is_otg) 1389 if (!gadget_is_otg(udc->gadget))
1394 return; 1390 return;
1395 1391
1396 if (OTG_CTRL_REG & OTG_ID) 1392 if (OTG_CTRL_REG & OTG_ID)
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index 1407ad1c8128..3e715082de36 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -54,7 +54,7 @@
54#include <asm/hardware.h> 54#include <asm/hardware.h>
55 55
56#include <linux/usb/ch9.h> 56#include <linux/usb/ch9.h>
57#include <linux/usb_gadget.h> 57#include <linux/usb/gadget.h>
58 58
59#include <asm/mach/udc_pxa2xx.h> 59#include <asm/mach/udc_pxa2xx.h>
60 60
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index 0be80c635c48..e3e90f8a75e7 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -42,7 +42,7 @@
42#include <linux/seq_file.h> 42#include <linux/seq_file.h>
43 43
44#include <linux/usb.h> 44#include <linux/usb.h>
45#include <linux/usb_gadget.h> 45#include <linux/usb/gadget.h>
46 46
47#include <asm/byteorder.h> 47#include <asm/byteorder.h>
48#include <asm/io.h> 48#include <asm/io.h>
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index ce4d2e09633d..f5738eb8e765 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -17,34 +17,15 @@
17 * 17 *
18 */ 18 */
19 19
20#include <linux/module.h>
21#include <linux/kernel.h> 20#include <linux/kernel.h>
22#include <linux/delay.h>
23#include <linux/ioport.h>
24#include <linux/slab.h>
25#include <linux/errno.h>
26#include <linux/init.h>
27#include <linux/timer.h>
28#include <linux/list.h>
29#include <linux/interrupt.h>
30#include <linux/utsname.h> 21#include <linux/utsname.h>
31#include <linux/wait.h>
32#include <linux/proc_fs.h>
33#include <linux/device.h> 22#include <linux/device.h>
34#include <linux/tty.h> 23#include <linux/tty.h>
35#include <linux/tty_flip.h> 24#include <linux/tty_flip.h>
36#include <linux/mutex.h>
37
38#include <asm/byteorder.h>
39#include <asm/io.h>
40#include <asm/irq.h>
41#include <asm/system.h>
42#include <asm/unaligned.h>
43#include <asm/uaccess.h>
44 25
45#include <linux/usb/ch9.h> 26#include <linux/usb/ch9.h>
46#include <linux/usb/cdc.h> 27#include <linux/usb/cdc.h>
47#include <linux/usb_gadget.h> 28#include <linux/usb/gadget.h>
48 29
49#include "gadget_chips.h" 30#include "gadget_chips.h"
50 31
@@ -89,30 +70,29 @@
89#define GS_DEFAULT_PARITY USB_CDC_NO_PARITY 70#define GS_DEFAULT_PARITY USB_CDC_NO_PARITY
90#define GS_DEFAULT_CHAR_FORMAT USB_CDC_1_STOP_BITS 71#define GS_DEFAULT_CHAR_FORMAT USB_CDC_1_STOP_BITS
91 72
92/* select highspeed/fullspeed, hiding highspeed if not configured */ 73/* maxpacket and other transfer characteristics vary by speed. */
93#ifdef CONFIG_USB_GADGET_DUALSPEED 74static inline struct usb_endpoint_descriptor *
94#define GS_SPEED_SELECT(is_hs,hs,fs) ((is_hs) ? (hs) : (fs)) 75choose_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
95#else 76 struct usb_endpoint_descriptor *fs)
96#define GS_SPEED_SELECT(is_hs,hs,fs) (fs) 77{
97#endif /* CONFIG_USB_GADGET_DUALSPEED */ 78 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
79 return hs;
80 return fs;
81}
82
98 83
99/* debug settings */ 84/* debug settings */
100#ifdef GS_DEBUG 85#ifdef DEBUG
101static int debug = 1; 86static int debug = 1;
87#else
88#define debug 0
89#endif
102 90
103#define gs_debug(format, arg...) \ 91#define gs_debug(format, arg...) \
104 do { if (debug) printk(KERN_DEBUG format, ## arg); } while(0) 92 do { if (debug) printk(KERN_DEBUG format, ## arg); } while(0)
105#define gs_debug_level(level, format, arg...) \ 93#define gs_debug_level(level, format, arg...) \
106 do { if (debug>=level) printk(KERN_DEBUG format, ## arg); } while(0) 94 do { if (debug>=level) printk(KERN_DEBUG format, ## arg); } while(0)
107 95
108#else
109
110#define gs_debug(format, arg...) \
111 do { } while(0)
112#define gs_debug_level(level, format, arg...) \
113 do { } while(0)
114
115#endif /* GS_DEBUG */
116 96
117/* Thanks to NetChip Technologies for donating this product ID. 97/* Thanks to NetChip Technologies for donating this product ID.
118 * 98 *
@@ -147,10 +127,10 @@ struct gs_req_entry {
147 127
148/* the port structure holds info for each port, one for each minor number */ 128/* the port structure holds info for each port, one for each minor number */
149struct gs_port { 129struct gs_port {
150 struct gs_dev *port_dev; /* pointer to device struct */ 130 struct gs_dev *port_dev; /* pointer to device struct */
151 struct tty_struct *port_tty; /* pointer to tty struct */ 131 struct tty_struct *port_tty; /* pointer to tty struct */
152 spinlock_t port_lock; 132 spinlock_t port_lock;
153 int port_num; 133 int port_num;
154 int port_open_count; 134 int port_open_count;
155 int port_in_use; /* open/close in progress */ 135 int port_in_use; /* open/close in progress */
156 wait_queue_head_t port_write_wait;/* waiting to write */ 136 wait_queue_head_t port_write_wait;/* waiting to write */
@@ -188,7 +168,7 @@ static void __exit gs_module_exit(void);
188/* tty driver */ 168/* tty driver */
189static int gs_open(struct tty_struct *tty, struct file *file); 169static int gs_open(struct tty_struct *tty, struct file *file);
190static void gs_close(struct tty_struct *tty, struct file *file); 170static void gs_close(struct tty_struct *tty, struct file *file);
191static int gs_write(struct tty_struct *tty, 171static int gs_write(struct tty_struct *tty,
192 const unsigned char *buf, int count); 172 const unsigned char *buf, int count);
193static void gs_put_char(struct tty_struct *tty, unsigned char ch); 173static void gs_put_char(struct tty_struct *tty, unsigned char ch);
194static void gs_flush_chars(struct tty_struct *tty); 174static void gs_flush_chars(struct tty_struct *tty);
@@ -222,7 +202,7 @@ static void gs_setup_complete(struct usb_ep *ep, struct usb_request *req);
222static void gs_disconnect(struct usb_gadget *gadget); 202static void gs_disconnect(struct usb_gadget *gadget);
223static int gs_set_config(struct gs_dev *dev, unsigned config); 203static int gs_set_config(struct gs_dev *dev, unsigned config);
224static void gs_reset_config(struct gs_dev *dev); 204static void gs_reset_config(struct gs_dev *dev);
225static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed, 205static int gs_build_config_buf(u8 *buf, struct usb_gadget *g,
226 u8 type, unsigned int index, int is_otg); 206 u8 type, unsigned int index, int is_otg);
227 207
228static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, 208static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len,
@@ -415,18 +395,18 @@ static const struct usb_cdc_header_desc gs_header_desc = {
415}; 395};
416 396
417static const struct usb_cdc_call_mgmt_descriptor gs_call_mgmt_descriptor = { 397static const struct usb_cdc_call_mgmt_descriptor gs_call_mgmt_descriptor = {
418 .bLength = sizeof(gs_call_mgmt_descriptor), 398 .bLength = sizeof(gs_call_mgmt_descriptor),
419 .bDescriptorType = USB_DT_CS_INTERFACE, 399 .bDescriptorType = USB_DT_CS_INTERFACE,
420 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE, 400 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
421 .bmCapabilities = 0, 401 .bmCapabilities = 0,
422 .bDataInterface = 1, /* index of data interface */ 402 .bDataInterface = 1, /* index of data interface */
423}; 403};
424 404
425static struct usb_cdc_acm_descriptor gs_acm_descriptor = { 405static struct usb_cdc_acm_descriptor gs_acm_descriptor = {
426 .bLength = sizeof(gs_acm_descriptor), 406 .bLength = sizeof(gs_acm_descriptor),
427 .bDescriptorType = USB_DT_CS_INTERFACE, 407 .bDescriptorType = USB_DT_CS_INTERFACE,
428 .bDescriptorSubType = USB_CDC_ACM_TYPE, 408 .bDescriptorSubType = USB_CDC_ACM_TYPE,
429 .bmCapabilities = 0, 409 .bmCapabilities = 0,
430}; 410};
431 411
432static const struct usb_cdc_union_desc gs_union_desc = { 412static const struct usb_cdc_union_desc gs_union_desc = {
@@ -436,7 +416,7 @@ static const struct usb_cdc_union_desc gs_union_desc = {
436 .bMasterInterface0 = 0, /* index of control interface */ 416 .bMasterInterface0 = 0, /* index of control interface */
437 .bSlaveInterface0 = 1, /* index of data interface */ 417 .bSlaveInterface0 = 1, /* index of data interface */
438}; 418};
439 419
440static struct usb_endpoint_descriptor gs_fullspeed_notify_desc = { 420static struct usb_endpoint_descriptor gs_fullspeed_notify_desc = {
441 .bLength = USB_DT_ENDPOINT_SIZE, 421 .bLength = USB_DT_ENDPOINT_SIZE,
442 .bDescriptorType = USB_DT_ENDPOINT, 422 .bDescriptorType = USB_DT_ENDPOINT,
@@ -482,7 +462,6 @@ static const struct usb_descriptor_header *gs_acm_fullspeed_function[] = {
482 NULL, 462 NULL,
483}; 463};
484 464
485#ifdef CONFIG_USB_GADGET_DUALSPEED
486static struct usb_endpoint_descriptor gs_highspeed_notify_desc = { 465static struct usb_endpoint_descriptor gs_highspeed_notify_desc = {
487 .bLength = USB_DT_ENDPOINT_SIZE, 466 .bLength = USB_DT_ENDPOINT_SIZE,
488 .bDescriptorType = USB_DT_ENDPOINT, 467 .bDescriptorType = USB_DT_ENDPOINT,
@@ -536,15 +515,13 @@ static const struct usb_descriptor_header *gs_acm_highspeed_function[] = {
536 NULL, 515 NULL,
537}; 516};
538 517
539#endif /* CONFIG_USB_GADGET_DUALSPEED */
540
541 518
542/* Module */ 519/* Module */
543MODULE_DESCRIPTION(GS_LONG_NAME); 520MODULE_DESCRIPTION(GS_LONG_NAME);
544MODULE_AUTHOR("Al Borchers"); 521MODULE_AUTHOR("Al Borchers");
545MODULE_LICENSE("GPL"); 522MODULE_LICENSE("GPL");
546 523
547#ifdef GS_DEBUG 524#ifdef DEBUG
548module_param(debug, int, S_IRUGO|S_IWUSR); 525module_param(debug, int, S_IRUGO|S_IWUSR);
549MODULE_PARM_DESC(debug, "Enable debugging, 0=off, 1=on"); 526MODULE_PARM_DESC(debug, "Enable debugging, 0=off, 1=on");
550#endif 527#endif
@@ -915,7 +892,8 @@ static void gs_put_char(struct tty_struct *tty, unsigned char ch)
915 return; 892 return;
916 } 893 }
917 894
918 gs_debug("gs_put_char: (%d,%p) char=0x%x, called from %p, %p, %p\n", port->port_num, tty, ch, __builtin_return_address(0), __builtin_return_address(1), __builtin_return_address(2)); 895 gs_debug("gs_put_char: (%d,%p) char=0x%x, called from %p\n",
896 port->port_num, tty, ch, __builtin_return_address(0));
919 897
920 spin_lock_irqsave(&port->port_lock, flags); 898 spin_lock_irqsave(&port->port_lock, flags);
921 899
@@ -1116,7 +1094,11 @@ static int gs_send(struct gs_dev *dev)
1116 len = gs_send_packet(dev, req->buf, ep->maxpacket); 1094 len = gs_send_packet(dev, req->buf, ep->maxpacket);
1117 1095
1118 if (len > 0) { 1096 if (len > 0) {
1119gs_debug_level(3, "gs_send: len=%d, 0x%2.2x 0x%2.2x 0x%2.2x ...\n", len, *((unsigned char *)req->buf), *((unsigned char *)req->buf+1), *((unsigned char *)req->buf+2)); 1097 gs_debug_level(3, "gs_send: len=%d, 0x%2.2x "
1098 "0x%2.2x 0x%2.2x ...\n", len,
1099 *((unsigned char *)req->buf),
1100 *((unsigned char *)req->buf+1),
1101 *((unsigned char *)req->buf+2));
1120 list_del(&req_entry->re_entry); 1102 list_del(&req_entry->re_entry);
1121 req->length = len; 1103 req->length = len;
1122 spin_unlock_irqrestore(&dev->dev_lock, flags); 1104 spin_unlock_irqrestore(&dev->dev_lock, flags);
@@ -1269,7 +1251,7 @@ static void gs_read_complete(struct usb_ep *ep, struct usb_request *req)
1269 1251
1270 switch(req->status) { 1252 switch(req->status) {
1271 case 0: 1253 case 0:
1272 /* normal completion */ 1254 /* normal completion */
1273 gs_recv_packet(dev, req->buf, req->actual); 1255 gs_recv_packet(dev, req->buf, req->actual);
1274requeue: 1256requeue:
1275 req->length = ep->maxpacket; 1257 req->length = ep->maxpacket;
@@ -1406,23 +1388,24 @@ static int __init gs_bind(struct usb_gadget *gadget)
1406 ? USB_CLASS_COMM : USB_CLASS_VENDOR_SPEC; 1388 ? USB_CLASS_COMM : USB_CLASS_VENDOR_SPEC;
1407 gs_device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; 1389 gs_device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1408 1390
1409#ifdef CONFIG_USB_GADGET_DUALSPEED 1391 if (gadget_is_dualspeed(gadget)) {
1410 gs_qualifier_desc.bDeviceClass = use_acm 1392 gs_qualifier_desc.bDeviceClass = use_acm
1411 ? USB_CLASS_COMM : USB_CLASS_VENDOR_SPEC; 1393 ? USB_CLASS_COMM : USB_CLASS_VENDOR_SPEC;
1412 /* assume ep0 uses the same packet size for both speeds */ 1394 /* assume ep0 uses the same packet size for both speeds */
1413 gs_qualifier_desc.bMaxPacketSize0 = gs_device_desc.bMaxPacketSize0; 1395 gs_qualifier_desc.bMaxPacketSize0 =
1414 /* assume endpoints are dual-speed */ 1396 gs_device_desc.bMaxPacketSize0;
1415 gs_highspeed_notify_desc.bEndpointAddress = 1397 /* assume endpoints are dual-speed */
1416 gs_fullspeed_notify_desc.bEndpointAddress; 1398 gs_highspeed_notify_desc.bEndpointAddress =
1417 gs_highspeed_in_desc.bEndpointAddress = 1399 gs_fullspeed_notify_desc.bEndpointAddress;
1418 gs_fullspeed_in_desc.bEndpointAddress; 1400 gs_highspeed_in_desc.bEndpointAddress =
1419 gs_highspeed_out_desc.bEndpointAddress = 1401 gs_fullspeed_in_desc.bEndpointAddress;
1420 gs_fullspeed_out_desc.bEndpointAddress; 1402 gs_highspeed_out_desc.bEndpointAddress =
1421#endif /* CONFIG_USB_GADGET_DUALSPEED */ 1403 gs_fullspeed_out_desc.bEndpointAddress;
1404 }
1422 1405
1423 usb_gadget_set_selfpowered(gadget); 1406 usb_gadget_set_selfpowered(gadget);
1424 1407
1425 if (gadget->is_otg) { 1408 if (gadget_is_otg(gadget)) {
1426 gs_otg_descriptor.bmAttributes |= USB_OTG_HNP, 1409 gs_otg_descriptor.bmAttributes |= USB_OTG_HNP,
1427 gs_bulk_config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1410 gs_bulk_config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1428 gs_acm_config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1411 gs_acm_config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
@@ -1487,6 +1470,12 @@ static void /* __init_or_exit */ gs_unbind(struct usb_gadget *gadget)
1487 dev->dev_ctrl_req = NULL; 1470 dev->dev_ctrl_req = NULL;
1488 } 1471 }
1489 gs_free_ports(dev); 1472 gs_free_ports(dev);
1473 if (dev->dev_notify_ep)
1474 usb_ep_disable(dev->dev_notify_ep);
1475 if (dev->dev_in_ep)
1476 usb_ep_disable(dev->dev_in_ep);
1477 if (dev->dev_out_ep)
1478 usb_ep_disable(dev->dev_out_ep);
1490 kfree(dev); 1479 kfree(dev);
1491 set_gadget_data(gadget, NULL); 1480 set_gadget_data(gadget, NULL);
1492 } 1481 }
@@ -1570,9 +1559,8 @@ static int gs_setup_standard(struct usb_gadget *gadget,
1570 memcpy(req->buf, &gs_device_desc, ret); 1559 memcpy(req->buf, &gs_device_desc, ret);
1571 break; 1560 break;
1572 1561
1573#ifdef CONFIG_USB_GADGET_DUALSPEED
1574 case USB_DT_DEVICE_QUALIFIER: 1562 case USB_DT_DEVICE_QUALIFIER:
1575 if (!gadget->is_dualspeed) 1563 if (!gadget_is_dualspeed(gadget))
1576 break; 1564 break;
1577 ret = min(wLength, 1565 ret = min(wLength,
1578 (u16)sizeof(struct usb_qualifier_descriptor)); 1566 (u16)sizeof(struct usb_qualifier_descriptor));
@@ -1580,14 +1568,13 @@ static int gs_setup_standard(struct usb_gadget *gadget,
1580 break; 1568 break;
1581 1569
1582 case USB_DT_OTHER_SPEED_CONFIG: 1570 case USB_DT_OTHER_SPEED_CONFIG:
1583 if (!gadget->is_dualspeed) 1571 if (!gadget_is_dualspeed(gadget))
1584 break; 1572 break;
1585 /* fall through */ 1573 /* fall through */
1586#endif /* CONFIG_USB_GADGET_DUALSPEED */
1587 case USB_DT_CONFIG: 1574 case USB_DT_CONFIG:
1588 ret = gs_build_config_buf(req->buf, gadget->speed, 1575 ret = gs_build_config_buf(req->buf, gadget,
1589 wValue >> 8, wValue & 0xff, 1576 wValue >> 8, wValue & 0xff,
1590 gadget->is_otg); 1577 gadget_is_otg(gadget));
1591 if (ret >= 0) 1578 if (ret >= 0)
1592 ret = min(wLength, (u16)ret); 1579 ret = min(wLength, (u16)ret);
1593 break; 1580 break;
@@ -1827,8 +1814,7 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1827 1814
1828 if (EP_NOTIFY_NAME 1815 if (EP_NOTIFY_NAME
1829 && strcmp(ep->name, EP_NOTIFY_NAME) == 0) { 1816 && strcmp(ep->name, EP_NOTIFY_NAME) == 0) {
1830 ep_desc = GS_SPEED_SELECT( 1817 ep_desc = choose_ep_desc(gadget,
1831 gadget->speed == USB_SPEED_HIGH,
1832 &gs_highspeed_notify_desc, 1818 &gs_highspeed_notify_desc,
1833 &gs_fullspeed_notify_desc); 1819 &gs_fullspeed_notify_desc);
1834 ret = usb_ep_enable(ep,ep_desc); 1820 ret = usb_ep_enable(ep,ep_desc);
@@ -1844,9 +1830,8 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1844 } 1830 }
1845 1831
1846 else if (strcmp(ep->name, EP_IN_NAME) == 0) { 1832 else if (strcmp(ep->name, EP_IN_NAME) == 0) {
1847 ep_desc = GS_SPEED_SELECT( 1833 ep_desc = choose_ep_desc(gadget,
1848 gadget->speed == USB_SPEED_HIGH, 1834 &gs_highspeed_in_desc,
1849 &gs_highspeed_in_desc,
1850 &gs_fullspeed_in_desc); 1835 &gs_fullspeed_in_desc);
1851 ret = usb_ep_enable(ep,ep_desc); 1836 ret = usb_ep_enable(ep,ep_desc);
1852 if (ret == 0) { 1837 if (ret == 0) {
@@ -1861,8 +1846,7 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1861 } 1846 }
1862 1847
1863 else if (strcmp(ep->name, EP_OUT_NAME) == 0) { 1848 else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
1864 ep_desc = GS_SPEED_SELECT( 1849 ep_desc = choose_ep_desc(gadget,
1865 gadget->speed == USB_SPEED_HIGH,
1866 &gs_highspeed_out_desc, 1850 &gs_highspeed_out_desc,
1867 &gs_fullspeed_out_desc); 1851 &gs_fullspeed_out_desc);
1868 ret = usb_ep_enable(ep,ep_desc); 1852 ret = usb_ep_enable(ep,ep_desc);
@@ -1981,11 +1965,11 @@ static void gs_reset_config(struct gs_dev *dev)
1981 * Builds the config descriptors in the given buffer and returns the 1965 * Builds the config descriptors in the given buffer and returns the
1982 * length, or a negative error number. 1966 * length, or a negative error number.
1983 */ 1967 */
1984static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed, 1968static int gs_build_config_buf(u8 *buf, struct usb_gadget *g,
1985 u8 type, unsigned int index, int is_otg) 1969 u8 type, unsigned int index, int is_otg)
1986{ 1970{
1987 int len; 1971 int len;
1988 int high_speed; 1972 int high_speed = 0;
1989 const struct usb_config_descriptor *config_desc; 1973 const struct usb_config_descriptor *config_desc;
1990 const struct usb_descriptor_header **function; 1974 const struct usb_descriptor_header **function;
1991 1975
@@ -1993,20 +1977,22 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
1993 return -EINVAL; 1977 return -EINVAL;
1994 1978
1995 /* other speed switches high and full speed */ 1979 /* other speed switches high and full speed */
1996 high_speed = (speed == USB_SPEED_HIGH); 1980 if (gadget_is_dualspeed(g)) {
1997 if (type == USB_DT_OTHER_SPEED_CONFIG) 1981 high_speed = (g->speed == USB_SPEED_HIGH);
1998 high_speed = !high_speed; 1982 if (type == USB_DT_OTHER_SPEED_CONFIG)
1983 high_speed = !high_speed;
1984 }
1999 1985
2000 if (use_acm) { 1986 if (use_acm) {
2001 config_desc = &gs_acm_config_desc; 1987 config_desc = &gs_acm_config_desc;
2002 function = GS_SPEED_SELECT(high_speed, 1988 function = high_speed
2003 gs_acm_highspeed_function, 1989 ? gs_acm_highspeed_function
2004 gs_acm_fullspeed_function); 1990 : gs_acm_fullspeed_function;
2005 } else { 1991 } else {
2006 config_desc = &gs_bulk_config_desc; 1992 config_desc = &gs_bulk_config_desc;
2007 function = GS_SPEED_SELECT(high_speed, 1993 function = high_speed
2008 gs_bulk_highspeed_function, 1994 ? gs_bulk_highspeed_function
2009 gs_bulk_fullspeed_function); 1995 : gs_bulk_fullspeed_function;
2010 } 1996 }
2011 1997
2012 /* for now, don't advertise srp-only devices */ 1998 /* for now, don't advertise srp-only devices */
diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c
index 3459ea6c6c0b..878e428a0ec1 100644
--- a/drivers/usb/gadget/usbstring.c
+++ b/drivers/usb/gadget/usbstring.c
@@ -15,7 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16 16
17#include <linux/usb/ch9.h> 17#include <linux/usb/ch9.h>
18#include <linux/usb_gadget.h> 18#include <linux/usb/gadget.h>
19 19
20#include <asm/unaligned.h> 20#include <asm/unaligned.h>
21 21
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index fcfe869acb94..fcde5d9c87df 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -1,38 +1,22 @@
1/* 1/*
2 * zero.c -- Gadget Zero, for USB development 2 * zero.c -- Gadget Zero, for USB development
3 * 3 *
4 * Copyright (C) 2003-2004 David Brownell 4 * Copyright (C) 2003-2007 David Brownell
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * This program is free software; you can redistribute it and/or modify
8 * modification, are permitted provided that the following conditions 8 * it under the terms of the GNU General Public License as published by
9 * are met: 9 * the Free Software Foundation; either version 2 of the License, or
10 * 1. Redistributions of source code must retain the above copyright 10 * (at your option) any later version.
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The names of the above-listed copyright holders may not be used
17 * to endorse or promote products derived from this software without
18 * specific prior written permission.
19 * 11 *
20 * ALTERNATIVELY, this software may be distributed under the terms of the 12 * This program is distributed in the hope that it will be useful,
21 * GNU General Public License ("GPL") as published by the Free Software 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * Foundation, either version 2 of that License or (at your option) any 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * later version. 15 * GNU General Public License for more details.
24 * 16 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 17 * You should have received a copy of the GNU General Public License
26 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 18 * along with this program; if not, write to the Free Software
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */ 20 */
37 21
38 22
@@ -57,40 +41,28 @@
57 * Many drivers will only have one configuration, letting them be much 41 * Many drivers will only have one configuration, letting them be much
58 * simpler if they also don't support high speed operation (like this 42 * simpler if they also don't support high speed operation (like this
59 * driver does). 43 * driver does).
44 *
45 * Why is *this* driver using two configurations, rather than setting up
46 * two interfaces with different functions? To help verify that multiple
47 * configuration infrastucture is working correctly; also, so that it can
48 * work with low capability USB controllers without four bulk endpoints.
60 */ 49 */
61 50
62#define DEBUG 1 51/* #define VERBOSE_DEBUG */
63// #define VERBOSE
64 52
65#include <linux/module.h>
66#include <linux/kernel.h> 53#include <linux/kernel.h>
67#include <linux/delay.h>
68#include <linux/ioport.h>
69#include <linux/slab.h>
70#include <linux/errno.h>
71#include <linux/init.h>
72#include <linux/timer.h>
73#include <linux/list.h>
74#include <linux/interrupt.h>
75#include <linux/utsname.h> 54#include <linux/utsname.h>
76#include <linux/device.h> 55#include <linux/device.h>
77#include <linux/moduleparam.h>
78
79#include <asm/byteorder.h>
80#include <asm/io.h>
81#include <asm/irq.h>
82#include <asm/system.h>
83#include <asm/unaligned.h>
84 56
85#include <linux/usb/ch9.h> 57#include <linux/usb/ch9.h>
86#include <linux/usb_gadget.h> 58#include <linux/usb/gadget.h>
87 59
88#include "gadget_chips.h" 60#include "gadget_chips.h"
89 61
90 62
91/*-------------------------------------------------------------------------*/ 63/*-------------------------------------------------------------------------*/
92 64
93#define DRIVER_VERSION "St Patrick's Day 2004" 65#define DRIVER_VERSION "Lughnasadh, 2007"
94 66
95static const char shortname [] = "zero"; 67static const char shortname [] = "zero";
96static const char longname [] = "Gadget Zero"; 68static const char longname [] = "Gadget Zero";
@@ -131,30 +103,16 @@ struct zero_dev {
131 struct timer_list resume; 103 struct timer_list resume;
132}; 104};
133 105
134#define xprintk(d,level,fmt,args...) \ 106#define DBG(d, fmt, args...) \
135 dev_printk(level , &(d)->gadget->dev , fmt , ## args) 107 dev_dbg(&(d)->gadget->dev , fmt , ## args)
136 108#define VDBG(d, fmt, args...) \
137#ifdef DEBUG 109 dev_vdbg(&(d)->gadget->dev , fmt , ## args)
138#define DBG(dev,fmt,args...) \ 110#define ERROR(d, fmt, args...) \
139 xprintk(dev , KERN_DEBUG , fmt , ## args) 111 dev_err(&(d)->gadget->dev , fmt , ## args)
140#else 112#define WARN(d, fmt, args...) \
141#define DBG(dev,fmt,args...) \ 113 dev_warn(&(d)->gadget->dev , fmt , ## args)
142 do { } while (0) 114#define INFO(d, fmt, args...) \
143#endif /* DEBUG */ 115 dev_info(&(d)->gadget->dev , fmt , ## args)
144
145#ifdef VERBOSE
146#define VDBG DBG
147#else
148#define VDBG(dev,fmt,args...) \
149 do { } while (0)
150#endif /* VERBOSE */
151
152#define ERROR(dev,fmt,args...) \
153 xprintk(dev , KERN_ERR , fmt , ## args)
154#define WARN(dev,fmt,args...) \
155 xprintk(dev , KERN_WARNING , fmt , ## args)
156#define INFO(dev,fmt,args...) \
157 xprintk(dev , KERN_INFO , fmt , ## args)
158 116
159/*-------------------------------------------------------------------------*/ 117/*-------------------------------------------------------------------------*/
160 118
@@ -326,8 +284,6 @@ static const struct usb_descriptor_header *fs_loopback_function [] = {
326 NULL, 284 NULL,
327}; 285};
328 286
329#ifdef CONFIG_USB_GADGET_DUALSPEED
330
331/* 287/*
332 * usb 2.0 devices need to expose both high speed and full speed 288 * usb 2.0 devices need to expose both high speed and full speed
333 * descriptors, unless they only run at full speed. 289 * descriptors, unless they only run at full speed.
@@ -383,17 +339,20 @@ static const struct usb_descriptor_header *hs_loopback_function [] = {
383}; 339};
384 340
385/* maxpacket and other transfer characteristics vary by speed. */ 341/* maxpacket and other transfer characteristics vary by speed. */
386#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs)) 342static inline struct usb_endpoint_descriptor *
387 343ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
388#else 344 struct usb_endpoint_descriptor *fs)
345{
346 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
347 return hs;
348 return fs;
349}
389 350
390/* if there's no high speed support, maxpacket doesn't change. */ 351static char manufacturer[50];
391#define ep_desc(g,hs,fs) fs
392 352
393#endif /* !CONFIG_USB_GADGET_DUALSPEED */ 353/* default serial number takes at least two packets */
354static char serial[] = "0123456789.0123456789.0123456789";
394 355
395static char manufacturer [50];
396static char serial [40];
397 356
398/* static strings, in UTF-8 */ 357/* static strings, in UTF-8 */
399static struct usb_string strings [] = { 358static struct usb_string strings [] = {
@@ -435,30 +394,29 @@ config_buf (struct usb_gadget *gadget,
435 int is_source_sink; 394 int is_source_sink;
436 int len; 395 int len;
437 const struct usb_descriptor_header **function; 396 const struct usb_descriptor_header **function;
438#ifdef CONFIG_USB_GADGET_DUALSPEED 397 int hs = 0;
439 int hs = (gadget->speed == USB_SPEED_HIGH);
440#endif
441 398
442 /* two configurations will always be index 0 and index 1 */ 399 /* two configurations will always be index 0 and index 1 */
443 if (index > 1) 400 if (index > 1)
444 return -EINVAL; 401 return -EINVAL;
445 is_source_sink = loopdefault ? (index == 1) : (index == 0); 402 is_source_sink = loopdefault ? (index == 1) : (index == 0);
446 403
447#ifdef CONFIG_USB_GADGET_DUALSPEED 404 if (gadget_is_dualspeed(gadget)) {
448 if (type == USB_DT_OTHER_SPEED_CONFIG) 405 hs = (gadget->speed == USB_SPEED_HIGH);
449 hs = !hs; 406 if (type == USB_DT_OTHER_SPEED_CONFIG)
407 hs = !hs;
408 }
450 if (hs) 409 if (hs)
451 function = is_source_sink 410 function = is_source_sink
452 ? hs_source_sink_function 411 ? hs_source_sink_function
453 : hs_loopback_function; 412 : hs_loopback_function;
454 else 413 else
455#endif
456 function = is_source_sink 414 function = is_source_sink
457 ? fs_source_sink_function 415 ? fs_source_sink_function
458 : fs_loopback_function; 416 : fs_loopback_function;
459 417
460 /* for now, don't advertise srp-only devices */ 418 /* for now, don't advertise srp-only devices */
461 if (!gadget->is_otg) 419 if (!gadget_is_otg(gadget))
462 function++; 420 function++;
463 421
464 len = usb_gadget_config_buf (is_source_sink 422 len = usb_gadget_config_buf (is_source_sink
@@ -498,6 +456,19 @@ static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
498 456
499/*-------------------------------------------------------------------------*/ 457/*-------------------------------------------------------------------------*/
500 458
459/*
460 * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripherals,
461 * this just sinks bulk packets OUT to the peripheral and sources them IN
462 * to the host, optionally with specific data patterns.
463 *
464 * In terms of control messaging, this supports all the standard requests
465 * plus two that support control-OUT tests.
466 *
467 * Note that because this doesn't queue more than one request at a time,
468 * some other function must be used to test queueing logic. The network
469 * link (g_ether) is probably the best option for that.
470 */
471
501/* optionally require specific source/sink data patterns */ 472/* optionally require specific source/sink data patterns */
502 473
503static int 474static int
@@ -534,12 +505,7 @@ check_read_data (
534 return 0; 505 return 0;
535} 506}
536 507
537static void 508static void reinit_write_data(struct usb_ep *ep, struct usb_request *req)
538reinit_write_data (
539 struct zero_dev *dev,
540 struct usb_ep *ep,
541 struct usb_request *req
542)
543{ 509{
544 unsigned i; 510 unsigned i;
545 u8 *buf = req->buf; 511 u8 *buf = req->buf;
@@ -566,16 +532,16 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
566 532
567 switch (status) { 533 switch (status) {
568 534
569 case 0: /* normal completion? */ 535 case 0: /* normal completion? */
570 if (ep == dev->out_ep) { 536 if (ep == dev->out_ep) {
571 check_read_data (dev, ep, req); 537 check_read_data (dev, ep, req);
572 memset (req->buf, 0x55, req->length); 538 memset (req->buf, 0x55, req->length);
573 } else 539 } else
574 reinit_write_data (dev, ep, req); 540 reinit_write_data(ep, req);
575 break; 541 break;
576 542
577 /* this endpoint is normally active while we're configured */ 543 /* this endpoint is normally active while we're configured */
578 case -ECONNABORTED: /* hardware forced ep reset */ 544 case -ECONNABORTED: /* hardware forced ep reset */
579 case -ECONNRESET: /* request dequeued */ 545 case -ECONNRESET: /* request dequeued */
580 case -ESHUTDOWN: /* disconnect from host */ 546 case -ESHUTDOWN: /* disconnect from host */
581 VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status, 547 VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
@@ -607,8 +573,7 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
607 } 573 }
608} 574}
609 575
610static struct usb_request * 576static struct usb_request *source_sink_start_ep(struct usb_ep *ep)
611source_sink_start_ep (struct usb_ep *ep, gfp_t gfp_flags)
612{ 577{
613 struct usb_request *req; 578 struct usb_request *req;
614 int status; 579 int status;
@@ -621,11 +586,11 @@ source_sink_start_ep (struct usb_ep *ep, gfp_t gfp_flags)
621 req->complete = source_sink_complete; 586 req->complete = source_sink_complete;
622 587
623 if (strcmp (ep->name, EP_IN_NAME) == 0) 588 if (strcmp (ep->name, EP_IN_NAME) == 0)
624 reinit_write_data (ep->driver_data, ep, req); 589 reinit_write_data(ep, req);
625 else 590 else
626 memset (req->buf, 0x55, req->length); 591 memset (req->buf, 0x55, req->length);
627 592
628 status = usb_ep_queue (ep, req, gfp_flags); 593 status = usb_ep_queue(ep, req, GFP_ATOMIC);
629 if (status) { 594 if (status) {
630 struct zero_dev *dev = ep->driver_data; 595 struct zero_dev *dev = ep->driver_data;
631 596
@@ -637,8 +602,7 @@ source_sink_start_ep (struct usb_ep *ep, gfp_t gfp_flags)
637 return req; 602 return req;
638} 603}
639 604
640static int 605static int set_source_sink_config(struct zero_dev *dev)
641set_source_sink_config (struct zero_dev *dev, gfp_t gfp_flags)
642{ 606{
643 int result = 0; 607 int result = 0;
644 struct usb_ep *ep; 608 struct usb_ep *ep;
@@ -653,8 +617,7 @@ set_source_sink_config (struct zero_dev *dev, gfp_t gfp_flags)
653 result = usb_ep_enable (ep, d); 617 result = usb_ep_enable (ep, d);
654 if (result == 0) { 618 if (result == 0) {
655 ep->driver_data = dev; 619 ep->driver_data = dev;
656 if (source_sink_start_ep(ep, gfp_flags) 620 if (source_sink_start_ep(ep) != NULL) {
657 != NULL) {
658 dev->in_ep = ep; 621 dev->in_ep = ep;
659 continue; 622 continue;
660 } 623 }
@@ -668,8 +631,7 @@ set_source_sink_config (struct zero_dev *dev, gfp_t gfp_flags)
668 result = usb_ep_enable (ep, d); 631 result = usb_ep_enable (ep, d);
669 if (result == 0) { 632 if (result == 0) {
670 ep->driver_data = dev; 633 ep->driver_data = dev;
671 if (source_sink_start_ep(ep, gfp_flags) 634 if (source_sink_start_ep(ep) != NULL) {
672 != NULL) {
673 dev->out_ep = ep; 635 dev->out_ep = ep;
674 continue; 636 continue;
675 } 637 }
@@ -701,7 +663,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
701 663
702 switch (status) { 664 switch (status) {
703 665
704 case 0: /* normal completion? */ 666 case 0: /* normal completion? */
705 if (ep == dev->out_ep) { 667 if (ep == dev->out_ep) {
706 /* loop this OUT packet back IN to the host */ 668 /* loop this OUT packet back IN to the host */
707 req->zero = (req->actual < req->length); 669 req->zero = (req->actual < req->length);
@@ -735,7 +697,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
735 * rely on the hardware driver to clean up on disconnect or 697 * rely on the hardware driver to clean up on disconnect or
736 * endpoint disable. 698 * endpoint disable.
737 */ 699 */
738 case -ECONNABORTED: /* hardware forced ep reset */ 700 case -ECONNABORTED: /* hardware forced ep reset */
739 case -ECONNRESET: /* request dequeued */ 701 case -ECONNRESET: /* request dequeued */
740 case -ESHUTDOWN: /* disconnect from host */ 702 case -ESHUTDOWN: /* disconnect from host */
741 free_ep_req (ep, req); 703 free_ep_req (ep, req);
@@ -743,8 +705,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
743 } 705 }
744} 706}
745 707
746static int 708static int set_loopback_config(struct zero_dev *dev)
747set_loopback_config (struct zero_dev *dev, gfp_t gfp_flags)
748{ 709{
749 int result = 0; 710 int result = 0;
750 struct usb_ep *ep; 711 struct usb_ep *ep;
@@ -844,8 +805,7 @@ static void zero_reset_config (struct zero_dev *dev)
844 * code can do, perhaps by disallowing more than one configuration or 805 * code can do, perhaps by disallowing more than one configuration or
845 * by limiting configuration choices (like the pxa2xx). 806 * by limiting configuration choices (like the pxa2xx).
846 */ 807 */
847static int 808static int zero_set_config(struct zero_dev *dev, unsigned number)
848zero_set_config (struct zero_dev *dev, unsigned number, gfp_t gfp_flags)
849{ 809{
850 int result = 0; 810 int result = 0;
851 struct usb_gadget *gadget = dev->gadget; 811 struct usb_gadget *gadget = dev->gadget;
@@ -855,17 +815,17 @@ zero_set_config (struct zero_dev *dev, unsigned number, gfp_t gfp_flags)
855 815
856 if (gadget_is_sa1100 (gadget) && dev->config) { 816 if (gadget_is_sa1100 (gadget) && dev->config) {
857 /* tx fifo is full, but we can't clear it...*/ 817 /* tx fifo is full, but we can't clear it...*/
858 INFO (dev, "can't change configurations\n"); 818 ERROR(dev, "can't change configurations\n");
859 return -ESPIPE; 819 return -ESPIPE;
860 } 820 }
861 zero_reset_config (dev); 821 zero_reset_config (dev);
862 822
863 switch (number) { 823 switch (number) {
864 case CONFIG_SOURCE_SINK: 824 case CONFIG_SOURCE_SINK:
865 result = set_source_sink_config (dev, gfp_flags); 825 result = set_source_sink_config(dev);
866 break; 826 break;
867 case CONFIG_LOOPBACK: 827 case CONFIG_LOOPBACK:
868 result = set_loopback_config (dev, gfp_flags); 828 result = set_loopback_config(dev);
869 break; 829 break;
870 default: 830 default:
871 result = -EINVAL; 831 result = -EINVAL;
@@ -885,7 +845,7 @@ zero_set_config (struct zero_dev *dev, unsigned number, gfp_t gfp_flags)
885 case USB_SPEED_LOW: speed = "low"; break; 845 case USB_SPEED_LOW: speed = "low"; break;
886 case USB_SPEED_FULL: speed = "full"; break; 846 case USB_SPEED_FULL: speed = "full"; break;
887 case USB_SPEED_HIGH: speed = "high"; break; 847 case USB_SPEED_HIGH: speed = "high"; break;
888 default: speed = "?"; break; 848 default: speed = "?"; break;
889 } 849 }
890 850
891 dev->config = number; 851 dev->config = number;
@@ -938,19 +898,17 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
938 value = min (w_length, (u16) sizeof device_desc); 898 value = min (w_length, (u16) sizeof device_desc);
939 memcpy (req->buf, &device_desc, value); 899 memcpy (req->buf, &device_desc, value);
940 break; 900 break;
941#ifdef CONFIG_USB_GADGET_DUALSPEED
942 case USB_DT_DEVICE_QUALIFIER: 901 case USB_DT_DEVICE_QUALIFIER:
943 if (!gadget->is_dualspeed) 902 if (!gadget_is_dualspeed(gadget))
944 break; 903 break;
945 value = min (w_length, (u16) sizeof dev_qualifier); 904 value = min (w_length, (u16) sizeof dev_qualifier);
946 memcpy (req->buf, &dev_qualifier, value); 905 memcpy (req->buf, &dev_qualifier, value);
947 break; 906 break;
948 907
949 case USB_DT_OTHER_SPEED_CONFIG: 908 case USB_DT_OTHER_SPEED_CONFIG:
950 if (!gadget->is_dualspeed) 909 if (!gadget_is_dualspeed(gadget))
951 break; 910 break;
952 // FALLTHROUGH 911 // FALLTHROUGH
953#endif /* CONFIG_USB_GADGET_DUALSPEED */
954 case USB_DT_CONFIG: 912 case USB_DT_CONFIG:
955 value = config_buf (gadget, req->buf, 913 value = config_buf (gadget, req->buf,
956 w_value >> 8, 914 w_value >> 8,
@@ -984,7 +942,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
984 else 942 else
985 VDBG (dev, "HNP inactive\n"); 943 VDBG (dev, "HNP inactive\n");
986 spin_lock (&dev->lock); 944 spin_lock (&dev->lock);
987 value = zero_set_config (dev, w_value, GFP_ATOMIC); 945 value = zero_set_config(dev, w_value);
988 spin_unlock (&dev->lock); 946 spin_unlock (&dev->lock);
989 break; 947 break;
990 case USB_REQ_GET_CONFIGURATION: 948 case USB_REQ_GET_CONFIGURATION:
@@ -1013,7 +971,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1013 * use this "reset the config" shortcut. 971 * use this "reset the config" shortcut.
1014 */ 972 */
1015 zero_reset_config (dev); 973 zero_reset_config (dev);
1016 zero_set_config (dev, config, GFP_ATOMIC); 974 zero_set_config(dev, config);
1017 value = 0; 975 value = 0;
1018 } 976 }
1019 spin_unlock (&dev->lock); 977 spin_unlock (&dev->lock);
@@ -1163,7 +1121,7 @@ autoconf_fail:
1163 } 1121 }
1164 EP_IN_NAME = ep->name; 1122 EP_IN_NAME = ep->name;
1165 ep->driver_data = ep; /* claim */ 1123 ep->driver_data = ep; /* claim */
1166 1124
1167 ep = usb_ep_autoconfig (gadget, &fs_sink_desc); 1125 ep = usb_ep_autoconfig (gadget, &fs_sink_desc);
1168 if (!ep) 1126 if (!ep)
1169 goto autoconf_fail; 1127 goto autoconf_fail;
@@ -1207,16 +1165,18 @@ autoconf_fail:
1207 1165
1208 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; 1166 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1209 1167
1210#ifdef CONFIG_USB_GADGET_DUALSPEED 1168 if (gadget_is_dualspeed(gadget)) {
1211 /* assume ep0 uses the same value for both speeds ... */ 1169 /* assume ep0 uses the same value for both speeds ... */
1212 dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0; 1170 dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
1213 1171
1214 /* and that all endpoints are dual-speed */ 1172 /* and that all endpoints are dual-speed */
1215 hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress; 1173 hs_source_desc.bEndpointAddress =
1216 hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress; 1174 fs_source_desc.bEndpointAddress;
1217#endif 1175 hs_sink_desc.bEndpointAddress =
1176 fs_sink_desc.bEndpointAddress;
1177 }
1218 1178
1219 if (gadget->is_otg) { 1179 if (gadget_is_otg(gadget)) {
1220 otg_descriptor.bmAttributes |= USB_OTG_HNP, 1180 otg_descriptor.bmAttributes |= USB_OTG_HNP,
1221 source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1181 source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1222 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1182 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
@@ -1294,23 +1254,18 @@ static struct usb_gadget_driver zero_driver = {
1294 .suspend = zero_suspend, 1254 .suspend = zero_suspend,
1295 .resume = zero_resume, 1255 .resume = zero_resume,
1296 1256
1297 .driver = { 1257 .driver = {
1298 .name = (char *) shortname, 1258 .name = (char *) shortname,
1299 .owner = THIS_MODULE, 1259 .owner = THIS_MODULE,
1300 }, 1260 },
1301}; 1261};
1302 1262
1303MODULE_AUTHOR ("David Brownell"); 1263MODULE_AUTHOR("David Brownell");
1304MODULE_LICENSE ("Dual BSD/GPL"); 1264MODULE_LICENSE("GPL");
1305 1265
1306 1266
1307static int __init init (void) 1267static int __init init (void)
1308{ 1268{
1309 /* a real value would likely come through some id prom
1310 * or module option. this one takes at least two packets.
1311 */
1312 strlcpy (serial, "0123456789.0123456789.0123456789", sizeof serial);
1313
1314 return usb_gadget_register_driver (&zero_driver); 1269 return usb_gadget_register_driver (&zero_driver);
1315} 1270}
1316module_init (init); 1271module_init (init);