saa7146_vv.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #ifndef __SAA7146_VV__
  2. #define __SAA7146_VV__
  3. #include <media/v4l2-common.h>
  4. #include <media/v4l2-ioctl.h>
  5. #include <media/v4l2-fh.h>
  6. #include <media/saa7146.h>
  7. #include <media/videobuf-dma-sg.h>
  8. #define MAX_SAA7146_CAPTURE_BUFFERS 32 /* arbitrary */
  9. #define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */
  10. #define WRITE_RPS0(x) do { \
  11. dev->d_rps0.cpu_addr[ count++ ] = cpu_to_le32(x); \
  12. } while (0);
  13. #define WRITE_RPS1(x) do { \
  14. dev->d_rps1.cpu_addr[ count++ ] = cpu_to_le32(x); \
  15. } while (0);
  16. struct saa7146_video_dma {
  17. u32 base_odd;
  18. u32 base_even;
  19. u32 prot_addr;
  20. u32 pitch;
  21. u32 base_page;
  22. u32 num_line_byte;
  23. };
  24. #define FORMAT_BYTE_SWAP 0x1
  25. #define FORMAT_IS_PLANAR 0x2
  26. struct saa7146_format {
  27. char *name;
  28. u32 pixelformat;
  29. u32 trans;
  30. u8 depth;
  31. u8 flags;
  32. u8 swap;
  33. };
  34. struct saa7146_standard
  35. {
  36. char *name;
  37. v4l2_std_id id;
  38. int v_offset; /* number of lines of vertical offset before processing */
  39. int v_field; /* number of lines in a field for HPS to process */
  40. int h_offset; /* horizontal offset of processing window */
  41. int h_pixels; /* number of horizontal pixels to process */
  42. int v_max_out;
  43. int h_max_out;
  44. };
  45. /* buffer for one video/vbi frame */
  46. struct saa7146_buf {
  47. /* common v4l buffer stuff -- must be first */
  48. struct videobuf_buffer vb;
  49. /* saa7146 specific */
  50. struct v4l2_pix_format *fmt;
  51. int (*activate)(struct saa7146_dev *dev,
  52. struct saa7146_buf *buf,
  53. struct saa7146_buf *next);
  54. /* page tables */
  55. struct saa7146_pgtable pt[3];
  56. };
  57. struct saa7146_dmaqueue {
  58. struct saa7146_dev *dev;
  59. struct saa7146_buf *curr;
  60. struct list_head queue;
  61. struct timer_list timeout;
  62. };
  63. struct saa7146_overlay {
  64. struct saa7146_fh *fh;
  65. struct v4l2_window win;
  66. struct v4l2_clip clips[16];
  67. int nclips;
  68. };
  69. /* per open data */
  70. struct saa7146_fh {
  71. /* Must be the first field! */
  72. struct v4l2_fh fh;
  73. struct saa7146_dev *dev;
  74. /* video capture */
  75. struct videobuf_queue video_q;
  76. /* vbi capture */
  77. struct videobuf_queue vbi_q;
  78. unsigned int resources; /* resource management for device open */
  79. };
  80. #define STATUS_OVERLAY 0x01
  81. #define STATUS_CAPTURE 0x02
  82. struct saa7146_vv
  83. {
  84. /* vbi capture */
  85. struct saa7146_dmaqueue vbi_dmaq;
  86. struct v4l2_vbi_format vbi_fmt;
  87. struct timer_list vbi_read_timeout;
  88. /* vbi workaround interrupt queue */
  89. wait_queue_head_t vbi_wq;
  90. int vbi_fieldcount;
  91. struct saa7146_fh *vbi_streaming;
  92. int video_status;
  93. struct saa7146_fh *video_fh;
  94. /* video overlay */
  95. struct saa7146_overlay ov;
  96. struct v4l2_framebuffer ov_fb;
  97. struct saa7146_format *ov_fmt;
  98. struct saa7146_fh *ov_suspend;
  99. /* video capture */
  100. struct saa7146_dmaqueue video_dmaq;
  101. struct v4l2_pix_format video_fmt;
  102. enum v4l2_field last_field;
  103. /* common: fixme? shouldn't this be in saa7146_fh?
  104. (this leads to a more complicated question: shall the driver
  105. store the different settings (for example S_INPUT) for every open
  106. and restore it appropriately, or should all settings be common for
  107. all opens? currently, we do the latter, like all other
  108. drivers do... */
  109. struct saa7146_standard *standard;
  110. int vflip;
  111. int hflip;
  112. int current_hps_source;
  113. int current_hps_sync;
  114. struct saa7146_dma d_clipping; /* pointer to clipping memory */
  115. unsigned int resources; /* resource management for device */
  116. };
  117. /* flags */
  118. #define SAA7146_USE_PORT_B_FOR_VBI 0x2 /* use input port b for vbi hardware bug workaround */
  119. struct saa7146_ext_vv
  120. {
  121. /* informations about the video capabilities of the device */
  122. int inputs;
  123. int audios;
  124. u32 capabilities;
  125. int flags;
  126. /* additionally supported transmission standards */
  127. struct saa7146_standard *stds;
  128. int num_stds;
  129. int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
  130. /* the extension can override this */
  131. struct v4l2_ioctl_ops vid_ops;
  132. struct v4l2_ioctl_ops vbi_ops;
  133. /* pointer to the saa7146 core ops */
  134. const struct v4l2_ioctl_ops *core_ops;
  135. struct v4l2_file_operations vbi_fops;
  136. };
  137. struct saa7146_use_ops {
  138. void (*init)(struct saa7146_dev *, struct saa7146_vv *);
  139. int(*open)(struct saa7146_dev *, struct file *);
  140. void (*release)(struct saa7146_dev *, struct file *);
  141. void (*irq_done)(struct saa7146_dev *, unsigned long status);
  142. ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
  143. };
  144. /* from saa7146_fops.c */
  145. int saa7146_register_device(struct video_device *vid, struct saa7146_dev *dev, char *name, int type);
  146. int saa7146_unregister_device(struct video_device *vid, struct saa7146_dev *dev);
  147. void saa7146_buffer_finish(struct saa7146_dev *dev, struct saa7146_dmaqueue *q, int state);
  148. void saa7146_buffer_next(struct saa7146_dev *dev, struct saa7146_dmaqueue *q,int vbi);
  149. int saa7146_buffer_queue(struct saa7146_dev *dev, struct saa7146_dmaqueue *q, struct saa7146_buf *buf);
  150. void saa7146_buffer_timeout(unsigned long data);
  151. void saa7146_dma_free(struct saa7146_dev* dev,struct videobuf_queue *q,
  152. struct saa7146_buf *buf);
  153. int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv);
  154. int saa7146_vv_release(struct saa7146_dev* dev);
  155. /* from saa7146_hlp.c */
  156. int saa7146_enable_overlay(struct saa7146_fh *fh);
  157. void saa7146_disable_overlay(struct saa7146_fh *fh);
  158. void saa7146_set_capture(struct saa7146_dev *dev, struct saa7146_buf *buf, struct saa7146_buf *next);
  159. void saa7146_write_out_dma(struct saa7146_dev* dev, int which, struct saa7146_video_dma* vdma) ;
  160. void saa7146_set_hps_source_and_sync(struct saa7146_dev *saa, int source, int sync);
  161. void saa7146_set_gpio(struct saa7146_dev *saa, u8 pin, u8 data);
  162. /* from saa7146_video.c */
  163. extern const struct v4l2_ioctl_ops saa7146_video_ioctl_ops;
  164. extern const struct v4l2_ioctl_ops saa7146_vbi_ioctl_ops;
  165. extern struct saa7146_use_ops saa7146_video_uops;
  166. int saa7146_start_preview(struct saa7146_fh *fh);
  167. int saa7146_stop_preview(struct saa7146_fh *fh);
  168. long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg);
  169. int saa7146_s_ctrl(struct v4l2_ctrl *ctrl);
  170. /* from saa7146_vbi.c */
  171. extern struct saa7146_use_ops saa7146_vbi_uops;
  172. /* resource management functions */
  173. int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit);
  174. void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits);
  175. #define RESOURCE_DMA1_HPS 0x1
  176. #define RESOURCE_DMA2_CLP 0x2
  177. #define RESOURCE_DMA3_BRS 0x4
  178. /* saa7146 source inputs */
  179. #define SAA7146_HPS_SOURCE_PORT_A 0x00
  180. #define SAA7146_HPS_SOURCE_PORT_B 0x01
  181. #define SAA7146_HPS_SOURCE_YPB_CPA 0x02
  182. #define SAA7146_HPS_SOURCE_YPA_CPB 0x03
  183. /* sync inputs */
  184. #define SAA7146_HPS_SYNC_PORT_A 0x00
  185. #define SAA7146_HPS_SYNC_PORT_B 0x01
  186. /* some memory sizes */
  187. /* max. 16 clipping rectangles */
  188. #define SAA7146_CLIPPING_MEM (16 * 4 * sizeof(u32))
  189. /* some defines for the various clipping-modes */
  190. #define SAA7146_CLIPPING_RECT 0x4
  191. #define SAA7146_CLIPPING_RECT_INVERTED 0x5
  192. #define SAA7146_CLIPPING_MASK 0x6
  193. #define SAA7146_CLIPPING_MASK_INVERTED 0x7
  194. /* output formats: each entry holds four informations */
  195. #define RGB08_COMPOSED 0x0217 /* composed is used in the sense of "not-planar" */
  196. /* this means: planar?=0, yuv2rgb-conversation-mode=2, dither=yes(=1), format-mode = 7 */
  197. #define RGB15_COMPOSED 0x0213
  198. #define RGB16_COMPOSED 0x0210
  199. #define RGB24_COMPOSED 0x0201
  200. #define RGB32_COMPOSED 0x0202
  201. #define Y8 0x0006
  202. #define YUV411_COMPOSED 0x0003
  203. #define YUV422_COMPOSED 0x0000
  204. /* this means: planar?=1, yuv2rgb-conversion-mode=0, dither=no(=0), format-mode = b */
  205. #define YUV411_DECOMPOSED 0x100b
  206. #define YUV422_DECOMPOSED 0x1009
  207. #define YUV420_DECOMPOSED 0x100a
  208. #define IS_PLANAR(x) (x & 0xf000)
  209. /* misc defines */
  210. #define SAA7146_NO_SWAP (0x0)
  211. #define SAA7146_TWO_BYTE_SWAP (0x1)
  212. #define SAA7146_FOUR_BYTE_SWAP (0x2)
  213. #endif