aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tda9887.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/tda9887.c')
-rw-r--r--drivers/media/video/tda9887.c163
1 files changed, 89 insertions, 74 deletions
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index 94053f149ddf..4249127c0a1d 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -11,7 +11,6 @@
11 11
12#include <media/audiochip.h> 12#include <media/audiochip.h>
13#include <media/tuner.h> 13#include <media/tuner.h>
14#include <media/id.h>
15 14
16/* Chips: 15/* Chips:
17 TDA9885 (PAL, NTSC) 16 TDA9885 (PAL, NTSC)
@@ -44,8 +43,13 @@ MODULE_LICENSE("GPL");
44/* ---------------------------------------------------------------------- */ 43/* ---------------------------------------------------------------------- */
45 44
46#define UNSET (-1U) 45#define UNSET (-1U)
47#define PREFIX "tda9885/6/7: " 46#define tda9887_info(fmt, arg...) do {\
48#define dprintk if (debug) printk 47 printk(KERN_INFO "%s %d-%04x: " fmt, t->client.name, \
48 i2c_adapter_id(t->client.adapter), t->client.addr , ##arg); } while (0)
49#define tda9887_dbg(fmt, arg...) do {\
50 if (debug) \
51 printk(KERN_INFO "%s %d-%04x: " fmt, t->client.name, \
52 i2c_adapter_id(t->client.adapter), t->client.addr , ##arg); } while (0)
49 53
50struct tda9887 { 54struct tda9887 {
51 struct i2c_client client; 55 struct i2c_client client;
@@ -55,6 +59,7 @@ struct tda9887 {
55 unsigned int pinnacle_id; 59 unsigned int pinnacle_id;
56 unsigned int using_v4l2; 60 unsigned int using_v4l2;
57 unsigned int radio_mode; 61 unsigned int radio_mode;
62 unsigned char data[4];
58}; 63};
59 64
60struct tvnorm { 65struct tvnorm {
@@ -180,7 +185,8 @@ static struct tvnorm tvnorms[] = {
180 .name = "SECAM-L", 185 .name = "SECAM-L",
181 .b = ( cPositiveAmTV | 186 .b = ( cPositiveAmTV |
182 cQSS ), 187 cQSS ),
183 .e = ( cAudioIF_6_5 | 188 .e = ( cGating_36 |
189 cAudioIF_6_5 |
184 cVideoIF_38_90 ), 190 cVideoIF_38_90 ),
185 },{ 191 },{
186 .std = V4L2_STD_SECAM_DK, 192 .std = V4L2_STD_SECAM_DK,
@@ -236,7 +242,7 @@ static struct tvnorm radio_mono = {
236 242
237/* ---------------------------------------------------------------------- */ 243/* ---------------------------------------------------------------------- */
238 244
239static void dump_read_message(unsigned char *buf) 245static void dump_read_message(struct tda9887 *t, unsigned char *buf)
240{ 246{
241 static char *afc[16] = { 247 static char *afc[16] = {
242 "- 12.5 kHz", 248 "- 12.5 kHz",
@@ -256,15 +262,15 @@ static void dump_read_message(unsigned char *buf)
256 "+ 37.5 kHz", 262 "+ 37.5 kHz",
257 "+ 12.5 kHz", 263 "+ 12.5 kHz",
258 }; 264 };
259 printk(PREFIX "read: 0x%2x\n", buf[0]); 265 tda9887_info("read: 0x%2x\n", buf[0]);
260 printk(" after power on : %s\n", (buf[0] & 0x01) ? "yes" : "no"); 266 tda9887_info(" after power on : %s\n", (buf[0] & 0x01) ? "yes" : "no");
261 printk(" afc : %s\n", afc[(buf[0] >> 1) & 0x0f]); 267 tda9887_info(" afc : %s\n", afc[(buf[0] >> 1) & 0x0f]);
262 printk(" fmif level : %s\n", (buf[0] & 0x20) ? "high" : "low"); 268 tda9887_info(" fmif level : %s\n", (buf[0] & 0x20) ? "high" : "low");
263 printk(" afc window : %s\n", (buf[0] & 0x40) ? "in" : "out"); 269 tda9887_info(" afc window : %s\n", (buf[0] & 0x40) ? "in" : "out");
264 printk(" vfi level : %s\n", (buf[0] & 0x80) ? "high" : "low"); 270 tda9887_info(" vfi level : %s\n", (buf[0] & 0x80) ? "high" : "low");
265} 271}
266 272
267static void dump_write_message(unsigned char *buf) 273static void dump_write_message(struct tda9887 *t, unsigned char *buf)
268{ 274{
269 static char *sound[4] = { 275 static char *sound[4] = {
270 "AM/TV", 276 "AM/TV",
@@ -304,58 +310,58 @@ static void dump_write_message(unsigned char *buf)
304 "44 MHz", 310 "44 MHz",
305 }; 311 };
306 312
307 printk(PREFIX "write: byte B 0x%02x\n",buf[1]); 313 tda9887_info("write: byte B 0x%02x\n",buf[1]);
308 printk(" B0 video mode : %s\n", 314 tda9887_info(" B0 video mode : %s\n",
309 (buf[1] & 0x01) ? "video trap" : "sound trap"); 315 (buf[1] & 0x01) ? "video trap" : "sound trap");
310 printk(" B1 auto mute fm : %s\n", 316 tda9887_info(" B1 auto mute fm : %s\n",
311 (buf[1] & 0x02) ? "yes" : "no"); 317 (buf[1] & 0x02) ? "yes" : "no");
312 printk(" B2 carrier mode : %s\n", 318 tda9887_info(" B2 carrier mode : %s\n",
313 (buf[1] & 0x04) ? "QSS" : "Intercarrier"); 319 (buf[1] & 0x04) ? "QSS" : "Intercarrier");
314 printk(" B3-4 tv sound/radio : %s\n", 320 tda9887_info(" B3-4 tv sound/radio : %s\n",
315 sound[(buf[1] & 0x18) >> 3]); 321 sound[(buf[1] & 0x18) >> 3]);
316 printk(" B5 force mute audio: %s\n", 322 tda9887_info(" B5 force mute audio: %s\n",
317 (buf[1] & 0x20) ? "yes" : "no"); 323 (buf[1] & 0x20) ? "yes" : "no");
318 printk(" B6 output port 1 : %s\n", 324 tda9887_info(" B6 output port 1 : %s\n",
319 (buf[1] & 0x40) ? "high (inactive)" : "low (active)"); 325 (buf[1] & 0x40) ? "high (inactive)" : "low (active)");
320 printk(" B7 output port 2 : %s\n", 326 tda9887_info(" B7 output port 2 : %s\n",
321 (buf[1] & 0x80) ? "high (inactive)" : "low (active)"); 327 (buf[1] & 0x80) ? "high (inactive)" : "low (active)");
322 328
323 printk(PREFIX "write: byte C 0x%02x\n",buf[2]); 329 tda9887_info("write: byte C 0x%02x\n",buf[2]);
324 printk(" C0-4 top adjustment : %s dB\n", adjust[buf[2] & 0x1f]); 330 tda9887_info(" C0-4 top adjustment : %s dB\n", adjust[buf[2] & 0x1f]);
325 printk(" C5-6 de-emphasis : %s\n", deemph[(buf[2] & 0x60) >> 5]); 331 tda9887_info(" C5-6 de-emphasis : %s\n", deemph[(buf[2] & 0x60) >> 5]);
326 printk(" C7 audio gain : %s\n", 332 tda9887_info(" C7 audio gain : %s\n",
327 (buf[2] & 0x80) ? "-6" : "0"); 333 (buf[2] & 0x80) ? "-6" : "0");
328 334
329 printk(PREFIX "write: byte E 0x%02x\n",buf[3]); 335 tda9887_info("write: byte E 0x%02x\n",buf[3]);
330 printk(" E0-1 sound carrier : %s\n", 336 tda9887_info(" E0-1 sound carrier : %s\n",
331 carrier[(buf[3] & 0x03)]); 337 carrier[(buf[3] & 0x03)]);
332 printk(" E6 l pll ganting : %s\n", 338 tda9887_info(" E6 l pll gating : %s\n",
333 (buf[3] & 0x40) ? "36" : "13"); 339 (buf[3] & 0x40) ? "36" : "13");
334 340
335 if (buf[1] & 0x08) { 341 if (buf[1] & 0x08) {
336 /* radio */ 342 /* radio */
337 printk(" E2-4 video if : %s\n", 343 tda9887_info(" E2-4 video if : %s\n",
338 rif[(buf[3] & 0x0c) >> 2]); 344 rif[(buf[3] & 0x0c) >> 2]);
339 printk(" E7 vif agc output : %s\n", 345 tda9887_info(" E7 vif agc output : %s\n",
340 (buf[3] & 0x80) 346 (buf[3] & 0x80)
341 ? ((buf[3] & 0x10) ? "fm-agc radio" : "sif-agc radio") 347 ? ((buf[3] & 0x10) ? "fm-agc radio" : "sif-agc radio")
342 : "fm radio carrier afc"); 348 : "fm radio carrier afc");
343 } else { 349 } else {
344 /* video */ 350 /* video */
345 printk(" E2-4 video if : %s\n", 351 tda9887_info(" E2-4 video if : %s\n",
346 vif[(buf[3] & 0x1c) >> 2]); 352 vif[(buf[3] & 0x1c) >> 2]);
347 printk(" E5 tuner gain : %s\n", 353 tda9887_info(" E5 tuner gain : %s\n",
348 (buf[3] & 0x80) 354 (buf[3] & 0x80)
349 ? ((buf[3] & 0x20) ? "external" : "normal") 355 ? ((buf[3] & 0x20) ? "external" : "normal")
350 : ((buf[3] & 0x20) ? "minimum" : "normal")); 356 : ((buf[3] & 0x20) ? "minimum" : "normal"));
351 printk(" E7 vif agc output : %s\n", 357 tda9887_info(" E7 vif agc output : %s\n",
352 (buf[3] & 0x80) 358 (buf[3] & 0x80)
353 ? ((buf[3] & 0x20) 359 ? ((buf[3] & 0x20)
354 ? "pin3 port, pin22 vif agc out" 360 ? "pin3 port, pin22 vif agc out"
355 : "pin22 port, pin3 vif acg ext in") 361 : "pin22 port, pin3 vif acg ext in")
356 : "pin3+pin22 port"); 362 : "pin3+pin22 port");
357 } 363 }
358 printk("--\n"); 364 tda9887_info("--\n");
359} 365}
360 366
361/* ---------------------------------------------------------------------- */ 367/* ---------------------------------------------------------------------- */
@@ -379,11 +385,11 @@ static int tda9887_set_tvnorm(struct tda9887 *t, char *buf)
379 } 385 }
380 } 386 }
381 if (NULL == norm) { 387 if (NULL == norm) {
382 dprintk(PREFIX "Unsupported tvnorm entry - audio muted\n"); 388 tda9887_dbg("Unsupported tvnorm entry - audio muted\n");
383 return -1; 389 return -1;
384 } 390 }
385 391
386 dprintk(PREFIX "configure for: %s\n",norm->name); 392 tda9887_dbg("configure for: %s\n",norm->name);
387 buf[1] = norm->b; 393 buf[1] = norm->b;
388 buf[2] = norm->c; 394 buf[2] = norm->c;
389 buf[3] = norm->e; 395 buf[3] = norm->e;
@@ -458,6 +464,8 @@ static int tda9887_set_config(struct tda9887 *t, char *buf)
458 break; 464 break;
459 } 465 }
460 } 466 }
467 if ((t->config & TDA9887_INTERCARRIER_NTSC) && (t->std & V4L2_STD_NTSC))
468 buf[1] &= ~cQSS;
461 return 0; 469 return 0;
462} 470}
463 471
@@ -475,11 +483,11 @@ static int tda9887_set_pinnacle(struct tda9887 *t, char *buf)
475 } 483 }
476 } 484 }
477 if (t->std & V4L2_STD_525_60) { 485 if (t->std & V4L2_STD_525_60) {
478 if ((5 == t->pinnacle_id) || (6 == t->pinnacle_id)) { 486 if ((5 == t->pinnacle_id) || (6 == t->pinnacle_id)) {
479 bCarrierMode = cIntercarrier; 487 bCarrierMode = cIntercarrier;
480 } else { 488 } else {
481 bCarrierMode = cQSS; 489 bCarrierMode = cQSS;
482 } 490 }
483 } 491 }
484 492
485 if (bCarrierMode != UNSET) { 493 if (bCarrierMode != UNSET) {
@@ -505,26 +513,26 @@ static int tda9887_fixup_std(struct tda9887 *t)
505 case 'B': 513 case 'B':
506 case 'g': 514 case 'g':
507 case 'G': 515 case 'G':
508 dprintk(PREFIX "insmod fixup: PAL => PAL-BG\n"); 516 tda9887_dbg("insmod fixup: PAL => PAL-BG\n");
509 t->std = V4L2_STD_PAL_BG; 517 t->std = V4L2_STD_PAL_BG;
510 break; 518 break;
511 case 'i': 519 case 'i':
512 case 'I': 520 case 'I':
513 dprintk(PREFIX "insmod fixup: PAL => PAL-I\n"); 521 tda9887_dbg("insmod fixup: PAL => PAL-I\n");
514 t->std = V4L2_STD_PAL_I; 522 t->std = V4L2_STD_PAL_I;
515 break; 523 break;
516 case 'd': 524 case 'd':
517 case 'D': 525 case 'D':
518 case 'k': 526 case 'k':
519 case 'K': 527 case 'K':
520 dprintk(PREFIX "insmod fixup: PAL => PAL-DK\n"); 528 tda9887_dbg("insmod fixup: PAL => PAL-DK\n");
521 t->std = V4L2_STD_PAL_DK; 529 t->std = V4L2_STD_PAL_DK;
522 break; 530 break;
523 case '-': 531 case '-':
524 /* default parameter, do nothing */ 532 /* default parameter, do nothing */
525 break; 533 break;
526 default: 534 default:
527 printk(PREFIX "pal= argument not recognised\n"); 535 tda9887_info("pal= argument not recognised\n");
528 break; 536 break;
529 } 537 }
530 } 538 }
@@ -534,19 +542,19 @@ static int tda9887_fixup_std(struct tda9887 *t)
534 case 'D': 542 case 'D':
535 case 'k': 543 case 'k':
536 case 'K': 544 case 'K':
537 dprintk(PREFIX "insmod fixup: SECAM => SECAM-DK\n"); 545 tda9887_dbg("insmod fixup: SECAM => SECAM-DK\n");
538 t->std = V4L2_STD_SECAM_DK; 546 t->std = V4L2_STD_SECAM_DK;
539 break; 547 break;
540 case 'l': 548 case 'l':
541 case 'L': 549 case 'L':
542 dprintk(PREFIX "insmod fixup: SECAM => SECAM-L\n"); 550 tda9887_dbg("insmod fixup: SECAM => SECAM-L\n");
543 t->std = V4L2_STD_SECAM_L; 551 t->std = V4L2_STD_SECAM_L;
544 break; 552 break;
545 case '-': 553 case '-':
546 /* default parameter, do nothing */ 554 /* default parameter, do nothing */
547 break; 555 break;
548 default: 556 default:
549 printk(PREFIX "secam= argument not recognised\n"); 557 tda9887_info("secam= argument not recognised\n");
550 break; 558 break;
551 } 559 }
552 } 560 }
@@ -559,41 +567,40 @@ static int tda9887_status(struct tda9887 *t)
559 int rc; 567 int rc;
560 568
561 memset(buf,0,sizeof(buf)); 569 memset(buf,0,sizeof(buf));
562 if (1 != (rc = i2c_master_recv(&t->client,buf,1))) 570 if (1 != (rc = i2c_master_recv(&t->client,buf,1)))
563 printk(PREFIX "i2c i/o error: rc == %d (should be 1)\n",rc); 571 tda9887_info("i2c i/o error: rc == %d (should be 1)\n",rc);
564 dump_read_message(buf); 572 dump_read_message(t, buf);
565 return 0; 573 return 0;
566} 574}
567 575
568static int tda9887_configure(struct tda9887 *t) 576static int tda9887_configure(struct tda9887 *t)
569{ 577{
570 unsigned char buf[4];
571 int rc; 578 int rc;
572 579
573 memset(buf,0,sizeof(buf)); 580 memset(t->data,0,sizeof(t->data));
574 tda9887_set_tvnorm(t,buf); 581 tda9887_set_tvnorm(t,t->data);
575 582
576 buf[1] |= cOutputPort1Inactive; 583 t->data[1] |= cOutputPort1Inactive;
577 buf[1] |= cOutputPort2Inactive; 584 t->data[1] |= cOutputPort2Inactive;
578 585
579 if (UNSET != t->pinnacle_id) { 586 if (UNSET != t->pinnacle_id) {
580 tda9887_set_pinnacle(t,buf); 587 tda9887_set_pinnacle(t,t->data);
581 } 588 }
582 tda9887_set_config(t,buf); 589 tda9887_set_config(t,t->data);
583 tda9887_set_insmod(t,buf); 590 tda9887_set_insmod(t,t->data);
584 591
585 if (t->mode == T_STANDBY) { 592 if (t->mode == T_STANDBY) {
586 buf[1] |= cForcedMuteAudioON; 593 t->data[1] |= cForcedMuteAudioON;
587 } 594 }
588 595
589 596
590 dprintk(PREFIX "writing: b=0x%02x c=0x%02x e=0x%02x\n", 597 tda9887_dbg("writing: b=0x%02x c=0x%02x e=0x%02x\n",
591 buf[1],buf[2],buf[3]); 598 t->data[1],t->data[2],t->data[3]);
592 if (debug > 1) 599 if (debug > 1)
593 dump_write_message(buf); 600 dump_write_message(t, t->data);
594 601
595 if (4 != (rc = i2c_master_send(&t->client,buf,4))) 602 if (4 != (rc = i2c_master_send(&t->client,t->data,4)))
596 printk(PREFIX "i2c i/o error: rc == %d (should be 4)\n",rc); 603 tda9887_info("i2c i/o error: rc == %d (should be 4)\n",rc);
597 604
598 if (debug > 2) { 605 if (debug > 2) {
599 msleep_interruptible(1000); 606 msleep_interruptible(1000);
@@ -608,13 +615,11 @@ static int tda9887_attach(struct i2c_adapter *adap, int addr, int kind)
608{ 615{
609 struct tda9887 *t; 616 struct tda9887 *t;
610 617
611 client_template.adapter = adap; 618 client_template.adapter = adap;
612 client_template.addr = addr; 619 client_template.addr = addr;
613
614 printk(PREFIX "chip found @ 0x%x\n", addr<<1);
615 620
616 if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL))) 621 if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL)))
617 return -ENOMEM; 622 return -ENOMEM;
618 memset(t,0,sizeof(*t)); 623 memset(t,0,sizeof(*t));
619 624
620 t->client = client_template; 625 t->client = client_template;
@@ -622,6 +627,8 @@ static int tda9887_attach(struct i2c_adapter *adap, int addr, int kind)
622 t->pinnacle_id = UNSET; 627 t->pinnacle_id = UNSET;
623 t->radio_mode = V4L2_TUNER_MODE_STEREO; 628 t->radio_mode = V4L2_TUNER_MODE_STEREO;
624 629
630 tda9887_info("chip found @ 0x%x (%s)\n", addr<<1, adap->name);
631
625 i2c_set_clientdata(&t->client, t); 632 i2c_set_clientdata(&t->client, t);
626 i2c_attach_client(&t->client); 633 i2c_attach_client(&t->client);
627 634
@@ -655,18 +662,18 @@ static int tda9887_detach(struct i2c_client *client)
655} 662}
656 663
657#define SWITCH_V4L2 if (!t->using_v4l2 && debug) \ 664#define SWITCH_V4L2 if (!t->using_v4l2 && debug) \
658 printk(PREFIX "switching to v4l2\n"); \ 665 tda9887_info("switching to v4l2\n"); \
659 t->using_v4l2 = 1; 666 t->using_v4l2 = 1;
660#define CHECK_V4L2 if (t->using_v4l2) { if (debug) \ 667#define CHECK_V4L2 if (t->using_v4l2) { if (debug) \
661 printk(PREFIX "ignore v4l1 call\n"); \ 668 tda9887_info("ignore v4l1 call\n"); \
662 return 0; } 669 return 0; }
663 670
664static int 671static int
665tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg) 672tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
666{ 673{
667 struct tda9887 *t = i2c_get_clientdata(client); 674 struct tda9887 *t = i2c_get_clientdata(client);
668 675
669 switch (cmd) { 676 switch (cmd) {
670 677
671 /* --- configuration --- */ 678 /* --- configuration --- */
672 case AUDC_SET_RADIO: 679 case AUDC_SET_RADIO:
@@ -777,6 +784,11 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
777 } 784 }
778 break; 785 break;
779 } 786 }
787 case VIDIOC_LOG_STATUS:
788 {
789 tda9887_info("Data bytes: b=%02x c=%02x e=%02x\n", t->data[1], t->data[2], t->data[3]);
790 break;
791 }
780 default: 792 default:
781 /* nothing */ 793 /* nothing */
782 break; 794 break;
@@ -786,7 +798,10 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
786 798
787static int tda9887_suspend(struct device * dev, pm_message_t state) 799static int tda9887_suspend(struct device * dev, pm_message_t state)
788{ 800{
789 dprintk("tda9887: suspend\n"); 801 struct i2c_client *c = container_of(dev, struct i2c_client, dev);
802 struct tda9887 *t = i2c_get_clientdata(c);
803
804 tda9887_dbg("suspend\n");
790 return 0; 805 return 0;
791} 806}
792 807
@@ -795,7 +810,7 @@ static int tda9887_resume(struct device * dev)
795 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 810 struct i2c_client *c = container_of(dev, struct i2c_client, dev);
796 struct tda9887 *t = i2c_get_clientdata(c); 811 struct tda9887 *t = i2c_get_clientdata(c);
797 812
798 dprintk("tda9887: resume\n"); 813 tda9887_dbg("resume\n");
799 tda9887_configure(t); 814 tda9887_configure(t);
800 return 0; 815 return 0;
801} 816}