go7007-priv.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software Foundation,
  15. * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  16. */
  17. /*
  18. * This is the private include file for the go7007 driver. It should not
  19. * be included by anybody but the driver itself, and especially not by
  20. * user-space applications.
  21. */
  22. #include <media/v4l2-device.h>
  23. struct go7007;
  24. /* IDs to activate board-specific support code */
  25. #define GO7007_BOARDID_MATRIX_II 0
  26. #define GO7007_BOARDID_MATRIX_RELOAD 1
  27. #define GO7007_BOARDID_STAR_TREK 2
  28. #define GO7007_BOARDID_PCI_VOYAGER 3
  29. #define GO7007_BOARDID_XMEN 4
  30. #define GO7007_BOARDID_XMEN_II 5
  31. #define GO7007_BOARDID_XMEN_III 6
  32. #define GO7007_BOARDID_MATRIX_REV 7
  33. #define GO7007_BOARDID_PX_M402U 16
  34. #define GO7007_BOARDID_PX_TV402U_ANY 17 /* need to check tuner model */
  35. #define GO7007_BOARDID_PX_TV402U_NA 18 /* detected NTSC tuner */
  36. #define GO7007_BOARDID_PX_TV402U_EU 19 /* detected PAL tuner */
  37. #define GO7007_BOARDID_PX_TV402U_JP 20 /* detected NTSC-J tuner */
  38. #define GO7007_BOARDID_LIFEVIEW_LR192 21 /* TV Walker Ultra */
  39. #define GO7007_BOARDID_ENDURA 22
  40. #define GO7007_BOARDID_ADLINK_MPG24 23
  41. #define GO7007_BOARDID_SENSORAY_2250 24 /* Sensoray 2250/2251 */
  42. /* Various characteristics of each board */
  43. #define GO7007_BOARD_HAS_AUDIO (1<<0)
  44. #define GO7007_BOARD_USE_ONBOARD_I2C (1<<1)
  45. #define GO7007_BOARD_HAS_TUNER (1<<2)
  46. /* Characteristics of sensor devices */
  47. #define GO7007_SENSOR_VALID_POLAR (1<<0)
  48. #define GO7007_SENSOR_HREF_POLAR (1<<1)
  49. #define GO7007_SENSOR_VREF_POLAR (1<<2)
  50. #define GO7007_SENSOR_FIELD_ID_POLAR (1<<3)
  51. #define GO7007_SENSOR_BIT_WIDTH (1<<4)
  52. #define GO7007_SENSOR_VALID_ENABLE (1<<5)
  53. #define GO7007_SENSOR_656 (1<<6)
  54. #define GO7007_SENSOR_CONFIG_MASK 0x7f
  55. #define GO7007_SENSOR_TV (1<<7)
  56. #define GO7007_SENSOR_VBI (1<<8)
  57. #define GO7007_SENSOR_SCALING (1<<9)
  58. /* Characteristics of audio sensor devices */
  59. #define GO7007_AUDIO_I2S_MODE_1 (1)
  60. #define GO7007_AUDIO_I2S_MODE_2 (2)
  61. #define GO7007_AUDIO_I2S_MODE_3 (3)
  62. #define GO7007_AUDIO_BCLK_POLAR (1<<2)
  63. #define GO7007_AUDIO_WORD_14 (14<<4)
  64. #define GO7007_AUDIO_WORD_16 (16<<4)
  65. #define GO7007_AUDIO_ONE_CHANNEL (1<<11)
  66. #define GO7007_AUDIO_I2S_MASTER (1<<16)
  67. #define GO7007_AUDIO_OKI_MODE (1<<17)
  68. struct go7007_board_info {
  69. char *firmware;
  70. unsigned int flags;
  71. int hpi_buffer_cap;
  72. unsigned int sensor_flags;
  73. int sensor_width;
  74. int sensor_height;
  75. int sensor_framerate;
  76. int sensor_h_offset;
  77. int sensor_v_offset;
  78. unsigned int audio_flags;
  79. int audio_rate;
  80. int audio_bclk_div;
  81. int audio_main_div;
  82. int num_i2c_devs;
  83. struct {
  84. const char *type;
  85. int id;
  86. int addr;
  87. } i2c_devs[4];
  88. int num_inputs;
  89. struct {
  90. int video_input;
  91. int audio_input;
  92. char *name;
  93. } inputs[4];
  94. };
  95. struct go7007_hpi_ops {
  96. int (*interface_reset)(struct go7007 *go);
  97. int (*write_interrupt)(struct go7007 *go, int addr, int data);
  98. int (*read_interrupt)(struct go7007 *go);
  99. int (*stream_start)(struct go7007 *go);
  100. int (*stream_stop)(struct go7007 *go);
  101. int (*send_firmware)(struct go7007 *go, u8 *data, int len);
  102. int (*send_command)(struct go7007 *go, unsigned int cmd, void *arg);
  103. };
  104. /* The video buffer size must be a multiple of PAGE_SIZE */
  105. #define GO7007_BUF_PAGES (128 * 1024 / PAGE_SIZE)
  106. #define GO7007_BUF_SIZE (GO7007_BUF_PAGES << PAGE_SHIFT)
  107. struct go7007_buffer {
  108. struct go7007 *go; /* Reverse reference for VMA ops */
  109. int index; /* Reverse reference for DQBUF */
  110. enum { BUF_STATE_IDLE, BUF_STATE_QUEUED, BUF_STATE_DONE } state;
  111. u32 seq;
  112. struct timeval timestamp;
  113. struct list_head stream;
  114. struct page *pages[GO7007_BUF_PAGES + 1]; /* extra for straddling */
  115. unsigned long user_addr;
  116. unsigned int page_count;
  117. unsigned int offset;
  118. unsigned int bytesused;
  119. unsigned int frame_offset;
  120. u32 modet_active;
  121. int mapped;
  122. };
  123. struct go7007_file {
  124. struct go7007 *go;
  125. struct mutex lock;
  126. int buf_count;
  127. struct go7007_buffer *bufs;
  128. };
  129. #define GO7007_FORMAT_MJPEG 0
  130. #define GO7007_FORMAT_MPEG4 1
  131. #define GO7007_FORMAT_MPEG1 2
  132. #define GO7007_FORMAT_MPEG2 3
  133. #define GO7007_FORMAT_H263 4
  134. #define GO7007_RATIO_1_1 0
  135. #define GO7007_RATIO_4_3 1
  136. #define GO7007_RATIO_16_9 2
  137. enum go7007_parser_state {
  138. STATE_DATA,
  139. STATE_00,
  140. STATE_00_00,
  141. STATE_00_00_01,
  142. STATE_FF,
  143. STATE_VBI_LEN_A,
  144. STATE_VBI_LEN_B,
  145. STATE_MODET_MAP,
  146. STATE_UNPARSED,
  147. };
  148. struct go7007 {
  149. struct device *dev;
  150. struct go7007_board_info *board_info;
  151. unsigned int board_id;
  152. int tuner_type;
  153. int channel_number; /* for multi-channel boards like Adlink PCI-MPG24 */
  154. char name[64];
  155. struct video_device *video_dev;
  156. struct v4l2_device v4l2_dev;
  157. int ref_count;
  158. enum { STATUS_INIT, STATUS_ONLINE, STATUS_SHUTDOWN } status;
  159. spinlock_t spinlock;
  160. struct mutex hw_lock;
  161. int streaming;
  162. int in_use;
  163. int audio_enabled;
  164. /* Video input */
  165. int input;
  166. enum { GO7007_STD_NTSC, GO7007_STD_PAL, GO7007_STD_OTHER } standard;
  167. int sensor_framerate;
  168. int width;
  169. int height;
  170. int encoder_h_offset;
  171. int encoder_v_offset;
  172. unsigned int encoder_h_halve:1;
  173. unsigned int encoder_v_halve:1;
  174. unsigned int encoder_subsample:1;
  175. /* Encoder config */
  176. int format;
  177. int bitrate;
  178. int fps_scale;
  179. int pali;
  180. int aspect_ratio;
  181. int gop_size;
  182. unsigned int ipb:1;
  183. unsigned int closed_gop:1;
  184. unsigned int repeat_seqhead:1;
  185. unsigned int seq_header_enable:1;
  186. unsigned int gop_header_enable:1;
  187. unsigned int dvd_mode:1;
  188. unsigned int interlace_coding:1;
  189. /* Motion detection */
  190. unsigned int modet_enable:1;
  191. struct {
  192. unsigned int enable:1;
  193. int pixel_threshold;
  194. int motion_threshold;
  195. int mb_threshold;
  196. } modet[4];
  197. unsigned char modet_map[1624];
  198. unsigned char active_map[216];
  199. /* Video streaming */
  200. struct go7007_buffer *active_buf;
  201. enum go7007_parser_state state;
  202. int parse_length;
  203. u16 modet_word;
  204. int seen_frame;
  205. u32 next_seq;
  206. struct list_head stream;
  207. wait_queue_head_t frame_waitq;
  208. /* Audio streaming */
  209. void (*audio_deliver)(struct go7007 *go, u8 *buf, int length);
  210. void *snd_context;
  211. /* I2C */
  212. int i2c_adapter_online;
  213. struct i2c_adapter i2c_adapter;
  214. /* HPI driver */
  215. struct go7007_hpi_ops *hpi_ops;
  216. void *hpi_context;
  217. int interrupt_available;
  218. wait_queue_head_t interrupt_waitq;
  219. unsigned short interrupt_value;
  220. unsigned short interrupt_data;
  221. };
  222. static inline struct go7007 *to_go7007(struct v4l2_device *v4l2_dev)
  223. {
  224. return container_of(v4l2_dev, struct go7007, v4l2_dev);
  225. }
  226. /* All of these must be called with the hpi_lock mutex held! */
  227. #define go7007_interface_reset(go) \
  228. ((go)->hpi_ops->interface_reset(go))
  229. #define go7007_write_interrupt(go, x, y) \
  230. ((go)->hpi_ops->write_interrupt)((go), (x), (y))
  231. #define go7007_stream_start(go) \
  232. ((go)->hpi_ops->stream_start(go))
  233. #define go7007_stream_stop(go) \
  234. ((go)->hpi_ops->stream_stop(go))
  235. #define go7007_send_firmware(go, x, y) \
  236. ((go)->hpi_ops->send_firmware)((go), (x), (y))
  237. #define go7007_write_addr(go, x, y) \
  238. ((go)->hpi_ops->write_interrupt)((go), (x)|0x8000, (y))
  239. /* go7007-driver.c */
  240. int go7007_read_addr(struct go7007 *go, u16 addr, u16 *data);
  241. int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data);
  242. int go7007_boot_encoder(struct go7007 *go, int init_i2c);
  243. int go7007_reset_encoder(struct go7007 *go);
  244. int go7007_register_encoder(struct go7007 *go);
  245. int go7007_start_encoder(struct go7007 *go);
  246. void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length);
  247. struct go7007 *go7007_alloc(struct go7007_board_info *board,
  248. struct device *dev);
  249. void go7007_remove(struct go7007 *go);
  250. /* go7007-fw.c */
  251. int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen);
  252. /* go7007-i2c.c */
  253. int go7007_i2c_init(struct go7007 *go);
  254. int go7007_i2c_remove(struct go7007 *go);
  255. /* go7007-v4l2.c */
  256. int go7007_v4l2_init(struct go7007 *go);
  257. void go7007_v4l2_remove(struct go7007 *go);
  258. /* snd-go7007.c */
  259. int go7007_snd_init(struct go7007 *go);
  260. int go7007_snd_remove(struct go7007 *go);