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->crop.top = 0; in rvin_reset_format()
230 vin->crop.left = 0; in rvin_reset_format()
231 vin->crop.width = vin->format.width; in rvin_reset_format()
232 vin->crop.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->compose.top = 0; in rvin_reset_format()
243 vin->compose.left = 0; in rvin_reset_format()
244 vin->compose.width = vin->format.width; in rvin_reset_format()
245 vin->compose.height = vin->format.height; in rvin_reset_format()
250 static int rvin_try_format(struct rvin_dev *vin, u32 which, in rvin_try_format() argument
254 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_try_format()
259 .pad = vin->parallel.source_pad, in rvin_try_format()
273 if (!rvin_format_from_pixel(vin, pix->pixelformat)) in rvin_try_format()
276 v4l2_fill_mbus_format(&format.format, pix, vin->mbus_code); in rvin_try_format()
303 rvin_format_align(vin, pix); in rvin_try_format()
321 struct rvin_dev *vin = video_drvdata(file); in rvin_try_fmt_vid_cap() local
323 return rvin_try_format(vin, V4L2_SUBDEV_FORMAT_TRY, &f->fmt.pix, NULL); in rvin_try_fmt_vid_cap()
329 struct rvin_dev *vin = video_drvdata(file); in rvin_s_fmt_vid_cap() local
333 if (vb2_is_busy(&vin->queue)) in rvin_s_fmt_vid_cap()
336 ret = rvin_try_format(vin, V4L2_SUBDEV_FORMAT_ACTIVE, &f->fmt.pix, in rvin_s_fmt_vid_cap()
341 vin->format = f->fmt.pix; in rvin_s_fmt_vid_cap()
345 fmt_rect.width = vin->format.width; in rvin_s_fmt_vid_cap()
346 fmt_rect.height = vin->format.height; in rvin_s_fmt_vid_cap()
348 v4l2_rect_map_inside(&vin->crop, &src_rect); in rvin_s_fmt_vid_cap()
349 v4l2_rect_map_inside(&vin->compose, &fmt_rect); in rvin_s_fmt_vid_cap()
357 struct rvin_dev *vin = video_drvdata(file); in rvin_g_fmt_vid_cap() local
359 f->fmt.pix = vin->format; in rvin_g_fmt_vid_cap()
367 struct rvin_dev *vin = video_drvdata(file); in rvin_enum_fmt_vid_cap() local
374 * with VIN, so all supported YCbCr and RGB media bus codes can produce in rvin_enum_fmt_vid_cap()
416 if (rvin_format_from_pixel(vin, rvin_formats[i].fourcc)) in rvin_enum_fmt_vid_cap()
428 static int rvin_remote_rectangle(struct rvin_dev *vin, struct v4l2_rect *rect) in rvin_remote_rectangle() argument
437 if (vin->info->use_mc) { in rvin_remote_rectangle()
438 struct media_pad *pad = media_pad_remote_pad_first(&vin->pad); in rvin_remote_rectangle()
446 sd = vin_to_source(vin); in rvin_remote_rectangle()
447 index = vin->parallel.source_pad; in rvin_remote_rectangle()
460 switch (vin->format.field) { in rvin_remote_rectangle()
477 struct rvin_dev *vin = video_drvdata(file); in rvin_g_selection() local
480 if (!vin->scaler) in rvin_g_selection()
489 ret = rvin_remote_rectangle(vin, &s->r); in rvin_g_selection()
495 s->r = vin->crop; in rvin_g_selection()
500 s->r.width = vin->format.width; in rvin_g_selection()
501 s->r.height = vin->format.height; in rvin_g_selection()
504 s->r = vin->compose; in rvin_g_selection()
516 struct rvin_dev *vin = video_drvdata(file); in rvin_s_selection() local
526 if (!vin->scaler) in rvin_s_selection()
537 ret = rvin_remote_rectangle(vin, &max_rect); in rvin_s_selection()
549 vin->crop = s->r = r; in rvin_s_selection()
551 vin_dbg(vin, "Cropped %dx%d@%d:%d of %dx%d\n", in rvin_s_selection()
558 max_rect.width = vin->format.width; in rvin_s_selection()
559 max_rect.height = vin->format.height; in rvin_s_selection()
567 while ((r.top * vin->format.bytesperline) & HW_BUFFER_MASK) in rvin_s_selection()
570 fmt = rvin_format_from_pixel(vin, vin->format.pixelformat); in rvin_s_selection()
574 vin->compose = s->r = r; in rvin_s_selection()
576 vin_dbg(vin, "Compose %dx%d@%d:%d in %dx%d\n", in rvin_s_selection()
578 vin->format.width, vin->format.height); in rvin_s_selection()
585 rvin_crop_scale_comp(vin); in rvin_s_selection()
593 struct rvin_dev *vin = video_drvdata(file); in rvin_g_parm() local
594 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_g_parm()
596 return v4l2_g_parm_cap(&vin->vdev, sd, parm); in rvin_g_parm()
602 struct rvin_dev *vin = video_drvdata(file); in rvin_s_parm() local
603 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_s_parm()
605 return v4l2_s_parm_cap(&vin->vdev, sd, parm); in rvin_s_parm()
611 struct rvin_dev *vin = video_drvdata(file); in rvin_g_pixelaspect() local
612 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_g_pixelaspect()
623 struct rvin_dev *vin = video_drvdata(file); in rvin_enum_input() local
624 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_enum_input()
641 i->std = vin->vdev.tvnorms; in rvin_enum_input()
664 struct rvin_dev *vin = video_drvdata(file); in rvin_querystd() local
665 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_querystd()
672 struct rvin_dev *vin = video_drvdata(file); in rvin_s_std() local
675 ret = v4l2_subdev_call(vin_to_source(vin), video, s_std, a); in rvin_s_std()
679 vin->std = a; in rvin_s_std()
682 return rvin_reset_format(vin); in rvin_s_std()
687 struct rvin_dev *vin = video_drvdata(file); in rvin_g_std() local
689 if (v4l2_subdev_has_op(vin_to_source(vin), pad, dv_timings_cap)) in rvin_g_std()
692 *a = vin->std; in rvin_g_std()
710 struct rvin_dev *vin = video_drvdata(file); in rvin_enum_dv_timings() local
711 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_enum_dv_timings()
717 timings->pad = vin->parallel.sink_pad; in rvin_enum_dv_timings()
729 struct rvin_dev *vin = video_drvdata(file); in rvin_s_dv_timings() local
730 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_s_dv_timings()
738 return rvin_reset_format(vin); in rvin_s_dv_timings()
744 struct rvin_dev *vin = video_drvdata(file); in rvin_g_dv_timings() local
745 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_g_dv_timings()
753 struct rvin_dev *vin = video_drvdata(file); in rvin_query_dv_timings() local
754 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_query_dv_timings()
762 struct rvin_dev *vin = video_drvdata(file); in rvin_dv_timings_cap() local
763 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_dv_timings_cap()
769 cap->pad = vin->parallel.sink_pad; in rvin_dv_timings_cap()
780 struct rvin_dev *vin = video_drvdata(file); in rvin_g_edid() local
781 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_g_edid()
787 edid->pad = vin->parallel.sink_pad; in rvin_g_edid()
798 struct rvin_dev *vin = video_drvdata(file); in rvin_s_edid() local
799 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_s_edid()
805 edid->pad = vin->parallel.sink_pad; in rvin_s_edid()
865 static void rvin_mc_try_format(struct rvin_dev *vin, in rvin_mc_try_format() argument
880 rvin_format_align(vin, pix); in rvin_mc_try_format()
886 struct rvin_dev *vin = video_drvdata(file); in rvin_mc_try_fmt_vid_cap() local
888 rvin_mc_try_format(vin, &f->fmt.pix); in rvin_mc_try_fmt_vid_cap()
896 struct rvin_dev *vin = video_drvdata(file); in rvin_mc_s_fmt_vid_cap() local
898 if (vb2_is_busy(&vin->queue)) in rvin_mc_s_fmt_vid_cap()
901 rvin_mc_try_format(vin, &f->fmt.pix); in rvin_mc_s_fmt_vid_cap()
903 vin->format = f->fmt.pix; in rvin_mc_s_fmt_vid_cap()
905 vin->crop.top = 0; in rvin_mc_s_fmt_vid_cap()
906 vin->crop.left = 0; in rvin_mc_s_fmt_vid_cap()
907 vin->crop.width = vin->format.width; in rvin_mc_s_fmt_vid_cap()
908 vin->crop.height = vin->format.height; in rvin_mc_s_fmt_vid_cap()
909 vin->compose = vin->crop; in rvin_mc_s_fmt_vid_cap()
943 static int rvin_power_parallel(struct rvin_dev *vin, bool on) in rvin_power_parallel() argument
945 struct v4l2_subdev *sd = vin_to_source(vin); in rvin_power_parallel()
958 struct rvin_dev *vin = video_drvdata(file); in rvin_open() local
961 ret = pm_runtime_resume_and_get(vin->dev); in rvin_open()
965 ret = mutex_lock_interruptible(&vin->lock); in rvin_open()
969 file->private_data = vin; in rvin_open()
975 if (vin->info->use_mc) in rvin_open()
976 ret = v4l2_pipeline_pm_get(&vin->vdev.entity); in rvin_open()
978 ret = rvin_power_parallel(vin, true); in rvin_open()
983 ret = v4l2_ctrl_handler_setup(&vin->ctrl_handler); in rvin_open()
987 mutex_unlock(&vin->lock); in rvin_open()
991 if (vin->info->use_mc) in rvin_open()
992 v4l2_pipeline_pm_put(&vin->vdev.entity); in rvin_open()
994 rvin_power_parallel(vin, false); in rvin_open()
998 mutex_unlock(&vin->lock); in rvin_open()
1000 pm_runtime_put(vin->dev); in rvin_open()
1007 struct rvin_dev *vin = video_drvdata(file); in rvin_release() local
1011 mutex_lock(&vin->lock); in rvin_release()
1019 if (vin->info->use_mc) { in rvin_release()
1020 v4l2_pipeline_pm_put(&vin->vdev.entity); in rvin_release()
1023 rvin_power_parallel(vin, false); in rvin_release()
1026 mutex_unlock(&vin->lock); in rvin_release()
1028 pm_runtime_put(vin->dev); in rvin_release()
1043 void rvin_v4l2_unregister(struct rvin_dev *vin) in rvin_v4l2_unregister() argument
1045 if (!video_is_registered(&vin->vdev)) in rvin_v4l2_unregister()
1048 v4l2_info(&vin->v4l2_dev, "Removing %s\n", in rvin_v4l2_unregister()
1049 video_device_node_name(&vin->vdev)); in rvin_v4l2_unregister()
1052 video_unregister_device(&vin->vdev); in rvin_v4l2_unregister()
1055 static void rvin_notify_video_device(struct rvin_dev *vin, in rvin_notify_video_device() argument
1060 v4l2_event_queue(&vin->vdev, arg); in rvin_notify_video_device()
1073 struct rvin_dev *vin = in rvin_notify() local
1078 if (!vin->info->use_mc) { in rvin_notify()
1079 rvin_notify_video_device(vin, notification, arg); in rvin_notify()
1083 group = vin->group; in rvin_notify()
1086 vin = group->vin[i]; in rvin_notify()
1087 if (!vin) in rvin_notify()
1090 pad = media_pad_remote_pad_first(&vin->pad); in rvin_notify()
1098 rvin_notify_video_device(vin, notification, arg); in rvin_notify()
1102 int rvin_v4l2_register(struct rvin_dev *vin) in rvin_v4l2_register() argument
1104 struct video_device *vdev = &vin->vdev; in rvin_v4l2_register()
1107 vin->v4l2_dev.notify = rvin_notify; in rvin_v4l2_register()
1110 vdev->v4l2_dev = &vin->v4l2_dev; in rvin_v4l2_register()
1111 vdev->queue = &vin->queue; in rvin_v4l2_register()
1112 snprintf(vdev->name, sizeof(vdev->name), "VIN%u output", vin->id); in rvin_v4l2_register()
1114 vdev->lock = &vin->lock; in rvin_v4l2_register()
1120 vin->format.pixelformat = RVIN_DEFAULT_FORMAT; in rvin_v4l2_register()
1121 vin->format.width = RVIN_DEFAULT_WIDTH; in rvin_v4l2_register()
1122 vin->format.height = RVIN_DEFAULT_HEIGHT; in rvin_v4l2_register()
1123 vin->format.field = RVIN_DEFAULT_FIELD; in rvin_v4l2_register()
1124 vin->format.colorspace = RVIN_DEFAULT_COLORSPACE; in rvin_v4l2_register()
1126 if (vin->info->use_mc) { in rvin_v4l2_register()
1131 rvin_reset_format(vin); in rvin_v4l2_register()
1134 rvin_format_align(vin, &vin->format); in rvin_v4l2_register()
1136 ret = video_register_device(&vin->vdev, VFL_TYPE_VIDEO, -1); in rvin_v4l2_register()
1138 vin_err(vin, "Failed to register video device\n"); in rvin_v4l2_register()
1142 video_set_drvdata(&vin->vdev, vin); in rvin_v4l2_register()
1144 v4l2_info(&vin->v4l2_dev, "Device registered as %s\n", in rvin_v4l2_register()
1145 video_device_node_name(&vin->vdev)); in rvin_v4l2_register()