aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/msp3400-kthreads.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/msp3400-kthreads.c')
-rw-r--r--drivers/media/video/msp3400-kthreads.c121
1 files changed, 64 insertions, 57 deletions
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index c3984ea9ca07..633a10213789 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -170,7 +170,7 @@ static void msp_set_source(struct i2c_client *client, u16 src)
170 msp_write_dsp(client, 0x000a, src); 170 msp_write_dsp(client, 0x000a, src);
171 msp_write_dsp(client, 0x000b, src); 171 msp_write_dsp(client, 0x000b, src);
172 msp_write_dsp(client, 0x000c, src); 172 msp_write_dsp(client, 0x000c, src);
173 if (state->has_scart23_in_scart2_out) 173 if (state->has_scart2_out)
174 msp_write_dsp(client, 0x0041, src); 174 msp_write_dsp(client, 0x0041, src);
175} 175}
176 176
@@ -228,6 +228,7 @@ static void msp3400c_set_audmode(struct i2c_client *client)
228 char *modestr = (state->audmode >= 0 && state->audmode < 5) ? 228 char *modestr = (state->audmode >= 0 && state->audmode < 5) ?
229 strmode[state->audmode] : "unknown"; 229 strmode[state->audmode] : "unknown";
230 int src = 0; /* channel source: FM/AM, nicam or SCART */ 230 int src = 0; /* channel source: FM/AM, nicam or SCART */
231 int audmode = state->audmode;
231 232
232 if (state->opmode == OPMODE_AUTOSELECT) { 233 if (state->opmode == OPMODE_AUTOSELECT) {
233 /* this method would break everything, let's make sure 234 /* this method would break everything, let's make sure
@@ -239,11 +240,29 @@ static void msp3400c_set_audmode(struct i2c_client *client)
239 return; 240 return;
240 } 241 }
241 242
243 /* Note: for the C and D revs no NTSC stereo + SAP is possible as
244 the hardware does not support SAP. So the rxsubchans combination
245 of STEREO | LANG2 does not occur. */
246
247 /* switch to mono if only mono is available */
248 if (state->rxsubchans == V4L2_TUNER_SUB_MONO)
249 audmode = V4L2_TUNER_MODE_MONO;
250 /* if bilingual */
251 else if (state->rxsubchans & V4L2_TUNER_SUB_LANG2) {
252 /* and mono or stereo, then fallback to lang1 */
253 if (audmode == V4L2_TUNER_MODE_MONO ||
254 audmode == V4L2_TUNER_MODE_STEREO)
255 audmode = V4L2_TUNER_MODE_LANG1;
256 }
257 /* if stereo, and audmode is not mono, then switch to stereo */
258 else if (audmode != V4L2_TUNER_MODE_MONO)
259 audmode = V4L2_TUNER_MODE_STEREO;
260
242 /* switch demodulator */ 261 /* switch demodulator */
243 switch (state->mode) { 262 switch (state->mode) {
244 case MSP_MODE_FM_TERRA: 263 case MSP_MODE_FM_TERRA:
245 v4l_dbg(1, msp_debug, client, "FM set_audmode: %s\n", modestr); 264 v4l_dbg(1, msp_debug, client, "FM set_audmode: %s\n", modestr);
246 switch (state->audmode) { 265 switch (audmode) {
247 case V4L2_TUNER_MODE_STEREO: 266 case V4L2_TUNER_MODE_STEREO:
248 msp_write_dsp(client, 0x000e, 0x3001); 267 msp_write_dsp(client, 0x000e, 0x3001);
249 break; 268 break;
@@ -257,7 +276,7 @@ static void msp3400c_set_audmode(struct i2c_client *client)
257 break; 276 break;
258 case MSP_MODE_FM_SAT: 277 case MSP_MODE_FM_SAT:
259 v4l_dbg(1, msp_debug, client, "SAT set_audmode: %s\n", modestr); 278 v4l_dbg(1, msp_debug, client, "SAT set_audmode: %s\n", modestr);
260 switch (state->audmode) { 279 switch (audmode) {
261 case V4L2_TUNER_MODE_MONO: 280 case V4L2_TUNER_MODE_MONO:
262 msp3400c_set_carrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5)); 281 msp3400c_set_carrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
263 break; 282 break;
@@ -296,7 +315,8 @@ static void msp3400c_set_audmode(struct i2c_client *client)
296 } 315 }
297 316
298 /* switch audio */ 317 /* switch audio */
299 switch (state->audmode) { 318 v4l_dbg(1, msp_debug, client, "set audmode %d\n", audmode);
319 switch (audmode) {
300 case V4L2_TUNER_MODE_STEREO: 320 case V4L2_TUNER_MODE_STEREO:
301 case V4L2_TUNER_MODE_LANG1_LANG2: 321 case V4L2_TUNER_MODE_LANG1_LANG2:
302 src |= 0x0020; 322 src |= 0x0020;
@@ -314,10 +334,6 @@ static void msp3400c_set_audmode(struct i2c_client *client)
314 src = 0x0030; 334 src = 0x0030;
315 break; 335 break;
316 case V4L2_TUNER_MODE_LANG1: 336 case V4L2_TUNER_MODE_LANG1:
317 /* switch to stereo for stereo transmission, otherwise
318 keep first language */
319 if (state->rxsubchans & V4L2_TUNER_SUB_STEREO)
320 src |= 0x0020;
321 break; 337 break;
322 case V4L2_TUNER_MODE_LANG2: 338 case V4L2_TUNER_MODE_LANG2:
323 src |= 0x0010; 339 src |= 0x0010;
@@ -367,7 +383,7 @@ static int msp3400c_detect_stereo(struct i2c_client *client)
367 if (val > 32767) 383 if (val > 32767)
368 val -= 65536; 384 val -= 65536;
369 v4l_dbg(2, msp_debug, client, "stereo detect register: %d\n", val); 385 v4l_dbg(2, msp_debug, client, "stereo detect register: %d\n", val);
370 if (val > 4096) { 386 if (val > 8192) {
371 rxsubchans = V4L2_TUNER_SUB_STEREO; 387 rxsubchans = V4L2_TUNER_SUB_STEREO;
372 } else if (val < -4096) { 388 } else if (val < -4096) {
373 rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 389 rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
@@ -464,19 +480,22 @@ int msp3400c_thread(void *data)
464 if (state->radio || MSP_MODE_EXTERN == state->mode) { 480 if (state->radio || MSP_MODE_EXTERN == state->mode) {
465 /* no carrier scan, just unmute */ 481 /* no carrier scan, just unmute */
466 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n"); 482 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n");
483 state->scan_in_progress = 0;
467 msp_set_audio(client); 484 msp_set_audio(client);
468 continue; 485 continue;
469 } 486 }
470 487
471 /* mute */ 488 /* mute audio */
472 msp_set_mute(client); 489 state->scan_in_progress = 1;
490 msp_set_audio(client);
491
473 msp3400c_set_mode(client, MSP_MODE_AM_DETECT); 492 msp3400c_set_mode(client, MSP_MODE_AM_DETECT);
474 val1 = val2 = 0; 493 val1 = val2 = 0;
475 max1 = max2 = -1; 494 max1 = max2 = -1;
476 state->watch_stereo = 0; 495 state->watch_stereo = 0;
477 state->nicam_on = 0; 496 state->nicam_on = 0;
478 497
479 /* some time for the tuner to sync */ 498 /* wait for tuner to settle down after a channel change */
480 if (msp_sleep(state, 200)) 499 if (msp_sleep(state, 200))
481 goto restart; 500 goto restart;
482 501
@@ -552,7 +571,6 @@ int msp3400c_thread(void *data)
552 /* B/G NICAM */ 571 /* B/G NICAM */
553 state->second = msp3400c_carrier_detect_55[max2].cdo; 572 state->second = msp3400c_carrier_detect_55[max2].cdo;
554 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1); 573 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1);
555 msp3400c_set_carrier(client, state->second, state->main);
556 state->nicam_on = 1; 574 state->nicam_on = 1;
557 state->watch_stereo = 1; 575 state->watch_stereo = 1;
558 } else { 576 } else {
@@ -563,7 +581,6 @@ int msp3400c_thread(void *data)
563 /* PAL I NICAM */ 581 /* PAL I NICAM */
564 state->second = MSP_CARRIER(6.552); 582 state->second = MSP_CARRIER(6.552);
565 msp3400c_set_mode(client, MSP_MODE_FM_NICAM2); 583 msp3400c_set_mode(client, MSP_MODE_FM_NICAM2);
566 msp3400c_set_carrier(client, state->second, state->main);
567 state->nicam_on = 1; 584 state->nicam_on = 1;
568 state->watch_stereo = 1; 585 state->watch_stereo = 1;
569 break; 586 break;
@@ -577,13 +594,11 @@ int msp3400c_thread(void *data)
577 /* L NICAM or AM-mono */ 594 /* L NICAM or AM-mono */
578 state->second = msp3400c_carrier_detect_65[max2].cdo; 595 state->second = msp3400c_carrier_detect_65[max2].cdo;
579 msp3400c_set_mode(client, MSP_MODE_AM_NICAM); 596 msp3400c_set_mode(client, MSP_MODE_AM_NICAM);
580 msp3400c_set_carrier(client, state->second, state->main);
581 state->watch_stereo = 1; 597 state->watch_stereo = 1;
582 } else if (max2 == 0 && state->has_nicam) { 598 } else if (max2 == 0 && state->has_nicam) {
583 /* D/K NICAM */ 599 /* D/K NICAM */
584 state->second = msp3400c_carrier_detect_65[max2].cdo; 600 state->second = msp3400c_carrier_detect_65[max2].cdo;
585 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1); 601 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1);
586 msp3400c_set_carrier(client, state->second, state->main);
587 state->nicam_on = 1; 602 state->nicam_on = 1;
588 state->watch_stereo = 1; 603 state->watch_stereo = 1;
589 } else { 604 } else {
@@ -595,25 +610,25 @@ int msp3400c_thread(void *data)
595 no_second: 610 no_second:
596 state->second = msp3400c_carrier_detect_main[max1].cdo; 611 state->second = msp3400c_carrier_detect_main[max1].cdo;
597 msp3400c_set_mode(client, MSP_MODE_FM_TERRA); 612 msp3400c_set_mode(client, MSP_MODE_FM_TERRA);
598 msp3400c_set_carrier(client, state->second, state->main);
599 state->rxsubchans = V4L2_TUNER_SUB_MONO;
600 break; 613 break;
601 } 614 }
615 msp3400c_set_carrier(client, state->second, state->main);
602 616
603 /* unmute */ 617 /* unmute */
604 msp_set_audio(client); 618 state->scan_in_progress = 0;
605 msp3400c_set_audmode(client); 619 msp3400c_set_audmode(client);
620 msp_set_audio(client);
606 621
607 if (msp_debug) 622 if (msp_debug)
608 msp3400c_print_mode(client); 623 msp3400c_print_mode(client);
609 624
610 /* monitor tv audio mode, the first time don't wait 625 /* monitor tv audio mode, the first time don't wait
611 so long to get a quick stereo/bilingual result */ 626 so long to get a quick stereo/bilingual result */
612 if (msp_sleep(state, 1000)) 627 count = 3;
613 goto restart;
614 while (state->watch_stereo) { 628 while (state->watch_stereo) {
615 if (msp_sleep(state, 5000)) 629 if (msp_sleep(state, count ? 1000 : 5000))
616 goto restart; 630 goto restart;
631 if (count) count--;
617 watch_stereo(client); 632 watch_stereo(client);
618 } 633 }
619 } 634 }
@@ -626,7 +641,7 @@ int msp3410d_thread(void *data)
626{ 641{
627 struct i2c_client *client = data; 642 struct i2c_client *client = data;
628 struct msp_state *state = i2c_get_clientdata(client); 643 struct msp_state *state = i2c_get_clientdata(client);
629 int val, i, std; 644 int val, i, std, count;
630 645
631 v4l_dbg(1, msp_debug, client, "msp3410 daemon started\n"); 646 v4l_dbg(1, msp_debug, client, "msp3410 daemon started\n");
632 647
@@ -644,16 +659,14 @@ int msp3410d_thread(void *data)
644 if (state->mode == MSP_MODE_EXTERN) { 659 if (state->mode == MSP_MODE_EXTERN) {
645 /* no carrier scan needed, just unmute */ 660 /* no carrier scan needed, just unmute */
646 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n"); 661 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n");
662 state->scan_in_progress = 0;
647 msp_set_audio(client); 663 msp_set_audio(client);
648 continue; 664 continue;
649 } 665 }
650 666
651 /* put into sane state (and mute) */ 667 /* mute audio */
652 msp_reset(client); 668 state->scan_in_progress = 1;
653 669 msp_set_audio(client);
654 /* some time for the tuner to sync */
655 if (msp_sleep(state,200))
656 goto restart;
657 670
658 /* start autodetect. Note: autodetect is not supported for 671 /* start autodetect. Note: autodetect is not supported for
659 NTSC-M and radio, hence we force the standard in those cases. */ 672 NTSC-M and radio, hence we force the standard in those cases. */
@@ -664,6 +677,10 @@ int msp3410d_thread(void *data)
664 state->watch_stereo = 0; 677 state->watch_stereo = 0;
665 state->nicam_on = 0; 678 state->nicam_on = 0;
666 679
680 /* wait for tuner to settle down after a channel change */
681 if (msp_sleep(state, 200))
682 goto restart;
683
667 if (msp_debug) 684 if (msp_debug)
668 v4l_dbg(2, msp_debug, client, "setting standard: %s (0x%04x)\n", 685 v4l_dbg(2, msp_debug, client, "setting standard: %s (0x%04x)\n",
669 msp_standard_std_name(std), std); 686 msp_standard_std_name(std), std);
@@ -693,6 +710,7 @@ int msp3410d_thread(void *data)
693 state->main = msp_stdlist[i].main; 710 state->main = msp_stdlist[i].main;
694 state->second = msp_stdlist[i].second; 711 state->second = msp_stdlist[i].second;
695 state->std = val; 712 state->std = val;
713 state->rxsubchans = V4L2_TUNER_SUB_MONO;
696 714
697 if (msp_amsound && !state->radio && (state->v4l2_std & V4L2_STD_SECAM) && 715 if (msp_amsound && !state->radio && (state->v4l2_std & V4L2_STD_SECAM) &&
698 (val != 0x0009)) { 716 (val != 0x0009)) {
@@ -714,20 +732,17 @@ int msp3410d_thread(void *data)
714 else 732 else
715 state->mode = MSP_MODE_FM_NICAM1; 733 state->mode = MSP_MODE_FM_NICAM1;
716 /* just turn on stereo */ 734 /* just turn on stereo */
717 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
718 state->nicam_on = 1; 735 state->nicam_on = 1;
719 state->watch_stereo = 1; 736 state->watch_stereo = 1;
720 break; 737 break;
721 case 0x0009: 738 case 0x0009:
722 state->mode = MSP_MODE_AM_NICAM; 739 state->mode = MSP_MODE_AM_NICAM;
723 state->rxsubchans = V4L2_TUNER_SUB_MONO;
724 state->nicam_on = 1; 740 state->nicam_on = 1;
725 state->watch_stereo = 1; 741 state->watch_stereo = 1;
726 break; 742 break;
727 case 0x0020: /* BTSC */ 743 case 0x0020: /* BTSC */
728 /* The pre-'G' models only have BTSC-mono */ 744 /* The pre-'G' models only have BTSC-mono */
729 state->mode = MSP_MODE_BTSC; 745 state->mode = MSP_MODE_BTSC;
730 state->rxsubchans = V4L2_TUNER_SUB_MONO;
731 break; 746 break;
732 case 0x0040: /* FM radio */ 747 case 0x0040: /* FM radio */
733 state->mode = MSP_MODE_FM_RADIO; 748 state->mode = MSP_MODE_FM_RADIO;
@@ -737,15 +752,12 @@ int msp3410d_thread(void *data)
737 msp3400c_set_mode(client, MSP_MODE_FM_RADIO); 752 msp3400c_set_mode(client, MSP_MODE_FM_RADIO);
738 msp3400c_set_carrier(client, MSP_CARRIER(10.7), 753 msp3400c_set_carrier(client, MSP_CARRIER(10.7),
739 MSP_CARRIER(10.7)); 754 MSP_CARRIER(10.7));
740 /* scart routing (this doesn't belong here I think) */
741 msp_set_scart(client,SCART_IN2,0);
742 break; 755 break;
743 case 0x0002: 756 case 0x0002:
744 case 0x0003: 757 case 0x0003:
745 case 0x0004: 758 case 0x0004:
746 case 0x0005: 759 case 0x0005:
747 state->mode = MSP_MODE_FM_TERRA; 760 state->mode = MSP_MODE_FM_TERRA;
748 state->rxsubchans = V4L2_TUNER_SUB_MONO;
749 state->watch_stereo = 1; 761 state->watch_stereo = 1;
750 break; 762 break;
751 } 763 }
@@ -759,20 +771,19 @@ int msp3410d_thread(void *data)
759 if (state->has_i2s_conf) 771 if (state->has_i2s_conf)
760 msp_write_dem(client, 0x40, state->i2s_mode); 772 msp_write_dem(client, 0x40, state->i2s_mode);
761 773
762 /* unmute, restore misc registers */ 774 /* unmute */
763 msp_set_audio(client);
764
765 msp_write_dsp(client, 0x13, state->acb);
766 msp3400c_set_audmode(client); 775 msp3400c_set_audmode(client);
776 state->scan_in_progress = 0;
777 msp_set_audio(client);
767 778
768 /* monitor tv audio mode, the first time don't wait 779 /* monitor tv audio mode, the first time don't wait
769 so long to get a quick stereo/bilingual result */ 780 so long to get a quick stereo/bilingual result */
770 if (msp_sleep(state, 1000)) 781 count = 3;
771 goto restart;
772 while (state->watch_stereo) { 782 while (state->watch_stereo) {
773 watch_stereo(client); 783 if (msp_sleep(state, count ? 1000 : 5000))
774 if (msp_sleep(state, 5000))
775 goto restart; 784 goto restart;
785 if (count) count--;
786 watch_stereo(client);
776 } 787 }
777 } 788 }
778 v4l_dbg(1, msp_debug, client, "thread: exit\n"); 789 v4l_dbg(1, msp_debug, client, "thread: exit\n");
@@ -829,27 +840,27 @@ static void msp34xxg_set_source(struct i2c_client *client, u16 reg, int in)
829 source = 0; /* mono only */ 840 source = 0; /* mono only */
830 matrix = 0x30; 841 matrix = 0x30;
831 break; 842 break;
832 case V4L2_TUNER_MODE_LANG1:
833 source = 3; /* stereo or A */
834 matrix = 0x00;
835 break;
836 case V4L2_TUNER_MODE_LANG2: 843 case V4L2_TUNER_MODE_LANG2:
837 source = 4; /* stereo or B */ 844 source = 4; /* stereo or B */
838 matrix = 0x10; 845 matrix = 0x10;
839 break; 846 break;
840 case V4L2_TUNER_MODE_STEREO:
841 case V4L2_TUNER_MODE_LANG1_LANG2: 847 case V4L2_TUNER_MODE_LANG1_LANG2:
842 default:
843 source = 1; /* stereo or A|B */ 848 source = 1; /* stereo or A|B */
844 matrix = 0x20; 849 matrix = 0x20;
845 break; 850 break;
851 case V4L2_TUNER_MODE_STEREO:
852 case V4L2_TUNER_MODE_LANG1:
853 default:
854 source = 3; /* stereo or A */
855 matrix = 0x00;
856 break;
846 } 857 }
847 858
848 if (in == MSP_DSP_OUT_TUNER) 859 if (in == MSP_DSP_IN_TUNER)
849 source = (source << 8) | 0x20; 860 source = (source << 8) | 0x20;
850 /* the msp34x2g puts the MAIN_AVC, MAIN and AUX sources in 12, 13, 14 861 /* the msp34x2g puts the MAIN_AVC, MAIN and AUX sources in 12, 13, 14
851 instead of 11, 12, 13. So we add one for that msp version. */ 862 instead of 11, 12, 13. So we add one for that msp version. */
852 else if (in >= MSP_DSP_OUT_MAIN_AVC && state->has_dolby_pro_logic) 863 else if (in >= MSP_DSP_IN_MAIN_AVC && state->has_dolby_pro_logic)
853 source = ((in + 1) << 8) | matrix; 864 source = ((in + 1) << 8) | matrix;
854 else 865 else
855 source = (in << 8) | matrix; 866 source = (in << 8) | matrix;
@@ -869,7 +880,7 @@ static void msp34xxg_set_sources(struct i2c_client *client)
869 msp34xxg_set_source(client, 0x000c, (in >> 4) & 0xf); 880 msp34xxg_set_source(client, 0x000c, (in >> 4) & 0xf);
870 msp34xxg_set_source(client, 0x0009, (in >> 8) & 0xf); 881 msp34xxg_set_source(client, 0x0009, (in >> 8) & 0xf);
871 msp34xxg_set_source(client, 0x000a, (in >> 12) & 0xf); 882 msp34xxg_set_source(client, 0x000a, (in >> 12) & 0xf);
872 if (state->has_scart23_in_scart2_out) 883 if (state->has_scart2_out)
873 msp34xxg_set_source(client, 0x0041, (in >> 16) & 0xf); 884 msp34xxg_set_source(client, 0x0041, (in >> 16) & 0xf);
874 msp34xxg_set_source(client, 0x000b, (in >> 20) & 0xf); 885 msp34xxg_set_source(client, 0x000b, (in >> 20) & 0xf);
875} 886}
@@ -887,10 +898,6 @@ static void msp34xxg_reset(struct i2c_client *client)
887 898
888 msp_reset(client); 899 msp_reset(client);
889 900
890 /* make sure that input/output is muted (paranoid mode) */
891 /* ACB, mute DSP input, mute SCART 1 */
892 msp_write_dsp(client, 0x13, 0x0f20);
893
894 if (state->has_i2s_conf) 901 if (state->has_i2s_conf)
895 msp_write_dem(client, 0x40, state->i2s_mode); 902 msp_write_dem(client, 0x40, state->i2s_mode);
896 903
@@ -1028,7 +1035,7 @@ static void msp34xxg_set_audmode(struct i2c_client *client)
1028 1035
1029 if (state->std == 0x20) { 1036 if (state->std == 0x20) {
1030 if ((state->rxsubchans & V4L2_TUNER_SUB_SAP) && 1037 if ((state->rxsubchans & V4L2_TUNER_SUB_SAP) &&
1031 (state->audmode == V4L2_TUNER_MODE_STEREO || 1038 (state->audmode == V4L2_TUNER_MODE_LANG1_LANG2 ||
1032 state->audmode == V4L2_TUNER_MODE_LANG2)) { 1039 state->audmode == V4L2_TUNER_MODE_LANG2)) {
1033 msp_write_dem(client, 0x20, 0x21); 1040 msp_write_dem(client, 0x20, 0x21);
1034 } else { 1041 } else {