1 // SPDX-License-Identifier: GPL-2.0-or-later
3 saa6752hs - i2c-driver for the saa6752hs by Philips
5 Copyright (C) 2004 Andrew de Quincey
9 Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/string.h>
16 #include <linux/timer.h>
17 #include <linux/delay.h>
18 #include <linux/errno.h>
19 #include <linux/slab.h>
20 #include <linux/poll.h>
21 #include <linux/i2c.h>
22 #include <linux/types.h>
23 #include <linux/videodev2.h>
24 #include <linux/init.h>
25 #include <linux/crc32.h>
26 #include <media/v4l2-device.h>
27 #include <media/v4l2-ctrls.h>
28 #include <media/v4l2-common.h>
30 #define MPEG_VIDEO_TARGET_BITRATE_MAX 27000
31 #define MPEG_VIDEO_MAX_BITRATE_MAX 27000
32 #define MPEG_TOTAL_TARGET_BITRATE_MAX 27000
33 #define MPEG_PID_MAX ((1 << 14) - 1)
36 MODULE_DESCRIPTION("device driver for saa6752hs MPEG2 encoder");
37 MODULE_AUTHOR("Andrew de Quincey");
38 MODULE_LICENSE("GPL");
40 enum saa6752hs_videoformat
{
41 SAA6752HS_VF_D1
= 0, /* standard D1 video format: 720x576 */
42 SAA6752HS_VF_2_3_D1
= 1,/* 2/3D1 video format: 480x576 */
43 SAA6752HS_VF_1_2_D1
= 2,/* 1/2D1 video format: 352x576 */
44 SAA6752HS_VF_SIF
= 3, /* SIF video format: 352x288 */
48 struct saa6752hs_mpeg_params
{
49 /* transport streams */
56 enum v4l2_mpeg_audio_encoding au_encoding
;
57 enum v4l2_mpeg_audio_l2_bitrate au_l2_bitrate
;
58 enum v4l2_mpeg_audio_ac3_bitrate au_ac3_bitrate
;
61 enum v4l2_mpeg_video_aspect vi_aspect
;
62 enum v4l2_mpeg_video_bitrate_mode vi_bitrate_mode
;
64 __u32 vi_bitrate_peak
;
67 static const struct v4l2_format v4l2_format_table
[] =
70 { .fmt
= { .pix
= { .width
= 720, .height
= 576 }}},
71 [SAA6752HS_VF_2_3_D1
] =
72 { .fmt
= { .pix
= { .width
= 480, .height
= 576 }}},
73 [SAA6752HS_VF_1_2_D1
] =
74 { .fmt
= { .pix
= { .width
= 352, .height
= 576 }}},
76 { .fmt
= { .pix
= { .width
= 352, .height
= 288 }}},
77 [SAA6752HS_VF_UNKNOWN
] =
78 { .fmt
= { .pix
= { .width
= 0, .height
= 0}}},
81 struct saa6752hs_state
{
82 struct v4l2_subdev sd
;
83 struct v4l2_ctrl_handler hdl
;
84 struct { /* video bitrate mode control cluster */
85 struct v4l2_ctrl
*video_bitrate_mode
;
86 struct v4l2_ctrl
*video_bitrate
;
87 struct v4l2_ctrl
*video_bitrate_peak
;
91 struct saa6752hs_mpeg_params params
;
92 enum saa6752hs_videoformat video_format
;
96 enum saa6752hs_command
{
97 SAA6752HS_COMMAND_RESET
= 0,
98 SAA6752HS_COMMAND_STOP
= 1,
99 SAA6752HS_COMMAND_START
= 2,
100 SAA6752HS_COMMAND_PAUSE
= 3,
101 SAA6752HS_COMMAND_RECONFIGURE
= 4,
102 SAA6752HS_COMMAND_SLEEP
= 5,
103 SAA6752HS_COMMAND_RECONFIGURE_FORCE
= 6,
105 SAA6752HS_COMMAND_MAX
108 static inline struct saa6752hs_state
*to_state(struct v4l2_subdev
*sd
)
110 return container_of(sd
, struct saa6752hs_state
, sd
);
113 /* ---------------------------------------------------------------------- */
115 static const u8 PAT
[] = {
116 0xc2, /* i2c register */
117 0x00, /* table number for encoder */
120 0x40, 0x00, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0), pid(0) */
121 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
123 0x00, /* PSI pointer to start of table */
126 0xb0, 0x0d, /* section_syntax_indicator(1), section_length(13) */
128 0x00, 0x01, /* transport_stream_id(1) */
130 0xc1, /* version_number(0), current_next_indicator(1) */
132 0x00, 0x00, /* section_number(0), last_section_number(0) */
134 0x00, 0x01, /* program_number(1) */
136 0xe0, 0x00, /* PMT PID */
138 0x00, 0x00, 0x00, 0x00 /* CRC32 */
141 static const u8 PMT
[] = {
142 0xc2, /* i2c register */
143 0x01, /* table number for encoder */
146 0x40, 0x00, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0), pid */
147 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
149 0x00, /* PSI pointer to start of table */
152 0xb0, 0x17, /* section_syntax_indicator(1), section_length(23) */
154 0x00, 0x01, /* program_number(1) */
156 0xc1, /* version_number(0), current_next_indicator(1) */
158 0x00, 0x00, /* section_number(0), last_section_number(0) */
160 0xe0, 0x00, /* PCR_PID */
162 0xf0, 0x00, /* program_info_length(0) */
164 0x02, 0xe0, 0x00, 0xf0, 0x00, /* video stream type(2), pid */
165 0x04, 0xe0, 0x00, 0xf0, 0x00, /* audio stream type(4), pid */
167 0x00, 0x00, 0x00, 0x00 /* CRC32 */
170 static const u8 PMT_AC3
[] = {
171 0xc2, /* i2c register */
172 0x01, /* table number for encoder(1) */
175 0x40, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0) */
176 0x10, /* PMT PID (0x0010) */
177 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
179 0x00, /* PSI pointer to start of table */
182 0xb0, 0x1a, /* section_syntax_indicator(1), section_length(26) */
184 0x00, 0x01, /* program_number(1) */
186 0xc1, /* version_number(0), current_next_indicator(1) */
188 0x00, 0x00, /* section_number(0), last_section_number(0) */
190 0xe1, 0x04, /* PCR_PID (0x0104) */
192 0xf0, 0x00, /* program_info_length(0) */
194 0x02, 0xe1, 0x00, 0xf0, 0x00, /* video stream type(2), pid */
195 0x06, 0xe1, 0x03, 0xf0, 0x03, /* audio stream type(6), pid */
197 0x01, /* Descriptor_length(1) */
198 0x00, /* component_type_flag(0), bsid_flag(0), mainid_flag(0), asvc_flag(0), reserved flags(0) */
200 0xED, 0xDE, 0x2D, 0xF3 /* CRC32 BE */
203 static const struct saa6752hs_mpeg_params param_defaults
=
210 .vi_aspect
= V4L2_MPEG_VIDEO_ASPECT_4x3
,
212 .vi_bitrate_peak
= 6000,
213 .vi_bitrate_mode
= V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
,
215 .au_encoding
= V4L2_MPEG_AUDIO_ENCODING_LAYER_2
,
216 .au_l2_bitrate
= V4L2_MPEG_AUDIO_L2_BITRATE_256K
,
217 .au_ac3_bitrate
= V4L2_MPEG_AUDIO_AC3_BITRATE_256K
,
220 /* ---------------------------------------------------------------------- */
222 static int saa6752hs_chip_command(struct i2c_client
*client
,
223 enum saa6752hs_command command
)
225 unsigned char buf
[3];
226 unsigned long timeout
;
229 /* execute the command */
231 case SAA6752HS_COMMAND_RESET
:
235 case SAA6752HS_COMMAND_STOP
:
239 case SAA6752HS_COMMAND_START
:
243 case SAA6752HS_COMMAND_PAUSE
:
247 case SAA6752HS_COMMAND_RECONFIGURE
:
251 case SAA6752HS_COMMAND_SLEEP
:
255 case SAA6752HS_COMMAND_RECONFIGURE_FORCE
:
263 /* set it and wait for it to be so */
264 i2c_master_send(client
, buf
, 1);
265 timeout
= jiffies
+ HZ
* 3;
267 /* get the current status */
269 i2c_master_send(client
, buf
, 1);
270 i2c_master_recv(client
, buf
, 1);
272 if (!(buf
[0] & 0x20))
274 if (time_after(jiffies
,timeout
)) {
282 /* delay a bit to let encoder settle */
289 static inline void set_reg8(struct i2c_client
*client
, uint8_t reg
, uint8_t val
)
295 i2c_master_send(client
, buf
, 2);
298 static inline void set_reg16(struct i2c_client
*client
, uint8_t reg
, uint16_t val
)
305 i2c_master_send(client
, buf
, 3);
308 static int saa6752hs_set_bitrate(struct i2c_client
*client
,
309 struct saa6752hs_state
*h
)
311 struct saa6752hs_mpeg_params
*params
= &h
->params
;
315 /* set the bitrate mode */
316 set_reg8(client
, 0x71,
317 params
->vi_bitrate_mode
!= V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
);
319 /* set the video bitrate */
320 if (params
->vi_bitrate_mode
== V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
) {
321 /* set the target bitrate */
322 set_reg16(client
, 0x80, params
->vi_bitrate
);
324 /* set the max bitrate */
325 set_reg16(client
, 0x81, params
->vi_bitrate_peak
);
326 tot_bitrate
= params
->vi_bitrate_peak
;
328 /* set the target bitrate (no max bitrate for CBR) */
329 set_reg16(client
, 0x81, params
->vi_bitrate
);
330 tot_bitrate
= params
->vi_bitrate
;
333 /* set the audio encoding */
334 set_reg8(client
, 0x93,
335 params
->au_encoding
== V4L2_MPEG_AUDIO_ENCODING_AC3
);
337 /* set the audio bitrate */
338 if (params
->au_encoding
== V4L2_MPEG_AUDIO_ENCODING_AC3
)
339 is_384k
= V4L2_MPEG_AUDIO_AC3_BITRATE_384K
== params
->au_ac3_bitrate
;
341 is_384k
= V4L2_MPEG_AUDIO_L2_BITRATE_384K
== params
->au_l2_bitrate
;
342 set_reg8(client
, 0x94, is_384k
);
343 tot_bitrate
+= is_384k
? 384 : 256;
345 /* Note: the total max bitrate is determined by adding the video and audio
346 bitrates together and also adding an extra 768kbit/s to stay on the
347 safe side. If more control should be required, then an extra MPEG control
350 if (tot_bitrate
> MPEG_TOTAL_TARGET_BITRATE_MAX
)
351 tot_bitrate
= MPEG_TOTAL_TARGET_BITRATE_MAX
;
353 /* set the total bitrate */
354 set_reg16(client
, 0xb1, tot_bitrate
);
358 static int saa6752hs_try_ctrl(struct v4l2_ctrl
*ctrl
)
360 struct saa6752hs_state
*h
=
361 container_of(ctrl
->handler
, struct saa6752hs_state
, hdl
);
364 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
365 /* peak bitrate shall be >= normal bitrate */
366 if (ctrl
->val
== V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
&&
367 h
->video_bitrate_peak
->val
< h
->video_bitrate
->val
)
368 h
->video_bitrate_peak
->val
= h
->video_bitrate
->val
;
374 static int saa6752hs_s_ctrl(struct v4l2_ctrl
*ctrl
)
376 struct saa6752hs_state
*h
=
377 container_of(ctrl
->handler
, struct saa6752hs_state
, hdl
);
378 struct saa6752hs_mpeg_params
*params
= &h
->params
;
381 case V4L2_CID_MPEG_STREAM_TYPE
:
383 case V4L2_CID_MPEG_STREAM_PID_PMT
:
384 params
->ts_pid_pmt
= ctrl
->val
;
386 case V4L2_CID_MPEG_STREAM_PID_AUDIO
:
387 params
->ts_pid_audio
= ctrl
->val
;
389 case V4L2_CID_MPEG_STREAM_PID_VIDEO
:
390 params
->ts_pid_video
= ctrl
->val
;
392 case V4L2_CID_MPEG_STREAM_PID_PCR
:
393 params
->ts_pid_pcr
= ctrl
->val
;
395 case V4L2_CID_MPEG_AUDIO_ENCODING
:
396 params
->au_encoding
= ctrl
->val
;
398 case V4L2_CID_MPEG_AUDIO_L2_BITRATE
:
399 params
->au_l2_bitrate
= ctrl
->val
;
401 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE
:
402 params
->au_ac3_bitrate
= ctrl
->val
;
404 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
:
406 case V4L2_CID_MPEG_VIDEO_ENCODING
:
408 case V4L2_CID_MPEG_VIDEO_ASPECT
:
409 params
->vi_aspect
= ctrl
->val
;
411 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
412 params
->vi_bitrate_mode
= ctrl
->val
;
413 params
->vi_bitrate
= h
->video_bitrate
->val
/ 1000;
414 params
->vi_bitrate_peak
= h
->video_bitrate_peak
->val
/ 1000;
415 v4l2_ctrl_activate(h
->video_bitrate_peak
,
416 ctrl
->val
== V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
);
424 static int saa6752hs_init(struct v4l2_subdev
*sd
, u32 leading_null_bytes
)
426 unsigned char buf
[9], buf2
[4];
427 struct saa6752hs_state
*h
= to_state(sd
);
428 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
431 unsigned char localPAT
[256];
432 unsigned char localPMT
[256];
434 /* Set video format - must be done first as it resets other settings */
435 set_reg8(client
, 0x41, h
->video_format
);
437 /* Set number of lines in input signal */
438 set_reg8(client
, 0x40, (h
->standard
& V4L2_STD_525_60
) ? 1 : 0);
441 saa6752hs_set_bitrate(client
, h
);
443 /* Set GOP structure {3, 13} */
444 set_reg16(client
, 0x72, 0x030d);
446 /* Set minimum Q-scale {4} */
447 set_reg8(client
, 0x82, 0x04);
449 /* Set maximum Q-scale {12} */
450 set_reg8(client
, 0x83, 0x0c);
452 /* Set Output Protocol */
453 set_reg8(client
, 0xd0, 0x81);
455 /* Set video output stream format {TS} */
456 set_reg8(client
, 0xb0, 0x05);
458 /* Set leading null byte for TS */
459 set_reg16(client
, 0xf6, leading_null_bytes
);
462 memcpy(localPAT
, PAT
, sizeof(PAT
));
463 localPAT
[17] = 0xe0 | ((h
->params
.ts_pid_pmt
>> 8) & 0x0f);
464 localPAT
[18] = h
->params
.ts_pid_pmt
& 0xff;
465 crc
= crc32_be(~0, &localPAT
[7], sizeof(PAT
) - 7 - 4);
466 localPAT
[sizeof(PAT
) - 4] = (crc
>> 24) & 0xFF;
467 localPAT
[sizeof(PAT
) - 3] = (crc
>> 16) & 0xFF;
468 localPAT
[sizeof(PAT
) - 2] = (crc
>> 8) & 0xFF;
469 localPAT
[sizeof(PAT
) - 1] = crc
& 0xFF;
472 if (h
->params
.au_encoding
== V4L2_MPEG_AUDIO_ENCODING_AC3
) {
473 size
= sizeof(PMT_AC3
);
474 memcpy(localPMT
, PMT_AC3
, size
);
477 memcpy(localPMT
, PMT
, size
);
479 localPMT
[3] = 0x40 | ((h
->params
.ts_pid_pmt
>> 8) & 0x0f);
480 localPMT
[4] = h
->params
.ts_pid_pmt
& 0xff;
481 localPMT
[15] = 0xE0 | ((h
->params
.ts_pid_pcr
>> 8) & 0x0F);
482 localPMT
[16] = h
->params
.ts_pid_pcr
& 0xFF;
483 localPMT
[20] = 0xE0 | ((h
->params
.ts_pid_video
>> 8) & 0x0F);
484 localPMT
[21] = h
->params
.ts_pid_video
& 0xFF;
485 localPMT
[25] = 0xE0 | ((h
->params
.ts_pid_audio
>> 8) & 0x0F);
486 localPMT
[26] = h
->params
.ts_pid_audio
& 0xFF;
487 crc
= crc32_be(~0, &localPMT
[7], size
- 7 - 4);
488 localPMT
[size
- 4] = (crc
>> 24) & 0xFF;
489 localPMT
[size
- 3] = (crc
>> 16) & 0xFF;
490 localPMT
[size
- 2] = (crc
>> 8) & 0xFF;
491 localPMT
[size
- 1] = crc
& 0xFF;
494 set_reg16(client
, 0xc1, h
->params
.ts_pid_audio
);
497 set_reg16(client
, 0xc0, h
->params
.ts_pid_video
);
500 set_reg16(client
, 0xc4, h
->params
.ts_pid_pcr
);
503 i2c_master_send(client
, localPAT
, sizeof(PAT
));
504 i2c_master_send(client
, localPMT
, size
);
506 /* mute then unmute audio. This removes buzzing artefacts */
507 set_reg8(client
, 0xa4, 1);
508 set_reg8(client
, 0xa4, 0);
511 saa6752hs_chip_command(client
, SAA6752HS_COMMAND_START
);
513 /* readout current state */
519 i2c_master_send(client
, buf
, 5);
520 i2c_master_recv(client
, buf2
, 4);
522 /* change aspect ratio */
529 switch (h
->params
.vi_aspect
) {
530 case V4L2_MPEG_VIDEO_ASPECT_16x9
:
531 buf
[6] = buf2
[1] | 0x40;
533 case V4L2_MPEG_VIDEO_ASPECT_4x3
:
535 buf
[6] = buf2
[1] & 0xBF;
540 i2c_master_send(client
, buf
, 9);
545 static int saa6752hs_get_fmt(struct v4l2_subdev
*sd
,
546 struct v4l2_subdev_pad_config
*cfg
,
547 struct v4l2_subdev_format
*format
)
549 struct v4l2_mbus_framefmt
*f
= &format
->format
;
550 struct saa6752hs_state
*h
= to_state(sd
);
555 if (h
->video_format
== SAA6752HS_VF_UNKNOWN
)
556 h
->video_format
= SAA6752HS_VF_D1
;
557 f
->width
= v4l2_format_table
[h
->video_format
].fmt
.pix
.width
;
558 f
->height
= v4l2_format_table
[h
->video_format
].fmt
.pix
.height
;
559 f
->code
= MEDIA_BUS_FMT_FIXED
;
560 f
->field
= V4L2_FIELD_INTERLACED
;
561 f
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
565 static int saa6752hs_set_fmt(struct v4l2_subdev
*sd
,
566 struct v4l2_subdev_pad_config
*cfg
,
567 struct v4l2_subdev_format
*format
)
569 struct v4l2_mbus_framefmt
*f
= &format
->format
;
570 struct saa6752hs_state
*h
= to_state(sd
);
571 int dist_352
, dist_480
, dist_720
;
576 f
->code
= MEDIA_BUS_FMT_FIXED
;
578 dist_352
= abs(f
->width
- 352);
579 dist_480
= abs(f
->width
- 480);
580 dist_720
= abs(f
->width
- 720);
581 if (dist_720
< dist_480
) {
584 } else if (dist_480
< dist_352
) {
589 if (abs(f
->height
- 576) < abs(f
->height
- 288))
594 f
->field
= V4L2_FIELD_INTERLACED
;
595 f
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
597 if (format
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
603 FIXME: translate and round width/height into EMPRESS
607 ---------------------------
608 SIF | 352x288 | 352x240
609 1/2 D1 | 352x576 | 352x480
610 2/3 D1 | 480x576 | 480x480
611 D1 | 720x576 | 720x480
614 if (f
->code
!= MEDIA_BUS_FMT_FIXED
)
618 h
->video_format
= SAA6752HS_VF_D1
;
619 else if (f
->width
== 480)
620 h
->video_format
= SAA6752HS_VF_2_3_D1
;
621 else if (f
->height
== 576)
622 h
->video_format
= SAA6752HS_VF_1_2_D1
;
624 h
->video_format
= SAA6752HS_VF_SIF
;
628 static int saa6752hs_s_std(struct v4l2_subdev
*sd
, v4l2_std_id std
)
630 struct saa6752hs_state
*h
= to_state(sd
);
636 /* ----------------------------------------------------------------------- */
638 static const struct v4l2_ctrl_ops saa6752hs_ctrl_ops
= {
639 .try_ctrl
= saa6752hs_try_ctrl
,
640 .s_ctrl
= saa6752hs_s_ctrl
,
643 static const struct v4l2_subdev_core_ops saa6752hs_core_ops
= {
644 .init
= saa6752hs_init
,
647 static const struct v4l2_subdev_video_ops saa6752hs_video_ops
= {
648 .s_std
= saa6752hs_s_std
,
651 static const struct v4l2_subdev_pad_ops saa6752hs_pad_ops
= {
652 .get_fmt
= saa6752hs_get_fmt
,
653 .set_fmt
= saa6752hs_set_fmt
,
656 static const struct v4l2_subdev_ops saa6752hs_ops
= {
657 .core
= &saa6752hs_core_ops
,
658 .video
= &saa6752hs_video_ops
,
659 .pad
= &saa6752hs_pad_ops
,
662 static int saa6752hs_probe(struct i2c_client
*client
,
663 const struct i2c_device_id
*id
)
665 struct saa6752hs_state
*h
;
666 struct v4l2_subdev
*sd
;
667 struct v4l2_ctrl_handler
*hdl
;
671 v4l_info(client
, "chip found @ 0x%x (%s)\n",
672 client
->addr
<< 1, client
->adapter
->name
);
674 h
= devm_kzalloc(&client
->dev
, sizeof(*h
), GFP_KERNEL
);
678 v4l2_i2c_subdev_init(sd
, client
, &saa6752hs_ops
);
680 i2c_master_send(client
, &addr
, 1);
681 i2c_master_recv(client
, data
, sizeof(data
));
682 h
->revision
= (data
[8] << 8) | data
[9];
684 if (h
->revision
== 0x0206) {
686 v4l_info(client
, "supports AC-3\n");
688 h
->params
= param_defaults
;
691 v4l2_ctrl_handler_init(hdl
, 14);
692 v4l2_ctrl_new_std_menu(hdl
, &saa6752hs_ctrl_ops
,
693 V4L2_CID_MPEG_AUDIO_ENCODING
,
694 h
->has_ac3
? V4L2_MPEG_AUDIO_ENCODING_AC3
:
695 V4L2_MPEG_AUDIO_ENCODING_LAYER_2
,
696 0x0d, V4L2_MPEG_AUDIO_ENCODING_LAYER_2
);
698 v4l2_ctrl_new_std_menu(hdl
, &saa6752hs_ctrl_ops
,
699 V4L2_CID_MPEG_AUDIO_L2_BITRATE
,
700 V4L2_MPEG_AUDIO_L2_BITRATE_384K
,
701 ~((1 << V4L2_MPEG_AUDIO_L2_BITRATE_256K
) |
702 (1 << V4L2_MPEG_AUDIO_L2_BITRATE_384K
)),
703 V4L2_MPEG_AUDIO_L2_BITRATE_256K
);
706 v4l2_ctrl_new_std_menu(hdl
, &saa6752hs_ctrl_ops
,
707 V4L2_CID_MPEG_AUDIO_AC3_BITRATE
,
708 V4L2_MPEG_AUDIO_AC3_BITRATE_384K
,
709 ~((1 << V4L2_MPEG_AUDIO_AC3_BITRATE_256K
) |
710 (1 << V4L2_MPEG_AUDIO_AC3_BITRATE_384K
)),
711 V4L2_MPEG_AUDIO_AC3_BITRATE_256K
);
713 v4l2_ctrl_new_std_menu(hdl
, &saa6752hs_ctrl_ops
,
714 V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
,
715 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000
,
716 ~(1 << V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000
),
717 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000
);
719 v4l2_ctrl_new_std_menu(hdl
, &saa6752hs_ctrl_ops
,
720 V4L2_CID_MPEG_VIDEO_ENCODING
,
721 V4L2_MPEG_VIDEO_ENCODING_MPEG_2
,
722 ~(1 << V4L2_MPEG_VIDEO_ENCODING_MPEG_2
),
723 V4L2_MPEG_VIDEO_ENCODING_MPEG_2
);
725 v4l2_ctrl_new_std_menu(hdl
, &saa6752hs_ctrl_ops
,
726 V4L2_CID_MPEG_VIDEO_ASPECT
,
727 V4L2_MPEG_VIDEO_ASPECT_16x9
, 0x01,
728 V4L2_MPEG_VIDEO_ASPECT_4x3
);
730 h
->video_bitrate_peak
= v4l2_ctrl_new_std(hdl
, &saa6752hs_ctrl_ops
,
731 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
,
732 1000000, 27000000, 1000, 8000000);
734 v4l2_ctrl_new_std_menu(hdl
, &saa6752hs_ctrl_ops
,
735 V4L2_CID_MPEG_STREAM_TYPE
,
736 V4L2_MPEG_STREAM_TYPE_MPEG2_TS
,
737 ~(1 << V4L2_MPEG_STREAM_TYPE_MPEG2_TS
),
738 V4L2_MPEG_STREAM_TYPE_MPEG2_TS
);
740 h
->video_bitrate_mode
= v4l2_ctrl_new_std_menu(hdl
, &saa6752hs_ctrl_ops
,
741 V4L2_CID_MPEG_VIDEO_BITRATE_MODE
,
742 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
, 0,
743 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
);
744 h
->video_bitrate
= v4l2_ctrl_new_std(hdl
, &saa6752hs_ctrl_ops
,
745 V4L2_CID_MPEG_VIDEO_BITRATE
, 1000000, 27000000, 1000, 6000000);
746 v4l2_ctrl_new_std(hdl
, &saa6752hs_ctrl_ops
,
747 V4L2_CID_MPEG_STREAM_PID_PMT
, 0, (1 << 14) - 1, 1, 16);
748 v4l2_ctrl_new_std(hdl
, &saa6752hs_ctrl_ops
,
749 V4L2_CID_MPEG_STREAM_PID_AUDIO
, 0, (1 << 14) - 1, 1, 260);
750 v4l2_ctrl_new_std(hdl
, &saa6752hs_ctrl_ops
,
751 V4L2_CID_MPEG_STREAM_PID_VIDEO
, 0, (1 << 14) - 1, 1, 256);
752 v4l2_ctrl_new_std(hdl
, &saa6752hs_ctrl_ops
,
753 V4L2_CID_MPEG_STREAM_PID_PCR
, 0, (1 << 14) - 1, 1, 259);
754 sd
->ctrl_handler
= hdl
;
756 int err
= hdl
->error
;
758 v4l2_ctrl_handler_free(hdl
);
761 v4l2_ctrl_cluster(3, &h
->video_bitrate_mode
);
762 v4l2_ctrl_handler_setup(hdl
);
763 h
->standard
= 0; /* Assume 625 input lines */
767 static int saa6752hs_remove(struct i2c_client
*client
)
769 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
771 v4l2_device_unregister_subdev(sd
);
772 v4l2_ctrl_handler_free(&to_state(sd
)->hdl
);
776 static const struct i2c_device_id saa6752hs_id
[] = {
780 MODULE_DEVICE_TABLE(i2c
, saa6752hs_id
);
782 static struct i2c_driver saa6752hs_driver
= {
786 .probe
= saa6752hs_probe
,
787 .remove
= saa6752hs_remove
,
788 .id_table
= saa6752hs_id
,
791 module_i2c_driver(saa6752hs_driver
);