• Home
  • Raw
  • Download

Lines Matching refs:ctx

64 #define ctx_dbg(level, ctx, fmt, arg...)	\  argument
65 v4l2_dbg(level, debug, &ctx->v4l2_dev, fmt, ##arg)
66 #define ctx_info(ctx, fmt, arg...) \ argument
67 v4l2_info(&ctx->v4l2_dev, fmt, ##arg)
68 #define ctx_err(ctx, fmt, arg...) \ argument
69 v4l2_err(&ctx->v4l2_dev, fmt, ##arg)
255 struct cal_ctx *ctx[CAL_NUM_CONTEXT]; member
313 static const struct cal_fmt *find_format_by_pix(struct cal_ctx *ctx, in find_format_by_pix() argument
319 for (k = 0; k < ctx->num_active_fmt; k++) { in find_format_by_pix()
320 fmt = ctx->active_fmt[k]; in find_format_by_pix()
328 static const struct cal_fmt *find_format_by_code(struct cal_ctx *ctx, in find_format_by_code() argument
334 for (k = 0; k < ctx->num_active_fmt; k++) { in find_format_by_code()
335 fmt = ctx->active_fmt[k]; in find_format_by_code()
388 static void camerarx_phy_enable(struct cal_ctx *ctx) in camerarx_phy_enable() argument
392 if (!ctx->dev->cm->base) { in camerarx_phy_enable()
393 ctx_err(ctx, "cm not mapped\n"); in camerarx_phy_enable()
397 val = reg_read(ctx->dev->cm, CM_CTRL_CORE_CAMERRX_CONTROL); in camerarx_phy_enable()
398 if (ctx->csi2_port == 1) { in camerarx_phy_enable()
404 } else if (ctx->csi2_port == 2) { in camerarx_phy_enable()
411 reg_write(ctx->dev->cm, CM_CTRL_CORE_CAMERRX_CONTROL, val); in camerarx_phy_enable()
414 static void camerarx_phy_disable(struct cal_ctx *ctx) in camerarx_phy_disable() argument
418 if (!ctx->dev->cm->base) { in camerarx_phy_disable()
419 ctx_err(ctx, "cm not mapped\n"); in camerarx_phy_disable()
423 val = reg_read(ctx->dev->cm, CM_CTRL_CORE_CAMERRX_CONTROL); in camerarx_phy_disable()
424 if (ctx->csi2_port == 1) in camerarx_phy_disable()
426 else if (ctx->csi2_port == 2) in camerarx_phy_disable()
428 reg_write(ctx->dev->cm, CM_CTRL_CORE_CAMERRX_CONTROL, val); in camerarx_phy_disable()
494 if (dev->ctx[0]) { in cal_quickdump_regs()
496 &dev->ctx[0]->cc->res->start); in cal_quickdump_regs()
498 (__force const void *)dev->ctx[0]->cc->base, in cal_quickdump_regs()
499 resource_size(dev->ctx[0]->cc->res), in cal_quickdump_regs()
503 if (dev->ctx[1]) { in cal_quickdump_regs()
505 &dev->ctx[1]->cc->res->start); in cal_quickdump_regs()
507 (__force const void *)dev->ctx[1]->cc->base, in cal_quickdump_regs()
508 resource_size(dev->ctx[1]->cc->res), in cal_quickdump_regs()
522 static void enable_irqs(struct cal_ctx *ctx) in enable_irqs() argument
525 reg_write_field(ctx->dev, in enable_irqs()
528 CAL_HL_IRQ_MASK(ctx->csi2_port)); in enable_irqs()
530 reg_write_field(ctx->dev, in enable_irqs()
533 CAL_HL_IRQ_MASK(ctx->csi2_port)); in enable_irqs()
535 reg_write(ctx->dev, CAL_CSI2_VC_IRQENABLE(1), 0xFF000000); in enable_irqs()
538 static void disable_irqs(struct cal_ctx *ctx) in disable_irqs() argument
541 reg_write_field(ctx->dev, in disable_irqs()
544 CAL_HL_IRQ_MASK(ctx->csi2_port)); in disable_irqs()
546 reg_write_field(ctx->dev, in disable_irqs()
549 CAL_HL_IRQ_MASK(ctx->csi2_port)); in disable_irqs()
551 reg_write(ctx->dev, CAL_CSI2_VC_IRQENABLE(1), 0); in disable_irqs()
554 static void csi2_init(struct cal_ctx *ctx) in csi2_init() argument
559 val = reg_read(ctx->dev, CAL_CSI2_TIMING(ctx->csi2_port)); in csi2_init()
567 reg_write(ctx->dev, CAL_CSI2_TIMING(ctx->csi2_port), val); in csi2_init()
568 ctx_dbg(3, ctx, "CAL_CSI2_TIMING(%d) = 0x%08x\n", ctx->csi2_port, in csi2_init()
569 reg_read(ctx->dev, CAL_CSI2_TIMING(ctx->csi2_port))); in csi2_init()
571 val = reg_read(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port)); in csi2_init()
576 reg_write(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port), val); in csi2_init()
578 if (reg_read_field(ctx->dev, in csi2_init()
579 CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port), in csi2_init()
585 ctx_dbg(3, ctx, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x\n", ctx->csi2_port, in csi2_init()
586 reg_read(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port))); in csi2_init()
588 val = reg_read(ctx->dev, CAL_CTRL); in csi2_init()
595 reg_write(ctx->dev, CAL_CTRL, val); in csi2_init()
596 ctx_dbg(3, ctx, "CAL_CTRL = 0x%08x\n", reg_read(ctx->dev, CAL_CTRL)); in csi2_init()
599 static void csi2_lane_config(struct cal_ctx *ctx) in csi2_lane_config() argument
601 u32 val = reg_read(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port)); in csi2_lane_config()
605 &ctx->endpoint.bus.mipi_csi2; in csi2_lane_config()
622 reg_write(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port), val); in csi2_lane_config()
623 ctx_dbg(3, ctx, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x\n", in csi2_lane_config()
624 ctx->csi2_port, val); in csi2_lane_config()
627 static void csi2_ppi_enable(struct cal_ctx *ctx) in csi2_ppi_enable() argument
629 reg_write_field(ctx->dev, CAL_CSI2_PPI_CTRL(ctx->csi2_port), in csi2_ppi_enable()
633 static void csi2_ppi_disable(struct cal_ctx *ctx) in csi2_ppi_disable() argument
635 reg_write_field(ctx->dev, CAL_CSI2_PPI_CTRL(ctx->csi2_port), in csi2_ppi_disable()
639 static void csi2_ctx_config(struct cal_ctx *ctx) in csi2_ctx_config() argument
643 val = reg_read(ctx->dev, CAL_CSI2_CTX0(ctx->csi2_port)); in csi2_ctx_config()
644 set_field(&val, ctx->csi2_port, CAL_CSI2_CTX_CPORT_MASK); in csi2_ctx_config()
655 set_field(&val, ctx->virtual_channel, CAL_CSI2_CTX_VC_MASK); in csi2_ctx_config()
661 reg_write(ctx->dev, CAL_CSI2_CTX0(ctx->csi2_port), val); in csi2_ctx_config()
662 ctx_dbg(3, ctx, "CAL_CSI2_CTX0(%d) = 0x%08x\n", ctx->csi2_port, in csi2_ctx_config()
663 reg_read(ctx->dev, CAL_CSI2_CTX0(ctx->csi2_port))); in csi2_ctx_config()
666 static void pix_proc_config(struct cal_ctx *ctx) in pix_proc_config() argument
670 val = reg_read(ctx->dev, CAL_PIX_PROC(ctx->csi2_port)); in pix_proc_config()
675 set_field(&val, ctx->csi2_port, CAL_PIX_PROC_CPORT_MASK); in pix_proc_config()
677 reg_write(ctx->dev, CAL_PIX_PROC(ctx->csi2_port), val); in pix_proc_config()
678 ctx_dbg(3, ctx, "CAL_PIX_PROC(%d) = 0x%08x\n", ctx->csi2_port, in pix_proc_config()
679 reg_read(ctx->dev, CAL_PIX_PROC(ctx->csi2_port))); in pix_proc_config()
682 static void cal_wr_dma_config(struct cal_ctx *ctx, in cal_wr_dma_config() argument
687 val = reg_read(ctx->dev, CAL_WR_DMA_CTRL(ctx->csi2_port)); in cal_wr_dma_config()
688 set_field(&val, ctx->csi2_port, CAL_WR_DMA_CTRL_CPORT_MASK); in cal_wr_dma_config()
696 reg_write(ctx->dev, CAL_WR_DMA_CTRL(ctx->csi2_port), val); in cal_wr_dma_config()
697 ctx_dbg(3, ctx, "CAL_WR_DMA_CTRL(%d) = 0x%08x\n", ctx->csi2_port, in cal_wr_dma_config()
698 reg_read(ctx->dev, CAL_WR_DMA_CTRL(ctx->csi2_port))); in cal_wr_dma_config()
704 reg_write_field(ctx->dev, in cal_wr_dma_config()
705 CAL_WR_DMA_OFST(ctx->csi2_port), in cal_wr_dma_config()
708 ctx_dbg(3, ctx, "CAL_WR_DMA_OFST(%d) = 0x%08x\n", ctx->csi2_port, in cal_wr_dma_config()
709 reg_read(ctx->dev, CAL_WR_DMA_OFST(ctx->csi2_port))); in cal_wr_dma_config()
711 val = reg_read(ctx->dev, CAL_WR_DMA_XSIZE(ctx->csi2_port)); in cal_wr_dma_config()
720 reg_write(ctx->dev, CAL_WR_DMA_XSIZE(ctx->csi2_port), val); in cal_wr_dma_config()
721 ctx_dbg(3, ctx, "CAL_WR_DMA_XSIZE(%d) = 0x%08x\n", ctx->csi2_port, in cal_wr_dma_config()
722 reg_read(ctx->dev, CAL_WR_DMA_XSIZE(ctx->csi2_port))); in cal_wr_dma_config()
725 static void cal_wr_dma_addr(struct cal_ctx *ctx, unsigned int dmaaddr) in cal_wr_dma_addr() argument
727 reg_write(ctx->dev, CAL_WR_DMA_ADDR(ctx->csi2_port), dmaaddr); in cal_wr_dma_addr()
738 static void csi2_phy_config(struct cal_ctx *ctx) in csi2_phy_config() argument
747 ddrclkperiod_us = ctx->external_rate / 2000000; in csi2_phy_config()
749 ctx_dbg(1, ctx, "ddrclkperiod_us: %d\n", ddrclkperiod_us); in csi2_phy_config()
753 ctx_dbg(1, ctx, "ths_term: %d (0x%02x)\n", ths_term, ths_term); in csi2_phy_config()
771 ctx_dbg(1, ctx, "ths_settle: %d (0x%02x)\n", ths_settle, ths_settle); in csi2_phy_config()
773 reg0 = reg_read(ctx->cc, CAL_CSI2_PHY_REG0); in csi2_phy_config()
779 ctx_dbg(1, ctx, "CSI2_%d_REG0 = 0x%08x\n", (ctx->csi2_port - 1), reg0); in csi2_phy_config()
780 reg_write(ctx->cc, CAL_CSI2_PHY_REG0, reg0); in csi2_phy_config()
782 reg1 = reg_read(ctx->cc, CAL_CSI2_PHY_REG1); in csi2_phy_config()
788 ctx_dbg(1, ctx, "CSI2_%d_REG1 = 0x%08x\n", (ctx->csi2_port - 1), reg1); in csi2_phy_config()
789 reg_write(ctx->cc, CAL_CSI2_PHY_REG1, reg1); in csi2_phy_config()
792 static int cal_get_external_info(struct cal_ctx *ctx) in cal_get_external_info() argument
796 if (!ctx->sensor) in cal_get_external_info()
799 ctrl = v4l2_ctrl_find(ctx->sensor->ctrl_handler, V4L2_CID_PIXEL_RATE); in cal_get_external_info()
801 ctx_err(ctx, "no pixel rate control in subdev: %s\n", in cal_get_external_info()
802 ctx->sensor->name); in cal_get_external_info()
806 ctx->external_rate = v4l2_ctrl_g_ctrl_int64(ctrl); in cal_get_external_info()
807 ctx_dbg(3, ctx, "sensor Pixel Rate: %d\n", ctx->external_rate); in cal_get_external_info()
812 static inline void cal_schedule_next_buffer(struct cal_ctx *ctx) in cal_schedule_next_buffer() argument
814 struct cal_dmaqueue *dma_q = &ctx->vidq; in cal_schedule_next_buffer()
819 ctx->next_frm = buf; in cal_schedule_next_buffer()
823 cal_wr_dma_addr(ctx, addr); in cal_schedule_next_buffer()
826 static inline void cal_process_buffer_complete(struct cal_ctx *ctx) in cal_process_buffer_complete() argument
828 ctx->cur_frm->vb.vb2_buf.timestamp = ktime_get_ns(); in cal_process_buffer_complete()
829 ctx->cur_frm->vb.field = ctx->m_fmt.field; in cal_process_buffer_complete()
830 ctx->cur_frm->vb.sequence = ctx->sequence++; in cal_process_buffer_complete()
832 vb2_buffer_done(&ctx->cur_frm->vb.vb2_buf, VB2_BUF_STATE_DONE); in cal_process_buffer_complete()
833 ctx->cur_frm = ctx->next_frm; in cal_process_buffer_complete()
844 struct cal_ctx *ctx; in cal_irq() local
856 ctx = dev->ctx[0]; in cal_irq()
858 if (ctx->cur_frm != ctx->next_frm) in cal_irq()
859 cal_process_buffer_complete(ctx); in cal_irq()
863 ctx = dev->ctx[1]; in cal_irq()
865 if (ctx->cur_frm != ctx->next_frm) in cal_irq()
866 cal_process_buffer_complete(ctx); in cal_irq()
878 ctx = dev->ctx[0]; in cal_irq()
879 dma_q = &ctx->vidq; in cal_irq()
881 spin_lock(&ctx->slock); in cal_irq()
883 ctx->cur_frm == ctx->next_frm) in cal_irq()
884 cal_schedule_next_buffer(ctx); in cal_irq()
885 spin_unlock(&ctx->slock); in cal_irq()
889 ctx = dev->ctx[1]; in cal_irq()
890 dma_q = &ctx->vidq; in cal_irq()
892 spin_lock(&ctx->slock); in cal_irq()
894 ctx->cur_frm == ctx->next_frm) in cal_irq()
895 cal_schedule_next_buffer(ctx); in cal_irq()
896 spin_unlock(&ctx->slock); in cal_irq()
909 struct cal_ctx *ctx = video_drvdata(file); in cal_querycap() local
915 "platform:%s", ctx->v4l2_dev.name); in cal_querycap()
922 struct cal_ctx *ctx = video_drvdata(file); in cal_enum_fmt_vid_cap() local
925 if (f->index >= ctx->num_active_fmt) in cal_enum_fmt_vid_cap()
928 fmt = ctx->active_fmt[f->index]; in cal_enum_fmt_vid_cap()
935 static int __subdev_get_format(struct cal_ctx *ctx, in __subdev_get_format() argument
945 ret = v4l2_subdev_call(ctx->sensor, pad, get_fmt, NULL, &sd_fmt); in __subdev_get_format()
951 ctx_dbg(1, ctx, "%s %dx%d code:%04X\n", __func__, in __subdev_get_format()
957 static int __subdev_set_format(struct cal_ctx *ctx, in __subdev_set_format() argument
968 ret = v4l2_subdev_call(ctx->sensor, pad, set_fmt, NULL, &sd_fmt); in __subdev_set_format()
972 ctx_dbg(1, ctx, "%s %dx%d code:%04X\n", __func__, in __subdev_set_format()
978 static int cal_calc_format_size(struct cal_ctx *ctx, in cal_calc_format_size() argument
983 ctx_dbg(3, ctx, "No cal_fmt provided!\n"); in cal_calc_format_size()
994 ctx_dbg(3, ctx, "%s: fourcc: %s size: %dx%d bpl:%d img_size:%d\n", in cal_calc_format_size()
1005 struct cal_ctx *ctx = video_drvdata(file); in cal_g_fmt_vid_cap() local
1007 *f = ctx->v_fmt; in cal_g_fmt_vid_cap()
1015 struct cal_ctx *ctx = video_drvdata(file); in cal_try_fmt_vid_cap() local
1020 fmt = find_format_by_pix(ctx, f->fmt.pix.pixelformat); in cal_try_fmt_vid_cap()
1022 ctx_dbg(3, ctx, "Fourcc format (0x%08x) not found.\n", in cal_try_fmt_vid_cap()
1026 fmt = ctx->active_fmt[0]; in cal_try_fmt_vid_cap()
1030 f->fmt.pix.field = ctx->v_fmt.fmt.pix.field; in cal_try_fmt_vid_cap()
1039 ret = v4l2_subdev_call(ctx->sensor, pad, enum_frame_size, in cal_try_fmt_vid_cap()
1059 f->fmt.pix.width = ctx->v_fmt.fmt.pix.width; in cal_try_fmt_vid_cap()
1060 f->fmt.pix.height = ctx->v_fmt.fmt.pix.height; in cal_try_fmt_vid_cap()
1067 f->fmt.pix.colorspace = ctx->v_fmt.fmt.pix.colorspace; in cal_try_fmt_vid_cap()
1068 return cal_calc_format_size(ctx, fmt, f); in cal_try_fmt_vid_cap()
1074 struct cal_ctx *ctx = video_drvdata(file); in cal_s_fmt_vid_cap() local
1075 struct vb2_queue *q = &ctx->vb_vidq; in cal_s_fmt_vid_cap()
1081 ctx_dbg(3, ctx, "%s device busy\n", __func__); in cal_s_fmt_vid_cap()
1089 fmt = find_format_by_pix(ctx, f->fmt.pix.pixelformat); in cal_s_fmt_vid_cap()
1093 ret = __subdev_set_format(ctx, &mbus_fmt); in cal_s_fmt_vid_cap()
1099 ctx_dbg(3, ctx, in cal_s_fmt_vid_cap()
1105 v4l2_fill_pix_format(&ctx->v_fmt.fmt.pix, &mbus_fmt); in cal_s_fmt_vid_cap()
1106 ctx->v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in cal_s_fmt_vid_cap()
1107 ctx->v_fmt.fmt.pix.pixelformat = fmt->fourcc; in cal_s_fmt_vid_cap()
1108 cal_calc_format_size(ctx, fmt, &ctx->v_fmt); in cal_s_fmt_vid_cap()
1109 ctx->fmt = fmt; in cal_s_fmt_vid_cap()
1110 ctx->m_fmt = mbus_fmt; in cal_s_fmt_vid_cap()
1111 *f = ctx->v_fmt; in cal_s_fmt_vid_cap()
1119 struct cal_ctx *ctx = video_drvdata(file); in cal_enum_framesizes() local
1125 fmt = find_format_by_pix(ctx, fsize->pixel_format); in cal_enum_framesizes()
1127 ctx_dbg(3, ctx, "Invalid pixel code: %x\n", in cal_enum_framesizes()
1136 ret = v4l2_subdev_call(ctx->sensor, pad, enum_frame_size, NULL, &fse); in cal_enum_framesizes()
1140 ctx_dbg(1, ctx, "%s: index: %d code: %x W:[%d,%d] H:[%d,%d]\n", in cal_enum_framesizes()
1164 struct cal_ctx *ctx = video_drvdata(file); in cal_g_input() local
1166 *i = ctx->input; in cal_g_input()
1172 struct cal_ctx *ctx = video_drvdata(file); in cal_s_input() local
1177 ctx->input = i; in cal_s_input()
1185 struct cal_ctx *ctx = video_drvdata(file); in cal_enum_frameintervals() local
1195 fmt = find_format_by_pix(ctx, fival->pixel_format); in cal_enum_frameintervals()
1200 ret = v4l2_subdev_call(ctx->sensor, pad, enum_frame_interval, in cal_enum_frameintervals()
1217 struct cal_ctx *ctx = vb2_get_drv_priv(vq); in cal_queue_setup() local
1218 unsigned size = ctx->v_fmt.fmt.pix.sizeimage; in cal_queue_setup()
1232 ctx_dbg(3, ctx, "nbuffers=%d, size=%d\n", *nbuffers, sizes[0]); in cal_queue_setup()
1239 struct cal_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); in cal_buffer_prepare() local
1244 if (WARN_ON(!ctx->fmt)) in cal_buffer_prepare()
1247 size = ctx->v_fmt.fmt.pix.sizeimage; in cal_buffer_prepare()
1249 ctx_err(ctx, in cal_buffer_prepare()
1261 struct cal_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); in cal_buffer_queue() local
1264 struct cal_dmaqueue *vidq = &ctx->vidq; in cal_buffer_queue()
1268 spin_lock_irqsave(&ctx->slock, flags); in cal_buffer_queue()
1270 spin_unlock_irqrestore(&ctx->slock, flags); in cal_buffer_queue()
1275 struct cal_ctx *ctx = vb2_get_drv_priv(vq); in cal_start_streaming() local
1276 struct cal_dmaqueue *dma_q = &ctx->vidq; in cal_start_streaming()
1282 spin_lock_irqsave(&ctx->slock, flags); in cal_start_streaming()
1284 spin_unlock_irqrestore(&ctx->slock, flags); in cal_start_streaming()
1285 ctx_dbg(3, ctx, "buffer queue is empty\n"); in cal_start_streaming()
1290 ctx->cur_frm = buf; in cal_start_streaming()
1291 ctx->next_frm = buf; in cal_start_streaming()
1293 spin_unlock_irqrestore(&ctx->slock, flags); in cal_start_streaming()
1295 addr = vb2_dma_contig_plane_dma_addr(&ctx->cur_frm->vb.vb2_buf, 0); in cal_start_streaming()
1296 ctx->sequence = 0; in cal_start_streaming()
1298 ret = cal_get_external_info(ctx); in cal_start_streaming()
1302 cal_runtime_get(ctx->dev); in cal_start_streaming()
1304 enable_irqs(ctx); in cal_start_streaming()
1305 camerarx_phy_enable(ctx); in cal_start_streaming()
1306 csi2_init(ctx); in cal_start_streaming()
1307 csi2_phy_config(ctx); in cal_start_streaming()
1308 csi2_lane_config(ctx); in cal_start_streaming()
1309 csi2_ctx_config(ctx); in cal_start_streaming()
1310 pix_proc_config(ctx); in cal_start_streaming()
1311 cal_wr_dma_config(ctx, ctx->v_fmt.fmt.pix.bytesperline); in cal_start_streaming()
1312 cal_wr_dma_addr(ctx, addr); in cal_start_streaming()
1313 csi2_ppi_enable(ctx); in cal_start_streaming()
1315 ret = v4l2_subdev_call(ctx->sensor, video, s_stream, 1); in cal_start_streaming()
1317 ctx_err(ctx, "stream on failed in subdev\n"); in cal_start_streaming()
1318 cal_runtime_put(ctx->dev); in cal_start_streaming()
1323 cal_quickdump_regs(ctx->dev); in cal_start_streaming()
1337 struct cal_ctx *ctx = vb2_get_drv_priv(vq); in cal_stop_streaming() local
1338 struct cal_dmaqueue *dma_q = &ctx->vidq; in cal_stop_streaming()
1342 if (v4l2_subdev_call(ctx->sensor, video, s_stream, 0)) in cal_stop_streaming()
1343 ctx_err(ctx, "stream off failed in subdev\n"); in cal_stop_streaming()
1345 csi2_ppi_disable(ctx); in cal_stop_streaming()
1346 disable_irqs(ctx); in cal_stop_streaming()
1349 spin_lock_irqsave(&ctx->slock, flags); in cal_stop_streaming()
1355 if (ctx->cur_frm == ctx->next_frm) { in cal_stop_streaming()
1356 vb2_buffer_done(&ctx->cur_frm->vb.vb2_buf, VB2_BUF_STATE_ERROR); in cal_stop_streaming()
1358 vb2_buffer_done(&ctx->cur_frm->vb.vb2_buf, VB2_BUF_STATE_ERROR); in cal_stop_streaming()
1359 vb2_buffer_done(&ctx->next_frm->vb.vb2_buf, in cal_stop_streaming()
1362 ctx->cur_frm = NULL; in cal_stop_streaming()
1363 ctx->next_frm = NULL; in cal_stop_streaming()
1364 spin_unlock_irqrestore(&ctx->slock, flags); in cal_stop_streaming()
1366 cal_runtime_put(ctx->dev); in cal_stop_streaming()
1427 static int cal_complete_ctx(struct cal_ctx *ctx);
1433 struct cal_ctx *ctx = notifier_to_ctx(notifier); in cal_async_bound() local
1438 if (ctx->sensor) { in cal_async_bound()
1439 ctx_info(ctx, "Rejecting subdev %s (Already set!!)", in cal_async_bound()
1444 ctx->sensor = subdev; in cal_async_bound()
1445 ctx_dbg(1, ctx, "Using sensor %s for capture\n", subdev->name); in cal_async_bound()
1448 ctx->num_active_fmt = 0; in cal_async_bound()
1459 ctx_dbg(2, ctx, in cal_async_bound()
1467 ctx->active_fmt[i] = fmt; in cal_async_bound()
1468 ctx_dbg(2, ctx, in cal_async_bound()
1472 ctx->num_active_fmt = ++i; in cal_async_bound()
1478 ctx_err(ctx, "No suitable format reported by subdev %s\n", in cal_async_bound()
1483 cal_complete_ctx(ctx); in cal_async_bound()
1490 struct cal_ctx *ctx = notifier_to_ctx(notifier); in cal_async_complete() local
1495 ret = __subdev_get_format(ctx, &mbus_fmt); in cal_async_complete()
1499 fmt = find_format_by_code(ctx, mbus_fmt.code); in cal_async_complete()
1501 ctx_dbg(3, ctx, "mbus code format (0x%08x) not found.\n", in cal_async_complete()
1507 v4l2_fill_pix_format(&ctx->v_fmt.fmt.pix, &mbus_fmt); in cal_async_complete()
1508 ctx->v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in cal_async_complete()
1509 ctx->v_fmt.fmt.pix.pixelformat = fmt->fourcc; in cal_async_complete()
1510 cal_calc_format_size(ctx, fmt, &ctx->v_fmt); in cal_async_complete()
1511 ctx->fmt = fmt; in cal_async_complete()
1512 ctx->m_fmt = mbus_fmt; in cal_async_complete()
1522 static int cal_complete_ctx(struct cal_ctx *ctx) in cal_complete_ctx() argument
1528 ctx->timeperframe = tpf_default; in cal_complete_ctx()
1529 ctx->external_rate = 192000000; in cal_complete_ctx()
1532 spin_lock_init(&ctx->slock); in cal_complete_ctx()
1533 mutex_init(&ctx->mutex); in cal_complete_ctx()
1536 q = &ctx->vb_vidq; in cal_complete_ctx()
1539 q->drv_priv = ctx; in cal_complete_ctx()
1544 q->lock = &ctx->mutex; in cal_complete_ctx()
1546 q->dev = ctx->v4l2_dev.dev; in cal_complete_ctx()
1553 INIT_LIST_HEAD(&ctx->vidq.active); in cal_complete_ctx()
1555 vfd = &ctx->vdev; in cal_complete_ctx()
1557 vfd->v4l2_dev = &ctx->v4l2_dev; in cal_complete_ctx()
1564 vfd->lock = &ctx->mutex; in cal_complete_ctx()
1565 video_set_drvdata(vfd, ctx); in cal_complete_ctx()
1571 v4l2_info(&ctx->v4l2_dev, "V4L2 device registered as %s\n", in cal_complete_ctx()
1640 static int of_cal_create_instance(struct cal_ctx *ctx, int inst) in of_cal_create_instance() argument
1642 struct platform_device *pdev = ctx->dev->pdev; in of_cal_create_instance()
1651 asd = &ctx->asd; in of_cal_create_instance()
1652 endpoint = &ctx->endpoint; in of_cal_create_instance()
1659 ctx_dbg(3, ctx, "Scanning Port node for csi2 port: %d\n", inst); in of_cal_create_instance()
1663 ctx_dbg(1, ctx, "No port node found for csi2 port:%d\n", in of_cal_create_instance()
1670 ctx_dbg(3, ctx, "port:%d inst:%d <reg>:%d\n", in of_cal_create_instance()
1679 ctx_dbg(1, ctx, "No port node matches csi2 port:%d\n", in of_cal_create_instance()
1684 ctx_dbg(3, ctx, "Scanning sub-device for csi2 port: %d\n", in of_cal_create_instance()
1689 ctx_dbg(3, ctx, "can't get next endpoint\n"); in of_cal_create_instance()
1695 ctx_dbg(3, ctx, "can't get remote parent\n"); in of_cal_create_instance()
1704 ctx_err(ctx, "Port:%d sub-device %pOFn is not a CSI2 device\n", in of_cal_create_instance()
1710 ctx->virtual_channel = endpoint->base.id; in of_cal_create_instance()
1712 ctx_dbg(3, ctx, "Port:%d v4l2-endpoint: CSI2\n", inst); in of_cal_create_instance()
1713 ctx_dbg(3, ctx, "Virtual Channel=%d\n", ctx->virtual_channel); in of_cal_create_instance()
1714 ctx_dbg(3, ctx, "flags=0x%08x\n", endpoint->bus.mipi_csi2.flags); in of_cal_create_instance()
1715 ctx_dbg(3, ctx, "clock_lane=%d\n", endpoint->bus.mipi_csi2.clock_lane); in of_cal_create_instance()
1716 ctx_dbg(3, ctx, "num_data_lanes=%d\n", in of_cal_create_instance()
1718 ctx_dbg(3, ctx, "data_lanes= <\n"); in of_cal_create_instance()
1720 ctx_dbg(3, ctx, "\t%d\n", in of_cal_create_instance()
1722 ctx_dbg(3, ctx, "\t>\n"); in of_cal_create_instance()
1724 ctx_dbg(1, ctx, "Port: %d found sub-device %pOFn\n", in of_cal_create_instance()
1727 v4l2_async_notifier_init(&ctx->notifier); in of_cal_create_instance()
1729 ret = v4l2_async_notifier_add_subdev(&ctx->notifier, asd); in of_cal_create_instance()
1731 ctx_err(ctx, "Error adding asd\n"); in of_cal_create_instance()
1735 ctx->notifier.ops = &cal_async_ops; in of_cal_create_instance()
1736 ret = v4l2_async_notifier_register(&ctx->v4l2_dev, in of_cal_create_instance()
1737 &ctx->notifier); in of_cal_create_instance()
1739 ctx_err(ctx, "Error registering async notifier\n"); in of_cal_create_instance()
1740 v4l2_async_notifier_cleanup(&ctx->notifier); in of_cal_create_instance()
1761 struct cal_ctx *ctx; in cal_create_instance() local
1765 ctx = devm_kzalloc(&dev->pdev->dev, sizeof(*ctx), GFP_KERNEL); in cal_create_instance()
1766 if (!ctx) in cal_create_instance()
1770 ctx->dev = dev; in cal_create_instance()
1772 snprintf(ctx->v4l2_dev.name, sizeof(ctx->v4l2_dev.name), in cal_create_instance()
1774 ret = v4l2_device_register(&dev->pdev->dev, &ctx->v4l2_dev); in cal_create_instance()
1778 hdl = &ctx->ctrl_handler; in cal_create_instance()
1781 ctx_err(ctx, "Failed to init ctrl handler\n"); in cal_create_instance()
1784 ctx->v4l2_dev.ctrl_handler = hdl; in cal_create_instance()
1787 ctx->cc = dev->cc[inst]; in cal_create_instance()
1790 ctx->csi2_port = inst + 1; in cal_create_instance()
1792 ret = of_cal_create_instance(ctx, inst); in cal_create_instance()
1797 return ctx; in cal_create_instance()
1802 v4l2_device_unregister(&ctx->v4l2_dev); in cal_create_instance()
1810 struct cal_ctx *ctx; in cal_probe() local
1856 dev->ctx[0] = NULL; in cal_probe()
1857 dev->ctx[1] = NULL; in cal_probe()
1859 dev->ctx[0] = cal_create_instance(dev, 0); in cal_probe()
1860 dev->ctx[1] = cal_create_instance(dev, 1); in cal_probe()
1861 if (!dev->ctx[0] && !dev->ctx[1]) { in cal_probe()
1882 ctx = dev->ctx[i]; in cal_probe()
1883 if (ctx) { in cal_probe()
1884 v4l2_async_notifier_unregister(&ctx->notifier); in cal_probe()
1885 v4l2_async_notifier_cleanup(&ctx->notifier); in cal_probe()
1886 v4l2_ctrl_handler_free(&ctx->ctrl_handler); in cal_probe()
1887 v4l2_device_unregister(&ctx->v4l2_dev); in cal_probe()
1898 struct cal_ctx *ctx; in cal_remove() local
1906 ctx = dev->ctx[i]; in cal_remove()
1907 if (ctx) { in cal_remove()
1908 ctx_dbg(1, ctx, "unregistering %s\n", in cal_remove()
1909 video_device_node_name(&ctx->vdev)); in cal_remove()
1910 camerarx_phy_disable(ctx); in cal_remove()
1911 v4l2_async_notifier_unregister(&ctx->notifier); in cal_remove()
1912 v4l2_async_notifier_cleanup(&ctx->notifier); in cal_remove()
1913 v4l2_ctrl_handler_free(&ctx->ctrl_handler); in cal_remove()
1914 v4l2_device_unregister(&ctx->v4l2_dev); in cal_remove()
1915 video_unregister_device(&ctx->vdev); in cal_remove()