]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/media/usb/stk1160/stk1160-v4l.c
Merge tag 'mac80211-next-for-davem-2015-08-14' into next
[karo-tx-linux.git] / drivers / media / usb / stk1160 / stk1160-v4l.c
1 /*
2  * STK1160 driver
3  *
4  * Copyright (C) 2012 Ezequiel Garcia
5  * <elezegarcia--a.t--gmail.com>
6  *
7  * Based on Easycap driver by R.M. Thomas
8  *      Copyright (C) 2010 R.M. Thomas
9  *      <rmthomas--a.t--sciolus.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  */
22
23 #include <linux/module.h>
24 #include <linux/usb.h>
25 #include <linux/mm.h>
26 #include <linux/slab.h>
27
28 #include <linux/videodev2.h>
29 #include <media/v4l2-device.h>
30 #include <media/v4l2-common.h>
31 #include <media/v4l2-ioctl.h>
32 #include <media/v4l2-fh.h>
33 #include <media/v4l2-event.h>
34 #include <media/videobuf2-vmalloc.h>
35
36 #include <media/saa7115.h>
37
38 #include "stk1160.h"
39 #include "stk1160-reg.h"
40
41 static bool keep_buffers;
42 module_param(keep_buffers, bool, 0644);
43 MODULE_PARM_DESC(keep_buffers, "don't release buffers upon stop streaming");
44
45 /* supported video standards */
46 static struct stk1160_fmt format[] = {
47         {
48                 .name     = "16 bpp YUY2, 4:2:2, packed",
49                 .fourcc   = V4L2_PIX_FMT_UYVY,
50                 .depth    = 16,
51         }
52 };
53
54 static void stk1160_set_std(struct stk1160 *dev)
55 {
56         int i;
57
58         static struct regval std525[] = {
59
60                 /* 720x480 */
61
62                 /* Frame start */
63                 {STK116_CFSPO_STX_L, 0x0000},
64                 {STK116_CFSPO_STX_H, 0x0000},
65                 {STK116_CFSPO_STY_L, 0x0003},
66                 {STK116_CFSPO_STY_H, 0x0000},
67
68                 /* Frame end */
69                 {STK116_CFEPO_ENX_L, 0x05a0},
70                 {STK116_CFEPO_ENX_H, 0x0005},
71                 {STK116_CFEPO_ENY_L, 0x00f3},
72                 {STK116_CFEPO_ENY_H, 0x0000},
73
74                 {0xffff, 0xffff}
75         };
76
77         static struct regval std625[] = {
78
79                 /* 720x576 */
80
81                 /* TODO: Each line of frame has some junk at the end */
82                 /* Frame start */
83                 {STK116_CFSPO,   0x0000},
84                 {STK116_CFSPO+1, 0x0000},
85                 {STK116_CFSPO+2, 0x0001},
86                 {STK116_CFSPO+3, 0x0000},
87
88                 /* Frame end */
89                 {STK116_CFEPO,   0x05a0},
90                 {STK116_CFEPO+1, 0x0005},
91                 {STK116_CFEPO+2, 0x0121},
92                 {STK116_CFEPO+3, 0x0001},
93
94                 {0xffff, 0xffff}
95         };
96
97         if (dev->norm & V4L2_STD_525_60) {
98                 stk1160_dbg("registers to NTSC like standard\n");
99                 for (i = 0; std525[i].reg != 0xffff; i++)
100                         stk1160_write_reg(dev, std525[i].reg, std525[i].val);
101         } else {
102                 stk1160_dbg("registers to PAL like standard\n");
103                 for (i = 0; std625[i].reg != 0xffff; i++)
104                         stk1160_write_reg(dev, std625[i].reg, std625[i].val);
105         }
106
107 }
108
109 /*
110  * Set a new alternate setting.
111  * Returns true is dev->max_pkt_size has changed, false otherwise.
112  */
113 static bool stk1160_set_alternate(struct stk1160 *dev)
114 {
115         int i, prev_alt = dev->alt;
116         unsigned int min_pkt_size;
117         bool new_pkt_size;
118
119         /*
120          * If we don't set right alternate,
121          * then we will get a green screen with junk.
122          */
123         min_pkt_size = STK1160_MIN_PKT_SIZE;
124
125         for (i = 0; i < dev->num_alt; i++) {
126                 /* stop when the selected alt setting offers enough bandwidth */
127                 if (dev->alt_max_pkt_size[i] >= min_pkt_size) {
128                         dev->alt = i;
129                         break;
130                 /*
131                  * otherwise make sure that we end up with the maximum bandwidth
132                  * because the min_pkt_size equation might be wrong...
133                  */
134                 } else if (dev->alt_max_pkt_size[i] >
135                            dev->alt_max_pkt_size[dev->alt])
136                         dev->alt = i;
137         }
138
139         stk1160_info("setting alternate %d\n", dev->alt);
140
141         if (dev->alt != prev_alt) {
142                 stk1160_dbg("minimum isoc packet size: %u (alt=%d)\n",
143                                 min_pkt_size, dev->alt);
144                 stk1160_dbg("setting alt %d with wMaxPacketSize=%u\n",
145                                dev->alt, dev->alt_max_pkt_size[dev->alt]);
146                 usb_set_interface(dev->udev, 0, dev->alt);
147         }
148
149         new_pkt_size = dev->max_pkt_size != dev->alt_max_pkt_size[dev->alt];
150         dev->max_pkt_size = dev->alt_max_pkt_size[dev->alt];
151
152         return new_pkt_size;
153 }
154
155 static int stk1160_start_streaming(struct stk1160 *dev)
156 {
157         bool new_pkt_size;
158         int rc = 0;
159         int i;
160
161         /* Check device presence */
162         if (!dev->udev)
163                 return -ENODEV;
164
165         if (mutex_lock_interruptible(&dev->v4l_lock))
166                 return -ERESTARTSYS;
167         /*
168          * For some reason it is mandatory to set alternate *first*
169          * and only *then* initialize isoc urbs.
170          * Someone please explain me why ;)
171          */
172         new_pkt_size = stk1160_set_alternate(dev);
173
174         /*
175          * We (re)allocate isoc urbs if:
176          * there is no allocated isoc urbs, OR
177          * a new dev->max_pkt_size is detected
178          */
179         if (!dev->isoc_ctl.num_bufs || new_pkt_size) {
180                 rc = stk1160_alloc_isoc(dev);
181                 if (rc < 0)
182                         goto out_stop_hw;
183         }
184
185         /* submit urbs and enables IRQ */
186         for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
187                 rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_KERNEL);
188                 if (rc) {
189                         stk1160_err("cannot submit urb[%d] (%d)\n", i, rc);
190                         goto out_uninit;
191                 }
192         }
193
194         /* Start saa711x */
195         v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1);
196
197         /* Start stk1160 */
198         stk1160_write_reg(dev, STK1160_DCTRL, 0xb3);
199         stk1160_write_reg(dev, STK1160_DCTRL+3, 0x00);
200
201         stk1160_dbg("streaming started\n");
202
203         mutex_unlock(&dev->v4l_lock);
204
205         return 0;
206
207 out_uninit:
208         stk1160_uninit_isoc(dev);
209 out_stop_hw:
210         usb_set_interface(dev->udev, 0, 0);
211         stk1160_clear_queue(dev);
212
213         mutex_unlock(&dev->v4l_lock);
214
215         return rc;
216 }
217
218 /* Must be called with v4l_lock hold */
219 static void stk1160_stop_hw(struct stk1160 *dev)
220 {
221         /* If the device is not physically present, there is nothing to do */
222         if (!dev->udev)
223                 return;
224
225         /* set alternate 0 */
226         dev->alt = 0;
227         stk1160_info("setting alternate %d\n", dev->alt);
228         usb_set_interface(dev->udev, 0, 0);
229
230         /* Stop stk1160 */
231         stk1160_write_reg(dev, STK1160_DCTRL, 0x00);
232         stk1160_write_reg(dev, STK1160_DCTRL+3, 0x00);
233
234         /* Stop saa711x */
235         v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
236 }
237
238 static int stk1160_stop_streaming(struct stk1160 *dev)
239 {
240         if (mutex_lock_interruptible(&dev->v4l_lock))
241                 return -ERESTARTSYS;
242
243         /*
244          * Once URBs are cancelled, the URB complete handler
245          * won't be running. This is required to safely release the
246          * current buffer (dev->isoc_ctl.buf).
247          */
248         stk1160_cancel_isoc(dev);
249
250         /*
251          * It is possible to keep buffers around using a module parameter.
252          * This is intended to avoid memory fragmentation.
253          */
254         if (!keep_buffers)
255                 stk1160_free_isoc(dev);
256
257         stk1160_stop_hw(dev);
258
259         stk1160_clear_queue(dev);
260
261         stk1160_dbg("streaming stopped\n");
262
263         mutex_unlock(&dev->v4l_lock);
264
265         return 0;
266 }
267
268 static struct v4l2_file_operations stk1160_fops = {
269         .owner = THIS_MODULE,
270         .open = v4l2_fh_open,
271         .release = vb2_fop_release,
272         .read = vb2_fop_read,
273         .poll = vb2_fop_poll,
274         .mmap = vb2_fop_mmap,
275         .unlocked_ioctl = video_ioctl2,
276 };
277
278 /*
279  * vidioc ioctls
280  */
281 static int vidioc_querycap(struct file *file,
282                 void *priv, struct v4l2_capability *cap)
283 {
284         struct stk1160 *dev = video_drvdata(file);
285
286         strcpy(cap->driver, "stk1160");
287         strcpy(cap->card, "stk1160");
288         usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
289         cap->device_caps =
290                 V4L2_CAP_VIDEO_CAPTURE |
291                 V4L2_CAP_STREAMING |
292                 V4L2_CAP_READWRITE;
293         cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
294         return 0;
295 }
296
297 static int vidioc_enum_fmt_vid_cap(struct file *file, void  *priv,
298                 struct v4l2_fmtdesc *f)
299 {
300         if (f->index != 0)
301                 return -EINVAL;
302
303         strlcpy(f->description, format[f->index].name, sizeof(f->description));
304         f->pixelformat = format[f->index].fourcc;
305         return 0;
306 }
307
308 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
309                                         struct v4l2_format *f)
310 {
311         struct stk1160 *dev = video_drvdata(file);
312
313         f->fmt.pix.width = dev->width;
314         f->fmt.pix.height = dev->height;
315         f->fmt.pix.field = V4L2_FIELD_INTERLACED;
316         f->fmt.pix.pixelformat = dev->fmt->fourcc;
317         f->fmt.pix.bytesperline = dev->width * 2;
318         f->fmt.pix.sizeimage = dev->height * f->fmt.pix.bytesperline;
319         f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
320
321         return 0;
322 }
323
324 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
325                         struct v4l2_format *f)
326 {
327         struct stk1160 *dev = video_drvdata(file);
328
329         /*
330          * User can't choose size at his own will,
331          * so we just return him the current size chosen
332          * at standard selection.
333          * TODO: Implement frame scaling?
334          */
335
336         f->fmt.pix.pixelformat = dev->fmt->fourcc;
337         f->fmt.pix.width = dev->width;
338         f->fmt.pix.height = dev->height;
339         f->fmt.pix.field = V4L2_FIELD_INTERLACED;
340         f->fmt.pix.bytesperline = dev->width * 2;
341         f->fmt.pix.sizeimage = dev->height * f->fmt.pix.bytesperline;
342         f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
343
344         return 0;
345 }
346
347 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
348                                         struct v4l2_format *f)
349 {
350         struct stk1160 *dev = video_drvdata(file);
351         struct vb2_queue *q = &dev->vb_vidq;
352
353         if (vb2_is_busy(q))
354                 return -EBUSY;
355
356         vidioc_try_fmt_vid_cap(file, priv, f);
357
358         /* We don't support any format changes */
359
360         return 0;
361 }
362
363 static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *norm)
364 {
365         struct stk1160 *dev = video_drvdata(file);
366         v4l2_device_call_all(&dev->v4l2_dev, 0, video, querystd, norm);
367         return 0;
368 }
369
370 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
371 {
372         struct stk1160 *dev = video_drvdata(file);
373
374         *norm = dev->norm;
375         return 0;
376 }
377
378 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
379 {
380         struct stk1160 *dev = video_drvdata(file);
381         struct vb2_queue *q = &dev->vb_vidq;
382
383         if (dev->norm == norm)
384                 return 0;
385
386         if (vb2_is_busy(q))
387                 return -EBUSY;
388
389         /* Check device presence */
390         if (!dev->udev)
391                 return -ENODEV;
392
393         /* We need to set this now, before we call stk1160_set_std */
394         dev->norm = norm;
395
396         /* This is taken from saa7115 video decoder */
397         if (dev->norm & V4L2_STD_525_60) {
398                 dev->width = 720;
399                 dev->height = 480;
400         } else if (dev->norm & V4L2_STD_625_50) {
401                 dev->width = 720;
402                 dev->height = 576;
403         } else {
404                 stk1160_err("invalid standard\n");
405                 return -EINVAL;
406         }
407
408         stk1160_set_std(dev);
409
410         v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_std,
411                         dev->norm);
412
413         return 0;
414 }
415
416
417 static int vidioc_enum_input(struct file *file, void *priv,
418                                 struct v4l2_input *i)
419 {
420         struct stk1160 *dev = video_drvdata(file);
421
422         if (i->index > STK1160_MAX_INPUT)
423                 return -EINVAL;
424
425         /* S-Video special handling */
426         if (i->index == STK1160_SVIDEO_INPUT)
427                 sprintf(i->name, "S-Video");
428         else
429                 sprintf(i->name, "Composite%d", i->index);
430
431         i->type = V4L2_INPUT_TYPE_CAMERA;
432         i->std = dev->vdev.tvnorms;
433         return 0;
434 }
435
436 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
437 {
438         struct stk1160 *dev = video_drvdata(file);
439         *i = dev->ctl_input;
440         return 0;
441 }
442
443 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
444 {
445         struct stk1160 *dev = video_drvdata(file);
446
447         if (i > STK1160_MAX_INPUT)
448                 return -EINVAL;
449
450         dev->ctl_input = i;
451
452         stk1160_select_input(dev);
453
454         return 0;
455 }
456
457 #ifdef CONFIG_VIDEO_ADV_DEBUG
458 static int vidioc_g_register(struct file *file, void *priv,
459                              struct v4l2_dbg_register *reg)
460 {
461         struct stk1160 *dev = video_drvdata(file);
462         int rc;
463         u8 val;
464
465         /* Match host */
466         rc = stk1160_read_reg(dev, reg->reg, &val);
467         reg->val = val;
468         reg->size = 1;
469
470         return rc;
471 }
472
473 static int vidioc_s_register(struct file *file, void *priv,
474                              const struct v4l2_dbg_register *reg)
475 {
476         struct stk1160 *dev = video_drvdata(file);
477
478         /* Match host */
479         return stk1160_write_reg(dev, reg->reg, reg->val);
480 }
481 #endif
482
483 static const struct v4l2_ioctl_ops stk1160_ioctl_ops = {
484         .vidioc_querycap      = vidioc_querycap,
485         .vidioc_enum_fmt_vid_cap  = vidioc_enum_fmt_vid_cap,
486         .vidioc_g_fmt_vid_cap     = vidioc_g_fmt_vid_cap,
487         .vidioc_try_fmt_vid_cap   = vidioc_try_fmt_vid_cap,
488         .vidioc_s_fmt_vid_cap     = vidioc_s_fmt_vid_cap,
489         .vidioc_querystd      = vidioc_querystd,
490         .vidioc_g_std         = vidioc_g_std,
491         .vidioc_s_std         = vidioc_s_std,
492         .vidioc_enum_input    = vidioc_enum_input,
493         .vidioc_g_input       = vidioc_g_input,
494         .vidioc_s_input       = vidioc_s_input,
495
496         /* vb2 takes care of these */
497         .vidioc_reqbufs       = vb2_ioctl_reqbufs,
498         .vidioc_querybuf      = vb2_ioctl_querybuf,
499         .vidioc_qbuf          = vb2_ioctl_qbuf,
500         .vidioc_dqbuf         = vb2_ioctl_dqbuf,
501         .vidioc_streamon      = vb2_ioctl_streamon,
502         .vidioc_streamoff     = vb2_ioctl_streamoff,
503         .vidioc_expbuf        = vb2_ioctl_expbuf,
504
505         .vidioc_log_status  = v4l2_ctrl_log_status,
506         .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
507         .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
508
509 #ifdef CONFIG_VIDEO_ADV_DEBUG
510         .vidioc_g_register = vidioc_g_register,
511         .vidioc_s_register = vidioc_s_register,
512 #endif
513 };
514
515 /********************************************************************/
516
517 /*
518  * Videobuf2 operations
519  */
520 static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *v4l_fmt,
521                                 unsigned int *nbuffers, unsigned int *nplanes,
522                                 unsigned int sizes[], void *alloc_ctxs[])
523 {
524         struct stk1160 *dev = vb2_get_drv_priv(vq);
525         unsigned long size;
526
527         size = dev->width * dev->height * 2;
528
529         /*
530          * Here we can change the number of buffers being requested.
531          * So, we set a minimum and a maximum like this:
532          */
533         *nbuffers = clamp_t(unsigned int, *nbuffers,
534                         STK1160_MIN_VIDEO_BUFFERS, STK1160_MAX_VIDEO_BUFFERS);
535
536         /* This means a packed colorformat */
537         *nplanes = 1;
538
539         sizes[0] = size;
540
541         stk1160_info("%s: buffer count %d, each %ld bytes\n",
542                         __func__, *nbuffers, size);
543
544         return 0;
545 }
546
547 static void buffer_queue(struct vb2_buffer *vb)
548 {
549         unsigned long flags;
550         struct stk1160 *dev = vb2_get_drv_priv(vb->vb2_queue);
551         struct stk1160_buffer *buf =
552                 container_of(vb, struct stk1160_buffer, vb);
553
554         spin_lock_irqsave(&dev->buf_lock, flags);
555         if (!dev->udev) {
556                 /*
557                  * If the device is disconnected return the buffer to userspace
558                  * directly. The next QBUF call will fail with -ENODEV.
559                  */
560                 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
561         } else {
562
563                 buf->mem = vb2_plane_vaddr(vb, 0);
564                 buf->length = vb2_plane_size(vb, 0);
565                 buf->bytesused = 0;
566                 buf->pos = 0;
567
568                 /*
569                  * If buffer length is less from expected then we return
570                  * the buffer to userspace directly.
571                  */
572                 if (buf->length < dev->width * dev->height * 2)
573                         vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
574                 else
575                         list_add_tail(&buf->list, &dev->avail_bufs);
576
577         }
578         spin_unlock_irqrestore(&dev->buf_lock, flags);
579 }
580
581 static int start_streaming(struct vb2_queue *vq, unsigned int count)
582 {
583         struct stk1160 *dev = vb2_get_drv_priv(vq);
584         return stk1160_start_streaming(dev);
585 }
586
587 /* abort streaming and wait for last buffer */
588 static void stop_streaming(struct vb2_queue *vq)
589 {
590         struct stk1160 *dev = vb2_get_drv_priv(vq);
591         stk1160_stop_streaming(dev);
592 }
593
594 static struct vb2_ops stk1160_video_qops = {
595         .queue_setup            = queue_setup,
596         .buf_queue              = buffer_queue,
597         .start_streaming        = start_streaming,
598         .stop_streaming         = stop_streaming,
599         .wait_prepare           = vb2_ops_wait_prepare,
600         .wait_finish            = vb2_ops_wait_finish,
601 };
602
603 static struct video_device v4l_template = {
604         .name = "stk1160",
605         .tvnorms = V4L2_STD_525_60 | V4L2_STD_625_50,
606         .fops = &stk1160_fops,
607         .ioctl_ops = &stk1160_ioctl_ops,
608         .release = video_device_release_empty,
609 };
610
611 /********************************************************************/
612
613 /* Must be called with both v4l_lock and vb_queue_lock hold */
614 void stk1160_clear_queue(struct stk1160 *dev)
615 {
616         struct stk1160_buffer *buf;
617         unsigned long flags;
618
619         /* Release all active buffers */
620         spin_lock_irqsave(&dev->buf_lock, flags);
621         while (!list_empty(&dev->avail_bufs)) {
622                 buf = list_first_entry(&dev->avail_bufs,
623                         struct stk1160_buffer, list);
624                 list_del(&buf->list);
625                 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
626                 stk1160_info("buffer [%p/%d] aborted\n",
627                                 buf, buf->vb.v4l2_buf.index);
628         }
629
630         /* It's important to release the current buffer */
631         if (dev->isoc_ctl.buf) {
632                 buf = dev->isoc_ctl.buf;
633                 dev->isoc_ctl.buf = NULL;
634
635                 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
636                 stk1160_info("buffer [%p/%d] aborted\n",
637                                 buf, buf->vb.v4l2_buf.index);
638         }
639         spin_unlock_irqrestore(&dev->buf_lock, flags);
640 }
641
642 int stk1160_vb2_setup(struct stk1160 *dev)
643 {
644         int rc;
645         struct vb2_queue *q;
646
647         q = &dev->vb_vidq;
648         q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
649         q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
650         q->drv_priv = dev;
651         q->buf_struct_size = sizeof(struct stk1160_buffer);
652         q->ops = &stk1160_video_qops;
653         q->mem_ops = &vb2_vmalloc_memops;
654         q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
655
656         rc = vb2_queue_init(q);
657         if (rc < 0)
658                 return rc;
659
660         /* initialize video dma queue */
661         INIT_LIST_HEAD(&dev->avail_bufs);
662
663         return 0;
664 }
665
666 int stk1160_video_register(struct stk1160 *dev)
667 {
668         int rc;
669
670         /* Initialize video_device with a template structure */
671         dev->vdev = v4l_template;
672         dev->vdev.queue = &dev->vb_vidq;
673
674         /*
675          * Provide mutexes for v4l2 core and for videobuf2 queue.
676          * It will be used to protect *only* v4l2 ioctls.
677          */
678         dev->vdev.lock = &dev->v4l_lock;
679         dev->vdev.queue->lock = &dev->vb_queue_lock;
680
681         /* This will be used to set video_device parent */
682         dev->vdev.v4l2_dev = &dev->v4l2_dev;
683
684         /* NTSC is default */
685         dev->norm = V4L2_STD_NTSC_M;
686         dev->width = 720;
687         dev->height = 480;
688
689         /* set default format */
690         dev->fmt = &format[0];
691         stk1160_set_std(dev);
692
693         v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_std,
694                         dev->norm);
695
696         video_set_drvdata(&dev->vdev, dev);
697         rc = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1);
698         if (rc < 0) {
699                 stk1160_err("video_register_device failed (%d)\n", rc);
700                 return rc;
701         }
702
703         v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n",
704                   video_device_node_name(&dev->vdev));
705
706         return 0;
707 }