11a59d1b8SThomas Gleixner// SPDX-License-Identifier: GPL-2.0-or-later
21a0adaf3SHans Verkuil/*
333c0fcadSHans Verkuil    Audio/video-routing-related ivtv functions.
433c0fcadSHans Verkuil    Copyright (C) 2003-2004  Kevin Thayer <nufan_wfk at yahoo.com>
533c0fcadSHans Verkuil    Copyright (C) 2005-2007  Hans Verkuil <hverkuil@xs4all.nl>
61a0adaf3SHans Verkuil
71a0adaf3SHans Verkuil */
81a0adaf3SHans Verkuil
91a0adaf3SHans Verkuil#include "ivtv-driver.h"
101a0adaf3SHans Verkuil#include "ivtv-i2c.h"
111a0adaf3SHans Verkuil#include "ivtv-cards.h"
1233c0fcadSHans Verkuil#include "ivtv-gpio.h"
1333c0fcadSHans Verkuil#include "ivtv-routing.h"
1433c0fcadSHans Verkuil
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>
191a0adaf3SHans Verkuil
2033c0fcadSHans Verkuil/* Selects the audio input and output according to the current
2133c0fcadSHans Verkuil   settings. */
2233c0fcadSHans Verkuilvoid ivtv_audio_set_io(struct ivtv *itv)
231a0adaf3SHans Verkuil{
24e2a1774dSHans Verkuil	const struct ivtv_card_audio_input *in;
255325b427SHans Verkuil	u32 input, output = 0;
261a0adaf3SHans Verkuil
2733c0fcadSHans Verkuil	/* Determine which input to use */
28e2a1774dSHans Verkuil	if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags))
29e2a1774dSHans Verkuil		in = &itv->card->radio_input;
30e2a1774dSHans Verkuil	else
31e2a1774dSHans Verkuil		in = &itv->card->audio_inputs[itv->audio_input];
321a0adaf3SHans Verkuil
3333c0fcadSHans Verkuil	/* handle muxer chips */
345325b427SHans Verkuil	input = in->muxer_input;
35e2a1774dSHans Verkuil	if (itv->card->hw_muxer & IVTV_HW_M52790)
365325b427SHans Verkuil		output = M52790_OUT_STEREO;
375325b427SHans Verkuil	v4l2_subdev_call(itv->sd_muxer, audio, s_routing,
385325b427SHans Verkuil			input, output, 0);
391a0adaf3SHans Verkuil
405325b427SHans Verkuil	input = in->audio_input;
415325b427SHans Verkuil	output = 0;
42e2a1774dSHans Verkuil	if (itv->card->hw_audio & IVTV_HW_MSP34XX)
435325b427SHans Verkuil		output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
445325b427SHans Verkuil	ivtv_call_hw(itv, itv->card->hw_audio, audio, s_routing,
455325b427SHans Verkuil			input, output, 0);
461a0adaf3SHans Verkuil}
471a0adaf3SHans Verkuil
4833c0fcadSHans Verkuil/* Selects the video input and output according to the current
4933c0fcadSHans Verkuil   settings. */
501a0adaf3SHans Verkuilvoid ivtv_video_set_io(struct ivtv *itv)
511a0adaf3SHans Verkuil{
521a0adaf3SHans Verkuil	int inp = itv->active_input;
535325b427SHans Verkuil	u32 input;
541a0adaf3SHans Verkuil	u32 type;
551a0adaf3SHans Verkuil
565325b427SHans Verkuil	v4l2_subdev_call(itv->sd_video, video, s_routing,
575325b427SHans Verkuil		itv->card->video_inputs[inp].video_input, 0, 0);
581a0adaf3SHans Verkuil
591a0adaf3SHans Verkuil	type = itv->card->video_inputs[inp].video_type;
601a0adaf3SHans Verkuil
611a0adaf3SHans Verkuil	if (type == IVTV_CARD_INPUT_VID_TUNER) {
625325b427SHans Verkuil		input = 0;  /* Tuner */
631a0adaf3SHans Verkuil	} else if (type < IVTV_CARD_INPUT_COMPOSITE1) {
645325b427SHans Verkuil		input = 2;  /* S-Video */
651a0adaf3SHans Verkuil	} else {
665325b427SHans Verkuil		input = 1;  /* Composite */
671a0adaf3SHans Verkuil	}
681a0adaf3SHans Verkuil
691a0adaf3SHans Verkuil	if (itv->card->hw_video & IVTV_HW_GPIO)
705325b427SHans Verkuil		ivtv_call_hw(itv, IVTV_HW_GPIO, video, s_routing,
715325b427SHans Verkuil				input, 0, 0);
721a0adaf3SHans Verkuil
731a0adaf3SHans Verkuil	if (itv->card->hw_video & IVTV_HW_UPD64031A) {
741a0adaf3SHans Verkuil		if (type == IVTV_CARD_INPUT_VID_TUNER ||
751a0adaf3SHans Verkuil		    type >= IVTV_CARD_INPUT_COMPOSITE1) {
761a0adaf3SHans Verkuil			/* Composite: GR on, connect to 3DYCS */
775325b427SHans Verkuil			input = UPD64031A_GR_ON | UPD64031A_3DYCS_COMPOSITE;
781a0adaf3SHans Verkuil		} else {
791a0adaf3SHans Verkuil			/* S-Video: GR bypassed, turn it off */
805325b427SHans Verkuil			input = UPD64031A_GR_OFF | UPD64031A_3DYCS_DISABLE;
811a0adaf3SHans Verkuil		}
825325b427SHans Verkuil		input |= itv->card->gr_config;
831a0adaf3SHans Verkuil
845325b427SHans Verkuil		ivtv_call_hw(itv, IVTV_HW_UPD64031A, video, s_routing,
855325b427SHans Verkuil				input, 0, 0);
861a0adaf3SHans Verkuil	}
871a0adaf3SHans Verkuil
881a0adaf3SHans Verkuil	if (itv->card->hw_video & IVTV_HW_UPD6408X) {
895325b427SHans Verkuil		input = UPD64083_YCS_MODE;
901a0adaf3SHans Verkuil		if (type > IVTV_CARD_INPUT_VID_TUNER &&
911a0adaf3SHans Verkuil		    type < IVTV_CARD_INPUT_COMPOSITE1) {
925325b427SHans Verkuil			/* S-Video uses YCNR mode and internal Y-ADC, the
935325b427SHans Verkuil			   upd64031a is not used. */
945325b427SHans Verkuil			input |= UPD64083_YCNR_MODE;
951a0adaf3SHans Verkuil		}
961a0adaf3SHans Verkuil		else if (itv->card->hw_video & IVTV_HW_UPD64031A) {
975325b427SHans Verkuil			/* Use upd64031a output for tuner and
985325b427SHans Verkuil			   composite(CX23416GYC only) inputs */
995325b427SHans Verkuil			if (type == IVTV_CARD_INPUT_VID_TUNER ||
1005325b427SHans Verkuil			    itv->card->type == IVTV_CARD_CX23416GYC) {
1015325b427SHans Verkuil				input |= UPD64083_EXT_Y_ADC;
1025325b427SHans Verkuil			}
1031a0adaf3SHans Verkuil		}
1045325b427SHans Verkuil		ivtv_call_hw(itv, IVTV_HW_UPD6408X, video, s_routing,
1055325b427SHans Verkuil				input, 0, 0);
1061a0adaf3SHans Verkuil	}
1071a0adaf3SHans Verkuil}
108