se401.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #ifndef __LINUX_se401_H
  2. #define __LINUX_se401_H
  3. #include <linux/uaccess.h>
  4. #include <linux/videodev.h>
  5. #include <media/v4l2-common.h>
  6. #include <media/v4l2-ioctl.h>
  7. #include <linux/mutex.h>
  8. #define se401_DEBUG /* Turn on debug messages */
  9. #ifdef se401_DEBUG
  10. # define PDEBUG(level, fmt, args...) \
  11. if (debug >= level) \
  12. info("[" __PRETTY_FUNCTION__ ":%d] " fmt, __LINE__ , ## args)
  13. #else
  14. # define PDEBUG(level, fmt, args...) do {} while (0)
  15. #endif
  16. /* An almost drop-in replacement for sleep_on_interruptible */
  17. #define wait_interruptible(test, queue, wait) \
  18. { \
  19. add_wait_queue(queue, wait); \
  20. set_current_state(TASK_INTERRUPTIBLE); \
  21. if (test) \
  22. schedule(); \
  23. remove_wait_queue(queue, wait); \
  24. set_current_state(TASK_RUNNING); \
  25. if (signal_pending(current)) \
  26. break; \
  27. }
  28. #define SE401_REQ_GET_CAMERA_DESCRIPTOR 0x06
  29. #define SE401_REQ_START_CONTINUOUS_CAPTURE 0x41
  30. #define SE401_REQ_STOP_CONTINUOUS_CAPTURE 0x42
  31. #define SE401_REQ_CAPTURE_FRAME 0x43
  32. #define SE401_REQ_GET_BRT 0x44
  33. #define SE401_REQ_SET_BRT 0x45
  34. #define SE401_REQ_GET_WIDTH 0x4c
  35. #define SE401_REQ_SET_WIDTH 0x4d
  36. #define SE401_REQ_GET_HEIGHT 0x4e
  37. #define SE401_REQ_SET_HEIGHT 0x4f
  38. #define SE401_REQ_GET_OUTPUT_MODE 0x50
  39. #define SE401_REQ_SET_OUTPUT_MODE 0x51
  40. #define SE401_REQ_GET_EXT_FEATURE 0x52
  41. #define SE401_REQ_SET_EXT_FEATURE 0x53
  42. #define SE401_REQ_CAMERA_POWER 0x56
  43. #define SE401_REQ_LED_CONTROL 0x57
  44. #define SE401_REQ_BIOS 0xff
  45. #define SE401_BIOS_READ 0x07
  46. #define SE401_FORMAT_BAYER 0x40
  47. /* Hyundai hv7131b registers
  48. 7121 and 7141 should be the same (haven't really checked...) */
  49. /* Mode registers: */
  50. #define HV7131_REG_MODE_A 0x00
  51. #define HV7131_REG_MODE_B 0x01
  52. #define HV7131_REG_MODE_C 0x02
  53. /* Frame registers: */
  54. #define HV7131_REG_FRSU 0x10
  55. #define HV7131_REG_FRSL 0x11
  56. #define HV7131_REG_FCSU 0x12
  57. #define HV7131_REG_FCSL 0x13
  58. #define HV7131_REG_FWHU 0x14
  59. #define HV7131_REG_FWHL 0x15
  60. #define HV7131_REG_FWWU 0x16
  61. #define HV7131_REG_FWWL 0x17
  62. /* Timing registers: */
  63. #define HV7131_REG_THBU 0x20
  64. #define HV7131_REG_THBL 0x21
  65. #define HV7131_REG_TVBU 0x22
  66. #define HV7131_REG_TVBL 0x23
  67. #define HV7131_REG_TITU 0x25
  68. #define HV7131_REG_TITM 0x26
  69. #define HV7131_REG_TITL 0x27
  70. #define HV7131_REG_TMCD 0x28
  71. /* Adjust Registers: */
  72. #define HV7131_REG_ARLV 0x30
  73. #define HV7131_REG_ARCG 0x31
  74. #define HV7131_REG_AGCG 0x32
  75. #define HV7131_REG_ABCG 0x33
  76. #define HV7131_REG_APBV 0x34
  77. #define HV7131_REG_ASLP 0x54
  78. /* Offset Registers: */
  79. #define HV7131_REG_OFSR 0x50
  80. #define HV7131_REG_OFSG 0x51
  81. #define HV7131_REG_OFSB 0x52
  82. /* REset level statistics registers: */
  83. #define HV7131_REG_LOREFNOH 0x57
  84. #define HV7131_REG_LOREFNOL 0x58
  85. #define HV7131_REG_HIREFNOH 0x59
  86. #define HV7131_REG_HIREFNOL 0x5a
  87. /* se401 registers */
  88. #define SE401_OPERATINGMODE 0x2000
  89. /* size of usb transfers */
  90. #define SE401_PACKETSIZE 4096
  91. /* number of queued bulk transfers to use, should be about 8 */
  92. #define SE401_NUMSBUF 1
  93. /* read the usb specs for this one :) */
  94. #define SE401_VIDEO_ENDPOINT 1
  95. #define SE401_BUTTON_ENDPOINT 2
  96. /* number of frames supported by the v4l part */
  97. #define SE401_NUMFRAMES 2
  98. /* scratch buffers for passing data to the decoders */
  99. #define SE401_NUMSCRATCH 32
  100. /* maximum amount of data in a JangGu packet */
  101. #define SE401_VLCDATALEN 1024
  102. /* number of nul sized packets to receive before kicking the camera */
  103. #define SE401_MAX_NULLPACKETS 4000
  104. /* number of decoding errors before kicking the camera */
  105. #define SE401_MAX_ERRORS 200
  106. struct usb_device;
  107. struct se401_sbuf {
  108. unsigned char *data;
  109. };
  110. enum {
  111. FRAME_UNUSED, /* Unused (no MCAPTURE) */
  112. FRAME_READY, /* Ready to start grabbing */
  113. FRAME_GRABBING, /* In the process of being grabbed into */
  114. FRAME_DONE, /* Finished grabbing, but not been synced yet */
  115. FRAME_ERROR, /* Something bad happened while processing */
  116. };
  117. enum {
  118. FMT_BAYER,
  119. FMT_JANGGU,
  120. };
  121. enum {
  122. BUFFER_UNUSED,
  123. BUFFER_READY,
  124. BUFFER_BUSY,
  125. BUFFER_DONE,
  126. };
  127. struct se401_scratch {
  128. unsigned char *data;
  129. volatile int state;
  130. int offset;
  131. int length;
  132. };
  133. struct se401_frame {
  134. unsigned char *data; /* Frame buffer */
  135. volatile int grabstate; /* State of grabbing */
  136. unsigned char *curline;
  137. int curlinepix;
  138. int curpix;
  139. };
  140. struct usb_se401 {
  141. struct video_device vdev;
  142. /* Device structure */
  143. struct usb_device *dev;
  144. unsigned char iface;
  145. char *camera_name;
  146. int change;
  147. int brightness;
  148. int hue;
  149. int rgain;
  150. int ggain;
  151. int bgain;
  152. int expose_h;
  153. int expose_m;
  154. int expose_l;
  155. int resetlevel;
  156. int enhance;
  157. int format;
  158. int sizes;
  159. int *width;
  160. int *height;
  161. int cwidth; /* current width */
  162. int cheight; /* current height */
  163. int palette;
  164. int maxframesize;
  165. int cframesize; /* current framesize */
  166. struct mutex lock;
  167. int user; /* user count for exclusive use */
  168. int removed; /* device disconnected */
  169. int streaming; /* Are we streaming video? */
  170. char *fbuf; /* Videodev buffer area */
  171. struct urb *urb[SE401_NUMSBUF];
  172. struct urb *inturb;
  173. int button;
  174. int buttonpressed;
  175. int curframe; /* Current receiving frame */
  176. struct se401_frame frame[SE401_NUMFRAMES];
  177. int readcount;
  178. int framecount;
  179. int error;
  180. int dropped;
  181. int scratch_next;
  182. int scratch_use;
  183. int scratch_overflow;
  184. struct se401_scratch scratch[SE401_NUMSCRATCH];
  185. /* Decoder specific data: */
  186. unsigned char vlcdata[SE401_VLCDATALEN];
  187. int vlcdatapos;
  188. int bayeroffset;
  189. struct se401_sbuf sbuf[SE401_NUMSBUF];
  190. wait_queue_head_t wq; /* Processes waiting */
  191. int nullpackets;
  192. };
  193. #endif