1 #include <linux/module.h>
2 #include <linux/kernel.h>
3 #include <linux/sched.h>
4 #include <linux/string.h>
5 #include <linux/timer.h>
6 #include <linux/delay.h>
7 #include <linux/errno.h>
8 #include <linux/slab.h>
9 #include <linux/poll.h>
10 #include <linux/i2c.h>
11 #include <linux/types.h>
12 #include <linux/videodev2.h>
13 #include <media/v4l2-common.h>
14 #include <linux/init.h>
15 #include <linux/crc32.h>
18 #define MPEG_VIDEO_TARGET_BITRATE_MAX 27000
19 #define MPEG_VIDEO_MAX_BITRATE_MAX 27000
20 #define MPEG_TOTAL_TARGET_BITRATE_MAX 27000
21 #define MPEG_PID_MAX ((1 << 14) - 1)
23 /* Addresses to scan */
24 static unsigned short normal_i2c[] = {0x20, I2C_CLIENT_END};
27 MODULE_DESCRIPTION("device driver for saa6752hs MPEG2 encoder");
28 MODULE_AUTHOR("Andrew de Quincey");
29 MODULE_LICENSE("GPL");
31 static struct i2c_driver driver;
32 static struct i2c_client client_template;
34 enum saa6752hs_videoformat {
35 SAA6752HS_VF_D1 = 0, /* standard D1 video format: 720x576 */
36 SAA6752HS_VF_2_3_D1 = 1,/* 2/3D1 video format: 480x576 */
37 SAA6752HS_VF_1_2_D1 = 2,/* 1/2D1 video format: 352x576 */
38 SAA6752HS_VF_SIF = 3, /* SIF video format: 352x288 */
42 struct saa6752hs_mpeg_params {
43 /* transport streams */
50 enum v4l2_mpeg_audio_l2_bitrate au_l2_bitrate;
53 enum v4l2_mpeg_video_aspect vi_aspect;
54 enum v4l2_mpeg_video_bitrate_mode vi_bitrate_mode;
56 __u32 vi_bitrate_peak;
59 static const struct v4l2_format v4l2_format_table[] =
62 { .fmt = { .pix = { .width = 720, .height = 576 }}},
63 [SAA6752HS_VF_2_3_D1] =
64 { .fmt = { .pix = { .width = 480, .height = 576 }}},
65 [SAA6752HS_VF_1_2_D1] =
66 { .fmt = { .pix = { .width = 352, .height = 576 }}},
68 { .fmt = { .pix = { .width = 352, .height = 288 }}},
69 [SAA6752HS_VF_UNKNOWN] =
70 { .fmt = { .pix = { .width = 0, .height = 0}}},
73 struct saa6752hs_state {
74 struct i2c_client client;
75 struct v4l2_mpeg_compression old_params;
76 struct saa6752hs_mpeg_params params;
77 enum saa6752hs_videoformat video_format;
81 enum saa6752hs_command {
82 SAA6752HS_COMMAND_RESET = 0,
83 SAA6752HS_COMMAND_STOP = 1,
84 SAA6752HS_COMMAND_START = 2,
85 SAA6752HS_COMMAND_PAUSE = 3,
86 SAA6752HS_COMMAND_RECONFIGURE = 4,
87 SAA6752HS_COMMAND_SLEEP = 5,
88 SAA6752HS_COMMAND_RECONFIGURE_FORCE = 6,
93 /* ---------------------------------------------------------------------- */
96 0xc2, /* i2c register */
97 0x00, /* table number for encoder */
100 0x40, 0x00, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0), pid(0) */
101 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
103 0x00, /* PSI pointer to start of table */
106 0xb0, 0x0d, /* section_syntax_indicator(1), section_length(13) */
108 0x00, 0x01, /* transport_stream_id(1) */
110 0xc1, /* version_number(0), current_next_indicator(1) */
112 0x00, 0x00, /* section_number(0), last_section_number(0) */
114 0x00, 0x01, /* program_number(1) */
116 0xe0, 0x00, /* PMT PID */
118 0x00, 0x00, 0x00, 0x00 /* CRC32 */
122 0xc2, /* i2c register */
123 0x01, /* table number for encoder */
126 0x40, 0x00, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0), pid */
127 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
129 0x00, /* PSI pointer to start of table */
132 0xb0, 0x17, /* section_syntax_indicator(1), section_length(23) */
134 0x00, 0x01, /* program_number(1) */
136 0xc1, /* version_number(0), current_next_indicator(1) */
138 0x00, 0x00, /* section_number(0), last_section_number(0) */
140 0xe0, 0x00, /* PCR_PID */
142 0xf0, 0x00, /* program_info_length(0) */
144 0x02, 0xe0, 0x00, 0xf0, 0x00, /* video stream type(2), pid */
145 0x04, 0xe0, 0x00, 0xf0, 0x00, /* audio stream type(4), pid */
147 0x00, 0x00, 0x00, 0x00 /* CRC32 */
150 static struct saa6752hs_mpeg_params param_defaults =
157 .vi_aspect = V4L2_MPEG_VIDEO_ASPECT_4x3,
159 .vi_bitrate_peak = 6000,
160 .vi_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
162 .au_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_256K,
165 static struct v4l2_mpeg_compression old_param_defaults =
167 .st_type = V4L2_MPEG_TS_2,
169 .mode = V4L2_BITRATE_CBR,
178 .vi_type = V4L2_MPEG_VI_2,
179 .vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3,
181 .mode = V4L2_BITRATE_VBR,
186 .au_type = V4L2_MPEG_AU_2_II,
188 .mode = V4L2_BITRATE_CBR,
194 /* ---------------------------------------------------------------------- */
196 static int saa6752hs_chip_command(struct i2c_client* client,
197 enum saa6752hs_command command)
199 unsigned char buf[3];
200 unsigned long timeout;
203 /* execute the command */
205 case SAA6752HS_COMMAND_RESET:
209 case SAA6752HS_COMMAND_STOP:
213 case SAA6752HS_COMMAND_START:
217 case SAA6752HS_COMMAND_PAUSE:
221 case SAA6752HS_COMMAND_RECONFIGURE:
225 case SAA6752HS_COMMAND_SLEEP:
229 case SAA6752HS_COMMAND_RECONFIGURE_FORCE:
237 /* set it and wait for it to be so */
238 i2c_master_send(client, buf, 1);
239 timeout = jiffies + HZ * 3;
241 /* get the current status */
243 i2c_master_send(client, buf, 1);
244 i2c_master_recv(client, buf, 1);
246 if (!(buf[0] & 0x20))
248 if (time_after(jiffies,timeout)) {
256 /* delay a bit to let encoder settle */
263 static int saa6752hs_set_bitrate(struct i2c_client* client,
264 struct saa6752hs_mpeg_params* params)
269 /* set the bitrate mode */
271 buf[1] = (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) ? 0 : 1;
272 i2c_master_send(client, buf, 2);
274 /* set the video bitrate */
275 if (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) {
276 /* set the target bitrate */
278 buf[1] = params->vi_bitrate >> 8;
279 buf[2] = params->vi_bitrate & 0xff;
280 i2c_master_send(client, buf, 3);
282 /* set the max bitrate */
284 buf[1] = params->vi_bitrate_peak >> 8;
285 buf[2] = params->vi_bitrate_peak & 0xff;
286 i2c_master_send(client, buf, 3);
287 tot_bitrate = params->vi_bitrate_peak;
289 /* set the target bitrate (no max bitrate for CBR) */
291 buf[1] = params->vi_bitrate >> 8;
292 buf[2] = params->vi_bitrate & 0xff;
293 i2c_master_send(client, buf, 3);
294 tot_bitrate = params->vi_bitrate;
297 /* set the audio bitrate */
299 buf[1] = (V4L2_MPEG_AUDIO_L2_BITRATE_256K == params->au_l2_bitrate) ? 0 : 1;
300 i2c_master_send(client, buf, 2);
301 tot_bitrate += (V4L2_MPEG_AUDIO_L2_BITRATE_256K == params->au_l2_bitrate) ? 256 : 384;
303 /* Note: the total max bitrate is determined by adding the video and audio
304 bitrates together and also adding an extra 768kbit/s to stay on the
305 safe side. If more control should be required, then an extra MPEG control
308 if (tot_bitrate > MPEG_TOTAL_TARGET_BITRATE_MAX)
309 tot_bitrate = MPEG_TOTAL_TARGET_BITRATE_MAX;
311 /* set the total bitrate */
313 buf[1] = tot_bitrate >> 8;
314 buf[2] = tot_bitrate & 0xff;
315 i2c_master_send(client, buf, 3);
320 static void saa6752hs_set_subsampling(struct i2c_client* client,
321 struct v4l2_format* f)
323 struct saa6752hs_state *h = i2c_get_clientdata(client);
324 int dist_352, dist_480, dist_720;
327 FIXME: translate and round width/height into EMPRESS
331 ---------------------------
332 SIF | 352x288 | 352x240
333 1/2 D1 | 352x576 | 352x480
334 2/3 D1 | 480x576 | 480x480
335 D1 | 720x576 | 720x480
338 dist_352 = abs(f->fmt.pix.width - 352);
339 dist_480 = abs(f->fmt.pix.width - 480);
340 dist_720 = abs(f->fmt.pix.width - 720);
341 if (dist_720 < dist_480) {
342 f->fmt.pix.width = 720;
343 f->fmt.pix.height = 576;
344 h->video_format = SAA6752HS_VF_D1;
346 else if (dist_480 < dist_352) {
347 f->fmt.pix.width = 480;
348 f->fmt.pix.height = 576;
349 h->video_format = SAA6752HS_VF_2_3_D1;
352 f->fmt.pix.width = 352;
353 if (abs(f->fmt.pix.height - 576) <
354 abs(f->fmt.pix.height - 288)) {
355 f->fmt.pix.height = 576;
356 h->video_format = SAA6752HS_VF_1_2_D1;
359 f->fmt.pix.height = 288;
360 h->video_format = SAA6752HS_VF_SIF;
366 static void saa6752hs_old_set_params(struct i2c_client* client,
367 struct v4l2_mpeg_compression* params)
369 struct saa6752hs_state *h = i2c_get_clientdata(client);
372 if (params->ts_pid_pmt <= MPEG_PID_MAX) {
373 h->old_params.ts_pid_pmt = params->ts_pid_pmt;
374 h->params.ts_pid_pmt = params->ts_pid_pmt;
376 if (params->ts_pid_pcr <= MPEG_PID_MAX) {
377 h->old_params.ts_pid_pcr = params->ts_pid_pcr;
378 h->params.ts_pid_pcr = params->ts_pid_pcr;
380 if (params->ts_pid_video <= MPEG_PID_MAX) {
381 h->old_params.ts_pid_video = params->ts_pid_video;
382 h->params.ts_pid_video = params->ts_pid_video;
384 if (params->ts_pid_audio <= MPEG_PID_MAX) {
385 h->old_params.ts_pid_audio = params->ts_pid_audio;
386 h->params.ts_pid_audio = params->ts_pid_audio;
389 /* check bitrate parameters */
390 if ((params->vi_bitrate.mode == V4L2_BITRATE_CBR) ||
391 (params->vi_bitrate.mode == V4L2_BITRATE_VBR)) {
392 h->old_params.vi_bitrate.mode = params->vi_bitrate.mode;
393 h->params.vi_bitrate_mode = (params->vi_bitrate.mode == V4L2_BITRATE_VBR) ?
394 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR : V4L2_MPEG_VIDEO_BITRATE_MODE_CBR;
396 if (params->vi_bitrate.mode != V4L2_BITRATE_NONE)
397 h->old_params.st_bitrate.target = params->st_bitrate.target;
398 if (params->vi_bitrate.mode != V4L2_BITRATE_NONE)
399 h->old_params.vi_bitrate.target = params->vi_bitrate.target;
400 if (params->vi_bitrate.mode == V4L2_BITRATE_VBR)
401 h->old_params.vi_bitrate.max = params->vi_bitrate.max;
402 if (params->au_bitrate.mode != V4L2_BITRATE_NONE)
403 h->old_params.au_bitrate.target = params->au_bitrate.target;
406 if (params->vi_aspect_ratio == V4L2_MPEG_ASPECT_4_3 ||
407 params->vi_aspect_ratio == V4L2_MPEG_ASPECT_16_9) {
408 h->old_params.vi_aspect_ratio = params->vi_aspect_ratio;
409 if (params->vi_aspect_ratio == V4L2_MPEG_ASPECT_4_3)
410 h->params.vi_aspect = V4L2_MPEG_VIDEO_ASPECT_4x3;
412 h->params.vi_aspect = V4L2_MPEG_VIDEO_ASPECT_16x9;
416 if (h->old_params.st_bitrate.target > MPEG_TOTAL_TARGET_BITRATE_MAX)
417 h->old_params.st_bitrate.target = MPEG_TOTAL_TARGET_BITRATE_MAX;
418 if (h->old_params.vi_bitrate.target > MPEG_VIDEO_TARGET_BITRATE_MAX)
419 h->old_params.vi_bitrate.target = MPEG_VIDEO_TARGET_BITRATE_MAX;
420 if (h->old_params.vi_bitrate.max > MPEG_VIDEO_MAX_BITRATE_MAX)
421 h->old_params.vi_bitrate.max = MPEG_VIDEO_MAX_BITRATE_MAX;
422 h->params.vi_bitrate = params->vi_bitrate.target;
423 h->params.vi_bitrate_peak = params->vi_bitrate.max;
424 if (h->old_params.au_bitrate.target <= 256) {
425 h->old_params.au_bitrate.target = 256;
426 h->params.au_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_256K;
429 h->old_params.au_bitrate.target = 384;
430 h->params.au_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_384K;
434 static int handle_ctrl(struct saa6752hs_mpeg_params *params,
435 struct v4l2_ext_control *ctrl, unsigned int cmd)
438 int set = (cmd == VIDIOC_S_EXT_CTRLS);
442 case V4L2_CID_MPEG_STREAM_TYPE:
443 old = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
444 if (set && new != old)
448 case V4L2_CID_MPEG_STREAM_PID_PMT:
449 old = params->ts_pid_pmt;
450 if (set && new > MPEG_PID_MAX)
452 if (new > MPEG_PID_MAX)
454 params->ts_pid_pmt = new;
456 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
457 old = params->ts_pid_audio;
458 if (set && new > MPEG_PID_MAX)
460 if (new > MPEG_PID_MAX)
462 params->ts_pid_audio = new;
464 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
465 old = params->ts_pid_video;
466 if (set && new > MPEG_PID_MAX)
468 if (new > MPEG_PID_MAX)
470 params->ts_pid_video = new;
472 case V4L2_CID_MPEG_STREAM_PID_PCR:
473 old = params->ts_pid_pcr;
474 if (set && new > MPEG_PID_MAX)
476 if (new > MPEG_PID_MAX)
478 params->ts_pid_pcr = new;
480 case V4L2_CID_MPEG_AUDIO_ENCODING:
481 old = V4L2_MPEG_AUDIO_ENCODING_LAYER_2;
482 if (set && new != old)
486 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
487 old = params->au_l2_bitrate;
488 if (set && new != V4L2_MPEG_AUDIO_L2_BITRATE_256K &&
489 new != V4L2_MPEG_AUDIO_L2_BITRATE_384K)
491 if (new <= V4L2_MPEG_AUDIO_L2_BITRATE_256K)
492 new = V4L2_MPEG_AUDIO_L2_BITRATE_256K;
494 new = V4L2_MPEG_AUDIO_L2_BITRATE_384K;
495 params->au_l2_bitrate = new;
497 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
498 old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
499 if (set && new != old)
503 case V4L2_CID_MPEG_VIDEO_ENCODING:
504 old = V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
505 if (set && new != old)
509 case V4L2_CID_MPEG_VIDEO_ASPECT:
510 old = params->vi_aspect;
511 if (set && new != V4L2_MPEG_VIDEO_ASPECT_16x9 &&
512 new != V4L2_MPEG_VIDEO_ASPECT_4x3)
514 if (new != V4L2_MPEG_VIDEO_ASPECT_16x9)
515 new = V4L2_MPEG_VIDEO_ASPECT_4x3;
516 params->vi_aspect = new;
518 case V4L2_CID_MPEG_VIDEO_BITRATE:
519 old = params->vi_bitrate * 1000;
520 new = 1000 * (new / 1000);
521 if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
523 if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
524 new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
525 params->vi_bitrate = new / 1000;
527 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
528 old = params->vi_bitrate_peak * 1000;
529 new = 1000 * (new / 1000);
530 if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
532 if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
533 new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
534 params->vi_bitrate_peak = new / 1000;
536 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
537 old = params->vi_bitrate_mode;
538 params->vi_bitrate_mode = new;
543 if (cmd == VIDIOC_G_EXT_CTRLS)
550 static int saa6752hs_init(struct i2c_client* client)
552 unsigned char buf[9], buf2[4];
553 struct saa6752hs_state *h;
555 unsigned char localPAT[256];
556 unsigned char localPMT[256];
558 h = i2c_get_clientdata(client);
560 /* Set video format - must be done first as it resets other settings */
562 buf[1] = h->video_format;
563 i2c_master_send(client, buf, 2);
565 /* Set number of lines in input signal */
568 if (h->standard & V4L2_STD_525_60)
570 i2c_master_send(client, buf, 2);
573 saa6752hs_set_bitrate(client, &h->params);
575 /* Set GOP structure {3, 13} */
579 i2c_master_send(client,buf,3);
581 /* Set minimum Q-scale {4} */
584 i2c_master_send(client,buf,2);
586 /* Set maximum Q-scale {12} */
589 i2c_master_send(client,buf,2);
591 /* Set Output Protocol */
594 i2c_master_send(client,buf,2);
596 /* Set video output stream format {TS} */
599 i2c_master_send(client,buf,2);
602 memcpy(localPAT, PAT, sizeof(PAT));
603 localPAT[17] = 0xe0 | ((h->params.ts_pid_pmt >> 8) & 0x0f);
604 localPAT[18] = h->params.ts_pid_pmt & 0xff;
605 crc = crc32_be(~0, &localPAT[7], sizeof(PAT) - 7 - 4);
606 localPAT[sizeof(PAT) - 4] = (crc >> 24) & 0xFF;
607 localPAT[sizeof(PAT) - 3] = (crc >> 16) & 0xFF;
608 localPAT[sizeof(PAT) - 2] = (crc >> 8) & 0xFF;
609 localPAT[sizeof(PAT) - 1] = crc & 0xFF;
612 memcpy(localPMT, PMT, sizeof(PMT));
613 localPMT[3] = 0x40 | ((h->params.ts_pid_pmt >> 8) & 0x0f);
614 localPMT[4] = h->params.ts_pid_pmt & 0xff;
615 localPMT[15] = 0xE0 | ((h->params.ts_pid_pcr >> 8) & 0x0F);
616 localPMT[16] = h->params.ts_pid_pcr & 0xFF;
617 localPMT[20] = 0xE0 | ((h->params.ts_pid_video >> 8) & 0x0F);
618 localPMT[21] = h->params.ts_pid_video & 0xFF;
619 localPMT[25] = 0xE0 | ((h->params.ts_pid_audio >> 8) & 0x0F);
620 localPMT[26] = h->params.ts_pid_audio & 0xFF;
621 crc = crc32_be(~0, &localPMT[7], sizeof(PMT) - 7 - 4);
622 localPMT[sizeof(PMT) - 4] = (crc >> 24) & 0xFF;
623 localPMT[sizeof(PMT) - 3] = (crc >> 16) & 0xFF;
624 localPMT[sizeof(PMT) - 2] = (crc >> 8) & 0xFF;
625 localPMT[sizeof(PMT) - 1] = crc & 0xFF;
629 buf[1] = (h->params.ts_pid_audio >> 8) & 0xFF;
630 buf[2] = h->params.ts_pid_audio & 0xFF;
631 i2c_master_send(client,buf,3);
635 buf[1] = (h->params.ts_pid_video >> 8) & 0xFF;
636 buf[2] = h->params.ts_pid_video & 0xFF;
637 i2c_master_send(client,buf,3);
641 buf[1] = (h->params.ts_pid_pcr >> 8) & 0xFF;
642 buf[2] = h->params.ts_pid_pcr & 0xFF;
643 i2c_master_send(client,buf,3);
646 i2c_master_send(client,localPAT,sizeof(PAT));
647 i2c_master_send(client,localPMT,sizeof(PMT));
649 /* mute then unmute audio. This removes buzzing artefacts */
652 i2c_master_send(client, buf, 2);
654 i2c_master_send(client, buf, 2);
657 saa6752hs_chip_command(client, SAA6752HS_COMMAND_START);
659 /* readout current state */
665 i2c_master_send(client, buf, 5);
666 i2c_master_recv(client, buf2, 4);
668 /* change aspect ratio */
675 switch(h->params.vi_aspect) {
676 case V4L2_MPEG_VIDEO_ASPECT_16x9:
677 buf[6] = buf2[1] | 0x40;
679 case V4L2_MPEG_VIDEO_ASPECT_4x3:
681 buf[6] = buf2[1] & 0xBF;
687 i2c_master_send(client, buf, 9);
692 static int saa6752hs_attach(struct i2c_adapter *adap, int addr, int kind)
694 struct saa6752hs_state *h;
697 if (NULL == (h = kzalloc(sizeof(*h), GFP_KERNEL)))
699 h->client = client_template;
700 h->params = param_defaults;
701 h->old_params = old_param_defaults;
702 h->client.adapter = adap;
703 h->client.addr = addr;
705 /* Assume 625 input lines */
708 i2c_set_clientdata(&h->client, h);
709 i2c_attach_client(&h->client);
711 v4l_info(&h->client,"saa6752hs: chip found @ 0x%x\n", addr<<1);
716 static int saa6752hs_probe(struct i2c_adapter *adap)
718 if (adap->class & I2C_CLASS_TV_ANALOG)
719 return i2c_probe(adap, &addr_data, saa6752hs_attach);
723 static int saa6752hs_detach(struct i2c_client *client)
725 struct saa6752hs_state *h;
727 h = i2c_get_clientdata(client);
728 i2c_detach_client(client);
734 saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
736 struct saa6752hs_state *h = i2c_get_clientdata(client);
737 struct v4l2_ext_controls *ctrls = arg;
738 struct v4l2_mpeg_compression *old_params = arg;
739 struct saa6752hs_mpeg_params params;
744 case VIDIOC_S_MPEGCOMP:
745 if (NULL == old_params) {
746 /* apply settings and start encoder */
747 saa6752hs_init(client);
750 saa6752hs_old_set_params(client, old_params);
752 case VIDIOC_G_MPEGCOMP:
753 *old_params = h->old_params;
755 case VIDIOC_S_EXT_CTRLS:
756 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
758 if (ctrls->count == 0) {
759 /* apply settings and start encoder */
760 saa6752hs_init(client);
764 case VIDIOC_TRY_EXT_CTRLS:
765 case VIDIOC_G_EXT_CTRLS:
766 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
769 for (i = 0; i < ctrls->count; i++) {
770 if ((err = handle_ctrl(¶ms, ctrls->controls + i, cmd))) {
771 ctrls->error_idx = i;
779 struct v4l2_format *f = arg;
781 if (h->video_format == SAA6752HS_VF_UNKNOWN)
782 h->video_format = SAA6752HS_VF_D1;
784 v4l2_format_table[h->video_format].fmt.pix.width;
786 v4l2_format_table[h->video_format].fmt.pix.height;
791 struct v4l2_format *f = arg;
793 saa6752hs_set_subsampling(client, f);
797 h->standard = *((v4l2_std_id *) arg);
807 /* ----------------------------------------------------------------------- */
809 static struct i2c_driver driver = {
813 .id = I2C_DRIVERID_SAA6752HS,
814 .attach_adapter = saa6752hs_probe,
815 .detach_client = saa6752hs_detach,
816 .command = saa6752hs_command,
819 static struct i2c_client client_template =
825 static int __init saa6752hs_init_module(void)
827 return i2c_add_driver(&driver);
830 static void __exit saa6752hs_cleanup_module(void)
832 i2c_del_driver(&driver);
835 module_init(saa6752hs_init_module);
836 module_exit(saa6752hs_cleanup_module);
839 * Overrides for Emacs so that we follow Linus's tabbing style.
840 * ---------------------------------------------------------------------------