se401.h 5.3 KB

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