blob: 2cc32c51417342e732e5124a6aa4dc0977007d52 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __SAA7146_VV__
2#define __SAA7146_VV__
3
Mauro Carvalho Chehab5e87efa2006-06-05 10:26:32 -03004#include <media/v4l2-common.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -03005#include <media/v4l2-ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <media/saa7146.h>
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -03007#include <media/videobuf-dma-sg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9#define MAX_SAA7146_CAPTURE_BUFFERS 32 /* arbitrary */
10#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */
11
12#define WRITE_RPS0(x) do { \
13 dev->d_rps0.cpu_addr[ count++ ] = cpu_to_le32(x); \
14 } while (0);
15
16#define WRITE_RPS1(x) do { \
17 dev->d_rps1.cpu_addr[ count++ ] = cpu_to_le32(x); \
18 } while (0);
19
20struct saa7146_video_dma {
21 u32 base_odd;
22 u32 base_even;
23 u32 prot_addr;
24 u32 pitch;
25 u32 base_page;
26 u32 num_line_byte;
27};
28
29#define FORMAT_BYTE_SWAP 0x1
30#define FORMAT_IS_PLANAR 0x2
31
32struct saa7146_format {
33 char *name;
34 u32 pixelformat;
35 u32 trans;
36 u8 depth;
37 u8 flags;
38 u8 swap;
39};
40
41struct saa7146_standard
42{
43 char *name;
44 v4l2_std_id id;
45
46 int v_offset; /* number of lines of vertical offset before processing */
47 int v_field; /* number of lines in a field for HPS to process */
48
49 int h_offset; /* horizontal offset of processing window */
50 int h_pixels; /* number of horizontal pixels to process */
51
52 int v_max_out;
53 int h_max_out;
54};
55
56/* buffer for one video/vbi frame */
57struct saa7146_buf {
58 /* common v4l buffer stuff -- must be first */
59 struct videobuf_buffer vb;
60
61 /* saa7146 specific */
62 struct v4l2_pix_format *fmt;
63 int (*activate)(struct saa7146_dev *dev,
64 struct saa7146_buf *buf,
65 struct saa7146_buf *next);
66
67 /* page tables */
68 struct saa7146_pgtable pt[3];
69};
70
71struct saa7146_dmaqueue {
72 struct saa7146_dev *dev;
73 struct saa7146_buf *curr;
74 struct list_head queue;
75 struct timer_list timeout;
76};
77
78struct saa7146_overlay {
79 struct saa7146_fh *fh;
80 struct v4l2_window win;
81 struct v4l2_clip clips[16];
82 int nclips;
83};
84
85/* per open data */
86struct saa7146_fh {
87 struct saa7146_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 /* video capture */
90 struct videobuf_queue video_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 /* vbi capture */
93 struct videobuf_queue vbi_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 unsigned int resources; /* resource management for device open */
96};
97
98#define STATUS_OVERLAY 0x01
99#define STATUS_CAPTURE 0x02
100
101struct saa7146_vv
102{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 /* vbi capture */
Hans Verkuil9bb60192012-05-01 11:45:27 -0300104 struct saa7146_dmaqueue vbi_dmaq;
Hans Verkuilfca34692012-05-01 11:28:20 -0300105 struct v4l2_vbi_format vbi_fmt;
106 struct timer_list vbi_read_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 /* vbi workaround interrupt queue */
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800108 wait_queue_head_t vbi_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 int vbi_fieldcount;
110 struct saa7146_fh *vbi_streaming;
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 int video_status;
113 struct saa7146_fh *video_fh;
114
115 /* video overlay */
Hans Verkuil5da545a2012-05-01 11:06:44 -0300116 struct saa7146_overlay ov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 struct v4l2_framebuffer ov_fb;
118 struct saa7146_format *ov_fmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 struct saa7146_fh *ov_suspend;
120
121 /* video capture */
Hans Verkuil9bb60192012-05-01 11:45:27 -0300122 struct saa7146_dmaqueue video_dmaq;
Hans Verkuilfd74d6e2012-05-01 11:17:35 -0300123 struct v4l2_pix_format video_fmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 enum v4l2_field last_field;
125
126 /* common: fixme? shouldn't this be in saa7146_fh?
127 (this leads to a more complicated question: shall the driver
128 store the different settings (for example S_INPUT) for every open
129 and restore it appropriately, or should all settings be common for
130 all opens? currently, we do the latter, like all other
131 drivers do... */
132 struct saa7146_standard *standard;
133
134 int vflip;
135 int hflip;
136 int current_hps_source;
137 int current_hps_sync;
138
139 struct saa7146_dma d_clipping; /* pointer to clipping memory */
140
141 unsigned int resources; /* resource management for device */
142};
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/* flags */
145#define SAA7146_USE_PORT_B_FOR_VBI 0x2 /* use input port b for vbi hardware bug workaround */
146
147struct saa7146_ext_vv
148{
149 /* informations about the video capabilities of the device */
150 int inputs;
151 int audios;
152 u32 capabilities;
153 int flags;
154
155 /* additionally supported transmission standards */
156 struct saa7146_standard *stds;
157 int num_stds;
158 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
159
Hans Verkuilb9600742009-01-18 19:59:11 -0300160 /* the extension can override this */
161 struct v4l2_ioctl_ops ops;
162 /* pointer to the saa7146 core ops */
163 const struct v4l2_ioctl_ops *core_ops;
Oliver Endriss5b0fa4f2006-01-09 18:21:37 -0200164
Hans Verkuilbec43662008-12-30 06:58:20 -0300165 struct v4l2_file_operations vbi_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166};
167
168struct saa7146_use_ops {
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800169 void (*init)(struct saa7146_dev *, struct saa7146_vv *);
170 int(*open)(struct saa7146_dev *, struct file *);
171 void (*release)(struct saa7146_dev *, struct file *);
172 void (*irq_done)(struct saa7146_dev *, unsigned long status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
174};
175
176/* from saa7146_fops.c */
177int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev, char *name, int type);
178int saa7146_unregister_device(struct video_device **vid, struct saa7146_dev* dev);
179void saa7146_buffer_finish(struct saa7146_dev *dev, struct saa7146_dmaqueue *q, int state);
180void saa7146_buffer_next(struct saa7146_dev *dev, struct saa7146_dmaqueue *q,int vbi);
181int saa7146_buffer_queue(struct saa7146_dev *dev, struct saa7146_dmaqueue *q, struct saa7146_buf *buf);
182void saa7146_buffer_timeout(unsigned long data);
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300183void saa7146_dma_free(struct saa7146_dev* dev,struct videobuf_queue *q,
184 struct saa7146_buf *buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv);
187int saa7146_vv_release(struct saa7146_dev* dev);
188
189/* from saa7146_hlp.c */
190int saa7146_enable_overlay(struct saa7146_fh *fh);
191void saa7146_disable_overlay(struct saa7146_fh *fh);
192
193void saa7146_set_capture(struct saa7146_dev *dev, struct saa7146_buf *buf, struct saa7146_buf *next);
194void saa7146_write_out_dma(struct saa7146_dev* dev, int which, struct saa7146_video_dma* vdma) ;
195void saa7146_set_hps_source_and_sync(struct saa7146_dev *saa, int source, int sync);
196void saa7146_set_gpio(struct saa7146_dev *saa, u8 pin, u8 data);
197
198/* from saa7146_video.c */
Hans Verkuilb9600742009-01-18 19:59:11 -0300199extern const struct v4l2_ioctl_ops saa7146_video_ioctl_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200extern struct saa7146_use_ops saa7146_video_uops;
201int saa7146_start_preview(struct saa7146_fh *fh);
202int saa7146_stop_preview(struct saa7146_fh *fh);
Hans Verkuil069b7472008-12-30 07:04:34 -0300203long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg);
Hans Verkuil6e65ca92012-04-29 16:47:47 -0300204int saa7146_s_ctrl(struct v4l2_ctrl *ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206/* from saa7146_vbi.c */
207extern struct saa7146_use_ops saa7146_vbi_uops;
208
209/* resource management functions */
210int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit);
211void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits);
212
213#define RESOURCE_DMA1_HPS 0x1
214#define RESOURCE_DMA2_CLP 0x2
215#define RESOURCE_DMA3_BRS 0x4
216
217/* saa7146 source inputs */
218#define SAA7146_HPS_SOURCE_PORT_A 0x00
219#define SAA7146_HPS_SOURCE_PORT_B 0x01
220#define SAA7146_HPS_SOURCE_YPB_CPA 0x02
221#define SAA7146_HPS_SOURCE_YPA_CPB 0x03
222
223/* sync inputs */
224#define SAA7146_HPS_SYNC_PORT_A 0x00
225#define SAA7146_HPS_SYNC_PORT_B 0x01
226
227/* some memory sizes */
Oliver Endriss7a7cd192007-03-13 23:44:57 -0300228/* max. 16 clipping rectangles */
229#define SAA7146_CLIPPING_MEM (16 * 4 * sizeof(u32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231/* some defines for the various clipping-modes */
232#define SAA7146_CLIPPING_RECT 0x4
233#define SAA7146_CLIPPING_RECT_INVERTED 0x5
234#define SAA7146_CLIPPING_MASK 0x6
235#define SAA7146_CLIPPING_MASK_INVERTED 0x7
236
237/* output formats: each entry holds four informations */
238#define RGB08_COMPOSED 0x0217 /* composed is used in the sense of "not-planar" */
239/* this means: planar?=0, yuv2rgb-conversation-mode=2, dither=yes(=1), format-mode = 7 */
240#define RGB15_COMPOSED 0x0213
241#define RGB16_COMPOSED 0x0210
242#define RGB24_COMPOSED 0x0201
243#define RGB32_COMPOSED 0x0202
244
245#define Y8 0x0006
246#define YUV411_COMPOSED 0x0003
247#define YUV422_COMPOSED 0x0000
248/* this means: planar?=1, yuv2rgb-conversion-mode=0, dither=no(=0), format-mode = b */
249#define YUV411_DECOMPOSED 0x100b
250#define YUV422_DECOMPOSED 0x1009
251#define YUV420_DECOMPOSED 0x100a
252
253#define IS_PLANAR(x) (x & 0xf000)
254
255/* misc defines */
256#define SAA7146_NO_SWAP (0x0)
257#define SAA7146_TWO_BYTE_SWAP (0x1)
258#define SAA7146_FOUR_BYTE_SWAP (0x2)
259
260#endif