]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/video/msp3400-kthreads.c
V4L/DVB (3580): Last round of msp3400 cleanups before adding routing commands
[mirror_ubuntu-artful-kernel.git] / drivers / media / video / msp3400-kthreads.c
CommitLineData
7e8b09ea
HV
1/*
2 * Programming the mspx4xx sound processor family
3 *
4 * (c) 1997-2001 Gerd Knorr <kraxel@bytesex.org>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/slab.h>
25#include <linux/i2c.h>
26#include <linux/videodev.h>
27#include <linux/videodev2.h>
28#include <media/v4l2-common.h>
7e8b09ea
HV
29#include <linux/kthread.h>
30#include <linux/suspend.h>
31#include "msp3400.h"
32
33/* this one uses the automatic sound standard detection of newer msp34xx
34 chip versions */
35static struct {
36 int retval;
37 int main, second;
38 char *name;
5af0c8f6 39} msp_stdlist[] = {
7e8b09ea
HV
40 { 0x0000, 0, 0, "could not detect sound standard" },
41 { 0x0001, 0, 0, "autodetect start" },
42 { 0x0002, MSP_CARRIER(4.5), MSP_CARRIER(4.72), "4.5/4.72 M Dual FM-Stereo" },
43 { 0x0003, MSP_CARRIER(5.5), MSP_CARRIER(5.7421875), "5.5/5.74 B/G Dual FM-Stereo" },
44 { 0x0004, MSP_CARRIER(6.5), MSP_CARRIER(6.2578125), "6.5/6.25 D/K1 Dual FM-Stereo" },
45 { 0x0005, MSP_CARRIER(6.5), MSP_CARRIER(6.7421875), "6.5/6.74 D/K2 Dual FM-Stereo" },
46 { 0x0006, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 D/K FM-Mono (HDEV3)" },
de533ccf 47 { 0x0007, MSP_CARRIER(6.5), MSP_CARRIER(5.7421875), "6.5/5.74 D/K3 Dual FM-Stereo" },
7e8b09ea
HV
48 { 0x0008, MSP_CARRIER(5.5), MSP_CARRIER(5.85), "5.5/5.85 B/G NICAM FM" },
49 { 0x0009, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 L NICAM AM" },
50 { 0x000a, MSP_CARRIER(6.0), MSP_CARRIER(6.55), "6.0/6.55 I NICAM FM" },
51 { 0x000b, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM" },
52 { 0x000c, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM (HDEV2)" },
de533ccf 53 { 0x000d, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM (HDEV3)" },
7e8b09ea
HV
54 { 0x0020, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Stereo" },
55 { 0x0021, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Mono + SAP" },
56 { 0x0030, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M EIA-J Japan Stereo" },
57 { 0x0040, MSP_CARRIER(10.7), MSP_CARRIER(10.7), "10.7 FM-Stereo Radio" },
58 { 0x0050, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 SAT-Mono" },
59 { 0x0051, MSP_CARRIER(7.02), MSP_CARRIER(7.20), "7.02/7.20 SAT-Stereo" },
60 { 0x0060, MSP_CARRIER(7.2), MSP_CARRIER(7.2), "7.2 SAT ADR" },
61 { -1, 0, 0, NULL }, /* EOF */
62};
63
64static struct msp3400c_init_data_dem {
65 int fir1[6];
66 int fir2[6];
67 int cdo1;
68 int cdo2;
69 int ad_cv;
70 int mode_reg;
71 int dsp_src;
72 int dsp_matrix;
73} msp3400c_init_data[] = {
74 { /* AM (for carrier detect / msp3400) */
75 {75, 19, 36, 35, 39, 40},
76 {75, 19, 36, 35, 39, 40},
77 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
78 0x00d0, 0x0500, 0x0020, 0x3000
79 },{ /* AM (for carrier detect / msp3410) */
80 {-1, -1, -8, 2, 59, 126},
81 {-1, -1, -8, 2, 59, 126},
82 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
83 0x00d0, 0x0100, 0x0020, 0x3000
84 },{ /* FM Radio */
85 {-8, -8, 4, 6, 78, 107},
86 {-8, -8, 4, 6, 78, 107},
87 MSP_CARRIER(10.7), MSP_CARRIER(10.7),
88 0x00d0, 0x0480, 0x0020, 0x3000
89 },{ /* Terrestial FM-mono + FM-stereo */
90 {3, 18, 27, 48, 66, 72},
91 {3, 18, 27, 48, 66, 72},
92 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
93 0x00d0, 0x0480, 0x0030, 0x3000
94 },{ /* Sat FM-mono */
95 { 1, 9, 14, 24, 33, 37},
96 { 3, 18, 27, 48, 66, 72},
97 MSP_CARRIER(6.5), MSP_CARRIER(6.5),
98 0x00c6, 0x0480, 0x0000, 0x3000
99 },{ /* NICAM/FM -- B/G (5.5/5.85), D/K (6.5/5.85) */
100 {-2, -8, -10, 10, 50, 86},
101 {3, 18, 27, 48, 66, 72},
102 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
103 0x00d0, 0x0040, 0x0120, 0x3000
104 },{ /* NICAM/FM -- I (6.0/6.552) */
105 {2, 4, -6, -4, 40, 94},
106 {3, 18, 27, 48, 66, 72},
107 MSP_CARRIER(6.0), MSP_CARRIER(6.0),
108 0x00d0, 0x0040, 0x0120, 0x3000
109 },{ /* NICAM/AM -- L (6.5/5.85) */
110 {-2, -8, -10, 10, 50, 86},
111 {-4, -12, -9, 23, 79, 126},
112 MSP_CARRIER(6.5), MSP_CARRIER(6.5),
8a4b275f 113 0x00c6, 0x0140, 0x0120, 0x7c00
7e8b09ea
HV
114 },
115};
116
117struct msp3400c_carrier_detect {
118 int cdo;
119 char *name;
120};
121
122static struct msp3400c_carrier_detect msp3400c_carrier_detect_main[] = {
123 /* main carrier */
124 { MSP_CARRIER(4.5), "4.5 NTSC" },
125 { MSP_CARRIER(5.5), "5.5 PAL B/G" },
126 { MSP_CARRIER(6.0), "6.0 PAL I" },
127 { MSP_CARRIER(6.5), "6.5 PAL D/K + SAT + SECAM" }
128};
129
130static struct msp3400c_carrier_detect msp3400c_carrier_detect_55[] = {
131 /* PAL B/G */
132 { MSP_CARRIER(5.7421875), "5.742 PAL B/G FM-stereo" },
133 { MSP_CARRIER(5.85), "5.85 PAL B/G NICAM" }
134};
135
136static struct msp3400c_carrier_detect msp3400c_carrier_detect_65[] = {
137 /* PAL SAT / SECAM */
138 { MSP_CARRIER(5.85), "5.85 PAL D/K + SECAM NICAM" },
139 { MSP_CARRIER(6.2578125), "6.25 PAL D/K1 FM-stereo" },
140 { MSP_CARRIER(6.7421875), "6.74 PAL D/K2 FM-stereo" },
141 { MSP_CARRIER(7.02), "7.02 PAL SAT FM-stereo s/b" },
142 { MSP_CARRIER(7.20), "7.20 PAL SAT FM-stereo s" },
143 { MSP_CARRIER(7.38), "7.38 PAL SAT FM-stereo b" },
144};
145
146/* ------------------------------------------------------------------------ */
147
5af0c8f6 148const char *msp_standard_std_name(int std)
7e8b09ea
HV
149{
150 int i;
151
5af0c8f6
HV
152 for (i = 0; msp_stdlist[i].name != NULL; i++)
153 if (msp_stdlist[i].retval == std)
154 return msp_stdlist[i].name;
7e8b09ea
HV
155 return "unknown";
156}
157
044f324f 158static void msp_set_source(struct i2c_client *client, u16 src)
8a4b275f
HV
159{
160 struct msp_state *state = i2c_get_clientdata(client);
161
162 if (msp_dolby) {
163 msp_write_dsp(client, 0x0008, 0x0520); /* I2S1 */
164 msp_write_dsp(client, 0x0009, 0x0620); /* I2S2 */
165 } else {
166 msp_write_dsp(client, 0x0008, src);
167 msp_write_dsp(client, 0x0009, src);
168 }
169 msp_write_dsp(client, 0x000a, src);
170 msp_write_dsp(client, 0x000b, src);
171 msp_write_dsp(client, 0x000c, src);
172 if (state->has_scart23_in_scart2_out)
173 msp_write_dsp(client, 0x0041, src);
174}
175
176void msp3400c_set_carrier(struct i2c_client *client, int cdo1, int cdo2)
7e8b09ea
HV
177{
178 msp_write_dem(client, 0x0093, cdo1 & 0xfff);
179 msp_write_dem(client, 0x009b, cdo1 >> 12);
180 msp_write_dem(client, 0x00a3, cdo2 & 0xfff);
181 msp_write_dem(client, 0x00ab, cdo2 >> 12);
8a4b275f 182 msp_write_dem(client, 0x0056, 0); /* LOAD_REG_1/2 */
7e8b09ea
HV
183}
184
8a4b275f 185void msp3400c_set_mode(struct i2c_client *client, int mode)
7e8b09ea
HV
186{
187 struct msp_state *state = i2c_get_clientdata(client);
8a4b275f 188 struct msp3400c_init_data_dem *data = &msp3400c_init_data[mode];
7e8b09ea
HV
189 int i;
190
8a4b275f
HV
191 v4l_dbg(1, msp_debug, client, "set_mode: %d\n", mode);
192 state->mode = mode;
7e8b09ea
HV
193 state->rxsubchans = V4L2_TUNER_SUB_MONO;
194
8a4b275f 195 msp_write_dem(client, 0x00bb, data->ad_cv);
7e8b09ea
HV
196
197 for (i = 5; i >= 0; i--) /* fir 1 */
8a4b275f 198 msp_write_dem(client, 0x0001, data->fir1[i]);
7e8b09ea
HV
199
200 msp_write_dem(client, 0x0005, 0x0004); /* fir 2 */
201 msp_write_dem(client, 0x0005, 0x0040);
202 msp_write_dem(client, 0x0005, 0x0000);
203 for (i = 5; i >= 0; i--)
8a4b275f 204 msp_write_dem(client, 0x0005, data->fir2[i]);
7e8b09ea 205
8a4b275f 206 msp_write_dem(client, 0x0083, data->mode_reg);
7e8b09ea 207
8a4b275f 208 msp3400c_set_carrier(client, data->cdo1, data->cdo2);
7e8b09ea 209
8a4b275f 210 msp_set_source(client, data->dsp_src);
de533ccf 211 /* set prescales */
7e8b09ea 212
de533ccf
HV
213 /* volume prescale for SCART (AM mono input) */
214 msp_write_dsp(client, 0x000d, 0x1900);
215 msp_write_dsp(client, 0x000e, data->dsp_matrix);
216 if (state->has_nicam) /* nicam prescale */
217 msp_write_dsp(client, 0x0010, 0x5a00);
7e8b09ea
HV
218}
219
8a4b275f
HV
220/* Set audio mode. Note that the pre-'G' models do not support BTSC+SAP,
221 nor do they support stereo BTSC. */
044f324f 222static void msp3400c_set_audmode(struct i2c_client *client)
7e8b09ea 223{
d312a46e 224 static char *strmode[] = { "mono", "stereo", "lang2", "lang1" };
7e8b09ea 225 struct msp_state *state = i2c_get_clientdata(client);
8a4b275f
HV
226 char *modestr = (state->audmode >= 0 && state->audmode < 4) ?
227 strmode[state->audmode] : "unknown";
228 int src = 0; /* channel source: FM/AM, nicam or SCART */
7e8b09ea
HV
229
230 if (state->opmode == OPMODE_AUTOSELECT) {
231 /* this method would break everything, let's make sure
232 * it's never called
233 */
8a4b275f
HV
234 v4l_dbg(1, msp_debug, client,
235 "set_audmode called with mode=%d instead of set_source (ignored)\n",
236 state->audmode);
7e8b09ea
HV
237 return;
238 }
239
240 /* switch demodulator */
241 switch (state->mode) {
242 case MSP_MODE_FM_TERRA:
8a4b275f
HV
243 v4l_dbg(1, msp_debug, client, "FM set_audmode: %s\n", modestr);
244 switch (state->audmode) {
7e8b09ea
HV
245 case V4L2_TUNER_MODE_STEREO:
246 msp_write_dsp(client, 0x000e, 0x3001);
247 break;
248 case V4L2_TUNER_MODE_MONO:
249 case V4L2_TUNER_MODE_LANG1:
250 case V4L2_TUNER_MODE_LANG2:
251 msp_write_dsp(client, 0x000e, 0x3000);
252 break;
253 }
254 break;
255 case MSP_MODE_FM_SAT:
8a4b275f
HV
256 v4l_dbg(1, msp_debug, client, "SAT set_audmode: %s\n", modestr);
257 switch (state->audmode) {
7e8b09ea 258 case V4L2_TUNER_MODE_MONO:
8a4b275f 259 msp3400c_set_carrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
7e8b09ea
HV
260 break;
261 case V4L2_TUNER_MODE_STEREO:
8a4b275f 262 msp3400c_set_carrier(client, MSP_CARRIER(7.2), MSP_CARRIER(7.02));
7e8b09ea
HV
263 break;
264 case V4L2_TUNER_MODE_LANG1:
8a4b275f 265 msp3400c_set_carrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
7e8b09ea
HV
266 break;
267 case V4L2_TUNER_MODE_LANG2:
8a4b275f 268 msp3400c_set_carrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
7e8b09ea
HV
269 break;
270 }
271 break;
272 case MSP_MODE_FM_NICAM1:
273 case MSP_MODE_FM_NICAM2:
274 case MSP_MODE_AM_NICAM:
8a4b275f 275 v4l_dbg(1, msp_debug, client, "NICAM set_audmode: %s\n",modestr);
7e8b09ea 276 if (state->nicam_on)
8a4b275f 277 src = 0x0100; /* NICAM */
7e8b09ea
HV
278 break;
279 case MSP_MODE_BTSC:
8a4b275f 280 v4l_dbg(1, msp_debug, client, "BTSC set_audmode: %s\n",modestr);
7e8b09ea
HV
281 break;
282 case MSP_MODE_EXTERN:
8a4b275f
HV
283 v4l_dbg(1, msp_debug, client, "extern set_audmode: %s\n",modestr);
284 src = 0x0200; /* SCART */
7e8b09ea
HV
285 break;
286 case MSP_MODE_FM_RADIO:
8a4b275f 287 v4l_dbg(1, msp_debug, client, "FM-Radio set_audmode: %s\n",modestr);
7e8b09ea
HV
288 break;
289 default:
8a4b275f 290 v4l_dbg(1, msp_debug, client, "mono set_audmode\n");
7e8b09ea
HV
291 return;
292 }
293
294 /* switch audio */
8a4b275f 295 switch (state->audmode) {
7e8b09ea 296 case V4L2_TUNER_MODE_STEREO:
8a4b275f 297 src |= 0x0020;
7e8b09ea
HV
298 break;
299 case V4L2_TUNER_MODE_MONO:
300 if (state->mode == MSP_MODE_AM_NICAM) {
f167cb4e 301 v4l_dbg(1, msp_debug, client, "switching to AM mono\n");
7e8b09ea
HV
302 /* AM mono decoding is handled by tuner, not MSP chip */
303 /* SCART switching control register */
304 msp_set_scart(client, SCART_MONO, 0);
305 src = 0x0200;
306 break;
307 }
8a4b275f
HV
308 if (state->rxsubchans & V4L2_TUNER_SUB_STEREO)
309 src = 0x0030;
310 break;
7e8b09ea 311 case V4L2_TUNER_MODE_LANG1:
8a4b275f
HV
312 /* switch to stereo for stereo transmission, otherwise
313 keep first language */
314 if (state->rxsubchans & V4L2_TUNER_SUB_STEREO)
315 src |= 0x0020;
7e8b09ea
HV
316 break;
317 case V4L2_TUNER_MODE_LANG2:
8a4b275f 318 src |= 0x0010;
7e8b09ea
HV
319 break;
320 }
8a4b275f 321 v4l_dbg(1, msp_debug, client, "set_audmode final source/matrix = 0x%x\n", src);
7e8b09ea 322
8a4b275f 323 msp_set_source(client, src);
7e8b09ea
HV
324}
325
326static void msp3400c_print_mode(struct i2c_client *client)
327{
328 struct msp_state *state = i2c_get_clientdata(client);
329
330 if (state->main == state->second) {
f167cb4e 331 v4l_dbg(1, msp_debug, client, "mono sound carrier: %d.%03d MHz\n",
7e8b09ea
HV
332 state->main / 910000, (state->main / 910) % 1000);
333 } else {
f167cb4e 334 v4l_dbg(1, msp_debug, client, "main sound carrier: %d.%03d MHz\n",
7e8b09ea
HV
335 state->main / 910000, (state->main / 910) % 1000);
336 }
337 if (state->mode == MSP_MODE_FM_NICAM1 || state->mode == MSP_MODE_FM_NICAM2)
f167cb4e 338 v4l_dbg(1, msp_debug, client, "NICAM/FM carrier : %d.%03d MHz\n",
7e8b09ea
HV
339 state->second / 910000, (state->second/910) % 1000);
340 if (state->mode == MSP_MODE_AM_NICAM)
f167cb4e 341 v4l_dbg(1, msp_debug, client, "NICAM/AM carrier : %d.%03d MHz\n",
7e8b09ea
HV
342 state->second / 910000, (state->second / 910) % 1000);
343 if (state->mode == MSP_MODE_FM_TERRA && state->main != state->second) {
f167cb4e 344 v4l_dbg(1, msp_debug, client, "FM-stereo carrier : %d.%03d MHz\n",
7e8b09ea
HV
345 state->second / 910000, (state->second / 910) % 1000);
346 }
347}
348
349/* ----------------------------------------------------------------------- */
350
8a4b275f 351static int msp3400c_detect_stereo(struct i2c_client *client)
7e8b09ea
HV
352{
353 struct msp_state *state = i2c_get_clientdata(client);
354 int val;
355 int rxsubchans = state->rxsubchans;
8a4b275f 356 int newnicam = state->nicam_on;
7e8b09ea
HV
357 int update = 0;
358
359 switch (state->mode) {
360 case MSP_MODE_FM_TERRA:
361 val = msp_read_dsp(client, 0x18);
362 if (val > 32767)
363 val -= 65536;
f167cb4e 364 v4l_dbg(2, msp_debug, client, "stereo detect register: %d\n", val);
7e8b09ea 365 if (val > 4096) {
8a4b275f 366 rxsubchans = V4L2_TUNER_SUB_STEREO;
7e8b09ea
HV
367 } else if (val < -4096) {
368 rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
369 } else {
370 rxsubchans = V4L2_TUNER_SUB_MONO;
371 }
372 newnicam = 0;
373 break;
374 case MSP_MODE_FM_NICAM1:
375 case MSP_MODE_FM_NICAM2:
376 case MSP_MODE_AM_NICAM:
377 val = msp_read_dem(client, 0x23);
f167cb4e 378 v4l_dbg(2, msp_debug, client, "nicam sync=%d, mode=%d\n",
7e8b09ea
HV
379 val & 1, (val & 0x1e) >> 1);
380
381 if (val & 1) {
382 /* nicam synced */
383 switch ((val & 0x1e) >> 1) {
384 case 0:
385 case 8:
386 rxsubchans = V4L2_TUNER_SUB_STEREO;
387 break;
388 case 1:
389 case 9:
8a4b275f 390 rxsubchans = V4L2_TUNER_SUB_MONO;
7e8b09ea
HV
391 break;
392 case 2:
393 case 10:
8a4b275f 394 rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
7e8b09ea
HV
395 break;
396 default:
397 rxsubchans = V4L2_TUNER_SUB_MONO;
398 break;
399 }
400 newnicam = 1;
401 } else {
402 newnicam = 0;
403 rxsubchans = V4L2_TUNER_SUB_MONO;
404 }
405 break;
7e8b09ea
HV
406 }
407 if (rxsubchans != state->rxsubchans) {
408 update = 1;
8a4b275f
HV
409 v4l_dbg(1, msp_debug, client, "watch: rxsubchans %02x => %02x\n",
410 state->rxsubchans, rxsubchans);
7e8b09ea
HV
411 state->rxsubchans = rxsubchans;
412 }
413 if (newnicam != state->nicam_on) {
414 update = 1;
f167cb4e 415 v4l_dbg(1, msp_debug, client, "watch: nicam %d => %d\n",
8a4b275f 416 state->nicam_on, newnicam);
7e8b09ea
HV
417 state->nicam_on = newnicam;
418 }
419 return update;
420}
421
422/*
423 * A kernel thread for msp3400 control -- we don't want to block the
424 * in the ioctl while doing the sound carrier & stereo detect
425 */
426/* stereo/multilang monitoring */
427static void watch_stereo(struct i2c_client *client)
428{
429 struct msp_state *state = i2c_get_clientdata(client);
430
de533ccf
HV
431 if (msp_detect_stereo(client)) {
432 msp_set_audmode(client);
7e8b09ea
HV
433 }
434
f167cb4e 435 if (msp_once)
7e8b09ea
HV
436 state->watch_stereo = 0;
437}
438
439int msp3400c_thread(void *data)
440{
441 struct i2c_client *client = data;
442 struct msp_state *state = i2c_get_clientdata(client);
443 struct msp3400c_carrier_detect *cd;
8a4b275f 444 int count, max1, max2, val1, val2, val, this;
7e8b09ea
HV
445
446
f167cb4e 447 v4l_dbg(1, msp_debug, client, "msp3400 daemon started\n");
7e8b09ea 448 for (;;) {
f167cb4e 449 v4l_dbg(2, msp_debug, client, "msp3400 thread: sleep\n");
7e8b09ea 450 msp_sleep(state, -1);
f167cb4e 451 v4l_dbg(2, msp_debug, client, "msp3400 thread: wakeup\n");
7e8b09ea
HV
452
453 restart:
8a4b275f 454 v4l_dbg(2, msp_debug, client, "thread: restart scan\n");
7e8b09ea
HV
455 state->restart = 0;
456 if (kthread_should_stop())
457 break;
458
7560d7a4 459 if (state->radio || MSP_MODE_EXTERN == state->mode) {
7e8b09ea 460 /* no carrier scan, just unmute */
f167cb4e 461 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n");
7e8b09ea
HV
462 msp_set_audio(client);
463 continue;
464 }
465
466 /* mute */
467 msp_set_mute(client);
de533ccf 468 msp3400c_set_mode(client, MSP_MODE_AM_DETECT);
7e8b09ea
HV
469 val1 = val2 = 0;
470 max1 = max2 = -1;
471 state->watch_stereo = 0;
8a4b275f 472 state->nicam_on = 0;
7e8b09ea
HV
473
474 /* some time for the tuner to sync */
8a4b275f 475 if (msp_sleep(state, 200))
7e8b09ea
HV
476 goto restart;
477
478 /* carrier detect pass #1 -- main carrier */
479 cd = msp3400c_carrier_detect_main;
480 count = ARRAY_SIZE(msp3400c_carrier_detect_main);
481
f167cb4e 482 if (msp_amsound && (state->v4l2_std & V4L2_STD_SECAM)) {
7e8b09ea
HV
483 /* autodetect doesn't work well with AM ... */
484 max1 = 3;
485 count = 0;
f167cb4e 486 v4l_dbg(1, msp_debug, client, "AM sound override\n");
7e8b09ea
HV
487 }
488
489 for (this = 0; this < count; this++) {
8a4b275f 490 msp3400c_set_carrier(client, cd[this].cdo, cd[this].cdo);
7e8b09ea
HV
491 if (msp_sleep(state,100))
492 goto restart;
493 val = msp_read_dsp(client, 0x1b);
494 if (val > 32767)
495 val -= 65536;
496 if (val1 < val)
497 val1 = val, max1 = this;
f167cb4e 498 v4l_dbg(1, msp_debug, client, "carrier1 val: %5d / %s\n", val,cd[this].name);
7e8b09ea
HV
499 }
500
501 /* carrier detect pass #2 -- second (stereo) carrier */
502 switch (max1) {
503 case 1: /* 5.5 */
504 cd = msp3400c_carrier_detect_55;
505 count = ARRAY_SIZE(msp3400c_carrier_detect_55);
506 break;
507 case 3: /* 6.5 */
508 cd = msp3400c_carrier_detect_65;
509 count = ARRAY_SIZE(msp3400c_carrier_detect_65);
510 break;
511 case 0: /* 4.5 */
512 case 2: /* 6.0 */
513 default:
514 cd = NULL;
515 count = 0;
516 break;
517 }
518
f167cb4e 519 if (msp_amsound && (state->v4l2_std & V4L2_STD_SECAM)) {
7e8b09ea
HV
520 /* autodetect doesn't work well with AM ... */
521 cd = NULL;
522 count = 0;
523 max2 = 0;
524 }
525 for (this = 0; this < count; this++) {
8a4b275f 526 msp3400c_set_carrier(client, cd[this].cdo, cd[this].cdo);
7e8b09ea
HV
527 if (msp_sleep(state,100))
528 goto restart;
529 val = msp_read_dsp(client, 0x1b);
530 if (val > 32767)
531 val -= 65536;
532 if (val2 < val)
533 val2 = val, max2 = this;
f167cb4e 534 v4l_dbg(1, msp_debug, client, "carrier2 val: %5d / %s\n", val,cd[this].name);
7e8b09ea
HV
535 }
536
537 /* program the msp3400 according to the results */
8a4b275f 538 state->main = msp3400c_carrier_detect_main[max1].cdo;
7e8b09ea
HV
539 switch (max1) {
540 case 1: /* 5.5 */
541 if (max2 == 0) {
542 /* B/G FM-stereo */
543 state->second = msp3400c_carrier_detect_55[max2].cdo;
8a4b275f 544 msp3400c_set_mode(client, MSP_MODE_FM_TERRA);
7e8b09ea 545 state->watch_stereo = 1;
7560d7a4 546 } else if (max2 == 1 && state->has_nicam) {
7e8b09ea
HV
547 /* B/G NICAM */
548 state->second = msp3400c_carrier_detect_55[max2].cdo;
8a4b275f
HV
549 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1);
550 msp3400c_set_carrier(client, state->second, state->main);
7e8b09ea 551 state->nicam_on = 1;
7e8b09ea
HV
552 state->watch_stereo = 1;
553 } else {
554 goto no_second;
555 }
556 break;
557 case 2: /* 6.0 */
558 /* PAL I NICAM */
559 state->second = MSP_CARRIER(6.552);
8a4b275f
HV
560 msp3400c_set_mode(client, MSP_MODE_FM_NICAM2);
561 msp3400c_set_carrier(client, state->second, state->main);
7e8b09ea 562 state->nicam_on = 1;
7e8b09ea
HV
563 state->watch_stereo = 1;
564 break;
565 case 3: /* 6.5 */
566 if (max2 == 1 || max2 == 2) {
567 /* D/K FM-stereo */
568 state->second = msp3400c_carrier_detect_65[max2].cdo;
8a4b275f 569 msp3400c_set_mode(client, MSP_MODE_FM_TERRA);
7e8b09ea 570 state->watch_stereo = 1;
5af0c8f6 571 } else if (max2 == 0 && (state->v4l2_std & V4L2_STD_SECAM)) {
7e8b09ea
HV
572 /* L NICAM or AM-mono */
573 state->second = msp3400c_carrier_detect_65[max2].cdo;
8a4b275f
HV
574 msp3400c_set_mode(client, MSP_MODE_AM_NICAM);
575 msp3400c_set_carrier(client, state->second, state->main);
7e8b09ea 576 state->watch_stereo = 1;
7560d7a4 577 } else if (max2 == 0 && state->has_nicam) {
7e8b09ea
HV
578 /* D/K NICAM */
579 state->second = msp3400c_carrier_detect_65[max2].cdo;
8a4b275f
HV
580 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1);
581 msp3400c_set_carrier(client, state->second, state->main);
7e8b09ea 582 state->nicam_on = 1;
7e8b09ea
HV
583 state->watch_stereo = 1;
584 } else {
585 goto no_second;
586 }
587 break;
588 case 0: /* 4.5 */
589 default:
590 no_second:
591 state->second = msp3400c_carrier_detect_main[max1].cdo;
8a4b275f
HV
592 msp3400c_set_mode(client, MSP_MODE_FM_TERRA);
593 msp3400c_set_carrier(client, state->second, state->main);
7e8b09ea 594 state->rxsubchans = V4L2_TUNER_SUB_MONO;
7e8b09ea
HV
595 break;
596 }
597
598 /* unmute */
599 msp_set_audio(client);
8a4b275f 600 msp3400c_set_audmode(client);
7e8b09ea 601
f167cb4e 602 if (msp_debug)
7e8b09ea
HV
603 msp3400c_print_mode(client);
604
8a4b275f
HV
605 /* monitor tv audio mode, the first time don't wait
606 so long to get a quick stereo/bilingual result */
607 if (msp_sleep(state, 1000))
608 goto restart;
7e8b09ea 609 while (state->watch_stereo) {
8a4b275f 610 if (msp_sleep(state, 5000))
7e8b09ea
HV
611 goto restart;
612 watch_stereo(client);
613 }
614 }
f167cb4e 615 v4l_dbg(1, msp_debug, client, "thread: exit\n");
7e8b09ea
HV
616 return 0;
617}
618
619
620int msp3410d_thread(void *data)
621{
622 struct i2c_client *client = data;
623 struct msp_state *state = i2c_get_clientdata(client);
d312a46e 624 int val, i, std;
7e8b09ea 625
f167cb4e 626 v4l_dbg(1, msp_debug, client, "msp3410 daemon started\n");
7e8b09ea
HV
627
628 for (;;) {
f167cb4e 629 v4l_dbg(2, msp_debug, client, "msp3410 thread: sleep\n");
7e8b09ea 630 msp_sleep(state,-1);
f167cb4e 631 v4l_dbg(2, msp_debug, client, "msp3410 thread: wakeup\n");
7e8b09ea
HV
632
633 restart:
8a4b275f 634 v4l_dbg(2, msp_debug, client, "thread: restart scan\n");
7e8b09ea
HV
635 state->restart = 0;
636 if (kthread_should_stop())
637 break;
638
639 if (state->mode == MSP_MODE_EXTERN) {
640 /* no carrier scan needed, just unmute */
f167cb4e 641 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n");
7e8b09ea
HV
642 msp_set_audio(client);
643 continue;
644 }
645
646 /* put into sane state (and mute) */
647 msp_reset(client);
648
649 /* some time for the tuner to sync */
650 if (msp_sleep(state,200))
651 goto restart;
652
de533ccf
HV
653 /* start autodetect. Note: autodetect is not supported for
654 NTSC-M and radio, hence we force the standard in those cases. */
5af0c8f6
HV
655 if (state->radio)
656 std = 0x40;
d312a46e 657 else
5af0c8f6 658 std = (state->v4l2_std & V4L2_STD_NTSC) ? 0x20 : 1;
7e8b09ea 659 state->watch_stereo = 0;
8a4b275f 660 state->nicam_on = 0;
7e8b09ea 661
f167cb4e 662 if (msp_debug)
8a4b275f 663 v4l_dbg(2, msp_debug, client, "setting standard: %s (0x%04x)\n",
5af0c8f6 664 msp_standard_std_name(std), std);
7e8b09ea
HV
665
666 if (std != 1) {
667 /* programmed some specific mode */
668 val = std;
669 } else {
670 /* triggered autodetect */
5af0c8f6 671 msp_write_dem(client, 0x20, std);
7e8b09ea 672 for (;;) {
d312a46e 673 if (msp_sleep(state, 100))
7e8b09ea
HV
674 goto restart;
675
676 /* check results */
677 val = msp_read_dem(client, 0x7e);
678 if (val < 0x07ff)
679 break;
8a4b275f 680 v4l_dbg(2, msp_debug, client, "detection still in progress\n");
7e8b09ea
HV
681 }
682 }
5af0c8f6
HV
683 for (i = 0; msp_stdlist[i].name != NULL; i++)
684 if (msp_stdlist[i].retval == val)
7e8b09ea 685 break;
f167cb4e 686 v4l_dbg(1, msp_debug, client, "current standard: %s (0x%04x)\n",
5af0c8f6
HV
687 msp_standard_std_name(val), val);
688 state->main = msp_stdlist[i].main;
689 state->second = msp_stdlist[i].second;
690 state->std = val;
691
f167cb4e 692 if (msp_amsound && !state->radio && (state->v4l2_std & V4L2_STD_SECAM) &&
5af0c8f6 693 (val != 0x0009)) {
7e8b09ea 694 /* autodetection has failed, let backup */
f167cb4e 695 v4l_dbg(1, msp_debug, client, "autodetection failed,"
5af0c8f6
HV
696 " switching to backup standard: %s (0x%04x)\n",
697 msp_stdlist[8].name ? msp_stdlist[8].name : "unknown",val);
de533ccf 698 state->std = val = 0x0009;
7e8b09ea
HV
699 msp_write_dem(client, 0x20, val);
700 }
701
7e8b09ea
HV
702 /* set stereo */
703 switch (val) {
704 case 0x0008: /* B/G NICAM */
705 case 0x000a: /* I NICAM */
de533ccf
HV
706 case 0x000b: /* D/K NICAM */
707 if (val == 0x000a)
7e8b09ea 708 state->mode = MSP_MODE_FM_NICAM2;
de533ccf
HV
709 else
710 state->mode = MSP_MODE_FM_NICAM1;
7e8b09ea
HV
711 /* just turn on stereo */
712 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
713 state->nicam_on = 1;
714 state->watch_stereo = 1;
7e8b09ea
HV
715 break;
716 case 0x0009:
717 state->mode = MSP_MODE_AM_NICAM;
718 state->rxsubchans = V4L2_TUNER_SUB_MONO;
719 state->nicam_on = 1;
7e8b09ea
HV
720 state->watch_stereo = 1;
721 break;
722 case 0x0020: /* BTSC */
8a4b275f 723 /* The pre-'G' models only have BTSC-mono */
7e8b09ea 724 state->mode = MSP_MODE_BTSC;
8a4b275f 725 state->rxsubchans = V4L2_TUNER_SUB_MONO;
7e8b09ea
HV
726 break;
727 case 0x0040: /* FM radio */
7560d7a4 728 state->mode = MSP_MODE_FM_RADIO;
7e8b09ea 729 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
7560d7a4 730 /* not needed in theory if we have radio, but
7e8b09ea 731 short programming enables carrier mute */
8a4b275f
HV
732 msp3400c_set_mode(client, MSP_MODE_FM_RADIO);
733 msp3400c_set_carrier(client, MSP_CARRIER(10.7),
7e8b09ea 734 MSP_CARRIER(10.7));
8a4b275f 735 /* scart routing (this doesn't belong here I think) */
7e8b09ea 736 msp_set_scart(client,SCART_IN2,0);
7e8b09ea 737 break;
de533ccf 738 case 0x0002:
7e8b09ea
HV
739 case 0x0003:
740 case 0x0004:
741 case 0x0005:
5af0c8f6 742 state->mode = MSP_MODE_FM_TERRA;
7e8b09ea 743 state->rxsubchans = V4L2_TUNER_SUB_MONO;
7e8b09ea
HV
744 state->watch_stereo = 1;
745 break;
746 }
747
de533ccf
HV
748 /* set various prescales */
749 msp_write_dsp(client, 0x0d, 0x1900); /* scart */
750 msp_write_dsp(client, 0x0e, 0x3000); /* FM */
751 if (state->has_nicam)
752 msp_write_dsp(client, 0x10, 0x5a00); /* nicam */
753
5af0c8f6
HV
754 if (state->has_i2s_conf)
755 msp_write_dem(client, 0x40, state->i2s_mode);
7e8b09ea 756
de533ccf
HV
757 /* unmute, restore misc registers */
758 msp_set_audio(client);
759
760 msp_write_dsp(client, 0x13, state->acb);
8a4b275f
HV
761 msp3400c_set_audmode(client);
762
763 /* monitor tv audio mode, the first time don't wait
764 so long to get a quick stereo/bilingual result */
765 if (msp_sleep(state, 1000))
766 goto restart;
7e8b09ea 767 while (state->watch_stereo) {
7e8b09ea 768 watch_stereo(client);
8a4b275f
HV
769 if (msp_sleep(state, 5000))
770 goto restart;
7e8b09ea
HV
771 }
772 }
f167cb4e 773 v4l_dbg(1, msp_debug, client, "thread: exit\n");
7e8b09ea
HV
774 return 0;
775}
776
777/* ----------------------------------------------------------------------- */
778
de533ccf
HV
779/* msp34xxG + (autoselect no-thread)
780 * this one uses both automatic standard detection and automatic sound
781 * select which are available in the newer G versions
782 * struct msp: only norm, acb and source are really used in this mode
783 */
7e8b09ea
HV
784
785/* set the same 'source' for the loudspeaker, scart and quasi-peak detector
786 * the value for source is the same as bit 15:8 of DSP registers 0x08,
787 * 0x0a and 0x0c: 0=mono, 1=stereo or A|B, 2=SCART, 3=stereo or A, 4=stereo or B
7e8b09ea
HV
788 */
789static void msp34xxg_set_source(struct i2c_client *client, int source)
790{
791 struct msp_state *state = i2c_get_clientdata(client);
792
793 /* fix matrix mode to stereo and let the msp choose what
794 * to output according to 'source', as recommended
795 * for MONO (source==0) downmixing set bit[7:0] to 0x30
796 */
797 int value = (source & 0x07) << 8 | (source == 0 ? 0x30 : 0x20);
798
f167cb4e 799 v4l_dbg(1, msp_debug, client, "set source to %d (0x%x)\n", source, value);
8a4b275f 800 msp_set_source(client, value);
7e8b09ea
HV
801 /*
802 * set identification threshold. Personally, I
803 * I set it to a higher value that the default
804 * of 0x190 to ignore noisy stereo signals.
805 * this needs tuning. (recommended range 0x00a0-0x03c0)
806 * 0x7f0 = forced mono mode
807 */
808 /* a2 threshold for stereo/bilingual */
f167cb4e 809 msp_write_dem(client, 0x22, msp_stereo_thresh);
7e8b09ea
HV
810 state->source = source;
811}
812
9a80a93d
HV
813static int msp34xxg_modus(struct i2c_client *client)
814{
815 struct msp_state *state = i2c_get_clientdata(client);
816
817 if (state->radio) {
818 v4l_dbg(1, msp_debug, client, "selected radio modus\n");
819 return 0x0001;
820 }
821
822 if (state->v4l2_std & V4L2_STD_PAL) {
823 v4l_dbg(1, msp_debug, client, "selected PAL modus\n");
824 return 0x7001;
825 }
826 if (state->v4l2_std == V4L2_STD_NTSC_M_JP) {
827 v4l_dbg(1, msp_debug, client, "selected M (EIA-J) modus\n");
828 return 0x4001;
829 }
830 if (state->v4l2_std == V4L2_STD_NTSC_M_KR) {
831 v4l_dbg(1, msp_debug, client, "selected M (A2) modus\n");
832 return 0x0001;
833 }
834 if (state->v4l2_std & V4L2_STD_MN) {
835 v4l_dbg(1, msp_debug, client, "selected M (BTSC) modus\n");
836 return 0x2001;
837 }
838 if (state->v4l2_std & V4L2_STD_SECAM) {
839 v4l_dbg(1, msp_debug, client, "selected SECAM modus\n");
840 return 0x6001;
841 }
842 return 0x0001;
843}
844
de533ccf
HV
845/* (re-)initialize the msp34xxg */
846static void msp34xxg_reset(struct i2c_client *client)
7e8b09ea
HV
847{
848 struct msp_state *state = i2c_get_clientdata(client);
de533ccf 849 int modus;
7e8b09ea 850
de533ccf
HV
851 /* initialize std to 1 (autodetect) to signal that no standard is
852 selected yet. */
853 state->std = 1;
854
855 msp_reset(client);
7e8b09ea
HV
856
857 /* make sure that input/output is muted (paranoid mode) */
858 /* ACB, mute DSP input, mute SCART 1 */
de533ccf 859 msp_write_dsp(client, 0x13, 0x0f20);
7e8b09ea 860
5af0c8f6
HV
861 if (state->has_i2s_conf)
862 msp_write_dem(client, 0x40, state->i2s_mode);
7e8b09ea
HV
863
864 /* step-by-step initialisation, as described in the manual */
9a80a93d 865 modus = msp34xxg_modus(client);
de533ccf 866 msp_write_dem(client, 0x30, modus);
7e8b09ea
HV
867
868 /* write the dsps that may have an influence on
869 standard/audio autodetection right now */
870 msp34xxg_set_source(client, state->source);
871
de533ccf
HV
872 msp_write_dsp(client, 0x0d, 0x1900); /* scart */
873 msp_write_dsp(client, 0x0e, 0x3000); /* FM */
874 if (state->has_nicam)
875 msp_write_dsp(client, 0x10, 0x5a00); /* nicam */
7e8b09ea 876
de533ccf
HV
877 /* set identification threshold. Personally, I
878 * I set it to a higher value than the default
879 * of 0x190 to ignore noisy stereo signals.
880 * this needs tuning. (recommended range 0x00a0-0x03c0)
881 * 0x7f0 = forced mono mode
882 *
883 * a2 threshold for stereo/bilingual.
884 * Note: this register is part of the Manual/Compatibility mode.
885 * It is supported by all 'G'-family chips.
886 */
887 msp_write_dem(client, 0x22, msp_stereo_thresh);
7e8b09ea
HV
888}
889
890int msp34xxg_thread(void *data)
891{
892 struct i2c_client *client = data;
893 struct msp_state *state = i2c_get_clientdata(client);
de533ccf 894 int val, i;
7e8b09ea 895
f167cb4e 896 v4l_dbg(1, msp_debug, client, "msp34xxg daemon started\n");
7e8b09ea
HV
897
898 state->source = 1; /* default */
899 for (;;) {
f167cb4e 900 v4l_dbg(2, msp_debug, client, "msp34xxg thread: sleep\n");
7e8b09ea 901 msp_sleep(state, -1);
f167cb4e 902 v4l_dbg(2, msp_debug, client, "msp34xxg thread: wakeup\n");
7e8b09ea
HV
903
904 restart:
f167cb4e 905 v4l_dbg(1, msp_debug, client, "thread: restart scan\n");
7e8b09ea
HV
906 state->restart = 0;
907 if (kthread_should_stop())
908 break;
909
910 /* setup the chip*/
911 msp34xxg_reset(client);
de533ccf
HV
912 state->std = state->radio ? 0x40 : msp_standard;
913 if (state->std != 1)
7e8b09ea 914 goto unmute;
de533ccf
HV
915 /* start autodetect */
916 msp_write_dem(client, 0x20, state->std);
7e8b09ea
HV
917
918 /* watch autodetect */
de533ccf 919 v4l_dbg(1, msp_debug, client, "started autodetect, waiting for result\n");
7e8b09ea
HV
920 for (i = 0; i < 10; i++) {
921 if (msp_sleep(state, 100))
922 goto restart;
923
924 /* check results */
925 val = msp_read_dem(client, 0x7e);
926 if (val < 0x07ff) {
de533ccf 927 state->std = val;
7e8b09ea
HV
928 break;
929 }
f167cb4e 930 v4l_dbg(2, msp_debug, client, "detection still in progress\n");
7e8b09ea 931 }
de533ccf 932 if (state->std == 1) {
f167cb4e 933 v4l_dbg(1, msp_debug, client, "detection still in progress after 10 tries. giving up.\n");
7e8b09ea
HV
934 continue;
935 }
936
937 unmute:
de533ccf
HV
938 v4l_dbg(1, msp_debug, client, "detected standard: %s (0x%04x)\n",
939 msp_standard_std_name(state->std), state->std);
7e8b09ea
HV
940
941 /* unmute: dispatch sound to scart output, set scart volume */
942 msp_set_audio(client);
943
944 /* restore ACB */
945 if (msp_write_dsp(client, 0x13, state->acb))
946 return -1;
947
de533ccf
HV
948 /* the periodic stereo/SAP check is only relevant for
949 the 0x20 standard (BTSC) */
950 if (state->std != 0x20)
951 continue;
952
953 state->watch_stereo = 1;
954
955 /* monitor tv audio mode, the first time don't wait
956 in order to get a quick stereo/SAP update */
957 watch_stereo(client);
958 while (state->watch_stereo) {
959 watch_stereo(client);
960 if (msp_sleep(state, 5000))
961 goto restart;
962 }
7e8b09ea 963 }
f167cb4e 964 v4l_dbg(1, msp_debug, client, "thread: exit\n");
7e8b09ea
HV
965 return 0;
966}
967
de533ccf 968static int msp34xxg_detect_stereo(struct i2c_client *client)
7e8b09ea
HV
969{
970 struct msp_state *state = i2c_get_clientdata(client);
7e8b09ea
HV
971 int status = msp_read_dem(client, 0x0200);
972 int is_bilingual = status & 0x100;
973 int is_stereo = status & 0x40;
de533ccf 974 int oldrx = state->rxsubchans;
7e8b09ea
HV
975
976 state->rxsubchans = 0;
977 if (is_stereo)
8a4b275f 978 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
7e8b09ea 979 else
8a4b275f 980 state->rxsubchans = V4L2_TUNER_SUB_MONO;
7e8b09ea 981 if (is_bilingual) {
de533ccf
HV
982 if (state->std == 0x20)
983 state->rxsubchans |= V4L2_TUNER_SUB_SAP;
984 else
985 state->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
7e8b09ea 986 }
f167cb4e 987 v4l_dbg(1, msp_debug, client, "status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n",
7e8b09ea 988 status, is_stereo, is_bilingual, state->rxsubchans);
de533ccf 989 return (oldrx != state->rxsubchans);
7e8b09ea
HV
990}
991
044f324f 992static void msp34xxg_set_audmode(struct i2c_client *client)
7e8b09ea
HV
993{
994 struct msp_state *state = i2c_get_clientdata(client);
995 int source;
996
de533ccf
HV
997 if (state->std == 0x20) {
998 if ((state->rxsubchans & V4L2_TUNER_SUB_SAP) &&
999 (state->audmode == V4L2_TUNER_MODE_STEREO ||
1000 state->audmode == V4L2_TUNER_MODE_LANG2)) {
1001 msp_write_dem(client, 0x20, 0x21);
1002 } else {
1003 msp_write_dem(client, 0x20, 0x20);
1004 }
1005 }
1006
8a4b275f 1007 switch (state->audmode) {
7e8b09ea
HV
1008 case V4L2_TUNER_MODE_MONO:
1009 source = 0; /* mono only */
1010 break;
1011 case V4L2_TUNER_MODE_STEREO:
1012 source = 1; /* stereo or A|B, see comment in msp34xxg_get_v4l2_stereo() */
1013 /* problem: that could also mean 2 (scart input) */
1014 break;
1015 case V4L2_TUNER_MODE_LANG1:
1016 source = 3; /* stereo or A */
1017 break;
1018 case V4L2_TUNER_MODE_LANG2:
1019 source = 4; /* stereo or B */
1020 break;
1021 default:
7e8b09ea
HV
1022 source = 1;
1023 break;
1024 }
7e8b09ea
HV
1025 msp34xxg_set_source(client, source);
1026}
1027
8a4b275f
HV
1028void msp_set_audmode(struct i2c_client *client)
1029{
1030 struct msp_state *state = i2c_get_clientdata(client);
1031
1032 switch (state->opmode) {
1033 case OPMODE_MANUAL:
1034 case OPMODE_AUTODETECT:
8a4b275f
HV
1035 msp3400c_set_audmode(client);
1036 break;
1037 case OPMODE_AUTOSELECT:
1038 msp34xxg_set_audmode(client);
1039 break;
1040 }
1041}
1042
de533ccf 1043int msp_detect_stereo(struct i2c_client *client)
8a4b275f
HV
1044{
1045 struct msp_state *state = i2c_get_clientdata(client);
1046
1047 switch (state->opmode) {
1048 case OPMODE_MANUAL:
1049 case OPMODE_AUTODETECT:
de533ccf 1050 return msp3400c_detect_stereo(client);
8a4b275f 1051 case OPMODE_AUTOSELECT:
de533ccf 1052 return msp34xxg_detect_stereo(client);
8a4b275f 1053 }
de533ccf 1054 return 0;
8a4b275f
HV
1055}
1056