Lines Matching refs:ctx

149 static const struct cal_fmt *find_format_by_pix(struct cal_ctx *ctx,
155 for (k = 0; k < ctx->num_active_fmt; k++) {
156 fmt = ctx->active_fmt[k];
164 static const struct cal_fmt *find_format_by_code(struct cal_ctx *ctx,
170 for (k = 0; k < ctx->num_active_fmt; k++) {
171 fmt = ctx->active_fmt[k];
182 struct cal_ctx *ctx = video_drvdata(file);
188 "platform:%s", dev_name(ctx->cal->dev));
195 struct cal_ctx *ctx = video_drvdata(file);
198 if (f->index >= ctx->num_active_fmt)
201 fmt = ctx->active_fmt[f->index];
208 static int __subdev_get_format(struct cal_ctx *ctx,
218 ret = v4l2_subdev_call(ctx->phy->sensor, pad, get_fmt, NULL, &sd_fmt);
224 ctx_dbg(1, ctx, "%s %dx%d code:%04X\n", __func__,
230 static int __subdev_set_format(struct cal_ctx *ctx,
241 ret = v4l2_subdev_call(ctx->phy->sensor, pad, set_fmt, NULL, &sd_fmt);
245 ctx_dbg(1, ctx, "%s %dx%d code:%04X\n", __func__,
251 static int cal_calc_format_size(struct cal_ctx *ctx,
258 ctx_dbg(3, ctx, "No cal_fmt provided!\n");
277 ctx_dbg(3, ctx, "%s: fourcc: %s size: %dx%d bpl:%d img_size:%d\n",
288 struct cal_ctx *ctx = video_drvdata(file);
290 *f = ctx->v_fmt;
298 struct cal_ctx *ctx = video_drvdata(file);
303 fmt = find_format_by_pix(ctx, f->fmt.pix.pixelformat);
305 ctx_dbg(3, ctx, "Fourcc format (0x%08x) not found.\n",
309 fmt = ctx->active_fmt[0];
313 f->fmt.pix.field = ctx->v_fmt.fmt.pix.field;
322 ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_frame_size,
342 f->fmt.pix.width = ctx->v_fmt.fmt.pix.width;
343 f->fmt.pix.height = ctx->v_fmt.fmt.pix.height;
350 f->fmt.pix.colorspace = ctx->v_fmt.fmt.pix.colorspace;
351 return cal_calc_format_size(ctx, fmt, f);
357 struct cal_ctx *ctx = video_drvdata(file);
358 struct vb2_queue *q = &ctx->vb_vidq;
364 ctx_dbg(3, ctx, "%s device busy\n", __func__);
372 fmt = find_format_by_pix(ctx, f->fmt.pix.pixelformat);
376 ret = __subdev_set_format(ctx, &mbus_fmt);
382 ctx_dbg(3, ctx,
388 v4l2_fill_pix_format(&ctx->v_fmt.fmt.pix, &mbus_fmt);
389 ctx->v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
390 ctx->v_fmt.fmt.pix.pixelformat = fmt->fourcc;
391 cal_calc_format_size(ctx, fmt, &ctx->v_fmt);
392 ctx->fmt = fmt;
393 ctx->m_fmt = mbus_fmt;
394 *f = ctx->v_fmt;
402 struct cal_ctx *ctx = video_drvdata(file);
408 fmt = find_format_by_pix(ctx, fsize->pixel_format);
410 ctx_dbg(3, ctx, "Invalid pixel code: %x\n",
420 ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_frame_size, NULL,
425 ctx_dbg(1, ctx, "%s: index: %d code: %x W:[%d,%d] H:[%d,%d]\n",
462 struct cal_ctx *ctx = video_drvdata(file);
472 fmt = find_format_by_pix(ctx, fival->pixel_format);
477 ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_frame_interval,
531 struct cal_ctx *ctx = vb2_get_drv_priv(vq);
532 unsigned int size = ctx->v_fmt.fmt.pix.sizeimage;
546 ctx_dbg(3, ctx, "nbuffers=%d, size=%d\n", *nbuffers, sizes[0]);
553 struct cal_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
558 if (WARN_ON(!ctx->fmt))
561 size = ctx->v_fmt.fmt.pix.sizeimage;
563 ctx_err(ctx,
575 struct cal_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
578 struct cal_dmaqueue *vidq = &ctx->vidq;
582 spin_lock_irqsave(&ctx->slock, flags);
584 spin_unlock_irqrestore(&ctx->slock, flags);
589 struct cal_ctx *ctx = vb2_get_drv_priv(vq);
590 struct cal_dmaqueue *dma_q = &ctx->vidq;
596 spin_lock_irqsave(&ctx->slock, flags);
598 spin_unlock_irqrestore(&ctx->slock, flags);
599 ctx_dbg(3, ctx, "buffer queue is empty\n");
604 ctx->cur_frm = buf;
605 ctx->next_frm = buf;
607 spin_unlock_irqrestore(&ctx->slock, flags);
609 addr = vb2_dma_contig_plane_dma_addr(&ctx->cur_frm->vb.vb2_buf, 0);
610 ctx->sequence = 0;
612 pm_runtime_get_sync(ctx->cal->dev);
614 cal_ctx_csi2_config(ctx);
615 cal_ctx_pix_proc_config(ctx);
616 cal_ctx_wr_dma_config(ctx, ctx->v_fmt.fmt.pix.bytesperline,
617 ctx->v_fmt.fmt.pix.height);
619 cal_camerarx_enable_irqs(ctx->phy);
621 ret = cal_camerarx_start(ctx->phy, ctx->fmt);
625 cal_ctx_wr_dma_addr(ctx, addr);
626 cal_camerarx_ppi_enable(ctx->phy);
629 cal_quickdump_regs(ctx->cal);
634 spin_lock_irqsave(&ctx->slock, flags);
635 vb2_buffer_done(&ctx->cur_frm->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
636 ctx->cur_frm = NULL;
637 ctx->next_frm = NULL;
642 spin_unlock_irqrestore(&ctx->slock, flags);
648 struct cal_ctx *ctx = vb2_get_drv_priv(vq);
649 struct cal_dmaqueue *dma_q = &ctx->vidq;
655 cal_camerarx_ppi_disable(ctx->phy);
663 spin_lock_irqsave(&ctx->slock, flags);
664 dma_act = ctx->dma_act;
665 spin_unlock_irqrestore(&ctx->slock, flags);
669 ctx_err(ctx, "failed to disable dma cleanly\n");
671 cal_camerarx_disable_irqs(ctx->phy);
672 cal_camerarx_stop(ctx->phy);
675 spin_lock_irqsave(&ctx->slock, flags);
681 if (ctx->cur_frm == ctx->next_frm) {
682 vb2_buffer_done(&ctx->cur_frm->vb.vb2_buf, VB2_BUF_STATE_ERROR);
684 vb2_buffer_done(&ctx->cur_frm->vb.vb2_buf, VB2_BUF_STATE_ERROR);
685 vb2_buffer_done(&ctx->next_frm->vb.vb2_buf,
688 ctx->cur_frm = NULL;
689 ctx->next_frm = NULL;
690 spin_unlock_irqrestore(&ctx->slock, flags);
692 pm_runtime_put_sync(ctx->cal->dev);
720 static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx)
729 ctx->active_fmt = devm_kcalloc(ctx->cal->dev, ARRAY_SIZE(cal_formats),
730 sizeof(*ctx->active_fmt), GFP_KERNEL);
731 ctx->num_active_fmt = 0;
738 ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_mbus_code,
743 ctx_dbg(2, ctx,
745 ctx->phy->sensor->name, mbus_code.code, j);
751 ctx->active_fmt[i] = fmt;
752 ctx_dbg(2, ctx,
756 ctx->num_active_fmt = ++i;
762 ctx_err(ctx, "No suitable format reported by subdev %s\n",
763 ctx->phy->sensor->name);
767 ret = __subdev_get_format(ctx, &mbus_fmt);
771 fmt = find_format_by_code(ctx, mbus_fmt.code);
773 ctx_dbg(3, ctx, "mbus code format (0x%08x) not found.\n",
779 v4l2_fill_pix_format(&ctx->v_fmt.fmt.pix, &mbus_fmt);
780 ctx->v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
781 ctx->v_fmt.fmt.pix.pixelformat = fmt->fourcc;
782 cal_calc_format_size(ctx, fmt, &ctx->v_fmt);
783 ctx->fmt = fmt;
784 ctx->m_fmt = mbus_fmt;
789 int cal_ctx_v4l2_register(struct cal_ctx *ctx)
791 struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
792 struct video_device *vfd = &ctx->vdev;
795 ret = cal_ctx_v4l2_init_formats(ctx);
799 ret = v4l2_ctrl_add_handler(hdl, ctx->phy->sensor->ctrl_handler, NULL,
802 ctx_err(ctx, "Failed to add sensor ctrl handler\n");
808 ctx_err(ctx, "Failed to register video device\n");
812 ctx_info(ctx, "V4L2 device registered as %s\n",
818 void cal_ctx_v4l2_unregister(struct cal_ctx *ctx)
820 ctx_dbg(1, ctx, "unregistering %s\n",
821 video_device_node_name(&ctx->vdev));
823 video_unregister_device(&ctx->vdev);
826 int cal_ctx_v4l2_init(struct cal_ctx *ctx)
828 struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
829 struct video_device *vfd = &ctx->vdev;
830 struct vb2_queue *q = &ctx->vb_vidq;
833 INIT_LIST_HEAD(&ctx->vidq.active);
834 spin_lock_init(&ctx->slock);
835 mutex_init(&ctx->mutex);
840 q->drv_priv = ctx;
845 q->lock = &ctx->mutex;
847 q->dev = ctx->cal->dev;
855 vfd->v4l2_dev = &ctx->cal->v4l2_dev;
857 snprintf(vfd->name, sizeof(vfd->name), "CAL output %u", ctx->index);
858 vfd->lock = &ctx->mutex;
859 video_set_drvdata(vfd, ctx);
861 ctx->pad.flags = MEDIA_PAD_FL_SINK;
862 ret = media_entity_pads_init(&vfd->entity, 1, &ctx->pad);
869 ctx_err(ctx, "Failed to init ctrl handler\n");
882 void cal_ctx_v4l2_cleanup(struct cal_ctx *ctx)
884 v4l2_ctrl_handler_free(&ctx->ctrl_handler);
885 media_entity_cleanup(&ctx->vdev.entity);