go7007-priv.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Copyright (C) 2005-2006 Micronas USA Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License (Version 2) as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. /*
  14. * This is the private include file for the go7007 driver. It should not
  15. * be included by anybody but the driver itself, and especially not by
  16. * user-space applications.
  17. */
  18. #include <media/v4l2-device.h>
  19. #include <media/v4l2-ctrls.h>
  20. #include <media/v4l2-fh.h>
  21. #include <media/videobuf2-v4l2.h>
  22. struct go7007;
  23. /* IDs to activate board-specific support code */
  24. #define GO7007_BOARDID_MATRIX_II 0
  25. #define GO7007_BOARDID_MATRIX_RELOAD 1
  26. #define GO7007_BOARDID_STAR_TREK 2
  27. #define GO7007_BOARDID_PCI_VOYAGER 3
  28. #define GO7007_BOARDID_XMEN 4
  29. #define GO7007_BOARDID_XMEN_II 5
  30. #define GO7007_BOARDID_XMEN_III 6
  31. #define GO7007_BOARDID_MATRIX_REV 7
  32. #define GO7007_BOARDID_PX_M402U 8
  33. #define GO7007_BOARDID_PX_TV402U 9
  34. #define GO7007_BOARDID_LIFEVIEW_LR192 10 /* TV Walker Ultra */
  35. #define GO7007_BOARDID_ENDURA 11
  36. #define GO7007_BOARDID_ADLINK_MPG24 12
  37. #define GO7007_BOARDID_SENSORAY_2250 13 /* Sensoray 2250/2251 */
  38. #define GO7007_BOARDID_ADS_USBAV_709 14
  39. /* Various characteristics of each board */
  40. #define GO7007_BOARD_HAS_AUDIO (1<<0)
  41. #define GO7007_BOARD_USE_ONBOARD_I2C (1<<1)
  42. #define GO7007_BOARD_HAS_TUNER (1<<2)
  43. /* Characteristics of sensor devices */
  44. #define GO7007_SENSOR_VALID_POLAR (1<<0)
  45. #define GO7007_SENSOR_HREF_POLAR (1<<1)
  46. #define GO7007_SENSOR_VREF_POLAR (1<<2)
  47. #define GO7007_SENSOR_FIELD_ID_POLAR (1<<3)
  48. #define GO7007_SENSOR_BIT_WIDTH (1<<4)
  49. #define GO7007_SENSOR_VALID_ENABLE (1<<5)
  50. #define GO7007_SENSOR_656 (1<<6)
  51. #define GO7007_SENSOR_CONFIG_MASK 0x7f
  52. #define GO7007_SENSOR_TV (1<<7)
  53. #define GO7007_SENSOR_VBI (1<<8)
  54. #define GO7007_SENSOR_SCALING (1<<9)
  55. #define GO7007_SENSOR_SAA7115 (1<<10)
  56. /* Characteristics of audio sensor devices */
  57. #define GO7007_AUDIO_I2S_MODE_1 (1)
  58. #define GO7007_AUDIO_I2S_MODE_2 (2)
  59. #define GO7007_AUDIO_I2S_MODE_3 (3)
  60. #define GO7007_AUDIO_BCLK_POLAR (1<<2)
  61. #define GO7007_AUDIO_WORD_14 (14<<4)
  62. #define GO7007_AUDIO_WORD_16 (16<<4)
  63. #define GO7007_AUDIO_ONE_CHANNEL (1<<11)
  64. #define GO7007_AUDIO_I2S_MASTER (1<<16)
  65. #define GO7007_AUDIO_OKI_MODE (1<<17)
  66. #define GO7007_CID_CUSTOM_BASE (V4L2_CID_DETECT_CLASS_BASE + 0x1000)
  67. #define V4L2_CID_PIXEL_THRESHOLD0 (GO7007_CID_CUSTOM_BASE+1)
  68. #define V4L2_CID_MOTION_THRESHOLD0 (GO7007_CID_CUSTOM_BASE+2)
  69. #define V4L2_CID_MB_THRESHOLD0 (GO7007_CID_CUSTOM_BASE+3)
  70. #define V4L2_CID_PIXEL_THRESHOLD1 (GO7007_CID_CUSTOM_BASE+4)
  71. #define V4L2_CID_MOTION_THRESHOLD1 (GO7007_CID_CUSTOM_BASE+5)
  72. #define V4L2_CID_MB_THRESHOLD1 (GO7007_CID_CUSTOM_BASE+6)
  73. #define V4L2_CID_PIXEL_THRESHOLD2 (GO7007_CID_CUSTOM_BASE+7)
  74. #define V4L2_CID_MOTION_THRESHOLD2 (GO7007_CID_CUSTOM_BASE+8)
  75. #define V4L2_CID_MB_THRESHOLD2 (GO7007_CID_CUSTOM_BASE+9)
  76. #define V4L2_CID_PIXEL_THRESHOLD3 (GO7007_CID_CUSTOM_BASE+10)
  77. #define V4L2_CID_MOTION_THRESHOLD3 (GO7007_CID_CUSTOM_BASE+11)
  78. #define V4L2_CID_MB_THRESHOLD3 (GO7007_CID_CUSTOM_BASE+12)
  79. struct go7007_board_info {
  80. unsigned int flags;
  81. int hpi_buffer_cap;
  82. unsigned int sensor_flags;
  83. int sensor_width;
  84. int sensor_height;
  85. int sensor_framerate;
  86. int sensor_h_offset;
  87. int sensor_v_offset;
  88. unsigned int audio_flags;
  89. int audio_rate;
  90. int audio_bclk_div;
  91. int audio_main_div;
  92. int num_i2c_devs;
  93. struct go_i2c {
  94. const char *type;
  95. unsigned int is_video:1;
  96. unsigned int is_audio:1;
  97. int addr;
  98. u32 flags;
  99. } i2c_devs[5];
  100. int num_inputs;
  101. struct {
  102. int video_input;
  103. int audio_index;
  104. char *name;
  105. } inputs[4];
  106. int video_config;
  107. int num_aud_inputs;
  108. struct {
  109. int audio_input;
  110. char *name;
  111. } aud_inputs[3];
  112. };
  113. struct go7007_hpi_ops {
  114. int (*interface_reset)(struct go7007 *go);
  115. int (*write_interrupt)(struct go7007 *go, int addr, int data);
  116. int (*read_interrupt)(struct go7007 *go);
  117. int (*stream_start)(struct go7007 *go);
  118. int (*stream_stop)(struct go7007 *go);
  119. int (*send_firmware)(struct go7007 *go, u8 *data, int len);
  120. int (*send_command)(struct go7007 *go, unsigned int cmd, void *arg);
  121. void (*release)(struct go7007 *go);
  122. };
  123. /* The video buffer size must be a multiple of PAGE_SIZE */
  124. #define GO7007_BUF_PAGES (128 * 1024 / PAGE_SIZE)
  125. #define GO7007_BUF_SIZE (GO7007_BUF_PAGES << PAGE_SHIFT)
  126. struct go7007_buffer {
  127. struct vb2_v4l2_buffer vb;
  128. struct list_head list;
  129. unsigned int frame_offset;
  130. u32 modet_active;
  131. };
  132. #define GO7007_RATIO_1_1 0
  133. #define GO7007_RATIO_4_3 1
  134. #define GO7007_RATIO_16_9 2
  135. enum go7007_parser_state {
  136. STATE_DATA,
  137. STATE_00,
  138. STATE_00_00,
  139. STATE_00_00_01,
  140. STATE_FF,
  141. STATE_VBI_LEN_A,
  142. STATE_VBI_LEN_B,
  143. STATE_MODET_MAP,
  144. STATE_UNPARSED,
  145. };
  146. struct go7007 {
  147. struct device *dev;
  148. u8 bus_info[32];
  149. const struct go7007_board_info *board_info;
  150. unsigned int board_id;
  151. int tuner_type;
  152. int channel_number; /* for multi-channel boards like Adlink PCI-MPG24 */
  153. char name[64];
  154. struct video_device vdev;
  155. void *boot_fw;
  156. unsigned boot_fw_len;
  157. struct v4l2_device v4l2_dev;
  158. struct v4l2_ctrl_handler hdl;
  159. struct v4l2_ctrl *mpeg_video_encoding;
  160. struct v4l2_ctrl *mpeg_video_gop_size;
  161. struct v4l2_ctrl *mpeg_video_gop_closure;
  162. struct v4l2_ctrl *mpeg_video_bitrate;
  163. struct v4l2_ctrl *mpeg_video_aspect_ratio;
  164. struct v4l2_ctrl *mpeg_video_b_frames;
  165. struct v4l2_ctrl *mpeg_video_rep_seqheader;
  166. struct v4l2_ctrl *modet_mode;
  167. enum { STATUS_INIT, STATUS_ONLINE, STATUS_SHUTDOWN } status;
  168. spinlock_t spinlock;
  169. struct mutex hw_lock;
  170. struct mutex serialize_lock;
  171. int audio_enabled;
  172. struct v4l2_subdev *sd_video;
  173. struct v4l2_subdev *sd_audio;
  174. u8 usb_buf[16];
  175. /* Video input */
  176. int input;
  177. int aud_input;
  178. enum { GO7007_STD_NTSC, GO7007_STD_PAL, GO7007_STD_OTHER } standard;
  179. v4l2_std_id std;
  180. int sensor_framerate;
  181. int width;
  182. int height;
  183. int encoder_h_offset;
  184. int encoder_v_offset;
  185. unsigned int encoder_h_halve:1;
  186. unsigned int encoder_v_halve:1;
  187. unsigned int encoder_subsample:1;
  188. /* Encoder config */
  189. u32 format;
  190. int bitrate;
  191. int fps_scale;
  192. int pali;
  193. int aspect_ratio;
  194. int gop_size;
  195. unsigned int ipb:1;
  196. unsigned int closed_gop:1;
  197. unsigned int repeat_seqhead:1;
  198. unsigned int seq_header_enable:1;
  199. unsigned int gop_header_enable:1;
  200. unsigned int dvd_mode:1;
  201. unsigned int interlace_coding:1;
  202. /* Motion detection */
  203. unsigned int modet_enable:1;
  204. struct {
  205. unsigned int enable:1;
  206. int pixel_threshold;
  207. int motion_threshold;
  208. int mb_threshold;
  209. } modet[4];
  210. unsigned char modet_map[1624];
  211. unsigned char active_map[216];
  212. u32 modet_event_status;
  213. /* Video streaming */
  214. struct mutex queue_lock;
  215. struct vb2_queue vidq;
  216. enum go7007_parser_state state;
  217. int parse_length;
  218. u16 modet_word;
  219. int seen_frame;
  220. u32 next_seq;
  221. struct list_head vidq_active;
  222. wait_queue_head_t frame_waitq;
  223. struct go7007_buffer *active_buf;
  224. /* Audio streaming */
  225. void (*audio_deliver)(struct go7007 *go, u8 *buf, int length);
  226. void *snd_context;
  227. /* I2C */
  228. int i2c_adapter_online;
  229. struct i2c_adapter i2c_adapter;
  230. /* HPI driver */
  231. const struct go7007_hpi_ops *hpi_ops;
  232. void *hpi_context;
  233. int interrupt_available;
  234. wait_queue_head_t interrupt_waitq;
  235. unsigned short interrupt_value;
  236. unsigned short interrupt_data;
  237. };
  238. static inline struct go7007 *to_go7007(struct v4l2_device *v4l2_dev)
  239. {
  240. return container_of(v4l2_dev, struct go7007, v4l2_dev);
  241. }
  242. /* All of these must be called with the hpi_lock mutex held! */
  243. #define go7007_interface_reset(go) \
  244. ((go)->hpi_ops->interface_reset(go))
  245. #define go7007_write_interrupt(go, x, y) \
  246. ((go)->hpi_ops->write_interrupt)((go), (x), (y))
  247. #define go7007_stream_start(go) \
  248. ((go)->hpi_ops->stream_start(go))
  249. #define go7007_stream_stop(go) \
  250. ((go)->hpi_ops->stream_stop(go))
  251. #define go7007_send_firmware(go, x, y) \
  252. ((go)->hpi_ops->send_firmware)((go), (x), (y))
  253. #define go7007_write_addr(go, x, y) \
  254. ((go)->hpi_ops->write_interrupt)((go), (x)|0x8000, (y))
  255. /* go7007-driver.c */
  256. int go7007_read_addr(struct go7007 *go, u16 addr, u16 *data);
  257. int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data);
  258. int go7007_boot_encoder(struct go7007 *go, int init_i2c);
  259. int go7007_reset_encoder(struct go7007 *go);
  260. int go7007_register_encoder(struct go7007 *go, unsigned num_i2c_devs);
  261. int go7007_start_encoder(struct go7007 *go);
  262. void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length);
  263. struct go7007 *go7007_alloc(const struct go7007_board_info *board,
  264. struct device *dev);
  265. void go7007_update_board(struct go7007 *go);
  266. /* go7007-fw.c */
  267. int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen);
  268. /* go7007-i2c.c */
  269. int go7007_i2c_init(struct go7007 *go);
  270. int go7007_i2c_remove(struct go7007 *go);
  271. /* go7007-v4l2.c */
  272. int go7007_v4l2_init(struct go7007 *go);
  273. int go7007_v4l2_ctrl_init(struct go7007 *go);
  274. void go7007_v4l2_remove(struct go7007 *go);
  275. /* snd-go7007.c */
  276. int go7007_snd_init(struct go7007 *go);
  277. int go7007_snd_remove(struct go7007 *go);