Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * $Id$ |
| 4 | * |
| 5 | * Copyright (C) 2005 Mike Isely <isely@pobox.com> |
| 6 | * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr> |
| 7 | * |
| 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 |
| 11 | * |
| 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. |
| 16 | * |
| 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 |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include "pvrusb2-i2c-cmd-v4l2.h" |
| 24 | #include "pvrusb2-hdw-internal.h" |
| 25 | #include "pvrusb2-debug.h" |
| 26 | #include <linux/videodev2.h> |
Pantelis Koukousoulas | 275b2e2 | 2006-12-27 23:05:19 -0300 | [diff] [blame^] | 27 | #include <media/v4l2-common.h> /* AUDC_SET_RADIO */ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 28 | |
| 29 | static void set_standard(struct pvr2_hdw *hdw) |
| 30 | { |
| 31 | v4l2_std_id vs; |
| 32 | vs = hdw->std_mask_cur; |
| 33 | pvr2_trace(PVR2_TRACE_CHIPS, |
Mauro Carvalho Chehab | 40346b2 | 2006-08-08 15:21:47 -0300 | [diff] [blame] | 34 | "i2c v4l2 set_standard(0x%llx)",(long long unsigned)vs); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 35 | |
| 36 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | static int check_standard(struct pvr2_hdw *hdw) |
| 41 | { |
| 42 | return hdw->std_dirty != 0; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = { |
| 47 | .check = check_standard, |
| 48 | .update = set_standard, |
| 49 | .name = "v4l2_standard", |
| 50 | }; |
| 51 | |
| 52 | |
Pantelis Koukousoulas | 275b2e2 | 2006-12-27 23:05:19 -0300 | [diff] [blame^] | 53 | static void set_radio(struct pvr2_hdw *hdw) |
| 54 | { |
| 55 | pvr2_trace(PVR2_TRACE_CHIPS, |
| 56 | "i2c v4l2 set_radio()"); |
| 57 | |
| 58 | if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) { |
| 59 | pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL); |
| 60 | } else { |
| 61 | set_standard(hdw); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | |
| 66 | static int check_radio(struct pvr2_hdw *hdw) |
| 67 | { |
| 68 | return hdw->input_dirty != 0; |
| 69 | } |
| 70 | |
| 71 | |
| 72 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_radio = { |
| 73 | .check = check_radio, |
| 74 | .update = set_radio, |
| 75 | .name = "v4l2_radio", |
| 76 | }; |
| 77 | |
| 78 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 79 | static void set_bcsh(struct pvr2_hdw *hdw) |
| 80 | { |
| 81 | struct v4l2_control ctrl; |
| 82 | pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh" |
| 83 | " b=%d c=%d s=%d h=%d", |
| 84 | hdw->brightness_val,hdw->contrast_val, |
| 85 | hdw->saturation_val,hdw->hue_val); |
| 86 | memset(&ctrl,0,sizeof(ctrl)); |
| 87 | ctrl.id = V4L2_CID_BRIGHTNESS; |
| 88 | ctrl.value = hdw->brightness_val; |
| 89 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 90 | ctrl.id = V4L2_CID_CONTRAST; |
| 91 | ctrl.value = hdw->contrast_val; |
| 92 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 93 | ctrl.id = V4L2_CID_SATURATION; |
| 94 | ctrl.value = hdw->saturation_val; |
| 95 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 96 | ctrl.id = V4L2_CID_HUE; |
| 97 | ctrl.value = hdw->hue_val; |
| 98 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | static int check_bcsh(struct pvr2_hdw *hdw) |
| 103 | { |
| 104 | return (hdw->brightness_dirty || |
| 105 | hdw->contrast_dirty || |
| 106 | hdw->saturation_dirty || |
| 107 | hdw->hue_dirty); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = { |
| 112 | .check = check_bcsh, |
| 113 | .update = set_bcsh, |
| 114 | .name = "v4l2_bcsh", |
| 115 | }; |
| 116 | |
| 117 | |
| 118 | static void set_volume(struct pvr2_hdw *hdw) |
| 119 | { |
| 120 | struct v4l2_control ctrl; |
| 121 | pvr2_trace(PVR2_TRACE_CHIPS, |
| 122 | "i2c v4l2 set_volume" |
| 123 | "(vol=%d bal=%d bas=%d treb=%d mute=%d)", |
| 124 | hdw->volume_val, |
| 125 | hdw->balance_val, |
| 126 | hdw->bass_val, |
| 127 | hdw->treble_val, |
| 128 | hdw->mute_val); |
| 129 | memset(&ctrl,0,sizeof(ctrl)); |
| 130 | ctrl.id = V4L2_CID_AUDIO_MUTE; |
| 131 | ctrl.value = hdw->mute_val ? 1 : 0; |
| 132 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 133 | ctrl.id = V4L2_CID_AUDIO_VOLUME; |
| 134 | ctrl.value = hdw->volume_val; |
| 135 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 136 | ctrl.id = V4L2_CID_AUDIO_BALANCE; |
| 137 | ctrl.value = hdw->balance_val; |
| 138 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 139 | ctrl.id = V4L2_CID_AUDIO_BASS; |
| 140 | ctrl.value = hdw->bass_val; |
| 141 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 142 | ctrl.id = V4L2_CID_AUDIO_TREBLE; |
| 143 | ctrl.value = hdw->treble_val; |
| 144 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | static int check_volume(struct pvr2_hdw *hdw) |
| 149 | { |
| 150 | return (hdw->volume_dirty || |
| 151 | hdw->balance_dirty || |
| 152 | hdw->bass_dirty || |
| 153 | hdw->treble_dirty || |
| 154 | hdw->mute_dirty); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = { |
| 159 | .check = check_volume, |
| 160 | .update = set_volume, |
| 161 | .name = "v4l2_volume", |
| 162 | }; |
| 163 | |
| 164 | |
| 165 | static void set_frequency(struct pvr2_hdw *hdw) |
| 166 | { |
| 167 | unsigned long fv; |
| 168 | struct v4l2_frequency freq; |
| 169 | fv = hdw->freqVal; |
| 170 | pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv); |
| 171 | memset(&freq,0,sizeof(freq)); |
| 172 | freq.frequency = fv / 62500; |
| 173 | freq.tuner = 0; |
Pantelis Koukousoulas | 275b2e2 | 2006-12-27 23:05:19 -0300 | [diff] [blame^] | 174 | freq.type = (hdw->input_val == PVR2_CVAL_INPUT_RADIO) ? |
| 175 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 176 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq); |
| 177 | } |
| 178 | |
| 179 | |
| 180 | static int check_frequency(struct pvr2_hdw *hdw) |
| 181 | { |
| 182 | return hdw->freqDirty != 0; |
| 183 | } |
| 184 | |
| 185 | |
| 186 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = { |
| 187 | .check = check_frequency, |
| 188 | .update = set_frequency, |
| 189 | .name = "v4l2_freq", |
| 190 | }; |
| 191 | |
| 192 | |
| 193 | static void set_size(struct pvr2_hdw *hdw) |
| 194 | { |
| 195 | struct v4l2_format fmt; |
| 196 | |
| 197 | memset(&fmt,0,sizeof(fmt)); |
| 198 | |
| 199 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 200 | fmt.fmt.pix.width = hdw->res_hor_val; |
| 201 | fmt.fmt.pix.height = hdw->res_ver_val; |
| 202 | |
| 203 | pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)", |
| 204 | fmt.fmt.pix.width,fmt.fmt.pix.height); |
| 205 | |
| 206 | pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt); |
| 207 | } |
| 208 | |
| 209 | |
| 210 | static int check_size(struct pvr2_hdw *hdw) |
| 211 | { |
| 212 | return (hdw->res_hor_dirty || hdw->res_ver_dirty); |
| 213 | } |
| 214 | |
| 215 | |
| 216 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = { |
| 217 | .check = check_size, |
| 218 | .update = set_size, |
| 219 | .name = "v4l2_size", |
| 220 | }; |
| 221 | |
| 222 | |
| 223 | static void do_log(struct pvr2_hdw *hdw) |
| 224 | { |
| 225 | pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()"); |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 226 | pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 227 | |
| 228 | } |
| 229 | |
| 230 | |
| 231 | static int check_log(struct pvr2_hdw *hdw) |
| 232 | { |
| 233 | return hdw->log_requested != 0; |
| 234 | } |
| 235 | |
| 236 | |
| 237 | const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = { |
| 238 | .check = check_log, |
| 239 | .update = do_log, |
| 240 | .name = "v4l2_log", |
| 241 | }; |
| 242 | |
| 243 | |
| 244 | void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl) |
| 245 | { |
| 246 | pvr2_i2c_client_cmd(cp, |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 247 | (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | |
| 251 | /* |
| 252 | Stuff for Emacs to see, in order to encourage consistent editing style: |
| 253 | *** Local Variables: *** |
| 254 | *** mode: c *** |
| 255 | *** fill-column: 70 *** |
| 256 | *** tab-width: 8 *** |
| 257 | *** c-basic-offset: 8 *** |
| 258 | *** End: *** |
| 259 | */ |