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