1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun Audio/video-routing-related ivtv functions.
4*4882a593Smuzhiyun Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
5*4882a593Smuzhiyun Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include "ivtv-driver.h"
10*4882a593Smuzhiyun #include "ivtv-i2c.h"
11*4882a593Smuzhiyun #include "ivtv-cards.h"
12*4882a593Smuzhiyun #include "ivtv-gpio.h"
13*4882a593Smuzhiyun #include "ivtv-routing.h"
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include <media/drv-intf/msp3400.h>
16*4882a593Smuzhiyun #include <media/i2c/m52790.h>
17*4882a593Smuzhiyun #include <media/i2c/upd64031a.h>
18*4882a593Smuzhiyun #include <media/i2c/upd64083.h>
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun /* Selects the audio input and output according to the current
21*4882a593Smuzhiyun settings. */
ivtv_audio_set_io(struct ivtv * itv)22*4882a593Smuzhiyun void ivtv_audio_set_io(struct ivtv *itv)
23*4882a593Smuzhiyun {
24*4882a593Smuzhiyun const struct ivtv_card_audio_input *in;
25*4882a593Smuzhiyun u32 input, output = 0;
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun /* Determine which input to use */
28*4882a593Smuzhiyun if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags))
29*4882a593Smuzhiyun in = &itv->card->radio_input;
30*4882a593Smuzhiyun else
31*4882a593Smuzhiyun in = &itv->card->audio_inputs[itv->audio_input];
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun /* handle muxer chips */
34*4882a593Smuzhiyun input = in->muxer_input;
35*4882a593Smuzhiyun if (itv->card->hw_muxer & IVTV_HW_M52790)
36*4882a593Smuzhiyun output = M52790_OUT_STEREO;
37*4882a593Smuzhiyun v4l2_subdev_call(itv->sd_muxer, audio, s_routing,
38*4882a593Smuzhiyun input, output, 0);
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun input = in->audio_input;
41*4882a593Smuzhiyun output = 0;
42*4882a593Smuzhiyun if (itv->card->hw_audio & IVTV_HW_MSP34XX)
43*4882a593Smuzhiyun output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
44*4882a593Smuzhiyun ivtv_call_hw(itv, itv->card->hw_audio, audio, s_routing,
45*4882a593Smuzhiyun input, output, 0);
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun /* Selects the video input and output according to the current
49*4882a593Smuzhiyun settings. */
ivtv_video_set_io(struct ivtv * itv)50*4882a593Smuzhiyun void ivtv_video_set_io(struct ivtv *itv)
51*4882a593Smuzhiyun {
52*4882a593Smuzhiyun int inp = itv->active_input;
53*4882a593Smuzhiyun u32 input;
54*4882a593Smuzhiyun u32 type;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun v4l2_subdev_call(itv->sd_video, video, s_routing,
57*4882a593Smuzhiyun itv->card->video_inputs[inp].video_input, 0, 0);
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun type = itv->card->video_inputs[inp].video_type;
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun if (type == IVTV_CARD_INPUT_VID_TUNER) {
62*4882a593Smuzhiyun input = 0; /* Tuner */
63*4882a593Smuzhiyun } else if (type < IVTV_CARD_INPUT_COMPOSITE1) {
64*4882a593Smuzhiyun input = 2; /* S-Video */
65*4882a593Smuzhiyun } else {
66*4882a593Smuzhiyun input = 1; /* Composite */
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun if (itv->card->hw_video & IVTV_HW_GPIO)
70*4882a593Smuzhiyun ivtv_call_hw(itv, IVTV_HW_GPIO, video, s_routing,
71*4882a593Smuzhiyun input, 0, 0);
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun if (itv->card->hw_video & IVTV_HW_UPD64031A) {
74*4882a593Smuzhiyun if (type == IVTV_CARD_INPUT_VID_TUNER ||
75*4882a593Smuzhiyun type >= IVTV_CARD_INPUT_COMPOSITE1) {
76*4882a593Smuzhiyun /* Composite: GR on, connect to 3DYCS */
77*4882a593Smuzhiyun input = UPD64031A_GR_ON | UPD64031A_3DYCS_COMPOSITE;
78*4882a593Smuzhiyun } else {
79*4882a593Smuzhiyun /* S-Video: GR bypassed, turn it off */
80*4882a593Smuzhiyun input = UPD64031A_GR_OFF | UPD64031A_3DYCS_DISABLE;
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun input |= itv->card->gr_config;
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun ivtv_call_hw(itv, IVTV_HW_UPD64031A, video, s_routing,
85*4882a593Smuzhiyun input, 0, 0);
86*4882a593Smuzhiyun }
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun if (itv->card->hw_video & IVTV_HW_UPD6408X) {
89*4882a593Smuzhiyun input = UPD64083_YCS_MODE;
90*4882a593Smuzhiyun if (type > IVTV_CARD_INPUT_VID_TUNER &&
91*4882a593Smuzhiyun type < IVTV_CARD_INPUT_COMPOSITE1) {
92*4882a593Smuzhiyun /* S-Video uses YCNR mode and internal Y-ADC, the
93*4882a593Smuzhiyun upd64031a is not used. */
94*4882a593Smuzhiyun input |= UPD64083_YCNR_MODE;
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun else if (itv->card->hw_video & IVTV_HW_UPD64031A) {
97*4882a593Smuzhiyun /* Use upd64031a output for tuner and
98*4882a593Smuzhiyun composite(CX23416GYC only) inputs */
99*4882a593Smuzhiyun if (type == IVTV_CARD_INPUT_VID_TUNER ||
100*4882a593Smuzhiyun itv->card->type == IVTV_CARD_CX23416GYC) {
101*4882a593Smuzhiyun input |= UPD64083_EXT_Y_ADC;
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun ivtv_call_hw(itv, IVTV_HW_UPD6408X, video, s_routing,
105*4882a593Smuzhiyun input, 0, 0);
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun }
108