blob: 89c442eb884930b2f5f92de6e2da78ddd7845771 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <media/saa7146.h>
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -03006#include <media/videobuf-dma-sg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8#define MAX_SAA7146_CAPTURE_BUFFERS 32 /* arbitrary */
9#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */
10
11#define WRITE_RPS0(x) do { \
12 dev->d_rps0.cpu_addr[ count++ ] = cpu_to_le32(x); \
13 } while (0);
14
15#define WRITE_RPS1(x) do { \
16 dev->d_rps1.cpu_addr[ count++ ] = cpu_to_le32(x); \
17 } while (0);
18
19struct saa7146_video_dma {
20 u32 base_odd;
21 u32 base_even;
22 u32 prot_addr;
23 u32 pitch;
24 u32 base_page;
25 u32 num_line_byte;
26};
27
28#define FORMAT_BYTE_SWAP 0x1
29#define FORMAT_IS_PLANAR 0x2
30
31struct saa7146_format {
32 char *name;
33 u32 pixelformat;
34 u32 trans;
35 u8 depth;
36 u8 flags;
37 u8 swap;
38};
39
40struct saa7146_standard
41{
42 char *name;
43 v4l2_std_id id;
44
45 int v_offset; /* number of lines of vertical offset before processing */
46 int v_field; /* number of lines in a field for HPS to process */
47
48 int h_offset; /* horizontal offset of processing window */
49 int h_pixels; /* number of horizontal pixels to process */
50
51 int v_max_out;
52 int h_max_out;
53};
54
55/* buffer for one video/vbi frame */
56struct saa7146_buf {
57 /* common v4l buffer stuff -- must be first */
58 struct videobuf_buffer vb;
59
60 /* saa7146 specific */
61 struct v4l2_pix_format *fmt;
62 int (*activate)(struct saa7146_dev *dev,
63 struct saa7146_buf *buf,
64 struct saa7146_buf *next);
65
66 /* page tables */
67 struct saa7146_pgtable pt[3];
68};
69
70struct saa7146_dmaqueue {
71 struct saa7146_dev *dev;
72 struct saa7146_buf *curr;
73 struct list_head queue;
74 struct timer_list timeout;
75};
76
77struct saa7146_overlay {
78 struct saa7146_fh *fh;
79 struct v4l2_window win;
80 struct v4l2_clip clips[16];
81 int nclips;
82};
83
84/* per open data */
85struct saa7146_fh {
86 struct saa7146_dev *dev;
87 /* if this is a vbi or capture open */
88 enum v4l2_buf_type type;
89
90 /* video overlay */
91 struct saa7146_overlay ov;
92
93 /* video capture */
94 struct videobuf_queue video_q;
95 struct v4l2_pix_format video_fmt;
96
97 /* vbi capture */
98 struct videobuf_queue vbi_q;
99 struct v4l2_vbi_format vbi_fmt;
100 struct timer_list vbi_read_timeout;
101
102 unsigned int resources; /* resource management for device open */
103};
104
105#define STATUS_OVERLAY 0x01
106#define STATUS_CAPTURE 0x02
107
108struct saa7146_vv
109{
110 int vbi_minor;
111
112 /* vbi capture */
113 struct saa7146_dmaqueue vbi_q;
114 /* vbi workaround interrupt queue */
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800115 wait_queue_head_t vbi_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 int vbi_fieldcount;
117 struct saa7146_fh *vbi_streaming;
118
119 int video_minor;
120
121 int video_status;
122 struct saa7146_fh *video_fh;
123
124 /* video overlay */
125 struct v4l2_framebuffer ov_fb;
126 struct saa7146_format *ov_fmt;
127 struct saa7146_overlay *ov_data;
128 struct saa7146_fh *ov_suspend;
129
130 /* video capture */
131 struct saa7146_dmaqueue video_q;
132 enum v4l2_field last_field;
133
134 /* common: fixme? shouldn't this be in saa7146_fh?
135 (this leads to a more complicated question: shall the driver
136 store the different settings (for example S_INPUT) for every open
137 and restore it appropriately, or should all settings be common for
138 all opens? currently, we do the latter, like all other
139 drivers do... */
140 struct saa7146_standard *standard;
141
142 int vflip;
143 int hflip;
144 int current_hps_source;
145 int current_hps_sync;
146
147 struct saa7146_dma d_clipping; /* pointer to clipping memory */
148
149 unsigned int resources; /* resource management for device */
150};
151
152#define SAA7146_EXCLUSIVE 0x1
153#define SAA7146_BEFORE 0x2
154#define SAA7146_AFTER 0x4
155
156struct saa7146_extension_ioctls
157{
158 unsigned int cmd;
159 int flags;
160};
161
162/* flags */
163#define SAA7146_USE_PORT_B_FOR_VBI 0x2 /* use input port b for vbi hardware bug workaround */
164
165struct saa7146_ext_vv
166{
167 /* informations about the video capabilities of the device */
168 int inputs;
169 int audios;
170 u32 capabilities;
171 int flags;
172
173 /* additionally supported transmission standards */
174 struct saa7146_standard *stds;
175 int num_stds;
176 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
177
178 struct saa7146_extension_ioctls *ioctls;
179 int (*ioctl)(struct saa7146_fh*, unsigned int cmd, void *arg);
Oliver Endriss5b0fa4f2006-01-09 18:21:37 -0200180
181 struct file_operations vbi_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182};
183
184struct saa7146_use_ops {
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800185 void (*init)(struct saa7146_dev *, struct saa7146_vv *);
186 int(*open)(struct saa7146_dev *, struct file *);
187 void (*release)(struct saa7146_dev *, struct file *);
188 void (*irq_done)(struct saa7146_dev *, unsigned long status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
190};
191
192/* from saa7146_fops.c */
193int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev, char *name, int type);
194int saa7146_unregister_device(struct video_device **vid, struct saa7146_dev* dev);
195void saa7146_buffer_finish(struct saa7146_dev *dev, struct saa7146_dmaqueue *q, int state);
196void saa7146_buffer_next(struct saa7146_dev *dev, struct saa7146_dmaqueue *q,int vbi);
197int saa7146_buffer_queue(struct saa7146_dev *dev, struct saa7146_dmaqueue *q, struct saa7146_buf *buf);
198void saa7146_buffer_timeout(unsigned long data);
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300199void saa7146_dma_free(struct saa7146_dev* dev,struct videobuf_queue *q,
200 struct saa7146_buf *buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv);
203int saa7146_vv_release(struct saa7146_dev* dev);
204
205/* from saa7146_hlp.c */
206int saa7146_enable_overlay(struct saa7146_fh *fh);
207void saa7146_disable_overlay(struct saa7146_fh *fh);
208
209void saa7146_set_capture(struct saa7146_dev *dev, struct saa7146_buf *buf, struct saa7146_buf *next);
210void saa7146_write_out_dma(struct saa7146_dev* dev, int which, struct saa7146_video_dma* vdma) ;
211void saa7146_set_hps_source_and_sync(struct saa7146_dev *saa, int source, int sync);
212void saa7146_set_gpio(struct saa7146_dev *saa, u8 pin, u8 data);
213
214/* from saa7146_video.c */
215extern struct saa7146_use_ops saa7146_video_uops;
216int saa7146_start_preview(struct saa7146_fh *fh);
217int saa7146_stop_preview(struct saa7146_fh *fh);
Adrian Bunk32a1db42007-05-01 22:13:47 -0300218int saa7146_video_do_ioctl(struct inode *inode, struct file *file,
219 unsigned int cmd, void *arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221/* from saa7146_vbi.c */
222extern struct saa7146_use_ops saa7146_vbi_uops;
223
224/* resource management functions */
225int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit);
226void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits);
227
228#define RESOURCE_DMA1_HPS 0x1
229#define RESOURCE_DMA2_CLP 0x2
230#define RESOURCE_DMA3_BRS 0x4
231
232/* saa7146 source inputs */
233#define SAA7146_HPS_SOURCE_PORT_A 0x00
234#define SAA7146_HPS_SOURCE_PORT_B 0x01
235#define SAA7146_HPS_SOURCE_YPB_CPA 0x02
236#define SAA7146_HPS_SOURCE_YPA_CPB 0x03
237
238/* sync inputs */
239#define SAA7146_HPS_SYNC_PORT_A 0x00
240#define SAA7146_HPS_SYNC_PORT_B 0x01
241
242/* some memory sizes */
Oliver Endriss7a7cd192007-03-13 23:44:57 -0300243/* max. 16 clipping rectangles */
244#define SAA7146_CLIPPING_MEM (16 * 4 * sizeof(u32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246/* some defines for the various clipping-modes */
247#define SAA7146_CLIPPING_RECT 0x4
248#define SAA7146_CLIPPING_RECT_INVERTED 0x5
249#define SAA7146_CLIPPING_MASK 0x6
250#define SAA7146_CLIPPING_MASK_INVERTED 0x7
251
252/* output formats: each entry holds four informations */
253#define RGB08_COMPOSED 0x0217 /* composed is used in the sense of "not-planar" */
254/* this means: planar?=0, yuv2rgb-conversation-mode=2, dither=yes(=1), format-mode = 7 */
255#define RGB15_COMPOSED 0x0213
256#define RGB16_COMPOSED 0x0210
257#define RGB24_COMPOSED 0x0201
258#define RGB32_COMPOSED 0x0202
259
260#define Y8 0x0006
261#define YUV411_COMPOSED 0x0003
262#define YUV422_COMPOSED 0x0000
263/* this means: planar?=1, yuv2rgb-conversion-mode=0, dither=no(=0), format-mode = b */
264#define YUV411_DECOMPOSED 0x100b
265#define YUV422_DECOMPOSED 0x1009
266#define YUV420_DECOMPOSED 0x100a
267
268#define IS_PLANAR(x) (x & 0xf000)
269
270/* misc defines */
271#define SAA7146_NO_SWAP (0x0)
272#define SAA7146_TWO_BYTE_SWAP (0x1)
273#define SAA7146_FOUR_BYTE_SWAP (0x2)
274
275#endif