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