Hans Verkuil | 33c0fca | 2007-08-23 06:32:46 -0300 | [diff] [blame] | 1 | /* |
| 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> |
| 28 | #include <media/upd64031a.h> |
| 29 | #include <media/upd64083.h> |
| 30 | |
| 31 | /* Selects the audio input and output according to the current |
| 32 | settings. */ |
| 33 | void ivtv_audio_set_io(struct ivtv *itv) |
| 34 | { |
| 35 | struct v4l2_routing route; |
| 36 | u32 audio_input; |
| 37 | int mux_input; |
| 38 | |
| 39 | /* Determine which input to use */ |
| 40 | if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) { |
| 41 | audio_input = itv->card->radio_input.audio_input; |
| 42 | mux_input = itv->card->radio_input.muxer_input; |
| 43 | } else { |
| 44 | audio_input = itv->card->audio_inputs[itv->audio_input].audio_input; |
| 45 | mux_input = itv->card->audio_inputs[itv->audio_input].muxer_input; |
| 46 | } |
| 47 | |
| 48 | /* handle muxer chips */ |
| 49 | route.input = mux_input; |
| 50 | route.output = 0; |
| 51 | ivtv_i2c_hw(itv, itv->card->hw_muxer, VIDIOC_INT_S_AUDIO_ROUTING, &route); |
| 52 | |
| 53 | route.input = audio_input; |
| 54 | if (itv->card->hw_audio & IVTV_HW_MSP34XX) { |
| 55 | route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); |
| 56 | } |
| 57 | ivtv_i2c_hw(itv, itv->card->hw_audio, VIDIOC_INT_S_AUDIO_ROUTING, &route); |
| 58 | } |
| 59 | |
| 60 | /* Selects the video input and output according to the current |
| 61 | settings. */ |
| 62 | void ivtv_video_set_io(struct ivtv *itv) |
| 63 | { |
| 64 | struct v4l2_routing route; |
| 65 | int inp = itv->active_input; |
| 66 | u32 type; |
| 67 | |
| 68 | route.input = itv->card->video_inputs[inp].video_input; |
| 69 | route.output = 0; |
| 70 | itv->video_dec_func(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route); |
| 71 | |
| 72 | type = itv->card->video_inputs[inp].video_type; |
| 73 | |
| 74 | if (type == IVTV_CARD_INPUT_VID_TUNER) { |
| 75 | route.input = 0; /* Tuner */ |
| 76 | } else if (type < IVTV_CARD_INPUT_COMPOSITE1) { |
| 77 | route.input = 2; /* S-Video */ |
| 78 | } else { |
| 79 | route.input = 1; /* Composite */ |
| 80 | } |
| 81 | |
| 82 | if (itv->card->hw_video & IVTV_HW_GPIO) |
| 83 | ivtv_gpio(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route); |
| 84 | |
| 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 */ |
| 89 | route.input = UPD64031A_GR_ON | UPD64031A_3DYCS_COMPOSITE; |
| 90 | } else { |
| 91 | /* S-Video: GR bypassed, turn it off */ |
| 92 | route.input = UPD64031A_GR_OFF | UPD64031A_3DYCS_DISABLE; |
| 93 | } |
| 94 | route.input |= itv->card->gr_config; |
| 95 | |
| 96 | ivtv_upd64031a(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route); |
| 97 | } |
| 98 | |
| 99 | if (itv->card->hw_video & IVTV_HW_UPD6408X) { |
| 100 | route.input = UPD64083_YCS_MODE; |
| 101 | if (type > IVTV_CARD_INPUT_VID_TUNER && |
| 102 | type < IVTV_CARD_INPUT_COMPOSITE1) { |
| 103 | /* S-Video uses YCNR mode and internal Y-ADC, the upd64031a |
| 104 | is not used. */ |
| 105 | route.input |= UPD64083_YCNR_MODE; |
| 106 | } |
| 107 | else if (itv->card->hw_video & IVTV_HW_UPD64031A) { |
| 108 | /* Use upd64031a output for tuner and composite(CX23416GYC only) inputs */ |
| 109 | if ((type == IVTV_CARD_INPUT_VID_TUNER)|| |
| 110 | (itv->card->type == IVTV_CARD_CX23416GYC)) { |
| 111 | route.input |= UPD64083_EXT_Y_ADC; |
| 112 | } |
| 113 | } |
| 114 | ivtv_upd64083(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route); |
| 115 | } |
| 116 | } |