blob: 8d66ab14428160550aea4bc48b9984c35051865b [file] [log] [blame]
Mike Iselyd8554972006-06-26 20:58:46 -03001/*
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 Koukousoulas275b2e22006-12-27 23:05:19 -030027#include <media/v4l2-common.h> /* AUDC_SET_RADIO */
Mike Iselyd8554972006-06-26 20:58:46 -030028
29static void set_standard(struct pvr2_hdw *hdw)
30{
Mike Iselyf5156b02006-12-27 23:14:54 -030031 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_standard");
Mike Iselyd8554972006-06-26 20:58:46 -030032
Mike Iselyf5156b02006-12-27 23:14:54 -030033 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
34 pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL);
35 } else {
36 v4l2_std_id vs;
37 vs = hdw->std_mask_cur;
38 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
39 }
Mike Iselyd8554972006-06-26 20:58:46 -030040}
41
42
43static int check_standard(struct pvr2_hdw *hdw)
44{
Mike Iselyf5156b02006-12-27 23:14:54 -030045 return (hdw->input_dirty != 0) || (hdw->std_dirty != 0);
Mike Iselyd8554972006-06-26 20:58:46 -030046}
47
48
49const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
50 .check = check_standard,
51 .update = set_standard,
52 .name = "v4l2_standard",
53};
54
55
56static void set_bcsh(struct pvr2_hdw *hdw)
57{
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);
76}
77
78
79static int check_bcsh(struct pvr2_hdw *hdw)
80{
81 return (hdw->brightness_dirty ||
82 hdw->contrast_dirty ||
83 hdw->saturation_dirty ||
84 hdw->hue_dirty);
85}
86
87
88const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
89 .check = check_bcsh,
90 .update = set_bcsh,
91 .name = "v4l2_bcsh",
92};
93
94
95static void set_volume(struct pvr2_hdw *hdw)
96{
97 struct v4l2_control ctrl;
98 pvr2_trace(PVR2_TRACE_CHIPS,
99 "i2c v4l2 set_volume"
100 "(vol=%d bal=%d bas=%d treb=%d mute=%d)",
101 hdw->volume_val,
102 hdw->balance_val,
103 hdw->bass_val,
104 hdw->treble_val,
105 hdw->mute_val);
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);
122}
123
124
125static int check_volume(struct pvr2_hdw *hdw)
126{
127 return (hdw->volume_dirty ||
128 hdw->balance_dirty ||
129 hdw->bass_dirty ||
130 hdw->treble_dirty ||
131 hdw->mute_dirty);
132}
133
134
135const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
136 .check = check_volume,
137 .update = set_volume,
138 .name = "v4l2_volume",
139};
140
141
142static void set_frequency(struct pvr2_hdw *hdw)
143{
144 unsigned long fv;
145 struct v4l2_frequency freq;
146 fv = hdw->freqVal;
147 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
148 memset(&freq,0,sizeof(freq));
Pantelis Koukousoulas25d85272006-12-27 23:06:04 -0300149 freq.frequency = fv;
Mike Iselyd8554972006-06-26 20:58:46 -0300150 freq.tuner = 0;
Pantelis Koukousoulas275b2e22006-12-27 23:05:19 -0300151 freq.type = (hdw->input_val == PVR2_CVAL_INPUT_RADIO) ?
152 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Mike Iselyd8554972006-06-26 20:58:46 -0300153 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
154}
155
156
157static int check_frequency(struct pvr2_hdw *hdw)
158{
159 return hdw->freqDirty != 0;
160}
161
162
163const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
164 .check = check_frequency,
165 .update = set_frequency,
166 .name = "v4l2_freq",
167};
168
169
170static void set_size(struct pvr2_hdw *hdw)
171{
172 struct v4l2_format fmt;
173
174 memset(&fmt,0,sizeof(fmt));
175
176 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
177 fmt.fmt.pix.width = hdw->res_hor_val;
178 fmt.fmt.pix.height = hdw->res_ver_val;
179
180 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
181 fmt.fmt.pix.width,fmt.fmt.pix.height);
182
183 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
184}
185
186
187static int check_size(struct pvr2_hdw *hdw)
188{
189 return (hdw->res_hor_dirty || hdw->res_ver_dirty);
190}
191
192
193const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
194 .check = check_size,
195 .update = set_size,
196 .name = "v4l2_size",
197};
198
199
200static void do_log(struct pvr2_hdw *hdw)
201{
202 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300203 pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
Mike Iselyd8554972006-06-26 20:58:46 -0300204
205}
206
207
208static int check_log(struct pvr2_hdw *hdw)
209{
210 return hdw->log_requested != 0;
211}
212
213
214const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
215 .check = check_log,
216 .update = do_log,
217 .name = "v4l2_log",
218};
219
220
221void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
222{
223 pvr2_i2c_client_cmd(cp,
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300224 (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
Mike Iselyd8554972006-06-26 20:58:46 -0300225}
226
227
228/*
229 Stuff for Emacs to see, in order to encourage consistent editing style:
230 *** Local Variables: ***
231 *** mode: c ***
232 *** fill-column: 70 ***
233 *** tab-width: 8 ***
234 *** c-basic-offset: 8 ***
235 *** End: ***
236 */