uvc_compat.h
Go to the documentation of this file.
1 #ifndef _UVC_COMPAT_H
2 #define _UVC_COMPAT_H
3 
4 #include <linux/version.h>
5 
6 #ifndef __KERNEL__
7 #ifndef __user
8 #define __user
9 #endif
10 #endif
11 
12 #ifdef CONFIG_INPUT
13 #undef CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV
14 #define CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV 1
15 #endif
16 
17 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
18 /*
19  * Extended control API
20  */
21 struct v4l2_ext_control {
22  __u32 id;
23  __u32 reserved2[2];
24  union {
25  __s32 value;
26  __s64 value64;
27  void *reserved;
28  };
29 } __attribute__ ((packed));
30 
31 struct v4l2_ext_controls {
32  __u32 ctrl_class;
33  __u32 count;
34  __u32 error_idx;
35  __u32 reserved[2];
36  struct v4l2_ext_control *controls;
37 };
38 
39 /* Values for ctrl_class field */
40 #define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */
41 #define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */
42 
43 #define V4L2_CTRL_ID_MASK (0x0fffffff)
44 #define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL)
45 #define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000)
46 
47 /* Control flags */
48 #define V4L2_CTRL_FLAG_READ_ONLY 0x0004
49 #define V4L2_CTRL_FLAG_UPDATE 0x0008
50 #define V4L2_CTRL_FLAG_INACTIVE 0x0010
51 #define V4L2_CTRL_FLAG_SLIDER 0x0020
52 
53 /* Query flags, to be ORed with the control ID */
54 #define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000
55 
56 /* User-class control IDs defined by V4L2 */
57 #undef V4L2_CID_BASE
58 #define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900)
59 #define V4L2_CID_USER_BASE V4L2_CID_BASE
60 #define V4L2_CID_USER_CLASS (V4L2_CTRL_CLASS_USER | 1)
61 
62 #define VIDIOC_G_EXT_CTRLS _IOWR('V', 71, struct v4l2_ext_controls)
63 #define VIDIOC_S_EXT_CTRLS _IOWR('V', 72, struct v4l2_ext_controls)
64 #define VIDIOC_TRY_EXT_CTRLS _IOWR('V', 73, struct v4l2_ext_controls)
65 
66 #endif
67 
68 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
69 /*
70  * Frame size and frame rate enumeration
71  *
72  * Included in Linux 2.6.19
73  */
74 enum v4l2_frmsizetypes {
75  V4L2_FRMSIZE_TYPE_DISCRETE = 1,
76  V4L2_FRMSIZE_TYPE_CONTINUOUS = 2,
77  V4L2_FRMSIZE_TYPE_STEPWISE = 3,
78 };
79 
80 struct v4l2_frmsize_discrete {
81  __u32 width; /* Frame width [pixel] */
82  __u32 height; /* Frame height [pixel] */
83 };
84 
85 struct v4l2_frmsize_stepwise {
86  __u32 min_width; /* Minimum frame width [pixel] */
87  __u32 max_width; /* Maximum frame width [pixel] */
88  __u32 step_width; /* Frame width step size [pixel] */
89  __u32 min_height; /* Minimum frame height [pixel] */
90  __u32 max_height; /* Maximum frame height [pixel] */
91  __u32 step_height; /* Frame height step size [pixel] */
92 };
93 
94 struct v4l2_frmsizeenum {
95  __u32 index; /* Frame size number */
96  __u32 pixel_format; /* Pixel format */
97  __u32 type; /* Frame size type the device supports. */
98 
99  union { /* Frame size */
100  struct v4l2_frmsize_discrete discrete;
101  struct v4l2_frmsize_stepwise stepwise;
102  };
103 
104  __u32 reserved[2]; /* Reserved space for future use */
105 };
106 
107 enum v4l2_frmivaltypes {
108  V4L2_FRMIVAL_TYPE_DISCRETE = 1,
109  V4L2_FRMIVAL_TYPE_CONTINUOUS = 2,
110  V4L2_FRMIVAL_TYPE_STEPWISE = 3,
111 };
112 
113 struct v4l2_frmival_stepwise {
114  struct v4l2_fract min; /* Minimum frame interval [s] */
115  struct v4l2_fract max; /* Maximum frame interval [s] */
116  struct v4l2_fract step; /* Frame interval step size [s] */
117 };
118 
119 struct v4l2_frmivalenum {
120  __u32 index; /* Frame format index */
121  __u32 pixel_format; /* Pixel format */
122  __u32 width; /* Frame width */
123  __u32 height; /* Frame height */
124  __u32 type; /* Frame interval type the device supports. */
125 
126  union { /* Frame interval */
127  struct v4l2_fract discrete;
128  struct v4l2_frmival_stepwise stepwise;
129  };
130 
131  __u32 reserved[2]; /* Reserved space for future use */
132 };
133 
134 #define VIDIOC_ENUM_FRAMESIZES _IOWR('V', 74, struct v4l2_frmsizeenum)
135 #define VIDIOC_ENUM_FRAMEINTERVALS _IOWR('V', 75, struct v4l2_frmivalenum)
136 #endif
137 
138 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
139 /*
140  * V4L2 Control identifiers.
141  */
142 #define V4L2_CTRL_CLASS_CAMERA 0x009A0000 /* Camera class controls */
143 
144 #define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_BASE+24)
145 enum v4l2_power_line_frequency {
146  V4L2_CID_POWER_LINE_FREQUENCY_DISABLED = 0,
147  V4L2_CID_POWER_LINE_FREQUENCY_50HZ = 1,
148  V4L2_CID_POWER_LINE_FREQUENCY_60HZ = 2,
149 };
150 
151 #define V4L2_CID_HUE_AUTO (V4L2_CID_BASE+25)
152 #define V4L2_CID_WHITE_BALANCE_TEMPERATURE (V4L2_CID_BASE+26)
153 #define V4L2_CID_SHARPNESS (V4L2_CID_BASE+27)
154 #define V4L2_CID_BACKLIGHT_COMPENSATION (V4L2_CID_BASE+28)
155 
156 #define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900)
157 #define V4L2_CID_CAMERA_CLASS (V4L2_CTRL_CLASS_CAMERA | 1)
158 
159 #define V4L2_CID_EXPOSURE_AUTO (V4L2_CID_CAMERA_CLASS_BASE+1)
160 enum v4l2_exposure_auto_type {
161  V4L2_EXPOSURE_MANUAL = 0,
162  V4L2_EXPOSURE_AUTO = 1,
163  V4L2_EXPOSURE_SHUTTER_PRIORITY = 2,
164  V4L2_EXPOSURE_APERTURE_PRIORITY = 3
165 };
166 #define V4L2_CID_EXPOSURE_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+2)
167 #define V4L2_CID_EXPOSURE_AUTO_PRIORITY (V4L2_CID_CAMERA_CLASS_BASE+3)
168 
169 #define V4L2_CID_PAN_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+4)
170 #define V4L2_CID_TILT_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+5)
171 #define V4L2_CID_PAN_RESET (V4L2_CID_CAMERA_CLASS_BASE+6)
172 #define V4L2_CID_TILT_RESET (V4L2_CID_CAMERA_CLASS_BASE+7)
173 
174 #define V4L2_CID_PAN_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+8)
175 #define V4L2_CID_TILT_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+9)
176 
177 #define V4L2_CID_FOCUS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+10)
178 #define V4L2_CID_FOCUS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+11)
179 #define V4L2_CID_FOCUS_AUTO (V4L2_CID_CAMERA_CLASS_BASE+12)
180 
181 #define V4L2_CID_ZOOM_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+13)
182 
183 #endif
184 
185 #define V4L2_CID_ROLL_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17)
186 #define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+18)
187 
188 #ifdef __KERNEL__
189 
190 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
191 #define __nocast
192 #endif
193 
194 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
195 /*
196  * kzalloc()
197  */
198 typedef unsigned int __nocast gfp_t;
199 
200 static inline void *
201 kzalloc(size_t size, gfp_t gfp_flags)
202 {
203  void *mem = kmalloc(size, gfp_flags);
204  if (mem)
205  memset(mem, 0, size);
206  return mem;
207 }
208 #endif
209 
210 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
211 /*
212  * vm_insert_page()
213  */
214 #include <linux/mm.h>
215 
216 static inline int
217 vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
218  struct page *page)
219 {
220  /* Not sure if this is needed. remap_pfn_range() sets VM_RESERVED
221  * in 2.6.14.
222  */
223  vma->vm_flags |= VM_RESERVED;
224 
225  SetPageReserved(page);
226  return remap_pfn_range(vma, addr, page_to_pfn(page), PAGE_SIZE,
227  vma->vm_page_prot);
228 }
229 #endif
230 
231 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
232 /*
233  * v4l_printk_ioctl()
234  */
235 static inline void
236 v4l_printk_ioctl(unsigned int cmd)
237 {
238  switch (_IOC_TYPE(cmd)) {
239  case 'v':
240  printk(KERN_DEBUG "ioctl 0x%x (V4L1)\n", cmd);
241  break;
242  case 'V':
243  printk(KERN_DEBUG "ioctl 0x%x (%s)\n",
244  cmd, v4l2_ioctl_names[_IOC_NR(cmd)]);
245  break;
246  default:
247  printk(KERN_DEBUG "ioctl 0x%x (?)\n", cmd);
248  break;
249  }
250 }
251 #endif
252 
253 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
254 /*
255  * Mutex API
256  */
257 #include <asm/semaphore.h>
258 #define mutex_lock(mutex) down(mutex)
259 #define mutex_lock_interruptible(mutex) down_interruptible(mutex)
260 #define mutex_unlock(mutex) up(mutex)
261 #define mutex_init(mutex) init_MUTEX(mutex)
262 #define mutex semaphore
263 #else
264 #include <asm/mutex.h>
265 #endif
266 
267 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
268 #include <linux/videodev.h>
269 #endif
270 
271 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
272 /*
273  * usb_endpoint_* functions
274  *
275  * Included in Linux 2.6.19
276  * Backported to 2.6.18 in Red Hat Enterprise Linux 5.2
277  */
278 #ifdef RHEL_RELEASE_CODE
279 #if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,2)
280 #define RHEL_HAS_USB_ENDPOINT
281 #endif
282 #endif
283 
284 #ifndef RHEL_HAS_USB_ENDPOINT
285 static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
286 {
287  return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
288 }
289 
290 static inline int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
291 {
292  return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
293  USB_ENDPOINT_XFER_INT);
294 }
295 
296 static inline int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd)
297 {
298  return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
299  USB_ENDPOINT_XFER_ISOC);
300 }
301 
302 static inline int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
303 {
304  return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
305  USB_ENDPOINT_XFER_BULK);
306 }
307 
308 static inline int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
309 {
310  return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
311 }
312 #endif /* RHEL_HAS_USB_ENDPOINT */
313 
314 /*
315  * USB auto suspend
316  *
317  * Included in Linux 2.6.19
318  */
319 static inline int usb_autopm_get_interface(struct usb_interface *intf)
320 { return 0; }
321 
322 static inline void usb_autopm_put_interface(struct usb_interface *intf)
323 { }
324 
325 /*
326  * DIV_ROUND_UP() macro
327  *
328  * Included in Linux 2.6.19
329  */
330 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
331 #endif
332 
333 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
334 /*
335  * Linked list API
336  */
337 #define list_first_entry(ptr, type, member) \
338  list_entry((ptr)->next, type, member)
339 
340 /*
341  * uninitialized_var() macro
342  */
343 #define uninitialized_var(x) x
344 #endif
345 
346 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
347 #if defined(OBSOLETE_OWNER) || defined(OBSOLETE_DEVDATA)
348 /*
349  * video_drvdata()
350  */
351 static inline void *video_drvdata(struct file *file)
352 {
353  return video_get_drvdata(video_devdata(file));
354 }
355 #endif
356 #endif
357 
358 #endif /* __KERNEL__ */
359 
360 #endif /* _UVC_COMPAT_H */
361 
string cmd


opt_camera
Author(s): Kei Okada
autogenerated on Tue May 11 2021 02:55:43