Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1 | /* |
| 2 | * |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 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> |
Mike Isely | 7a4a377 | 2006-12-27 23:40:59 -0300 | [diff] [blame] | 26 | #include <media/v4l2-common.h> |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 27 | |
| 28 | static void set_standard(struct pvr2_hdw *hdw) |
| 29 | { |
Mike Isely | f5156b0 | 2006-12-27 23:14:54 -0300 | [diff] [blame] | 30 | pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_standard"); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 31 | |
Mike Isely | f5156b0 | 2006-12-27 23:14:54 -0300 | [diff] [blame] | 32 | if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) { |
| 33 | pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL); |
| 34 | } else { |
| 35 | v4l2_std_id vs; |
| 36 | vs = hdw->std_mask_cur; |
| 37 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs); |
| 38 | } |
Mike Isely | 18103c5 | 2007-01-20 00:09:47 -0300 | [diff] [blame] | 39 | hdw->tuner_signal_stale = !0; |
Mike Isely | 432907f | 2008-08-31 21:02:20 -0300 | [diff] [blame] | 40 | hdw->cropcap_stale = !0; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | |
| 44 | static int check_standard(struct pvr2_hdw *hdw) |
| 45 | { |
Mike Isely | f5156b0 | 2006-12-27 23:14:54 -0300 | [diff] [blame] | 46 | return (hdw->input_dirty != 0) || (hdw->std_dirty != 0); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | |
| 50 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = { |
| 51 | .check = check_standard, |
| 52 | .update = set_standard, |
| 53 | .name = "v4l2_standard", |
| 54 | }; |
| 55 | |
| 56 | |
| 57 | static void set_bcsh(struct pvr2_hdw *hdw) |
| 58 | { |
| 59 | struct v4l2_control ctrl; |
| 60 | pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh" |
| 61 | " b=%d c=%d s=%d h=%d", |
| 62 | hdw->brightness_val,hdw->contrast_val, |
| 63 | hdw->saturation_val,hdw->hue_val); |
| 64 | memset(&ctrl,0,sizeof(ctrl)); |
| 65 | ctrl.id = V4L2_CID_BRIGHTNESS; |
| 66 | ctrl.value = hdw->brightness_val; |
| 67 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 68 | ctrl.id = V4L2_CID_CONTRAST; |
| 69 | ctrl.value = hdw->contrast_val; |
| 70 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 71 | ctrl.id = V4L2_CID_SATURATION; |
| 72 | ctrl.value = hdw->saturation_val; |
| 73 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 74 | ctrl.id = V4L2_CID_HUE; |
| 75 | ctrl.value = hdw->hue_val; |
| 76 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | static int check_bcsh(struct pvr2_hdw *hdw) |
| 81 | { |
| 82 | return (hdw->brightness_dirty || |
| 83 | hdw->contrast_dirty || |
| 84 | hdw->saturation_dirty || |
| 85 | hdw->hue_dirty); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = { |
| 90 | .check = check_bcsh, |
| 91 | .update = set_bcsh, |
| 92 | .name = "v4l2_bcsh", |
| 93 | }; |
| 94 | |
| 95 | |
| 96 | static void set_volume(struct pvr2_hdw *hdw) |
| 97 | { |
| 98 | struct v4l2_control ctrl; |
| 99 | pvr2_trace(PVR2_TRACE_CHIPS, |
| 100 | "i2c v4l2 set_volume" |
| 101 | "(vol=%d bal=%d bas=%d treb=%d mute=%d)", |
| 102 | hdw->volume_val, |
| 103 | hdw->balance_val, |
| 104 | hdw->bass_val, |
| 105 | hdw->treble_val, |
| 106 | hdw->mute_val); |
| 107 | memset(&ctrl,0,sizeof(ctrl)); |
| 108 | ctrl.id = V4L2_CID_AUDIO_MUTE; |
| 109 | ctrl.value = hdw->mute_val ? 1 : 0; |
| 110 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 111 | ctrl.id = V4L2_CID_AUDIO_VOLUME; |
| 112 | ctrl.value = hdw->volume_val; |
| 113 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 114 | ctrl.id = V4L2_CID_AUDIO_BALANCE; |
| 115 | ctrl.value = hdw->balance_val; |
| 116 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 117 | ctrl.id = V4L2_CID_AUDIO_BASS; |
| 118 | ctrl.value = hdw->bass_val; |
| 119 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 120 | ctrl.id = V4L2_CID_AUDIO_TREBLE; |
| 121 | ctrl.value = hdw->treble_val; |
| 122 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | static int check_volume(struct pvr2_hdw *hdw) |
| 127 | { |
| 128 | return (hdw->volume_dirty || |
| 129 | hdw->balance_dirty || |
| 130 | hdw->bass_dirty || |
| 131 | hdw->treble_dirty || |
| 132 | hdw->mute_dirty); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = { |
| 137 | .check = check_volume, |
| 138 | .update = set_volume, |
| 139 | .name = "v4l2_volume", |
| 140 | }; |
| 141 | |
| 142 | |
Mike Isely | 606cf9c | 2007-01-20 01:56:04 -0300 | [diff] [blame] | 143 | static void set_audiomode(struct pvr2_hdw *hdw) |
| 144 | { |
| 145 | struct v4l2_tuner vt; |
| 146 | memset(&vt,0,sizeof(vt)); |
| 147 | vt.audmode = hdw->audiomode_val; |
| 148 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_TUNER,&vt); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | static int check_audiomode(struct pvr2_hdw *hdw) |
| 153 | { |
| 154 | return (hdw->input_dirty || |
| 155 | hdw->audiomode_dirty); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode = { |
| 160 | .check = check_audiomode, |
| 161 | .update = set_audiomode, |
| 162 | .name = "v4l2_audiomode", |
| 163 | }; |
| 164 | |
| 165 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 166 | static void set_frequency(struct pvr2_hdw *hdw) |
| 167 | { |
| 168 | unsigned long fv; |
| 169 | struct v4l2_frequency freq; |
Mike Isely | 1bde028 | 2006-12-27 23:30:13 -0300 | [diff] [blame] | 170 | fv = pvr2_hdw_get_cur_freq(hdw); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 171 | pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv); |
Mike Isely | 18103c5 | 2007-01-20 00:09:47 -0300 | [diff] [blame] | 172 | if (hdw->tuner_signal_stale) { |
| 173 | pvr2_i2c_core_status_poll(hdw); |
| 174 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 175 | memset(&freq,0,sizeof(freq)); |
Mike Isely | 18103c5 | 2007-01-20 00:09:47 -0300 | [diff] [blame] | 176 | if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) { |
Mike Isely | f138212 | 2006-12-27 23:23:22 -0300 | [diff] [blame] | 177 | // ((fv * 1000) / 62500) |
| 178 | freq.frequency = (fv * 2) / 125; |
Mike Isely | f138212 | 2006-12-27 23:23:22 -0300 | [diff] [blame] | 179 | } else { |
| 180 | freq.frequency = fv / 62500; |
Mike Isely | 18103c5 | 2007-01-20 00:09:47 -0300 | [diff] [blame] | 181 | } |
| 182 | /* tuner-core currently doesn't seem to care about this, but |
| 183 | let's set it anyway for completeness. */ |
| 184 | if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) { |
| 185 | freq.type = V4L2_TUNER_RADIO; |
| 186 | } else { |
Mike Isely | f138212 | 2006-12-27 23:23:22 -0300 | [diff] [blame] | 187 | freq.type = V4L2_TUNER_ANALOG_TV; |
| 188 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 189 | freq.tuner = 0; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 190 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq); |
| 191 | } |
| 192 | |
| 193 | |
| 194 | static int check_frequency(struct pvr2_hdw *hdw) |
| 195 | { |
| 196 | return hdw->freqDirty != 0; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = { |
| 201 | .check = check_frequency, |
| 202 | .update = set_frequency, |
| 203 | .name = "v4l2_freq", |
| 204 | }; |
| 205 | |
| 206 | |
| 207 | static void set_size(struct pvr2_hdw *hdw) |
| 208 | { |
| 209 | struct v4l2_format fmt; |
| 210 | |
| 211 | memset(&fmt,0,sizeof(fmt)); |
| 212 | |
| 213 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 214 | fmt.fmt.pix.width = hdw->res_hor_val; |
| 215 | fmt.fmt.pix.height = hdw->res_ver_val; |
| 216 | |
| 217 | pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)", |
| 218 | fmt.fmt.pix.width,fmt.fmt.pix.height); |
| 219 | |
| 220 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | static int check_size(struct pvr2_hdw *hdw) |
| 225 | { |
| 226 | return (hdw->res_hor_dirty || hdw->res_ver_dirty); |
| 227 | } |
| 228 | |
| 229 | |
| 230 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = { |
| 231 | .check = check_size, |
| 232 | .update = set_size, |
| 233 | .name = "v4l2_size", |
| 234 | }; |
| 235 | |
| 236 | |
vdb128@picaros.org | e784bfb | 2008-08-30 18:26:39 -0300 | [diff] [blame] | 237 | static void set_crop(struct pvr2_hdw *hdw) |
| 238 | { |
vdb128@picaros.org | e784bfb | 2008-08-30 18:26:39 -0300 | [diff] [blame] | 239 | struct v4l2_crop crop; |
vdb128@picaros.org | e784bfb | 2008-08-30 18:26:39 -0300 | [diff] [blame] | 240 | |
| 241 | memset(&crop, 0, sizeof crop); |
| 242 | crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mike Isely | 432907f | 2008-08-31 21:02:20 -0300 | [diff] [blame] | 243 | crop.c.left = hdw->cropl_val; |
| 244 | crop.c.top = hdw->cropt_val; |
vdb128@picaros.org | e784bfb | 2008-08-30 18:26:39 -0300 | [diff] [blame] | 245 | crop.c.height = hdw->croph_val; |
| 246 | crop.c.width = hdw->cropw_val; |
| 247 | |
| 248 | pvr2_trace(PVR2_TRACE_CHIPS, |
Mike Isely | 432907f | 2008-08-31 21:02:20 -0300 | [diff] [blame] | 249 | "i2c v4l2 set_crop crop=%d:%d:%d:%d", |
vdb128@picaros.org | e784bfb | 2008-08-30 18:26:39 -0300 | [diff] [blame] | 250 | crop.c.width, crop.c.height, crop.c.left, crop.c.top); |
| 251 | |
Mike Isely | 432907f | 2008-08-31 21:02:20 -0300 | [diff] [blame] | 252 | pvr2_i2c_core_cmd(hdw, VIDIOC_S_CROP, &crop); |
vdb128@picaros.org | e784bfb | 2008-08-30 18:26:39 -0300 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | static int check_crop(struct pvr2_hdw *hdw) |
| 256 | { |
Mike Isely | 2bb87c2 | 2008-09-03 21:51:59 -0300 | [diff] [blame] | 257 | return (hdw->cropl_dirty || hdw->cropt_dirty || |
| 258 | hdw->cropw_dirty || hdw->croph_dirty); |
vdb128@picaros.org | e784bfb | 2008-08-30 18:26:39 -0300 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop = { |
| 262 | .check = check_crop, |
| 263 | .update = set_crop, |
| 264 | .name = "v4l2_crop", |
| 265 | }; |
| 266 | |
| 267 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 268 | static void do_log(struct pvr2_hdw *hdw) |
| 269 | { |
| 270 | pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()"); |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 271 | pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 272 | |
| 273 | } |
| 274 | |
| 275 | |
| 276 | static int check_log(struct pvr2_hdw *hdw) |
| 277 | { |
| 278 | return hdw->log_requested != 0; |
| 279 | } |
| 280 | |
| 281 | |
| 282 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = { |
| 283 | .check = check_log, |
| 284 | .update = do_log, |
| 285 | .name = "v4l2_log", |
| 286 | }; |
| 287 | |
| 288 | |
| 289 | void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl) |
| 290 | { |
| 291 | pvr2_i2c_client_cmd(cp, |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 292 | (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | |
Mike Isely | 18103c5 | 2007-01-20 00:09:47 -0300 | [diff] [blame] | 296 | void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp) |
| 297 | { |
Mike Isely | 432907f | 2008-08-31 21:02:20 -0300 | [diff] [blame] | 298 | int stat; |
| 299 | struct pvr2_hdw *hdw = cp->hdw; |
| 300 | if (hdw->cropcap_stale) { |
| 301 | hdw->cropcap_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 302 | stat = pvr2_i2c_client_cmd(cp, VIDIOC_CROPCAP, |
| 303 | &hdw->cropcap_info); |
| 304 | if (stat == 0) { |
| 305 | /* Check was successful, so the data is no |
| 306 | longer considered stale. */ |
| 307 | hdw->cropcap_stale = 0; |
| 308 | } |
| 309 | } |
| 310 | pvr2_i2c_client_cmd(cp, VIDIOC_G_TUNER, &hdw->tuner_signal_info); |
Mike Isely | 18103c5 | 2007-01-20 00:09:47 -0300 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 314 | /* |
| 315 | Stuff for Emacs to see, in order to encourage consistent editing style: |
| 316 | *** Local Variables: *** |
| 317 | *** mode: c *** |
| 318 | *** fill-column: 70 *** |
| 319 | *** tab-width: 8 *** |
| 320 | *** c-basic-offset: 8 *** |
| 321 | *** End: *** |
| 322 | */ |