blob: 8898c569a1c90adab6cbc13e2b0a1afd6b1684d3 [file] [log] [blame]
Hans Verkuil33c0fca2007-08-23 06:32:46 -03001/*
2 Audio/video-routing-related ivtv functions.
3 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
4 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "ivtv-driver.h"
22#include "ivtv-i2c.h"
23#include "ivtv-cards.h"
24#include "ivtv-gpio.h"
25#include "ivtv-routing.h"
26
27#include <media/msp3400.h>
Hans Verkuile2a17742007-10-30 05:50:03 -030028#include <media/m52790.h>
Hans Verkuil33c0fca2007-08-23 06:32:46 -030029#include <media/upd64031a.h>
30#include <media/upd64083.h>
31
32/* Selects the audio input and output according to the current
33 settings. */
34void ivtv_audio_set_io(struct ivtv *itv)
35{
Hans Verkuile2a17742007-10-30 05:50:03 -030036 const struct ivtv_card_audio_input *in;
Hans Verkuil5325b422009-04-02 11:26:22 -030037 u32 input, output = 0;
Hans Verkuil33c0fca2007-08-23 06:32:46 -030038
39 /* Determine which input to use */
Hans Verkuile2a17742007-10-30 05:50:03 -030040 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags))
41 in = &itv->card->radio_input;
42 else
43 in = &itv->card->audio_inputs[itv->audio_input];
Hans Verkuil33c0fca2007-08-23 06:32:46 -030044
45 /* handle muxer chips */
Hans Verkuil5325b422009-04-02 11:26:22 -030046 input = in->muxer_input;
Hans Verkuile2a17742007-10-30 05:50:03 -030047 if (itv->card->hw_muxer & IVTV_HW_M52790)
Hans Verkuil5325b422009-04-02 11:26:22 -030048 output = M52790_OUT_STEREO;
49 v4l2_subdev_call(itv->sd_muxer, audio, s_routing,
50 input, output, 0);
Hans Verkuil33c0fca2007-08-23 06:32:46 -030051
Hans Verkuil5325b422009-04-02 11:26:22 -030052 input = in->audio_input;
53 output = 0;
Hans Verkuile2a17742007-10-30 05:50:03 -030054 if (itv->card->hw_audio & IVTV_HW_MSP34XX)
Hans Verkuil5325b422009-04-02 11:26:22 -030055 output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
56 ivtv_call_hw(itv, itv->card->hw_audio, audio, s_routing,
57 input, output, 0);
Hans Verkuil33c0fca2007-08-23 06:32:46 -030058}
59
60/* Selects the video input and output according to the current
61 settings. */
62void ivtv_video_set_io(struct ivtv *itv)
63{
Hans Verkuil33c0fca2007-08-23 06:32:46 -030064 int inp = itv->active_input;
Hans Verkuil5325b422009-04-02 11:26:22 -030065 u32 input;
Hans Verkuil33c0fca2007-08-23 06:32:46 -030066 u32 type;
67
Hans Verkuil5325b422009-04-02 11:26:22 -030068 v4l2_subdev_call(itv->sd_video, video, s_routing,
69 itv->card->video_inputs[inp].video_input, 0, 0);
Hans Verkuil33c0fca2007-08-23 06:32:46 -030070
71 type = itv->card->video_inputs[inp].video_type;
72
73 if (type == IVTV_CARD_INPUT_VID_TUNER) {
Hans Verkuil5325b422009-04-02 11:26:22 -030074 input = 0; /* Tuner */
Hans Verkuil33c0fca2007-08-23 06:32:46 -030075 } else if (type < IVTV_CARD_INPUT_COMPOSITE1) {
Hans Verkuil5325b422009-04-02 11:26:22 -030076 input = 2; /* S-Video */
Hans Verkuil33c0fca2007-08-23 06:32:46 -030077 } else {
Hans Verkuil5325b422009-04-02 11:26:22 -030078 input = 1; /* Composite */
Hans Verkuil33c0fca2007-08-23 06:32:46 -030079 }
80
81 if (itv->card->hw_video & IVTV_HW_GPIO)
Hans Verkuil5325b422009-04-02 11:26:22 -030082 ivtv_call_hw(itv, IVTV_HW_GPIO, video, s_routing,
83 input, 0, 0);
Hans Verkuil33c0fca2007-08-23 06:32:46 -030084
85 if (itv->card->hw_video & IVTV_HW_UPD64031A) {
86 if (type == IVTV_CARD_INPUT_VID_TUNER ||
87 type >= IVTV_CARD_INPUT_COMPOSITE1) {
88 /* Composite: GR on, connect to 3DYCS */
Hans Verkuil5325b422009-04-02 11:26:22 -030089 input = UPD64031A_GR_ON | UPD64031A_3DYCS_COMPOSITE;
Hans Verkuil33c0fca2007-08-23 06:32:46 -030090 } else {
91 /* S-Video: GR bypassed, turn it off */
Hans Verkuil5325b422009-04-02 11:26:22 -030092 input = UPD64031A_GR_OFF | UPD64031A_3DYCS_DISABLE;
Hans Verkuil33c0fca2007-08-23 06:32:46 -030093 }
Hans Verkuil5325b422009-04-02 11:26:22 -030094 input |= itv->card->gr_config;
Hans Verkuil33c0fca2007-08-23 06:32:46 -030095
Hans Verkuil5325b422009-04-02 11:26:22 -030096 ivtv_call_hw(itv, IVTV_HW_UPD64031A, video, s_routing,
97 input, 0, 0);
Hans Verkuil33c0fca2007-08-23 06:32:46 -030098 }
99
100 if (itv->card->hw_video & IVTV_HW_UPD6408X) {
Hans Verkuil5325b422009-04-02 11:26:22 -0300101 input = UPD64083_YCS_MODE;
Hans Verkuil33c0fca2007-08-23 06:32:46 -0300102 if (type > IVTV_CARD_INPUT_VID_TUNER &&
103 type < IVTV_CARD_INPUT_COMPOSITE1) {
Hans Verkuil5325b422009-04-02 11:26:22 -0300104 /* S-Video uses YCNR mode and internal Y-ADC, the
105 upd64031a is not used. */
106 input |= UPD64083_YCNR_MODE;
Hans Verkuil33c0fca2007-08-23 06:32:46 -0300107 }
108 else if (itv->card->hw_video & IVTV_HW_UPD64031A) {
Hans Verkuil5325b422009-04-02 11:26:22 -0300109 /* Use upd64031a output for tuner and
110 composite(CX23416GYC only) inputs */
111 if (type == IVTV_CARD_INPUT_VID_TUNER ||
112 itv->card->type == IVTV_CARD_CX23416GYC) {
113 input |= UPD64083_EXT_Y_ADC;
114 }
Hans Verkuil33c0fca2007-08-23 06:32:46 -0300115 }
Hans Verkuil5325b422009-04-02 11:26:22 -0300116 ivtv_call_hw(itv, IVTV_HW_UPD6408X, video, s_routing,
117 input, 0, 0);
Hans Verkuil33c0fca2007-08-23 06:32:46 -0300118 }
119}