xref: /linux/include/media/drv-intf/saa7146_vv.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __SAA7146_VV__
3 #define __SAA7146_VV__
4 
5 #include <media/v4l2-common.h>
6 #include <media/v4l2-ioctl.h>
7 #include <media/v4l2-fh.h>
8 #include <media/drv-intf/saa7146.h>
9 #include <media/videobuf2-dma-sg.h>
10 
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 
22 struct	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 
34 struct saa7146_format {
35 	u32	pixelformat;
36 	u32	trans;
37 	u8	depth;
38 	u8	flags;
39 	u8	swap;
40 };
41 
42 struct 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 */
58 struct saa7146_buf {
59 	/* common v4l buffer stuff -- must be first */
60 	struct vb2_v4l2_buffer vb;
61 	struct list_head list;
62 
63 	/* saa7146 specific */
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 
72 struct saa7146_dmaqueue {
73 	struct saa7146_dev	*dev;
74 	struct saa7146_buf	*curr;
75 	struct list_head	queue;
76 	struct timer_list	timeout;
77 	struct vb2_queue	q;
78 };
79 
80 struct saa7146_vv
81 {
82 	/* vbi capture */
83 	struct saa7146_dmaqueue		vbi_dmaq;
84 	struct v4l2_vbi_format		vbi_fmt;
85 	struct timer_list		vbi_read_timeout;
86 	/* vbi workaround interrupt queue */
87 	wait_queue_head_t		vbi_wq;
88 
89 	/* video capture */
90 	struct saa7146_dmaqueue		video_dmaq;
91 	struct v4l2_pix_format		video_fmt;
92 	enum v4l2_field			last_field;
93 	u32				seqnr;
94 
95 	/* common: fixme? shouldn't this be in saa7146_fh?
96 	   (this leads to a more complicated question: shall the driver
97 	   store the different settings (for example S_INPUT) for every open
98 	   and restore it appropriately, or should all settings be common for
99 	   all opens? currently, we do the latter, like all other
100 	   drivers do... */
101 	struct saa7146_standard	*standard;
102 
103 	int	vflip;
104 	int	hflip;
105 	int	current_hps_source;
106 	int	current_hps_sync;
107 
108 	unsigned int resources; /* resource management for device */
109 };
110 
111 /* flags */
112 #define SAA7146_USE_PORT_B_FOR_VBI	0x2     /* use input port b for vbi hardware bug workaround */
113 
114 struct saa7146_ext_vv
115 {
116 	/* information about the video capabilities of the device */
117 	int	inputs;
118 	int	audios;
119 	u32	capabilities;
120 	int	flags;
121 
122 	/* additionally supported transmission standards */
123 	struct saa7146_standard *stds;
124 	int num_stds;
125 	int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
126 
127 	/* the extension can override this */
128 	struct v4l2_ioctl_ops vid_ops;
129 	struct v4l2_ioctl_ops vbi_ops;
130 	/* pointer to the saa7146 core ops */
131 	const struct v4l2_ioctl_ops *core_ops;
132 
133 	struct v4l2_file_operations vbi_fops;
134 };
135 
136 struct saa7146_use_ops  {
137 	void (*init)(struct saa7146_dev *, struct saa7146_vv *);
138 	void (*irq_done)(struct saa7146_dev *, unsigned long status);
139 };
140 
141 /* from saa7146_fops.c */
142 int saa7146_register_device(struct video_device *vid, struct saa7146_dev *dev, char *name, int type);
143 int saa7146_unregister_device(struct video_device *vid, struct saa7146_dev *dev);
144 void saa7146_buffer_finish(struct saa7146_dev *dev, struct saa7146_dmaqueue *q, int state);
145 void saa7146_buffer_next(struct saa7146_dev *dev, struct saa7146_dmaqueue *q,int vbi);
146 int saa7146_buffer_queue(struct saa7146_dev *dev, struct saa7146_dmaqueue *q, struct saa7146_buf *buf);
147 void saa7146_buffer_timeout(struct timer_list *t);
148 
149 int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv);
150 int saa7146_vv_release(struct saa7146_dev* dev);
151 
152 /* from saa7146_hlp.c */
153 void saa7146_set_capture(struct saa7146_dev *dev, struct saa7146_buf *buf, struct saa7146_buf *next);
154 void saa7146_write_out_dma(struct saa7146_dev* dev, int which, struct saa7146_video_dma* vdma) ;
155 void saa7146_set_hps_source_and_sync(struct saa7146_dev *saa, int source, int sync);
156 void saa7146_set_gpio(struct saa7146_dev *saa, u8 pin, u8 data);
157 
158 /* from saa7146_video.c */
159 extern const struct v4l2_ioctl_ops saa7146_video_ioctl_ops;
160 extern const struct v4l2_ioctl_ops saa7146_vbi_ioctl_ops;
161 extern const struct saa7146_use_ops saa7146_video_uops;
162 extern const struct vb2_ops video_qops;
163 long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg);
164 int saa7146_s_ctrl(struct v4l2_ctrl *ctrl);
165 
166 /* from saa7146_vbi.c */
167 extern const struct saa7146_use_ops saa7146_vbi_uops;
168 extern const struct vb2_ops vbi_qops;
169 
170 /* resource management functions */
171 int saa7146_res_get(struct saa7146_dev *dev, unsigned int bit);
172 void saa7146_res_free(struct saa7146_dev *dev, unsigned int bits);
173 
174 #define RESOURCE_DMA1_HPS	0x1
175 #define RESOURCE_DMA2_CLP	0x2
176 #define RESOURCE_DMA3_BRS	0x4
177 
178 /* saa7146 source inputs */
179 #define SAA7146_HPS_SOURCE_PORT_A	0x00
180 #define SAA7146_HPS_SOURCE_PORT_B	0x01
181 #define SAA7146_HPS_SOURCE_YPB_CPA	0x02
182 #define SAA7146_HPS_SOURCE_YPA_CPB	0x03
183 
184 /* sync inputs */
185 #define SAA7146_HPS_SYNC_PORT_A		0x00
186 #define SAA7146_HPS_SYNC_PORT_B		0x01
187 
188 /* some memory sizes */
189 /* max. 16 clipping rectangles */
190 #define SAA7146_CLIPPING_MEM	(16 * 4 * sizeof(u32))
191 
192 /* some defines for the various clipping-modes */
193 #define SAA7146_CLIPPING_RECT		0x4
194 #define SAA7146_CLIPPING_RECT_INVERTED	0x5
195 #define SAA7146_CLIPPING_MASK		0x6
196 #define SAA7146_CLIPPING_MASK_INVERTED	0x7
197 
198 /* output formats: each entry holds four information */
199 #define RGB08_COMPOSED	0x0217 /* composed is used in the sense of "not-planar" */
200 /* this means: planar?=0, yuv2rgb-conversation-mode=2, dither=yes(=1), format-mode = 7 */
201 #define RGB15_COMPOSED	0x0213
202 #define RGB16_COMPOSED	0x0210
203 #define RGB24_COMPOSED	0x0201
204 #define RGB32_COMPOSED	0x0202
205 
206 #define Y8			0x0006
207 #define YUV411_COMPOSED		0x0003
208 #define YUV422_COMPOSED		0x0000
209 /* this means: planar?=1, yuv2rgb-conversion-mode=0, dither=no(=0), format-mode = b */
210 #define YUV411_DECOMPOSED	0x100b
211 #define YUV422_DECOMPOSED	0x1009
212 #define YUV420_DECOMPOSED	0x100a
213 
214 #define IS_PLANAR(x) (x & 0xf000)
215 
216 /* misc defines */
217 #define SAA7146_NO_SWAP		(0x0)
218 #define SAA7146_TWO_BYTE_SWAP	(0x1)
219 #define SAA7146_FOUR_BYTE_SWAP	(0x2)
220 
221 #endif
222