diff options
-rw-r--r-- | drivers/usb/gadget/f_uvc.c | 4 | ||||
-rw-r--r-- | drivers/usb/gadget/uvc.h | 10 | ||||
-rw-r--r-- | drivers/usb/gadget/uvc_queue.c | 153 | ||||
-rw-r--r-- | drivers/usb/gadget/uvc_queue.h | 20 | ||||
-rw-r--r-- | drivers/usb/gadget/uvc_v4l2.c | 2 | ||||
-rw-r--r-- | drivers/usb/gadget/uvc_video.c | 6 | ||||
-rw-r--r-- | drivers/usb/gadget/webcam.c | 4 |
7 files changed, 89 insertions, 110 deletions
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c index fc2611f8b326..dbe6db0184fd 100644 --- a/drivers/usb/gadget/f_uvc.c +++ b/drivers/usb/gadget/f_uvc.c | |||
@@ -28,7 +28,7 @@ | |||
28 | 28 | ||
29 | #include "uvc.h" | 29 | #include "uvc.h" |
30 | 30 | ||
31 | unsigned int uvc_trace_param; | 31 | unsigned int uvc_gadget_trace_param; |
32 | 32 | ||
33 | /* -------------------------------------------------------------------------- | 33 | /* -------------------------------------------------------------------------- |
34 | * Function descriptors | 34 | * Function descriptors |
@@ -656,6 +656,6 @@ error: | |||
656 | return ret; | 656 | return ret; |
657 | } | 657 | } |
658 | 658 | ||
659 | module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR); | 659 | module_param_named(trace, uvc_gadget_trace_param, uint, S_IRUGO|S_IWUSR); |
660 | MODULE_PARM_DESC(trace, "Trace level bitmask"); | 660 | MODULE_PARM_DESC(trace, "Trace level bitmask"); |
661 | 661 | ||
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h index 0a705e63c936..e92454cddd7d 100644 --- a/drivers/usb/gadget/uvc.h +++ b/drivers/usb/gadget/uvc.h | |||
@@ -107,11 +107,11 @@ struct uvc_streaming_control { | |||
107 | #define UVC_WARN_MINMAX 0 | 107 | #define UVC_WARN_MINMAX 0 |
108 | #define UVC_WARN_PROBE_DEF 1 | 108 | #define UVC_WARN_PROBE_DEF 1 |
109 | 109 | ||
110 | extern unsigned int uvc_trace_param; | 110 | extern unsigned int uvc_gadget_trace_param; |
111 | 111 | ||
112 | #define uvc_trace(flag, msg...) \ | 112 | #define uvc_trace(flag, msg...) \ |
113 | do { \ | 113 | do { \ |
114 | if (uvc_trace_param & flag) \ | 114 | if (uvc_gadget_trace_param & flag) \ |
115 | printk(KERN_DEBUG "uvcvideo: " msg); \ | 115 | printk(KERN_DEBUG "uvcvideo: " msg); \ |
116 | } while (0) | 116 | } while (0) |
117 | 117 | ||
@@ -220,16 +220,10 @@ struct uvc_file_handle | |||
220 | #define to_uvc_file_handle(handle) \ | 220 | #define to_uvc_file_handle(handle) \ |
221 | container_of(handle, struct uvc_file_handle, vfh) | 221 | container_of(handle, struct uvc_file_handle, vfh) |
222 | 222 | ||
223 | extern struct v4l2_file_operations uvc_v4l2_fops; | ||
224 | |||
225 | /* ------------------------------------------------------------------------ | 223 | /* ------------------------------------------------------------------------ |
226 | * Functions | 224 | * Functions |
227 | */ | 225 | */ |
228 | 226 | ||
229 | extern int uvc_video_enable(struct uvc_video *video, int enable); | ||
230 | extern int uvc_video_init(struct uvc_video *video); | ||
231 | extern int uvc_video_pump(struct uvc_video *video); | ||
232 | |||
233 | extern void uvc_endpoint_stream(struct uvc_device *dev); | 227 | extern void uvc_endpoint_stream(struct uvc_device *dev); |
234 | 228 | ||
235 | extern void uvc_function_connect(struct uvc_device *uvc); | 229 | extern void uvc_function_connect(struct uvc_device *uvc); |
diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c index 43891991bf21..f7395ac5dc17 100644 --- a/drivers/usb/gadget/uvc_queue.c +++ b/drivers/usb/gadget/uvc_queue.c | |||
@@ -78,7 +78,8 @@ | |||
78 | * | 78 | * |
79 | */ | 79 | */ |
80 | 80 | ||
81 | void uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) | 81 | static void |
82 | uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) | ||
82 | { | 83 | { |
83 | mutex_init(&queue->mutex); | 84 | mutex_init(&queue->mutex); |
84 | spin_lock_init(&queue->irqlock); | 85 | spin_lock_init(&queue->irqlock); |
@@ -88,6 +89,28 @@ void uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) | |||
88 | } | 89 | } |
89 | 90 | ||
90 | /* | 91 | /* |
92 | * Free the video buffers. | ||
93 | * | ||
94 | * This function must be called with the queue lock held. | ||
95 | */ | ||
96 | static int uvc_free_buffers(struct uvc_video_queue *queue) | ||
97 | { | ||
98 | unsigned int i; | ||
99 | |||
100 | for (i = 0; i < queue->count; ++i) { | ||
101 | if (queue->buffer[i].vma_use_count != 0) | ||
102 | return -EBUSY; | ||
103 | } | ||
104 | |||
105 | if (queue->count) { | ||
106 | vfree(queue->mem); | ||
107 | queue->count = 0; | ||
108 | } | ||
109 | |||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | /* | ||
91 | * Allocate the video buffers. | 114 | * Allocate the video buffers. |
92 | * | 115 | * |
93 | * Pages are reserved to make sure they will not be swapped, as they will be | 116 | * Pages are reserved to make sure they will not be swapped, as they will be |
@@ -95,8 +118,9 @@ void uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) | |||
95 | * | 118 | * |
96 | * Buffers will be individually mapped, so they must all be page aligned. | 119 | * Buffers will be individually mapped, so they must all be page aligned. |
97 | */ | 120 | */ |
98 | int uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers, | 121 | static int |
99 | unsigned int buflength) | 122 | uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers, |
123 | unsigned int buflength) | ||
100 | { | 124 | { |
101 | unsigned int bufsize = PAGE_ALIGN(buflength); | 125 | unsigned int bufsize = PAGE_ALIGN(buflength); |
102 | unsigned int i; | 126 | unsigned int i; |
@@ -150,28 +174,6 @@ done: | |||
150 | return ret; | 174 | return ret; |
151 | } | 175 | } |
152 | 176 | ||
153 | /* | ||
154 | * Free the video buffers. | ||
155 | * | ||
156 | * This function must be called with the queue lock held. | ||
157 | */ | ||
158 | int uvc_free_buffers(struct uvc_video_queue *queue) | ||
159 | { | ||
160 | unsigned int i; | ||
161 | |||
162 | for (i = 0; i < queue->count; ++i) { | ||
163 | if (queue->buffer[i].vma_use_count != 0) | ||
164 | return -EBUSY; | ||
165 | } | ||
166 | |||
167 | if (queue->count) { | ||
168 | vfree(queue->mem); | ||
169 | queue->count = 0; | ||
170 | } | ||
171 | |||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static void __uvc_query_buffer(struct uvc_buffer *buf, | 177 | static void __uvc_query_buffer(struct uvc_buffer *buf, |
176 | struct v4l2_buffer *v4l2_buf) | 178 | struct v4l2_buffer *v4l2_buf) |
177 | { | 179 | { |
@@ -195,8 +197,8 @@ static void __uvc_query_buffer(struct uvc_buffer *buf, | |||
195 | } | 197 | } |
196 | } | 198 | } |
197 | 199 | ||
198 | int uvc_query_buffer(struct uvc_video_queue *queue, | 200 | static int |
199 | struct v4l2_buffer *v4l2_buf) | 201 | uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf) |
200 | { | 202 | { |
201 | int ret = 0; | 203 | int ret = 0; |
202 | 204 | ||
@@ -217,8 +219,8 @@ done: | |||
217 | * Queue a video buffer. Attempting to queue a buffer that has already been | 219 | * Queue a video buffer. Attempting to queue a buffer that has already been |
218 | * queued will return -EINVAL. | 220 | * queued will return -EINVAL. |
219 | */ | 221 | */ |
220 | int uvc_queue_buffer(struct uvc_video_queue *queue, | 222 | static int |
221 | struct v4l2_buffer *v4l2_buf) | 223 | uvc_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf) |
222 | { | 224 | { |
223 | struct uvc_buffer *buf; | 225 | struct uvc_buffer *buf; |
224 | unsigned long flags; | 226 | unsigned long flags; |
@@ -298,8 +300,9 @@ static int uvc_queue_waiton(struct uvc_buffer *buf, int nonblocking) | |||
298 | * Dequeue a video buffer. If nonblocking is false, block until a buffer is | 300 | * Dequeue a video buffer. If nonblocking is false, block until a buffer is |
299 | * available. | 301 | * available. |
300 | */ | 302 | */ |
301 | int uvc_dequeue_buffer(struct uvc_video_queue *queue, | 303 | static int |
302 | struct v4l2_buffer *v4l2_buf, int nonblocking) | 304 | uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf, |
305 | int nonblocking) | ||
303 | { | 306 | { |
304 | struct uvc_buffer *buf; | 307 | struct uvc_buffer *buf; |
305 | int ret = 0; | 308 | int ret = 0; |
@@ -359,8 +362,9 @@ done: | |||
359 | * This function implements video queue polling and is intended to be used by | 362 | * This function implements video queue polling and is intended to be used by |
360 | * the device poll handler. | 363 | * the device poll handler. |
361 | */ | 364 | */ |
362 | unsigned int uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, | 365 | static unsigned int |
363 | poll_table *wait) | 366 | uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, |
367 | poll_table *wait) | ||
364 | { | 368 | { |
365 | struct uvc_buffer *buf; | 369 | struct uvc_buffer *buf; |
366 | unsigned int mask = 0; | 370 | unsigned int mask = 0; |
@@ -407,7 +411,8 @@ static struct vm_operations_struct uvc_vm_ops = { | |||
407 | * This function implements video buffer memory mapping and is intended to be | 411 | * This function implements video buffer memory mapping and is intended to be |
408 | * used by the device mmap handler. | 412 | * used by the device mmap handler. |
409 | */ | 413 | */ |
410 | int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) | 414 | static int |
415 | uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) | ||
411 | { | 416 | { |
412 | struct uvc_buffer *uninitialized_var(buffer); | 417 | struct uvc_buffer *uninitialized_var(buffer); |
413 | struct page *page; | 418 | struct page *page; |
@@ -458,6 +463,42 @@ done: | |||
458 | } | 463 | } |
459 | 464 | ||
460 | /* | 465 | /* |
466 | * Cancel the video buffers queue. | ||
467 | * | ||
468 | * Cancelling the queue marks all buffers on the irq queue as erroneous, | ||
469 | * wakes them up and removes them from the queue. | ||
470 | * | ||
471 | * If the disconnect parameter is set, further calls to uvc_queue_buffer will | ||
472 | * fail with -ENODEV. | ||
473 | * | ||
474 | * This function acquires the irq spinlock and can be called from interrupt | ||
475 | * context. | ||
476 | */ | ||
477 | static void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) | ||
478 | { | ||
479 | struct uvc_buffer *buf; | ||
480 | unsigned long flags; | ||
481 | |||
482 | spin_lock_irqsave(&queue->irqlock, flags); | ||
483 | while (!list_empty(&queue->irqqueue)) { | ||
484 | buf = list_first_entry(&queue->irqqueue, struct uvc_buffer, | ||
485 | queue); | ||
486 | list_del(&buf->queue); | ||
487 | buf->state = UVC_BUF_STATE_ERROR; | ||
488 | wake_up(&buf->wait); | ||
489 | } | ||
490 | /* This must be protected by the irqlock spinlock to avoid race | ||
491 | * conditions between uvc_queue_buffer and the disconnection event that | ||
492 | * could result in an interruptible wait in uvc_dequeue_buffer. Do not | ||
493 | * blindly replace this logic by checking for the UVC_DEV_DISCONNECTED | ||
494 | * state outside the queue code. | ||
495 | */ | ||
496 | if (disconnect) | ||
497 | queue->flags |= UVC_QUEUE_DISCONNECTED; | ||
498 | spin_unlock_irqrestore(&queue->irqlock, flags); | ||
499 | } | ||
500 | |||
501 | /* | ||
461 | * Enable or disable the video buffers queue. | 502 | * Enable or disable the video buffers queue. |
462 | * | 503 | * |
463 | * The queue must be enabled before starting video acquisition and must be | 504 | * The queue must be enabled before starting video acquisition and must be |
@@ -474,7 +515,7 @@ done: | |||
474 | * This function can't be called from interrupt context. Use | 515 | * This function can't be called from interrupt context. Use |
475 | * uvc_queue_cancel() instead. | 516 | * uvc_queue_cancel() instead. |
476 | */ | 517 | */ |
477 | int uvc_queue_enable(struct uvc_video_queue *queue, int enable) | 518 | static int uvc_queue_enable(struct uvc_video_queue *queue, int enable) |
478 | { | 519 | { |
479 | unsigned int i; | 520 | unsigned int i; |
480 | int ret = 0; | 521 | int ret = 0; |
@@ -503,44 +544,8 @@ done: | |||
503 | return ret; | 544 | return ret; |
504 | } | 545 | } |
505 | 546 | ||
506 | /* | 547 | static struct uvc_buffer * |
507 | * Cancel the video buffers queue. | 548 | uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf) |
508 | * | ||
509 | * Cancelling the queue marks all buffers on the irq queue as erroneous, | ||
510 | * wakes them up and removes them from the queue. | ||
511 | * | ||
512 | * If the disconnect parameter is set, further calls to uvc_queue_buffer will | ||
513 | * fail with -ENODEV. | ||
514 | * | ||
515 | * This function acquires the irq spinlock and can be called from interrupt | ||
516 | * context. | ||
517 | */ | ||
518 | void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) | ||
519 | { | ||
520 | struct uvc_buffer *buf; | ||
521 | unsigned long flags; | ||
522 | |||
523 | spin_lock_irqsave(&queue->irqlock, flags); | ||
524 | while (!list_empty(&queue->irqqueue)) { | ||
525 | buf = list_first_entry(&queue->irqqueue, struct uvc_buffer, | ||
526 | queue); | ||
527 | list_del(&buf->queue); | ||
528 | buf->state = UVC_BUF_STATE_ERROR; | ||
529 | wake_up(&buf->wait); | ||
530 | } | ||
531 | /* This must be protected by the irqlock spinlock to avoid race | ||
532 | * conditions between uvc_queue_buffer and the disconnection event that | ||
533 | * could result in an interruptible wait in uvc_dequeue_buffer. Do not | ||
534 | * blindly replace this logic by checking for the UVC_DEV_DISCONNECTED | ||
535 | * state outside the queue code. | ||
536 | */ | ||
537 | if (disconnect) | ||
538 | queue->flags |= UVC_QUEUE_DISCONNECTED; | ||
539 | spin_unlock_irqrestore(&queue->irqlock, flags); | ||
540 | } | ||
541 | |||
542 | struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | ||
543 | struct uvc_buffer *buf) | ||
544 | { | 549 | { |
545 | struct uvc_buffer *nextbuf; | 550 | struct uvc_buffer *nextbuf; |
546 | unsigned long flags; | 551 | unsigned long flags; |
@@ -568,7 +573,7 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | |||
568 | return nextbuf; | 573 | return nextbuf; |
569 | } | 574 | } |
570 | 575 | ||
571 | struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue) | 576 | static struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue) |
572 | { | 577 | { |
573 | struct uvc_buffer *buf = NULL; | 578 | struct uvc_buffer *buf = NULL; |
574 | 579 | ||
diff --git a/drivers/usb/gadget/uvc_queue.h b/drivers/usb/gadget/uvc_queue.h index 7f5a33fe7ae2..1812a8ecc5d0 100644 --- a/drivers/usb/gadget/uvc_queue.h +++ b/drivers/usb/gadget/uvc_queue.h | |||
@@ -58,30 +58,10 @@ struct uvc_video_queue { | |||
58 | struct list_head irqqueue; | 58 | struct list_head irqqueue; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | extern void uvc_queue_init(struct uvc_video_queue *queue, | ||
62 | enum v4l2_buf_type type); | ||
63 | extern int uvc_alloc_buffers(struct uvc_video_queue *queue, | ||
64 | unsigned int nbuffers, unsigned int buflength); | ||
65 | extern int uvc_free_buffers(struct uvc_video_queue *queue); | ||
66 | extern int uvc_query_buffer(struct uvc_video_queue *queue, | ||
67 | struct v4l2_buffer *v4l2_buf); | ||
68 | extern int uvc_queue_buffer(struct uvc_video_queue *queue, | ||
69 | struct v4l2_buffer *v4l2_buf); | ||
70 | extern int uvc_dequeue_buffer(struct uvc_video_queue *queue, | ||
71 | struct v4l2_buffer *v4l2_buf, int nonblocking); | ||
72 | extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable); | ||
73 | extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); | ||
74 | extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | ||
75 | struct uvc_buffer *buf); | ||
76 | extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, | ||
77 | struct file *file, poll_table *wait); | ||
78 | extern int uvc_queue_mmap(struct uvc_video_queue *queue, | ||
79 | struct vm_area_struct *vma); | ||
80 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) | 61 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) |
81 | { | 62 | { |
82 | return queue->flags & UVC_QUEUE_STREAMING; | 63 | return queue->flags & UVC_QUEUE_STREAMING; |
83 | } | 64 | } |
84 | extern struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue); | ||
85 | 65 | ||
86 | #endif /* __KERNEL__ */ | 66 | #endif /* __KERNEL__ */ |
87 | 67 | ||
diff --git a/drivers/usb/gadget/uvc_v4l2.c b/drivers/usb/gadget/uvc_v4l2.c index a7989f29837e..2dcffdac86d2 100644 --- a/drivers/usb/gadget/uvc_v4l2.c +++ b/drivers/usb/gadget/uvc_v4l2.c | |||
@@ -363,7 +363,7 @@ uvc_v4l2_poll(struct file *file, poll_table *wait) | |||
363 | return mask; | 363 | return mask; |
364 | } | 364 | } |
365 | 365 | ||
366 | struct v4l2_file_operations uvc_v4l2_fops = { | 366 | static struct v4l2_file_operations uvc_v4l2_fops = { |
367 | .owner = THIS_MODULE, | 367 | .owner = THIS_MODULE, |
368 | .open = uvc_v4l2_open, | 368 | .open = uvc_v4l2_open, |
369 | .release = uvc_v4l2_release, | 369 | .release = uvc_v4l2_release, |
diff --git a/drivers/usb/gadget/uvc_video.c b/drivers/usb/gadget/uvc_video.c index de8cbc46518d..b08f35438d70 100644 --- a/drivers/usb/gadget/uvc_video.c +++ b/drivers/usb/gadget/uvc_video.c | |||
@@ -271,7 +271,7 @@ error: | |||
271 | * This function fills the available USB requests (listed in req_free) with | 271 | * This function fills the available USB requests (listed in req_free) with |
272 | * video data from the queued buffers. | 272 | * video data from the queued buffers. |
273 | */ | 273 | */ |
274 | int | 274 | static int |
275 | uvc_video_pump(struct uvc_video *video) | 275 | uvc_video_pump(struct uvc_video *video) |
276 | { | 276 | { |
277 | struct usb_request *req; | 277 | struct usb_request *req; |
@@ -328,7 +328,7 @@ uvc_video_pump(struct uvc_video *video) | |||
328 | /* | 328 | /* |
329 | * Enable or disable the video stream. | 329 | * Enable or disable the video stream. |
330 | */ | 330 | */ |
331 | int | 331 | static int |
332 | uvc_video_enable(struct uvc_video *video, int enable) | 332 | uvc_video_enable(struct uvc_video *video, int enable) |
333 | { | 333 | { |
334 | unsigned int i; | 334 | unsigned int i; |
@@ -367,7 +367,7 @@ uvc_video_enable(struct uvc_video *video, int enable) | |||
367 | /* | 367 | /* |
368 | * Initialize the UVC video stream. | 368 | * Initialize the UVC video stream. |
369 | */ | 369 | */ |
370 | int | 370 | static int |
371 | uvc_video_init(struct uvc_video *video) | 371 | uvc_video_init(struct uvc_video *video) |
372 | { | 372 | { |
373 | INIT_LIST_HEAD(&video->req_free); | 373 | INIT_LIST_HEAD(&video->req_free); |
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c index 417fd6887698..f5f3030cc416 100644 --- a/drivers/usb/gadget/webcam.c +++ b/drivers/usb/gadget/webcam.c | |||
@@ -28,10 +28,10 @@ | |||
28 | #include "config.c" | 28 | #include "config.c" |
29 | #include "epautoconf.c" | 29 | #include "epautoconf.c" |
30 | 30 | ||
31 | #include "f_uvc.c" | ||
32 | #include "uvc_queue.c" | 31 | #include "uvc_queue.c" |
33 | #include "uvc_v4l2.c" | ||
34 | #include "uvc_video.c" | 32 | #include "uvc_video.c" |
33 | #include "uvc_v4l2.c" | ||
34 | #include "f_uvc.c" | ||
35 | 35 | ||
36 | /* -------------------------------------------------------------------------- | 36 | /* -------------------------------------------------------------------------- |
37 | * Device descriptor | 37 | * Device descriptor |