Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * webcam.c -- USB webcam gadget driver |
| 3 | * |
| 4 | * Copyright (C) 2009-2010 |
| 5 | * Laurent Pinchart (laurent.pinchart@ideasonboard.com) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 11 | */ |
Klaus Schwarzkopf | 28c9fc6 | 2011-09-09 16:10:44 +0200 | [diff] [blame] | 12 | |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/usb/video.h> |
| 16 | |
| 17 | #include "f_uvc.h" |
| 18 | |
| 19 | /* |
| 20 | * Kbuild is not very cooperative with respect to linking separately |
| 21 | * compiled library objects into one module. So for now we won't use |
| 22 | * separate compilation ... ensuring init/exit sections work to shrink |
| 23 | * the runtime footprint, and giving us at least some parts of what |
| 24 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. |
| 25 | */ |
| 26 | #include "composite.c" |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 27 | |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 28 | #include "uvc_queue.c" |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 29 | #include "uvc_video.c" |
Laurent Pinchart | 5d9955f | 2010-07-10 16:13:05 -0300 | [diff] [blame] | 30 | #include "uvc_v4l2.c" |
| 31 | #include "f_uvc.c" |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 32 | |
| 33 | /* -------------------------------------------------------------------------- |
| 34 | * Device descriptor |
| 35 | */ |
| 36 | |
| 37 | #define WEBCAM_VENDOR_ID 0x1d6b /* Linux Foundation */ |
| 38 | #define WEBCAM_PRODUCT_ID 0x0102 /* Webcam A/V gadget */ |
| 39 | #define WEBCAM_DEVICE_BCD 0x0010 /* 0.10 */ |
| 40 | |
| 41 | static char webcam_vendor_label[] = "Linux Foundation"; |
| 42 | static char webcam_product_label[] = "Webcam gadget"; |
| 43 | static char webcam_config_label[] = "Video"; |
| 44 | |
| 45 | /* string IDs are assigned dynamically */ |
| 46 | |
| 47 | #define STRING_MANUFACTURER_IDX 0 |
| 48 | #define STRING_PRODUCT_IDX 1 |
| 49 | #define STRING_DESCRIPTION_IDX 2 |
| 50 | |
| 51 | static struct usb_string webcam_strings[] = { |
| 52 | [STRING_MANUFACTURER_IDX].s = webcam_vendor_label, |
| 53 | [STRING_PRODUCT_IDX].s = webcam_product_label, |
| 54 | [STRING_DESCRIPTION_IDX].s = webcam_config_label, |
| 55 | { } |
| 56 | }; |
| 57 | |
| 58 | static struct usb_gadget_strings webcam_stringtab = { |
| 59 | .language = 0x0409, /* en-us */ |
| 60 | .strings = webcam_strings, |
| 61 | }; |
| 62 | |
| 63 | static struct usb_gadget_strings *webcam_device_strings[] = { |
| 64 | &webcam_stringtab, |
| 65 | NULL, |
| 66 | }; |
| 67 | |
| 68 | static struct usb_device_descriptor webcam_device_descriptor = { |
| 69 | .bLength = USB_DT_DEVICE_SIZE, |
| 70 | .bDescriptorType = USB_DT_DEVICE, |
| 71 | .bcdUSB = cpu_to_le16(0x0200), |
| 72 | .bDeviceClass = USB_CLASS_MISC, |
| 73 | .bDeviceSubClass = 0x02, |
| 74 | .bDeviceProtocol = 0x01, |
| 75 | .bMaxPacketSize0 = 0, /* dynamic */ |
| 76 | .idVendor = cpu_to_le16(WEBCAM_VENDOR_ID), |
| 77 | .idProduct = cpu_to_le16(WEBCAM_PRODUCT_ID), |
| 78 | .bcdDevice = cpu_to_le16(WEBCAM_DEVICE_BCD), |
| 79 | .iManufacturer = 0, /* dynamic */ |
| 80 | .iProduct = 0, /* dynamic */ |
| 81 | .iSerialNumber = 0, /* dynamic */ |
| 82 | .bNumConfigurations = 0, /* dynamic */ |
| 83 | }; |
| 84 | |
| 85 | DECLARE_UVC_HEADER_DESCRIPTOR(1); |
| 86 | |
| 87 | static const struct UVC_HEADER_DESCRIPTOR(1) uvc_control_header = { |
| 88 | .bLength = UVC_DT_HEADER_SIZE(1), |
| 89 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 90 | .bDescriptorSubType = UVC_VC_HEADER, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 91 | .bcdUVC = cpu_to_le16(0x0100), |
| 92 | .wTotalLength = 0, /* dynamic */ |
| 93 | .dwClockFrequency = cpu_to_le32(48000000), |
| 94 | .bInCollection = 0, /* dynamic */ |
| 95 | .baInterfaceNr[0] = 0, /* dynamic */ |
| 96 | }; |
| 97 | |
| 98 | static const struct uvc_camera_terminal_descriptor uvc_camera_terminal = { |
| 99 | .bLength = UVC_DT_CAMERA_TERMINAL_SIZE(3), |
| 100 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 101 | .bDescriptorSubType = UVC_VC_INPUT_TERMINAL, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 102 | .bTerminalID = 1, |
| 103 | .wTerminalType = cpu_to_le16(0x0201), |
| 104 | .bAssocTerminal = 0, |
| 105 | .iTerminal = 0, |
| 106 | .wObjectiveFocalLengthMin = cpu_to_le16(0), |
| 107 | .wObjectiveFocalLengthMax = cpu_to_le16(0), |
| 108 | .wOcularFocalLength = cpu_to_le16(0), |
| 109 | .bControlSize = 3, |
| 110 | .bmControls[0] = 2, |
| 111 | .bmControls[1] = 0, |
| 112 | .bmControls[2] = 0, |
| 113 | }; |
| 114 | |
| 115 | static const struct uvc_processing_unit_descriptor uvc_processing = { |
| 116 | .bLength = UVC_DT_PROCESSING_UNIT_SIZE(2), |
| 117 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 118 | .bDescriptorSubType = UVC_VC_PROCESSING_UNIT, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 119 | .bUnitID = 2, |
| 120 | .bSourceID = 1, |
| 121 | .wMaxMultiplier = cpu_to_le16(16*1024), |
| 122 | .bControlSize = 2, |
| 123 | .bmControls[0] = 1, |
| 124 | .bmControls[1] = 0, |
| 125 | .iProcessing = 0, |
| 126 | }; |
| 127 | |
| 128 | static const struct uvc_output_terminal_descriptor uvc_output_terminal = { |
| 129 | .bLength = UVC_DT_OUTPUT_TERMINAL_SIZE, |
| 130 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 131 | .bDescriptorSubType = UVC_VC_OUTPUT_TERMINAL, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 132 | .bTerminalID = 3, |
| 133 | .wTerminalType = cpu_to_le16(0x0101), |
| 134 | .bAssocTerminal = 0, |
| 135 | .bSourceID = 2, |
| 136 | .iTerminal = 0, |
| 137 | }; |
| 138 | |
| 139 | DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(1, 2); |
| 140 | |
| 141 | static const struct UVC_INPUT_HEADER_DESCRIPTOR(1, 2) uvc_input_header = { |
| 142 | .bLength = UVC_DT_INPUT_HEADER_SIZE(1, 2), |
| 143 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 144 | .bDescriptorSubType = UVC_VS_INPUT_HEADER, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 145 | .bNumFormats = 2, |
| 146 | .wTotalLength = 0, /* dynamic */ |
| 147 | .bEndpointAddress = 0, /* dynamic */ |
| 148 | .bmInfo = 0, |
| 149 | .bTerminalLink = 3, |
| 150 | .bStillCaptureMethod = 0, |
| 151 | .bTriggerSupport = 0, |
| 152 | .bTriggerUsage = 0, |
| 153 | .bControlSize = 1, |
| 154 | .bmaControls[0][0] = 0, |
| 155 | .bmaControls[1][0] = 4, |
| 156 | }; |
| 157 | |
| 158 | static const struct uvc_format_uncompressed uvc_format_yuv = { |
| 159 | .bLength = UVC_DT_FORMAT_UNCOMPRESSED_SIZE, |
| 160 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 161 | .bDescriptorSubType = UVC_VS_FORMAT_UNCOMPRESSED, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 162 | .bFormatIndex = 1, |
| 163 | .bNumFrameDescriptors = 2, |
| 164 | .guidFormat = |
| 165 | { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, |
| 166 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}, |
| 167 | .bBitsPerPixel = 16, |
| 168 | .bDefaultFrameIndex = 1, |
| 169 | .bAspectRatioX = 0, |
| 170 | .bAspectRatioY = 0, |
| 171 | .bmInterfaceFlags = 0, |
| 172 | .bCopyProtect = 0, |
| 173 | }; |
| 174 | |
| 175 | DECLARE_UVC_FRAME_UNCOMPRESSED(1); |
| 176 | DECLARE_UVC_FRAME_UNCOMPRESSED(3); |
| 177 | |
| 178 | static const struct UVC_FRAME_UNCOMPRESSED(3) uvc_frame_yuv_360p = { |
| 179 | .bLength = UVC_DT_FRAME_UNCOMPRESSED_SIZE(3), |
| 180 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 181 | .bDescriptorSubType = UVC_VS_FRAME_UNCOMPRESSED, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 182 | .bFrameIndex = 1, |
| 183 | .bmCapabilities = 0, |
| 184 | .wWidth = cpu_to_le16(640), |
| 185 | .wHeight = cpu_to_le16(360), |
| 186 | .dwMinBitRate = cpu_to_le32(18432000), |
| 187 | .dwMaxBitRate = cpu_to_le32(55296000), |
| 188 | .dwMaxVideoFrameBufferSize = cpu_to_le32(460800), |
| 189 | .dwDefaultFrameInterval = cpu_to_le32(666666), |
| 190 | .bFrameIntervalType = 3, |
| 191 | .dwFrameInterval[0] = cpu_to_le32(666666), |
| 192 | .dwFrameInterval[1] = cpu_to_le32(1000000), |
| 193 | .dwFrameInterval[2] = cpu_to_le32(5000000), |
| 194 | }; |
| 195 | |
| 196 | static const struct UVC_FRAME_UNCOMPRESSED(1) uvc_frame_yuv_720p = { |
| 197 | .bLength = UVC_DT_FRAME_UNCOMPRESSED_SIZE(1), |
| 198 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 199 | .bDescriptorSubType = UVC_VS_FRAME_UNCOMPRESSED, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 200 | .bFrameIndex = 2, |
| 201 | .bmCapabilities = 0, |
| 202 | .wWidth = cpu_to_le16(1280), |
| 203 | .wHeight = cpu_to_le16(720), |
| 204 | .dwMinBitRate = cpu_to_le32(29491200), |
| 205 | .dwMaxBitRate = cpu_to_le32(29491200), |
| 206 | .dwMaxVideoFrameBufferSize = cpu_to_le32(1843200), |
| 207 | .dwDefaultFrameInterval = cpu_to_le32(5000000), |
| 208 | .bFrameIntervalType = 1, |
| 209 | .dwFrameInterval[0] = cpu_to_le32(5000000), |
| 210 | }; |
| 211 | |
| 212 | static const struct uvc_format_mjpeg uvc_format_mjpg = { |
| 213 | .bLength = UVC_DT_FORMAT_MJPEG_SIZE, |
| 214 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 215 | .bDescriptorSubType = UVC_VS_FORMAT_MJPEG, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 216 | .bFormatIndex = 2, |
| 217 | .bNumFrameDescriptors = 2, |
| 218 | .bmFlags = 0, |
| 219 | .bDefaultFrameIndex = 1, |
| 220 | .bAspectRatioX = 0, |
| 221 | .bAspectRatioY = 0, |
| 222 | .bmInterfaceFlags = 0, |
| 223 | .bCopyProtect = 0, |
| 224 | }; |
| 225 | |
| 226 | DECLARE_UVC_FRAME_MJPEG(1); |
| 227 | DECLARE_UVC_FRAME_MJPEG(3); |
| 228 | |
| 229 | static const struct UVC_FRAME_MJPEG(3) uvc_frame_mjpg_360p = { |
| 230 | .bLength = UVC_DT_FRAME_MJPEG_SIZE(3), |
| 231 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 232 | .bDescriptorSubType = UVC_VS_FRAME_MJPEG, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 233 | .bFrameIndex = 1, |
| 234 | .bmCapabilities = 0, |
| 235 | .wWidth = cpu_to_le16(640), |
| 236 | .wHeight = cpu_to_le16(360), |
| 237 | .dwMinBitRate = cpu_to_le32(18432000), |
| 238 | .dwMaxBitRate = cpu_to_le32(55296000), |
| 239 | .dwMaxVideoFrameBufferSize = cpu_to_le32(460800), |
| 240 | .dwDefaultFrameInterval = cpu_to_le32(666666), |
| 241 | .bFrameIntervalType = 3, |
| 242 | .dwFrameInterval[0] = cpu_to_le32(666666), |
| 243 | .dwFrameInterval[1] = cpu_to_le32(1000000), |
| 244 | .dwFrameInterval[2] = cpu_to_le32(5000000), |
| 245 | }; |
| 246 | |
| 247 | static const struct UVC_FRAME_MJPEG(1) uvc_frame_mjpg_720p = { |
| 248 | .bLength = UVC_DT_FRAME_MJPEG_SIZE(1), |
| 249 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 250 | .bDescriptorSubType = UVC_VS_FRAME_MJPEG, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 251 | .bFrameIndex = 2, |
| 252 | .bmCapabilities = 0, |
| 253 | .wWidth = cpu_to_le16(1280), |
| 254 | .wHeight = cpu_to_le16(720), |
| 255 | .dwMinBitRate = cpu_to_le32(29491200), |
| 256 | .dwMaxBitRate = cpu_to_le32(29491200), |
| 257 | .dwMaxVideoFrameBufferSize = cpu_to_le32(1843200), |
| 258 | .dwDefaultFrameInterval = cpu_to_le32(5000000), |
| 259 | .bFrameIntervalType = 1, |
| 260 | .dwFrameInterval[0] = cpu_to_le32(5000000), |
| 261 | }; |
| 262 | |
| 263 | static const struct uvc_color_matching_descriptor uvc_color_matching = { |
| 264 | .bLength = UVC_DT_COLOR_MATCHING_SIZE, |
| 265 | .bDescriptorType = USB_DT_CS_INTERFACE, |
Laurent Pinchart | bbafc0c | 2010-07-10 15:03:20 -0300 | [diff] [blame] | 266 | .bDescriptorSubType = UVC_VS_COLORFORMAT, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 267 | .bColorPrimaries = 1, |
| 268 | .bTransferCharacteristics = 1, |
| 269 | .bMatrixCoefficients = 4, |
| 270 | }; |
| 271 | |
Bhupesh Sharma | fbcaba0 | 2012-06-01 15:08:56 +0530 | [diff] [blame] | 272 | static const struct uvc_descriptor_header * const uvc_fs_control_cls[] = { |
| 273 | (const struct uvc_descriptor_header *) &uvc_control_header, |
| 274 | (const struct uvc_descriptor_header *) &uvc_camera_terminal, |
| 275 | (const struct uvc_descriptor_header *) &uvc_processing, |
| 276 | (const struct uvc_descriptor_header *) &uvc_output_terminal, |
| 277 | NULL, |
| 278 | }; |
| 279 | |
| 280 | static const struct uvc_descriptor_header * const uvc_ss_control_cls[] = { |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 281 | (const struct uvc_descriptor_header *) &uvc_control_header, |
| 282 | (const struct uvc_descriptor_header *) &uvc_camera_terminal, |
| 283 | (const struct uvc_descriptor_header *) &uvc_processing, |
| 284 | (const struct uvc_descriptor_header *) &uvc_output_terminal, |
| 285 | NULL, |
| 286 | }; |
| 287 | |
| 288 | static const struct uvc_descriptor_header * const uvc_fs_streaming_cls[] = { |
| 289 | (const struct uvc_descriptor_header *) &uvc_input_header, |
| 290 | (const struct uvc_descriptor_header *) &uvc_format_yuv, |
| 291 | (const struct uvc_descriptor_header *) &uvc_frame_yuv_360p, |
| 292 | (const struct uvc_descriptor_header *) &uvc_frame_yuv_720p, |
| 293 | (const struct uvc_descriptor_header *) &uvc_format_mjpg, |
| 294 | (const struct uvc_descriptor_header *) &uvc_frame_mjpg_360p, |
| 295 | (const struct uvc_descriptor_header *) &uvc_frame_mjpg_720p, |
| 296 | (const struct uvc_descriptor_header *) &uvc_color_matching, |
| 297 | NULL, |
| 298 | }; |
| 299 | |
| 300 | static const struct uvc_descriptor_header * const uvc_hs_streaming_cls[] = { |
| 301 | (const struct uvc_descriptor_header *) &uvc_input_header, |
| 302 | (const struct uvc_descriptor_header *) &uvc_format_yuv, |
| 303 | (const struct uvc_descriptor_header *) &uvc_frame_yuv_360p, |
| 304 | (const struct uvc_descriptor_header *) &uvc_frame_yuv_720p, |
| 305 | (const struct uvc_descriptor_header *) &uvc_format_mjpg, |
| 306 | (const struct uvc_descriptor_header *) &uvc_frame_mjpg_360p, |
| 307 | (const struct uvc_descriptor_header *) &uvc_frame_mjpg_720p, |
| 308 | (const struct uvc_descriptor_header *) &uvc_color_matching, |
| 309 | NULL, |
| 310 | }; |
| 311 | |
Bhupesh Sharma | fbcaba0 | 2012-06-01 15:08:56 +0530 | [diff] [blame] | 312 | static const struct uvc_descriptor_header * const uvc_ss_streaming_cls[] = { |
| 313 | (const struct uvc_descriptor_header *) &uvc_input_header, |
| 314 | (const struct uvc_descriptor_header *) &uvc_format_yuv, |
| 315 | (const struct uvc_descriptor_header *) &uvc_frame_yuv_360p, |
| 316 | (const struct uvc_descriptor_header *) &uvc_frame_yuv_720p, |
| 317 | (const struct uvc_descriptor_header *) &uvc_format_mjpg, |
| 318 | (const struct uvc_descriptor_header *) &uvc_frame_mjpg_360p, |
| 319 | (const struct uvc_descriptor_header *) &uvc_frame_mjpg_720p, |
| 320 | (const struct uvc_descriptor_header *) &uvc_color_matching, |
| 321 | NULL, |
| 322 | }; |
| 323 | |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 324 | /* -------------------------------------------------------------------------- |
| 325 | * USB configuration |
| 326 | */ |
| 327 | |
Michal Nazarewicz | e12995e | 2010-08-12 17:43:52 +0200 | [diff] [blame] | 328 | static int __init |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 329 | webcam_config_bind(struct usb_configuration *c) |
| 330 | { |
Bhupesh Sharma | fbcaba0 | 2012-06-01 15:08:56 +0530 | [diff] [blame] | 331 | return uvc_bind_config(c, uvc_fs_control_cls, uvc_ss_control_cls, |
| 332 | uvc_fs_streaming_cls, uvc_hs_streaming_cls, |
| 333 | uvc_ss_streaming_cls); |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static struct usb_configuration webcam_config_driver = { |
| 337 | .label = webcam_config_label, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 338 | .bConfigurationValue = 1, |
| 339 | .iConfiguration = 0, /* dynamic */ |
| 340 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
| 341 | .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, |
| 342 | }; |
| 343 | |
| 344 | static int /* __init_or_exit */ |
| 345 | webcam_unbind(struct usb_composite_dev *cdev) |
| 346 | { |
| 347 | return 0; |
| 348 | } |
| 349 | |
Michal Nazarewicz | e12995e | 2010-08-12 17:43:52 +0200 | [diff] [blame] | 350 | static int __init |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 351 | webcam_bind(struct usb_composite_dev *cdev) |
| 352 | { |
| 353 | int ret; |
| 354 | |
| 355 | /* Allocate string descriptor numbers ... note that string contents |
| 356 | * can be overridden by the composite_dev glue. |
| 357 | */ |
| 358 | if ((ret = usb_string_id(cdev)) < 0) |
| 359 | goto error; |
| 360 | webcam_strings[STRING_MANUFACTURER_IDX].id = ret; |
| 361 | webcam_device_descriptor.iManufacturer = ret; |
| 362 | |
| 363 | if ((ret = usb_string_id(cdev)) < 0) |
| 364 | goto error; |
| 365 | webcam_strings[STRING_PRODUCT_IDX].id = ret; |
| 366 | webcam_device_descriptor.iProduct = ret; |
| 367 | |
| 368 | if ((ret = usb_string_id(cdev)) < 0) |
| 369 | goto error; |
| 370 | webcam_strings[STRING_DESCRIPTION_IDX].id = ret; |
| 371 | webcam_config_driver.iConfiguration = ret; |
| 372 | |
| 373 | /* Register our configuration. */ |
Uwe Kleine-König | c9bfff9 | 2010-08-12 17:43:55 +0200 | [diff] [blame] | 374 | if ((ret = usb_add_config(cdev, &webcam_config_driver, |
| 375 | webcam_config_bind)) < 0) |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 376 | goto error; |
| 377 | |
| 378 | INFO(cdev, "Webcam Video Gadget\n"); |
| 379 | return 0; |
| 380 | |
| 381 | error: |
| 382 | webcam_unbind(cdev); |
| 383 | return ret; |
| 384 | } |
| 385 | |
| 386 | /* -------------------------------------------------------------------------- |
| 387 | * Driver |
| 388 | */ |
| 389 | |
Sebastian Andrzej Siewior | c2ec75c | 2012-09-06 20:11:03 +0200 | [diff] [blame] | 390 | static __refdata struct usb_composite_driver webcam_driver = { |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 391 | .name = "g_webcam", |
| 392 | .dev = &webcam_device_descriptor, |
| 393 | .strings = webcam_device_strings, |
Bhupesh Sharma | fbcaba0 | 2012-06-01 15:08:56 +0530 | [diff] [blame] | 394 | .max_speed = USB_SPEED_SUPER, |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 395 | .bind = webcam_bind, |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 396 | .unbind = webcam_unbind, |
| 397 | }; |
| 398 | |
| 399 | static int __init |
| 400 | webcam_init(void) |
| 401 | { |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 402 | return usb_composite_probe(&webcam_driver); |
Laurent Pinchart | a9914127 | 2010-05-02 20:57:42 +0200 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static void __exit |
| 406 | webcam_cleanup(void) |
| 407 | { |
| 408 | usb_composite_unregister(&webcam_driver); |
| 409 | } |
| 410 | |
| 411 | module_init(webcam_init); |
| 412 | module_exit(webcam_cleanup); |
| 413 | |
| 414 | MODULE_AUTHOR("Laurent Pinchart"); |
| 415 | MODULE_DESCRIPTION("Webcam Video Gadget"); |
| 416 | MODULE_LICENSE("GPL"); |
| 417 | MODULE_VERSION("0.1.0"); |
| 418 | |