3 Merging GPIO support into driver:
4 Copyright (C) 2004 Chris Kennedy <c@groovy.org>
5 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "ivtv-driver.h"
23 #include "ivtv-cards.h"
24 #include "ivtv-gpio.h"
25 #include "tuner-xc2028.h"
26 #include <media/tuner.h>
29 * GPIO assignment of Yuan MPG600/MPG160
31 * bit 15 14 13 12 | 11 10 9 8 | 7 6 5 4 | 3 2 1 0
32 * OUTPUT IN1 IN0 AM3 AM2 AM1 AM0
35 * IN* : Input selection
43 * AM3 0: Normal 1: Mixed(Sub+Main channel)
44 * AM2 0: Subchannel 1: Main channel
45 * AM1 0: Stereo 1: Mono
46 * AM0 0: Normal 1: Mute
48 * DM* : Detected tuner audio Mode
49 * DM1 0: Stereo 1: Mono
50 * DM0 0: Multiplex 1: Normal
52 * GPIO Initial Settings
55 * OUTPUT 0x000C 0x400C
57 * Special thanks to Makoto Iguchi <iguchi@tahoo.org> and Mr. Anonymous
58 * for analyzing GPIO of MPG160.
60 *****************************************************************************
62 * GPIO assignment of Avermedia M179 (per information direct from AVerMedia)
64 * bit 15 14 13 12 | 11 10 9 8 | 7 6 5 4 | 3 2 1 0
65 * OUTPUT IN0 AM0 IN1 AM1 AM2 IN2 BR0 BR1
68 * IN* : Input selection
72 * 1 0 0 TV Tuner Audio
78 * 0 0 0 TV Tuner Audio: L_OUT=(L+R)/2, R_OUT=SAP
79 * 0 0 1 TV Tuner Audio: L_OUT=R_OUT=SAP (SAP)
80 * 0 1 0 TV Tuner Audio: L_OUT=L, R_OUT=R (stereo)
81 * 0 1 1 TV Tuner Audio: mute
82 * 1 * * TV Tuner Audio: L_OUT=R_OUT=(L+R)/2 (mono)
84 * BR* : Audio Sample Rate (BR stands for bitrate for some reason)
90 * DM* : Detected tuner audio Mode
93 * Special thanks to AVerMedia Technologies, Inc. and Jiun-Kuei Jung at
94 * AVerMedia for providing the GPIO information used to add support
98 /********************* GPIO stuffs *********************/
101 #define IVTV_REG_GPIO_IN 0x9008
102 #define IVTV_REG_GPIO_OUT 0x900c
103 #define IVTV_REG_GPIO_DIR 0x9020
105 void ivtv_reset_ir_gpio(struct ivtv
*itv
)
109 if (itv
->card
->type
!= IVTV_CARD_PVR_150
)
111 IVTV_DEBUG_INFO("Resetting PVR150 IR\n");
112 curout
= read_reg(IVTV_REG_GPIO_OUT
);
113 curdir
= read_reg(IVTV_REG_GPIO_DIR
);
115 write_reg(curdir
, IVTV_REG_GPIO_DIR
);
116 curout
= (curout
& ~0xF) | 1;
117 write_reg(curout
, IVTV_REG_GPIO_OUT
);
118 /* We could use something else for smaller time */
119 schedule_timeout_interruptible(msecs_to_jiffies(1));
121 write_reg(curout
, IVTV_REG_GPIO_OUT
);
123 write_reg(curdir
, IVTV_REG_GPIO_DIR
);
126 /* Xceive tuner reset function */
127 int ivtv_reset_tuner_gpio(void *dev
, int cmd
, int value
)
129 struct i2c_algo_bit_data
*algo
= dev
;
130 struct ivtv
*itv
= algo
->data
;
133 if (cmd
!= XC2028_TUNER_RESET
)
135 IVTV_DEBUG_INFO("Resetting tuner\n");
136 curout
= read_reg(IVTV_REG_GPIO_OUT
);
137 curout
&= ~(1 << itv
->card
->xceive_pin
);
138 write_reg(curout
, IVTV_REG_GPIO_OUT
);
139 schedule_timeout_interruptible(msecs_to_jiffies(1));
141 curout
|= 1 << itv
->card
->xceive_pin
;
142 write_reg(curout
, IVTV_REG_GPIO_OUT
);
143 schedule_timeout_interruptible(msecs_to_jiffies(1));
147 void ivtv_gpio_init(struct ivtv
*itv
)
149 if (itv
->card
->gpio_init
.direction
== 0)
152 IVTV_DEBUG_INFO("GPIO initial dir: %08x out: %08x\n",
153 read_reg(IVTV_REG_GPIO_DIR
), read_reg(IVTV_REG_GPIO_OUT
));
155 /* init output data then direction */
156 write_reg(itv
->card
->gpio_init
.initial_value
, IVTV_REG_GPIO_OUT
);
157 write_reg(itv
->card
->gpio_init
.direction
, IVTV_REG_GPIO_DIR
);
160 static struct v4l2_queryctrl gpio_ctrl_mute
= {
161 .id
= V4L2_CID_AUDIO_MUTE
,
162 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
171 int ivtv_gpio(struct ivtv
*itv
, unsigned int command
, void *arg
)
173 struct v4l2_tuner
*tuner
= arg
;
174 struct v4l2_control
*ctrl
= arg
;
175 struct v4l2_routing
*route
= arg
;
179 case VIDIOC_INT_AUDIO_CLOCK_FREQ
:
180 mask
= itv
->card
->gpio_audio_freq
.mask
;
181 switch (*(u32
*)arg
) {
183 data
= itv
->card
->gpio_audio_freq
.f32000
;
186 data
= itv
->card
->gpio_audio_freq
.f44100
;
190 data
= itv
->card
->gpio_audio_freq
.f48000
;
196 mask
= itv
->card
->gpio_audio_detect
.mask
;
197 if (mask
== 0 || (read_reg(IVTV_REG_GPIO_IN
) & mask
))
198 tuner
->rxsubchans
= V4L2_TUNER_MODE_STEREO
|
199 V4L2_TUNER_MODE_LANG1
| V4L2_TUNER_MODE_LANG2
;
201 tuner
->rxsubchans
= V4L2_TUNER_SUB_MONO
;
205 mask
= itv
->card
->gpio_audio_mode
.mask
;
206 switch (tuner
->audmode
) {
207 case V4L2_TUNER_MODE_LANG1
:
208 data
= itv
->card
->gpio_audio_mode
.lang1
;
210 case V4L2_TUNER_MODE_LANG2
:
211 data
= itv
->card
->gpio_audio_mode
.lang2
;
213 case V4L2_TUNER_MODE_MONO
:
214 data
= itv
->card
->gpio_audio_mode
.mono
;
216 case V4L2_TUNER_MODE_STEREO
:
217 case V4L2_TUNER_MODE_LANG1_LANG2
:
219 data
= itv
->card
->gpio_audio_mode
.stereo
;
225 mask
= itv
->card
->gpio_audio_input
.mask
;
226 data
= itv
->card
->gpio_audio_input
.radio
;
230 mask
= itv
->card
->gpio_audio_input
.mask
;
231 data
= itv
->card
->gpio_audio_input
.tuner
;
234 case VIDIOC_INT_S_AUDIO_ROUTING
:
235 if (route
->input
> 2)
237 mask
= itv
->card
->gpio_audio_input
.mask
;
238 switch (route
->input
) {
240 data
= itv
->card
->gpio_audio_input
.tuner
;
243 data
= itv
->card
->gpio_audio_input
.linein
;
247 data
= itv
->card
->gpio_audio_input
.radio
;
253 if (ctrl
->id
!= V4L2_CID_AUDIO_MUTE
)
255 mask
= itv
->card
->gpio_audio_mute
.mask
;
256 data
= itv
->card
->gpio_audio_mute
.mute
;
257 ctrl
->value
= (read_reg(IVTV_REG_GPIO_OUT
) & mask
) == data
;
261 if (ctrl
->id
!= V4L2_CID_AUDIO_MUTE
)
263 mask
= itv
->card
->gpio_audio_mute
.mask
;
264 data
= ctrl
->value
? itv
->card
->gpio_audio_mute
.mute
: 0;
267 case VIDIOC_QUERYCTRL
:
269 struct v4l2_queryctrl
*qc
= arg
;
271 if (qc
->id
!= V4L2_CID_AUDIO_MUTE
)
273 *qc
= gpio_ctrl_mute
;
277 case VIDIOC_LOG_STATUS
:
278 IVTV_INFO("GPIO status: DIR=0x%04x OUT=0x%04x IN=0x%04x\n",
279 read_reg(IVTV_REG_GPIO_DIR
), read_reg(IVTV_REG_GPIO_OUT
),
280 read_reg(IVTV_REG_GPIO_IN
));
283 case VIDIOC_INT_S_VIDEO_ROUTING
:
284 if (route
->input
> 2) /* 0:Tuner 1:Composite 2:S-Video */
286 mask
= itv
->card
->gpio_video_input
.mask
;
287 if (route
->input
== 0)
288 data
= itv
->card
->gpio_video_input
.tuner
;
289 else if (route
->input
== 1)
290 data
= itv
->card
->gpio_video_input
.composite
;
292 data
= itv
->card
->gpio_video_input
.svideo
;
299 write_reg((read_reg(IVTV_REG_GPIO_OUT
) & ~mask
) | (data
& mask
), IVTV_REG_GPIO_OUT
);