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 int __rvin_try_format_source(struct rvin_dev
*vin
,
97 struct v4l2_pix_format
*pix
,
98 struct rvin_source_fmt
*source
)
100 struct v4l2_subdev
*sd
;
101 struct v4l2_subdev_pad_config
*pad_cfg
;
102 struct v4l2_subdev_format format
= {
107 sd
= vin_to_source(vin
);
109 v4l2_fill_mbus_format(&format
.format
, pix
, vin
->source
.code
);
111 pad_cfg
= v4l2_subdev_alloc_pad_config(sd
);
115 format
.pad
= vin
->src_pad_idx
;
117 ret
= v4l2_device_call_until_err(sd
->v4l2_dev
, 0, pad
, set_fmt
,
122 v4l2_fill_pix_format(pix
, &format
.format
);
124 source
->width
= pix
->width
;
125 source
->height
= pix
->height
;
127 vin_dbg(vin
, "Source resolution: %ux%u\n", source
->width
,
131 v4l2_subdev_free_pad_config(pad_cfg
);
135 static int __rvin_try_format(struct rvin_dev
*vin
,
137 struct v4l2_pix_format
*pix
,
138 struct rvin_source_fmt
*source
)
140 const struct rvin_video_format
*info
;
141 u32 rwidth
, rheight
, walign
;
145 rheight
= pix
->height
;
148 * Retrieve format information and select the current format if the
149 * requested format isn't supported.
151 info
= rvin_format_from_pixel(pix
->pixelformat
);
153 vin_dbg(vin
, "Format %x not found, keeping %x\n",
154 pix
->pixelformat
, vin
->format
.pixelformat
);
157 pix
->height
= rheight
;
160 /* Always recalculate */
161 pix
->bytesperline
= 0;
164 /* Limit to source capabilities */
165 __rvin_try_format_source(vin
, which
, pix
, source
);
167 /* If source can't match format try if VIN can scale */
168 if (source
->width
!= rwidth
|| source
->height
!= rheight
)
169 rvin_scale_try(vin
, pix
, rwidth
, rheight
);
171 /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
172 walign
= vin
->format
.pixelformat
== V4L2_PIX_FMT_NV16
? 5 : 1;
174 /* Limit to VIN capabilities */
175 v4l_bound_align_image(&pix
->width
, 2, RVIN_MAX_WIDTH
, walign
,
176 &pix
->height
, 4, RVIN_MAX_HEIGHT
, 2, 0);
178 switch (pix
->field
) {
179 case V4L2_FIELD_NONE
:
181 case V4L2_FIELD_BOTTOM
:
182 case V4L2_FIELD_INTERLACED_TB
:
183 case V4L2_FIELD_INTERLACED_BT
:
184 case V4L2_FIELD_INTERLACED
:
187 pix
->field
= V4L2_FIELD_NONE
;
191 pix
->bytesperline
= max_t(u32
, pix
->bytesperline
,
192 rvin_format_bytesperline(pix
));
193 pix
->sizeimage
= max_t(u32
, pix
->sizeimage
,
194 rvin_format_sizeimage(pix
));
196 vin_dbg(vin
, "Requested %ux%u Got %ux%u bpl: %d size: %d\n",
197 rwidth
, rheight
, pix
->width
, pix
->height
,
198 pix
->bytesperline
, pix
->sizeimage
);
203 static int rvin_querycap(struct file
*file
, void *priv
,
204 struct v4l2_capability
*cap
)
206 struct rvin_dev
*vin
= video_drvdata(file
);
208 strlcpy(cap
->driver
, KBUILD_MODNAME
, sizeof(cap
->driver
));
209 strlcpy(cap
->card
, "R_Car_VIN", sizeof(cap
->card
));
210 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "platform:%s",
215 static int rvin_try_fmt_vid_cap(struct file
*file
, void *priv
,
216 struct v4l2_format
*f
)
218 struct rvin_dev
*vin
= video_drvdata(file
);
219 struct rvin_source_fmt source
;
221 return __rvin_try_format(vin
, V4L2_SUBDEV_FORMAT_TRY
, &f
->fmt
.pix
,
225 static int rvin_s_fmt_vid_cap(struct file
*file
, void *priv
,
226 struct v4l2_format
*f
)
228 struct rvin_dev
*vin
= video_drvdata(file
);
229 struct rvin_source_fmt source
;
232 if (vb2_is_busy(&vin
->queue
))
235 ret
= __rvin_try_format(vin
, V4L2_SUBDEV_FORMAT_ACTIVE
, &f
->fmt
.pix
,
240 vin
->source
.width
= source
.width
;
241 vin
->source
.height
= source
.height
;
243 vin
->format
= f
->fmt
.pix
;
248 static int rvin_g_fmt_vid_cap(struct file
*file
, void *priv
,
249 struct v4l2_format
*f
)
251 struct rvin_dev
*vin
= video_drvdata(file
);
253 f
->fmt
.pix
= vin
->format
;
258 static int rvin_enum_fmt_vid_cap(struct file
*file
, void *priv
,
259 struct v4l2_fmtdesc
*f
)
261 if (f
->index
>= ARRAY_SIZE(rvin_formats
))
264 f
->pixelformat
= rvin_formats
[f
->index
].fourcc
;
269 static int rvin_g_selection(struct file
*file
, void *fh
,
270 struct v4l2_selection
*s
)
272 struct rvin_dev
*vin
= video_drvdata(file
);
274 if (s
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
278 case V4L2_SEL_TGT_CROP_BOUNDS
:
279 case V4L2_SEL_TGT_CROP_DEFAULT
:
280 s
->r
.left
= s
->r
.top
= 0;
281 s
->r
.width
= vin
->source
.width
;
282 s
->r
.height
= vin
->source
.height
;
284 case V4L2_SEL_TGT_CROP
:
287 case V4L2_SEL_TGT_COMPOSE_BOUNDS
:
288 case V4L2_SEL_TGT_COMPOSE_DEFAULT
:
289 s
->r
.left
= s
->r
.top
= 0;
290 s
->r
.width
= vin
->format
.width
;
291 s
->r
.height
= vin
->format
.height
;
293 case V4L2_SEL_TGT_COMPOSE
:
303 static int rvin_s_selection(struct file
*file
, void *fh
,
304 struct v4l2_selection
*s
)
306 struct rvin_dev
*vin
= video_drvdata(file
);
307 const struct rvin_video_format
*fmt
;
308 struct v4l2_rect r
= s
->r
;
309 struct v4l2_rect max_rect
;
310 struct v4l2_rect min_rect
= {
315 if (s
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
318 v4l2_rect_set_min_size(&r
, &min_rect
);
321 case V4L2_SEL_TGT_CROP
:
322 /* Can't crop outside of source input */
323 max_rect
.top
= max_rect
.left
= 0;
324 max_rect
.width
= vin
->source
.width
;
325 max_rect
.height
= vin
->source
.height
;
326 v4l2_rect_map_inside(&r
, &max_rect
);
328 v4l_bound_align_image(&r
.width
, 2, vin
->source
.width
, 1,
329 &r
.height
, 4, vin
->source
.height
, 2, 0);
331 r
.top
= clamp_t(s32
, r
.top
, 0, vin
->source
.height
- r
.height
);
332 r
.left
= clamp_t(s32
, r
.left
, 0, vin
->source
.width
- r
.width
);
334 vin
->crop
= s
->r
= r
;
336 vin_dbg(vin
, "Cropped %dx%d@%d:%d of %dx%d\n",
337 r
.width
, r
.height
, r
.left
, r
.top
,
338 vin
->source
.width
, vin
->source
.height
);
340 case V4L2_SEL_TGT_COMPOSE
:
341 /* Make sure compose rect fits inside output format */
342 max_rect
.top
= max_rect
.left
= 0;
343 max_rect
.width
= vin
->format
.width
;
344 max_rect
.height
= vin
->format
.height
;
345 v4l2_rect_map_inside(&r
, &max_rect
);
348 * Composing is done by adding a offset to the buffer address,
349 * the HW wants this address to be aligned to HW_BUFFER_MASK.
350 * Make sure the top and left values meets this requirement.
352 while ((r
.top
* vin
->format
.bytesperline
) & HW_BUFFER_MASK
)
355 fmt
= rvin_format_from_pixel(vin
->format
.pixelformat
);
356 while ((r
.left
* fmt
->bpp
) & HW_BUFFER_MASK
)
359 vin
->compose
= s
->r
= r
;
361 vin_dbg(vin
, "Compose %dx%d@%d:%d in %dx%d\n",
362 r
.width
, r
.height
, r
.left
, r
.top
,
363 vin
->format
.width
, vin
->format
.height
);
369 /* HW supports modifying configuration while running */
370 rvin_crop_scale_comp(vin
);
375 static int rvin_cropcap(struct file
*file
, void *priv
,
376 struct v4l2_cropcap
*crop
)
378 struct rvin_dev
*vin
= video_drvdata(file
);
379 struct v4l2_subdev
*sd
= vin_to_source(vin
);
381 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
384 return v4l2_subdev_call(sd
, video
, cropcap
, crop
);
387 static int rvin_enum_input(struct file
*file
, void *priv
,
388 struct v4l2_input
*i
)
390 struct rvin_dev
*vin
= video_drvdata(file
);
391 struct v4l2_subdev
*sd
= vin_to_source(vin
);
397 ret
= v4l2_subdev_call(sd
, video
, g_input_status
, &i
->status
);
398 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
401 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
402 i
->std
= vin
->vdev
.tvnorms
;
404 if (v4l2_subdev_has_op(sd
, pad
, dv_timings_cap
))
405 i
->capabilities
= V4L2_IN_CAP_DV_TIMINGS
;
407 strlcpy(i
->name
, "Camera", sizeof(i
->name
));
412 static int rvin_g_input(struct file
*file
, void *priv
, unsigned int *i
)
418 static int rvin_s_input(struct file
*file
, void *priv
, unsigned int i
)
425 static int rvin_querystd(struct file
*file
, void *priv
, v4l2_std_id
*a
)
427 struct rvin_dev
*vin
= video_drvdata(file
);
428 struct v4l2_subdev
*sd
= vin_to_source(vin
);
430 return v4l2_subdev_call(sd
, video
, querystd
, a
);
433 static int rvin_s_std(struct file
*file
, void *priv
, v4l2_std_id a
)
435 struct rvin_dev
*vin
= video_drvdata(file
);
436 struct v4l2_subdev
*sd
= vin_to_source(vin
);
437 struct v4l2_subdev_format fmt
= {
438 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
440 struct v4l2_mbus_framefmt
*mf
= &fmt
.format
;
441 int ret
= v4l2_subdev_call(sd
, video
, s_std
, a
);
446 /* Changing the standard will change the width/height */
447 ret
= v4l2_subdev_call(sd
, pad
, get_fmt
, NULL
, &fmt
);
449 vin_err(vin
, "Failed to get initial format\n");
453 vin
->format
.width
= mf
->width
;
454 vin
->format
.height
= mf
->height
;
456 vin
->crop
.top
= vin
->crop
.left
= 0;
457 vin
->crop
.width
= mf
->width
;
458 vin
->crop
.height
= mf
->height
;
460 vin
->compose
.top
= vin
->compose
.left
= 0;
461 vin
->compose
.width
= mf
->width
;
462 vin
->compose
.height
= mf
->height
;
467 static int rvin_g_std(struct file
*file
, void *priv
, v4l2_std_id
*a
)
469 struct rvin_dev
*vin
= video_drvdata(file
);
470 struct v4l2_subdev
*sd
= vin_to_source(vin
);
472 return v4l2_subdev_call(sd
, video
, g_std
, a
);
475 static int rvin_subscribe_event(struct v4l2_fh
*fh
,
476 const struct v4l2_event_subscription
*sub
)
479 case V4L2_EVENT_SOURCE_CHANGE
:
480 return v4l2_event_subscribe(fh
, sub
, 4, NULL
);
482 return v4l2_ctrl_subscribe_event(fh
, sub
);
485 static int rvin_enum_dv_timings(struct file
*file
, void *priv_fh
,
486 struct v4l2_enum_dv_timings
*timings
)
488 struct rvin_dev
*vin
= video_drvdata(file
);
489 struct v4l2_subdev
*sd
= vin_to_source(vin
);
493 timings
->pad
= vin
->src_pad_idx
;
495 ret
= v4l2_subdev_call(sd
, pad
, enum_dv_timings
, timings
);
502 static int rvin_s_dv_timings(struct file
*file
, void *priv_fh
,
503 struct v4l2_dv_timings
*timings
)
505 struct rvin_dev
*vin
= video_drvdata(file
);
506 struct v4l2_subdev
*sd
= vin_to_source(vin
);
509 err
= v4l2_subdev_call(sd
,
510 video
, s_dv_timings
, timings
);
512 vin
->source
.width
= timings
->bt
.width
;
513 vin
->source
.height
= timings
->bt
.height
;
514 vin
->format
.width
= timings
->bt
.width
;
515 vin
->format
.height
= timings
->bt
.height
;
520 static int rvin_g_dv_timings(struct file
*file
, void *priv_fh
,
521 struct v4l2_dv_timings
*timings
)
523 struct rvin_dev
*vin
= video_drvdata(file
);
524 struct v4l2_subdev
*sd
= vin_to_source(vin
);
526 return v4l2_subdev_call(sd
,
527 video
, g_dv_timings
, timings
);
530 static int rvin_query_dv_timings(struct file
*file
, void *priv_fh
,
531 struct v4l2_dv_timings
*timings
)
533 struct rvin_dev
*vin
= video_drvdata(file
);
534 struct v4l2_subdev
*sd
= vin_to_source(vin
);
536 return v4l2_subdev_call(sd
,
537 video
, query_dv_timings
, timings
);
540 static int rvin_dv_timings_cap(struct file
*file
, void *priv_fh
,
541 struct v4l2_dv_timings_cap
*cap
)
543 struct rvin_dev
*vin
= video_drvdata(file
);
544 struct v4l2_subdev
*sd
= vin_to_source(vin
);
548 cap
->pad
= vin
->src_pad_idx
;
550 ret
= v4l2_subdev_call(sd
, pad
, dv_timings_cap
, cap
);
557 static const struct v4l2_ioctl_ops rvin_ioctl_ops
= {
558 .vidioc_querycap
= rvin_querycap
,
559 .vidioc_try_fmt_vid_cap
= rvin_try_fmt_vid_cap
,
560 .vidioc_g_fmt_vid_cap
= rvin_g_fmt_vid_cap
,
561 .vidioc_s_fmt_vid_cap
= rvin_s_fmt_vid_cap
,
562 .vidioc_enum_fmt_vid_cap
= rvin_enum_fmt_vid_cap
,
564 .vidioc_g_selection
= rvin_g_selection
,
565 .vidioc_s_selection
= rvin_s_selection
,
567 .vidioc_cropcap
= rvin_cropcap
,
569 .vidioc_enum_input
= rvin_enum_input
,
570 .vidioc_g_input
= rvin_g_input
,
571 .vidioc_s_input
= rvin_s_input
,
573 .vidioc_dv_timings_cap
= rvin_dv_timings_cap
,
574 .vidioc_enum_dv_timings
= rvin_enum_dv_timings
,
575 .vidioc_g_dv_timings
= rvin_g_dv_timings
,
576 .vidioc_s_dv_timings
= rvin_s_dv_timings
,
577 .vidioc_query_dv_timings
= rvin_query_dv_timings
,
579 .vidioc_querystd
= rvin_querystd
,
580 .vidioc_g_std
= rvin_g_std
,
581 .vidioc_s_std
= rvin_s_std
,
583 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
584 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
585 .vidioc_querybuf
= vb2_ioctl_querybuf
,
586 .vidioc_qbuf
= vb2_ioctl_qbuf
,
587 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
588 .vidioc_expbuf
= vb2_ioctl_expbuf
,
589 .vidioc_prepare_buf
= vb2_ioctl_prepare_buf
,
590 .vidioc_streamon
= vb2_ioctl_streamon
,
591 .vidioc_streamoff
= vb2_ioctl_streamoff
,
593 .vidioc_log_status
= v4l2_ctrl_log_status
,
594 .vidioc_subscribe_event
= rvin_subscribe_event
,
595 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
598 /* -----------------------------------------------------------------------------
602 static int rvin_power_on(struct rvin_dev
*vin
)
605 struct v4l2_subdev
*sd
= vin_to_source(vin
);
607 pm_runtime_get_sync(vin
->v4l2_dev
.dev
);
609 ret
= v4l2_subdev_call(sd
, core
, s_power
, 1);
610 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
615 static int rvin_power_off(struct rvin_dev
*vin
)
618 struct v4l2_subdev
*sd
= vin_to_source(vin
);
620 ret
= v4l2_subdev_call(sd
, core
, s_power
, 0);
622 pm_runtime_put(vin
->v4l2_dev
.dev
);
624 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
630 static int rvin_initialize_device(struct file
*file
)
632 struct rvin_dev
*vin
= video_drvdata(file
);
635 struct v4l2_format f
= {
636 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
638 .width
= vin
->format
.width
,
639 .height
= vin
->format
.height
,
640 .field
= vin
->format
.field
,
641 .colorspace
= vin
->format
.colorspace
,
642 .pixelformat
= vin
->format
.pixelformat
,
646 ret
= rvin_power_on(vin
);
650 pm_runtime_enable(&vin
->vdev
.dev
);
651 ret
= pm_runtime_resume(&vin
->vdev
.dev
);
652 if (ret
< 0 && ret
!= -ENOSYS
)
656 * Try to configure with default parameters. Notice: this is the
657 * very first open, so, we cannot race against other calls,
658 * apart from someone else calling open() simultaneously, but
659 * .host_lock is protecting us against it.
661 ret
= rvin_s_fmt_vid_cap(file
, NULL
, &f
);
665 v4l2_ctrl_handler_setup(&vin
->ctrl_handler
);
669 pm_runtime_disable(&vin
->vdev
.dev
);
676 static int rvin_open(struct file
*file
)
678 struct rvin_dev
*vin
= video_drvdata(file
);
681 mutex_lock(&vin
->lock
);
683 file
->private_data
= vin
;
685 ret
= v4l2_fh_open(file
);
689 if (!v4l2_fh_is_singular_file(file
))
692 if (rvin_initialize_device(file
)) {
693 v4l2_fh_release(file
);
698 mutex_unlock(&vin
->lock
);
702 static int rvin_release(struct file
*file
)
704 struct rvin_dev
*vin
= video_drvdata(file
);
708 mutex_lock(&vin
->lock
);
710 /* Save the singular status before we call the clean-up helper */
711 fh_singular
= v4l2_fh_is_singular_file(file
);
713 /* the release helper will cleanup any on-going streaming */
714 ret
= _vb2_fop_release(file
, NULL
);
717 * If this was the last open file.
718 * Then de-initialize hw module.
721 pm_runtime_suspend(&vin
->vdev
.dev
);
722 pm_runtime_disable(&vin
->vdev
.dev
);
726 mutex_unlock(&vin
->lock
);
731 static const struct v4l2_file_operations rvin_fops
= {
732 .owner
= THIS_MODULE
,
733 .unlocked_ioctl
= video_ioctl2
,
735 .release
= rvin_release
,
736 .poll
= vb2_fop_poll
,
737 .mmap
= vb2_fop_mmap
,
738 .read
= vb2_fop_read
,
741 void rvin_v4l2_remove(struct rvin_dev
*vin
)
743 v4l2_info(&vin
->v4l2_dev
, "Removing %s\n",
744 video_device_node_name(&vin
->vdev
));
746 /* Checks internaly if handlers have been init or not */
747 v4l2_ctrl_handler_free(&vin
->ctrl_handler
);
749 /* Checks internaly if vdev have been init or not */
750 video_unregister_device(&vin
->vdev
);
753 static void rvin_notify(struct v4l2_subdev
*sd
,
754 unsigned int notification
, void *arg
)
756 struct rvin_dev
*vin
=
757 container_of(sd
->v4l2_dev
, struct rvin_dev
, v4l2_dev
);
759 switch (notification
) {
760 case V4L2_DEVICE_NOTIFY_EVENT
:
761 v4l2_event_queue(&vin
->vdev
, arg
);
768 int rvin_v4l2_probe(struct rvin_dev
*vin
)
770 struct v4l2_subdev_format fmt
= {
771 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
773 struct v4l2_mbus_framefmt
*mf
= &fmt
.format
;
774 struct video_device
*vdev
= &vin
->vdev
;
775 struct v4l2_subdev
*sd
= vin_to_source(vin
);
776 #if defined(CONFIG_MEDIA_CONTROLLER)
781 v4l2_set_subdev_hostdata(sd
, vin
);
783 vin
->v4l2_dev
.notify
= rvin_notify
;
785 ret
= v4l2_subdev_call(sd
, video
, g_tvnorms
, &vin
->vdev
.tvnorms
);
786 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
789 if (vin
->vdev
.tvnorms
== 0) {
790 /* Disable the STD API if there are no tvnorms defined */
791 v4l2_disable_ioctl(&vin
->vdev
, VIDIOC_G_STD
);
792 v4l2_disable_ioctl(&vin
->vdev
, VIDIOC_S_STD
);
793 v4l2_disable_ioctl(&vin
->vdev
, VIDIOC_QUERYSTD
);
794 v4l2_disable_ioctl(&vin
->vdev
, VIDIOC_ENUMSTD
);
797 /* Add the controls */
799 * Currently the subdev with the largest number of controls (13) is
800 * ov6550. So let's pick 16 as a hint for the control handler. Note
801 * that this is a hint only: too large and you waste some memory, too
802 * small and there is a (very) small performance hit when looking up
803 * controls in the internal hash.
805 ret
= v4l2_ctrl_handler_init(&vin
->ctrl_handler
, 16);
809 ret
= v4l2_ctrl_add_handler(&vin
->ctrl_handler
, sd
->ctrl_handler
, NULL
);
814 vdev
->fops
= &rvin_fops
;
815 vdev
->v4l2_dev
= &vin
->v4l2_dev
;
816 vdev
->queue
= &vin
->queue
;
817 strlcpy(vdev
->name
, KBUILD_MODNAME
, sizeof(vdev
->name
));
818 vdev
->release
= video_device_release_empty
;
819 vdev
->ioctl_ops
= &rvin_ioctl_ops
;
820 vdev
->lock
= &vin
->lock
;
821 vdev
->ctrl_handler
= &vin
->ctrl_handler
;
822 vdev
->device_caps
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
|
825 vin
->src_pad_idx
= 0;
826 #if defined(CONFIG_MEDIA_CONTROLLER)
827 for (pad_idx
= 0; pad_idx
< sd
->entity
.num_pads
; pad_idx
++)
828 if (sd
->entity
.pads
[pad_idx
].flags
829 == MEDIA_PAD_FL_SOURCE
)
831 if (pad_idx
>= sd
->entity
.num_pads
)
834 vin
->src_pad_idx
= pad_idx
;
836 fmt
.pad
= vin
->src_pad_idx
;
838 /* Try to improve our guess of a reasonable window format */
839 ret
= v4l2_subdev_call(sd
, pad
, get_fmt
, NULL
, &fmt
);
841 vin_err(vin
, "Failed to get initial format\n");
845 /* Set default format */
846 vin
->format
.width
= mf
->width
;
847 vin
->format
.height
= mf
->height
;
848 vin
->format
.colorspace
= mf
->colorspace
;
849 vin
->format
.field
= mf
->field
;
850 vin
->format
.pixelformat
= RVIN_DEFAULT_FORMAT
;
853 /* Set initial crop and compose */
854 vin
->crop
.top
= vin
->crop
.left
= 0;
855 vin
->crop
.width
= mf
->width
;
856 vin
->crop
.height
= mf
->height
;
858 vin
->compose
.top
= vin
->compose
.left
= 0;
859 vin
->compose
.width
= mf
->width
;
860 vin
->compose
.height
= mf
->height
;
862 ret
= video_register_device(&vin
->vdev
, VFL_TYPE_GRABBER
, -1);
864 vin_err(vin
, "Failed to register video device\n");
868 video_set_drvdata(&vin
->vdev
, vin
);
870 v4l2_info(&vin
->v4l2_dev
, "Device registered as %s\n",
871 video_device_node_name(&vin
->vdev
));