Lines Matching +full:dual +full:- +full:radio

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * (c) 1997-2001 Gerd Knorr <kraxel@bytesex.org>
9 * AM-Mono
13 * FM-Mono
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)
20 * FM-Stereo (satellite)
22 * switch to stereo -- untested)
29 * - better SAT support
43 #include <media/v4l2-device.h>
44 #include <media/v4l2-ioctl.h>
45 #include <media/drv-intf/msp3400.h>
47 #include "msp3400-driver.h"
49 /* ---------------------------------------------------------------------- */
59 bool msp_amsound; /* hard-wire AM sound at 6.5 Hz (france),
66 (msp34xxg only) 0x00a0-0x03c0 */
68 /* read-only */
71 /* read-write */
81 MODULE_PARM_DESC(debug, "Enable debug messages [0-3]");
83 MODULE_PARM_DESC(standard, "Specify audio standard: 32 = NTSC, 64 = radio, Default: Autodetect");
87 /* ---------------------------------------------------------------------- */
97 /* ----------------------------------------------------------------------- */
109 .addr = client->addr, in msp_reset()
115 .addr = client->addr, in msp_reset()
123 .addr = client->addr, in msp_reset()
128 .addr = client->addr, in msp_reset()
135 dev_dbg_lvl(&client->dev, 3, msp_debug, "msp_reset\n"); in msp_reset()
136 if (i2c_transfer(client->adapter, &reset[0], 1) != 1 || in msp_reset()
137 i2c_transfer(client->adapter, &reset[1], 1) != 1 || in msp_reset()
138 i2c_transfer(client->adapter, test, 2) != 2) { in msp_reset()
139 dev_err(&client->dev, "chip reset failed\n"); in msp_reset()
140 return -1; in msp_reset()
152 .addr = client->addr, in msp_read()
157 .addr = client->addr, in msp_read()
169 if (i2c_transfer(client->adapter, msgs, 2) == 2) in msp_read()
171 dev_warn(&client->dev, "I/O error #%d (read 0x%02x/0x%02x)\n", err, in msp_read()
176 dev_warn(&client->dev, "resetting chip, sound will go off.\n"); in msp_read()
178 return -1; in msp_read()
181 dev_dbg_lvl(&client->dev, 3, msp_debug, "msp_read(0x%x, 0x%x): 0x%x\n", in msp_read()
207 dev_dbg_lvl(&client->dev, 3, msp_debug, "msp_write(0x%x, 0x%x, 0x%x)\n", in msp_write()
212 dev_warn(&client->dev, "I/O error #%d (write 0x%02x/0x%02x)\n", err, in msp_write()
217 dev_warn(&client->dev, "resetting chip, sound will go off.\n"); in msp_write()
219 return -1; in msp_write()
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
259 * ----------------------------------------------------------------------- */
264 { 0x0320, 0x0000, 0x0200, 0x0300, 0x0020, -1, -1, 0x0100, 0x0320 },
279 state->in_scart = in; in msp_set_scart()
282 if (-1 == scarts[out][in + 1]) in msp_set_scart()
285 state->acb &= ~scarts[out][0]; in msp_set_scart()
286 state->acb |= scarts[out][in + 1]; in msp_set_scart()
288 state->acb = 0xf60; /* Mute Input and SCART 1 Output */ in msp_set_scart()
290 dev_dbg_lvl(&client->dev, 1, msp_debug, "scart switch: %s => %d (ACB=0x%04x)\n", in msp_set_scart()
291 scart_names[in], out, state->acb); in msp_set_scart()
292 msp_write_dsp(client, 0x13, state->acb); in msp_set_scart()
295 if (state->has_i2s_conf) in msp_set_scart()
296 msp_write_dem(client, 0x40, state->i2s_mode); in msp_set_scart()
299 /* ------------------------------------------------------------------------ */
305 if (NULL == state->kthread) in msp_wake_thread()
307 state->watch_stereo = 0; in msp_wake_thread()
308 state->restart = 1; in msp_wake_thread()
309 wake_up_interruptible(&state->wq); in msp_wake_thread()
318 wait_event_freezable_timeout(state->wq, kthread_should_stop() || in msp_sleep()
319 state->restart, timeout); in msp_sleep()
321 return state->restart; in msp_sleep()
324 /* ------------------------------------------------------------------------ */
329 struct i2c_client *client = v4l2_get_subdevdata(&state->sd); in msp_s_ctrl()
330 int val = ctrl->val; in msp_s_ctrl()
332 switch (ctrl->id) { in msp_s_ctrl()
335 int reallymuted = state->muted->val | state->scan_in_progress; in msp_s_ctrl()
340 dev_dbg_lvl(&client->dev, 1, msp_debug, "mute=%s scanning=%s volume=%d\n", in msp_s_ctrl()
341 state->muted->val ? "on" : "off", in msp_s_ctrl()
342 state->scan_in_progress ? "yes" : "no", in msp_s_ctrl()
343 state->volume->val); in msp_s_ctrl()
347 if (state->has_scart2_out_volume) in msp_s_ctrl()
349 if (state->has_headphones) in msp_s_ctrl()
355 val = ((val - 32768) * 0x60 / 65535) << 8; in msp_s_ctrl()
357 if (state->has_headphones) in msp_s_ctrl()
362 val = ((val - 32768) * 0x60 / 65535) << 8; in msp_s_ctrl()
364 if (state->has_headphones) in msp_s_ctrl()
371 if (state->has_headphones) in msp_s_ctrl()
376 val = (u8)((val / 256) - 128); in msp_s_ctrl()
378 if (state->has_headphones) in msp_s_ctrl()
383 return -EINVAL; in msp_s_ctrl()
391 v4l2_ctrl_lock(state->volume); in msp_update_volume()
392 state->volume->val = state->volume->cur.val; in msp_update_volume()
393 state->muted->val = state->muted->cur.val; in msp_update_volume()
394 msp_s_ctrl(state->volume); in msp_update_volume()
395 v4l2_ctrl_unlock(state->volume); in msp_update_volume()
398 /* --- v4l2 ioctls --- */
404 if (state->radio) in msp_s_radio()
406 state->radio = 1; in msp_s_radio()
407 dev_dbg_lvl(&client->dev, 1, msp_debug, "switching to radio mode\n"); in msp_s_radio()
408 state->watch_stereo = 0; in msp_s_radio()
409 switch (state->opmode) { in msp_s_radio()
411 /* set msp3400 to FM radio mode */ in msp_s_radio()
430 /* new channel -- kick audio carrier scan */ in msp_s_frequency()
440 *id &= state->detected_std; in msp_querystd()
442 dev_dbg_lvl(&client->dev, 2, msp_debug, in msp_querystd()
444 msp_standard_std_name(state->std), state->detected_std); in msp_querystd()
453 int update = state->radio || state->v4l2_std != id; in msp_s_std()
455 state->v4l2_std = id; in msp_s_std()
456 state->radio = 0; in msp_s_std()
475 if (state->route_in == input && state->route_out == output) in msp_s_routing()
477 state->route_in = input; in msp_s_routing()
478 state->route_out = output; in msp_s_routing()
484 state->mode = extern_input ? MSP_MODE_EXTERN : MSP_MODE_AM_DETECT; in msp_s_routing()
485 state->rxsubchans = V4L2_TUNER_SUB_STEREO; in msp_s_routing()
490 reg = (state->opmode == OPMODE_AUTOSELECT) ? 0x30 : 0xbb; in msp_s_routing()
503 if (vt->type != V4L2_TUNER_ANALOG_TV) in msp_g_tuner()
505 if (!state->radio) { in msp_g_tuner()
506 if (state->opmode == OPMODE_AUTOSELECT) in msp_g_tuner()
508 vt->rxsubchans = state->rxsubchans; in msp_g_tuner()
510 vt->audmode = state->audmode; in msp_g_tuner()
511 vt->capability |= V4L2_TUNER_CAP_STEREO | in msp_g_tuner()
521 if (state->radio) /* TODO: add mono/stereo support for radio */ in msp_s_tuner()
523 if (state->audmode == vt->audmode) in msp_s_tuner()
525 state->audmode = vt->audmode; in msp_s_tuner()
536 dev_dbg_lvl(&client->dev, 1, msp_debug, "Setting I2S speed to %d\n", freq); in msp_s_i2s_clock_freq()
540 state->i2s_mode = 0; in msp_s_i2s_clock_freq()
543 state->i2s_mode = 1; in msp_s_i2s_clock_freq()
546 return -EINVAL; in msp_s_i2s_clock_freq()
556 char prefix[sizeof(sd->name) + 20]; in msp_log_status()
558 if (state->opmode == OPMODE_AUTOSELECT) in msp_log_status()
560 dev_info(&client->dev, "%s rev1 = 0x%04x rev2 = 0x%04x\n", in msp_log_status()
561 client->name, state->rev1, state->rev2); in msp_log_status()
562 snprintf(prefix, sizeof(prefix), "%s: Audio: ", sd->name); in msp_log_status()
563 v4l2_ctrl_handler_log_status(&state->hdl, prefix); in msp_log_status()
564 switch (state->mode) { in msp_log_status()
566 case MSP_MODE_FM_RADIO: p = "FM Radio"; break; in msp_log_status()
567 case MSP_MODE_FM_TERRA: p = "Terrestrial FM-mono/stereo"; break; in msp_log_status()
568 case MSP_MODE_FM_SAT: p = "Satellite FM-mono"; break; in msp_log_status()
576 if (state->mode == MSP_MODE_EXTERN) { in msp_log_status()
577 dev_info(&client->dev, "Mode: %s\n", p); in msp_log_status()
578 } else if (state->opmode == OPMODE_MANUAL) { in msp_log_status()
579 dev_info(&client->dev, "Mode: %s (%s%s)\n", p, in msp_log_status()
580 (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono", in msp_log_status()
581 (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : ""); in msp_log_status()
583 if (state->opmode == OPMODE_AUTODETECT) in msp_log_status()
584 dev_info(&client->dev, "Mode: %s\n", p); in msp_log_status()
585 dev_info(&client->dev, "Standard: %s (%s%s)\n", in msp_log_status()
586 msp_standard_std_name(state->std), in msp_log_status()
587 (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono", in msp_log_status()
588 (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : ""); in msp_log_status()
590 dev_info(&client->dev, "Audmode: 0x%04x\n", state->audmode); in msp_log_status()
591 dev_info(&client->dev, "Routing: 0x%08x (input) 0x%08x (output)\n", in msp_log_status()
592 state->route_in, state->route_out); in msp_log_status()
593 dev_info(&client->dev, "ACB: 0x%04x\n", state->acb); in msp_log_status()
601 dev_dbg_lvl(&client->dev, 1, msp_debug, "suspend\n"); in msp_suspend()
609 dev_dbg_lvl(&client->dev, 1, msp_debug, "resume\n"); in msp_resume()
615 /* ----------------------------------------------------------------------- */
649 /* ----------------------------------------------------------------------- */
675 strscpy(client->name, "msp3400", sizeof(client->name)); in msp_probe()
677 if (msp_reset(client) == -1) { in msp_probe()
678 dev_dbg_lvl(&client->dev, 1, msp_debug, "msp3400 not found\n"); in msp_probe()
679 return -ENODEV; in msp_probe()
682 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); in msp_probe()
684 return -ENOMEM; in msp_probe()
686 sd = &state->sd; in msp_probe()
690 state->pads[MSP3400_PAD_IF_INPUT].flags = MEDIA_PAD_FL_SINK; in msp_probe()
691 state->pads[MSP3400_PAD_IF_INPUT].sig_type = PAD_SIGNAL_AUDIO; in msp_probe()
692 state->pads[MSP3400_PAD_OUT].flags = MEDIA_PAD_FL_SOURCE; in msp_probe()
693 state->pads[MSP3400_PAD_OUT].sig_type = PAD_SIGNAL_AUDIO; in msp_probe()
695 sd->entity.function = MEDIA_ENT_F_IF_AUD_DECODER; in msp_probe()
697 ret = media_entity_pads_init(&sd->entity, 2, state->pads); in msp_probe()
702 state->v4l2_std = V4L2_STD_NTSC; in msp_probe()
703 state->detected_std = V4L2_STD_ALL; in msp_probe()
704 state->audmode = V4L2_TUNER_MODE_STEREO; in msp_probe()
705 state->input = -1; in msp_probe()
706 state->i2s_mode = 0; in msp_probe()
707 init_waitqueue_head(&state->wq); in msp_probe()
709 state->route_in = MSP_INPUT_DEFAULT; in msp_probe()
710 state->route_out = MSP_OUTPUT_DEFAULT; in msp_probe()
712 state->rev1 = msp_read_dsp(client, 0x1e); in msp_probe()
713 if (state->rev1 != -1) in msp_probe()
714 state->rev2 = msp_read_dsp(client, 0x1f); in msp_probe()
715 dev_dbg_lvl(&client->dev, 1, msp_debug, "rev1=0x%04x, rev2=0x%04x\n", in msp_probe()
716 state->rev1, state->rev2); in msp_probe()
717 if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) { in msp_probe()
718 dev_dbg_lvl(&client->dev, 1, msp_debug, in msp_probe()
720 return -ENODEV; in msp_probe()
723 msp_family = ((state->rev1 >> 4) & 0x0f) + 3; in msp_probe()
724 msp_product = (state->rev2 >> 8) & 0xff; in msp_probe()
727 msp_revision = (state->rev1 & 0x0f) + '@'; in msp_probe()
728 msp_hard = ((state->rev1 >> 8) & 0xff) + '@'; in msp_probe()
729 msp_rom = state->rev2 & 0x1f; in msp_probe()
731 state->ident = msp_family * 10000 + 4000 + msp_product * 10 + in msp_probe()
732 msp_revision - '@'; in msp_probe()
735 state->has_nicam = in msp_probe()
737 /* Has radio support: was added with revision G */ in msp_probe()
738 state->has_radio = in msp_probe()
741 state->has_headphones = in msp_probe()
744 state->has_scart2 = in msp_probe()
747 state->has_scart3 = in msp_probe()
750 state->has_scart4 = in msp_probe()
754 state->has_scart2_out = in msp_probe()
756 /* Has scart2 a volume control? Not in pre-D revisions. */ in msp_probe()
757 state->has_scart2_out_volume = in msp_probe()
758 msp_revision > 'C' && state->has_scart2_out; in msp_probe()
760 state->has_i2s_conf = in msp_probe()
762 /* Has subwoofer output: not in pre-D revs and not in stripped down in msp_probe()
764 state->has_subwoofer = in msp_probe()
768 state->has_sound_processing = in msp_probe()
771 state->has_virtual_dolby_surround = in msp_probe()
774 state->has_dolby_pro_logic = in msp_probe()
778 state->force_btsc = in msp_probe()
781 state->opmode = opmode; in msp_probe()
782 if (state->opmode < OPMODE_MANUAL in msp_probe()
783 || state->opmode > OPMODE_AUTOSELECT) { in msp_probe()
786 state->opmode = OPMODE_AUTOSELECT; in msp_probe()
789 state->opmode = OPMODE_AUTODETECT; in msp_probe()
791 state->opmode = OPMODE_MANUAL; in msp_probe()
794 hdl = &state->hdl; in msp_probe()
796 if (state->has_sound_processing) { in msp_probe()
804 state->volume = v4l2_ctrl_new_std(hdl, &msp_ctrl_ops, in msp_probe()
808 state->muted = v4l2_ctrl_new_std(hdl, &msp_ctrl_ops, in msp_probe()
810 sd->ctrl_handler = hdl; in msp_probe()
811 if (hdl->error) { in msp_probe()
812 int err = hdl->error; in msp_probe()
818 v4l2_ctrl_cluster(2, &state->volume); in msp_probe()
821 dev_info(&client->dev, in msp_probe()
822 "MSP%d4%02d%c-%c%d found on %s: supports %s%s%s, mode is %s\n", in msp_probe()
825 client->adapter->name, in msp_probe()
826 (state->has_nicam) ? "nicam" : "", in msp_probe()
827 (state->has_nicam && state->has_radio) ? " and " : "", in msp_probe()
828 (state->has_radio) ? "radio" : "", in msp_probe()
829 opmode_str[state->opmode]); in msp_probe()
831 /* version-specific initialization */ in msp_probe()
832 switch (state->opmode) { in msp_probe()
846 state->kthread = kthread_run(thread_func, client, "msp34xx"); in msp_probe()
848 if (IS_ERR(state->kthread)) in msp_probe()
849 dev_warn(&client->dev, "kernel_thread() failed\n"); in msp_probe()
859 v4l2_device_unregister_subdev(&state->sd); in msp_remove()
861 if (state->kthread) { in msp_remove()
862 state->restart = 1; in msp_remove()
863 kthread_stop(state->kthread); in msp_remove()
867 v4l2_ctrl_handler_free(&state->hdl); in msp_remove()
870 /* ----------------------------------------------------------------------- */