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