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 "audiochip.h"
54 #include "i2c-compat.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 */
84 int left, right; /* volume */
87 /* shadow register set */
88 int dfp_regs[DFP_COUNT];
91 struct task_struct *thread;
94 struct semaphore *notify;
95 int active,restart,rmmod;
98 struct timer_list wake_stereo;
101 #define HAVE_NICAM(msp) (((msp->rev2>>8) & 0xff) != 00)
102 #define HAVE_SIMPLE(msp) ((msp->rev1 & 0xff) >= 'D'-'@')
103 #define HAVE_RADIO(msp) ((msp->rev1 & 0xff) >= 'G'-'@')
105 #define MSP3400_MAX 4
106 static struct i2c_client *msps[MSP3400_MAX];
108 #define VIDEO_MODE_RADIO 16 /* norm magic for radio mode */
110 /* ---------------------------------------------------------------------- */
112 #define dprintk if (debug) 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 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 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 left, int right)
384 int vol = 0,val = 0,balance = 0;
387 vol = (left > right) ? left : right;
388 val = (vol * 0x73 / 65535) << 8;
391 balance = ((right-left) * 127) / vol;
395 "msp34xx: setvolume: mute=%s %d:%d v=0x%02x b=0x%02x\n",
396 muted ? "on" : "off", left, right, val>>8, balance);
397 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0000, val); /* loudspeaker */
398 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0006, val); /* headphones */
399 /* scart - on/off only */
400 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0007, val ? 0x4000 : 0);
401 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0001, balance << 8);
404 static void msp3400c_setbass(struct i2c_client *client, int bass)
406 int val = ((bass-32768) * 0x60 / 65535) << 8;
408 dprintk(KERN_DEBUG "msp34xx: setbass: %d 0x%02x\n",bass, val>>8);
409 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0002, val); /* loudspeaker */
412 static void msp3400c_settreble(struct i2c_client *client, int treble)
414 int val = ((treble-32768) * 0x60 / 65535) << 8;
416 dprintk(KERN_DEBUG "msp34xx: settreble: %d 0x%02x\n",treble, val>>8);
417 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0003, val); /* loudspeaker */
420 static void msp3400c_setmode(struct i2c_client *client, int type)
422 struct msp3400c *msp = i2c_get_clientdata(client);
425 dprintk(KERN_DEBUG "msp3400: setmode: %d\n",type);
427 msp->stereo = VIDEO_SOUND_MONO;
429 msp3400c_write(client,I2C_MSP3400C_DEM, 0x00bb, /* ad_cv */
430 msp_init_data[type].ad_cv);
432 for (i = 5; i >= 0; i--) /* fir 1 */
433 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0001,
434 msp_init_data[type].fir1[i]);
436 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0004); /* fir 2 */
437 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0040);
438 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0000);
439 for (i = 5; i >= 0; i--)
440 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005,
441 msp_init_data[type].fir2[i]);
443 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0083, /* MODE_REG */
444 msp_init_data[type].mode_reg);
446 msp3400c_setcarrier(client, msp_init_data[type].cdo1,
447 msp_init_data[type].cdo2);
449 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0056, 0); /*LOAD_REG_1/2*/
452 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,
454 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,
456 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,
457 msp_init_data[type].dfp_src);
459 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,
460 msp_init_data[type].dfp_src);
461 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,
462 msp_init_data[type].dfp_src);
463 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,
464 msp_init_data[type].dfp_src);
466 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000a,
467 msp_init_data[type].dfp_src);
468 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000e,
469 msp_init_data[type].dfp_matrix);
471 if (HAVE_NICAM(msp)) {
473 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0010, 0x5a00); /* was: 0x3000 */
477 /* turn on/off nicam + stereo */
478 static void msp3400c_setstereo(struct i2c_client *client, int mode)
480 static char *strmode[16] = {
482 [ 0 ... 15 ] = "invalid",
484 [ VIDEO_SOUND_MONO ] = "mono",
485 [ VIDEO_SOUND_STEREO ] = "stereo",
486 [ VIDEO_SOUND_LANG1 ] = "lang1",
487 [ VIDEO_SOUND_LANG2 ] = "lang2",
489 struct msp3400c *msp = i2c_get_clientdata(client);
490 int nicam=0; /* channel source: FM/AM or nicam */
493 /* switch demodulator */
495 case MSP_MODE_FM_TERRA:
496 dprintk(KERN_DEBUG "msp3400: FM setstereo: %s\n",strmode[mode]);
497 msp3400c_setcarrier(client,msp->second,msp->main);
499 case VIDEO_SOUND_STEREO:
500 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000e, 0x3001);
502 case VIDEO_SOUND_MONO:
503 case VIDEO_SOUND_LANG1:
504 case VIDEO_SOUND_LANG2:
505 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000e, 0x3000);
509 case MSP_MODE_FM_SAT:
510 dprintk(KERN_DEBUG "msp3400: SAT setstereo: %s\n",strmode[mode]);
512 case VIDEO_SOUND_MONO:
513 msp3400c_setcarrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
515 case VIDEO_SOUND_STEREO:
516 msp3400c_setcarrier(client, MSP_CARRIER(7.2), MSP_CARRIER(7.02));
518 case VIDEO_SOUND_LANG1:
519 msp3400c_setcarrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
521 case VIDEO_SOUND_LANG2:
522 msp3400c_setcarrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
526 case MSP_MODE_FM_NICAM1:
527 case MSP_MODE_FM_NICAM2:
528 case MSP_MODE_AM_NICAM:
529 dprintk(KERN_DEBUG "msp3400: NICAM setstereo: %s\n",strmode[mode]);
530 msp3400c_setcarrier(client,msp->second,msp->main);
535 dprintk(KERN_DEBUG "msp3400: BTSC setstereo: %s\n",strmode[mode]);
538 case MSP_MODE_EXTERN:
539 dprintk(KERN_DEBUG "msp3400: extern setstereo: %s\n",strmode[mode]);
542 case MSP_MODE_FM_RADIO:
543 dprintk(KERN_DEBUG "msp3400: FM-Radio setstereo: %s\n",strmode[mode]);
546 dprintk(KERN_DEBUG "msp3400: mono setstereo\n");
552 case VIDEO_SOUND_STEREO:
553 src = 0x0020 | nicam;
556 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0005,0x4000);
559 case VIDEO_SOUND_MONO:
560 if (msp->mode == MSP_MODE_AM_NICAM) {
561 dprintk("msp3400: switching to AM mono\n");
562 /* AM mono decoding is handled by tuner, not MSP chip */
563 /* SCART switching control register */
564 msp3400c_set_scart(client,SCART_MONO,0);
568 case VIDEO_SOUND_LANG1:
569 src = 0x0000 | nicam;
571 case VIDEO_SOUND_LANG2:
572 src = 0x0010 | nicam;
576 "msp3400: setstereo final source/matrix = 0x%x\n", src);
579 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,0x0520);
580 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,0x0620);
581 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000a,src);
582 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,src);
584 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,src);
585 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,src);
586 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000a,src);
587 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,src);
592 msp3400c_print_mode(struct msp3400c *msp)
594 if (msp->main == msp->second) {
595 printk(KERN_DEBUG "msp3400: mono sound carrier: %d.%03d MHz\n",
596 msp->main/910000,(msp->main/910)%1000);
598 printk(KERN_DEBUG "msp3400: main sound carrier: %d.%03d MHz\n",
599 msp->main/910000,(msp->main/910)%1000);
601 if (msp->mode == MSP_MODE_FM_NICAM1 ||
602 msp->mode == MSP_MODE_FM_NICAM2)
603 printk(KERN_DEBUG "msp3400: NICAM/FM carrier : %d.%03d MHz\n",
604 msp->second/910000,(msp->second/910)%1000);
605 if (msp->mode == MSP_MODE_AM_NICAM)
606 printk(KERN_DEBUG "msp3400: NICAM/AM carrier : %d.%03d MHz\n",
607 msp->second/910000,(msp->second/910)%1000);
608 if (msp->mode == MSP_MODE_FM_TERRA &&
609 msp->main != msp->second) {
610 printk(KERN_DEBUG "msp3400: FM-stereo carrier : %d.%03d MHz\n",
611 msp->second/910000,(msp->second/910)%1000);
616 msp3400c_restore_dfp(struct i2c_client *client)
618 struct msp3400c *msp = i2c_get_clientdata(client);
621 for (i = 0; i < DFP_COUNT; i++) {
622 if (-1 == msp->dfp_regs[i])
624 msp3400c_write(client,I2C_MSP3400C_DFP, i, msp->dfp_regs[i]);
628 /* ----------------------------------------------------------------------- */
630 struct REGISTER_DUMP {
635 struct REGISTER_DUMP d1[] = {
636 { 0x007e, "autodetect" },
637 { 0x0023, "C_AD_BITS " },
638 { 0x0038, "ADD_BITS " },
639 { 0x003e, "CIB_BITS " },
640 { 0x0057, "ERROR_RATE" },
644 autodetect_stereo(struct i2c_client *client)
646 struct msp3400c *msp = i2c_get_clientdata(client);
648 int newstereo = msp->stereo;
649 int newnicam = msp->nicam_on;
653 case MSP_MODE_FM_TERRA:
654 val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x18);
658 "msp34xx: stereo detect register: %d\n",val);
660 newstereo = VIDEO_SOUND_STEREO | VIDEO_SOUND_MONO;
661 } else if (val < -4096) {
662 newstereo = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
664 newstereo = VIDEO_SOUND_MONO;
668 case MSP_MODE_FM_NICAM1:
669 case MSP_MODE_FM_NICAM2:
670 case MSP_MODE_AM_NICAM:
671 val = msp3400c_read(client, I2C_MSP3400C_DEM, 0x23);
673 "msp34xx: nicam sync=%d, mode=%d\n",
674 val & 1, (val & 0x1e) >> 1);
678 switch ((val & 0x1e) >> 1) {
681 newstereo = VIDEO_SOUND_STEREO;
685 newstereo = VIDEO_SOUND_MONO
690 newstereo = VIDEO_SOUND_MONO
695 newstereo = VIDEO_SOUND_MONO;
701 newstereo = VIDEO_SOUND_MONO;
705 val = msp3400c_read(client, I2C_MSP3400C_DEM, 0x200);
707 "msp3410: status=0x%x (pri=%s, sec=%s, %s%s%s)\n",
709 (val & 0x0002) ? "no" : "yes",
710 (val & 0x0004) ? "no" : "yes",
711 (val & 0x0040) ? "stereo" : "mono",
712 (val & 0x0080) ? ", nicam 2nd mono" : "",
713 (val & 0x0100) ? ", bilingual/SAP" : "");
714 newstereo = VIDEO_SOUND_MONO;
715 if (val & 0x0040) newstereo |= VIDEO_SOUND_STEREO;
716 if (val & 0x0100) newstereo |= VIDEO_SOUND_LANG1;
719 if (newstereo != msp->stereo) {
721 dprintk(KERN_DEBUG "msp34xx: watch: stereo %d => %d\n",
722 msp->stereo,newstereo);
723 msp->stereo = newstereo;
725 if (newnicam != msp->nicam_on) {
727 dprintk(KERN_DEBUG "msp34xx: watch: nicam %d => %d\n",
728 msp->nicam_on,newnicam);
729 msp->nicam_on = newnicam;
735 * A kernel thread for msp3400 control -- we don't want to block the
736 * in the ioctl while doing the sound carrier & stereo detect
739 static void msp3400c_stereo_wake(unsigned long data)
741 struct msp3400c *msp = (struct msp3400c*)data; /* XXX alpha ??? */
743 wake_up_interruptible(&msp->wq);
746 /* stereo/multilang monitoring */
747 static void watch_stereo(struct i2c_client *client)
749 struct msp3400c *msp = i2c_get_clientdata(client);
751 if (autodetect_stereo(client)) {
752 if (msp->stereo & VIDEO_SOUND_STEREO)
753 msp3400c_setstereo(client,VIDEO_SOUND_STEREO);
754 else if (msp->stereo & VIDEO_SOUND_LANG1)
755 msp3400c_setstereo(client,VIDEO_SOUND_LANG1);
756 else if (msp->stereo & VIDEO_SOUND_LANG2)
757 msp3400c_setstereo(client,VIDEO_SOUND_LANG2);
759 msp3400c_setstereo(client,VIDEO_SOUND_MONO);
762 msp->watch_stereo = 0;
763 if (msp->watch_stereo)
764 mod_timer(&msp->wake_stereo, jiffies+5*HZ);
767 static int msp3400c_thread(void *data)
769 struct i2c_client *client = data;
770 struct msp3400c *msp = i2c_get_clientdata(client);
772 struct CARRIER_DETECT *cd;
773 int count, max1,max2,val1,val2, val,this;
777 sigfillset(¤t->blocked);
778 strcpy(current->comm,"msp3400");
779 msp->thread = current;
782 printk("msp3400: daemon started\n");
783 if(msp->notify != NULL)
790 printk("msp3400: thread: sleep\n");
791 interruptible_sleep_on(&msp->wq);
793 printk("msp3400: thread: wakeup\n");
794 if (msp->rmmod || signal_pending(current))
799 if (msp->watch_stereo) {
800 watch_stereo(client);
805 /* some time for the tuner to sync */
806 current->state = TASK_INTERRUPTIBLE;
807 schedule_timeout(HZ/5);
808 if (signal_pending(current))
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->left, msp->right);
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 current->state = TASK_INTERRUPTIBLE;
842 schedule_timeout(HZ/10);
843 if (signal_pending(current))
848 val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);
852 val1 = val, max1 = this;
853 dprintk("msp3400: carrier1 val: %5d / %s\n", val,cd[this].name);
856 /* carrier detect pass #2 -- second (stereo) carrier */
859 cd = carrier_detect_55; count = CARRIER_COUNT(carrier_detect_55);
862 cd = carrier_detect_65; count = CARRIER_COUNT(carrier_detect_65);
867 cd = NULL; count = 0;
871 if (amsound && (msp->norm == VIDEO_MODE_SECAM)) {
872 /* autodetect doesn't work well with AM ... */
873 cd = NULL; count = 0; max2 = 0;
875 for (this = 0; this < count; this++) {
876 msp3400c_setcarrier(client, cd[this].cdo,cd[this].cdo);
878 current->state = TASK_INTERRUPTIBLE;
879 schedule_timeout(HZ/10);
880 if (signal_pending(current))
885 val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);
889 val2 = val, max2 = this;
890 dprintk("msp3400: carrier2 val: %5d / %s\n", val,cd[this].name);
893 /* programm the msp3400 according to the results */
894 msp->main = carrier_detect_main[max1].cdo;
899 msp->second = carrier_detect_55[max2].cdo;
900 msp3400c_setmode(client, MSP_MODE_FM_TERRA);
902 msp3400c_setstereo(client, VIDEO_SOUND_MONO);
903 msp->watch_stereo = 1;
904 } else if (max2 == 1 && HAVE_NICAM(msp)) {
906 msp->second = carrier_detect_55[max2].cdo;
907 msp3400c_setmode(client, MSP_MODE_FM_NICAM1);
909 msp3400c_setcarrier(client, msp->second, msp->main);
910 msp->watch_stereo = 1;
917 msp->second = MSP_CARRIER(6.552);
918 msp3400c_setmode(client, MSP_MODE_FM_NICAM2);
920 msp3400c_setcarrier(client, msp->second, msp->main);
921 msp->watch_stereo = 1;
924 if (max2 == 1 || max2 == 2) {
926 msp->second = carrier_detect_65[max2].cdo;
927 msp3400c_setmode(client, MSP_MODE_FM_TERRA);
929 msp3400c_setstereo(client, VIDEO_SOUND_MONO);
930 msp->watch_stereo = 1;
931 } else if (max2 == 0 &&
932 msp->norm == VIDEO_MODE_SECAM) {
933 /* L NICAM or AM-mono */
934 msp->second = carrier_detect_65[max2].cdo;
935 msp3400c_setmode(client, MSP_MODE_AM_NICAM);
937 msp3400c_setstereo(client, VIDEO_SOUND_MONO);
938 msp3400c_setcarrier(client, msp->second, msp->main);
939 /* volume prescale for SCART (AM mono input) */
940 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000d, 0x1900);
941 msp->watch_stereo = 1;
942 } else if (max2 == 0 && HAVE_NICAM(msp)) {
944 msp->second = carrier_detect_65[max2].cdo;
945 msp3400c_setmode(client, MSP_MODE_FM_NICAM1);
947 msp3400c_setcarrier(client, msp->second, msp->main);
948 msp->watch_stereo = 1;
956 msp->second = carrier_detect_main[max1].cdo;
957 msp3400c_setmode(client, MSP_MODE_FM_TERRA);
959 msp3400c_setcarrier(client, msp->second, msp->main);
960 msp->stereo = VIDEO_SOUND_MONO;
961 msp3400c_setstereo(client, VIDEO_SOUND_MONO);
965 /* unmute + restore dfp registers */
966 msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
967 msp3400c_restore_dfp(client);
969 if (msp->watch_stereo)
970 mod_timer(&msp->wake_stereo, jiffies+5*HZ);
973 msp3400c_print_mode(msp);
979 dprintk(KERN_DEBUG "msp3400: thread: exit\n");
983 if(msp->notify != NULL)
988 /* ----------------------------------------------------------------------- */
989 /* this one uses the automatic sound standard detection of newer */
990 /* msp34xx chip versions */
992 static struct MODES {
997 { 0x0000, 0, 0, "ERROR" },
998 { 0x0001, 0, 0, "autodetect start" },
999 { 0x0002, MSP_CARRIER(4.5), MSP_CARRIER(4.72), "4.5/4.72 M Dual FM-Stereo" },
1000 { 0x0003, MSP_CARRIER(5.5), MSP_CARRIER(5.7421875), "5.5/5.74 B/G Dual FM-Stereo" },
1001 { 0x0004, MSP_CARRIER(6.5), MSP_CARRIER(6.2578125), "6.5/6.25 D/K1 Dual FM-Stereo" },
1002 { 0x0005, MSP_CARRIER(6.5), MSP_CARRIER(6.7421875), "6.5/6.74 D/K2 Dual FM-Stereo" },
1003 { 0x0006, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 D/K FM-Mono (HDEV3)" },
1004 { 0x0008, MSP_CARRIER(5.5), MSP_CARRIER(5.85), "5.5/5.85 B/G NICAM FM" },
1005 { 0x0009, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 L NICAM AM" },
1006 { 0x000a, MSP_CARRIER(6.0), MSP_CARRIER(6.55), "6.0/6.55 I NICAM FM" },
1007 { 0x000b, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM" },
1008 { 0x000c, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM (HDEV2)" },
1009 { 0x0020, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Stereo" },
1010 { 0x0021, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Mono + SAP" },
1011 { 0x0030, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M EIA-J Japan Stereo" },
1012 { 0x0040, MSP_CARRIER(10.7), MSP_CARRIER(10.7), "10.7 FM-Stereo Radio" },
1013 { 0x0050, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 SAT-Mono" },
1014 { 0x0051, MSP_CARRIER(7.02), MSP_CARRIER(7.20), "7.02/7.20 SAT-Stereo" },
1015 { 0x0060, MSP_CARRIER(7.2), MSP_CARRIER(7.2), "7.2 SAT ADR" },
1016 { -1, 0, 0, NULL }, /* EOF */
1019 static int msp3410d_thread(void *data)
1021 struct i2c_client *client = data;
1022 struct msp3400c *msp = i2c_get_clientdata(client);
1027 sigfillset(¤t->blocked);
1028 strcpy(current->comm,"msp3410 [auto]");
1029 msp->thread = current;
1032 printk("msp3410: daemon started\n");
1033 if(msp->notify != NULL)
1040 printk(KERN_DEBUG "msp3410: thread: sleep\n");
1041 interruptible_sleep_on(&msp->wq);
1043 printk(KERN_DEBUG "msp3410: thread: wakeup\n");
1044 if (msp->rmmod || signal_pending(current))
1049 if (msp->watch_stereo) {
1050 watch_stereo(client);
1055 /* some time for the tuner to sync */
1056 current->state = TASK_INTERRUPTIBLE;
1057 schedule_timeout(HZ/5);
1058 if (signal_pending(current))
1062 if (msp->mode == MSP_MODE_EXTERN) {
1063 /* no carrier scan needed, just unmute */
1064 dprintk(KERN_DEBUG "msp3410: thread: no carrier scan\n");
1065 msp3400c_setvolume(client, msp->muted,
1066 msp->left, msp->right);
1070 del_timer(&msp->wake_stereo);
1071 msp->watch_stereo = 0;
1073 /* put into sane state (and mute) */
1074 msp3400c_reset(client);
1076 /* start autodetect */
1077 switch (msp->norm) {
1078 case VIDEO_MODE_PAL:
1082 case VIDEO_MODE_NTSC: /* BTSC */
1086 case VIDEO_MODE_SECAM:
1090 case VIDEO_MODE_RADIO:
1099 msp3400c_write(client, I2C_MSP3400C_DEM, 0x30, mode);
1100 msp3400c_write(client, I2C_MSP3400C_DEM, 0x20, std);
1104 for (i = 0; modelist[i].name != NULL; i++)
1105 if (modelist[i].retval == std)
1107 printk(KERN_DEBUG "msp3410: setting mode: %s (0x%04x)\n",
1108 modelist[i].name ? modelist[i].name : "unknown",std);
1112 /* programmed some specific mode */
1115 /* triggered autodetect */
1117 current->state = TASK_INTERRUPTIBLE;
1118 schedule_timeout(HZ/10);
1119 if (signal_pending(current))
1125 val = msp3400c_read(client, I2C_MSP3400C_DEM, 0x7e);
1128 dprintk(KERN_DEBUG "msp3410: detection still in progress\n");
1131 for (i = 0; modelist[i].name != NULL; i++)
1132 if (modelist[i].retval == val)
1134 dprintk(KERN_DEBUG "msp3410: current mode: %s (0x%04x)\n",
1135 modelist[i].name ? modelist[i].name : "unknown",
1137 msp->main = modelist[i].main;
1138 msp->second = modelist[i].second;
1140 if (amsound && (msp->norm == VIDEO_MODE_SECAM) && (val != 0x0009)) {
1141 /* autodetection has failed, let backup */
1142 dprintk(KERN_DEBUG "msp3410: autodetection failed,"
1143 " switching to backup mode: %s (0x%04x)\n",
1144 modelist[8].name ? modelist[8].name : "unknown",val);
1146 msp3400c_write(client, I2C_MSP3400C_DEM, 0x20, val);
1149 /* set various prescales */
1150 msp3400c_write(client, I2C_MSP3400C_DFP, 0x0d, 0x1900); /* scart */
1151 msp3400c_write(client, I2C_MSP3400C_DFP, 0x0e, 0x2403); /* FM */
1152 msp3400c_write(client, I2C_MSP3400C_DFP, 0x10, 0x5a00); /* nicam */
1156 case 0x0008: /* B/G NICAM */
1157 case 0x000a: /* I NICAM */
1159 msp->mode = MSP_MODE_FM_NICAM1;
1161 msp->mode = MSP_MODE_FM_NICAM2;
1162 /* just turn on stereo */
1163 msp->stereo = VIDEO_SOUND_STEREO;
1165 msp->watch_stereo = 1;
1166 msp3400c_setstereo(client,VIDEO_SOUND_STEREO);
1169 msp->mode = MSP_MODE_AM_NICAM;
1170 msp->stereo = VIDEO_SOUND_MONO;
1172 msp3400c_setstereo(client,VIDEO_SOUND_MONO);
1173 msp->watch_stereo = 1;
1175 case 0x0020: /* BTSC */
1176 /* just turn on stereo */
1177 msp->mode = MSP_MODE_BTSC;
1178 msp->stereo = VIDEO_SOUND_STEREO;
1180 msp->watch_stereo = 1;
1181 msp3400c_setstereo(client,VIDEO_SOUND_STEREO);
1183 case 0x0040: /* FM radio */
1184 msp->mode = MSP_MODE_FM_RADIO;
1185 msp->stereo = VIDEO_SOUND_STEREO;
1187 msp->watch_stereo = 0;
1188 /* not needed in theory if HAVE_RADIO(), but
1189 short programming enables carrier mute */
1190 msp3400c_setmode(client,MSP_MODE_FM_RADIO);
1191 msp3400c_setcarrier(client, MSP_CARRIER(10.7),
1194 msp3400c_set_scart(client,SCART_IN2,0);
1196 /* radio from SCART_IN2 */
1197 msp3400c_write(client,I2C_MSP3400C_DFP, 0x08, 0x0220);
1198 msp3400c_write(client,I2C_MSP3400C_DFP, 0x09, 0x0220);
1199 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0b, 0x0220);
1201 /* msp34xx does radio decoding */
1202 msp3400c_write(client,I2C_MSP3400C_DFP, 0x08, 0x0020);
1203 msp3400c_write(client,I2C_MSP3400C_DFP, 0x09, 0x0020);
1204 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0b, 0x0020);
1208 msp->mode = MSP_MODE_FM_TERRA;
1209 msp->stereo = VIDEO_SOUND_MONO;
1211 msp->watch_stereo = 1;
1215 /* unmute + restore dfp registers */
1216 msp3400c_setbass(client, msp->bass);
1217 msp3400c_settreble(client, msp->treble);
1218 msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
1219 msp3400c_restore_dfp(client);
1221 if (msp->watch_stereo)
1222 mod_timer(&msp->wake_stereo, jiffies+HZ);
1228 dprintk(KERN_DEBUG "msp3410: thread: exit\n");
1232 if(msp->notify != NULL)
1237 /* ----------------------------------------------------------------------- */
1239 static int msp_attach(struct i2c_adapter *adap, int addr,
1240 unsigned short flags, int kind);
1241 static int msp_detach(struct i2c_client *client);
1242 static int msp_probe(struct i2c_adapter *adap);
1243 static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg);
1245 static struct i2c_driver driver = {
1246 .name = "i2c msp3400 driver",
1247 .id = I2C_DRIVERID_MSP3400,
1248 .flags = I2C_DF_NOTIFY,
1249 .attach_adapter = msp_probe,
1250 .detach_client = msp_detach,
1251 .command = msp_command,
1254 static struct i2c_client client_template =
1256 I2C_DEVNAME("(unset)"),
1257 .flags = I2C_CLIENT_ALLOW_USE,
1261 static int msp_attach(struct i2c_adapter *adap, int addr,
1262 unsigned short flags, int kind)
1264 DECLARE_MUTEX_LOCKED(sem);
1265 struct msp3400c *msp;
1266 struct i2c_client *c;
1269 client_template.adapter = adap;
1270 client_template.addr = addr;
1272 if (-1 == msp3400c_reset(&client_template)) {
1273 dprintk("msp3400: no chip found\n");
1277 if (NULL == (c = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
1279 memcpy(c,&client_template,sizeof(struct i2c_client));
1280 if (NULL == (msp = kmalloc(sizeof(struct msp3400c),GFP_KERNEL))) {
1285 memset(msp,0,sizeof(struct msp3400c));
1289 msp->treble = 32768;
1292 for (i = 0; i < DFP_COUNT; i++)
1293 msp->dfp_regs[i] = -1;
1295 i2c_set_clientdata(c, msp);
1296 init_waitqueue_head(&msp->wq);
1298 if (-1 == msp3400c_reset(c)) {
1301 dprintk("msp3400: no chip found\n");
1305 msp->rev1 = msp3400c_read(c, I2C_MSP3400C_DFP, 0x1e);
1306 if (-1 != msp->rev1)
1307 msp->rev2 = msp3400c_read(c, I2C_MSP3400C_DFP, 0x1f);
1308 if ((-1 == msp->rev1) || (0 == msp->rev1 && 0 == msp->rev2)) {
1311 printk("msp3400: error while reading chip version\n");
1316 /* this will turn on a 1kHz beep - might be useful for debugging... */
1317 msp3400c_write(c,I2C_MSP3400C_DFP, 0x0014, 0x1040);
1319 msp3400c_setvolume(c,msp->muted,msp->left,msp->right);
1321 sprintf(c->name,"MSP34%02d%c-%c%d",
1322 (msp->rev2>>8)&0xff, (msp->rev1&0xff)+'@',
1323 ((msp->rev1>>8)&0xff)+'@', msp->rev2&0x1f);
1327 msp->simple = HAVE_SIMPLE(msp);
1329 /* use insmod option */
1330 msp->simple = simple;
1333 /* timer for stereo checking */
1334 init_timer(&msp->wake_stereo);
1335 msp->wake_stereo.function = msp3400c_stereo_wake;
1336 msp->wake_stereo.data = (unsigned long)msp;
1338 /* hello world :-) */
1339 printk(KERN_INFO "msp34xx: init: chip=%s",i2c_clientname(c));
1340 if (HAVE_NICAM(msp))
1342 if (HAVE_SIMPLE(msp))
1344 if (HAVE_RADIO(msp))
1348 /* startup control thread */
1351 rc = kernel_thread(msp->simple ? msp3410d_thread : msp3400c_thread,
1354 printk(KERN_WARNING "msp34xx: kernel_thread() failed\n");
1358 wake_up_interruptible(&msp->wq);
1360 /* update our own array */
1361 for (i = 0; i < MSP3400_MAX; i++) {
1362 if (NULL == msps[i]) {
1369 i2c_attach_client(c);
1373 static int msp_detach(struct i2c_client *client)
1375 DECLARE_MUTEX_LOCKED(sem);
1376 struct msp3400c *msp = i2c_get_clientdata(client);
1379 /* shutdown control thread */
1380 del_timer(&msp->wake_stereo);
1385 wake_up_interruptible(&msp->wq);
1389 msp3400c_reset(client);
1391 /* update our own array */
1392 for (i = 0; i < MSP3400_MAX; i++) {
1393 if (client == msps[i]) {
1399 i2c_detach_client(client);
1406 static int msp_probe(struct i2c_adapter *adap)
1408 #ifdef I2C_ADAP_CLASS_TV_ANALOG
1409 if (adap->class & I2C_ADAP_CLASS_TV_ANALOG)
1410 return i2c_probe(adap, &addr_data, msp_attach);
1412 if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848))
1413 return i2c_probe(adap, &addr_data, msp_attach);
1418 static void msp_wake_thread(struct i2c_client *client)
1420 struct msp3400c *msp = i2c_get_clientdata(client);
1422 msp3400c_setvolume(client,msp->muted,0,0);
1423 msp->watch_stereo=0;
1424 del_timer(&msp->wake_stereo);
1427 wake_up_interruptible(&msp->wq);
1430 static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
1432 struct msp3400c *msp = i2c_get_clientdata(client);
1435 int *iarg = (int*)arg;
1440 case AUDC_SET_INPUT:
1442 - IN1 is often used for external input
1443 - Hauppauge uses IN2 for the radio */
1444 dprintk(KERN_DEBUG "msp34xx: AUDC_SET_INPUT(%d)\n",*sarg);
1445 if (*sarg == msp->input)
1450 msp->mode = MSP_MODE_FM_RADIO;
1451 msp->stereo = VIDEO_SOUND_STEREO;
1452 msp3400c_set_scart(client,SCART_IN2,0);
1453 msp3400c_write(client,I2C_MSP3400C_DFP,0x000d,0x1900);
1454 msp3400c_setstereo(client,msp->stereo);
1457 msp->mode = MSP_MODE_EXTERN;
1458 msp->stereo = VIDEO_SOUND_STEREO;
1459 msp3400c_set_scart(client,SCART_IN1,0);
1460 msp3400c_write(client,I2C_MSP3400C_DFP,0x000d,0x1900);
1461 msp3400c_setstereo(client,msp->stereo);
1465 msp_wake_thread(client);
1468 if (*sarg & AUDIO_MUTE)
1469 msp3400c_set_scart(client,SCART_MUTE,0);
1476 case AUDC_SET_RADIO:
1477 dprintk(KERN_DEBUG "msp34xx: AUDC_SET_RADIO\n");
1478 msp->norm = VIDEO_MODE_RADIO;
1479 msp->watch_stereo=0;
1480 del_timer(&msp->wake_stereo);
1481 dprintk(KERN_DEBUG "msp34xx: switching to radio mode\n");
1483 /* the thread will do for us */
1484 msp_wake_thread(client);
1486 /* set msp3400 to FM radio mode */
1487 msp3400c_setmode(client,MSP_MODE_FM_RADIO);
1488 msp3400c_setcarrier(client, MSP_CARRIER(10.7),MSP_CARRIER(10.7));
1489 msp3400c_setvolume(client,msp->muted,msp->left,msp->right);
1496 /* work-in-progress: hook to control the DFP registers */
1497 case MSP_SET_DFPREG:
1499 struct msp_dfpreg *r = arg;
1502 if (r->reg < 0 || r->reg >= DFP_COUNT)
1504 for (i = 0; i < ARRAY_SIZE(bl_dfp); i++)
1505 if (r->reg == bl_dfp[i])
1507 msp->dfp_regs[r->reg] = r->value;
1508 msp3400c_write(client,I2C_MSP3400C_DFP,r->reg,r->value);
1511 case MSP_GET_DFPREG:
1513 struct msp_dfpreg *r = arg;
1515 if (r->reg < 0 || r->reg >= DFP_COUNT)
1517 r->value = msp3400c_read(client,I2C_MSP3400C_DFP,r->reg);
1522 /* --- v4l ioctls --- */
1523 /* take care: bttv does userspace copying, we'll get a
1524 kernel pointer here... */
1527 struct video_audio *va = arg;
1529 dprintk(KERN_DEBUG "msp34xx: VIDIOCGAUDIO\n");
1530 va->flags |= VIDEO_AUDIO_VOLUME |
1532 VIDEO_AUDIO_TREBLE |
1533 VIDEO_AUDIO_MUTABLE;
1535 va->flags |= VIDEO_AUDIO_MUTE;
1536 va->volume=max(msp->left,msp->right);
1537 va->balance=(32768*min(msp->left,msp->right))/
1538 (va->volume ? va->volume : 1);
1539 va->balance=(msp->left<msp->right)?
1540 (65535-va->balance) : va->balance;
1541 if (0 == va->volume)
1542 va->balance = 32768;
1543 va->bass = msp->bass;
1544 va->treble = msp->treble;
1546 if (msp->norm != VIDEO_MODE_RADIO) {
1547 autodetect_stereo(client);
1548 va->mode = msp->stereo;
1554 struct video_audio *va = arg;
1556 dprintk(KERN_DEBUG "msp34xx: VIDIOCSAUDIO\n");
1557 msp->muted = (va->flags & VIDEO_AUDIO_MUTE);
1558 msp->left = (min(65536 - va->balance,32768) *
1559 va->volume) / 32768;
1560 msp->right = (min(va->balance,(__u16)32768) *
1561 va->volume) / 32768;
1562 msp->bass = va->bass;
1563 msp->treble = va->treble;
1564 msp3400c_setvolume(client,msp->muted,msp->left,msp->right);
1565 msp3400c_setbass(client,msp->bass);
1566 msp3400c_settreble(client,msp->treble);
1568 if (va->mode != 0 && msp->norm != VIDEO_MODE_RADIO) {
1569 msp->watch_stereo=0;
1570 del_timer(&msp->wake_stereo);
1571 msp->stereo = va->mode & 0x0f;
1572 msp3400c_setstereo(client,va->mode & 0x0f);
1578 struct video_channel *vc = arg;
1580 dprintk(KERN_DEBUG "msp34xx: VIDIOCSCHAN\n");
1581 msp->norm = vc->norm;
1586 /* new channel -- kick audio carrier scan */
1587 dprintk(KERN_DEBUG "msp34xx: VIDIOCSFREQ\n");
1588 msp_wake_thread(client);
1599 /* ----------------------------------------------------------------------- */
1601 static int msp3400_init_module(void)
1603 i2c_add_driver(&driver);
1607 static void msp3400_cleanup_module(void)
1609 i2c_del_driver(&driver);
1612 module_init(msp3400_init_module);
1613 module_exit(msp3400_cleanup_module);
1616 * Overrides for Emacs so that we follow Linus's tabbing style.
1617 * ---------------------------------------------------------------------------