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()
478 struct mx2_camera_dev *pcdev = ici->priv; in mx2_videobuf_setup() local
486 alloc_ctxs[0] = pcdev->alloc_ctx; in mx2_videobuf_setup()
536 struct mx2_camera_dev *pcdev = ici->priv; in mx2_videobuf_queue() local
543 spin_lock_irqsave(&pcdev->lock, flags); in mx2_videobuf_queue()
545 list_add_tail(&buf->internal.queue, &pcdev->capture); in mx2_videobuf_queue()
547 spin_unlock_irqrestore(&pcdev->lock, flags); in mx2_videobuf_queue()
555 struct mx2_camera_dev *pcdev = ici->priv; in mx27_camera_emma_buf_init() local
556 struct mx2_fmt_cfg *prp = pcdev->emma_prp; in mx27_camera_emma_buf_init()
558 writel((pcdev->s_width << 16) | pcdev->s_height, in mx27_camera_emma_buf_init()
559 pcdev->base_emma + PRP_SRC_FRAME_SIZE); in mx27_camera_emma_buf_init()
561 pcdev->base_emma + PRP_SRC_PIXEL_FORMAT_CNTL); in mx27_camera_emma_buf_init()
564 pcdev->base_emma + PRP_CH1_OUT_IMAGE_SIZE); in mx27_camera_emma_buf_init()
566 pcdev->base_emma + PRP_DEST_CH1_LINE_STRIDE); in mx27_camera_emma_buf_init()
568 pcdev->base_emma + PRP_CH1_PIXEL_FORMAT_CNTL); in mx27_camera_emma_buf_init()
571 pcdev->base_emma + PRP_CH2_OUT_IMAGE_SIZE); in mx27_camera_emma_buf_init()
575 writel(prp->cfg.irq_flags, pcdev->base_emma + PRP_INTR_CNTL); in mx27_camera_emma_buf_init()
578 static void mx2_prp_resize_commit(struct mx2_camera_dev *pcdev) in mx2_prp_resize_commit() argument
583 unsigned char *s = pcdev->resizing[dir].s; in mx2_prp_resize_commit()
584 int len = pcdev->resizing[dir].len; in mx2_prp_resize_commit()
607 if (pcdev->resizing[dir].algo == RESIZE_ALGO_BILINEAR) in mx2_prp_resize_commit()
610 if (pcdev->emma_prp->cfg.channel == 1) { in mx2_prp_resize_commit()
612 writel(coeff[0], pcdev->base_emma + in mx2_prp_resize_commit()
614 writel(coeff[1], pcdev->base_emma + in mx2_prp_resize_commit()
616 writel(valid, pcdev->base_emma + in mx2_prp_resize_commit()
619 writel(coeff[0], pcdev->base_emma + in mx2_prp_resize_commit()
621 writel(coeff[1], pcdev->base_emma + in mx2_prp_resize_commit()
623 writel(valid, pcdev->base_emma + in mx2_prp_resize_commit()
628 writel(coeff[0], pcdev->base_emma + in mx2_prp_resize_commit()
630 writel(coeff[1], pcdev->base_emma + in mx2_prp_resize_commit()
632 writel(valid, pcdev->base_emma + in mx2_prp_resize_commit()
635 writel(coeff[0], pcdev->base_emma + in mx2_prp_resize_commit()
637 writel(coeff[1], pcdev->base_emma + in mx2_prp_resize_commit()
639 writel(valid, pcdev->base_emma + in mx2_prp_resize_commit()
651 struct mx2_camera_dev *pcdev = ici->priv; in mx2_start_streaming() local
652 struct mx2_fmt_cfg *prp = pcdev->emma_prp; in mx2_start_streaming()
662 spin_lock_irqsave(&pcdev->lock, flags); in mx2_start_streaming()
664 buf = list_first_entry(&pcdev->capture, struct mx2_buffer, in mx2_start_streaming()
670 mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum); in mx2_start_streaming()
671 list_move_tail(pcdev->capture.next, &pcdev->active_bufs); in mx2_start_streaming()
673 buf = list_first_entry(&pcdev->capture, struct mx2_buffer, in mx2_start_streaming()
679 mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum); in mx2_start_streaming()
680 list_move_tail(pcdev->capture.next, &pcdev->active_bufs); in mx2_start_streaming()
685 spin_unlock_irqrestore(&pcdev->lock, flags); in mx2_start_streaming()
696 pcdev->discard_size = icd->user_height * bytesperline; in mx2_start_streaming()
697 pcdev->discard_buffer = dma_alloc_coherent(ici->v4l2_dev.dev, in mx2_start_streaming()
698 pcdev->discard_size, in mx2_start_streaming()
699 &pcdev->discard_buffer_dma, GFP_ATOMIC); in mx2_start_streaming()
700 if (!pcdev->discard_buffer) { in mx2_start_streaming()
701 spin_unlock_irqrestore(&pcdev->lock, flags); in mx2_start_streaming()
705 pcdev->buf_discard[0].discard = true; in mx2_start_streaming()
706 list_add_tail(&pcdev->buf_discard[0].queue, in mx2_start_streaming()
707 &pcdev->discard); in mx2_start_streaming()
709 pcdev->buf_discard[1].discard = true; in mx2_start_streaming()
710 list_add_tail(&pcdev->buf_discard[1].queue, in mx2_start_streaming()
711 &pcdev->discard); in mx2_start_streaming()
713 mx2_prp_resize_commit(pcdev); in mx2_start_streaming()
726 pcdev->base_emma + PRP_CNTL); in mx2_start_streaming()
735 pcdev->base_emma + PRP_CNTL); in mx2_start_streaming()
737 spin_unlock_irqrestore(&pcdev->lock, flags); in mx2_start_streaming()
747 struct mx2_camera_dev *pcdev = ici->priv; in mx2_stop_streaming() local
748 struct mx2_fmt_cfg *prp = pcdev->emma_prp; in mx2_stop_streaming()
753 spin_lock_irqsave(&pcdev->lock, flags); in mx2_stop_streaming()
755 cntl = readl(pcdev->base_emma + PRP_CNTL); in mx2_stop_streaming()
758 pcdev->base_emma + PRP_CNTL); in mx2_stop_streaming()
761 pcdev->base_emma + PRP_CNTL); in mx2_stop_streaming()
763 INIT_LIST_HEAD(&pcdev->capture); in mx2_stop_streaming()
764 INIT_LIST_HEAD(&pcdev->active_bufs); in mx2_stop_streaming()
765 INIT_LIST_HEAD(&pcdev->discard); in mx2_stop_streaming()
767 b = pcdev->discard_buffer; in mx2_stop_streaming()
768 pcdev->discard_buffer = NULL; in mx2_stop_streaming()
770 spin_unlock_irqrestore(&pcdev->lock, flags); in mx2_stop_streaming()
773 pcdev->discard_size, b, pcdev->discard_buffer_dma); in mx2_stop_streaming()
808 static int mx27_camera_emma_prp_reset(struct mx2_camera_dev *pcdev) in mx27_camera_emma_prp_reset() argument
812 readl(pcdev->base_emma + PRP_CNTL); in mx27_camera_emma_prp_reset()
813 writel(PRP_CNTL_SWRST, pcdev->base_emma + PRP_CNTL); in mx27_camera_emma_prp_reset()
815 if (!(readl(pcdev->base_emma + PRP_CNTL) & PRP_CNTL_SWRST)) in mx27_camera_emma_prp_reset()
828 struct mx2_camera_dev *pcdev = ici->priv; in mx2_camera_set_bus_param() local
833 u32 csicr1 = pcdev->csicr1; in mx2_camera_set_bus_param()
852 if (pcdev->platform_flags & MX2_CAMERA_HSYNC_HIGH) in mx2_camera_set_bus_param()
860 if (pcdev->platform_flags & MX2_CAMERA_PCLK_SAMPLE_RISING) in mx2_camera_set_bus_param()
874 csicr1 = (csicr1 & ~CSICR1_FMT_MASK) | pcdev->emma_prp->cfg.csicr1; in mx2_camera_set_bus_param()
882 if (pcdev->platform_flags & MX2_CAMERA_EXT_VSYNC) in mx2_camera_set_bus_param()
884 if (pcdev->platform_flags & MX2_CAMERA_CCIR) in mx2_camera_set_bus_param()
886 if (pcdev->platform_flags & MX2_CAMERA_CCIR_INTERLACE) in mx2_camera_set_bus_param()
888 if (pcdev->platform_flags & MX2_CAMERA_GATED_CLOCK) in mx2_camera_set_bus_param()
890 if (pcdev->platform_flags & MX2_CAMERA_INV_DATA) in mx2_camera_set_bus_param()
893 pcdev->csicr1 = csicr1; in mx2_camera_set_bus_param()
900 ret = mx27_camera_emma_prp_reset(pcdev); in mx2_camera_set_bus_param()
904 writel(pcdev->csicr1, pcdev->base_csi + CSICR1); in mx2_camera_set_bus_param()
999 static int mx2_emmaprp_resize(struct mx2_camera_dev *pcdev, in mx2_emmaprp_resize() argument
1111 memcpy(&pcdev->resizing[dir], &tmprsz, sizeof(tmprsz)); in mx2_emmaprp_resize()
1120 struct mx2_camera_dev *pcdev = ici->priv; in mx2_camera_set_fmt() local
1148 pcdev->s_width = mf.width; in mx2_camera_set_fmt()
1149 pcdev->s_height = mf.height; in mx2_camera_set_fmt()
1151 __func__, pcdev->s_width, pcdev->s_height); in mx2_camera_set_fmt()
1153 pcdev->emma_prp = mx27_emma_prp_get_format(xlate->code, in mx2_camera_set_fmt()
1156 memset(pcdev->resizing, 0, sizeof(pcdev->resizing)); in mx2_camera_set_fmt()
1158 pcdev->emma_prp->cfg.in_fmt == PRP_CNTL_DATA_IN_YUV422) { in mx2_camera_set_fmt()
1159 if (mx2_emmaprp_resize(pcdev, &mf, pix, true) < 0) in mx2_camera_set_fmt()
1187 struct mx2_camera_dev *pcdev = ici->priv; in mx2_camera_try_fmt() local
1218 __func__, pcdev->s_width, pcdev->s_height); in mx2_camera_try_fmt()
1226 if (mx2_emmaprp_resize(pcdev, &mf, pix, false) < 0) in mx2_camera_try_fmt()
1288 static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev, in mx27_camera_frame_done_emma() argument
1292 struct mx2_fmt_cfg *prp = pcdev->emma_prp; in mx27_camera_frame_done_emma()
1299 ibuf = list_first_entry(&pcdev->active_bufs, struct mx2_buf_internal, in mx27_camera_frame_done_emma()
1309 list_move_tail(pcdev->active_bufs.next, &pcdev->discard); in mx27_camera_frame_done_emma()
1317 if (readl(pcdev->base_emma + PRP_DEST_RGB1_PTR + in mx27_camera_frame_done_emma()
1319 dev_err(pcdev->dev, "%lx != %x\n", phys, in mx27_camera_frame_done_emma()
1320 readl(pcdev->base_emma + in mx27_camera_frame_done_emma()
1324 if (readl(pcdev->base_emma + PRP_DEST_Y_PTR - in mx27_camera_frame_done_emma()
1326 dev_err(pcdev->dev, "%lx != %x\n", phys, in mx27_camera_frame_done_emma()
1327 readl(pcdev->base_emma + in mx27_camera_frame_done_emma()
1332 dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%p %lu\n", __func__, vb, in mx27_camera_frame_done_emma()
1338 vb->v4l2_buf.sequence = pcdev->frame_count; in mx27_camera_frame_done_emma()
1345 pcdev->frame_count++; in mx27_camera_frame_done_emma()
1347 if (list_empty(&pcdev->capture)) { in mx27_camera_frame_done_emma()
1348 if (list_empty(&pcdev->discard)) { in mx27_camera_frame_done_emma()
1349 dev_warn(pcdev->dev, "%s: trying to access empty discard list\n", in mx27_camera_frame_done_emma()
1354 ibuf = list_first_entry(&pcdev->discard, in mx27_camera_frame_done_emma()
1358 list_move_tail(pcdev->discard.next, &pcdev->active_bufs); in mx27_camera_frame_done_emma()
1359 mx27_update_emma_buf(pcdev, pcdev->discard_buffer_dma, bufnum); in mx27_camera_frame_done_emma()
1363 buf = list_first_entry(&pcdev->capture, struct mx2_buffer, in mx27_camera_frame_done_emma()
1368 list_move_tail(pcdev->capture.next, &pcdev->active_bufs); in mx27_camera_frame_done_emma()
1373 mx27_update_emma_buf(pcdev, phys, bufnum); in mx27_camera_frame_done_emma()
1378 struct mx2_camera_dev *pcdev = data; in mx27_camera_emma_irq() local
1379 unsigned int status = readl(pcdev->base_emma + PRP_INTRSTATUS); in mx27_camera_emma_irq()
1382 spin_lock(&pcdev->lock); in mx27_camera_emma_irq()
1384 if (list_empty(&pcdev->active_bufs)) { in mx27_camera_emma_irq()
1385 dev_warn(pcdev->dev, "%s: called while active list is empty\n", in mx27_camera_emma_irq()
1389 spin_unlock(&pcdev->lock); in mx27_camera_emma_irq()
1395 u32 cntl = readl(pcdev->base_emma + PRP_CNTL); in mx27_camera_emma_irq()
1397 pcdev->base_emma + PRP_CNTL); in mx27_camera_emma_irq()
1398 writel(cntl, pcdev->base_emma + PRP_CNTL); in mx27_camera_emma_irq()
1400 ibuf = list_first_entry(&pcdev->active_bufs, in mx27_camera_emma_irq()
1402 mx27_camera_frame_done_emma(pcdev, in mx27_camera_emma_irq()
1412 ibuf = list_first_entry(&pcdev->active_bufs, in mx27_camera_emma_irq()
1414 mx27_camera_frame_done_emma(pcdev, ibuf->bufnum, false); in mx27_camera_emma_irq()
1417 mx27_camera_frame_done_emma(pcdev, 0, false); in mx27_camera_emma_irq()
1419 mx27_camera_frame_done_emma(pcdev, 1, false); in mx27_camera_emma_irq()
1422 spin_unlock(&pcdev->lock); in mx27_camera_emma_irq()
1423 writel(status, pcdev->base_emma + PRP_INTRSTATUS); in mx27_camera_emma_irq()
1430 struct mx2_camera_dev *pcdev = platform_get_drvdata(pdev); in mx27_camera_emma_init() local
1438 dev_err(pcdev->dev, "no EMMA resources\n"); in mx27_camera_emma_init()
1443 pcdev->base_emma = devm_ioremap_resource(pcdev->dev, res_emma); in mx27_camera_emma_init()
1444 if (IS_ERR(pcdev->base_emma)) { in mx27_camera_emma_init()
1445 err = PTR_ERR(pcdev->base_emma); in mx27_camera_emma_init()
1449 err = devm_request_irq(pcdev->dev, irq_emma, mx27_camera_emma_irq, 0, in mx27_camera_emma_init()
1450 MX2_CAM_DRV_NAME, pcdev); in mx27_camera_emma_init()
1452 dev_err(pcdev->dev, "Camera EMMA interrupt register failed\n"); in mx27_camera_emma_init()
1456 pcdev->clk_emma_ipg = devm_clk_get(pcdev->dev, "emma-ipg"); in mx27_camera_emma_init()
1457 if (IS_ERR(pcdev->clk_emma_ipg)) { in mx27_camera_emma_init()
1458 err = PTR_ERR(pcdev->clk_emma_ipg); in mx27_camera_emma_init()
1462 clk_prepare_enable(pcdev->clk_emma_ipg); in mx27_camera_emma_init()
1464 pcdev->clk_emma_ahb = devm_clk_get(pcdev->dev, "emma-ahb"); in mx27_camera_emma_init()
1465 if (IS_ERR(pcdev->clk_emma_ahb)) { in mx27_camera_emma_init()
1466 err = PTR_ERR(pcdev->clk_emma_ahb); in mx27_camera_emma_init()
1470 clk_prepare_enable(pcdev->clk_emma_ahb); in mx27_camera_emma_init()
1472 err = mx27_camera_emma_prp_reset(pcdev); in mx27_camera_emma_init()
1479 clk_disable_unprepare(pcdev->clk_emma_ahb); in mx27_camera_emma_init()
1481 clk_disable_unprepare(pcdev->clk_emma_ipg); in mx27_camera_emma_init()
1488 struct mx2_camera_dev *pcdev; in mx2_camera_probe() local
1503 pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL); in mx2_camera_probe()
1504 if (!pcdev) { in mx2_camera_probe()
1510 pcdev->clk_csi_ahb = devm_clk_get(&pdev->dev, "ahb"); in mx2_camera_probe()
1511 if (IS_ERR(pcdev->clk_csi_ahb)) { in mx2_camera_probe()
1513 err = PTR_ERR(pcdev->clk_csi_ahb); in mx2_camera_probe()
1517 pcdev->clk_csi_per = devm_clk_get(&pdev->dev, "per"); in mx2_camera_probe()
1518 if (IS_ERR(pcdev->clk_csi_per)) { in mx2_camera_probe()
1520 err = PTR_ERR(pcdev->clk_csi_per); in mx2_camera_probe()
1524 pcdev->pdata = pdev->dev.platform_data; in mx2_camera_probe()
1525 if (pcdev->pdata) { in mx2_camera_probe()
1528 pcdev->platform_flags = pcdev->pdata->flags; in mx2_camera_probe()
1530 rate = clk_round_rate(pcdev->clk_csi_per, in mx2_camera_probe()
1531 pcdev->pdata->clk * 2); in mx2_camera_probe()
1536 err = clk_set_rate(pcdev->clk_csi_per, rate); in mx2_camera_probe()
1541 INIT_LIST_HEAD(&pcdev->capture); in mx2_camera_probe()
1542 INIT_LIST_HEAD(&pcdev->active_bufs); in mx2_camera_probe()
1543 INIT_LIST_HEAD(&pcdev->discard); in mx2_camera_probe()
1544 spin_lock_init(&pcdev->lock); in mx2_camera_probe()
1546 pcdev->base_csi = devm_ioremap_resource(&pdev->dev, res_csi); in mx2_camera_probe()
1547 if (IS_ERR(pcdev->base_csi)) { in mx2_camera_probe()
1548 err = PTR_ERR(pcdev->base_csi); in mx2_camera_probe()
1552 pcdev->dev = &pdev->dev; in mx2_camera_probe()
1553 platform_set_drvdata(pdev, pcdev); in mx2_camera_probe()
1565 pcdev->soc_host.drv_name = MX2_CAM_DRV_NAME, in mx2_camera_probe()
1566 pcdev->soc_host.ops = &mx2_soc_camera_host_ops, in mx2_camera_probe()
1567 pcdev->soc_host.priv = pcdev; in mx2_camera_probe()
1568 pcdev->soc_host.v4l2_dev.dev = &pdev->dev; in mx2_camera_probe()
1569 pcdev->soc_host.nr = pdev->id; in mx2_camera_probe()
1571 pcdev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); in mx2_camera_probe()
1572 if (IS_ERR(pcdev->alloc_ctx)) { in mx2_camera_probe()
1573 err = PTR_ERR(pcdev->alloc_ctx); in mx2_camera_probe()
1576 err = soc_camera_host_register(&pcdev->soc_host); in mx2_camera_probe()
1581 clk_get_rate(pcdev->clk_csi_per)); in mx2_camera_probe()
1586 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); in mx2_camera_probe()
1588 clk_disable_unprepare(pcdev->clk_emma_ipg); in mx2_camera_probe()
1589 clk_disable_unprepare(pcdev->clk_emma_ahb); in mx2_camera_probe()
1597 struct mx2_camera_dev *pcdev = container_of(soc_host, in mx2_camera_remove() local
1600 soc_camera_host_unregister(&pcdev->soc_host); in mx2_camera_remove()
1602 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); in mx2_camera_remove()
1604 clk_disable_unprepare(pcdev->clk_emma_ipg); in mx2_camera_remove()
1605 clk_disable_unprepare(pcdev->clk_emma_ahb); in mx2_camera_remove()