V4L/DVB (4367): Videodev: Handle class_device related errors
[linux-2.6] / drivers / media / video / pvrusb2 / pvrusb2-i2c-cmd-v4l2.c
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>
27
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,
34                    "i2c v4l2 set_standard(0x%llx)",(__u64)vs);
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
53 static void set_bcsh(struct pvr2_hdw *hdw)
54 {
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);
73 }
74
75
76 static int check_bcsh(struct pvr2_hdw *hdw)
77 {
78         return (hdw->brightness_dirty ||
79                 hdw->contrast_dirty ||
80                 hdw->saturation_dirty ||
81                 hdw->hue_dirty);
82 }
83
84
85 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
86         .check = check_bcsh,
87         .update = set_bcsh,
88         .name = "v4l2_bcsh",
89 };
90
91
92 static void set_volume(struct pvr2_hdw *hdw)
93 {
94         struct v4l2_control ctrl;
95         pvr2_trace(PVR2_TRACE_CHIPS,
96                    "i2c v4l2 set_volume"
97                    "(vol=%d bal=%d bas=%d treb=%d mute=%d)",
98                    hdw->volume_val,
99                    hdw->balance_val,
100                    hdw->bass_val,
101                    hdw->treble_val,
102                    hdw->mute_val);
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);
119 }
120
121
122 static int check_volume(struct pvr2_hdw *hdw)
123 {
124         return (hdw->volume_dirty ||
125                 hdw->balance_dirty ||
126                 hdw->bass_dirty ||
127                 hdw->treble_dirty ||
128                 hdw->mute_dirty);
129 }
130
131
132 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
133         .check = check_volume,
134         .update = set_volume,
135         .name = "v4l2_volume",
136 };
137
138
139 static void set_frequency(struct pvr2_hdw *hdw)
140 {
141         unsigned long fv;
142         struct v4l2_frequency freq;
143         fv = hdw->freqVal;
144         pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
145         memset(&freq,0,sizeof(freq));
146         freq.frequency = fv / 62500;
147         freq.tuner = 0;
148         freq.type = V4L2_TUNER_ANALOG_TV;
149         pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
150 }
151
152
153 static int check_frequency(struct pvr2_hdw *hdw)
154 {
155         return hdw->freqDirty != 0;
156 }
157
158
159 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
160         .check = check_frequency,
161         .update = set_frequency,
162         .name = "v4l2_freq",
163 };
164
165
166 static void set_size(struct pvr2_hdw *hdw)
167 {
168         struct v4l2_format fmt;
169
170         memset(&fmt,0,sizeof(fmt));
171
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;
175
176         pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
177                            fmt.fmt.pix.width,fmt.fmt.pix.height);
178
179         pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
180 }
181
182
183 static int check_size(struct pvr2_hdw *hdw)
184 {
185         return (hdw->res_hor_dirty || hdw->res_ver_dirty);
186 }
187
188
189 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
190         .check = check_size,
191         .update = set_size,
192         .name = "v4l2_size",
193 };
194
195
196 static void do_log(struct pvr2_hdw *hdw)
197 {
198         pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
199         pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
200
201 }
202
203
204 static int check_log(struct pvr2_hdw *hdw)
205 {
206         return hdw->log_requested != 0;
207 }
208
209
210 const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
211         .check = check_log,
212         .update = do_log,
213         .name = "v4l2_log",
214 };
215
216
217 void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
218 {
219         pvr2_i2c_client_cmd(cp,
220                             (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
221 }
222
223
224 /*
225   Stuff for Emacs to see, in order to encourage consistent editing style:
226   *** Local Variables: ***
227   *** mode: c ***
228   *** fill-column: 70 ***
229   *** tab-width: 8 ***
230   *** c-basic-offset: 8 ***
231   *** End: ***
232   */