blob: 635805fb35e876e754bb02cc17770c8784453d48 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef __SAA7146_VV__
3#define __SAA7146_VV__
4
Mauro Carvalho Chehab5e87efa2006-06-05 10:26:32 -03005#include <media/v4l2-common.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -03006#include <media/v4l2-ioctl.h>
Hans Verkuil537fa492012-05-01 12:04:52 -03007#include <media/v4l2-fh.h>
Mauro Carvalho Chehabd647f0b2015-11-13 19:40:07 -02008#include <media/drv-intf/saa7146.h>
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -03009#include <media/videobuf-dma-sg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11#define MAX_SAA7146_CAPTURE_BUFFERS 32 /* arbitrary */
12#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */
13
14#define WRITE_RPS0(x) do { \
15 dev->d_rps0.cpu_addr[ count++ ] = cpu_to_le32(x); \
16 } while (0);
17
18#define WRITE_RPS1(x) do { \
19 dev->d_rps1.cpu_addr[ count++ ] = cpu_to_le32(x); \
20 } while (0);
21
22struct saa7146_video_dma {
23 u32 base_odd;
24 u32 base_even;
25 u32 prot_addr;
26 u32 pitch;
27 u32 base_page;
28 u32 num_line_byte;
29};
30
31#define FORMAT_BYTE_SWAP 0x1
32#define FORMAT_IS_PLANAR 0x2
33
34struct saa7146_format {
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 u32 pixelformat;
36 u32 trans;
37 u8 depth;
38 u8 flags;
39 u8 swap;
40};
41
42struct saa7146_standard
43{
44 char *name;
45 v4l2_std_id id;
46
47 int v_offset; /* number of lines of vertical offset before processing */
48 int v_field; /* number of lines in a field for HPS to process */
49
50 int h_offset; /* horizontal offset of processing window */
51 int h_pixels; /* number of horizontal pixels to process */
52
53 int v_max_out;
54 int h_max_out;
55};
56
57/* buffer for one video/vbi frame */
58struct saa7146_buf {
59 /* common v4l buffer stuff -- must be first */
60 struct videobuf_buffer vb;
61
62 /* saa7146 specific */
63 struct v4l2_pix_format *fmt;
64 int (*activate)(struct saa7146_dev *dev,
65 struct saa7146_buf *buf,
66 struct saa7146_buf *next);
67
68 /* page tables */
69 struct saa7146_pgtable pt[3];
70};
71
72struct saa7146_dmaqueue {
73 struct saa7146_dev *dev;
74 struct saa7146_buf *curr;
75 struct list_head queue;
76 struct timer_list timeout;
77};
78
79struct saa7146_overlay {
80 struct saa7146_fh *fh;
81 struct v4l2_window win;
82 struct v4l2_clip clips[16];
83 int nclips;
84};
85
86/* per open data */
87struct saa7146_fh {
Hans Verkuil537fa492012-05-01 12:04:52 -030088 /* Must be the first field! */
89 struct v4l2_fh fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 struct saa7146_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 /* video capture */
93 struct videobuf_queue video_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 /* vbi capture */
96 struct videobuf_queue vbi_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 unsigned int resources; /* resource management for device open */
99};
100
101#define STATUS_OVERLAY 0x01
102#define STATUS_CAPTURE 0x02
103
104struct saa7146_vv
105{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 /* vbi capture */
Hans Verkuil9bb60192012-05-01 11:45:27 -0300107 struct saa7146_dmaqueue vbi_dmaq;
Hans Verkuilfca34692012-05-01 11:28:20 -0300108 struct v4l2_vbi_format vbi_fmt;
109 struct timer_list vbi_read_timeout;
Kees Cook3e314912017-10-16 19:10:12 -0400110 struct file *vbi_read_timeout_file;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 /* vbi workaround interrupt queue */
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800112 wait_queue_head_t vbi_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 int vbi_fieldcount;
114 struct saa7146_fh *vbi_streaming;
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 int video_status;
117 struct saa7146_fh *video_fh;
118
119 /* video overlay */
Hans Verkuil5da545a2012-05-01 11:06:44 -0300120 struct saa7146_overlay ov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 struct v4l2_framebuffer ov_fb;
122 struct saa7146_format *ov_fmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 struct saa7146_fh *ov_suspend;
124
125 /* video capture */
Hans Verkuil9bb60192012-05-01 11:45:27 -0300126 struct saa7146_dmaqueue video_dmaq;
Hans Verkuilfd74d6e2012-05-01 11:17:35 -0300127 struct v4l2_pix_format video_fmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 enum v4l2_field last_field;
129
130 /* common: fixme? shouldn't this be in saa7146_fh?
131 (this leads to a more complicated question: shall the driver
132 store the different settings (for example S_INPUT) for every open
133 and restore it appropriately, or should all settings be common for
134 all opens? currently, we do the latter, like all other
135 drivers do... */
136 struct saa7146_standard *standard;
137
138 int vflip;
139 int hflip;
140 int current_hps_source;
141 int current_hps_sync;
142
143 struct saa7146_dma d_clipping; /* pointer to clipping memory */
144
145 unsigned int resources; /* resource management for device */
146};
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/* flags */
149#define SAA7146_USE_PORT_B_FOR_VBI 0x2 /* use input port b for vbi hardware bug workaround */
150
151struct saa7146_ext_vv
152{
Mauro Carvalho Chehabe907bf32019-02-18 14:29:06 -0500153 /* information about the video capabilities of the device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 int inputs;
155 int audios;
156 u32 capabilities;
157 int flags;
158
159 /* additionally supported transmission standards */
160 struct saa7146_standard *stds;
161 int num_stds;
162 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
163
Hans Verkuilb9600742009-01-18 19:59:11 -0300164 /* the extension can override this */
Hans Verkuilab49ae02012-05-01 12:57:57 -0300165 struct v4l2_ioctl_ops vid_ops;
166 struct v4l2_ioctl_ops vbi_ops;
Hans Verkuilb9600742009-01-18 19:59:11 -0300167 /* pointer to the saa7146 core ops */
168 const struct v4l2_ioctl_ops *core_ops;
Oliver Endriss5b0fa4f2006-01-09 18:21:37 -0200169
Hans Verkuilbec436612008-12-30 06:58:20 -0300170 struct v4l2_file_operations vbi_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171};
172
173struct saa7146_use_ops {
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800174 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
179};
180
181/* from saa7146_fops.c */
Hans Verkuil3ae863e2015-03-09 13:33:57 -0300182int 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184void 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);
Kees Cook12a83612017-10-16 19:10:42 -0400187void saa7146_buffer_timeout(struct timer_list *t);
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300188void saa7146_dma_free(struct saa7146_dev* dev,struct videobuf_queue *q,
189 struct saa7146_buf *buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv);
192int saa7146_vv_release(struct saa7146_dev* dev);
193
194/* from saa7146_hlp.c */
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/* from saa7146_video.c */
Hans Verkuilb9600742009-01-18 19:59:11 -0300204extern const struct v4l2_ioctl_ops saa7146_video_ioctl_ops;
Hans Verkuilab49ae02012-05-01 12:57:57 -0300205extern const struct v4l2_ioctl_ops saa7146_vbi_ioctl_ops;
Bhumika Goyalad627012017-09-13 16:37:50 -0300206extern const struct saa7146_use_ops saa7146_video_uops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207int saa7146_start_preview(struct saa7146_fh *fh);
208int saa7146_stop_preview(struct saa7146_fh *fh);
Hans Verkuil069b7472008-12-30 07:04:34 -0300209long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg);
Hans Verkuil6e65ca92012-04-29 16:47:47 -0300210int saa7146_s_ctrl(struct v4l2_ctrl *ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212/* from saa7146_vbi.c */
Bhumika Goyalad627012017-09-13 16:37:50 -0300213extern const struct saa7146_use_ops saa7146_vbi_uops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215/* resource management functions */
216int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit);
217void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits);
218
219#define RESOURCE_DMA1_HPS 0x1
220#define RESOURCE_DMA2_CLP 0x2
221#define RESOURCE_DMA3_BRS 0x4
222
223/* saa7146 source inputs */
224#define SAA7146_HPS_SOURCE_PORT_A 0x00
225#define SAA7146_HPS_SOURCE_PORT_B 0x01
226#define SAA7146_HPS_SOURCE_YPB_CPA 0x02
227#define SAA7146_HPS_SOURCE_YPA_CPB 0x03
228
229/* sync inputs */
230#define SAA7146_HPS_SYNC_PORT_A 0x00
231#define SAA7146_HPS_SYNC_PORT_B 0x01
232
233/* some memory sizes */
Oliver Endriss7a7cd192007-03-13 23:44:57 -0300234/* max. 16 clipping rectangles */
235#define SAA7146_CLIPPING_MEM (16 * 4 * sizeof(u32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237/* some defines for the various clipping-modes */
238#define SAA7146_CLIPPING_RECT 0x4
239#define SAA7146_CLIPPING_RECT_INVERTED 0x5
240#define SAA7146_CLIPPING_MASK 0x6
241#define SAA7146_CLIPPING_MASK_INVERTED 0x7
242
Mauro Carvalho Chehabe907bf32019-02-18 14:29:06 -0500243/* output formats: each entry holds four information */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define RGB08_COMPOSED 0x0217 /* composed is used in the sense of "not-planar" */
245/* this means: planar?=0, yuv2rgb-conversation-mode=2, dither=yes(=1), format-mode = 7 */
246#define RGB15_COMPOSED 0x0213
247#define RGB16_COMPOSED 0x0210
248#define RGB24_COMPOSED 0x0201
249#define RGB32_COMPOSED 0x0202
250
251#define Y8 0x0006
252#define YUV411_COMPOSED 0x0003
253#define YUV422_COMPOSED 0x0000
254/* this means: planar?=1, yuv2rgb-conversion-mode=0, dither=no(=0), format-mode = b */
255#define YUV411_DECOMPOSED 0x100b
256#define YUV422_DECOMPOSED 0x1009
257#define YUV420_DECOMPOSED 0x100a
258
259#define IS_PLANAR(x) (x & 0xf000)
260
261/* misc defines */
262#define SAA7146_NO_SWAP (0x0)
263#define SAA7146_TWO_BYTE_SWAP (0x1)
264#define SAA7146_FOUR_BYTE_SWAP (0x2)
265
266#endif