1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for Renesas R-Car VIN
5 * Copyright (C) 2016 Renesas Electronics Corp.
6 * Copyright (C) 2011-2013 Renesas Solutions Corp.
7 * Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com>
8 * Copyright (C) 2008 Magnus Damm
10 * Based on the soc-camera rcar_vin driver
13 #include <linux/pm_runtime.h>
15 #include <media/v4l2-event.h>
16 #include <media/v4l2-ioctl.h>
17 #include <media/v4l2-mc.h>
18 #include <media/v4l2-rect.h>
22 #define RVIN_DEFAULT_FORMAT V4L2_PIX_FMT_YUYV
23 #define RVIN_DEFAULT_WIDTH 800
24 #define RVIN_DEFAULT_HEIGHT 600
25 #define RVIN_DEFAULT_FIELD V4L2_FIELD_NONE
26 #define RVIN_DEFAULT_COLORSPACE V4L2_COLORSPACE_SRGB
28 /* -----------------------------------------------------------------------------
32 static const struct rvin_video_format rvin_formats[] = {
34 .fourcc = V4L2_PIX_FMT_NV16,
38 .fourcc = V4L2_PIX_FMT_YUYV,
42 .fourcc = V4L2_PIX_FMT_UYVY,
46 .fourcc = V4L2_PIX_FMT_RGB565,
50 .fourcc = V4L2_PIX_FMT_XRGB555,
54 .fourcc = V4L2_PIX_FMT_XBGR32,
58 .fourcc = V4L2_PIX_FMT_ARGB555,
62 .fourcc = V4L2_PIX_FMT_ABGR32,
67 const struct rvin_video_format *rvin_format_from_pixel(struct rvin_dev *vin,
72 if (vin->info->model == RCAR_M1 && pixelformat == V4L2_PIX_FMT_XBGR32)
75 for (i = 0; i < ARRAY_SIZE(rvin_formats); i++)
76 if (rvin_formats[i].fourcc == pixelformat)
77 return rvin_formats + i;
82 static u32 rvin_format_bytesperline(struct rvin_dev *vin,
83 struct v4l2_pix_format *pix)
85 const struct rvin_video_format *fmt;
88 fmt = rvin_format_from_pixel(vin, pix->pixelformat);
93 align = pix->pixelformat == V4L2_PIX_FMT_NV16 ? 0x20 : 0x10;
95 return ALIGN(pix->width, align) * fmt->bpp;
98 static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix)
100 if (pix->pixelformat == V4L2_PIX_FMT_NV16)
101 return pix->bytesperline * pix->height * 2;
103 return pix->bytesperline * pix->height;
106 static void rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix)
110 if (!rvin_format_from_pixel(vin, pix->pixelformat))
111 pix->pixelformat = RVIN_DEFAULT_FORMAT;
113 switch (pix->field) {
115 case V4L2_FIELD_BOTTOM:
116 case V4L2_FIELD_NONE:
117 case V4L2_FIELD_INTERLACED_TB:
118 case V4L2_FIELD_INTERLACED_BT:
119 case V4L2_FIELD_INTERLACED:
121 case V4L2_FIELD_ALTERNATE:
123 * Driver does not (yet) support outputting ALTERNATE to a
124 * userspace. It does support outputting INTERLACED so use
125 * the VIN hardware to combine the two fields.
127 pix->field = V4L2_FIELD_INTERLACED;
131 pix->field = RVIN_DEFAULT_FIELD;
135 /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
136 walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
138 /* Limit to VIN capabilities */
139 v4l_bound_align_image(&pix->width, 2, vin->info->max_width, walign,
140 &pix->height, 4, vin->info->max_height, 2, 0);
142 pix->bytesperline = rvin_format_bytesperline(vin, pix);
143 pix->sizeimage = rvin_format_sizeimage(pix);
145 vin_dbg(vin, "Format %ux%u bpl: %u size: %u\n",
146 pix->width, pix->height, pix->bytesperline, pix->sizeimage);
149 /* -----------------------------------------------------------------------------
153 static int rvin_reset_format(struct rvin_dev *vin)
155 struct v4l2_subdev_format fmt = {
156 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
157 .pad = vin->parallel->source_pad,
161 ret = v4l2_subdev_call(vin_to_source(vin), pad, get_fmt, NULL, &fmt);
165 v4l2_fill_pix_format(&vin->format, &fmt.format);
167 rvin_format_align(vin, &vin->format);
169 vin->src_rect.top = 0;
170 vin->src_rect.left = 0;
171 vin->src_rect.width = vin->format.width;
172 vin->src_rect.height = vin->format.height;
174 vin->crop = vin->src_rect;
175 vin->compose = vin->src_rect;
180 static int rvin_try_format(struct rvin_dev *vin, u32 which,
181 struct v4l2_pix_format *pix,
182 struct v4l2_rect *crop, struct v4l2_rect *compose)
184 struct v4l2_subdev *sd = vin_to_source(vin);
185 struct v4l2_subdev_pad_config *pad_cfg;
186 struct v4l2_subdev_format format = {
188 .pad = vin->parallel->source_pad,
190 enum v4l2_field field;
194 pad_cfg = v4l2_subdev_alloc_pad_config(sd);
198 if (!rvin_format_from_pixel(vin, pix->pixelformat))
199 pix->pixelformat = RVIN_DEFAULT_FORMAT;
201 v4l2_fill_mbus_format(&format.format, pix, vin->mbus_code);
203 /* Allow the video device to override field and to scale */
206 height = pix->height;
208 ret = v4l2_subdev_call(sd, pad, set_fmt, pad_cfg, &format);
209 if (ret < 0 && ret != -ENOIOCTLCMD)
213 v4l2_fill_pix_format(pix, &format.format);
218 crop->width = pix->width;
219 crop->height = pix->height;
222 * If source is ALTERNATE the driver will use the VIN hardware
223 * to INTERLACE it. The crop height then needs to be doubled.
225 if (pix->field == V4L2_FIELD_ALTERNATE)
229 if (field != V4L2_FIELD_ANY)
233 pix->height = height;
235 rvin_format_align(vin, pix);
240 compose->width = pix->width;
241 compose->height = pix->height;
244 v4l2_subdev_free_pad_config(pad_cfg);
249 static int rvin_querycap(struct file *file, void *priv,
250 struct v4l2_capability *cap)
252 struct rvin_dev *vin = video_drvdata(file);
254 strscpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver));
255 strscpy(cap->card, "R_Car_VIN", sizeof(cap->card));
256 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
261 static int rvin_try_fmt_vid_cap(struct file *file, void *priv,
262 struct v4l2_format *f)
264 struct rvin_dev *vin = video_drvdata(file);
266 return rvin_try_format(vin, V4L2_SUBDEV_FORMAT_TRY, &f->fmt.pix, NULL,
270 static int rvin_s_fmt_vid_cap(struct file *file, void *priv,
271 struct v4l2_format *f)
273 struct rvin_dev *vin = video_drvdata(file);
274 struct v4l2_rect crop, compose;
277 if (vb2_is_busy(&vin->queue))
280 ret = rvin_try_format(vin, V4L2_SUBDEV_FORMAT_ACTIVE, &f->fmt.pix,
285 vin->format = f->fmt.pix;
286 v4l2_rect_map_inside(&vin->crop, &crop);
287 v4l2_rect_map_inside(&vin->compose, &compose);
288 vin->src_rect = crop;
293 static int rvin_g_fmt_vid_cap(struct file *file, void *priv,
294 struct v4l2_format *f)
296 struct rvin_dev *vin = video_drvdata(file);
298 f->fmt.pix = vin->format;
303 static int rvin_enum_fmt_vid_cap(struct file *file, void *priv,
304 struct v4l2_fmtdesc *f)
306 if (f->index >= ARRAY_SIZE(rvin_formats))
309 f->pixelformat = rvin_formats[f->index].fourcc;
314 static int rvin_g_selection(struct file *file, void *fh,
315 struct v4l2_selection *s)
317 struct rvin_dev *vin = video_drvdata(file);
319 if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
323 case V4L2_SEL_TGT_CROP_BOUNDS:
324 case V4L2_SEL_TGT_CROP_DEFAULT:
325 s->r.left = s->r.top = 0;
326 s->r.width = vin->src_rect.width;
327 s->r.height = vin->src_rect.height;
329 case V4L2_SEL_TGT_CROP:
332 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
333 case V4L2_SEL_TGT_COMPOSE_DEFAULT:
334 s->r.left = s->r.top = 0;
335 s->r.width = vin->format.width;
336 s->r.height = vin->format.height;
338 case V4L2_SEL_TGT_COMPOSE:
348 static int rvin_s_selection(struct file *file, void *fh,
349 struct v4l2_selection *s)
351 struct rvin_dev *vin = video_drvdata(file);
352 const struct rvin_video_format *fmt;
353 struct v4l2_rect r = s->r;
354 struct v4l2_rect max_rect;
355 struct v4l2_rect min_rect = {
360 if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
363 v4l2_rect_set_min_size(&r, &min_rect);
366 case V4L2_SEL_TGT_CROP:
367 /* Can't crop outside of source input */
368 max_rect.top = max_rect.left = 0;
369 max_rect.width = vin->src_rect.width;
370 max_rect.height = vin->src_rect.height;
371 v4l2_rect_map_inside(&r, &max_rect);
373 v4l_bound_align_image(&r.width, 6, vin->src_rect.width, 0,
374 &r.height, 2, vin->src_rect.height, 0, 0);
376 r.top = clamp_t(s32, r.top, 0,
377 vin->src_rect.height - r.height);
378 r.left = clamp_t(s32, r.left, 0, vin->src_rect.width - r.width);
380 vin->crop = s->r = r;
382 vin_dbg(vin, "Cropped %dx%d@%d:%d of %dx%d\n",
383 r.width, r.height, r.left, r.top,
384 vin->src_rect.width, vin->src_rect.height);
386 case V4L2_SEL_TGT_COMPOSE:
387 /* Make sure compose rect fits inside output format */
388 max_rect.top = max_rect.left = 0;
389 max_rect.width = vin->format.width;
390 max_rect.height = vin->format.height;
391 v4l2_rect_map_inside(&r, &max_rect);
394 * Composing is done by adding a offset to the buffer address,
395 * the HW wants this address to be aligned to HW_BUFFER_MASK.
396 * Make sure the top and left values meets this requirement.
398 while ((r.top * vin->format.bytesperline) & HW_BUFFER_MASK)
401 fmt = rvin_format_from_pixel(vin, vin->format.pixelformat);
402 while ((r.left * fmt->bpp) & HW_BUFFER_MASK)
405 vin->compose = s->r = r;
407 vin_dbg(vin, "Compose %dx%d@%d:%d in %dx%d\n",
408 r.width, r.height, r.left, r.top,
409 vin->format.width, vin->format.height);
415 /* HW supports modifying configuration while running */
416 rvin_crop_scale_comp(vin);
421 static int rvin_g_pixelaspect(struct file *file, void *priv,
422 int type, struct v4l2_fract *f)
424 struct rvin_dev *vin = video_drvdata(file);
425 struct v4l2_subdev *sd = vin_to_source(vin);
427 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
430 return v4l2_subdev_call(sd, video, g_pixelaspect, f);
433 static int rvin_enum_input(struct file *file, void *priv,
434 struct v4l2_input *i)
436 struct rvin_dev *vin = video_drvdata(file);
437 struct v4l2_subdev *sd = vin_to_source(vin);
443 ret = v4l2_subdev_call(sd, video, g_input_status, &i->status);
444 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
447 i->type = V4L2_INPUT_TYPE_CAMERA;
449 if (v4l2_subdev_has_op(sd, pad, dv_timings_cap)) {
450 i->capabilities = V4L2_IN_CAP_DV_TIMINGS;
453 i->capabilities = V4L2_IN_CAP_STD;
454 i->std = vin->vdev.tvnorms;
457 strscpy(i->name, "Camera", sizeof(i->name));
462 static int rvin_g_input(struct file *file, void *priv, unsigned int *i)
468 static int rvin_s_input(struct file *file, void *priv, unsigned int i)
475 static int rvin_querystd(struct file *file, void *priv, v4l2_std_id *a)
477 struct rvin_dev *vin = video_drvdata(file);
478 struct v4l2_subdev *sd = vin_to_source(vin);
480 return v4l2_subdev_call(sd, video, querystd, a);
483 static int rvin_s_std(struct file *file, void *priv, v4l2_std_id a)
485 struct rvin_dev *vin = video_drvdata(file);
488 ret = v4l2_subdev_call(vin_to_source(vin), video, s_std, a);
494 /* Changing the standard will change the width/height */
495 return rvin_reset_format(vin);
498 static int rvin_g_std(struct file *file, void *priv, v4l2_std_id *a)
500 struct rvin_dev *vin = video_drvdata(file);
502 if (v4l2_subdev_has_op(vin_to_source(vin), pad, dv_timings_cap))
510 static int rvin_subscribe_event(struct v4l2_fh *fh,
511 const struct v4l2_event_subscription *sub)
514 case V4L2_EVENT_SOURCE_CHANGE:
515 return v4l2_event_subscribe(fh, sub, 4, NULL);
517 return v4l2_ctrl_subscribe_event(fh, sub);
520 static int rvin_enum_dv_timings(struct file *file, void *priv_fh,
521 struct v4l2_enum_dv_timings *timings)
523 struct rvin_dev *vin = video_drvdata(file);
524 struct v4l2_subdev *sd = vin_to_source(vin);
530 timings->pad = vin->parallel->sink_pad;
532 ret = v4l2_subdev_call(sd, pad, enum_dv_timings, timings);
539 static int rvin_s_dv_timings(struct file *file, void *priv_fh,
540 struct v4l2_dv_timings *timings)
542 struct rvin_dev *vin = video_drvdata(file);
543 struct v4l2_subdev *sd = vin_to_source(vin);
546 ret = v4l2_subdev_call(sd, video, s_dv_timings, timings);
550 /* Changing the timings will change the width/height */
551 return rvin_reset_format(vin);
554 static int rvin_g_dv_timings(struct file *file, void *priv_fh,
555 struct v4l2_dv_timings *timings)
557 struct rvin_dev *vin = video_drvdata(file);
558 struct v4l2_subdev *sd = vin_to_source(vin);
560 return v4l2_subdev_call(sd, video, g_dv_timings, timings);
563 static int rvin_query_dv_timings(struct file *file, void *priv_fh,
564 struct v4l2_dv_timings *timings)
566 struct rvin_dev *vin = video_drvdata(file);
567 struct v4l2_subdev *sd = vin_to_source(vin);
569 return v4l2_subdev_call(sd, video, query_dv_timings, timings);
572 static int rvin_dv_timings_cap(struct file *file, void *priv_fh,
573 struct v4l2_dv_timings_cap *cap)
575 struct rvin_dev *vin = video_drvdata(file);
576 struct v4l2_subdev *sd = vin_to_source(vin);
582 cap->pad = vin->parallel->sink_pad;
584 ret = v4l2_subdev_call(sd, pad, dv_timings_cap, cap);
591 static int rvin_g_edid(struct file *file, void *fh, struct v4l2_edid *edid)
593 struct rvin_dev *vin = video_drvdata(file);
594 struct v4l2_subdev *sd = vin_to_source(vin);
600 edid->pad = vin->parallel->sink_pad;
602 ret = v4l2_subdev_call(sd, pad, get_edid, edid);
609 static int rvin_s_edid(struct file *file, void *fh, struct v4l2_edid *edid)
611 struct rvin_dev *vin = video_drvdata(file);
612 struct v4l2_subdev *sd = vin_to_source(vin);
618 edid->pad = vin->parallel->sink_pad;
620 ret = v4l2_subdev_call(sd, pad, set_edid, edid);
627 static const struct v4l2_ioctl_ops rvin_ioctl_ops = {
628 .vidioc_querycap = rvin_querycap,
629 .vidioc_try_fmt_vid_cap = rvin_try_fmt_vid_cap,
630 .vidioc_g_fmt_vid_cap = rvin_g_fmt_vid_cap,
631 .vidioc_s_fmt_vid_cap = rvin_s_fmt_vid_cap,
632 .vidioc_enum_fmt_vid_cap = rvin_enum_fmt_vid_cap,
634 .vidioc_g_selection = rvin_g_selection,
635 .vidioc_s_selection = rvin_s_selection,
637 .vidioc_g_pixelaspect = rvin_g_pixelaspect,
639 .vidioc_enum_input = rvin_enum_input,
640 .vidioc_g_input = rvin_g_input,
641 .vidioc_s_input = rvin_s_input,
643 .vidioc_dv_timings_cap = rvin_dv_timings_cap,
644 .vidioc_enum_dv_timings = rvin_enum_dv_timings,
645 .vidioc_g_dv_timings = rvin_g_dv_timings,
646 .vidioc_s_dv_timings = rvin_s_dv_timings,
647 .vidioc_query_dv_timings = rvin_query_dv_timings,
649 .vidioc_g_edid = rvin_g_edid,
650 .vidioc_s_edid = rvin_s_edid,
652 .vidioc_querystd = rvin_querystd,
653 .vidioc_g_std = rvin_g_std,
654 .vidioc_s_std = rvin_s_std,
656 .vidioc_reqbufs = vb2_ioctl_reqbufs,
657 .vidioc_create_bufs = vb2_ioctl_create_bufs,
658 .vidioc_querybuf = vb2_ioctl_querybuf,
659 .vidioc_qbuf = vb2_ioctl_qbuf,
660 .vidioc_dqbuf = vb2_ioctl_dqbuf,
661 .vidioc_expbuf = vb2_ioctl_expbuf,
662 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
663 .vidioc_streamon = vb2_ioctl_streamon,
664 .vidioc_streamoff = vb2_ioctl_streamoff,
666 .vidioc_log_status = v4l2_ctrl_log_status,
667 .vidioc_subscribe_event = rvin_subscribe_event,
668 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
671 /* -----------------------------------------------------------------------------
672 * V4L2 Media Controller
675 static void rvin_mc_try_format(struct rvin_dev *vin,
676 struct v4l2_pix_format *pix)
679 * The V4L2 specification clearly documents the colorspace fields
680 * as being set by drivers for capture devices. Using the values
681 * supplied by userspace thus wouldn't comply with the API. Until
682 * the API is updated force fixed values.
684 pix->colorspace = RVIN_DEFAULT_COLORSPACE;
685 pix->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(pix->colorspace);
686 pix->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(pix->colorspace);
687 pix->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true, pix->colorspace,
690 rvin_format_align(vin, pix);
693 static int rvin_mc_try_fmt_vid_cap(struct file *file, void *priv,
694 struct v4l2_format *f)
696 struct rvin_dev *vin = video_drvdata(file);
698 rvin_mc_try_format(vin, &f->fmt.pix);
703 static int rvin_mc_s_fmt_vid_cap(struct file *file, void *priv,
704 struct v4l2_format *f)
706 struct rvin_dev *vin = video_drvdata(file);
708 if (vb2_is_busy(&vin->queue))
711 rvin_mc_try_format(vin, &f->fmt.pix);
713 vin->format = f->fmt.pix;
717 vin->crop.width = vin->format.width;
718 vin->crop.height = vin->format.height;
719 vin->compose = vin->crop;
724 static int rvin_mc_enum_input(struct file *file, void *priv,
725 struct v4l2_input *i)
730 i->type = V4L2_INPUT_TYPE_CAMERA;
731 strscpy(i->name, "Camera", sizeof(i->name));
736 static const struct v4l2_ioctl_ops rvin_mc_ioctl_ops = {
737 .vidioc_querycap = rvin_querycap,
738 .vidioc_try_fmt_vid_cap = rvin_mc_try_fmt_vid_cap,
739 .vidioc_g_fmt_vid_cap = rvin_g_fmt_vid_cap,
740 .vidioc_s_fmt_vid_cap = rvin_mc_s_fmt_vid_cap,
741 .vidioc_enum_fmt_vid_cap = rvin_enum_fmt_vid_cap,
743 .vidioc_enum_input = rvin_mc_enum_input,
744 .vidioc_g_input = rvin_g_input,
745 .vidioc_s_input = rvin_s_input,
747 .vidioc_reqbufs = vb2_ioctl_reqbufs,
748 .vidioc_create_bufs = vb2_ioctl_create_bufs,
749 .vidioc_querybuf = vb2_ioctl_querybuf,
750 .vidioc_qbuf = vb2_ioctl_qbuf,
751 .vidioc_dqbuf = vb2_ioctl_dqbuf,
752 .vidioc_expbuf = vb2_ioctl_expbuf,
753 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
754 .vidioc_streamon = vb2_ioctl_streamon,
755 .vidioc_streamoff = vb2_ioctl_streamoff,
757 .vidioc_log_status = v4l2_ctrl_log_status,
758 .vidioc_subscribe_event = rvin_subscribe_event,
759 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
762 /* -----------------------------------------------------------------------------
766 static int rvin_power_parallel(struct rvin_dev *vin, bool on)
768 struct v4l2_subdev *sd = vin_to_source(vin);
769 int power = on ? 1 : 0;
772 ret = v4l2_subdev_call(sd, core, s_power, power);
773 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
779 static int rvin_open(struct file *file)
781 struct rvin_dev *vin = video_drvdata(file);
784 ret = pm_runtime_get_sync(vin->dev);
788 ret = mutex_lock_interruptible(&vin->lock);
792 file->private_data = vin;
794 ret = v4l2_fh_open(file);
798 if (vin->info->use_mc)
799 ret = v4l2_pipeline_pm_use(&vin->vdev.entity, 1);
800 else if (v4l2_fh_is_singular_file(file))
801 ret = rvin_power_parallel(vin, true);
806 ret = v4l2_ctrl_handler_setup(&vin->ctrl_handler);
810 mutex_unlock(&vin->lock);
814 if (vin->info->use_mc)
815 v4l2_pipeline_pm_use(&vin->vdev.entity, 0);
816 else if (v4l2_fh_is_singular_file(file))
817 rvin_power_parallel(vin, false);
819 v4l2_fh_release(file);
821 mutex_unlock(&vin->lock);
823 pm_runtime_put(vin->dev);
828 static int rvin_release(struct file *file)
830 struct rvin_dev *vin = video_drvdata(file);
834 mutex_lock(&vin->lock);
836 /* Save the singular status before we call the clean-up helper */
837 fh_singular = v4l2_fh_is_singular_file(file);
839 /* the release helper will cleanup any on-going streaming */
840 ret = _vb2_fop_release(file, NULL);
842 if (vin->info->use_mc) {
843 v4l2_pipeline_pm_use(&vin->vdev.entity, 0);
846 rvin_power_parallel(vin, false);
849 mutex_unlock(&vin->lock);
851 pm_runtime_put(vin->dev);
856 static const struct v4l2_file_operations rvin_fops = {
857 .owner = THIS_MODULE,
858 .unlocked_ioctl = video_ioctl2,
860 .release = rvin_release,
861 .poll = vb2_fop_poll,
862 .mmap = vb2_fop_mmap,
863 .read = vb2_fop_read,
866 void rvin_v4l2_unregister(struct rvin_dev *vin)
868 if (!video_is_registered(&vin->vdev))
871 v4l2_info(&vin->v4l2_dev, "Removing %s\n",
872 video_device_node_name(&vin->vdev));
874 /* Checks internally if vdev have been init or not */
875 video_unregister_device(&vin->vdev);
878 static void rvin_notify(struct v4l2_subdev *sd,
879 unsigned int notification, void *arg)
881 struct rvin_dev *vin =
882 container_of(sd->v4l2_dev, struct rvin_dev, v4l2_dev);
884 switch (notification) {
885 case V4L2_DEVICE_NOTIFY_EVENT:
886 v4l2_event_queue(&vin->vdev, arg);
893 int rvin_v4l2_register(struct rvin_dev *vin)
895 struct video_device *vdev = &vin->vdev;
898 vin->v4l2_dev.notify = rvin_notify;
901 vdev->v4l2_dev = &vin->v4l2_dev;
902 vdev->queue = &vin->queue;
903 snprintf(vdev->name, sizeof(vdev->name), "VIN%u output", vin->id);
904 vdev->release = video_device_release_empty;
905 vdev->lock = &vin->lock;
906 vdev->fops = &rvin_fops;
907 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
910 /* Set a default format */
911 vin->format.pixelformat = RVIN_DEFAULT_FORMAT;
912 vin->format.width = RVIN_DEFAULT_WIDTH;
913 vin->format.height = RVIN_DEFAULT_HEIGHT;
914 vin->format.field = RVIN_DEFAULT_FIELD;
915 vin->format.colorspace = RVIN_DEFAULT_COLORSPACE;
917 if (vin->info->use_mc) {
918 vdev->ioctl_ops = &rvin_mc_ioctl_ops;
920 vdev->ioctl_ops = &rvin_ioctl_ops;
921 rvin_reset_format(vin);
924 rvin_format_align(vin, &vin->format);
926 ret = video_register_device(&vin->vdev, VFL_TYPE_GRABBER, -1);
928 vin_err(vin, "Failed to register video device\n");
932 video_set_drvdata(&vin->vdev, vin);
934 v4l2_info(&vin->v4l2_dev, "Device registered as %s\n",
935 video_device_node_name(&vin->vdev));