saa7146_vv.h 7.4 KB

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