18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci    Audio/video-routing-related ivtv functions.
48c2ecf20Sopenharmony_ci    Copyright (C) 2003-2004  Kevin Thayer <nufan_wfk at yahoo.com>
58c2ecf20Sopenharmony_ci    Copyright (C) 2005-2007  Hans Verkuil <hverkuil@xs4all.nl>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "ivtv-driver.h"
108c2ecf20Sopenharmony_ci#include "ivtv-i2c.h"
118c2ecf20Sopenharmony_ci#include "ivtv-cards.h"
128c2ecf20Sopenharmony_ci#include "ivtv-gpio.h"
138c2ecf20Sopenharmony_ci#include "ivtv-routing.h"
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <media/drv-intf/msp3400.h>
168c2ecf20Sopenharmony_ci#include <media/i2c/m52790.h>
178c2ecf20Sopenharmony_ci#include <media/i2c/upd64031a.h>
188c2ecf20Sopenharmony_ci#include <media/i2c/upd64083.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* Selects the audio input and output according to the current
218c2ecf20Sopenharmony_ci   settings. */
228c2ecf20Sopenharmony_civoid ivtv_audio_set_io(struct ivtv *itv)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	const struct ivtv_card_audio_input *in;
258c2ecf20Sopenharmony_ci	u32 input, output = 0;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	/* Determine which input to use */
288c2ecf20Sopenharmony_ci	if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags))
298c2ecf20Sopenharmony_ci		in = &itv->card->radio_input;
308c2ecf20Sopenharmony_ci	else
318c2ecf20Sopenharmony_ci		in = &itv->card->audio_inputs[itv->audio_input];
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	/* handle muxer chips */
348c2ecf20Sopenharmony_ci	input = in->muxer_input;
358c2ecf20Sopenharmony_ci	if (itv->card->hw_muxer & IVTV_HW_M52790)
368c2ecf20Sopenharmony_ci		output = M52790_OUT_STEREO;
378c2ecf20Sopenharmony_ci	v4l2_subdev_call(itv->sd_muxer, audio, s_routing,
388c2ecf20Sopenharmony_ci			input, output, 0);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	input = in->audio_input;
418c2ecf20Sopenharmony_ci	output = 0;
428c2ecf20Sopenharmony_ci	if (itv->card->hw_audio & IVTV_HW_MSP34XX)
438c2ecf20Sopenharmony_ci		output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
448c2ecf20Sopenharmony_ci	ivtv_call_hw(itv, itv->card->hw_audio, audio, s_routing,
458c2ecf20Sopenharmony_ci			input, output, 0);
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* Selects the video input and output according to the current
498c2ecf20Sopenharmony_ci   settings. */
508c2ecf20Sopenharmony_civoid ivtv_video_set_io(struct ivtv *itv)
518c2ecf20Sopenharmony_ci{
528c2ecf20Sopenharmony_ci	int inp = itv->active_input;
538c2ecf20Sopenharmony_ci	u32 input;
548c2ecf20Sopenharmony_ci	u32 type;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	v4l2_subdev_call(itv->sd_video, video, s_routing,
578c2ecf20Sopenharmony_ci		itv->card->video_inputs[inp].video_input, 0, 0);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	type = itv->card->video_inputs[inp].video_type;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	if (type == IVTV_CARD_INPUT_VID_TUNER) {
628c2ecf20Sopenharmony_ci		input = 0;  /* Tuner */
638c2ecf20Sopenharmony_ci	} else if (type < IVTV_CARD_INPUT_COMPOSITE1) {
648c2ecf20Sopenharmony_ci		input = 2;  /* S-Video */
658c2ecf20Sopenharmony_ci	} else {
668c2ecf20Sopenharmony_ci		input = 1;  /* Composite */
678c2ecf20Sopenharmony_ci	}
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	if (itv->card->hw_video & IVTV_HW_GPIO)
708c2ecf20Sopenharmony_ci		ivtv_call_hw(itv, IVTV_HW_GPIO, video, s_routing,
718c2ecf20Sopenharmony_ci				input, 0, 0);
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	if (itv->card->hw_video & IVTV_HW_UPD64031A) {
748c2ecf20Sopenharmony_ci		if (type == IVTV_CARD_INPUT_VID_TUNER ||
758c2ecf20Sopenharmony_ci		    type >= IVTV_CARD_INPUT_COMPOSITE1) {
768c2ecf20Sopenharmony_ci			/* Composite: GR on, connect to 3DYCS */
778c2ecf20Sopenharmony_ci			input = UPD64031A_GR_ON | UPD64031A_3DYCS_COMPOSITE;
788c2ecf20Sopenharmony_ci		} else {
798c2ecf20Sopenharmony_ci			/* S-Video: GR bypassed, turn it off */
808c2ecf20Sopenharmony_ci			input = UPD64031A_GR_OFF | UPD64031A_3DYCS_DISABLE;
818c2ecf20Sopenharmony_ci		}
828c2ecf20Sopenharmony_ci		input |= itv->card->gr_config;
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci		ivtv_call_hw(itv, IVTV_HW_UPD64031A, video, s_routing,
858c2ecf20Sopenharmony_ci				input, 0, 0);
868c2ecf20Sopenharmony_ci	}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	if (itv->card->hw_video & IVTV_HW_UPD6408X) {
898c2ecf20Sopenharmony_ci		input = UPD64083_YCS_MODE;
908c2ecf20Sopenharmony_ci		if (type > IVTV_CARD_INPUT_VID_TUNER &&
918c2ecf20Sopenharmony_ci		    type < IVTV_CARD_INPUT_COMPOSITE1) {
928c2ecf20Sopenharmony_ci			/* S-Video uses YCNR mode and internal Y-ADC, the
938c2ecf20Sopenharmony_ci			   upd64031a is not used. */
948c2ecf20Sopenharmony_ci			input |= UPD64083_YCNR_MODE;
958c2ecf20Sopenharmony_ci		}
968c2ecf20Sopenharmony_ci		else if (itv->card->hw_video & IVTV_HW_UPD64031A) {
978c2ecf20Sopenharmony_ci			/* Use upd64031a output for tuner and
988c2ecf20Sopenharmony_ci			   composite(CX23416GYC only) inputs */
998c2ecf20Sopenharmony_ci			if (type == IVTV_CARD_INPUT_VID_TUNER ||
1008c2ecf20Sopenharmony_ci			    itv->card->type == IVTV_CARD_CX23416GYC) {
1018c2ecf20Sopenharmony_ci				input |= UPD64083_EXT_Y_ADC;
1028c2ecf20Sopenharmony_ci			}
1038c2ecf20Sopenharmony_ci		}
1048c2ecf20Sopenharmony_ci		ivtv_call_hw(itv, IVTV_HW_UPD6408X, video, s_routing,
1058c2ecf20Sopenharmony_ci				input, 0, 0);
1068c2ecf20Sopenharmony_ci	}
1078c2ecf20Sopenharmony_ci}
108