2 * programming the msp34* sound processor family
4 * (c) 1997-2001 Gerd Knorr <kraxel@bytesex.org>
6 * what works and what doesn't:
9 * Support for Hauppauge cards added (decoding handled by tuner) added by
10 * Frederic Crozat <fcrozat@mail.dotcom.fr>
13 * should work. The stereo modes are backward compatible to FM-mono,
14 * therefore FM-Mono should be allways available.
16 * FM-Stereo (B/G, used in germany)
17 * should work, with autodetect
19 * FM-Stereo (satellite)
20 * should work, no autodetect (i.e. default is mono, but you can
21 * switch to stereo -- untested)
23 * NICAM (B/G, L , used in UK, Scandinavia, Spain and France)
24 * should work, with autodetect. Support for NICAM was added by
25 * Pekka Pietikainen <pp@netppl.fi>
29 * - better SAT support
32 * 980623 Thomas Sailer (sailer@ife.ee.ethz.ch)
33 * using soundcore instead of OSS
37 #include <linux/config.h>
38 #include <linux/module.h>
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/string.h>
42 #include <linux/timer.h>
43 #include <linux/delay.h>
44 #include <linux/errno.h>
45 #include <linux/slab.h>
46 #include <linux/i2c.h>
47 #include <linux/videodev.h>
48 #include <linux/init.h>
49 #include <linux/smp_lock.h>
50 #include <asm/semaphore.h>
51 #include <asm/pgtable.h>
53 #include <media/audiochip.h>
57 /* insmod parameters */
58 static int debug
= 0; /* debug output */
59 static int once
= 0; /* no continous stereo monitoring */
60 static int amsound
= 0; /* hard-wire AM sound at 6.5 Hz (france),
61 the autoscan seems work well only with FM... */
62 static int simple
= -1; /* use short programming (>= msp3410 only) */
65 #define DFP_COUNT 0x41
66 static const int bl_dfp
[] = {
67 0x00, 0x01, 0x02, 0x03, 0x06, 0x08, 0x09, 0x0a,
68 0x0b, 0x0d, 0x0e, 0x10
80 int main
, second
; /* sound carrier */
87 /* shadow register set */
88 int dfp_regs
[DFP_COUNT
];
92 struct completion texit
;
100 struct timer_list wake_stereo
;
103 #define HAVE_NICAM(msp) (((msp->rev2>>8) & 0xff) != 00)
104 #define HAVE_SIMPLE(msp) ((msp->rev1 & 0xff) >= 'D'-'@')
105 #define HAVE_RADIO(msp) ((msp->rev1 & 0xff) >= 'G'-'@')
107 #define VIDEO_MODE_RADIO 16 /* norm magic for radio mode */
109 /* ---------------------------------------------------------------------- */
111 #define dprintk if (debug >= 1) printk
112 #define d2printk if (debug >= 2) printk
114 MODULE_PARM(once
,"i");
115 MODULE_PARM(debug
,"i");
116 MODULE_PARM(simple
,"i");
117 MODULE_PARM(amsound
,"i");
118 MODULE_PARM(dolby
,"i");
120 MODULE_DESCRIPTION("device driver for msp34xx TV sound processor");
121 MODULE_AUTHOR("Gerd Knorr");
122 MODULE_LICENSE("Dual BSD/GPL"); /* FreeBSD uses this too */
124 /* ---------------------------------------------------------------------- */
126 #define I2C_MSP3400C 0x80
127 #define I2C_MSP3400C_ALT 0x88
129 #define I2C_MSP3400C_DEM 0x10
130 #define I2C_MSP3400C_DFP 0x12
132 /* Addresses to scan */
133 static unsigned short normal_i2c
[] = {
135 I2C_MSP3400C_ALT
>> 1,
138 static unsigned short normal_i2c_range
[] = {I2C_CLIENT_END
,I2C_CLIENT_END
};
141 /* ----------------------------------------------------------------------- */
142 /* functions for talking to the MSP3400C Sound processor */
144 #ifndef I2C_M_IGNORE_NAK
145 # define I2C_M_IGNORE_NAK 0x1000
148 static int msp3400c_reset(struct i2c_client
*client
)
150 /* reset and read revision code */
151 static char reset_off
[3] = { 0x00, 0x80, 0x00 };
152 static char reset_on
[3] = { 0x00, 0x00, 0x00 };
153 static char write
[3] = { I2C_MSP3400C_DFP
+ 1, 0x00, 0x1e };
155 struct i2c_msg reset
[2] = {
156 { client
->addr
, I2C_M_IGNORE_NAK
, 3, reset_off
},
157 { client
->addr
, I2C_M_IGNORE_NAK
, 3, reset_on
},
159 struct i2c_msg test
[2] = {
160 { client
->addr
, 0, 3, write
},
161 { client
->addr
, I2C_M_RD
, 2, read
},
164 if ( (1 != i2c_transfer(client
->adapter
,&reset
[0],1)) ||
165 (1 != i2c_transfer(client
->adapter
,&reset
[1],1)) ||
166 (2 != i2c_transfer(client
->adapter
,test
,2)) ) {
167 printk(KERN_ERR
"msp3400: chip reset failed\n");
174 msp3400c_read(struct i2c_client
*client
, int dev
, int addr
)
178 unsigned char write
[3];
179 unsigned char read
[2];
180 struct i2c_msg msgs
[2] = {
181 { client
->addr
, 0, 3, write
},
182 { client
->addr
, I2C_M_RD
, 2, read
}
185 write
[1] = addr
>> 8;
186 write
[2] = addr
& 0xff;
188 for (err
= 0; err
< 3;) {
189 if (2 == i2c_transfer(client
->adapter
,msgs
,2))
192 printk(KERN_WARNING
"msp34xx: I/O error #%d (read 0x%02x/0x%02x)\n",
194 set_current_state(TASK_INTERRUPTIBLE
);
195 schedule_timeout(HZ
/10);
198 printk(KERN_WARNING
"msp34xx: giving up, reseting chip. Sound will go off, sorry folks :-|\n");
199 msp3400c_reset(client
);
202 return read
[0] << 8 | read
[1];
206 msp3400c_write(struct i2c_client
*client
, int dev
, int addr
, int val
)
209 unsigned char buffer
[5];
212 buffer
[1] = addr
>> 8;
213 buffer
[2] = addr
& 0xff;
214 buffer
[3] = val
>> 8;
215 buffer
[4] = val
& 0xff;
217 for (err
= 0; err
< 3;) {
218 if (5 == i2c_master_send(client
, buffer
, 5))
221 printk(KERN_WARNING
"msp34xx: I/O error #%d (write 0x%02x/0x%02x)\n",
223 set_current_state(TASK_INTERRUPTIBLE
);
224 schedule_timeout(HZ
/10);
227 printk(KERN_WARNING
"msp34xx: giving up, reseting chip. Sound will go off, sorry folks :-|\n");
228 msp3400c_reset(client
);
234 /* ------------------------------------------------------------------------ */
236 /* This macro is allowed for *constants* only, gcc must calculate it
237 at compile time. Remember -- no floats in kernel mode */
238 #define MSP_CARRIER(freq) ((int)((float)(freq/18.432)*(1<<24)))
240 #define MSP_MODE_AM_DETECT 0
241 #define MSP_MODE_FM_RADIO 2
242 #define MSP_MODE_FM_TERRA 3
243 #define MSP_MODE_FM_SAT 4
244 #define MSP_MODE_FM_NICAM1 5
245 #define MSP_MODE_FM_NICAM2 6
246 #define MSP_MODE_AM_NICAM 7
247 #define MSP_MODE_BTSC 8
248 #define MSP_MODE_EXTERN 9
250 static struct MSP_INIT_DATA_DEM
{
259 } msp_init_data
[] = {
260 /* AM (for carrier detect / msp3400) */
261 { { 75, 19, 36, 35, 39, 40 }, { 75, 19, 36, 35, 39, 40 },
262 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
263 0x00d0, 0x0500, 0x0020, 0x3000},
265 /* AM (for carrier detect / msp3410) */
266 { { -1, -1, -8, 2, 59, 126 }, { -1, -1, -8, 2, 59, 126 },
267 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
268 0x00d0, 0x0100, 0x0020, 0x3000},
271 { { -8, -8, 4, 6, 78, 107 }, { -8, -8, 4, 6, 78, 107 },
272 MSP_CARRIER(10.7), MSP_CARRIER(10.7),
273 0x00d0, 0x0480, 0x0020, 0x3000 },
275 /* Terrestial FM-mono + FM-stereo */
276 { { 3, 18, 27, 48, 66, 72 }, { 3, 18, 27, 48, 66, 72 },
277 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
278 0x00d0, 0x0480, 0x0030, 0x3000},
281 { { 1, 9, 14, 24, 33, 37 }, { 3, 18, 27, 48, 66, 72 },
282 MSP_CARRIER(6.5), MSP_CARRIER(6.5),
283 0x00c6, 0x0480, 0x0000, 0x3000},
285 /* NICAM/FM -- B/G (5.5/5.85), D/K (6.5/5.85) */
286 { { -2, -8, -10, 10, 50, 86 }, { 3, 18, 27, 48, 66, 72 },
287 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
288 0x00d0, 0x0040, 0x0120, 0x3000},
290 /* NICAM/FM -- I (6.0/6.552) */
291 { { 2, 4, -6, -4, 40, 94 }, { 3, 18, 27, 48, 66, 72 },
292 MSP_CARRIER(6.0), MSP_CARRIER(6.0),
293 0x00d0, 0x0040, 0x0120, 0x3000},
295 /* NICAM/AM -- L (6.5/5.85) */
296 { { -2, -8, -10, 10, 50, 86 }, { -4, -12, -9, 23, 79, 126 },
297 MSP_CARRIER(6.5), MSP_CARRIER(6.5),
298 0x00c6, 0x0140, 0x0120, 0x7c03},
301 struct CARRIER_DETECT
{
306 static struct CARRIER_DETECT carrier_detect_main
[] = {
308 { MSP_CARRIER(4.5), "4.5 NTSC" },
309 { MSP_CARRIER(5.5), "5.5 PAL B/G" },
310 { MSP_CARRIER(6.0), "6.0 PAL I" },
311 { MSP_CARRIER(6.5), "6.5 PAL D/K + SAT + SECAM" }
314 static struct CARRIER_DETECT carrier_detect_55
[] = {
316 { MSP_CARRIER(5.7421875), "5.742 PAL B/G FM-stereo" },
317 { MSP_CARRIER(5.85), "5.85 PAL B/G NICAM" }
320 static struct CARRIER_DETECT carrier_detect_65
[] = {
321 /* PAL SAT / SECAM */
322 { MSP_CARRIER(5.85), "5.85 PAL D/K + SECAM NICAM" },
323 { MSP_CARRIER(6.2578125), "6.25 PAL D/K1 FM-stereo" },
324 { MSP_CARRIER(6.7421875), "6.74 PAL D/K2 FM-stereo" },
325 { MSP_CARRIER(7.02), "7.02 PAL SAT FM-stereo s/b" },
326 { MSP_CARRIER(7.20), "7.20 PAL SAT FM-stereo s" },
327 { MSP_CARRIER(7.38), "7.38 PAL SAT FM-stereo b" },
330 #define CARRIER_COUNT(x) (sizeof(x)/sizeof(struct CARRIER_DETECT))
332 /* ----------------------------------------------------------------------- */
337 #define SCART_IN1_DA 3
338 #define SCART_IN2_DA 4
344 static int scarts
[3][9] = {
345 /* MASK IN1 IN2 IN1_DA IN2_DA IN3 IN4 MONO MUTE */
346 { 0x0320, 0x0000, 0x0200, -1, -1, 0x0300, 0x0020, 0x0100, 0x0320 },
347 { 0x0c40, 0x0440, 0x0400, 0x0c00, 0x0040, 0x0000, 0x0840, 0x0800, 0x0c40 },
348 { 0x3080, 0x1000, 0x1080, 0x0000, 0x0080, 0x2080, 0x3080, 0x2000, 0x3000 },
351 static char *scart_names
[] = {
352 "mask", "in1", "in2", "in1 da", "in2 da", "in3", "in4", "mono", "mute"
356 msp3400c_set_scart(struct i2c_client
*client
, int in
, int out
)
358 struct msp3400c
*msp
= i2c_get_clientdata(client
);
360 if (-1 == scarts
[out
][in
])
364 "msp34xx: scart switch: %s => %d\n",scart_names
[in
],out
);
365 msp
->acb
&= ~scarts
[out
][SCART_MASK
];
366 msp
->acb
|= scarts
[out
][in
];
367 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0013, msp
->acb
);
370 /* ------------------------------------------------------------------------ */
372 static void msp3400c_setcarrier(struct i2c_client
*client
, int cdo1
, int cdo2
)
374 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x0093, cdo1
& 0xfff);
375 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x009b, cdo1
>> 12);
376 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x00a3, cdo2
& 0xfff);
377 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x00ab, cdo2
>> 12);
378 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x0056, 0); /*LOAD_REG_1/2*/
381 static void msp3400c_setvolume(struct i2c_client
*client
,
382 int muted
, int volume
, int balance
)
384 int val
= 0, bal
= 0;
387 val
= (volume
* 0x73 / 65535) << 8;
390 bal
= (balance
/ 256) - 128;
393 "msp34xx: setvolume: mute=%s %d:%d v=0x%02x b=0x%02x\n",
394 muted
? "on" : "off", volume
, balance
, val
>>8, bal
);
395 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0000, val
); /* loudspeaker */
396 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0006, val
); /* headphones */
397 /* scart - on/off only */
398 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0007, val
? 0x4000 : 0);
399 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0001, bal
<< 8);
402 static void msp3400c_setbass(struct i2c_client
*client
, int bass
)
404 int val
= ((bass
-32768) * 0x60 / 65535) << 8;
406 dprintk(KERN_DEBUG
"msp34xx: setbass: %d 0x%02x\n",bass
, val
>>8);
407 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0002, val
); /* loudspeaker */
410 static void msp3400c_settreble(struct i2c_client
*client
, int treble
)
412 int val
= ((treble
-32768) * 0x60 / 65535) << 8;
414 dprintk(KERN_DEBUG
"msp34xx: settreble: %d 0x%02x\n",treble
, val
>>8);
415 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0003, val
); /* loudspeaker */
418 static void msp3400c_setmode(struct i2c_client
*client
, int type
)
420 struct msp3400c
*msp
= i2c_get_clientdata(client
);
423 dprintk(KERN_DEBUG
"msp3400: setmode: %d\n",type
);
425 msp
->stereo
= VIDEO_SOUND_MONO
;
427 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x00bb, /* ad_cv */
428 msp_init_data
[type
].ad_cv
);
430 for (i
= 5; i
>= 0; i
--) /* fir 1 */
431 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x0001,
432 msp_init_data
[type
].fir1
[i
]);
434 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x0005, 0x0004); /* fir 2 */
435 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x0005, 0x0040);
436 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x0005, 0x0000);
437 for (i
= 5; i
>= 0; i
--)
438 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x0005,
439 msp_init_data
[type
].fir2
[i
]);
441 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x0083, /* MODE_REG */
442 msp_init_data
[type
].mode_reg
);
444 msp3400c_setcarrier(client
, msp_init_data
[type
].cdo1
,
445 msp_init_data
[type
].cdo2
);
447 msp3400c_write(client
,I2C_MSP3400C_DEM
, 0x0056, 0); /*LOAD_REG_1/2*/
450 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0008,
452 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0009,
454 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x000b,
455 msp_init_data
[type
].dfp_src
);
457 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0008,
458 msp_init_data
[type
].dfp_src
);
459 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0009,
460 msp_init_data
[type
].dfp_src
);
461 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x000b,
462 msp_init_data
[type
].dfp_src
);
464 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x000a,
465 msp_init_data
[type
].dfp_src
);
466 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x000e,
467 msp_init_data
[type
].dfp_matrix
);
469 if (HAVE_NICAM(msp
)) {
471 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0010, 0x5a00); /* was: 0x3000 */
475 /* turn on/off nicam + stereo */
476 static void msp3400c_setstereo(struct i2c_client
*client
, int mode
)
478 static char *strmode
[16] = {
480 [ 0 ... 15 ] = "invalid",
482 [ VIDEO_SOUND_MONO
] = "mono",
483 [ VIDEO_SOUND_STEREO
] = "stereo",
484 [ VIDEO_SOUND_LANG1
] = "lang1",
485 [ VIDEO_SOUND_LANG2
] = "lang2",
487 struct msp3400c
*msp
= i2c_get_clientdata(client
);
488 int nicam
=0; /* channel source: FM/AM or nicam */
491 /* switch demodulator */
493 case MSP_MODE_FM_TERRA
:
494 dprintk(KERN_DEBUG
"msp3400: FM setstereo: %s\n",strmode
[mode
]);
495 msp3400c_setcarrier(client
,msp
->second
,msp
->main
);
497 case VIDEO_SOUND_STEREO
:
498 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x000e, 0x3001);
500 case VIDEO_SOUND_MONO
:
501 case VIDEO_SOUND_LANG1
:
502 case VIDEO_SOUND_LANG2
:
503 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x000e, 0x3000);
507 case MSP_MODE_FM_SAT
:
508 dprintk(KERN_DEBUG
"msp3400: SAT setstereo: %s\n",strmode
[mode
]);
510 case VIDEO_SOUND_MONO
:
511 msp3400c_setcarrier(client
, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
513 case VIDEO_SOUND_STEREO
:
514 msp3400c_setcarrier(client
, MSP_CARRIER(7.2), MSP_CARRIER(7.02));
516 case VIDEO_SOUND_LANG1
:
517 msp3400c_setcarrier(client
, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
519 case VIDEO_SOUND_LANG2
:
520 msp3400c_setcarrier(client
, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
524 case MSP_MODE_FM_NICAM1
:
525 case MSP_MODE_FM_NICAM2
:
526 case MSP_MODE_AM_NICAM
:
527 dprintk(KERN_DEBUG
"msp3400: NICAM setstereo: %s\n",strmode
[mode
]);
528 msp3400c_setcarrier(client
,msp
->second
,msp
->main
);
533 dprintk(KERN_DEBUG
"msp3400: BTSC setstereo: %s\n",strmode
[mode
]);
536 case MSP_MODE_EXTERN
:
537 dprintk(KERN_DEBUG
"msp3400: extern setstereo: %s\n",strmode
[mode
]);
540 case MSP_MODE_FM_RADIO
:
541 dprintk(KERN_DEBUG
"msp3400: FM-Radio setstereo: %s\n",strmode
[mode
]);
544 dprintk(KERN_DEBUG
"msp3400: mono setstereo\n");
550 case VIDEO_SOUND_STEREO
:
551 src
= 0x0020 | nicam
;
554 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0005,0x4000);
557 case VIDEO_SOUND_MONO
:
558 if (msp
->mode
== MSP_MODE_AM_NICAM
) {
559 dprintk("msp3400: switching to AM mono\n");
560 /* AM mono decoding is handled by tuner, not MSP chip */
561 /* SCART switching control register */
562 msp3400c_set_scart(client
,SCART_MONO
,0);
566 case VIDEO_SOUND_LANG1
:
567 src
= 0x0000 | nicam
;
569 case VIDEO_SOUND_LANG2
:
570 src
= 0x0010 | nicam
;
574 "msp3400: setstereo final source/matrix = 0x%x\n", src
);
577 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0008,0x0520);
578 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0009,0x0620);
579 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x000a,src
);
580 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x000b,src
);
582 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0008,src
);
583 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0009,src
);
584 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x000a,src
);
585 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x000b,src
);
590 msp3400c_print_mode(struct msp3400c
*msp
)
592 if (msp
->main
== msp
->second
) {
593 printk(KERN_DEBUG
"msp3400: mono sound carrier: %d.%03d MHz\n",
594 msp
->main
/910000,(msp
->main
/910)%1000);
596 printk(KERN_DEBUG
"msp3400: main sound carrier: %d.%03d MHz\n",
597 msp
->main
/910000,(msp
->main
/910)%1000);
599 if (msp
->mode
== MSP_MODE_FM_NICAM1
||
600 msp
->mode
== MSP_MODE_FM_NICAM2
)
601 printk(KERN_DEBUG
"msp3400: NICAM/FM carrier : %d.%03d MHz\n",
602 msp
->second
/910000,(msp
->second
/910)%1000);
603 if (msp
->mode
== MSP_MODE_AM_NICAM
)
604 printk(KERN_DEBUG
"msp3400: NICAM/AM carrier : %d.%03d MHz\n",
605 msp
->second
/910000,(msp
->second
/910)%1000);
606 if (msp
->mode
== MSP_MODE_FM_TERRA
&&
607 msp
->main
!= msp
->second
) {
608 printk(KERN_DEBUG
"msp3400: FM-stereo carrier : %d.%03d MHz\n",
609 msp
->second
/910000,(msp
->second
/910)%1000);
614 msp3400c_restore_dfp(struct i2c_client
*client
)
616 struct msp3400c
*msp
= i2c_get_clientdata(client
);
619 for (i
= 0; i
< DFP_COUNT
; i
++) {
620 if (-1 == msp
->dfp_regs
[i
])
622 msp3400c_write(client
,I2C_MSP3400C_DFP
, i
, msp
->dfp_regs
[i
]);
626 /* ----------------------------------------------------------------------- */
628 struct REGISTER_DUMP
{
633 struct REGISTER_DUMP d1
[] = {
634 { 0x007e, "autodetect" },
635 { 0x0023, "C_AD_BITS " },
636 { 0x0038, "ADD_BITS " },
637 { 0x003e, "CIB_BITS " },
638 { 0x0057, "ERROR_RATE" },
642 autodetect_stereo(struct i2c_client
*client
)
644 struct msp3400c
*msp
= i2c_get_clientdata(client
);
646 int newstereo
= msp
->stereo
;
647 int newnicam
= msp
->nicam_on
;
651 case MSP_MODE_FM_TERRA
:
652 val
= msp3400c_read(client
, I2C_MSP3400C_DFP
, 0x18);
656 "msp34xx: stereo detect register: %d\n",val
);
658 newstereo
= VIDEO_SOUND_STEREO
| VIDEO_SOUND_MONO
;
659 } else if (val
< -4096) {
660 newstereo
= VIDEO_SOUND_LANG1
| VIDEO_SOUND_LANG2
;
662 newstereo
= VIDEO_SOUND_MONO
;
666 case MSP_MODE_FM_NICAM1
:
667 case MSP_MODE_FM_NICAM2
:
668 case MSP_MODE_AM_NICAM
:
669 val
= msp3400c_read(client
, I2C_MSP3400C_DEM
, 0x23);
671 "msp34xx: nicam sync=%d, mode=%d\n",
672 val
& 1, (val
& 0x1e) >> 1);
676 switch ((val
& 0x1e) >> 1) {
679 newstereo
= VIDEO_SOUND_STEREO
;
683 newstereo
= VIDEO_SOUND_MONO
688 newstereo
= VIDEO_SOUND_MONO
693 newstereo
= VIDEO_SOUND_MONO
;
699 newstereo
= VIDEO_SOUND_MONO
;
703 val
= msp3400c_read(client
, I2C_MSP3400C_DEM
, 0x200);
705 "msp3410: status=0x%x (pri=%s, sec=%s, %s%s%s)\n",
707 (val
& 0x0002) ? "no" : "yes",
708 (val
& 0x0004) ? "no" : "yes",
709 (val
& 0x0040) ? "stereo" : "mono",
710 (val
& 0x0080) ? ", nicam 2nd mono" : "",
711 (val
& 0x0100) ? ", bilingual/SAP" : "");
712 newstereo
= VIDEO_SOUND_MONO
;
713 if (val
& 0x0040) newstereo
|= VIDEO_SOUND_STEREO
;
714 if (val
& 0x0100) newstereo
|= VIDEO_SOUND_LANG1
;
717 if (newstereo
!= msp
->stereo
) {
719 dprintk(KERN_DEBUG
"msp34xx: watch: stereo %d => %d\n",
720 msp
->stereo
,newstereo
);
721 msp
->stereo
= newstereo
;
723 if (newnicam
!= msp
->nicam_on
) {
725 dprintk(KERN_DEBUG
"msp34xx: watch: nicam %d => %d\n",
726 msp
->nicam_on
,newnicam
);
727 msp
->nicam_on
= newnicam
;
733 * A kernel thread for msp3400 control -- we don't want to block the
734 * in the ioctl while doing the sound carrier & stereo detect
737 static int msp34xx_sleep(struct msp3400c
*msp
, int timeout
)
739 DECLARE_WAITQUEUE(wait
, current
);
741 add_wait_queue(&msp
->wq
, &wait
);
743 set_current_state(TASK_INTERRUPTIBLE
);
747 schedule_timeout(timeout
);
749 remove_wait_queue(&msp
->wq
, &wait
);
750 return msp
->rmmod
|| signal_pending(current
);
753 static void msp3400c_stereo_wake(unsigned long data
)
755 struct msp3400c
*msp
= (struct msp3400c
*)data
; /* XXX alpha ??? */
757 wake_up_interruptible(&msp
->wq
);
760 /* stereo/multilang monitoring */
761 static void watch_stereo(struct i2c_client
*client
)
763 struct msp3400c
*msp
= i2c_get_clientdata(client
);
765 if (autodetect_stereo(client
)) {
766 if (msp
->stereo
& VIDEO_SOUND_STEREO
)
767 msp3400c_setstereo(client
,VIDEO_SOUND_STEREO
);
768 else if (msp
->stereo
& VIDEO_SOUND_LANG1
)
769 msp3400c_setstereo(client
,VIDEO_SOUND_LANG1
);
770 else if (msp
->stereo
& VIDEO_SOUND_LANG2
)
771 msp3400c_setstereo(client
,VIDEO_SOUND_LANG2
);
773 msp3400c_setstereo(client
,VIDEO_SOUND_MONO
);
776 msp
->watch_stereo
= 0;
777 if (msp
->watch_stereo
)
778 mod_timer(&msp
->wake_stereo
, jiffies
+5*HZ
);
781 static int msp3400c_thread(void *data
)
783 struct i2c_client
*client
= data
;
784 struct msp3400c
*msp
= i2c_get_clientdata(client
);
786 struct CARRIER_DETECT
*cd
;
787 int count
, max1
,max2
,val1
,val2
, val
,this;
789 daemonize("msp3400");
790 allow_signal(SIGTERM
);
791 printk("msp3400: daemon started\n");
794 d2printk("msp3400: thread: sleep\n");
795 if (msp34xx_sleep(msp
,-1))
798 d2printk("msp3400: thread: wakeup\n");
801 if (msp
->watch_stereo
) {
802 watch_stereo(client
);
807 /* some time for the tuner to sync */
808 if (msp34xx_sleep(msp
,HZ
/5))
812 if (VIDEO_MODE_RADIO
== msp
->norm
||
813 MSP_MODE_EXTERN
== msp
->mode
) {
814 /* no carrier scan, just unmute */
815 printk("msp3400: thread: no carrier scan\n");
816 msp3400c_setvolume(client
, msp
->muted
,
817 msp
->volume
, msp
->balance
);
821 msp3400c_setvolume(client
, msp
->muted
, 0, 0);
822 msp3400c_setmode(client
, MSP_MODE_AM_DETECT
/* +1 */ );
825 del_timer(&msp
->wake_stereo
);
826 msp
->watch_stereo
= 0;
828 /* carrier detect pass #1 -- main carrier */
829 cd
= carrier_detect_main
; count
= CARRIER_COUNT(carrier_detect_main
);
831 if (amsound
&& (msp
->norm
== VIDEO_MODE_SECAM
)) {
832 /* autodetect doesn't work well with AM ... */
835 dprintk("msp3400: AM sound override\n");
838 for (this = 0; this < count
; this++) {
839 msp3400c_setcarrier(client
, cd
[this].cdo
,cd
[this].cdo
);
841 if (msp34xx_sleep(msp
,HZ
/10))
846 val
= msp3400c_read(client
, I2C_MSP3400C_DFP
, 0x1b);
850 val1
= val
, max1
= this;
851 dprintk("msp3400: carrier1 val: %5d / %s\n", val
,cd
[this].name
);
854 /* carrier detect pass #2 -- second (stereo) carrier */
857 cd
= carrier_detect_55
; count
= CARRIER_COUNT(carrier_detect_55
);
860 cd
= carrier_detect_65
; count
= CARRIER_COUNT(carrier_detect_65
);
865 cd
= NULL
; count
= 0;
869 if (amsound
&& (msp
->norm
== VIDEO_MODE_SECAM
)) {
870 /* autodetect doesn't work well with AM ... */
871 cd
= NULL
; count
= 0; max2
= 0;
873 for (this = 0; this < count
; this++) {
874 msp3400c_setcarrier(client
, cd
[this].cdo
,cd
[this].cdo
);
876 if (msp34xx_sleep(msp
,HZ
/10))
881 val
= msp3400c_read(client
, I2C_MSP3400C_DFP
, 0x1b);
885 val2
= val
, max2
= this;
886 dprintk("msp3400: carrier2 val: %5d / %s\n", val
,cd
[this].name
);
889 /* programm the msp3400 according to the results */
890 msp
->main
= carrier_detect_main
[max1
].cdo
;
895 msp
->second
= carrier_detect_55
[max2
].cdo
;
896 msp3400c_setmode(client
, MSP_MODE_FM_TERRA
);
898 msp3400c_setstereo(client
, VIDEO_SOUND_MONO
);
899 msp
->watch_stereo
= 1;
900 } else if (max2
== 1 && HAVE_NICAM(msp
)) {
902 msp
->second
= carrier_detect_55
[max2
].cdo
;
903 msp3400c_setmode(client
, MSP_MODE_FM_NICAM1
);
905 msp3400c_setcarrier(client
, msp
->second
, msp
->main
);
906 msp
->watch_stereo
= 1;
913 msp
->second
= MSP_CARRIER(6.552);
914 msp3400c_setmode(client
, MSP_MODE_FM_NICAM2
);
916 msp3400c_setcarrier(client
, msp
->second
, msp
->main
);
917 msp
->watch_stereo
= 1;
920 if (max2
== 1 || max2
== 2) {
922 msp
->second
= carrier_detect_65
[max2
].cdo
;
923 msp3400c_setmode(client
, MSP_MODE_FM_TERRA
);
925 msp3400c_setstereo(client
, VIDEO_SOUND_MONO
);
926 msp
->watch_stereo
= 1;
927 } else if (max2
== 0 &&
928 msp
->norm
== VIDEO_MODE_SECAM
) {
929 /* L NICAM or AM-mono */
930 msp
->second
= carrier_detect_65
[max2
].cdo
;
931 msp3400c_setmode(client
, MSP_MODE_AM_NICAM
);
933 msp3400c_setstereo(client
, VIDEO_SOUND_MONO
);
934 msp3400c_setcarrier(client
, msp
->second
, msp
->main
);
935 /* volume prescale for SCART (AM mono input) */
936 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x000d, 0x1900);
937 msp
->watch_stereo
= 1;
938 } else if (max2
== 0 && HAVE_NICAM(msp
)) {
940 msp
->second
= carrier_detect_65
[max2
].cdo
;
941 msp3400c_setmode(client
, MSP_MODE_FM_NICAM1
);
943 msp3400c_setcarrier(client
, msp
->second
, msp
->main
);
944 msp
->watch_stereo
= 1;
952 msp
->second
= carrier_detect_main
[max1
].cdo
;
953 msp3400c_setmode(client
, MSP_MODE_FM_TERRA
);
955 msp3400c_setcarrier(client
, msp
->second
, msp
->main
);
956 msp
->stereo
= VIDEO_SOUND_MONO
;
957 msp3400c_setstereo(client
, VIDEO_SOUND_MONO
);
961 /* unmute + restore dfp registers */
962 msp3400c_setvolume(client
, msp
->muted
,
963 msp
->volume
, msp
->balance
);
964 msp3400c_restore_dfp(client
);
966 if (msp
->watch_stereo
)
967 mod_timer(&msp
->wake_stereo
, jiffies
+5*HZ
);
970 msp3400c_print_mode(msp
);
977 dprintk(KERN_DEBUG
"msp3400: thread: exit\n");
978 complete_and_exit(&msp
->texit
, 0);
981 /* ----------------------------------------------------------------------- */
982 /* this one uses the automatic sound standard detection of newer */
983 /* msp34xx chip versions */
985 static struct MODES
{
990 { 0x0000, 0, 0, "ERROR" },
991 { 0x0001, 0, 0, "autodetect start" },
992 { 0x0002, MSP_CARRIER(4.5), MSP_CARRIER(4.72), "4.5/4.72 M Dual FM-Stereo" },
993 { 0x0003, MSP_CARRIER(5.5), MSP_CARRIER(5.7421875), "5.5/5.74 B/G Dual FM-Stereo" },
994 { 0x0004, MSP_CARRIER(6.5), MSP_CARRIER(6.2578125), "6.5/6.25 D/K1 Dual FM-Stereo" },
995 { 0x0005, MSP_CARRIER(6.5), MSP_CARRIER(6.7421875), "6.5/6.74 D/K2 Dual FM-Stereo" },
996 { 0x0006, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 D/K FM-Mono (HDEV3)" },
997 { 0x0008, MSP_CARRIER(5.5), MSP_CARRIER(5.85), "5.5/5.85 B/G NICAM FM" },
998 { 0x0009, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 L NICAM AM" },
999 { 0x000a, MSP_CARRIER(6.0), MSP_CARRIER(6.55), "6.0/6.55 I NICAM FM" },
1000 { 0x000b, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM" },
1001 { 0x000c, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM (HDEV2)" },
1002 { 0x0020, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Stereo" },
1003 { 0x0021, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Mono + SAP" },
1004 { 0x0030, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M EIA-J Japan Stereo" },
1005 { 0x0040, MSP_CARRIER(10.7), MSP_CARRIER(10.7), "10.7 FM-Stereo Radio" },
1006 { 0x0050, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 SAT-Mono" },
1007 { 0x0051, MSP_CARRIER(7.02), MSP_CARRIER(7.20), "7.02/7.20 SAT-Stereo" },
1008 { 0x0060, MSP_CARRIER(7.2), MSP_CARRIER(7.2), "7.2 SAT ADR" },
1009 { -1, 0, 0, NULL
}, /* EOF */
1012 static int msp3410d_thread(void *data
)
1014 struct i2c_client
*client
= data
;
1015 struct msp3400c
*msp
= i2c_get_clientdata(client
);
1018 daemonize("msp3410 [auto]");
1019 allow_signal(SIGTERM
);
1020 printk("msp3410: daemon started\n");
1023 d2printk(KERN_DEBUG
"msp3410: thread: sleep\n");
1024 if (msp34xx_sleep(msp
,-1))
1027 d2printk(KERN_DEBUG
"msp3410: thread: wakeup\n");
1030 if (msp
->watch_stereo
) {
1031 watch_stereo(client
);
1036 /* some time for the tuner to sync */
1037 if (msp34xx_sleep(msp
,HZ
/5))
1041 if (msp
->mode
== MSP_MODE_EXTERN
) {
1042 /* no carrier scan needed, just unmute */
1043 dprintk(KERN_DEBUG
"msp3410: thread: no carrier scan\n");
1044 msp3400c_setvolume(client
, msp
->muted
,
1045 msp
->volume
, msp
->balance
);
1049 del_timer(&msp
->wake_stereo
);
1050 msp
->watch_stereo
= 0;
1052 /* put into sane state (and mute) */
1053 msp3400c_reset(client
);
1055 /* start autodetect */
1056 switch (msp
->norm
) {
1057 case VIDEO_MODE_PAL
:
1061 case VIDEO_MODE_NTSC
: /* BTSC */
1065 case VIDEO_MODE_SECAM
:
1069 case VIDEO_MODE_RADIO
:
1078 msp3400c_write(client
, I2C_MSP3400C_DEM
, 0x30, mode
);
1079 msp3400c_write(client
, I2C_MSP3400C_DEM
, 0x20, std
);
1083 for (i
= 0; modelist
[i
].name
!= NULL
; i
++)
1084 if (modelist
[i
].retval
== std
)
1086 printk(KERN_DEBUG
"msp3410: setting mode: %s (0x%04x)\n",
1087 modelist
[i
].name
? modelist
[i
].name
: "unknown",std
);
1091 /* programmed some specific mode */
1094 /* triggered autodetect */
1096 if (msp34xx_sleep(msp
,HZ
/10))
1102 val
= msp3400c_read(client
, I2C_MSP3400C_DEM
, 0x7e);
1105 dprintk(KERN_DEBUG
"msp3410: detection still in progress\n");
1108 for (i
= 0; modelist
[i
].name
!= NULL
; i
++)
1109 if (modelist
[i
].retval
== val
)
1111 dprintk(KERN_DEBUG
"msp3410: current mode: %s (0x%04x)\n",
1112 modelist
[i
].name
? modelist
[i
].name
: "unknown",
1114 msp
->main
= modelist
[i
].main
;
1115 msp
->second
= modelist
[i
].second
;
1117 if (amsound
&& (msp
->norm
== VIDEO_MODE_SECAM
) && (val
!= 0x0009)) {
1118 /* autodetection has failed, let backup */
1119 dprintk(KERN_DEBUG
"msp3410: autodetection failed,"
1120 " switching to backup mode: %s (0x%04x)\n",
1121 modelist
[8].name
? modelist
[8].name
: "unknown",val
);
1123 msp3400c_write(client
, I2C_MSP3400C_DEM
, 0x20, val
);
1126 /* set various prescales */
1127 msp3400c_write(client
, I2C_MSP3400C_DFP
, 0x0d, 0x1900); /* scart */
1128 msp3400c_write(client
, I2C_MSP3400C_DFP
, 0x0e, 0x2403); /* FM */
1129 msp3400c_write(client
, I2C_MSP3400C_DFP
, 0x10, 0x5a00); /* nicam */
1133 case 0x0008: /* B/G NICAM */
1134 case 0x000a: /* I NICAM */
1136 msp
->mode
= MSP_MODE_FM_NICAM1
;
1138 msp
->mode
= MSP_MODE_FM_NICAM2
;
1139 /* just turn on stereo */
1140 msp
->stereo
= VIDEO_SOUND_STEREO
;
1142 msp
->watch_stereo
= 1;
1143 msp3400c_setstereo(client
,VIDEO_SOUND_STEREO
);
1146 msp
->mode
= MSP_MODE_AM_NICAM
;
1147 msp
->stereo
= VIDEO_SOUND_MONO
;
1149 msp3400c_setstereo(client
,VIDEO_SOUND_MONO
);
1150 msp
->watch_stereo
= 1;
1152 case 0x0020: /* BTSC */
1153 /* just turn on stereo */
1154 msp
->mode
= MSP_MODE_BTSC
;
1155 msp
->stereo
= VIDEO_SOUND_STEREO
;
1157 msp
->watch_stereo
= 1;
1158 msp3400c_setstereo(client
,VIDEO_SOUND_STEREO
);
1160 case 0x0040: /* FM radio */
1161 msp
->mode
= MSP_MODE_FM_RADIO
;
1162 msp
->stereo
= VIDEO_SOUND_STEREO
;
1164 msp
->watch_stereo
= 0;
1165 /* not needed in theory if HAVE_RADIO(), but
1166 short programming enables carrier mute */
1167 msp3400c_setmode(client
,MSP_MODE_FM_RADIO
);
1168 msp3400c_setcarrier(client
, MSP_CARRIER(10.7),
1171 msp3400c_set_scart(client
,SCART_IN2
,0);
1173 /* radio from SCART_IN2 */
1174 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x08, 0x0220);
1175 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x09, 0x0220);
1176 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0b, 0x0220);
1178 /* msp34xx does radio decoding */
1179 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x08, 0x0020);
1180 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x09, 0x0020);
1181 msp3400c_write(client
,I2C_MSP3400C_DFP
, 0x0b, 0x0020);
1187 msp
->mode
= MSP_MODE_FM_TERRA
;
1188 msp
->stereo
= VIDEO_SOUND_MONO
;
1190 msp
->watch_stereo
= 1;
1194 /* unmute + restore dfp registers */
1195 msp3400c_setbass(client
, msp
->bass
);
1196 msp3400c_settreble(client
, msp
->treble
);
1197 msp3400c_setvolume(client
, msp
->muted
,
1198 msp
->volume
, msp
->balance
);
1199 msp3400c_restore_dfp(client
);
1201 if (msp
->watch_stereo
)
1202 mod_timer(&msp
->wake_stereo
, jiffies
+HZ
);
1209 dprintk(KERN_DEBUG
"msp3410: thread: exit\n");
1210 complete_and_exit(&msp
->texit
, 0);
1214 /* ----------------------------------------------------------------------- */
1216 static int msp_attach(struct i2c_adapter
*adap
, int addr
, int kind
);
1217 static int msp_detach(struct i2c_client
*client
);
1218 static int msp_probe(struct i2c_adapter
*adap
);
1219 static int msp_command(struct i2c_client
*client
, unsigned int cmd
, void *arg
);
1221 static struct i2c_driver driver
= {
1222 .owner
= THIS_MODULE
,
1223 .name
= "i2c msp3400 driver",
1224 .id
= I2C_DRIVERID_MSP3400
,
1225 .flags
= I2C_DF_NOTIFY
,
1226 .attach_adapter
= msp_probe
,
1227 .detach_client
= msp_detach
,
1228 .command
= msp_command
,
1231 static struct i2c_client client_template
=
1233 I2C_DEVNAME("(unset)"),
1234 .flags
= I2C_CLIENT_ALLOW_USE
,
1238 static int msp_attach(struct i2c_adapter
*adap
, int addr
, int kind
)
1240 struct msp3400c
*msp
;
1241 struct i2c_client
*c
;
1244 client_template
.adapter
= adap
;
1245 client_template
.addr
= addr
;
1247 if (-1 == msp3400c_reset(&client_template
)) {
1248 dprintk("msp3400: no chip found\n");
1252 if (NULL
== (c
= kmalloc(sizeof(struct i2c_client
),GFP_KERNEL
)))
1254 memcpy(c
,&client_template
,sizeof(struct i2c_client
));
1255 if (NULL
== (msp
= kmalloc(sizeof(struct msp3400c
),GFP_KERNEL
))) {
1260 memset(msp
,0,sizeof(struct msp3400c
));
1261 msp
->volume
= 65535;
1262 msp
->balance
= 32768;
1264 msp
->treble
= 32768;
1267 for (i
= 0; i
< DFP_COUNT
; i
++)
1268 msp
->dfp_regs
[i
] = -1;
1270 i2c_set_clientdata(c
, msp
);
1271 init_waitqueue_head(&msp
->wq
);
1273 if (-1 == msp3400c_reset(c
)) {
1276 dprintk("msp3400: no chip found\n");
1280 msp
->rev1
= msp3400c_read(c
, I2C_MSP3400C_DFP
, 0x1e);
1281 if (-1 != msp
->rev1
)
1282 msp
->rev2
= msp3400c_read(c
, I2C_MSP3400C_DFP
, 0x1f);
1283 if ((-1 == msp
->rev1
) || (0 == msp
->rev1
&& 0 == msp
->rev2
)) {
1286 printk("msp3400: error while reading chip version\n");
1291 /* this will turn on a 1kHz beep - might be useful for debugging... */
1292 msp3400c_write(c
,I2C_MSP3400C_DFP
, 0x0014, 0x1040);
1294 msp3400c_setvolume(c
, msp
->muted
, msp
->volume
, msp
->balance
);
1296 snprintf(c
->name
, sizeof(c
->name
), "MSP34%02d%c-%c%d",
1297 (msp
->rev2
>>8)&0xff, (msp
->rev1
&0xff)+'@',
1298 ((msp
->rev1
>>8)&0xff)+'@', msp
->rev2
&0x1f);
1302 msp
->simple
= HAVE_SIMPLE(msp
);
1304 /* use insmod option */
1305 msp
->simple
= simple
;
1308 /* timer for stereo checking */
1309 init_timer(&msp
->wake_stereo
);
1310 msp
->wake_stereo
.function
= msp3400c_stereo_wake
;
1311 msp
->wake_stereo
.data
= (unsigned long)msp
;
1313 /* hello world :-) */
1314 printk(KERN_INFO
"msp34xx: init: chip=%s",i2c_clientname(c
));
1315 if (HAVE_NICAM(msp
))
1317 if (HAVE_SIMPLE(msp
))
1319 if (HAVE_RADIO(msp
))
1323 /* startup control thread */
1324 init_completion(&msp
->texit
);
1325 msp
->tpid
= kernel_thread(msp
->simple
? msp3410d_thread
: msp3400c_thread
,
1328 printk(KERN_WARNING
"msp34xx: kernel_thread() failed\n");
1329 wake_up_interruptible(&msp
->wq
);
1332 i2c_attach_client(c
);
1336 static int msp_detach(struct i2c_client
*client
)
1338 struct msp3400c
*msp
= i2c_get_clientdata(client
);
1340 /* shutdown control thread */
1341 del_timer_sync(&msp
->wake_stereo
);
1342 if (msp
->tpid
>= 0) {
1344 wake_up_interruptible(&msp
->wq
);
1345 wait_for_completion(&msp
->texit
);
1347 msp3400c_reset(client
);
1349 i2c_detach_client(client
);
1355 static int msp_probe(struct i2c_adapter
*adap
)
1357 #ifdef I2C_CLASS_TV_ANALOG
1358 if (adap
->class & I2C_CLASS_TV_ANALOG
)
1359 return i2c_probe(adap
, &addr_data
, msp_attach
);
1362 case I2C_ALGO_BIT
| I2C_HW_SMBUS_VOODOO3
:
1363 case I2C_ALGO_BIT
| I2C_HW_B_BT848
:
1364 //case I2C_ALGO_SAA7134:
1365 return i2c_probe(adap
, &addr_data
, msp_attach
);
1372 static void msp_wake_thread(struct i2c_client
*client
)
1374 struct msp3400c
*msp
= i2c_get_clientdata(client
);
1376 msp3400c_setvolume(client
,msp
->muted
,0,0);
1377 msp
->watch_stereo
=0;
1378 del_timer(&msp
->wake_stereo
);
1381 wake_up_interruptible(&msp
->wq
);
1384 static int msp_command(struct i2c_client
*client
, unsigned int cmd
, void *arg
)
1386 struct msp3400c
*msp
= i2c_get_clientdata(client
);
1392 case AUDC_SET_INPUT
:
1393 dprintk(KERN_DEBUG
"msp34xx: AUDC_SET_INPUT(%d)\n",*sarg
);
1394 if (*sarg
== msp
->input
)
1399 /* Hauppauge uses IN2 for the radio */
1400 msp
->mode
= MSP_MODE_FM_RADIO
;
1403 case AUDIO_EXTERN_1
:
1404 /* IN1 is often used for external input ... */
1405 msp
->mode
= MSP_MODE_EXTERN
;
1408 case AUDIO_EXTERN_2
:
1409 /* ... sometimes it is IN2 through ;) */
1410 msp
->mode
= MSP_MODE_EXTERN
;
1415 msp_wake_thread(client
);
1418 if (*sarg
& AUDIO_MUTE
)
1419 msp3400c_set_scart(client
,SCART_MUTE
,0);
1423 msp
->stereo
= VIDEO_SOUND_STEREO
;
1424 msp3400c_set_scart(client
,scart
,0);
1425 msp3400c_write(client
,I2C_MSP3400C_DFP
,0x000d,0x1900);
1426 msp3400c_setstereo(client
,msp
->stereo
);
1432 case AUDC_SET_RADIO
:
1433 dprintk(KERN_DEBUG
"msp34xx: AUDC_SET_RADIO\n");
1434 msp
->norm
= VIDEO_MODE_RADIO
;
1435 msp
->watch_stereo
=0;
1436 del_timer(&msp
->wake_stereo
);
1437 dprintk(KERN_DEBUG
"msp34xx: switching to radio mode\n");
1439 /* the thread will do for us */
1440 msp_wake_thread(client
);
1442 /* set msp3400 to FM radio mode */
1443 msp3400c_setmode(client
,MSP_MODE_FM_RADIO
);
1444 msp3400c_setcarrier(client
, MSP_CARRIER(10.7),
1446 msp3400c_setvolume(client
, msp
->muted
,
1447 msp
->volume
, msp
->balance
);
1454 /* work-in-progress: hook to control the DFP registers */
1455 case MSP_SET_DFPREG
:
1457 struct msp_dfpreg
*r
= arg
;
1460 if (r
->reg
< 0 || r
->reg
>= DFP_COUNT
)
1462 for (i
= 0; i
< ARRAY_SIZE(bl_dfp
); i
++)
1463 if (r
->reg
== bl_dfp
[i
])
1465 msp
->dfp_regs
[r
->reg
] = r
->value
;
1466 msp3400c_write(client
,I2C_MSP3400C_DFP
,r
->reg
,r
->value
);
1469 case MSP_GET_DFPREG
:
1471 struct msp_dfpreg
*r
= arg
;
1473 if (r
->reg
< 0 || r
->reg
>= DFP_COUNT
)
1475 r
->value
= msp3400c_read(client
,I2C_MSP3400C_DFP
,r
->reg
);
1480 /* --- v4l ioctls --- */
1481 /* take care: bttv does userspace copying, we'll get a
1482 kernel pointer here... */
1485 struct video_audio
*va
= arg
;
1487 dprintk(KERN_DEBUG
"msp34xx: VIDIOCGAUDIO\n");
1488 va
->flags
|= VIDEO_AUDIO_VOLUME
|
1490 VIDEO_AUDIO_TREBLE
|
1491 VIDEO_AUDIO_MUTABLE
;
1493 va
->flags
|= VIDEO_AUDIO_MUTE
;
1495 va
->volume
= msp
->volume
;
1496 va
->balance
= (va
->volume
) ? msp
->balance
: 32768;
1497 va
->bass
= msp
->bass
;
1498 va
->treble
= msp
->treble
;
1500 if (msp
->norm
!= VIDEO_MODE_RADIO
) {
1501 autodetect_stereo(client
);
1502 va
->mode
= msp
->stereo
;
1508 struct video_audio
*va
= arg
;
1510 dprintk(KERN_DEBUG
"msp34xx: VIDIOCSAUDIO\n");
1511 msp
->muted
= (va
->flags
& VIDEO_AUDIO_MUTE
);
1512 msp
->volume
= va
->volume
;
1513 msp
->balance
= va
->balance
;
1514 msp
->bass
= va
->bass
;
1515 msp
->treble
= va
->treble
;
1517 msp3400c_setvolume(client
, msp
->muted
,
1518 msp
->volume
, msp
->balance
);
1519 msp3400c_setbass(client
,msp
->bass
);
1520 msp3400c_settreble(client
,msp
->treble
);
1522 if (va
->mode
!= 0 && msp
->norm
!= VIDEO_MODE_RADIO
) {
1523 msp
->watch_stereo
=0;
1524 del_timer(&msp
->wake_stereo
);
1525 msp
->stereo
= va
->mode
& 0x0f;
1526 msp3400c_setstereo(client
,va
->mode
& 0x0f);
1532 struct video_channel
*vc
= arg
;
1534 dprintk(KERN_DEBUG
"msp34xx: VIDIOCSCHAN (norm=%d)\n",vc
->norm
);
1535 msp
->norm
= vc
->norm
;
1540 /* new channel -- kick audio carrier scan */
1541 dprintk(KERN_DEBUG
"msp34xx: VIDIOCSFREQ\n");
1542 msp_wake_thread(client
);
1553 /* ----------------------------------------------------------------------- */
1555 static int __init
msp3400_init_module(void)
1557 return i2c_add_driver(&driver
);
1560 static void __exit
msp3400_cleanup_module(void)
1562 i2c_del_driver(&driver
);
1565 module_init(msp3400_init_module
);
1566 module_exit(msp3400_cleanup_module
);
1569 * Overrides for Emacs so that we follow Linus's tabbing style.
1570 * ---------------------------------------------------------------------------