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/moduleparam.h>
40 #include <linux/kernel.h>
41 #include <linux/sched.h>
42 #include <linux/string.h>
43 #include <linux/timer.h>
44 #include <linux/delay.h>
45 #include <linux/errno.h>
46 #include <linux/slab.h>
47 #include <linux/i2c.h>
48 #include <linux/init.h>
49 #include <linux/smp_lock.h>
50 #include <linux/kthread.h>
51 #include <linux/suspend.h>
52 #include <asm/semaphore.h>
53 #include <asm/pgtable.h>
55 #include <linux/videodev.h>
56 #include <media/audiochip.h>
57 #include <media/v4l2-common.h>
60 /* ---------------------------------------------------------------------- */
62 MODULE_DESCRIPTION("device driver for msp34xx TV sound processor");
63 MODULE_AUTHOR("Gerd Knorr");
64 MODULE_LICENSE("GPL");
66 #define OPMODE_AUTO -1
67 #define OPMODE_MANUAL 0
68 #define OPMODE_AUTODETECT 1 /* use autodetect (>= msp3410 only) */
69 #define OPMODE_AUTOSELECT 2 /* use autodetect & autoselect (>= msp34xxG) */
71 /* module parameters */
72 static int opmode = OPMODE_AUTO;
73 static int debug = 0; /* debug output */
74 static int once = 0; /* no continous stereo monitoring */
75 static int amsound = 0; /* hard-wire AM sound at 6.5 Hz (france),
76 the autoscan seems work well only with FM... */
77 static int standard = 1; /* Override auto detect of audio standard, if needed. */
80 static int stereo_threshold = 0x190; /* a2 threshold for stereo/bilingual
81 (msp34xxg only) 0x00a0-0x03c0 */
84 module_param(opmode, int, 0444);
87 module_param(once, int, 0644);
88 module_param(debug, int, 0644);
89 module_param(stereo_threshold, int, 0644);
90 module_param(standard, int, 0644);
91 module_param(amsound, int, 0644);
92 module_param(dolby, int, 0644);
94 MODULE_PARM_DESC(opmode, "Forces a MSP3400 opmode. 0=Manual, 1=Autodetect, 2=Autodetect and autoselect");
95 MODULE_PARM_DESC(once, "No continuous stereo monitoring");
96 MODULE_PARM_DESC(debug, "Enable debug messages");
97 MODULE_PARM_DESC(stereo_threshold, "Sets signal threshold to activate stereo");
98 MODULE_PARM_DESC(standard, "Specify audio standard: 32 = NTSC, 64 = radio, Default: Autodetect");
99 MODULE_PARM_DESC(amsound, "Hardwire AM sound at 6.5Hz (France), FM can autoscan");
100 MODULE_PARM_DESC(dolby, "Activates Dolby processsing");
102 /* ---------------------------------------------------------------------- */
104 #define msp3400_err(fmt, arg...) do { \
105 printk(KERN_ERR "%s %d-%04x: " fmt, client->driver->driver.name, \
106 i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)
107 #define msp3400_warn(fmt, arg...) do { \
108 printk(KERN_WARNING "%s %d-%04x: " fmt, client->driver->driver.name, \
109 i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)
110 #define msp3400_info(fmt, arg...) do { \
111 printk(KERN_INFO "%s %d-%04x: " fmt, client->driver->driver.name, \
112 i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)
115 #define msp_dbg1(fmt, arg...) \
118 printk(KERN_INFO "%s debug %d-%04x: " fmt, \
119 client->driver->driver.name, \
120 i2c_adapter_id(client->adapter), client->addr , ## arg); \
124 #define msp_dbg2(fmt, arg...) \
127 printk(KERN_INFO "%s debug %d-%04x: " fmt, \
128 client->driver->driver.name, \
129 i2c_adapter_id(client->adapter), client->addr , ## arg); \
132 /* level 3 debug. Use with care. */
133 #define msp_dbg3(fmt, arg...) \
136 printk(KERN_INFO "%s debug %d-%04x: " fmt, \
137 client->driver->driver.name, \
138 i2c_adapter_id(client->adapter), client->addr , ## arg); \
141 /* control subaddress */
142 #define I2C_MSP_CONTROL 0x00
143 /* demodulator unit subaddress */
144 #define I2C_MSP_DEM 0x10
145 /* DSP unit subaddress */
146 #define I2C_MSP_DSP 0x12
148 /* Addresses to scan */
149 static unsigned short normal_i2c[] = { 0x80 >> 1, 0x88 >> 1, I2C_CLIENT_END };
155 #define DFP_COUNT 0x41
156 static const int bl_dfp[] = {
157 0x00, 0x01, 0x02, 0x03, 0x06, 0x08, 0x09, 0x0a,
158 0x0b, 0x0d, 0x0e, 0x10
161 #define HAVE_NICAM(state) (((state->rev2>>8) & 0xff) != 00)
162 #define HAVE_RADIO(state) ((state->rev1 & 0x0f) >= 'G'-'@')
175 int main, second; /* sound carrier */
177 int source; /* see msp34xxg_set_source */
184 int left, right; /* volume */
187 /* shadow register set */
188 int dfp_regs[DFP_COUNT];
191 struct task_struct *kthread;
192 wait_queue_head_t wq;
197 #define VIDEO_MODE_RADIO 16 /* norm magic for radio mode */
200 /* ----------------------------------------------------------------------- */
201 /* functions for talking to the MSP3400C Sound processor */
203 static int msp_reset(struct i2c_client *client)
205 /* reset and read revision code */
206 static u8 reset_off[3] = { I2C_MSP_CONTROL, 0x80, 0x00 };
207 static u8 reset_on[3] = { I2C_MSP_CONTROL, 0x00, 0x00 };
208 static u8 write[3] = { I2C_MSP_DSP + 1, 0x00, 0x1e };
210 struct i2c_msg reset[2] = {
211 { client->addr, I2C_M_IGNORE_NAK, 3, reset_off },
212 { client->addr, I2C_M_IGNORE_NAK, 3, reset_on },
214 struct i2c_msg test[2] = {
215 { client->addr, 0, 3, write },
216 { client->addr, I2C_M_RD, 2, read },
219 msp_dbg3("msp_reset\n");
220 if (1 != i2c_transfer(client->adapter, &reset[0], 1) ||
221 1 != i2c_transfer(client->adapter, &reset[1], 1) ||
222 2 != i2c_transfer(client->adapter, test, 2)) {
223 msp_err("chip reset failed\n");
229 static int msp_read(struct i2c_client *client, int dev, int addr)
234 struct i2c_msg msgs[2] = {
235 { client->addr, 0, 3, write },
236 { client->addr, I2C_M_RD, 2, read }
240 write[1] = addr >> 8;
241 write[2] = addr & 0xff;
243 for (err = 0; err < 3; err++) {
244 if (2 == i2c_transfer(client->adapter, msgs, 2))
246 msp_warn("I/O error #%d (read 0x%02x/0x%02x)\n", err,
248 current->state = TASK_INTERRUPTIBLE;
249 schedule_timeout(msecs_to_jiffies(10));
252 msp_warn("giving up, resetting chip. Sound will go off, sorry folks :-|\n");
256 retval = read[0] << 8 | read[1];
257 msp_dbg3("msp_read(0x%x, 0x%x): 0x%x\n", dev, addr, retval);
261 static inline int msp_read_dem(struct i2c_client *client, int addr)
263 return msp_read(client, I2C_MSP_DEM, addr);
266 static inline int msp_read_dsp(struct i2c_client *client, int addr)
268 return msp_read(client, I2C_MSP_DSP, addr);
271 static int msp_write(struct i2c_client *client, int dev, int addr, int val)
277 buffer[1] = addr >> 8;
278 buffer[2] = addr & 0xff;
279 buffer[3] = val >> 8;
280 buffer[4] = val & 0xff;
282 msp_dbg3("msp_write(0x%x, 0x%x, 0x%x)\n", dev, addr, val);
283 for (err = 0; err < 3; err++) {
284 if (5 == i2c_master_send(client, buffer, 5))
286 msp_warn("I/O error #%d (write 0x%02x/0x%02x)\n", err,
288 current->state = TASK_INTERRUPTIBLE;
289 schedule_timeout(msecs_to_jiffies(10));
292 msp_warn("giving up, resetting chip. Sound will go off, sorry folks :-|\n");
299 static inline int msp_write_dem(struct i2c_client *client, int addr, int val)
301 return msp_write(client, I2C_MSP_DEM, addr, val);
304 static inline int msp_write_dsp(struct i2c_client *client, int addr, int val)
306 return msp_write(client, I2C_MSP_DSP, addr, val);
309 /* ------------------------------------------------------------------------ */
311 /* This macro is allowed for *constants* only, gcc must calculate it
312 at compile time. Remember -- no floats in kernel mode */
313 #define MSP_CARRIER(freq) ((int)((float)(freq / 18.432) * (1 << 24)))
315 #define MSP_MODE_AM_DETECT 0
316 #define MSP_MODE_FM_RADIO 2
317 #define MSP_MODE_FM_TERRA 3
318 #define MSP_MODE_FM_SAT 4
319 #define MSP_MODE_FM_NICAM1 5
320 #define MSP_MODE_FM_NICAM2 6
321 #define MSP_MODE_AM_NICAM 7
322 #define MSP_MODE_BTSC 8
323 #define MSP_MODE_EXTERN 9
325 static struct MSP_INIT_DATA_DEM {
334 } msp_init_data[] = {
335 { /* AM (for carrier detect / msp3400) */
336 {75, 19, 36, 35, 39, 40},
337 {75, 19, 36, 35, 39, 40},
338 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
339 0x00d0, 0x0500, 0x0020, 0x3000
340 },{ /* AM (for carrier detect / msp3410) */
341 {-1, -1, -8, 2, 59, 126},
342 {-1, -1, -8, 2, 59, 126},
343 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
344 0x00d0, 0x0100, 0x0020, 0x3000
346 {-8, -8, 4, 6, 78, 107},
347 {-8, -8, 4, 6, 78, 107},
348 MSP_CARRIER(10.7), MSP_CARRIER(10.7),
349 0x00d0, 0x0480, 0x0020, 0x3000
350 },{ /* Terrestial FM-mono + FM-stereo */
351 {3, 18, 27, 48, 66, 72},
352 {3, 18, 27, 48, 66, 72},
353 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
354 0x00d0, 0x0480, 0x0030, 0x3000
355 },{ /* Sat FM-mono */
356 { 1, 9, 14, 24, 33, 37},
357 { 3, 18, 27, 48, 66, 72},
358 MSP_CARRIER(6.5), MSP_CARRIER(6.5),
359 0x00c6, 0x0480, 0x0000, 0x3000
360 },{ /* NICAM/FM -- B/G (5.5/5.85), D/K (6.5/5.85) */
361 {-2, -8, -10, 10, 50, 86},
362 {3, 18, 27, 48, 66, 72},
363 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
364 0x00d0, 0x0040, 0x0120, 0x3000
365 },{ /* NICAM/FM -- I (6.0/6.552) */
366 {2, 4, -6, -4, 40, 94},
367 {3, 18, 27, 48, 66, 72},
368 MSP_CARRIER(6.0), MSP_CARRIER(6.0),
369 0x00d0, 0x0040, 0x0120, 0x3000
370 },{ /* NICAM/AM -- L (6.5/5.85) */
371 {-2, -8, -10, 10, 50, 86},
372 {-4, -12, -9, 23, 79, 126},
373 MSP_CARRIER(6.5), MSP_CARRIER(6.5),
374 0x00c6, 0x0140, 0x0120, 0x7c03
378 struct CARRIER_DETECT {
383 static struct CARRIER_DETECT carrier_detect_main[] = {
385 { MSP_CARRIER(4.5), "4.5 NTSC" },
386 { MSP_CARRIER(5.5), "5.5 PAL B/G" },
387 { MSP_CARRIER(6.0), "6.0 PAL I" },
388 { MSP_CARRIER(6.5), "6.5 PAL D/K + SAT + SECAM" }
391 static struct CARRIER_DETECT carrier_detect_55[] = {
393 { MSP_CARRIER(5.7421875), "5.742 PAL B/G FM-stereo" },
394 { MSP_CARRIER(5.85), "5.85 PAL B/G NICAM" }
397 static struct CARRIER_DETECT carrier_detect_65[] = {
398 /* PAL SAT / SECAM */
399 { MSP_CARRIER(5.85), "5.85 PAL D/K + SECAM NICAM" },
400 { MSP_CARRIER(6.2578125), "6.25 PAL D/K1 FM-stereo" },
401 { MSP_CARRIER(6.7421875), "6.74 PAL D/K2 FM-stereo" },
402 { MSP_CARRIER(7.02), "7.02 PAL SAT FM-stereo s/b" },
403 { MSP_CARRIER(7.20), "7.20 PAL SAT FM-stereo s" },
404 { MSP_CARRIER(7.38), "7.38 PAL SAT FM-stereo b" },
407 #define CARRIER_COUNT(x) (sizeof(x)/sizeof(struct CARRIER_DETECT))
409 /* ----------------------------------------------------------------------- *
410 * bits 9 8 5 - SCART DSP input Select:
411 * 0 0 0 - SCART 1 to DSP input (reset position)
412 * 0 1 0 - MONO to DSP input
413 * 1 0 0 - SCART 2 to DSP input
414 * 1 1 1 - Mute DSP input
416 * bits 11 10 6 - SCART 1 Output Select:
417 * 0 0 0 - undefined (reset position)
418 * 0 1 0 - SCART 2 Input to SCART 1 Output (for devices with 2 SCARTS)
419 * 1 0 0 - MONO input to SCART 1 Output
420 * 1 1 0 - SCART 1 DA to SCART 1 Output
421 * 0 0 1 - SCART 2 DA to SCART 1 Output
422 * 0 1 1 - SCART 1 Input to SCART 1 Output
423 * 1 1 1 - Mute SCART 1 Output
425 * bits 13 12 7 - SCART 2 Output Select (for devices with 2 Output SCART):
426 * 0 0 0 - SCART 1 DA to SCART 2 Output (reset position)
427 * 0 1 0 - SCART 1 Input to SCART 2 Output
428 * 1 0 0 - MONO input to SCART 2 Output
429 * 0 0 1 - SCART 2 DA to SCART 2 Output
430 * 0 1 1 - SCART 2 Input to SCART 2 Output
431 * 1 1 0 - Mute SCART 2 Output
433 * Bits 4 to 0 should be zero.
434 * ----------------------------------------------------------------------- */
436 static int scarts[3][9] = {
437 /* MASK IN1 IN2 IN1_DA IN2_DA IN3 IN4 MONO MUTE */
438 /* SCART DSP Input select */
439 { 0x0320, 0x0000, 0x0200, -1, -1, 0x0300, 0x0020, 0x0100, 0x0320 },
440 /* SCART1 Output select */
441 { 0x0c40, 0x0440, 0x0400, 0x0c00, 0x0040, 0x0000, 0x0840, 0x0800, 0x0c40 },
442 /* SCART2 Output select */
443 { 0x3080, 0x1000, 0x1080, 0x0000, 0x0080, 0x2080, 0x3080, 0x2000, 0x3000 },
446 static char *scart_names[] = {
447 "mask", "in1", "in2", "in1 da", "in2 da", "in3", "in4", "mono", "mute"
450 static void msp_set_scart(struct i2c_client *client, int in, int out)
452 struct msp_state *state = i2c_get_clientdata(client);
456 if (in >= 1 && in <= 8 && out >= 0 && out <= 2) {
457 if (-1 == scarts[out][in])
460 state->acb &= ~scarts[out][SCART_MASK];
461 state->acb |= scarts[out][in];
463 state->acb = 0xf60; /* Mute Input and SCART 1 Output */
465 msp_dbg1("scart switch: %s => %d (ACB=0x%04x)\n",
466 scart_names[in], out, state->acb);
467 msp_write_dsp(client, 0x13, state->acb);
469 /* Sets I2S speed 0 = 1.024 Mbps, 1 = 2.048 Mbps */
470 msp_write_dem(client, 0x40, state->i2s_mode);
473 /* ------------------------------------------------------------------------ */
475 static void msp3400c_setcarrier(struct i2c_client *client, int cdo1, int cdo2)
477 msp_write_dem(client, 0x0093, cdo1 & 0xfff);
478 msp_write_dem(client, 0x009b, cdo1 >> 12);
479 msp_write_dem(client, 0x00a3, cdo2 & 0xfff);
480 msp_write_dem(client, 0x00ab, cdo2 >> 12);
481 msp_write_dem(client, 0x0056, 0); /*LOAD_REG_1/2*/
484 static void msp_set_volume(struct i2c_client *client,
485 int muted, int left, int right)
487 int vol = 0, val = 0, balance = 0;
490 vol = (left > right) ? left : right;
491 val = (vol * 0x7f / 65535) << 8;
494 balance = ((right - left) * 127) / vol;
497 msp_dbg1("setvolume: mute=%s %d:%d v=0x%02x b=0x%02x\n",
498 muted ? "on" : "off", left, right, val >> 8, balance);
499 msp_write_dsp(client, 0x0000, val); /* loudspeaker */
500 msp_write_dsp(client, 0x0006, val); /* headphones */
501 msp_write_dsp(client, 0x0007,
502 muted ? 0x1 : (val | 0x1));
503 msp_write_dsp(client, 0x0001, balance << 8);
506 static void msp_set_bass(struct i2c_client *client, int bass)
508 int val = ((bass-32768) * 0x60 / 65535) << 8;
510 msp_dbg1("setbass: %d 0x%02x\n", bass, val >> 8);
511 msp_write_dsp(client, 0x0002, val); /* loudspeaker */
514 static void msp_set_treble(struct i2c_client *client, int treble)
516 int val = ((treble-32768) * 0x60 / 65535) << 8;
518 msp_dbg1("settreble: %d 0x%02x\n",treble, val>>8);
519 msp_write_dsp(client, 0x0003, val); /* loudspeaker */
522 static void msp3400c_setmode(struct i2c_client *client, int type)
524 struct msp_state *state = i2c_get_clientdata(client);
527 msp_dbg1("setmode: %d\n",type);
529 state->audmode = V4L2_TUNER_MODE_MONO;
530 state->rxsubchans = V4L2_TUNER_SUB_MONO;
532 msp_write_dem(client, 0x00bb, /* ad_cv */
533 msp_init_data[type].ad_cv);
535 for (i = 5; i >= 0; i--) /* fir 1 */
536 msp_write_dem(client, 0x0001,
537 msp_init_data[type].fir1[i]);
539 msp_write_dem(client, 0x0005, 0x0004); /* fir 2 */
540 msp_write_dem(client, 0x0005, 0x0040);
541 msp_write_dem(client, 0x0005, 0x0000);
542 for (i = 5; i >= 0; i--)
543 msp_write_dem(client, 0x0005,
544 msp_init_data[type].fir2[i]);
546 msp_write_dem(client, 0x0083, /* MODE_REG */
547 msp_init_data[type].mode_reg);
549 msp3400c_setcarrier(client, msp_init_data[type].cdo1,
550 msp_init_data[type].cdo2);
552 msp_write_dem(client, 0x0056, 0); /*LOAD_REG_1/2*/
555 msp_write_dsp(client, 0x0008,
557 msp_write_dsp(client, 0x0009,
559 msp_write_dsp(client, 0x000b,
560 msp_init_data[type].dfp_src);
562 msp_write_dsp(client, 0x0008,
563 msp_init_data[type].dfp_src);
564 msp_write_dsp(client, 0x0009,
565 msp_init_data[type].dfp_src);
566 msp_write_dsp(client, 0x000b,
567 msp_init_data[type].dfp_src);
569 msp_write_dsp(client, 0x000a,
570 msp_init_data[type].dfp_src);
571 msp_write_dsp(client, 0x000e,
572 msp_init_data[type].dfp_matrix);
574 if (HAVE_NICAM(state)) {
576 msp_write_dsp(client, 0x0010, 0x5a00); /* was: 0x3000 */
580 /* given a bitmask of VIDEO_SOUND_XXX returns the "best" in the bitmask */
581 static int msp3400c_best_video_sound(int rxsubchans)
583 if (rxsubchans & V4L2_TUNER_SUB_STEREO)
584 return V4L2_TUNER_MODE_STEREO;
585 if (rxsubchans & V4L2_TUNER_SUB_LANG1)
586 return V4L2_TUNER_MODE_LANG1;
587 if (rxsubchans & V4L2_TUNER_SUB_LANG2)
588 return V4L2_TUNER_MODE_LANG2;
589 return V4L2_TUNER_MODE_MONO;
592 /* turn on/off nicam + stereo */
593 static void msp3400c_setstereo(struct i2c_client *client, int mode)
595 static char *strmode[] = { "0", "mono", "stereo", "3",
596 "lang1", "5", "6", "7", "lang2"
598 struct msp_state *state = i2c_get_clientdata(client);
599 int nicam = 0; /* channel source: FM/AM or nicam */
602 if (state->opmode == OPMODE_AUTOSELECT) {
603 /* this method would break everything, let's make sure
606 msp_dbg1("setstereo called with mode=%d instead of set_source (ignored)\n",
611 /* switch demodulator */
612 switch (state->mode) {
613 case MSP_MODE_FM_TERRA:
614 msp_dbg1("FM setstereo: %s\n", strmode[mode]);
615 msp3400c_setcarrier(client,state->second,state->main);
617 case V4L2_TUNER_MODE_STEREO:
618 msp_write_dsp(client, 0x000e, 0x3001);
620 case V4L2_TUNER_MODE_MONO:
621 case V4L2_TUNER_MODE_LANG1:
622 case V4L2_TUNER_MODE_LANG2:
623 msp_write_dsp(client, 0x000e, 0x3000);
627 case MSP_MODE_FM_SAT:
628 msp_dbg1("SAT setstereo: %s\n", strmode[mode]);
630 case V4L2_TUNER_MODE_MONO:
631 msp3400c_setcarrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
633 case V4L2_TUNER_MODE_STEREO:
634 msp3400c_setcarrier(client, MSP_CARRIER(7.2), MSP_CARRIER(7.02));
636 case V4L2_TUNER_MODE_LANG1:
637 msp3400c_setcarrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
639 case V4L2_TUNER_MODE_LANG2:
640 msp3400c_setcarrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
644 case MSP_MODE_FM_NICAM1:
645 case MSP_MODE_FM_NICAM2:
646 case MSP_MODE_AM_NICAM:
647 msp_dbg1("NICAM setstereo: %s\n",strmode[mode]);
648 msp3400c_setcarrier(client,state->second,state->main);
653 msp_dbg1("BTSC setstereo: %s\n",strmode[mode]);
656 case MSP_MODE_EXTERN:
657 msp_dbg1("extern setstereo: %s\n",strmode[mode]);
660 case MSP_MODE_FM_RADIO:
661 msp_dbg1("FM-Radio setstereo: %s\n",strmode[mode]);
664 msp_dbg1("mono setstereo\n");
669 switch (msp3400c_best_video_sound(mode)) {
670 case V4L2_TUNER_MODE_STEREO:
671 src = 0x0020 | nicam;
673 case V4L2_TUNER_MODE_MONO:
674 if (state->mode == MSP_MODE_AM_NICAM) {
675 msp_dbg1("switching to AM mono\n");
676 /* AM mono decoding is handled by tuner, not MSP chip */
677 /* SCART switching control register */
678 msp_set_scart(client,SCART_MONO,0);
682 case V4L2_TUNER_MODE_LANG1:
683 src = 0x0000 | nicam;
685 case V4L2_TUNER_MODE_LANG2:
686 src = 0x0010 | nicam;
689 msp_dbg1("setstereo final source/matrix = 0x%x\n", src);
692 msp_write_dsp(client, 0x0008,0x0520);
693 msp_write_dsp(client, 0x0009,0x0620);
694 msp_write_dsp(client, 0x000a,src);
695 msp_write_dsp(client, 0x000b,src);
697 msp_write_dsp(client, 0x0008,src);
698 msp_write_dsp(client, 0x0009,src);
699 msp_write_dsp(client, 0x000a,src);
700 msp_write_dsp(client, 0x000b,src);
705 msp3400c_print_mode(struct i2c_client *client)
707 struct msp_state *state = i2c_get_clientdata(client);
709 if (state->main == state->second) {
710 msp_dbg1("mono sound carrier: %d.%03d MHz\n",
711 state->main/910000,(state->main/910)%1000);
713 msp_dbg1("main sound carrier: %d.%03d MHz\n",
714 state->main/910000,(state->main/910)%1000);
716 if (state->mode == MSP_MODE_FM_NICAM1 || state->mode == MSP_MODE_FM_NICAM2)
717 msp_dbg1("NICAM/FM carrier : %d.%03d MHz\n",
718 state->second/910000,(state->second/910)%1000);
719 if (state->mode == MSP_MODE_AM_NICAM)
720 msp_dbg1("NICAM/AM carrier : %d.%03d MHz\n",
721 state->second/910000,(state->second/910)%1000);
722 if (state->mode == MSP_MODE_FM_TERRA &&
723 state->main != state->second) {
724 msp_dbg1("FM-stereo carrier : %d.%03d MHz\n",
725 state->second/910000,(state->second/910)%1000);
729 static void msp3400c_restore_dfp(struct i2c_client *client)
731 struct msp_state *state = i2c_get_clientdata(client);
734 for (i = 0; i < DFP_COUNT; i++) {
735 if (-1 == state->dfp_regs[i])
737 msp_write_dsp(client, i, state->dfp_regs[i]);
741 /* if the dfp_regs is set, set what's in there. Otherwise, set the default value */
742 static int msp_write_dfp_with_default(struct i2c_client *client,
743 int addr, int default_value)
745 struct msp_state *state = i2c_get_clientdata(client);
746 int value = default_value;
747 if (addr < DFP_COUNT && -1 != state->dfp_regs[addr])
748 value = state->dfp_regs[addr];
749 return msp_write_dsp(client, addr, value);
752 /* ----------------------------------------------------------------------- */
754 struct REGISTER_DUMP {
759 struct REGISTER_DUMP d1[] = {
760 {0x007e, "autodetect"},
761 {0x0023, "C_AD_BITS "},
762 {0x0038, "ADD_BITS "},
763 {0x003e, "CIB_BITS "},
764 {0x0057, "ERROR_RATE"},
767 static int autodetect_stereo(struct i2c_client *client)
769 struct msp_state *state = i2c_get_clientdata(client);
771 int rxsubchans = state->rxsubchans;
772 int newnicam = state->nicam_on;
775 switch (state->mode) {
776 case MSP_MODE_FM_TERRA:
777 val = msp_read_dsp(client, 0x18);
780 msp_dbg2("stereo detect register: %d\n",val);
782 rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
783 } else if (val < -4096) {
784 rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
786 rxsubchans = V4L2_TUNER_SUB_MONO;
790 case MSP_MODE_FM_NICAM1:
791 case MSP_MODE_FM_NICAM2:
792 case MSP_MODE_AM_NICAM:
793 val = msp_read_dem(client, 0x23);
794 msp_dbg2("nicam sync=%d, mode=%d\n",
795 val & 1, (val & 0x1e) >> 1);
799 switch ((val & 0x1e) >> 1) {
802 rxsubchans = V4L2_TUNER_SUB_STEREO;
806 rxsubchans = V4L2_TUNER_SUB_MONO
807 | V4L2_TUNER_SUB_LANG1;
811 rxsubchans = V4L2_TUNER_SUB_MONO
812 | V4L2_TUNER_SUB_LANG1
813 | V4L2_TUNER_SUB_LANG2;
816 rxsubchans = V4L2_TUNER_SUB_MONO;
822 rxsubchans = V4L2_TUNER_SUB_MONO;
826 val = msp_read_dem(client, 0x200);
827 msp_dbg2("status=0x%x (pri=%s, sec=%s, %s%s%s)\n",
829 (val & 0x0002) ? "no" : "yes",
830 (val & 0x0004) ? "no" : "yes",
831 (val & 0x0040) ? "stereo" : "mono",
832 (val & 0x0080) ? ", nicam 2nd mono" : "",
833 (val & 0x0100) ? ", bilingual/SAP" : "");
834 rxsubchans = V4L2_TUNER_SUB_MONO;
835 if (val & 0x0040) rxsubchans |= V4L2_TUNER_SUB_STEREO;
836 if (val & 0x0100) rxsubchans |= V4L2_TUNER_SUB_LANG1;
839 if (rxsubchans != state->rxsubchans) {
841 msp_dbg1("watch: rxsubchans %d => %d\n",
842 state->rxsubchans,rxsubchans);
843 state->rxsubchans = rxsubchans;
845 if (newnicam != state->nicam_on) {
847 msp_dbg1("watch: nicam %d => %d\n",
848 state->nicam_on,newnicam);
849 state->nicam_on = newnicam;
855 * A kernel thread for msp3400 control -- we don't want to block the
856 * in the ioctl while doing the sound carrier & stereo detect
859 static int msp_sleep(struct msp_state *state, int timeout)
861 DECLARE_WAITQUEUE(wait, current);
863 add_wait_queue(&state->wq, &wait);
864 if (!kthread_should_stop()) {
866 set_current_state(TASK_INTERRUPTIBLE);
869 schedule_timeout_interruptible
870 (msecs_to_jiffies(timeout));
874 remove_wait_queue(&state->wq, &wait);
876 return state->restart;
879 /* stereo/multilang monitoring */
880 static void watch_stereo(struct i2c_client *client)
882 struct msp_state *state = i2c_get_clientdata(client);
884 if (autodetect_stereo(client)) {
885 if (state->stereo & V4L2_TUNER_MODE_STEREO)
886 msp3400c_setstereo(client, V4L2_TUNER_MODE_STEREO);
887 else if (state->stereo & VIDEO_SOUND_LANG1)
888 msp3400c_setstereo(client, V4L2_TUNER_MODE_LANG1);
890 msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
894 state->watch_stereo = 0;
898 static int msp3400c_thread(void *data)
900 struct i2c_client *client = data;
901 struct msp_state *state = i2c_get_clientdata(client);
902 struct CARRIER_DETECT *cd;
903 int count, max1,max2,val1,val2, val,this;
906 msp_info("msp3400 daemon started\n");
908 msp_dbg2("msp3400 thread: sleep\n");
909 msp_sleep(state, -1);
910 msp_dbg2("msp3400 thread: wakeup\n");
913 msp_dbg1("thread: restart scan\n");
915 if (kthread_should_stop())
918 if (VIDEO_MODE_RADIO == state->norm ||
919 MSP_MODE_EXTERN == state->mode) {
920 /* no carrier scan, just unmute */
921 msp_info("thread: no carrier scan\n");
922 msp_set_volume(client, state->muted, state->left, state->right);
927 msp_set_volume(client, state->muted, 0, 0);
928 msp3400c_setmode(client, MSP_MODE_AM_DETECT /* +1 */ );
931 state->watch_stereo = 0;
933 /* some time for the tuner to sync */
934 if (msp_sleep(state,200))
937 /* carrier detect pass #1 -- main carrier */
938 cd = carrier_detect_main;
939 count = CARRIER_COUNT(carrier_detect_main);
941 if (amsound && (state->norm == VIDEO_MODE_SECAM)) {
942 /* autodetect doesn't work well with AM ... */
945 msp_dbg1("AM sound override\n");
948 for (this = 0; this < count; this++) {
949 msp3400c_setcarrier(client, cd[this].cdo,cd[this].cdo);
950 if (msp_sleep(state,100))
952 val = msp_read_dsp(client, 0x1b);
956 val1 = val, max1 = this;
957 msp_dbg1("carrier1 val: %5d / %s\n", val,cd[this].name);
960 /* carrier detect pass #2 -- second (stereo) carrier */
963 cd = carrier_detect_55;
964 count = CARRIER_COUNT(carrier_detect_55);
967 cd = carrier_detect_65;
968 count = CARRIER_COUNT(carrier_detect_65);
978 if (amsound && (state->norm == VIDEO_MODE_SECAM)) {
979 /* autodetect doesn't work well with AM ... */
984 for (this = 0; this < count; this++) {
985 msp3400c_setcarrier(client, cd[this].cdo,cd[this].cdo);
986 if (msp_sleep(state,100))
988 val = msp_read_dsp(client, 0x1b);
992 val2 = val, max2 = this;
993 msp_dbg1("carrier2 val: %5d / %s\n", val,cd[this].name);
996 /* program the msp3400 according to the results */
997 state->main = carrier_detect_main[max1].cdo;
1002 state->second = carrier_detect_55[max2].cdo;
1003 msp3400c_setmode(client, MSP_MODE_FM_TERRA);
1004 state->nicam_on = 0;
1005 msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
1006 state->watch_stereo = 1;
1007 } else if (max2 == 1 && HAVE_NICAM(state)) {
1009 state->second = carrier_detect_55[max2].cdo;
1010 msp3400c_setmode(client, MSP_MODE_FM_NICAM1);
1011 state->nicam_on = 1;
1012 msp3400c_setcarrier(client, state->second, state->main);
1013 state->watch_stereo = 1;
1020 state->second = MSP_CARRIER(6.552);
1021 msp3400c_setmode(client, MSP_MODE_FM_NICAM2);
1022 state->nicam_on = 1;
1023 msp3400c_setcarrier(client, state->second, state->main);
1024 state->watch_stereo = 1;
1027 if (max2 == 1 || max2 == 2) {
1029 state->second = carrier_detect_65[max2].cdo;
1030 msp3400c_setmode(client, MSP_MODE_FM_TERRA);
1031 state->nicam_on = 0;
1032 msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
1033 state->watch_stereo = 1;
1034 } else if (max2 == 0 &&
1035 state->norm == VIDEO_MODE_SECAM) {
1036 /* L NICAM or AM-mono */
1037 state->second = carrier_detect_65[max2].cdo;
1038 msp3400c_setmode(client, MSP_MODE_AM_NICAM);
1039 state->nicam_on = 0;
1040 msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
1041 msp3400c_setcarrier(client, state->second, state->main);
1042 /* volume prescale for SCART (AM mono input) */
1043 msp_write_dsp(client, 0x000d, 0x1900);
1044 state->watch_stereo = 1;
1045 } else if (max2 == 0 && HAVE_NICAM(state)) {
1047 state->second = carrier_detect_65[max2].cdo;
1048 msp3400c_setmode(client, MSP_MODE_FM_NICAM1);
1049 state->nicam_on = 1;
1050 msp3400c_setcarrier(client, state->second, state->main);
1051 state->watch_stereo = 1;
1059 state->second = carrier_detect_main[max1].cdo;
1060 msp3400c_setmode(client, MSP_MODE_FM_TERRA);
1061 state->nicam_on = 0;
1062 msp3400c_setcarrier(client, state->second, state->main);
1063 state->rxsubchans = V4L2_TUNER_SUB_MONO;
1064 msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
1069 msp_set_volume(client, state->muted, state->left, state->right);
1070 msp3400c_restore_dfp(client);
1073 msp3400c_print_mode(client);
1075 /* monitor tv audio mode */
1076 while (state->watch_stereo) {
1077 if (msp_sleep(state,5000))
1079 watch_stereo(client);
1082 msp_dbg1("thread: exit\n");
1086 /* ----------------------------------------------------------------------- */
1087 /* this one uses the automatic sound standard detection of newer */
1088 /* msp34xx chip versions */
1090 static struct MODES {
1095 { 0x0000, 0, 0, "could not detect sound standard" },
1096 { 0x0001, 0, 0, "autodetect started" },
1097 { 0x0002, MSP_CARRIER(4.5), MSP_CARRIER(4.72), "4.5/4.72 M Dual FM-Stereo" },
1098 { 0x0003, MSP_CARRIER(5.5), MSP_CARRIER(5.7421875), "5.5/5.74 B/G Dual FM-Stereo" },
1099 { 0x0004, MSP_CARRIER(6.5), MSP_CARRIER(6.2578125), "6.5/6.25 D/K1 Dual FM-Stereo" },
1100 { 0x0005, MSP_CARRIER(6.5), MSP_CARRIER(6.7421875), "6.5/6.74 D/K2 Dual FM-Stereo" },
1101 { 0x0006, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 D/K FM-Mono (HDEV3)" },
1102 { 0x0008, MSP_CARRIER(5.5), MSP_CARRIER(5.85), "5.5/5.85 B/G NICAM FM" },
1103 { 0x0009, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 L NICAM AM" },
1104 { 0x000a, MSP_CARRIER(6.0), MSP_CARRIER(6.55), "6.0/6.55 I NICAM FM" },
1105 { 0x000b, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM" },
1106 { 0x000c, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM (HDEV2)" },
1107 { 0x0020, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Stereo" },
1108 { 0x0021, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Mono + SAP" },
1109 { 0x0030, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M EIA-J Japan Stereo" },
1110 { 0x0040, MSP_CARRIER(10.7), MSP_CARRIER(10.7), "10.7 FM-Stereo Radio" },
1111 { 0x0050, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 SAT-Mono" },
1112 { 0x0051, MSP_CARRIER(7.02), MSP_CARRIER(7.20), "7.02/7.20 SAT-Stereo" },
1113 { 0x0060, MSP_CARRIER(7.2), MSP_CARRIER(7.2), "7.2 SAT ADR" },
1114 { -1, 0, 0, NULL }, /* EOF */
1117 static inline const char *msp_standard_mode_name(int mode)
1120 for (i = 0; modelist[i].name != NULL; i++)
1121 if (modelist[i].retval == mode)
1122 return modelist[i].name;
1126 static int msp_modus(struct i2c_client *client, int norm)
1129 case VIDEO_MODE_PAL:
1130 msp_dbg1("video mode selected to PAL\n");
1133 /* experimental: not sure this works with all chip versions */
1136 /* previous value, try this if it breaks ... */
1139 case VIDEO_MODE_NTSC: /* BTSC */
1140 msp_dbg1("video mode selected to NTSC\n");
1142 case VIDEO_MODE_SECAM:
1143 msp_dbg1("video mode selected to SECAM\n");
1145 case VIDEO_MODE_RADIO:
1146 msp_dbg1("video mode selected to Radio\n");
1148 case VIDEO_MODE_AUTO:
1149 msp_dbg1("video mode selected to Auto\n");
1156 static int msp_standard(int norm)
1159 case VIDEO_MODE_PAL:
1161 case VIDEO_MODE_NTSC: /* BTSC */
1163 case VIDEO_MODE_SECAM:
1165 case VIDEO_MODE_RADIO:
1172 static int msp3410d_thread(void *data)
1174 struct i2c_client *client = data;
1175 struct msp_state *state = i2c_get_clientdata(client);
1178 msp_info("msp3410 daemon started\n");
1181 msp_dbg2("msp3410 thread: sleep\n");
1182 msp_sleep(state,-1);
1183 msp_dbg2("msp3410 thread: wakeup\n");
1186 msp_dbg1("thread: restart scan\n");
1188 if (kthread_should_stop())
1191 if (state->mode == MSP_MODE_EXTERN) {
1192 /* no carrier scan needed, just unmute */
1193 msp_dbg1("thread: no carrier scan\n");
1194 msp_set_volume(client, state->muted, state->left, state->right);
1198 /* put into sane state (and mute) */
1201 /* some time for the tuner to sync */
1202 if (msp_sleep(state,200))
1205 /* start autodetect */
1206 mode = msp_modus(client, state->norm);
1207 std = msp_standard(state->norm);
1208 msp_write_dem(client, 0x30, mode);
1209 msp_write_dem(client, 0x20, std);
1210 state->watch_stereo = 0;
1213 msp_dbg1("setting mode: %s (0x%04x)\n",
1214 msp_standard_mode_name(std) ,std);
1217 /* programmed some specific mode */
1220 /* triggered autodetect */
1222 if (msp_sleep(state,100))
1226 val = msp_read_dem(client, 0x7e);
1229 msp_dbg1("detection still in progress\n");
1232 for (i = 0; modelist[i].name != NULL; i++)
1233 if (modelist[i].retval == val)
1235 msp_dbg1("current mode: %s (0x%04x)\n",
1236 modelist[i].name ? modelist[i].name : "unknown",
1238 state->main = modelist[i].main;
1239 state->second = modelist[i].second;
1241 if (amsound && (state->norm == VIDEO_MODE_SECAM) && (val != 0x0009)) {
1242 /* autodetection has failed, let backup */
1243 msp_dbg1("autodetection failed,"
1244 " switching to backup mode: %s (0x%04x)\n",
1245 modelist[8].name ? modelist[8].name : "unknown",val);
1247 msp_write_dem(client, 0x20, val);
1250 /* set various prescales */
1251 msp_write_dsp(client, 0x0d, 0x1900); /* scart */
1252 msp_write_dsp(client, 0x0e, 0x2403); /* FM */
1253 msp_write_dsp(client, 0x10, 0x5a00); /* nicam */
1257 case 0x0008: /* B/G NICAM */
1258 case 0x000a: /* I NICAM */
1260 state->mode = MSP_MODE_FM_NICAM1;
1262 state->mode = MSP_MODE_FM_NICAM2;
1263 /* just turn on stereo */
1264 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
1265 state->nicam_on = 1;
1266 state->watch_stereo = 1;
1267 msp3400c_setstereo(client,V4L2_TUNER_MODE_STEREO);
1270 state->mode = MSP_MODE_AM_NICAM;
1271 state->rxsubchans = V4L2_TUNER_SUB_MONO;
1272 state->nicam_on = 1;
1273 msp3400c_setstereo(client,V4L2_TUNER_MODE_MONO);
1274 state->watch_stereo = 1;
1276 case 0x0020: /* BTSC */
1277 /* just turn on stereo */
1278 state->mode = MSP_MODE_BTSC;
1279 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
1280 state->nicam_on = 0;
1281 state->watch_stereo = 1;
1282 msp3400c_setstereo(client,V4L2_TUNER_MODE_STEREO);
1284 case 0x0040: /* FM radio */
1285 state->mode = MSP_MODE_FM_RADIO;
1286 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
1287 state->audmode = V4L2_TUNER_MODE_STEREO;
1288 state->nicam_on = 0;
1289 state->watch_stereo = 0;
1290 /* not needed in theory if HAVE_RADIO(), but
1291 short programming enables carrier mute */
1292 msp3400c_setmode(client,MSP_MODE_FM_RADIO);
1293 msp3400c_setcarrier(client, MSP_CARRIER(10.7),
1296 msp_set_scart(client,SCART_IN2,0);
1297 /* msp34xx does radio decoding */
1298 msp_write_dsp(client, 0x08, 0x0020);
1299 msp_write_dsp(client, 0x09, 0x0020);
1300 msp_write_dsp(client, 0x0b, 0x0020);
1305 state->mode = MSP_MODE_FM_TERRA;
1306 state->rxsubchans = V4L2_TUNER_SUB_MONO;
1307 state->audmode = V4L2_TUNER_MODE_MONO;
1308 state->nicam_on = 0;
1309 state->watch_stereo = 1;
1313 /* unmute, restore misc registers */
1314 msp_set_bass(client, state->bass);
1315 msp_set_treble(client, state->treble);
1316 msp_set_volume(client, state->muted, state->left, state->right);
1317 msp_write_dsp(client, 0x13, state->acb);
1318 msp_write_dem(client, 0x40, state->i2s_mode);
1319 msp3400c_restore_dfp(client);
1321 /* monitor tv audio mode */
1322 while (state->watch_stereo) {
1323 if (msp_sleep(state,5000))
1325 watch_stereo(client);
1328 msp_dbg1("thread: exit\n");
1332 /* ----------------------------------------------------------------------- */
1333 /* msp34xxG + (autoselect no-thread) */
1334 /* this one uses both automatic standard detection and automatic sound */
1335 /* select which are available in the newer G versions */
1336 /* struct msp: only norm, acb and source are really used in this mode */
1338 static void msp34xxg_set_source(struct i2c_client *client, int source);
1340 /* (re-)initialize the msp34xxg, according to the current norm in state->norm
1341 * return 0 if it worked, -1 if it failed
1343 static int msp34xxg_reset(struct i2c_client *client)
1345 struct msp_state *state = i2c_get_clientdata(client);
1348 if (msp_reset(client))
1351 /* make sure that input/output is muted (paranoid mode) */
1352 if (msp_write_dsp(client,
1354 0x0f20 /* mute DSP input, mute SCART 1 */))
1357 msp_write_dem(client, 0x40, state->i2s_mode);
1359 /* step-by-step initialisation, as described in the manual */
1360 modus = msp_modus(client, state->norm);
1361 std = msp_standard(state->norm);
1362 modus &= ~0x03; /* STATUS_CHANGE=0 */
1363 modus |= 0x01; /* AUTOMATIC_SOUND_DETECTION=1 */
1364 if (msp_write_dem(client, 0x30/*MODUS*/, modus))
1366 if (msp_write_dem(client, 0x20/*standard*/, std))
1369 /* write the dfps that may have an influence on
1370 standard/audio autodetection right now */
1371 msp34xxg_set_source(client, state->source);
1373 if (msp_write_dfp_with_default(client, 0x0e, /* AM/FM Prescale */
1375 /* default: [15:8] 75khz deviation */
1379 if (msp_write_dfp_with_default(client, 0x10, /* NICAM Prescale */
1381 /* default: 9db gain (as recommended) */
1388 static int msp34xxg_thread(void *data)
1390 struct i2c_client *client = data;
1391 struct msp_state *state = i2c_get_clientdata(client);
1394 msp_info("msp34xxg daemon started\n");
1396 state->source = 1; /* default */
1398 msp_dbg2("msp34xxg thread: sleep\n");
1399 msp_sleep(state,-1);
1400 msp_dbg2("msp34xxg thread: wakeup\n");
1403 msp_dbg1("thread: restart scan\n");
1405 if (kthread_should_stop())
1409 msp34xxg_reset(client);
1414 /* watch autodetect */
1415 msp_dbg1("triggered autodetect, waiting for result\n");
1416 for (i = 0; i < 10; i++) {
1417 if (msp_sleep(state,100))
1421 val = msp_read_dem(client, 0x7e);
1426 msp_dbg1("detection still in progress\n");
1429 msp_dbg1("detection still in progress after 10 tries. giving up.\n");
1435 msp_dbg1("current mode: %s (0x%04x)\n",
1436 msp_standard_mode_name(std), std);
1438 /* unmute: dispatch sound to scart output, set scart volume */
1439 msp_dbg1("unmute\n");
1441 msp_set_bass(client, state->bass);
1442 msp_set_treble(client, state->treble);
1443 msp_set_volume(client, state->muted, state->left, state->right);
1446 if (msp_write_dsp(client, 0x13, state->acb))
1449 msp_write_dem(client, 0x40, state->i2s_mode);
1451 msp_dbg1("thread: exit\n");
1455 /* set the same 'source' for the loudspeaker, scart and quasi-peak detector
1456 * the value for source is the same as bit 15:8 of DFP registers 0x08,
1457 * 0x0a and 0x0c: 0=mono, 1=stereo or A|B, 2=SCART, 3=stereo or A, 4=stereo or B
1459 * this function replaces msp3400c_setstereo
1461 static void msp34xxg_set_source(struct i2c_client *client, int source)
1463 struct msp_state *state = i2c_get_clientdata(client);
1465 /* fix matrix mode to stereo and let the msp choose what
1466 * to output according to 'source', as recommended
1467 * for MONO (source==0) downmixing set bit[7:0] to 0x30
1469 int value = (source&0x07)<<8|(source==0 ? 0x30:0x20);
1470 msp_dbg1("set source to %d (0x%x)\n", source, value);
1471 msp_write_dsp(client,
1472 0x08, /* Loudspeaker Output */
1474 msp_write_dsp(client,
1475 0x0a, /* SCART1 DA Output */
1477 msp_write_dsp(client,
1478 0x0c, /* Quasi-peak detector */
1481 * set identification threshold. Personally, I
1482 * I set it to a higher value that the default
1483 * of 0x190 to ignore noisy stereo signals.
1484 * this needs tuning. (recommended range 0x00a0-0x03c0)
1485 * 0x7f0 = forced mono mode
1487 msp_write_dem(client,
1488 0x22, /* a2 threshold for stereo/bilingual */
1490 state->source=source;
1493 static void msp34xxg_detect_stereo(struct i2c_client *client)
1495 struct msp_state *state = i2c_get_clientdata(client);
1497 int status = msp_read_dem(client,
1498 0x0200 /* STATUS */);
1499 int is_bilingual = status&0x100;
1500 int is_stereo = status&0x40;
1502 state->rxsubchans = 0;
1504 state->rxsubchans |= V4L2_TUNER_SUB_STEREO;
1506 state->rxsubchans |= V4L2_TUNER_SUB_MONO;
1508 state->rxsubchans |= V4L2_TUNER_SUB_LANG1|V4L2_TUNER_SUB_LANG2;
1509 /* I'm supposed to check whether it's SAP or not
1510 * and set only LANG2/SAP in this case. Yet, the MSP
1511 * does a lot of work to hide this and handle everything
1512 * the same way. I don't want to work around it so unless
1513 * this is a problem, I'll handle SAP just like lang1/lang2.
1516 msp_dbg1("status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n",
1517 status, is_stereo, is_bilingual, state->rxsubchans);
1520 static void msp34xxg_set_audmode(struct i2c_client *client, int audmode)
1522 struct msp_state *state = i2c_get_clientdata(client);
1526 case V4L2_TUNER_MODE_MONO:
1527 source=0; /* mono only */
1529 case V4L2_TUNER_MODE_STEREO:
1530 source=1; /* stereo or A|B, see comment in msp34xxg_get_v4l2_stereo() */
1531 /* problem: that could also mean 2 (scart input) */
1533 case V4L2_TUNER_MODE_LANG1:
1534 source=3; /* stereo or A */
1536 case V4L2_TUNER_MODE_LANG2:
1537 source=4; /* stereo or B */
1544 state->audmode = audmode;
1545 msp34xxg_set_source(client, source);
1549 /* ----------------------------------------------------------------------- */
1551 static void msp_wake_thread(struct i2c_client *client)
1553 struct msp_state *state = i2c_get_clientdata(client);
1555 if (NULL == state->kthread)
1557 msp_set_volume(client,state->muted,0,0);
1558 state->watch_stereo = 0;
1560 wake_up_interruptible(&state->wq);
1563 /* ----------------------------------------------------------------------- */
1565 static int mode_v4l2_to_v4l1(int rxsubchans)
1569 if (rxsubchans & V4L2_TUNER_SUB_STEREO)
1570 mode |= VIDEO_SOUND_STEREO;
1571 if (rxsubchans & V4L2_TUNER_SUB_LANG2)
1572 mode |= VIDEO_SOUND_LANG2;
1573 if (rxsubchans & V4L2_TUNER_SUB_LANG1)
1574 mode |= VIDEO_SOUND_LANG1;
1576 mode |= VIDEO_SOUND_MONO;
1580 static int mode_v4l1_to_v4l2(int mode)
1582 if (mode & VIDEO_SOUND_STEREO)
1583 return V4L2_TUNER_MODE_STEREO;
1584 if (mode & VIDEO_SOUND_LANG2)
1585 return V4L2_TUNER_MODE_LANG2;
1586 if (mode & VIDEO_SOUND_LANG1)
1587 return V4L2_TUNER_MODE_LANG1;
1588 return V4L2_TUNER_MODE_MONO;
1591 static void msp_any_detect_stereo(struct i2c_client *client)
1593 struct msp_state *state = i2c_get_clientdata(client);
1595 switch (state->opmode) {
1597 case OPMODE_AUTODETECT:
1598 autodetect_stereo(client);
1600 case OPMODE_AUTOSELECT:
1601 msp34xxg_detect_stereo(client);
1606 static struct v4l2_queryctrl msp_qctrl[] = {
1608 .id = V4L2_CID_AUDIO_VOLUME,
1613 .default_value = 58880,
1615 .type = V4L2_CTRL_TYPE_INTEGER,
1617 .id = V4L2_CID_AUDIO_MUTE,
1624 .type = V4L2_CTRL_TYPE_BOOLEAN,
1626 .id = V4L2_CID_AUDIO_BASS,
1631 .default_value = 32768,
1632 .type = V4L2_CTRL_TYPE_INTEGER,
1634 .id = V4L2_CID_AUDIO_TREBLE,
1639 .default_value = 32768,
1640 .type = V4L2_CTRL_TYPE_INTEGER,
1645 static void msp_any_set_audmode(struct i2c_client *client, int audmode)
1647 struct msp_state *state = i2c_get_clientdata(client);
1649 switch (state->opmode) {
1651 case OPMODE_AUTODETECT:
1652 state->watch_stereo = 0;
1653 msp3400c_setstereo(client, audmode);
1655 case OPMODE_AUTOSELECT:
1656 msp34xxg_set_audmode(client, audmode);
1661 static int msp_get_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
1663 struct msp_state *state = i2c_get_clientdata(client);
1666 case V4L2_CID_AUDIO_MUTE:
1667 ctrl->value = state->muted;
1669 case V4L2_CID_AUDIO_BALANCE:
1671 int volume = max(state->left, state->right);
1673 ctrl->value = (32768 * min(state->left, state->right)) /
1674 (volume ? volume : 1);
1675 ctrl->value = (state->left < state->right) ?
1676 (65535 - ctrl->value) : ctrl->value;
1678 ctrl->value = 32768;
1681 case V4L2_CID_AUDIO_BASS:
1682 ctrl->value = state->bass;
1684 case V4L2_CID_AUDIO_TREBLE:
1685 ctrl->value = state->treble;
1687 case V4L2_CID_AUDIO_VOLUME:
1688 ctrl->value = max(state->left, state->right);
1695 static int msp_set_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
1697 struct msp_state *state = i2c_get_clientdata(client);
1698 int set_volume = 0, balance, volume;
1701 case V4L2_CID_AUDIO_MUTE:
1702 if (ctrl->value < 0 || ctrl->value >= 2)
1704 state->muted = ctrl->value;
1705 msp_set_volume(client, state->muted, state->left, state->right);
1708 case V4L2_CID_AUDIO_BALANCE:
1709 balance = ctrl->value;
1710 volume = max(state->left, state->right);
1714 case V4L2_CID_AUDIO_BASS:
1715 state->bass = ctrl->value;
1716 msp_set_bass(client, state->bass);
1719 case V4L2_CID_AUDIO_TREBLE:
1720 state->treble = ctrl->value;
1721 msp_set_treble(client, state->treble);
1724 case V4L2_CID_AUDIO_VOLUME:
1725 volume = max(state->left, state->right);
1727 balance = (32768 * min(state->left, state->right)) /
1728 (volume ? volume : 1);
1729 balance = (state->left < state->right) ?
1730 (65535 - balance) : balance;
1734 volume = ctrl->value;
1743 state->left = (min(65536 - balance, 32768) * volume) / 32768;
1744 state->right = (min(balance, 32768) * volume) / 32768;
1746 msp_dbg2("volume=%d, balance=%d, left=%d, right=%d",
1747 volume, balance, state->left, state->right);
1749 msp_set_volume(client, state->muted, state->left, state->right);
1754 static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
1756 struct msp_state *state = i2c_get_clientdata(client);
1761 case AUDC_SET_INPUT:
1762 msp_dbg1("AUDC_SET_INPUT(%d)\n",*sarg);
1764 if (*sarg == state->input)
1766 state->input = *sarg;
1769 /* Hauppauge uses IN2 for the radio */
1770 state->mode = MSP_MODE_FM_RADIO;
1773 case AUDIO_EXTERN_1:
1774 /* IN1 is often used for external input ... */
1775 state->mode = MSP_MODE_EXTERN;
1778 case AUDIO_EXTERN_2:
1779 /* ... sometimes it is IN2 through ;) */
1780 state->mode = MSP_MODE_EXTERN;
1787 if (*sarg & AUDIO_MUTE)
1788 msp_set_scart(client, SCART_MUTE, 0);
1792 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
1793 state->audmode = V4L2_TUNER_MODE_STEREO;
1794 msp_set_scart(client, scart, 0);
1795 msp_write_dsp(client, 0x000d, 0x1900);
1796 if (state->opmode != OPMODE_AUTOSELECT)
1797 msp3400c_setstereo(client, state->audmode);
1799 msp_wake_thread(client);
1802 case AUDC_SET_RADIO:
1803 msp_dbg1("AUDC_SET_RADIO\n");
1804 state->norm = VIDEO_MODE_RADIO;
1805 msp_dbg1("switching to radio mode\n");
1806 state->watch_stereo = 0;
1807 switch (state->opmode) {
1809 /* set msp3400 to FM radio mode */
1810 msp3400c_setmode(client, MSP_MODE_FM_RADIO);
1811 msp3400c_setcarrier(client, MSP_CARRIER(10.7),
1813 msp_set_volume(client, state->muted, state->left, state->right);
1815 case OPMODE_AUTODETECT:
1816 case OPMODE_AUTOSELECT:
1817 /* the thread will do for us */
1818 msp_wake_thread(client);
1822 /* work-in-progress: hook to control the DFP registers */
1823 case MSP_SET_DFPREG:
1825 struct msp_dfpreg *r = arg;
1828 if (r->reg < 0 || r->reg >= DFP_COUNT)
1830 for (i = 0; i < sizeof(bl_dfp) / sizeof(int); i++)
1831 if (r->reg == bl_dfp[i])
1833 state->dfp_regs[r->reg] = r->value;
1834 msp_write_dsp(client, r->reg, r->value);
1838 case MSP_GET_DFPREG:
1840 struct msp_dfpreg *r = arg;
1842 if (r->reg < 0 || r->reg >= DFP_COUNT)
1844 r->value = msp_read_dsp(client, r->reg);
1848 /* --- v4l ioctls --- */
1849 /* take care: bttv does userspace copying, we'll get a
1850 kernel pointer here... */
1853 struct video_audio *va = arg;
1855 msp_dbg1("VIDIOCGAUDIO\n");
1856 va->flags |= VIDEO_AUDIO_VOLUME |
1858 VIDEO_AUDIO_TREBLE |
1859 VIDEO_AUDIO_MUTABLE;
1861 va->flags |= VIDEO_AUDIO_MUTE;
1864 va->flags |= VIDEO_AUDIO_MUTE;
1865 va->volume = max(state->left, state->right);
1866 va->balance = (32768 * min(state->left, state->right)) /
1867 (va->volume ? va->volume : 1);
1868 va->balance = (state->left < state->right) ?
1869 (65535 - va->balance) : va->balance;
1870 if (0 == va->volume)
1871 va->balance = 32768;
1872 va->bass = state->bass;
1873 va->treble = state->treble;
1875 msp_any_detect_stereo(client);
1876 va->mode = mode_v4l2_to_v4l1(state->rxsubchans);
1882 struct video_audio *va = arg;
1884 msp_dbg1("VIDIOCSAUDIO\n");
1885 state->muted = (va->flags & VIDEO_AUDIO_MUTE);
1886 state->left = (min(65536 - va->balance, 32768) *
1887 va->volume) / 32768;
1888 state->right = (min((int)va->balance, 32768) * va->volume) / 32768;
1889 state->bass = va->bass;
1890 state->treble = va->treble;
1891 msp_dbg1("vol %d, bal %d, flags %x, left %d, right %d, bass %d, treble %d, mode %x\n",
1892 va->volume, va->balance, va->flags, state->left,
1893 state->right, state->bass, state->treble, state->mode);
1894 msp_set_volume(client, state->muted, state->left, state->right);
1895 msp_set_bass(client, state->bass);
1896 msp_set_treble(client, state->treble);
1898 if (va->mode != 0 && state->norm != VIDEO_MODE_RADIO)
1899 msp_any_set_audmode(client,mode_v4l1_to_v4l2(va->mode));
1905 struct video_channel *vc = arg;
1907 msp_dbg1("VIDIOCSCHAN (norm=%d)\n",vc->norm);
1908 state->norm = vc->norm;
1909 msp_wake_thread(client);
1914 case VIDIOC_S_FREQUENCY:
1916 /* new channel -- kick audio carrier scan */
1917 msp_dbg1("VIDIOCSFREQ\n");
1918 msp_wake_thread(client);
1922 /* msp34xx specific */
1923 case MSP_SET_MATRIX:
1925 struct msp_matrix *mspm = arg;
1927 msp_dbg1("MSP_SET_MATRIX\n");
1928 msp_set_scart(client, mspm->input, mspm->output);
1932 /* --- v4l2 ioctls --- */
1935 v4l2_std_id *id = arg;
1937 /*FIXME: use V4L2 mode flags on msp3400 instead of V4L1*/
1938 if (*id & V4L2_STD_PAL) {
1939 state->norm=VIDEO_MODE_PAL;
1940 } else if (*id & V4L2_STD_SECAM) {
1941 state->norm=VIDEO_MODE_SECAM;
1943 state->norm=VIDEO_MODE_NTSC;
1946 msp_wake_thread(client);
1950 case VIDIOC_ENUMINPUT:
1952 struct v4l2_input *i = arg;
1957 i->type = V4L2_INPUT_TYPE_TUNER;
1960 strcpy(i->name,"Radio");
1962 case AUDIO_EXTERN_1:
1963 strcpy(i->name,"Extern 1");
1965 case AUDIO_EXTERN_2:
1966 strcpy(i->name,"Extern 2");
1969 strcpy(i->name,"Television");
1977 case VIDIOC_G_AUDIO:
1979 struct v4l2_audio *a = arg;
1981 memset(a,0,sizeof(*a));
1985 strcpy(a->name,"Radio");
1987 case AUDIO_EXTERN_1:
1988 strcpy(a->name,"Extern 1");
1990 case AUDIO_EXTERN_2:
1991 strcpy(a->name,"Extern 2");
1994 strcpy(a->name,"Television");
2000 msp_any_detect_stereo(client);
2001 if (state->audmode == V4L2_TUNER_MODE_STEREO) {
2002 a->capability=V4L2_AUDCAP_STEREO;
2008 case VIDIOC_S_AUDIO:
2010 struct v4l2_audio *sarg = arg;
2012 switch (sarg->index) {
2014 /* Hauppauge uses IN2 for the radio */
2015 state->mode = MSP_MODE_FM_RADIO;
2018 case AUDIO_EXTERN_1:
2019 /* IN1 is often used for external input ... */
2020 state->mode = MSP_MODE_EXTERN;
2023 case AUDIO_EXTERN_2:
2024 /* ... sometimes it is IN2 through ;) */
2025 state->mode = MSP_MODE_EXTERN;
2033 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
2034 state->audmode = V4L2_TUNER_MODE_STEREO;
2035 msp_set_scart(client,scart,0);
2036 msp_write_dsp(client,0x000d,0x1900);
2038 if (sarg->capability==V4L2_AUDCAP_STEREO) {
2039 state->audmode = V4L2_TUNER_MODE_STEREO;
2041 state->audmode &= ~V4L2_TUNER_MODE_STEREO;
2043 msp_any_set_audmode(client, state->audmode);
2044 msp_wake_thread(client);
2048 case VIDIOC_G_TUNER:
2050 struct v4l2_tuner *vt = arg;
2052 msp_any_detect_stereo(client);
2053 vt->audmode = state->audmode;
2054 vt->rxsubchans = state->rxsubchans;
2055 vt->capability = V4L2_TUNER_CAP_STEREO |
2056 V4L2_TUNER_CAP_LANG1|
2057 V4L2_TUNER_CAP_LANG2;
2061 case VIDIOC_S_TUNER:
2063 struct v4l2_tuner *vt=(struct v4l2_tuner *)arg;
2065 /* only set audmode */
2066 if (vt->audmode != -1 && vt->audmode != 0)
2067 msp_any_set_audmode(client, vt->audmode);
2071 case VIDIOC_G_AUDOUT:
2073 struct v4l2_audioout *a=(struct v4l2_audioout *)arg;
2076 memset(a,0,sizeof(*a));
2080 strcpy(a->name,"Scart1 Out");
2083 strcpy(a->name,"Scart2 Out");
2086 strcpy(a->name,"I2S Out");
2095 case VIDIOC_S_AUDOUT:
2097 struct v4l2_audioout *a=(struct v4l2_audioout *)arg;
2099 if (a->index<0||a->index>2)
2102 msp_dbg1("Setting audio out on msp34xx to input %i\n",a->index);
2103 msp_set_scart(client,state->in_scart,a->index+1);
2108 case VIDIOC_INT_I2S_CLOCK_FREQ:
2112 msp_dbg1("Setting I2S speed to %d\n",*a);
2127 case VIDIOC_QUERYCTRL:
2129 struct v4l2_queryctrl *qc = arg;
2132 msp_dbg1("VIDIOC_QUERYCTRL\n");
2134 for (i = 0; i < ARRAY_SIZE(msp_qctrl); i++)
2135 if (qc->id && qc->id == msp_qctrl[i].id) {
2136 memcpy(qc, &(msp_qctrl[i]),
2146 struct v4l2_control *ctrl = arg;
2147 msp_dbg1("VIDIOC_G_CTRL\n");
2149 return msp_get_ctrl(client, ctrl);
2154 struct v4l2_control *ctrl = arg;
2156 msp_dbg1("VIDIOC_S_CTRL\n");
2158 return msp_set_ctrl(client, ctrl);
2161 case VIDIOC_LOG_STATUS:
2162 msp_any_detect_stereo(client);
2163 msp_info("%s rev1 = 0x%04x rev2 = 0x%04x\n",
2164 client->name, state->rev1, state->rev2);
2165 msp_info("Volume: left %d right %d bass %d treble %d%s\n",
2166 state->left, state->right,
2167 state->bass, state->treble,
2168 state->muted ? " (muted)" : "");
2169 msp_info("Mode: %s (%s%s)\n", msp_standard_mode_name(state->mode),
2170 (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
2171 (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
2172 msp_info("ACB: 0x%04x\n", state->acb);
2182 static int msp_suspend(struct device * dev, pm_message_t state)
2184 struct i2c_client *client = container_of(dev, struct i2c_client, dev);
2186 msp_dbg1("suspend\n");
2191 static int msp_resume(struct device * dev)
2193 struct i2c_client *client = container_of(dev, struct i2c_client, dev);
2195 msp_dbg1("resume\n");
2196 msp_wake_thread(client);
2200 /* ----------------------------------------------------------------------- */
2202 static struct i2c_driver i2c_driver;
2204 static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
2206 struct i2c_client *client;
2207 struct msp_state *state;
2208 int (*thread_func)(void *data) = NULL;
2211 client = kmalloc(sizeof(*client), GFP_KERNEL);
2214 memset(client, 0, sizeof(*client));
2215 client->addr = address;
2216 client->adapter = adapter;
2217 client->driver = &i2c_driver;
2218 client->flags = I2C_CLIENT_ALLOW_USE;
2219 snprintf(client->name, sizeof(client->name) - 1, "msp3400");
2221 if (msp_reset(client) == -1) {
2222 msp_dbg1("msp3400 not found\n");
2227 state = kmalloc(sizeof(*state), GFP_KERNEL);
2228 if (state == NULL) {
2232 i2c_set_clientdata(client, state);
2234 memset(state, 0, sizeof(*state));
2235 state->norm = VIDEO_MODE_NTSC;
2236 state->left = 58880; /* 0db gain */
2237 state->right = 58880; /* 0db gain */
2238 state->bass = 32768;
2239 state->treble = 32768;
2242 state->i2s_mode = 0;
2243 for (i = 0; i < DFP_COUNT; i++)
2244 state->dfp_regs[i] = -1;
2245 init_waitqueue_head(&state->wq);
2247 state->rev1 = msp_read_dsp(client, 0x1e);
2248 if (state->rev1 != -1)
2249 state->rev2 = msp_read_dsp(client, 0x1f);
2250 msp_dbg1("rev1=0x%04x, rev2=0x%04x\n", state->rev1, state->rev2);
2251 if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) {
2252 msp_dbg1("error while reading chip version\n");
2258 msp_set_volume(client, state->muted, state->left, state->right);
2260 snprintf(client->name, sizeof(client->name), "MSP%c4%02d%c-%c%d",
2261 ((state->rev1 >> 4) & 0x0f) + '3',
2262 (state->rev2 >> 8) & 0xff,
2263 (state->rev1 & 0x0f) + '@',
2264 ((state->rev1 >> 8) & 0xff) + '@',
2265 state->rev2 & 0x1f);
2267 state->opmode = opmode;
2268 if (state->opmode == OPMODE_AUTO) {
2269 /* MSP revision G and up have both autodetect and autoselect */
2270 if ((state->rev1 & 0x0f) >= 'G'-'@')
2271 state->opmode = OPMODE_AUTOSELECT;
2272 /* MSP revision D and up have autodetect */
2273 else if ((state->rev1 & 0x0f) >= 'D'-'@')
2274 state->opmode = OPMODE_AUTODETECT;
2276 state->opmode = OPMODE_MANUAL;
2279 /* hello world :-) */
2280 msp_info("%s found @ 0x%x (%s)\n", client->name, address << 1, adapter->name);
2281 msp_info("%s ", client->name);
2282 if (HAVE_NICAM(state) && HAVE_RADIO(state))
2283 printk("supports nicam and radio, ");
2284 else if (HAVE_NICAM(state))
2285 printk("supports nicam, ");
2286 else if (HAVE_RADIO(state))
2287 printk("supports radio, ");
2290 /* version-specific initialization */
2291 switch (state->opmode) {
2294 thread_func = msp3400c_thread;
2296 case OPMODE_AUTODETECT:
2297 printk("autodetect");
2298 thread_func = msp3410d_thread;
2300 case OPMODE_AUTOSELECT:
2301 printk("autodetect and autoselect");
2302 thread_func = msp34xxg_thread;
2307 /* startup control thread if needed */
2309 state->kthread = kthread_run(thread_func, client, "msp34xx");
2311 if (NULL == state->kthread)
2312 msp_warn("kernel_thread() failed\n");
2313 msp_wake_thread(client);
2317 i2c_attach_client(client);
2322 static int msp_probe(struct i2c_adapter *adapter)
2324 if (adapter->class & I2C_CLASS_TV_ANALOG)
2325 return i2c_probe(adapter, &addr_data, msp_attach);
2329 static int msp_detach(struct i2c_client *client)
2331 struct msp_state *state = i2c_get_clientdata(client);
2334 /* shutdown control thread */
2335 if (state->kthread) {
2337 kthread_stop(state->kthread);
2341 err = i2c_detach_client(client);
2351 /* ----------------------------------------------------------------------- */
2353 /* i2c implementation */
2354 static struct i2c_driver i2c_driver = {
2356 .id = I2C_DRIVERID_MSP3400,
2357 .flags = I2C_DF_NOTIFY,
2358 .attach_adapter = msp_probe,
2359 .detach_client = msp_detach,
2360 .command = msp_command,
2362 .suspend = msp_suspend,
2363 .resume = msp_resume,
2365 .owner = THIS_MODULE,
2368 static int __init msp3400_init_module(void)
2370 return i2c_add_driver(&i2c_driver);
2373 static void __exit msp3400_cleanup_module(void)
2375 i2c_del_driver(&i2c_driver);
2378 module_init(msp3400_init_module);
2379 module_exit(msp3400_cleanup_module);
2382 * Overrides for Emacs so that we follow Linus's tabbing style.
2383 * ---------------------------------------------------------------------------