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