1#ifndef __SAA7146_VV__
2#define __SAA7146_VV__
3
4#include <media/v4l2-common.h>
5#include <media/v4l2-ioctl.h>
6#include <media/saa7146.h>
7#include <media/videobuf-dma-sg.h>
8
9#define MAX_SAA7146_CAPTURE_BUFFERS 32
10#define BUFFER_TIMEOUT (HZ/2)
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;
47 int v_field;
48
49 int h_offset;
50 int h_pixels;
51
52 int v_max_out;
53 int h_max_out;
54};
55
56
57struct saa7146_buf {
58
59 struct videobuf_buffer vb;
60
61
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
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
86struct saa7146_fh {
87 struct saa7146_dev *dev;
88
89 enum v4l2_buf_type type;
90
91
92 struct saa7146_overlay ov;
93
94
95 struct videobuf_queue video_q;
96 struct v4l2_pix_format video_fmt;
97
98
99 struct videobuf_queue vbi_q;
100 struct v4l2_vbi_format vbi_fmt;
101 struct timer_list vbi_read_timeout;
102
103 unsigned int resources;
104};
105
106#define STATUS_OVERLAY 0x01
107#define STATUS_CAPTURE 0x02
108
109struct saa7146_vv
110{
111
112 struct saa7146_dmaqueue vbi_q;
113
114 wait_queue_head_t vbi_wq;
115 int vbi_fieldcount;
116 struct saa7146_fh *vbi_streaming;
117
118 int video_status;
119 struct saa7146_fh *video_fh;
120
121
122 struct v4l2_framebuffer ov_fb;
123 struct saa7146_format *ov_fmt;
124 struct saa7146_overlay *ov_data;
125 struct saa7146_fh *ov_suspend;
126
127
128 struct saa7146_dmaqueue video_q;
129 enum v4l2_field last_field;
130
131
132
133
134
135
136
137 struct saa7146_standard *standard;
138
139 int vflip;
140 int hflip;
141 int current_hps_source;
142 int current_hps_sync;
143
144 struct saa7146_dma d_clipping;
145
146 unsigned int resources;
147};
148
149
150#define SAA7146_USE_PORT_B_FOR_VBI 0x2
151
152struct saa7146_ext_vv
153{
154
155 int inputs;
156 int audios;
157 u32 capabilities;
158 int flags;
159
160
161 struct saa7146_standard *stds;
162 int num_stds;
163 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
164
165
166 struct v4l2_ioctl_ops ops;
167
168 const struct v4l2_ioctl_ops *core_ops;
169
170 struct v4l2_file_operations vbi_fops;
171};
172
173struct saa7146_use_ops {
174 void (*init)(struct saa7146_dev *, struct saa7146_vv *);
175 int(*open)(struct saa7146_dev *, struct file *);
176 void (*release)(struct saa7146_dev *, struct file *);
177 void (*irq_done)(struct saa7146_dev *, unsigned long status);
178 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
179};
180
181
182int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev, char *name, int type);
183int saa7146_unregister_device(struct video_device **vid, struct saa7146_dev* dev);
184void saa7146_buffer_finish(struct saa7146_dev *dev, struct saa7146_dmaqueue *q, int state);
185void saa7146_buffer_next(struct saa7146_dev *dev, struct saa7146_dmaqueue *q,int vbi);
186int saa7146_buffer_queue(struct saa7146_dev *dev, struct saa7146_dmaqueue *q, struct saa7146_buf *buf);
187void saa7146_buffer_timeout(unsigned long data);
188void saa7146_dma_free(struct saa7146_dev* dev,struct videobuf_queue *q,
189 struct saa7146_buf *buf);
190
191int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv);
192int saa7146_vv_release(struct saa7146_dev* dev);
193
194
195int saa7146_enable_overlay(struct saa7146_fh *fh);
196void saa7146_disable_overlay(struct saa7146_fh *fh);
197
198void saa7146_set_capture(struct saa7146_dev *dev, struct saa7146_buf *buf, struct saa7146_buf *next);
199void saa7146_write_out_dma(struct saa7146_dev* dev, int which, struct saa7146_video_dma* vdma) ;
200void saa7146_set_hps_source_and_sync(struct saa7146_dev *saa, int source, int sync);
201void saa7146_set_gpio(struct saa7146_dev *saa, u8 pin, u8 data);
202
203
204extern const struct v4l2_ioctl_ops saa7146_video_ioctl_ops;
205extern struct saa7146_use_ops saa7146_video_uops;
206int saa7146_start_preview(struct saa7146_fh *fh);
207int saa7146_stop_preview(struct saa7146_fh *fh);
208long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg);
209
210
211extern struct saa7146_use_ops saa7146_vbi_uops;
212
213
214int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit);
215void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits);
216
217#define RESOURCE_DMA1_HPS 0x1
218#define RESOURCE_DMA2_CLP 0x2
219#define RESOURCE_DMA3_BRS 0x4
220
221
222#define SAA7146_HPS_SOURCE_PORT_A 0x00
223#define SAA7146_HPS_SOURCE_PORT_B 0x01
224#define SAA7146_HPS_SOURCE_YPB_CPA 0x02
225#define SAA7146_HPS_SOURCE_YPA_CPB 0x03
226
227
228#define SAA7146_HPS_SYNC_PORT_A 0x00
229#define SAA7146_HPS_SYNC_PORT_B 0x01
230
231
232
233#define SAA7146_CLIPPING_MEM (16 * 4 * sizeof(u32))
234
235
236#define SAA7146_CLIPPING_RECT 0x4
237#define SAA7146_CLIPPING_RECT_INVERTED 0x5
238#define SAA7146_CLIPPING_MASK 0x6
239#define SAA7146_CLIPPING_MASK_INVERTED 0x7
240
241
242#define RGB08_COMPOSED 0x0217
243
244#define RGB15_COMPOSED 0x0213
245#define RGB16_COMPOSED 0x0210
246#define RGB24_COMPOSED 0x0201
247#define RGB32_COMPOSED 0x0202
248
249#define Y8 0x0006
250#define YUV411_COMPOSED 0x0003
251#define YUV422_COMPOSED 0x0000
252
253#define YUV411_DECOMPOSED 0x100b
254#define YUV422_DECOMPOSED 0x1009
255#define YUV420_DECOMPOSED 0x100a
256
257#define IS_PLANAR(x) (x & 0xf000)
258
259
260#define SAA7146_NO_SWAP (0x0)
261#define SAA7146_TWO_BYTE_SWAP (0x1)
262#define SAA7146_FOUR_BYTE_SWAP (0x2)
263
264#endif
265