]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
7afe513bebf9fe4a90fd0b7ebc9b0f98f9d14e44
[linux-2.6-omap-h63xx.git] / drivers / media / video / pvrusb2 / pvrusb2-i2c-cmd-v4l2.c
1 /*
2  *
3  *
4  *  Copyright (C) 2005 Mike Isely <isely@pobox.com>
5  *  Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
6  *
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
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
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>
27
28
29 static void execute_init(struct pvr2_hdw *hdw)
30 {
31         u32 dummy = 0;
32         pvr2_trace(PVR2_TRACE_CHIPS, "i2c v4l2 init");
33         pvr2_i2c_core_cmd(hdw, VIDIOC_INT_INIT, &dummy);
34 }
35
36
37 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_init = {
38         .update = execute_init,
39         .name = "v4l2_init",
40 };
41
42
43 static void set_standard(struct pvr2_hdw *hdw)
44 {
45         pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_standard");
46
47         if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
48                 pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL);
49         } else {
50                 v4l2_std_id vs;
51                 vs = hdw->std_mask_cur;
52                 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
53         }
54         hdw->tuner_signal_stale = !0;
55         hdw->cropcap_stale = !0;
56 }
57
58
59 static int check_standard(struct pvr2_hdw *hdw)
60 {
61         return (hdw->input_dirty != 0) || (hdw->std_dirty != 0);
62 }
63
64
65 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
66         .check = check_standard,
67         .update = set_standard,
68         .name = "v4l2_standard",
69 };
70
71
72 static void set_bcsh(struct pvr2_hdw *hdw)
73 {
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);
92 }
93
94
95 static int check_bcsh(struct pvr2_hdw *hdw)
96 {
97         return (hdw->brightness_dirty ||
98                 hdw->contrast_dirty ||
99                 hdw->saturation_dirty ||
100                 hdw->hue_dirty);
101 }
102
103
104 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
105         .check = check_bcsh,
106         .update = set_bcsh,
107         .name = "v4l2_bcsh",
108 };
109
110
111 static void set_volume(struct pvr2_hdw *hdw)
112 {
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)",
117                    hdw->volume_val,
118                    hdw->balance_val,
119                    hdw->bass_val,
120                    hdw->treble_val,
121                    hdw->mute_val);
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);
138 }
139
140
141 static int check_volume(struct pvr2_hdw *hdw)
142 {
143         return (hdw->volume_dirty ||
144                 hdw->balance_dirty ||
145                 hdw->bass_dirty ||
146                 hdw->treble_dirty ||
147                 hdw->mute_dirty);
148 }
149
150
151 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
152         .check = check_volume,
153         .update = set_volume,
154         .name = "v4l2_volume",
155 };
156
157
158 static void set_audiomode(struct pvr2_hdw *hdw)
159 {
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);
164 }
165
166
167 static int check_audiomode(struct pvr2_hdw *hdw)
168 {
169         return (hdw->input_dirty ||
170                 hdw->audiomode_dirty);
171 }
172
173
174 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode = {
175         .check = check_audiomode,
176         .update = set_audiomode,
177         .name = "v4l2_audiomode",
178 };
179
180
181 static void set_frequency(struct pvr2_hdw *hdw)
182 {
183         unsigned long fv;
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);
189         }
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;
194         } else {
195                 freq.frequency = fv / 62500;
196         }
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;
201         } else {
202                 freq.type = V4L2_TUNER_ANALOG_TV;
203         }
204         freq.tuner = 0;
205         pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
206 }
207
208
209 static int check_frequency(struct pvr2_hdw *hdw)
210 {
211         return hdw->freqDirty != 0;
212 }
213
214
215 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
216         .check = check_frequency,
217         .update = set_frequency,
218         .name = "v4l2_freq",
219 };
220
221
222 static void set_size(struct pvr2_hdw *hdw)
223 {
224         struct v4l2_format fmt;
225
226         memset(&fmt,0,sizeof(fmt));
227
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;
231
232         pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
233                            fmt.fmt.pix.width,fmt.fmt.pix.height);
234
235         pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
236 }
237
238
239 static int check_size(struct pvr2_hdw *hdw)
240 {
241         return (hdw->res_hor_dirty || hdw->res_ver_dirty);
242 }
243
244
245 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
246         .check = check_size,
247         .update = set_size,
248         .name = "v4l2_size",
249 };
250
251
252 static void set_crop(struct pvr2_hdw *hdw)
253 {
254         struct v4l2_crop crop;
255
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;
262
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);
266
267         pvr2_i2c_core_cmd(hdw, VIDIOC_S_CROP, &crop);
268 }
269
270 static int check_crop(struct pvr2_hdw *hdw)
271 {
272         return (hdw->cropl_dirty || hdw->cropt_dirty ||
273                 hdw->cropw_dirty || hdw->croph_dirty);
274 }
275
276 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop = {
277         .check = check_crop,
278         .update = set_crop,
279         .name = "v4l2_crop",
280 };
281
282
283 static void do_log(struct pvr2_hdw *hdw)
284 {
285         pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
286         pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
287
288 }
289
290
291 static int check_log(struct pvr2_hdw *hdw)
292 {
293         return hdw->log_requested != 0;
294 }
295
296
297 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
298         .check = check_log,
299         .update = do_log,
300         .name = "v4l2_log",
301 };
302
303
304 void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
305 {
306         pvr2_i2c_client_cmd(cp,
307                             (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
308 }
309
310
311 void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp)
312 {
313         int stat;
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,
318                                            &hdw->cropcap_info);
319                 if (stat == 0) {
320                         /* Check was successful, so the data is no
321                            longer considered stale. */
322                         hdw->cropcap_stale = 0;
323                 }
324         }
325         pvr2_i2c_client_cmd(cp, VIDIOC_G_TUNER, &hdw->tuner_signal_info);
326 }
327
328
329
330 /*
331   Stuff for Emacs to see, in order to encourage consistent editing style:
332   *** Local Variables: ***
333   *** mode: c ***
334   *** fill-column: 70 ***
335   *** tab-width: 8 ***
336   *** c-basic-offset: 8 ***
337   *** End: ***
338   */