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>
27 #include <media/v4l2-common.h> /* AUDC_SET_RADIO */
29 static void set_standard(struct pvr2_hdw *hdw)
31 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_standard");
33 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
34 pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL);
37 vs = hdw->std_mask_cur;
38 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
43 static int check_standard(struct pvr2_hdw *hdw)
45 return (hdw->input_dirty != 0) || (hdw->std_dirty != 0);
49 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
50 .check = check_standard,
51 .update = set_standard,
52 .name = "v4l2_standard",
56 static void set_bcsh(struct pvr2_hdw *hdw)
58 struct v4l2_control ctrl;
59 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh"
60 " b=%d c=%d s=%d h=%d",
61 hdw->brightness_val,hdw->contrast_val,
62 hdw->saturation_val,hdw->hue_val);
63 memset(&ctrl,0,sizeof(ctrl));
64 ctrl.id = V4L2_CID_BRIGHTNESS;
65 ctrl.value = hdw->brightness_val;
66 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
67 ctrl.id = V4L2_CID_CONTRAST;
68 ctrl.value = hdw->contrast_val;
69 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
70 ctrl.id = V4L2_CID_SATURATION;
71 ctrl.value = hdw->saturation_val;
72 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
73 ctrl.id = V4L2_CID_HUE;
74 ctrl.value = hdw->hue_val;
75 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
79 static int check_bcsh(struct pvr2_hdw *hdw)
81 return (hdw->brightness_dirty ||
82 hdw->contrast_dirty ||
83 hdw->saturation_dirty ||
88 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
95 static void set_volume(struct pvr2_hdw *hdw)
97 struct v4l2_control ctrl;
98 pvr2_trace(PVR2_TRACE_CHIPS,
100 "(vol=%d bal=%d bas=%d treb=%d mute=%d)",
106 memset(&ctrl,0,sizeof(ctrl));
107 ctrl.id = V4L2_CID_AUDIO_MUTE;
108 ctrl.value = hdw->mute_val ? 1 : 0;
109 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
110 ctrl.id = V4L2_CID_AUDIO_VOLUME;
111 ctrl.value = hdw->volume_val;
112 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
113 ctrl.id = V4L2_CID_AUDIO_BALANCE;
114 ctrl.value = hdw->balance_val;
115 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
116 ctrl.id = V4L2_CID_AUDIO_BASS;
117 ctrl.value = hdw->bass_val;
118 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
119 ctrl.id = V4L2_CID_AUDIO_TREBLE;
120 ctrl.value = hdw->treble_val;
121 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
125 static int check_volume(struct pvr2_hdw *hdw)
127 return (hdw->volume_dirty ||
128 hdw->balance_dirty ||
135 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
136 .check = check_volume,
137 .update = set_volume,
138 .name = "v4l2_volume",
142 static void set_frequency(struct pvr2_hdw *hdw)
145 struct v4l2_frequency freq;
147 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
148 memset(&freq,0,sizeof(freq));
149 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
150 // ((fv * 1000) / 62500)
151 freq.frequency = (fv * 2) / 125;
152 freq.type = V4L2_TUNER_RADIO;
154 freq.frequency = fv / 62500;
155 freq.type = V4L2_TUNER_ANALOG_TV;
158 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
162 static int check_frequency(struct pvr2_hdw *hdw)
164 return hdw->freqDirty != 0;
168 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
169 .check = check_frequency,
170 .update = set_frequency,
175 static void set_size(struct pvr2_hdw *hdw)
177 struct v4l2_format fmt;
179 memset(&fmt,0,sizeof(fmt));
181 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
182 fmt.fmt.pix.width = hdw->res_hor_val;
183 fmt.fmt.pix.height = hdw->res_ver_val;
185 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
186 fmt.fmt.pix.width,fmt.fmt.pix.height);
188 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
192 static int check_size(struct pvr2_hdw *hdw)
194 return (hdw->res_hor_dirty || hdw->res_ver_dirty);
198 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
205 static void do_log(struct pvr2_hdw *hdw)
207 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
208 pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
213 static int check_log(struct pvr2_hdw *hdw)
215 return hdw->log_requested != 0;
219 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
226 void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
228 pvr2_i2c_client_cmd(cp,
229 (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
234 Stuff for Emacs to see, in order to encourage consistent editing style:
235 *** Local Variables: ***
237 *** fill-column: 70 ***
239 *** c-basic-offset: 8 ***