2 * vivid-core.h - core datastructures
4 * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6 * This program is free software; you may redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
11 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
12 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
13 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
14 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
15 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 #ifndef _VIVID_CORE_H_
21 #define _VIVID_CORE_H_
24 #include <linux/workqueue.h>
25 #include <media/cec.h>
26 #include <media/videobuf2-v4l2.h>
27 #include <media/v4l2-device.h>
28 #include <media/v4l2-dev.h>
29 #include <media/v4l2-ctrls.h>
30 #include <media/tpg/v4l2-tpg.h>
31 #include "vivid-rds-gen.h"
32 #include "vivid-vbi-gen.h"
34 #define dprintk(dev, level, fmt, arg...) \
35 v4l2_dbg(level, vivid_debug, &dev->v4l2_dev, fmt, ## arg)
37 /* Maximum allowed frame rate
39 * vivid will allow setting timeperframe in [1/FPS_MAX - FPS_MAX/1] range.
41 * Ideally FPS_MAX should be infinity, i.e. practically UINT_MAX, but that
42 * might hit application errors when they manipulate these values.
44 * Besides, for tpf < 10ms image-generation logic should be changed, to avoid
45 * producing frames with equal content.
49 /* The maximum number of clip rectangles */
51 /* The maximum number of inputs */
53 /* The maximum number of outputs */
54 #define MAX_OUTPUTS 16
55 /* The maximum up or down scaling factor is 4 */
57 /* The maximum image width/height are set to 4K DMT */
58 #define MAX_WIDTH 4096
59 #define MAX_HEIGHT 2160
60 /* The minimum image width/height */
63 /* The data_offset of plane 0 for the multiplanar formats */
64 #define PLANE0_DATA_OFFSET 128
66 /* The supported TV frequency range in MHz */
67 #define MIN_TV_FREQ (44U * 16U)
68 #define MAX_TV_FREQ (958U * 16U)
70 /* The number of samples returned in every SDR buffer */
71 #define SDR_CAP_SAMPLES_PER_BUF 0x4000
73 /* used by the threads to know when to resync internal counters */
74 #define JIFFIES_PER_DAY (3600U * 24U * HZ)
75 #define JIFFIES_RESYNC (JIFFIES_PER_DAY * (0xf0000000U / JIFFIES_PER_DAY))
77 extern const struct v4l2_rect vivid_min_rect
;
78 extern const struct v4l2_rect vivid_max_rect
;
79 extern unsigned vivid_debug
;
82 u32 fourcc
; /* v4l2 format id */
83 enum tgp_color_enc color_enc
;
85 u8 vdownsampling
[TPG_MAX_PLANES
];
89 u32 data_offset
[TPG_MAX_PLANES
];
90 u32 bit_depth
[TPG_MAX_PLANES
];
93 extern struct vivid_fmt vivid_formats
[];
95 /* buffer for one video frame */
97 /* common v4l buffer stuff -- must be first */
98 struct vb2_v4l2_buffer vb
;
99 struct list_head list
;
109 enum vivid_signal_mode
{
111 CURRENT_STD
= CURRENT_DV_TIMINGS
,
116 SELECTED_STD
= SELECTED_DV_TIMINGS
,
118 CYCLE_STD
= CYCLE_DV_TIMINGS
,
122 enum vivid_colorspace
{
134 #define VIVID_INVALID_SIGNAL(mode) \
135 ((mode) == NO_SIGNAL || (mode) == NO_LOCK || (mode) == OUT_OF_RANGE)
137 struct vivid_cec_work
{
138 struct list_head list
;
139 struct delayed_work work
;
140 struct cec_adapter
*adap
;
141 struct vivid_dev
*dev
;
143 unsigned int timeout_ms
;
150 struct v4l2_device v4l2_dev
;
151 struct v4l2_ctrl_handler ctrl_hdl_user_gen
;
152 struct v4l2_ctrl_handler ctrl_hdl_user_vid
;
153 struct v4l2_ctrl_handler ctrl_hdl_user_aud
;
154 struct v4l2_ctrl_handler ctrl_hdl_streaming
;
155 struct v4l2_ctrl_handler ctrl_hdl_sdtv_cap
;
156 struct v4l2_ctrl_handler ctrl_hdl_loop_cap
;
157 struct v4l2_ctrl_handler ctrl_hdl_fb
;
158 struct video_device vid_cap_dev
;
159 struct v4l2_ctrl_handler ctrl_hdl_vid_cap
;
160 struct video_device vid_out_dev
;
161 struct v4l2_ctrl_handler ctrl_hdl_vid_out
;
162 struct video_device vbi_cap_dev
;
163 struct v4l2_ctrl_handler ctrl_hdl_vbi_cap
;
164 struct video_device vbi_out_dev
;
165 struct v4l2_ctrl_handler ctrl_hdl_vbi_out
;
166 struct video_device radio_rx_dev
;
167 struct v4l2_ctrl_handler ctrl_hdl_radio_rx
;
168 struct video_device radio_tx_dev
;
169 struct v4l2_ctrl_handler ctrl_hdl_radio_tx
;
170 struct video_device sdr_cap_dev
;
171 struct v4l2_ctrl_handler ctrl_hdl_sdr_cap
;
184 /* supported features */
187 u8 input_type
[MAX_INPUTS
];
188 u8 input_name_counter
[MAX_INPUTS
];
189 unsigned num_outputs
;
190 u8 output_type
[MAX_OUTPUTS
];
191 u8 output_name_counter
[MAX_OUTPUTS
];
192 bool has_audio_inputs
;
193 bool has_audio_outputs
;
197 bool has_raw_vbi_cap
;
198 bool has_sliced_vbi_cap
;
200 bool has_raw_vbi_out
;
201 bool has_sliced_vbi_out
;
210 struct v4l2_ctrl
*brightness
;
211 struct v4l2_ctrl
*contrast
;
212 struct v4l2_ctrl
*saturation
;
213 struct v4l2_ctrl
*hue
;
215 /* autogain/gain cluster */
216 struct v4l2_ctrl
*autogain
;
217 struct v4l2_ctrl
*gain
;
219 struct v4l2_ctrl
*volume
;
220 struct v4l2_ctrl
*mute
;
221 struct v4l2_ctrl
*alpha
;
222 struct v4l2_ctrl
*button
;
223 struct v4l2_ctrl
*boolean
;
224 struct v4l2_ctrl
*int32
;
225 struct v4l2_ctrl
*int64
;
226 struct v4l2_ctrl
*menu
;
227 struct v4l2_ctrl
*string
;
228 struct v4l2_ctrl
*bitmask
;
229 struct v4l2_ctrl
*int_menu
;
230 struct v4l2_ctrl
*test_pattern
;
231 struct v4l2_ctrl
*colorspace
;
232 struct v4l2_ctrl
*rgb_range_cap
;
233 struct v4l2_ctrl
*real_rgb_range_cap
;
235 /* std_signal_mode/standard cluster */
236 struct v4l2_ctrl
*ctrl_std_signal_mode
;
237 struct v4l2_ctrl
*ctrl_standard
;
240 /* dv_timings_signal_mode/timings cluster */
241 struct v4l2_ctrl
*ctrl_dv_timings_signal_mode
;
242 struct v4l2_ctrl
*ctrl_dv_timings
;
244 struct v4l2_ctrl
*ctrl_has_crop_cap
;
245 struct v4l2_ctrl
*ctrl_has_compose_cap
;
246 struct v4l2_ctrl
*ctrl_has_scaler_cap
;
247 struct v4l2_ctrl
*ctrl_has_crop_out
;
248 struct v4l2_ctrl
*ctrl_has_compose_out
;
249 struct v4l2_ctrl
*ctrl_has_scaler_out
;
250 struct v4l2_ctrl
*ctrl_tx_mode
;
251 struct v4l2_ctrl
*ctrl_tx_rgb_range
;
253 struct v4l2_ctrl
*radio_tx_rds_pi
;
254 struct v4l2_ctrl
*radio_tx_rds_pty
;
255 struct v4l2_ctrl
*radio_tx_rds_mono_stereo
;
256 struct v4l2_ctrl
*radio_tx_rds_art_head
;
257 struct v4l2_ctrl
*radio_tx_rds_compressed
;
258 struct v4l2_ctrl
*radio_tx_rds_dyn_pty
;
259 struct v4l2_ctrl
*radio_tx_rds_ta
;
260 struct v4l2_ctrl
*radio_tx_rds_tp
;
261 struct v4l2_ctrl
*radio_tx_rds_ms
;
262 struct v4l2_ctrl
*radio_tx_rds_psname
;
263 struct v4l2_ctrl
*radio_tx_rds_radiotext
;
265 struct v4l2_ctrl
*radio_rx_rds_pty
;
266 struct v4l2_ctrl
*radio_rx_rds_ta
;
267 struct v4l2_ctrl
*radio_rx_rds_tp
;
268 struct v4l2_ctrl
*radio_rx_rds_ms
;
269 struct v4l2_ctrl
*radio_rx_rds_psname
;
270 struct v4l2_ctrl
*radio_rx_rds_radiotext
;
272 unsigned input_brightness
[MAX_INPUTS
];
274 unsigned button_pressed
;
279 bool vbi_cap_interlaced
;
284 unsigned long video_pbase
;
286 u32 video_buffer_size
;
289 int display_byte_stride
;
292 struct fb_info fb_info
;
293 struct fb_var_screeninfo fb_defined
;
294 struct fb_fix_screeninfo fb_fix
;
296 /* Error injection */
297 bool queue_setup_error
;
298 bool buf_prepare_error
;
299 bool start_streaming_error
;
303 u64 time_wrap_offset
;
304 unsigned perc_dropped_buffers
;
305 enum vivid_signal_mode std_signal_mode
;
306 unsigned query_std_last
;
307 v4l2_std_id query_std
;
308 enum tpg_video_aspect std_aspect_ratio
;
310 enum vivid_signal_mode dv_timings_signal_mode
;
311 char **query_dv_timings_qmenu
;
312 unsigned query_dv_timings_size
;
313 unsigned query_dv_timings_last
;
314 unsigned query_dv_timings
;
315 enum tpg_video_aspect dv_timings_aspect_ratio
;
320 struct v4l2_dv_timings dv_timings_cap
;
322 struct vivid_vbi_gen_data vbi_gen
;
324 unsigned edid_blocks
;
325 unsigned edid_max_blocks
;
326 unsigned webcam_size_idx
;
327 unsigned webcam_ival_idx
;
330 unsigned tv_field_cap
;
331 unsigned tv_audio_input
;
333 /* Capture Overlay */
334 struct v4l2_framebuffer fb_cap
;
335 struct v4l2_fh
*overlay_cap_owner
;
337 int overlay_cap_top
, overlay_cap_left
;
338 enum v4l2_field overlay_cap_field
;
340 struct v4l2_clip clips_cap
[MAX_CLIPS
];
341 struct v4l2_clip try_clips_cap
[MAX_CLIPS
];
342 unsigned clipcount_cap
;
347 struct v4l2_dv_timings dv_timings_out
;
351 u32 quantization_out
;
354 unsigned bytesperline_out
[TPG_MAX_PLANES
];
355 unsigned tv_field_out
;
356 unsigned tv_audio_output
;
357 bool vbi_out_have_wss
;
359 bool vbi_out_have_cc
[2];
364 unsigned cur_scaled_line
;
368 bool overlay_out_enabled
;
369 int overlay_out_top
, overlay_out_left
;
371 struct v4l2_clip clips_out
[MAX_CLIPS
];
372 struct v4l2_clip try_clips_out
[MAX_CLIPS
];
373 unsigned clipcount_out
;
374 unsigned fbuf_out_flags
;
381 bool must_blank
[VIDEO_MAX_FRAME
];
383 const struct vivid_fmt
*fmt_cap
;
384 struct v4l2_fract timeperframe_vid_cap
;
385 enum v4l2_field field_cap
;
386 struct v4l2_rect src_rect
;
387 struct v4l2_rect fmt_cap_rect
;
388 struct v4l2_rect crop_cap
;
389 struct v4l2_rect compose_cap
;
390 struct v4l2_rect crop_bounds_cap
;
391 struct vb2_queue vb_vid_cap_q
;
392 struct list_head vid_cap_active
;
393 struct vb2_queue vb_vbi_cap_q
;
394 struct list_head vbi_cap_active
;
396 /* thread for generating video capture stream */
397 struct task_struct
*kthread_vid_cap
;
398 unsigned long jiffies_vid_cap
;
402 u32 vid_cap_seq_start
;
403 u32 vid_cap_seq_count
;
404 bool vid_cap_streaming
;
405 u32 vbi_cap_seq_start
;
406 u32 vbi_cap_seq_count
;
407 bool vbi_cap_streaming
;
408 bool stream_sliced_vbi_cap
;
411 const struct vivid_fmt
*fmt_out
;
412 struct v4l2_fract timeperframe_vid_out
;
413 enum v4l2_field field_out
;
414 struct v4l2_rect sink_rect
;
415 struct v4l2_rect fmt_out_rect
;
416 struct v4l2_rect crop_out
;
417 struct v4l2_rect compose_out
;
418 struct v4l2_rect compose_bounds_out
;
419 struct vb2_queue vb_vid_out_q
;
420 struct list_head vid_out_active
;
421 struct vb2_queue vb_vbi_out_q
;
422 struct list_head vbi_out_active
;
424 /* video loop precalculated rectangles */
427 * Intersection between what the output side composes and the capture side
428 * crops. I.e., what actually needs to be copied from the output buffer to
429 * the capture buffer.
431 struct v4l2_rect loop_vid_copy
;
432 /* The part of the output buffer that (after scaling) corresponds to loop_vid_copy. */
433 struct v4l2_rect loop_vid_out
;
434 /* The part of the capture buffer that (after scaling) corresponds to loop_vid_copy. */
435 struct v4l2_rect loop_vid_cap
;
437 * The intersection of the framebuffer, the overlay output window and
438 * loop_vid_copy. I.e., the part of the framebuffer that actually should be
439 * blended with the compose_out rectangle. This uses the framebuffer origin.
441 struct v4l2_rect loop_fb_copy
;
442 /* The same as loop_fb_copy but with compose_out origin. */
443 struct v4l2_rect loop_vid_overlay
;
445 * The part of the capture buffer that (after scaling) corresponds
446 * to loop_vid_overlay.
448 struct v4l2_rect loop_vid_overlay_cap
;
450 /* thread for generating video output stream */
451 struct task_struct
*kthread_vid_out
;
452 unsigned long jiffies_vid_out
;
456 u32 vid_out_seq_start
;
457 u32 vid_out_seq_count
;
458 bool vid_out_streaming
;
459 u32 vbi_out_seq_start
;
460 u32 vbi_out_seq_count
;
461 bool vbi_out_streaming
;
462 bool stream_sliced_vbi_out
;
465 struct vb2_queue vb_sdr_cap_q
;
466 struct list_head sdr_cap_active
;
467 u32 sdr_pixelformat
; /* v4l2 format id */
468 unsigned sdr_buffersize
;
469 unsigned sdr_adc_freq
;
470 unsigned sdr_fm_freq
;
471 unsigned sdr_fm_deviation
;
472 int sdr_fixp_src_phase
;
473 int sdr_fixp_mod_phase
;
475 bool tstamp_src_is_soe
;
477 bool has_compose_cap
;
480 bool has_compose_out
;
483 /* thread for generating SDR stream */
484 struct task_struct
*kthread_sdr_cap
;
485 unsigned long jiffies_sdr_cap
;
486 u32 sdr_cap_seq_offset
;
487 u32 sdr_cap_seq_count
;
488 bool sdr_cap_seq_resync
;
491 struct vivid_rds_gen rds_gen
;
494 unsigned radio_rx_freq
;
495 unsigned radio_rx_audmode
;
496 int radio_rx_sig_qual
;
497 unsigned radio_rx_hw_seek_mode
;
498 bool radio_rx_hw_seek_prog_lim
;
499 bool radio_rx_rds_controls
;
500 bool radio_rx_rds_enabled
;
501 unsigned radio_rx_rds_use_alternates
;
502 unsigned radio_rx_rds_last_block
;
503 struct v4l2_fh
*radio_rx_rds_owner
;
505 /* Radio transmitter */
506 unsigned radio_tx_freq
;
507 unsigned radio_tx_subchans
;
508 bool radio_tx_rds_controls
;
509 unsigned radio_tx_rds_last_block
;
510 struct v4l2_fh
*radio_tx_rds_owner
;
512 /* Shared between radio receiver and transmitter */
514 ktime_t radio_rds_init_time
;
517 struct cec_adapter
*cec_rx_adap
;
518 struct cec_adapter
*cec_tx_adap
[MAX_OUTPUTS
];
519 struct workqueue_struct
*cec_workqueue
;
520 spinlock_t cec_slock
;
521 struct list_head cec_work_list
;
522 unsigned int cec_xfer_time_jiffies
;
523 unsigned long cec_xfer_start_jiffies
;
524 u8 cec_output2bus_map
[MAX_OUTPUTS
];
528 unsigned long osd_jiffies
;
531 static inline bool vivid_is_webcam(const struct vivid_dev
*dev
)
533 return dev
->input_type
[dev
->input
] == WEBCAM
;
536 static inline bool vivid_is_tv_cap(const struct vivid_dev
*dev
)
538 return dev
->input_type
[dev
->input
] == TV
;
541 static inline bool vivid_is_svid_cap(const struct vivid_dev
*dev
)
543 return dev
->input_type
[dev
->input
] == SVID
;
546 static inline bool vivid_is_hdmi_cap(const struct vivid_dev
*dev
)
548 return dev
->input_type
[dev
->input
] == HDMI
;
551 static inline bool vivid_is_sdtv_cap(const struct vivid_dev
*dev
)
553 return vivid_is_tv_cap(dev
) || vivid_is_svid_cap(dev
);
556 static inline bool vivid_is_svid_out(const struct vivid_dev
*dev
)
558 return dev
->output_type
[dev
->output
] == SVID
;
561 static inline bool vivid_is_hdmi_out(const struct vivid_dev
*dev
)
563 return dev
->output_type
[dev
->output
] == HDMI
;