blob: b1f6809625e872ebcd69a3be565f18d756655b76 [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>
Mike Isely7a4a3772006-12-27 23:40:59 -030027#include <media/v4l2-common.h>
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 Isely18103c52007-01-20 00:09:47 -030040 hdw->tuner_signal_stale = !0;
Mike Iselyd8554972006-06-26 20:58:46 -030041}
42
43
44static int check_standard(struct pvr2_hdw *hdw)
45{
Mike Iselyf5156b02006-12-27 23:14:54 -030046 return (hdw->input_dirty != 0) || (hdw->std_dirty != 0);
Mike Iselyd8554972006-06-26 20:58:46 -030047}
48
49
50const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
51 .check = check_standard,
52 .update = set_standard,
53 .name = "v4l2_standard",
54};
55
56
57static 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
80static 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
89const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
90 .check = check_bcsh,
91 .update = set_bcsh,
92 .name = "v4l2_bcsh",
93};
94
95
96static 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
126static 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
136const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
137 .check = check_volume,
138 .update = set_volume,
139 .name = "v4l2_volume",
140};
141
142
143static void set_frequency(struct pvr2_hdw *hdw)
144{
145 unsigned long fv;
146 struct v4l2_frequency freq;
Mike Isely1bde0282006-12-27 23:30:13 -0300147 fv = pvr2_hdw_get_cur_freq(hdw);
Mike Iselyd8554972006-06-26 20:58:46 -0300148 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
Mike Isely18103c52007-01-20 00:09:47 -0300149 if (hdw->tuner_signal_stale) {
150 pvr2_i2c_core_status_poll(hdw);
151 }
Mike Iselyd8554972006-06-26 20:58:46 -0300152 memset(&freq,0,sizeof(freq));
Mike Isely18103c52007-01-20 00:09:47 -0300153 if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
Mike Iselyf1382122006-12-27 23:23:22 -0300154 // ((fv * 1000) / 62500)
155 freq.frequency = (fv * 2) / 125;
Mike Iselyf1382122006-12-27 23:23:22 -0300156 } else {
157 freq.frequency = fv / 62500;
Mike Isely18103c52007-01-20 00:09:47 -0300158 }
159 /* tuner-core currently doesn't seem to care about this, but
160 let's set it anyway for completeness. */
161 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
162 freq.type = V4L2_TUNER_RADIO;
163 } else {
Mike Iselyf1382122006-12-27 23:23:22 -0300164 freq.type = V4L2_TUNER_ANALOG_TV;
165 }
Mike Iselyd8554972006-06-26 20:58:46 -0300166 freq.tuner = 0;
Mike Iselyd8554972006-06-26 20:58:46 -0300167 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
168}
169
170
171static int check_frequency(struct pvr2_hdw *hdw)
172{
173 return hdw->freqDirty != 0;
174}
175
176
177const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
178 .check = check_frequency,
179 .update = set_frequency,
180 .name = "v4l2_freq",
181};
182
183
184static void set_size(struct pvr2_hdw *hdw)
185{
186 struct v4l2_format fmt;
187
188 memset(&fmt,0,sizeof(fmt));
189
190 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
191 fmt.fmt.pix.width = hdw->res_hor_val;
192 fmt.fmt.pix.height = hdw->res_ver_val;
193
194 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
195 fmt.fmt.pix.width,fmt.fmt.pix.height);
196
197 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
198}
199
200
201static int check_size(struct pvr2_hdw *hdw)
202{
203 return (hdw->res_hor_dirty || hdw->res_ver_dirty);
204}
205
206
207const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
208 .check = check_size,
209 .update = set_size,
210 .name = "v4l2_size",
211};
212
213
214static void do_log(struct pvr2_hdw *hdw)
215{
216 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300217 pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
Mike Iselyd8554972006-06-26 20:58:46 -0300218
219}
220
221
222static int check_log(struct pvr2_hdw *hdw)
223{
224 return hdw->log_requested != 0;
225}
226
227
228const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
229 .check = check_log,
230 .update = do_log,
231 .name = "v4l2_log",
232};
233
234
235void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
236{
237 pvr2_i2c_client_cmd(cp,
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300238 (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
Mike Iselyd8554972006-06-26 20:58:46 -0300239}
240
241
Mike Isely18103c52007-01-20 00:09:47 -0300242void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp)
243{
244 pvr2_i2c_client_cmd(cp,VIDIOC_G_TUNER,&cp->hdw->tuner_signal_info);
245}
246
247
Mike Iselyd8554972006-06-26 20:58:46 -0300248/*
249 Stuff for Emacs to see, in order to encourage consistent editing style:
250 *** Local Variables: ***
251 *** mode: c ***
252 *** fill-column: 70 ***
253 *** tab-width: 8 ***
254 *** c-basic-offset: 8 ***
255 *** End: ***
256 */