xref: /linux/drivers/media/test-drivers/vivid/vivid-core.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * vivid-core.h - core datastructures
4  *
5  * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6  */
7 
8 #ifndef _VIVID_CORE_H_
9 #define _VIVID_CORE_H_
10 
11 #include <linux/fb.h>
12 #include <linux/workqueue.h>
13 #include <media/cec.h>
14 #include <media/videobuf2-v4l2.h>
15 #include <media/v4l2-device.h>
16 #include <media/v4l2-dev.h>
17 #include <media/v4l2-ctrls.h>
18 #include <media/tpg/v4l2-tpg.h>
19 #include "vivid-rds-gen.h"
20 #include "vivid-vbi-gen.h"
21 
22 #define dprintk(dev, level, fmt, arg...) \
23 	v4l2_dbg(level, vivid_debug, &dev->v4l2_dev, fmt, ## arg)
24 
25 /* The maximum number of inputs */
26 #define MAX_INPUTS 16
27 /* The maximum number of outputs */
28 #define MAX_OUTPUTS 16
29 /* The maximum up or down scaling factor is 4 */
30 #define MAX_ZOOM  4
31 /* The maximum image width/height are set to 4K DMT */
32 #define MAX_WIDTH  4096
33 #define MAX_HEIGHT 2160
34 /* The minimum image width/height */
35 #define MIN_WIDTH  16
36 #define MIN_HEIGHT MIN_WIDTH
37 /* Pixel Array control divider */
38 #define PIXEL_ARRAY_DIV MIN_WIDTH
39 /* The data_offset of plane 0 for the multiplanar formats */
40 #define PLANE0_DATA_OFFSET 128
41 
42 /* The supported TV frequency range in MHz */
43 #define MIN_TV_FREQ (44U * 16U)
44 #define MAX_TV_FREQ (958U * 16U)
45 
46 /* The number of samples returned in every SDR buffer */
47 #define SDR_CAP_SAMPLES_PER_BUF 0x4000
48 
49 /* used by the threads to know when to resync internal counters */
50 #define JIFFIES_PER_DAY (3600U * 24U * HZ)
51 #define JIFFIES_RESYNC (JIFFIES_PER_DAY * (0xf0000000U / JIFFIES_PER_DAY))
52 
53 /*
54  * Maximum number of HDMI inputs allowed by vivid, due to limitations
55  * of the Physical Address in the EDID and used by CEC we stop at 15
56  * inputs and outputs.
57  */
58 #define MAX_HDMI_INPUTS 15
59 #define MAX_HDMI_OUTPUTS 15
60 
61 /* Maximum number of S-Video inputs allowed by vivid */
62 #define MAX_SVID_INPUTS 16
63 
64 /* The maximum number of items in a menu control */
65 #define MAX_MENU_ITEMS BITS_PER_LONG_LONG
66 
67 /* Number of fixed menu items in the 'Connected To' menu controls */
68 #define FIXED_MENU_ITEMS 2
69 
70 /* The maximum number of vivid devices */
71 #define VIVID_MAX_DEVS CONFIG_VIDEO_VIVID_MAX_DEVS
72 
73 extern const struct v4l2_rect vivid_min_rect;
74 extern const struct v4l2_rect vivid_max_rect;
75 extern unsigned vivid_debug;
76 
77 /*
78  * NULL-terminated string array for the HDMI 'Connected To' menu controls
79  * with the list of possible HDMI outputs.
80  *
81  * The first two items are fixed ("TPG" and "None").
82  */
83 extern char *vivid_ctrl_hdmi_to_output_strings[1 + MAX_MENU_ITEMS];
84 /* Menu control skip mask of all HDMI outputs that are in use */
85 extern u64 hdmi_to_output_menu_skip_mask;
86 /*
87  * Bitmask of which vivid instances need to update any connected
88  * HDMI outputs.
89  */
90 extern u64 hdmi_input_update_outputs_mask;
91 /*
92  * Spinlock for access to hdmi_to_output_menu_skip_mask and
93  * hdmi_input_update_outputs_mask.
94  */
95 extern spinlock_t hdmi_output_skip_mask_lock;
96 /*
97  * Workqueue that updates the menu controls whenever the HDMI menu skip mask
98  * changes.
99  */
100 extern struct workqueue_struct *update_hdmi_ctrls_workqueue;
101 
102 /*
103  * The HDMI menu control value (index in the menu list) maps to an HDMI
104  * output that is part of the given vivid_dev instance and has the given
105  * output index (as returned by VIDIOC_G_OUTPUT).
106  *
107  * NULL/0 if not available.
108  */
109 extern struct vivid_dev *vivid_ctrl_hdmi_to_output_instance[MAX_MENU_ITEMS];
110 extern unsigned int vivid_ctrl_hdmi_to_output_index[MAX_MENU_ITEMS];
111 
112 /*
113  * NULL-terminated string array for the S-Video 'Connected To' menu controls
114  * with the list of possible S-Video outputs.
115  *
116  * The first two items are fixed ("TPG" and "None").
117  */
118 extern char *vivid_ctrl_svid_to_output_strings[1 + MAX_MENU_ITEMS];
119 /* Menu control skip mask of all S-Video outputs that are in use */
120 extern u64 svid_to_output_menu_skip_mask;
121 /* Spinlock for access to svid_to_output_menu_skip_mask */
122 extern spinlock_t svid_output_skip_mask_lock;
123 /*
124  * Workqueue that updates the menu controls whenever the S-Video menu skip mask
125  * changes.
126  */
127 extern struct workqueue_struct *update_svid_ctrls_workqueue;
128 
129 /*
130  * The S-Video menu control value (index in the menu list) maps to an S-Video
131  * output that is part of the given vivid_dev instance and has the given
132  * output index (as returned by VIDIOC_G_OUTPUT).
133  *
134  * NULL/0 if not available.
135  */
136 extern struct vivid_dev *vivid_ctrl_svid_to_output_instance[MAX_MENU_ITEMS];
137 extern unsigned int vivid_ctrl_svid_to_output_index[MAX_MENU_ITEMS];
138 
139 extern struct vivid_dev *vivid_devs[VIVID_MAX_DEVS];
140 extern unsigned int n_devs;
141 
142 struct vivid_fmt {
143 	u32	fourcc;          /* v4l2 format id */
144 	enum	tgp_color_enc color_enc;
145 	bool	can_do_overlay;
146 	u8	vdownsampling[TPG_MAX_PLANES];
147 	u32	alpha_mask;
148 	u8	planes;
149 	u8	buffers;
150 	u32	data_offset[TPG_MAX_PLANES];
151 	u32	bit_depth[TPG_MAX_PLANES];
152 };
153 
154 extern struct vivid_fmt vivid_formats[];
155 
156 /* buffer for one video frame */
157 struct vivid_buffer {
158 	/* common v4l buffer stuff -- must be first */
159 	struct vb2_v4l2_buffer vb;
160 	struct list_head	list;
161 };
162 
163 enum vivid_input {
164 	WEBCAM,
165 	TV,
166 	SVID,
167 	HDMI,
168 };
169 
170 enum vivid_signal_mode {
171 	CURRENT_DV_TIMINGS,
172 	CURRENT_STD = CURRENT_DV_TIMINGS,
173 	NO_SIGNAL,
174 	NO_LOCK,
175 	OUT_OF_RANGE,
176 	SELECTED_DV_TIMINGS,
177 	SELECTED_STD = SELECTED_DV_TIMINGS,
178 	CYCLE_DV_TIMINGS,
179 	CYCLE_STD = CYCLE_DV_TIMINGS,
180 	CUSTOM_DV_TIMINGS,
181 };
182 
183 enum vivid_colorspace {
184 	VIVID_CS_170M,
185 	VIVID_CS_709,
186 	VIVID_CS_SRGB,
187 	VIVID_CS_OPRGB,
188 	VIVID_CS_2020,
189 	VIVID_CS_DCI_P3,
190 	VIVID_CS_240M,
191 	VIVID_CS_SYS_M,
192 	VIVID_CS_SYS_BG,
193 };
194 
195 #define VIVID_INVALID_SIGNAL(mode) \
196 	((mode) == NO_SIGNAL || (mode) == NO_LOCK || (mode) == OUT_OF_RANGE)
197 
198 struct vivid_cec_xfer {
199 	struct cec_adapter	*adap;
200 	u8			msg[CEC_MAX_MSG_SIZE];
201 	u32			len;
202 	u32			sft;
203 };
204 
205 struct vivid_dev {
206 	u8				inst;
207 	struct v4l2_device		v4l2_dev;
208 #ifdef CONFIG_MEDIA_CONTROLLER
209 	struct media_device		mdev;
210 	struct media_pad		vid_cap_pad;
211 	struct media_pad		vid_out_pad;
212 	struct media_pad		vbi_cap_pad;
213 	struct media_pad		vbi_out_pad;
214 	struct media_pad		sdr_cap_pad;
215 	struct media_pad		meta_cap_pad;
216 	struct media_pad		meta_out_pad;
217 	struct media_pad		touch_cap_pad;
218 #endif
219 	struct v4l2_ctrl_handler	ctrl_hdl_user_gen;
220 	struct v4l2_ctrl_handler	ctrl_hdl_user_vid;
221 	struct v4l2_ctrl_handler	ctrl_hdl_user_aud;
222 	struct v4l2_ctrl_handler	ctrl_hdl_streaming;
223 	struct v4l2_ctrl_handler	ctrl_hdl_sdtv_cap;
224 	struct v4l2_ctrl_handler	ctrl_hdl_loop_cap;
225 	struct v4l2_ctrl_handler	ctrl_hdl_fb;
226 	struct video_device		vid_cap_dev;
227 	struct v4l2_ctrl_handler	ctrl_hdl_vid_cap;
228 	struct video_device		vid_out_dev;
229 	struct v4l2_ctrl_handler	ctrl_hdl_vid_out;
230 	struct video_device		vbi_cap_dev;
231 	struct v4l2_ctrl_handler	ctrl_hdl_vbi_cap;
232 	struct video_device		vbi_out_dev;
233 	struct v4l2_ctrl_handler	ctrl_hdl_vbi_out;
234 	struct video_device		radio_rx_dev;
235 	struct v4l2_ctrl_handler	ctrl_hdl_radio_rx;
236 	struct video_device		radio_tx_dev;
237 	struct v4l2_ctrl_handler	ctrl_hdl_radio_tx;
238 	struct video_device		sdr_cap_dev;
239 	struct v4l2_ctrl_handler	ctrl_hdl_sdr_cap;
240 	struct video_device		meta_cap_dev;
241 	struct v4l2_ctrl_handler	ctrl_hdl_meta_cap;
242 	struct video_device		meta_out_dev;
243 	struct v4l2_ctrl_handler	ctrl_hdl_meta_out;
244 	struct video_device		touch_cap_dev;
245 	struct v4l2_ctrl_handler	ctrl_hdl_touch_cap;
246 
247 	spinlock_t			slock;
248 	struct mutex			mutex;
249 	struct work_struct		update_hdmi_ctrl_work;
250 	struct work_struct		update_svid_ctrl_work;
251 
252 	/* capabilities */
253 	u32				vid_cap_caps;
254 	u32				vid_out_caps;
255 	u32				vbi_cap_caps;
256 	u32				vbi_out_caps;
257 	u32				sdr_cap_caps;
258 	u32				radio_rx_caps;
259 	u32				radio_tx_caps;
260 	u32				meta_cap_caps;
261 	u32				meta_out_caps;
262 	u32				touch_cap_caps;
263 
264 	/* supported features */
265 	bool				multiplanar;
266 	u8				num_inputs;
267 	u8				num_hdmi_inputs;
268 	u8				num_svid_inputs;
269 	u8				input_type[MAX_INPUTS];
270 	u8				input_name_counter[MAX_INPUTS];
271 	u8				num_outputs;
272 	u8				num_hdmi_outputs;
273 	u8				output_type[MAX_OUTPUTS];
274 	u8				output_name_counter[MAX_OUTPUTS];
275 	bool				has_audio_inputs;
276 	bool				has_audio_outputs;
277 	bool				has_vid_cap;
278 	bool				has_vid_out;
279 	bool				has_vbi_cap;
280 	bool				has_raw_vbi_cap;
281 	bool				has_sliced_vbi_cap;
282 	bool				has_vbi_out;
283 	bool				has_raw_vbi_out;
284 	bool				has_sliced_vbi_out;
285 	bool				has_radio_rx;
286 	bool				has_radio_tx;
287 	bool				has_sdr_cap;
288 	bool				has_fb;
289 	bool				has_meta_cap;
290 	bool				has_meta_out;
291 	bool				has_tv_tuner;
292 	bool				has_touch_cap;
293 
294 	/* Output index (0-MAX_OUTPUTS) to vivid instance of connected input */
295 	struct vivid_dev		*output_to_input_instance[MAX_OUTPUTS];
296 	/* Output index (0-MAX_OUTPUTS) to input index (0-MAX_INPUTS) of connected input */
297 	u8				output_to_input_index[MAX_OUTPUTS];
298 	/* Output index (0-MAX_OUTPUTS) to HDMI or S-Video output index (0-MAX_HDMI/SVID_OUTPUTS) */
299 	u8				output_to_iface_index[MAX_OUTPUTS];
300 	/* ctrl_hdmi_to_output or ctrl_svid_to_output control value for each input */
301 	s32                             input_is_connected_to_output[MAX_INPUTS];
302 	/* HDMI index (0-MAX_HDMI_OUTPUTS) to output index (0-MAX_OUTPUTS) */
303 	u8				hdmi_index_to_output_index[MAX_HDMI_OUTPUTS];
304 	/* HDMI index (0-MAX_HDMI_INPUTS) to input index (0-MAX_INPUTS) */
305 	u8				hdmi_index_to_input_index[MAX_HDMI_INPUTS];
306 	/* S-Video index (0-MAX_SVID_INPUTS) to input index (0-MAX_INPUTS) */
307 	u8				svid_index_to_input_index[MAX_SVID_INPUTS];
308 
309 	/* controls */
310 	struct v4l2_ctrl		*brightness;
311 	struct v4l2_ctrl		*contrast;
312 	struct v4l2_ctrl		*saturation;
313 	struct v4l2_ctrl		*hue;
314 	struct {
315 		/* autogain/gain cluster */
316 		struct v4l2_ctrl	*autogain;
317 		struct v4l2_ctrl	*gain;
318 	};
319 	struct v4l2_ctrl		*volume;
320 	struct v4l2_ctrl		*mute;
321 	struct v4l2_ctrl		*alpha;
322 	struct v4l2_ctrl		*button;
323 	struct v4l2_ctrl		*boolean;
324 	struct v4l2_ctrl		*int32;
325 	struct v4l2_ctrl		*int64;
326 	struct v4l2_ctrl		*menu;
327 	struct v4l2_ctrl		*string;
328 	struct v4l2_ctrl		*bitmask;
329 	struct v4l2_ctrl		*int_menu;
330 	struct v4l2_ctrl		*ro_int32;
331 	struct v4l2_ctrl		*pixel_array;
332 	struct v4l2_ctrl		*test_pattern;
333 	struct v4l2_ctrl		*colorspace;
334 	struct v4l2_ctrl		*rgb_range_cap;
335 	struct v4l2_ctrl		*real_rgb_range_cap;
336 	struct {
337 		/* std_signal_mode/standard cluster */
338 		struct v4l2_ctrl	*ctrl_std_signal_mode;
339 		struct v4l2_ctrl	*ctrl_standard;
340 	};
341 	struct {
342 		/* dv_timings_signal_mode/timings cluster */
343 		struct v4l2_ctrl	*ctrl_dv_timings_signal_mode;
344 		struct v4l2_ctrl	*ctrl_dv_timings;
345 	};
346 	struct v4l2_ctrl		*ctrl_has_crop_cap;
347 	struct v4l2_ctrl		*ctrl_has_compose_cap;
348 	struct v4l2_ctrl		*ctrl_has_scaler_cap;
349 	struct v4l2_ctrl		*ctrl_has_crop_out;
350 	struct v4l2_ctrl		*ctrl_has_compose_out;
351 	struct v4l2_ctrl		*ctrl_has_scaler_out;
352 	struct v4l2_ctrl		*ctrl_tx_mode;
353 	struct v4l2_ctrl		*ctrl_tx_rgb_range;
354 	struct v4l2_ctrl		*ctrl_tx_edid_present;
355 	struct v4l2_ctrl		*ctrl_tx_hotplug;
356 	struct v4l2_ctrl		*ctrl_tx_rxsense;
357 
358 	struct v4l2_ctrl		*ctrl_rx_power_present;
359 
360 	struct v4l2_ctrl		*radio_tx_rds_pi;
361 	struct v4l2_ctrl		*radio_tx_rds_pty;
362 	struct v4l2_ctrl		*radio_tx_rds_mono_stereo;
363 	struct v4l2_ctrl		*radio_tx_rds_art_head;
364 	struct v4l2_ctrl		*radio_tx_rds_compressed;
365 	struct v4l2_ctrl		*radio_tx_rds_dyn_pty;
366 	struct v4l2_ctrl		*radio_tx_rds_ta;
367 	struct v4l2_ctrl		*radio_tx_rds_tp;
368 	struct v4l2_ctrl		*radio_tx_rds_ms;
369 	struct v4l2_ctrl		*radio_tx_rds_psname;
370 	struct v4l2_ctrl		*radio_tx_rds_radiotext;
371 
372 	struct v4l2_ctrl		*radio_rx_rds_pty;
373 	struct v4l2_ctrl		*radio_rx_rds_ta;
374 	struct v4l2_ctrl		*radio_rx_rds_tp;
375 	struct v4l2_ctrl		*radio_rx_rds_ms;
376 	struct v4l2_ctrl		*radio_rx_rds_psname;
377 	struct v4l2_ctrl		*radio_rx_rds_radiotext;
378 
379 	struct v4l2_ctrl                *ctrl_hdmi_to_output[MAX_HDMI_INPUTS];
380 	char				ctrl_hdmi_to_output_names[MAX_HDMI_INPUTS][32];
381 	struct v4l2_ctrl		*ctrl_svid_to_output[MAX_SVID_INPUTS];
382 	char				ctrl_svid_to_output_names[MAX_SVID_INPUTS][32];
383 
384 	unsigned			input_brightness[MAX_INPUTS];
385 	unsigned			osd_mode;
386 	unsigned			button_pressed;
387 	bool				sensor_hflip;
388 	bool				sensor_vflip;
389 	bool				hflip;
390 	bool				vflip;
391 	bool				vbi_cap_interlaced;
392 	bool				loop_video;
393 	bool				reduced_fps;
394 
395 	/* Framebuffer */
396 	unsigned long			video_pbase;
397 	void				*video_vbase;
398 	u32				video_buffer_size;
399 	int				display_width;
400 	int				display_height;
401 	int				display_byte_stride;
402 	int				bits_per_pixel;
403 	int				bytes_per_pixel;
404 	struct fb_info			fb_info;
405 	struct fb_var_screeninfo	fb_defined;
406 	struct fb_fix_screeninfo	fb_fix;
407 
408 	/* Error injection */
409 	bool				disconnect_error;
410 	bool				queue_setup_error;
411 	bool				buf_prepare_error;
412 	bool				start_streaming_error;
413 	bool				dqbuf_error;
414 	bool				req_validate_error;
415 	bool				seq_wrap;
416 	u64				time_wrap;
417 	u64				time_wrap_offset;
418 	unsigned			perc_dropped_buffers;
419 	enum vivid_signal_mode		std_signal_mode[MAX_INPUTS];
420 	unsigned int			query_std_last[MAX_INPUTS];
421 	v4l2_std_id			query_std[MAX_INPUTS];
422 	enum tpg_video_aspect		std_aspect_ratio[MAX_INPUTS];
423 
424 	enum vivid_signal_mode		dv_timings_signal_mode[MAX_INPUTS];
425 	char				**query_dv_timings_qmenu;
426 	char				*query_dv_timings_qmenu_strings;
427 	unsigned			query_dv_timings_size;
428 	unsigned int			query_dv_timings_last[MAX_INPUTS];
429 	unsigned int			query_dv_timings[MAX_INPUTS];
430 	enum tpg_video_aspect		dv_timings_aspect_ratio[MAX_INPUTS];
431 
432 	/* Input */
433 	unsigned			input;
434 	v4l2_std_id			std_cap[MAX_INPUTS];
435 	struct v4l2_dv_timings		dv_timings_cap[MAX_INPUTS];
436 	int				dv_timings_cap_sel[MAX_INPUTS];
437 	u32				service_set_cap;
438 	struct vivid_vbi_gen_data	vbi_gen;
439 	u8				*edid;
440 	unsigned			edid_blocks;
441 	unsigned			edid_max_blocks;
442 	unsigned			webcam_size_idx;
443 	unsigned			webcam_ival_idx;
444 	unsigned			tv_freq;
445 	unsigned			tv_audmode;
446 	unsigned			tv_field_cap;
447 	unsigned			tv_audio_input;
448 
449 	u32				power_present;
450 
451 	/* Output */
452 	unsigned			output;
453 	v4l2_std_id			std_out;
454 	struct v4l2_dv_timings		dv_timings_out;
455 	u32				colorspace_out;
456 	u32				ycbcr_enc_out;
457 	u32				hsv_enc_out;
458 	u32				quantization_out;
459 	u32				xfer_func_out;
460 	u32				service_set_out;
461 	unsigned			bytesperline_out[TPG_MAX_PLANES];
462 	unsigned			tv_field_out;
463 	unsigned			tv_audio_output;
464 	bool				vbi_out_have_wss;
465 	u8				vbi_out_wss[2];
466 	bool				vbi_out_have_cc[2];
467 	u8				vbi_out_cc[2][2];
468 	bool				dvi_d_out;
469 	u8				*scaled_line;
470 	u8				*blended_line;
471 	unsigned			cur_scaled_line;
472 
473 	/* Output Overlay */
474 	void				*fb_vbase_out;
475 	bool				overlay_out_enabled;
476 	int				overlay_out_top, overlay_out_left;
477 	unsigned			fbuf_out_flags;
478 	u32				chromakey_out;
479 	u8				global_alpha_out;
480 
481 	/* video capture */
482 	struct tpg_data			tpg;
483 	unsigned			ms_vid_cap;
484 	bool				must_blank[VIDEO_MAX_FRAME];
485 
486 	const struct vivid_fmt		*fmt_cap;
487 	struct v4l2_fract		timeperframe_vid_cap;
488 	enum v4l2_field			field_cap;
489 	struct v4l2_rect		src_rect;
490 	struct v4l2_rect		fmt_cap_rect;
491 	struct v4l2_rect		crop_cap;
492 	struct v4l2_rect		compose_cap;
493 	struct v4l2_rect		crop_bounds_cap;
494 	struct vb2_queue		vb_vid_cap_q;
495 	struct list_head		vid_cap_active;
496 	struct vb2_queue		vb_vbi_cap_q;
497 	struct list_head		vbi_cap_active;
498 	struct vb2_queue		vb_meta_cap_q;
499 	struct list_head		meta_cap_active;
500 	struct vb2_queue		vb_touch_cap_q;
501 	struct list_head		touch_cap_active;
502 
503 	/* thread for generating video capture stream */
504 	struct task_struct		*kthread_vid_cap;
505 	unsigned long			jiffies_vid_cap;
506 	u64				cap_stream_start;
507 	u64				cap_frame_period;
508 	u64				cap_frame_eof_offset;
509 	u32				cap_seq_offset;
510 	u32				cap_seq_count;
511 	bool				cap_seq_resync;
512 	u32				vid_cap_seq_start;
513 	u32				vid_cap_seq_count;
514 	bool				vid_cap_streaming;
515 	u32				vbi_cap_seq_start;
516 	u32				vbi_cap_seq_count;
517 	bool				vbi_cap_streaming;
518 	u32				meta_cap_seq_start;
519 	u32				meta_cap_seq_count;
520 	bool				meta_cap_streaming;
521 
522 	/* Touch capture */
523 	struct task_struct		*kthread_touch_cap;
524 	unsigned long			jiffies_touch_cap;
525 	u64				touch_cap_stream_start;
526 	u32				touch_cap_seq_offset;
527 	bool				touch_cap_seq_resync;
528 	u32				touch_cap_seq_start;
529 	u32				touch_cap_seq_count;
530 	u32				touch_cap_with_seq_wrap_count;
531 	bool				touch_cap_streaming;
532 	struct v4l2_fract		timeperframe_tch_cap;
533 	struct v4l2_pix_format		tch_format;
534 	int				tch_pat_random;
535 
536 	/* video output */
537 	const struct vivid_fmt		*fmt_out;
538 	struct v4l2_fract		timeperframe_vid_out;
539 	enum v4l2_field			field_out;
540 	struct v4l2_rect		sink_rect;
541 	struct v4l2_rect		fmt_out_rect;
542 	struct v4l2_rect		crop_out;
543 	struct v4l2_rect		compose_out;
544 	struct v4l2_rect		compose_bounds_out;
545 	struct vb2_queue		vb_vid_out_q;
546 	struct list_head		vid_out_active;
547 	struct vb2_queue		vb_vbi_out_q;
548 	struct list_head		vbi_out_active;
549 	struct vb2_queue		vb_meta_out_q;
550 	struct list_head		meta_out_active;
551 
552 	/* video loop precalculated rectangles */
553 
554 	/*
555 	 * Intersection between what the output side composes and the capture side
556 	 * crops. I.e., what actually needs to be copied from the output buffer to
557 	 * the capture buffer.
558 	 */
559 	struct v4l2_rect		loop_vid_copy;
560 	/* The part of the output buffer that (after scaling) corresponds to loop_vid_copy. */
561 	struct v4l2_rect		loop_vid_out;
562 	/* The part of the capture buffer that (after scaling) corresponds to loop_vid_copy. */
563 	struct v4l2_rect		loop_vid_cap;
564 	/*
565 	 * The intersection of the framebuffer, the overlay output window and
566 	 * loop_vid_copy. I.e., the part of the framebuffer that actually should be
567 	 * blended with the compose_out rectangle. This uses the framebuffer origin.
568 	 */
569 	struct v4l2_rect		loop_fb_copy;
570 	/* The same as loop_fb_copy but with compose_out origin. */
571 	struct v4l2_rect		loop_vid_overlay;
572 	/*
573 	 * The part of the capture buffer that (after scaling) corresponds
574 	 * to loop_vid_overlay.
575 	 */
576 	struct v4l2_rect		loop_vid_overlay_cap;
577 
578 	/* thread for generating video output stream */
579 	struct task_struct		*kthread_vid_out;
580 	unsigned long			jiffies_vid_out;
581 	u32				out_seq_offset;
582 	u32				out_seq_count;
583 	bool				out_seq_resync;
584 	u32				vid_out_seq_start;
585 	u32				vid_out_seq_count;
586 	bool				vid_out_streaming;
587 	u32				vbi_out_seq_start;
588 	u32				vbi_out_seq_count;
589 	bool				vbi_out_streaming;
590 	bool				stream_sliced_vbi_out;
591 	u32				meta_out_seq_start;
592 	u32				meta_out_seq_count;
593 	bool				meta_out_streaming;
594 
595 	/* SDR capture */
596 	struct vb2_queue		vb_sdr_cap_q;
597 	struct list_head		sdr_cap_active;
598 	u32				sdr_pixelformat; /* v4l2 format id */
599 	unsigned			sdr_buffersize;
600 	unsigned			sdr_adc_freq;
601 	unsigned			sdr_fm_freq;
602 	unsigned			sdr_fm_deviation;
603 	int				sdr_fixp_src_phase;
604 	int				sdr_fixp_mod_phase;
605 
606 	bool				tstamp_src_is_soe;
607 	bool				has_crop_cap;
608 	bool				has_compose_cap;
609 	bool				has_scaler_cap;
610 	bool				has_crop_out;
611 	bool				has_compose_out;
612 	bool				has_scaler_out;
613 
614 	/* thread for generating SDR stream */
615 	struct task_struct		*kthread_sdr_cap;
616 	unsigned long			jiffies_sdr_cap;
617 	u32				sdr_cap_seq_offset;
618 	u32				sdr_cap_seq_start;
619 	u32				sdr_cap_seq_count;
620 	u32				sdr_cap_with_seq_wrap_count;
621 	bool				sdr_cap_seq_resync;
622 
623 	/* RDS generator */
624 	struct vivid_rds_gen		rds_gen;
625 
626 	/* Radio receiver */
627 	unsigned			radio_rx_freq;
628 	unsigned			radio_rx_audmode;
629 	int				radio_rx_sig_qual;
630 	unsigned			radio_rx_hw_seek_mode;
631 	bool				radio_rx_hw_seek_prog_lim;
632 	bool				radio_rx_rds_controls;
633 	bool				radio_rx_rds_enabled;
634 	unsigned			radio_rx_rds_use_alternates;
635 	unsigned			radio_rx_rds_last_block;
636 	struct v4l2_fh			*radio_rx_rds_owner;
637 
638 	/* Radio transmitter */
639 	unsigned			radio_tx_freq;
640 	unsigned			radio_tx_subchans;
641 	bool				radio_tx_rds_controls;
642 	unsigned			radio_tx_rds_last_block;
643 	struct v4l2_fh			*radio_tx_rds_owner;
644 
645 	/* Shared between radio receiver and transmitter */
646 	bool				radio_rds_loop;
647 	ktime_t				radio_rds_init_time;
648 
649 	/* CEC */
650 	struct cec_adapter		*cec_rx_adap;
651 	struct cec_adapter		*cec_tx_adap[MAX_HDMI_OUTPUTS];
652 	struct task_struct		*kthread_cec;
653 	wait_queue_head_t		kthread_waitq_cec;
654 	struct vivid_cec_xfer		xfers[MAX_OUTPUTS];
655 	spinlock_t			cec_xfers_slock; /* read and write cec messages */
656 	u32				cec_sft; /* bus signal free time, in bit periods */
657 	u8				last_initiator;
658 
659 	/* CEC OSD String */
660 	char				osd[14];
661 	unsigned long			osd_jiffies;
662 
663 	bool				meta_pts;
664 	bool				meta_scr;
665 };
666 
vivid_is_webcam(const struct vivid_dev * dev)667 static inline bool vivid_is_webcam(const struct vivid_dev *dev)
668 {
669 	return dev->input_type[dev->input] == WEBCAM;
670 }
671 
vivid_is_tv_cap(const struct vivid_dev * dev)672 static inline bool vivid_is_tv_cap(const struct vivid_dev *dev)
673 {
674 	return dev->input_type[dev->input] == TV;
675 }
676 
vivid_is_svid_cap(const struct vivid_dev * dev)677 static inline bool vivid_is_svid_cap(const struct vivid_dev *dev)
678 {
679 	return dev->input_type[dev->input] == SVID;
680 }
681 
vivid_is_hdmi_cap(const struct vivid_dev * dev)682 static inline bool vivid_is_hdmi_cap(const struct vivid_dev *dev)
683 {
684 	return dev->input_type[dev->input] == HDMI;
685 }
686 
vivid_is_sdtv_cap(const struct vivid_dev * dev)687 static inline bool vivid_is_sdtv_cap(const struct vivid_dev *dev)
688 {
689 	return vivid_is_tv_cap(dev) || vivid_is_svid_cap(dev);
690 }
691 
vivid_is_svid_out(const struct vivid_dev * dev)692 static inline bool vivid_is_svid_out(const struct vivid_dev *dev)
693 {
694 	return dev->output_type[dev->output] == SVID;
695 }
696 
vivid_is_hdmi_out(const struct vivid_dev * dev)697 static inline bool vivid_is_hdmi_out(const struct vivid_dev *dev)
698 {
699 	return dev->output_type[dev->output] == HDMI;
700 }
701 
702 #endif
703