1
2
3
4
5
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
26#define MAX_CLIPS 16
27
28#define MAX_INPUTS 16
29
30#define MAX_OUTPUTS 16
31
32#define MAX_ZOOM 4
33
34#define MAX_WIDTH 4096
35#define MAX_HEIGHT 2160
36
37#define MIN_WIDTH 16
38#define MIN_HEIGHT 16
39
40#define PLANE0_DATA_OFFSET 128
41
42
43#define MIN_TV_FREQ (44U * 16U)
44#define MAX_TV_FREQ (958U * 16U)
45
46
47#define SDR_CAP_SAMPLES_PER_BUF 0x4000
48
49
50#define JIFFIES_PER_DAY (3600U * 24U * HZ)
51#define JIFFIES_RESYNC (JIFFIES_PER_DAY * (0xf0000000U / JIFFIES_PER_DAY))
52
53extern const struct v4l2_rect vivid_min_rect;
54extern const struct v4l2_rect vivid_max_rect;
55extern unsigned vivid_debug;
56
57struct vivid_fmt {
58 u32 fourcc;
59 enum tgp_color_enc color_enc;
60 bool can_do_overlay;
61 u8 vdownsampling[TPG_MAX_PLANES];
62 u32 alpha_mask;
63 u8 planes;
64 u8 buffers;
65 u32 data_offset[TPG_MAX_PLANES];
66 u32 bit_depth[TPG_MAX_PLANES];
67};
68
69extern struct vivid_fmt vivid_formats[];
70
71
72struct vivid_buffer {
73
74 struct vb2_v4l2_buffer vb;
75 struct list_head list;
76};
77
78enum vivid_input {
79 WEBCAM,
80 TV,
81 SVID,
82 HDMI,
83};
84
85enum vivid_signal_mode {
86 CURRENT_DV_TIMINGS,
87 CURRENT_STD = CURRENT_DV_TIMINGS,
88 NO_SIGNAL,
89 NO_LOCK,
90 OUT_OF_RANGE,
91 SELECTED_DV_TIMINGS,
92 SELECTED_STD = SELECTED_DV_TIMINGS,
93 CYCLE_DV_TIMINGS,
94 CYCLE_STD = CYCLE_DV_TIMINGS,
95 CUSTOM_DV_TIMINGS,
96};
97
98enum vivid_colorspace {
99 VIVID_CS_170M,
100 VIVID_CS_709,
101 VIVID_CS_SRGB,
102 VIVID_CS_OPRGB,
103 VIVID_CS_2020,
104 VIVID_CS_DCI_P3,
105 VIVID_CS_240M,
106 VIVID_CS_SYS_M,
107 VIVID_CS_SYS_BG,
108};
109
110#define VIVID_INVALID_SIGNAL(mode) \
111 ((mode) == NO_SIGNAL || (mode) == NO_LOCK || (mode) == OUT_OF_RANGE)
112
113struct vivid_cec_work {
114 struct list_head list;
115 struct delayed_work work;
116 struct cec_adapter *adap;
117 struct vivid_dev *dev;
118 unsigned int usecs;
119 unsigned int timeout_ms;
120 u8 tx_status;
121 struct cec_msg msg;
122};
123
124struct vivid_dev {
125 unsigned inst;
126 struct v4l2_device v4l2_dev;
127#ifdef CONFIG_MEDIA_CONTROLLER
128 struct media_device mdev;
129 struct media_pad vid_cap_pad;
130 struct media_pad vid_out_pad;
131 struct media_pad vbi_cap_pad;
132 struct media_pad vbi_out_pad;
133 struct media_pad sdr_cap_pad;
134 struct media_pad meta_cap_pad;
135 struct media_pad meta_out_pad;
136#endif
137 struct v4l2_ctrl_handler ctrl_hdl_user_gen;
138 struct v4l2_ctrl_handler ctrl_hdl_user_vid;
139 struct v4l2_ctrl_handler ctrl_hdl_user_aud;
140 struct v4l2_ctrl_handler ctrl_hdl_streaming;
141 struct v4l2_ctrl_handler ctrl_hdl_sdtv_cap;
142 struct v4l2_ctrl_handler ctrl_hdl_loop_cap;
143 struct v4l2_ctrl_handler ctrl_hdl_fb;
144 struct video_device vid_cap_dev;
145 struct v4l2_ctrl_handler ctrl_hdl_vid_cap;
146 struct video_device vid_out_dev;
147 struct v4l2_ctrl_handler ctrl_hdl_vid_out;
148 struct video_device vbi_cap_dev;
149 struct v4l2_ctrl_handler ctrl_hdl_vbi_cap;
150 struct video_device vbi_out_dev;
151 struct v4l2_ctrl_handler ctrl_hdl_vbi_out;
152 struct video_device radio_rx_dev;
153 struct v4l2_ctrl_handler ctrl_hdl_radio_rx;
154 struct video_device radio_tx_dev;
155 struct v4l2_ctrl_handler ctrl_hdl_radio_tx;
156 struct video_device sdr_cap_dev;
157 struct v4l2_ctrl_handler ctrl_hdl_sdr_cap;
158 struct video_device meta_cap_dev;
159 struct v4l2_ctrl_handler ctrl_hdl_meta_cap;
160 struct video_device meta_out_dev;
161 struct v4l2_ctrl_handler ctrl_hdl_meta_out;
162
163 spinlock_t slock;
164 struct mutex mutex;
165
166
167 u32 vid_cap_caps;
168 u32 vid_out_caps;
169 u32 vbi_cap_caps;
170 u32 vbi_out_caps;
171 u32 sdr_cap_caps;
172 u32 radio_rx_caps;
173 u32 radio_tx_caps;
174 u32 meta_cap_caps;
175 u32 meta_out_caps;
176
177
178 bool multiplanar;
179 unsigned num_inputs;
180 unsigned int num_hdmi_inputs;
181 u8 input_type[MAX_INPUTS];
182 u8 input_name_counter[MAX_INPUTS];
183 unsigned num_outputs;
184 unsigned int num_hdmi_outputs;
185 u8 output_type[MAX_OUTPUTS];
186 u8 output_name_counter[MAX_OUTPUTS];
187 bool has_audio_inputs;
188 bool has_audio_outputs;
189 bool has_vid_cap;
190 bool has_vid_out;
191 bool has_vbi_cap;
192 bool has_raw_vbi_cap;
193 bool has_sliced_vbi_cap;
194 bool has_vbi_out;
195 bool has_raw_vbi_out;
196 bool has_sliced_vbi_out;
197 bool has_radio_rx;
198 bool has_radio_tx;
199 bool has_sdr_cap;
200 bool has_fb;
201 bool has_meta_cap;
202 bool has_meta_out;
203 bool has_tv_tuner;
204
205 bool can_loop_video;
206
207
208 struct v4l2_ctrl *brightness;
209 struct v4l2_ctrl *contrast;
210 struct v4l2_ctrl *saturation;
211 struct v4l2_ctrl *hue;
212 struct {
213
214 struct v4l2_ctrl *autogain;
215 struct v4l2_ctrl *gain;
216 };
217 struct v4l2_ctrl *volume;
218 struct v4l2_ctrl *mute;
219 struct v4l2_ctrl *alpha;
220 struct v4l2_ctrl *button;
221 struct v4l2_ctrl *boolean;
222 struct v4l2_ctrl *int32;
223 struct v4l2_ctrl *int64;
224 struct v4l2_ctrl *menu;
225 struct v4l2_ctrl *string;
226 struct v4l2_ctrl *bitmask;
227 struct v4l2_ctrl *int_menu;
228 struct v4l2_ctrl *test_pattern;
229 struct v4l2_ctrl *colorspace;
230 struct v4l2_ctrl *rgb_range_cap;
231 struct v4l2_ctrl *real_rgb_range_cap;
232 struct {
233
234 struct v4l2_ctrl *ctrl_std_signal_mode;
235 struct v4l2_ctrl *ctrl_standard;
236 };
237 struct {
238
239 struct v4l2_ctrl *ctrl_dv_timings_signal_mode;
240 struct v4l2_ctrl *ctrl_dv_timings;
241 };
242 struct v4l2_ctrl *ctrl_display_present;
243 struct v4l2_ctrl *ctrl_has_crop_cap;
244 struct v4l2_ctrl *ctrl_has_compose_cap;
245 struct v4l2_ctrl *ctrl_has_scaler_cap;
246 struct v4l2_ctrl *ctrl_has_crop_out;
247 struct v4l2_ctrl *ctrl_has_compose_out;
248 struct v4l2_ctrl *ctrl_has_scaler_out;
249 struct v4l2_ctrl *ctrl_tx_mode;
250 struct v4l2_ctrl *ctrl_tx_rgb_range;
251 struct v4l2_ctrl *ctrl_tx_edid_present;
252 struct v4l2_ctrl *ctrl_tx_hotplug;
253 struct v4l2_ctrl *ctrl_tx_rxsense;
254
255 struct v4l2_ctrl *ctrl_rx_power_present;
256
257 struct v4l2_ctrl *radio_tx_rds_pi;
258 struct v4l2_ctrl *radio_tx_rds_pty;
259 struct v4l2_ctrl *radio_tx_rds_mono_stereo;
260 struct v4l2_ctrl *radio_tx_rds_art_head;
261 struct v4l2_ctrl *radio_tx_rds_compressed;
262 struct v4l2_ctrl *radio_tx_rds_dyn_pty;
263 struct v4l2_ctrl *radio_tx_rds_ta;
264 struct v4l2_ctrl *radio_tx_rds_tp;
265 struct v4l2_ctrl *radio_tx_rds_ms;
266 struct v4l2_ctrl *radio_tx_rds_psname;
267 struct v4l2_ctrl *radio_tx_rds_radiotext;
268
269 struct v4l2_ctrl *radio_rx_rds_pty;
270 struct v4l2_ctrl *radio_rx_rds_ta;
271 struct v4l2_ctrl *radio_rx_rds_tp;
272 struct v4l2_ctrl *radio_rx_rds_ms;
273 struct v4l2_ctrl *radio_rx_rds_psname;
274 struct v4l2_ctrl *radio_rx_rds_radiotext;
275
276 unsigned input_brightness[MAX_INPUTS];
277 unsigned osd_mode;
278 unsigned button_pressed;
279 bool sensor_hflip;
280 bool sensor_vflip;
281 bool hflip;
282 bool vflip;
283 bool vbi_cap_interlaced;
284 bool loop_video;
285 bool reduced_fps;
286
287
288 unsigned long video_pbase;
289 void *video_vbase;
290 u32 video_buffer_size;
291 int display_width;
292 int display_height;
293 int display_byte_stride;
294 int bits_per_pixel;
295 int bytes_per_pixel;
296 struct fb_info fb_info;
297 struct fb_var_screeninfo fb_defined;
298 struct fb_fix_screeninfo fb_fix;
299
300
301 bool queue_setup_error;
302 bool buf_prepare_error;
303 bool start_streaming_error;
304 bool dqbuf_error;
305 bool req_validate_error;
306 bool seq_wrap;
307 bool time_wrap;
308 u64 time_wrap_offset;
309 unsigned perc_dropped_buffers;
310 enum vivid_signal_mode std_signal_mode[MAX_INPUTS];
311 unsigned int query_std_last[MAX_INPUTS];
312 v4l2_std_id query_std[MAX_INPUTS];
313 enum tpg_video_aspect std_aspect_ratio[MAX_INPUTS];
314
315 enum vivid_signal_mode dv_timings_signal_mode[MAX_INPUTS];
316 char **query_dv_timings_qmenu;
317 char *query_dv_timings_qmenu_strings;
318 unsigned query_dv_timings_size;
319 unsigned int query_dv_timings_last[MAX_INPUTS];
320 unsigned int query_dv_timings[MAX_INPUTS];
321 enum tpg_video_aspect dv_timings_aspect_ratio[MAX_INPUTS];
322
323
324 unsigned input;
325 v4l2_std_id std_cap[MAX_INPUTS];
326 struct v4l2_dv_timings dv_timings_cap[MAX_INPUTS];
327 int dv_timings_cap_sel[MAX_INPUTS];
328 u32 service_set_cap;
329 struct vivid_vbi_gen_data vbi_gen;
330 u8 *edid;
331 unsigned edid_blocks;
332 unsigned edid_max_blocks;
333 unsigned webcam_size_idx;
334 unsigned webcam_ival_idx;
335 unsigned tv_freq;
336 unsigned tv_audmode;
337 unsigned tv_field_cap;
338 unsigned tv_audio_input;
339
340 u32 power_present;
341
342
343 struct v4l2_framebuffer fb_cap;
344 struct v4l2_fh *overlay_cap_owner;
345 void *fb_vbase_cap;
346 int overlay_cap_top, overlay_cap_left;
347 enum v4l2_field overlay_cap_field;
348 void *bitmap_cap;
349 struct v4l2_clip clips_cap[MAX_CLIPS];
350 struct v4l2_clip try_clips_cap[MAX_CLIPS];
351 unsigned clipcount_cap;
352
353
354 unsigned output;
355 v4l2_std_id std_out;
356 struct v4l2_dv_timings dv_timings_out;
357 u32 colorspace_out;
358 u32 ycbcr_enc_out;
359 u32 hsv_enc_out;
360 u32 quantization_out;
361 u32 xfer_func_out;
362 u32 service_set_out;
363 unsigned bytesperline_out[TPG_MAX_PLANES];
364 unsigned tv_field_out;
365 unsigned tv_audio_output;
366 bool vbi_out_have_wss;
367 u8 vbi_out_wss[2];
368 bool vbi_out_have_cc[2];
369 u8 vbi_out_cc[2][2];
370 bool dvi_d_out;
371 u8 *scaled_line;
372 u8 *blended_line;
373 unsigned cur_scaled_line;
374 bool display_present[MAX_OUTPUTS];
375
376
377 void *fb_vbase_out;
378 bool overlay_out_enabled;
379 int overlay_out_top, overlay_out_left;
380 void *bitmap_out;
381 struct v4l2_clip clips_out[MAX_CLIPS];
382 struct v4l2_clip try_clips_out[MAX_CLIPS];
383 unsigned clipcount_out;
384 unsigned fbuf_out_flags;
385 u32 chromakey_out;
386 u8 global_alpha_out;
387
388
389 struct tpg_data tpg;
390 unsigned ms_vid_cap;
391 bool must_blank[VIDEO_MAX_FRAME];
392
393 const struct vivid_fmt *fmt_cap;
394 struct v4l2_fract timeperframe_vid_cap;
395 enum v4l2_field field_cap;
396 struct v4l2_rect src_rect;
397 struct v4l2_rect fmt_cap_rect;
398 struct v4l2_rect crop_cap;
399 struct v4l2_rect compose_cap;
400 struct v4l2_rect crop_bounds_cap;
401 struct vb2_queue vb_vid_cap_q;
402 struct list_head vid_cap_active;
403 struct vb2_queue vb_vbi_cap_q;
404 struct list_head vbi_cap_active;
405 struct vb2_queue vb_meta_cap_q;
406 struct list_head meta_cap_active;
407
408
409 struct task_struct *kthread_vid_cap;
410 unsigned long jiffies_vid_cap;
411 u64 cap_stream_start;
412 u64 cap_frame_period;
413 u64 cap_frame_eof_offset;
414 u32 cap_seq_offset;
415 u32 cap_seq_count;
416 bool cap_seq_resync;
417 u32 vid_cap_seq_start;
418 u32 vid_cap_seq_count;
419 bool vid_cap_streaming;
420 u32 vbi_cap_seq_start;
421 u32 vbi_cap_seq_count;
422 bool vbi_cap_streaming;
423 bool stream_sliced_vbi_cap;
424 u32 meta_cap_seq_start;
425 u32 meta_cap_seq_count;
426 bool meta_cap_streaming;
427
428
429 const struct vivid_fmt *fmt_out;
430 struct v4l2_fract timeperframe_vid_out;
431 enum v4l2_field field_out;
432 struct v4l2_rect sink_rect;
433 struct v4l2_rect fmt_out_rect;
434 struct v4l2_rect crop_out;
435 struct v4l2_rect compose_out;
436 struct v4l2_rect compose_bounds_out;
437 struct vb2_queue vb_vid_out_q;
438 struct list_head vid_out_active;
439 struct vb2_queue vb_vbi_out_q;
440 struct list_head vbi_out_active;
441 struct vb2_queue vb_meta_out_q;
442 struct list_head meta_out_active;
443
444
445
446
447
448
449
450
451 struct v4l2_rect loop_vid_copy;
452
453 struct v4l2_rect loop_vid_out;
454
455 struct v4l2_rect loop_vid_cap;
456
457
458
459
460
461 struct v4l2_rect loop_fb_copy;
462
463 struct v4l2_rect loop_vid_overlay;
464
465
466
467
468 struct v4l2_rect loop_vid_overlay_cap;
469
470
471 struct task_struct *kthread_vid_out;
472 unsigned long jiffies_vid_out;
473 u32 out_seq_offset;
474 u32 out_seq_count;
475 bool out_seq_resync;
476 u32 vid_out_seq_start;
477 u32 vid_out_seq_count;
478 bool vid_out_streaming;
479 u32 vbi_out_seq_start;
480 u32 vbi_out_seq_count;
481 bool vbi_out_streaming;
482 bool stream_sliced_vbi_out;
483 u32 meta_out_seq_start;
484 u32 meta_out_seq_count;
485 bool meta_out_streaming;
486
487
488 struct vb2_queue vb_sdr_cap_q;
489 struct list_head sdr_cap_active;
490 u32 sdr_pixelformat;
491 unsigned sdr_buffersize;
492 unsigned sdr_adc_freq;
493 unsigned sdr_fm_freq;
494 unsigned sdr_fm_deviation;
495 int sdr_fixp_src_phase;
496 int sdr_fixp_mod_phase;
497
498 bool tstamp_src_is_soe;
499 bool has_crop_cap;
500 bool has_compose_cap;
501 bool has_scaler_cap;
502 bool has_crop_out;
503 bool has_compose_out;
504 bool has_scaler_out;
505
506
507 struct task_struct *kthread_sdr_cap;
508 unsigned long jiffies_sdr_cap;
509 u32 sdr_cap_seq_offset;
510 u32 sdr_cap_seq_count;
511 bool sdr_cap_seq_resync;
512
513
514 struct vivid_rds_gen rds_gen;
515
516
517 unsigned radio_rx_freq;
518 unsigned radio_rx_audmode;
519 int radio_rx_sig_qual;
520 unsigned radio_rx_hw_seek_mode;
521 bool radio_rx_hw_seek_prog_lim;
522 bool radio_rx_rds_controls;
523 bool radio_rx_rds_enabled;
524 unsigned radio_rx_rds_use_alternates;
525 unsigned radio_rx_rds_last_block;
526 struct v4l2_fh *radio_rx_rds_owner;
527
528
529 unsigned radio_tx_freq;
530 unsigned radio_tx_subchans;
531 bool radio_tx_rds_controls;
532 unsigned radio_tx_rds_last_block;
533 struct v4l2_fh *radio_tx_rds_owner;
534
535
536 bool radio_rds_loop;
537 ktime_t radio_rds_init_time;
538
539
540 struct cec_adapter *cec_rx_adap;
541 struct cec_adapter *cec_tx_adap[MAX_OUTPUTS];
542 struct workqueue_struct *cec_workqueue;
543 spinlock_t cec_slock;
544 struct list_head cec_work_list;
545 unsigned int cec_xfer_time_jiffies;
546 unsigned long cec_xfer_start_jiffies;
547 u8 cec_output2bus_map[MAX_OUTPUTS];
548
549
550 char osd[14];
551 unsigned long osd_jiffies;
552
553 bool meta_pts;
554 bool meta_scr;
555};
556
557static inline bool vivid_is_webcam(const struct vivid_dev *dev)
558{
559 return dev->input_type[dev->input] == WEBCAM;
560}
561
562static inline bool vivid_is_tv_cap(const struct vivid_dev *dev)
563{
564 return dev->input_type[dev->input] == TV;
565}
566
567static inline bool vivid_is_svid_cap(const struct vivid_dev *dev)
568{
569 return dev->input_type[dev->input] == SVID;
570}
571
572static inline bool vivid_is_hdmi_cap(const struct vivid_dev *dev)
573{
574 return dev->input_type[dev->input] == HDMI;
575}
576
577static inline bool vivid_is_sdtv_cap(const struct vivid_dev *dev)
578{
579 return vivid_is_tv_cap(dev) || vivid_is_svid_cap(dev);
580}
581
582static inline bool vivid_is_svid_out(const struct vivid_dev *dev)
583{
584 return dev->output_type[dev->output] == SVID;
585}
586
587static inline bool vivid_is_hdmi_out(const struct vivid_dev *dev)
588{
589 return dev->output_type[dev->output] == HDMI;
590}
591
592#endif
593