Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

V4L/DVB (3582): Implement correct msp3400 input/output routing

- implement VIDIOC_INT_S_AUDIO_ROUTING for msp3400 and tvaudio
- use the new command in bttv, pvrusb2 and em28xx.
- remove the now obsolete MSP_SET_MATRIX from msp3400 (yeah!)
- remove the obsolete VIDIOC_S_AUDIO from msp3400.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
2474ed44 49965a80

+181 -119
+43 -9
drivers/media/video/bt8xx/bttv-driver.c
··· 37 37 #include "bttvp.h" 38 38 #include <media/v4l2-common.h> 39 39 #include <media/tvaudio.h> 40 + #include <media/msp3400.h> 40 41 41 42 #include <linux/dma-mapping.h> 42 43 ··· 935 934 audio_mux(struct bttv *btv, int input, int mute) 936 935 { 937 936 int gpio_val, signal; 938 - struct v4l2_audio aud_input; 939 937 struct v4l2_control ctrl; 940 938 struct i2c_client *c; 941 939 942 - memset(&aud_input, 0, sizeof(aud_input)); 943 940 gpio_inout(bttv_tvcards[btv->c.type].gpiomask, 944 941 bttv_tvcards[btv->c.type].gpiomask); 945 942 signal = btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC; ··· 952 953 gpio_val = bttv_tvcards[btv->c.type].gpiomute; 953 954 else 954 955 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input]; 955 - aud_input.index = btv->audio; 956 956 957 957 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val); 958 958 if (bttv_gpio) ··· 960 962 return 0; 961 963 962 964 ctrl.id = V4L2_CID_AUDIO_MUTE; 963 - /* take automute into account, just btv->mute is not enough */ 964 - ctrl.value = mute; 965 + ctrl.value = btv->mute; 965 966 bttv_call_i2c_clients(btv, VIDIOC_S_CTRL, &ctrl); 966 967 c = btv->i2c_msp34xx_client; 967 - if (c) 968 - c->driver->command(c, VIDIOC_S_AUDIO, &aud_input); 968 + if (c) { 969 + struct v4l2_routing route; 970 + 971 + /* Note: the inputs tuner/radio/extern/intern are translated 972 + to msp routings. This assumes common behavior for all msp3400 973 + based TV cards. When this assumption fails, then the 974 + specific MSP routing must be added to the card table. 975 + For now this is sufficient. */ 976 + switch (input) { 977 + case TVAUDIO_INPUT_RADIO: 978 + route.input = MSP_INPUT(MSP_IN_SCART_2, MSP_IN_TUNER_1, 979 + MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART); 980 + break; 981 + case TVAUDIO_INPUT_EXTERN: 982 + route.input = MSP_INPUT(MSP_IN_SCART_1, MSP_IN_TUNER_1, 983 + MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART); 984 + break; 985 + case TVAUDIO_INPUT_INTERN: 986 + /* Yes, this is the same input as for RADIO. I doubt 987 + if this is ever used. The only board with an INTERN 988 + input is the BTTV_BOARD_AVERMEDIA98. I wonder how 989 + that was tested. My guess is that the whole INTERN 990 + input does not work. */ 991 + route.input = MSP_INPUT(MSP_IN_SCART_2, MSP_IN_TUNER_1, 992 + MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART); 993 + break; 994 + case TVAUDIO_INPUT_TUNER: 995 + default: 996 + route.input = MSP_INPUT_DEFAULT; 997 + break; 998 + } 999 + route.output = MSP_OUTPUT_DEFAULT; 1000 + c->driver->command(c, VIDIOC_INT_S_AUDIO_ROUTING, &route); 1001 + } 969 1002 c = btv->i2c_tvaudio_client; 970 - if (c) 971 - c->driver->command(c, VIDIOC_S_AUDIO, &aud_input); 1003 + if (c) { 1004 + struct v4l2_routing route; 1005 + 1006 + route.input = input; 1007 + route.output = 0; 1008 + c->driver->command(c, VIDIOC_INT_S_AUDIO_ROUTING, &route); 1009 + } 972 1010 return 0; 973 1011 } 974 1012
+5 -3
drivers/media/video/em28xx/em28xx-cards.c
··· 28 28 #include <linux/i2c.h> 29 29 #include <linux/usb.h> 30 30 #include <media/tuner.h> 31 - #include <media/audiochip.h> 31 + #include <media/msp3400.h> 32 32 #include <media/tveeprom.h> 33 + #include <media/audiochip.h> 33 34 #include <media/v4l2-common.h> 34 35 35 36 #include "em28xx.h" ··· 147 146 .input = {{ 148 147 .type = EM28XX_VMUX_TELEVISION, 149 148 .vmux = 0, 150 - .amux = 6, 149 + .amux = MSP_INPUT_DEFAULT, 151 150 },{ 152 151 .type = EM28XX_VMUX_SVIDEO, 153 152 .vmux = 2, 154 - .amux = 1, 153 + .amux = MSP_INPUT(MSP_IN_SCART_1, MSP_IN_TUNER_1, 154 + MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART), 155 155 }}, 156 156 }, 157 157 [EM2820_BOARD_MSI_VOX_USB_2] = {
+7 -1
drivers/media/video/em28xx/em28xx-video.c
··· 38 38 #include "em28xx.h" 39 39 #include <media/tuner.h> 40 40 #include <media/v4l2-common.h> 41 + #include <media/msp3400.h> 41 42 42 43 #define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \ 43 44 "Markus Rechberger <mrechberger@gmail.com>, " \ ··· 217 216 em28xx_videodbg("Setting input index=%d, vmux=%d, amux=%d\n",index,input,dev->ctl_ainput); 218 217 219 218 if (dev->has_msp34xx) { 219 + struct v4l2_routing route; 220 + 220 221 if (dev->i2s_speed) 221 222 em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, &dev->i2s_speed); 222 - em28xx_i2c_call_clients(dev, VIDIOC_S_AUDIO, &dev->ctl_ainput); 223 + route.input = dev->ctl_ainput; 224 + route.output = MSP_OUTPUT(MSP_OUT_SCART1_DA); 225 + /* Note: this is msp3400 specific */ 226 + em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, &route); 223 227 ainput = EM28XX_AUDIO_SRC_TUNER; 224 228 em28xx_audio_source(dev, ainput); 225 229 } else {
+31 -36
drivers/media/video/msp3400-driver.c
··· 555 555 static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) 556 556 { 557 557 struct msp_state *state = i2c_get_clientdata(client); 558 - int scart = -1; 559 558 560 559 if (msp_debug >= 2) 561 560 v4l_i2c_print_ioctl(client, cmd); ··· 659 660 break; 660 661 } 661 662 662 - /* msp34xx specific */ 663 - case MSP_SET_MATRIX: 664 - { 665 - struct msp_matrix *mspm = arg; 666 - 667 - msp_set_scart(client, mspm->input - 1, mspm->output); 668 - break; 669 - } 670 - 671 663 /* --- v4l2 ioctls --- */ 672 664 case VIDIOC_S_STD: 673 665 { ··· 672 682 return 0; 673 683 } 674 684 675 - case VIDIOC_S_AUDIO: 685 + case VIDIOC_INT_G_AUDIO_ROUTING: 676 686 { 677 - struct v4l2_audio *sarg = arg; 687 + struct v4l2_routing *rt = arg; 678 688 679 - switch (sarg->index) { 680 - case TVAUDIO_INPUT_RADIO: 681 - /* Hauppauge uses IN2 for the radio */ 682 - state->mode = MSP_MODE_FM_RADIO; 683 - scart = SCART_IN2; 684 - break; 685 - case TVAUDIO_INPUT_EXTERN: 686 - /* IN1 is often used for external input ... */ 687 - state->mode = MSP_MODE_EXTERN; 688 - scart = SCART_IN1; 689 - break; 690 - case TVAUDIO_INPUT_INTERN: 691 - /* ... sometimes it is IN2 through ;) */ 692 - state->mode = MSP_MODE_EXTERN; 693 - scart = SCART_IN2; 694 - break; 695 - case TVAUDIO_INPUT_TUNER: 696 - state->mode = -1; 697 - break; 689 + *rt = state->routing; 690 + break; 691 + } 692 + 693 + case VIDIOC_INT_S_AUDIO_ROUTING: 694 + { 695 + struct v4l2_routing *rt = arg; 696 + int tuner = (rt->input >> 3) & 1; 697 + int old_tuner = (state->routing.input >> 3) & 1; 698 + int sc_in = rt->input & 0x7; 699 + int sc1_out = rt->output & 0xf; 700 + int sc2_out = (rt->output >> 4) & 0xf; 701 + u16 val; 702 + 703 + state->routing = *rt; 704 + if (state->opmode == OPMODE_AUTOSELECT) { 705 + val = msp_read_dem(client, 0x30) & ~0x100; 706 + msp_write_dem(client, 0x30, val | (tuner ? 0x100 : 0)); 707 + } else { 708 + val = msp_read_dem(client, 0xbb) & ~0x100; 709 + msp_write_dem(client, 0xbb, val | (tuner ? 0x100 : 0)); 698 710 } 699 - if (scart >= 0) { 700 - state->rxsubchans = V4L2_TUNER_SUB_STEREO; 701 - msp_set_scart(client, scart, 0); 702 - } 711 + msp_set_scart(client, sc_in, 0); 712 + msp_set_scart(client, sc1_out, 1); 713 + msp_set_scart(client, sc2_out, 2); 703 714 msp_set_audmode(client); 704 - msp_wake_thread(client); 715 + if (tuner != old_tuner) 716 + msp_wake_thread(client); 705 717 break; 706 718 } 707 719 ··· 933 941 state->muted = 0; 934 942 state->i2s_mode = 0; 935 943 init_waitqueue_head(&state->wq); 944 + /* These are the reset input/output positions */ 945 + state->routing.input = MSP_INPUT_DEFAULT; 946 + state->routing.output = MSP_OUTPUT_DEFAULT; 936 947 937 948 state->rev1 = msp_read_dsp(client, 0x1e); 938 949 if (state->rev1 != -1)
+3 -1
drivers/media/video/msp3400-driver.h
··· 4 4 #ifndef MSP3400_DRIVER_H 5 5 #define MSP3400_DRIVER_H 6 6 7 + #include <media/msp3400.h> 8 + 7 9 /* ---------------------------------------------------------------------- */ 8 10 9 11 /* This macro is allowed for *constants* only, gcc must calculate it ··· 74 72 int i2s_mode; 75 73 int main, second; /* sound carrier */ 76 74 int input; 77 - int source; /* see msp34xxg_set_source */ 75 + struct v4l2_routing routing; 78 76 79 77 /* v4l2 */ 80 78 int audmode;
+60 -51
drivers/media/video/msp3400-kthreads.c
··· 187 187 { 188 188 struct msp_state *state = i2c_get_clientdata(client); 189 189 struct msp3400c_init_data_dem *data = &msp3400c_init_data[mode]; 190 + int tuner = (state->routing.input >> 3) & 1; 190 191 int i; 191 192 192 193 v4l_dbg(1, msp_debug, client, "set_mode: %d\n", mode); 193 194 state->mode = mode; 194 195 state->rxsubchans = V4L2_TUNER_SUB_MONO; 195 196 196 - msp_write_dem(client, 0x00bb, data->ad_cv); 197 + msp_write_dem(client, 0x00bb, data->ad_cv | (tuner ? 0x100 : 0)); 197 198 198 199 for (i = 5; i >= 0; i--) /* fir 1 */ 199 200 msp_write_dem(client, 0x0001, data->fir1[i]); ··· 784 783 * struct msp: only norm, acb and source are really used in this mode 785 784 */ 786 785 787 - /* set the same 'source' for the loudspeaker, scart and quasi-peak detector 788 - * the value for source is the same as bit 15:8 of DSP registers 0x08, 789 - * 0x0a and 0x0c: 0=mono, 1=stereo or A|B, 2=SCART, 3=stereo or A, 4=stereo or B 790 - */ 791 - static void msp34xxg_set_source(struct i2c_client *client, int source) 792 - { 793 - struct msp_state *state = i2c_get_clientdata(client); 794 - 795 - /* fix matrix mode to stereo and let the msp choose what 796 - * to output according to 'source', as recommended 797 - * for MONO (source==0) downmixing set bit[7:0] to 0x30 798 - */ 799 - int value = (source & 0x07) << 8 | (source == 0 ? 0x30 : 0x20); 800 - 801 - v4l_dbg(1, msp_debug, client, "set source to %d (0x%x)\n", source, value); 802 - msp_set_source(client, value); 803 - /* 804 - * set identification threshold. Personally, I 805 - * I set it to a higher value that the default 806 - * of 0x190 to ignore noisy stereo signals. 807 - * this needs tuning. (recommended range 0x00a0-0x03c0) 808 - * 0x7f0 = forced mono mode 809 - */ 810 - /* a2 threshold for stereo/bilingual */ 811 - msp_write_dem(client, 0x22, msp_stereo_thresh); 812 - state->source = source; 813 - } 814 - 815 786 static int msp34xxg_modus(struct i2c_client *client) 816 787 { 817 788 struct msp_state *state = i2c_get_clientdata(client); ··· 816 843 return 0x0001; 817 844 } 818 845 846 + static void msp34xxg_set_source(struct i2c_client *client, u16 reg, int in) 847 + { 848 + struct msp_state *state = i2c_get_clientdata(client); 849 + int source, matrix; 850 + 851 + switch (state->audmode) { 852 + case V4L2_TUNER_MODE_MONO: 853 + source = 0; /* mono only */ 854 + matrix = 0x30; 855 + break; 856 + case V4L2_TUNER_MODE_LANG1: 857 + source = 3; /* stereo or A */ 858 + matrix = 0x00; 859 + break; 860 + case V4L2_TUNER_MODE_LANG2: 861 + source = 4; /* stereo or B */ 862 + matrix = 0x10; 863 + break; 864 + case V4L2_TUNER_MODE_STEREO: 865 + default: 866 + source = 1; /* stereo or A|B */ 867 + matrix = 0x20; 868 + break; 869 + } 870 + 871 + if (in == MSP_DSP_OUT_TUNER) 872 + source = (source << 8) | 0x20; 873 + /* the msp34x2g puts the MAIN_AVC, MAIN and AUX sources in 12, 13, 14 874 + instead of 11, 12, 13. So we add one for that msp version. */ 875 + else if (in >= MSP_DSP_OUT_MAIN_AVC && state->has_dolby_pro_logic) 876 + source = ((in + 1) << 8) | matrix; 877 + else 878 + source = (in << 8) | matrix; 879 + 880 + v4l_dbg(1, msp_debug, client, "set source to %d (0x%x) for output %02x\n", 881 + in, source, reg); 882 + msp_write_dsp(client, reg, source); 883 + } 884 + 885 + static void msp34xxg_set_sources(struct i2c_client *client) 886 + { 887 + struct msp_state *state = i2c_get_clientdata(client); 888 + u32 in = state->routing.input; 889 + 890 + msp34xxg_set_source(client, 0x0008, (in >> 4) & 0xf); 891 + /* quasi-peak detector is set to same input as the loudspeaker (MAIN) */ 892 + msp34xxg_set_source(client, 0x000c, (in >> 4) & 0xf); 893 + msp34xxg_set_source(client, 0x0009, (in >> 8) & 0xf); 894 + msp34xxg_set_source(client, 0x000a, (in >> 12) & 0xf); 895 + if (state->has_scart23_in_scart2_out) 896 + msp34xxg_set_source(client, 0x0041, (in >> 16) & 0xf); 897 + msp34xxg_set_source(client, 0x000b, (in >> 20) & 0xf); 898 + } 899 + 819 900 /* (re-)initialize the msp34xxg */ 820 901 static void msp34xxg_reset(struct i2c_client *client) 821 902 { 822 903 struct msp_state *state = i2c_get_clientdata(client); 904 + int tuner = (state->routing.input >> 3) & 1; 823 905 int modus; 824 906 825 907 /* initialize std to 1 (autodetect) to signal that no standard is ··· 892 864 893 865 /* step-by-step initialisation, as described in the manual */ 894 866 modus = msp34xxg_modus(client); 867 + modus |= tuner ? 0x100 : 0; 895 868 msp_write_dem(client, 0x30, modus); 896 869 897 870 /* write the dsps that may have an influence on 898 871 standard/audio autodetection right now */ 899 - msp34xxg_set_source(client, state->source); 872 + msp34xxg_set_sources(client); 900 873 901 874 msp_write_dsp(client, 0x0d, 0x1900); /* scart */ 902 875 msp_write_dsp(client, 0x0e, 0x3000); /* FM */ ··· 925 896 926 897 v4l_dbg(1, msp_debug, client, "msp34xxg daemon started\n"); 927 898 928 - state->source = 1; /* default */ 929 899 for (;;) { 930 900 v4l_dbg(2, msp_debug, client, "msp34xxg thread: sleep\n"); 931 901 msp_sleep(state, -1); ··· 1021 993 static void msp34xxg_set_audmode(struct i2c_client *client) 1022 994 { 1023 995 struct msp_state *state = i2c_get_clientdata(client); 1024 - int source; 1025 996 1026 997 if (state->std == 0x20) { 1027 998 if ((state->rxsubchans & V4L2_TUNER_SUB_SAP) && ··· 1032 1005 } 1033 1006 } 1034 1007 1035 - switch (state->audmode) { 1036 - case V4L2_TUNER_MODE_MONO: 1037 - source = 0; /* mono only */ 1038 - break; 1039 - case V4L2_TUNER_MODE_STEREO: 1040 - source = 1; /* stereo or A|B, see comment in msp34xxg_get_v4l2_stereo() */ 1041 - /* problem: that could also mean 2 (scart input) */ 1042 - break; 1043 - case V4L2_TUNER_MODE_LANG1: 1044 - source = 3; /* stereo or A */ 1045 - break; 1046 - case V4L2_TUNER_MODE_LANG2: 1047 - source = 4; /* stereo or B */ 1048 - break; 1049 - default: 1050 - source = 1; 1051 - break; 1052 - } 1053 - msp34xxg_set_source(client, source); 1008 + msp34xxg_set_sources(client); 1054 1009 } 1055 1010 1056 1011 void msp_set_audmode(struct i2c_client *client)
+24
drivers/media/video/tvaudio.c
··· 1682 1682 case VIDIOC_S_CTRL: 1683 1683 return tvaudio_set_ctrl(chip, arg); 1684 1684 1685 + case VIDIOC_INT_G_AUDIO_ROUTING: 1686 + { 1687 + struct v4l2_routing *rt = arg; 1688 + 1689 + rt->input = chip->input; 1690 + rt->output = 0; 1691 + break; 1692 + } 1693 + 1694 + case VIDIOC_INT_S_AUDIO_ROUTING: 1695 + { 1696 + struct v4l2_routing *rt = arg; 1697 + 1698 + if (!(desc->flags & CHIP_HAS_INPUTSEL) || rt->input >= 4) 1699 + return -EINVAL; 1700 + /* There are four inputs: tuner, radio, extern and intern. */ 1701 + chip->input = rt->input; 1702 + if (chip->muted) 1703 + break; 1704 + chip_write_masked(chip, desc->inputreg, 1705 + desc->inputmap[chip->input], desc->inputmask); 1706 + break; 1707 + } 1708 + 1685 1709 case VIDIOC_S_AUDIO: 1686 1710 { 1687 1711 struct v4l2_audio *sarg = arg;
+3 -10
drivers/media/video/v4l2-common.c
··· 312 312 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP", 313 313 #endif 314 314 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO", 315 - [_IOC_NR(MSP_SET_MATRIX)] = "MSP_SET_MATRIX", 316 315 317 316 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR", 318 317 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY", ··· 430 431 printk ("%s: value=%d\n", s, *p); 431 432 break; 432 433 } 433 - case MSP_SET_MATRIX: 434 - { 435 - struct msp_matrix *p=arg; 436 - printk ("%s: input=%d, output=%d\n", s, p->input, p->output); 437 - break; 438 - } 439 434 case VIDIOC_G_AUDIO: 440 435 case VIDIOC_S_AUDIO: 441 436 case VIDIOC_ENUMAUDIO: ··· 458 465 struct v4l2_buffer *p=arg; 459 466 struct v4l2_timecode *tc=&p->timecode; 460 467 printk ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, " 461 - "bytesused=%d, flags=0x%08d, " 468 + "bytesused=%d, flags=0x%08x, " 462 469 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx\n", 463 470 s, 464 471 (p->timestamp.tv_sec/3600), ··· 472 479 prt_names(p->memory,v4l2_memory_names), 473 480 p->m.userptr); 474 481 printk ("%s: timecode= %02d:%02d:%02d type=%d, " 475 - "flags=0x%08d, frames=%d, userbits=0x%p", 482 + "flags=0x%08x, frames=%d, userbits=0x%08p\n", 476 483 s,tc->hours,tc->minutes,tc->seconds, 477 484 tc->type, tc->flags, tc->frames, tc->userbits); 478 485 break; ··· 658 665 case VIDIOC_INT_G_VIDEO_ROUTING: 659 666 { 660 667 struct v4l2_routing *p=arg; 661 - printk ("%s: input=%d, output=%d\n", s, p->input, p->output); 668 + printk ("%s: input=0x%x, output=0x%x\n", s, p->input, p->output); 662 669 break; 663 670 } 664 671 case VIDIOC_G_SLICED_VBI_CAP:
+5
include/media/msp3400.h
··· 145 145 MSP_DSP_TO_SCART1(sc_i2s_src) | \ 146 146 MSP_DSP_TO_SCART2(sc_i2s_src) | \ 147 147 MSP_DSP_TO_I2S(sc_i2s_src)) 148 + #define MSP_INPUT_DEFAULT MSP_INPUT(MSP_IN_SCART_1, MSP_IN_TUNER_1, \ 149 + MSP_DSP_OUT_TUNER, MSP_DSP_OUT_TUNER) 148 150 #define MSP_OUTPUT(sc) \ 149 151 (MSP_OUT_TO_SCART1(sc) | \ 150 152 MSP_OUT_TO_SCART2(sc)) 153 + /* This equals the RESET position of the msp3400 ACB register */ 154 + #define MSP_OUTPUT_DEFAULT (MSP_OUT_TO_SCART1(MSP_OUT_SCART3) | \ 155 + MSP_OUT_TO_SCART2(MSP_OUT_SCART1_DA)) 151 156 152 157 /* Tuner inputs vs. msp version */ 153 158 /* Chip TUNER_1 TUNER_2
-8
include/media/v4l2-common.h
··· 123 123 /* v4l device was opened in Radio mode, to be replaced by VIDIOC_INT_S_TUNER_MODE */ 124 124 #define AUDC_SET_RADIO _IO('d',88) 125 125 126 - /* msp3400 ioctl: will be removed in the near future, to be replaced by 127 - VIDIOC_INT_S_AUDIO_ROUTING. */ 128 - struct msp_matrix { 129 - int input; 130 - int output; 131 - }; 132 - #define MSP_SET_MATRIX _IOW('m',17,struct msp_matrix) 133 - 134 126 /* tuner ioctls */ 135 127 136 128 /* Sets tuner type and its I2C addr */