2 * Programming the mspx4xx 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>
28 * - better SAT support
30 * 980623 Thomas Sailer (sailer@ife.ee.ethz.ch)
31 * using soundcore instead of OSS
33 * This program is free software; you can redistribute it and/or
34 * modify it under the terms of the GNU General Public License
35 * as published by the Free Software Foundation; either version 2
36 * of the License, or (at your option) any later version.
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/slab.h>
48 #include <linux/i2c.h>
49 #include <linux/kthread.h>
50 #include <linux/freezer.h>
51 #include <linux/videodev2.h>
52 #include <media/v4l2-device.h>
53 #include <media/v4l2-ioctl.h>
54 #include <media/drv-intf/msp3400.h>
55 #include <media/i2c/tvaudio.h>
56 #include "msp3400-driver.h"
58 /* ---------------------------------------------------------------------- */
60 MODULE_DESCRIPTION("device driver for msp34xx TV sound processor");
61 MODULE_AUTHOR("Gerd Knorr");
62 MODULE_LICENSE("GPL");
64 /* module parameters */
65 static int opmode
= OPMODE_AUTO
;
66 int msp_debug
; /* msp_debug output */
67 bool msp_once
; /* no continuous stereo monitoring */
68 bool msp_amsound
; /* hard-wire AM sound at 6.5 Hz (france),
69 the autoscan seems work well only with FM... */
70 int msp_standard
= 1; /* Override auto detect of audio msp_standard,
74 int msp_stereo_thresh
= 0x190; /* a2 threshold for stereo/bilingual
75 (msp34xxg only) 0x00a0-0x03c0 */
78 module_param(opmode
, int, 0444);
81 module_param_named(once
, msp_once
, bool, 0644);
82 module_param_named(debug
, msp_debug
, int, 0644);
83 module_param_named(stereo_threshold
, msp_stereo_thresh
, int, 0644);
84 module_param_named(standard
, msp_standard
, int, 0644);
85 module_param_named(amsound
, msp_amsound
, bool, 0644);
86 module_param_named(dolby
, msp_dolby
, bool, 0644);
88 MODULE_PARM_DESC(opmode
, "Forces a MSP3400 opmode. 0=Manual, 1=Autodetect, 2=Autodetect and autoselect");
89 MODULE_PARM_DESC(once
, "No continuous stereo monitoring");
90 MODULE_PARM_DESC(debug
, "Enable debug messages [0-3]");
91 MODULE_PARM_DESC(stereo_threshold
, "Sets signal threshold to activate stereo");
92 MODULE_PARM_DESC(standard
, "Specify audio standard: 32 = NTSC, 64 = radio, Default: Autodetect");
93 MODULE_PARM_DESC(amsound
, "Hardwire AM sound at 6.5Hz (France), FM can autoscan");
94 MODULE_PARM_DESC(dolby
, "Activates Dolby processing");
96 /* ---------------------------------------------------------------------- */
98 /* control subaddress */
99 #define I2C_MSP_CONTROL 0x00
100 /* demodulator unit subaddress */
101 #define I2C_MSP_DEM 0x10
102 /* DSP unit subaddress */
103 #define I2C_MSP_DSP 0x12
106 /* ----------------------------------------------------------------------- */
107 /* functions for talking to the MSP3400C Sound processor */
109 int msp_reset(struct i2c_client
*client
)
111 /* reset and read revision code */
112 static u8 reset_off
[3] = { I2C_MSP_CONTROL
, 0x80, 0x00 };
113 static u8 reset_on
[3] = { I2C_MSP_CONTROL
, 0x00, 0x00 };
114 static u8 write
[3] = { I2C_MSP_DSP
+ 1, 0x00, 0x1e };
116 struct i2c_msg reset
[2] = {
118 .addr
= client
->addr
,
119 .flags
= I2C_M_IGNORE_NAK
,
124 .addr
= client
->addr
,
125 .flags
= I2C_M_IGNORE_NAK
,
130 struct i2c_msg test
[2] = {
132 .addr
= client
->addr
,
137 .addr
= client
->addr
,
144 dev_dbg_lvl(&client
->dev
, 3, msp_debug
, "msp_reset\n");
145 if (i2c_transfer(client
->adapter
, &reset
[0], 1) != 1 ||
146 i2c_transfer(client
->adapter
, &reset
[1], 1) != 1 ||
147 i2c_transfer(client
->adapter
, test
, 2) != 2) {
148 dev_err(&client
->dev
, "chip reset failed\n");
154 static int msp_read(struct i2c_client
*client
, int dev
, int addr
)
159 struct i2c_msg msgs
[2] = {
161 .addr
= client
->addr
,
166 .addr
= client
->addr
,
174 write
[1] = addr
>> 8;
175 write
[2] = addr
& 0xff;
177 for (err
= 0; err
< 3; err
++) {
178 if (i2c_transfer(client
->adapter
, msgs
, 2) == 2)
180 dev_warn(&client
->dev
, "I/O error #%d (read 0x%02x/0x%02x)\n", err
,
182 schedule_timeout_interruptible(msecs_to_jiffies(10));
185 dev_warn(&client
->dev
, "resetting chip, sound will go off.\n");
189 retval
= read
[0] << 8 | read
[1];
190 dev_dbg_lvl(&client
->dev
, 3, msp_debug
, "msp_read(0x%x, 0x%x): 0x%x\n",
195 int msp_read_dem(struct i2c_client
*client
, int addr
)
197 return msp_read(client
, I2C_MSP_DEM
, addr
);
200 int msp_read_dsp(struct i2c_client
*client
, int addr
)
202 return msp_read(client
, I2C_MSP_DSP
, addr
);
205 static int msp_write(struct i2c_client
*client
, int dev
, int addr
, int val
)
211 buffer
[1] = addr
>> 8;
212 buffer
[2] = addr
& 0xff;
213 buffer
[3] = val
>> 8;
214 buffer
[4] = val
& 0xff;
216 dev_dbg_lvl(&client
->dev
, 3, msp_debug
, "msp_write(0x%x, 0x%x, 0x%x)\n",
218 for (err
= 0; err
< 3; err
++) {
219 if (i2c_master_send(client
, buffer
, 5) == 5)
221 dev_warn(&client
->dev
, "I/O error #%d (write 0x%02x/0x%02x)\n", err
,
223 schedule_timeout_interruptible(msecs_to_jiffies(10));
226 dev_warn(&client
->dev
, "resetting chip, sound will go off.\n");
233 int msp_write_dem(struct i2c_client
*client
, int addr
, int val
)
235 return msp_write(client
, I2C_MSP_DEM
, addr
, val
);
238 int msp_write_dsp(struct i2c_client
*client
, int addr
, int val
)
240 return msp_write(client
, I2C_MSP_DSP
, addr
, val
);
243 /* ----------------------------------------------------------------------- *
244 * bits 9 8 5 - SCART DSP input Select:
245 * 0 0 0 - SCART 1 to DSP input (reset position)
246 * 0 1 0 - MONO to DSP input
247 * 1 0 0 - SCART 2 to DSP input
248 * 1 1 1 - Mute DSP input
250 * bits 11 10 6 - SCART 1 Output Select:
251 * 0 0 0 - undefined (reset position)
252 * 0 1 0 - SCART 2 Input to SCART 1 Output (for devices with 2 SCARTS)
253 * 1 0 0 - MONO input to SCART 1 Output
254 * 1 1 0 - SCART 1 DA to SCART 1 Output
255 * 0 0 1 - SCART 2 DA to SCART 1 Output
256 * 0 1 1 - SCART 1 Input to SCART 1 Output
257 * 1 1 1 - Mute SCART 1 Output
259 * bits 13 12 7 - SCART 2 Output Select (for devices with 2 Output SCART):
260 * 0 0 0 - SCART 1 DA to SCART 2 Output (reset position)
261 * 0 1 0 - SCART 1 Input to SCART 2 Output
262 * 1 0 0 - MONO input to SCART 2 Output
263 * 0 0 1 - SCART 2 DA to SCART 2 Output
264 * 0 1 1 - SCART 2 Input to SCART 2 Output
265 * 1 1 0 - Mute SCART 2 Output
267 * Bits 4 to 0 should be zero.
268 * ----------------------------------------------------------------------- */
270 static int scarts
[3][9] = {
271 /* MASK IN1 IN2 IN3 IN4 IN1_DA IN2_DA MONO MUTE */
272 /* SCART DSP Input select */
273 { 0x0320, 0x0000, 0x0200, 0x0300, 0x0020, -1, -1, 0x0100, 0x0320 },
274 /* SCART1 Output select */
275 { 0x0c40, 0x0440, 0x0400, 0x0000, 0x0840, 0x0c00, 0x0040, 0x0800, 0x0c40 },
276 /* SCART2 Output select */
277 { 0x3080, 0x1000, 0x1080, 0x2080, 0x3080, 0x0000, 0x0080, 0x2000, 0x3000 },
280 static char *scart_names
[] = {
281 "in1", "in2", "in3", "in4", "in1 da", "in2 da", "mono", "mute"
284 void msp_set_scart(struct i2c_client
*client
, int in
, int out
)
286 struct msp_state
*state
= to_state(i2c_get_clientdata(client
));
288 state
->in_scart
= in
;
290 if (in
>= 0 && in
<= 7 && out
>= 0 && out
<= 2) {
291 if (-1 == scarts
[out
][in
+ 1])
294 state
->acb
&= ~scarts
[out
][0];
295 state
->acb
|= scarts
[out
][in
+ 1];
297 state
->acb
= 0xf60; /* Mute Input and SCART 1 Output */
299 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "scart switch: %s => %d (ACB=0x%04x)\n",
300 scart_names
[in
], out
, state
->acb
);
301 msp_write_dsp(client
, 0x13, state
->acb
);
303 /* Sets I2S speed 0 = 1.024 Mbps, 1 = 2.048 Mbps */
304 if (state
->has_i2s_conf
)
305 msp_write_dem(client
, 0x40, state
->i2s_mode
);
308 /* ------------------------------------------------------------------------ */
310 static void msp_wake_thread(struct i2c_client
*client
)
312 struct msp_state
*state
= to_state(i2c_get_clientdata(client
));
314 if (NULL
== state
->kthread
)
316 state
->watch_stereo
= 0;
318 wake_up_interruptible(&state
->wq
);
321 int msp_sleep(struct msp_state
*state
, int timeout
)
323 DECLARE_WAITQUEUE(wait
, current
);
325 add_wait_queue(&state
->wq
, &wait
);
326 if (!kthread_should_stop()) {
328 set_current_state(TASK_INTERRUPTIBLE
);
331 schedule_timeout_interruptible
332 (msecs_to_jiffies(timeout
));
336 remove_wait_queue(&state
->wq
, &wait
);
338 return state
->restart
;
341 /* ------------------------------------------------------------------------ */
343 static int msp_s_ctrl(struct v4l2_ctrl
*ctrl
)
345 struct msp_state
*state
= ctrl_to_state(ctrl
);
346 struct i2c_client
*client
= v4l2_get_subdevdata(&state
->sd
);
350 case V4L2_CID_AUDIO_VOLUME
: {
351 /* audio volume cluster */
352 int reallymuted
= state
->muted
->val
| state
->scan_in_progress
;
355 val
= (val
* 0x7f / 65535) << 8;
357 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "mute=%s scanning=%s volume=%d\n",
358 state
->muted
->val
? "on" : "off",
359 state
->scan_in_progress
? "yes" : "no",
362 msp_write_dsp(client
, 0x0000, val
);
363 msp_write_dsp(client
, 0x0007, reallymuted
? 0x1 : (val
| 0x1));
364 if (state
->has_scart2_out_volume
)
365 msp_write_dsp(client
, 0x0040, reallymuted
? 0x1 : (val
| 0x1));
366 if (state
->has_headphones
)
367 msp_write_dsp(client
, 0x0006, val
);
371 case V4L2_CID_AUDIO_BASS
:
372 val
= ((val
- 32768) * 0x60 / 65535) << 8;
373 msp_write_dsp(client
, 0x0002, val
);
374 if (state
->has_headphones
)
375 msp_write_dsp(client
, 0x0031, val
);
378 case V4L2_CID_AUDIO_TREBLE
:
379 val
= ((val
- 32768) * 0x60 / 65535) << 8;
380 msp_write_dsp(client
, 0x0003, val
);
381 if (state
->has_headphones
)
382 msp_write_dsp(client
, 0x0032, val
);
385 case V4L2_CID_AUDIO_LOUDNESS
:
386 val
= val
? ((5 * 4) << 8) : 0;
387 msp_write_dsp(client
, 0x0004, val
);
388 if (state
->has_headphones
)
389 msp_write_dsp(client
, 0x0033, val
);
392 case V4L2_CID_AUDIO_BALANCE
:
393 val
= (u8
)((val
/ 256) - 128);
394 msp_write_dsp(client
, 0x0001, val
<< 8);
395 if (state
->has_headphones
)
396 msp_write_dsp(client
, 0x0030, val
<< 8);
405 void msp_update_volume(struct msp_state
*state
)
407 /* Force an update of the volume/mute cluster */
408 v4l2_ctrl_lock(state
->volume
);
409 state
->volume
->val
= state
->volume
->cur
.val
;
410 state
->muted
->val
= state
->muted
->cur
.val
;
411 msp_s_ctrl(state
->volume
);
412 v4l2_ctrl_unlock(state
->volume
);
415 /* --- v4l2 ioctls --- */
416 static int msp_s_radio(struct v4l2_subdev
*sd
)
418 struct msp_state
*state
= to_state(sd
);
419 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
424 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "switching to radio mode\n");
425 state
->watch_stereo
= 0;
426 switch (state
->opmode
) {
428 /* set msp3400 to FM radio mode */
429 msp3400c_set_mode(client
, MSP_MODE_FM_RADIO
);
430 msp3400c_set_carrier(client
, MSP_CARRIER(10.7),
432 msp_update_volume(state
);
434 case OPMODE_AUTODETECT
:
435 case OPMODE_AUTOSELECT
:
436 /* the thread will do for us */
437 msp_wake_thread(client
);
443 static int msp_s_frequency(struct v4l2_subdev
*sd
, const struct v4l2_frequency
*freq
)
445 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
447 /* new channel -- kick audio carrier scan */
448 msp_wake_thread(client
);
452 static int msp_querystd(struct v4l2_subdev
*sd
, v4l2_std_id
*id
)
454 struct msp_state
*state
= to_state(sd
);
455 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
457 *id
&= state
->detected_std
;
459 dev_dbg_lvl(&client
->dev
, 2, msp_debug
,
460 "detected standard: %s(0x%08Lx)\n",
461 msp_standard_std_name(state
->std
), state
->detected_std
);
466 static int msp_s_std(struct v4l2_subdev
*sd
, v4l2_std_id id
)
468 struct msp_state
*state
= to_state(sd
);
469 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
470 int update
= state
->radio
|| state
->v4l2_std
!= id
;
472 state
->v4l2_std
= id
;
475 msp_wake_thread(client
);
479 static int msp_s_routing(struct v4l2_subdev
*sd
,
480 u32 input
, u32 output
, u32 config
)
482 struct msp_state
*state
= to_state(sd
);
483 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
484 int tuner
= (input
>> 3) & 1;
485 int sc_in
= input
& 0x7;
486 int sc1_out
= output
& 0xf;
487 int sc2_out
= (output
>> 4) & 0xf;
490 int extern_input
= 1;
492 if (state
->route_in
== input
&& state
->route_out
== output
)
494 state
->route_in
= input
;
495 state
->route_out
= output
;
496 /* check if the tuner input is used */
497 for (i
= 0; i
< 5; i
++) {
498 if (((input
>> (4 + i
* 4)) & 0xf) == 0)
501 state
->mode
= extern_input
? MSP_MODE_EXTERN
: MSP_MODE_AM_DETECT
;
502 state
->rxsubchans
= V4L2_TUNER_SUB_STEREO
;
503 msp_set_scart(client
, sc_in
, 0);
504 msp_set_scart(client
, sc1_out
, 1);
505 msp_set_scart(client
, sc2_out
, 2);
506 msp_set_audmode(client
);
507 reg
= (state
->opmode
== OPMODE_AUTOSELECT
) ? 0x30 : 0xbb;
508 val
= msp_read_dem(client
, reg
);
509 msp_write_dem(client
, reg
, (val
& ~0x100) | (tuner
<< 8));
510 /* wake thread when a new input is chosen */
511 msp_wake_thread(client
);
515 static int msp_g_tuner(struct v4l2_subdev
*sd
, struct v4l2_tuner
*vt
)
517 struct msp_state
*state
= to_state(sd
);
518 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
520 if (vt
->type
!= V4L2_TUNER_ANALOG_TV
)
523 if (state
->opmode
== OPMODE_AUTOSELECT
)
524 msp_detect_stereo(client
);
525 vt
->rxsubchans
= state
->rxsubchans
;
527 vt
->audmode
= state
->audmode
;
528 vt
->capability
|= V4L2_TUNER_CAP_STEREO
|
529 V4L2_TUNER_CAP_LANG1
| V4L2_TUNER_CAP_LANG2
;
533 static int msp_s_tuner(struct v4l2_subdev
*sd
, const struct v4l2_tuner
*vt
)
535 struct msp_state
*state
= to_state(sd
);
536 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
538 if (state
->radio
) /* TODO: add mono/stereo support for radio */
540 if (state
->audmode
== vt
->audmode
)
542 state
->audmode
= vt
->audmode
;
543 /* only set audmode */
544 msp_set_audmode(client
);
548 static int msp_s_i2s_clock_freq(struct v4l2_subdev
*sd
, u32 freq
)
550 struct msp_state
*state
= to_state(sd
);
551 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
553 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "Setting I2S speed to %d\n", freq
);
568 static int msp_log_status(struct v4l2_subdev
*sd
)
570 struct msp_state
*state
= to_state(sd
);
571 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
573 char prefix
[V4L2_SUBDEV_NAME_SIZE
+ 20];
575 if (state
->opmode
== OPMODE_AUTOSELECT
)
576 msp_detect_stereo(client
);
577 dev_info(&client
->dev
, "%s rev1 = 0x%04x rev2 = 0x%04x\n",
578 client
->name
, state
->rev1
, state
->rev2
);
579 snprintf(prefix
, sizeof(prefix
), "%s: Audio: ", sd
->name
);
580 v4l2_ctrl_handler_log_status(&state
->hdl
, prefix
);
581 switch (state
->mode
) {
582 case MSP_MODE_AM_DETECT
: p
= "AM (for carrier detect)"; break;
583 case MSP_MODE_FM_RADIO
: p
= "FM Radio"; break;
584 case MSP_MODE_FM_TERRA
: p
= "Terrestrial FM-mono/stereo"; break;
585 case MSP_MODE_FM_SAT
: p
= "Satellite FM-mono"; break;
586 case MSP_MODE_FM_NICAM1
: p
= "NICAM/FM (B/G, D/K)"; break;
587 case MSP_MODE_FM_NICAM2
: p
= "NICAM/FM (I)"; break;
588 case MSP_MODE_AM_NICAM
: p
= "NICAM/AM (L)"; break;
589 case MSP_MODE_BTSC
: p
= "BTSC"; break;
590 case MSP_MODE_EXTERN
: p
= "External input"; break;
591 default: p
= "unknown"; break;
593 if (state
->mode
== MSP_MODE_EXTERN
) {
594 dev_info(&client
->dev
, "Mode: %s\n", p
);
595 } else if (state
->opmode
== OPMODE_MANUAL
) {
596 dev_info(&client
->dev
, "Mode: %s (%s%s)\n", p
,
597 (state
->rxsubchans
& V4L2_TUNER_SUB_STEREO
) ? "stereo" : "mono",
598 (state
->rxsubchans
& V4L2_TUNER_SUB_LANG2
) ? ", dual" : "");
600 if (state
->opmode
== OPMODE_AUTODETECT
)
601 dev_info(&client
->dev
, "Mode: %s\n", p
);
602 dev_info(&client
->dev
, "Standard: %s (%s%s)\n",
603 msp_standard_std_name(state
->std
),
604 (state
->rxsubchans
& V4L2_TUNER_SUB_STEREO
) ? "stereo" : "mono",
605 (state
->rxsubchans
& V4L2_TUNER_SUB_LANG2
) ? ", dual" : "");
607 dev_info(&client
->dev
, "Audmode: 0x%04x\n", state
->audmode
);
608 dev_info(&client
->dev
, "Routing: 0x%08x (input) 0x%08x (output)\n",
609 state
->route_in
, state
->route_out
);
610 dev_info(&client
->dev
, "ACB: 0x%04x\n", state
->acb
);
614 #ifdef CONFIG_PM_SLEEP
615 static int msp_suspend(struct device
*dev
)
617 struct i2c_client
*client
= to_i2c_client(dev
);
618 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "suspend\n");
623 static int msp_resume(struct device
*dev
)
625 struct i2c_client
*client
= to_i2c_client(dev
);
626 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "resume\n");
627 msp_wake_thread(client
);
632 /* ----------------------------------------------------------------------- */
634 static const struct v4l2_ctrl_ops msp_ctrl_ops
= {
635 .s_ctrl
= msp_s_ctrl
,
638 static const struct v4l2_subdev_core_ops msp_core_ops
= {
639 .log_status
= msp_log_status
,
642 static const struct v4l2_subdev_video_ops msp_video_ops
= {
644 .querystd
= msp_querystd
,
647 static const struct v4l2_subdev_tuner_ops msp_tuner_ops
= {
648 .s_frequency
= msp_s_frequency
,
649 .g_tuner
= msp_g_tuner
,
650 .s_tuner
= msp_s_tuner
,
651 .s_radio
= msp_s_radio
,
654 static const struct v4l2_subdev_audio_ops msp_audio_ops
= {
655 .s_routing
= msp_s_routing
,
656 .s_i2s_clock_freq
= msp_s_i2s_clock_freq
,
659 static const struct v4l2_subdev_ops msp_ops
= {
660 .core
= &msp_core_ops
,
661 .video
= &msp_video_ops
,
662 .tuner
= &msp_tuner_ops
,
663 .audio
= &msp_audio_ops
,
666 /* ----------------------------------------------------------------------- */
669 static const char * const opmode_str
[] = {
670 [OPMODE_MANUAL
] = "manual",
671 [OPMODE_AUTODETECT
] = "autodetect",
672 [OPMODE_AUTOSELECT
] = "autodetect and autoselect",
675 static int msp_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
677 struct msp_state
*state
;
678 struct v4l2_subdev
*sd
;
679 struct v4l2_ctrl_handler
*hdl
;
680 int (*thread_func
)(void *data
) = NULL
;
684 int msp_product
, msp_prod_hi
, msp_prod_lo
;
686 #if defined(CONFIG_MEDIA_CONTROLLER)
691 strlcpy(client
->name
, "msp3400", sizeof(client
->name
));
693 if (msp_reset(client
) == -1) {
694 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "msp3400 not found\n");
698 state
= devm_kzalloc(&client
->dev
, sizeof(*state
), GFP_KERNEL
);
703 v4l2_i2c_subdev_init(sd
, client
, &msp_ops
);
705 #if defined(CONFIG_MEDIA_CONTROLLER)
706 state
->pads
[IF_AUD_DEC_PAD_IF_INPUT
].flags
= MEDIA_PAD_FL_SINK
;
707 state
->pads
[IF_AUD_DEC_PAD_OUT
].flags
= MEDIA_PAD_FL_SOURCE
;
709 sd
->entity
.function
= MEDIA_ENT_F_IF_AUD_DECODER
;
711 ret
= media_entity_pads_init(&sd
->entity
, 2, state
->pads
);
716 state
->v4l2_std
= V4L2_STD_NTSC
;
717 state
->detected_std
= V4L2_STD_ALL
;
718 state
->audmode
= V4L2_TUNER_MODE_STEREO
;
721 init_waitqueue_head(&state
->wq
);
722 /* These are the reset input/output positions */
723 state
->route_in
= MSP_INPUT_DEFAULT
;
724 state
->route_out
= MSP_OUTPUT_DEFAULT
;
726 state
->rev1
= msp_read_dsp(client
, 0x1e);
727 if (state
->rev1
!= -1)
728 state
->rev2
= msp_read_dsp(client
, 0x1f);
729 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "rev1=0x%04x, rev2=0x%04x\n",
730 state
->rev1
, state
->rev2
);
731 if (state
->rev1
== -1 || (state
->rev1
== 0 && state
->rev2
== 0)) {
732 dev_dbg_lvl(&client
->dev
, 1, msp_debug
,
733 "not an msp3400 (cannot read chip version)\n");
737 msp_family
= ((state
->rev1
>> 4) & 0x0f) + 3;
738 msp_product
= (state
->rev2
>> 8) & 0xff;
739 msp_prod_hi
= msp_product
/ 10;
740 msp_prod_lo
= msp_product
% 10;
741 msp_revision
= (state
->rev1
& 0x0f) + '@';
742 msp_hard
= ((state
->rev1
>> 8) & 0xff) + '@';
743 msp_rom
= state
->rev2
& 0x1f;
744 /* Rev B=2, C=3, D=4, G=7 */
745 state
->ident
= msp_family
* 10000 + 4000 + msp_product
* 10 +
748 /* Has NICAM support: all mspx41x and mspx45x products have NICAM */
750 msp_prod_hi
== 1 || msp_prod_hi
== 5;
751 /* Has radio support: was added with revision G */
754 /* Has headphones output: not for stripped down products */
755 state
->has_headphones
=
757 /* Has scart2 input: not in stripped down products of the '3' family */
759 msp_family
>= 4 || msp_prod_lo
< 7;
760 /* Has scart3 input: not in stripped down products of the '3' family */
762 msp_family
>= 4 || msp_prod_lo
< 5;
763 /* Has scart4 input: not in pre D revisions, not in stripped D revs */
765 msp_family
>= 4 || (msp_revision
>= 'D' && msp_prod_lo
< 5);
766 /* Has scart2 output: not in stripped down products of
768 state
->has_scart2_out
=
769 msp_family
>= 4 || msp_prod_lo
< 5;
770 /* Has scart2 a volume control? Not in pre-D revisions. */
771 state
->has_scart2_out_volume
=
772 msp_revision
> 'C' && state
->has_scart2_out
;
773 /* Has a configurable i2s out? */
774 state
->has_i2s_conf
=
775 msp_revision
>= 'G' && msp_prod_lo
< 7;
776 /* Has subwoofer output: not in pre-D revs and not in stripped down
778 state
->has_subwoofer
=
779 msp_revision
>= 'D' && msp_prod_lo
< 5;
780 /* Has soundprocessing (bass/treble/balance/loudness/equalizer):
781 * not in stripped down products */
782 state
->has_sound_processing
=
784 /* Has Virtual Dolby Surround: only in msp34x1 */
785 state
->has_virtual_dolby_surround
=
786 msp_revision
== 'G' && msp_prod_lo
== 1;
787 /* Has Virtual Dolby Surround & Dolby Pro Logic: only in msp34x2 */
788 state
->has_dolby_pro_logic
=
789 msp_revision
== 'G' && msp_prod_lo
== 2;
790 /* The msp343xG supports BTSC only and cannot do Automatic Standard
793 msp_family
== 3 && msp_revision
== 'G' && msp_prod_hi
== 3;
795 state
->opmode
= opmode
;
796 if (state
->opmode
< OPMODE_MANUAL
797 || state
->opmode
> OPMODE_AUTOSELECT
) {
798 /* MSP revision G and up have both autodetect and autoselect */
799 if (msp_revision
>= 'G')
800 state
->opmode
= OPMODE_AUTOSELECT
;
801 /* MSP revision D and up have autodetect */
802 else if (msp_revision
>= 'D')
803 state
->opmode
= OPMODE_AUTODETECT
;
805 state
->opmode
= OPMODE_MANUAL
;
809 v4l2_ctrl_handler_init(hdl
, 6);
810 if (state
->has_sound_processing
) {
811 v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
812 V4L2_CID_AUDIO_BASS
, 0, 65535, 65535 / 100, 32768);
813 v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
814 V4L2_CID_AUDIO_TREBLE
, 0, 65535, 65535 / 100, 32768);
815 v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
816 V4L2_CID_AUDIO_LOUDNESS
, 0, 1, 1, 0);
818 state
->volume
= v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
819 V4L2_CID_AUDIO_VOLUME
, 0, 65535, 65535 / 100, 58880);
820 v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
821 V4L2_CID_AUDIO_BALANCE
, 0, 65535, 65535 / 100, 32768);
822 state
->muted
= v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
823 V4L2_CID_AUDIO_MUTE
, 0, 1, 1, 0);
824 sd
->ctrl_handler
= hdl
;
826 int err
= hdl
->error
;
828 v4l2_ctrl_handler_free(hdl
);
832 v4l2_ctrl_cluster(2, &state
->volume
);
833 v4l2_ctrl_handler_setup(hdl
);
835 dev_info(&client
->dev
,
836 "MSP%d4%02d%c-%c%d found on %s: supports %s%s%s, mode is %s\n",
837 msp_family
, msp_product
,
838 msp_revision
, msp_hard
, msp_rom
,
839 client
->adapter
->name
,
840 (state
->has_nicam
) ? "nicam" : "",
841 (state
->has_nicam
&& state
->has_radio
) ? " and " : "",
842 (state
->has_radio
) ? "radio" : "",
843 opmode_str
[state
->opmode
]);
845 /* version-specific initialization */
846 switch (state
->opmode
) {
848 thread_func
= msp3400c_thread
;
850 case OPMODE_AUTODETECT
:
851 thread_func
= msp3410d_thread
;
853 case OPMODE_AUTOSELECT
:
854 thread_func
= msp34xxg_thread
;
858 /* startup control thread if needed */
860 state
->kthread
= kthread_run(thread_func
, client
, "msp34xx");
862 if (IS_ERR(state
->kthread
))
863 dev_warn(&client
->dev
, "kernel_thread() failed\n");
864 msp_wake_thread(client
);
869 static int msp_remove(struct i2c_client
*client
)
871 struct msp_state
*state
= to_state(i2c_get_clientdata(client
));
873 v4l2_device_unregister_subdev(&state
->sd
);
874 /* shutdown control thread */
875 if (state
->kthread
) {
877 kthread_stop(state
->kthread
);
881 v4l2_ctrl_handler_free(&state
->hdl
);
885 /* ----------------------------------------------------------------------- */
887 static const struct dev_pm_ops msp3400_pm_ops
= {
888 SET_SYSTEM_SLEEP_PM_OPS(msp_suspend
, msp_resume
)
891 static const struct i2c_device_id msp_id
[] = {
895 MODULE_DEVICE_TABLE(i2c
, msp_id
);
897 static struct i2c_driver msp_driver
= {
900 .pm
= &msp3400_pm_ops
,
903 .remove
= msp_remove
,
907 module_i2c_driver(msp_driver
);