1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Programming the mspx4xx sound processor family
5 * (c) 1997-2001 Gerd Knorr <kraxel@bytesex.org>
7 * what works and what doesn't:
10 * Support for Hauppauge cards added (decoding handled by tuner) added by
11 * Frederic Crozat <fcrozat@mail.dotcom.fr>
14 * should work. The stereo modes are backward compatible to FM-mono,
15 * therefore FM-Mono should be always available.
17 * FM-Stereo (B/G, used in germany)
18 * should work, with autodetect
20 * FM-Stereo (satellite)
21 * should work, no autodetect (i.e. default is mono, but you can
22 * switch to stereo -- untested)
24 * NICAM (B/G, L , used in UK, Scandinavia, Spain and France)
25 * should work, with autodetect. Support for NICAM was added by
26 * Pekka Pietikainen <pp@netppl.fi>
29 * - better SAT support
31 * 980623 Thomas Sailer (sailer@ife.ee.ethz.ch)
32 * using soundcore instead of OSS
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/i2c.h>
40 #include <linux/kthread.h>
41 #include <linux/freezer.h>
42 #include <linux/videodev2.h>
43 #include <media/v4l2-device.h>
44 #include <media/v4l2-ioctl.h>
45 #include <media/drv-intf/msp3400.h>
46 #include <media/i2c/tvaudio.h>
47 #include "msp3400-driver.h"
49 /* ---------------------------------------------------------------------- */
51 MODULE_DESCRIPTION("device driver for msp34xx TV sound processor");
52 MODULE_AUTHOR("Gerd Knorr");
53 MODULE_LICENSE("GPL");
55 /* module parameters */
56 static int opmode
= OPMODE_AUTO
;
57 int msp_debug
; /* msp_debug output */
58 bool msp_once
; /* no continuous stereo monitoring */
59 bool msp_amsound
; /* hard-wire AM sound at 6.5 Hz (france),
60 the autoscan seems work well only with FM... */
61 int msp_standard
= 1; /* Override auto detect of audio msp_standard,
65 int msp_stereo_thresh
= 0x190; /* a2 threshold for stereo/bilingual
66 (msp34xxg only) 0x00a0-0x03c0 */
69 module_param(opmode
, int, 0444);
72 module_param_named(once
, msp_once
, bool, 0644);
73 module_param_named(debug
, msp_debug
, int, 0644);
74 module_param_named(stereo_threshold
, msp_stereo_thresh
, int, 0644);
75 module_param_named(standard
, msp_standard
, int, 0644);
76 module_param_named(amsound
, msp_amsound
, bool, 0644);
77 module_param_named(dolby
, msp_dolby
, bool, 0644);
79 MODULE_PARM_DESC(opmode
, "Forces a MSP3400 opmode. 0=Manual, 1=Autodetect, 2=Autodetect and autoselect");
80 MODULE_PARM_DESC(once
, "No continuous stereo monitoring");
81 MODULE_PARM_DESC(debug
, "Enable debug messages [0-3]");
82 MODULE_PARM_DESC(stereo_threshold
, "Sets signal threshold to activate stereo");
83 MODULE_PARM_DESC(standard
, "Specify audio standard: 32 = NTSC, 64 = radio, Default: Autodetect");
84 MODULE_PARM_DESC(amsound
, "Hardwire AM sound at 6.5Hz (France), FM can autoscan");
85 MODULE_PARM_DESC(dolby
, "Activates Dolby processing");
87 /* ---------------------------------------------------------------------- */
89 /* control subaddress */
90 #define I2C_MSP_CONTROL 0x00
91 /* demodulator unit subaddress */
92 #define I2C_MSP_DEM 0x10
93 /* DSP unit subaddress */
94 #define I2C_MSP_DSP 0x12
97 /* ----------------------------------------------------------------------- */
98 /* functions for talking to the MSP3400C Sound processor */
100 int msp_reset(struct i2c_client
*client
)
102 /* reset and read revision code */
103 static u8 reset_off
[3] = { I2C_MSP_CONTROL
, 0x80, 0x00 };
104 static u8 reset_on
[3] = { I2C_MSP_CONTROL
, 0x00, 0x00 };
105 static u8 write
[3] = { I2C_MSP_DSP
+ 1, 0x00, 0x1e };
107 struct i2c_msg reset
[2] = {
109 .addr
= client
->addr
,
110 .flags
= I2C_M_IGNORE_NAK
,
115 .addr
= client
->addr
,
116 .flags
= I2C_M_IGNORE_NAK
,
121 struct i2c_msg test
[2] = {
123 .addr
= client
->addr
,
128 .addr
= client
->addr
,
135 dev_dbg_lvl(&client
->dev
, 3, msp_debug
, "msp_reset\n");
136 if (i2c_transfer(client
->adapter
, &reset
[0], 1) != 1 ||
137 i2c_transfer(client
->adapter
, &reset
[1], 1) != 1 ||
138 i2c_transfer(client
->adapter
, test
, 2) != 2) {
139 dev_err(&client
->dev
, "chip reset failed\n");
145 static int msp_read(struct i2c_client
*client
, int dev
, int addr
)
150 struct i2c_msg msgs
[2] = {
152 .addr
= client
->addr
,
157 .addr
= client
->addr
,
165 write
[1] = addr
>> 8;
166 write
[2] = addr
& 0xff;
168 for (err
= 0; err
< 3; err
++) {
169 if (i2c_transfer(client
->adapter
, msgs
, 2) == 2)
171 dev_warn(&client
->dev
, "I/O error #%d (read 0x%02x/0x%02x)\n", err
,
173 schedule_timeout_interruptible(msecs_to_jiffies(10));
176 dev_warn(&client
->dev
, "resetting chip, sound will go off.\n");
180 retval
= read
[0] << 8 | read
[1];
181 dev_dbg_lvl(&client
->dev
, 3, msp_debug
, "msp_read(0x%x, 0x%x): 0x%x\n",
186 int msp_read_dem(struct i2c_client
*client
, int addr
)
188 return msp_read(client
, I2C_MSP_DEM
, addr
);
191 int msp_read_dsp(struct i2c_client
*client
, int addr
)
193 return msp_read(client
, I2C_MSP_DSP
, addr
);
196 static int msp_write(struct i2c_client
*client
, int dev
, int addr
, int val
)
202 buffer
[1] = addr
>> 8;
203 buffer
[2] = addr
& 0xff;
204 buffer
[3] = val
>> 8;
205 buffer
[4] = val
& 0xff;
207 dev_dbg_lvl(&client
->dev
, 3, msp_debug
, "msp_write(0x%x, 0x%x, 0x%x)\n",
209 for (err
= 0; err
< 3; err
++) {
210 if (i2c_master_send(client
, buffer
, 5) == 5)
212 dev_warn(&client
->dev
, "I/O error #%d (write 0x%02x/0x%02x)\n", err
,
214 schedule_timeout_interruptible(msecs_to_jiffies(10));
217 dev_warn(&client
->dev
, "resetting chip, sound will go off.\n");
224 int msp_write_dem(struct i2c_client
*client
, int addr
, int val
)
226 return msp_write(client
, I2C_MSP_DEM
, addr
, val
);
229 int msp_write_dsp(struct i2c_client
*client
, int addr
, int val
)
231 return msp_write(client
, I2C_MSP_DSP
, addr
, val
);
234 /* ----------------------------------------------------------------------- *
235 * bits 9 8 5 - SCART DSP input Select:
236 * 0 0 0 - SCART 1 to DSP input (reset position)
237 * 0 1 0 - MONO to DSP input
238 * 1 0 0 - SCART 2 to DSP input
239 * 1 1 1 - Mute DSP input
241 * bits 11 10 6 - SCART 1 Output Select:
242 * 0 0 0 - undefined (reset position)
243 * 0 1 0 - SCART 2 Input to SCART 1 Output (for devices with 2 SCARTS)
244 * 1 0 0 - MONO input to SCART 1 Output
245 * 1 1 0 - SCART 1 DA to SCART 1 Output
246 * 0 0 1 - SCART 2 DA to SCART 1 Output
247 * 0 1 1 - SCART 1 Input to SCART 1 Output
248 * 1 1 1 - Mute SCART 1 Output
250 * bits 13 12 7 - SCART 2 Output Select (for devices with 2 Output SCART):
251 * 0 0 0 - SCART 1 DA to SCART 2 Output (reset position)
252 * 0 1 0 - SCART 1 Input to SCART 2 Output
253 * 1 0 0 - MONO input to SCART 2 Output
254 * 0 0 1 - SCART 2 DA to SCART 2 Output
255 * 0 1 1 - SCART 2 Input to SCART 2 Output
256 * 1 1 0 - Mute SCART 2 Output
258 * Bits 4 to 0 should be zero.
259 * ----------------------------------------------------------------------- */
261 static int scarts
[3][9] = {
262 /* MASK IN1 IN2 IN3 IN4 IN1_DA IN2_DA MONO MUTE */
263 /* SCART DSP Input select */
264 { 0x0320, 0x0000, 0x0200, 0x0300, 0x0020, -1, -1, 0x0100, 0x0320 },
265 /* SCART1 Output select */
266 { 0x0c40, 0x0440, 0x0400, 0x0000, 0x0840, 0x0c00, 0x0040, 0x0800, 0x0c40 },
267 /* SCART2 Output select */
268 { 0x3080, 0x1000, 0x1080, 0x2080, 0x3080, 0x0000, 0x0080, 0x2000, 0x3000 },
271 static char *scart_names
[] = {
272 "in1", "in2", "in3", "in4", "in1 da", "in2 da", "mono", "mute"
275 void msp_set_scart(struct i2c_client
*client
, int in
, int out
)
277 struct msp_state
*state
= to_state(i2c_get_clientdata(client
));
279 state
->in_scart
= in
;
281 if (in
>= 0 && in
<= 7 && out
>= 0 && out
<= 2) {
282 if (-1 == scarts
[out
][in
+ 1])
285 state
->acb
&= ~scarts
[out
][0];
286 state
->acb
|= scarts
[out
][in
+ 1];
288 state
->acb
= 0xf60; /* Mute Input and SCART 1 Output */
290 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "scart switch: %s => %d (ACB=0x%04x)\n",
291 scart_names
[in
], out
, state
->acb
);
292 msp_write_dsp(client
, 0x13, state
->acb
);
294 /* Sets I2S speed 0 = 1.024 Mbps, 1 = 2.048 Mbps */
295 if (state
->has_i2s_conf
)
296 msp_write_dem(client
, 0x40, state
->i2s_mode
);
299 /* ------------------------------------------------------------------------ */
301 static void msp_wake_thread(struct i2c_client
*client
)
303 struct msp_state
*state
= to_state(i2c_get_clientdata(client
));
305 if (NULL
== state
->kthread
)
307 state
->watch_stereo
= 0;
309 wake_up_interruptible(&state
->wq
);
312 int msp_sleep(struct msp_state
*state
, int msec
)
316 timeout
= msec
< 0 ? MAX_SCHEDULE_TIMEOUT
: msecs_to_jiffies(msec
);
318 wait_event_freezable_timeout(state
->wq
, kthread_should_stop() ||
319 state
->restart
, timeout
);
321 return state
->restart
;
324 /* ------------------------------------------------------------------------ */
326 static int msp_s_ctrl(struct v4l2_ctrl
*ctrl
)
328 struct msp_state
*state
= ctrl_to_state(ctrl
);
329 struct i2c_client
*client
= v4l2_get_subdevdata(&state
->sd
);
333 case V4L2_CID_AUDIO_VOLUME
: {
334 /* audio volume cluster */
335 int reallymuted
= state
->muted
->val
| state
->scan_in_progress
;
338 val
= (val
* 0x7f / 65535) << 8;
340 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "mute=%s scanning=%s volume=%d\n",
341 state
->muted
->val
? "on" : "off",
342 state
->scan_in_progress
? "yes" : "no",
345 msp_write_dsp(client
, 0x0000, val
);
346 msp_write_dsp(client
, 0x0007, reallymuted
? 0x1 : (val
| 0x1));
347 if (state
->has_scart2_out_volume
)
348 msp_write_dsp(client
, 0x0040, reallymuted
? 0x1 : (val
| 0x1));
349 if (state
->has_headphones
)
350 msp_write_dsp(client
, 0x0006, val
);
354 case V4L2_CID_AUDIO_BASS
:
355 val
= ((val
- 32768) * 0x60 / 65535) << 8;
356 msp_write_dsp(client
, 0x0002, val
);
357 if (state
->has_headphones
)
358 msp_write_dsp(client
, 0x0031, val
);
361 case V4L2_CID_AUDIO_TREBLE
:
362 val
= ((val
- 32768) * 0x60 / 65535) << 8;
363 msp_write_dsp(client
, 0x0003, val
);
364 if (state
->has_headphones
)
365 msp_write_dsp(client
, 0x0032, val
);
368 case V4L2_CID_AUDIO_LOUDNESS
:
369 val
= val
? ((5 * 4) << 8) : 0;
370 msp_write_dsp(client
, 0x0004, val
);
371 if (state
->has_headphones
)
372 msp_write_dsp(client
, 0x0033, val
);
375 case V4L2_CID_AUDIO_BALANCE
:
376 val
= (u8
)((val
/ 256) - 128);
377 msp_write_dsp(client
, 0x0001, val
<< 8);
378 if (state
->has_headphones
)
379 msp_write_dsp(client
, 0x0030, val
<< 8);
388 void msp_update_volume(struct msp_state
*state
)
390 /* Force an update of the volume/mute cluster */
391 v4l2_ctrl_lock(state
->volume
);
392 state
->volume
->val
= state
->volume
->cur
.val
;
393 state
->muted
->val
= state
->muted
->cur
.val
;
394 msp_s_ctrl(state
->volume
);
395 v4l2_ctrl_unlock(state
->volume
);
398 /* --- v4l2 ioctls --- */
399 static int msp_s_radio(struct v4l2_subdev
*sd
)
401 struct msp_state
*state
= to_state(sd
);
402 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
407 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "switching to radio mode\n");
408 state
->watch_stereo
= 0;
409 switch (state
->opmode
) {
411 /* set msp3400 to FM radio mode */
412 msp3400c_set_mode(client
, MSP_MODE_FM_RADIO
);
413 msp3400c_set_carrier(client
, MSP_CARRIER(10.7),
415 msp_update_volume(state
);
417 case OPMODE_AUTODETECT
:
418 case OPMODE_AUTOSELECT
:
419 /* the thread will do for us */
420 msp_wake_thread(client
);
426 static int msp_s_frequency(struct v4l2_subdev
*sd
, const struct v4l2_frequency
*freq
)
428 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
430 /* new channel -- kick audio carrier scan */
431 msp_wake_thread(client
);
435 static int msp_querystd(struct v4l2_subdev
*sd
, v4l2_std_id
*id
)
437 struct msp_state
*state
= to_state(sd
);
438 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
440 *id
&= state
->detected_std
;
442 dev_dbg_lvl(&client
->dev
, 2, msp_debug
,
443 "detected standard: %s(0x%08Lx)\n",
444 msp_standard_std_name(state
->std
), state
->detected_std
);
449 static int msp_s_std(struct v4l2_subdev
*sd
, v4l2_std_id id
)
451 struct msp_state
*state
= to_state(sd
);
452 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
453 int update
= state
->radio
|| state
->v4l2_std
!= id
;
455 state
->v4l2_std
= id
;
458 msp_wake_thread(client
);
462 static int msp_s_routing(struct v4l2_subdev
*sd
,
463 u32 input
, u32 output
, u32 config
)
465 struct msp_state
*state
= to_state(sd
);
466 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
467 int tuner
= (input
>> 3) & 1;
468 int sc_in
= input
& 0x7;
469 int sc1_out
= output
& 0xf;
470 int sc2_out
= (output
>> 4) & 0xf;
473 int extern_input
= 1;
475 if (state
->route_in
== input
&& state
->route_out
== output
)
477 state
->route_in
= input
;
478 state
->route_out
= output
;
479 /* check if the tuner input is used */
480 for (i
= 0; i
< 5; i
++) {
481 if (((input
>> (4 + i
* 4)) & 0xf) == 0)
484 state
->mode
= extern_input
? MSP_MODE_EXTERN
: MSP_MODE_AM_DETECT
;
485 state
->rxsubchans
= V4L2_TUNER_SUB_STEREO
;
486 msp_set_scart(client
, sc_in
, 0);
487 msp_set_scart(client
, sc1_out
, 1);
488 msp_set_scart(client
, sc2_out
, 2);
489 msp_set_audmode(client
);
490 reg
= (state
->opmode
== OPMODE_AUTOSELECT
) ? 0x30 : 0xbb;
491 val
= msp_read_dem(client
, reg
);
492 msp_write_dem(client
, reg
, (val
& ~0x100) | (tuner
<< 8));
493 /* wake thread when a new input is chosen */
494 msp_wake_thread(client
);
498 static int msp_g_tuner(struct v4l2_subdev
*sd
, struct v4l2_tuner
*vt
)
500 struct msp_state
*state
= to_state(sd
);
501 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
503 if (vt
->type
!= V4L2_TUNER_ANALOG_TV
)
506 if (state
->opmode
== OPMODE_AUTOSELECT
)
507 msp_detect_stereo(client
);
508 vt
->rxsubchans
= state
->rxsubchans
;
510 vt
->audmode
= state
->audmode
;
511 vt
->capability
|= V4L2_TUNER_CAP_STEREO
|
512 V4L2_TUNER_CAP_LANG1
| V4L2_TUNER_CAP_LANG2
;
516 static int msp_s_tuner(struct v4l2_subdev
*sd
, const struct v4l2_tuner
*vt
)
518 struct msp_state
*state
= to_state(sd
);
519 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
521 if (state
->radio
) /* TODO: add mono/stereo support for radio */
523 if (state
->audmode
== vt
->audmode
)
525 state
->audmode
= vt
->audmode
;
526 /* only set audmode */
527 msp_set_audmode(client
);
531 static int msp_s_i2s_clock_freq(struct v4l2_subdev
*sd
, u32 freq
)
533 struct msp_state
*state
= to_state(sd
);
534 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
536 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "Setting I2S speed to %d\n", freq
);
551 static int msp_log_status(struct v4l2_subdev
*sd
)
553 struct msp_state
*state
= to_state(sd
);
554 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
556 char prefix
[sizeof(sd
->name
) + 20];
558 if (state
->opmode
== OPMODE_AUTOSELECT
)
559 msp_detect_stereo(client
);
560 dev_info(&client
->dev
, "%s rev1 = 0x%04x rev2 = 0x%04x\n",
561 client
->name
, state
->rev1
, state
->rev2
);
562 snprintf(prefix
, sizeof(prefix
), "%s: Audio: ", sd
->name
);
563 v4l2_ctrl_handler_log_status(&state
->hdl
, prefix
);
564 switch (state
->mode
) {
565 case MSP_MODE_AM_DETECT
: p
= "AM (for carrier detect)"; break;
566 case MSP_MODE_FM_RADIO
: p
= "FM Radio"; break;
567 case MSP_MODE_FM_TERRA
: p
= "Terrestrial FM-mono/stereo"; break;
568 case MSP_MODE_FM_SAT
: p
= "Satellite FM-mono"; break;
569 case MSP_MODE_FM_NICAM1
: p
= "NICAM/FM (B/G, D/K)"; break;
570 case MSP_MODE_FM_NICAM2
: p
= "NICAM/FM (I)"; break;
571 case MSP_MODE_AM_NICAM
: p
= "NICAM/AM (L)"; break;
572 case MSP_MODE_BTSC
: p
= "BTSC"; break;
573 case MSP_MODE_EXTERN
: p
= "External input"; break;
574 default: p
= "unknown"; break;
576 if (state
->mode
== MSP_MODE_EXTERN
) {
577 dev_info(&client
->dev
, "Mode: %s\n", p
);
578 } else if (state
->opmode
== OPMODE_MANUAL
) {
579 dev_info(&client
->dev
, "Mode: %s (%s%s)\n", p
,
580 (state
->rxsubchans
& V4L2_TUNER_SUB_STEREO
) ? "stereo" : "mono",
581 (state
->rxsubchans
& V4L2_TUNER_SUB_LANG2
) ? ", dual" : "");
583 if (state
->opmode
== OPMODE_AUTODETECT
)
584 dev_info(&client
->dev
, "Mode: %s\n", p
);
585 dev_info(&client
->dev
, "Standard: %s (%s%s)\n",
586 msp_standard_std_name(state
->std
),
587 (state
->rxsubchans
& V4L2_TUNER_SUB_STEREO
) ? "stereo" : "mono",
588 (state
->rxsubchans
& V4L2_TUNER_SUB_LANG2
) ? ", dual" : "");
590 dev_info(&client
->dev
, "Audmode: 0x%04x\n", state
->audmode
);
591 dev_info(&client
->dev
, "Routing: 0x%08x (input) 0x%08x (output)\n",
592 state
->route_in
, state
->route_out
);
593 dev_info(&client
->dev
, "ACB: 0x%04x\n", state
->acb
);
597 #ifdef CONFIG_PM_SLEEP
598 static int msp_suspend(struct device
*dev
)
600 struct i2c_client
*client
= to_i2c_client(dev
);
601 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "suspend\n");
606 static int msp_resume(struct device
*dev
)
608 struct i2c_client
*client
= to_i2c_client(dev
);
609 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "resume\n");
610 msp_wake_thread(client
);
615 /* ----------------------------------------------------------------------- */
617 static const struct v4l2_ctrl_ops msp_ctrl_ops
= {
618 .s_ctrl
= msp_s_ctrl
,
621 static const struct v4l2_subdev_core_ops msp_core_ops
= {
622 .log_status
= msp_log_status
,
625 static const struct v4l2_subdev_video_ops msp_video_ops
= {
627 .querystd
= msp_querystd
,
630 static const struct v4l2_subdev_tuner_ops msp_tuner_ops
= {
631 .s_frequency
= msp_s_frequency
,
632 .g_tuner
= msp_g_tuner
,
633 .s_tuner
= msp_s_tuner
,
634 .s_radio
= msp_s_radio
,
637 static const struct v4l2_subdev_audio_ops msp_audio_ops
= {
638 .s_routing
= msp_s_routing
,
639 .s_i2s_clock_freq
= msp_s_i2s_clock_freq
,
642 static const struct v4l2_subdev_ops msp_ops
= {
643 .core
= &msp_core_ops
,
644 .video
= &msp_video_ops
,
645 .tuner
= &msp_tuner_ops
,
646 .audio
= &msp_audio_ops
,
649 /* ----------------------------------------------------------------------- */
652 static const char * const opmode_str
[] = {
653 [OPMODE_MANUAL
] = "manual",
654 [OPMODE_AUTODETECT
] = "autodetect",
655 [OPMODE_AUTOSELECT
] = "autodetect and autoselect",
658 static int msp_probe(struct i2c_client
*client
)
660 const struct i2c_device_id
*id
= i2c_client_get_device_id(client
);
661 struct msp_state
*state
;
662 struct v4l2_subdev
*sd
;
663 struct v4l2_ctrl_handler
*hdl
;
664 int (*thread_func
)(void *data
) = NULL
;
668 int msp_product
, msp_prod_hi
, msp_prod_lo
;
670 #if defined(CONFIG_MEDIA_CONTROLLER)
675 strscpy(client
->name
, "msp3400", sizeof(client
->name
));
677 if (msp_reset(client
) == -1) {
678 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "msp3400 not found\n");
682 state
= devm_kzalloc(&client
->dev
, sizeof(*state
), GFP_KERNEL
);
687 v4l2_i2c_subdev_init(sd
, client
, &msp_ops
);
689 #if defined(CONFIG_MEDIA_CONTROLLER)
690 state
->pads
[MSP3400_PAD_IF_INPUT
].flags
= MEDIA_PAD_FL_SINK
;
691 state
->pads
[MSP3400_PAD_IF_INPUT
].sig_type
= PAD_SIGNAL_AUDIO
;
692 state
->pads
[MSP3400_PAD_OUT
].flags
= MEDIA_PAD_FL_SOURCE
;
693 state
->pads
[MSP3400_PAD_OUT
].sig_type
= PAD_SIGNAL_AUDIO
;
695 sd
->entity
.function
= MEDIA_ENT_F_IF_AUD_DECODER
;
697 ret
= media_entity_pads_init(&sd
->entity
, 2, state
->pads
);
702 state
->v4l2_std
= V4L2_STD_NTSC
;
703 state
->detected_std
= V4L2_STD_ALL
;
704 state
->audmode
= V4L2_TUNER_MODE_STEREO
;
707 init_waitqueue_head(&state
->wq
);
708 /* These are the reset input/output positions */
709 state
->route_in
= MSP_INPUT_DEFAULT
;
710 state
->route_out
= MSP_OUTPUT_DEFAULT
;
712 state
->rev1
= msp_read_dsp(client
, 0x1e);
713 if (state
->rev1
!= -1)
714 state
->rev2
= msp_read_dsp(client
, 0x1f);
715 dev_dbg_lvl(&client
->dev
, 1, msp_debug
, "rev1=0x%04x, rev2=0x%04x\n",
716 state
->rev1
, state
->rev2
);
717 if (state
->rev1
== -1 || (state
->rev1
== 0 && state
->rev2
== 0)) {
718 dev_dbg_lvl(&client
->dev
, 1, msp_debug
,
719 "not an msp3400 (cannot read chip version)\n");
723 msp_family
= ((state
->rev1
>> 4) & 0x0f) + 3;
724 msp_product
= (state
->rev2
>> 8) & 0xff;
725 msp_prod_hi
= msp_product
/ 10;
726 msp_prod_lo
= msp_product
% 10;
727 msp_revision
= (state
->rev1
& 0x0f) + '@';
728 msp_hard
= ((state
->rev1
>> 8) & 0xff) + '@';
729 msp_rom
= state
->rev2
& 0x1f;
730 /* Rev B=2, C=3, D=4, G=7 */
731 state
->ident
= msp_family
* 10000 + 4000 + msp_product
* 10 +
734 /* Has NICAM support: all mspx41x and mspx45x products have NICAM */
736 msp_prod_hi
== 1 || msp_prod_hi
== 5;
737 /* Has radio support: was added with revision G */
740 /* Has headphones output: not for stripped down products */
741 state
->has_headphones
=
743 /* Has scart2 input: not in stripped down products of the '3' family */
745 msp_family
>= 4 || msp_prod_lo
< 7;
746 /* Has scart3 input: not in stripped down products of the '3' family */
748 msp_family
>= 4 || msp_prod_lo
< 5;
749 /* Has scart4 input: not in pre D revisions, not in stripped D revs */
751 msp_family
>= 4 || (msp_revision
>= 'D' && msp_prod_lo
< 5);
752 /* Has scart2 output: not in stripped down products of
754 state
->has_scart2_out
=
755 msp_family
>= 4 || msp_prod_lo
< 5;
756 /* Has scart2 a volume control? Not in pre-D revisions. */
757 state
->has_scart2_out_volume
=
758 msp_revision
> 'C' && state
->has_scart2_out
;
759 /* Has a configurable i2s out? */
760 state
->has_i2s_conf
=
761 msp_revision
>= 'G' && msp_prod_lo
< 7;
762 /* Has subwoofer output: not in pre-D revs and not in stripped down
764 state
->has_subwoofer
=
765 msp_revision
>= 'D' && msp_prod_lo
< 5;
766 /* Has soundprocessing (bass/treble/balance/loudness/equalizer):
767 * not in stripped down products */
768 state
->has_sound_processing
=
770 /* Has Virtual Dolby Surround: only in msp34x1 */
771 state
->has_virtual_dolby_surround
=
772 msp_revision
== 'G' && msp_prod_lo
== 1;
773 /* Has Virtual Dolby Surround & Dolby Pro Logic: only in msp34x2 */
774 state
->has_dolby_pro_logic
=
775 msp_revision
== 'G' && msp_prod_lo
== 2;
776 /* The msp343xG supports BTSC only and cannot do Automatic Standard
779 msp_family
== 3 && msp_revision
== 'G' && msp_prod_hi
== 3;
781 state
->opmode
= opmode
;
782 if (state
->opmode
< OPMODE_MANUAL
783 || state
->opmode
> OPMODE_AUTOSELECT
) {
784 /* MSP revision G and up have both autodetect and autoselect */
785 if (msp_revision
>= 'G')
786 state
->opmode
= OPMODE_AUTOSELECT
;
787 /* MSP revision D and up have autodetect */
788 else if (msp_revision
>= 'D')
789 state
->opmode
= OPMODE_AUTODETECT
;
791 state
->opmode
= OPMODE_MANUAL
;
795 v4l2_ctrl_handler_init(hdl
, 6);
796 if (state
->has_sound_processing
) {
797 v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
798 V4L2_CID_AUDIO_BASS
, 0, 65535, 65535 / 100, 32768);
799 v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
800 V4L2_CID_AUDIO_TREBLE
, 0, 65535, 65535 / 100, 32768);
801 v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
802 V4L2_CID_AUDIO_LOUDNESS
, 0, 1, 1, 0);
804 state
->volume
= v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
805 V4L2_CID_AUDIO_VOLUME
, 0, 65535, 65535 / 100, 58880);
806 v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
807 V4L2_CID_AUDIO_BALANCE
, 0, 65535, 65535 / 100, 32768);
808 state
->muted
= v4l2_ctrl_new_std(hdl
, &msp_ctrl_ops
,
809 V4L2_CID_AUDIO_MUTE
, 0, 1, 1, 0);
810 sd
->ctrl_handler
= hdl
;
812 int err
= hdl
->error
;
814 v4l2_ctrl_handler_free(hdl
);
818 v4l2_ctrl_cluster(2, &state
->volume
);
819 v4l2_ctrl_handler_setup(hdl
);
821 dev_info(&client
->dev
,
822 "MSP%d4%02d%c-%c%d found on %s: supports %s%s%s, mode is %s\n",
823 msp_family
, msp_product
,
824 msp_revision
, msp_hard
, msp_rom
,
825 client
->adapter
->name
,
826 (state
->has_nicam
) ? "nicam" : "",
827 (state
->has_nicam
&& state
->has_radio
) ? " and " : "",
828 (state
->has_radio
) ? "radio" : "",
829 opmode_str
[state
->opmode
]);
831 /* version-specific initialization */
832 switch (state
->opmode
) {
834 thread_func
= msp3400c_thread
;
836 case OPMODE_AUTODETECT
:
837 thread_func
= msp3410d_thread
;
839 case OPMODE_AUTOSELECT
:
840 thread_func
= msp34xxg_thread
;
844 /* startup control thread if needed */
846 state
->kthread
= kthread_run(thread_func
, client
, "msp34xx");
848 if (IS_ERR(state
->kthread
))
849 dev_warn(&client
->dev
, "kernel_thread() failed\n");
850 msp_wake_thread(client
);
855 static void msp_remove(struct i2c_client
*client
)
857 struct msp_state
*state
= to_state(i2c_get_clientdata(client
));
859 v4l2_device_unregister_subdev(&state
->sd
);
860 /* shutdown control thread */
861 if (state
->kthread
) {
863 kthread_stop(state
->kthread
);
867 v4l2_ctrl_handler_free(&state
->hdl
);
870 /* ----------------------------------------------------------------------- */
872 static const struct dev_pm_ops msp3400_pm_ops
= {
873 SET_SYSTEM_SLEEP_PM_OPS(msp_suspend
, msp_resume
)
876 static const struct i2c_device_id msp_id
[] = {
880 MODULE_DEVICE_TABLE(i2c
, msp_id
);
882 static struct i2c_driver msp_driver
= {
885 .pm
= &msp3400_pm_ops
,
888 .remove
= msp_remove
,
892 module_i2c_driver(msp_driver
);