Diff markup
1 /* 1 /*
2 * Driver for the Conexant CX23885 PCIe bridg 2 * Driver for the Conexant CX23885 PCIe bridge
3 * 3 *
4 * Copyright (c) 2007 Steven Toth <stoth@haup !! 4 * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
5 * 5 *
6 * This program is free software; you can red 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Publ 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either versi 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 * 10 *
11 * This program is distributed in the hope th 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULA 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * 14 *
15 * GNU General Public License for more detail 15 * GNU General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU 17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22 #include <linux/init.h> 22 #include <linux/init.h>
23 #include <linux/list.h> 23 #include <linux/list.h>
24 #include <linux/module.h> 24 #include <linux/module.h>
25 #include <linux/moduleparam.h> 25 #include <linux/moduleparam.h>
26 #include <linux/kmod.h> 26 #include <linux/kmod.h>
27 #include <linux/kernel.h> 27 #include <linux/kernel.h>
28 #include <linux/slab.h> 28 #include <linux/slab.h>
>> 29 #include <linux/smp_lock.h>
29 #include <linux/interrupt.h> 30 #include <linux/interrupt.h>
30 #include <linux/delay.h> 31 #include <linux/delay.h>
31 #include <linux/kthread.h> 32 #include <linux/kthread.h>
32 #include <asm/div64.h> 33 #include <asm/div64.h>
33 34
34 #include "cx23885.h" 35 #include "cx23885.h"
35 #include <media/v4l2-common.h> 36 #include <media/v4l2-common.h>
36 !! 37 #include <media/v4l2-ioctl.h>
37 #ifdef CONFIG_VIDEO_V4L1_COMPAT <<
38 /* Include V4L1 specific functions. Should be <<
39 #include <linux/videodev.h> <<
40 #endif <<
41 38
42 MODULE_DESCRIPTION("v4l2 driver module for cx2 39 MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
43 MODULE_AUTHOR("Steven Toth <stoth@hauppauge.co !! 40 MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
44 MODULE_LICENSE("GPL"); 41 MODULE_LICENSE("GPL");
45 42
46 /* ------------------------------------------- 43 /* ------------------------------------------------------------------ */
47 44
48 static unsigned int video_nr[] = {[0 ... (CX23 45 static unsigned int video_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
49 static unsigned int vbi_nr[] = {[0 ... (CX23 46 static unsigned int vbi_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
50 static unsigned int radio_nr[] = {[0 ... (CX23 47 static unsigned int radio_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
51 48
52 module_param_array(video_nr, int, NULL, 0444); 49 module_param_array(video_nr, int, NULL, 0444);
53 module_param_array(vbi_nr, int, NULL, 0444); 50 module_param_array(vbi_nr, int, NULL, 0444);
54 module_param_array(radio_nr, int, NULL, 0444); 51 module_param_array(radio_nr, int, NULL, 0444);
55 52
56 MODULE_PARM_DESC(video_nr, "video device numbe 53 MODULE_PARM_DESC(video_nr, "video device numbers");
57 MODULE_PARM_DESC(vbi_nr, "vbi device numbers") 54 MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
58 MODULE_PARM_DESC(radio_nr, "radio device numbe 55 MODULE_PARM_DESC(radio_nr, "radio device numbers");
59 56
60 static unsigned int video_debug; 57 static unsigned int video_debug;
61 module_param(video_debug, int, 0644); 58 module_param(video_debug, int, 0644);
62 MODULE_PARM_DESC(video_debug, "enable debug me 59 MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
63 60
64 static unsigned int irq_debug; 61 static unsigned int irq_debug;
65 module_param(irq_debug, int, 0644); 62 module_param(irq_debug, int, 0644);
66 MODULE_PARM_DESC(irq_debug, "enable debug mess 63 MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]");
67 64
68 static unsigned int vid_limit = 16; 65 static unsigned int vid_limit = 16;
69 module_param(vid_limit, int, 0644); 66 module_param(vid_limit, int, 0644);
70 MODULE_PARM_DESC(vid_limit, "capture memory li 67 MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
71 68
72 #define dprintk(level, fmt, arg...)\ 69 #define dprintk(level, fmt, arg...)\
73 do { if (video_debug >= level)\ 70 do { if (video_debug >= level)\
74 printk(KERN_DEBUG "%s/0: " fmt 71 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
75 } while (0) 72 } while (0)
76 73
77 /* ------------------------------------------- 74 /* ------------------------------------------------------------------- */
78 /* static data 75 /* static data */
79 76
80 #define FORMAT_FLAGS_PACKED 0x01 77 #define FORMAT_FLAGS_PACKED 0x01
81 78
82 static struct cx23885_fmt formats[] = { 79 static struct cx23885_fmt formats[] = {
83 { 80 {
84 .name = "8 bpp, gray", 81 .name = "8 bpp, gray",
85 .fourcc = V4L2_PIX_FMT_GREY, 82 .fourcc = V4L2_PIX_FMT_GREY,
86 .depth = 8, 83 .depth = 8,
87 .flags = FORMAT_FLAGS_PACKE 84 .flags = FORMAT_FLAGS_PACKED,
88 }, { 85 }, {
89 .name = "15 bpp RGB, le", 86 .name = "15 bpp RGB, le",
90 .fourcc = V4L2_PIX_FMT_RGB55 87 .fourcc = V4L2_PIX_FMT_RGB555,
91 .depth = 16, 88 .depth = 16,
92 .flags = FORMAT_FLAGS_PACKE 89 .flags = FORMAT_FLAGS_PACKED,
93 }, { 90 }, {
94 .name = "15 bpp RGB, be", 91 .name = "15 bpp RGB, be",
95 .fourcc = V4L2_PIX_FMT_RGB55 92 .fourcc = V4L2_PIX_FMT_RGB555X,
96 .depth = 16, 93 .depth = 16,
97 .flags = FORMAT_FLAGS_PACKE 94 .flags = FORMAT_FLAGS_PACKED,
98 }, { 95 }, {
99 .name = "16 bpp RGB, le", 96 .name = "16 bpp RGB, le",
100 .fourcc = V4L2_PIX_FMT_RGB56 97 .fourcc = V4L2_PIX_FMT_RGB565,
101 .depth = 16, 98 .depth = 16,
102 .flags = FORMAT_FLAGS_PACKE 99 .flags = FORMAT_FLAGS_PACKED,
103 }, { 100 }, {
104 .name = "16 bpp RGB, be", 101 .name = "16 bpp RGB, be",
105 .fourcc = V4L2_PIX_FMT_RGB56 102 .fourcc = V4L2_PIX_FMT_RGB565X,
106 .depth = 16, 103 .depth = 16,
107 .flags = FORMAT_FLAGS_PACKE 104 .flags = FORMAT_FLAGS_PACKED,
108 }, { 105 }, {
109 .name = "24 bpp RGB, le", 106 .name = "24 bpp RGB, le",
110 .fourcc = V4L2_PIX_FMT_BGR24 107 .fourcc = V4L2_PIX_FMT_BGR24,
111 .depth = 24, 108 .depth = 24,
112 .flags = FORMAT_FLAGS_PACKE 109 .flags = FORMAT_FLAGS_PACKED,
113 }, { 110 }, {
114 .name = "32 bpp RGB, le", 111 .name = "32 bpp RGB, le",
115 .fourcc = V4L2_PIX_FMT_BGR32 112 .fourcc = V4L2_PIX_FMT_BGR32,
116 .depth = 32, 113 .depth = 32,
117 .flags = FORMAT_FLAGS_PACKE 114 .flags = FORMAT_FLAGS_PACKED,
118 }, { 115 }, {
119 .name = "32 bpp RGB, be", 116 .name = "32 bpp RGB, be",
120 .fourcc = V4L2_PIX_FMT_RGB32 117 .fourcc = V4L2_PIX_FMT_RGB32,
121 .depth = 32, 118 .depth = 32,
122 .flags = FORMAT_FLAGS_PACKE 119 .flags = FORMAT_FLAGS_PACKED,
123 }, { 120 }, {
124 .name = "4:2:2, packed, YU 121 .name = "4:2:2, packed, YUYV",
125 .fourcc = V4L2_PIX_FMT_YUYV, 122 .fourcc = V4L2_PIX_FMT_YUYV,
126 .depth = 16, 123 .depth = 16,
127 .flags = FORMAT_FLAGS_PACKE 124 .flags = FORMAT_FLAGS_PACKED,
128 }, { 125 }, {
129 .name = "4:2:2, packed, UY 126 .name = "4:2:2, packed, UYVY",
130 .fourcc = V4L2_PIX_FMT_UYVY, 127 .fourcc = V4L2_PIX_FMT_UYVY,
131 .depth = 16, 128 .depth = 16,
132 .flags = FORMAT_FLAGS_PACKE 129 .flags = FORMAT_FLAGS_PACKED,
133 }, 130 },
134 }; 131 };
135 132
136 static struct cx23885_fmt *format_by_fourcc(un 133 static struct cx23885_fmt *format_by_fourcc(unsigned int fourcc)
137 { 134 {
138 unsigned int i; 135 unsigned int i;
139 136
140 for (i = 0; i < ARRAY_SIZE(formats); i 137 for (i = 0; i < ARRAY_SIZE(formats); i++)
141 if (formats[i].fourcc == fourc 138 if (formats[i].fourcc == fourcc)
142 return formats+i; 139 return formats+i;
143 140
144 printk(KERN_ERR "%s(0x%08x) NOT FOUND\ !! 141 printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __func__, fourcc);
145 return NULL; 142 return NULL;
146 } 143 }
147 144
148 /* ------------------------------------------- 145 /* ------------------------------------------------------------------- */
149 146
150 static const struct v4l2_queryctrl no_ctl = { 147 static const struct v4l2_queryctrl no_ctl = {
151 .name = "42", 148 .name = "42",
152 .flags = V4L2_CTRL_FLAG_DISABLED, 149 .flags = V4L2_CTRL_FLAG_DISABLED,
153 }; 150 };
154 151
155 static struct cx23885_ctrl cx23885_ctls[] = { 152 static struct cx23885_ctrl cx23885_ctls[] = {
156 /* --- video --- */ 153 /* --- video --- */
157 { 154 {
158 .v = { 155 .v = {
159 .id = V4L2_ 156 .id = V4L2_CID_BRIGHTNESS,
160 .name = "Brig 157 .name = "Brightness",
161 .minimum = 0x00, 158 .minimum = 0x00,
162 .maximum = 0xff, 159 .maximum = 0xff,
163 .step = 1, 160 .step = 1,
164 .default_value = 0x7f, 161 .default_value = 0x7f,
165 .type = V4L2_ 162 .type = V4L2_CTRL_TYPE_INTEGER,
166 }, 163 },
167 .off = 128, 164 .off = 128,
168 .reg = LUMA_ 165 .reg = LUMA_CTRL,
169 .mask = 0x00f 166 .mask = 0x00ff,
170 .shift = 0, 167 .shift = 0,
171 }, { 168 }, {
172 .v = { 169 .v = {
173 .id = V4L2_ 170 .id = V4L2_CID_CONTRAST,
174 .name = "Cont 171 .name = "Contrast",
175 .minimum = 0, 172 .minimum = 0,
176 .maximum = 0xff, 173 .maximum = 0xff,
177 .step = 1, 174 .step = 1,
178 .default_value = 0x3f, 175 .default_value = 0x3f,
179 .type = V4L2_ 176 .type = V4L2_CTRL_TYPE_INTEGER,
180 }, 177 },
181 .off = 0, 178 .off = 0,
182 .reg = LUMA_ 179 .reg = LUMA_CTRL,
183 .mask = 0xff0 180 .mask = 0xff00,
184 .shift = 8, 181 .shift = 8,
185 }, { 182 }, {
186 .v = { 183 .v = {
187 .id = V4L2_ 184 .id = V4L2_CID_HUE,
188 .name = "Hue" 185 .name = "Hue",
189 .minimum = 0, 186 .minimum = 0,
190 .maximum = 0xff, 187 .maximum = 0xff,
191 .step = 1, 188 .step = 1,
192 .default_value = 0x7f, 189 .default_value = 0x7f,
193 .type = V4L2_ 190 .type = V4L2_CTRL_TYPE_INTEGER,
194 }, 191 },
195 .off = 128, 192 .off = 128,
196 .reg = CHROM 193 .reg = CHROMA_CTRL,
197 .mask = 0xff0 194 .mask = 0xff0000,
198 .shift = 16, 195 .shift = 16,
199 }, { 196 }, {
200 /* strictly, this only describ 197 /* strictly, this only describes only U saturation.
201 * V saturation is handled spe 198 * V saturation is handled specially through code.
202 */ 199 */
203 .v = { 200 .v = {
204 .id = V4L2_ 201 .id = V4L2_CID_SATURATION,
205 .name = "Satu 202 .name = "Saturation",
206 .minimum = 0, 203 .minimum = 0,
207 .maximum = 0xff, 204 .maximum = 0xff,
208 .step = 1, 205 .step = 1,
209 .default_value = 0x7f, 206 .default_value = 0x7f,
210 .type = V4L2_ 207 .type = V4L2_CTRL_TYPE_INTEGER,
211 }, 208 },
212 .off = 0, 209 .off = 0,
213 .reg = CHROM 210 .reg = CHROMA_CTRL,
214 .mask = 0x00f 211 .mask = 0x00ff,
215 .shift = 0, 212 .shift = 0,
216 }, { 213 }, {
217 /* --- audio --- */ 214 /* --- audio --- */
218 .v = { 215 .v = {
219 .id = V4L2_ 216 .id = V4L2_CID_AUDIO_MUTE,
220 .name = "Mute 217 .name = "Mute",
221 .minimum = 0, 218 .minimum = 0,
222 .maximum = 1, 219 .maximum = 1,
223 .default_value = 1, 220 .default_value = 1,
224 .type = V4L2_ 221 .type = V4L2_CTRL_TYPE_BOOLEAN,
225 }, 222 },
226 .reg = PATH1 223 .reg = PATH1_CTL1,
227 .mask = (0x1f 224 .mask = (0x1f << 24),
228 .shift = 24, 225 .shift = 24,
229 }, { 226 }, {
230 .v = { 227 .v = {
231 .id = V4L2_ 228 .id = V4L2_CID_AUDIO_VOLUME,
232 .name = "Volu 229 .name = "Volume",
233 .minimum = 0, 230 .minimum = 0,
234 .maximum = 0x3f, 231 .maximum = 0x3f,
235 .step = 1, 232 .step = 1,
236 .default_value = 0x3f, 233 .default_value = 0x3f,
237 .type = V4L2_ 234 .type = V4L2_CTRL_TYPE_INTEGER,
238 }, 235 },
239 .reg = PATH1 236 .reg = PATH1_VOL_CTL,
240 .mask = 0xff, 237 .mask = 0xff,
241 .shift = 0, 238 .shift = 0,
242 } 239 }
243 }; 240 };
244 static const int CX23885_CTLS = ARRAY_SIZE(cx2 241 static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls);
245 242
246 const u32 cx23885_user_ctrls[] = { !! 243 /* Must be sorted from low to high control ID! */
>> 244 static const u32 cx23885_user_ctrls[] = {
247 V4L2_CID_USER_CLASS, 245 V4L2_CID_USER_CLASS,
248 V4L2_CID_BRIGHTNESS, 246 V4L2_CID_BRIGHTNESS,
249 V4L2_CID_CONTRAST, 247 V4L2_CID_CONTRAST,
250 V4L2_CID_SATURATION, 248 V4L2_CID_SATURATION,
251 V4L2_CID_HUE, 249 V4L2_CID_HUE,
252 V4L2_CID_AUDIO_VOLUME, 250 V4L2_CID_AUDIO_VOLUME,
253 V4L2_CID_AUDIO_MUTE, 251 V4L2_CID_AUDIO_MUTE,
254 0 252 0
255 }; 253 };
256 EXPORT_SYMBOL(cx23885_user_ctrls); <<
257 254
258 static const u32 *ctrl_classes[] = { 255 static const u32 *ctrl_classes[] = {
259 cx23885_user_ctrls, 256 cx23885_user_ctrls,
260 NULL 257 NULL
261 }; 258 };
262 259
263 void cx23885_video_wakeup(struct cx23885_dev * !! 260 static void cx23885_video_wakeup(struct cx23885_dev *dev,
264 struct cx23885_dmaqueue *q, u 261 struct cx23885_dmaqueue *q, u32 count)
265 { 262 {
266 struct cx23885_buffer *buf; 263 struct cx23885_buffer *buf;
267 int bc; 264 int bc;
268 265
269 for (bc = 0;; bc++) { 266 for (bc = 0;; bc++) {
270 if (list_empty(&q->active)) 267 if (list_empty(&q->active))
271 break; 268 break;
272 buf = list_entry(q->active.nex 269 buf = list_entry(q->active.next,
273 struct cx2388 270 struct cx23885_buffer, vb.queue);
274 271
275 /* count comes from the hw and 272 /* count comes from the hw and is is 16bit wide --
276 * this trick handles wrap-aro 273 * this trick handles wrap-arounds correctly for
277 * up to 32767 buffers in flig 274 * up to 32767 buffers in flight... */
278 if ((s16) (count - buf->count) 275 if ((s16) (count - buf->count) < 0)
279 break; 276 break;
280 277
281 do_gettimeofday(&buf->vb.ts); 278 do_gettimeofday(&buf->vb.ts);
282 dprintk(2, "[%p/%d] wakeup reg 279 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i,
283 count, buf->count); 280 count, buf->count);
284 buf->vb.state = VIDEOBUF_DONE; 281 buf->vb.state = VIDEOBUF_DONE;
285 list_del(&buf->vb.queue); 282 list_del(&buf->vb.queue);
286 wake_up(&buf->vb.done); 283 wake_up(&buf->vb.done);
287 } 284 }
288 if (list_empty(&q->active)) { !! 285 if (list_empty(&q->active))
289 del_timer(&q->timeout); 286 del_timer(&q->timeout);
290 } else { !! 287 else
291 mod_timer(&q->timeout, jiffies 288 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
292 } <<
293 if (bc != 1) 289 if (bc != 1)
294 printk(KERN_ERR "%s: %d buffer 290 printk(KERN_ERR "%s: %d buffers handled (should be 1)\n",
295 __FUNCTION__, bc); !! 291 __func__, bc);
296 } 292 }
297 293
298 int cx23885_set_tvnorm(struct cx23885_dev *dev !! 294 static int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
299 { 295 {
300 dprintk(1, "%s(norm = 0x%08x) name: [% 296 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
301 __FUNCTION__, !! 297 __func__,
302 (unsigned int)norm, 298 (unsigned int)norm,
303 v4l2_norm_to_name(norm)); 299 v4l2_norm_to_name(norm));
304 300
305 dev->tvnorm = norm; 301 dev->tvnorm = norm;
306 302
307 /* Tell the analog tuner/demods */ !! 303 call_all(dev, core, s_std, norm);
308 cx23885_call_i2c_clients(&dev->i2c_bus <<
309 <<
310 /* Tell the internal A/V decoder */ <<
311 cx23885_call_i2c_clients(&dev->i2c_bus <<
312 304
313 return 0; 305 return 0;
314 } 306 }
315 307
316 struct video_device *cx23885_vdev_init(struct !! 308 static struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
317 struct pci 309 struct pci_dev *pci,
318 struct vid 310 struct video_device *template,
319 char *type 311 char *type)
320 { 312 {
321 struct video_device *vfd; 313 struct video_device *vfd;
322 dprintk(1, "%s()\n", __FUNCTION__); !! 314 dprintk(1, "%s()\n", __func__);
323 315
324 vfd = video_device_alloc(); 316 vfd = video_device_alloc();
325 if (NULL == vfd) 317 if (NULL == vfd)
326 return NULL; 318 return NULL;
327 *vfd = *template; 319 *vfd = *template;
328 vfd->minor = -1; !! 320 vfd->minor = -1;
329 vfd->dev = &pci->dev; !! 321 vfd->v4l2_dev = &dev->v4l2_dev;
330 vfd->release = video_device_release; 322 vfd->release = video_device_release;
331 snprintf(vfd->name, sizeof(vfd->name), 323 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
332 dev->name, type, cx23885_boar 324 dev->name, type, cx23885_boards[dev->board].name);
333 return vfd; 325 return vfd;
334 } 326 }
335 327
336 int cx23885_ctrl_query(struct v4l2_queryctrl * !! 328 static int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl)
337 { 329 {
338 int i; 330 int i;
339 331
340 if (qctrl->id < V4L2_CID_BASE || 332 if (qctrl->id < V4L2_CID_BASE ||
341 qctrl->id >= V4L2_CID_LASTP1) 333 qctrl->id >= V4L2_CID_LASTP1)
342 return -EINVAL; 334 return -EINVAL;
343 for (i = 0; i < CX23885_CTLS; i++) 335 for (i = 0; i < CX23885_CTLS; i++)
344 if (cx23885_ctls[i].v.id == qc 336 if (cx23885_ctls[i].v.id == qctrl->id)
345 break; 337 break;
346 if (i == CX23885_CTLS) { 338 if (i == CX23885_CTLS) {
347 *qctrl = no_ctl; 339 *qctrl = no_ctl;
348 return 0; 340 return 0;
349 } 341 }
350 *qctrl = cx23885_ctls[i].v; 342 *qctrl = cx23885_ctls[i].v;
351 return 0; 343 return 0;
352 } 344 }
353 EXPORT_SYMBOL(cx23885_ctrl_query); <<
354 345
355 /* ------------------------------------------- 346 /* ------------------------------------------------------------------- */
356 /* resource management 347 /* resource management */
357 348
358 static int res_get(struct cx23885_dev *dev, st 349 static int res_get(struct cx23885_dev *dev, struct cx23885_fh *fh,
359 unsigned int bit) 350 unsigned int bit)
360 { 351 {
361 dprintk(1, "%s()\n", __FUNCTION__); !! 352 dprintk(1, "%s()\n", __func__);
362 if (fh->resources & bit) 353 if (fh->resources & bit)
363 /* have it already allocated * 354 /* have it already allocated */
364 return 1; 355 return 1;
365 356
366 /* is it free? */ 357 /* is it free? */
367 mutex_lock(&dev->lock); 358 mutex_lock(&dev->lock);
368 if (dev->resources & bit) { 359 if (dev->resources & bit) {
369 /* no, someone else uses it */ 360 /* no, someone else uses it */
370 mutex_unlock(&dev->lock); 361 mutex_unlock(&dev->lock);
371 return 0; 362 return 0;
372 } 363 }
373 /* it's free, grab it */ 364 /* it's free, grab it */
374 fh->resources |= bit; 365 fh->resources |= bit;
375 dev->resources |= bit; 366 dev->resources |= bit;
376 dprintk(1, "res: get %d\n", bit); 367 dprintk(1, "res: get %d\n", bit);
377 mutex_unlock(&dev->lock); 368 mutex_unlock(&dev->lock);
378 return 1; 369 return 1;
379 } 370 }
380 371
381 static int res_check(struct cx23885_fh *fh, un 372 static int res_check(struct cx23885_fh *fh, unsigned int bit)
382 { 373 {
383 return (fh->resources & bit); !! 374 return fh->resources & bit;
384 } 375 }
385 376
386 static int res_locked(struct cx23885_dev *dev, 377 static int res_locked(struct cx23885_dev *dev, unsigned int bit)
387 { 378 {
388 return (dev->resources & bit); !! 379 return dev->resources & bit;
389 } 380 }
390 381
391 static void res_free(struct cx23885_dev *dev, 382 static void res_free(struct cx23885_dev *dev, struct cx23885_fh *fh,
392 unsigned int bits) 383 unsigned int bits)
393 { 384 {
394 BUG_ON((fh->resources & bits) != bits) 385 BUG_ON((fh->resources & bits) != bits);
395 dprintk(1, "%s()\n", __FUNCTION__); !! 386 dprintk(1, "%s()\n", __func__);
396 387
397 mutex_lock(&dev->lock); 388 mutex_lock(&dev->lock);
398 fh->resources &= ~bits; 389 fh->resources &= ~bits;
399 dev->resources &= ~bits; 390 dev->resources &= ~bits;
400 dprintk(1, "res: put %d\n", bits); 391 dprintk(1, "res: put %d\n", bits);
401 mutex_unlock(&dev->lock); 392 mutex_unlock(&dev->lock);
402 } 393 }
403 394
404 int cx23885_video_mux(struct cx23885_dev *dev, !! 395 static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
405 { 396 {
406 struct v4l2_routing route; <<
407 memset(&route, 0, sizeof(route)); <<
408 <<
409 dprintk(1, "%s() video_mux: %d [vmux=% 397 dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
410 __FUNCTION__, !! 398 __func__,
411 input, INPUT(input)->vmux, 399 input, INPUT(input)->vmux,
412 INPUT(input)->gpio0, INPUT(inp 400 INPUT(input)->gpio0, INPUT(input)->gpio1,
413 INPUT(input)->gpio2, INPUT(inp 401 INPUT(input)->gpio2, INPUT(input)->gpio3);
414 dev->input = input; 402 dev->input = input;
415 403
416 route.input = INPUT(input)->vmux; <<
417 <<
418 /* Tell the internal A/V decoder */ 404 /* Tell the internal A/V decoder */
419 cx23885_call_i2c_clients(&dev->i2c_bus !! 405 v4l2_subdev_call(dev->sd_cx25840, video, s_routing,
420 VIDIOC_INT_S_VIDEO_ROUTING, &r !! 406 INPUT(input)->vmux, 0, 0);
421 407
422 return 0; 408 return 0;
423 } 409 }
424 EXPORT_SYMBOL(cx23885_video_mux); <<
425 410
426 /* ------------------------------------------- 411 /* ------------------------------------------------------------------ */
427 int cx23885_set_scale(struct cx23885_dev *dev, !! 412 static int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width,
428 unsigned int height, enum v4l2_field f 413 unsigned int height, enum v4l2_field field)
429 { 414 {
430 dprintk(1, "%s()\n", __FUNCTION__); !! 415 dprintk(1, "%s()\n", __func__);
431 return 0; 416 return 0;
432 } 417 }
433 418
434 static int cx23885_start_video_dma(struct cx23 419 static int cx23885_start_video_dma(struct cx23885_dev *dev,
435 struct cx23885_dmaq 420 struct cx23885_dmaqueue *q,
436 struct cx23885_buff 421 struct cx23885_buffer *buf)
437 { 422 {
438 dprintk(1, "%s()\n", __FUNCTION__); !! 423 dprintk(1, "%s()\n", __func__);
439 424
440 /* setup fifo + format */ 425 /* setup fifo + format */
441 cx23885_sram_channel_setup(dev, &dev-> 426 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH01],
442 buf->bpl, buf- 427 buf->bpl, buf->risc.dma);
443 cx23885_set_scale(dev, buf->vb.width, 428 cx23885_set_scale(dev, buf->vb.width, buf->vb.height, buf->vb.field);
444 429
445 /* reset counter */ 430 /* reset counter */
446 cx_write(VID_A_GPCNT_CTL, 3); 431 cx_write(VID_A_GPCNT_CTL, 3);
447 q->count = 1; 432 q->count = 1;
448 433
449 /* enable irq */ 434 /* enable irq */
450 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MS 435 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | 0x01);
451 cx_set(VID_A_INT_MSK, 0x000011); 436 cx_set(VID_A_INT_MSK, 0x000011);
452 437
453 /* start dma */ 438 /* start dma */
454 cx_set(DEV_CNTRL2, (1<<5)); 439 cx_set(DEV_CNTRL2, (1<<5));
455 cx_set(VID_A_DMA_CTL, 0x11); /* FIFO a 440 cx_set(VID_A_DMA_CTL, 0x11); /* FIFO and RISC enable */
456 441
457 return 0; 442 return 0;
458 } 443 }
459 444
460 445
461 static int cx23885_restart_video_queue(struct 446 static int cx23885_restart_video_queue(struct cx23885_dev *dev,
462 struct cx23885_ 447 struct cx23885_dmaqueue *q)
463 { 448 {
464 struct cx23885_buffer *buf, *prev; 449 struct cx23885_buffer *buf, *prev;
465 struct list_head *item; 450 struct list_head *item;
466 dprintk(1, "%s()\n", __FUNCTION__); !! 451 dprintk(1, "%s()\n", __func__);
467 452
468 if (!list_empty(&q->active)) { 453 if (!list_empty(&q->active)) {
469 buf = list_entry(q->active.nex 454 buf = list_entry(q->active.next, struct cx23885_buffer,
470 vb.queue); 455 vb.queue);
471 dprintk(2, "restart_queue [%p/ 456 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
472 buf, buf->vb.i); 457 buf, buf->vb.i);
473 cx23885_start_video_dma(dev, q 458 cx23885_start_video_dma(dev, q, buf);
474 list_for_each(item, &q->active 459 list_for_each(item, &q->active) {
475 buf = list_entry(item, 460 buf = list_entry(item, struct cx23885_buffer,
476 vb.queue); 461 vb.queue);
477 buf->count = q->cou 462 buf->count = q->count++;
478 } 463 }
479 mod_timer(&q->timeout, jiffies 464 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
480 return 0; 465 return 0;
481 } 466 }
482 467
483 prev = NULL; 468 prev = NULL;
484 for (;;) { 469 for (;;) {
485 if (list_empty(&q->queued)) 470 if (list_empty(&q->queued))
486 return 0; 471 return 0;
487 buf = list_entry(q->queued.nex 472 buf = list_entry(q->queued.next, struct cx23885_buffer,
488 vb.queue); 473 vb.queue);
489 if (NULL == prev) { 474 if (NULL == prev) {
490 list_move_tail(&buf->v 475 list_move_tail(&buf->vb.queue, &q->active);
491 cx23885_start_video_dm 476 cx23885_start_video_dma(dev, q, buf);
492 buf->vb.state = VIDEOB 477 buf->vb.state = VIDEOBUF_ACTIVE;
493 buf->count = q->cou 478 buf->count = q->count++;
494 mod_timer(&q->timeout, 479 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
495 dprintk(2, "[%p/%d] re 480 dprintk(2, "[%p/%d] restart_queue - first active\n",
496 buf, buf->vb.i 481 buf, buf->vb.i);
497 482
498 } else if (prev->vb.width == 483 } else if (prev->vb.width == buf->vb.width &&
499 prev->vb.height == 484 prev->vb.height == buf->vb.height &&
500 prev->fmt == 485 prev->fmt == buf->fmt) {
501 list_move_tail(&buf->v 486 list_move_tail(&buf->vb.queue, &q->active);
502 buf->vb.state = VIDEOB 487 buf->vb.state = VIDEOBUF_ACTIVE;
503 buf->count = q->cou 488 buf->count = q->count++;
504 prev->risc.jmp[1] = cp 489 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
505 prev->risc.jmp[2] = cp 490 prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */
506 dprintk(2, "[%p/%d] re 491 dprintk(2, "[%p/%d] restart_queue - move to active\n",
507 buf, buf->vb.i 492 buf, buf->vb.i);
508 } else { 493 } else {
509 return 0; 494 return 0;
510 } 495 }
511 prev = buf; 496 prev = buf;
512 } 497 }
513 } 498 }
514 499
515 static int buffer_setup(struct videobuf_queue 500 static int buffer_setup(struct videobuf_queue *q, unsigned int *count,
516 unsigned int *size) 501 unsigned int *size)
517 { 502 {
518 struct cx23885_fh *fh = q->priv_data; 503 struct cx23885_fh *fh = q->priv_data;
519 504
520 *size = fh->fmt->depth*fh->width*fh->h 505 *size = fh->fmt->depth*fh->width*fh->height >> 3;
521 if (0 == *count) 506 if (0 == *count)
522 *count = 32; 507 *count = 32;
523 while (*size * *count > vid_limit * 10 508 while (*size * *count > vid_limit * 1024 * 1024)
524 (*count)--; 509 (*count)--;
525 return 0; 510 return 0;
526 } 511 }
527 512
528 static int buffer_prepare(struct videobuf_queu 513 static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
529 enum v4l2_field field) 514 enum v4l2_field field)
530 { 515 {
531 struct cx23885_fh *fh = q->priv_data; 516 struct cx23885_fh *fh = q->priv_data;
532 struct cx23885_dev *dev = fh->dev; 517 struct cx23885_dev *dev = fh->dev;
533 struct cx23885_buffer *buf = 518 struct cx23885_buffer *buf =
534 container_of(vb, struct cx2388 519 container_of(vb, struct cx23885_buffer, vb);
535 int rc, init_buffer = 0; 520 int rc, init_buffer = 0;
536 u32 line0_offset, line1_offset; 521 u32 line0_offset, line1_offset;
537 struct videobuf_dmabuf *dma = videobuf 522 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
538 523
539 BUG_ON(NULL == fh->fmt); 524 BUG_ON(NULL == fh->fmt);
540 if (fh->width < 48 || fh->width > no 525 if (fh->width < 48 || fh->width > norm_maxw(dev->tvnorm) ||
541 fh->height < 32 || fh->height > no 526 fh->height < 32 || fh->height > norm_maxh(dev->tvnorm))
542 return -EINVAL; 527 return -EINVAL;
543 buf->vb.size = (fh->width * fh->height 528 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
544 if (0 != buf->vb.baddr && buf->vb.bs 529 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
545 return -EINVAL; 530 return -EINVAL;
546 531
547 if (buf->fmt != fh->fmt || 532 if (buf->fmt != fh->fmt ||
548 buf->vb.width != fh->width || 533 buf->vb.width != fh->width ||
549 buf->vb.height != fh->height || 534 buf->vb.height != fh->height ||
550 buf->vb.field != field) { 535 buf->vb.field != field) {
551 buf->fmt = fh->fmt; 536 buf->fmt = fh->fmt;
552 buf->vb.width = fh->width; 537 buf->vb.width = fh->width;
553 buf->vb.height = fh->height; 538 buf->vb.height = fh->height;
554 buf->vb.field = field; 539 buf->vb.field = field;
555 init_buffer = 1; 540 init_buffer = 1;
556 } 541 }
557 542
558 if (VIDEOBUF_NEEDS_INIT == buf->vb.sta 543 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
559 init_buffer = 1; 544 init_buffer = 1;
560 rc = videobuf_iolock(q, &buf-> 545 rc = videobuf_iolock(q, &buf->vb, NULL);
561 if (0 != rc) 546 if (0 != rc)
562 goto fail; 547 goto fail;
563 } 548 }
564 549
565 if (init_buffer) { 550 if (init_buffer) {
566 buf->bpl = buf->vb.width * buf 551 buf->bpl = buf->vb.width * buf->fmt->depth >> 3;
567 switch (buf->vb.field) { 552 switch (buf->vb.field) {
568 case V4L2_FIELD_TOP: 553 case V4L2_FIELD_TOP:
569 cx23885_risc_buffer(de 554 cx23885_risc_buffer(dev->pci, &buf->risc,
570 dma-> 555 dma->sglist, 0, UNSET,
571 buf-> 556 buf->bpl, 0, buf->vb.height);
572 break; 557 break;
573 case V4L2_FIELD_BOTTOM: 558 case V4L2_FIELD_BOTTOM:
574 cx23885_risc_buffer(de 559 cx23885_risc_buffer(dev->pci, &buf->risc,
575 dma-> 560 dma->sglist, UNSET, 0,
576 buf-> 561 buf->bpl, 0, buf->vb.height);
577 break; 562 break;
578 case V4L2_FIELD_INTERLACED: 563 case V4L2_FIELD_INTERLACED:
579 if (dev->tvnorm & V4L2 564 if (dev->tvnorm & V4L2_STD_NTSC) {
580 /* cx25840 tra 565 /* cx25840 transmits NTSC bottom field first */
581 dprintk(1, "%s 566 dprintk(1, "%s() Creating NTSC risc\n",
582 __FUNC !! 567 __func__);
583 line0_offset = 568 line0_offset = buf->bpl;
584 line1_offset = 569 line1_offset = 0;
585 } else { 570 } else {
586 /* All other f 571 /* All other formats are top field first */
587 dprintk(1, "%s 572 dprintk(1, "%s() Creating PAL/SECAM risc\n",
588 __FUNC !! 573 __func__);
589 line0_offset = 574 line0_offset = 0;
590 line1_offset = 575 line1_offset = buf->bpl;
591 } 576 }
592 cx23885_risc_buffer(de 577 cx23885_risc_buffer(dev->pci, &buf->risc,
593 dma->s 578 dma->sglist, line0_offset,
594 line1_ 579 line1_offset,
595 buf->b 580 buf->bpl, buf->bpl,
596 buf->v 581 buf->vb.height >> 1);
597 break; 582 break;
598 case V4L2_FIELD_SEQ_TB: 583 case V4L2_FIELD_SEQ_TB:
599 cx23885_risc_buffer(de 584 cx23885_risc_buffer(dev->pci, &buf->risc,
600 dma-> 585 dma->sglist,
601 0, bu 586 0, buf->bpl * (buf->vb.height >> 1),
602 buf-> 587 buf->bpl, 0,
603 buf-> 588 buf->vb.height >> 1);
604 break; 589 break;
605 case V4L2_FIELD_SEQ_BT: 590 case V4L2_FIELD_SEQ_BT:
606 cx23885_risc_buffer(de 591 cx23885_risc_buffer(dev->pci, &buf->risc,
607 dma-> 592 dma->sglist,
608 buf-> 593 buf->bpl * (buf->vb.height >> 1), 0,
609 buf-> 594 buf->bpl, 0,
610 buf-> 595 buf->vb.height >> 1);
611 break; 596 break;
612 default: 597 default:
613 BUG(); 598 BUG();
614 } 599 }
615 } 600 }
616 dprintk(2, "[%p/%d] buffer_prep - %dx% 601 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
617 buf, buf->vb.i, 602 buf, buf->vb.i,
618 fh->width, fh->height, fh->fmt 603 fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
619 (unsigned long)buf->risc.dma); 604 (unsigned long)buf->risc.dma);
620 605
621 buf->vb.state = VIDEOBUF_PREPARED; 606 buf->vb.state = VIDEOBUF_PREPARED;
622 return 0; 607 return 0;
623 608
624 fail: 609 fail:
625 cx23885_free_buffer(q, buf); 610 cx23885_free_buffer(q, buf);
626 return rc; 611 return rc;
627 } 612 }
628 613
629 static void buffer_queue(struct videobuf_queue 614 static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
630 { 615 {
631 struct cx23885_buffer *buf = contain 616 struct cx23885_buffer *buf = container_of(vb,
632 struct cx23885_buffer, vb); 617 struct cx23885_buffer, vb);
633 struct cx23885_buffer *prev; 618 struct cx23885_buffer *prev;
634 struct cx23885_fh *fh = vq->pr 619 struct cx23885_fh *fh = vq->priv_data;
635 struct cx23885_dev *dev = fh->de 620 struct cx23885_dev *dev = fh->dev;
636 struct cx23885_dmaqueue *q = &dev-> 621 struct cx23885_dmaqueue *q = &dev->vidq;
637 622
638 /* add jump to stopper */ 623 /* add jump to stopper */
639 buf->risc.jmp[0] = cpu_to_le32(RISC_JU 624 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
640 buf->risc.jmp[1] = cpu_to_le32(q->stop 625 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
641 buf->risc.jmp[2] = cpu_to_le32(0); /* 626 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
642 627
643 if (!list_empty(&q->queued)) { 628 if (!list_empty(&q->queued)) {
644 list_add_tail(&buf->vb.queue, 629 list_add_tail(&buf->vb.queue, &q->queued);
645 buf->vb.state = VIDEOBUF_QUEUE 630 buf->vb.state = VIDEOBUF_QUEUED;
646 dprintk(2, "[%p/%d] buffer_que 631 dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
647 buf, buf->vb.i); 632 buf, buf->vb.i);
648 633
649 } else if (list_empty(&q->active)) { 634 } else if (list_empty(&q->active)) {
650 list_add_tail(&buf->vb.queue, 635 list_add_tail(&buf->vb.queue, &q->active);
651 cx23885_start_video_dma(dev, q 636 cx23885_start_video_dma(dev, q, buf);
652 buf->vb.state = VIDEOBUF_ACTIV 637 buf->vb.state = VIDEOBUF_ACTIVE;
653 buf->count = q->count++; 638 buf->count = q->count++;
654 mod_timer(&q->timeout, jiffies 639 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
655 dprintk(2, "[%p/%d] buffer_que 640 dprintk(2, "[%p/%d] buffer_queue - first active\n",
656 buf, buf->vb.i); 641 buf, buf->vb.i);
657 642
658 } else { 643 } else {
659 prev = list_entry(q->active.pr 644 prev = list_entry(q->active.prev, struct cx23885_buffer,
660 vb.queue); 645 vb.queue);
661 if (prev->vb.width == buf->vb 646 if (prev->vb.width == buf->vb.width &&
662 prev->vb.height == buf->vb 647 prev->vb.height == buf->vb.height &&
663 prev->fmt == buf->fm 648 prev->fmt == buf->fmt) {
664 list_add_tail(&buf->vb 649 list_add_tail(&buf->vb.queue, &q->active);
665 buf->vb.state = VIDEOB 650 buf->vb.state = VIDEOBUF_ACTIVE;
666 buf->count = q->cou 651 buf->count = q->count++;
667 prev->risc.jmp[1] = cp 652 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
668 /* 64 bit bits 63-32 * 653 /* 64 bit bits 63-32 */
669 prev->risc.jmp[2] = cp 654 prev->risc.jmp[2] = cpu_to_le32(0);
670 dprintk(2, "[%p/%d] bu 655 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
671 buf, buf->vb.i 656 buf, buf->vb.i);
672 657
673 } else { 658 } else {
674 list_add_tail(&buf->vb 659 list_add_tail(&buf->vb.queue, &q->queued);
675 buf->vb.state = VIDEOB 660 buf->vb.state = VIDEOBUF_QUEUED;
676 dprintk(2, "[%p/%d] bu 661 dprintk(2, "[%p/%d] buffer_queue - first queued\n",
677 buf, buf->vb.i 662 buf, buf->vb.i);
678 } 663 }
679 } 664 }
680 } 665 }
681 666
682 static void buffer_release(struct videobuf_que 667 static void buffer_release(struct videobuf_queue *q,
683 struct videobuf_buffer *vb) 668 struct videobuf_buffer *vb)
684 { 669 {
685 struct cx23885_buffer *buf = container 670 struct cx23885_buffer *buf = container_of(vb,
686 struct cx23885_buffer, vb); 671 struct cx23885_buffer, vb);
687 672
688 cx23885_free_buffer(q, buf); 673 cx23885_free_buffer(q, buf);
689 } 674 }
690 675
691 static struct videobuf_queue_ops cx23885_video 676 static struct videobuf_queue_ops cx23885_video_qops = {
692 .buf_setup = buffer_setup, 677 .buf_setup = buffer_setup,
693 .buf_prepare = buffer_prepare, 678 .buf_prepare = buffer_prepare,
694 .buf_queue = buffer_queue, 679 .buf_queue = buffer_queue,
695 .buf_release = buffer_release, 680 .buf_release = buffer_release,
696 }; 681 };
697 682
698 static struct videobuf_queue *get_queue(struct 683 static struct videobuf_queue *get_queue(struct cx23885_fh *fh)
699 { 684 {
700 switch (fh->type) { 685 switch (fh->type) {
701 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 686 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
702 return &fh->vidq; 687 return &fh->vidq;
703 case V4L2_BUF_TYPE_VBI_CAPTURE: 688 case V4L2_BUF_TYPE_VBI_CAPTURE:
704 return &fh->vbiq; 689 return &fh->vbiq;
705 default: 690 default:
706 BUG(); 691 BUG();
707 return NULL; 692 return NULL;
708 } 693 }
709 } 694 }
710 695
711 static int get_resource(struct cx23885_fh *fh) 696 static int get_resource(struct cx23885_fh *fh)
712 { 697 {
713 switch (fh->type) { 698 switch (fh->type) {
714 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 699 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
715 return RESOURCE_VIDEO; 700 return RESOURCE_VIDEO;
716 case V4L2_BUF_TYPE_VBI_CAPTURE: 701 case V4L2_BUF_TYPE_VBI_CAPTURE:
717 return RESOURCE_VBI; 702 return RESOURCE_VBI;
718 default: 703 default:
719 BUG(); 704 BUG();
720 return 0; 705 return 0;
721 } 706 }
722 } 707 }
723 708
724 static int video_open(struct inode *inode, str !! 709 static int video_open(struct file *file)
725 { 710 {
726 int minor = iminor(inode); !! 711 int minor = video_devdata(file)->minor;
727 struct cx23885_dev *h, *dev = NULL; 712 struct cx23885_dev *h, *dev = NULL;
728 struct cx23885_fh *fh; 713 struct cx23885_fh *fh;
729 struct list_head *list; 714 struct list_head *list;
730 enum v4l2_buf_type type = 0; 715 enum v4l2_buf_type type = 0;
731 int radio = 0; 716 int radio = 0;
732 717
>> 718 lock_kernel();
733 list_for_each(list, &cx23885_devlist) 719 list_for_each(list, &cx23885_devlist) {
734 h = list_entry(list, struct cx 720 h = list_entry(list, struct cx23885_dev, devlist);
735 if (h->video_dev->minor == min !! 721 if (h->video_dev &&
>> 722 h->video_dev->minor == minor) {
736 dev = h; 723 dev = h;
737 type = V4L2_BUF_TYPE_V 724 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
738 } 725 }
739 if (h->vbi_dev && 726 if (h->vbi_dev &&
740 h->vbi_dev->minor == minor) !! 727 h->vbi_dev->minor == minor) {
741 dev = h; 728 dev = h;
742 type = V4L2_BUF_TYPE_V 729 type = V4L2_BUF_TYPE_VBI_CAPTURE;
743 } 730 }
744 if (h->radio_dev && 731 if (h->radio_dev &&
745 h->radio_dev->minor == min 732 h->radio_dev->minor == minor) {
746 radio = 1; 733 radio = 1;
747 dev = h; 734 dev = h;
748 } 735 }
749 } 736 }
750 if (NULL == dev) !! 737 if (NULL == dev) {
>> 738 unlock_kernel();
751 return -ENODEV; 739 return -ENODEV;
>> 740 }
752 741
753 dprintk(1, "open minor=%d radio=%d typ 742 dprintk(1, "open minor=%d radio=%d type=%s\n",
754 minor, radio, v4l2_type_names[ 743 minor, radio, v4l2_type_names[type]);
755 744
756 /* allocate + initialize per filehandl 745 /* allocate + initialize per filehandle data */
757 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 746 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
758 if (NULL == fh) !! 747 if (NULL == fh) {
>> 748 unlock_kernel();
759 return -ENOMEM; 749 return -ENOMEM;
>> 750 }
760 file->private_data = fh; 751 file->private_data = fh;
761 fh->dev = dev; 752 fh->dev = dev;
762 fh->radio = radio; 753 fh->radio = radio;
763 fh->type = type; 754 fh->type = type;
764 fh->width = 320; 755 fh->width = 320;
765 fh->height = 240; 756 fh->height = 240;
766 fh->fmt = format_by_fourcc(V4L2_P 757 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
767 758
768 videobuf_queue_pci_init(&fh->vidq, &cx !! 759 videobuf_queue_sg_init(&fh->vidq, &cx23885_video_qops,
769 dev->pci, &dev->sl !! 760 &dev->pci->dev, &dev->slock,
770 V4L2_BUF_TYPE_VIDE 761 V4L2_BUF_TYPE_VIDEO_CAPTURE,
771 V4L2_FIELD_INTERLA 762 V4L2_FIELD_INTERLACED,
772 sizeof(struct cx23 763 sizeof(struct cx23885_buffer),
773 fh); 764 fh);
774 765
775 dprintk(1, "post videobuf_queue_init() 766 dprintk(1, "post videobuf_queue_init()\n");
776 767
>> 768 unlock_kernel();
777 769
778 return 0; 770 return 0;
779 } 771 }
780 772
781 static ssize_t video_read(struct file *file, c 773 static ssize_t video_read(struct file *file, char __user *data,
782 size_t count, loff_t *ppos) 774 size_t count, loff_t *ppos)
783 { 775 {
784 struct cx23885_fh *fh = file->private_ 776 struct cx23885_fh *fh = file->private_data;
785 777
786 switch (fh->type) { 778 switch (fh->type) {
787 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 779 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
788 if (res_locked(fh->dev, RESOUR 780 if (res_locked(fh->dev, RESOURCE_VIDEO))
789 return -EBUSY; 781 return -EBUSY;
790 return videobuf_read_one(&fh-> 782 return videobuf_read_one(&fh->vidq, data, count, ppos,
791 file- 783 file->f_flags & O_NONBLOCK);
792 case V4L2_BUF_TYPE_VBI_CAPTURE: 784 case V4L2_BUF_TYPE_VBI_CAPTURE:
793 if (!res_get(fh->dev, fh, RESO 785 if (!res_get(fh->dev, fh, RESOURCE_VBI))
794 return -EBUSY; 786 return -EBUSY;
795 return videobuf_read_stream(&f 787 return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1,
796 fi 788 file->f_flags & O_NONBLOCK);
797 default: 789 default:
798 BUG(); 790 BUG();
799 return 0; 791 return 0;
800 } 792 }
801 } 793 }
802 794
803 static unsigned int video_poll(struct file *fi 795 static unsigned int video_poll(struct file *file,
804 struct poll_table_struct *wait) 796 struct poll_table_struct *wait)
805 { 797 {
806 struct cx23885_fh *fh = file->private_ 798 struct cx23885_fh *fh = file->private_data;
807 struct cx23885_buffer *buf; 799 struct cx23885_buffer *buf;
>> 800 unsigned int rc = POLLERR;
808 801
809 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->t 802 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
810 if (!res_get(fh->dev, fh, RESO 803 if (!res_get(fh->dev, fh, RESOURCE_VBI))
811 return POLLERR; 804 return POLLERR;
812 return videobuf_poll_stream(fi 805 return videobuf_poll_stream(file, &fh->vbiq, wait);
813 } 806 }
814 807
>> 808 mutex_lock(&fh->vidq.vb_lock);
815 if (res_check(fh, RESOURCE_VIDEO)) { 809 if (res_check(fh, RESOURCE_VIDEO)) {
816 /* streaming capture */ 810 /* streaming capture */
817 if (list_empty(&fh->vidq.strea 811 if (list_empty(&fh->vidq.stream))
818 return POLLERR; !! 812 goto done;
819 buf = list_entry(fh->vidq.stre 813 buf = list_entry(fh->vidq.stream.next,
820 struct cx23885_buffer, 814 struct cx23885_buffer, vb.stream);
821 } else { 815 } else {
822 /* read() capture */ 816 /* read() capture */
823 buf = (struct cx23885_buffer * 817 buf = (struct cx23885_buffer *)fh->vidq.read_buf;
824 if (NULL == buf) 818 if (NULL == buf)
825 return POLLERR; !! 819 goto done;
826 } 820 }
827 poll_wait(file, &buf->vb.done, wait); 821 poll_wait(file, &buf->vb.done, wait);
828 if (buf->vb.state == VIDEOBUF_DONE || 822 if (buf->vb.state == VIDEOBUF_DONE ||
829 buf->vb.state == VIDEOBUF_ERROR) 823 buf->vb.state == VIDEOBUF_ERROR)
830 return POLLIN|POLLRDNORM; !! 824 rc = POLLIN|POLLRDNORM;
831 return 0; !! 825 else
>> 826 rc = 0;
>> 827 done:
>> 828 mutex_unlock(&fh->vidq.vb_lock);
>> 829 return rc;
832 } 830 }
833 831
834 static int video_release(struct inode *inode, !! 832 static int video_release(struct file *file)
835 { 833 {
836 struct cx23885_fh *fh = file->private_ 834 struct cx23885_fh *fh = file->private_data;
837 struct cx23885_dev *dev = fh->dev; 835 struct cx23885_dev *dev = fh->dev;
838 836
839 /* turn off overlay */ 837 /* turn off overlay */
840 if (res_check(fh, RESOURCE_OVERLAY)) { 838 if (res_check(fh, RESOURCE_OVERLAY)) {
841 /* FIXME */ 839 /* FIXME */
842 res_free(dev, fh, RESOURCE_OVE 840 res_free(dev, fh, RESOURCE_OVERLAY);
843 } 841 }
844 842
845 /* stop video capture */ 843 /* stop video capture */
846 if (res_check(fh, RESOURCE_VIDEO)) { 844 if (res_check(fh, RESOURCE_VIDEO)) {
847 videobuf_queue_cancel(&fh->vid 845 videobuf_queue_cancel(&fh->vidq);
848 res_free(dev, fh, RESOURCE_VID 846 res_free(dev, fh, RESOURCE_VIDEO);
849 } 847 }
850 if (fh->vidq.read_buf) { 848 if (fh->vidq.read_buf) {
851 buffer_release(&fh->vidq, fh-> 849 buffer_release(&fh->vidq, fh->vidq.read_buf);
852 kfree(fh->vidq.read_buf); 850 kfree(fh->vidq.read_buf);
853 } 851 }
854 852
855 /* stop vbi capture */ 853 /* stop vbi capture */
856 if (res_check(fh, RESOURCE_VBI)) { 854 if (res_check(fh, RESOURCE_VBI)) {
857 if (fh->vbiq.streaming) 855 if (fh->vbiq.streaming)
858 videobuf_streamoff(&fh 856 videobuf_streamoff(&fh->vbiq);
859 if (fh->vbiq.reading) 857 if (fh->vbiq.reading)
860 videobuf_read_stop(&fh 858 videobuf_read_stop(&fh->vbiq);
861 res_free(dev, fh, RESOURCE_VBI 859 res_free(dev, fh, RESOURCE_VBI);
862 } 860 }
863 861
864 videobuf_mmap_free(&fh->vidq); 862 videobuf_mmap_free(&fh->vidq);
865 file->private_data = NULL; 863 file->private_data = NULL;
866 kfree(fh); 864 kfree(fh);
867 865
868 /* We are not putting the tuner to sle 866 /* We are not putting the tuner to sleep here on exit, because
869 * we want to use the mpeg encoder in 867 * we want to use the mpeg encoder in another session to capture
870 * tuner video. Closing this will resu 868 * tuner video. Closing this will result in no video to the encoder.
871 */ 869 */
872 870
873 return 0; 871 return 0;
874 } 872 }
875 873
876 static int video_mmap(struct file *file, struc 874 static int video_mmap(struct file *file, struct vm_area_struct *vma)
877 { 875 {
878 struct cx23885_fh *fh = file->private_ 876 struct cx23885_fh *fh = file->private_data;
879 877
880 return videobuf_mmap_mapper(get_queue( 878 return videobuf_mmap_mapper(get_queue(fh), vma);
881 } 879 }
882 880
883 /* ------------------------------------------- 881 /* ------------------------------------------------------------------ */
884 /* VIDEO CTRL IOCTLS 882 /* VIDEO CTRL IOCTLS */
885 883
886 int cx23885_get_control(struct cx23885_dev *de !! 884 static int cx23885_get_control(struct cx23885_dev *dev,
>> 885 struct v4l2_control *ctl)
887 { 886 {
888 dprintk(1, "%s() calling cx25840(VIDIO !! 887 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__);
889 cx23885_call_i2c_clients(&dev->i2c_bus !! 888 call_all(dev, core, g_ctrl, ctl);
890 return 0; 889 return 0;
891 } 890 }
892 EXPORT_SYMBOL(cx23885_get_control); <<
893 891
894 int cx23885_set_control(struct cx23885_dev *de !! 892 static int cx23885_set_control(struct cx23885_dev *dev,
>> 893 struct v4l2_control *ctl)
895 { 894 {
896 dprintk(1, "%s() calling cx25840(VIDIO 895 dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)"
897 " (disabled - no action)\n", _ !! 896 " (disabled - no action)\n", __func__);
898 return 0; 897 return 0;
899 } 898 }
900 EXPORT_SYMBOL(cx23885_set_control); <<
901 899
902 static void init_controls(struct cx23885_dev * 900 static void init_controls(struct cx23885_dev *dev)
903 { 901 {
904 struct v4l2_control ctrl; 902 struct v4l2_control ctrl;
905 int i; 903 int i;
906 904
907 for (i = 0; i < CX23885_CTLS; i++) { 905 for (i = 0; i < CX23885_CTLS; i++) {
908 ctrl.id = cx23885_ctls[i].v.id 906 ctrl.id = cx23885_ctls[i].v.id;
909 ctrl.value = cx23885_ctls[i].v 907 ctrl.value = cx23885_ctls[i].v.default_value;
910 908
911 cx23885_set_control(dev, &ctrl 909 cx23885_set_control(dev, &ctrl);
912 } 910 }
913 } 911 }
914 912
915 /* ------------------------------------------- 913 /* ------------------------------------------------------------------ */
916 /* VIDEO IOCTLS 914 /* VIDEO IOCTLS */
917 915
918 static int vidioc_g_fmt_cap(struct file *file, !! 916 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
919 struct v4l2_format *f) 917 struct v4l2_format *f)
920 { 918 {
921 struct cx23885_fh *fh = priv; 919 struct cx23885_fh *fh = priv;
922 920
923 f->fmt.pix.width = fh->width; 921 f->fmt.pix.width = fh->width;
924 f->fmt.pix.height = fh->height; 922 f->fmt.pix.height = fh->height;
925 f->fmt.pix.field = fh->vidq.fie 923 f->fmt.pix.field = fh->vidq.field;
926 f->fmt.pix.pixelformat = fh->fmt->fou 924 f->fmt.pix.pixelformat = fh->fmt->fourcc;
927 f->fmt.pix.bytesperline = 925 f->fmt.pix.bytesperline =
928 (f->fmt.pix.width * fh->fmt->d 926 (f->fmt.pix.width * fh->fmt->depth) >> 3;
929 f->fmt.pix.sizeimage = 927 f->fmt.pix.sizeimage =
930 f->fmt.pix.height * f->fmt.pix 928 f->fmt.pix.height * f->fmt.pix.bytesperline;
931 929
932 return 0; 930 return 0;
933 } 931 }
934 932
935 static int vidioc_try_fmt_cap(struct file *fil !! 933 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
936 struct v4l2_format *f) 934 struct v4l2_format *f)
937 { 935 {
938 struct cx23885_dev *dev = ((struct cx2 936 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
939 struct cx23885_fmt *fmt; 937 struct cx23885_fmt *fmt;
940 enum v4l2_field field; 938 enum v4l2_field field;
941 unsigned int maxw, maxh; 939 unsigned int maxw, maxh;
942 940
943 fmt = format_by_fourcc(f->fmt.pix.pixe 941 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
944 if (NULL == fmt) 942 if (NULL == fmt)
945 return -EINVAL; 943 return -EINVAL;
946 944
947 field = f->fmt.pix.field; 945 field = f->fmt.pix.field;
948 maxw = norm_maxw(dev->tvnorm); 946 maxw = norm_maxw(dev->tvnorm);
949 maxh = norm_maxh(dev->tvnorm); 947 maxh = norm_maxh(dev->tvnorm);
950 948
951 if (V4L2_FIELD_ANY == field) { 949 if (V4L2_FIELD_ANY == field) {
952 field = (f->fmt.pix.height > m 950 field = (f->fmt.pix.height > maxh/2)
953 ? V4L2_FIELD_INTERLACE 951 ? V4L2_FIELD_INTERLACED
954 : V4L2_FIELD_BOTTOM; 952 : V4L2_FIELD_BOTTOM;
955 } 953 }
956 954
957 switch (field) { 955 switch (field) {
958 case V4L2_FIELD_TOP: 956 case V4L2_FIELD_TOP:
959 case V4L2_FIELD_BOTTOM: 957 case V4L2_FIELD_BOTTOM:
960 maxh = maxh / 2; 958 maxh = maxh / 2;
961 break; 959 break;
962 case V4L2_FIELD_INTERLACED: 960 case V4L2_FIELD_INTERLACED:
963 break; 961 break;
964 default: 962 default:
965 return -EINVAL; 963 return -EINVAL;
966 } 964 }
967 965
968 f->fmt.pix.field = field; 966 f->fmt.pix.field = field;
969 if (f->fmt.pix.height < 32) !! 967 v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
970 f->fmt.pix.height = 32; !! 968 &f->fmt.pix.height, 32, maxh, 0, 0);
971 if (f->fmt.pix.height > maxh) <<
972 f->fmt.pix.height = maxh; <<
973 if (f->fmt.pix.width < 48) <<
974 f->fmt.pix.width = 48; <<
975 if (f->fmt.pix.width > maxw) <<
976 f->fmt.pix.width = maxw; <<
977 f->fmt.pix.width &= ~0x03; <<
978 f->fmt.pix.bytesperline = 969 f->fmt.pix.bytesperline =
979 (f->fmt.pix.width * fmt->depth 970 (f->fmt.pix.width * fmt->depth) >> 3;
980 f->fmt.pix.sizeimage = 971 f->fmt.pix.sizeimage =
981 f->fmt.pix.height * f->fmt.pix 972 f->fmt.pix.height * f->fmt.pix.bytesperline;
982 973
983 return 0; 974 return 0;
984 } 975 }
985 976
986 static int vidioc_s_fmt_cap(struct file *file, !! 977 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
987 struct v4l2_format *f) 978 struct v4l2_format *f)
988 { 979 {
989 struct cx23885_fh *fh = priv; 980 struct cx23885_fh *fh = priv;
990 struct cx23885_dev *dev = ((struct cx 981 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
991 int err; 982 int err;
992 983
993 dprintk(2, "%s()\n", __FUNCTION__); !! 984 dprintk(2, "%s()\n", __func__);
994 err = vidioc_try_fmt_cap(file, priv, f !! 985 err = vidioc_try_fmt_vid_cap(file, priv, f);
995 986
996 if (0 != err) 987 if (0 != err)
997 return err; 988 return err;
998 fh->fmt = format_by_fourcc(f->f 989 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
999 fh->width = f->fmt.pix.width; 990 fh->width = f->fmt.pix.width;
1000 fh->height = f->fmt.pix.height; 991 fh->height = f->fmt.pix.height;
1001 fh->vidq.field = f->fmt.pix.field; 992 fh->vidq.field = f->fmt.pix.field;
1002 dprintk(2, "%s() width=%d height=%d f !! 993 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__,
1003 fh->width, fh->height, fh->vi 994 fh->width, fh->height, fh->vidq.field);
1004 cx23885_call_i2c_clients(&dev->i2c_bu !! 995 call_all(dev, video, s_fmt, f);
1005 return 0; 996 return 0;
1006 } 997 }
1007 998
1008 static int vidioc_querycap(struct file *file, 999 static int vidioc_querycap(struct file *file, void *priv,
1009 struct v4l2_capability *cap) 1000 struct v4l2_capability *cap)
1010 { 1001 {
1011 struct cx23885_dev *dev = ((struct c 1002 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1012 1003
1013 strcpy(cap->driver, "cx23885"); 1004 strcpy(cap->driver, "cx23885");
1014 strlcpy(cap->card, cx23885_boards[dev 1005 strlcpy(cap->card, cx23885_boards[dev->board].name,
1015 sizeof(cap->card)); 1006 sizeof(cap->card));
1016 sprintf(cap->bus_info, "PCIe:%s", pci 1007 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
1017 cap->version = CX23885_VERSION_CODE; 1008 cap->version = CX23885_VERSION_CODE;
1018 cap->capabilities = 1009 cap->capabilities =
1019 V4L2_CAP_VIDEO_CAPTURE | 1010 V4L2_CAP_VIDEO_CAPTURE |
1020 V4L2_CAP_READWRITE | 1011 V4L2_CAP_READWRITE |
1021 V4L2_CAP_STREAMING | 1012 V4L2_CAP_STREAMING |
1022 V4L2_CAP_VBI_CAPTURE; 1013 V4L2_CAP_VBI_CAPTURE;
1023 if (UNSET != dev->tuner_type) 1014 if (UNSET != dev->tuner_type)
1024 cap->capabilities |= V4L2_CAP 1015 cap->capabilities |= V4L2_CAP_TUNER;
1025 return 0; 1016 return 0;
1026 } 1017 }
1027 1018
1028 static int vidioc_enum_fmt_cap(struct file *f !! 1019 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1029 struct v4l2_fmtdesc *f) 1020 struct v4l2_fmtdesc *f)
1030 { 1021 {
1031 if (unlikely(f->index >= ARRAY_SIZE(f 1022 if (unlikely(f->index >= ARRAY_SIZE(formats)))
1032 return -EINVAL; 1023 return -EINVAL;
1033 1024
1034 strlcpy(f->description, formats[f->in 1025 strlcpy(f->description, formats[f->index].name,
1035 sizeof(f->description)); 1026 sizeof(f->description));
1036 f->pixelformat = formats[f->index].fo 1027 f->pixelformat = formats[f->index].fourcc;
1037 1028
1038 return 0; 1029 return 0;
1039 } 1030 }
1040 1031
1041 #ifdef CONFIG_VIDEO_V4L1_COMPAT 1032 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1042 static int vidiocgmbuf(struct file *file, voi 1033 static int vidiocgmbuf(struct file *file, void *priv,
1043 struct video_mbuf *mbuf) 1034 struct video_mbuf *mbuf)
1044 { 1035 {
1045 struct cx23885_fh *fh = priv; 1036 struct cx23885_fh *fh = priv;
1046 struct videobuf_queue *q; 1037 struct videobuf_queue *q;
1047 struct v4l2_requestbuffers req; 1038 struct v4l2_requestbuffers req;
1048 unsigned int i; 1039 unsigned int i;
1049 int err; 1040 int err;
1050 1041
1051 q = get_queue(fh); 1042 q = get_queue(fh);
1052 memset(&req, 0, sizeof(req)); 1043 memset(&req, 0, sizeof(req));
1053 req.type = q->type; 1044 req.type = q->type;
1054 req.count = 8; 1045 req.count = 8;
1055 req.memory = V4L2_MEMORY_MMAP; 1046 req.memory = V4L2_MEMORY_MMAP;
1056 err = videobuf_reqbufs(q, &req); 1047 err = videobuf_reqbufs(q, &req);
1057 if (err < 0) 1048 if (err < 0)
1058 return err; 1049 return err;
1059 1050
1060 mbuf->frames = req.count; 1051 mbuf->frames = req.count;
1061 mbuf->size = 0; 1052 mbuf->size = 0;
1062 for (i = 0; i < mbuf->frames; i++) { 1053 for (i = 0; i < mbuf->frames; i++) {
1063 mbuf->offsets[i] = q->bufs[i 1054 mbuf->offsets[i] = q->bufs[i]->boff;
1064 mbuf->size += q->bufs[i 1055 mbuf->size += q->bufs[i]->bsize;
1065 } 1056 }
1066 return 0; 1057 return 0;
1067 } 1058 }
1068 #endif 1059 #endif
1069 1060
1070 static int vidioc_reqbufs(struct file *file, 1061 static int vidioc_reqbufs(struct file *file, void *priv,
1071 struct v4l2_requestbuffers *p) 1062 struct v4l2_requestbuffers *p)
1072 { 1063 {
1073 struct cx23885_fh *fh = priv; 1064 struct cx23885_fh *fh = priv;
1074 return (videobuf_reqbufs(get_queue(fh !! 1065 return videobuf_reqbufs(get_queue(fh), p);
1075 } 1066 }
1076 1067
1077 static int vidioc_querybuf(struct file *file, 1068 static int vidioc_querybuf(struct file *file, void *priv,
1078 struct v4l2_buffer *p) 1069 struct v4l2_buffer *p)
1079 { 1070 {
1080 struct cx23885_fh *fh = priv; 1071 struct cx23885_fh *fh = priv;
1081 return (videobuf_querybuf(get_queue(f !! 1072 return videobuf_querybuf(get_queue(fh), p);
1082 } 1073 }
1083 1074
1084 static int vidioc_qbuf(struct file *file, voi 1075 static int vidioc_qbuf(struct file *file, void *priv,
1085 struct v4l2_buffer *p) 1076 struct v4l2_buffer *p)
1086 { 1077 {
1087 struct cx23885_fh *fh = priv; 1078 struct cx23885_fh *fh = priv;
1088 return (videobuf_qbuf(get_queue(fh), !! 1079 return videobuf_qbuf(get_queue(fh), p);
1089 } 1080 }
1090 1081
1091 static int vidioc_dqbuf(struct file *file, vo 1082 static int vidioc_dqbuf(struct file *file, void *priv,
1092 struct v4l2_buffer *p) 1083 struct v4l2_buffer *p)
1093 { 1084 {
1094 struct cx23885_fh *fh = priv; 1085 struct cx23885_fh *fh = priv;
1095 return (videobuf_dqbuf(get_queue(fh), !! 1086 return videobuf_dqbuf(get_queue(fh), p,
1096 file->f_flags !! 1087 file->f_flags & O_NONBLOCK);
1097 } 1088 }
1098 1089
1099 static int vidioc_streamon(struct file *file, 1090 static int vidioc_streamon(struct file *file, void *priv,
1100 enum v4l2_buf_type i) 1091 enum v4l2_buf_type i)
1101 { 1092 {
1102 struct cx23885_fh *fh = priv; 1093 struct cx23885_fh *fh = priv;
1103 struct cx23885_dev *dev = fh->dev; 1094 struct cx23885_dev *dev = fh->dev;
1104 dprintk(1, "%s()\n", __FUNCTION__); !! 1095 dprintk(1, "%s()\n", __func__);
1105 1096
1106 if (unlikely(fh->type != V4L2_BUF_TYP 1097 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
1107 return -EINVAL; 1098 return -EINVAL;
1108 if (unlikely(i != fh->type)) 1099 if (unlikely(i != fh->type))
1109 return -EINVAL; 1100 return -EINVAL;
1110 1101
1111 if (unlikely(!res_get(dev, fh, get_re 1102 if (unlikely(!res_get(dev, fh, get_resource(fh))))
1112 return -EBUSY; 1103 return -EBUSY;
1113 return videobuf_streamon(get_queue(fh 1104 return videobuf_streamon(get_queue(fh));
1114 } 1105 }
1115 1106
1116 static int vidioc_streamoff(struct file *file 1107 static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1117 { 1108 {
1118 struct cx23885_fh *fh = priv; 1109 struct cx23885_fh *fh = priv;
1119 struct cx23885_dev *dev = fh->dev; 1110 struct cx23885_dev *dev = fh->dev;
1120 int err, res; 1111 int err, res;
1121 dprintk(1, "%s()\n", __FUNCTION__); !! 1112 dprintk(1, "%s()\n", __func__);
1122 1113
1123 if (fh->type != V4L2_BUF_TYPE_VIDEO_C 1114 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1124 return -EINVAL; 1115 return -EINVAL;
1125 if (i != fh->type) 1116 if (i != fh->type)
1126 return -EINVAL; 1117 return -EINVAL;
1127 1118
1128 res = get_resource(fh); 1119 res = get_resource(fh);
1129 err = videobuf_streamoff(get_queue(fh 1120 err = videobuf_streamoff(get_queue(fh));
1130 if (err < 0) 1121 if (err < 0)
1131 return err; 1122 return err;
1132 res_free(dev, fh, res); 1123 res_free(dev, fh, res);
1133 return 0; 1124 return 0;
1134 } 1125 }
1135 1126
1136 static int vidioc_s_std(struct file *file, vo 1127 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
1137 { 1128 {
1138 struct cx23885_dev *dev = ((struct cx 1129 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1139 dprintk(1, "%s()\n", __FUNCTION__); !! 1130 dprintk(1, "%s()\n", __func__);
1140 1131
1141 mutex_lock(&dev->lock); 1132 mutex_lock(&dev->lock);
1142 cx23885_set_tvnorm(dev, *tvnorms); 1133 cx23885_set_tvnorm(dev, *tvnorms);
1143 mutex_unlock(&dev->lock); 1134 mutex_unlock(&dev->lock);
1144 1135
1145 return 0; 1136 return 0;
1146 } 1137 }
1147 1138
1148 int cx23885_enum_input(struct cx23885_dev *de !! 1139 static int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
1149 { 1140 {
1150 static const char *iname[] = { 1141 static const char *iname[] = {
1151 [CX23885_VMUX_COMPOSITE1] = " 1142 [CX23885_VMUX_COMPOSITE1] = "Composite1",
1152 [CX23885_VMUX_COMPOSITE2] = " 1143 [CX23885_VMUX_COMPOSITE2] = "Composite2",
1153 [CX23885_VMUX_COMPOSITE3] = " 1144 [CX23885_VMUX_COMPOSITE3] = "Composite3",
1154 [CX23885_VMUX_COMPOSITE4] = " 1145 [CX23885_VMUX_COMPOSITE4] = "Composite4",
1155 [CX23885_VMUX_SVIDEO] = " 1146 [CX23885_VMUX_SVIDEO] = "S-Video",
1156 [CX23885_VMUX_TELEVISION] = " 1147 [CX23885_VMUX_TELEVISION] = "Television",
1157 [CX23885_VMUX_CABLE] = " 1148 [CX23885_VMUX_CABLE] = "Cable TV",
1158 [CX23885_VMUX_DVB] = " 1149 [CX23885_VMUX_DVB] = "DVB",
1159 [CX23885_VMUX_DEBUG] = " 1150 [CX23885_VMUX_DEBUG] = "for debug only",
1160 }; 1151 };
1161 unsigned int n; 1152 unsigned int n;
1162 dprintk(1, "%s()\n", __FUNCTION__); !! 1153 dprintk(1, "%s()\n", __func__);
1163 1154
1164 n = i->index; 1155 n = i->index;
1165 if (n >= 4) 1156 if (n >= 4)
1166 return -EINVAL; 1157 return -EINVAL;
1167 1158
1168 if (0 == INPUT(n)->type) 1159 if (0 == INPUT(n)->type)
1169 return -EINVAL; 1160 return -EINVAL;
1170 1161
1171 memset(i, 0, sizeof(*i)); 1162 memset(i, 0, sizeof(*i));
1172 i->index = n; 1163 i->index = n;
1173 i->type = V4L2_INPUT_TYPE_CAMERA; 1164 i->type = V4L2_INPUT_TYPE_CAMERA;
1174 strcpy(i->name, iname[INPUT(n)->type] 1165 strcpy(i->name, iname[INPUT(n)->type]);
1175 if ((CX23885_VMUX_TELEVISION == INPUT 1166 if ((CX23885_VMUX_TELEVISION == INPUT(n)->type) ||
1176 (CX23885_VMUX_CABLE == INPUT( 1167 (CX23885_VMUX_CABLE == INPUT(n)->type))
1177 i->type = V4L2_INPUT_TYPE_TUN 1168 i->type = V4L2_INPUT_TYPE_TUNER;
1178 i->std = CX23885_NORMS; 1169 i->std = CX23885_NORMS;
1179 return 0; 1170 return 0;
1180 } 1171 }
1181 EXPORT_SYMBOL(cx23885_enum_input); <<
1182 1172
1183 static int vidioc_enum_input(struct file *fil 1173 static int vidioc_enum_input(struct file *file, void *priv,
1184 struct v4l2_i 1174 struct v4l2_input *i)
1185 { 1175 {
1186 struct cx23885_dev *dev = ((struct cx 1176 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1187 dprintk(1, "%s()\n", __FUNCTION__); !! 1177 dprintk(1, "%s()\n", __func__);
1188 return cx23885_enum_input(dev, i); 1178 return cx23885_enum_input(dev, i);
1189 } 1179 }
1190 1180
1191 static int vidioc_g_input(struct file *file, 1181 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1192 { 1182 {
1193 struct cx23885_dev *dev = ((struct cx 1183 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1194 1184
1195 *i = dev->input; 1185 *i = dev->input;
1196 dprintk(1, "%s() returns %d\n", __FUN !! 1186 dprintk(1, "%s() returns %d\n", __func__, *i);
1197 return 0; 1187 return 0;
1198 } 1188 }
1199 1189
1200 static int vidioc_s_input(struct file *file, 1190 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1201 { 1191 {
1202 struct cx23885_dev *dev = ((struct cx 1192 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1203 1193
1204 dprintk(1, "%s(%d)\n", __FUNCTION__, !! 1194 dprintk(1, "%s(%d)\n", __func__, i);
1205 1195
1206 if (i >= 4) { 1196 if (i >= 4) {
1207 dprintk(1, "%s() -EINVAL\n", !! 1197 dprintk(1, "%s() -EINVAL\n", __func__);
1208 return -EINVAL; 1198 return -EINVAL;
1209 } 1199 }
1210 1200
1211 mutex_lock(&dev->lock); 1201 mutex_lock(&dev->lock);
1212 cx23885_video_mux(dev, i); 1202 cx23885_video_mux(dev, i);
1213 mutex_unlock(&dev->lock); 1203 mutex_unlock(&dev->lock);
1214 return 0; 1204 return 0;
1215 } 1205 }
1216 1206
1217 static int vidioc_queryctrl(struct file *file 1207 static int vidioc_queryctrl(struct file *file, void *priv,
1218 struct v4l2_q 1208 struct v4l2_queryctrl *qctrl)
1219 { 1209 {
1220 qctrl->id = v4l2_ctrl_next(ctrl_class 1210 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1221 if (unlikely(qctrl->id == 0)) 1211 if (unlikely(qctrl->id == 0))
1222 return -EINVAL; 1212 return -EINVAL;
1223 return cx23885_ctrl_query(qctrl); 1213 return cx23885_ctrl_query(qctrl);
1224 } 1214 }
1225 1215
1226 static int vidioc_g_ctrl(struct file *file, v 1216 static int vidioc_g_ctrl(struct file *file, void *priv,
1227 struct v4l2_c 1217 struct v4l2_control *ctl)
1228 { 1218 {
1229 struct cx23885_dev *dev = ((struct cx 1219 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1230 1220
1231 return cx23885_get_control(dev, ctl); 1221 return cx23885_get_control(dev, ctl);
1232 } 1222 }
1233 1223
1234 static int vidioc_s_ctrl(struct file *file, v 1224 static int vidioc_s_ctrl(struct file *file, void *priv,
1235 struct v4l2_c 1225 struct v4l2_control *ctl)
1236 { 1226 {
1237 struct cx23885_dev *dev = ((struct cx 1227 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1238 1228
1239 return cx23885_set_control(dev, ctl); 1229 return cx23885_set_control(dev, ctl);
1240 } 1230 }
1241 1231
1242 static int vidioc_g_tuner(struct file *file, 1232 static int vidioc_g_tuner(struct file *file, void *priv,
1243 struct v4l2_t 1233 struct v4l2_tuner *t)
1244 { 1234 {
1245 struct cx23885_dev *dev = ((struct cx 1235 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1246 1236
1247 if (unlikely(UNSET == dev->tuner_type 1237 if (unlikely(UNSET == dev->tuner_type))
1248 return -EINVAL; 1238 return -EINVAL;
1249 if (0 != t->index) 1239 if (0 != t->index)
1250 return -EINVAL; 1240 return -EINVAL;
1251 1241
1252 strcpy(t->name, "Television"); 1242 strcpy(t->name, "Television");
1253 t->type = V4L2_TUNER_ANALOG_TV; 1243 t->type = V4L2_TUNER_ANALOG_TV;
1254 t->capability = V4L2_TUNER_CAP_NORM; 1244 t->capability = V4L2_TUNER_CAP_NORM;
1255 t->rangehigh = 0xffffffffUL; 1245 t->rangehigh = 0xffffffffUL;
1256 t->signal = 0xffff ; /* LOCKED */ 1246 t->signal = 0xffff ; /* LOCKED */
1257 return 0; 1247 return 0;
1258 } 1248 }
1259 1249
1260 static int vidioc_s_tuner(struct file *file, 1250 static int vidioc_s_tuner(struct file *file, void *priv,
1261 struct v4l2_t 1251 struct v4l2_tuner *t)
1262 { 1252 {
1263 struct cx23885_dev *dev = ((struct cx 1253 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1264 1254
1265 if (UNSET == dev->tuner_type) 1255 if (UNSET == dev->tuner_type)
1266 return -EINVAL; 1256 return -EINVAL;
1267 if (0 != t->index) 1257 if (0 != t->index)
1268 return -EINVAL; 1258 return -EINVAL;
1269 return 0; 1259 return 0;
1270 } 1260 }
1271 1261
1272 static int vidioc_g_frequency(struct file *fi 1262 static int vidioc_g_frequency(struct file *file, void *priv,
1273 struct v4l2_f 1263 struct v4l2_frequency *f)
1274 { 1264 {
1275 struct cx23885_fh *fh = priv; 1265 struct cx23885_fh *fh = priv;
1276 struct cx23885_dev *dev = fh->dev; 1266 struct cx23885_dev *dev = fh->dev;
1277 1267
1278 if (unlikely(UNSET == dev->tuner_type 1268 if (unlikely(UNSET == dev->tuner_type))
1279 return -EINVAL; 1269 return -EINVAL;
1280 1270
1281 /* f->type = fh->radio ? V4L2_TUNER_R 1271 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1282 f->type = fh->radio ? V4L2_TUNER_RADI 1272 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1283 f->frequency = dev->freq; 1273 f->frequency = dev->freq;
1284 1274
1285 cx23885_call_i2c_clients(&dev->i2c_bu !! 1275 call_all(dev, tuner, g_frequency, f);
1286 1276
1287 return 0; 1277 return 0;
1288 } 1278 }
1289 1279
1290 int cx23885_set_freq(struct cx23885_dev *dev, !! 1280 static int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
1291 { 1281 {
1292 if (unlikely(UNSET == dev->tuner_type 1282 if (unlikely(UNSET == dev->tuner_type))
1293 return -EINVAL; 1283 return -EINVAL;
1294 if (unlikely(f->tuner != 0)) 1284 if (unlikely(f->tuner != 0))
1295 return -EINVAL; 1285 return -EINVAL;
1296 1286
1297 mutex_lock(&dev->lock); 1287 mutex_lock(&dev->lock);
1298 dev->freq = f->frequency; 1288 dev->freq = f->frequency;
1299 1289
1300 cx23885_call_i2c_clients(&dev->i2c_bu !! 1290 call_all(dev, tuner, s_frequency, f);
1301 1291
1302 /* When changing channels it is requi 1292 /* When changing channels it is required to reset TVAUDIO */
1303 msleep(10); 1293 msleep(10);
1304 1294
1305 mutex_unlock(&dev->lock); 1295 mutex_unlock(&dev->lock);
1306 1296
1307 return 0; 1297 return 0;
1308 } 1298 }
1309 EXPORT_SYMBOL(cx23885_set_freq); <<
1310 1299
1311 static int vidioc_s_frequency(struct file *fi 1300 static int vidioc_s_frequency(struct file *file, void *priv,
1312 struct v4l2_f 1301 struct v4l2_frequency *f)
1313 { 1302 {
1314 struct cx23885_fh *fh = priv; 1303 struct cx23885_fh *fh = priv;
1315 struct cx23885_dev *dev = fh->dev; 1304 struct cx23885_dev *dev = fh->dev;
1316 1305
1317 if (unlikely(0 == fh->radio && f->typ 1306 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1318 return -EINVAL; 1307 return -EINVAL;
1319 if (unlikely(1 == fh->radio && f->typ 1308 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1320 return -EINVAL; 1309 return -EINVAL;
1321 1310
1322 return 1311 return
1323 cx23885_set_freq(dev, f); 1312 cx23885_set_freq(dev, f);
1324 } 1313 }
1325 1314
1326 #ifdef CONFIG_VIDEO_ADV_DEBUG 1315 #ifdef CONFIG_VIDEO_ADV_DEBUG
1327 static int vidioc_g_register(struct file *fil 1316 static int vidioc_g_register(struct file *file, void *fh,
1328 struct v4l2_r !! 1317 struct v4l2_dbg_register *reg)
1329 { 1318 {
1330 struct cx23885_dev *dev = ((struct cx 1319 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
1331 1320
1332 if (!v4l2_chip_match_host(reg->match_ !! 1321 if (!v4l2_chip_match_host(®->match))
1333 return -EINVAL; 1322 return -EINVAL;
1334 1323
1335 cx23885_call_i2c_clients(&dev->i2c_bu !! 1324 call_all(dev, core, g_register, reg);
1336 1325
1337 return 0; 1326 return 0;
1338 } 1327 }
1339 1328
1340 static int vidioc_s_register(struct file *fil 1329 static int vidioc_s_register(struct file *file, void *fh,
1341 struct v4l2_r !! 1330 struct v4l2_dbg_register *reg)
1342 { 1331 {
1343 struct cx23885_dev *dev = ((struct cx 1332 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
1344 1333
1345 if (!v4l2_chip_match_host(reg->match_ !! 1334 if (!v4l2_chip_match_host(®->match))
1346 return -EINVAL; 1335 return -EINVAL;
1347 1336
1348 cx23885_call_i2c_clients(&dev->i2c_bu !! 1337 call_all(dev, core, s_register, reg);
1349 1338
1350 return 0; 1339 return 0;
1351 } 1340 }
1352 #endif 1341 #endif
1353 1342
1354 /* ------------------------------------------ 1343 /* ----------------------------------------------------------- */
1355 1344
1356 static void cx23885_vid_timeout(unsigned long 1345 static void cx23885_vid_timeout(unsigned long data)
1357 { 1346 {
1358 struct cx23885_dev *dev = (struct cx2 1347 struct cx23885_dev *dev = (struct cx23885_dev *)data;
1359 struct cx23885_dmaqueue *q = &dev->vi 1348 struct cx23885_dmaqueue *q = &dev->vidq;
1360 struct cx23885_buffer *buf; 1349 struct cx23885_buffer *buf;
1361 unsigned long flags; 1350 unsigned long flags;
1362 1351
1363 cx23885_sram_channel_dump(dev, &dev-> 1352 cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]);
1364 1353
1365 cx_clear(VID_A_DMA_CTL, 0x11); 1354 cx_clear(VID_A_DMA_CTL, 0x11);
1366 1355
1367 spin_lock_irqsave(&dev->slock, flags) 1356 spin_lock_irqsave(&dev->slock, flags);
1368 while (!list_empty(&q->active)) { 1357 while (!list_empty(&q->active)) {
1369 buf = list_entry(q->active.ne 1358 buf = list_entry(q->active.next,
1370 struct cx23885_buffer 1359 struct cx23885_buffer, vb.queue);
1371 list_del(&buf->vb.queue); 1360 list_del(&buf->vb.queue);
1372 buf->vb.state = VIDEOBUF_ERRO 1361 buf->vb.state = VIDEOBUF_ERROR;
1373 wake_up(&buf->vb.done); 1362 wake_up(&buf->vb.done);
1374 printk(KERN_ERR "%s/0: [%p/%d 1363 printk(KERN_ERR "%s/0: [%p/%d] timeout - dma=0x%08lx\n",
1375 dev->name, buf, buf-> 1364 dev->name, buf, buf->vb.i,
1376 (unsigned long)buf->r 1365 (unsigned long)buf->risc.dma);
1377 } 1366 }
1378 cx23885_restart_video_queue(dev, q); 1367 cx23885_restart_video_queue(dev, q);
1379 spin_unlock_irqrestore(&dev->slock, f 1368 spin_unlock_irqrestore(&dev->slock, flags);
1380 } 1369 }
1381 1370
1382 int cx23885_video_irq(struct cx23885_dev *dev 1371 int cx23885_video_irq(struct cx23885_dev *dev, u32 status)
1383 { 1372 {
1384 u32 mask, count; 1373 u32 mask, count;
1385 int handled = 0; 1374 int handled = 0;
1386 1375
1387 mask = cx_read(VID_A_INT_MSK); 1376 mask = cx_read(VID_A_INT_MSK);
1388 if (0 == (status & mask)) 1377 if (0 == (status & mask))
1389 return handled; 1378 return handled;
1390 cx_write(VID_A_INT_STAT, status); 1379 cx_write(VID_A_INT_STAT, status);
1391 1380
1392 dprintk(2, "%s() status = 0x%08x\n", !! 1381 dprintk(2, "%s() status = 0x%08x\n", __func__, status);
1393 /* risc op code error */ 1382 /* risc op code error */
1394 if (status & (1 << 16)) { 1383 if (status & (1 << 16)) {
1395 printk(KERN_WARNING "%s/0: vi 1384 printk(KERN_WARNING "%s/0: video risc op code error\n",
1396 dev->name); 1385 dev->name);
1397 cx_clear(VID_A_DMA_CTL, 0x11) 1386 cx_clear(VID_A_DMA_CTL, 0x11);
1398 cx23885_sram_channel_dump(dev 1387 cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]);
1399 } 1388 }
1400 1389
1401 /* risc1 y */ 1390 /* risc1 y */
1402 if (status & 0x01) { 1391 if (status & 0x01) {
1403 spin_lock(&dev->slock); 1392 spin_lock(&dev->slock);
1404 count = cx_read(VID_A_GPCNT); 1393 count = cx_read(VID_A_GPCNT);
1405 cx23885_video_wakeup(dev, &de 1394 cx23885_video_wakeup(dev, &dev->vidq, count);
1406 spin_unlock(&dev->slock); 1395 spin_unlock(&dev->slock);
1407 handled++; 1396 handled++;
1408 } 1397 }
1409 /* risc2 y */ 1398 /* risc2 y */
1410 if (status & 0x10) { 1399 if (status & 0x10) {
1411 dprintk(2, "stopper video\n") 1400 dprintk(2, "stopper video\n");
1412 spin_lock(&dev->slock); 1401 spin_lock(&dev->slock);
1413 cx23885_restart_video_queue(d 1402 cx23885_restart_video_queue(dev, &dev->vidq);
1414 spin_unlock(&dev->slock); 1403 spin_unlock(&dev->slock);
1415 handled++; 1404 handled++;
1416 } 1405 }
1417 1406
1418 return handled; 1407 return handled;
1419 } 1408 }
1420 1409
1421 /* ------------------------------------------ 1410 /* ----------------------------------------------------------- */
1422 /* exported stuff 1411 /* exported stuff */
1423 1412
1424 static const struct file_operations video_fop !! 1413 static const struct v4l2_file_operations video_fops = {
1425 .owner = THIS_MODULE, 1414 .owner = THIS_MODULE,
1426 .open = video_open, 1415 .open = video_open,
1427 .release = video_release, 1416 .release = video_release,
1428 .read = video_read, 1417 .read = video_read,
1429 .poll = video_poll, 1418 .poll = video_poll,
1430 .mmap = video_mmap, 1419 .mmap = video_mmap,
1431 .ioctl = video_ioctl2, 1420 .ioctl = video_ioctl2,
1432 .compat_ioctl = v4l_compat_ioctl32, <<
1433 .llseek = no_llseek, <<
1434 }; 1421 };
1435 1422
1436 static struct video_device cx23885_vbi_templa !! 1423 static const struct v4l2_ioctl_ops video_ioctl_ops = {
1437 static struct video_device cx23885_video_temp <<
1438 .name = "cx23885-vide <<
1439 .type = VID_TYPE_CAPT <<
1440 .fops = &video_fops, <<
1441 .minor = -1, <<
1442 .vidioc_querycap = vidioc_queryc 1424 .vidioc_querycap = vidioc_querycap,
1443 .vidioc_enum_fmt_cap = vidioc_enum_f !! 1425 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1444 .vidioc_g_fmt_cap = vidioc_g_fmt_ !! 1426 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1445 .vidioc_try_fmt_cap = vidioc_try_fm !! 1427 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1446 .vidioc_s_fmt_cap = vidioc_s_fmt_ !! 1428 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1447 .vidioc_g_fmt_vbi = cx23885_vbi_f !! 1429 .vidioc_g_fmt_vbi_cap = cx23885_vbi_fmt,
1448 .vidioc_try_fmt_vbi = cx23885_vbi_f !! 1430 .vidioc_try_fmt_vbi_cap = cx23885_vbi_fmt,
1449 .vidioc_s_fmt_vbi = cx23885_vbi_f !! 1431 .vidioc_s_fmt_vbi_cap = cx23885_vbi_fmt,
1450 .vidioc_reqbufs = vidioc_reqbuf 1432 .vidioc_reqbufs = vidioc_reqbufs,
1451 .vidioc_querybuf = vidioc_queryb 1433 .vidioc_querybuf = vidioc_querybuf,
1452 .vidioc_qbuf = vidioc_qbuf, 1434 .vidioc_qbuf = vidioc_qbuf,
1453 .vidioc_dqbuf = vidioc_dqbuf, 1435 .vidioc_dqbuf = vidioc_dqbuf,
1454 .vidioc_s_std = vidioc_s_std, 1436 .vidioc_s_std = vidioc_s_std,
1455 .vidioc_enum_input = vidioc_enum_i 1437 .vidioc_enum_input = vidioc_enum_input,
1456 .vidioc_g_input = vidioc_g_inpu 1438 .vidioc_g_input = vidioc_g_input,
1457 .vidioc_s_input = vidioc_s_inpu 1439 .vidioc_s_input = vidioc_s_input,
1458 .vidioc_queryctrl = vidioc_queryc 1440 .vidioc_queryctrl = vidioc_queryctrl,
1459 .vidioc_g_ctrl = vidioc_g_ctrl 1441 .vidioc_g_ctrl = vidioc_g_ctrl,
1460 .vidioc_s_ctrl = vidioc_s_ctrl 1442 .vidioc_s_ctrl = vidioc_s_ctrl,
1461 .vidioc_streamon = vidioc_stream 1443 .vidioc_streamon = vidioc_streamon,
1462 .vidioc_streamoff = vidioc_stream 1444 .vidioc_streamoff = vidioc_streamoff,
1463 #ifdef CONFIG_VIDEO_V4L1_COMPAT 1445 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1464 .vidiocgmbuf = vidiocgmbuf, 1446 .vidiocgmbuf = vidiocgmbuf,
1465 #endif 1447 #endif
1466 .vidioc_g_tuner = vidioc_g_tune 1448 .vidioc_g_tuner = vidioc_g_tuner,
1467 .vidioc_s_tuner = vidioc_s_tune 1449 .vidioc_s_tuner = vidioc_s_tuner,
1468 .vidioc_g_frequency = vidioc_g_freq 1450 .vidioc_g_frequency = vidioc_g_frequency,
1469 .vidioc_s_frequency = vidioc_s_freq 1451 .vidioc_s_frequency = vidioc_s_frequency,
1470 #ifdef CONFIG_VIDEO_ADV_DEBUG 1452 #ifdef CONFIG_VIDEO_ADV_DEBUG
1471 .vidioc_g_register = vidioc_g_regi 1453 .vidioc_g_register = vidioc_g_register,
1472 .vidioc_s_register = vidioc_s_regi 1454 .vidioc_s_register = vidioc_s_register,
1473 #endif 1455 #endif
>> 1456 };
>> 1457
>> 1458 static struct video_device cx23885_vbi_template;
>> 1459 static struct video_device cx23885_video_template = {
>> 1460 .name = "cx23885-video",
>> 1461 .fops = &video_fops,
>> 1462 .minor = -1,
>> 1463 .ioctl_ops = &video_ioctl_ops,
1474 .tvnorms = CX23885_NORMS 1464 .tvnorms = CX23885_NORMS,
1475 .current_norm = V4L2_STD_NTSC 1465 .current_norm = V4L2_STD_NTSC_M,
1476 }; 1466 };
1477 1467
1478 static const struct file_operations radio_fop !! 1468 static const struct v4l2_file_operations radio_fops = {
1479 .owner = THIS_MODULE, 1469 .owner = THIS_MODULE,
1480 .open = video_open, 1470 .open = video_open,
1481 .release = video_release, 1471 .release = video_release,
1482 .ioctl = video_ioctl2, 1472 .ioctl = video_ioctl2,
1483 .compat_ioctl = v4l_compat_ioctl32, <<
1484 .llseek = no_llseek, <<
1485 }; 1473 };
1486 1474
1487 1475
1488 void cx23885_video_unregister(struct cx23885_ 1476 void cx23885_video_unregister(struct cx23885_dev *dev)
1489 { 1477 {
1490 dprintk(1, "%s()\n", __FUNCTION__); !! 1478 dprintk(1, "%s()\n", __func__);
1491 cx_clear(PCI_INT_MSK, 1); 1479 cx_clear(PCI_INT_MSK, 1);
1492 1480
1493 if (dev->video_dev) { 1481 if (dev->video_dev) {
1494 if (-1 != dev->video_dev->min 1482 if (-1 != dev->video_dev->minor)
1495 video_unregister_devi 1483 video_unregister_device(dev->video_dev);
1496 else 1484 else
1497 video_device_release( 1485 video_device_release(dev->video_dev);
1498 dev->video_dev = NULL; 1486 dev->video_dev = NULL;
1499 1487
1500 btcx_riscmem_free(dev->pci, & 1488 btcx_riscmem_free(dev->pci, &dev->vidq.stopper);
1501 } 1489 }
1502 } 1490 }
1503 1491
1504 int cx23885_video_register(struct cx23885_dev 1492 int cx23885_video_register(struct cx23885_dev *dev)
1505 { 1493 {
1506 int err; 1494 int err;
1507 1495
1508 dprintk(1, "%s()\n", __FUNCTION__); !! 1496 dprintk(1, "%s()\n", __func__);
1509 spin_lock_init(&dev->slock); 1497 spin_lock_init(&dev->slock);
1510 1498
1511 /* Initialize VBI template */ 1499 /* Initialize VBI template */
1512 memcpy(&cx23885_vbi_template, &cx2388 1500 memcpy(&cx23885_vbi_template, &cx23885_video_template,
1513 sizeof(cx23885_vbi_template)) 1501 sizeof(cx23885_vbi_template));
1514 strcpy(cx23885_vbi_template.name, "cx 1502 strcpy(cx23885_vbi_template.name, "cx23885-vbi");
1515 cx23885_vbi_template.type = VID_TYPE_ <<
1516 1503
1517 dev->tvnorm = cx23885_video_template. 1504 dev->tvnorm = cx23885_video_template.current_norm;
1518 1505
1519 /* init video dma queues */ 1506 /* init video dma queues */
1520 INIT_LIST_HEAD(&dev->vidq.active); 1507 INIT_LIST_HEAD(&dev->vidq.active);
1521 INIT_LIST_HEAD(&dev->vidq.queued); 1508 INIT_LIST_HEAD(&dev->vidq.queued);
1522 dev->vidq.timeout.function = cx23885_ 1509 dev->vidq.timeout.function = cx23885_vid_timeout;
1523 dev->vidq.timeout.data = (unsigned lo 1510 dev->vidq.timeout.data = (unsigned long)dev;
1524 init_timer(&dev->vidq.timeout); 1511 init_timer(&dev->vidq.timeout);
1525 cx23885_risc_stopper(dev->pci, &dev-> 1512 cx23885_risc_stopper(dev->pci, &dev->vidq.stopper,
1526 VID_A_DMA_CTL, 0x11, 0x00); 1513 VID_A_DMA_CTL, 0x11, 0x00);
1527 1514
1528 /* Don't enable VBI yet */ 1515 /* Don't enable VBI yet */
1529 cx_set(PCI_INT_MSK, 1); 1516 cx_set(PCI_INT_MSK, 1);
1530 1517
>> 1518 if (TUNER_ABSENT != dev->tuner_type) {
>> 1519 struct v4l2_subdev *sd = NULL;
>> 1520
>> 1521 if (dev->tuner_addr)
>> 1522 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
>> 1523 &dev->i2c_bus[1].i2c_adap,
>> 1524 "tuner", "tuner", dev->tuner_addr);
>> 1525 else
>> 1526 sd = v4l2_i2c_new_probed_subdev(&dev->v4l2_dev,
>> 1527 &dev->i2c_bus[1].i2c_adap,
>> 1528 "tuner", "tuner", v4l2_i2c_tuner_addrs(ADDRS_TV));
>> 1529 if (sd) {
>> 1530 struct tuner_setup tun_setup;
>> 1531
>> 1532 tun_setup.mode_mask = T_ANALOG_TV;
>> 1533 tun_setup.type = dev->tuner_type;
>> 1534 tun_setup.addr = v4l2_i2c_subdev_addr(sd);
>> 1535
>> 1536 v4l2_subdev_call(sd, tuner, s_type_addr, &tun_setup);
>> 1537 }
>> 1538 }
>> 1539
1531 1540
1532 /* register v4l devices */ 1541 /* register v4l devices */
1533 dev->video_dev = cx23885_vdev_init(de 1542 dev->video_dev = cx23885_vdev_init(dev, dev->pci,
1534 &cx23885_video_template, "vid 1543 &cx23885_video_template, "video");
1535 err = video_register_device(dev->vide 1544 err = video_register_device(dev->video_dev, VFL_TYPE_GRABBER,
1536 video_nr[ 1545 video_nr[dev->nr]);
1537 if (err < 0) { 1546 if (err < 0) {
1538 printk(KERN_INFO "%s: can't r 1547 printk(KERN_INFO "%s: can't register video device\n",
1539 dev->name); 1548 dev->name);
1540 goto fail_unreg; 1549 goto fail_unreg;
1541 } 1550 }
1542 printk(KERN_INFO "%s/0: registered de 1551 printk(KERN_INFO "%s/0: registered device video%d [v4l2]\n",
1543 dev->name, dev->video_dev->min !! 1552 dev->name, dev->video_dev->num);
1544 /* initial device configuration */ 1553 /* initial device configuration */
1545 mutex_lock(&dev->lock); 1554 mutex_lock(&dev->lock);
1546 cx23885_set_tvnorm(dev, dev->tvnorm); 1555 cx23885_set_tvnorm(dev, dev->tvnorm);
1547 init_controls(dev); 1556 init_controls(dev);
1548 cx23885_video_mux(dev, 0); 1557 cx23885_video_mux(dev, 0);
1549 mutex_unlock(&dev->lock); 1558 mutex_unlock(&dev->lock);
1550 1559
1551 return 0; 1560 return 0;
1552 1561
1553 fail_unreg: 1562 fail_unreg:
1554 cx23885_video_unregister(dev); 1563 cx23885_video_unregister(dev);
1555 return err; 1564 return err;
1556 } 1565 }
1557 1566
1558 1567
|
This page was automatically generated by the
LXR engine.
|