uvcvideo.txt 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. Linux USB Video Class (UVC) driver
  2. ==================================
  3. This file documents some driver-specific aspects of the UVC driver, such as
  4. driver-specific ioctls and implementation notes.
  5. Questions and remarks can be sent to the Linux UVC development mailing list at
  6. linux-uvc-devel@lists.berlios.de.
  7. Extension Unit (XU) support
  8. ---------------------------
  9. 1. Introduction
  10. The UVC specification allows for vendor-specific extensions through extension
  11. units (XUs). The Linux UVC driver supports extension unit controls (XU controls)
  12. through two separate mechanisms:
  13. - through mappings of XU controls to V4L2 controls
  14. - through a driver-specific ioctl interface
  15. The first one allows generic V4L2 applications to use XU controls by mapping
  16. certain XU controls onto V4L2 controls, which then show up during ordinary
  17. control enumeration.
  18. The second mechanism requires uvcvideo-specific knowledge for the application to
  19. access XU controls but exposes the entire UVC XU concept to user space for
  20. maximum flexibility.
  21. Both mechanisms complement each other and are described in more detail below.
  22. 2. Control mappings
  23. The UVC driver provides an API for user space applications to define so-called
  24. control mappings at runtime. These allow for individual XU controls or byte
  25. ranges thereof to be mapped to new V4L2 controls. Such controls appear and
  26. function exactly like normal V4L2 controls (i.e. the stock controls, such as
  27. brightness, contrast, etc.). However, reading or writing of such a V4L2 controls
  28. triggers a read or write of the associated XU control.
  29. The ioctl used to create these control mappings is called UVCIOC_CTRL_MAP.
  30. Previous driver versions (before 0.2.0) required another ioctl to be used
  31. beforehand (UVCIOC_CTRL_ADD) to pass XU control information to the UVC driver.
  32. This is no longer necessary as newer uvcvideo versions query the information
  33. directly from the device.
  34. For details on the UVCIOC_CTRL_MAP ioctl please refer to the section titled
  35. "IOCTL reference" below.
  36. 3. Driver specific XU control interface
  37. For applications that need to access XU controls directly, e.g. for testing
  38. purposes, firmware upload, or accessing binary controls, a second mechanism to
  39. access XU controls is provided in the form of a driver-specific ioctl, namely
  40. UVCIOC_CTRL_QUERY.
  41. A call to this ioctl allows applications to send queries to the UVC driver that
  42. directly map to the low-level UVC control requests.
  43. In order to make such a request the UVC unit ID of the control's extension unit
  44. and the control selector need to be known. This information either needs to be
  45. hardcoded in the application or queried using other ways such as by parsing the
  46. UVC descriptor or, if available, using the media controller API to enumerate a
  47. device's entities.
  48. Unless the control size is already known it is necessary to first make a
  49. UVC_GET_LEN requests in order to be able to allocate a sufficiently large buffer
  50. and set the buffer size to the correct value. Similarly, to find out whether
  51. UVC_GET_CUR or UVC_SET_CUR are valid requests for a given control, a
  52. UVC_GET_INFO request should be made. The bits 0 (GET supported) and 1 (SET
  53. supported) of the resulting byte indicate which requests are valid.
  54. With the addition of the UVCIOC_CTRL_QUERY ioctl the UVCIOC_CTRL_GET and
  55. UVCIOC_CTRL_SET ioctls have become obsolete since their functionality is a
  56. subset of the former ioctl. For the time being they are still supported but
  57. application developers are encouraged to use UVCIOC_CTRL_QUERY instead.
  58. For details on the UVCIOC_CTRL_QUERY ioctl please refer to the section titled
  59. "IOCTL reference" below.
  60. 4. Security
  61. The API doesn't currently provide a fine-grained access control facility. The
  62. UVCIOC_CTRL_ADD and UVCIOC_CTRL_MAP ioctls require super user permissions.
  63. Suggestions on how to improve this are welcome.
  64. 5. Debugging
  65. In order to debug problems related to XU controls or controls in general it is
  66. recommended to enable the UVC_TRACE_CONTROL bit in the module parameter 'trace'.
  67. This causes extra output to be written into the system log.
  68. 6. IOCTL reference
  69. ---- UVCIOC_CTRL_MAP - Map a UVC control to a V4L2 control ----
  70. Argument: struct uvc_xu_control_mapping
  71. Description:
  72. This ioctl creates a mapping between a UVC control or part of a UVC
  73. control and a V4L2 control. Once mappings are defined, userspace
  74. applications can access vendor-defined UVC control through the V4L2
  75. control API.
  76. To create a mapping, applications fill the uvc_xu_control_mapping
  77. structure with information about an existing UVC control defined with
  78. UVCIOC_CTRL_ADD and a new V4L2 control.
  79. A UVC control can be mapped to several V4L2 controls. For instance,
  80. a UVC pan/tilt control could be mapped to separate pan and tilt V4L2
  81. controls. The UVC control is divided into non overlapping fields using
  82. the 'size' and 'offset' fields and are then independently mapped to
  83. V4L2 control.
  84. For signed integer V4L2 controls the data_type field should be set to
  85. UVC_CTRL_DATA_TYPE_SIGNED. Other values are currently ignored.
  86. Return value:
  87. On success 0 is returned. On error -1 is returned and errno is set
  88. appropriately.
  89. ENOMEM
  90. Not enough memory to perform the operation.
  91. EPERM
  92. Insufficient privileges (super user privileges are required).
  93. EINVAL
  94. No such UVC control.
  95. EOVERFLOW
  96. The requested offset and size would overflow the UVC control.
  97. EEXIST
  98. Mapping already exists.
  99. Data types:
  100. * struct uvc_xu_control_mapping
  101. __u32 id V4L2 control identifier
  102. __u8 name[32] V4L2 control name
  103. __u8 entity[16] UVC extension unit GUID
  104. __u8 selector UVC control selector
  105. __u8 size V4L2 control size (in bits)
  106. __u8 offset V4L2 control offset (in bits)
  107. enum v4l2_ctrl_type
  108. v4l2_type V4L2 control type
  109. enum uvc_control_data_type
  110. data_type UVC control data type
  111. struct uvc_menu_info
  112. *menu_info Array of menu entries (for menu controls only)
  113. __u32 menu_count Number of menu entries (for menu controls only)
  114. * struct uvc_menu_info
  115. __u32 value Menu entry value used by the device
  116. __u8 name[32] Menu entry name
  117. * enum uvc_control_data_type
  118. UVC_CTRL_DATA_TYPE_RAW Raw control (byte array)
  119. UVC_CTRL_DATA_TYPE_SIGNED Signed integer
  120. UVC_CTRL_DATA_TYPE_UNSIGNED Unsigned integer
  121. UVC_CTRL_DATA_TYPE_BOOLEAN Boolean
  122. UVC_CTRL_DATA_TYPE_ENUM Enumeration
  123. UVC_CTRL_DATA_TYPE_BITMASK Bitmask
  124. ---- UVCIOC_CTRL_QUERY - Query a UVC XU control ----
  125. Argument: struct uvc_xu_control_query
  126. Description:
  127. This ioctl queries a UVC XU control identified by its extension unit ID
  128. and control selector.
  129. There are a number of different queries available that closely
  130. correspond to the low-level control requests described in the UVC
  131. specification. These requests are:
  132. UVC_GET_CUR
  133. Obtain the current value of the control.
  134. UVC_GET_MIN
  135. Obtain the minimum value of the control.
  136. UVC_GET_MAX
  137. Obtain the maximum value of the control.
  138. UVC_GET_DEF
  139. Obtain the default value of the control.
  140. UVC_GET_RES
  141. Query the resolution of the control, i.e. the step size of the
  142. allowed control values.
  143. UVC_GET_LEN
  144. Query the size of the control in bytes.
  145. UVC_GET_INFO
  146. Query the control information bitmap, which indicates whether
  147. get/set requests are supported.
  148. UVC_SET_CUR
  149. Update the value of the control.
  150. Applications must set the 'size' field to the correct length for the
  151. control. Exceptions are the UVC_GET_LEN and UVC_GET_INFO queries, for
  152. which the size must be set to 2 and 1, respectively. The 'data' field
  153. must point to a valid writable buffer big enough to hold the indicated
  154. number of data bytes.
  155. Data is copied directly from the device without any driver-side
  156. processing. Applications are responsible for data buffer formatting,
  157. including little-endian/big-endian conversion. This is particularly
  158. important for the result of the UVC_GET_LEN requests, which is always
  159. returned as a little-endian 16-bit integer by the device.
  160. Return value:
  161. On success 0 is returned. On error -1 is returned and errno is set
  162. appropriately.
  163. ENOENT
  164. The device does not support the given control or the specified
  165. extension unit could not be found.
  166. ENOBUFS
  167. The specified buffer size is incorrect (too big or too small).
  168. EINVAL
  169. An invalid request code was passed.
  170. EBADRQC
  171. The given request is not supported by the given control.
  172. EFAULT
  173. The data pointer references an inaccessible memory area.
  174. Data types:
  175. * struct uvc_xu_control_query
  176. __u8 unit Extension unit ID
  177. __u8 selector Control selector
  178. __u8 query Request code to send to the device
  179. __u16 size Control data size (in bytes)
  180. __u8 *data Control value