Lines Matching refs:ctx

59 	struct cal_ctx *ctx = video_drvdata(file);
61 *f = ctx->v_fmt;
71 static const struct cal_format_info *find_format_by_pix(struct cal_ctx *ctx,
77 for (k = 0; k < ctx->num_active_fmt; k++) {
78 fmtinfo = ctx->active_fmt[k];
86 static const struct cal_format_info *find_format_by_code(struct cal_ctx *ctx,
92 for (k = 0; k < ctx->num_active_fmt; k++) {
93 fmtinfo = ctx->active_fmt[k];
104 struct cal_ctx *ctx = video_drvdata(file);
107 if (f->index >= ctx->num_active_fmt)
110 fmtinfo = ctx->active_fmt[f->index];
117 static int __subdev_get_format(struct cal_ctx *ctx,
127 ret = v4l2_subdev_call(ctx->phy->source, pad, get_fmt, NULL, &sd_fmt);
133 ctx_dbg(1, ctx, "%s %dx%d code:%04X\n", __func__,
139 static int __subdev_set_format(struct cal_ctx *ctx,
151 ret = v4l2_subdev_call(ctx->phy->source, pad, set_fmt, NULL, &sd_fmt);
155 ctx_dbg(1, ctx, "%s %dx%d code:%04X\n", __func__,
161 static void cal_calc_format_size(struct cal_ctx *ctx,
183 ctx_dbg(3, ctx, "%s: fourcc: %s size: %dx%d bpl:%d img_size:%d\n",
192 struct cal_ctx *ctx = video_drvdata(file);
199 fmtinfo = find_format_by_pix(ctx, f->fmt.pix.pixelformat);
201 ctx_dbg(3, ctx, "Fourcc format (0x%08x) not found.\n",
205 fmtinfo = ctx->active_fmt[0];
209 f->fmt.pix.field = ctx->v_fmt.fmt.pix.field;
218 ret = v4l2_subdev_call(ctx->phy->source, pad, enum_frame_size,
238 f->fmt.pix.width = ctx->v_fmt.fmt.pix.width;
239 f->fmt.pix.height = ctx->v_fmt.fmt.pix.height;
246 f->fmt.pix.colorspace = ctx->v_fmt.fmt.pix.colorspace;
247 cal_calc_format_size(ctx, fmtinfo, f);
254 struct cal_ctx *ctx = video_drvdata(file);
255 struct vb2_queue *q = &ctx->vb_vidq;
264 ctx_dbg(3, ctx, "%s device busy\n", __func__);
272 fmtinfo = find_format_by_pix(ctx, f->fmt.pix.pixelformat);
276 ret = __subdev_set_format(ctx, &sd_fmt.format);
282 ctx_dbg(3, ctx,
288 v4l2_fill_pix_format(&ctx->v_fmt.fmt.pix, &sd_fmt.format);
289 ctx->v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
290 ctx->v_fmt.fmt.pix.pixelformat = fmtinfo->fourcc;
291 ctx->v_fmt.fmt.pix.field = sd_fmt.format.field;
292 cal_calc_format_size(ctx, fmtinfo, &ctx->v_fmt);
294 v4l2_subdev_call(&ctx->phy->subdev, pad, set_fmt, NULL, &sd_fmt);
296 ctx->fmtinfo = fmtinfo;
297 *f = ctx->v_fmt;
305 struct cal_ctx *ctx = video_drvdata(file);
315 fmtinfo = find_format_by_pix(ctx, fsize->pixel_format);
317 ctx_dbg(3, ctx, "Invalid pixel code: %x\n",
324 ret = v4l2_subdev_call(ctx->phy->source, pad, enum_frame_size, NULL,
329 ctx_dbg(1, ctx, "%s: index: %d code: %x W:[%d,%d] H:[%d,%d]\n",
366 struct cal_ctx *ctx = video_drvdata(file);
376 fmtinfo = find_format_by_pix(ctx, fival->pixel_format);
381 ret = v4l2_subdev_call(ctx->phy->source, pad, enum_frame_interval,
393 struct cal_ctx *ctx = video_drvdata(file);
395 return v4l2_g_parm_cap(video_devdata(file), ctx->phy->source, a);
400 struct cal_ctx *ctx = video_drvdata(file);
402 return v4l2_s_parm_cap(video_devdata(file), ctx->phy->source, a);
464 static void cal_mc_try_fmt(struct cal_ctx *ctx, struct v4l2_format *f,
507 format->colorspace = ctx->v_fmt.fmt.pix.colorspace;
512 ctx_dbg(3, ctx, "%s: %s %ux%u (bytesperline %u sizeimage %u)\n",
521 struct cal_ctx *ctx = video_drvdata(file);
523 cal_mc_try_fmt(ctx, f, NULL);
530 struct cal_ctx *ctx = video_drvdata(file);
533 if (vb2_is_busy(&ctx->vb_vidq)) {
534 ctx_dbg(3, ctx, "%s device busy\n", __func__);
538 cal_mc_try_fmt(ctx, f, &fmtinfo);
540 ctx->v_fmt = *f;
541 ctx->fmtinfo = fmtinfo;
549 struct cal_ctx *ctx = video_drvdata(file);
558 ctx_dbg(3, ctx, "Invalid pixel format 0x%08x\n",
604 struct cal_ctx *ctx = vb2_get_drv_priv(vq);
605 unsigned int size = ctx->v_fmt.fmt.pix.sizeimage;
620 ctx_dbg(3, ctx, "nbuffers=%d, size=%d\n", *nbuffers, sizes[0]);
627 struct cal_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
632 size = ctx->v_fmt.fmt.pix.sizeimage;
634 ctx_err(ctx,
646 struct cal_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
652 spin_lock_irqsave(&ctx->dma.lock, flags);
653 list_add_tail(&buf->list, &ctx->dma.queue);
654 spin_unlock_irqrestore(&ctx->dma.lock, flags);
657 static void cal_release_buffers(struct cal_ctx *ctx,
663 spin_lock_irq(&ctx->dma.lock);
665 list_for_each_entry_safe(buf, tmp, &ctx->dma.queue, list) {
670 if (ctx->dma.pending) {
671 vb2_buffer_done(&ctx->dma.pending->vb.vb2_buf, state);
672 ctx->dma.pending = NULL;
675 if (ctx->dma.active) {
676 vb2_buffer_done(&ctx->dma.active->vb.vb2_buf, state);
677 ctx->dma.active = NULL;
680 spin_unlock_irq(&ctx->dma.lock);
688 static int cal_video_check_format(struct cal_ctx *ctx)
695 remote_pad = media_pad_remote_pad_first(&ctx->pad);
699 state = v4l2_subdev_lock_and_get_active_state(&ctx->phy->subdev);
707 if (ctx->fmtinfo->code != format->code ||
708 ctx->v_fmt.fmt.pix.height != format->height ||
709 ctx->v_fmt.fmt.pix.width != format->width ||
710 ctx->v_fmt.fmt.pix.field != format->field) {
723 struct cal_ctx *ctx = vb2_get_drv_priv(vq);
728 ret = video_device_pipeline_alloc_start(&ctx->vdev);
730 ctx_err(ctx, "Failed to start media pipeline: %d\n", ret);
738 ret = cal_video_check_format(ctx);
740 ctx_dbg(3, ctx,
745 ret = cal_ctx_prepare(ctx);
747 ctx_err(ctx, "Failed to prepare context: %d\n", ret);
751 spin_lock_irq(&ctx->dma.lock);
752 buf = list_first_entry(&ctx->dma.queue, struct cal_buffer, list);
753 ctx->dma.active = buf;
755 spin_unlock_irq(&ctx->dma.lock);
759 ret = pm_runtime_resume_and_get(ctx->cal->dev);
763 cal_ctx_set_dma_addr(ctx, addr);
764 cal_ctx_start(ctx);
766 ret = v4l2_subdev_call(&ctx->phy->subdev, video, s_stream, 1);
771 cal_quickdump_regs(ctx->cal);
776 cal_ctx_stop(ctx);
777 pm_runtime_put_sync(ctx->cal->dev);
778 cal_ctx_unprepare(ctx);
781 video_device_pipeline_stop(&ctx->vdev);
783 cal_release_buffers(ctx, VB2_BUF_STATE_QUEUED);
790 struct cal_ctx *ctx = vb2_get_drv_priv(vq);
792 cal_ctx_stop(ctx);
794 v4l2_subdev_call(&ctx->phy->subdev, video, s_stream, 0);
796 pm_runtime_put_sync(ctx->cal->dev);
798 cal_ctx_unprepare(ctx);
800 cal_release_buffers(ctx, VB2_BUF_STATE_ERROR);
802 video_device_pipeline_stop(&ctx->vdev);
829 static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx)
837 ctx->active_fmt = devm_kcalloc(ctx->cal->dev, cal_num_formats,
838 sizeof(*ctx->active_fmt), GFP_KERNEL);
839 if (!ctx->active_fmt)
842 ctx->num_active_fmt = 0;
850 ret = v4l2_subdev_call(ctx->phy->source, pad, enum_mbus_code,
856 ctx_err(ctx, "Error enumerating mbus codes in subdev %s: %d\n",
857 ctx->phy->source->name, ret);
861 ctx_dbg(2, ctx,
863 ctx->phy->source->name, mbus_code.code, j);
869 ctx->active_fmt[i] = fmtinfo;
870 ctx_dbg(2, ctx,
874 ctx->num_active_fmt = ++i;
880 ctx_err(ctx, "No suitable format reported by subdev %s\n",
881 ctx->phy->source->name);
885 ret = __subdev_get_format(ctx, &mbus_fmt);
889 fmtinfo = find_format_by_code(ctx, mbus_fmt.code);
891 ctx_dbg(3, ctx, "mbus code format (0x%08x) not found.\n",
897 v4l2_fill_pix_format(&ctx->v_fmt.fmt.pix, &mbus_fmt);
898 ctx->v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
899 ctx->v_fmt.fmt.pix.pixelformat = fmtinfo->fourcc;
900 cal_calc_format_size(ctx, fmtinfo, &ctx->v_fmt);
901 ctx->fmtinfo = fmtinfo;
906 static int cal_ctx_v4l2_init_mc_format(struct cal_ctx *ctx)
909 struct v4l2_pix_format *pix_fmt = &ctx->v_fmt.fmt.pix;
924 ctx->v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
927 cal_calc_format_size(ctx, fmtinfo, &ctx->v_fmt);
928 ctx->fmtinfo = fmtinfo;
933 int cal_ctx_v4l2_register(struct cal_ctx *ctx)
935 struct video_device *vfd = &ctx->vdev;
939 struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
941 ret = cal_ctx_v4l2_init_formats(ctx);
943 ctx_err(ctx, "Failed to init formats: %d\n", ret);
947 ret = v4l2_ctrl_add_handler(hdl, ctx->phy->source->ctrl_handler,
950 ctx_err(ctx, "Failed to add source ctrl handler\n");
954 ret = cal_ctx_v4l2_init_mc_format(ctx);
956 ctx_err(ctx, "Failed to init format: %d\n", ret);
963 ctx_err(ctx, "Failed to register video device\n");
967 ret = media_create_pad_link(&ctx->phy->subdev.entity,
973 ctx_err(ctx, "Failed to create media link for context %u\n",
974 ctx->dma_ctx);
979 ctx_info(ctx, "V4L2 device registered as %s\n",
985 void cal_ctx_v4l2_unregister(struct cal_ctx *ctx)
987 ctx_dbg(1, ctx, "unregistering %s\n",
988 video_device_node_name(&ctx->vdev));
990 video_unregister_device(&ctx->vdev);
993 int cal_ctx_v4l2_init(struct cal_ctx *ctx)
995 struct video_device *vfd = &ctx->vdev;
996 struct vb2_queue *q = &ctx->vb_vidq;
999 INIT_LIST_HEAD(&ctx->dma.queue);
1000 spin_lock_init(&ctx->dma.lock);
1001 mutex_init(&ctx->mutex);
1002 init_waitqueue_head(&ctx->dma.wait);
1007 q->drv_priv = ctx;
1012 q->lock = &ctx->mutex;
1014 q->dev = ctx->cal->dev;
1024 vfd->v4l2_dev = &ctx->cal->v4l2_dev;
1026 snprintf(vfd->name, sizeof(vfd->name), "CAL output %u", ctx->dma_ctx);
1029 vfd->lock = &ctx->mutex;
1030 video_set_drvdata(vfd, ctx);
1032 ctx->pad.flags = MEDIA_PAD_FL_SINK;
1033 ret = media_entity_pads_init(&vfd->entity, 1, &ctx->pad);
1039 struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
1043 ctx_err(ctx, "Failed to init ctrl handler\n");
1057 void cal_ctx_v4l2_cleanup(struct cal_ctx *ctx)
1060 v4l2_ctrl_handler_free(&ctx->ctrl_handler);
1062 media_entity_cleanup(&ctx->vdev.entity);