Commit | Line | Data |
---|---|---|
9701dc94 | 1 | /* |
e28f49b0 | 2 | tm6000-video.c - driver for TM5600/TM6000/TM6010 USB video capture devices |
9701dc94 MCC |
3 | |
4 | Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org> | |
5 | ||
7c3f53ec ML |
6 | Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.com> |
7 | - Fixed module load/unload | |
8 | ||
9701dc94 MCC |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation version 2 | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | */ | |
22 | #include <linux/module.h> | |
23 | #include <linux/delay.h> | |
24 | #include <linux/errno.h> | |
25 | #include <linux/fs.h> | |
26 | #include <linux/kernel.h> | |
27 | #include <linux/slab.h> | |
28 | #include <linux/mm.h> | |
29 | #include <linux/ioport.h> | |
30 | #include <linux/init.h> | |
31 | #include <linux/sched.h> | |
32 | #include <linux/random.h> | |
33 | #include <linux/version.h> | |
34 | #include <linux/usb.h> | |
35 | #include <linux/videodev2.h> | |
2a8145d4 | 36 | #include <media/v4l2-ioctl.h> |
9701dc94 MCC |
37 | #include <linux/interrupt.h> |
38 | #include <linux/kthread.h> | |
39 | #include <linux/highmem.h> | |
40 | #include <linux/freezer.h> | |
41 | ||
42 | #include "tm6000-regs.h" | |
43 | #include "tm6000.h" | |
44 | ||
45 | #define BUFFER_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */ | |
46 | ||
95a83824 ML |
47 | /* Limits minimum and default number of buffers */ |
48 | #define TM6000_MIN_BUF 4 | |
49 | #define TM6000_DEF_BUF 8 | |
50 | ||
ee1fc07c MCC |
51 | #define TM6000_MAX_ISO_PACKETS 40 /* Max number of ISO packets */ |
52 | ||
9701dc94 MCC |
53 | /* Declare static vars that will be used as parameters */ |
54 | static unsigned int vid_limit = 16; /* Video memory limit, in Mb */ | |
55 | static int video_nr = -1; /* /dev/videoN, -1 for autodetect */ | |
56 | ||
9701dc94 MCC |
57 | /* Debug level */ |
58 | int tm6000_debug; | |
59 | ||
60 | /* supported controls */ | |
61 | static struct v4l2_queryctrl tm6000_qctrl[] = { | |
62 | { | |
63 | .id = V4L2_CID_BRIGHTNESS, | |
64 | .type = V4L2_CTRL_TYPE_INTEGER, | |
65 | .name = "Brightness", | |
66 | .minimum = 0, | |
67 | .maximum = 255, | |
68 | .step = 1, | |
69 | .default_value = 54, | |
70 | .flags = 0, | |
71 | }, { | |
72 | .id = V4L2_CID_CONTRAST, | |
73 | .type = V4L2_CTRL_TYPE_INTEGER, | |
74 | .name = "Contrast", | |
75 | .minimum = 0, | |
76 | .maximum = 255, | |
77 | .step = 0x1, | |
78 | .default_value = 119, | |
79 | .flags = 0, | |
80 | }, { | |
81 | .id = V4L2_CID_SATURATION, | |
82 | .type = V4L2_CTRL_TYPE_INTEGER, | |
83 | .name = "Saturation", | |
84 | .minimum = 0, | |
85 | .maximum = 255, | |
86 | .step = 0x1, | |
87 | .default_value = 112, | |
88 | .flags = 0, | |
89 | }, { | |
90 | .id = V4L2_CID_HUE, | |
91 | .type = V4L2_CTRL_TYPE_INTEGER, | |
92 | .name = "Hue", | |
93 | .minimum = -128, | |
94 | .maximum = 127, | |
95 | .step = 0x1, | |
c4acf48c | 96 | .default_value = 0, |
9701dc94 MCC |
97 | .flags = 0, |
98 | } | |
99 | }; | |
100 | ||
101 | static int qctl_regs[ARRAY_SIZE(tm6000_qctrl)]; | |
102 | ||
103 | static struct tm6000_fmt format[] = { | |
104 | { | |
105 | .name = "4:2:2, packed, YVY2", | |
106 | .fourcc = V4L2_PIX_FMT_YUYV, | |
107 | .depth = 16, | |
c4acf48c | 108 | }, { |
9701dc94 MCC |
109 | .name = "4:2:2, packed, UYVY", |
110 | .fourcc = V4L2_PIX_FMT_UYVY, | |
111 | .depth = 16, | |
c4acf48c | 112 | }, { |
9701dc94 MCC |
113 | .name = "A/V + VBI mux packet", |
114 | .fourcc = V4L2_PIX_FMT_TM6000, | |
115 | .depth = 16, | |
116 | } | |
117 | }; | |
118 | ||
9701dc94 MCC |
119 | /* ------------------------------------------------------------------ |
120 | DMA and thread functions | |
121 | ------------------------------------------------------------------*/ | |
122 | ||
123 | #define norm_maxw(a) 720 | |
4475c044 | 124 | #define norm_maxh(a) 576 |
9701dc94 | 125 | |
9701dc94 MCC |
126 | #define norm_minw(a) norm_maxw(a) |
127 | #define norm_minh(a) norm_maxh(a) | |
128 | ||
129 | /* | |
130 | * video-buf generic routine to get the next available buffer | |
131 | */ | |
721f507b | 132 | static inline void get_next_buf(struct tm6000_dmaqueue *dma_q, |
c4acf48c | 133 | struct tm6000_buffer **buf) |
9701dc94 | 134 | { |
c4acf48c | 135 | struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq); |
721f507b | 136 | char *outp; |
9701dc94 MCC |
137 | |
138 | if (list_empty(&dma_q->active)) { | |
c4acf48c | 139 | dprintk(dev, V4L2_DEBUG_QUEUE, "No active queue to serve\n"); |
1f9305b7 | 140 | *buf = NULL; |
721f507b | 141 | return; |
9701dc94 MCC |
142 | } |
143 | ||
144 | *buf = list_entry(dma_q->active.next, | |
145 | struct tm6000_buffer, vb.queue); | |
146 | ||
721f507b MCC |
147 | if (!buf) |
148 | return; | |
149 | ||
150 | /* Cleans up buffer - Usefull for testing for frame/URB loss */ | |
151 | outp = videobuf_to_vmalloc(&(*buf)->vb); | |
42238713 MCC |
152 | // if (outp) |
153 | // memset(outp, 0, (*buf)->vb.size); | |
721f507b MCC |
154 | |
155 | return; | |
9701dc94 MCC |
156 | } |
157 | ||
158 | /* | |
159 | * Announces that a buffer were filled and request the next | |
160 | */ | |
c4acf48c MCC |
161 | static inline void buffer_filled(struct tm6000_core *dev, |
162 | struct tm6000_dmaqueue *dma_q, | |
163 | struct tm6000_buffer *buf) | |
9701dc94 MCC |
164 | { |
165 | /* Advice that buffer was filled */ | |
c4acf48c | 166 | dprintk(dev, V4L2_DEBUG_ISOC, "[%p/%d] wakeup\n", buf, buf->vb.i); |
47878f16 | 167 | buf->vb.state = VIDEOBUF_DONE; |
9701dc94 MCC |
168 | buf->vb.field_count++; |
169 | do_gettimeofday(&buf->vb.ts); | |
170 | ||
171 | list_del(&buf->vb.queue); | |
172 | wake_up(&buf->vb.done); | |
173 | } | |
174 | ||
c4acf48c MCC |
175 | const char *tm6000_msg_type[] = { |
176 | "unknown(0)", /* 0 */ | |
177 | "video", /* 1 */ | |
178 | "audio", /* 2 */ | |
179 | "vbi", /* 3 */ | |
180 | "pts", /* 4 */ | |
181 | "err", /* 5 */ | |
182 | "unknown(6)", /* 6 */ | |
183 | "unknown(7)", /* 7 */ | |
a228618c MCC |
184 | }; |
185 | ||
9701dc94 MCC |
186 | /* |
187 | * Identify the tm5600/6000 buffer header type and properly handles | |
188 | */ | |
c4acf48c | 189 | static int copy_packet(struct urb *urb, u32 header, u8 **ptr, u8 *endp, |
e2c9500d | 190 | u8 *out_p, struct tm6000_buffer **buf) |
9701dc94 MCC |
191 | { |
192 | struct tm6000_dmaqueue *dma_q = urb->context; | |
c4acf48c | 193 | struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq); |
9701dc94 | 194 | u8 c; |
c4acf48c MCC |
195 | unsigned int cmd, cpysize, pktsize, size, field, block, line, pos = 0; |
196 | int rc = 0; | |
a228618c | 197 | /* FIXME: move to tm6000-isoc */ |
c4acf48c | 198 | static int last_line = -2, start_line = -2, last_field = -2; |
9701dc94 MCC |
199 | |
200 | /* FIXME: this is the hardcoded window size | |
201 | */ | |
c4acf48c | 202 | unsigned int linewidth = (*buf)->vb.width << 1; |
9701dc94 | 203 | |
ed0236af MCC |
204 | if (!dev->isoc_ctl.cmd) { |
205 | c = (header >> 24) & 0xff; | |
206 | ||
207 | /* split the header fields */ | |
0f9bdbc2 SR |
208 | size = ((header & 0x7e) << 1); |
209 | ||
210 | if (size > 0) | |
211 | size -= 4; | |
212 | ||
ed0236af MCC |
213 | block = (header >> 7) & 0xf; |
214 | field = (header >> 11) & 0x1; | |
215 | line = (header >> 12) & 0x1ff; | |
216 | cmd = (header >> 21) & 0x7; | |
217 | ||
218 | /* Validates header fields */ | |
219 | if(size > TM6000_URB_MSG_LEN) | |
220 | size = TM6000_URB_MSG_LEN; | |
204193d9 | 221 | |
ed0236af MCC |
222 | if (cmd == TM6000_URB_MSG_VIDEO) { |
223 | if ((block+1)*TM6000_URB_MSG_LEN>linewidth) | |
224 | cmd = TM6000_URB_MSG_ERR; | |
225 | ||
226 | /* FIXME: Mounts the image as field0+field1 | |
227 | * It should, instead, check if the user selected | |
228 | * entrelaced or non-entrelaced mode | |
229 | */ | |
3c7c5e9e SR |
230 | pos = ((line << 1) - field - 1) * linewidth + |
231 | block * TM6000_URB_MSG_LEN; | |
ed0236af MCC |
232 | |
233 | /* Don't allow to write out of the buffer */ | |
234 | if (pos+TM6000_URB_MSG_LEN > (*buf)->vb.size) { | |
235 | dprintk(dev, V4L2_DEBUG_ISOC, | |
236 | "ERR: size=%d, num=%d, line=%d, " | |
237 | "field=%d\n", | |
238 | size, block, line, field); | |
239 | ||
240 | cmd = TM6000_URB_MSG_ERR; | |
241 | } | |
204193d9 | 242 | } else { |
ed0236af | 243 | pos=0; |
6eb5c8a6 | 244 | } |
ed0236af | 245 | |
6eb5c8a6 | 246 | /* Prints debug info */ |
ed0236af MCC |
247 | dprintk(dev, V4L2_DEBUG_ISOC, "size=%d, num=%d, " |
248 | " line=%d, field=%d\n", | |
249 | size, block, line, field); | |
e2c9500d | 250 | |
ed0236af MCC |
251 | if ((last_line!=line)&&(last_line+1!=line) && |
252 | (cmd != TM6000_URB_MSG_ERR) ) { | |
253 | if (cmd != TM6000_URB_MSG_VIDEO) { | |
254 | dprintk(dev, V4L2_DEBUG_ISOC, "cmd=%d, " | |
255 | "size=%d, num=%d, line=%d, field=%d\n", | |
256 | cmd, size, block, line, field); | |
257 | } | |
258 | if (start_line<0) | |
259 | start_line=last_line; | |
260 | /* Prints debug info */ | |
261 | dprintk(dev, V4L2_DEBUG_ISOC, "lines= %d-%d, " | |
262 | "field=%d\n", | |
263 | start_line, last_line, field); | |
264 | ||
265 | if ((start_line<6 && last_line>200) && | |
266 | (last_field != field) ) { | |
267 | ||
268 | dev->isoc_ctl.nfields++; | |
269 | if (dev->isoc_ctl.nfields>=2) { | |
270 | dev->isoc_ctl.nfields=0; | |
271 | ||
272 | /* Announces that a new buffer were filled */ | |
273 | buffer_filled (dev, dma_q, *buf); | |
274 | dprintk(dev, V4L2_DEBUG_ISOC, | |
275 | "new buffer filled\n"); | |
721f507b MCC |
276 | get_next_buf (dma_q, buf); |
277 | if (!*buf) | |
278 | return rc; | |
e8a4845d MCC |
279 | out_p = videobuf_to_vmalloc(&((*buf)->vb)); |
280 | if (!out_p) | |
281 | return rc; | |
282 | ||
283 | pos = dev->isoc_ctl.pos = 0; | |
ed0236af MCC |
284 | } |
285 | } | |
a228618c | 286 | |
ed0236af MCC |
287 | start_line=line; |
288 | last_field=field; | |
a228618c | 289 | } |
6ae635c4 MCC |
290 | if (cmd == TM6000_URB_MSG_VIDEO) |
291 | last_line = line; | |
cc6c60d9 | 292 | |
ed0236af MCC |
293 | pktsize = TM6000_URB_MSG_LEN; |
294 | } else { | |
295 | /* Continue the last copy */ | |
296 | cmd = dev->isoc_ctl.cmd; | |
297 | size= dev->isoc_ctl.size; | |
298 | pos = dev->isoc_ctl.pos; | |
299 | pktsize = dev->isoc_ctl.pktsize; | |
e2c9500d MCC |
300 | } |
301 | ||
c4acf48c | 302 | cpysize = (endp-(*ptr) > size) ? size : endp - *ptr; |
e2c9500d MCC |
303 | |
304 | if (cpysize) { | |
305 | /* handles each different URB message */ | |
ed0236af | 306 | switch(cmd) { |
e2c9500d MCC |
307 | case TM6000_URB_MSG_VIDEO: |
308 | /* Fills video buffer */ | |
ed0236af | 309 | memcpy(&out_p[pos], *ptr, cpysize); |
a228618c MCC |
310 | break; |
311 | case TM6000_URB_MSG_PTS: | |
312 | break; | |
313 | case TM6000_URB_MSG_AUDIO: | |
3569417e SR |
314 | /* Need some code to process audio */ |
315 | printk ("%ld: cmd=%s, size=%d\n", jiffies, | |
ed0236af | 316 | tm6000_msg_type[cmd],size); |
a228618c | 317 | break; |
3569417e SR |
318 | case TM6000_URB_MSG_VBI: |
319 | break; | |
a228618c | 320 | default: |
ed0236af MCC |
321 | dprintk (dev, V4L2_DEBUG_ISOC, "cmd=%s, size=%d\n", |
322 | tm6000_msg_type[cmd],size); | |
e2c9500d MCC |
323 | } |
324 | } | |
ed0236af MCC |
325 | if (cpysize<size) { |
326 | /* End of URB packet, but cmd processing is not | |
327 | * complete. Preserve the state for a next packet | |
328 | */ | |
329 | dev->isoc_ctl.pos = pos+cpysize; | |
330 | dev->isoc_ctl.size= size-cpysize; | |
331 | dev->isoc_ctl.cmd = cmd; | |
332 | dev->isoc_ctl.pktsize = pktsize-cpysize; | |
333 | (*ptr)+=cpysize; | |
334 | } else { | |
335 | dev->isoc_ctl.cmd = 0; | |
336 | (*ptr)+=pktsize; | |
337 | } | |
e2c9500d | 338 | |
a228618c | 339 | return rc; |
e2c9500d MCC |
340 | } |
341 | ||
342 | static int copy_streams(u8 *data, u8 *out_p, unsigned long len, | |
343 | struct urb *urb, struct tm6000_buffer **buf) | |
344 | { | |
345 | struct tm6000_dmaqueue *dma_q = urb->context; | |
ed0236af MCC |
346 | struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq); |
347 | u8 *ptr=data, *endp=data+len; | |
348 | unsigned long header=0; | |
349 | int rc=0; | |
350 | ||
351 | for (ptr=data; ptr<endp;) { | |
352 | if (!dev->isoc_ctl.cmd) { | |
353 | u8 *p=(u8 *)&dev->isoc_ctl.tmp_buf; | |
354 | /* FIXME: This seems very complex | |
355 | * It just recovers up to 3 bytes of the header that | |
356 | * might be at the previous packet | |
357 | */ | |
358 | if (dev->isoc_ctl.tmp_buf_len) { | |
359 | while (dev->isoc_ctl.tmp_buf_len) { | |
360 | if ( *(ptr+3-dev->isoc_ctl.tmp_buf_len) == 0x47) { | |
361 | break; | |
362 | } | |
363 | p++; | |
364 | dev->isoc_ctl.tmp_buf_len--; | |
365 | } | |
366 | if (dev->isoc_ctl.tmp_buf_len) { | |
801dd3b3 | 367 | memcpy(&header, p, |
ed0236af | 368 | dev->isoc_ctl.tmp_buf_len); |
801dd3b3 MCC |
369 | memcpy((u8 *)&header + |
370 | dev->isoc_ctl.tmp_buf_len, | |
ed0236af | 371 | ptr, |
801dd3b3 MCC |
372 | 4 - dev->isoc_ctl.tmp_buf_len); |
373 | ptr += 4 - dev->isoc_ctl.tmp_buf_len; | |
ed0236af MCC |
374 | goto HEADER; |
375 | } | |
376 | } | |
9701dc94 | 377 | /* Seek for sync */ |
ed0236af MCC |
378 | for (;ptr<endp-3;ptr++) { |
379 | if (*(ptr+3)==0x47) | |
9701dc94 | 380 | break; |
9701dc94 | 381 | } |
cc6c60d9 | 382 | |
ed0236af MCC |
383 | if (ptr+3>=endp) { |
384 | dev->isoc_ctl.tmp_buf_len=endp-ptr; | |
385 | memcpy (&dev->isoc_ctl.tmp_buf,ptr, | |
386 | dev->isoc_ctl.tmp_buf_len); | |
387 | dev->isoc_ctl.cmd=0; | |
9701dc94 | 388 | return rc; |
cc6c60d9 | 389 | } |
6eb5c8a6 | 390 | |
ed0236af MCC |
391 | /* Get message header */ |
392 | header=*(unsigned long *)ptr; | |
393 | ptr+=4; | |
394 | } | |
395 | HEADER: | |
e2c9500d | 396 | /* Copy or continue last copy */ |
ed0236af MCC |
397 | rc=copy_packet(urb,header,&ptr,endp,out_p,buf); |
398 | if (rc<0) { | |
399 | buf=NULL; | |
a228618c MCC |
400 | printk(KERN_ERR "tm6000: buffer underrun at %ld\n", |
401 | jiffies); | |
402 | return rc; | |
403 | } | |
f4b727b3 MCC |
404 | if (!*buf) |
405 | return 0; | |
9701dc94 MCC |
406 | } |
407 | ||
a228618c | 408 | return 0; |
9701dc94 MCC |
409 | } |
410 | /* | |
411 | * Identify the tm5600/6000 buffer header type and properly handles | |
412 | */ | |
413 | static int copy_multiplexed(u8 *ptr, u8 *out_p, unsigned long len, | |
414 | struct urb *urb, struct tm6000_buffer **buf) | |
415 | { | |
416 | struct tm6000_dmaqueue *dma_q = urb->context; | |
ed0236af MCC |
417 | struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq); |
418 | unsigned int pos=dev->isoc_ctl.pos,cpysize; | |
419 | int rc=1; | |
420 | ||
421 | while (len>0) { | |
422 | cpysize=min(len,(*buf)->vb.size-pos); | |
423 | //printk("Copying %d bytes (max=%lu) from %p to %p[%u]\n",cpysize,(*buf)->vb.size,ptr,out_p,pos); | |
424 | memcpy(&out_p[pos], ptr, cpysize); | |
425 | pos+=cpysize; | |
426 | ptr+=cpysize; | |
427 | len-=cpysize; | |
9701dc94 | 428 | if (pos >= (*buf)->vb.size) { |
ed0236af | 429 | pos=0; |
9701dc94 | 430 | /* Announces that a new buffer were filled */ |
ed0236af | 431 | buffer_filled (dev, dma_q, *buf); |
5f796752 | 432 | dprintk(dev, V4L2_DEBUG_ISOC, "new buffer filled\n"); |
721f507b MCC |
433 | get_next_buf (dma_q, buf); |
434 | if (!*buf) | |
9701dc94 | 435 | break; |
e8a4845d MCC |
436 | out_p = videobuf_to_vmalloc(&((*buf)->vb)); |
437 | if (!out_p) | |
438 | return rc; | |
439 | pos = 0; | |
9701dc94 MCC |
440 | } |
441 | } | |
442 | ||
ed0236af | 443 | dev->isoc_ctl.pos=pos; |
9701dc94 MCC |
444 | return rc; |
445 | } | |
446 | ||
ed0236af MCC |
447 | static void inline print_err_status (struct tm6000_core *dev, |
448 | int packet, int status) | |
5f796752 MCC |
449 | { |
450 | char *errmsg = "Unknown"; | |
451 | ||
ed0236af | 452 | switch(status) { |
5f796752 MCC |
453 | case -ENOENT: |
454 | errmsg = "unlinked synchronuously"; | |
455 | break; | |
456 | case -ECONNRESET: | |
457 | errmsg = "unlinked asynchronuously"; | |
458 | break; | |
459 | case -ENOSR: | |
460 | errmsg = "Buffer error (overrun)"; | |
461 | break; | |
462 | case -EPIPE: | |
463 | errmsg = "Stalled (device not responding)"; | |
464 | break; | |
465 | case -EOVERFLOW: | |
466 | errmsg = "Babble (bad cable?)"; | |
467 | break; | |
468 | case -EPROTO: | |
469 | errmsg = "Bit-stuff error (bad cable?)"; | |
470 | break; | |
471 | case -EILSEQ: | |
472 | errmsg = "CRC/Timeout (could be anything)"; | |
473 | break; | |
474 | case -ETIME: | |
475 | errmsg = "Device does not respond"; | |
476 | break; | |
477 | } | |
ed0236af | 478 | if (packet<0) { |
5f796752 MCC |
479 | dprintk(dev, V4L2_DEBUG_QUEUE, "URB status %d [%s].\n", |
480 | status, errmsg); | |
481 | } else { | |
ed0236af | 482 | dprintk(dev, V4L2_DEBUG_QUEUE, "URB packet %d, status %d [%s].\n", |
5f796752 MCC |
483 | packet, status, errmsg); |
484 | } | |
485 | } | |
486 | ||
487 | ||
9701dc94 MCC |
488 | /* |
489 | * Controls the isoc copy of each urb packet | |
490 | */ | |
e8a4845d | 491 | static inline int tm6000_isoc_copy(struct urb *urb) |
9701dc94 MCC |
492 | { |
493 | struct tm6000_dmaqueue *dma_q = urb->context; | |
ed0236af | 494 | struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq); |
e8a4845d | 495 | struct tm6000_buffer *buf; |
ed0236af | 496 | int i, len=0, rc=1; |
e8a4845d MCC |
497 | int size; |
498 | char *outp = NULL, *p; | |
ed0236af | 499 | unsigned long copied; |
9701dc94 | 500 | |
e8a4845d | 501 | get_next_buf(dma_q, &buf); |
c16dd82b | 502 | if (buf) |
e8a4845d MCC |
503 | outp = videobuf_to_vmalloc(&buf->vb); |
504 | ||
505 | if (!outp) | |
506 | return 0; | |
507 | ||
508 | size = buf->vb.size; | |
509 | ||
ed0236af MCC |
510 | copied=0; |
511 | ||
512 | if (urb->status<0) { | |
513 | print_err_status (dev,-1,urb->status); | |
5f796752 MCC |
514 | return 0; |
515 | } | |
9701dc94 MCC |
516 | |
517 | for (i = 0; i < urb->number_of_packets; i++) { | |
518 | int status = urb->iso_frame_desc[i].status; | |
9701dc94 | 519 | |
ed0236af MCC |
520 | if (status<0) { |
521 | print_err_status (dev,i,status); | |
9701dc94 | 522 | continue; |
5f796752 | 523 | } |
9701dc94 | 524 | |
ed0236af MCC |
525 | len=urb->iso_frame_desc[i].actual_length; |
526 | ||
527 | // if (len>=TM6000_URB_MSG_LEN) { | |
528 | p=urb->transfer_buffer + urb->iso_frame_desc[i].offset; | |
529 | if (!urb->iso_frame_desc[i].status) { | |
e8a4845d MCC |
530 | if ((buf->fmt->fourcc)==V4L2_PIX_FMT_TM6000) { |
531 | rc=copy_multiplexed(p, outp, len, urb, &buf); | |
ed0236af MCC |
532 | if (rc<=0) |
533 | return rc; | |
534 | } else { | |
e8a4845d | 535 | copy_streams(p, outp, len, urb, &buf); |
ed0236af MCC |
536 | } |
537 | } | |
538 | copied += len; | |
f4b727b3 | 539 | if (copied >= size || !buf) |
ed0236af MCC |
540 | break; |
541 | // } | |
9701dc94 | 542 | } |
9701dc94 MCC |
543 | return rc; |
544 | } | |
545 | ||
546 | /* ------------------------------------------------------------------ | |
547 | URB control | |
548 | ------------------------------------------------------------------*/ | |
549 | ||
550 | /* | |
551 | * IRQ callback, called by URB callback | |
552 | */ | |
553 | static void tm6000_irq_callback(struct urb *urb) | |
554 | { | |
9701dc94 | 555 | struct tm6000_dmaqueue *dma_q = urb->context; |
c4acf48c | 556 | struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq); |
e8a4845d | 557 | int i; |
9701dc94 | 558 | |
721f507b MCC |
559 | if (!dev) |
560 | return; | |
a228618c | 561 | |
e8a4845d MCC |
562 | spin_lock(&dev->slock); |
563 | tm6000_isoc_copy(urb); | |
564 | spin_unlock(&dev->slock); | |
9701dc94 | 565 | |
e8a4845d MCC |
566 | /* Reset urb buffers */ |
567 | for (i = 0; i < urb->number_of_packets; i++) { | |
568 | urb->iso_frame_desc[i].status = 0; | |
569 | urb->iso_frame_desc[i].actual_length = 0; | |
570 | } | |
9701dc94 | 571 | |
c4acf48c MCC |
572 | urb->status = usb_submit_urb(urb, GFP_ATOMIC); |
573 | if (urb->status) | |
9701dc94 MCC |
574 | tm6000_err("urb resubmit failed (error=%i)\n", |
575 | urb->status); | |
9701dc94 MCC |
576 | } |
577 | ||
578 | /* | |
579 | * Stop and Deallocate URBs | |
580 | */ | |
581 | static void tm6000_uninit_isoc(struct tm6000_core *dev) | |
582 | { | |
583 | struct urb *urb; | |
584 | int i; | |
585 | ||
ee1fc07c MCC |
586 | dev->isoc_ctl.nfields = -1; |
587 | dev->isoc_ctl.buf = NULL; | |
9701dc94 MCC |
588 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { |
589 | urb=dev->isoc_ctl.urb[i]; | |
590 | if (urb) { | |
591 | usb_kill_urb(urb); | |
592 | usb_unlink_urb(urb); | |
593 | if (dev->isoc_ctl.transfer_buffer[i]) { | |
5a11b6fe | 594 | usb_free_coherent(dev->udev, |
9701dc94 MCC |
595 | urb->transfer_buffer_length, |
596 | dev->isoc_ctl.transfer_buffer[i], | |
597 | urb->transfer_dma); | |
598 | } | |
599 | usb_free_urb(urb); | |
600 | dev->isoc_ctl.urb[i] = NULL; | |
601 | } | |
602 | dev->isoc_ctl.transfer_buffer[i] = NULL; | |
603 | } | |
604 | ||
605 | kfree (dev->isoc_ctl.urb); | |
606 | kfree (dev->isoc_ctl.transfer_buffer); | |
c144c037 | 607 | |
9701dc94 MCC |
608 | dev->isoc_ctl.urb=NULL; |
609 | dev->isoc_ctl.transfer_buffer=NULL; | |
c144c037 | 610 | dev->isoc_ctl.num_bufs = 0; |
9701dc94 MCC |
611 | |
612 | dev->isoc_ctl.num_bufs=0; | |
613 | } | |
614 | ||
9701dc94 MCC |
615 | /* |
616 | * Allocate URBs and start IRQ | |
617 | */ | |
ee1fc07c | 618 | static int tm6000_prepare_isoc(struct tm6000_core *dev, unsigned int framesize) |
9701dc94 MCC |
619 | { |
620 | struct tm6000_dmaqueue *dma_q = &dev->vidq; | |
ee1fc07c | 621 | int i, j, sb_size, pipe, size, max_packets, num_bufs = 5; |
9701dc94 | 622 | struct urb *urb; |
204193d9 | 623 | |
9701dc94 MCC |
624 | /* De-allocates all pending stuff */ |
625 | tm6000_uninit_isoc(dev); | |
626 | ||
6ae635c4 MCC |
627 | usb_set_interface(dev->udev, |
628 | dev->isoc_in.bInterfaceNumber, | |
629 | dev->isoc_in.bAlternateSetting); | |
630 | ||
ee1fc07c | 631 | pipe = usb_rcvisocpipe(dev->udev, |
6ae635c4 | 632 | dev->isoc_in.endp->desc.bEndpointAddress & |
ee1fc07c MCC |
633 | USB_ENDPOINT_NUMBER_MASK); |
634 | ||
635 | size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe)); | |
636 | ||
6ae635c4 MCC |
637 | if (size > dev->isoc_in.maxsize) |
638 | size = dev->isoc_in.maxsize; | |
ee1fc07c MCC |
639 | |
640 | dev->isoc_ctl.max_pkt_size = size; | |
641 | ||
642 | max_packets = ( framesize + size - 1) / size; | |
643 | ||
644 | if (max_packets > TM6000_MAX_ISO_PACKETS) | |
645 | max_packets = TM6000_MAX_ISO_PACKETS; | |
646 | ||
647 | sb_size = max_packets * size; | |
648 | ||
649 | dev->isoc_ctl.num_bufs = num_bufs; | |
650 | ||
c144c037 | 651 | dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL); |
9701dc94 MCC |
652 | if (!dev->isoc_ctl.urb) { |
653 | tm6000_err("cannot alloc memory for usb buffers\n"); | |
654 | return -ENOMEM; | |
655 | } | |
656 | ||
ee1fc07c | 657 | dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs, |
9701dc94 | 658 | GFP_KERNEL); |
f8960ee7 | 659 | if (!dev->isoc_ctl.transfer_buffer) { |
9701dc94 MCC |
660 | tm6000_err("cannot allocate memory for usbtransfer\n"); |
661 | kfree(dev->isoc_ctl.urb); | |
662 | return -ENOMEM; | |
663 | } | |
664 | ||
ee1fc07c MCC |
665 | dprintk(dev, V4L2_DEBUG_QUEUE, "Allocating %d x %d packets" |
666 | " (%d bytes) of %d bytes each to handle %u size\n", | |
667 | max_packets, num_bufs, sb_size, | |
6ae635c4 | 668 | dev->isoc_in.maxsize, size); |
9701dc94 MCC |
669 | |
670 | /* allocate urbs and transfer buffers */ | |
671 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { | |
672 | urb = usb_alloc_urb(max_packets, GFP_KERNEL); | |
673 | if (!urb) { | |
674 | tm6000_err("cannot alloc isoc_ctl.urb %i\n", i); | |
675 | tm6000_uninit_isoc(dev); | |
c1a16414 | 676 | usb_free_urb(urb); |
9701dc94 MCC |
677 | return -ENOMEM; |
678 | } | |
679 | dev->isoc_ctl.urb[i] = urb; | |
680 | ||
5a11b6fe | 681 | dev->isoc_ctl.transfer_buffer[i] = usb_alloc_coherent(dev->udev, |
c13dd704 | 682 | sb_size, GFP_KERNEL, &urb->transfer_dma); |
9701dc94 MCC |
683 | if (!dev->isoc_ctl.transfer_buffer[i]) { |
684 | tm6000_err ("unable to allocate %i bytes for transfer" | |
a228618c MCC |
685 | " buffer %i%s\n", |
686 | sb_size, i, | |
687 | in_interrupt()?" while in int":""); | |
9701dc94 MCC |
688 | tm6000_uninit_isoc(dev); |
689 | return -ENOMEM; | |
690 | } | |
691 | memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size); | |
692 | ||
ee1fc07c MCC |
693 | usb_fill_bulk_urb(urb, dev->udev, pipe, |
694 | dev->isoc_ctl.transfer_buffer[i], sb_size, | |
695 | tm6000_irq_callback, dma_q); | |
6ae635c4 | 696 | urb->interval = dev->isoc_in.endp->desc.bInterval; |
9701dc94 | 697 | urb->number_of_packets = max_packets; |
ee1fc07c | 698 | urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; |
9701dc94 | 699 | |
9701dc94 | 700 | for (j = 0; j < max_packets; j++) { |
ee1fc07c MCC |
701 | urb->iso_frame_desc[j].offset = size * j; |
702 | urb->iso_frame_desc[j].length = size; | |
9701dc94 MCC |
703 | } |
704 | } | |
705 | ||
706 | return 0; | |
707 | } | |
708 | ||
c144c037 | 709 | static int tm6000_start_thread( struct tm6000_core *dev) |
9701dc94 | 710 | { |
c144c037 MCC |
711 | struct tm6000_dmaqueue *dma_q = &dev->vidq; |
712 | int i; | |
9701dc94 MCC |
713 | |
714 | dma_q->frame=0; | |
715 | dma_q->ini_jiffies=jiffies; | |
716 | ||
717 | init_waitqueue_head(&dma_q->wq); | |
718 | ||
719 | /* submit urbs and enables IRQ */ | |
720 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { | |
c144c037 | 721 | int rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC); |
9701dc94 MCC |
722 | if (rc) { |
723 | tm6000_err("submit of urb %i failed (error=%i)\n", i, | |
724 | rc); | |
725 | tm6000_uninit_isoc(dev); | |
726 | return rc; | |
727 | } | |
728 | } | |
729 | ||
9701dc94 MCC |
730 | return 0; |
731 | } | |
732 | ||
9701dc94 MCC |
733 | /* ------------------------------------------------------------------ |
734 | Videobuf operations | |
735 | ------------------------------------------------------------------*/ | |
95a83824 | 736 | |
9701dc94 MCC |
737 | static int |
738 | buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) | |
739 | { | |
740 | struct tm6000_fh *fh = vq->priv_data; | |
741 | ||
742 | *size = fh->fmt->depth * fh->width * fh->height >> 3; | |
743 | if (0 == *count) | |
95a83824 ML |
744 | *count = TM6000_DEF_BUF; |
745 | ||
746 | if (*count < TM6000_MIN_BUF) { | |
747 | *count=TM6000_MIN_BUF; | |
748 | } | |
749 | ||
9701dc94 MCC |
750 | while (*size * *count > vid_limit * 1024 * 1024) |
751 | (*count)--; | |
95a83824 | 752 | |
9701dc94 MCC |
753 | return 0; |
754 | } | |
755 | ||
756 | static void free_buffer(struct videobuf_queue *vq, struct tm6000_buffer *buf) | |
757 | { | |
721f507b MCC |
758 | struct tm6000_fh *fh = vq->priv_data; |
759 | struct tm6000_core *dev = fh->dev; | |
760 | unsigned long flags; | |
761 | ||
9701dc94 MCC |
762 | if (in_interrupt()) |
763 | BUG(); | |
764 | ||
721f507b MCC |
765 | /* We used to wait for the buffer to finish here, but this didn't work |
766 | because, as we were keeping the state as VIDEOBUF_QUEUED, | |
767 | videobuf_queue_cancel marked it as finished for us. | |
768 | (Also, it could wedge forever if the hardware was misconfigured.) | |
769 | ||
770 | This should be safe; by the time we get here, the buffer isn't | |
771 | queued anymore. If we ever start marking the buffers as | |
772 | VIDEOBUF_ACTIVE, it won't be, though. | |
773 | */ | |
774 | spin_lock_irqsave(&dev->slock, flags); | |
775 | if (dev->isoc_ctl.buf == buf) | |
776 | dev->isoc_ctl.buf = NULL; | |
777 | spin_unlock_irqrestore(&dev->slock, flags); | |
778 | ||
9701dc94 | 779 | videobuf_vmalloc_free(&buf->vb); |
47878f16 | 780 | buf->vb.state = VIDEOBUF_NEEDS_INIT; |
9701dc94 MCC |
781 | } |
782 | ||
783 | static int | |
784 | buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, | |
785 | enum v4l2_field field) | |
786 | { | |
787 | struct tm6000_fh *fh = vq->priv_data; | |
788 | struct tm6000_buffer *buf = container_of(vb,struct tm6000_buffer,vb); | |
789 | struct tm6000_core *dev = fh->dev; | |
204193d9 | 790 | int rc = 0, urb_init = 0; |
9701dc94 MCC |
791 | |
792 | BUG_ON(NULL == fh->fmt); | |
793 | ||
9701dc94 MCC |
794 | |
795 | /* FIXME: It assumes depth=2 */ | |
796 | /* The only currently supported format is 16 bits/pixel */ | |
797 | buf->vb.size = fh->fmt->depth*fh->width*fh->height >> 3; | |
798 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) | |
799 | return -EINVAL; | |
800 | ||
801 | if (buf->fmt != fh->fmt || | |
802 | buf->vb.width != fh->width || | |
803 | buf->vb.height != fh->height || | |
804 | buf->vb.field != field) { | |
805 | buf->fmt = fh->fmt; | |
806 | buf->vb.width = fh->width; | |
807 | buf->vb.height = fh->height; | |
808 | buf->vb.field = field; | |
47878f16 | 809 | buf->vb.state = VIDEOBUF_NEEDS_INIT; |
9701dc94 MCC |
810 | } |
811 | ||
47878f16 | 812 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
ee1fc07c | 813 | if (0 != (rc = videobuf_iolock(vq, &buf->vb, NULL))) |
9701dc94 | 814 | goto fail; |
ee1fc07c | 815 | urb_init = 1; |
9701dc94 MCC |
816 | } |
817 | ||
9701dc94 | 818 | if (!dev->isoc_ctl.num_bufs) |
ee1fc07c | 819 | urb_init = 1; |
9701dc94 MCC |
820 | |
821 | if (urb_init) { | |
ee1fc07c | 822 | rc = tm6000_prepare_isoc(dev, buf->vb.size); |
c144c037 MCC |
823 | if (rc < 0) |
824 | goto fail; | |
ee1fc07c | 825 | |
c144c037 | 826 | rc = tm6000_start_thread(dev); |
ee1fc07c | 827 | if (rc < 0) |
9701dc94 | 828 | goto fail; |
c144c037 | 829 | |
9701dc94 MCC |
830 | } |
831 | ||
47878f16 | 832 | buf->vb.state = VIDEOBUF_PREPARED; |
9701dc94 MCC |
833 | return 0; |
834 | ||
835 | fail: | |
ee1fc07c | 836 | free_buffer(vq, buf); |
9701dc94 MCC |
837 | return rc; |
838 | } | |
839 | ||
840 | static void | |
841 | buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) | |
842 | { | |
843 | struct tm6000_buffer *buf = container_of(vb,struct tm6000_buffer,vb); | |
844 | struct tm6000_fh *fh = vq->priv_data; | |
845 | struct tm6000_core *dev = fh->dev; | |
846 | struct tm6000_dmaqueue *vidq = &dev->vidq; | |
c144c037 MCC |
847 | |
848 | buf->vb.state = VIDEOBUF_QUEUED; | |
849 | list_add_tail(&buf->vb.queue, &vidq->active); | |
9701dc94 MCC |
850 | } |
851 | ||
852 | static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb) | |
853 | { | |
854 | struct tm6000_buffer *buf = container_of(vb,struct tm6000_buffer,vb); | |
9701dc94 MCC |
855 | |
856 | free_buffer(vq,buf); | |
857 | } | |
858 | ||
859 | static struct videobuf_queue_ops tm6000_video_qops = { | |
860 | .buf_setup = buffer_setup, | |
861 | .buf_prepare = buffer_prepare, | |
862 | .buf_queue = buffer_queue, | |
863 | .buf_release = buffer_release, | |
864 | }; | |
865 | ||
866 | /* ------------------------------------------------------------------ | |
867 | IOCTL handling | |
868 | ------------------------------------------------------------------*/ | |
869 | ||
870 | static int res_get(struct tm6000_core *dev, struct tm6000_fh *fh) | |
871 | { | |
872 | /* is it free? */ | |
873 | mutex_lock(&dev->lock); | |
874 | if (dev->resources) { | |
875 | /* no, someone else uses it */ | |
876 | mutex_unlock(&dev->lock); | |
877 | return 0; | |
878 | } | |
879 | /* it's free, grab it */ | |
880 | dev->resources =1; | |
881 | dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: get\n"); | |
882 | mutex_unlock(&dev->lock); | |
883 | return 1; | |
884 | } | |
885 | ||
886 | static int res_locked(struct tm6000_core *dev) | |
887 | { | |
888 | return (dev->resources); | |
889 | } | |
890 | ||
891 | static void res_free(struct tm6000_core *dev, struct tm6000_fh *fh) | |
892 | { | |
893 | mutex_lock(&dev->lock); | |
894 | dev->resources = 0; | |
895 | dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: put\n"); | |
896 | mutex_unlock(&dev->lock); | |
897 | } | |
898 | ||
899 | /* ------------------------------------------------------------------ | |
900 | IOCTL vidioc handling | |
901 | ------------------------------------------------------------------*/ | |
902 | static int vidioc_querycap (struct file *file, void *priv, | |
903 | struct v4l2_capability *cap) | |
904 | { | |
905 | // struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev; | |
906 | ||
907 | strlcpy(cap->driver, "tm6000", sizeof(cap->driver)); | |
e28f49b0 | 908 | strlcpy(cap->card,"Trident TVMaster TM5600/6000/6010", sizeof(cap->card)); |
9701dc94 MCC |
909 | // strlcpy(cap->bus_info, dev->udev->dev.bus_id, sizeof(cap->bus_info)); |
910 | cap->version = TM6000_VERSION; | |
911 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | | |
912 | V4L2_CAP_STREAMING | | |
913 | V4L2_CAP_TUNER | | |
914 | V4L2_CAP_READWRITE; | |
915 | return 0; | |
916 | } | |
917 | ||
2a8145d4 | 918 | static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv, |
9701dc94 MCC |
919 | struct v4l2_fmtdesc *f) |
920 | { | |
921 | if (unlikely(f->index >= ARRAY_SIZE(format))) | |
922 | return -EINVAL; | |
923 | ||
924 | strlcpy(f->description,format[f->index].name,sizeof(f->description)); | |
925 | f->pixelformat = format[f->index].fourcc; | |
926 | return 0; | |
927 | } | |
928 | ||
2a8145d4 | 929 | static int vidioc_g_fmt_vid_cap (struct file *file, void *priv, |
9701dc94 MCC |
930 | struct v4l2_format *f) |
931 | { | |
932 | struct tm6000_fh *fh=priv; | |
933 | ||
934 | f->fmt.pix.width = fh->width; | |
935 | f->fmt.pix.height = fh->height; | |
936 | f->fmt.pix.field = fh->vb_vidq.field; | |
937 | f->fmt.pix.pixelformat = fh->fmt->fourcc; | |
938 | f->fmt.pix.bytesperline = | |
939 | (f->fmt.pix.width * fh->fmt->depth) >> 3; | |
940 | f->fmt.pix.sizeimage = | |
941 | f->fmt.pix.height * f->fmt.pix.bytesperline; | |
942 | ||
943 | return (0); | |
944 | } | |
945 | ||
946 | static struct tm6000_fmt* format_by_fourcc(unsigned int fourcc) | |
947 | { | |
948 | unsigned int i; | |
949 | ||
950 | for (i = 0; i < ARRAY_SIZE(format); i++) | |
951 | if (format[i].fourcc == fourcc) | |
952 | return format+i; | |
953 | return NULL; | |
954 | } | |
955 | ||
2a8145d4 | 956 | static int vidioc_try_fmt_vid_cap (struct file *file, void *priv, |
9701dc94 MCC |
957 | struct v4l2_format *f) |
958 | { | |
959 | struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev; | |
960 | struct tm6000_fmt *fmt; | |
961 | enum v4l2_field field; | |
962 | ||
963 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); | |
964 | if (NULL == fmt) { | |
965 | dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Fourcc format (0x%08x)" | |
966 | " invalid.\n", f->fmt.pix.pixelformat); | |
967 | return -EINVAL; | |
968 | } | |
969 | ||
970 | field = f->fmt.pix.field; | |
971 | ||
972 | if (field == V4L2_FIELD_ANY) { | |
973 | // field=V4L2_FIELD_INTERLACED; | |
974 | field=V4L2_FIELD_SEQ_TB; | |
975 | } else if (V4L2_FIELD_INTERLACED != field) { | |
976 | dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Field type invalid.\n"); | |
977 | return -EINVAL; | |
978 | } | |
979 | ||
4475c044 | 980 | tm6000_get_std_res (dev); |
9701dc94 | 981 | |
4475c044 MCC |
982 | f->fmt.pix.width = dev->width; |
983 | f->fmt.pix.height = dev->height; | |
9701dc94 MCC |
984 | |
985 | f->fmt.pix.width &= ~0x01; | |
986 | ||
987 | f->fmt.pix.field = field; | |
988 | ||
989 | f->fmt.pix.bytesperline = | |
990 | (f->fmt.pix.width * fmt->depth) >> 3; | |
991 | f->fmt.pix.sizeimage = | |
992 | f->fmt.pix.height * f->fmt.pix.bytesperline; | |
993 | ||
994 | return 0; | |
995 | } | |
996 | ||
997 | /*FIXME: This seems to be generic enough to be at videodev2 */ | |
2a8145d4 | 998 | static int vidioc_s_fmt_vid_cap (struct file *file, void *priv, |
9701dc94 MCC |
999 | struct v4l2_format *f) |
1000 | { | |
1001 | struct tm6000_fh *fh=priv; | |
1002 | struct tm6000_core *dev = fh->dev; | |
2a8145d4 | 1003 | int ret = vidioc_try_fmt_vid_cap(file,fh,f); |
9701dc94 MCC |
1004 | if (ret < 0) |
1005 | return (ret); | |
1006 | ||
1007 | fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); | |
1008 | fh->width = f->fmt.pix.width; | |
1009 | fh->height = f->fmt.pix.height; | |
1010 | fh->vb_vidq.field = f->fmt.pix.field; | |
1011 | fh->type = f->type; | |
1012 | ||
1013 | dev->fourcc = f->fmt.pix.pixelformat; | |
1014 | ||
1015 | tm6000_set_fourcc_format(dev); | |
1016 | ||
1017 | return (0); | |
1018 | } | |
1019 | ||
1020 | static int vidioc_reqbufs (struct file *file, void *priv, | |
1021 | struct v4l2_requestbuffers *p) | |
1022 | { | |
1023 | struct tm6000_fh *fh=priv; | |
1024 | ||
1025 | return (videobuf_reqbufs(&fh->vb_vidq, p)); | |
1026 | } | |
1027 | ||
1028 | static int vidioc_querybuf (struct file *file, void *priv, | |
1029 | struct v4l2_buffer *p) | |
1030 | { | |
1031 | struct tm6000_fh *fh=priv; | |
1032 | ||
1033 | return (videobuf_querybuf(&fh->vb_vidq, p)); | |
1034 | } | |
1035 | ||
1036 | static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p) | |
1037 | { | |
1038 | struct tm6000_fh *fh=priv; | |
1039 | ||
1040 | return (videobuf_qbuf(&fh->vb_vidq, p)); | |
1041 | } | |
1042 | ||
1043 | static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p) | |
1044 | { | |
1045 | struct tm6000_fh *fh=priv; | |
1046 | ||
1047 | return (videobuf_dqbuf(&fh->vb_vidq, p, | |
1048 | file->f_flags & O_NONBLOCK)); | |
1049 | } | |
1050 | ||
1051 | #ifdef CONFIG_VIDEO_V4L1_COMPAT | |
1052 | static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf) | |
1053 | { | |
1054 | struct tm6000_fh *fh=priv; | |
1055 | ||
1056 | return videobuf_cgmbuf (&fh->vb_vidq, mbuf, 8); | |
1057 | } | |
1058 | #endif | |
1059 | ||
1060 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) | |
1061 | { | |
1062 | struct tm6000_fh *fh=priv; | |
1063 | struct tm6000_core *dev = fh->dev; | |
1064 | ||
1065 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
1066 | return -EINVAL; | |
1067 | if (i != fh->type) | |
1068 | return -EINVAL; | |
1069 | ||
1070 | if (!res_get(dev,fh)) | |
1071 | return -EBUSY; | |
1072 | return (videobuf_streamon(&fh->vb_vidq)); | |
1073 | } | |
1074 | ||
1075 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) | |
1076 | { | |
1077 | struct tm6000_fh *fh=priv; | |
1078 | struct tm6000_core *dev = fh->dev; | |
1079 | ||
1080 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
1081 | return -EINVAL; | |
1082 | if (i != fh->type) | |
1083 | return -EINVAL; | |
1084 | ||
1085 | videobuf_streamoff(&fh->vb_vidq); | |
1086 | res_free(dev,fh); | |
1087 | ||
1088 | return (0); | |
1089 | } | |
1090 | ||
1091 | static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *norm) | |
1092 | { | |
1093 | int rc=0; | |
1094 | struct tm6000_fh *fh=priv; | |
1095 | struct tm6000_core *dev = fh->dev; | |
1096 | ||
1097 | rc=tm6000_set_standard (dev, norm); | |
71e7cfae MCC |
1098 | |
1099 | fh->width = dev->width; | |
1100 | fh->height = dev->height; | |
1101 | ||
9701dc94 MCC |
1102 | if (rc<0) |
1103 | return rc; | |
1104 | ||
427f7fac | 1105 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm); |
9701dc94 MCC |
1106 | |
1107 | return 0; | |
1108 | } | |
1109 | ||
1110 | static int vidioc_enum_input (struct file *file, void *priv, | |
1111 | struct v4l2_input *inp) | |
1112 | { | |
1113 | switch (inp->index) { | |
1114 | case TM6000_INPUT_TV: | |
1115 | inp->type = V4L2_INPUT_TYPE_TUNER; | |
1116 | strcpy(inp->name,"Television"); | |
1117 | break; | |
1118 | case TM6000_INPUT_COMPOSITE: | |
1119 | inp->type = V4L2_INPUT_TYPE_CAMERA; | |
1120 | strcpy(inp->name,"Composite"); | |
1121 | break; | |
1122 | case TM6000_INPUT_SVIDEO: | |
1123 | inp->type = V4L2_INPUT_TYPE_CAMERA; | |
1124 | strcpy(inp->name,"S-Video"); | |
1125 | break; | |
1126 | default: | |
1127 | return -EINVAL; | |
1128 | } | |
1129 | inp->std = TM6000_STD; | |
1130 | ||
1131 | return 0; | |
1132 | } | |
1133 | ||
1134 | static int vidioc_g_input (struct file *file, void *priv, unsigned int *i) | |
1135 | { | |
1136 | struct tm6000_fh *fh=priv; | |
1137 | struct tm6000_core *dev = fh->dev; | |
1138 | ||
1139 | *i=dev->input; | |
1140 | ||
1141 | return 0; | |
1142 | } | |
1143 | static int vidioc_s_input (struct file *file, void *priv, unsigned int i) | |
1144 | { | |
1145 | struct tm6000_fh *fh=priv; | |
1146 | struct tm6000_core *dev = fh->dev; | |
1147 | int rc=0; | |
1148 | char buf[1]; | |
1149 | ||
1150 | switch (i) { | |
1151 | case TM6000_INPUT_TV: | |
1152 | dev->input=i; | |
1153 | *buf=0; | |
1154 | break; | |
1155 | case TM6000_INPUT_COMPOSITE: | |
1156 | case TM6000_INPUT_SVIDEO: | |
1157 | dev->input=i; | |
1158 | *buf=1; | |
1159 | break; | |
1160 | default: | |
1161 | return -EINVAL; | |
1162 | } | |
1163 | rc=tm6000_read_write_usb (dev, USB_DIR_OUT | USB_TYPE_VENDOR, | |
1164 | REQ_03_SET_GET_MCU_PIN, 0x03, 1, buf, 1); | |
1165 | ||
1166 | if (!rc) { | |
1167 | dev->input=i; | |
7c3f53ec | 1168 | rc=vidioc_s_std (file, priv, &dev->vfd->current_norm); |
9701dc94 MCC |
1169 | } |
1170 | ||
1171 | return (rc); | |
1172 | } | |
1173 | ||
1174 | /* --- controls ---------------------------------------------- */ | |
1175 | static int vidioc_queryctrl (struct file *file, void *priv, | |
1176 | struct v4l2_queryctrl *qc) | |
1177 | { | |
1178 | int i; | |
1179 | ||
1180 | for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++) | |
1181 | if (qc->id && qc->id == tm6000_qctrl[i].id) { | |
1182 | memcpy(qc, &(tm6000_qctrl[i]), | |
1183 | sizeof(*qc)); | |
1184 | return (0); | |
1185 | } | |
1186 | ||
1187 | return -EINVAL; | |
1188 | } | |
1189 | ||
1190 | static int vidioc_g_ctrl (struct file *file, void *priv, | |
1191 | struct v4l2_control *ctrl) | |
1192 | { | |
1193 | struct tm6000_fh *fh=priv; | |
1194 | struct tm6000_core *dev = fh->dev; | |
1195 | int val; | |
1196 | ||
1197 | /* FIXME: Probably, those won't work! Maybe we need shadow regs */ | |
1198 | switch (ctrl->id) { | |
1199 | case V4L2_CID_CONTRAST: | |
9afec493 | 1200 | val = tm6000_get_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, 0); |
9701dc94 MCC |
1201 | break; |
1202 | case V4L2_CID_BRIGHTNESS: | |
9afec493 | 1203 | val = tm6000_get_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, 0); |
9701dc94 MCC |
1204 | return 0; |
1205 | case V4L2_CID_SATURATION: | |
9afec493 | 1206 | val = tm6000_get_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, 0); |
9701dc94 MCC |
1207 | return 0; |
1208 | case V4L2_CID_HUE: | |
9afec493 | 1209 | val = tm6000_get_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, 0); |
9701dc94 MCC |
1210 | return 0; |
1211 | default: | |
1212 | return -EINVAL; | |
1213 | } | |
1214 | ||
1215 | if (val<0) | |
1216 | return val; | |
1217 | ||
1218 | ctrl->value=val; | |
1219 | ||
1220 | return 0; | |
1221 | } | |
1222 | static int vidioc_s_ctrl (struct file *file, void *priv, | |
1223 | struct v4l2_control *ctrl) | |
1224 | { | |
1225 | struct tm6000_fh *fh =priv; | |
1226 | struct tm6000_core *dev = fh->dev; | |
1227 | u8 val=ctrl->value; | |
1228 | ||
1229 | switch (ctrl->id) { | |
1230 | case V4L2_CID_CONTRAST: | |
9afec493 | 1231 | tm6000_set_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, val); |
9701dc94 MCC |
1232 | return 0; |
1233 | case V4L2_CID_BRIGHTNESS: | |
9afec493 | 1234 | tm6000_set_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, val); |
9701dc94 MCC |
1235 | return 0; |
1236 | case V4L2_CID_SATURATION: | |
9afec493 | 1237 | tm6000_set_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, val); |
9701dc94 MCC |
1238 | return 0; |
1239 | case V4L2_CID_HUE: | |
9afec493 | 1240 | tm6000_set_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, val); |
9701dc94 MCC |
1241 | return 0; |
1242 | } | |
1243 | return -EINVAL; | |
1244 | } | |
1245 | ||
1246 | static int vidioc_g_tuner (struct file *file, void *priv, | |
1247 | struct v4l2_tuner *t) | |
1248 | { | |
1249 | struct tm6000_fh *fh =priv; | |
1250 | struct tm6000_core *dev = fh->dev; | |
1251 | ||
1252 | if (unlikely(UNSET == dev->tuner_type)) | |
1253 | return -EINVAL; | |
1254 | if (0 != t->index) | |
1255 | return -EINVAL; | |
1256 | ||
1257 | strcpy(t->name, "Television"); | |
1258 | t->type = V4L2_TUNER_ANALOG_TV; | |
1259 | t->capability = V4L2_TUNER_CAP_NORM; | |
1260 | t->rangehigh = 0xffffffffUL; | |
1261 | t->rxsubchans = V4L2_TUNER_SUB_MONO; | |
1262 | ||
1263 | return 0; | |
1264 | } | |
1265 | ||
1266 | static int vidioc_s_tuner (struct file *file, void *priv, | |
1267 | struct v4l2_tuner *t) | |
1268 | { | |
1269 | struct tm6000_fh *fh =priv; | |
1270 | struct tm6000_core *dev = fh->dev; | |
1271 | ||
1272 | if (UNSET == dev->tuner_type) | |
1273 | return -EINVAL; | |
1274 | if (0 != t->index) | |
1275 | return -EINVAL; | |
1276 | ||
1277 | return 0; | |
1278 | } | |
1279 | ||
1280 | static int vidioc_g_frequency (struct file *file, void *priv, | |
1281 | struct v4l2_frequency *f) | |
1282 | { | |
1283 | struct tm6000_fh *fh =priv; | |
1284 | struct tm6000_core *dev = fh->dev; | |
1285 | ||
1286 | if (unlikely(UNSET == dev->tuner_type)) | |
1287 | return -EINVAL; | |
1288 | ||
1289 | f->type = V4L2_TUNER_ANALOG_TV; | |
1290 | f->frequency = dev->freq; | |
1291 | ||
427f7fac | 1292 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f); |
9701dc94 MCC |
1293 | |
1294 | return 0; | |
1295 | } | |
1296 | ||
1297 | static int vidioc_s_frequency (struct file *file, void *priv, | |
1298 | struct v4l2_frequency *f) | |
1299 | { | |
1300 | struct tm6000_fh *fh =priv; | |
1301 | struct tm6000_core *dev = fh->dev; | |
1302 | ||
1303 | if (unlikely(f->type != V4L2_TUNER_ANALOG_TV)) | |
1304 | return -EINVAL; | |
1305 | ||
1306 | if (unlikely(UNSET == dev->tuner_type)) | |
1307 | return -EINVAL; | |
1308 | if (unlikely(f->tuner != 0)) | |
1309 | return -EINVAL; | |
1310 | ||
1311 | // mutex_lock(&dev->lock); | |
1312 | dev->freq = f->frequency; | |
64d339d4 | 1313 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f); |
9701dc94 MCC |
1314 | // mutex_unlock(&dev->lock); |
1315 | ||
1316 | return 0; | |
1317 | } | |
1318 | ||
1319 | /* ------------------------------------------------------------------ | |
1320 | File operations for the device | |
1321 | ------------------------------------------------------------------*/ | |
1322 | ||
64d339d4 | 1323 | static int tm6000_open(struct file *file) |
9701dc94 | 1324 | { |
0a34df53 MCC |
1325 | struct video_device *vdev = video_devdata(file); |
1326 | struct tm6000_core *dev = video_drvdata(file); | |
9701dc94 | 1327 | struct tm6000_fh *fh; |
e8d04167 | 1328 | enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
9701dc94 MCC |
1329 | int i,rc; |
1330 | ||
0a34df53 MCC |
1331 | printk(KERN_INFO "tm6000: open called (dev=%s)\n", |
1332 | video_device_node_name(vdev)); | |
7c3f53ec | 1333 | |
0a34df53 MCC |
1334 | dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n", |
1335 | video_device_node_name(vdev)); | |
9701dc94 | 1336 | |
9701dc94 MCC |
1337 | |
1338 | /* If more than one user, mutex should be added */ | |
1339 | dev->users++; | |
1340 | ||
0a34df53 MCC |
1341 | dprintk(dev, V4L2_DEBUG_OPEN, "open dev=%s type=%s users=%d\n", |
1342 | video_device_node_name(vdev), v4l2_type_names[type], | |
1343 | dev->users); | |
9701dc94 MCC |
1344 | |
1345 | /* allocate + initialize per filehandle data */ | |
1346 | fh = kzalloc(sizeof(*fh),GFP_KERNEL); | |
1347 | if (NULL == fh) { | |
1348 | dev->users--; | |
1349 | return -ENOMEM; | |
1350 | } | |
1351 | ||
1352 | file->private_data = fh; | |
1353 | fh->dev = dev; | |
1354 | ||
1355 | fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | |
1356 | dev->fourcc = format[0].fourcc; | |
1357 | ||
1358 | fh->fmt = format_by_fourcc(dev->fourcc); | |
4475c044 MCC |
1359 | |
1360 | tm6000_get_std_res (dev); | |
1361 | ||
1362 | fh->width = dev->width; | |
1363 | fh->height = dev->height; | |
9701dc94 MCC |
1364 | |
1365 | dprintk(dev, V4L2_DEBUG_OPEN, "Open: fh=0x%08lx, dev=0x%08lx, " | |
1366 | "dev->vidq=0x%08lx\n", | |
1367 | (unsigned long)fh,(unsigned long)dev,(unsigned long)&dev->vidq); | |
1368 | dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty " | |
1369 | "queued=%d\n",list_empty(&dev->vidq.queued)); | |
1370 | dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty " | |
1371 | "active=%d\n",list_empty(&dev->vidq.active)); | |
1372 | ||
1373 | /* initialize hardware on analog mode */ | |
1374 | if (dev->mode!=TM6000_MODE_ANALOG) { | |
1375 | rc=tm6000_init_analog_mode (dev); | |
1376 | if (rc<0) | |
1377 | return rc; | |
1378 | ||
1379 | /* Put all controls at a sane state */ | |
1380 | for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++) | |
1381 | qctl_regs[i] =tm6000_qctrl[i].default_value; | |
1382 | ||
1383 | dev->mode=TM6000_MODE_ANALOG; | |
1384 | } | |
1385 | ||
1386 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops, | |
1387 | NULL, &dev->slock, | |
1388 | fh->type, | |
1389 | V4L2_FIELD_INTERLACED, | |
1390 | sizeof(struct tm6000_buffer),fh); | |
1391 | ||
1392 | return 0; | |
1393 | } | |
1394 | ||
1395 | static ssize_t | |
1396 | tm6000_read(struct file *file, char __user *data, size_t count, loff_t *pos) | |
1397 | { | |
1398 | struct tm6000_fh *fh = file->private_data; | |
1399 | ||
1400 | if (fh->type==V4L2_BUF_TYPE_VIDEO_CAPTURE) { | |
1401 | if (res_locked(fh->dev)) | |
1402 | return -EBUSY; | |
1403 | ||
1404 | return videobuf_read_stream(&fh->vb_vidq, data, count, pos, 0, | |
1405 | file->f_flags & O_NONBLOCK); | |
1406 | } | |
1407 | return 0; | |
1408 | } | |
1409 | ||
1410 | static unsigned int | |
1411 | tm6000_poll(struct file *file, struct poll_table_struct *wait) | |
1412 | { | |
1413 | struct tm6000_fh *fh = file->private_data; | |
1414 | struct tm6000_buffer *buf; | |
1415 | ||
1416 | if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) | |
1417 | return POLLERR; | |
1418 | ||
1419 | if (res_get(fh->dev,fh)) { | |
1420 | /* streaming capture */ | |
1421 | if (list_empty(&fh->vb_vidq.stream)) | |
1422 | return POLLERR; | |
1423 | buf = list_entry(fh->vb_vidq.stream.next,struct tm6000_buffer,vb.stream); | |
1424 | } else { | |
1425 | /* read() capture */ | |
dc6a02aa MCC |
1426 | return videobuf_poll_stream(file, &fh->vb_vidq, |
1427 | wait); | |
9701dc94 MCC |
1428 | } |
1429 | poll_wait(file, &buf->vb.done, wait); | |
47878f16 MCC |
1430 | if (buf->vb.state == VIDEOBUF_DONE || |
1431 | buf->vb.state == VIDEOBUF_ERROR) | |
9701dc94 MCC |
1432 | return POLLIN|POLLRDNORM; |
1433 | return 0; | |
1434 | } | |
1435 | ||
64d339d4 | 1436 | static int tm6000_release(struct file *file) |
9701dc94 MCC |
1437 | { |
1438 | struct tm6000_fh *fh = file->private_data; | |
1439 | struct tm6000_core *dev = fh->dev; | |
0a34df53 | 1440 | struct video_device *vdev = video_devdata(file); |
9701dc94 | 1441 | |
0a34df53 MCC |
1442 | dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: close called (dev=%s, users=%d)\n", |
1443 | video_device_node_name(vdev), dev->users); | |
7c3f53ec | 1444 | |
a58d35cb MCC |
1445 | dev->users--; |
1446 | ||
1447 | if (!dev->users) { | |
c144c037 | 1448 | tm6000_uninit_isoc(dev); |
a58d35cb MCC |
1449 | videobuf_mmap_free(&fh->vb_vidq); |
1450 | } | |
9701dc94 MCC |
1451 | |
1452 | kfree (fh); | |
1453 | ||
9701dc94 MCC |
1454 | return 0; |
1455 | } | |
1456 | ||
1457 | static int tm6000_mmap(struct file *file, struct vm_area_struct * vma) | |
1458 | { | |
1459 | struct tm6000_fh *fh = file->private_data; | |
1460 | int ret; | |
1461 | ||
1462 | ret=videobuf_mmap_mapper(&fh->vb_vidq, vma); | |
1463 | ||
1464 | return ret; | |
1465 | } | |
1466 | ||
64d339d4 | 1467 | static struct v4l2_file_operations tm6000_fops = { |
9701dc94 MCC |
1468 | .owner = THIS_MODULE, |
1469 | .open = tm6000_open, | |
1470 | .release = tm6000_release, | |
1471 | .ioctl = video_ioctl2, /* V4L2 ioctl handler */ | |
1472 | .read = tm6000_read, | |
1473 | .poll = tm6000_poll, | |
1474 | .mmap = tm6000_mmap, | |
9701dc94 MCC |
1475 | }; |
1476 | ||
2a8145d4 MCC |
1477 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
1478 | .vidioc_querycap = vidioc_querycap, | |
1479 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, | |
1480 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, | |
1481 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, | |
1482 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, | |
1483 | .vidioc_s_std = vidioc_s_std, | |
1484 | .vidioc_enum_input = vidioc_enum_input, | |
1485 | .vidioc_g_input = vidioc_g_input, | |
1486 | .vidioc_s_input = vidioc_s_input, | |
1487 | .vidioc_queryctrl = vidioc_queryctrl, | |
1488 | .vidioc_g_ctrl = vidioc_g_ctrl, | |
1489 | .vidioc_s_ctrl = vidioc_s_ctrl, | |
1490 | .vidioc_g_tuner = vidioc_g_tuner, | |
1491 | .vidioc_s_tuner = vidioc_s_tuner, | |
1492 | .vidioc_g_frequency = vidioc_g_frequency, | |
1493 | .vidioc_s_frequency = vidioc_s_frequency, | |
1494 | .vidioc_streamon = vidioc_streamon, | |
1495 | .vidioc_streamoff = vidioc_streamoff, | |
1496 | .vidioc_reqbufs = vidioc_reqbufs, | |
1497 | .vidioc_querybuf = vidioc_querybuf, | |
1498 | .vidioc_qbuf = vidioc_qbuf, | |
1499 | .vidioc_dqbuf = vidioc_dqbuf, | |
1500 | #ifdef CONFIG_VIDEO_V4L1_COMPAT | |
1501 | .vidiocgmbuf = vidiocgmbuf, | |
1502 | #endif | |
1503 | }; | |
1504 | ||
9701dc94 MCC |
1505 | static struct video_device tm6000_template = { |
1506 | .name = "tm6000", | |
9701dc94 | 1507 | .fops = &tm6000_fops, |
2a8145d4 | 1508 | .ioctl_ops = &video_ioctl_ops, |
9701dc94 | 1509 | .release = video_device_release, |
2a8145d4 MCC |
1510 | .tvnorms = TM6000_STD, |
1511 | .current_norm = V4L2_STD_NTSC_M, | |
9701dc94 | 1512 | }; |
2a8145d4 | 1513 | |
9701dc94 MCC |
1514 | /* ----------------------------------------------------------------- |
1515 | Initialization and module stuff | |
1516 | ------------------------------------------------------------------*/ | |
1517 | ||
1518 | int tm6000_v4l2_register(struct tm6000_core *dev) | |
1519 | { | |
7c3f53ec ML |
1520 | int ret = -1; |
1521 | struct video_device *vfd; | |
1522 | ||
1523 | vfd = video_device_alloc(); | |
1524 | if(!vfd) { | |
1525 | return -ENOMEM; | |
1526 | } | |
1527 | dev->vfd = vfd; | |
9701dc94 | 1528 | |
9701dc94 MCC |
1529 | /* init video dma queues */ |
1530 | INIT_LIST_HEAD(&dev->vidq.active); | |
1531 | INIT_LIST_HEAD(&dev->vidq.queued); | |
1532 | ||
7c3f53ec ML |
1533 | memcpy (dev->vfd, &tm6000_template, sizeof(*(dev->vfd))); |
1534 | dev->vfd->debug=tm6000_debug; | |
427f7fac | 1535 | vfd->v4l2_dev = &dev->v4l2_dev; |
e8d04167 | 1536 | video_set_drvdata(vfd, dev); |
9701dc94 | 1537 | |
7c3f53ec | 1538 | ret = video_register_device(dev->vfd, VFL_TYPE_GRABBER, video_nr); |
e28f49b0 | 1539 | printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret); |
9701dc94 MCC |
1540 | return ret; |
1541 | } | |
1542 | ||
1543 | int tm6000_v4l2_unregister(struct tm6000_core *dev) | |
1544 | { | |
7c3f53ec | 1545 | video_unregister_device(dev->vfd); |
22927e8e | 1546 | |
9701dc94 MCC |
1547 | return 0; |
1548 | } | |
1549 | ||
1550 | int tm6000_v4l2_exit(void) | |
1551 | { | |
1552 | return 0; | |
1553 | } | |
1554 | ||
1555 | module_param(video_nr, int, 0); | |
1556 | MODULE_PARM_DESC(video_nr,"Allow changing video device number"); | |
1557 | ||
1558 | module_param_named (debug, tm6000_debug, int, 0444); | |
1559 | MODULE_PARM_DESC(debug,"activates debug info"); | |
1560 | ||
1561 | module_param(vid_limit,int,0644); | |
1562 | MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes"); | |
1563 |