4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
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
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.
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
22 #include "pvrusb2-i2c-cmd-v4l2.h"
23 #include "pvrusb2-hdw-internal.h"
24 #include "pvrusb2-debug.h"
25 #include <linux/videodev2.h>
26 #include <media/v4l2-common.h>
28 static void execute_init(struct pvr2_hdw *hdw)
31 pvr2_trace(PVR2_TRACE_CHIPS, "i2c v4l2 init");
32 pvr2_i2c_core_cmd(hdw, VIDIOC_INT_INIT, &dummy);
36 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_init = {
37 .update = execute_init,
42 static void set_standard(struct pvr2_hdw *hdw)
44 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_standard");
46 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
47 pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL);
50 vs = hdw->std_mask_cur;
51 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
53 hdw->tuner_signal_stale = !0;
54 hdw->cropcap_stale = !0;
58 static int check_standard(struct pvr2_hdw *hdw)
60 return (hdw->input_dirty != 0) || (hdw->std_dirty != 0);
64 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
65 .check = check_standard,
66 .update = set_standard,
67 .name = "v4l2_standard",
71 static void set_bcsh(struct pvr2_hdw *hdw)
73 struct v4l2_control ctrl;
74 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh"
75 " b=%d c=%d s=%d h=%d",
76 hdw->brightness_val,hdw->contrast_val,
77 hdw->saturation_val,hdw->hue_val);
78 memset(&ctrl,0,sizeof(ctrl));
79 ctrl.id = V4L2_CID_BRIGHTNESS;
80 ctrl.value = hdw->brightness_val;
81 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
82 ctrl.id = V4L2_CID_CONTRAST;
83 ctrl.value = hdw->contrast_val;
84 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
85 ctrl.id = V4L2_CID_SATURATION;
86 ctrl.value = hdw->saturation_val;
87 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
88 ctrl.id = V4L2_CID_HUE;
89 ctrl.value = hdw->hue_val;
90 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
94 static int check_bcsh(struct pvr2_hdw *hdw)
96 return (hdw->brightness_dirty ||
97 hdw->contrast_dirty ||
98 hdw->saturation_dirty ||
103 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
110 static void set_volume(struct pvr2_hdw *hdw)
112 struct v4l2_control ctrl;
113 pvr2_trace(PVR2_TRACE_CHIPS,
114 "i2c v4l2 set_volume"
115 "(vol=%d bal=%d bas=%d treb=%d mute=%d)",
121 memset(&ctrl,0,sizeof(ctrl));
122 ctrl.id = V4L2_CID_AUDIO_MUTE;
123 ctrl.value = hdw->mute_val ? 1 : 0;
124 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
125 ctrl.id = V4L2_CID_AUDIO_VOLUME;
126 ctrl.value = hdw->volume_val;
127 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
128 ctrl.id = V4L2_CID_AUDIO_BALANCE;
129 ctrl.value = hdw->balance_val;
130 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
131 ctrl.id = V4L2_CID_AUDIO_BASS;
132 ctrl.value = hdw->bass_val;
133 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
134 ctrl.id = V4L2_CID_AUDIO_TREBLE;
135 ctrl.value = hdw->treble_val;
136 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
140 static int check_volume(struct pvr2_hdw *hdw)
142 return (hdw->volume_dirty ||
143 hdw->balance_dirty ||
150 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
151 .check = check_volume,
152 .update = set_volume,
153 .name = "v4l2_volume",
157 static void set_audiomode(struct pvr2_hdw *hdw)
159 struct v4l2_tuner vt;
160 memset(&vt,0,sizeof(vt));
161 vt.audmode = hdw->audiomode_val;
162 pvr2_i2c_core_cmd(hdw,VIDIOC_S_TUNER,&vt);
166 static int check_audiomode(struct pvr2_hdw *hdw)
168 return (hdw->input_dirty ||
169 hdw->audiomode_dirty);
173 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode = {
174 .check = check_audiomode,
175 .update = set_audiomode,
176 .name = "v4l2_audiomode",
180 static void set_frequency(struct pvr2_hdw *hdw)
183 struct v4l2_frequency freq;
184 fv = pvr2_hdw_get_cur_freq(hdw);
185 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
186 if (hdw->tuner_signal_stale) {
187 pvr2_i2c_core_status_poll(hdw);
189 memset(&freq,0,sizeof(freq));
190 if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
191 // ((fv * 1000) / 62500)
192 freq.frequency = (fv * 2) / 125;
194 freq.frequency = fv / 62500;
196 /* tuner-core currently doesn't seem to care about this, but
197 let's set it anyway for completeness. */
198 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
199 freq.type = V4L2_TUNER_RADIO;
201 freq.type = V4L2_TUNER_ANALOG_TV;
204 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
208 static int check_frequency(struct pvr2_hdw *hdw)
210 return hdw->freqDirty != 0;
214 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
215 .check = check_frequency,
216 .update = set_frequency,
221 static void set_size(struct pvr2_hdw *hdw)
223 struct v4l2_format fmt;
225 memset(&fmt,0,sizeof(fmt));
227 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
228 fmt.fmt.pix.width = hdw->res_hor_val;
229 fmt.fmt.pix.height = hdw->res_ver_val;
231 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
232 fmt.fmt.pix.width,fmt.fmt.pix.height);
234 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
238 static int check_size(struct pvr2_hdw *hdw)
240 return (hdw->res_hor_dirty || hdw->res_ver_dirty);
244 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
251 static void set_crop(struct pvr2_hdw *hdw)
253 struct v4l2_crop crop;
255 memset(&crop, 0, sizeof crop);
256 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
257 crop.c.left = hdw->cropl_val;
258 crop.c.top = hdw->cropt_val;
259 crop.c.height = hdw->croph_val;
260 crop.c.width = hdw->cropw_val;
262 pvr2_trace(PVR2_TRACE_CHIPS,
263 "i2c v4l2 set_crop crop=%d:%d:%d:%d",
264 crop.c.width, crop.c.height, crop.c.left, crop.c.top);
266 pvr2_i2c_core_cmd(hdw, VIDIOC_S_CROP, &crop);
269 static int check_crop(struct pvr2_hdw *hdw)
271 return (hdw->cropl_dirty || hdw->cropt_dirty ||
272 hdw->cropw_dirty || hdw->croph_dirty);
275 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop = {
282 static void do_log(struct pvr2_hdw *hdw)
284 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
285 pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
290 static int check_log(struct pvr2_hdw *hdw)
292 return hdw->log_requested != 0;
296 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
303 void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
305 pvr2_i2c_client_cmd(cp,
306 (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
310 void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp)
313 struct pvr2_hdw *hdw = cp->hdw;
314 if (hdw->cropcap_stale) {
315 hdw->cropcap_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
316 stat = pvr2_i2c_client_cmd(cp, VIDIOC_CROPCAP,
319 /* Check was successful, so the data is no
320 longer considered stale. */
321 hdw->cropcap_stale = 0;
324 pvr2_i2c_client_cmd(cp, VIDIOC_G_TUNER, &hdw->tuner_signal_info);
329 Stuff for Emacs to see, in order to encourage consistent editing style:
330 *** Local Variables: ***
332 *** fill-column: 70 ***
334 *** c-basic-offset: 8 ***