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>
56 /* insmod parameters */
57 static int debug = 0; /* debug output */
58 static int once = 0; /* no continous stereo monitoring */
59 static int amsound = 0; /* hard-wire AM sound at 6.5 Hz (france),
60 the autoscan seems work well only with FM... */
61 static int simple = -1; /* use short programming (>= msp3410 only) */
64 #define DFP_COUNT 0x41
65 static const int bl_dfp[] = {
66 0x00, 0x01, 0x02, 0x03, 0x06, 0x08, 0x09, 0x0a,
67 0x0b, 0x0d, 0x0e, 0x10
79 int main, second; /* sound carrier */
83 int left, right; /* volume */
86 /* shadow register set */
87 int dfp_regs[DFP_COUNT];
91 struct completion texit;
99 struct timer_list wake_stereo;
102 #define HAVE_NICAM(msp) (((msp->rev2>>8) & 0xff) != 00)
103 #define HAVE_SIMPLE(msp) ((msp->rev1 & 0xff) >= 'D'-'@')
104 #define HAVE_RADIO(msp) ((msp->rev1 & 0xff) >= 'G'-'@')
106 #define VIDEO_MODE_RADIO 16 /* norm magic for radio mode */
108 /* ---------------------------------------------------------------------- */
110 #define dprintk if (debug >= 1) printk
111 #define d2printk if (debug >= 2) printk
113 MODULE_PARM(once,"i");
114 MODULE_PARM(debug,"i");
115 MODULE_PARM(simple,"i");
116 MODULE_PARM(amsound,"i");
117 MODULE_PARM(dolby,"i");
119 MODULE_DESCRIPTION("device driver for msp34xx TV sound processor");
120 MODULE_AUTHOR("Gerd Knorr");
121 MODULE_LICENSE("Dual BSD/GPL"); /* FreeBSD uses this too */
123 /* ---------------------------------------------------------------------- */
125 #define I2C_MSP3400C 0x80
126 #define I2C_MSP3400C_ALT 0x88
128 #define I2C_MSP3400C_DEM 0x10
129 #define I2C_MSP3400C_DFP 0x12
131 /* Addresses to scan */
132 static unsigned short normal_i2c[] = {
134 I2C_MSP3400C_ALT >> 1,
137 static unsigned short normal_i2c_range[] = {I2C_CLIENT_END,I2C_CLIENT_END};
140 /* ----------------------------------------------------------------------- */
141 /* functions for talking to the MSP3400C Sound processor */
143 #ifndef I2C_M_IGNORE_NAK
144 # define I2C_M_IGNORE_NAK 0x1000
147 static int msp3400c_reset(struct i2c_client *client)
149 /* reset and read revision code */
150 static char reset_off[3] = { 0x00, 0x80, 0x00 };
151 static char reset_on[3] = { 0x00, 0x00, 0x00 };
152 static char write[3] = { I2C_MSP3400C_DFP + 1, 0x00, 0x1e };
154 struct i2c_msg reset[2] = {
155 { client->addr, I2C_M_IGNORE_NAK, 3, reset_off },
156 { client->addr, I2C_M_IGNORE_NAK, 3, reset_on },
158 struct i2c_msg test[2] = {
159 { client->addr, 0, 3, write },
160 { client->addr, I2C_M_RD, 2, read },
163 if ( (1 != i2c_transfer(client->adapter,&reset[0],1)) ||
164 (1 != i2c_transfer(client->adapter,&reset[1],1)) ||
165 (2 != i2c_transfer(client->adapter,test,2)) ) {
166 printk(KERN_ERR "msp3400: chip reset failed\n");
173 msp3400c_read(struct i2c_client *client, int dev, int addr)
177 unsigned char write[3];
178 unsigned char read[2];
179 struct i2c_msg msgs[2] = {
180 { client->addr, 0, 3, write },
181 { client->addr, I2C_M_RD, 2, read }
184 write[1] = addr >> 8;
185 write[2] = addr & 0xff;
187 for (err = 0; err < 3;) {
188 if (2 == i2c_transfer(client->adapter,msgs,2))
191 printk(KERN_WARNING "msp34xx: I/O error #%d (read 0x%02x/0x%02x)\n",
193 set_current_state(TASK_INTERRUPTIBLE);
194 schedule_timeout(HZ/10);
197 printk(KERN_WARNING "msp34xx: giving up, reseting chip. Sound will go off, sorry folks :-|\n");
198 msp3400c_reset(client);
201 return read[0] << 8 | read[1];
205 msp3400c_write(struct i2c_client *client, int dev, int addr, int val)
208 unsigned char buffer[5];
211 buffer[1] = addr >> 8;
212 buffer[2] = addr & 0xff;
213 buffer[3] = val >> 8;
214 buffer[4] = val & 0xff;
216 for (err = 0; err < 3;) {
217 if (5 == i2c_master_send(client, buffer, 5))
220 printk(KERN_WARNING "msp34xx: I/O error #%d (write 0x%02x/0x%02x)\n",
222 set_current_state(TASK_INTERRUPTIBLE);
223 schedule_timeout(HZ/10);
226 printk(KERN_WARNING "msp34xx: giving up, reseting chip. Sound will go off, sorry folks :-|\n");
227 msp3400c_reset(client);
233 /* ------------------------------------------------------------------------ */
235 /* This macro is allowed for *constants* only, gcc must calculate it
236 at compile time. Remember -- no floats in kernel mode */
237 #define MSP_CARRIER(freq) ((int)((float)(freq/18.432)*(1<<24)))
239 #define MSP_MODE_AM_DETECT 0
240 #define MSP_MODE_FM_RADIO 2
241 #define MSP_MODE_FM_TERRA 3
242 #define MSP_MODE_FM_SAT 4
243 #define MSP_MODE_FM_NICAM1 5
244 #define MSP_MODE_FM_NICAM2 6
245 #define MSP_MODE_AM_NICAM 7
246 #define MSP_MODE_BTSC 8
247 #define MSP_MODE_EXTERN 9
249 static struct MSP_INIT_DATA_DEM {
258 } msp_init_data[] = {
259 /* AM (for carrier detect / msp3400) */
260 { { 75, 19, 36, 35, 39, 40 }, { 75, 19, 36, 35, 39, 40 },
261 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
262 0x00d0, 0x0500, 0x0020, 0x3000},
264 /* AM (for carrier detect / msp3410) */
265 { { -1, -1, -8, 2, 59, 126 }, { -1, -1, -8, 2, 59, 126 },
266 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
267 0x00d0, 0x0100, 0x0020, 0x3000},
270 { { -8, -8, 4, 6, 78, 107 }, { -8, -8, 4, 6, 78, 107 },
271 MSP_CARRIER(10.7), MSP_CARRIER(10.7),
272 0x00d0, 0x0480, 0x0020, 0x3000 },
274 /* Terrestial FM-mono + FM-stereo */
275 { { 3, 18, 27, 48, 66, 72 }, { 3, 18, 27, 48, 66, 72 },
276 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
277 0x00d0, 0x0480, 0x0030, 0x3000},
280 { { 1, 9, 14, 24, 33, 37 }, { 3, 18, 27, 48, 66, 72 },
281 MSP_CARRIER(6.5), MSP_CARRIER(6.5),
282 0x00c6, 0x0480, 0x0000, 0x3000},
284 /* NICAM/FM -- B/G (5.5/5.85), D/K (6.5/5.85) */
285 { { -2, -8, -10, 10, 50, 86 }, { 3, 18, 27, 48, 66, 72 },
286 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
287 0x00d0, 0x0040, 0x0120, 0x3000},
289 /* NICAM/FM -- I (6.0/6.552) */
290 { { 2, 4, -6, -4, 40, 94 }, { 3, 18, 27, 48, 66, 72 },
291 MSP_CARRIER(6.0), MSP_CARRIER(6.0),
292 0x00d0, 0x0040, 0x0120, 0x3000},
294 /* NICAM/AM -- L (6.5/5.85) */
295 { { -2, -8, -10, 10, 50, 86 }, { -4, -12, -9, 23, 79, 126 },
296 MSP_CARRIER(6.5), MSP_CARRIER(6.5),
297 0x00c6, 0x0140, 0x0120, 0x7c03},
300 struct CARRIER_DETECT {
305 static struct CARRIER_DETECT carrier_detect_main[] = {
307 { MSP_CARRIER(4.5), "4.5 NTSC" },
308 { MSP_CARRIER(5.5), "5.5 PAL B/G" },
309 { MSP_CARRIER(6.0), "6.0 PAL I" },
310 { MSP_CARRIER(6.5), "6.5 PAL D/K + SAT + SECAM" }
313 static struct CARRIER_DETECT carrier_detect_55[] = {
315 { MSP_CARRIER(5.7421875), "5.742 PAL B/G FM-stereo" },
316 { MSP_CARRIER(5.85), "5.85 PAL B/G NICAM" }
319 static struct CARRIER_DETECT carrier_detect_65[] = {
320 /* PAL SAT / SECAM */
321 { MSP_CARRIER(5.85), "5.85 PAL D/K + SECAM NICAM" },
322 { MSP_CARRIER(6.2578125), "6.25 PAL D/K1 FM-stereo" },
323 { MSP_CARRIER(6.7421875), "6.74 PAL D/K2 FM-stereo" },
324 { MSP_CARRIER(7.02), "7.02 PAL SAT FM-stereo s/b" },
325 { MSP_CARRIER(7.20), "7.20 PAL SAT FM-stereo s" },
326 { MSP_CARRIER(7.38), "7.38 PAL SAT FM-stereo b" },
329 #define CARRIER_COUNT(x) (sizeof(x)/sizeof(struct CARRIER_DETECT))
331 /* ----------------------------------------------------------------------- */
336 #define SCART_IN1_DA 3
337 #define SCART_IN2_DA 4
343 static int scarts[3][9] = {
344 /* MASK IN1 IN2 IN1_DA IN2_DA IN3 IN4 MONO MUTE */
345 { 0x0320, 0x0000, 0x0200, -1, -1, 0x0300, 0x0020, 0x0100, 0x0320 },
346 { 0x0c40, 0x0440, 0x0400, 0x0c00, 0x0040, 0x0000, 0x0840, 0x0800, 0x0c40 },
347 { 0x3080, 0x1000, 0x1080, 0x0000, 0x0080, 0x2080, 0x3080, 0x2000, 0x3000 },
350 static char *scart_names[] = {
351 "mask", "in1", "in2", "in1 da", "in2 da", "in3", "in4", "mono", "mute"
355 msp3400c_set_scart(struct i2c_client *client, int in, int out)
357 struct msp3400c *msp = i2c_get_clientdata(client);
359 if (-1 == scarts[out][in])
363 "msp34xx: scart switch: %s => %d\n",scart_names[in],out);
364 msp->acb &= ~scarts[out][SCART_MASK];
365 msp->acb |= scarts[out][in];
366 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0013, msp->acb);
369 /* ------------------------------------------------------------------------ */
371 static void msp3400c_setcarrier(struct i2c_client *client, int cdo1, int cdo2)
373 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0093, cdo1 & 0xfff);
374 msp3400c_write(client,I2C_MSP3400C_DEM, 0x009b, cdo1 >> 12);
375 msp3400c_write(client,I2C_MSP3400C_DEM, 0x00a3, cdo2 & 0xfff);
376 msp3400c_write(client,I2C_MSP3400C_DEM, 0x00ab, cdo2 >> 12);
377 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0056, 0); /*LOAD_REG_1/2*/
380 static void msp3400c_setvolume(struct i2c_client *client,
381 int muted, int left, int right)
383 int vol = 0,val = 0,balance = 0;
386 vol = (left > right) ? left : right;
387 val = (vol * 0x73 / 65535) << 8;
390 balance = ((right-left) * 127) / vol;
394 "msp34xx: setvolume: mute=%s %d:%d v=0x%02x b=0x%02x\n",
395 muted ? "on" : "off", left, right, val>>8, balance);
396 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0000, val); /* loudspeaker */
397 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0006, val); /* headphones */
398 /* scart - on/off only */
399 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0007, val ? 0x4000 : 0);
400 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0001, balance << 8);
403 static void msp3400c_setbass(struct i2c_client *client, int bass)
405 int val = ((bass-32768) * 0x60 / 65535) << 8;
407 dprintk(KERN_DEBUG "msp34xx: setbass: %d 0x%02x\n",bass, val>>8);
408 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0002, val); /* loudspeaker */
411 static void msp3400c_settreble(struct i2c_client *client, int treble)
413 int val = ((treble-32768) * 0x60 / 65535) << 8;
415 dprintk(KERN_DEBUG "msp34xx: settreble: %d 0x%02x\n",treble, val>>8);
416 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0003, val); /* loudspeaker */
419 static void msp3400c_setmode(struct i2c_client *client, int type)
421 struct msp3400c *msp = i2c_get_clientdata(client);
424 dprintk(KERN_DEBUG "msp3400: setmode: %d\n",type);
426 msp->stereo = VIDEO_SOUND_MONO;
428 msp3400c_write(client,I2C_MSP3400C_DEM, 0x00bb, /* ad_cv */
429 msp_init_data[type].ad_cv);
431 for (i = 5; i >= 0; i--) /* fir 1 */
432 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0001,
433 msp_init_data[type].fir1[i]);
435 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0004); /* fir 2 */
436 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0040);
437 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0000);
438 for (i = 5; i >= 0; i--)
439 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005,
440 msp_init_data[type].fir2[i]);
442 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0083, /* MODE_REG */
443 msp_init_data[type].mode_reg);
445 msp3400c_setcarrier(client, msp_init_data[type].cdo1,
446 msp_init_data[type].cdo2);
448 msp3400c_write(client,I2C_MSP3400C_DEM, 0x0056, 0); /*LOAD_REG_1/2*/
451 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,
453 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,
455 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,
456 msp_init_data[type].dfp_src);
458 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,
459 msp_init_data[type].dfp_src);
460 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,
461 msp_init_data[type].dfp_src);
462 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,
463 msp_init_data[type].dfp_src);
465 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000a,
466 msp_init_data[type].dfp_src);
467 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000e,
468 msp_init_data[type].dfp_matrix);
470 if (HAVE_NICAM(msp)) {
472 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0010, 0x5a00); /* was: 0x3000 */
476 /* turn on/off nicam + stereo */
477 static void msp3400c_setstereo(struct i2c_client *client, int mode)
479 static char *strmode[16] = {
481 [ 0 ... 15 ] = "invalid",
483 [ VIDEO_SOUND_MONO ] = "mono",
484 [ VIDEO_SOUND_STEREO ] = "stereo",
485 [ VIDEO_SOUND_LANG1 ] = "lang1",
486 [ VIDEO_SOUND_LANG2 ] = "lang2",
488 struct msp3400c *msp = i2c_get_clientdata(client);
489 int nicam=0; /* channel source: FM/AM or nicam */
492 /* switch demodulator */
494 case MSP_MODE_FM_TERRA:
495 dprintk(KERN_DEBUG "msp3400: FM setstereo: %s\n",strmode[mode]);
496 msp3400c_setcarrier(client,msp->second,msp->main);
498 case VIDEO_SOUND_STEREO:
499 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000e, 0x3001);
501 case VIDEO_SOUND_MONO:
502 case VIDEO_SOUND_LANG1:
503 case VIDEO_SOUND_LANG2:
504 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000e, 0x3000);
508 case MSP_MODE_FM_SAT:
509 dprintk(KERN_DEBUG "msp3400: SAT setstereo: %s\n",strmode[mode]);
511 case VIDEO_SOUND_MONO:
512 msp3400c_setcarrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
514 case VIDEO_SOUND_STEREO:
515 msp3400c_setcarrier(client, MSP_CARRIER(7.2), MSP_CARRIER(7.02));
517 case VIDEO_SOUND_LANG1:
518 msp3400c_setcarrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
520 case VIDEO_SOUND_LANG2:
521 msp3400c_setcarrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
525 case MSP_MODE_FM_NICAM1:
526 case MSP_MODE_FM_NICAM2:
527 case MSP_MODE_AM_NICAM:
528 dprintk(KERN_DEBUG "msp3400: NICAM setstereo: %s\n",strmode[mode]);
529 msp3400c_setcarrier(client,msp->second,msp->main);
534 dprintk(KERN_DEBUG "msp3400: BTSC setstereo: %s\n",strmode[mode]);
537 case MSP_MODE_EXTERN:
538 dprintk(KERN_DEBUG "msp3400: extern setstereo: %s\n",strmode[mode]);
541 case MSP_MODE_FM_RADIO:
542 dprintk(KERN_DEBUG "msp3400: FM-Radio setstereo: %s\n",strmode[mode]);
545 dprintk(KERN_DEBUG "msp3400: mono setstereo\n");
551 case VIDEO_SOUND_STEREO:
552 src = 0x0020 | nicam;
555 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0005,0x4000);
558 case VIDEO_SOUND_MONO:
559 if (msp->mode == MSP_MODE_AM_NICAM) {
560 dprintk("msp3400: switching to AM mono\n");
561 /* AM mono decoding is handled by tuner, not MSP chip */
562 /* SCART switching control register */
563 msp3400c_set_scart(client,SCART_MONO,0);
567 case VIDEO_SOUND_LANG1:
568 src = 0x0000 | nicam;
570 case VIDEO_SOUND_LANG2:
571 src = 0x0010 | nicam;
575 "msp3400: setstereo final source/matrix = 0x%x\n", src);
578 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,0x0520);
579 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,0x0620);
580 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000a,src);
581 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,src);
583 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,src);
584 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,src);
585 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000a,src);
586 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,src);
591 msp3400c_print_mode(struct msp3400c *msp)
593 if (msp->main == msp->second) {
594 printk(KERN_DEBUG "msp3400: mono sound carrier: %d.%03d MHz\n",
595 msp->main/910000,(msp->main/910)%1000);
597 printk(KERN_DEBUG "msp3400: main sound carrier: %d.%03d MHz\n",
598 msp->main/910000,(msp->main/910)%1000);
600 if (msp->mode == MSP_MODE_FM_NICAM1 ||
601 msp->mode == MSP_MODE_FM_NICAM2)
602 printk(KERN_DEBUG "msp3400: NICAM/FM carrier : %d.%03d MHz\n",
603 msp->second/910000,(msp->second/910)%1000);
604 if (msp->mode == MSP_MODE_AM_NICAM)
605 printk(KERN_DEBUG "msp3400: NICAM/AM carrier : %d.%03d MHz\n",
606 msp->second/910000,(msp->second/910)%1000);
607 if (msp->mode == MSP_MODE_FM_TERRA &&
608 msp->main != msp->second) {
609 printk(KERN_DEBUG "msp3400: FM-stereo carrier : %d.%03d MHz\n",
610 msp->second/910000,(msp->second/910)%1000);
615 msp3400c_restore_dfp(struct i2c_client *client)
617 struct msp3400c *msp = i2c_get_clientdata(client);
620 for (i = 0; i < DFP_COUNT; i++) {
621 if (-1 == msp->dfp_regs[i])
623 msp3400c_write(client,I2C_MSP3400C_DFP, i, msp->dfp_regs[i]);
627 /* ----------------------------------------------------------------------- */
629 struct REGISTER_DUMP {
634 struct REGISTER_DUMP d1[] = {
635 { 0x007e, "autodetect" },
636 { 0x0023, "C_AD_BITS " },
637 { 0x0038, "ADD_BITS " },
638 { 0x003e, "CIB_BITS " },
639 { 0x0057, "ERROR_RATE" },
643 autodetect_stereo(struct i2c_client *client)
645 struct msp3400c *msp = i2c_get_clientdata(client);
647 int newstereo = msp->stereo;
648 int newnicam = msp->nicam_on;
652 case MSP_MODE_FM_TERRA:
653 val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x18);
657 "msp34xx: stereo detect register: %d\n",val);
659 newstereo = VIDEO_SOUND_STEREO | VIDEO_SOUND_MONO;
660 } else if (val < -4096) {
661 newstereo = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
663 newstereo = VIDEO_SOUND_MONO;
667 case MSP_MODE_FM_NICAM1:
668 case MSP_MODE_FM_NICAM2:
669 case MSP_MODE_AM_NICAM:
670 val = msp3400c_read(client, I2C_MSP3400C_DEM, 0x23);
672 "msp34xx: nicam sync=%d, mode=%d\n",
673 val & 1, (val & 0x1e) >> 1);
677 switch ((val & 0x1e) >> 1) {
680 newstereo = VIDEO_SOUND_STEREO;
684 newstereo = VIDEO_SOUND_MONO
689 newstereo = VIDEO_SOUND_MONO
694 newstereo = VIDEO_SOUND_MONO;
700 newstereo = VIDEO_SOUND_MONO;
704 val = msp3400c_read(client, I2C_MSP3400C_DEM, 0x200);
706 "msp3410: status=0x%x (pri=%s, sec=%s, %s%s%s)\n",
708 (val & 0x0002) ? "no" : "yes",
709 (val & 0x0004) ? "no" : "yes",
710 (val & 0x0040) ? "stereo" : "mono",
711 (val & 0x0080) ? ", nicam 2nd mono" : "",
712 (val & 0x0100) ? ", bilingual/SAP" : "");
713 newstereo = VIDEO_SOUND_MONO;
714 if (val & 0x0040) newstereo |= VIDEO_SOUND_STEREO;
715 if (val & 0x0100) newstereo |= VIDEO_SOUND_LANG1;
718 if (newstereo != msp->stereo) {
720 dprintk(KERN_DEBUG "msp34xx: watch: stereo %d => %d\n",
721 msp->stereo,newstereo);
722 msp->stereo = newstereo;
724 if (newnicam != msp->nicam_on) {
726 dprintk(KERN_DEBUG "msp34xx: watch: nicam %d => %d\n",
727 msp->nicam_on,newnicam);
728 msp->nicam_on = newnicam;
734 * A kernel thread for msp3400 control -- we don't want to block the
735 * in the ioctl while doing the sound carrier & stereo detect
738 static int msp34xx_sleep(struct msp3400c *msp, int timeout)
740 DECLARE_WAITQUEUE(wait, current);
742 add_wait_queue(&msp->wq, &wait);
744 set_current_state(TASK_INTERRUPTIBLE);
748 schedule_timeout(timeout);
750 remove_wait_queue(&msp->wq, &wait);
751 return msp->rmmod || signal_pending(current);
754 static void msp3400c_stereo_wake(unsigned long data)
756 struct msp3400c *msp = (struct msp3400c*)data; /* XXX alpha ??? */
758 wake_up_interruptible(&msp->wq);
761 /* stereo/multilang monitoring */
762 static void watch_stereo(struct i2c_client *client)
764 struct msp3400c *msp = i2c_get_clientdata(client);
766 if (autodetect_stereo(client)) {
767 if (msp->stereo & VIDEO_SOUND_STEREO)
768 msp3400c_setstereo(client,VIDEO_SOUND_STEREO);
769 else if (msp->stereo & VIDEO_SOUND_LANG1)
770 msp3400c_setstereo(client,VIDEO_SOUND_LANG1);
771 else if (msp->stereo & VIDEO_SOUND_LANG2)
772 msp3400c_setstereo(client,VIDEO_SOUND_LANG2);
774 msp3400c_setstereo(client,VIDEO_SOUND_MONO);
777 msp->watch_stereo = 0;
778 if (msp->watch_stereo)
779 mod_timer(&msp->wake_stereo, jiffies+5*HZ);
782 static int msp3400c_thread(void *data)
784 struct i2c_client *client = data;
785 struct msp3400c *msp = i2c_get_clientdata(client);
787 struct CARRIER_DETECT *cd;
788 int count, max1,max2,val1,val2, val,this;
790 daemonize("msp3400");
791 allow_signal(SIGTERM);
792 printk("msp3400: daemon started\n");
795 d2printk("msp3400: thread: sleep\n");
796 if (msp34xx_sleep(msp,-1))
799 d2printk("msp3400: thread: wakeup\n");
802 if (msp->watch_stereo) {
803 watch_stereo(client);
808 /* some time for the tuner to sync */
809 if (msp34xx_sleep(msp,HZ/5))
813 if (VIDEO_MODE_RADIO == msp->norm ||
814 MSP_MODE_EXTERN == msp->mode) {
815 /* no carrier scan, just unmute */
816 printk("msp3400: thread: no carrier scan\n");
817 msp3400c_setvolume(client, msp->muted,
818 msp->left, msp->right);
822 msp3400c_setvolume(client, msp->muted, 0, 0);
823 msp3400c_setmode(client, MSP_MODE_AM_DETECT /* +1 */ );
826 del_timer(&msp->wake_stereo);
827 msp->watch_stereo = 0;
829 /* carrier detect pass #1 -- main carrier */
830 cd = carrier_detect_main; count = CARRIER_COUNT(carrier_detect_main);
832 if (amsound && (msp->norm == VIDEO_MODE_SECAM)) {
833 /* autodetect doesn't work well with AM ... */
836 dprintk("msp3400: AM sound override\n");
839 for (this = 0; this < count; this++) {
840 msp3400c_setcarrier(client, cd[this].cdo,cd[this].cdo);
842 if (msp34xx_sleep(msp,HZ/10))
847 val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);
851 val1 = val, max1 = this;
852 dprintk("msp3400: carrier1 val: %5d / %s\n", val,cd[this].name);
855 /* carrier detect pass #2 -- second (stereo) carrier */
858 cd = carrier_detect_55; count = CARRIER_COUNT(carrier_detect_55);
861 cd = carrier_detect_65; count = CARRIER_COUNT(carrier_detect_65);
866 cd = NULL; count = 0;
870 if (amsound && (msp->norm == VIDEO_MODE_SECAM)) {
871 /* autodetect doesn't work well with AM ... */
872 cd = NULL; count = 0; max2 = 0;
874 for (this = 0; this < count; this++) {
875 msp3400c_setcarrier(client, cd[this].cdo,cd[this].cdo);
877 if (msp34xx_sleep(msp,HZ/10))
882 val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);
886 val2 = val, max2 = this;
887 dprintk("msp3400: carrier2 val: %5d / %s\n", val,cd[this].name);
890 /* programm the msp3400 according to the results */
891 msp->main = carrier_detect_main[max1].cdo;
896 msp->second = carrier_detect_55[max2].cdo;
897 msp3400c_setmode(client, MSP_MODE_FM_TERRA);
899 msp3400c_setstereo(client, VIDEO_SOUND_MONO);
900 msp->watch_stereo = 1;
901 } else if (max2 == 1 && HAVE_NICAM(msp)) {
903 msp->second = carrier_detect_55[max2].cdo;
904 msp3400c_setmode(client, MSP_MODE_FM_NICAM1);
906 msp3400c_setcarrier(client, msp->second, msp->main);
907 msp->watch_stereo = 1;
914 msp->second = MSP_CARRIER(6.552);
915 msp3400c_setmode(client, MSP_MODE_FM_NICAM2);
917 msp3400c_setcarrier(client, msp->second, msp->main);
918 msp->watch_stereo = 1;
921 if (max2 == 1 || max2 == 2) {
923 msp->second = carrier_detect_65[max2].cdo;
924 msp3400c_setmode(client, MSP_MODE_FM_TERRA);
926 msp3400c_setstereo(client, VIDEO_SOUND_MONO);
927 msp->watch_stereo = 1;
928 } else if (max2 == 0 &&
929 msp->norm == VIDEO_MODE_SECAM) {
930 /* L NICAM or AM-mono */
931 msp->second = carrier_detect_65[max2].cdo;
932 msp3400c_setmode(client, MSP_MODE_AM_NICAM);
934 msp3400c_setstereo(client, VIDEO_SOUND_MONO);
935 msp3400c_setcarrier(client, msp->second, msp->main);
936 /* volume prescale for SCART (AM mono input) */
937 msp3400c_write(client,I2C_MSP3400C_DFP, 0x000d, 0x1900);
938 msp->watch_stereo = 1;
939 } else if (max2 == 0 && HAVE_NICAM(msp)) {
941 msp->second = carrier_detect_65[max2].cdo;
942 msp3400c_setmode(client, MSP_MODE_FM_NICAM1);
944 msp3400c_setcarrier(client, msp->second, msp->main);
945 msp->watch_stereo = 1;
953 msp->second = carrier_detect_main[max1].cdo;
954 msp3400c_setmode(client, MSP_MODE_FM_TERRA);
956 msp3400c_setcarrier(client, msp->second, msp->main);
957 msp->stereo = VIDEO_SOUND_MONO;
958 msp3400c_setstereo(client, VIDEO_SOUND_MONO);
962 /* unmute + restore dfp registers */
963 msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
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->left, msp->right);
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, msp->left, msp->right);
1198 msp3400c_restore_dfp(client);
1200 if (msp->watch_stereo)
1201 mod_timer(&msp->wake_stereo, jiffies+HZ);
1208 dprintk(KERN_DEBUG "msp3410: thread: exit\n");
1209 complete_and_exit(&msp->texit, 0);
1213 /* ----------------------------------------------------------------------- */
1215 static int msp_attach(struct i2c_adapter *adap, int addr, int kind);
1216 static int msp_detach(struct i2c_client *client);
1217 static int msp_probe(struct i2c_adapter *adap);
1218 static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg);
1220 static struct i2c_driver driver = {
1221 .owner = THIS_MODULE,
1222 .name = "i2c msp3400 driver",
1223 .id = I2C_DRIVERID_MSP3400,
1224 .flags = I2C_DF_NOTIFY,
1225 .attach_adapter = msp_probe,
1226 .detach_client = msp_detach,
1227 .command = msp_command,
1230 static struct i2c_client client_template =
1232 I2C_DEVNAME("(unset)"),
1233 .flags = I2C_CLIENT_ALLOW_USE,
1237 static int msp_attach(struct i2c_adapter *adap, int addr, int kind)
1239 struct msp3400c *msp;
1240 struct i2c_client *c;
1243 client_template.adapter = adap;
1244 client_template.addr = addr;
1246 if (-1 == msp3400c_reset(&client_template)) {
1247 dprintk("msp3400: no chip found\n");
1251 if (NULL == (c = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
1253 memcpy(c,&client_template,sizeof(struct i2c_client));
1254 if (NULL == (msp = kmalloc(sizeof(struct msp3400c),GFP_KERNEL))) {
1259 memset(msp,0,sizeof(struct msp3400c));
1263 msp->treble = 32768;
1266 for (i = 0; i < DFP_COUNT; i++)
1267 msp->dfp_regs[i] = -1;
1269 i2c_set_clientdata(c, msp);
1270 init_waitqueue_head(&msp->wq);
1272 if (-1 == msp3400c_reset(c)) {
1275 dprintk("msp3400: no chip found\n");
1279 msp->rev1 = msp3400c_read(c, I2C_MSP3400C_DFP, 0x1e);
1280 if (-1 != msp->rev1)
1281 msp->rev2 = msp3400c_read(c, I2C_MSP3400C_DFP, 0x1f);
1282 if ((-1 == msp->rev1) || (0 == msp->rev1 && 0 == msp->rev2)) {
1285 printk("msp3400: error while reading chip version\n");
1290 /* this will turn on a 1kHz beep - might be useful for debugging... */
1291 msp3400c_write(c,I2C_MSP3400C_DFP, 0x0014, 0x1040);
1293 msp3400c_setvolume(c,msp->muted,msp->left,msp->right);
1295 snprintf(c->name, sizeof(c->name), "MSP34%02d%c-%c%d",
1296 (msp->rev2>>8)&0xff, (msp->rev1&0xff)+'@',
1297 ((msp->rev1>>8)&0xff)+'@', msp->rev2&0x1f);
1301 msp->simple = HAVE_SIMPLE(msp);
1303 /* use insmod option */
1304 msp->simple = simple;
1307 /* timer for stereo checking */
1308 init_timer(&msp->wake_stereo);
1309 msp->wake_stereo.function = msp3400c_stereo_wake;
1310 msp->wake_stereo.data = (unsigned long)msp;
1312 /* hello world :-) */
1313 printk(KERN_INFO "msp34xx: init: chip=%s",i2c_clientname(c));
1314 if (HAVE_NICAM(msp))
1316 if (HAVE_SIMPLE(msp))
1318 if (HAVE_RADIO(msp))
1322 /* startup control thread */
1323 init_completion(&msp->texit);
1324 msp->tpid = kernel_thread(msp->simple ? msp3410d_thread : msp3400c_thread,
1327 printk(KERN_WARNING "msp34xx: kernel_thread() failed\n");
1328 wake_up_interruptible(&msp->wq);
1331 i2c_attach_client(c);
1335 static int msp_detach(struct i2c_client *client)
1337 struct msp3400c *msp = i2c_get_clientdata(client);
1339 /* shutdown control thread */
1340 del_timer_sync(&msp->wake_stereo);
1341 if (msp->tpid >= 0) {
1343 wake_up_interruptible(&msp->wq);
1344 wait_for_completion(&msp->texit);
1346 msp3400c_reset(client);
1348 i2c_detach_client(client);
1354 static int msp_probe(struct i2c_adapter *adap)
1356 #ifdef I2C_ADAP_CLASS_TV_ANALOG
1357 if (adap->class & I2C_ADAP_CLASS_TV_ANALOG)
1358 return i2c_probe(adap, &addr_data, msp_attach);
1361 case I2C_ALGO_BIT | I2C_HW_SMBUS_VOODOO3:
1362 case I2C_ALGO_BIT | I2C_HW_B_BT848:
1363 //case I2C_ALGO_SAA7134:
1364 return i2c_probe(adap, &addr_data, msp_attach);
1371 static void msp_wake_thread(struct i2c_client *client)
1373 struct msp3400c *msp = i2c_get_clientdata(client);
1375 msp3400c_setvolume(client,msp->muted,0,0);
1376 msp->watch_stereo=0;
1377 del_timer(&msp->wake_stereo);
1380 wake_up_interruptible(&msp->wq);
1383 static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
1385 struct msp3400c *msp = i2c_get_clientdata(client);
1391 case AUDC_SET_INPUT:
1392 dprintk(KERN_DEBUG "msp34xx: AUDC_SET_INPUT(%d)\n",*sarg);
1393 if (*sarg == msp->input)
1398 /* Hauppauge uses IN2 for the radio */
1399 msp->mode = MSP_MODE_FM_RADIO;
1402 case AUDIO_EXTERN_1:
1403 /* IN1 is often used for external input ... */
1404 msp->mode = MSP_MODE_EXTERN;
1407 case AUDIO_EXTERN_2:
1408 /* ... sometimes it is IN2 through ;) */
1409 msp->mode = MSP_MODE_EXTERN;
1414 msp_wake_thread(client);
1417 if (*sarg & AUDIO_MUTE)
1418 msp3400c_set_scart(client,SCART_MUTE,0);
1422 msp->stereo = VIDEO_SOUND_STEREO;
1423 msp3400c_set_scart(client,scart,0);
1424 msp3400c_write(client,I2C_MSP3400C_DFP,0x000d,0x1900);
1425 msp3400c_setstereo(client,msp->stereo);
1431 case AUDC_SET_RADIO:
1432 dprintk(KERN_DEBUG "msp34xx: AUDC_SET_RADIO\n");
1433 msp->norm = VIDEO_MODE_RADIO;
1434 msp->watch_stereo=0;
1435 del_timer(&msp->wake_stereo);
1436 dprintk(KERN_DEBUG "msp34xx: switching to radio mode\n");
1438 /* the thread will do for us */
1439 msp_wake_thread(client);
1441 /* set msp3400 to FM radio mode */
1442 msp3400c_setmode(client,MSP_MODE_FM_RADIO);
1443 msp3400c_setcarrier(client, MSP_CARRIER(10.7),MSP_CARRIER(10.7));
1444 msp3400c_setvolume(client,msp->muted,msp->left,msp->right);
1451 /* work-in-progress: hook to control the DFP registers */
1452 case MSP_SET_DFPREG:
1454 struct msp_dfpreg *r = arg;
1457 if (r->reg < 0 || r->reg >= DFP_COUNT)
1459 for (i = 0; i < ARRAY_SIZE(bl_dfp); i++)
1460 if (r->reg == bl_dfp[i])
1462 msp->dfp_regs[r->reg] = r->value;
1463 msp3400c_write(client,I2C_MSP3400C_DFP,r->reg,r->value);
1466 case MSP_GET_DFPREG:
1468 struct msp_dfpreg *r = arg;
1470 if (r->reg < 0 || r->reg >= DFP_COUNT)
1472 r->value = msp3400c_read(client,I2C_MSP3400C_DFP,r->reg);
1477 /* --- v4l ioctls --- */
1478 /* take care: bttv does userspace copying, we'll get a
1479 kernel pointer here... */
1482 struct video_audio *va = arg;
1484 dprintk(KERN_DEBUG "msp34xx: VIDIOCGAUDIO\n");
1485 va->flags |= VIDEO_AUDIO_VOLUME |
1487 VIDEO_AUDIO_TREBLE |
1488 VIDEO_AUDIO_MUTABLE;
1490 va->flags |= VIDEO_AUDIO_MUTE;
1491 va->volume=max(msp->left,msp->right);
1493 if (0 == va->volume) {
1494 va->balance = 32768;
1496 va->balance = (32768 * min(msp->left,msp->right))
1498 va->balance = (msp->left<msp->right) ?
1499 (65535 - va->balance) : va->balance;
1501 va->bass = msp->bass;
1502 va->treble = msp->treble;
1504 if (msp->norm != VIDEO_MODE_RADIO) {
1505 autodetect_stereo(client);
1506 va->mode = msp->stereo;
1512 struct video_audio *va = arg;
1514 dprintk(KERN_DEBUG "msp34xx: VIDIOCSAUDIO\n");
1515 msp->muted = (va->flags & VIDEO_AUDIO_MUTE);
1516 msp->left = (min(65536 - va->balance,32768) *
1517 va->volume) / 32768;
1518 msp->right = (min(va->balance,(__u16)32768) *
1519 va->volume) / 32768;
1520 msp->bass = va->bass;
1521 msp->treble = va->treble;
1522 msp3400c_setvolume(client,msp->muted,msp->left,msp->right);
1523 msp3400c_setbass(client,msp->bass);
1524 msp3400c_settreble(client,msp->treble);
1526 if (va->mode != 0 && msp->norm != VIDEO_MODE_RADIO) {
1527 msp->watch_stereo=0;
1528 del_timer(&msp->wake_stereo);
1529 msp->stereo = va->mode & 0x0f;
1530 msp3400c_setstereo(client,va->mode & 0x0f);
1536 struct video_channel *vc = arg;
1538 dprintk(KERN_DEBUG "msp34xx: VIDIOCSCHAN (norm=%d)\n",vc->norm);
1539 msp->norm = vc->norm;
1544 /* new channel -- kick audio carrier scan */
1545 dprintk(KERN_DEBUG "msp34xx: VIDIOCSFREQ\n");
1546 msp_wake_thread(client);
1557 /* ----------------------------------------------------------------------- */
1559 static int msp3400_init_module(void)
1561 i2c_add_driver(&driver);
1565 static void msp3400_cleanup_module(void)
1567 i2c_del_driver(&driver);
1570 module_init(msp3400_init_module);
1571 module_exit(msp3400_cleanup_module);
1574 * Overrides for Emacs so that we follow Linus's tabbing style.
1575 * ---------------------------------------------------------------------------