aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/saa7134/saa6752hs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/saa7134/saa6752hs.c')
-rw-r--r--drivers/media/video/saa7134/saa6752hs.c187
1 files changed, 98 insertions, 89 deletions
diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
index 382911c6ef22..cdd1ed9c8065 100644
--- a/drivers/media/video/saa7134/saa6752hs.c
+++ b/drivers/media/video/saa7134/saa6752hs.c
@@ -13,7 +13,6 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/crc32.h> 14#include <linux/crc32.h>
15 15
16#include <media/id.h>
17 16
18#define MPEG_VIDEO_TARGET_BITRATE_MAX 27000 17#define MPEG_VIDEO_TARGET_BITRATE_MAX 27000
19#define MPEG_VIDEO_MAX_BITRATE_MAX 27000 18#define MPEG_VIDEO_MAX_BITRATE_MAX 27000
@@ -57,6 +56,7 @@ struct saa6752hs_state {
57 struct i2c_client client; 56 struct i2c_client client;
58 struct v4l2_mpeg_compression params; 57 struct v4l2_mpeg_compression params;
59 enum saa6752hs_videoformat video_format; 58 enum saa6752hs_videoformat video_format;
59 v4l2_std_id standard;
60}; 60};
61 61
62enum saa6752hs_command { 62enum saa6752hs_command {
@@ -74,58 +74,58 @@ enum saa6752hs_command {
74/* ---------------------------------------------------------------------- */ 74/* ---------------------------------------------------------------------- */
75 75
76static u8 PAT[] = { 76static u8 PAT[] = {
77 0xc2, // i2c register 77 0xc2, /* i2c register */
78 0x00, // table number for encoder 78 0x00, /* table number for encoder */
79 79
80 0x47, // sync 80 0x47, /* sync */
81 0x40, 0x00, // transport_error_indicator(0), payload_unit_start(1), transport_priority(0), pid(0) 81 0x40, 0x00, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0), pid(0) */
82 0x10, // transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) 82 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
83 83
84 0x00, // PSI pointer to start of table 84 0x00, /* PSI pointer to start of table */
85 85
86 0x00, // tid(0) 86 0x00, /* tid(0) */
87 0xb0, 0x0d, // section_syntax_indicator(1), section_length(13) 87 0xb0, 0x0d, /* section_syntax_indicator(1), section_length(13) */
88 88
89 0x00, 0x01, // transport_stream_id(1) 89 0x00, 0x01, /* transport_stream_id(1) */
90 90
91 0xc1, // version_number(0), current_next_indicator(1) 91 0xc1, /* version_number(0), current_next_indicator(1) */
92 92
93 0x00, 0x00, // section_number(0), last_section_number(0) 93 0x00, 0x00, /* section_number(0), last_section_number(0) */
94 94
95 0x00, 0x01, // program_number(1) 95 0x00, 0x01, /* program_number(1) */
96 96
97 0xe0, 0x00, // PMT PID 97 0xe0, 0x00, /* PMT PID */
98 98
99 0x00, 0x00, 0x00, 0x00 // CRC32 99 0x00, 0x00, 0x00, 0x00 /* CRC32 */
100}; 100};
101 101
102static u8 PMT[] = { 102static u8 PMT[] = {
103 0xc2, // i2c register 103 0xc2, /* i2c register */
104 0x01, // table number for encoder 104 0x01, /* table number for encoder */
105 105
106 0x47, // sync 106 0x47, /* sync */
107 0x40, 0x00, // transport_error_indicator(0), payload_unit_start(1), transport_priority(0), pid 107 0x40, 0x00, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0), pid */
108 0x10, // transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) 108 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
109 109
110 0x00, // PSI pointer to start of table 110 0x00, /* PSI pointer to start of table */
111 111
112 0x02, // tid(2) 112 0x02, /* tid(2) */
113 0xb0, 0x17, // section_syntax_indicator(1), section_length(23) 113 0xb0, 0x17, /* section_syntax_indicator(1), section_length(23) */
114 114
115 0x00, 0x01, // program_number(1) 115 0x00, 0x01, /* program_number(1) */
116 116
117 0xc1, // version_number(0), current_next_indicator(1) 117 0xc1, /* version_number(0), current_next_indicator(1) */
118 118
119 0x00, 0x00, // section_number(0), last_section_number(0) 119 0x00, 0x00, /* section_number(0), last_section_number(0) */
120 120
121 0xe0, 0x00, // PCR_PID 121 0xe0, 0x00, /* PCR_PID */
122 122
123 0xf0, 0x00, // program_info_length(0) 123 0xf0, 0x00, /* program_info_length(0) */
124 124
125 0x02, 0xe0, 0x00, 0xf0, 0x00, // video stream type(2), pid 125 0x02, 0xe0, 0x00, 0xf0, 0x00, /* video stream type(2), pid */
126 0x04, 0xe0, 0x00, 0xf0, 0x00, // audio stream type(4), pid 126 0x04, 0xe0, 0x00, 0xf0, 0x00, /* audio stream type(4), pid */
127 127
128 0x00, 0x00, 0x00, 0x00 // CRC32 128 0x00, 0x00, 0x00, 0x00 /* CRC32 */
129}; 129};
130 130
131static struct v4l2_mpeg_compression param_defaults = 131static struct v4l2_mpeg_compression param_defaults =
@@ -166,33 +166,33 @@ static int saa6752hs_chip_command(struct i2c_client* client,
166 unsigned long timeout; 166 unsigned long timeout;
167 int status = 0; 167 int status = 0;
168 168
169 // execute the command 169 /* execute the command */
170 switch(command) { 170 switch(command) {
171 case SAA6752HS_COMMAND_RESET: 171 case SAA6752HS_COMMAND_RESET:
172 buf[0] = 0x00; 172 buf[0] = 0x00;
173 break; 173 break;
174 174
175 case SAA6752HS_COMMAND_STOP: 175 case SAA6752HS_COMMAND_STOP:
176 buf[0] = 0x03; 176 buf[0] = 0x03;
177 break; 177 break;
178 178
179 case SAA6752HS_COMMAND_START: 179 case SAA6752HS_COMMAND_START:
180 buf[0] = 0x02; 180 buf[0] = 0x02;
181 break; 181 break;
182 182
183 case SAA6752HS_COMMAND_PAUSE: 183 case SAA6752HS_COMMAND_PAUSE:
184 buf[0] = 0x04; 184 buf[0] = 0x04;
185 break; 185 break;
186 186
187 case SAA6752HS_COMMAND_RECONFIGURE: 187 case SAA6752HS_COMMAND_RECONFIGURE:
188 buf[0] = 0x05; 188 buf[0] = 0x05;
189 break; 189 break;
190 190
191 case SAA6752HS_COMMAND_SLEEP: 191 case SAA6752HS_COMMAND_SLEEP:
192 buf[0] = 0x06; 192 buf[0] = 0x06;
193 break; 193 break;
194 194
195 case SAA6752HS_COMMAND_RECONFIGURE_FORCE: 195 case SAA6752HS_COMMAND_RECONFIGURE_FORCE:
196 buf[0] = 0x07; 196 buf[0] = 0x07;
197 break; 197 break;
198 198
@@ -200,13 +200,13 @@ static int saa6752hs_chip_command(struct i2c_client* client,
200 return -EINVAL; 200 return -EINVAL;
201 } 201 }
202 202
203 // set it and wait for it to be so 203 /* set it and wait for it to be so */
204 i2c_master_send(client, buf, 1); 204 i2c_master_send(client, buf, 1);
205 timeout = jiffies + HZ * 3; 205 timeout = jiffies + HZ * 3;
206 for (;;) { 206 for (;;) {
207 // get the current status 207 /* get the current status */
208 buf[0] = 0x10; 208 buf[0] = 0x10;
209 i2c_master_send(client, buf, 1); 209 i2c_master_send(client, buf, 1);
210 i2c_master_recv(client, buf, 1); 210 i2c_master_recv(client, buf, 1);
211 211
212 if (!(buf[0] & 0x20)) 212 if (!(buf[0] & 0x20))
@@ -216,61 +216,58 @@ static int saa6752hs_chip_command(struct i2c_client* client,
216 break; 216 break;
217 } 217 }
218 218
219 // wait a bit
220 msleep(10); 219 msleep(10);
221 } 220 }
222 221
223 // delay a bit to let encoder settle 222 /* delay a bit to let encoder settle */
224 msleep(50); 223 msleep(50);
225 224
226 // done 225 return status;
227 return status;
228} 226}
229 227
230 228
231static int saa6752hs_set_bitrate(struct i2c_client* client, 229static int saa6752hs_set_bitrate(struct i2c_client* client,
232 struct v4l2_mpeg_compression* params) 230 struct v4l2_mpeg_compression* params)
233{ 231{
234 u8 buf[3]; 232 u8 buf[3];
235 233
236 // set the bitrate mode 234 /* set the bitrate mode */
237 buf[0] = 0x71; 235 buf[0] = 0x71;
238 buf[1] = (params->vi_bitrate.mode == V4L2_BITRATE_VBR) ? 0 : 1; 236 buf[1] = (params->vi_bitrate.mode == V4L2_BITRATE_VBR) ? 0 : 1;
239 i2c_master_send(client, buf, 2); 237 i2c_master_send(client, buf, 2);
240 238
241 // set the video bitrate 239 /* set the video bitrate */
242 if (params->vi_bitrate.mode == V4L2_BITRATE_VBR) { 240 if (params->vi_bitrate.mode == V4L2_BITRATE_VBR) {
243 // set the target bitrate 241 /* set the target bitrate */
244 buf[0] = 0x80; 242 buf[0] = 0x80;
245 buf[1] = params->vi_bitrate.target >> 8; 243 buf[1] = params->vi_bitrate.target >> 8;
246 buf[2] = params->vi_bitrate.target & 0xff; 244 buf[2] = params->vi_bitrate.target & 0xff;
247 i2c_master_send(client, buf, 3); 245 i2c_master_send(client, buf, 3);
248 246
249 // set the max bitrate 247 /* set the max bitrate */
250 buf[0] = 0x81; 248 buf[0] = 0x81;
251 buf[1] = params->vi_bitrate.max >> 8; 249 buf[1] = params->vi_bitrate.max >> 8;
252 buf[2] = params->vi_bitrate.max & 0xff; 250 buf[2] = params->vi_bitrate.max & 0xff;
253 i2c_master_send(client, buf, 3); 251 i2c_master_send(client, buf, 3);
254 } else { 252 } else {
255 // set the target bitrate (no max bitrate for CBR) 253 /* set the target bitrate (no max bitrate for CBR) */
256 buf[0] = 0x81; 254 buf[0] = 0x81;
257 buf[1] = params->vi_bitrate.target >> 8; 255 buf[1] = params->vi_bitrate.target >> 8;
258 buf[2] = params->vi_bitrate.target & 0xff; 256 buf[2] = params->vi_bitrate.target & 0xff;
259 i2c_master_send(client, buf, 3); 257 i2c_master_send(client, buf, 3);
260 } 258 }
261 259
262 // set the audio bitrate 260 /* set the audio bitrate */
263 buf[0] = 0x94; 261 buf[0] = 0x94;
264 buf[1] = (256 == params->au_bitrate.target) ? 0 : 1; 262 buf[1] = (256 == params->au_bitrate.target) ? 0 : 1;
265 i2c_master_send(client, buf, 2); 263 i2c_master_send(client, buf, 2);
266 264
267 // set the total bitrate 265 /* set the total bitrate */
268 buf[0] = 0xb1; 266 buf[0] = 0xb1;
269 buf[1] = params->st_bitrate.target >> 8; 267 buf[1] = params->st_bitrate.target >> 8;
270 buf[2] = params->st_bitrate.target & 0xff; 268 buf[2] = params->st_bitrate.target & 0xff;
271 i2c_master_send(client, buf, 3); 269 i2c_master_send(client, buf, 3);
272 270
273 // return success
274 return 0; 271 return 0;
275} 272}
276 273
@@ -376,36 +373,43 @@ static int saa6752hs_init(struct i2c_client* client)
376 373
377 h = i2c_get_clientdata(client); 374 h = i2c_get_clientdata(client);
378 375
379 // Set video format - must be done first as it resets other settings 376 /* Set video format - must be done first as it resets other settings */
380 buf[0] = 0x41; 377 buf[0] = 0x41;
381 buf[1] = h->video_format; 378 buf[1] = h->video_format;
382 i2c_master_send(client, buf, 2); 379 i2c_master_send(client, buf, 2);
383 380
384 // set bitrate 381 /* Set number of lines in input signal */
385 saa6752hs_set_bitrate(client, &h->params); 382 buf[0] = 0x40;
383 buf[1] = 0x00;
384 if (h->standard & V4L2_STD_525_60)
385 buf[1] = 0x01;
386 i2c_master_send(client, buf, 2);
387
388 /* set bitrate */
389 saa6752hs_set_bitrate(client, &h->params);
386 390
387 // Set GOP structure {3, 13} 391 /* Set GOP structure {3, 13} */
388 buf[0] = 0x72; 392 buf[0] = 0x72;
389 buf[1] = 0x03; 393 buf[1] = 0x03;
390 buf[2] = 0x0D; 394 buf[2] = 0x0D;
391 i2c_master_send(client,buf,3); 395 i2c_master_send(client,buf,3);
392 396
393 // Set minimum Q-scale {4} 397 /* Set minimum Q-scale {4} */
394 buf[0] = 0x82; 398 buf[0] = 0x82;
395 buf[1] = 0x04; 399 buf[1] = 0x04;
396 i2c_master_send(client,buf,2); 400 i2c_master_send(client,buf,2);
397 401
398 // Set maximum Q-scale {12} 402 /* Set maximum Q-scale {12} */
399 buf[0] = 0x83; 403 buf[0] = 0x83;
400 buf[1] = 0x0C; 404 buf[1] = 0x0C;
401 i2c_master_send(client,buf,2); 405 i2c_master_send(client,buf,2);
402 406
403 // Set Output Protocol 407 /* Set Output Protocol */
404 buf[0] = 0xD0; 408 buf[0] = 0xD0;
405 buf[1] = 0x81; 409 buf[1] = 0x81;
406 i2c_master_send(client,buf,2); 410 i2c_master_send(client,buf,2);
407 411
408 // Set video output stream format {TS} 412 /* Set video output stream format {TS} */
409 buf[0] = 0xB0; 413 buf[0] = 0xB0;
410 buf[1] = 0x05; 414 buf[1] = 0x05;
411 i2c_master_send(client,buf,2); 415 i2c_master_send(client,buf,2);
@@ -421,9 +425,9 @@ static int saa6752hs_init(struct i2c_client* client)
421 localPAT[sizeof(PAT) - 1] = crc & 0xFF; 425 localPAT[sizeof(PAT) - 1] = crc & 0xFF;
422 426
423 /* compute PMT */ 427 /* compute PMT */
424 memcpy(localPMT, PMT, sizeof(PMT)); 428 memcpy(localPMT, PMT, sizeof(PMT));
425 localPMT[3] = 0x40 | ((h->params.ts_pid_pmt >> 8) & 0x0f); 429 localPMT[3] = 0x40 | ((h->params.ts_pid_pmt >> 8) & 0x0f);
426 localPMT[4] = h->params.ts_pid_pmt & 0xff; 430 localPMT[4] = h->params.ts_pid_pmt & 0xff;
427 localPMT[15] = 0xE0 | ((h->params.ts_pid_pcr >> 8) & 0x0F); 431 localPMT[15] = 0xE0 | ((h->params.ts_pid_pcr >> 8) & 0x0F);
428 localPMT[16] = h->params.ts_pid_pcr & 0xFF; 432 localPMT[16] = h->params.ts_pid_pcr & 0xFF;
429 localPMT[20] = 0xE0 | ((h->params.ts_pid_video >> 8) & 0x0F); 433 localPMT[20] = 0xE0 | ((h->params.ts_pid_video >> 8) & 0x0F);
@@ -436,39 +440,39 @@ static int saa6752hs_init(struct i2c_client* client)
436 localPMT[sizeof(PMT) - 2] = (crc >> 8) & 0xFF; 440 localPMT[sizeof(PMT) - 2] = (crc >> 8) & 0xFF;
437 localPMT[sizeof(PMT) - 1] = crc & 0xFF; 441 localPMT[sizeof(PMT) - 1] = crc & 0xFF;
438 442
439 // Set Audio PID 443 /* Set Audio PID */
440 buf[0] = 0xC1; 444 buf[0] = 0xC1;
441 buf[1] = (h->params.ts_pid_audio >> 8) & 0xFF; 445 buf[1] = (h->params.ts_pid_audio >> 8) & 0xFF;
442 buf[2] = h->params.ts_pid_audio & 0xFF; 446 buf[2] = h->params.ts_pid_audio & 0xFF;
443 i2c_master_send(client,buf,3); 447 i2c_master_send(client,buf,3);
444 448
445 // Set Video PID 449 /* Set Video PID */
446 buf[0] = 0xC0; 450 buf[0] = 0xC0;
447 buf[1] = (h->params.ts_pid_video >> 8) & 0xFF; 451 buf[1] = (h->params.ts_pid_video >> 8) & 0xFF;
448 buf[2] = h->params.ts_pid_video & 0xFF; 452 buf[2] = h->params.ts_pid_video & 0xFF;
449 i2c_master_send(client,buf,3); 453 i2c_master_send(client,buf,3);
450 454
451 // Set PCR PID 455 /* Set PCR PID */
452 buf[0] = 0xC4; 456 buf[0] = 0xC4;
453 buf[1] = (h->params.ts_pid_pcr >> 8) & 0xFF; 457 buf[1] = (h->params.ts_pid_pcr >> 8) & 0xFF;
454 buf[2] = h->params.ts_pid_pcr & 0xFF; 458 buf[2] = h->params.ts_pid_pcr & 0xFF;
455 i2c_master_send(client,buf,3); 459 i2c_master_send(client,buf,3);
456 460
457 // Send SI tables 461 /* Send SI tables */
458 i2c_master_send(client,localPAT,sizeof(PAT)); 462 i2c_master_send(client,localPAT,sizeof(PAT));
459 i2c_master_send(client,localPMT,sizeof(PMT)); 463 i2c_master_send(client,localPMT,sizeof(PMT));
460 464
461 // mute then unmute audio. This removes buzzing artefacts 465 /* mute then unmute audio. This removes buzzing artefacts */
462 buf[0] = 0xa4; 466 buf[0] = 0xa4;
463 buf[1] = 1; 467 buf[1] = 1;
464 i2c_master_send(client, buf, 2); 468 i2c_master_send(client, buf, 2);
465 buf[1] = 0; 469 buf[1] = 0;
466 i2c_master_send(client, buf, 2); 470 i2c_master_send(client, buf, 2);
467 471
468 // start it going 472 /* start it going */
469 saa6752hs_chip_command(client, SAA6752HS_COMMAND_START); 473 saa6752hs_chip_command(client, SAA6752HS_COMMAND_START);
470 474
471 // readout current state 475 /* readout current state */
472 buf[0] = 0xE1; 476 buf[0] = 0xE1;
473 buf[1] = 0xA7; 477 buf[1] = 0xA7;
474 buf[2] = 0xFE; 478 buf[2] = 0xFE;
@@ -477,7 +481,7 @@ static int saa6752hs_init(struct i2c_client* client)
477 i2c_master_send(client, buf, 5); 481 i2c_master_send(client, buf, 5);
478 i2c_master_recv(client, buf2, 4); 482 i2c_master_recv(client, buf2, 4);
479 483
480 // change aspect ratio 484 /* change aspect ratio */
481 buf[0] = 0xE0; 485 buf[0] = 0xE0;
482 buf[1] = 0xA7; 486 buf[1] = 0xA7;
483 buf[2] = 0xFE; 487 buf[2] = 0xFE;
@@ -498,7 +502,6 @@ static int saa6752hs_init(struct i2c_client* client)
498 buf[8] = buf2[3]; 502 buf[8] = buf2[3];
499 i2c_master_send(client, buf, 9); 503 i2c_master_send(client, buf, 9);
500 504
501 // return success
502 return 0; 505 return 0;
503} 506}
504 507
@@ -506,16 +509,19 @@ static int saa6752hs_attach(struct i2c_adapter *adap, int addr, int kind)
506{ 509{
507 struct saa6752hs_state *h; 510 struct saa6752hs_state *h;
508 511
509 printk("saa6752hs: chip found @ 0x%x\n", addr<<1); 512 printk("saa6752hs: chip found @ 0x%x\n", addr<<1);
510 513
511 if (NULL == (h = kmalloc(sizeof(*h), GFP_KERNEL))) 514 if (NULL == (h = kmalloc(sizeof(*h), GFP_KERNEL)))
512 return -ENOMEM; 515 return -ENOMEM;
513 memset(h,0,sizeof(*h)); 516 memset(h,0,sizeof(*h));
514 h->client = client_template; 517 h->client = client_template;
515 h->params = param_defaults; 518 h->params = param_defaults;
516 h->client.adapter = adap; 519 h->client.adapter = adap;
517 h->client.addr = addr; 520 h->client.addr = addr;
518 521
522 /* Assume 625 input lines */
523 h->standard = 0;
524
519 i2c_set_clientdata(&h->client, h); 525 i2c_set_clientdata(&h->client, h);
520 i2c_attach_client(&h->client); 526 i2c_attach_client(&h->client);
521 return 0; 527 return 0;
@@ -545,7 +551,7 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
545 struct v4l2_mpeg_compression *params = arg; 551 struct v4l2_mpeg_compression *params = arg;
546 int err = 0; 552 int err = 0;
547 553
548 switch (cmd) { 554 switch (cmd) {
549 case VIDIOC_S_MPEGCOMP: 555 case VIDIOC_S_MPEGCOMP:
550 if (NULL == params) { 556 if (NULL == params) {
551 /* apply settings and start encoder */ 557 /* apply settings and start encoder */
@@ -559,7 +565,7 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
559 break; 565 break;
560 case VIDIOC_G_FMT: 566 case VIDIOC_G_FMT:
561 { 567 {
562 struct v4l2_format *f = arg; 568 struct v4l2_format *f = arg;
563 569
564 if (h->video_format == SAA6752HS_VF_UNKNOWN) 570 if (h->video_format == SAA6752HS_VF_UNKNOWN)
565 h->video_format = SAA6752HS_VF_D1; 571 h->video_format = SAA6752HS_VF_D1;
@@ -576,6 +582,9 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
576 saa6752hs_set_subsampling(client, f); 582 saa6752hs_set_subsampling(client, f);
577 break; 583 break;
578 } 584 }
585 case VIDIOC_S_STD:
586 h->standard = *((v4l2_std_id *) arg);
587 break;
579 default: 588 default:
580 /* nothing */ 589 /* nothing */
581 break; 590 break;