Lines Matching refs:pcdev

382 static void mx27_update_emma_buf(struct mx2_camera_dev *pcdev,  in mx27_update_emma_buf()  argument
385 struct mx2_fmt_cfg *prp = pcdev->emma_prp; in mx27_update_emma_buf()
388 writel(phys, pcdev->base_emma + in mx27_update_emma_buf()
391 writel(phys, pcdev->base_emma + in mx27_update_emma_buf()
394 u32 imgsize = pcdev->soc_host.icd->user_height * in mx27_update_emma_buf()
395 pcdev->soc_host.icd->user_width; in mx27_update_emma_buf()
397 writel(phys + imgsize, pcdev->base_emma + in mx27_update_emma_buf()
399 writel(phys + ((5 * imgsize) / 4), pcdev->base_emma + in mx27_update_emma_buf()
405 static void mx2_camera_deactivate(struct mx2_camera_dev *pcdev) in mx2_camera_deactivate() argument
407 clk_disable_unprepare(pcdev->clk_csi_ahb); in mx2_camera_deactivate()
408 clk_disable_unprepare(pcdev->clk_csi_per); in mx2_camera_deactivate()
409 writel(0, pcdev->base_csi + CSICR1); in mx2_camera_deactivate()
410 writel(0, pcdev->base_emma + PRP_CNTL); in mx2_camera_deactivate()
433 struct mx2_camera_dev *pcdev = ici->priv; in mx2_camera_clock_start() local
437 ret = clk_prepare_enable(pcdev->clk_csi_ahb); in mx2_camera_clock_start()
441 ret = clk_prepare_enable(pcdev->clk_csi_per); in mx2_camera_clock_start()
448 pcdev->csicr1 = csicr1; in mx2_camera_clock_start()
449 writel(pcdev->csicr1, pcdev->base_csi + CSICR1); in mx2_camera_clock_start()
451 pcdev->frame_count = 0; in mx2_camera_clock_start()
456 clk_disable_unprepare(pcdev->clk_csi_ahb); in mx2_camera_clock_start()
463 struct mx2_camera_dev *pcdev = ici->priv; in mx2_camera_clock_stop() local
465 mx2_camera_deactivate(pcdev); in mx2_camera_clock_stop()
479 struct mx2_camera_dev *pcdev = ici->priv; in mx2_videobuf_setup() local
487 alloc_ctxs[0] = pcdev->alloc_ctx; in mx2_videobuf_setup()
538 struct mx2_camera_dev *pcdev = ici->priv; in mx2_videobuf_queue() local
545 spin_lock_irqsave(&pcdev->lock, flags); in mx2_videobuf_queue()
547 list_add_tail(&buf->internal.queue, &pcdev->capture); in mx2_videobuf_queue()
549 spin_unlock_irqrestore(&pcdev->lock, flags); in mx2_videobuf_queue()
557 struct mx2_camera_dev *pcdev = ici->priv; in mx27_camera_emma_buf_init() local
558 struct mx2_fmt_cfg *prp = pcdev->emma_prp; in mx27_camera_emma_buf_init()
560 writel((pcdev->s_width << 16) | pcdev->s_height, in mx27_camera_emma_buf_init()
561 pcdev->base_emma + PRP_SRC_FRAME_SIZE); in mx27_camera_emma_buf_init()
563 pcdev->base_emma + PRP_SRC_PIXEL_FORMAT_CNTL); in mx27_camera_emma_buf_init()
566 pcdev->base_emma + PRP_CH1_OUT_IMAGE_SIZE); in mx27_camera_emma_buf_init()
568 pcdev->base_emma + PRP_DEST_CH1_LINE_STRIDE); in mx27_camera_emma_buf_init()
570 pcdev->base_emma + PRP_CH1_PIXEL_FORMAT_CNTL); in mx27_camera_emma_buf_init()
573 pcdev->base_emma + PRP_CH2_OUT_IMAGE_SIZE); in mx27_camera_emma_buf_init()
577 writel(prp->cfg.irq_flags, pcdev->base_emma + PRP_INTR_CNTL); in mx27_camera_emma_buf_init()
580 static void mx2_prp_resize_commit(struct mx2_camera_dev *pcdev) in mx2_prp_resize_commit() argument
585 unsigned char *s = pcdev->resizing[dir].s; in mx2_prp_resize_commit()
586 int len = pcdev->resizing[dir].len; in mx2_prp_resize_commit()
609 if (pcdev->resizing[dir].algo == RESIZE_ALGO_BILINEAR) in mx2_prp_resize_commit()
612 if (pcdev->emma_prp->cfg.channel == 1) { in mx2_prp_resize_commit()
614 writel(coeff[0], pcdev->base_emma + in mx2_prp_resize_commit()
616 writel(coeff[1], pcdev->base_emma + in mx2_prp_resize_commit()
618 writel(valid, pcdev->base_emma + in mx2_prp_resize_commit()
621 writel(coeff[0], pcdev->base_emma + in mx2_prp_resize_commit()
623 writel(coeff[1], pcdev->base_emma + in mx2_prp_resize_commit()
625 writel(valid, pcdev->base_emma + in mx2_prp_resize_commit()
630 writel(coeff[0], pcdev->base_emma + in mx2_prp_resize_commit()
632 writel(coeff[1], pcdev->base_emma + in mx2_prp_resize_commit()
634 writel(valid, pcdev->base_emma + in mx2_prp_resize_commit()
637 writel(coeff[0], pcdev->base_emma + in mx2_prp_resize_commit()
639 writel(coeff[1], pcdev->base_emma + in mx2_prp_resize_commit()
641 writel(valid, pcdev->base_emma + in mx2_prp_resize_commit()
653 struct mx2_camera_dev *pcdev = ici->priv; in mx2_start_streaming() local
654 struct mx2_fmt_cfg *prp = pcdev->emma_prp; in mx2_start_streaming()
664 spin_lock_irqsave(&pcdev->lock, flags); in mx2_start_streaming()
666 buf = list_first_entry(&pcdev->capture, struct mx2_buffer, in mx2_start_streaming()
672 mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum); in mx2_start_streaming()
673 list_move_tail(pcdev->capture.next, &pcdev->active_bufs); in mx2_start_streaming()
675 buf = list_first_entry(&pcdev->capture, struct mx2_buffer, in mx2_start_streaming()
681 mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum); in mx2_start_streaming()
682 list_move_tail(pcdev->capture.next, &pcdev->active_bufs); in mx2_start_streaming()
687 spin_unlock_irqrestore(&pcdev->lock, flags); in mx2_start_streaming()
698 pcdev->discard_size = icd->user_height * bytesperline; in mx2_start_streaming()
699 pcdev->discard_buffer = dma_alloc_coherent(ici->v4l2_dev.dev, in mx2_start_streaming()
700 pcdev->discard_size, in mx2_start_streaming()
701 &pcdev->discard_buffer_dma, GFP_ATOMIC); in mx2_start_streaming()
702 if (!pcdev->discard_buffer) { in mx2_start_streaming()
703 spin_unlock_irqrestore(&pcdev->lock, flags); in mx2_start_streaming()
707 pcdev->buf_discard[0].discard = true; in mx2_start_streaming()
708 list_add_tail(&pcdev->buf_discard[0].queue, in mx2_start_streaming()
709 &pcdev->discard); in mx2_start_streaming()
711 pcdev->buf_discard[1].discard = true; in mx2_start_streaming()
712 list_add_tail(&pcdev->buf_discard[1].queue, in mx2_start_streaming()
713 &pcdev->discard); in mx2_start_streaming()
715 mx2_prp_resize_commit(pcdev); in mx2_start_streaming()
728 pcdev->base_emma + PRP_CNTL); in mx2_start_streaming()
737 pcdev->base_emma + PRP_CNTL); in mx2_start_streaming()
739 spin_unlock_irqrestore(&pcdev->lock, flags); in mx2_start_streaming()
749 struct mx2_camera_dev *pcdev = ici->priv; in mx2_stop_streaming() local
750 struct mx2_fmt_cfg *prp = pcdev->emma_prp; in mx2_stop_streaming()
755 spin_lock_irqsave(&pcdev->lock, flags); in mx2_stop_streaming()
757 cntl = readl(pcdev->base_emma + PRP_CNTL); in mx2_stop_streaming()
760 pcdev->base_emma + PRP_CNTL); in mx2_stop_streaming()
763 pcdev->base_emma + PRP_CNTL); in mx2_stop_streaming()
765 INIT_LIST_HEAD(&pcdev->capture); in mx2_stop_streaming()
766 INIT_LIST_HEAD(&pcdev->active_bufs); in mx2_stop_streaming()
767 INIT_LIST_HEAD(&pcdev->discard); in mx2_stop_streaming()
769 b = pcdev->discard_buffer; in mx2_stop_streaming()
770 pcdev->discard_buffer = NULL; in mx2_stop_streaming()
772 spin_unlock_irqrestore(&pcdev->lock, flags); in mx2_stop_streaming()
775 pcdev->discard_size, b, pcdev->discard_buffer_dma); in mx2_stop_streaming()
810 static int mx27_camera_emma_prp_reset(struct mx2_camera_dev *pcdev) in mx27_camera_emma_prp_reset() argument
814 readl(pcdev->base_emma + PRP_CNTL); in mx27_camera_emma_prp_reset()
815 writel(PRP_CNTL_SWRST, pcdev->base_emma + PRP_CNTL); in mx27_camera_emma_prp_reset()
817 if (!(readl(pcdev->base_emma + PRP_CNTL) & PRP_CNTL_SWRST)) in mx27_camera_emma_prp_reset()
830 struct mx2_camera_dev *pcdev = ici->priv; in mx2_camera_set_bus_param() local
835 u32 csicr1 = pcdev->csicr1; in mx2_camera_set_bus_param()
854 if (pcdev->platform_flags & MX2_CAMERA_HSYNC_HIGH) in mx2_camera_set_bus_param()
862 if (pcdev->platform_flags & MX2_CAMERA_PCLK_SAMPLE_RISING) in mx2_camera_set_bus_param()
876 csicr1 = (csicr1 & ~CSICR1_FMT_MASK) | pcdev->emma_prp->cfg.csicr1; in mx2_camera_set_bus_param()
884 if (pcdev->platform_flags & MX2_CAMERA_EXT_VSYNC) in mx2_camera_set_bus_param()
886 if (pcdev->platform_flags & MX2_CAMERA_CCIR) in mx2_camera_set_bus_param()
888 if (pcdev->platform_flags & MX2_CAMERA_CCIR_INTERLACE) in mx2_camera_set_bus_param()
890 if (pcdev->platform_flags & MX2_CAMERA_GATED_CLOCK) in mx2_camera_set_bus_param()
892 if (pcdev->platform_flags & MX2_CAMERA_INV_DATA) in mx2_camera_set_bus_param()
895 pcdev->csicr1 = csicr1; in mx2_camera_set_bus_param()
902 ret = mx27_camera_emma_prp_reset(pcdev); in mx2_camera_set_bus_param()
906 writel(pcdev->csicr1, pcdev->base_csi + CSICR1); in mx2_camera_set_bus_param()
1007 static int mx2_emmaprp_resize(struct mx2_camera_dev *pcdev, in mx2_emmaprp_resize() argument
1119 memcpy(&pcdev->resizing[dir], &tmprsz, sizeof(tmprsz)); in mx2_emmaprp_resize()
1128 struct mx2_camera_dev *pcdev = ici->priv; in mx2_camera_set_fmt() local
1159 pcdev->s_width = mf->width; in mx2_camera_set_fmt()
1160 pcdev->s_height = mf->height; in mx2_camera_set_fmt()
1162 __func__, pcdev->s_width, pcdev->s_height); in mx2_camera_set_fmt()
1164 pcdev->emma_prp = mx27_emma_prp_get_format(xlate->code, in mx2_camera_set_fmt()
1167 memset(pcdev->resizing, 0, sizeof(pcdev->resizing)); in mx2_camera_set_fmt()
1169 pcdev->emma_prp->cfg.in_fmt == PRP_CNTL_DATA_IN_YUV422) { in mx2_camera_set_fmt()
1170 if (mx2_emmaprp_resize(pcdev, mf, pix, true) < 0) in mx2_camera_set_fmt()
1202 struct mx2_camera_dev *pcdev = ici->priv; in mx2_camera_try_fmt() local
1233 __func__, pcdev->s_width, pcdev->s_height); in mx2_camera_try_fmt()
1241 if (mx2_emmaprp_resize(pcdev, mf, pix, false) < 0) in mx2_camera_try_fmt()
1303 static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev, in mx27_camera_frame_done_emma() argument
1307 struct mx2_fmt_cfg *prp = pcdev->emma_prp; in mx27_camera_frame_done_emma()
1315 ibuf = list_first_entry(&pcdev->active_bufs, struct mx2_buf_internal, in mx27_camera_frame_done_emma()
1325 list_move_tail(pcdev->active_bufs.next, &pcdev->discard); in mx27_camera_frame_done_emma()
1334 if (readl(pcdev->base_emma + PRP_DEST_RGB1_PTR + in mx27_camera_frame_done_emma()
1336 dev_err(pcdev->dev, "%lx != %x\n", phys, in mx27_camera_frame_done_emma()
1337 readl(pcdev->base_emma + in mx27_camera_frame_done_emma()
1341 if (readl(pcdev->base_emma + PRP_DEST_Y_PTR - in mx27_camera_frame_done_emma()
1343 dev_err(pcdev->dev, "%lx != %x\n", phys, in mx27_camera_frame_done_emma()
1344 readl(pcdev->base_emma + in mx27_camera_frame_done_emma()
1349 dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%p %lu\n", __func__, vb, in mx27_camera_frame_done_emma()
1355 vbuf->sequence = pcdev->frame_count; in mx27_camera_frame_done_emma()
1362 pcdev->frame_count++; in mx27_camera_frame_done_emma()
1364 if (list_empty(&pcdev->capture)) { in mx27_camera_frame_done_emma()
1365 if (list_empty(&pcdev->discard)) { in mx27_camera_frame_done_emma()
1366 dev_warn(pcdev->dev, "%s: trying to access empty discard list\n", in mx27_camera_frame_done_emma()
1371 ibuf = list_first_entry(&pcdev->discard, in mx27_camera_frame_done_emma()
1375 list_move_tail(pcdev->discard.next, &pcdev->active_bufs); in mx27_camera_frame_done_emma()
1376 mx27_update_emma_buf(pcdev, pcdev->discard_buffer_dma, bufnum); in mx27_camera_frame_done_emma()
1380 buf = list_first_entry(&pcdev->capture, struct mx2_buffer, in mx27_camera_frame_done_emma()
1385 list_move_tail(pcdev->capture.next, &pcdev->active_bufs); in mx27_camera_frame_done_emma()
1390 mx27_update_emma_buf(pcdev, phys, bufnum); in mx27_camera_frame_done_emma()
1395 struct mx2_camera_dev *pcdev = data; in mx27_camera_emma_irq() local
1396 unsigned int status = readl(pcdev->base_emma + PRP_INTRSTATUS); in mx27_camera_emma_irq()
1399 spin_lock(&pcdev->lock); in mx27_camera_emma_irq()
1401 if (list_empty(&pcdev->active_bufs)) { in mx27_camera_emma_irq()
1402 dev_warn(pcdev->dev, "%s: called while active list is empty\n", in mx27_camera_emma_irq()
1406 spin_unlock(&pcdev->lock); in mx27_camera_emma_irq()
1412 u32 cntl = readl(pcdev->base_emma + PRP_CNTL); in mx27_camera_emma_irq()
1414 pcdev->base_emma + PRP_CNTL); in mx27_camera_emma_irq()
1415 writel(cntl, pcdev->base_emma + PRP_CNTL); in mx27_camera_emma_irq()
1417 ibuf = list_first_entry(&pcdev->active_bufs, in mx27_camera_emma_irq()
1419 mx27_camera_frame_done_emma(pcdev, in mx27_camera_emma_irq()
1429 ibuf = list_first_entry(&pcdev->active_bufs, in mx27_camera_emma_irq()
1431 mx27_camera_frame_done_emma(pcdev, ibuf->bufnum, false); in mx27_camera_emma_irq()
1434 mx27_camera_frame_done_emma(pcdev, 0, false); in mx27_camera_emma_irq()
1436 mx27_camera_frame_done_emma(pcdev, 1, false); in mx27_camera_emma_irq()
1439 spin_unlock(&pcdev->lock); in mx27_camera_emma_irq()
1440 writel(status, pcdev->base_emma + PRP_INTRSTATUS); in mx27_camera_emma_irq()
1447 struct mx2_camera_dev *pcdev = platform_get_drvdata(pdev); in mx27_camera_emma_init() local
1455 dev_err(pcdev->dev, "no EMMA resources\n"); in mx27_camera_emma_init()
1460 pcdev->base_emma = devm_ioremap_resource(pcdev->dev, res_emma); in mx27_camera_emma_init()
1461 if (IS_ERR(pcdev->base_emma)) { in mx27_camera_emma_init()
1462 err = PTR_ERR(pcdev->base_emma); in mx27_camera_emma_init()
1466 err = devm_request_irq(pcdev->dev, irq_emma, mx27_camera_emma_irq, 0, in mx27_camera_emma_init()
1467 MX2_CAM_DRV_NAME, pcdev); in mx27_camera_emma_init()
1469 dev_err(pcdev->dev, "Camera EMMA interrupt register failed\n"); in mx27_camera_emma_init()
1473 pcdev->clk_emma_ipg = devm_clk_get(pcdev->dev, "emma-ipg"); in mx27_camera_emma_init()
1474 if (IS_ERR(pcdev->clk_emma_ipg)) { in mx27_camera_emma_init()
1475 err = PTR_ERR(pcdev->clk_emma_ipg); in mx27_camera_emma_init()
1479 clk_prepare_enable(pcdev->clk_emma_ipg); in mx27_camera_emma_init()
1481 pcdev->clk_emma_ahb = devm_clk_get(pcdev->dev, "emma-ahb"); in mx27_camera_emma_init()
1482 if (IS_ERR(pcdev->clk_emma_ahb)) { in mx27_camera_emma_init()
1483 err = PTR_ERR(pcdev->clk_emma_ahb); in mx27_camera_emma_init()
1487 clk_prepare_enable(pcdev->clk_emma_ahb); in mx27_camera_emma_init()
1489 err = mx27_camera_emma_prp_reset(pcdev); in mx27_camera_emma_init()
1496 clk_disable_unprepare(pcdev->clk_emma_ahb); in mx27_camera_emma_init()
1498 clk_disable_unprepare(pcdev->clk_emma_ipg); in mx27_camera_emma_init()
1505 struct mx2_camera_dev *pcdev; in mx2_camera_probe() local
1520 pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL); in mx2_camera_probe()
1521 if (!pcdev) { in mx2_camera_probe()
1527 pcdev->clk_csi_ahb = devm_clk_get(&pdev->dev, "ahb"); in mx2_camera_probe()
1528 if (IS_ERR(pcdev->clk_csi_ahb)) { in mx2_camera_probe()
1530 err = PTR_ERR(pcdev->clk_csi_ahb); in mx2_camera_probe()
1534 pcdev->clk_csi_per = devm_clk_get(&pdev->dev, "per"); in mx2_camera_probe()
1535 if (IS_ERR(pcdev->clk_csi_per)) { in mx2_camera_probe()
1537 err = PTR_ERR(pcdev->clk_csi_per); in mx2_camera_probe()
1541 pcdev->pdata = pdev->dev.platform_data; in mx2_camera_probe()
1542 if (pcdev->pdata) { in mx2_camera_probe()
1545 pcdev->platform_flags = pcdev->pdata->flags; in mx2_camera_probe()
1547 rate = clk_round_rate(pcdev->clk_csi_per, in mx2_camera_probe()
1548 pcdev->pdata->clk * 2); in mx2_camera_probe()
1553 err = clk_set_rate(pcdev->clk_csi_per, rate); in mx2_camera_probe()
1558 INIT_LIST_HEAD(&pcdev->capture); in mx2_camera_probe()
1559 INIT_LIST_HEAD(&pcdev->active_bufs); in mx2_camera_probe()
1560 INIT_LIST_HEAD(&pcdev->discard); in mx2_camera_probe()
1561 spin_lock_init(&pcdev->lock); in mx2_camera_probe()
1563 pcdev->base_csi = devm_ioremap_resource(&pdev->dev, res_csi); in mx2_camera_probe()
1564 if (IS_ERR(pcdev->base_csi)) { in mx2_camera_probe()
1565 err = PTR_ERR(pcdev->base_csi); in mx2_camera_probe()
1569 pcdev->dev = &pdev->dev; in mx2_camera_probe()
1570 platform_set_drvdata(pdev, pcdev); in mx2_camera_probe()
1582 pcdev->soc_host.drv_name = MX2_CAM_DRV_NAME, in mx2_camera_probe()
1583 pcdev->soc_host.ops = &mx2_soc_camera_host_ops, in mx2_camera_probe()
1584 pcdev->soc_host.priv = pcdev; in mx2_camera_probe()
1585 pcdev->soc_host.v4l2_dev.dev = &pdev->dev; in mx2_camera_probe()
1586 pcdev->soc_host.nr = pdev->id; in mx2_camera_probe()
1588 pcdev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); in mx2_camera_probe()
1589 if (IS_ERR(pcdev->alloc_ctx)) { in mx2_camera_probe()
1590 err = PTR_ERR(pcdev->alloc_ctx); in mx2_camera_probe()
1593 err = soc_camera_host_register(&pcdev->soc_host); in mx2_camera_probe()
1598 clk_get_rate(pcdev->clk_csi_per)); in mx2_camera_probe()
1603 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); in mx2_camera_probe()
1605 clk_disable_unprepare(pcdev->clk_emma_ipg); in mx2_camera_probe()
1606 clk_disable_unprepare(pcdev->clk_emma_ahb); in mx2_camera_probe()
1614 struct mx2_camera_dev *pcdev = container_of(soc_host, in mx2_camera_remove() local
1617 soc_camera_host_unregister(&pcdev->soc_host); in mx2_camera_remove()
1619 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); in mx2_camera_remove()
1621 clk_disable_unprepare(pcdev->clk_emma_ipg); in mx2_camera_remove()
1622 clk_disable_unprepare(pcdev->clk_emma_ahb); in mx2_camera_remove()