[media] v4l2: add const to argument of write-only s_tuner ioctl
[deliverable/linux.git] / drivers / media / usb / hdpvr / hdpvr-video.c
CommitLineData
9aba42ef 1/*
e86da6f0 2 * Hauppauge HD PVR USB driver - video 4 linux 2 interface
9aba42ef
JG
3 *
4 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 */
11
12#include <linux/kernel.h>
54d80904 13#include <linux/kconfig.h>
9aba42ef
JG
14#include <linux/errno.h>
15#include <linux/init.h>
16#include <linux/slab.h>
17#include <linux/module.h>
18#include <linux/uaccess.h>
19#include <linux/usb.h>
20#include <linux/mutex.h>
9aba42ef
JG
21#include <linux/workqueue.h>
22
23#include <linux/videodev2.h>
24#include <media/v4l2-dev.h>
25#include <media/v4l2-common.h>
26#include <media/v4l2-ioctl.h>
27#include "hdpvr.h"
28
39bcb3ae 29#define BULK_URB_TIMEOUT 90 /* 0.09 seconds */
9aba42ef 30
9ef77adf
JG
31#define print_buffer_status() { \
32 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, \
33 "%s:%d buffer stat: %d free, %d proc\n", \
34 __func__, __LINE__, \
35 list_size(&dev->free_buff_list), \
36 list_size(&dev->rec_buff_list)); }
d211bfcb 37
9aba42ef
JG
38struct hdpvr_fh {
39 struct hdpvr_device *dev;
40};
41
42static uint list_size(struct list_head *list)
43{
44 struct list_head *tmp;
45 uint count = 0;
46
47 list_for_each(tmp, list) {
48 count++;
49 }
50
51 return count;
52}
53
54/*=========================================================================*/
55/* urb callback */
56static void hdpvr_read_bulk_callback(struct urb *urb)
57{
58 struct hdpvr_buffer *buf = (struct hdpvr_buffer *)urb->context;
59 struct hdpvr_device *dev = buf->dev;
60
61 /* marking buffer as received and wake waiting */
62 buf->status = BUFSTAT_READY;
63 wake_up_interruptible(&dev->wait_data);
64}
65
66/*=========================================================================*/
67/* bufffer bits */
68
69/* function expects dev->io_mutex to be hold by caller */
70int hdpvr_cancel_queue(struct hdpvr_device *dev)
71{
72 struct hdpvr_buffer *buf;
73
74 list_for_each_entry(buf, &dev->rec_buff_list, buff_list) {
75 usb_kill_urb(buf->urb);
76 buf->status = BUFSTAT_AVAILABLE;
77 }
78
79 list_splice_init(&dev->rec_buff_list, dev->free_buff_list.prev);
80
81 return 0;
82}
83
84static int hdpvr_free_queue(struct list_head *q)
85{
86 struct list_head *tmp;
87 struct list_head *p;
88 struct hdpvr_buffer *buf;
89 struct urb *urb;
90
91 for (p = q->next; p != q;) {
92 buf = list_entry(p, struct hdpvr_buffer, buff_list);
93
94 urb = buf->urb;
997ea58e
DM
95 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
96 urb->transfer_buffer, urb->transfer_dma);
9aba42ef
JG
97 usb_free_urb(urb);
98 tmp = p->next;
99 list_del(p);
100 kfree(buf);
101 p = tmp;
102 }
103
104 return 0;
105}
106
107/* function expects dev->io_mutex to be hold by caller */
108int hdpvr_free_buffers(struct hdpvr_device *dev)
109{
110 hdpvr_cancel_queue(dev);
111
112 hdpvr_free_queue(&dev->free_buff_list);
113 hdpvr_free_queue(&dev->rec_buff_list);
114
115 return 0;
116}
117
118/* function expects dev->io_mutex to be hold by caller */
119int hdpvr_alloc_buffers(struct hdpvr_device *dev, uint count)
120{
121 uint i;
122 int retval = -ENOMEM;
123 u8 *mem;
124 struct hdpvr_buffer *buf;
125 struct urb *urb;
126
9ef77adf 127 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
9aba42ef
JG
128 "allocating %u buffers\n", count);
129
130 for (i = 0; i < count; i++) {
131
132 buf = kzalloc(sizeof(struct hdpvr_buffer), GFP_KERNEL);
133 if (!buf) {
9ef77adf 134 v4l2_err(&dev->v4l2_dev, "cannot allocate buffer\n");
9aba42ef
JG
135 goto exit;
136 }
137 buf->dev = dev;
138
139 urb = usb_alloc_urb(0, GFP_KERNEL);
140 if (!urb) {
9ef77adf 141 v4l2_err(&dev->v4l2_dev, "cannot allocate urb\n");
cd0e280f 142 goto exit_urb;
9aba42ef
JG
143 }
144 buf->urb = urb;
145
997ea58e
DM
146 mem = usb_alloc_coherent(dev->udev, dev->bulk_in_size, GFP_KERNEL,
147 &urb->transfer_dma);
9aba42ef 148 if (!mem) {
9ef77adf
JG
149 v4l2_err(&dev->v4l2_dev,
150 "cannot allocate usb transfer buffer\n");
cd0e280f 151 goto exit_urb_buffer;
9aba42ef
JG
152 }
153
154 usb_fill_bulk_urb(buf->urb, dev->udev,
155 usb_rcvbulkpipe(dev->udev,
156 dev->bulk_in_endpointAddr),
157 mem, dev->bulk_in_size,
158 hdpvr_read_bulk_callback, buf);
159
4f5c933a 160 buf->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
9aba42ef
JG
161 buf->status = BUFSTAT_AVAILABLE;
162 list_add_tail(&buf->buff_list, &dev->free_buff_list);
163 }
164 return 0;
cd0e280f
JL
165exit_urb_buffer:
166 usb_free_urb(urb);
167exit_urb:
168 kfree(buf);
9aba42ef
JG
169exit:
170 hdpvr_free_buffers(dev);
171 return retval;
172}
173
174static int hdpvr_submit_buffers(struct hdpvr_device *dev)
175{
176 struct hdpvr_buffer *buf;
177 struct urb *urb;
178 int ret = 0, err_count = 0;
179
180 mutex_lock(&dev->io_mutex);
181
182 while (dev->status == STATUS_STREAMING &&
183 !list_empty(&dev->free_buff_list)) {
184
185 buf = list_entry(dev->free_buff_list.next, struct hdpvr_buffer,
186 buff_list);
187 if (buf->status != BUFSTAT_AVAILABLE) {
9ef77adf 188 v4l2_err(&dev->v4l2_dev,
4b512d26 189 "buffer not marked as available\n");
9aba42ef
JG
190 ret = -EFAULT;
191 goto err;
192 }
193
194 urb = buf->urb;
195 urb->status = 0;
196 urb->actual_length = 0;
197 ret = usb_submit_urb(urb, GFP_KERNEL);
198 if (ret) {
9ef77adf
JG
199 v4l2_err(&dev->v4l2_dev,
200 "usb_submit_urb in %s returned %d\n",
201 __func__, ret);
9aba42ef
JG
202 if (++err_count > 2)
203 break;
204 continue;
205 }
206 buf->status = BUFSTAT_INPROGRESS;
207 list_move_tail(&buf->buff_list, &dev->rec_buff_list);
208 }
209err:
d211bfcb 210 print_buffer_status();
9aba42ef
JG
211 mutex_unlock(&dev->io_mutex);
212 return ret;
213}
214
215static struct hdpvr_buffer *hdpvr_get_next_buffer(struct hdpvr_device *dev)
216{
217 struct hdpvr_buffer *buf;
218
219 mutex_lock(&dev->io_mutex);
220
221 if (list_empty(&dev->rec_buff_list)) {
222 mutex_unlock(&dev->io_mutex);
223 return NULL;
224 }
225
226 buf = list_entry(dev->rec_buff_list.next, struct hdpvr_buffer,
227 buff_list);
228 mutex_unlock(&dev->io_mutex);
229
230 return buf;
231}
232
233static void hdpvr_transmit_buffers(struct work_struct *work)
234{
235 struct hdpvr_device *dev = container_of(work, struct hdpvr_device,
236 worker);
237
238 while (dev->status == STATUS_STREAMING) {
239
240 if (hdpvr_submit_buffers(dev)) {
9ef77adf 241 v4l2_err(&dev->v4l2_dev, "couldn't submit buffers\n");
9aba42ef
JG
242 goto error;
243 }
244 if (wait_event_interruptible(dev->wait_buffer,
245 !list_empty(&dev->free_buff_list) ||
246 dev->status != STATUS_STREAMING))
247 goto error;
248 }
249
9ef77adf 250 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
9aba42ef
JG
251 "transmit worker exited\n");
252 return;
253error:
9ef77adf 254 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
9aba42ef
JG
255 "transmit buffers errored\n");
256 dev->status = STATUS_ERROR;
257}
258
259/* function expects dev->io_mutex to be hold by caller */
260static int hdpvr_start_streaming(struct hdpvr_device *dev)
261{
262 int ret;
263 struct hdpvr_video_info *vidinf;
264
265 if (dev->status == STATUS_STREAMING)
266 return 0;
267 else if (dev->status != STATUS_IDLE)
268 return -EAGAIN;
269
270 vidinf = get_video_info(dev);
271
272 if (vidinf) {
9ef77adf 273 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
9aba42ef
JG
274 "video signal: %dx%d@%dhz\n", vidinf->width,
275 vidinf->height, vidinf->fps);
276 kfree(vidinf);
277
278 /* start streaming 2 request */
279 ret = usb_control_msg(dev->udev,
280 usb_sndctrlpipe(dev->udev, 0),
281 0xb8, 0x38, 0x1, 0, NULL, 0, 8000);
9ef77adf 282 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
9aba42ef
JG
283 "encoder start control request returned %d\n", ret);
284
285 hdpvr_config_call(dev, CTRL_START_STREAMING_VALUE, 0x00);
286
afa15953
JG
287 dev->status = STATUS_STREAMING;
288
9aba42ef
JG
289 INIT_WORK(&dev->worker, hdpvr_transmit_buffers);
290 queue_work(dev->workqueue, &dev->worker);
291
9ef77adf 292 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
9aba42ef 293 "streaming started\n");
9aba42ef
JG
294
295 return 0;
296 }
297 msleep(250);
9ef77adf 298 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
9aba42ef
JG
299 "no video signal at input %d\n", dev->options.video_input);
300 return -EAGAIN;
301}
302
303
304/* function expects dev->io_mutex to be hold by caller */
305static int hdpvr_stop_streaming(struct hdpvr_device *dev)
306{
85d682b9
MN
307 int actual_length;
308 uint c = 0;
7d771ff0
JG
309 u8 *buf;
310
9aba42ef
JG
311 if (dev->status == STATUS_IDLE)
312 return 0;
313 else if (dev->status != STATUS_STREAMING)
314 return -EAGAIN;
315
7d771ff0
JG
316 buf = kmalloc(dev->bulk_in_size, GFP_KERNEL);
317 if (!buf)
318 v4l2_err(&dev->v4l2_dev, "failed to allocate temporary buffer "
319 "for emptying the internal device buffer. "
320 "Next capture start will be slow\n");
321
9aba42ef
JG
322 dev->status = STATUS_SHUTTING_DOWN;
323 hdpvr_config_call(dev, CTRL_STOP_STREAMING_VALUE, 0x00);
48f98f75 324 mutex_unlock(&dev->io_mutex);
9aba42ef
JG
325
326 wake_up_interruptible(&dev->wait_buffer);
327 msleep(50);
328
329 flush_workqueue(dev->workqueue);
330
48f98f75 331 mutex_lock(&dev->io_mutex);
9aba42ef
JG
332 /* kill the still outstanding urbs */
333 hdpvr_cancel_queue(dev);
334
7d771ff0
JG
335 /* emptying the device buffer beforeshutting it down */
336 while (buf && ++c < 500 &&
337 !usb_bulk_msg(dev->udev,
338 usb_rcvbulkpipe(dev->udev,
339 dev->bulk_in_endpointAddr),
340 buf, dev->bulk_in_size, &actual_length,
341 BULK_URB_TIMEOUT)) {
7d771ff0
JG
342 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
343 "%2d: got %d bytes\n", c, actual_length);
344 }
345 kfree(buf);
346 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
347 "used %d urbs to empty device buffers\n", c-1);
348 msleep(10);
349
9aba42ef
JG
350 dev->status = STATUS_IDLE;
351
352 return 0;
353}
354
355
356/*=======================================================================*/
357/*
358 * video 4 linux 2 file operations
359 */
360
361static int hdpvr_open(struct file *file)
362{
363 struct hdpvr_device *dev;
364 struct hdpvr_fh *fh;
365 int retval = -ENOMEM;
366
367 dev = (struct hdpvr_device *)video_get_drvdata(video_devdata(file));
368 if (!dev) {
4202066c 369 pr_err("open failing with with ENODEV\n");
9aba42ef
JG
370 retval = -ENODEV;
371 goto err;
372 }
373
374 fh = kzalloc(sizeof(struct hdpvr_fh), GFP_KERNEL);
375 if (!fh) {
9ef77adf 376 v4l2_err(&dev->v4l2_dev, "Out of memory\n");
9aba42ef
JG
377 goto err;
378 }
379 /* lock the device to allow correctly handling errors
380 * in resumption */
381 mutex_lock(&dev->io_mutex);
382 dev->open_count++;
00c1e216 383 mutex_unlock(&dev->io_mutex);
9aba42ef
JG
384
385 fh->dev = dev;
386
387 /* save our object in the file's private structure */
388 file->private_data = fh;
389
390 retval = 0;
391err:
9aba42ef
JG
392 return retval;
393}
394
395static int hdpvr_release(struct file *file)
396{
abf84383 397 struct hdpvr_fh *fh = file->private_data;
9aba42ef
JG
398 struct hdpvr_device *dev = fh->dev;
399
400 if (!dev)
401 return -ENODEV;
402
403 mutex_lock(&dev->io_mutex);
404 if (!(--dev->open_count) && dev->status == STATUS_STREAMING)
405 hdpvr_stop_streaming(dev);
406
407 mutex_unlock(&dev->io_mutex);
408
409 return 0;
410}
411
412/*
413 * hdpvr_v4l2_read()
414 * will allocate buffers when called for the first time
415 */
416static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count,
417 loff_t *pos)
418{
419 struct hdpvr_fh *fh = file->private_data;
420 struct hdpvr_device *dev = fh->dev;
421 struct hdpvr_buffer *buf = NULL;
422 struct urb *urb;
423 unsigned int ret = 0;
424 int rem, cnt;
425
426 if (*pos)
427 return -ESPIPE;
428
429 if (!dev)
430 return -ENODEV;
431
432 mutex_lock(&dev->io_mutex);
433 if (dev->status == STATUS_IDLE) {
434 if (hdpvr_start_streaming(dev)) {
9ef77adf
JG
435 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
436 "start_streaming failed\n");
9aba42ef
JG
437 ret = -EIO;
438 msleep(200);
439 dev->status = STATUS_IDLE;
440 mutex_unlock(&dev->io_mutex);
441 goto err;
442 }
d211bfcb 443 print_buffer_status();
9aba42ef
JG
444 }
445 mutex_unlock(&dev->io_mutex);
446
447 /* wait for the first buffer */
448 if (!(file->f_flags & O_NONBLOCK)) {
449 if (wait_event_interruptible(dev->wait_data,
450 hdpvr_get_next_buffer(dev)))
451 return -ERESTARTSYS;
452 }
453
454 buf = hdpvr_get_next_buffer(dev);
455
456 while (count > 0 && buf) {
457
458 if (buf->status != BUFSTAT_READY &&
459 dev->status != STATUS_DISCONNECTED) {
460 /* return nonblocking */
461 if (file->f_flags & O_NONBLOCK) {
462 if (!ret)
463 ret = -EAGAIN;
464 goto err;
465 }
466
467 if (wait_event_interruptible(dev->wait_data,
468 buf->status == BUFSTAT_READY)) {
469 ret = -ERESTARTSYS;
470 goto err;
471 }
472 }
473
474 if (buf->status != BUFSTAT_READY)
475 break;
476
477 /* set remaining bytes to copy */
478 urb = buf->urb;
479 rem = urb->actual_length - buf->pos;
480 cnt = rem > count ? count : rem;
481
482 if (copy_to_user(buffer, urb->transfer_buffer + buf->pos,
483 cnt)) {
9ef77adf 484 v4l2_err(&dev->v4l2_dev, "read: copy_to_user failed\n");
9aba42ef
JG
485 if (!ret)
486 ret = -EFAULT;
487 goto err;
488 }
489
490 buf->pos += cnt;
491 count -= cnt;
492 buffer += cnt;
493 ret += cnt;
494
495 /* finished, take next buffer */
496 if (buf->pos == urb->actual_length) {
497 mutex_lock(&dev->io_mutex);
498 buf->pos = 0;
499 buf->status = BUFSTAT_AVAILABLE;
500
501 list_move_tail(&buf->buff_list, &dev->free_buff_list);
502
d211bfcb 503 print_buffer_status();
9aba42ef
JG
504
505 mutex_unlock(&dev->io_mutex);
506
507 wake_up_interruptible(&dev->wait_buffer);
508
509 buf = hdpvr_get_next_buffer(dev);
510 }
511 }
512err:
513 if (!ret && !buf)
514 ret = -EAGAIN;
515 return ret;
516}
517
518static unsigned int hdpvr_poll(struct file *filp, poll_table *wait)
519{
d2ff3ec8 520 struct hdpvr_buffer *buf = NULL;
abf84383 521 struct hdpvr_fh *fh = filp->private_data;
9aba42ef
JG
522 struct hdpvr_device *dev = fh->dev;
523 unsigned int mask = 0;
524
525 mutex_lock(&dev->io_mutex);
526
957b4aa9 527 if (!video_is_registered(dev->video_dev)) {
00c1e216 528 mutex_unlock(&dev->io_mutex);
9aba42ef 529 return -EIO;
00c1e216 530 }
9aba42ef
JG
531
532 if (dev->status == STATUS_IDLE) {
533 if (hdpvr_start_streaming(dev)) {
9ef77adf
JG
534 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
535 "start_streaming failed\n");
9aba42ef
JG
536 dev->status = STATUS_IDLE;
537 }
538
d211bfcb 539 print_buffer_status();
9aba42ef
JG
540 }
541 mutex_unlock(&dev->io_mutex);
542
d2ff3ec8
JG
543 buf = hdpvr_get_next_buffer(dev);
544 /* only wait if no data is available */
545 if (!buf || buf->status != BUFSTAT_READY) {
546 poll_wait(filp, &dev->wait_data, wait);
547 buf = hdpvr_get_next_buffer(dev);
9aba42ef 548 }
d2ff3ec8
JG
549 if (buf && buf->status == BUFSTAT_READY)
550 mask |= POLLIN | POLLRDNORM;
9aba42ef
JG
551
552 return mask;
553}
554
555
9aba42ef
JG
556static const struct v4l2_file_operations hdpvr_fops = {
557 .owner = THIS_MODULE,
558 .open = hdpvr_open,
559 .release = hdpvr_release,
560 .read = hdpvr_read,
561 .poll = hdpvr_poll,
76717b88 562 .unlocked_ioctl = video_ioctl2,
9aba42ef
JG
563};
564
565/*=======================================================================*/
566/*
567 * V4L2 ioctl handling
568 */
569
570static int vidioc_querycap(struct file *file, void *priv,
571 struct v4l2_capability *cap)
572{
573 struct hdpvr_device *dev = video_drvdata(file);
574
575 strcpy(cap->driver, "hdpvr");
fdd70c33 576 strcpy(cap->card, "Hauppauge HD PVR");
9aba42ef 577 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
9aba42ef
JG
578 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
579 V4L2_CAP_AUDIO |
580 V4L2_CAP_READWRITE;
581 return 0;
582}
583
584static int vidioc_s_std(struct file *file, void *private_data,
585 v4l2_std_id *std)
586{
587 struct hdpvr_fh *fh = file->private_data;
588 struct hdpvr_device *dev = fh->dev;
589 u8 std_type = 1;
590
591 if (*std & (V4L2_STD_NTSC | V4L2_STD_PAL_60))
592 std_type = 0;
593
594 return hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, std_type);
595}
596
597static const char *iname[] = {
598 [HDPVR_COMPONENT] = "Component",
599 [HDPVR_SVIDEO] = "S-Video",
600 [HDPVR_COMPOSITE] = "Composite",
601};
602
603static int vidioc_enum_input(struct file *file, void *priv,
604 struct v4l2_input *i)
605{
606 struct hdpvr_fh *fh = file->private_data;
607 struct hdpvr_device *dev = fh->dev;
608 unsigned int n;
609
610 n = i->index;
611 if (n >= HDPVR_VIDEO_INPUTS)
612 return -EINVAL;
613
614 i->type = V4L2_INPUT_TYPE_CAMERA;
615
616 strncpy(i->name, iname[n], sizeof(i->name) - 1);
617 i->name[sizeof(i->name) - 1] = '\0';
618
619 i->audioset = 1<<HDPVR_RCA_FRONT | 1<<HDPVR_RCA_BACK | 1<<HDPVR_SPDIF;
620
621 i->std = dev->video_dev->tvnorms;
622
623 return 0;
624}
625
626static int vidioc_s_input(struct file *file, void *private_data,
627 unsigned int index)
628{
629 struct hdpvr_fh *fh = file->private_data;
630 struct hdpvr_device *dev = fh->dev;
631 int retval;
632
633 if (index >= HDPVR_VIDEO_INPUTS)
634 return -EINVAL;
635
636 if (dev->status != STATUS_IDLE)
637 return -EAGAIN;
638
639 retval = hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE, index+1);
640 if (!retval)
641 dev->options.video_input = index;
642
643 return retval;
644}
645
646static int vidioc_g_input(struct file *file, void *private_data,
647 unsigned int *index)
648{
649 struct hdpvr_fh *fh = file->private_data;
650 struct hdpvr_device *dev = fh->dev;
651
652 *index = dev->options.video_input;
653 return 0;
654}
655
656
657static const char *audio_iname[] = {
658 [HDPVR_RCA_FRONT] = "RCA front",
659 [HDPVR_RCA_BACK] = "RCA back",
660 [HDPVR_SPDIF] = "SPDIF",
661};
662
663static int vidioc_enumaudio(struct file *file, void *priv,
664 struct v4l2_audio *audio)
665{
666 unsigned int n;
667
668 n = audio->index;
669 if (n >= HDPVR_AUDIO_INPUTS)
670 return -EINVAL;
671
672 audio->capability = V4L2_AUDCAP_STEREO;
673
674 strncpy(audio->name, audio_iname[n], sizeof(audio->name) - 1);
675 audio->name[sizeof(audio->name) - 1] = '\0';
676
677 return 0;
678}
679
680static int vidioc_s_audio(struct file *file, void *private_data,
0e8025b9 681 const struct v4l2_audio *audio)
9aba42ef
JG
682{
683 struct hdpvr_fh *fh = file->private_data;
684 struct hdpvr_device *dev = fh->dev;
685 int retval;
686
687 if (audio->index >= HDPVR_AUDIO_INPUTS)
688 return -EINVAL;
689
690 if (dev->status != STATUS_IDLE)
691 return -EAGAIN;
692
693 retval = hdpvr_set_audio(dev, audio->index+1, dev->options.audio_codec);
694 if (!retval)
695 dev->options.audio_input = audio->index;
696
697 return retval;
698}
699
700static int vidioc_g_audio(struct file *file, void *private_data,
701 struct v4l2_audio *audio)
702{
703 struct hdpvr_fh *fh = file->private_data;
704 struct hdpvr_device *dev = fh->dev;
705
706 audio->index = dev->options.audio_input;
707 audio->capability = V4L2_AUDCAP_STEREO;
708 strncpy(audio->name, audio_iname[audio->index], sizeof(audio->name));
709 audio->name[sizeof(audio->name) - 1] = '\0';
710 return 0;
711}
712
713static const s32 supported_v4l2_ctrls[] = {
714 V4L2_CID_BRIGHTNESS,
715 V4L2_CID_CONTRAST,
716 V4L2_CID_SATURATION,
717 V4L2_CID_HUE,
718 V4L2_CID_SHARPNESS,
719 V4L2_CID_MPEG_AUDIO_ENCODING,
720 V4L2_CID_MPEG_VIDEO_ENCODING,
721 V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
722 V4L2_CID_MPEG_VIDEO_BITRATE,
723 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
724};
725
726static int fill_queryctrl(struct hdpvr_options *opt, struct v4l2_queryctrl *qc,
fda27874 727 int ac3, int fw_ver)
9aba42ef
JG
728{
729 int err;
730
fda27874
TR
731 if (fw_ver > 0x15) {
732 switch (qc->id) {
733 case V4L2_CID_BRIGHTNESS:
734 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
735 case V4L2_CID_CONTRAST:
736 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x40);
737 case V4L2_CID_SATURATION:
738 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x40);
739 case V4L2_CID_HUE:
740 return v4l2_ctrl_query_fill(qc, 0x0, 0x1e, 1, 0xf);
741 case V4L2_CID_SHARPNESS:
742 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
743 }
744 } else {
745 switch (qc->id) {
746 case V4L2_CID_BRIGHTNESS:
747 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x86);
748 case V4L2_CID_CONTRAST:
749 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
750 case V4L2_CID_SATURATION:
751 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
752 case V4L2_CID_HUE:
753 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
754 case V4L2_CID_SHARPNESS:
755 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
756 }
757 }
758
9aba42ef 759 switch (qc->id) {
9aba42ef
JG
760 case V4L2_CID_MPEG_AUDIO_ENCODING:
761 return v4l2_ctrl_query_fill(
762 qc, V4L2_MPEG_AUDIO_ENCODING_AAC,
763 ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3
764 : V4L2_MPEG_AUDIO_ENCODING_AAC,
765 1, V4L2_MPEG_AUDIO_ENCODING_AAC);
766 case V4L2_CID_MPEG_VIDEO_ENCODING:
767 return v4l2_ctrl_query_fill(
768 qc, V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC,
769 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1,
770 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC);
771
772/* case V4L2_CID_MPEG_VIDEO_? maybe keyframe interval: */
773/* return v4l2_ctrl_query_fill(qc, 0, 128, 128, 0); */
774 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
775 return v4l2_ctrl_query_fill(
776 qc, V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
777 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
778 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR);
779
780 case V4L2_CID_MPEG_VIDEO_BITRATE:
781 return v4l2_ctrl_query_fill(qc, 1000000, 13500000, 100000,
782 6500000);
783 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
784 err = v4l2_ctrl_query_fill(qc, 1100000, 20200000, 100000,
785 9000000);
786 if (!err && opt->bitrate_mode == HDPVR_CONSTANT)
787 qc->flags |= V4L2_CTRL_FLAG_INACTIVE;
788 return err;
789 default:
790 return -EINVAL;
791 }
792}
793
794static int vidioc_queryctrl(struct file *file, void *private_data,
795 struct v4l2_queryctrl *qc)
796{
797 struct hdpvr_fh *fh = file->private_data;
798 struct hdpvr_device *dev = fh->dev;
799 int i, next;
800 u32 id = qc->id;
801
802 memset(qc, 0, sizeof(*qc));
803
804 next = !!(id & V4L2_CTRL_FLAG_NEXT_CTRL);
805 qc->id = id & ~V4L2_CTRL_FLAG_NEXT_CTRL;
806
807 for (i = 0; i < ARRAY_SIZE(supported_v4l2_ctrls); i++) {
808 if (next) {
809 if (qc->id < supported_v4l2_ctrls[i])
810 qc->id = supported_v4l2_ctrls[i];
811 else
812 continue;
813 }
814
815 if (qc->id == supported_v4l2_ctrls[i])
816 return fill_queryctrl(&dev->options, qc,
fda27874
TR
817 dev->flags & HDPVR_FLAG_AC3_CAP,
818 dev->fw_ver);
9aba42ef
JG
819
820 if (qc->id < supported_v4l2_ctrls[i])
821 break;
822 }
823
824 return -EINVAL;
825}
826
827static int vidioc_g_ctrl(struct file *file, void *private_data,
828 struct v4l2_control *ctrl)
829{
830 struct hdpvr_fh *fh = file->private_data;
831 struct hdpvr_device *dev = fh->dev;
832
833 switch (ctrl->id) {
834 case V4L2_CID_BRIGHTNESS:
835 ctrl->value = dev->options.brightness;
836 break;
837 case V4L2_CID_CONTRAST:
838 ctrl->value = dev->options.contrast;
839 break;
840 case V4L2_CID_SATURATION:
841 ctrl->value = dev->options.saturation;
842 break;
843 case V4L2_CID_HUE:
844 ctrl->value = dev->options.hue;
845 break;
846 case V4L2_CID_SHARPNESS:
847 ctrl->value = dev->options.sharpness;
848 break;
849 default:
850 return -EINVAL;
851 }
852 return 0;
853}
854
855static int vidioc_s_ctrl(struct file *file, void *private_data,
856 struct v4l2_control *ctrl)
857{
858 struct hdpvr_fh *fh = file->private_data;
859 struct hdpvr_device *dev = fh->dev;
860 int retval;
861
862 switch (ctrl->id) {
863 case V4L2_CID_BRIGHTNESS:
864 retval = hdpvr_config_call(dev, CTRL_BRIGHTNESS, ctrl->value);
865 if (!retval)
866 dev->options.brightness = ctrl->value;
867 break;
868 case V4L2_CID_CONTRAST:
869 retval = hdpvr_config_call(dev, CTRL_CONTRAST, ctrl->value);
870 if (!retval)
871 dev->options.contrast = ctrl->value;
872 break;
873 case V4L2_CID_SATURATION:
874 retval = hdpvr_config_call(dev, CTRL_SATURATION, ctrl->value);
875 if (!retval)
876 dev->options.saturation = ctrl->value;
877 break;
878 case V4L2_CID_HUE:
879 retval = hdpvr_config_call(dev, CTRL_HUE, ctrl->value);
880 if (!retval)
881 dev->options.hue = ctrl->value;
882 break;
883 case V4L2_CID_SHARPNESS:
884 retval = hdpvr_config_call(dev, CTRL_SHARPNESS, ctrl->value);
885 if (!retval)
886 dev->options.sharpness = ctrl->value;
887 break;
888 default:
889 return -EINVAL;
890 }
891
892 return retval;
893}
894
895
896static int hdpvr_get_ctrl(struct hdpvr_options *opt,
897 struct v4l2_ext_control *ctrl)
898{
899 switch (ctrl->id) {
900 case V4L2_CID_MPEG_AUDIO_ENCODING:
901 ctrl->value = opt->audio_codec;
902 break;
903 case V4L2_CID_MPEG_VIDEO_ENCODING:
904 ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC;
905 break;
906/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
907/* ctrl->value = (opt->gop_mode & 0x2) ? 0 : 128; */
908/* break; */
909 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
910 ctrl->value = opt->bitrate_mode == HDPVR_CONSTANT
911 ? V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
912 : V4L2_MPEG_VIDEO_BITRATE_MODE_VBR;
913 break;
914 case V4L2_CID_MPEG_VIDEO_BITRATE:
915 ctrl->value = opt->bitrate * 100000;
916 break;
917 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
918 ctrl->value = opt->peak_bitrate * 100000;
919 break;
920 case V4L2_CID_MPEG_STREAM_TYPE:
921 ctrl->value = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
922 break;
923 default:
924 return -EINVAL;
925 }
926 return 0;
927}
928
929static int vidioc_g_ext_ctrls(struct file *file, void *priv,
930 struct v4l2_ext_controls *ctrls)
931{
932 struct hdpvr_fh *fh = file->private_data;
933 struct hdpvr_device *dev = fh->dev;
934 int i, err = 0;
935
936 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
937 for (i = 0; i < ctrls->count; i++) {
938 struct v4l2_ext_control *ctrl = ctrls->controls + i;
939
940 err = hdpvr_get_ctrl(&dev->options, ctrl);
941 if (err) {
942 ctrls->error_idx = i;
943 break;
944 }
945 }
946 return err;
947
948 }
949
950 return -EINVAL;
951}
952
953
954static int hdpvr_try_ctrl(struct v4l2_ext_control *ctrl, int ac3)
955{
956 int ret = -EINVAL;
957
958 switch (ctrl->id) {
959 case V4L2_CID_MPEG_AUDIO_ENCODING:
960 if (ctrl->value == V4L2_MPEG_AUDIO_ENCODING_AAC ||
961 (ac3 && ctrl->value == V4L2_MPEG_AUDIO_ENCODING_AC3))
962 ret = 0;
963 break;
964 case V4L2_CID_MPEG_VIDEO_ENCODING:
965 if (ctrl->value == V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC)
966 ret = 0;
967 break;
968/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
969/* if (ctrl->value == 0 || ctrl->value == 128) */
970/* ret = 0; */
971/* break; */
972 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
973 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR ||
974 ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR)
975 ret = 0;
976 break;
977 case V4L2_CID_MPEG_VIDEO_BITRATE:
978 {
979 uint bitrate = ctrl->value / 100000;
980 if (bitrate >= 10 && bitrate <= 135)
981 ret = 0;
982 break;
983 }
984 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
985 {
986 uint peak_bitrate = ctrl->value / 100000;
987 if (peak_bitrate >= 10 && peak_bitrate <= 202)
988 ret = 0;
989 break;
990 }
991 case V4L2_CID_MPEG_STREAM_TYPE:
992 if (ctrl->value == V4L2_MPEG_STREAM_TYPE_MPEG2_TS)
993 ret = 0;
994 break;
995 default:
996 return -EINVAL;
997 }
e92ba283 998 return ret;
9aba42ef
JG
999}
1000
1001static int vidioc_try_ext_ctrls(struct file *file, void *priv,
1002 struct v4l2_ext_controls *ctrls)
1003{
1004 struct hdpvr_fh *fh = file->private_data;
1005 struct hdpvr_device *dev = fh->dev;
1006 int i, err = 0;
1007
1008 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
1009 for (i = 0; i < ctrls->count; i++) {
1010 struct v4l2_ext_control *ctrl = ctrls->controls + i;
1011
1012 err = hdpvr_try_ctrl(ctrl,
1013 dev->flags & HDPVR_FLAG_AC3_CAP);
1014 if (err) {
1015 ctrls->error_idx = i;
1016 break;
1017 }
1018 }
1019 return err;
1020 }
1021
1022 return -EINVAL;
1023}
1024
1025
1026static int hdpvr_set_ctrl(struct hdpvr_device *dev,
1027 struct v4l2_ext_control *ctrl)
1028{
1029 struct hdpvr_options *opt = &dev->options;
1030 int ret = 0;
1031
1032 switch (ctrl->id) {
1033 case V4L2_CID_MPEG_AUDIO_ENCODING:
1034 if (dev->flags & HDPVR_FLAG_AC3_CAP) {
1035 opt->audio_codec = ctrl->value;
1036 ret = hdpvr_set_audio(dev, opt->audio_input,
1037 opt->audio_codec);
1038 }
1039 break;
1040 case V4L2_CID_MPEG_VIDEO_ENCODING:
1041 break;
1042/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
1043/* if (ctrl->value == 0 && !(opt->gop_mode & 0x2)) { */
1044/* opt->gop_mode |= 0x2; */
1045/* hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, */
1046/* opt->gop_mode); */
1047/* } */
1048/* if (ctrl->value == 128 && opt->gop_mode & 0x2) { */
1049/* opt->gop_mode &= ~0x2; */
1050/* hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, */
1051/* opt->gop_mode); */
1052/* } */
1053/* break; */
1054 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1055 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR &&
1056 opt->bitrate_mode != HDPVR_CONSTANT) {
1057 opt->bitrate_mode = HDPVR_CONSTANT;
1058 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE,
1059 opt->bitrate_mode);
1060 }
1061 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR &&
1062 opt->bitrate_mode == HDPVR_CONSTANT) {
1063 opt->bitrate_mode = HDPVR_VARIABLE_AVERAGE;
1064 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE,
1065 opt->bitrate_mode);
1066 }
1067 break;
1068 case V4L2_CID_MPEG_VIDEO_BITRATE: {
1069 uint bitrate = ctrl->value / 100000;
1070
1071 opt->bitrate = bitrate;
1072 if (bitrate >= opt->peak_bitrate)
1073 opt->peak_bitrate = bitrate+1;
1074
1075 hdpvr_set_bitrate(dev);
1076 break;
1077 }
1078 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: {
1079 uint peak_bitrate = ctrl->value / 100000;
1080
1081 if (opt->bitrate_mode == HDPVR_CONSTANT)
1082 break;
1083
1084 if (opt->bitrate < peak_bitrate) {
1085 opt->peak_bitrate = peak_bitrate;
1086 hdpvr_set_bitrate(dev);
1087 } else
1088 ret = -EINVAL;
1089 break;
1090 }
1091 case V4L2_CID_MPEG_STREAM_TYPE:
1092 break;
1093 default:
1094 return -EINVAL;
1095 }
1096 return ret;
1097}
1098
1099static int vidioc_s_ext_ctrls(struct file *file, void *priv,
1100 struct v4l2_ext_controls *ctrls)
1101{
1102 struct hdpvr_fh *fh = file->private_data;
1103 struct hdpvr_device *dev = fh->dev;
1104 int i, err = 0;
1105
1106 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
1107 for (i = 0; i < ctrls->count; i++) {
1108 struct v4l2_ext_control *ctrl = ctrls->controls + i;
1109
1110 err = hdpvr_try_ctrl(ctrl,
1111 dev->flags & HDPVR_FLAG_AC3_CAP);
1112 if (err) {
1113 ctrls->error_idx = i;
1114 break;
1115 }
1116 err = hdpvr_set_ctrl(dev, ctrl);
1117 if (err) {
1118 ctrls->error_idx = i;
1119 break;
1120 }
1121 }
1122 return err;
1123
1124 }
1125
1126 return -EINVAL;
1127}
1128
1129static int vidioc_enum_fmt_vid_cap(struct file *file, void *private_data,
1130 struct v4l2_fmtdesc *f)
1131{
1132
1133 if (f->index != 0 || f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1134 return -EINVAL;
1135
1136 f->flags = V4L2_FMT_FLAG_COMPRESSED;
1137 strncpy(f->description, "MPEG2-TS with AVC/AAC streams", 32);
1138 f->pixelformat = V4L2_PIX_FMT_MPEG;
1139
1140 return 0;
1141}
1142
1143static int vidioc_g_fmt_vid_cap(struct file *file, void *private_data,
1144 struct v4l2_format *f)
1145{
1146 struct hdpvr_fh *fh = file->private_data;
1147 struct hdpvr_device *dev = fh->dev;
1148 struct hdpvr_video_info *vid_info;
1149
1150 if (!dev)
1151 return -ENODEV;
1152
1153 vid_info = get_video_info(dev);
1154 if (!vid_info)
1155 return -EFAULT;
1156
1157 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1158 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1159 f->fmt.pix.width = vid_info->width;
1160 f->fmt.pix.height = vid_info->height;
1161 f->fmt.pix.sizeimage = dev->bulk_in_size;
1162 f->fmt.pix.colorspace = 0;
1163 f->fmt.pix.bytesperline = 0;
1164 f->fmt.pix.field = V4L2_FIELD_ANY;
1165
1166 kfree(vid_info);
1167 return 0;
1168}
1169
76717b88
JG
1170static int vidioc_encoder_cmd(struct file *filp, void *priv,
1171 struct v4l2_encoder_cmd *a)
1172{
1173 struct hdpvr_fh *fh = filp->private_data;
1174 struct hdpvr_device *dev = fh->dev;
1175 int res;
1176
1177 mutex_lock(&dev->io_mutex);
1178
1179 memset(&a->raw, 0, sizeof(a->raw));
1180 switch (a->cmd) {
1181 case V4L2_ENC_CMD_START:
1182 a->flags = 0;
1183 res = hdpvr_start_streaming(dev);
1184 break;
1185 case V4L2_ENC_CMD_STOP:
1186 res = hdpvr_stop_streaming(dev);
1187 break;
1188 default:
9ef77adf 1189 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
76717b88 1190 "Unsupported encoder cmd %d\n", a->cmd);
48f98f75 1191 res = -EINVAL;
76717b88
JG
1192 }
1193 mutex_unlock(&dev->io_mutex);
1194 return res;
1195}
1196
1197static int vidioc_try_encoder_cmd(struct file *filp, void *priv,
1198 struct v4l2_encoder_cmd *a)
1199{
1200 switch (a->cmd) {
1201 case V4L2_ENC_CMD_START:
1202 case V4L2_ENC_CMD_STOP:
1203 return 0;
1204 default:
1205 return -EINVAL;
1206 }
1207}
9aba42ef
JG
1208
1209static const struct v4l2_ioctl_ops hdpvr_ioctl_ops = {
1210 .vidioc_querycap = vidioc_querycap,
1211 .vidioc_s_std = vidioc_s_std,
1212 .vidioc_enum_input = vidioc_enum_input,
1213 .vidioc_g_input = vidioc_g_input,
1214 .vidioc_s_input = vidioc_s_input,
1215 .vidioc_enumaudio = vidioc_enumaudio,
1216 .vidioc_g_audio = vidioc_g_audio,
1217 .vidioc_s_audio = vidioc_s_audio,
1218 .vidioc_queryctrl = vidioc_queryctrl,
1219 .vidioc_g_ctrl = vidioc_g_ctrl,
1220 .vidioc_s_ctrl = vidioc_s_ctrl,
1221 .vidioc_g_ext_ctrls = vidioc_g_ext_ctrls,
1222 .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls,
1223 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls,
1224 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1225 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
76717b88
JG
1226 .vidioc_encoder_cmd = vidioc_encoder_cmd,
1227 .vidioc_try_encoder_cmd = vidioc_try_encoder_cmd,
9aba42ef
JG
1228};
1229
1230static void hdpvr_device_release(struct video_device *vdev)
1231{
1232 struct hdpvr_device *dev = video_get_drvdata(vdev);
1233
1234 hdpvr_delete(dev);
f2b305cd
HV
1235 mutex_lock(&dev->io_mutex);
1236 destroy_workqueue(dev->workqueue);
1237 mutex_unlock(&dev->io_mutex);
1238
1239 v4l2_device_unregister(&dev->v4l2_dev);
1240
1241 /* deregister I2C adapter */
54d80904 1242#if IS_ENABLED(CONFIG_I2C)
f2b305cd 1243 mutex_lock(&dev->i2c_mutex);
324b04ba 1244 i2c_del_adapter(&dev->i2c_adapter);
f2b305cd
HV
1245 mutex_unlock(&dev->i2c_mutex);
1246#endif /* CONFIG_I2C */
1247
1248 kfree(dev->usbc_buf);
1249 kfree(dev);
9aba42ef
JG
1250}
1251
1252static const struct video_device hdpvr_video_template = {
1253/* .type = VFL_TYPE_GRABBER, */
1254/* .type2 = VID_TYPE_CAPTURE | VID_TYPE_MPEG_ENCODER, */
1255 .fops = &hdpvr_fops,
1256 .release = hdpvr_device_release,
1257 .ioctl_ops = &hdpvr_ioctl_ops,
1258 .tvnorms =
1259 V4L2_STD_NTSC | V4L2_STD_SECAM | V4L2_STD_PAL_B |
1260 V4L2_STD_PAL_G | V4L2_STD_PAL_H | V4L2_STD_PAL_I |
1261 V4L2_STD_PAL_D | V4L2_STD_PAL_M | V4L2_STD_PAL_N |
1262 V4L2_STD_PAL_60,
99362e1e
HV
1263 .current_norm = V4L2_STD_NTSC | V4L2_STD_PAL_M |
1264 V4L2_STD_PAL_60,
9aba42ef
JG
1265};
1266
a50ab291
JG
1267int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent,
1268 int devnum)
9aba42ef
JG
1269{
1270 /* setup and register video device */
1271 dev->video_dev = video_device_alloc();
1272 if (!dev->video_dev) {
9ef77adf 1273 v4l2_err(&dev->v4l2_dev, "video_device_alloc() failed\n");
9aba42ef
JG
1274 goto error;
1275 }
1276
1277 *(dev->video_dev) = hdpvr_video_template;
1278 strcpy(dev->video_dev->name, "Hauppauge HD PVR");
a50ab291 1279 dev->video_dev->parent = parent;
9aba42ef
JG
1280 video_set_drvdata(dev->video_dev, dev);
1281
1282 if (video_register_device(dev->video_dev, VFL_TYPE_GRABBER, devnum)) {
9ef77adf 1283 v4l2_err(&dev->v4l2_dev, "video_device registration failed\n");
9aba42ef
JG
1284 goto error;
1285 }
1286
1287 return 0;
1288error:
1289 return -ENOMEM;
1290}
This page took 0.405563 seconds and 5 git commands to generate.