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
->digital
.code
);
111 pad_cfg
= v4l2_subdev_alloc_pad_config(sd
);
115 format
.pad
= vin
->src_pad_idx
;
117 ret
= v4l2_subdev_call(sd
, pad
, set_fmt
, pad_cfg
, &format
);
118 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
121 v4l2_fill_pix_format(pix
, &format
.format
);
123 source
->width
= pix
->width
;
124 source
->height
= pix
->height
;
126 vin_dbg(vin
, "Source resolution: %ux%u\n", source
->width
,
130 v4l2_subdev_free_pad_config(pad_cfg
);
134 static int __rvin_try_format(struct rvin_dev
*vin
,
136 struct v4l2_pix_format
*pix
,
137 struct rvin_source_fmt
*source
)
139 const struct rvin_video_format
*info
;
140 u32 rwidth
, rheight
, walign
;
144 rheight
= pix
->height
;
147 * Retrieve format information and select the current format if the
148 * requested format isn't supported.
150 info
= rvin_format_from_pixel(pix
->pixelformat
);
152 vin_dbg(vin
, "Format %x not found, keeping %x\n",
153 pix
->pixelformat
, vin
->format
.pixelformat
);
156 pix
->height
= rheight
;
159 /* Always recalculate */
160 pix
->bytesperline
= 0;
163 /* Limit to source capabilities */
164 __rvin_try_format_source(vin
, which
, pix
, source
);
166 /* If source can't match format try if VIN can scale */
167 if (source
->width
!= rwidth
|| source
->height
!= rheight
)
168 rvin_scale_try(vin
, pix
, rwidth
, rheight
);
170 /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
171 walign
= vin
->format
.pixelformat
== V4L2_PIX_FMT_NV16
? 5 : 1;
173 /* Limit to VIN capabilities */
174 v4l_bound_align_image(&pix
->width
, 2, RVIN_MAX_WIDTH
, walign
,
175 &pix
->height
, 4, RVIN_MAX_HEIGHT
, 2, 0);
177 switch (pix
->field
) {
178 case V4L2_FIELD_NONE
:
180 case V4L2_FIELD_BOTTOM
:
181 case V4L2_FIELD_INTERLACED_TB
:
182 case V4L2_FIELD_INTERLACED_BT
:
183 case V4L2_FIELD_INTERLACED
:
186 pix
->field
= V4L2_FIELD_NONE
;
190 pix
->bytesperline
= max_t(u32
, pix
->bytesperline
,
191 rvin_format_bytesperline(pix
));
192 pix
->sizeimage
= max_t(u32
, pix
->sizeimage
,
193 rvin_format_sizeimage(pix
));
195 if (vin
->chip
== RCAR_M1
&& pix
->pixelformat
== V4L2_PIX_FMT_XBGR32
) {
196 vin_err(vin
, "pixel format XBGR32 not supported on M1\n");
200 vin_dbg(vin
, "Requested %ux%u Got %ux%u bpl: %d size: %d\n",
201 rwidth
, rheight
, pix
->width
, pix
->height
,
202 pix
->bytesperline
, pix
->sizeimage
);
207 static int rvin_querycap(struct file
*file
, void *priv
,
208 struct v4l2_capability
*cap
)
210 struct rvin_dev
*vin
= video_drvdata(file
);
212 strlcpy(cap
->driver
, KBUILD_MODNAME
, sizeof(cap
->driver
));
213 strlcpy(cap
->card
, "R_Car_VIN", sizeof(cap
->card
));
214 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "platform:%s",
219 static int rvin_try_fmt_vid_cap(struct file
*file
, void *priv
,
220 struct v4l2_format
*f
)
222 struct rvin_dev
*vin
= video_drvdata(file
);
223 struct rvin_source_fmt source
;
225 return __rvin_try_format(vin
, V4L2_SUBDEV_FORMAT_TRY
, &f
->fmt
.pix
,
229 static int rvin_s_fmt_vid_cap(struct file
*file
, void *priv
,
230 struct v4l2_format
*f
)
232 struct rvin_dev
*vin
= video_drvdata(file
);
233 struct rvin_source_fmt source
;
236 if (vb2_is_busy(&vin
->queue
))
239 ret
= __rvin_try_format(vin
, V4L2_SUBDEV_FORMAT_ACTIVE
, &f
->fmt
.pix
,
244 vin
->source
.width
= source
.width
;
245 vin
->source
.height
= source
.height
;
247 vin
->format
= f
->fmt
.pix
;
252 static int rvin_g_fmt_vid_cap(struct file
*file
, void *priv
,
253 struct v4l2_format
*f
)
255 struct rvin_dev
*vin
= video_drvdata(file
);
257 f
->fmt
.pix
= vin
->format
;
262 static int rvin_enum_fmt_vid_cap(struct file
*file
, void *priv
,
263 struct v4l2_fmtdesc
*f
)
265 if (f
->index
>= ARRAY_SIZE(rvin_formats
))
268 f
->pixelformat
= rvin_formats
[f
->index
].fourcc
;
273 static int rvin_g_selection(struct file
*file
, void *fh
,
274 struct v4l2_selection
*s
)
276 struct rvin_dev
*vin
= video_drvdata(file
);
278 if (s
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
282 case V4L2_SEL_TGT_CROP_BOUNDS
:
283 case V4L2_SEL_TGT_CROP_DEFAULT
:
284 s
->r
.left
= s
->r
.top
= 0;
285 s
->r
.width
= vin
->source
.width
;
286 s
->r
.height
= vin
->source
.height
;
288 case V4L2_SEL_TGT_CROP
:
291 case V4L2_SEL_TGT_COMPOSE_BOUNDS
:
292 case V4L2_SEL_TGT_COMPOSE_DEFAULT
:
293 s
->r
.left
= s
->r
.top
= 0;
294 s
->r
.width
= vin
->format
.width
;
295 s
->r
.height
= vin
->format
.height
;
297 case V4L2_SEL_TGT_COMPOSE
:
307 static int rvin_s_selection(struct file
*file
, void *fh
,
308 struct v4l2_selection
*s
)
310 struct rvin_dev
*vin
= video_drvdata(file
);
311 const struct rvin_video_format
*fmt
;
312 struct v4l2_rect r
= s
->r
;
313 struct v4l2_rect max_rect
;
314 struct v4l2_rect min_rect
= {
319 if (s
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
322 v4l2_rect_set_min_size(&r
, &min_rect
);
325 case V4L2_SEL_TGT_CROP
:
326 /* Can't crop outside of source input */
327 max_rect
.top
= max_rect
.left
= 0;
328 max_rect
.width
= vin
->source
.width
;
329 max_rect
.height
= vin
->source
.height
;
330 v4l2_rect_map_inside(&r
, &max_rect
);
332 v4l_bound_align_image(&r
.width
, 2, vin
->source
.width
, 1,
333 &r
.height
, 4, vin
->source
.height
, 2, 0);
335 r
.top
= clamp_t(s32
, r
.top
, 0, vin
->source
.height
- r
.height
);
336 r
.left
= clamp_t(s32
, r
.left
, 0, vin
->source
.width
- r
.width
);
338 vin
->crop
= s
->r
= r
;
340 vin_dbg(vin
, "Cropped %dx%d@%d:%d of %dx%d\n",
341 r
.width
, r
.height
, r
.left
, r
.top
,
342 vin
->source
.width
, vin
->source
.height
);
344 case V4L2_SEL_TGT_COMPOSE
:
345 /* Make sure compose rect fits inside output format */
346 max_rect
.top
= max_rect
.left
= 0;
347 max_rect
.width
= vin
->format
.width
;
348 max_rect
.height
= vin
->format
.height
;
349 v4l2_rect_map_inside(&r
, &max_rect
);
352 * Composing is done by adding a offset to the buffer address,
353 * the HW wants this address to be aligned to HW_BUFFER_MASK.
354 * Make sure the top and left values meets this requirement.
356 while ((r
.top
* vin
->format
.bytesperline
) & HW_BUFFER_MASK
)
359 fmt
= rvin_format_from_pixel(vin
->format
.pixelformat
);
360 while ((r
.left
* fmt
->bpp
) & HW_BUFFER_MASK
)
363 vin
->compose
= s
->r
= r
;
365 vin_dbg(vin
, "Compose %dx%d@%d:%d in %dx%d\n",
366 r
.width
, r
.height
, r
.left
, r
.top
,
367 vin
->format
.width
, vin
->format
.height
);
373 /* HW supports modifying configuration while running */
374 rvin_crop_scale_comp(vin
);
379 static int rvin_cropcap(struct file
*file
, void *priv
,
380 struct v4l2_cropcap
*crop
)
382 struct rvin_dev
*vin
= video_drvdata(file
);
383 struct v4l2_subdev
*sd
= vin_to_source(vin
);
385 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
388 return v4l2_subdev_call(sd
, video
, g_pixelaspect
, &crop
->pixelaspect
);
391 static int rvin_enum_input(struct file
*file
, void *priv
,
392 struct v4l2_input
*i
)
394 struct rvin_dev
*vin
= video_drvdata(file
);
395 struct v4l2_subdev
*sd
= vin_to_source(vin
);
401 ret
= v4l2_subdev_call(sd
, video
, g_input_status
, &i
->status
);
402 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
405 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
406 i
->std
= vin
->vdev
.tvnorms
;
408 if (v4l2_subdev_has_op(sd
, pad
, dv_timings_cap
))
409 i
->capabilities
= V4L2_IN_CAP_DV_TIMINGS
;
411 strlcpy(i
->name
, "Camera", sizeof(i
->name
));
416 static int rvin_g_input(struct file
*file
, void *priv
, unsigned int *i
)
422 static int rvin_s_input(struct file
*file
, void *priv
, unsigned int i
)
429 static int rvin_querystd(struct file
*file
, void *priv
, v4l2_std_id
*a
)
431 struct rvin_dev
*vin
= video_drvdata(file
);
432 struct v4l2_subdev
*sd
= vin_to_source(vin
);
434 return v4l2_subdev_call(sd
, video
, querystd
, a
);
437 static int rvin_s_std(struct file
*file
, void *priv
, v4l2_std_id a
)
439 struct rvin_dev
*vin
= video_drvdata(file
);
440 struct v4l2_subdev
*sd
= vin_to_source(vin
);
441 struct v4l2_subdev_format fmt
= {
442 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
444 struct v4l2_mbus_framefmt
*mf
= &fmt
.format
;
445 int ret
= v4l2_subdev_call(sd
, video
, s_std
, a
);
450 /* Changing the standard will change the width/height */
451 ret
= v4l2_subdev_call(sd
, pad
, get_fmt
, NULL
, &fmt
);
453 vin_err(vin
, "Failed to get initial format\n");
457 vin
->format
.width
= mf
->width
;
458 vin
->format
.height
= mf
->height
;
460 vin
->crop
.top
= vin
->crop
.left
= 0;
461 vin
->crop
.width
= mf
->width
;
462 vin
->crop
.height
= mf
->height
;
464 vin
->compose
.top
= vin
->compose
.left
= 0;
465 vin
->compose
.width
= mf
->width
;
466 vin
->compose
.height
= mf
->height
;
471 static int rvin_g_std(struct file
*file
, void *priv
, v4l2_std_id
*a
)
473 struct rvin_dev
*vin
= video_drvdata(file
);
474 struct v4l2_subdev
*sd
= vin_to_source(vin
);
476 return v4l2_subdev_call(sd
, video
, g_std
, a
);
479 static int rvin_subscribe_event(struct v4l2_fh
*fh
,
480 const struct v4l2_event_subscription
*sub
)
483 case V4L2_EVENT_SOURCE_CHANGE
:
484 return v4l2_event_subscribe(fh
, sub
, 4, NULL
);
486 return v4l2_ctrl_subscribe_event(fh
, sub
);
489 static int rvin_enum_dv_timings(struct file
*file
, void *priv_fh
,
490 struct v4l2_enum_dv_timings
*timings
)
492 struct rvin_dev
*vin
= video_drvdata(file
);
493 struct v4l2_subdev
*sd
= vin_to_source(vin
);
497 timings
->pad
= vin
->src_pad_idx
;
499 ret
= v4l2_subdev_call(sd
, pad
, enum_dv_timings
, timings
);
506 static int rvin_s_dv_timings(struct file
*file
, void *priv_fh
,
507 struct v4l2_dv_timings
*timings
)
509 struct rvin_dev
*vin
= video_drvdata(file
);
510 struct v4l2_subdev
*sd
= vin_to_source(vin
);
513 ret
= v4l2_subdev_call(sd
, video
, s_dv_timings
, timings
);
517 vin
->source
.width
= timings
->bt
.width
;
518 vin
->source
.height
= timings
->bt
.height
;
519 vin
->format
.width
= timings
->bt
.width
;
520 vin
->format
.height
= timings
->bt
.height
;
525 static int rvin_g_dv_timings(struct file
*file
, void *priv_fh
,
526 struct v4l2_dv_timings
*timings
)
528 struct rvin_dev
*vin
= video_drvdata(file
);
529 struct v4l2_subdev
*sd
= vin_to_source(vin
);
531 return v4l2_subdev_call(sd
, video
, g_dv_timings
, timings
);
534 static int rvin_query_dv_timings(struct file
*file
, void *priv_fh
,
535 struct v4l2_dv_timings
*timings
)
537 struct rvin_dev
*vin
= video_drvdata(file
);
538 struct v4l2_subdev
*sd
= vin_to_source(vin
);
540 return v4l2_subdev_call(sd
, video
, query_dv_timings
, timings
);
543 static int rvin_dv_timings_cap(struct file
*file
, void *priv_fh
,
544 struct v4l2_dv_timings_cap
*cap
)
546 struct rvin_dev
*vin
= video_drvdata(file
);
547 struct v4l2_subdev
*sd
= vin_to_source(vin
);
551 cap
->pad
= vin
->src_pad_idx
;
553 ret
= v4l2_subdev_call(sd
, pad
, dv_timings_cap
, cap
);
560 static const struct v4l2_ioctl_ops rvin_ioctl_ops
= {
561 .vidioc_querycap
= rvin_querycap
,
562 .vidioc_try_fmt_vid_cap
= rvin_try_fmt_vid_cap
,
563 .vidioc_g_fmt_vid_cap
= rvin_g_fmt_vid_cap
,
564 .vidioc_s_fmt_vid_cap
= rvin_s_fmt_vid_cap
,
565 .vidioc_enum_fmt_vid_cap
= rvin_enum_fmt_vid_cap
,
567 .vidioc_g_selection
= rvin_g_selection
,
568 .vidioc_s_selection
= rvin_s_selection
,
570 .vidioc_cropcap
= rvin_cropcap
,
572 .vidioc_enum_input
= rvin_enum_input
,
573 .vidioc_g_input
= rvin_g_input
,
574 .vidioc_s_input
= rvin_s_input
,
576 .vidioc_dv_timings_cap
= rvin_dv_timings_cap
,
577 .vidioc_enum_dv_timings
= rvin_enum_dv_timings
,
578 .vidioc_g_dv_timings
= rvin_g_dv_timings
,
579 .vidioc_s_dv_timings
= rvin_s_dv_timings
,
580 .vidioc_query_dv_timings
= rvin_query_dv_timings
,
582 .vidioc_querystd
= rvin_querystd
,
583 .vidioc_g_std
= rvin_g_std
,
584 .vidioc_s_std
= rvin_s_std
,
586 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
587 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
588 .vidioc_querybuf
= vb2_ioctl_querybuf
,
589 .vidioc_qbuf
= vb2_ioctl_qbuf
,
590 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
591 .vidioc_expbuf
= vb2_ioctl_expbuf
,
592 .vidioc_prepare_buf
= vb2_ioctl_prepare_buf
,
593 .vidioc_streamon
= vb2_ioctl_streamon
,
594 .vidioc_streamoff
= vb2_ioctl_streamoff
,
596 .vidioc_log_status
= v4l2_ctrl_log_status
,
597 .vidioc_subscribe_event
= rvin_subscribe_event
,
598 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
601 /* -----------------------------------------------------------------------------
605 static int rvin_power_on(struct rvin_dev
*vin
)
608 struct v4l2_subdev
*sd
= vin_to_source(vin
);
610 pm_runtime_get_sync(vin
->v4l2_dev
.dev
);
612 ret
= v4l2_subdev_call(sd
, core
, s_power
, 1);
613 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
618 static int rvin_power_off(struct rvin_dev
*vin
)
621 struct v4l2_subdev
*sd
= vin_to_source(vin
);
623 ret
= v4l2_subdev_call(sd
, core
, s_power
, 0);
625 pm_runtime_put(vin
->v4l2_dev
.dev
);
627 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
633 static int rvin_initialize_device(struct file
*file
)
635 struct rvin_dev
*vin
= video_drvdata(file
);
638 struct v4l2_format f
= {
639 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
641 .width
= vin
->format
.width
,
642 .height
= vin
->format
.height
,
643 .field
= vin
->format
.field
,
644 .colorspace
= vin
->format
.colorspace
,
645 .pixelformat
= vin
->format
.pixelformat
,
649 ret
= rvin_power_on(vin
);
653 pm_runtime_enable(&vin
->vdev
.dev
);
654 ret
= pm_runtime_resume(&vin
->vdev
.dev
);
655 if (ret
< 0 && ret
!= -ENOSYS
)
659 * Try to configure with default parameters. Notice: this is the
660 * very first open, so, we cannot race against other calls,
661 * apart from someone else calling open() simultaneously, but
662 * .host_lock is protecting us against it.
664 ret
= rvin_s_fmt_vid_cap(file
, NULL
, &f
);
668 v4l2_ctrl_handler_setup(&vin
->ctrl_handler
);
672 pm_runtime_disable(&vin
->vdev
.dev
);
679 static int rvin_open(struct file
*file
)
681 struct rvin_dev
*vin
= video_drvdata(file
);
684 mutex_lock(&vin
->lock
);
686 file
->private_data
= vin
;
688 ret
= v4l2_fh_open(file
);
692 if (!v4l2_fh_is_singular_file(file
))
695 if (rvin_initialize_device(file
)) {
696 v4l2_fh_release(file
);
701 mutex_unlock(&vin
->lock
);
705 static int rvin_release(struct file
*file
)
707 struct rvin_dev
*vin
= video_drvdata(file
);
711 mutex_lock(&vin
->lock
);
713 /* Save the singular status before we call the clean-up helper */
714 fh_singular
= v4l2_fh_is_singular_file(file
);
716 /* the release helper will cleanup any on-going streaming */
717 ret
= _vb2_fop_release(file
, NULL
);
720 * If this was the last open file.
721 * Then de-initialize hw module.
724 pm_runtime_suspend(&vin
->vdev
.dev
);
725 pm_runtime_disable(&vin
->vdev
.dev
);
729 mutex_unlock(&vin
->lock
);
734 static const struct v4l2_file_operations rvin_fops
= {
735 .owner
= THIS_MODULE
,
736 .unlocked_ioctl
= video_ioctl2
,
738 .release
= rvin_release
,
739 .poll
= vb2_fop_poll
,
740 .mmap
= vb2_fop_mmap
,
741 .read
= vb2_fop_read
,
744 void rvin_v4l2_remove(struct rvin_dev
*vin
)
746 v4l2_info(&vin
->v4l2_dev
, "Removing %s\n",
747 video_device_node_name(&vin
->vdev
));
749 /* Checks internaly if handlers have been init or not */
750 v4l2_ctrl_handler_free(&vin
->ctrl_handler
);
752 /* Checks internaly if vdev have been init or not */
753 video_unregister_device(&vin
->vdev
);
756 static void rvin_notify(struct v4l2_subdev
*sd
,
757 unsigned int notification
, void *arg
)
759 struct rvin_dev
*vin
=
760 container_of(sd
->v4l2_dev
, struct rvin_dev
, v4l2_dev
);
762 switch (notification
) {
763 case V4L2_DEVICE_NOTIFY_EVENT
:
764 v4l2_event_queue(&vin
->vdev
, arg
);
771 int rvin_v4l2_probe(struct rvin_dev
*vin
)
773 struct v4l2_subdev_format fmt
= {
774 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
776 struct v4l2_mbus_framefmt
*mf
= &fmt
.format
;
777 struct video_device
*vdev
= &vin
->vdev
;
778 struct v4l2_subdev
*sd
= vin_to_source(vin
);
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 for (pad_idx
= 0; pad_idx
< sd
->entity
.num_pads
; pad_idx
++)
827 if (sd
->entity
.pads
[pad_idx
].flags
== MEDIA_PAD_FL_SOURCE
)
829 if (pad_idx
>= sd
->entity
.num_pads
)
832 vin
->src_pad_idx
= pad_idx
;
833 fmt
.pad
= vin
->src_pad_idx
;
835 /* Try to improve our guess of a reasonable window format */
836 ret
= v4l2_subdev_call(sd
, pad
, get_fmt
, NULL
, &fmt
);
838 vin_err(vin
, "Failed to get initial format\n");
842 /* Set default format */
843 vin
->format
.width
= mf
->width
;
844 vin
->format
.height
= mf
->height
;
845 vin
->format
.colorspace
= mf
->colorspace
;
846 vin
->format
.field
= mf
->field
;
847 vin
->format
.pixelformat
= RVIN_DEFAULT_FORMAT
;
850 /* Set initial crop and compose */
851 vin
->crop
.top
= vin
->crop
.left
= 0;
852 vin
->crop
.width
= mf
->width
;
853 vin
->crop
.height
= mf
->height
;
855 vin
->compose
.top
= vin
->compose
.left
= 0;
856 vin
->compose
.width
= mf
->width
;
857 vin
->compose
.height
= mf
->height
;
859 ret
= video_register_device(&vin
->vdev
, VFL_TYPE_GRABBER
, -1);
861 vin_err(vin
, "Failed to register video device\n");
865 video_set_drvdata(&vin
->vdev
, vin
);
867 v4l2_info(&vin
->v4l2_dev
, "Device registered as %s\n",
868 video_device_node_name(&vin
->vdev
));