Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: webcam: convert webcam to new interface of f_uvc

Use the new function interface of f_uvc.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Tested-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>

authored by

Andrzej Pietrasiewicz and committed by
Felipe Balbi
c913881e 6d11ed76

+40 -16
+1
drivers/usb/gadget/legacy/Kconfig
··· 468 468 depends on VIDEO_DEV 469 469 select USB_LIBCOMPOSITE 470 470 select VIDEOBUF2_VMALLOC 471 + select USB_F_UVC 471 472 help 472 473 The Webcam Gadget acts as a composite USB Audio and Video Class 473 474 device. It provides a userspace API to process UVC control requests
+1 -1
drivers/usb/gadget/legacy/Makefile
··· 19 19 g_hid-y := hid.o 20 20 g_dbgp-y := dbgp.o 21 21 g_nokia-y := nokia.o 22 - g_webcam-y := webcam.o ../function/uvc_queue.o ../function/uvc_v4l2.o ../function/uvc_video.o 22 + g_webcam-y := webcam.o 23 23 g_ncm-y := ncm.o 24 24 g_acm_ms-y := acm_ms.o 25 25 g_tcm_usb_gadget-y := tcm_usb_gadget.o
+38 -15
drivers/usb/gadget/legacy/webcam.c
··· 15 15 #include <linux/module.h> 16 16 #include <linux/usb/video.h> 17 17 18 - /* 19 - * Kbuild is not very cooperative with respect to linking separately 20 - * compiled library objects into one module. So for now we won't use 21 - * separate compilation ... ensuring init/exit sections work to shrink 22 - * the runtime footprint, and giving us at least some parts of what 23 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 24 - */ 25 - #define USBF_UVC_INCLUDED 26 - #include "f_uvc.c" 18 + #include "u_uvc.h" 27 19 28 20 USB_GADGET_COMPOSITE_OPTIONS(); 29 21 ··· 70 78 &webcam_stringtab, 71 79 NULL, 72 80 }; 81 + 82 + static struct usb_function_instance *fi_uvc; 83 + static struct usb_function *f_uvc; 73 84 74 85 static struct usb_device_descriptor webcam_device_descriptor = { 75 86 .bLength = USB_DT_DEVICE_SIZE, ··· 337 342 static int __init 338 343 webcam_config_bind(struct usb_configuration *c) 339 344 { 340 - return uvc_bind_config(c, uvc_fs_control_cls, 341 - uvc_ss_control_cls, uvc_fs_streaming_cls, 342 - uvc_hs_streaming_cls, uvc_ss_streaming_cls, 343 - streaming_interval, streaming_maxpacket, 344 - streaming_maxburst, trace); 345 + int status = 0; 346 + 347 + f_uvc = usb_get_function(fi_uvc); 348 + if (IS_ERR(f_uvc)) 349 + return PTR_ERR(f_uvc); 350 + 351 + status = usb_add_function(c, f_uvc); 352 + if (status < 0) 353 + usb_put_function(f_uvc); 354 + 355 + return status; 345 356 } 346 357 347 358 static struct usb_configuration webcam_config_driver = { ··· 361 360 static int /* __init_or_exit */ 362 361 webcam_unbind(struct usb_composite_dev *cdev) 363 362 { 363 + if (!IS_ERR_OR_NULL(f_uvc)) 364 + usb_put_function(f_uvc); 365 + if (!IS_ERR_OR_NULL(fi_uvc)) 366 + usb_put_function_instance(fi_uvc); 364 367 return 0; 365 368 } 366 369 367 370 static int __init 368 371 webcam_bind(struct usb_composite_dev *cdev) 369 372 { 373 + struct f_uvc_opts *uvc_opts; 370 374 int ret; 375 + 376 + fi_uvc = usb_get_function_instance("uvc"); 377 + if (IS_ERR(fi_uvc)) 378 + return PTR_ERR(fi_uvc); 379 + 380 + uvc_opts = container_of(fi_uvc, struct f_uvc_opts, func_inst); 381 + 382 + uvc_opts->streaming_interval = streaming_interval; 383 + uvc_opts->streaming_maxpacket = streaming_maxpacket; 384 + uvc_opts->streaming_maxburst = streaming_maxburst; 385 + uvc_set_trace_param(trace); 386 + 387 + uvc_opts->fs_control = uvc_fs_control_cls; 388 + uvc_opts->ss_control = uvc_ss_control_cls; 389 + uvc_opts->fs_streaming = uvc_fs_streaming_cls; 390 + uvc_opts->hs_streaming = uvc_hs_streaming_cls; 391 + uvc_opts->ss_streaming = uvc_ss_streaming_cls; 371 392 372 393 /* Allocate string descriptor numbers ... note that string contents 373 394 * can be overridden by the composite_dev glue. ··· 414 391 return 0; 415 392 416 393 error: 417 - webcam_unbind(cdev); 394 + usb_put_function_instance(fi_uvc); 418 395 return ret; 419 396 } 420 397