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>
29 static void execute_init(struct pvr2_hdw *hdw)
32 pvr2_trace(PVR2_TRACE_CHIPS, "i2c v4l2 init");
33 pvr2_i2c_core_cmd(hdw, VIDIOC_INT_INIT, &dummy);
37 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_init = {
38 .update = execute_init,
43 static void set_standard(struct pvr2_hdw *hdw)
45 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_standard");
47 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
48 pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL);
51 vs = hdw->std_mask_cur;
52 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
54 hdw->tuner_signal_stale = !0;
55 hdw->cropcap_stale = !0;
59 static int check_standard(struct pvr2_hdw *hdw)
61 return (hdw->input_dirty != 0) || (hdw->std_dirty != 0);
65 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
66 .check = check_standard,
67 .update = set_standard,
68 .name = "v4l2_standard",
72 static void set_bcsh(struct pvr2_hdw *hdw)
74 struct v4l2_control ctrl;
75 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh"
76 " b=%d c=%d s=%d h=%d",
77 hdw->brightness_val,hdw->contrast_val,
78 hdw->saturation_val,hdw->hue_val);
79 memset(&ctrl,0,sizeof(ctrl));
80 ctrl.id = V4L2_CID_BRIGHTNESS;
81 ctrl.value = hdw->brightness_val;
82 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
83 ctrl.id = V4L2_CID_CONTRAST;
84 ctrl.value = hdw->contrast_val;
85 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
86 ctrl.id = V4L2_CID_SATURATION;
87 ctrl.value = hdw->saturation_val;
88 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
89 ctrl.id = V4L2_CID_HUE;
90 ctrl.value = hdw->hue_val;
91 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
95 static int check_bcsh(struct pvr2_hdw *hdw)
97 return (hdw->brightness_dirty ||
98 hdw->contrast_dirty ||
99 hdw->saturation_dirty ||
104 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
111 static void set_volume(struct pvr2_hdw *hdw)
113 struct v4l2_control ctrl;
114 pvr2_trace(PVR2_TRACE_CHIPS,
115 "i2c v4l2 set_volume"
116 "(vol=%d bal=%d bas=%d treb=%d mute=%d)",
122 memset(&ctrl,0,sizeof(ctrl));
123 ctrl.id = V4L2_CID_AUDIO_MUTE;
124 ctrl.value = hdw->mute_val ? 1 : 0;
125 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
126 ctrl.id = V4L2_CID_AUDIO_VOLUME;
127 ctrl.value = hdw->volume_val;
128 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
129 ctrl.id = V4L2_CID_AUDIO_BALANCE;
130 ctrl.value = hdw->balance_val;
131 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
132 ctrl.id = V4L2_CID_AUDIO_BASS;
133 ctrl.value = hdw->bass_val;
134 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
135 ctrl.id = V4L2_CID_AUDIO_TREBLE;
136 ctrl.value = hdw->treble_val;
137 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
141 static int check_volume(struct pvr2_hdw *hdw)
143 return (hdw->volume_dirty ||
144 hdw->balance_dirty ||
151 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
152 .check = check_volume,
153 .update = set_volume,
154 .name = "v4l2_volume",
158 static void set_audiomode(struct pvr2_hdw *hdw)
160 struct v4l2_tuner vt;
161 memset(&vt,0,sizeof(vt));
162 vt.audmode = hdw->audiomode_val;
163 pvr2_i2c_core_cmd(hdw,VIDIOC_S_TUNER,&vt);
167 static int check_audiomode(struct pvr2_hdw *hdw)
169 return (hdw->input_dirty ||
170 hdw->audiomode_dirty);
174 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode = {
175 .check = check_audiomode,
176 .update = set_audiomode,
177 .name = "v4l2_audiomode",
181 static void set_frequency(struct pvr2_hdw *hdw)
184 struct v4l2_frequency freq;
185 fv = pvr2_hdw_get_cur_freq(hdw);
186 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
187 if (hdw->tuner_signal_stale) {
188 pvr2_hdw_status_poll(hdw);
190 memset(&freq,0,sizeof(freq));
191 if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
192 // ((fv * 1000) / 62500)
193 freq.frequency = (fv * 2) / 125;
195 freq.frequency = fv / 62500;
197 /* tuner-core currently doesn't seem to care about this, but
198 let's set it anyway for completeness. */
199 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
200 freq.type = V4L2_TUNER_RADIO;
202 freq.type = V4L2_TUNER_ANALOG_TV;
205 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
209 static int check_frequency(struct pvr2_hdw *hdw)
211 return hdw->freqDirty != 0;
215 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
216 .check = check_frequency,
217 .update = set_frequency,
222 static void set_size(struct pvr2_hdw *hdw)
224 struct v4l2_format fmt;
226 memset(&fmt,0,sizeof(fmt));
228 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
229 fmt.fmt.pix.width = hdw->res_hor_val;
230 fmt.fmt.pix.height = hdw->res_ver_val;
232 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
233 fmt.fmt.pix.width,fmt.fmt.pix.height);
235 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
239 static int check_size(struct pvr2_hdw *hdw)
241 return (hdw->res_hor_dirty || hdw->res_ver_dirty);
245 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
252 static void set_crop(struct pvr2_hdw *hdw)
254 struct v4l2_crop crop;
256 memset(&crop, 0, sizeof crop);
257 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
258 crop.c.left = hdw->cropl_val;
259 crop.c.top = hdw->cropt_val;
260 crop.c.height = hdw->croph_val;
261 crop.c.width = hdw->cropw_val;
263 pvr2_trace(PVR2_TRACE_CHIPS,
264 "i2c v4l2 set_crop crop=%d:%d:%d:%d",
265 crop.c.width, crop.c.height, crop.c.left, crop.c.top);
267 pvr2_i2c_core_cmd(hdw, VIDIOC_S_CROP, &crop);
270 static int check_crop(struct pvr2_hdw *hdw)
272 return (hdw->cropl_dirty || hdw->cropt_dirty ||
273 hdw->cropw_dirty || hdw->croph_dirty);
276 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop = {
283 static void do_log(struct pvr2_hdw *hdw)
285 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
286 pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
291 static int check_log(struct pvr2_hdw *hdw)
293 return hdw->log_requested != 0;
297 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
304 void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
306 pvr2_i2c_client_cmd(cp,
307 (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
311 void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp)
314 struct pvr2_hdw *hdw = cp->hdw;
315 if (hdw->cropcap_stale) {
316 hdw->cropcap_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
317 stat = pvr2_i2c_client_cmd(cp, VIDIOC_CROPCAP,
320 /* Check was successful, so the data is no
321 longer considered stale. */
322 hdw->cropcap_stale = 0;
325 pvr2_i2c_client_cmd(cp, VIDIOC_G_TUNER, &hdw->tuner_signal_info);
331 Stuff for Emacs to see, in order to encourage consistent editing style:
332 *** Local Variables: ***
334 *** fill-column: 70 ***
336 *** c-basic-offset: 8 ***