50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/slab.h>
53 #include <linux/i2c.h>
56 #include <linux/videodev2.h>
93 MODULE_PARM_DESC(opmode,
"Forces a MSP3400 opmode. 0=Manual, 1=Autodetect, 2=Autodetect and autoselect");
96 MODULE_PARM_DESC(stereo_threshold,
"Sets signal threshold to activate stereo");
97 MODULE_PARM_DESC(standard,
"Specify audio standard: 32 = NTSC, 64 = radio, Default: Autodetect");
98 MODULE_PARM_DESC(amsound,
"Hardwire AM sound at 6.5Hz (France), FM can autoscan");
104 #define I2C_MSP_CONTROL 0x00
106 #define I2C_MSP_DEM 0x10
108 #define I2C_MSP_DSP 0x12
129 .addr = client->
addr,
142 .addr = client->
addr,
153 v4l_err(client,
"chip reset failed\n");
171 .addr = client->
addr,
179 write[1] = addr >> 8;
180 write[2] = addr & 0xff;
182 for (err = 0; err < 3; err++) {
185 v4l_warn(client,
"I/O error #%d (read 0x%02x/0x%02x)\n", err,
190 v4l_warn(client,
"resetting chip, sound will go off.\n");
194 retval = read[0] << 8 | read[1];
210 static int msp_write(
struct i2c_client *client,
int dev,
int addr,
int val)
216 buffer[1] = addr >> 8;
217 buffer[2] = addr & 0xff;
218 buffer[3] = val >> 8;
219 buffer[4] = val & 0xff;
223 for (err = 0; err < 3; err++) {
226 v4l_warn(client,
"I/O error #%d (write 0x%02x/0x%02x)\n", err,
231 v4l_warn(client,
"resetting chip, sound will go off.\n");
275 static int scarts[3][9] = {
278 { 0x0320, 0x0000, 0x0200, 0x0300, 0x0020, -1, -1, 0x0100, 0x0320 },
280 { 0x0c40, 0x0440, 0x0400, 0x0000, 0x0840, 0x0c00, 0x0040, 0x0800, 0x0c40 },
282 { 0x3080, 0x1000, 0x1080, 0x2080, 0x3080, 0x0000, 0x0080, 0x2000, 0x3000 },
285 static char *scart_names[] = {
286 "in1",
"in2",
"in3",
"in4",
"in1 da",
"in2 da",
"mono",
"mute"
295 if (in >= 0 && in <= 7 && out >= 0 && out <= 2) {
296 if (-1 == scarts[out][in + 1])
299 state->
acb &= ~scarts[
out][0];
300 state->
acb |= scarts[
out][in + 1];
305 scart_names[in], out, state->
acb);
315 static void msp_wake_thread(
struct i2c_client *client)
350 struct msp_state *state = ctrl_to_state(ctrl);
351 struct i2c_client *client = v4l2_get_subdevdata(&state->
sd);
360 val = (val * 0x7f / 65535) << 8;
363 state->
muted->val ?
"on" :
"off",
368 msp_write_dsp(client, 0x0007, reallymuted ? 0x1 : (val | 0x1));
370 msp_write_dsp(client, 0x0040, reallymuted ? 0x1 : (val | 0x1));
377 val = ((val - 32768) * 0x60 / 65535) << 8;
384 val = ((val - 32768) * 0x60 / 65535) << 8;
391 val = val ? ((5 * 4) << 8) : 0;
398 val = (
u8)((val / 256) - 128);
413 v4l2_ctrl_lock(state->
volume);
416 msp_s_ctrl(state->
volume);
417 v4l2_ctrl_unlock(state->
volume);
424 struct i2c_client *client = v4l2_get_subdevdata(sd);
442 msp_wake_thread(client);
450 struct i2c_client *client = v4l2_get_subdevdata(sd);
453 msp_wake_thread(client);
460 struct i2c_client *client = v4l2_get_subdevdata(sd);
465 "detected standard: %s(0x%08Lx)\n",
474 struct i2c_client *client = v4l2_get_subdevdata(sd);
480 msp_wake_thread(client);
488 struct i2c_client *client = v4l2_get_subdevdata(sd);
489 int tuner = (input >> 3) & 1;
490 int sc_in = input & 0x7;
491 int sc1_out = output & 0xf;
492 int sc2_out = (output >> 4) & 0xf;
495 int extern_input = 1;
502 for (i = 0; i < 5; i++) {
503 if (((input >> (4 + i * 4)) & 0xf) == 0)
516 msp_wake_thread(client);
523 struct i2c_client *client = v4l2_get_subdevdata(sd);
541 struct i2c_client *client = v4l2_get_subdevdata(sd);
556 struct i2c_client *client = v4l2_get_subdevdata(sd);
576 struct i2c_client *client = v4l2_get_subdevdata(sd);
585 struct i2c_client *client = v4l2_get_subdevdata(sd);
591 v4l_info(client,
"%s rev1 = 0x%04x rev2 = 0x%04x\n",
593 snprintf(prefix,
sizeof(prefix),
"%s: Audio: ", sd->
name);
595 switch (state->
mode) {
605 default: p =
"unknown";
break;
610 v4l_info(client,
"Mode: %s (%s%s)\n", p,
616 v4l_info(client,
"Standard: %s (%s%s)\n",
622 v4l_info(client,
"Routing: 0x%08x (input) 0x%08x (output)\n",
628 #ifdef CONFIG_PM_SLEEP
629 static int msp_suspend(
struct device *dev)
637 static int msp_resume(
struct device *dev)
641 msp_wake_thread(client);
649 .s_ctrl = msp_s_ctrl,
653 .log_status = msp_log_status,
654 .g_chip_ident = msp_g_chip_ident,
666 .querystd = msp_querystd,
670 .s_frequency = msp_s_frequency,
671 .g_tuner = msp_g_tuner,
672 .s_tuner = msp_s_tuner,
673 .s_radio = msp_s_radio,
677 .s_routing = msp_s_routing,
678 .s_i2s_clock_freq = msp_s_i2s_clock_freq,
682 .core = &msp_core_ops,
683 .video = &msp_video_ops,
684 .tuner = &msp_tuner_ops,
685 .audio = &msp_audio_ops,
699 int msp_product, msp_prod_hi, msp_prod_lo;
728 if (state->
rev1 != -1)
732 if (state->
rev1 == -1 || (state->
rev1 == 0 && state->
rev2 == 0)) {
734 "not an msp3400 (cannot read chip version)\n");
739 msp_family = ((state->
rev1 >> 4) & 0x0f) + 3;
740 msp_product = (state->
rev2 >> 8) & 0xff;
741 msp_prod_hi = msp_product / 10;
742 msp_prod_lo = msp_product % 10;
743 msp_revision = (state->
rev1 & 0x0f) +
'@';
744 msp_hard = ((state->
rev1 >> 8) & 0xff) +
'@';
745 msp_rom = state->
rev2 & 0x1f;
747 state->
ident = msp_family * 10000 + 4000 + msp_product * 10 +
752 msp_prod_hi == 1 || msp_prod_hi == 5;
761 msp_family >= 4 || msp_prod_lo < 7;
764 msp_family >= 4 || msp_prod_lo < 5;
767 msp_family >= 4 || (msp_revision >=
'D' && msp_prod_lo < 5);
771 msp_family >= 4 || msp_prod_lo < 5;
777 msp_revision >=
'G' && msp_prod_lo < 7;
781 msp_revision >=
'D' && msp_prod_lo < 5;
788 msp_revision ==
'G' && msp_prod_lo == 1;
791 msp_revision ==
'G' && msp_prod_lo == 2;
795 msp_family == 3 && msp_revision ==
'G' && msp_prod_hi == 3;
800 if (msp_revision >=
'G')
803 else if (msp_revision >=
'D')
827 int err = hdl->
error;
838 v4l_info(client,
"MSP%d4%02d%c-%c%d found @ 0x%x (%s)\n",
839 msp_family, msp_product,
840 msp_revision, msp_hard, msp_rom,
873 v4l_warn(client,
"kernel_thread() failed\n");
874 msp_wake_thread(client);
879 static int msp_remove(
struct i2c_client *client)
881 struct msp_state *state = to_state(i2c_get_clientdata(client));
898 static const struct dev_pm_ops msp3400_pm_ops = {
912 .pm = &msp3400_pm_ops,
915 .remove = msp_remove,