2 * Driver for Renesas R-Car VIN
4 * Copyright (C) 2016 Renesas Electronics Corp.
5 * Copyright (C) 2011-2013 Renesas Solutions Corp.
6 * Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com>
7 * Copyright (C) 2008 Magnus Damm
9 * Based on the soc-camera rcar_vin driver
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
17 #include <linux/pm_runtime.h>
19 #include <media/v4l2-event.h>
20 #include <media/v4l2-ioctl.h>
21 #include <media/v4l2-rect.h>
25 #define RVIN_DEFAULT_FORMAT V4L2_PIX_FMT_YUYV
26 #define RVIN_MAX_WIDTH 2048
27 #define RVIN_MAX_HEIGHT 2048
29 /* -----------------------------------------------------------------------------
33 static const struct rvin_video_format rvin_formats
[] = {
35 .fourcc
= V4L2_PIX_FMT_NV16
,
39 .fourcc
= V4L2_PIX_FMT_YUYV
,
43 .fourcc
= V4L2_PIX_FMT_UYVY
,
47 .fourcc
= V4L2_PIX_FMT_RGB565
,
51 .fourcc
= V4L2_PIX_FMT_XRGB555
,
55 .fourcc
= V4L2_PIX_FMT_XBGR32
,
60 const struct rvin_video_format
*rvin_format_from_pixel(u32 pixelformat
)
64 for (i
= 0; i
< ARRAY_SIZE(rvin_formats
); i
++)
65 if (rvin_formats
[i
].fourcc
== pixelformat
)
66 return rvin_formats
+ i
;
71 static u32
rvin_format_bytesperline(struct v4l2_pix_format
*pix
)
73 const struct rvin_video_format
*fmt
;
75 fmt
= rvin_format_from_pixel(pix
->pixelformat
);
80 return pix
->width
* fmt
->bpp
;
83 static u32
rvin_format_sizeimage(struct v4l2_pix_format
*pix
)
85 if (pix
->pixelformat
== V4L2_PIX_FMT_NV16
)
86 return pix
->bytesperline
* pix
->height
* 2;
88 return pix
->bytesperline
* pix
->height
;
91 /* -----------------------------------------------------------------------------
95 static void rvin_reset_crop_compose(struct rvin_dev
*vin
)
97 vin
->crop
.top
= vin
->crop
.left
= 0;
98 vin
->crop
.width
= vin
->source
.width
;
99 vin
->crop
.height
= vin
->source
.height
;
101 vin
->compose
.top
= vin
->compose
.left
= 0;
102 vin
->compose
.width
= vin
->format
.width
;
103 vin
->compose
.height
= vin
->format
.height
;
106 static int rvin_reset_format(struct rvin_dev
*vin
)
108 struct v4l2_subdev_format fmt
= {
109 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
111 struct v4l2_mbus_framefmt
*mf
= &fmt
.format
;
114 fmt
.pad
= vin
->src_pad_idx
;
116 ret
= v4l2_subdev_call(vin_to_source(vin
), pad
, get_fmt
, NULL
, &fmt
);
120 vin
->format
.width
= mf
->width
;
121 vin
->format
.height
= mf
->height
;
122 vin
->format
.colorspace
= mf
->colorspace
;
123 vin
->format
.field
= mf
->field
;
125 switch (vin
->format
.field
) {
127 case V4L2_FIELD_BOTTOM
:
128 vin
->format
.height
/= 2;
130 case V4L2_FIELD_NONE
:
131 case V4L2_FIELD_INTERLACED_TB
:
132 case V4L2_FIELD_INTERLACED_BT
:
133 case V4L2_FIELD_INTERLACED
:
136 vin
->format
.field
= V4L2_FIELD_NONE
;
140 rvin_reset_crop_compose(vin
);
145 static int __rvin_try_format_source(struct rvin_dev
*vin
,
147 struct v4l2_pix_format
*pix
,
148 struct rvin_source_fmt
*source
)
150 struct v4l2_subdev
*sd
;
151 struct v4l2_subdev_pad_config
*pad_cfg
;
152 struct v4l2_subdev_format format
= {
155 enum v4l2_field field
;
158 sd
= vin_to_source(vin
);
160 v4l2_fill_mbus_format(&format
.format
, pix
, vin
->digital
.code
);
162 pad_cfg
= v4l2_subdev_alloc_pad_config(sd
);
166 format
.pad
= vin
->src_pad_idx
;
170 ret
= v4l2_subdev_call(sd
, pad
, set_fmt
, pad_cfg
, &format
);
171 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
174 v4l2_fill_pix_format(pix
, &format
.format
);
178 source
->width
= pix
->width
;
179 source
->height
= pix
->height
;
181 vin_dbg(vin
, "Source resolution: %ux%u\n", source
->width
,
185 v4l2_subdev_free_pad_config(pad_cfg
);
189 static int __rvin_try_format(struct rvin_dev
*vin
,
191 struct v4l2_pix_format
*pix
,
192 struct rvin_source_fmt
*source
)
194 const struct rvin_video_format
*info
;
195 u32 rwidth
, rheight
, walign
;
199 rheight
= pix
->height
;
201 /* Keep current field if no specific one is asked for */
202 if (pix
->field
== V4L2_FIELD_ANY
)
203 pix
->field
= vin
->format
.field
;
206 * Retrieve format information and select the current format if the
207 * requested format isn't supported.
209 info
= rvin_format_from_pixel(pix
->pixelformat
);
211 vin_dbg(vin
, "Format %x not found, keeping %x\n",
212 pix
->pixelformat
, vin
->format
.pixelformat
);
215 pix
->height
= rheight
;
218 /* Always recalculate */
219 pix
->bytesperline
= 0;
222 /* Limit to source capabilities */
223 __rvin_try_format_source(vin
, which
, pix
, source
);
225 switch (pix
->field
) {
227 case V4L2_FIELD_BOTTOM
:
231 case V4L2_FIELD_NONE
:
232 case V4L2_FIELD_INTERLACED_TB
:
233 case V4L2_FIELD_INTERLACED_BT
:
234 case V4L2_FIELD_INTERLACED
:
237 pix
->field
= V4L2_FIELD_NONE
;
241 /* If source can't match format try if VIN can scale */
242 if (source
->width
!= rwidth
|| source
->height
!= rheight
)
243 rvin_scale_try(vin
, pix
, rwidth
, rheight
);
245 /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
246 walign
= vin
->format
.pixelformat
== V4L2_PIX_FMT_NV16
? 5 : 1;
248 /* Limit to VIN capabilities */
249 v4l_bound_align_image(&pix
->width
, 2, RVIN_MAX_WIDTH
, walign
,
250 &pix
->height
, 4, RVIN_MAX_HEIGHT
, 2, 0);
252 pix
->bytesperline
= max_t(u32
, pix
->bytesperline
,
253 rvin_format_bytesperline(pix
));
254 pix
->sizeimage
= max_t(u32
, pix
->sizeimage
,
255 rvin_format_sizeimage(pix
));
257 if (vin
->chip
== RCAR_M1
&& pix
->pixelformat
== V4L2_PIX_FMT_XBGR32
) {
258 vin_err(vin
, "pixel format XBGR32 not supported on M1\n");
262 vin_dbg(vin
, "Requested %ux%u Got %ux%u bpl: %d size: %d\n",
263 rwidth
, rheight
, pix
->width
, pix
->height
,
264 pix
->bytesperline
, pix
->sizeimage
);
269 static int rvin_querycap(struct file
*file
, void *priv
,
270 struct v4l2_capability
*cap
)
272 struct rvin_dev
*vin
= video_drvdata(file
);
274 strlcpy(cap
->driver
, KBUILD_MODNAME
, sizeof(cap
->driver
));
275 strlcpy(cap
->card
, "R_Car_VIN", sizeof(cap
->card
));
276 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "platform:%s",
281 static int rvin_try_fmt_vid_cap(struct file
*file
, void *priv
,
282 struct v4l2_format
*f
)
284 struct rvin_dev
*vin
= video_drvdata(file
);
285 struct rvin_source_fmt source
;
287 return __rvin_try_format(vin
, V4L2_SUBDEV_FORMAT_TRY
, &f
->fmt
.pix
,
291 static int rvin_s_fmt_vid_cap(struct file
*file
, void *priv
,
292 struct v4l2_format
*f
)
294 struct rvin_dev
*vin
= video_drvdata(file
);
295 struct rvin_source_fmt source
;
298 if (vb2_is_busy(&vin
->queue
))
301 ret
= __rvin_try_format(vin
, V4L2_SUBDEV_FORMAT_ACTIVE
, &f
->fmt
.pix
,
306 vin
->source
.width
= source
.width
;
307 vin
->source
.height
= source
.height
;
309 vin
->format
= f
->fmt
.pix
;
311 rvin_reset_crop_compose(vin
);
316 static int rvin_g_fmt_vid_cap(struct file
*file
, void *priv
,
317 struct v4l2_format
*f
)
319 struct rvin_dev
*vin
= video_drvdata(file
);
321 f
->fmt
.pix
= vin
->format
;
326 static int rvin_enum_fmt_vid_cap(struct file
*file
, void *priv
,
327 struct v4l2_fmtdesc
*f
)
329 if (f
->index
>= ARRAY_SIZE(rvin_formats
))
332 f
->pixelformat
= rvin_formats
[f
->index
].fourcc
;
337 static int rvin_g_selection(struct file
*file
, void *fh
,
338 struct v4l2_selection
*s
)
340 struct rvin_dev
*vin
= video_drvdata(file
);
342 if (s
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
346 case V4L2_SEL_TGT_CROP_BOUNDS
:
347 case V4L2_SEL_TGT_CROP_DEFAULT
:
348 s
->r
.left
= s
->r
.top
= 0;
349 s
->r
.width
= vin
->source
.width
;
350 s
->r
.height
= vin
->source
.height
;
352 case V4L2_SEL_TGT_CROP
:
355 case V4L2_SEL_TGT_COMPOSE_BOUNDS
:
356 case V4L2_SEL_TGT_COMPOSE_DEFAULT
:
357 s
->r
.left
= s
->r
.top
= 0;
358 s
->r
.width
= vin
->format
.width
;
359 s
->r
.height
= vin
->format
.height
;
361 case V4L2_SEL_TGT_COMPOSE
:
371 static int rvin_s_selection(struct file
*file
, void *fh
,
372 struct v4l2_selection
*s
)
374 struct rvin_dev
*vin
= video_drvdata(file
);
375 const struct rvin_video_format
*fmt
;
376 struct v4l2_rect r
= s
->r
;
377 struct v4l2_rect max_rect
;
378 struct v4l2_rect min_rect
= {
383 if (s
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
386 v4l2_rect_set_min_size(&r
, &min_rect
);
389 case V4L2_SEL_TGT_CROP
:
390 /* Can't crop outside of source input */
391 max_rect
.top
= max_rect
.left
= 0;
392 max_rect
.width
= vin
->source
.width
;
393 max_rect
.height
= vin
->source
.height
;
394 v4l2_rect_map_inside(&r
, &max_rect
);
396 v4l_bound_align_image(&r
.width
, 2, vin
->source
.width
, 1,
397 &r
.height
, 4, vin
->source
.height
, 2, 0);
399 r
.top
= clamp_t(s32
, r
.top
, 0, vin
->source
.height
- r
.height
);
400 r
.left
= clamp_t(s32
, r
.left
, 0, vin
->source
.width
- r
.width
);
402 vin
->crop
= s
->r
= r
;
404 vin_dbg(vin
, "Cropped %dx%d@%d:%d of %dx%d\n",
405 r
.width
, r
.height
, r
.left
, r
.top
,
406 vin
->source
.width
, vin
->source
.height
);
408 case V4L2_SEL_TGT_COMPOSE
:
409 /* Make sure compose rect fits inside output format */
410 max_rect
.top
= max_rect
.left
= 0;
411 max_rect
.width
= vin
->format
.width
;
412 max_rect
.height
= vin
->format
.height
;
413 v4l2_rect_map_inside(&r
, &max_rect
);
416 * Composing is done by adding a offset to the buffer address,
417 * the HW wants this address to be aligned to HW_BUFFER_MASK.
418 * Make sure the top and left values meets this requirement.
420 while ((r
.top
* vin
->format
.bytesperline
) & HW_BUFFER_MASK
)
423 fmt
= rvin_format_from_pixel(vin
->format
.pixelformat
);
424 while ((r
.left
* fmt
->bpp
) & HW_BUFFER_MASK
)
427 vin
->compose
= s
->r
= r
;
429 vin_dbg(vin
, "Compose %dx%d@%d:%d in %dx%d\n",
430 r
.width
, r
.height
, r
.left
, r
.top
,
431 vin
->format
.width
, vin
->format
.height
);
437 /* HW supports modifying configuration while running */
438 rvin_crop_scale_comp(vin
);
443 static int rvin_cropcap(struct file
*file
, void *priv
,
444 struct v4l2_cropcap
*crop
)
446 struct rvin_dev
*vin
= video_drvdata(file
);
447 struct v4l2_subdev
*sd
= vin_to_source(vin
);
449 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
452 return v4l2_subdev_call(sd
, video
, g_pixelaspect
, &crop
->pixelaspect
);
455 static int rvin_enum_input(struct file
*file
, void *priv
,
456 struct v4l2_input
*i
)
458 struct rvin_dev
*vin
= video_drvdata(file
);
459 struct v4l2_subdev
*sd
= vin_to_source(vin
);
465 ret
= v4l2_subdev_call(sd
, video
, g_input_status
, &i
->status
);
466 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
469 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
470 i
->std
= vin
->vdev
.tvnorms
;
472 if (v4l2_subdev_has_op(sd
, pad
, dv_timings_cap
))
473 i
->capabilities
= V4L2_IN_CAP_DV_TIMINGS
;
475 strlcpy(i
->name
, "Camera", sizeof(i
->name
));
480 static int rvin_g_input(struct file
*file
, void *priv
, unsigned int *i
)
486 static int rvin_s_input(struct file
*file
, void *priv
, unsigned int i
)
493 static int rvin_querystd(struct file
*file
, void *priv
, v4l2_std_id
*a
)
495 struct rvin_dev
*vin
= video_drvdata(file
);
496 struct v4l2_subdev
*sd
= vin_to_source(vin
);
498 return v4l2_subdev_call(sd
, video
, querystd
, a
);
501 static int rvin_s_std(struct file
*file
, void *priv
, v4l2_std_id a
)
503 struct rvin_dev
*vin
= video_drvdata(file
);
506 ret
= v4l2_subdev_call(vin_to_source(vin
), video
, s_std
, a
);
510 /* Changing the standard will change the width/height */
511 return rvin_reset_format(vin
);
514 static int rvin_g_std(struct file
*file
, void *priv
, v4l2_std_id
*a
)
516 struct rvin_dev
*vin
= video_drvdata(file
);
517 struct v4l2_subdev
*sd
= vin_to_source(vin
);
519 return v4l2_subdev_call(sd
, video
, g_std
, a
);
522 static int rvin_subscribe_event(struct v4l2_fh
*fh
,
523 const struct v4l2_event_subscription
*sub
)
526 case V4L2_EVENT_SOURCE_CHANGE
:
527 return v4l2_event_subscribe(fh
, sub
, 4, NULL
);
529 return v4l2_ctrl_subscribe_event(fh
, sub
);
532 static int rvin_enum_dv_timings(struct file
*file
, void *priv_fh
,
533 struct v4l2_enum_dv_timings
*timings
)
535 struct rvin_dev
*vin
= video_drvdata(file
);
536 struct v4l2_subdev
*sd
= vin_to_source(vin
);
540 timings
->pad
= vin
->src_pad_idx
;
542 ret
= v4l2_subdev_call(sd
, pad
, enum_dv_timings
, timings
);
549 static int rvin_s_dv_timings(struct file
*file
, void *priv_fh
,
550 struct v4l2_dv_timings
*timings
)
552 struct rvin_dev
*vin
= video_drvdata(file
);
553 struct v4l2_subdev
*sd
= vin_to_source(vin
);
556 ret
= v4l2_subdev_call(sd
, video
, s_dv_timings
, timings
);
560 vin
->source
.width
= timings
->bt
.width
;
561 vin
->source
.height
= timings
->bt
.height
;
562 vin
->format
.width
= timings
->bt
.width
;
563 vin
->format
.height
= timings
->bt
.height
;
568 static int rvin_g_dv_timings(struct file
*file
, void *priv_fh
,
569 struct v4l2_dv_timings
*timings
)
571 struct rvin_dev
*vin
= video_drvdata(file
);
572 struct v4l2_subdev
*sd
= vin_to_source(vin
);
574 return v4l2_subdev_call(sd
, video
, g_dv_timings
, timings
);
577 static int rvin_query_dv_timings(struct file
*file
, void *priv_fh
,
578 struct v4l2_dv_timings
*timings
)
580 struct rvin_dev
*vin
= video_drvdata(file
);
581 struct v4l2_subdev
*sd
= vin_to_source(vin
);
583 return v4l2_subdev_call(sd
, video
, query_dv_timings
, timings
);
586 static int rvin_dv_timings_cap(struct file
*file
, void *priv_fh
,
587 struct v4l2_dv_timings_cap
*cap
)
589 struct rvin_dev
*vin
= video_drvdata(file
);
590 struct v4l2_subdev
*sd
= vin_to_source(vin
);
594 cap
->pad
= vin
->src_pad_idx
;
596 ret
= v4l2_subdev_call(sd
, pad
, dv_timings_cap
, cap
);
603 static const struct v4l2_ioctl_ops rvin_ioctl_ops
= {
604 .vidioc_querycap
= rvin_querycap
,
605 .vidioc_try_fmt_vid_cap
= rvin_try_fmt_vid_cap
,
606 .vidioc_g_fmt_vid_cap
= rvin_g_fmt_vid_cap
,
607 .vidioc_s_fmt_vid_cap
= rvin_s_fmt_vid_cap
,
608 .vidioc_enum_fmt_vid_cap
= rvin_enum_fmt_vid_cap
,
610 .vidioc_g_selection
= rvin_g_selection
,
611 .vidioc_s_selection
= rvin_s_selection
,
613 .vidioc_cropcap
= rvin_cropcap
,
615 .vidioc_enum_input
= rvin_enum_input
,
616 .vidioc_g_input
= rvin_g_input
,
617 .vidioc_s_input
= rvin_s_input
,
619 .vidioc_dv_timings_cap
= rvin_dv_timings_cap
,
620 .vidioc_enum_dv_timings
= rvin_enum_dv_timings
,
621 .vidioc_g_dv_timings
= rvin_g_dv_timings
,
622 .vidioc_s_dv_timings
= rvin_s_dv_timings
,
623 .vidioc_query_dv_timings
= rvin_query_dv_timings
,
625 .vidioc_querystd
= rvin_querystd
,
626 .vidioc_g_std
= rvin_g_std
,
627 .vidioc_s_std
= rvin_s_std
,
629 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
630 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
631 .vidioc_querybuf
= vb2_ioctl_querybuf
,
632 .vidioc_qbuf
= vb2_ioctl_qbuf
,
633 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
634 .vidioc_expbuf
= vb2_ioctl_expbuf
,
635 .vidioc_prepare_buf
= vb2_ioctl_prepare_buf
,
636 .vidioc_streamon
= vb2_ioctl_streamon
,
637 .vidioc_streamoff
= vb2_ioctl_streamoff
,
639 .vidioc_log_status
= v4l2_ctrl_log_status
,
640 .vidioc_subscribe_event
= rvin_subscribe_event
,
641 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
644 /* -----------------------------------------------------------------------------
648 static int rvin_power_on(struct rvin_dev
*vin
)
651 struct v4l2_subdev
*sd
= vin_to_source(vin
);
653 pm_runtime_get_sync(vin
->v4l2_dev
.dev
);
655 ret
= v4l2_subdev_call(sd
, core
, s_power
, 1);
656 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
661 static int rvin_power_off(struct rvin_dev
*vin
)
664 struct v4l2_subdev
*sd
= vin_to_source(vin
);
666 ret
= v4l2_subdev_call(sd
, core
, s_power
, 0);
668 pm_runtime_put(vin
->v4l2_dev
.dev
);
670 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
676 static int rvin_initialize_device(struct file
*file
)
678 struct rvin_dev
*vin
= video_drvdata(file
);
681 struct v4l2_format f
= {
682 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
684 .width
= vin
->format
.width
,
685 .height
= vin
->format
.height
,
686 .field
= vin
->format
.field
,
687 .colorspace
= vin
->format
.colorspace
,
688 .pixelformat
= vin
->format
.pixelformat
,
692 ret
= rvin_power_on(vin
);
696 pm_runtime_enable(&vin
->vdev
.dev
);
697 ret
= pm_runtime_resume(&vin
->vdev
.dev
);
698 if (ret
< 0 && ret
!= -ENOSYS
)
702 * Try to configure with default parameters. Notice: this is the
703 * very first open, so, we cannot race against other calls,
704 * apart from someone else calling open() simultaneously, but
705 * .host_lock is protecting us against it.
707 ret
= rvin_s_fmt_vid_cap(file
, NULL
, &f
);
711 v4l2_ctrl_handler_setup(&vin
->ctrl_handler
);
715 pm_runtime_disable(&vin
->vdev
.dev
);
722 static int rvin_open(struct file
*file
)
724 struct rvin_dev
*vin
= video_drvdata(file
);
727 mutex_lock(&vin
->lock
);
729 file
->private_data
= vin
;
731 ret
= v4l2_fh_open(file
);
735 if (!v4l2_fh_is_singular_file(file
))
738 if (rvin_initialize_device(file
)) {
739 v4l2_fh_release(file
);
744 mutex_unlock(&vin
->lock
);
748 static int rvin_release(struct file
*file
)
750 struct rvin_dev
*vin
= video_drvdata(file
);
754 mutex_lock(&vin
->lock
);
756 /* Save the singular status before we call the clean-up helper */
757 fh_singular
= v4l2_fh_is_singular_file(file
);
759 /* the release helper will cleanup any on-going streaming */
760 ret
= _vb2_fop_release(file
, NULL
);
763 * If this was the last open file.
764 * Then de-initialize hw module.
767 pm_runtime_suspend(&vin
->vdev
.dev
);
768 pm_runtime_disable(&vin
->vdev
.dev
);
772 mutex_unlock(&vin
->lock
);
777 static const struct v4l2_file_operations rvin_fops
= {
778 .owner
= THIS_MODULE
,
779 .unlocked_ioctl
= video_ioctl2
,
781 .release
= rvin_release
,
782 .poll
= vb2_fop_poll
,
783 .mmap
= vb2_fop_mmap
,
784 .read
= vb2_fop_read
,
787 void rvin_v4l2_remove(struct rvin_dev
*vin
)
789 v4l2_info(&vin
->v4l2_dev
, "Removing %s\n",
790 video_device_node_name(&vin
->vdev
));
792 /* Checks internaly if handlers have been init or not */
793 v4l2_ctrl_handler_free(&vin
->ctrl_handler
);
795 /* Checks internaly if vdev have been init or not */
796 video_unregister_device(&vin
->vdev
);
799 static void rvin_notify(struct v4l2_subdev
*sd
,
800 unsigned int notification
, void *arg
)
802 struct rvin_dev
*vin
=
803 container_of(sd
->v4l2_dev
, struct rvin_dev
, v4l2_dev
);
805 switch (notification
) {
806 case V4L2_DEVICE_NOTIFY_EVENT
:
807 v4l2_event_queue(&vin
->vdev
, arg
);
814 int rvin_v4l2_probe(struct rvin_dev
*vin
)
816 struct video_device
*vdev
= &vin
->vdev
;
817 struct v4l2_subdev
*sd
= vin_to_source(vin
);
820 v4l2_set_subdev_hostdata(sd
, vin
);
822 vin
->v4l2_dev
.notify
= rvin_notify
;
824 ret
= v4l2_subdev_call(sd
, video
, g_tvnorms
, &vin
->vdev
.tvnorms
);
825 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
828 if (vin
->vdev
.tvnorms
== 0) {
829 /* Disable the STD API if there are no tvnorms defined */
830 v4l2_disable_ioctl(&vin
->vdev
, VIDIOC_G_STD
);
831 v4l2_disable_ioctl(&vin
->vdev
, VIDIOC_S_STD
);
832 v4l2_disable_ioctl(&vin
->vdev
, VIDIOC_QUERYSTD
);
833 v4l2_disable_ioctl(&vin
->vdev
, VIDIOC_ENUMSTD
);
836 /* Add the controls */
838 * Currently the subdev with the largest number of controls (13) is
839 * ov6550. So let's pick 16 as a hint for the control handler. Note
840 * that this is a hint only: too large and you waste some memory, too
841 * small and there is a (very) small performance hit when looking up
842 * controls in the internal hash.
844 ret
= v4l2_ctrl_handler_init(&vin
->ctrl_handler
, 16);
848 ret
= v4l2_ctrl_add_handler(&vin
->ctrl_handler
, sd
->ctrl_handler
, NULL
);
853 vdev
->fops
= &rvin_fops
;
854 vdev
->v4l2_dev
= &vin
->v4l2_dev
;
855 vdev
->queue
= &vin
->queue
;
856 strlcpy(vdev
->name
, KBUILD_MODNAME
, sizeof(vdev
->name
));
857 vdev
->release
= video_device_release_empty
;
858 vdev
->ioctl_ops
= &rvin_ioctl_ops
;
859 vdev
->lock
= &vin
->lock
;
860 vdev
->ctrl_handler
= &vin
->ctrl_handler
;
861 vdev
->device_caps
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
|
864 vin
->src_pad_idx
= 0;
865 for (pad_idx
= 0; pad_idx
< sd
->entity
.num_pads
; pad_idx
++)
866 if (sd
->entity
.pads
[pad_idx
].flags
== MEDIA_PAD_FL_SOURCE
)
868 if (pad_idx
>= sd
->entity
.num_pads
)
871 vin
->src_pad_idx
= pad_idx
;
873 vin
->format
.pixelformat
= RVIN_DEFAULT_FORMAT
;
874 rvin_reset_format(vin
);
876 ret
= video_register_device(&vin
->vdev
, VFL_TYPE_GRABBER
, -1);
878 vin_err(vin
, "Failed to register video device\n");
882 video_set_drvdata(&vin
->vdev
, vin
);
884 v4l2_info(&vin
->v4l2_dev
, "Device registered as %s\n",
885 video_device_node_name(&vin
->vdev
));