1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * cx2341x - generic code for cx23415/6/8 based devices
5 * Copyright (C) 2006 Hans Verkuil <hverkuil@xs4all.nl>
9 #include <linux/module.h>
10 #include <linux/errno.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/types.h>
14 #include <linux/videodev2.h>
16 #include <media/tuner.h>
17 #include <media/drv-intf/cx2341x.h>
18 #include <media/v4l2-common.h>
20 MODULE_DESCRIPTION("cx23415/6/8 driver");
21 MODULE_AUTHOR("Hans Verkuil");
22 MODULE_LICENSE("GPL");
25 module_param(debug
, int, 0644);
26 MODULE_PARM_DESC(debug
, "Debug level (0-1)");
28 /********************** COMMON CODE *********************/
30 /* definitions for audio properties bits 29-28 */
31 #define CX2341X_AUDIO_ENCODING_METHOD_MPEG 0
32 #define CX2341X_AUDIO_ENCODING_METHOD_AC3 1
33 #define CX2341X_AUDIO_ENCODING_METHOD_LPCM 2
35 static const char *cx2341x_get_name(u32 id
)
38 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
:
39 return "Spatial Filter Mode";
40 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER
:
41 return "Spatial Filter";
42 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
:
43 return "Spatial Luma Filter Type";
44 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
:
45 return "Spatial Chroma Filter Type";
46 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
:
47 return "Temporal Filter Mode";
48 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER
:
49 return "Temporal Filter";
50 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
:
51 return "Median Filter Type";
52 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP
:
53 return "Median Luma Filter Maximum";
54 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM
:
55 return "Median Luma Filter Minimum";
56 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP
:
57 return "Median Chroma Filter Maximum";
58 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM
:
59 return "Median Chroma Filter Minimum";
60 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS
:
61 return "Insert Navigation Packets";
66 static const char **cx2341x_get_menu(u32 id
)
68 static const char *cx2341x_video_spatial_filter_mode_menu
[] = {
74 static const char *cx2341x_video_luma_spatial_filter_type_menu
[] = {
79 "2D Symmetric non-separable",
83 static const char *cx2341x_video_chroma_spatial_filter_type_menu
[] = {
89 static const char *cx2341x_video_temporal_filter_mode_menu
[] = {
95 static const char *cx2341x_video_median_filter_type_menu
[] = {
99 "Horizontal/Vertical",
105 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
:
106 return cx2341x_video_spatial_filter_mode_menu
;
107 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
:
108 return cx2341x_video_luma_spatial_filter_type_menu
;
109 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
:
110 return cx2341x_video_chroma_spatial_filter_type_menu
;
111 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
:
112 return cx2341x_video_temporal_filter_mode_menu
;
113 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
:
114 return cx2341x_video_median_filter_type_menu
;
119 static void cx2341x_ctrl_fill(u32 id
, const char **name
, enum v4l2_ctrl_type
*type
,
120 s32
*min
, s32
*max
, s32
*step
, s32
*def
, u32
*flags
)
122 *name
= cx2341x_get_name(id
);
126 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
:
127 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
:
128 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
:
129 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
:
130 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
:
131 *type
= V4L2_CTRL_TYPE_MENU
;
135 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS
:
136 *type
= V4L2_CTRL_TYPE_BOOLEAN
;
141 *type
= V4L2_CTRL_TYPE_INTEGER
;
145 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
:
146 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
:
147 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
:
148 *flags
|= V4L2_CTRL_FLAG_UPDATE
;
150 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER
:
151 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER
:
152 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP
:
153 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM
:
154 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP
:
155 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM
:
156 *flags
|= V4L2_CTRL_FLAG_SLIDER
;
158 case V4L2_CID_MPEG_VIDEO_ENCODING
:
159 *flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
165 /********************** OLD CODE *********************/
167 /* Must be sorted from low to high control ID! */
168 const u32 cx2341x_mpeg_ctrls
[] = {
169 V4L2_CID_CODEC_CLASS
,
170 V4L2_CID_MPEG_STREAM_TYPE
,
171 V4L2_CID_MPEG_STREAM_VBI_FMT
,
172 V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
,
173 V4L2_CID_MPEG_AUDIO_ENCODING
,
174 V4L2_CID_MPEG_AUDIO_L2_BITRATE
,
175 V4L2_CID_MPEG_AUDIO_MODE
,
176 V4L2_CID_MPEG_AUDIO_MODE_EXTENSION
,
177 V4L2_CID_MPEG_AUDIO_EMPHASIS
,
178 V4L2_CID_MPEG_AUDIO_CRC
,
179 V4L2_CID_MPEG_AUDIO_MUTE
,
180 V4L2_CID_MPEG_AUDIO_AC3_BITRATE
,
181 V4L2_CID_MPEG_VIDEO_ENCODING
,
182 V4L2_CID_MPEG_VIDEO_ASPECT
,
183 V4L2_CID_MPEG_VIDEO_B_FRAMES
,
184 V4L2_CID_MPEG_VIDEO_GOP_SIZE
,
185 V4L2_CID_MPEG_VIDEO_GOP_CLOSURE
,
186 V4L2_CID_MPEG_VIDEO_BITRATE_MODE
,
187 V4L2_CID_MPEG_VIDEO_BITRATE
,
188 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
,
189 V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION
,
190 V4L2_CID_MPEG_VIDEO_MUTE
,
191 V4L2_CID_MPEG_VIDEO_MUTE_YUV
,
192 V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
,
193 V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER
,
194 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
,
195 V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
,
196 V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
,
197 V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER
,
198 V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
,
199 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM
,
200 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP
,
201 V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM
,
202 V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP
,
203 V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS
,
206 EXPORT_SYMBOL(cx2341x_mpeg_ctrls
);
208 static const struct cx2341x_mpeg_params default_params
= {
211 .port
= CX2341X_PORT_MEMORY
,
217 .stream_type
= V4L2_MPEG_STREAM_TYPE_MPEG2_PS
,
218 .stream_vbi_fmt
= V4L2_MPEG_STREAM_VBI_FMT_NONE
,
219 .stream_insert_nav_packets
= 0,
222 .audio_sampling_freq
= V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000
,
223 .audio_encoding
= V4L2_MPEG_AUDIO_ENCODING_LAYER_2
,
224 .audio_l2_bitrate
= V4L2_MPEG_AUDIO_L2_BITRATE_224K
,
225 .audio_ac3_bitrate
= V4L2_MPEG_AUDIO_AC3_BITRATE_224K
,
226 .audio_mode
= V4L2_MPEG_AUDIO_MODE_STEREO
,
227 .audio_mode_extension
= V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4
,
228 .audio_emphasis
= V4L2_MPEG_AUDIO_EMPHASIS_NONE
,
229 .audio_crc
= V4L2_MPEG_AUDIO_CRC_NONE
,
233 .video_encoding
= V4L2_MPEG_VIDEO_ENCODING_MPEG_2
,
234 .video_aspect
= V4L2_MPEG_VIDEO_ASPECT_4x3
,
236 .video_gop_size
= 12,
237 .video_gop_closure
= 1,
238 .video_bitrate_mode
= V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
,
239 .video_bitrate
= 6000000,
240 .video_bitrate_peak
= 8000000,
241 .video_temporal_decimation
= 0,
243 .video_mute_yuv
= 0x008080, /* YCbCr value for black */
245 /* encoding filters */
246 .video_spatial_filter_mode
=
247 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL
,
248 .video_spatial_filter
= 0,
249 .video_luma_spatial_filter_type
=
250 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR
,
251 .video_chroma_spatial_filter_type
=
252 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR
,
253 .video_temporal_filter_mode
=
254 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL
,
255 .video_temporal_filter
= 8,
256 .video_median_filter_type
=
257 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF
,
258 .video_luma_median_filter_top
= 255,
259 .video_luma_median_filter_bottom
= 0,
260 .video_chroma_median_filter_top
= 255,
261 .video_chroma_median_filter_bottom
= 0,
263 /* Map the control ID to the correct field in the cx2341x_mpeg_params
264 struct. Return -EINVAL if the ID is unknown, else return 0. */
265 static int cx2341x_get_ctrl(const struct cx2341x_mpeg_params
*params
,
266 struct v4l2_ext_control
*ctrl
)
269 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
:
270 ctrl
->value
= params
->audio_sampling_freq
;
272 case V4L2_CID_MPEG_AUDIO_ENCODING
:
273 ctrl
->value
= params
->audio_encoding
;
275 case V4L2_CID_MPEG_AUDIO_L2_BITRATE
:
276 ctrl
->value
= params
->audio_l2_bitrate
;
278 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE
:
279 ctrl
->value
= params
->audio_ac3_bitrate
;
281 case V4L2_CID_MPEG_AUDIO_MODE
:
282 ctrl
->value
= params
->audio_mode
;
284 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION
:
285 ctrl
->value
= params
->audio_mode_extension
;
287 case V4L2_CID_MPEG_AUDIO_EMPHASIS
:
288 ctrl
->value
= params
->audio_emphasis
;
290 case V4L2_CID_MPEG_AUDIO_CRC
:
291 ctrl
->value
= params
->audio_crc
;
293 case V4L2_CID_MPEG_AUDIO_MUTE
:
294 ctrl
->value
= params
->audio_mute
;
296 case V4L2_CID_MPEG_VIDEO_ENCODING
:
297 ctrl
->value
= params
->video_encoding
;
299 case V4L2_CID_MPEG_VIDEO_ASPECT
:
300 ctrl
->value
= params
->video_aspect
;
302 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
303 ctrl
->value
= params
->video_b_frames
;
305 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
:
306 ctrl
->value
= params
->video_gop_size
;
308 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE
:
309 ctrl
->value
= params
->video_gop_closure
;
311 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
312 ctrl
->value
= params
->video_bitrate_mode
;
314 case V4L2_CID_MPEG_VIDEO_BITRATE
:
315 ctrl
->value
= params
->video_bitrate
;
317 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
:
318 ctrl
->value
= params
->video_bitrate_peak
;
320 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION
:
321 ctrl
->value
= params
->video_temporal_decimation
;
323 case V4L2_CID_MPEG_VIDEO_MUTE
:
324 ctrl
->value
= params
->video_mute
;
326 case V4L2_CID_MPEG_VIDEO_MUTE_YUV
:
327 ctrl
->value
= params
->video_mute_yuv
;
329 case V4L2_CID_MPEG_STREAM_TYPE
:
330 ctrl
->value
= params
->stream_type
;
332 case V4L2_CID_MPEG_STREAM_VBI_FMT
:
333 ctrl
->value
= params
->stream_vbi_fmt
;
335 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
:
336 ctrl
->value
= params
->video_spatial_filter_mode
;
338 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER
:
339 ctrl
->value
= params
->video_spatial_filter
;
341 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
:
342 ctrl
->value
= params
->video_luma_spatial_filter_type
;
344 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
:
345 ctrl
->value
= params
->video_chroma_spatial_filter_type
;
347 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
:
348 ctrl
->value
= params
->video_temporal_filter_mode
;
350 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER
:
351 ctrl
->value
= params
->video_temporal_filter
;
353 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
:
354 ctrl
->value
= params
->video_median_filter_type
;
356 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP
:
357 ctrl
->value
= params
->video_luma_median_filter_top
;
359 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM
:
360 ctrl
->value
= params
->video_luma_median_filter_bottom
;
362 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP
:
363 ctrl
->value
= params
->video_chroma_median_filter_top
;
365 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM
:
366 ctrl
->value
= params
->video_chroma_median_filter_bottom
;
368 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS
:
369 ctrl
->value
= params
->stream_insert_nav_packets
;
377 /* Map the control ID to the correct field in the cx2341x_mpeg_params
378 struct. Return -EINVAL if the ID is unknown, else return 0. */
379 static int cx2341x_set_ctrl(struct cx2341x_mpeg_params
*params
, int busy
,
380 struct v4l2_ext_control
*ctrl
)
383 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
:
386 params
->audio_sampling_freq
= ctrl
->value
;
388 case V4L2_CID_MPEG_AUDIO_ENCODING
:
391 if (params
->capabilities
& CX2341X_CAP_HAS_AC3
)
392 if (ctrl
->value
!= V4L2_MPEG_AUDIO_ENCODING_LAYER_2
&&
393 ctrl
->value
!= V4L2_MPEG_AUDIO_ENCODING_AC3
)
395 params
->audio_encoding
= ctrl
->value
;
397 case V4L2_CID_MPEG_AUDIO_L2_BITRATE
:
400 params
->audio_l2_bitrate
= ctrl
->value
;
402 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE
:
405 if (!(params
->capabilities
& CX2341X_CAP_HAS_AC3
))
407 params
->audio_ac3_bitrate
= ctrl
->value
;
409 case V4L2_CID_MPEG_AUDIO_MODE
:
410 params
->audio_mode
= ctrl
->value
;
412 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION
:
413 params
->audio_mode_extension
= ctrl
->value
;
415 case V4L2_CID_MPEG_AUDIO_EMPHASIS
:
416 params
->audio_emphasis
= ctrl
->value
;
418 case V4L2_CID_MPEG_AUDIO_CRC
:
419 params
->audio_crc
= ctrl
->value
;
421 case V4L2_CID_MPEG_AUDIO_MUTE
:
422 params
->audio_mute
= ctrl
->value
;
424 case V4L2_CID_MPEG_VIDEO_ASPECT
:
425 params
->video_aspect
= ctrl
->value
;
427 case V4L2_CID_MPEG_VIDEO_B_FRAMES
: {
428 int b
= ctrl
->value
+ 1;
429 int gop
= params
->video_gop_size
;
430 params
->video_b_frames
= ctrl
->value
;
431 params
->video_gop_size
= b
* ((gop
+ b
- 1) / b
);
432 /* Max GOP size = 34 */
433 while (params
->video_gop_size
> 34)
434 params
->video_gop_size
-= b
;
437 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
: {
438 int b
= params
->video_b_frames
+ 1;
439 int gop
= ctrl
->value
;
440 params
->video_gop_size
= b
* ((gop
+ b
- 1) / b
);
441 /* Max GOP size = 34 */
442 while (params
->video_gop_size
> 34)
443 params
->video_gop_size
-= b
;
444 ctrl
->value
= params
->video_gop_size
;
447 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE
:
448 params
->video_gop_closure
= ctrl
->value
;
450 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
453 /* MPEG-1 only allows CBR */
454 if (params
->video_encoding
== V4L2_MPEG_VIDEO_ENCODING_MPEG_1
&&
455 ctrl
->value
!= V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
)
457 params
->video_bitrate_mode
= ctrl
->value
;
459 case V4L2_CID_MPEG_VIDEO_BITRATE
:
462 params
->video_bitrate
= ctrl
->value
;
464 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
:
467 params
->video_bitrate_peak
= ctrl
->value
;
469 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION
:
470 params
->video_temporal_decimation
= ctrl
->value
;
472 case V4L2_CID_MPEG_VIDEO_MUTE
:
473 params
->video_mute
= (ctrl
->value
!= 0);
475 case V4L2_CID_MPEG_VIDEO_MUTE_YUV
:
476 params
->video_mute_yuv
= ctrl
->value
;
478 case V4L2_CID_MPEG_STREAM_TYPE
:
481 params
->stream_type
= ctrl
->value
;
482 params
->video_encoding
=
483 (params
->stream_type
== V4L2_MPEG_STREAM_TYPE_MPEG1_SS
||
484 params
->stream_type
== V4L2_MPEG_STREAM_TYPE_MPEG1_VCD
) ?
485 V4L2_MPEG_VIDEO_ENCODING_MPEG_1
:
486 V4L2_MPEG_VIDEO_ENCODING_MPEG_2
;
487 if (params
->video_encoding
== V4L2_MPEG_VIDEO_ENCODING_MPEG_1
)
488 /* MPEG-1 implies CBR */
489 params
->video_bitrate_mode
=
490 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
;
492 case V4L2_CID_MPEG_STREAM_VBI_FMT
:
493 params
->stream_vbi_fmt
= ctrl
->value
;
495 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
:
496 params
->video_spatial_filter_mode
= ctrl
->value
;
498 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER
:
499 params
->video_spatial_filter
= ctrl
->value
;
501 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
:
502 params
->video_luma_spatial_filter_type
= ctrl
->value
;
504 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
:
505 params
->video_chroma_spatial_filter_type
= ctrl
->value
;
507 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
:
508 params
->video_temporal_filter_mode
= ctrl
->value
;
510 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER
:
511 params
->video_temporal_filter
= ctrl
->value
;
513 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
:
514 params
->video_median_filter_type
= ctrl
->value
;
516 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP
:
517 params
->video_luma_median_filter_top
= ctrl
->value
;
519 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM
:
520 params
->video_luma_median_filter_bottom
= ctrl
->value
;
522 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP
:
523 params
->video_chroma_median_filter_top
= ctrl
->value
;
525 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM
:
526 params
->video_chroma_median_filter_bottom
= ctrl
->value
;
528 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS
:
529 params
->stream_insert_nav_packets
= ctrl
->value
;
537 static int cx2341x_ctrl_query_fill(struct v4l2_queryctrl
*qctrl
,
538 s32 min
, s32 max
, s32 step
, s32 def
)
544 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
:
545 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER
:
546 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
:
547 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
:
548 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
:
549 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER
:
550 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
:
551 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP
:
552 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM
:
553 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP
:
554 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM
:
555 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS
:
556 cx2341x_ctrl_fill(qctrl
->id
, &name
, &qctrl
->type
,
557 &min
, &max
, &step
, &def
, &qctrl
->flags
);
558 qctrl
->minimum
= min
;
559 qctrl
->maximum
= max
;
561 qctrl
->default_value
= def
;
562 qctrl
->reserved
[0] = qctrl
->reserved
[1] = 0;
563 strscpy(qctrl
->name
, name
, sizeof(qctrl
->name
));
567 return v4l2_ctrl_query_fill(qctrl
, min
, max
, step
, def
);
571 int cx2341x_ctrl_query(const struct cx2341x_mpeg_params
*params
,
572 struct v4l2_queryctrl
*qctrl
)
577 case V4L2_CID_CODEC_CLASS
:
578 return v4l2_ctrl_query_fill(qctrl
, 0, 0, 0, 0);
579 case V4L2_CID_MPEG_STREAM_TYPE
:
580 return v4l2_ctrl_query_fill(qctrl
,
581 V4L2_MPEG_STREAM_TYPE_MPEG2_PS
,
582 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD
, 1,
583 V4L2_MPEG_STREAM_TYPE_MPEG2_PS
);
585 case V4L2_CID_MPEG_STREAM_VBI_FMT
:
586 if (params
->capabilities
& CX2341X_CAP_HAS_SLICED_VBI
)
587 return v4l2_ctrl_query_fill(qctrl
,
588 V4L2_MPEG_STREAM_VBI_FMT_NONE
,
589 V4L2_MPEG_STREAM_VBI_FMT_IVTV
, 1,
590 V4L2_MPEG_STREAM_VBI_FMT_NONE
);
591 return cx2341x_ctrl_query_fill(qctrl
,
592 V4L2_MPEG_STREAM_VBI_FMT_NONE
,
593 V4L2_MPEG_STREAM_VBI_FMT_NONE
, 1,
594 default_params
.stream_vbi_fmt
);
596 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
:
597 return v4l2_ctrl_query_fill(qctrl
,
598 V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100
,
599 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000
, 1,
600 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000
);
602 case V4L2_CID_MPEG_AUDIO_ENCODING
:
603 if (params
->capabilities
& CX2341X_CAP_HAS_AC3
) {
605 * The state of L2 & AC3 bitrate controls can change
606 * when this control changes, but v4l2_ctrl_query_fill()
607 * already sets V4L2_CTRL_FLAG_UPDATE for
608 * V4L2_CID_MPEG_AUDIO_ENCODING, so we don't here.
610 return v4l2_ctrl_query_fill(qctrl
,
611 V4L2_MPEG_AUDIO_ENCODING_LAYER_2
,
612 V4L2_MPEG_AUDIO_ENCODING_AC3
, 1,
613 default_params
.audio_encoding
);
616 return v4l2_ctrl_query_fill(qctrl
,
617 V4L2_MPEG_AUDIO_ENCODING_LAYER_2
,
618 V4L2_MPEG_AUDIO_ENCODING_LAYER_2
, 1,
619 default_params
.audio_encoding
);
621 case V4L2_CID_MPEG_AUDIO_L2_BITRATE
:
622 err
= v4l2_ctrl_query_fill(qctrl
,
623 V4L2_MPEG_AUDIO_L2_BITRATE_192K
,
624 V4L2_MPEG_AUDIO_L2_BITRATE_384K
, 1,
625 default_params
.audio_l2_bitrate
);
628 if (params
->capabilities
& CX2341X_CAP_HAS_AC3
&&
629 params
->audio_encoding
!= V4L2_MPEG_AUDIO_ENCODING_LAYER_2
)
630 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
633 case V4L2_CID_MPEG_AUDIO_MODE
:
634 return v4l2_ctrl_query_fill(qctrl
,
635 V4L2_MPEG_AUDIO_MODE_STEREO
,
636 V4L2_MPEG_AUDIO_MODE_MONO
, 1,
637 V4L2_MPEG_AUDIO_MODE_STEREO
);
639 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION
:
640 err
= v4l2_ctrl_query_fill(qctrl
,
641 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4
,
642 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16
, 1,
643 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4
);
645 params
->audio_mode
!= V4L2_MPEG_AUDIO_MODE_JOINT_STEREO
)
646 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
649 case V4L2_CID_MPEG_AUDIO_EMPHASIS
:
650 return v4l2_ctrl_query_fill(qctrl
,
651 V4L2_MPEG_AUDIO_EMPHASIS_NONE
,
652 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17
, 1,
653 V4L2_MPEG_AUDIO_EMPHASIS_NONE
);
655 case V4L2_CID_MPEG_AUDIO_CRC
:
656 return v4l2_ctrl_query_fill(qctrl
,
657 V4L2_MPEG_AUDIO_CRC_NONE
,
658 V4L2_MPEG_AUDIO_CRC_CRC16
, 1,
659 V4L2_MPEG_AUDIO_CRC_NONE
);
661 case V4L2_CID_MPEG_AUDIO_MUTE
:
662 return v4l2_ctrl_query_fill(qctrl
, 0, 1, 1, 0);
664 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE
:
665 err
= v4l2_ctrl_query_fill(qctrl
,
666 V4L2_MPEG_AUDIO_AC3_BITRATE_48K
,
667 V4L2_MPEG_AUDIO_AC3_BITRATE_448K
, 1,
668 default_params
.audio_ac3_bitrate
);
671 if (params
->capabilities
& CX2341X_CAP_HAS_AC3
) {
672 if (params
->audio_encoding
!=
673 V4L2_MPEG_AUDIO_ENCODING_AC3
)
674 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
676 qctrl
->flags
|= V4L2_CTRL_FLAG_DISABLED
;
679 case V4L2_CID_MPEG_VIDEO_ENCODING
:
680 /* this setting is read-only for the cx2341x since the
681 V4L2_CID_MPEG_STREAM_TYPE really determines the
683 err
= v4l2_ctrl_query_fill(qctrl
,
684 V4L2_MPEG_VIDEO_ENCODING_MPEG_1
,
685 V4L2_MPEG_VIDEO_ENCODING_MPEG_2
, 1,
686 V4L2_MPEG_VIDEO_ENCODING_MPEG_2
);
688 qctrl
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
691 case V4L2_CID_MPEG_VIDEO_ASPECT
:
692 return v4l2_ctrl_query_fill(qctrl
,
693 V4L2_MPEG_VIDEO_ASPECT_1x1
,
694 V4L2_MPEG_VIDEO_ASPECT_221x100
, 1,
695 V4L2_MPEG_VIDEO_ASPECT_4x3
);
697 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
698 return v4l2_ctrl_query_fill(qctrl
, 0, 33, 1, 2);
700 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
:
701 return v4l2_ctrl_query_fill(qctrl
, 1, 34, 1,
702 params
->is_50hz
? 12 : 15);
704 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE
:
705 return v4l2_ctrl_query_fill(qctrl
, 0, 1, 1, 1);
707 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
708 err
= v4l2_ctrl_query_fill(qctrl
,
709 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
,
710 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
, 1,
711 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
);
713 params
->video_encoding
== V4L2_MPEG_VIDEO_ENCODING_MPEG_1
)
714 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
717 case V4L2_CID_MPEG_VIDEO_BITRATE
:
718 return v4l2_ctrl_query_fill(qctrl
, 0, 27000000, 1, 6000000);
720 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
:
721 err
= v4l2_ctrl_query_fill(qctrl
, 0, 27000000, 1, 8000000);
723 params
->video_bitrate_mode
==
724 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
)
725 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
728 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION
:
729 return v4l2_ctrl_query_fill(qctrl
, 0, 255, 1, 0);
731 case V4L2_CID_MPEG_VIDEO_MUTE
:
732 return v4l2_ctrl_query_fill(qctrl
, 0, 1, 1, 0);
734 case V4L2_CID_MPEG_VIDEO_MUTE_YUV
: /* Init YUV (really YCbCr) to black */
735 return v4l2_ctrl_query_fill(qctrl
, 0, 0xffffff, 1, 0x008080);
737 /* CX23415/6 specific */
738 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
:
739 return cx2341x_ctrl_query_fill(qctrl
,
740 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL
,
741 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO
, 1,
742 default_params
.video_spatial_filter_mode
);
744 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER
:
745 cx2341x_ctrl_query_fill(qctrl
, 0, 15, 1,
746 default_params
.video_spatial_filter
);
747 qctrl
->flags
|= V4L2_CTRL_FLAG_SLIDER
;
748 if (params
->video_spatial_filter_mode
==
749 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO
)
750 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
753 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
:
754 cx2341x_ctrl_query_fill(qctrl
,
755 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF
,
756 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE
,
758 default_params
.video_luma_spatial_filter_type
);
759 if (params
->video_spatial_filter_mode
==
760 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO
)
761 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
764 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
:
765 cx2341x_ctrl_query_fill(qctrl
,
766 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF
,
767 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR
,
769 default_params
.video_chroma_spatial_filter_type
);
770 if (params
->video_spatial_filter_mode
==
771 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO
)
772 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
775 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
:
776 return cx2341x_ctrl_query_fill(qctrl
,
777 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL
,
778 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO
, 1,
779 default_params
.video_temporal_filter_mode
);
781 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER
:
782 cx2341x_ctrl_query_fill(qctrl
, 0, 31, 1,
783 default_params
.video_temporal_filter
);
784 qctrl
->flags
|= V4L2_CTRL_FLAG_SLIDER
;
785 if (params
->video_temporal_filter_mode
==
786 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO
)
787 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
790 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
:
791 return cx2341x_ctrl_query_fill(qctrl
,
792 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF
,
793 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG
, 1,
794 default_params
.video_median_filter_type
);
796 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP
:
797 cx2341x_ctrl_query_fill(qctrl
, 0, 255, 1,
798 default_params
.video_luma_median_filter_top
);
799 qctrl
->flags
|= V4L2_CTRL_FLAG_SLIDER
;
800 if (params
->video_median_filter_type
==
801 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF
)
802 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
805 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM
:
806 cx2341x_ctrl_query_fill(qctrl
, 0, 255, 1,
807 default_params
.video_luma_median_filter_bottom
);
808 qctrl
->flags
|= V4L2_CTRL_FLAG_SLIDER
;
809 if (params
->video_median_filter_type
==
810 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF
)
811 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
814 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP
:
815 cx2341x_ctrl_query_fill(qctrl
, 0, 255, 1,
816 default_params
.video_chroma_median_filter_top
);
817 qctrl
->flags
|= V4L2_CTRL_FLAG_SLIDER
;
818 if (params
->video_median_filter_type
==
819 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF
)
820 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
823 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM
:
824 cx2341x_ctrl_query_fill(qctrl
, 0, 255, 1,
825 default_params
.video_chroma_median_filter_bottom
);
826 qctrl
->flags
|= V4L2_CTRL_FLAG_SLIDER
;
827 if (params
->video_median_filter_type
==
828 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF
)
829 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
832 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS
:
833 return cx2341x_ctrl_query_fill(qctrl
, 0, 1, 1,
834 default_params
.stream_insert_nav_packets
);
841 EXPORT_SYMBOL(cx2341x_ctrl_query
);
843 const char * const *cx2341x_ctrl_get_menu(const struct cx2341x_mpeg_params
*p
, u32 id
)
845 static const char * const mpeg_stream_type_without_ts
[] = {
846 "MPEG-2 Program Stream",
848 "MPEG-1 System Stream",
849 "MPEG-2 DVD-compatible Stream",
850 "MPEG-1 VCD-compatible Stream",
851 "MPEG-2 SVCD-compatible Stream",
855 static const char *mpeg_stream_type_with_ts
[] = {
856 "MPEG-2 Program Stream",
857 "MPEG-2 Transport Stream",
858 "MPEG-1 System Stream",
859 "MPEG-2 DVD-compatible Stream",
860 "MPEG-1 VCD-compatible Stream",
861 "MPEG-2 SVCD-compatible Stream",
865 static const char *mpeg_audio_encoding_l2_ac3
[] = {
875 case V4L2_CID_MPEG_STREAM_TYPE
:
876 return (p
->capabilities
& CX2341X_CAP_HAS_TS
) ?
877 mpeg_stream_type_with_ts
: mpeg_stream_type_without_ts
;
878 case V4L2_CID_MPEG_AUDIO_ENCODING
:
879 return (p
->capabilities
& CX2341X_CAP_HAS_AC3
) ?
880 mpeg_audio_encoding_l2_ac3
: v4l2_ctrl_get_menu(id
);
881 case V4L2_CID_MPEG_AUDIO_L1_BITRATE
:
882 case V4L2_CID_MPEG_AUDIO_L3_BITRATE
:
884 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
:
885 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
:
886 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
:
887 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
:
888 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
:
889 return cx2341x_get_menu(id
);
891 return v4l2_ctrl_get_menu(id
);
894 EXPORT_SYMBOL(cx2341x_ctrl_get_menu
);
896 static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params
*params
)
898 params
->audio_properties
=
899 (params
->audio_sampling_freq
<< 0) |
900 (params
->audio_mode
<< 8) |
901 (params
->audio_mode_extension
<< 10) |
902 (((params
->audio_emphasis
== V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17
)
903 ? 3 : params
->audio_emphasis
) << 12) |
904 (params
->audio_crc
<< 14);
906 if ((params
->capabilities
& CX2341X_CAP_HAS_AC3
) &&
907 params
->audio_encoding
== V4L2_MPEG_AUDIO_ENCODING_AC3
) {
908 params
->audio_properties
|=
909 /* Not sure if this MPEG Layer II setting is required */
910 ((3 - V4L2_MPEG_AUDIO_ENCODING_LAYER_2
) << 2) |
911 (params
->audio_ac3_bitrate
<< 4) |
912 (CX2341X_AUDIO_ENCODING_METHOD_AC3
<< 28);
914 /* Assuming MPEG Layer II */
915 params
->audio_properties
|=
916 ((3 - params
->audio_encoding
) << 2) |
917 ((1 + params
->audio_l2_bitrate
) << 4);
921 /* Check for correctness of the ctrl's value based on the data from
922 struct v4l2_queryctrl and the available menu items. Note that
923 menu_items may be NULL, in that case it is ignored. */
924 static int v4l2_ctrl_check(struct v4l2_ext_control
*ctrl
, struct v4l2_queryctrl
*qctrl
,
925 const char * const *menu_items
)
927 if (qctrl
->flags
& V4L2_CTRL_FLAG_DISABLED
)
929 if (qctrl
->flags
& V4L2_CTRL_FLAG_GRABBED
)
931 if (qctrl
->type
== V4L2_CTRL_TYPE_STRING
)
933 if (qctrl
->type
== V4L2_CTRL_TYPE_BUTTON
||
934 qctrl
->type
== V4L2_CTRL_TYPE_INTEGER64
||
935 qctrl
->type
== V4L2_CTRL_TYPE_CTRL_CLASS
)
937 if (ctrl
->value
< qctrl
->minimum
|| ctrl
->value
> qctrl
->maximum
)
939 if (qctrl
->type
== V4L2_CTRL_TYPE_MENU
&& menu_items
!= NULL
) {
940 if (menu_items
[ctrl
->value
] == NULL
||
941 menu_items
[ctrl
->value
][0] == '\0')
944 if (qctrl
->type
== V4L2_CTRL_TYPE_BITMASK
&&
945 (ctrl
->value
& ~qctrl
->maximum
))
950 int cx2341x_ext_ctrls(struct cx2341x_mpeg_params
*params
, int busy
,
951 struct v4l2_ext_controls
*ctrls
, unsigned int cmd
)
956 if (cmd
== VIDIOC_G_EXT_CTRLS
) {
957 for (i
= 0; i
< ctrls
->count
; i
++) {
958 struct v4l2_ext_control
*ctrl
= ctrls
->controls
+ i
;
960 err
= cx2341x_get_ctrl(params
, ctrl
);
962 ctrls
->error_idx
= i
;
968 for (i
= 0; i
< ctrls
->count
; i
++) {
969 struct v4l2_ext_control
*ctrl
= ctrls
->controls
+ i
;
970 struct v4l2_queryctrl qctrl
;
971 const char * const *menu_items
= NULL
;
974 err
= cx2341x_ctrl_query(params
, &qctrl
);
977 if (qctrl
.type
== V4L2_CTRL_TYPE_MENU
)
978 menu_items
= cx2341x_ctrl_get_menu(params
, qctrl
.id
);
979 err
= v4l2_ctrl_check(ctrl
, &qctrl
, menu_items
);
982 err
= cx2341x_set_ctrl(params
, busy
, ctrl
);
987 params
->video_bitrate_mode
== V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
&&
988 params
->video_bitrate_peak
< params
->video_bitrate
) {
990 ctrls
->error_idx
= ctrls
->count
;
993 ctrls
->error_idx
= i
;
995 cx2341x_calc_audio_properties(params
);
998 EXPORT_SYMBOL(cx2341x_ext_ctrls
);
1000 void cx2341x_fill_defaults(struct cx2341x_mpeg_params
*p
)
1002 *p
= default_params
;
1003 cx2341x_calc_audio_properties(p
);
1005 EXPORT_SYMBOL(cx2341x_fill_defaults
);
1007 static int cx2341x_api(void *priv
, cx2341x_mbox_func func
,
1008 u32 cmd
, int args
, ...)
1010 u32 data
[CX2341X_MBOX_MAX_DATA
];
1014 va_start(vargs
, args
);
1016 for (i
= 0; i
< args
; i
++)
1017 data
[i
] = va_arg(vargs
, int);
1019 return func(priv
, cmd
, args
, 0, data
);
1022 #define CMP_FIELD(__old, __new, __field) (__old->__field != __new->__field)
1024 int cx2341x_update(void *priv
, cx2341x_mbox_func func
,
1025 const struct cx2341x_mpeg_params
*old
,
1026 const struct cx2341x_mpeg_params
*new)
1028 static int mpeg_stream_type
[] = {
1038 cx2341x_api(priv
, func
, CX2341X_ENC_SET_OUTPUT_PORT
, 2, new->port
, 0);
1041 CMP_FIELD(old
, new, is_50hz
)) {
1042 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_FRAME_RATE
, 1,
1049 CMP_FIELD(old
, new, width
) ||
1050 CMP_FIELD(old
, new, height
) ||
1051 CMP_FIELD(old
, new, video_encoding
)) {
1053 u16 h
= new->height
;
1055 if (new->video_encoding
== V4L2_MPEG_VIDEO_ENCODING_MPEG_1
) {
1059 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_FRAME_SIZE
, 2,
1065 CMP_FIELD(old
, new, stream_type
)) {
1066 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_STREAM_TYPE
, 1,
1067 mpeg_stream_type
[new->stream_type
]);
1072 CMP_FIELD(old
, new, video_aspect
)) {
1073 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_ASPECT_RATIO
, 1,
1074 1 + new->video_aspect
);
1079 CMP_FIELD(old
, new, video_b_frames
) ||
1080 CMP_FIELD(old
, new, video_gop_size
)) {
1081 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_GOP_PROPERTIES
, 2,
1082 new->video_gop_size
, new->video_b_frames
+ 1);
1087 CMP_FIELD(old
, new, video_gop_closure
)) {
1088 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_GOP_CLOSURE
, 1,
1089 new->video_gop_closure
);
1094 CMP_FIELD(old
, new, audio_properties
)) {
1095 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_AUDIO_PROPERTIES
,
1096 1, new->audio_properties
);
1101 CMP_FIELD(old
, new, audio_mute
)) {
1102 err
= cx2341x_api(priv
, func
, CX2341X_ENC_MUTE_AUDIO
, 1,
1108 CMP_FIELD(old
, new, video_bitrate_mode
) ||
1109 CMP_FIELD(old
, new, video_bitrate
) ||
1110 CMP_FIELD(old
, new, video_bitrate_peak
)) {
1111 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_BIT_RATE
, 5,
1112 new->video_bitrate_mode
, new->video_bitrate
,
1113 new->video_bitrate_peak
/ 400, 0, 0);
1118 CMP_FIELD(old
, new, video_spatial_filter_mode
) ||
1119 CMP_FIELD(old
, new, video_temporal_filter_mode
) ||
1120 CMP_FIELD(old
, new, video_median_filter_type
)) {
1121 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_DNR_FILTER_MODE
,
1123 new->video_spatial_filter_mode
|
1124 (new->video_temporal_filter_mode
<< 1),
1125 new->video_median_filter_type
);
1130 CMP_FIELD(old
, new, video_luma_median_filter_bottom
) ||
1131 CMP_FIELD(old
, new, video_luma_median_filter_top
) ||
1132 CMP_FIELD(old
, new, video_chroma_median_filter_bottom
) ||
1133 CMP_FIELD(old
, new, video_chroma_median_filter_top
)) {
1134 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_CORING_LEVELS
, 4,
1135 new->video_luma_median_filter_bottom
,
1136 new->video_luma_median_filter_top
,
1137 new->video_chroma_median_filter_bottom
,
1138 new->video_chroma_median_filter_top
);
1143 CMP_FIELD(old
, new, video_luma_spatial_filter_type
) ||
1144 CMP_FIELD(old
, new, video_chroma_spatial_filter_type
)) {
1145 err
= cx2341x_api(priv
, func
,
1146 CX2341X_ENC_SET_SPATIAL_FILTER_TYPE
,
1147 2, new->video_luma_spatial_filter_type
,
1148 new->video_chroma_spatial_filter_type
);
1153 CMP_FIELD(old
, new, video_spatial_filter
) ||
1154 CMP_FIELD(old
, new, video_temporal_filter
)) {
1155 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_DNR_FILTER_PROPS
,
1156 2, new->video_spatial_filter
,
1157 new->video_temporal_filter
);
1162 CMP_FIELD(old
, new, video_temporal_decimation
)) {
1163 err
= cx2341x_api(priv
, func
, CX2341X_ENC_SET_FRAME_DROP_RATE
,
1164 1, new->video_temporal_decimation
);
1169 CMP_FIELD(old
, new, video_mute
) ||
1170 (new->video_mute
&& CMP_FIELD(old
, new, video_mute_yuv
))) {
1171 err
= cx2341x_api(priv
, func
, CX2341X_ENC_MUTE_VIDEO
, 1,
1172 new->video_mute
| (new->video_mute_yuv
<< 8));
1177 CMP_FIELD(old
, new, stream_insert_nav_packets
)) {
1178 err
= cx2341x_api(priv
, func
, CX2341X_ENC_MISC
, 2,
1179 7, new->stream_insert_nav_packets
);
1185 EXPORT_SYMBOL(cx2341x_update
);
1187 static const char *cx2341x_menu_item(const struct cx2341x_mpeg_params
*p
, u32 id
)
1189 const char * const *menu
= cx2341x_ctrl_get_menu(p
, id
);
1190 struct v4l2_ext_control ctrl
;
1195 if (cx2341x_get_ctrl(p
, &ctrl
))
1197 while (ctrl
.value
-- && *menu
) menu
++;
1206 void cx2341x_log_status(const struct cx2341x_mpeg_params
*p
, const char *prefix
)
1208 int is_mpeg1
= p
->video_encoding
== V4L2_MPEG_VIDEO_ENCODING_MPEG_1
;
1211 printk(KERN_INFO
"%s: Stream: %s",
1213 cx2341x_menu_item(p
, V4L2_CID_MPEG_STREAM_TYPE
));
1214 if (p
->stream_insert_nav_packets
)
1215 printk(KERN_CONT
" (with navigation packets)");
1216 printk(KERN_CONT
"\n");
1217 printk(KERN_INFO
"%s: VBI Format: %s\n",
1219 cx2341x_menu_item(p
, V4L2_CID_MPEG_STREAM_VBI_FMT
));
1222 printk(KERN_INFO
"%s: Video: %dx%d, %d fps%s\n",
1224 p
->width
/ (is_mpeg1
? 2 : 1), p
->height
/ (is_mpeg1
? 2 : 1),
1225 p
->is_50hz
? 25 : 30,
1226 (p
->video_mute
) ? " (muted)" : "");
1227 printk(KERN_INFO
"%s: Video: %s, %s, %s, %d",
1229 cx2341x_menu_item(p
, V4L2_CID_MPEG_VIDEO_ENCODING
),
1230 cx2341x_menu_item(p
, V4L2_CID_MPEG_VIDEO_ASPECT
),
1231 cx2341x_menu_item(p
, V4L2_CID_MPEG_VIDEO_BITRATE_MODE
),
1233 if (p
->video_bitrate_mode
== V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
)
1234 printk(KERN_CONT
", Peak %d", p
->video_bitrate_peak
);
1235 printk(KERN_CONT
"\n");
1237 "%s: Video: GOP Size %d, %d B-Frames, %sGOP Closure\n",
1239 p
->video_gop_size
, p
->video_b_frames
,
1240 p
->video_gop_closure
? "" : "No ");
1241 if (p
->video_temporal_decimation
)
1242 printk(KERN_INFO
"%s: Video: Temporal Decimation %d\n",
1243 prefix
, p
->video_temporal_decimation
);
1246 printk(KERN_INFO
"%s: Audio: %s, %s, %s, %s%s",
1248 cx2341x_menu_item(p
, V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
),
1249 cx2341x_menu_item(p
, V4L2_CID_MPEG_AUDIO_ENCODING
),
1250 cx2341x_menu_item(p
,
1251 p
->audio_encoding
== V4L2_MPEG_AUDIO_ENCODING_AC3
1252 ? V4L2_CID_MPEG_AUDIO_AC3_BITRATE
1253 : V4L2_CID_MPEG_AUDIO_L2_BITRATE
),
1254 cx2341x_menu_item(p
, V4L2_CID_MPEG_AUDIO_MODE
),
1255 p
->audio_mute
? " (muted)" : "");
1256 if (p
->audio_mode
== V4L2_MPEG_AUDIO_MODE_JOINT_STEREO
)
1257 printk(KERN_CONT
", %s", cx2341x_menu_item(p
,
1258 V4L2_CID_MPEG_AUDIO_MODE_EXTENSION
));
1259 printk(KERN_CONT
", %s, %s\n",
1260 cx2341x_menu_item(p
, V4L2_CID_MPEG_AUDIO_EMPHASIS
),
1261 cx2341x_menu_item(p
, V4L2_CID_MPEG_AUDIO_CRC
));
1263 /* Encoding filters */
1264 printk(KERN_INFO
"%s: Spatial Filter: %s, Luma %s, Chroma %s, %d\n",
1266 cx2341x_menu_item(p
,
1267 V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
),
1268 cx2341x_menu_item(p
,
1269 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
),
1270 cx2341x_menu_item(p
,
1271 V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
),
1272 p
->video_spatial_filter
);
1274 printk(KERN_INFO
"%s: Temporal Filter: %s, %d\n",
1276 cx2341x_menu_item(p
,
1277 V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
),
1278 p
->video_temporal_filter
);
1280 "%s: Median Filter: %s, Luma [%d, %d], Chroma [%d, %d]\n",
1282 cx2341x_menu_item(p
,
1283 V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
),
1284 p
->video_luma_median_filter_bottom
,
1285 p
->video_luma_median_filter_top
,
1286 p
->video_chroma_median_filter_bottom
,
1287 p
->video_chroma_median_filter_top
);
1289 EXPORT_SYMBOL(cx2341x_log_status
);
1293 /********************** NEW CODE *********************/
1295 static inline struct cx2341x_handler
*to_cxhdl(struct v4l2_ctrl
*ctrl
)
1297 return container_of(ctrl
->handler
, struct cx2341x_handler
, hdl
);
1300 static int cx2341x_hdl_api(struct cx2341x_handler
*hdl
,
1301 u32 cmd
, int args
, ...)
1303 u32 data
[CX2341X_MBOX_MAX_DATA
];
1307 va_start(vargs
, args
);
1309 for (i
= 0; i
< args
; i
++)
1310 data
[i
] = va_arg(vargs
, int);
1312 return hdl
->func(hdl
->priv
, cmd
, args
, 0, data
);
1315 /* ctrl->handler->lock is held, so it is safe to access cur.val */
1316 static inline int cx2341x_neq(struct v4l2_ctrl
*ctrl
)
1318 return ctrl
&& ctrl
->val
!= ctrl
->cur
.val
;
1321 static int cx2341x_try_ctrl(struct v4l2_ctrl
*ctrl
)
1323 struct cx2341x_handler
*hdl
= to_cxhdl(ctrl
);
1324 s32 val
= ctrl
->val
;
1327 case V4L2_CID_MPEG_VIDEO_B_FRAMES
: {
1328 /* video gop cluster */
1330 int gop
= hdl
->video_gop_size
->val
;
1332 gop
= b
* ((gop
+ b
- 1) / b
);
1334 /* Max GOP size = 34 */
1337 hdl
->video_gop_size
->val
= gop
;
1341 case V4L2_CID_MPEG_STREAM_TYPE
:
1342 /* stream type cluster */
1343 hdl
->video_encoding
->val
=
1344 (hdl
->stream_type
->val
== V4L2_MPEG_STREAM_TYPE_MPEG1_SS
||
1345 hdl
->stream_type
->val
== V4L2_MPEG_STREAM_TYPE_MPEG1_VCD
) ?
1346 V4L2_MPEG_VIDEO_ENCODING_MPEG_1
:
1347 V4L2_MPEG_VIDEO_ENCODING_MPEG_2
;
1348 if (hdl
->video_encoding
->val
== V4L2_MPEG_VIDEO_ENCODING_MPEG_1
)
1349 /* MPEG-1 implies CBR */
1350 hdl
->video_bitrate_mode
->val
=
1351 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
;
1352 /* peak bitrate shall be >= normal bitrate */
1353 if (hdl
->video_bitrate_mode
->val
== V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
&&
1354 hdl
->video_bitrate_peak
->val
< hdl
->video_bitrate
->val
)
1355 hdl
->video_bitrate_peak
->val
= hdl
->video_bitrate
->val
;
1361 static int cx2341x_s_ctrl(struct v4l2_ctrl
*ctrl
)
1363 static const int mpeg_stream_type
[] = {
1371 struct cx2341x_handler
*hdl
= to_cxhdl(ctrl
);
1372 s32 val
= ctrl
->val
;
1377 case V4L2_CID_MPEG_STREAM_VBI_FMT
:
1378 if (hdl
->ops
&& hdl
->ops
->s_stream_vbi_fmt
)
1379 return hdl
->ops
->s_stream_vbi_fmt(hdl
, val
);
1382 case V4L2_CID_MPEG_VIDEO_ASPECT
:
1383 return cx2341x_hdl_api(hdl
,
1384 CX2341X_ENC_SET_ASPECT_RATIO
, 1, val
+ 1);
1386 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE
:
1387 return cx2341x_hdl_api(hdl
, CX2341X_ENC_SET_GOP_CLOSURE
, 1, val
);
1389 case V4L2_CID_MPEG_AUDIO_MUTE
:
1390 return cx2341x_hdl_api(hdl
, CX2341X_ENC_MUTE_AUDIO
, 1, val
);
1392 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION
:
1393 return cx2341x_hdl_api(hdl
,
1394 CX2341X_ENC_SET_FRAME_DROP_RATE
, 1, val
);
1396 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS
:
1397 return cx2341x_hdl_api(hdl
, CX2341X_ENC_MISC
, 2, 7, val
);
1399 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
:
1400 /* audio properties cluster */
1401 props
= (hdl
->audio_sampling_freq
->val
<< 0) |
1402 (hdl
->audio_mode
->val
<< 8) |
1403 (hdl
->audio_mode_extension
->val
<< 10) |
1404 (hdl
->audio_crc
->val
<< 14);
1405 if (hdl
->audio_emphasis
->val
== V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17
)
1408 props
|= hdl
->audio_emphasis
->val
<< 12;
1410 if (hdl
->audio_encoding
->val
== V4L2_MPEG_AUDIO_ENCODING_AC3
) {
1413 /* Not sure if this MPEG Layer II setting is required */
1414 ((3 - V4L2_MPEG_AUDIO_ENCODING_LAYER_2
) << 2) |
1416 (hdl
->audio_ac3_bitrate
->val
<< 4) |
1417 (CX2341X_AUDIO_ENCODING_METHOD_AC3
<< 28);
1419 /* Assuming MPEG Layer II */
1421 ((3 - hdl
->audio_encoding
->val
) << 2) |
1422 ((1 + hdl
->audio_l2_bitrate
->val
) << 4);
1424 err
= cx2341x_hdl_api(hdl
,
1425 CX2341X_ENC_SET_AUDIO_PROPERTIES
, 1, props
);
1429 hdl
->audio_properties
= props
;
1430 if (hdl
->audio_ac3_bitrate
) {
1431 int is_ac3
= hdl
->audio_encoding
->val
==
1432 V4L2_MPEG_AUDIO_ENCODING_AC3
;
1434 v4l2_ctrl_activate(hdl
->audio_ac3_bitrate
, is_ac3
);
1435 v4l2_ctrl_activate(hdl
->audio_l2_bitrate
, !is_ac3
);
1437 v4l2_ctrl_activate(hdl
->audio_mode_extension
,
1438 hdl
->audio_mode
->val
== V4L2_MPEG_AUDIO_MODE_JOINT_STEREO
);
1439 if (cx2341x_neq(hdl
->audio_sampling_freq
) &&
1440 hdl
->ops
&& hdl
->ops
->s_audio_sampling_freq
)
1441 return hdl
->ops
->s_audio_sampling_freq(hdl
, hdl
->audio_sampling_freq
->val
);
1442 if (cx2341x_neq(hdl
->audio_mode
) &&
1443 hdl
->ops
&& hdl
->ops
->s_audio_mode
)
1444 return hdl
->ops
->s_audio_mode(hdl
, hdl
->audio_mode
->val
);
1447 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
1448 /* video gop cluster */
1449 return cx2341x_hdl_api(hdl
, CX2341X_ENC_SET_GOP_PROPERTIES
, 2,
1450 hdl
->video_gop_size
->val
,
1451 hdl
->video_b_frames
->val
+ 1);
1453 case V4L2_CID_MPEG_STREAM_TYPE
:
1454 /* stream type cluster */
1455 err
= cx2341x_hdl_api(hdl
,
1456 CX2341X_ENC_SET_STREAM_TYPE
, 1, mpeg_stream_type
[val
]);
1460 err
= cx2341x_hdl_api(hdl
, CX2341X_ENC_SET_BIT_RATE
, 5,
1461 hdl
->video_bitrate_mode
->val
,
1462 hdl
->video_bitrate
->val
,
1463 hdl
->video_bitrate_peak
->val
/ 400, 0, 0);
1467 v4l2_ctrl_activate(hdl
->video_bitrate_mode
,
1468 hdl
->video_encoding
->val
!= V4L2_MPEG_VIDEO_ENCODING_MPEG_1
);
1469 v4l2_ctrl_activate(hdl
->video_bitrate_peak
,
1470 hdl
->video_bitrate_mode
->val
!= V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
);
1471 if (cx2341x_neq(hdl
->video_encoding
) &&
1472 hdl
->ops
&& hdl
->ops
->s_video_encoding
)
1473 return hdl
->ops
->s_video_encoding(hdl
, hdl
->video_encoding
->val
);
1476 case V4L2_CID_MPEG_VIDEO_MUTE
:
1477 /* video mute cluster */
1478 return cx2341x_hdl_api(hdl
, CX2341X_ENC_MUTE_VIDEO
, 1,
1479 hdl
->video_mute
->val
|
1480 (hdl
->video_mute_yuv
->val
<< 8));
1482 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
: {
1485 /* video filter mode */
1486 err
= cx2341x_hdl_api(hdl
, CX2341X_ENC_SET_DNR_FILTER_MODE
, 2,
1487 hdl
->video_spatial_filter_mode
->val
|
1488 (hdl
->video_temporal_filter_mode
->val
<< 1),
1489 hdl
->video_median_filter_type
->val
);
1493 active_filter
= hdl
->video_spatial_filter_mode
->val
!=
1494 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO
;
1495 v4l2_ctrl_activate(hdl
->video_spatial_filter
, active_filter
);
1496 v4l2_ctrl_activate(hdl
->video_luma_spatial_filter_type
, active_filter
);
1497 v4l2_ctrl_activate(hdl
->video_chroma_spatial_filter_type
, active_filter
);
1498 active_filter
= hdl
->video_temporal_filter_mode
->val
!=
1499 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO
;
1500 v4l2_ctrl_activate(hdl
->video_temporal_filter
, active_filter
);
1501 active_filter
= hdl
->video_median_filter_type
->val
!=
1502 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF
;
1503 v4l2_ctrl_activate(hdl
->video_luma_median_filter_bottom
, active_filter
);
1504 v4l2_ctrl_activate(hdl
->video_luma_median_filter_top
, active_filter
);
1505 v4l2_ctrl_activate(hdl
->video_chroma_median_filter_bottom
, active_filter
);
1506 v4l2_ctrl_activate(hdl
->video_chroma_median_filter_top
, active_filter
);
1510 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
:
1511 /* video filter type cluster */
1512 return cx2341x_hdl_api(hdl
,
1513 CX2341X_ENC_SET_SPATIAL_FILTER_TYPE
, 2,
1514 hdl
->video_luma_spatial_filter_type
->val
,
1515 hdl
->video_chroma_spatial_filter_type
->val
);
1517 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER
:
1518 /* video filter cluster */
1519 return cx2341x_hdl_api(hdl
, CX2341X_ENC_SET_DNR_FILTER_PROPS
, 2,
1520 hdl
->video_spatial_filter
->val
,
1521 hdl
->video_temporal_filter
->val
);
1523 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP
:
1524 /* video median cluster */
1525 return cx2341x_hdl_api(hdl
, CX2341X_ENC_SET_CORING_LEVELS
, 4,
1526 hdl
->video_luma_median_filter_bottom
->val
,
1527 hdl
->video_luma_median_filter_top
->val
,
1528 hdl
->video_chroma_median_filter_bottom
->val
,
1529 hdl
->video_chroma_median_filter_top
->val
);
1534 static const struct v4l2_ctrl_ops cx2341x_ops
= {
1535 .try_ctrl
= cx2341x_try_ctrl
,
1536 .s_ctrl
= cx2341x_s_ctrl
,
1539 static struct v4l2_ctrl
*cx2341x_ctrl_new_custom(struct v4l2_ctrl_handler
*hdl
,
1540 u32 id
, s32 min
, s32 max
, s32 step
, s32 def
)
1542 struct v4l2_ctrl_config cfg
;
1544 memset(&cfg
, 0, sizeof(cfg
));
1545 cx2341x_ctrl_fill(id
, &cfg
.name
, &cfg
.type
, &min
, &max
, &step
, &def
, &cfg
.flags
);
1546 cfg
.ops
= &cx2341x_ops
;
1551 if (cfg
.type
== V4L2_CTRL_TYPE_MENU
) {
1553 cfg
.menu_skip_mask
= step
;
1554 cfg
.qmenu
= cx2341x_get_menu(id
);
1557 cfg
.menu_skip_mask
= 0;
1559 return v4l2_ctrl_new_custom(hdl
, &cfg
, NULL
);
1562 static struct v4l2_ctrl
*cx2341x_ctrl_new_std(struct v4l2_ctrl_handler
*hdl
,
1563 u32 id
, s32 min
, s32 max
, s32 step
, s32 def
)
1565 return v4l2_ctrl_new_std(hdl
, &cx2341x_ops
, id
, min
, max
, step
, def
);
1568 static struct v4l2_ctrl
*cx2341x_ctrl_new_menu(struct v4l2_ctrl_handler
*hdl
,
1569 u32 id
, s32 max
, s32 mask
, s32 def
)
1571 return v4l2_ctrl_new_std_menu(hdl
, &cx2341x_ops
, id
, max
, mask
, def
);
1574 int cx2341x_handler_init(struct cx2341x_handler
*cxhdl
,
1575 unsigned nr_of_controls_hint
)
1577 struct v4l2_ctrl_handler
*hdl
= &cxhdl
->hdl
;
1578 u32 caps
= cxhdl
->capabilities
;
1579 int has_sliced_vbi
= caps
& CX2341X_CAP_HAS_SLICED_VBI
;
1580 int has_ac3
= caps
& CX2341X_CAP_HAS_AC3
;
1581 int has_ts
= caps
& CX2341X_CAP_HAS_TS
;
1584 cxhdl
->height
= 480;
1586 v4l2_ctrl_handler_init(hdl
, nr_of_controls_hint
);
1588 /* Add controls in ascending control ID order for fastest
1590 cxhdl
->stream_type
= cx2341x_ctrl_new_menu(hdl
,
1591 V4L2_CID_MPEG_STREAM_TYPE
,
1592 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD
, has_ts
? 0 : 2,
1593 V4L2_MPEG_STREAM_TYPE_MPEG2_PS
);
1594 cxhdl
->stream_vbi_fmt
= cx2341x_ctrl_new_menu(hdl
,
1595 V4L2_CID_MPEG_STREAM_VBI_FMT
,
1596 V4L2_MPEG_STREAM_VBI_FMT_IVTV
, has_sliced_vbi
? 0 : 2,
1597 V4L2_MPEG_STREAM_VBI_FMT_NONE
);
1598 cxhdl
->audio_sampling_freq
= cx2341x_ctrl_new_menu(hdl
,
1599 V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
,
1600 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000
, 0,
1601 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000
);
1602 cxhdl
->audio_encoding
= cx2341x_ctrl_new_menu(hdl
,
1603 V4L2_CID_MPEG_AUDIO_ENCODING
,
1604 V4L2_MPEG_AUDIO_ENCODING_AC3
, has_ac3
? ~0x12 : ~0x2,
1605 V4L2_MPEG_AUDIO_ENCODING_LAYER_2
);
1606 cxhdl
->audio_l2_bitrate
= cx2341x_ctrl_new_menu(hdl
,
1607 V4L2_CID_MPEG_AUDIO_L2_BITRATE
,
1608 V4L2_MPEG_AUDIO_L2_BITRATE_384K
, 0x1ff,
1609 V4L2_MPEG_AUDIO_L2_BITRATE_224K
);
1610 cxhdl
->audio_mode
= cx2341x_ctrl_new_menu(hdl
,
1611 V4L2_CID_MPEG_AUDIO_MODE
,
1612 V4L2_MPEG_AUDIO_MODE_MONO
, 0,
1613 V4L2_MPEG_AUDIO_MODE_STEREO
);
1614 cxhdl
->audio_mode_extension
= cx2341x_ctrl_new_menu(hdl
,
1615 V4L2_CID_MPEG_AUDIO_MODE_EXTENSION
,
1616 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16
, 0,
1617 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4
);
1618 cxhdl
->audio_emphasis
= cx2341x_ctrl_new_menu(hdl
,
1619 V4L2_CID_MPEG_AUDIO_EMPHASIS
,
1620 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17
, 0,
1621 V4L2_MPEG_AUDIO_EMPHASIS_NONE
);
1622 cxhdl
->audio_crc
= cx2341x_ctrl_new_menu(hdl
,
1623 V4L2_CID_MPEG_AUDIO_CRC
,
1624 V4L2_MPEG_AUDIO_CRC_CRC16
, 0,
1625 V4L2_MPEG_AUDIO_CRC_NONE
);
1627 cx2341x_ctrl_new_std(hdl
, V4L2_CID_MPEG_AUDIO_MUTE
, 0, 1, 1, 0);
1629 cxhdl
->audio_ac3_bitrate
= cx2341x_ctrl_new_menu(hdl
,
1630 V4L2_CID_MPEG_AUDIO_AC3_BITRATE
,
1631 V4L2_MPEG_AUDIO_AC3_BITRATE_448K
, 0x03,
1632 V4L2_MPEG_AUDIO_AC3_BITRATE_224K
);
1633 cxhdl
->video_encoding
= cx2341x_ctrl_new_menu(hdl
,
1634 V4L2_CID_MPEG_VIDEO_ENCODING
,
1635 V4L2_MPEG_VIDEO_ENCODING_MPEG_2
, 0,
1636 V4L2_MPEG_VIDEO_ENCODING_MPEG_2
);
1637 cx2341x_ctrl_new_menu(hdl
,
1638 V4L2_CID_MPEG_VIDEO_ASPECT
,
1639 V4L2_MPEG_VIDEO_ASPECT_221x100
, 0,
1640 V4L2_MPEG_VIDEO_ASPECT_4x3
);
1641 cxhdl
->video_b_frames
= cx2341x_ctrl_new_std(hdl
,
1642 V4L2_CID_MPEG_VIDEO_B_FRAMES
, 0, 33, 1, 2);
1643 cxhdl
->video_gop_size
= cx2341x_ctrl_new_std(hdl
,
1644 V4L2_CID_MPEG_VIDEO_GOP_SIZE
,
1645 1, 34, 1, cxhdl
->is_50hz
? 12 : 15);
1646 cx2341x_ctrl_new_std(hdl
, V4L2_CID_MPEG_VIDEO_GOP_CLOSURE
, 0, 1, 1, 1);
1647 cxhdl
->video_bitrate_mode
= cx2341x_ctrl_new_menu(hdl
,
1648 V4L2_CID_MPEG_VIDEO_BITRATE_MODE
,
1649 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
, 0,
1650 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
);
1651 cxhdl
->video_bitrate
= cx2341x_ctrl_new_std(hdl
,
1652 V4L2_CID_MPEG_VIDEO_BITRATE
,
1653 0, 27000000, 1, 6000000);
1654 cxhdl
->video_bitrate_peak
= cx2341x_ctrl_new_std(hdl
,
1655 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
,
1656 0, 27000000, 1, 8000000);
1657 cx2341x_ctrl_new_std(hdl
,
1658 V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION
, 0, 255, 1, 0);
1659 cxhdl
->video_mute
= cx2341x_ctrl_new_std(hdl
,
1660 V4L2_CID_MPEG_VIDEO_MUTE
, 0, 1, 1, 0);
1661 cxhdl
->video_mute_yuv
= cx2341x_ctrl_new_std(hdl
,
1662 V4L2_CID_MPEG_VIDEO_MUTE_YUV
, 0, 0xffffff, 1, 0x008080);
1664 /* CX23415/6 specific */
1665 cxhdl
->video_spatial_filter_mode
= cx2341x_ctrl_new_custom(hdl
,
1666 V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
,
1667 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL
,
1668 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO
, 0,
1669 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL
);
1670 cxhdl
->video_spatial_filter
= cx2341x_ctrl_new_custom(hdl
,
1671 V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER
,
1673 cxhdl
->video_luma_spatial_filter_type
= cx2341x_ctrl_new_custom(hdl
,
1674 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
,
1675 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF
,
1676 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE
,
1678 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR
);
1679 cxhdl
->video_chroma_spatial_filter_type
= cx2341x_ctrl_new_custom(hdl
,
1680 V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
,
1681 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF
,
1682 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR
,
1684 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR
);
1685 cxhdl
->video_temporal_filter_mode
= cx2341x_ctrl_new_custom(hdl
,
1686 V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
,
1687 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL
,
1688 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO
,
1690 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL
);
1691 cxhdl
->video_temporal_filter
= cx2341x_ctrl_new_custom(hdl
,
1692 V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER
,
1694 cxhdl
->video_median_filter_type
= cx2341x_ctrl_new_custom(hdl
,
1695 V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
,
1696 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF
,
1697 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG
,
1699 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF
);
1700 cxhdl
->video_luma_median_filter_bottom
= cx2341x_ctrl_new_custom(hdl
,
1701 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM
,
1703 cxhdl
->video_luma_median_filter_top
= cx2341x_ctrl_new_custom(hdl
,
1704 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP
,
1706 cxhdl
->video_chroma_median_filter_bottom
= cx2341x_ctrl_new_custom(hdl
,
1707 V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM
,
1709 cxhdl
->video_chroma_median_filter_top
= cx2341x_ctrl_new_custom(hdl
,
1710 V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP
,
1712 cx2341x_ctrl_new_custom(hdl
, V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS
,
1716 int err
= hdl
->error
;
1718 v4l2_ctrl_handler_free(hdl
);
1722 v4l2_ctrl_cluster(8, &cxhdl
->audio_sampling_freq
);
1723 v4l2_ctrl_cluster(2, &cxhdl
->video_b_frames
);
1724 v4l2_ctrl_cluster(5, &cxhdl
->stream_type
);
1725 v4l2_ctrl_cluster(2, &cxhdl
->video_mute
);
1726 v4l2_ctrl_cluster(3, &cxhdl
->video_spatial_filter_mode
);
1727 v4l2_ctrl_cluster(2, &cxhdl
->video_luma_spatial_filter_type
);
1728 v4l2_ctrl_cluster(2, &cxhdl
->video_spatial_filter
);
1729 v4l2_ctrl_cluster(4, &cxhdl
->video_luma_median_filter_top
);
1733 EXPORT_SYMBOL(cx2341x_handler_init
);
1735 void cx2341x_handler_set_50hz(struct cx2341x_handler
*cxhdl
, int is_50hz
)
1737 cxhdl
->is_50hz
= is_50hz
;
1738 cxhdl
->video_gop_size
->default_value
= cxhdl
->is_50hz
? 12 : 15;
1740 EXPORT_SYMBOL(cx2341x_handler_set_50hz
);
1742 int cx2341x_handler_setup(struct cx2341x_handler
*cxhdl
)
1744 int h
= cxhdl
->height
;
1745 int w
= cxhdl
->width
;
1748 err
= cx2341x_hdl_api(cxhdl
, CX2341X_ENC_SET_OUTPUT_PORT
, 2, cxhdl
->port
, 0);
1751 err
= cx2341x_hdl_api(cxhdl
, CX2341X_ENC_SET_FRAME_RATE
, 1, cxhdl
->is_50hz
);
1755 if (v4l2_ctrl_g_ctrl(cxhdl
->video_encoding
) == V4L2_MPEG_VIDEO_ENCODING_MPEG_1
) {
1759 err
= cx2341x_hdl_api(cxhdl
, CX2341X_ENC_SET_FRAME_SIZE
, 2, h
, w
);
1762 return v4l2_ctrl_handler_setup(&cxhdl
->hdl
);
1764 EXPORT_SYMBOL(cx2341x_handler_setup
);
1766 void cx2341x_handler_set_busy(struct cx2341x_handler
*cxhdl
, int busy
)
1768 v4l2_ctrl_grab(cxhdl
->audio_sampling_freq
, busy
);
1769 v4l2_ctrl_grab(cxhdl
->audio_encoding
, busy
);
1770 v4l2_ctrl_grab(cxhdl
->audio_l2_bitrate
, busy
);
1771 v4l2_ctrl_grab(cxhdl
->audio_ac3_bitrate
, busy
);
1772 v4l2_ctrl_grab(cxhdl
->stream_vbi_fmt
, busy
);
1773 v4l2_ctrl_grab(cxhdl
->stream_type
, busy
);
1774 v4l2_ctrl_grab(cxhdl
->video_bitrate_mode
, busy
);
1775 v4l2_ctrl_grab(cxhdl
->video_bitrate
, busy
);
1776 v4l2_ctrl_grab(cxhdl
->video_bitrate_peak
, busy
);
1778 EXPORT_SYMBOL(cx2341x_handler_set_busy
);