Skip to content

Commit 5af0c8f

Browse files
hverkuilMauro Carvalho Chehab
authored andcommitted
V4L/DVB (3326): Fix stereo and standard reporting of msp3400 (esp. for radio)
- Add VIDIOC_LOG_STATUS to the radio device ioctl list. - Reduce the confusion between modes and standards - Fix stereo reporting for radio. - Don't set i2c configuration if the chip doesn't support it. - Fix reporting of current standard for radio. Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 5b0fa4f commit 5af0c8f

File tree

4 files changed

+100
-59
lines changed

4 files changed

+100
-59
lines changed

drivers/media/video/bttv-driver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,6 +3220,7 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
32203220
case VIDIOCSFREQ:
32213221
case VIDIOCGAUDIO:
32223222
case VIDIOCSAUDIO:
3223+
case VIDIOC_LOG_STATUS:
32233224
return bttv_common_ioctls(btv,cmd,arg);
32243225

32253226
default:

drivers/media/video/msp3400-driver.c

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ int msp_modus(struct i2c_client *client)
345345
return 0x0003;
346346
}
347347

348-
if (state->std & V4L2_STD_PAL) {
348+
if (state->v4l2_std & V4L2_STD_PAL) {
349349
v4l_dbg(1, client, "video mode selected to PAL\n");
350350

351351
#if 1
@@ -356,11 +356,11 @@ int msp_modus(struct i2c_client *client)
356356
return 0x1003;
357357
#endif
358358
}
359-
if (state->std & V4L2_STD_NTSC) {
359+
if (state->v4l2_std & V4L2_STD_NTSC) {
360360
v4l_dbg(1, client, "video mode selected to NTSC\n");
361361
return 0x2003;
362362
}
363-
if (state->std & V4L2_STD_SECAM) {
363+
if (state->v4l2_std & V4L2_STD_SECAM) {
364364
v4l_dbg(1, client, "video mode selected to SECAM\n");
365365
return 0x0003;
366366
}
@@ -663,6 +663,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
663663
break;
664664

665665
case AUDC_SET_RADIO:
666+
if (state->radio)
667+
return 0;
666668
state->radio = 1;
667669
v4l_dbg(1, client, "switching to radio mode\n");
668670
state->watch_stereo = 0;
@@ -701,6 +703,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
701703
va->bass = state->bass;
702704
va->treble = state->treble;
703705

706+
if (state->radio)
707+
break;
704708
if (state->opmode == OPMODE_AUTOSELECT)
705709
msp_any_detect_stereo(client);
706710
va->mode = msp_mode_v4l2_to_v4l1(state->rxsubchans);
@@ -738,8 +742,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
738742
std = V4L2_STD_SECAM;
739743
else
740744
std = V4L2_STD_NTSC;
741-
if (std != state->std) {
742-
state->std = std;
745+
if (std != state->v4l2_std) {
746+
state->v4l2_std = std;
743747
update = 1;
744748
}
745749
if (update)
@@ -768,9 +772,9 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
768772
case VIDIOC_S_STD:
769773
{
770774
v4l2_std_id *id = arg;
771-
int update = state->radio || state->std != *id;
775+
int update = state->radio || state->v4l2_std != *id;
772776

773-
state->std = *id;
777+
state->v4l2_std = *id;
774778
state->radio = 0;
775779
if (update)
776780
msp_wake_thread(client);
@@ -879,6 +883,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
879883
{
880884
struct v4l2_tuner *vt = arg;
881885

886+
if (state->radio)
887+
break;
882888
if (state->opmode == OPMODE_AUTOSELECT)
883889
msp_any_detect_stereo(client);
884890
vt->audmode = state->audmode;
@@ -892,6 +898,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
892898
{
893899
struct v4l2_tuner *vt = (struct v4l2_tuner *)arg;
894900

901+
if (state->radio)
902+
break;
895903
/* only set audmode */
896904
if (vt->audmode != -1 && vt->audmode != 0)
897905
msp_any_set_audmode(client, vt->audmode);
@@ -981,22 +989,46 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
981989
return msp_set_ctrl(client, arg);
982990

983991
case VIDIOC_LOG_STATUS:
992+
{
993+
const char *p;
994+
984995
if (state->opmode == OPMODE_AUTOSELECT)
985996
msp_any_detect_stereo(client);
986997
v4l_info(client, "%s rev1 = 0x%04x rev2 = 0x%04x\n",
987998
client->name, state->rev1, state->rev2);
988-
v4l_info(client, "Audio: volume %d%s\n",
999+
v4l_info(client, "Audio: volume %d%s\n",
9891000
state->volume, state->muted ? " (muted)" : "");
9901001
if (state->has_sound_processing) {
991-
v4l_info(client, "Audio: balance %d bass %d treble %d loudness %s\n",
1002+
v4l_info(client, "Audio: balance %d bass %d treble %d loudness %s\n",
9921003
state->balance, state->bass, state->treble,
9931004
state->loudness ? "on" : "off");
9941005
}
995-
v4l_info(client, "Mode: %s (%s%s)\n", msp_standard_mode_name(state->mode),
996-
(state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
997-
(state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
998-
v4l_info(client, "ACB: 0x%04x\n", state->acb);
1006+
switch (state->mode) {
1007+
case MSP_MODE_AM_DETECT: p = "AM (for carrier detect)"; break;
1008+
case MSP_MODE_FM_RADIO: p = "FM Radio"; break;
1009+
case MSP_MODE_FM_TERRA: p = "Terrestial FM-mono + FM-stereo"; break;
1010+
case MSP_MODE_FM_SAT: p = "Satellite FM-mono"; break;
1011+
case MSP_MODE_FM_NICAM1: p = "NICAM/FM (B/G, D/K)"; break;
1012+
case MSP_MODE_FM_NICAM2: p = "NICAM/FM (I)"; break;
1013+
case MSP_MODE_AM_NICAM: p = "NICAM/AM (L)"; break;
1014+
case MSP_MODE_BTSC: p = "BTSC"; break;
1015+
case MSP_MODE_EXTERN: p = "External input"; break;
1016+
default: p = "unknown"; break;
1017+
}
1018+
if (state->opmode == OPMODE_MANUAL) {
1019+
v4l_info(client, "Mode: %s (%s%s)\n", p,
1020+
(state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
1021+
(state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
1022+
} else {
1023+
v4l_info(client, "Mode: %s\n", p);
1024+
v4l_info(client, "Standard: %s (%s%s)\n",
1025+
msp_standard_std_name(state->std),
1026+
(state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
1027+
(state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
1028+
}
1029+
v4l_info(client, "ACB: 0x%04x\n", state->acb);
9991030
break;
1031+
}
10001032

10011033
default:
10021034
/* nothing */
@@ -1061,7 +1093,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
10611093
i2c_set_clientdata(client, state);
10621094

10631095
memset(state, 0, sizeof(*state));
1064-
state->std = V4L2_STD_NTSC;
1096+
state->v4l2_std = V4L2_STD_NTSC;
10651097
state->volume = 58880; /* 0db gain */
10661098
state->balance = 32768; /* 0db gain */
10671099
state->bass = 32768;
@@ -1109,6 +1141,8 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
11091141
state->has_scart23_in_scart2_out = msp_family >= 4 || msp_prod_lo < 5;
11101142
/* Has scart2 a volume control? Not in pre-D revisions. */
11111143
state->has_scart2_out_volume = msp_revision > 'C' && state->has_scart23_in_scart2_out;
1144+
/* Has a configurable i2s out? */
1145+
state->has_i2s_conf = msp_revision >= 'G' && msp_prod_lo < 7;
11121146
/* Has subwoofer output: not in pre-D revs and not in stripped down products */
11131147
state->has_subwoofer = msp_revision >= 'D' && msp_prod_lo < 5;
11141148
/* Has soundprocessing (bass/treble/balance/loudness/equalizer): not in

drivers/media/video/msp3400-kthreads.c

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static struct {
3737
int retval;
3838
int main, second;
3939
char *name;
40-
} msp_modelist[] = {
40+
} msp_stdlist[] = {
4141
{ 0x0000, 0, 0, "could not detect sound standard" },
4242
{ 0x0001, 0, 0, "autodetect start" },
4343
{ 0x0002, MSP_CARRIER(4.5), MSP_CARRIER(4.72), "4.5/4.72 M Dual FM-Stereo" },
@@ -144,13 +144,13 @@ static struct msp3400c_carrier_detect msp3400c_carrier_detect_65[] = {
144144

145145
/* ------------------------------------------------------------------------ */
146146

147-
const char *msp_standard_mode_name(int mode)
147+
const char *msp_standard_std_name(int std)
148148
{
149149
int i;
150150

151-
for (i = 0; msp_modelist[i].name != NULL; i++)
152-
if (msp_modelist[i].retval == mode)
153-
return msp_modelist[i].name;
151+
for (i = 0; msp_stdlist[i].name != NULL; i++)
152+
if (msp_stdlist[i].retval == std)
153+
return msp_stdlist[i].name;
154154
return "unknown";
155155
}
156156

@@ -498,7 +498,7 @@ int msp3400c_thread(void *data)
498498
cd = msp3400c_carrier_detect_main;
499499
count = ARRAY_SIZE(msp3400c_carrier_detect_main);
500500

501-
if (amsound && (state->std & V4L2_STD_SECAM)) {
501+
if (amsound && (state->v4l2_std & V4L2_STD_SECAM)) {
502502
/* autodetect doesn't work well with AM ... */
503503
max1 = 3;
504504
count = 0;
@@ -535,7 +535,7 @@ int msp3400c_thread(void *data)
535535
break;
536536
}
537537

538-
if (amsound && (state->std & V4L2_STD_SECAM)) {
538+
if (amsound && (state->v4l2_std & V4L2_STD_SECAM)) {
539539
/* autodetect doesn't work well with AM ... */
540540
cd = NULL;
541541
count = 0;
@@ -591,7 +591,7 @@ int msp3400c_thread(void *data)
591591
state->nicam_on = 0;
592592
msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
593593
state->watch_stereo = 1;
594-
} else if (max2 == 0 && (state->std & V4L2_STD_SECAM)) {
594+
} else if (max2 == 0 && (state->v4l2_std & V4L2_STD_SECAM)) {
595595
/* L NICAM or AM-mono */
596596
state->second = msp3400c_carrier_detect_65[max2].cdo;
597597
msp3400c_setmode(client, MSP_MODE_AM_NICAM);
@@ -676,22 +676,22 @@ int msp3410d_thread(void *data)
676676
goto restart;
677677

678678
/* start autodetect */
679-
std = 1;
680-
if (state->std & V4L2_STD_NTSC)
681-
std = 0x20;
679+
if (state->radio)
680+
std = 0x40;
682681
else
683-
msp_write_dem(client, 0x20, std);
682+
std = (state->v4l2_std & V4L2_STD_NTSC) ? 0x20 : 1;
684683
state->watch_stereo = 0;
685684

686685
if (debug)
687-
v4l_dbg(1, client, "setting mode: %s (0x%04x)\n",
688-
msp_standard_mode_name(std), std);
686+
v4l_dbg(1, client, "setting standard: %s (0x%04x)\n",
687+
msp_standard_std_name(std), std);
689688

690689
if (std != 1) {
691690
/* programmed some specific mode */
692691
val = std;
693692
} else {
694693
/* triggered autodetect */
694+
msp_write_dem(client, 0x20, std);
695695
for (;;) {
696696
if (msp_sleep(state, 100))
697697
goto restart;
@@ -703,19 +703,21 @@ int msp3410d_thread(void *data)
703703
v4l_dbg(1, client, "detection still in progress\n");
704704
}
705705
}
706-
for (i = 0; msp_modelist[i].name != NULL; i++)
707-
if (msp_modelist[i].retval == val)
706+
for (i = 0; msp_stdlist[i].name != NULL; i++)
707+
if (msp_stdlist[i].retval == val)
708708
break;
709-
v4l_dbg(1, client, "current mode: %s (0x%04x)\n",
710-
msp_standard_mode_name(val), val);
711-
state->main = msp_modelist[i].main;
712-
state->second = msp_modelist[i].second;
713-
714-
if (amsound && (state->std & V4L2_STD_SECAM) && (val != 0x0009)) {
709+
v4l_dbg(1, client, "current standard: %s (0x%04x)\n",
710+
msp_standard_std_name(val), val);
711+
state->main = msp_stdlist[i].main;
712+
state->second = msp_stdlist[i].second;
713+
state->std = val;
714+
715+
if (amsound && !state->radio && (state->v4l2_std & V4L2_STD_SECAM) &&
716+
(val != 0x0009)) {
715717
/* autodetection has failed, let backup */
716718
v4l_dbg(1, client, "autodetection failed,"
717-
" switching to backup mode: %s (0x%04x)\n",
718-
msp_modelist[8].name ? msp_modelist[8].name : "unknown",val);
719+
" switching to backup standard: %s (0x%04x)\n",
720+
msp_stdlist[8].name ? msp_stdlist[8].name : "unknown",val);
719721
val = 0x0009;
720722
msp_write_dem(client, 0x20, val);
721723
}
@@ -762,7 +764,7 @@ int msp3410d_thread(void *data)
762764
state->watch_stereo = 0;
763765
/* not needed in theory if we have radio, but
764766
short programming enables carrier mute */
765-
msp3400c_setmode(client,MSP_MODE_FM_RADIO);
767+
msp3400c_setmode(client, MSP_MODE_FM_RADIO);
766768
msp3400c_setcarrier(client, MSP_CARRIER(10.7),
767769
MSP_CARRIER(10.7));
768770
/* scart routing */
@@ -775,7 +777,7 @@ int msp3410d_thread(void *data)
775777
case 0x0003:
776778
case 0x0004:
777779
case 0x0005:
778-
state->mode = MSP_MODE_FM_TERRA;
780+
state->mode = MSP_MODE_FM_TERRA;
779781
state->rxsubchans = V4L2_TUNER_SUB_MONO;
780782
state->audmode = V4L2_TUNER_MODE_MONO;
781783
state->nicam_on = 0;
@@ -786,7 +788,8 @@ int msp3410d_thread(void *data)
786788
/* unmute, restore misc registers */
787789
msp_set_audio(client);
788790
msp_write_dsp(client, 0x13, state->acb);
789-
msp_write_dem(client, 0x40, state->i2s_mode);
791+
if (state->has_i2s_conf)
792+
msp_write_dem(client, 0x40, state->i2s_mode);
790793

791794
/* monitor tv audio mode */
792795
while (state->watch_stereo) {
@@ -857,14 +860,15 @@ static int msp34xxg_reset(struct i2c_client *client)
857860
if (msp_write_dsp(client, 0x13, 0x0f20))
858861
return -1;
859862

860-
msp_write_dem(client, 0x40, state->i2s_mode);
863+
if (state->has_i2s_conf)
864+
msp_write_dem(client, 0x40, state->i2s_mode);
861865

862866
/* step-by-step initialisation, as described in the manual */
863867
modus = msp_modus(client);
864868
if (state->radio)
865869
std = 0x40;
866870
else
867-
std = (state->std & V4L2_STD_NTSC) ? 0x20 : 1;
871+
std = (state->v4l2_std & V4L2_STD_NTSC) ? 0x20 : 1;
868872
modus &= ~0x03; /* STATUS_CHANGE = 0 */
869873
modus |= 0x01; /* AUTOMATIC_SOUND_DETECTION = 1 */
870874
if (msp_write_dem(client, 0x30, modus))
@@ -933,9 +937,9 @@ int msp34xxg_thread(void *data)
933937
}
934938

935939
unmute:
936-
state->mode = std;
937-
v4l_dbg(1, client, "current mode: %s (0x%04x)\n",
938-
msp_standard_mode_name(std), std);
940+
state->std = std;
941+
v4l_dbg(1, client, "current standard: %s (0x%04x)\n",
942+
msp_standard_std_name(std), std);
939943

940944
/* unmute: dispatch sound to scart output, set scart volume */
941945
msp_set_audio(client);

drivers/media/video/msp3400.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,24 @@ extern int stereo_threshold;
5757

5858
struct msp_state {
5959
int rev1, rev2;
60-
int has_nicam;
61-
int has_radio;
62-
int has_headphones;
63-
int has_ntsc_jp_d_k3;
64-
int has_scart4;
65-
int has_scart23_in_scart2_out;
66-
int has_scart2_out_volume;
67-
int has_subwoofer;
68-
int has_sound_processing;
69-
int has_virtual_dolby_surround;
70-
int has_dolby_pro_logic;
60+
u8 has_nicam;
61+
u8 has_radio;
62+
u8 has_headphones;
63+
u8 has_ntsc_jp_d_k3;
64+
u8 has_scart4;
65+
u8 has_scart23_in_scart2_out;
66+
u8 has_scart2_out_volume;
67+
u8 has_i2s_conf;
68+
u8 has_subwoofer;
69+
u8 has_sound_processing;
70+
u8 has_virtual_dolby_surround;
71+
u8 has_dolby_pro_logic;
7172

7273
int radio;
7374
int opmode;
75+
int std;
7476
int mode;
75-
v4l2_std_id std;
77+
v4l2_std_id v4l2_std;
7678
int nicam_on;
7779
int acb;
7880
int in_scart;
@@ -109,7 +111,7 @@ int msp_modus(struct i2c_client *client);
109111
int msp_sleep(struct msp_state *state, int timeout);
110112

111113
/* msp3400-kthreads.c */
112-
const char *msp_standard_mode_name(int mode);
114+
const char *msp_standard_std_name(int std);
113115
void msp3400c_setcarrier(struct i2c_client *client, int cdo1, int cdo2);
114116
void msp3400c_setmode(struct i2c_client *client, int type);
115117
void msp3400c_setstereo(struct i2c_client *client, int mode);

0 commit comments

Comments
 (0)