pwc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /* (C) 1999-2003 Nemosoft Unv.
  2. (C) 2004-2006 Luc Saillard (luc@saillard.org)
  3. NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
  4. driver and thus may have bugs that are not present in the original version.
  5. Please send bug reports and support requests to <luc@saillard.org>.
  6. The decompression routines have been implemented by reverse-engineering the
  7. Nemosoft binary pwcx module. Caveat emptor.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef PWC_H
  21. #define PWC_H
  22. #include <linux/module.h>
  23. #include <linux/usb.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/wait.h>
  26. #include <linux/mutex.h>
  27. #include <linux/mm.h>
  28. #include <linux/slab.h>
  29. #include <asm/errno.h>
  30. #include <linux/videodev2.h>
  31. #include <media/v4l2-common.h>
  32. #include <media/v4l2-ioctl.h>
  33. #include <media/videobuf2-vmalloc.h>
  34. #ifdef CONFIG_USB_PWC_INPUT_EVDEV
  35. #include <linux/input.h>
  36. #endif
  37. #include "pwc-uncompress.h"
  38. #include <media/pwc-ioctl.h>
  39. /* Version block */
  40. #define PWC_VERSION "10.0.15"
  41. #define PWC_NAME "pwc"
  42. #define PFX PWC_NAME ": "
  43. /* Trace certain actions in the driver */
  44. #define PWC_DEBUG_LEVEL_MODULE (1<<0)
  45. #define PWC_DEBUG_LEVEL_PROBE (1<<1)
  46. #define PWC_DEBUG_LEVEL_OPEN (1<<2)
  47. #define PWC_DEBUG_LEVEL_READ (1<<3)
  48. #define PWC_DEBUG_LEVEL_MEMORY (1<<4)
  49. #define PWC_DEBUG_LEVEL_FLOW (1<<5)
  50. #define PWC_DEBUG_LEVEL_SIZE (1<<6)
  51. #define PWC_DEBUG_LEVEL_IOCTL (1<<7)
  52. #define PWC_DEBUG_LEVEL_TRACE (1<<8)
  53. #define PWC_DEBUG_MODULE(fmt, args...) PWC_DEBUG(MODULE, fmt, ##args)
  54. #define PWC_DEBUG_PROBE(fmt, args...) PWC_DEBUG(PROBE, fmt, ##args)
  55. #define PWC_DEBUG_OPEN(fmt, args...) PWC_DEBUG(OPEN, fmt, ##args)
  56. #define PWC_DEBUG_READ(fmt, args...) PWC_DEBUG(READ, fmt, ##args)
  57. #define PWC_DEBUG_MEMORY(fmt, args...) PWC_DEBUG(MEMORY, fmt, ##args)
  58. #define PWC_DEBUG_FLOW(fmt, args...) PWC_DEBUG(FLOW, fmt, ##args)
  59. #define PWC_DEBUG_SIZE(fmt, args...) PWC_DEBUG(SIZE, fmt, ##args)
  60. #define PWC_DEBUG_IOCTL(fmt, args...) PWC_DEBUG(IOCTL, fmt, ##args)
  61. #define PWC_DEBUG_TRACE(fmt, args...) PWC_DEBUG(TRACE, fmt, ##args)
  62. #ifdef CONFIG_USB_PWC_DEBUG
  63. #define PWC_DEBUG_LEVEL (PWC_DEBUG_LEVEL_MODULE)
  64. #define PWC_DEBUG(level, fmt, args...) do {\
  65. if ((PWC_DEBUG_LEVEL_ ##level) & pwc_trace) \
  66. printk(KERN_DEBUG PFX fmt, ##args); \
  67. } while (0)
  68. #define PWC_ERROR(fmt, args...) printk(KERN_ERR PFX fmt, ##args)
  69. #define PWC_WARNING(fmt, args...) printk(KERN_WARNING PFX fmt, ##args)
  70. #define PWC_INFO(fmt, args...) printk(KERN_INFO PFX fmt, ##args)
  71. #define PWC_TRACE(fmt, args...) PWC_DEBUG(TRACE, fmt, ##args)
  72. #else /* if ! CONFIG_USB_PWC_DEBUG */
  73. #define PWC_ERROR(fmt, args...) printk(KERN_ERR PFX fmt, ##args)
  74. #define PWC_WARNING(fmt, args...) printk(KERN_WARNING PFX fmt, ##args)
  75. #define PWC_INFO(fmt, args...) printk(KERN_INFO PFX fmt, ##args)
  76. #define PWC_TRACE(fmt, args...) do { } while(0)
  77. #define PWC_DEBUG(level, fmt, args...) do { } while(0)
  78. #define pwc_trace 0
  79. #endif
  80. /* Defines for ToUCam cameras */
  81. #define TOUCAM_HEADER_SIZE 8
  82. #define TOUCAM_TRAILER_SIZE 4
  83. #define FEATURE_MOTOR_PANTILT 0x0001
  84. #define FEATURE_CODEC1 0x0002
  85. #define FEATURE_CODEC2 0x0004
  86. /* Ignore errors in the first N frames, to allow for startup delays */
  87. #define FRAME_LOWMARK 5
  88. /* Size and number of buffers for the ISO pipe. */
  89. #define MAX_ISO_BUFS 3
  90. #define ISO_FRAMES_PER_DESC 10
  91. #define ISO_MAX_FRAME_SIZE 960
  92. #define ISO_BUFFER_SIZE (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)
  93. /* Maximum size after decompression is 640x480 YUV data, 1.5 * 640 * 480 */
  94. #define PWC_FRAME_SIZE (460800 + TOUCAM_HEADER_SIZE + TOUCAM_TRAILER_SIZE)
  95. /* Absolute minimum and maximum number of buffers available for mmap() */
  96. #define MIN_FRAMES 2
  97. #define MAX_FRAMES 16
  98. /* Some macros to quickly find the type of a webcam */
  99. #define DEVICE_USE_CODEC1(x) ((x)<675)
  100. #define DEVICE_USE_CODEC2(x) ((x)>=675 && (x)<700)
  101. #define DEVICE_USE_CODEC3(x) ((x)>=700)
  102. #define DEVICE_USE_CODEC23(x) ((x)>=675)
  103. /* The following structures were based on cpia.h. Why reinvent the wheel? :-) */
  104. struct pwc_iso_buf
  105. {
  106. void *data;
  107. int length;
  108. int read;
  109. struct urb *urb;
  110. };
  111. /* intermediate buffers with raw data from the USB cam */
  112. struct pwc_frame_buf
  113. {
  114. struct vb2_buffer vb; /* common v4l buffer stuff -- must be first */
  115. struct list_head list;
  116. void *data;
  117. int filled; /* number of bytes filled */
  118. };
  119. struct pwc_device
  120. {
  121. struct video_device vdev;
  122. struct mutex modlock;
  123. /* Pointer to our usb_device, may be NULL after unplug */
  124. struct usb_device *udev;
  125. /* type of cam (645, 646, 675, 680, 690, 720, 730, 740, 750) */
  126. int type;
  127. int release; /* release number */
  128. int features; /* feature bits */
  129. char serial[30]; /* serial number (string) */
  130. /*** Video data ***/
  131. struct file *capt_file; /* file doing video capture */
  132. int vendpoint; /* video isoc endpoint */
  133. int vcinterface; /* video control interface */
  134. int valternate; /* alternate interface needed */
  135. int vframes, vsize; /* frames-per-second & size (see PSZ_*) */
  136. int pixfmt; /* pixelformat: V4L2_PIX_FMT_YUV420 or _PWCX */
  137. int vframe_count; /* received frames */
  138. int vmax_packet_size; /* USB maxpacket size */
  139. int vlast_packet_size; /* for frame synchronisation */
  140. int visoc_errors; /* number of contiguous ISOC errors */
  141. int vcompression; /* desired compression factor */
  142. int vbandlength; /* compressed band length; 0 is uncompressed */
  143. char vsnapshot; /* snapshot mode */
  144. char vsync; /* used by isoc handler */
  145. char vmirror; /* for ToUCaM series */
  146. char power_save; /* Do powersaving for this cam */
  147. int cmd_len;
  148. unsigned char cmd_buf[13];
  149. struct pwc_iso_buf sbuf[MAX_ISO_BUFS];
  150. char iso_init;
  151. /* videobuf2 queue and queued buffers list */
  152. struct vb2_queue vb_queue;
  153. struct list_head queued_bufs;
  154. spinlock_t queued_bufs_lock;
  155. /*
  156. * Frame currently being filled, this only gets touched by the
  157. * isoc urb complete handler, and by stream start / stop since
  158. * start / stop touch it before / after starting / killing the urbs
  159. * no locking is needed around this
  160. */
  161. struct pwc_frame_buf *fill_buf;
  162. int frame_header_size, frame_trailer_size;
  163. int frame_size;
  164. int frame_total_size; /* including header & trailer */
  165. int drop_frames;
  166. void *decompress_data; /* private data for decompression engine */
  167. /*
  168. * We have an 'image' and a 'view', where 'image' is the fixed-size img
  169. * as delivered by the camera, and 'view' is the size requested by the
  170. * program. The camera image is centered in this viewport, laced with
  171. * a gray or black border. view_min <= image <= view <= view_max;
  172. */
  173. int image_mask; /* supported sizes */
  174. struct pwc_coord view_min, view_max; /* minimum and maximum view */
  175. struct pwc_coord abs_max; /* maximum supported size */
  176. struct pwc_coord image, view; /* image and viewport size */
  177. struct pwc_coord offset; /* offset of the viewport */
  178. /*** motorized pan/tilt feature */
  179. struct pwc_mpt_range angle_range;
  180. int pan_angle; /* in degrees * 100 */
  181. int tilt_angle; /* absolute angle; 0,0 is home */
  182. /*
  183. * Set to 1 when the user push the button, reset to 0
  184. * when this value is read from sysfs.
  185. */
  186. int snapshot_button_status;
  187. #ifdef CONFIG_USB_PWC_INPUT_EVDEV
  188. struct input_dev *button_dev; /* webcam snapshot button input */
  189. char button_phys[64];
  190. #endif
  191. };
  192. /* Global variables */
  193. #ifdef CONFIG_USB_PWC_DEBUG
  194. extern int pwc_trace;
  195. #endif
  196. /** Functions in pwc-misc.c */
  197. /* sizes in pixels */
  198. extern const struct pwc_coord pwc_image_sizes[PSZ_MAX];
  199. int pwc_decode_size(struct pwc_device *pdev, int width, int height);
  200. void pwc_construct(struct pwc_device *pdev);
  201. /** Functions in pwc-ctrl.c */
  202. /* Request a certain video mode. Returns < 0 if not possible */
  203. extern int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frames, int compression, int snapshot);
  204. extern unsigned int pwc_get_fps(struct pwc_device *pdev, unsigned int index, unsigned int size);
  205. /* Calculate the number of bytes per image (not frame) */
  206. extern int pwc_mpt_reset(struct pwc_device *pdev, int flags);
  207. extern int pwc_mpt_set_angle(struct pwc_device *pdev, int pan, int tilt);
  208. /* Various controls; should be obvious. Value 0..65535, or < 0 on error */
  209. extern int pwc_get_brightness(struct pwc_device *pdev);
  210. extern int pwc_set_brightness(struct pwc_device *pdev, int value);
  211. extern int pwc_get_contrast(struct pwc_device *pdev);
  212. extern int pwc_set_contrast(struct pwc_device *pdev, int value);
  213. extern int pwc_get_gamma(struct pwc_device *pdev);
  214. extern int pwc_set_gamma(struct pwc_device *pdev, int value);
  215. extern int pwc_get_saturation(struct pwc_device *pdev, int *value);
  216. extern int pwc_set_saturation(struct pwc_device *pdev, int value);
  217. extern int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value);
  218. extern int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor);
  219. extern int pwc_restore_user(struct pwc_device *pdev);
  220. extern int pwc_save_user(struct pwc_device *pdev);
  221. extern int pwc_restore_factory(struct pwc_device *pdev);
  222. /* exported for use by v4l2 controls */
  223. extern int pwc_get_red_gain(struct pwc_device *pdev, int *value);
  224. extern int pwc_set_red_gain(struct pwc_device *pdev, int value);
  225. extern int pwc_get_blue_gain(struct pwc_device *pdev, int *value);
  226. extern int pwc_set_blue_gain(struct pwc_device *pdev, int value);
  227. extern int pwc_get_awb(struct pwc_device *pdev);
  228. extern int pwc_set_awb(struct pwc_device *pdev, int mode);
  229. extern int pwc_set_agc(struct pwc_device *pdev, int mode, int value);
  230. extern int pwc_get_agc(struct pwc_device *pdev, int *value);
  231. extern int pwc_set_shutter_speed(struct pwc_device *pdev, int mode, int value);
  232. extern int pwc_get_shutter_speed(struct pwc_device *pdev, int *value);
  233. extern int pwc_set_colour_mode(struct pwc_device *pdev, int colour);
  234. extern int pwc_get_colour_mode(struct pwc_device *pdev, int *colour);
  235. extern int pwc_set_contour(struct pwc_device *pdev, int contour);
  236. extern int pwc_get_contour(struct pwc_device *pdev, int *contour);
  237. extern int pwc_set_backlight(struct pwc_device *pdev, int backlight);
  238. extern int pwc_get_backlight(struct pwc_device *pdev, int *backlight);
  239. extern int pwc_set_flicker(struct pwc_device *pdev, int flicker);
  240. extern int pwc_get_flicker(struct pwc_device *pdev, int *flicker);
  241. extern int pwc_set_dynamic_noise(struct pwc_device *pdev, int noise);
  242. extern int pwc_get_dynamic_noise(struct pwc_device *pdev, int *noise);
  243. /* Power down or up the camera; not supported by all models */
  244. extern void pwc_camera_power(struct pwc_device *pdev, int power);
  245. /* Private ioctl()s; see pwc-ioctl.h */
  246. extern long pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg);
  247. extern const struct v4l2_ioctl_ops pwc_ioctl_ops;
  248. /** pwc-uncompress.c */
  249. /* Expand frame to image, possibly including decompression. Uses read_frame and fill_image */
  250. int pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf);
  251. #endif