Lines Matching full:vin

3  * Driver for Renesas R-Car VIN
20 #include "rcar-vin.h"
91 const struct rvin_video_format *rvin_format_from_pixel(struct rvin_dev *vin, in rvin_format_from_pixel() argument
98 if (vin->info->model == RCAR_M1) in rvin_format_from_pixel()
106 if (!vin->info->nv12 || !(BIT(vin->id) & 0x3333)) in rvin_format_from_pixel()
120 static u32 rvin_format_bytesperline(struct rvin_dev *vin, in rvin_format_bytesperline() argument
126 fmt = rvin_format_from_pixel(vin, pix->pixelformat); in rvin_format_bytesperline()
159 static void rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix) in rvin_format_align() argument
163 if (!rvin_format_from_pixel(vin, pix->pixelformat)) in rvin_format_align()
200 /* Limit to VIN capabilities */ in rvin_format_align()
201 v4l_bound_align_image(&pix->width, 5, vin->info->max_width, walign, in rvin_format_align()
202 &pix->height, 2, vin->info->max_height, 0, 0); in rvin_format_align()
204 pix->bytesperline = rvin_format_bytesperline(vin, pix); in rvin_format_align()
207 vin_dbg(vin, "Format %ux%u bpl: %u size: %u\n", in rvin_format_align()
215 static int rvin_reset_format(struct rvin_dev *vin) in rvin_reset_format() argument
219 .pad = vin->parallel.source_pad, in rvin_reset_format()
223 ret = v4l2_subdev_call(vin_to_source(vin), pad, get_fmt, NULL, &fmt); in rvin_reset_format()
227 v4l2_fill_pix_format(&vin->format, &fmt.format); in rvin_reset_format()
229 vin->src_rect.top = 0; in rvin_reset_format()
230 vin->src_rect.left = 0; in rvin_reset_format()
231 vin->src_rect.width = vin->format.width; in rvin_reset_format()
232 vin->src_rect.height = vin->format.height; in rvin_reset_format()
235 if (vin->format.field == V4L2_FIELD_ALTERNATE) { in rvin_reset_format()
236 vin->format.field = V4L2_FIELD_INTERLACED; in rvin_reset_format()
237 vin->format.height *= 2; in rvin_reset_format()
240 rvin_format_align(vin, &vin->format); in rvin_reset_format()
242 vin->crop = vin->src_rect; in rvin_reset_format()
244 vin->compose.top = 0; in rvin_reset_format()
245 vin->compose.left = 0; in rvin_reset_format()
246 vin->compose.width = vin->format.width; in rvin_reset_format()
247 vin->compose.height = vin->format.height; in rvin_reset_format()
252 static int rvin_try_format(struct rvin_dev *vin, u32 which, in rvin_try_format() argument
256 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_try_format()
261 .pad = vin->parallel.source_pad, in rvin_try_format()
275 if (!rvin_format_from_pixel(vin, pix->pixelformat)) in rvin_try_format()
278 v4l2_fill_mbus_format(&format.format, pix, vin->mbus_code); in rvin_try_format()
305 rvin_format_align(vin, pix); in rvin_try_format()
323 struct rvin_dev *vin = video_drvdata(file); in rvin_try_fmt_vid_cap() local
325 return rvin_try_format(vin, V4L2_SUBDEV_FORMAT_TRY, &f->fmt.pix, NULL); in rvin_try_fmt_vid_cap()
331 struct rvin_dev *vin = video_drvdata(file); in rvin_s_fmt_vid_cap() local
335 if (vb2_is_busy(&vin->queue)) in rvin_s_fmt_vid_cap()
338 ret = rvin_try_format(vin, V4L2_SUBDEV_FORMAT_ACTIVE, &f->fmt.pix, in rvin_s_fmt_vid_cap()
343 vin->format = f->fmt.pix; in rvin_s_fmt_vid_cap()
347 fmt_rect.width = vin->format.width; in rvin_s_fmt_vid_cap()
348 fmt_rect.height = vin->format.height; in rvin_s_fmt_vid_cap()
350 v4l2_rect_map_inside(&vin->crop, &src_rect); in rvin_s_fmt_vid_cap()
351 v4l2_rect_map_inside(&vin->compose, &fmt_rect); in rvin_s_fmt_vid_cap()
352 vin->src_rect = src_rect; in rvin_s_fmt_vid_cap()
360 struct rvin_dev *vin = video_drvdata(file); in rvin_g_fmt_vid_cap() local
362 f->fmt.pix = vin->format; in rvin_g_fmt_vid_cap()
370 struct rvin_dev *vin = video_drvdata(file); in rvin_enum_fmt_vid_cap() local
377 * with VIN, so all supported YCbCr and RGB media bus codes can produce in rvin_enum_fmt_vid_cap()
419 if (rvin_format_from_pixel(vin, rvin_formats[i].fourcc)) in rvin_enum_fmt_vid_cap()
434 struct rvin_dev *vin = video_drvdata(file); in rvin_g_selection() local
443 s->r.width = vin->src_rect.width; in rvin_g_selection()
444 s->r.height = vin->src_rect.height; in rvin_g_selection()
447 s->r = vin->crop; in rvin_g_selection()
452 s->r.width = vin->format.width; in rvin_g_selection()
453 s->r.height = vin->format.height; in rvin_g_selection()
456 s->r = vin->compose; in rvin_g_selection()
468 struct rvin_dev *vin = video_drvdata(file); in rvin_s_selection() local
486 max_rect.width = vin->src_rect.width; in rvin_s_selection()
487 max_rect.height = vin->src_rect.height; in rvin_s_selection()
490 v4l_bound_align_image(&r.width, 6, vin->src_rect.width, 0, in rvin_s_selection()
491 &r.height, 2, vin->src_rect.height, 0, 0); in rvin_s_selection()
494 vin->src_rect.height - r.height); in rvin_s_selection()
495 r.left = clamp_t(s32, r.left, 0, vin->src_rect.width - r.width); in rvin_s_selection()
497 vin->crop = s->r = r; in rvin_s_selection()
499 vin_dbg(vin, "Cropped %dx%d@%d:%d of %dx%d\n", in rvin_s_selection()
501 vin->src_rect.width, vin->src_rect.height); in rvin_s_selection()
506 max_rect.width = vin->format.width; in rvin_s_selection()
507 max_rect.height = vin->format.height; in rvin_s_selection()
515 while ((r.top * vin->format.bytesperline) & HW_BUFFER_MASK) in rvin_s_selection()
518 fmt = rvin_format_from_pixel(vin, vin->format.pixelformat); in rvin_s_selection()
522 vin->compose = s->r = r; in rvin_s_selection()
524 vin_dbg(vin, "Compose %dx%d@%d:%d in %dx%d\n", in rvin_s_selection()
526 vin->format.width, vin->format.height); in rvin_s_selection()
533 rvin_crop_scale_comp(vin); in rvin_s_selection()
541 struct rvin_dev *vin = video_drvdata(file); in rvin_g_parm() local
542 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_g_parm()
544 return v4l2_g_parm_cap(&vin->vdev, sd, parm); in rvin_g_parm()
550 struct rvin_dev *vin = video_drvdata(file); in rvin_s_parm() local
551 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_s_parm()
553 return v4l2_s_parm_cap(&vin->vdev, sd, parm); in rvin_s_parm()
559 struct rvin_dev *vin = video_drvdata(file); in rvin_g_pixelaspect() local
560 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_g_pixelaspect()
571 struct rvin_dev *vin = video_drvdata(file); in rvin_enum_input() local
572 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_enum_input()
589 i->std = vin->vdev.tvnorms; in rvin_enum_input()
612 struct rvin_dev *vin = video_drvdata(file); in rvin_querystd() local
613 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_querystd()
620 struct rvin_dev *vin = video_drvdata(file); in rvin_s_std() local
623 ret = v4l2_subdev_call(vin_to_source(vin), video, s_std, a); in rvin_s_std()
627 vin->std = a; in rvin_s_std()
630 return rvin_reset_format(vin); in rvin_s_std()
635 struct rvin_dev *vin = video_drvdata(file); in rvin_g_std() local
637 if (v4l2_subdev_has_op(vin_to_source(vin), pad, dv_timings_cap)) in rvin_g_std()
640 *a = vin->std; in rvin_g_std()
658 struct rvin_dev *vin = video_drvdata(file); in rvin_enum_dv_timings() local
659 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_enum_dv_timings()
665 timings->pad = vin->parallel.sink_pad; in rvin_enum_dv_timings()
677 struct rvin_dev *vin = video_drvdata(file); in rvin_s_dv_timings() local
678 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_s_dv_timings()
686 return rvin_reset_format(vin); in rvin_s_dv_timings()
692 struct rvin_dev *vin = video_drvdata(file); in rvin_g_dv_timings() local
693 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_g_dv_timings()
701 struct rvin_dev *vin = video_drvdata(file); in rvin_query_dv_timings() local
702 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_query_dv_timings()
710 struct rvin_dev *vin = video_drvdata(file); in rvin_dv_timings_cap() local
711 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_dv_timings_cap()
717 cap->pad = vin->parallel.sink_pad; in rvin_dv_timings_cap()
728 struct rvin_dev *vin = video_drvdata(file); in rvin_g_edid() local
729 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_g_edid()
735 edid->pad = vin->parallel.sink_pad; in rvin_g_edid()
746 struct rvin_dev *vin = video_drvdata(file); in rvin_s_edid() local
747 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_s_edid()
753 edid->pad = vin->parallel.sink_pad; in rvin_s_edid()
813 static void rvin_mc_try_format(struct rvin_dev *vin, in rvin_mc_try_format() argument
828 rvin_format_align(vin, pix); in rvin_mc_try_format()
834 struct rvin_dev *vin = video_drvdata(file); in rvin_mc_try_fmt_vid_cap() local
836 rvin_mc_try_format(vin, &f->fmt.pix); in rvin_mc_try_fmt_vid_cap()
844 struct rvin_dev *vin = video_drvdata(file); in rvin_mc_s_fmt_vid_cap() local
846 if (vb2_is_busy(&vin->queue)) in rvin_mc_s_fmt_vid_cap()
849 rvin_mc_try_format(vin, &f->fmt.pix); in rvin_mc_s_fmt_vid_cap()
851 vin->format = f->fmt.pix; in rvin_mc_s_fmt_vid_cap()
853 vin->crop.top = 0; in rvin_mc_s_fmt_vid_cap()
854 vin->crop.left = 0; in rvin_mc_s_fmt_vid_cap()
855 vin->crop.width = vin->format.width; in rvin_mc_s_fmt_vid_cap()
856 vin->crop.height = vin->format.height; in rvin_mc_s_fmt_vid_cap()
857 vin->compose = vin->crop; in rvin_mc_s_fmt_vid_cap()
888 static int rvin_power_parallel(struct rvin_dev *vin, bool on) in rvin_power_parallel() argument
890 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_power_parallel()
903 struct rvin_dev *vin = video_drvdata(file); in rvin_open() local
906 ret = pm_runtime_resume_and_get(vin->dev); in rvin_open()
910 ret = mutex_lock_interruptible(&vin->lock); in rvin_open()
914 file->private_data = vin; in rvin_open()
920 if (vin->info->use_mc) in rvin_open()
921 ret = v4l2_pipeline_pm_get(&vin->vdev.entity); in rvin_open()
923 ret = rvin_power_parallel(vin, true); in rvin_open()
928 ret = v4l2_ctrl_handler_setup(&vin->ctrl_handler); in rvin_open()
932 mutex_unlock(&vin->lock); in rvin_open()
936 if (vin->info->use_mc) in rvin_open()
937 v4l2_pipeline_pm_put(&vin->vdev.entity); in rvin_open()
939 rvin_power_parallel(vin, false); in rvin_open()
943 mutex_unlock(&vin->lock); in rvin_open()
945 pm_runtime_put(vin->dev); in rvin_open()
952 struct rvin_dev *vin = video_drvdata(file); in rvin_release() local
956 mutex_lock(&vin->lock); in rvin_release()
964 if (vin->info->use_mc) { in rvin_release()
965 v4l2_pipeline_pm_put(&vin->vdev.entity); in rvin_release()
968 rvin_power_parallel(vin, false); in rvin_release()
971 mutex_unlock(&vin->lock); in rvin_release()
973 pm_runtime_put(vin->dev); in rvin_release()
988 void rvin_v4l2_unregister(struct rvin_dev *vin) in rvin_v4l2_unregister() argument
990 if (!video_is_registered(&vin->vdev)) in rvin_v4l2_unregister()
993 v4l2_info(&vin->v4l2_dev, "Removing %s\n", in rvin_v4l2_unregister()
994 video_device_node_name(&vin->vdev)); in rvin_v4l2_unregister()
997 video_unregister_device(&vin->vdev); in rvin_v4l2_unregister()
1000 static void rvin_notify_video_device(struct rvin_dev *vin, in rvin_notify_video_device() argument
1005 v4l2_event_queue(&vin->vdev, arg); in rvin_notify_video_device()
1018 struct rvin_dev *vin = in rvin_notify() local
1023 if (!vin->info->use_mc) { in rvin_notify()
1024 rvin_notify_video_device(vin, notification, arg); in rvin_notify()
1028 group = vin->group; in rvin_notify()
1031 vin = group->vin[i]; in rvin_notify()
1032 if (!vin) in rvin_notify()
1035 pad = media_pad_remote_pad_first(&vin->pad); in rvin_notify()
1043 rvin_notify_video_device(vin, notification, arg); in rvin_notify()
1047 int rvin_v4l2_register(struct rvin_dev *vin) in rvin_v4l2_register() argument
1049 struct video_device *vdev = &vin->vdev; in rvin_v4l2_register()
1052 vin->v4l2_dev.notify = rvin_notify; in rvin_v4l2_register()
1055 vdev->v4l2_dev = &vin->v4l2_dev; in rvin_v4l2_register()
1056 vdev->queue = &vin->queue; in rvin_v4l2_register()
1057 snprintf(vdev->name, sizeof(vdev->name), "VIN%u output", vin->id); in rvin_v4l2_register()
1059 vdev->lock = &vin->lock; in rvin_v4l2_register()
1065 vin->format.pixelformat = RVIN_DEFAULT_FORMAT; in rvin_v4l2_register()
1066 vin->format.width = RVIN_DEFAULT_WIDTH; in rvin_v4l2_register()
1067 vin->format.height = RVIN_DEFAULT_HEIGHT; in rvin_v4l2_register()
1068 vin->format.field = RVIN_DEFAULT_FIELD; in rvin_v4l2_register()
1069 vin->format.colorspace = RVIN_DEFAULT_COLORSPACE; in rvin_v4l2_register()
1071 if (vin->info->use_mc) { in rvin_v4l2_register()
1076 rvin_reset_format(vin); in rvin_v4l2_register()
1079 rvin_format_align(vin, &vin->format); in rvin_v4l2_register()
1081 ret = video_register_device(&vin->vdev, VFL_TYPE_VIDEO, -1); in rvin_v4l2_register()
1083 vin_err(vin, "Failed to register video device\n"); in rvin_v4l2_register()
1087 video_set_drvdata(&vin->vdev, vin); in rvin_v4l2_register()
1089 v4l2_info(&vin->v4l2_dev, "Device registered as %s\n", in rvin_v4l2_register()
1090 video_device_node_name(&vin->vdev)); in rvin_v4l2_register()