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 #ifndef V4L2_CID_IRIS_ABSOLUTE
187 #define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+18)
188 #endif
189 
190 #ifdef __KERNEL__
191 
192 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
193 #define __nocast
194 #endif
195 
196 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
197 /*
198  * kzalloc()
199  */
200 typedef unsigned int __nocast gfp_t;
201 
202 static inline void *
203 kzalloc(size_t size, gfp_t gfp_flags)
204 {
205  void *mem = kmalloc(size, gfp_flags);
206  if (mem)
207  memset(mem, 0, size);
208  return mem;
209 }
210 #endif
211 
212 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
213 /*
214  * vm_insert_page()
215  */
216 #include <linux/mm.h>
217 
218 static inline int
219 vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
220  struct page *page)
221 {
222  /* Not sure if this is needed. remap_pfn_range() sets VM_RESERVED
223  * in 2.6.14.
224  */
225  vma->vm_flags |= VM_RESERVED;
226 
227  SetPageReserved(page);
228  return remap_pfn_range(vma, addr, page_to_pfn(page), PAGE_SIZE,
229  vma->vm_page_prot);
230 }
231 #endif
232 
233 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
234 /*
235  * v4l_printk_ioctl()
236  */
237 static inline void
238 v4l_printk_ioctl(unsigned int cmd)
239 {
240  switch (_IOC_TYPE(cmd)) {
241  case 'v':
242  printk(KERN_DEBUG "ioctl 0x%x (V4L1)\n", cmd);
243  break;
244  case 'V':
245  printk(KERN_DEBUG "ioctl 0x%x (%s)\n",
246  cmd, v4l2_ioctl_names[_IOC_NR(cmd)]);
247  break;
248  default:
249  printk(KERN_DEBUG "ioctl 0x%x (?)\n", cmd);
250  break;
251  }
252 }
253 #endif
254 
255 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
256 /*
257  * Mutex API
258  */
259 #include <asm/semaphore.h>
260 #define mutex_lock(mutex) down(mutex)
261 #define mutex_lock_interruptible(mutex) down_interruptible(mutex)
262 #define mutex_unlock(mutex) up(mutex)
263 #define mutex_init(mutex) init_MUTEX(mutex)
264 #define mutex semaphore
265 #else
266 #include <asm/mutex.h>
267 #endif
268 
269 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
270 #include <linux/videodev.h>
271 #endif
272 
273 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
274 /*
275  * usb_endpoint_* functions
276  *
277  * Included in Linux 2.6.19
278  * Backported to 2.6.18 in Red Hat Enterprise Linux 5.2
279  */
280 #ifdef RHEL_RELEASE_CODE
281 #if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,2)
282 #define RHEL_HAS_USB_ENDPOINT
283 #endif
284 #endif
285 
286 #ifndef RHEL_HAS_USB_ENDPOINT
287 static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
288 {
289  return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
290 }
291 
292 static inline int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
293 {
294  return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
295  USB_ENDPOINT_XFER_INT);
296 }
297 
298 static inline int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd)
299 {
300  return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
301  USB_ENDPOINT_XFER_ISOC);
302 }
303 
304 static inline int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
305 {
306  return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
307  USB_ENDPOINT_XFER_BULK);
308 }
309 
310 static inline int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
311 {
312  return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
313 }
314 #endif /* RHEL_HAS_USB_ENDPOINT */
315 
316 /*
317  * USB auto suspend
318  *
319  * Included in Linux 2.6.19
320  */
321 static inline int usb_autopm_get_interface(struct usb_interface *intf)
322 { return 0; }
323 
324 static inline void usb_autopm_put_interface(struct usb_interface *intf)
325 { }
326 
327 /*
328  * DIV_ROUND_UP() macro
329  *
330  * Included in Linux 2.6.19
331  */
332 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
333 #endif
334 
335 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
336 /*
337  * Linked list API
338  */
339 #define list_first_entry(ptr, type, member) \
340  list_entry((ptr)->next, type, member)
341 
342 /*
343  * uninitialized_var() macro
344  */
345 #define uninitialized_var(x) x
346 #endif
347 
348 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
349 #if defined(OBSOLETE_OWNER) || defined(OBSOLETE_DEVDATA)
350 /*
351  * video_drvdata()
352  */
353 static inline void *video_drvdata(struct file *file)
354 {
355  return video_get_drvdata(video_devdata(file));
356 }
357 #endif
358 #endif
359 
360 #endif /* __KERNEL__ */
361 
362 #endif /* _UVC_COMPAT_H */
363 
string cmd


opt_camera
Author(s): Kei Okada
autogenerated on Sat Jun 24 2023 02:40:31