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