5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
6 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License
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
23 #include "pvrusb2-i2c-cmd-v4l2.h"
24 #include "pvrusb2-hdw-internal.h"
25 #include "pvrusb2-debug.h"
26 #include <linux/videodev2.h>
29 static void set_standard(struct pvr2_hdw *hdw)
32 vs = hdw->std_mask_cur;
33 pvr2_trace(PVR2_TRACE_CHIPS,
34 "i2c v4l2 set_standard(0x%llx)",(long long unsigned)vs);
36 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
40 static int check_standard(struct pvr2_hdw *hdw)
42 return hdw->std_dirty != 0;
46 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
47 .check = check_standard,
48 .update = set_standard,
49 .name = "v4l2_standard",
53 static void set_bcsh(struct pvr2_hdw *hdw)
55 struct v4l2_control ctrl;
56 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh"
57 " b=%d c=%d s=%d h=%d",
58 hdw->brightness_val,hdw->contrast_val,
59 hdw->saturation_val,hdw->hue_val);
60 memset(&ctrl,0,sizeof(ctrl));
61 ctrl.id = V4L2_CID_BRIGHTNESS;
62 ctrl.value = hdw->brightness_val;
63 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
64 ctrl.id = V4L2_CID_CONTRAST;
65 ctrl.value = hdw->contrast_val;
66 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
67 ctrl.id = V4L2_CID_SATURATION;
68 ctrl.value = hdw->saturation_val;
69 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
70 ctrl.id = V4L2_CID_HUE;
71 ctrl.value = hdw->hue_val;
72 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
76 static int check_bcsh(struct pvr2_hdw *hdw)
78 return (hdw->brightness_dirty ||
79 hdw->contrast_dirty ||
80 hdw->saturation_dirty ||
85 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
92 static void set_volume(struct pvr2_hdw *hdw)
94 struct v4l2_control ctrl;
95 pvr2_trace(PVR2_TRACE_CHIPS,
97 "(vol=%d bal=%d bas=%d treb=%d mute=%d)",
103 memset(&ctrl,0,sizeof(ctrl));
104 ctrl.id = V4L2_CID_AUDIO_MUTE;
105 ctrl.value = hdw->mute_val ? 1 : 0;
106 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
107 ctrl.id = V4L2_CID_AUDIO_VOLUME;
108 ctrl.value = hdw->volume_val;
109 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
110 ctrl.id = V4L2_CID_AUDIO_BALANCE;
111 ctrl.value = hdw->balance_val;
112 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
113 ctrl.id = V4L2_CID_AUDIO_BASS;
114 ctrl.value = hdw->bass_val;
115 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
116 ctrl.id = V4L2_CID_AUDIO_TREBLE;
117 ctrl.value = hdw->treble_val;
118 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
122 static int check_volume(struct pvr2_hdw *hdw)
124 return (hdw->volume_dirty ||
125 hdw->balance_dirty ||
132 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
133 .check = check_volume,
134 .update = set_volume,
135 .name = "v4l2_volume",
139 static void set_frequency(struct pvr2_hdw *hdw)
142 struct v4l2_frequency freq;
144 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
145 memset(&freq,0,sizeof(freq));
146 freq.frequency = fv / 62500;
148 freq.type = V4L2_TUNER_ANALOG_TV;
149 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
153 static int check_frequency(struct pvr2_hdw *hdw)
155 return hdw->freqDirty != 0;
159 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
160 .check = check_frequency,
161 .update = set_frequency,
166 static void set_size(struct pvr2_hdw *hdw)
168 struct v4l2_format fmt;
170 memset(&fmt,0,sizeof(fmt));
172 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
173 fmt.fmt.pix.width = hdw->res_hor_val;
174 fmt.fmt.pix.height = hdw->res_ver_val;
176 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
177 fmt.fmt.pix.width,fmt.fmt.pix.height);
179 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
183 static int check_size(struct pvr2_hdw *hdw)
185 return (hdw->res_hor_dirty || hdw->res_ver_dirty);
189 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
196 static void do_log(struct pvr2_hdw *hdw)
198 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
199 pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
204 static int check_log(struct pvr2_hdw *hdw)
206 return hdw->log_requested != 0;
210 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
217 void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
219 pvr2_i2c_client_cmd(cp,
220 (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
225 Stuff for Emacs to see, in order to encourage consistent editing style:
226 *** Local Variables: ***
228 *** fill-column: 70 ***
230 *** c-basic-offset: 8 ***