go7007-priv.h 8.6 KB

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