23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/i2c.h>
27 #include <linux/videodev2.h>
42 { 0x0000, 0, 0,
"could not detect sound standard",
V4L2_STD_ALL },
82 { -1, 0, 0,
NULL, 0 },
85 static struct msp3400c_init_data_dem {
94 } msp3400c_init_data[] = {
96 {75, 19, 36, 35, 39, 40},
97 {75, 19, 36, 35, 39, 40},
99 0x00d0, 0x0500, 0x0020, 0x3000
101 {-1, -1, -8, 2, 59, 126},
102 {-1, -1, -8, 2, 59, 126},
104 0x00d0, 0x0100, 0x0020, 0x3000
106 {-8, -8, 4, 6, 78, 107},
107 {-8, -8, 4, 6, 78, 107},
109 0x00d0, 0x0480, 0x0020, 0x3000
111 {3, 18, 27, 48, 66, 72},
112 {3, 18, 27, 48, 66, 72},
114 0x00d0, 0x0480, 0x0030, 0x3000
116 { 1, 9, 14, 24, 33, 37},
117 { 3, 18, 27, 48, 66, 72},
119 0x00c6, 0x0480, 0x0000, 0x3000
121 {-2, -8, -10, 10, 50, 86},
122 {3, 18, 27, 48, 66, 72},
124 0x00d0, 0x0040, 0x0120, 0x3000
126 {2, 4, -6, -4, 40, 94},
127 {3, 18, 27, 48, 66, 72},
129 0x00d0, 0x0040, 0x0120, 0x3000
131 {-2, -8, -10, 10, 50, 86},
132 {-4, -12, -9, 23, 79, 126},
134 0x00c6, 0x0140, 0x0120, 0x7c00
153 {
MSP_CARRIER(5.7421875),
"5.742 PAL B/G FM-stereo" },
159 {
MSP_CARRIER(5.85),
"5.85 PAL D/K + SECAM NICAM" },
160 {
MSP_CARRIER(6.2578125),
"6.25 PAL D/K1 FM-stereo" },
161 {
MSP_CARRIER(6.7421875),
"6.74 PAL D/K2 FM-stereo" },
162 {
MSP_CARRIER(7.02),
"7.02 PAL SAT FM-stereo s/b" },
173 for (i = 0; msp_stdlist[
i].name !=
NULL; i++)
174 if (msp_stdlist[i].
retval == std)
175 return msp_stdlist[
i].name;
183 for (i = 0; msp_stdlist[
i].name !=
NULL; i++)
184 if (msp_stdlist[i].
retval == std)
185 return msp_stdlist[
i].std;
218 struct msp_state *state = to_state(i2c_get_clientdata(client));
219 struct msp3400c_init_data_dem *
data = &msp3400c_init_data[
mode];
227 msp_write_dem(client, 0x00bb, data->ad_cv | (tuner ? 0x100 : 0));
229 for (i = 5; i >= 0; i--)
235 for (i = 5; i >= 0; i--)
242 msp_set_source(client, data->dsp_src);
254 static void msp3400c_set_audmode(
struct i2c_client *client)
256 static char *strmode[] = {
257 "mono",
"stereo",
"lang2",
"lang1",
"lang1+lang2"
259 struct msp_state *state = to_state(i2c_get_clientdata(client));
261 strmode[state->
audmode] :
"unknown";
270 "set_audmode called with mode=%d instead of set_source (ignored)\n",
296 switch (state->
mode) {
333 "NICAM set_audmode: %s\n", modestr);
339 "BTSC set_audmode: %s\n", modestr);
343 "extern set_audmode: %s\n", modestr);
348 "FM-Radio set_audmode: %s\n", modestr);
381 "set_audmode final source/matrix = 0x%x\n", src);
383 msp_set_source(client, src);
386 static void msp3400c_print_mode(
struct i2c_client *client)
388 struct msp_state *state = to_state(i2c_get_clientdata(client));
392 "mono sound carrier: %d.%03d MHz\n",
393 state->
main / 910000, (state->
main / 910) % 1000);
396 "main sound carrier: %d.%03d MHz\n",
397 state->
main / 910000, (state->
main / 910) % 1000);
400 "NICAM/FM carrier : %d.%03d MHz\n",
404 "NICAM/AM carrier : %d.%03d MHz\n",
408 "FM-stereo carrier : %d.%03d MHz\n",
415 static int msp3400c_detect_stereo(
struct i2c_client *client)
417 struct msp_state *state = to_state(i2c_get_clientdata(client));
423 switch (state->
mode) {
429 "stereo detect register: %d\n", val);
432 }
else if (val < -4096) {
444 val & 1, (val & 0x1e) >> 1);
448 switch ((val & 0x1e) >> 1) {
475 "watch: rxsubchans %02x => %02x\n",
495 struct msp_state *state = to_state(i2c_get_clientdata(client));
507 struct msp_state *state = to_state(i2c_get_clientdata(client));
509 int count, max1, max2, val1, val2,
val,
i;
528 "thread: no carrier scan\n");
549 cd = msp3400c_carrier_detect_main;
550 count =
ARRAY_SIZE(msp3400c_carrier_detect_main);
559 for (i = 0; i <
count; i++) {
567 val1 =
val, max1 =
i;
569 "carrier1 val: %5d / %s\n", val, cd[i].
name);
575 cd = msp3400c_carrier_detect_55;
576 count =
ARRAY_SIZE(msp3400c_carrier_detect_55);
579 cd = msp3400c_carrier_detect_65;
580 count =
ARRAY_SIZE(msp3400c_carrier_detect_65);
596 for (i = 0; i <
count; i++) {
604 val2 =
val, max2 =
i;
606 "carrier2 val: %5d / %s\n", val, cd[i].
name);
610 state->
main = msp3400c_carrier_detect_main[max1].
cdo;
616 state->
second = msp3400c_carrier_detect_55[max2].
cdo;
619 }
else if (max2 == 1 && state->
has_nicam) {
621 state->
second = msp3400c_carrier_detect_55[max2].
cdo;
638 if (max2 == 1 || max2 == 2) {
640 state->
second = msp3400c_carrier_detect_65[max2].
cdo;
646 state->
second = msp3400c_carrier_detect_65[max2].
cdo;
650 }
else if (max2 == 0 && state->
has_nicam) {
652 state->
second = msp3400c_carrier_detect_65[max2].
cdo;
665 state->
second = msp3400c_carrier_detect_main[max1].
cdo;
673 msp3400c_set_audmode(client);
677 msp3400c_print_mode(client);
683 if (
msp_sleep(state, count ? 1000 : 5000))
687 watch_stereo(client);
698 struct msp_state *state = to_state(i2c_get_clientdata(client));
718 "thread: no carrier scan\n");
744 "setting standard: %s (0x%04x)\n",
762 "detection still in progress\n");
765 for (i = 0; msp_stdlist[
i].name !=
NULL; i++)
766 if (msp_stdlist[i].
retval == val)
770 state->
main = msp_stdlist[
i].main;
771 state->
second = msp_stdlist[
i].second;
779 " switching to backup standard: %s (0x%04x)\n",
780 msp_stdlist[8].
name ?
781 msp_stdlist[8].
name :
"unknown", val);
782 state->
std = val = 0x0009;
838 msp3400c_set_audmode(client);
846 if (
msp_sleep(state, count ? 1000 : 5000))
865 static int msp34xxg_modus(
struct i2c_client *client)
867 struct msp_state *state = to_state(i2c_get_clientdata(client));
894 struct msp_state *state = to_state(i2c_get_clientdata(client));
922 source = (source << 8) | 0x20;
926 source = ((in + 1) << 8) | matrix;
928 source = (in << 8) | matrix;
931 "set source to %d (0x%x) for output %02x\n", in, source, reg);
935 static void msp34xxg_set_sources(
struct i2c_client *client)
937 struct msp_state *state = to_state(i2c_get_clientdata(client));
940 msp34xxg_set_source(client, 0x0008, (in >> 4) & 0xf);
942 msp34xxg_set_source(client, 0x000c, (in >> 4) & 0xf);
943 msp34xxg_set_source(client, 0x0009, (in >> 8) & 0xf);
944 msp34xxg_set_source(client, 0x000a, (in >> 12) & 0xf);
946 msp34xxg_set_source(client, 0x0041, (in >> 16) & 0xf);
947 msp34xxg_set_source(client, 0x000b, (in >> 20) & 0xf);
951 static void msp34xxg_reset(
struct i2c_client *client)
953 struct msp_state *state = to_state(i2c_get_clientdata(client));
967 modus = msp34xxg_modus(client);
968 modus |= tuner ? 0x100 : 0;
973 msp34xxg_set_sources(client);
996 struct msp_state *state = to_state(i2c_get_clientdata(client));
1016 "thread: no carrier scan\n");
1023 msp34xxg_reset(client);
1028 if (state->
std != 1)
1033 "started autodetect, waiting for result\n");
1034 for (i = 0; i < 10; i++) {
1045 "detection still in progress\n");
1047 if (state->
std == 1) {
1049 "detection still in progress after 10 tries. giving up.\n");
1055 "detected standard: %s (0x%04x)\n",
1059 if (state->
std == 9) {
1073 if (state->
std != 0x20)
1091 static int msp34xxg_detect_stereo(
struct i2c_client *client)
1093 struct msp_state *state = to_state(i2c_get_clientdata(client));
1095 int is_bilingual = status & 0x100;
1096 int is_stereo = status & 0x40;
1108 if (state->
std == 0x20)
1115 "status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n",
1116 status, is_stereo, is_bilingual, state->
rxsubchans);
1120 static void msp34xxg_set_audmode(
struct i2c_client *client)
1122 struct msp_state *state = to_state(i2c_get_clientdata(client));
1124 if (state->
std == 0x20) {
1134 msp34xxg_set_sources(client);
1139 struct msp_state *state = to_state(i2c_get_clientdata(client));
1144 msp3400c_set_audmode(client);
1147 msp34xxg_set_audmode(client);
1154 struct msp_state *state = to_state(i2c_get_clientdata(client));
1159 return msp3400c_detect_stereo(client);
1161 return msp34xxg_detect_stereo(client);