00001 #ifndef _UVC_COMPAT_H 00002 #define _UVC_COMPAT_H 00003 00004 #include <linux/version.h> 00005 00006 #ifndef __KERNEL__ 00007 #ifndef __user 00008 #define __user 00009 #endif 00010 #endif 00011 00012 #ifdef CONFIG_INPUT 00013 #undef CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV 00014 #define CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV 1 00015 #endif 00016 00017 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) 00018 /* 00019 * Extended control API 00020 */ 00021 struct v4l2_ext_control { 00022 __u32 id; 00023 __u32 reserved2[2]; 00024 union { 00025 __s32 value; 00026 __s64 value64; 00027 void *reserved; 00028 }; 00029 } __attribute__ ((packed)); 00030 00031 struct v4l2_ext_controls { 00032 __u32 ctrl_class; 00033 __u32 count; 00034 __u32 error_idx; 00035 __u32 reserved[2]; 00036 struct v4l2_ext_control *controls; 00037 }; 00038 00039 /* Values for ctrl_class field */ 00040 #define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */ 00041 #define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */ 00042 00043 #define V4L2_CTRL_ID_MASK (0x0fffffff) 00044 #define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL) 00045 #define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000) 00046 00047 /* Control flags */ 00048 #define V4L2_CTRL_FLAG_READ_ONLY 0x0004 00049 #define V4L2_CTRL_FLAG_UPDATE 0x0008 00050 #define V4L2_CTRL_FLAG_INACTIVE 0x0010 00051 #define V4L2_CTRL_FLAG_SLIDER 0x0020 00052 00053 /* Query flags, to be ORed with the control ID */ 00054 #define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000 00055 00056 /* User-class control IDs defined by V4L2 */ 00057 #undef V4L2_CID_BASE 00058 #define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900) 00059 #define V4L2_CID_USER_BASE V4L2_CID_BASE 00060 #define V4L2_CID_USER_CLASS (V4L2_CTRL_CLASS_USER | 1) 00061 00062 #define VIDIOC_G_EXT_CTRLS _IOWR('V', 71, struct v4l2_ext_controls) 00063 #define VIDIOC_S_EXT_CTRLS _IOWR('V', 72, struct v4l2_ext_controls) 00064 #define VIDIOC_TRY_EXT_CTRLS _IOWR('V', 73, struct v4l2_ext_controls) 00065 00066 #endif 00067 00068 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) 00069 /* 00070 * Frame size and frame rate enumeration 00071 * 00072 * Included in Linux 2.6.19 00073 */ 00074 enum v4l2_frmsizetypes { 00075 V4L2_FRMSIZE_TYPE_DISCRETE = 1, 00076 V4L2_FRMSIZE_TYPE_CONTINUOUS = 2, 00077 V4L2_FRMSIZE_TYPE_STEPWISE = 3, 00078 }; 00079 00080 struct v4l2_frmsize_discrete { 00081 __u32 width; /* Frame width [pixel] */ 00082 __u32 height; /* Frame height [pixel] */ 00083 }; 00084 00085 struct v4l2_frmsize_stepwise { 00086 __u32 min_width; /* Minimum frame width [pixel] */ 00087 __u32 max_width; /* Maximum frame width [pixel] */ 00088 __u32 step_width; /* Frame width step size [pixel] */ 00089 __u32 min_height; /* Minimum frame height [pixel] */ 00090 __u32 max_height; /* Maximum frame height [pixel] */ 00091 __u32 step_height; /* Frame height step size [pixel] */ 00092 }; 00093 00094 struct v4l2_frmsizeenum { 00095 __u32 index; /* Frame size number */ 00096 __u32 pixel_format; /* Pixel format */ 00097 __u32 type; /* Frame size type the device supports. */ 00098 00099 union { /* Frame size */ 00100 struct v4l2_frmsize_discrete discrete; 00101 struct v4l2_frmsize_stepwise stepwise; 00102 }; 00103 00104 __u32 reserved[2]; /* Reserved space for future use */ 00105 }; 00106 00107 enum v4l2_frmivaltypes { 00108 V4L2_FRMIVAL_TYPE_DISCRETE = 1, 00109 V4L2_FRMIVAL_TYPE_CONTINUOUS = 2, 00110 V4L2_FRMIVAL_TYPE_STEPWISE = 3, 00111 }; 00112 00113 struct v4l2_frmival_stepwise { 00114 struct v4l2_fract min; /* Minimum frame interval [s] */ 00115 struct v4l2_fract max; /* Maximum frame interval [s] */ 00116 struct v4l2_fract step; /* Frame interval step size [s] */ 00117 }; 00118 00119 struct v4l2_frmivalenum { 00120 __u32 index; /* Frame format index */ 00121 __u32 pixel_format; /* Pixel format */ 00122 __u32 width; /* Frame width */ 00123 __u32 height; /* Frame height */ 00124 __u32 type; /* Frame interval type the device supports. */ 00125 00126 union { /* Frame interval */ 00127 struct v4l2_fract discrete; 00128 struct v4l2_frmival_stepwise stepwise; 00129 }; 00130 00131 __u32 reserved[2]; /* Reserved space for future use */ 00132 }; 00133 00134 #define VIDIOC_ENUM_FRAMESIZES _IOWR('V', 74, struct v4l2_frmsizeenum) 00135 #define VIDIOC_ENUM_FRAMEINTERVALS _IOWR('V', 75, struct v4l2_frmivalenum) 00136 #endif 00137 00138 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) 00139 /* 00140 * V4L2 Control identifiers. 00141 */ 00142 #define V4L2_CTRL_CLASS_CAMERA 0x009A0000 /* Camera class controls */ 00143 00144 #define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_BASE+24) 00145 enum v4l2_power_line_frequency { 00146 V4L2_CID_POWER_LINE_FREQUENCY_DISABLED = 0, 00147 V4L2_CID_POWER_LINE_FREQUENCY_50HZ = 1, 00148 V4L2_CID_POWER_LINE_FREQUENCY_60HZ = 2, 00149 }; 00150 00151 #define V4L2_CID_HUE_AUTO (V4L2_CID_BASE+25) 00152 #define V4L2_CID_WHITE_BALANCE_TEMPERATURE (V4L2_CID_BASE+26) 00153 #define V4L2_CID_SHARPNESS (V4L2_CID_BASE+27) 00154 #define V4L2_CID_BACKLIGHT_COMPENSATION (V4L2_CID_BASE+28) 00155 00156 #define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900) 00157 #define V4L2_CID_CAMERA_CLASS (V4L2_CTRL_CLASS_CAMERA | 1) 00158 00159 #define V4L2_CID_EXPOSURE_AUTO (V4L2_CID_CAMERA_CLASS_BASE+1) 00160 enum v4l2_exposure_auto_type { 00161 V4L2_EXPOSURE_MANUAL = 0, 00162 V4L2_EXPOSURE_AUTO = 1, 00163 V4L2_EXPOSURE_SHUTTER_PRIORITY = 2, 00164 V4L2_EXPOSURE_APERTURE_PRIORITY = 3 00165 }; 00166 #define V4L2_CID_EXPOSURE_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+2) 00167 #define V4L2_CID_EXPOSURE_AUTO_PRIORITY (V4L2_CID_CAMERA_CLASS_BASE+3) 00168 00169 #define V4L2_CID_PAN_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+4) 00170 #define V4L2_CID_TILT_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+5) 00171 #define V4L2_CID_PAN_RESET (V4L2_CID_CAMERA_CLASS_BASE+6) 00172 #define V4L2_CID_TILT_RESET (V4L2_CID_CAMERA_CLASS_BASE+7) 00173 00174 #define V4L2_CID_PAN_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+8) 00175 #define V4L2_CID_TILT_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+9) 00176 00177 #define V4L2_CID_FOCUS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+10) 00178 #define V4L2_CID_FOCUS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+11) 00179 #define V4L2_CID_FOCUS_AUTO (V4L2_CID_CAMERA_CLASS_BASE+12) 00180 00181 #endif 00182 00183 #ifdef __KERNEL__ 00184 00185 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) 00186 #define __nocast 00187 #endif 00188 00189 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) 00190 /* 00191 * kzalloc() 00192 */ 00193 typedef unsigned int __nocast gfp_t; 00194 00195 static inline void * 00196 kzalloc(size_t size, gfp_t gfp_flags) 00197 { 00198 void *mem = kmalloc(size, gfp_flags); 00199 if (mem) 00200 memset(mem, 0, size); 00201 return mem; 00202 } 00203 #endif 00204 00205 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) 00206 /* 00207 * vm_insert_page() 00208 */ 00209 #include <linux/mm.h> 00210 00211 static inline int 00212 vm_insert_page(struct vm_area_struct *vma, unsigned long addr, 00213 struct page *page) 00214 { 00215 /* Not sure if this is needed. remap_pfn_range() sets VM_RESERVED 00216 * in 2.6.14. 00217 */ 00218 vma->vm_flags |= VM_RESERVED; 00219 00220 SetPageReserved(page); 00221 return remap_pfn_range(vma, addr, page_to_pfn(page), PAGE_SIZE, 00222 vma->vm_page_prot); 00223 } 00224 #endif 00225 00226 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) 00227 /* 00228 * v4l_printk_ioctl() 00229 */ 00230 static inline void 00231 v4l_printk_ioctl(unsigned int cmd) 00232 { 00233 switch (_IOC_TYPE(cmd)) { 00234 case 'v': 00235 printk(KERN_DEBUG "ioctl 0x%x (V4L1)\n", cmd); 00236 break; 00237 case 'V': 00238 printk(KERN_DEBUG "ioctl 0x%x (%s)\n", 00239 cmd, v4l2_ioctl_names[_IOC_NR(cmd)]); 00240 break; 00241 default: 00242 printk(KERN_DEBUG "ioctl 0x%x (?)\n", cmd); 00243 break; 00244 } 00245 } 00246 #endif 00247 00248 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) 00249 /* 00250 * Mutex API 00251 */ 00252 #include <asm/semaphore.h> 00253 #define mutex_lock(mutex) down(mutex) 00254 #define mutex_lock_interruptible(mutex) down_interruptible(mutex) 00255 #define mutex_unlock(mutex) up(mutex) 00256 #define mutex_init(mutex) init_MUTEX(mutex) 00257 #define mutex semaphore 00258 #else 00259 #include <asm/mutex.h> 00260 #endif 00261 00262 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) 00263 #include <linux/videodev.h> 00264 #endif 00265 00266 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) 00267 /* 00268 * usb_endpoint_* functions 00269 * 00270 * Included in Linux 2.6.19 00271 * Backported to 2.6.18 in Red Hat Enterprise Linux 5.2 00272 */ 00273 #ifdef RHEL_RELEASE_CODE 00274 #if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,2) 00275 #define RHEL_HAS_USB_ENDPOINT 00276 #endif 00277 #endif 00278 00279 #ifndef RHEL_HAS_USB_ENDPOINT 00280 static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd) 00281 { 00282 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN); 00283 } 00284 00285 static inline int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd) 00286 { 00287 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 00288 USB_ENDPOINT_XFER_INT); 00289 } 00290 00291 static inline int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd) 00292 { 00293 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 00294 USB_ENDPOINT_XFER_ISOC); 00295 } 00296 00297 static inline int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd) 00298 { 00299 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 00300 USB_ENDPOINT_XFER_BULK); 00301 } 00302 00303 static inline int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd) 00304 { 00305 return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd)); 00306 } 00307 #endif /* RHEL_HAS_USB_ENDPOINT */ 00308 00309 /* 00310 * USB auto suspend 00311 * 00312 * Included in Linux 2.6.19 00313 */ 00314 static inline int usb_autopm_get_interface(struct usb_interface *intf) 00315 { return 0; } 00316 00317 static inline void usb_autopm_put_interface(struct usb_interface *intf) 00318 { } 00319 00320 #endif 00321 00322 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) 00323 /* 00324 * Linked list API 00325 */ 00326 #define list_first_entry(ptr, type, member) \ 00327 list_entry((ptr)->next, type, member) 00328 00329 /* 00330 * uninitialized_var() macro 00331 */ 00332 #define uninitialized_var(x) x 00333 #endif 00334 00335 #endif /* __KERNEL__ */ 00336 00337 #endif /* _UVC_COMPAT_H */ 00338