Lines Matching full:jpu

149 #define JIFECNT_SWAP_WB		(3 << 4) /* to JPU */
163 #define JIFDCNT_SWAP_WB (3 << 1) /* from JPU */
177 * struct jpu - JPEG IP abstraction
191 struct jpu { struct
255 * @jpu: JPEG IP device for this context
264 struct jpu *jpu; member
468 static u32 jpu_read(struct jpu *jpu, unsigned int reg) in jpu_read() argument
470 return ioread32(jpu->regs + reg); in jpu_read()
473 static void jpu_write(struct jpu *jpu, u32 val, unsigned int reg) in jpu_write() argument
475 iowrite32(val, jpu->regs + reg); in jpu_write()
488 static void jpu_set_tbl(struct jpu *jpu, u32 reg, const unsigned int *tbl, in jpu_set_tbl() argument
493 jpu_write(jpu, tbl[i], reg + (i << 2)); in jpu_set_tbl()
496 static void jpu_set_qtbl(struct jpu *jpu, unsigned short quality) in jpu_set_qtbl() argument
498 jpu_set_tbl(jpu, JCQTBL(0), qtbl_lum[quality], QTBL_SIZE); in jpu_set_qtbl()
499 jpu_set_tbl(jpu, JCQTBL(1), qtbl_chr[quality], QTBL_SIZE); in jpu_set_qtbl()
502 static void jpu_set_htbl(struct jpu *jpu) in jpu_set_htbl() argument
504 jpu_set_tbl(jpu, JCHTBD(0), hdctbl_lum, HDCTBL_SIZE); in jpu_set_htbl()
505 jpu_set_tbl(jpu, JCHTBA(0), hactbl_lum, HACTBL_SIZE); in jpu_set_htbl()
506 jpu_set_tbl(jpu, JCHTBD(1), hdctbl_chr, HDCTBL_SIZE); in jpu_set_htbl()
507 jpu_set_tbl(jpu, JCHTBA(1), hactbl_chr, HACTBL_SIZE); in jpu_set_htbl()
510 static int jpu_wait_reset(struct jpu *jpu) in jpu_wait_reset() argument
516 while (jpu_read(jpu, JCCMD) & JCCMD_SRST) { in jpu_wait_reset()
518 dev_err(jpu->dev, "timed out in reset\n"); in jpu_wait_reset()
527 static int jpu_reset(struct jpu *jpu) in jpu_reset() argument
529 jpu_write(jpu, JCCMD_SRST, JCCMD); in jpu_reset()
530 return jpu_wait_reset(jpu); in jpu_reset()
606 * basic size check and EOI - we don't want to let JPU cross in jpu_parse_hdr()
775 dev_dbg(ctx->jpu->dev, "unknown format; set default format\n"); in __jpu_try_fmt()
848 v4l2_err(&ctx->jpu->v4l2_dev, "%s queue busy\n", __func__); in jpu_s_fmt()
886 spin_lock_irqsave(&ctx->jpu->lock, flags); in jpu_s_ctrl()
889 spin_unlock_irqrestore(&ctx->jpu->lock, flags); in jpu_s_ctrl()
926 dev_err(ctx->jpu->dev, "src and dst formats do not match.\n"); in jpu_streamon()
1040 dev_err(ctx->jpu->dev, "%s field isn't supported\n", in jpu_buf_prepare()
1050 dev_err(ctx->jpu->dev, in jpu_buf_prepare()
1109 dev_err(ctx->jpu->dev, "incompatible or corrupted JPEG data\n"); in jpu_buf_queue()
1161 spin_lock_irqsave(&ctx->jpu->lock, flags); in jpu_stop_streaming()
1163 spin_unlock_irqrestore(&ctx->jpu->lock, flags); in jpu_stop_streaming()
1192 src_vq->lock = &ctx->jpu->mutex; in jpu_queue_init()
1193 src_vq->dev = ctx->jpu->v4l2_dev.dev; in jpu_queue_init()
1207 dst_vq->lock = &ctx->jpu->mutex; in jpu_queue_init()
1208 dst_vq->dev = ctx->jpu->v4l2_dev.dev; in jpu_queue_init()
1220 struct jpu *jpu = video_drvdata(file); in jpu_open() local
1234 ctx->jpu = jpu; in jpu_open()
1235 ctx->encoder = vfd == &jpu->vfd_encoder; in jpu_open()
1242 ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(jpu->m2m_dev, ctx, jpu_queue_init); in jpu_open()
1252 if (mutex_lock_interruptible(&jpu->mutex)) { in jpu_open()
1257 if (jpu->ref_count == 0) { in jpu_open()
1258 ret = clk_prepare_enable(jpu->clk); in jpu_open()
1262 ret = jpu_reset(jpu); in jpu_open()
1267 jpu->ref_count++; in jpu_open()
1269 mutex_unlock(&jpu->mutex); in jpu_open()
1273 clk_disable_unprepare(jpu->clk); in jpu_open()
1275 mutex_unlock(&jpu->mutex); in jpu_open()
1285 struct jpu *jpu = video_drvdata(file); in jpu_release() local
1294 mutex_lock(&jpu->mutex); in jpu_release()
1295 if (--jpu->ref_count == 0) in jpu_release()
1296 clk_disable_unprepare(jpu->clk); in jpu_release()
1297 mutex_unlock(&jpu->mutex); in jpu_release()
1322 spin_lock_irqsave(&ctx->jpu->lock, flags); in jpu_cleanup()
1332 jpu_write(ctx->jpu, JCCMD_SRST, JCCMD); in jpu_cleanup()
1334 spin_unlock_irqrestore(&ctx->jpu->lock, flags); in jpu_cleanup()
1336 v4l2_m2m_job_finish(ctx->jpu->m2m_dev, ctx->fh.m2m_ctx); in jpu_cleanup()
1342 struct jpu *jpu = ctx->jpu; in jpu_device_run() local
1351 if (jpu_wait_reset(jpu)) { in jpu_device_run()
1356 spin_lock_irqsave(&ctx->jpu->lock, flags); in jpu_device_run()
1358 jpu->curr = ctx; in jpu_device_run()
1401 jpu_write(jpu, JCMOD_DSP_ENC | JCMOD_PCTR | redu | in jpu_device_run()
1404 jpu_write(jpu, JIFECNT_SWAP_WB | inft, JIFECNT); in jpu_device_run()
1405 jpu_write(jpu, JIFDCNT_SWAP_WB, JIFDCNT); in jpu_device_run()
1406 jpu_write(jpu, JINTE_TRANSF_COMPL, JINTE); in jpu_device_run()
1409 jpu_write(jpu, src_1_addr, JIFESYA1); in jpu_device_run()
1410 jpu_write(jpu, src_2_addr, JIFESCA1); in jpu_device_run()
1413 jpu_write(jpu, bpl, JIFESMW); in jpu_device_run()
1415 jpu_write(jpu, (w >> 8) & JCSZ_MASK, JCHSZU); in jpu_device_run()
1416 jpu_write(jpu, w & JCSZ_MASK, JCHSZD); in jpu_device_run()
1418 jpu_write(jpu, (h >> 8) & JCSZ_MASK, JCVSZU); in jpu_device_run()
1419 jpu_write(jpu, h & JCSZ_MASK, JCVSZD); in jpu_device_run()
1421 jpu_write(jpu, w, JIFESHSZ); in jpu_device_run()
1422 jpu_write(jpu, h, JIFESVSZ); in jpu_device_run()
1424 jpu_write(jpu, dst_addr + JPU_JPEG_HDR_SIZE, JIFEDA1); in jpu_device_run()
1426 jpu_write(jpu, 0 << JCQTN_SHIFT(1) | 1 << JCQTN_SHIFT(2) | in jpu_device_run()
1429 jpu_write(jpu, 0 << JCHTN_AC_SHIFT(1) | 0 << JCHTN_DC_SHIFT(1) | in jpu_device_run()
1434 jpu_set_qtbl(jpu, ctx->compr_quality); in jpu_device_run()
1435 jpu_set_htbl(jpu); in jpu_device_run()
1440 dev_err(ctx->jpu->dev, in jpu_device_run()
1442 spin_unlock_irqrestore(&ctx->jpu->lock, flags); in jpu_device_run()
1457 jpu_write(jpu, JCMOD_DSP_DEC | JCMOD_PCTR, JCMOD); in jpu_device_run()
1458 jpu_write(jpu, JIFECNT_SWAP_WB, JIFECNT); in jpu_device_run()
1459 jpu_write(jpu, JIFDCNT_SWAP_WB, JIFDCNT); in jpu_device_run()
1462 jpu_write(jpu, JINTE_TRANSF_COMPL | JINTE_ERR, JINTE); in jpu_device_run()
1465 jpu_write(jpu, src_addr, JIFDSA1); in jpu_device_run()
1466 jpu_write(jpu, dst_1_addr, JIFDDYA1); in jpu_device_run()
1467 jpu_write(jpu, dst_2_addr, JIFDDCA1); in jpu_device_run()
1469 jpu_write(jpu, bpl, JIFDDMW); in jpu_device_run()
1473 jpu_write(jpu, JCCMD_JSRT, JCCMD); in jpu_device_run()
1475 spin_unlock_irqrestore(&ctx->jpu->lock, flags); in jpu_device_run()
1489 struct jpu *jpu = dev_id; in jpu_irq_handler() local
1494 int_status = jpu_read(jpu, JINTS); in jpu_irq_handler()
1502 jpu_write(jpu, ~(int_status & JINTS_MASK), JINTS); in jpu_irq_handler()
1504 jpu_write(jpu, JCCMD_JEND, JCCMD); in jpu_irq_handler()
1506 spin_lock(&jpu->lock); in jpu_irq_handler()
1512 curr_ctx = v4l2_m2m_get_curr_priv(jpu->m2m_dev); in jpu_irq_handler()
1515 dev_err(jpu->dev, "no active context for m2m\n"); in jpu_irq_handler()
1524 unsigned long payload_size = jpu_read(jpu, JCDTCU) << 16 in jpu_irq_handler()
1525 | jpu_read(jpu, JCDTCM) << 8 in jpu_irq_handler()
1526 | jpu_read(jpu, JCDTCD); in jpu_irq_handler()
1543 unsigned char error = jpu_read(jpu, JCDERR) & JCDERR_MASK; in jpu_irq_handler()
1545 dev_dbg(jpu->dev, "processing error: %#X: %s\n", error, in jpu_irq_handler()
1552 jpu->curr = NULL; in jpu_irq_handler()
1554 /* ...reset JPU after completion */ in jpu_irq_handler()
1555 jpu_write(jpu, JCCMD_SRST, JCCMD); in jpu_irq_handler()
1556 spin_unlock(&jpu->lock); in jpu_irq_handler()
1558 v4l2_m2m_job_finish(jpu->m2m_dev, curr_ctx->fh.m2m_ctx); in jpu_irq_handler()
1563 spin_unlock(&jpu->lock); in jpu_irq_handler()
1573 { .compatible = "renesas,jpu-r8a7790" }, /* H2 */
1574 { .compatible = "renesas,jpu-r8a7791" }, /* M2-W */
1575 { .compatible = "renesas,jpu-r8a7792" }, /* V2H */
1576 { .compatible = "renesas,jpu-r8a7793" }, /* M2-N */
1577 { .compatible = "renesas,rcar-gen2-jpu" },
1584 struct jpu *jpu; in jpu_probe() local
1588 jpu = devm_kzalloc(&pdev->dev, sizeof(*jpu), GFP_KERNEL); in jpu_probe()
1589 if (!jpu) in jpu_probe()
1592 mutex_init(&jpu->mutex); in jpu_probe()
1593 spin_lock_init(&jpu->lock); in jpu_probe()
1594 jpu->dev = &pdev->dev; in jpu_probe()
1597 jpu->regs = devm_platform_ioremap_resource(pdev, 0); in jpu_probe()
1598 if (IS_ERR(jpu->regs)) in jpu_probe()
1599 return PTR_ERR(jpu->regs); in jpu_probe()
1602 jpu->irq = ret = platform_get_irq(pdev, 0); in jpu_probe()
1606 ret = devm_request_irq(&pdev->dev, jpu->irq, jpu_irq_handler, 0, in jpu_probe()
1607 dev_name(&pdev->dev), jpu); in jpu_probe()
1609 dev_err(&pdev->dev, "cannot claim IRQ %d\n", jpu->irq); in jpu_probe()
1614 jpu->clk = devm_clk_get(&pdev->dev, NULL); in jpu_probe()
1615 if (IS_ERR(jpu->clk)) { in jpu_probe()
1617 return PTR_ERR(jpu->clk); in jpu_probe()
1621 ret = v4l2_device_register(&pdev->dev, &jpu->v4l2_dev); in jpu_probe()
1628 jpu->m2m_dev = v4l2_m2m_init(&jpu_m2m_ops); in jpu_probe()
1629 if (IS_ERR(jpu->m2m_dev)) { in jpu_probe()
1630 v4l2_err(&jpu->v4l2_dev, "Failed to init mem2mem device\n"); in jpu_probe()
1631 ret = PTR_ERR(jpu->m2m_dev); in jpu_probe()
1639 strscpy(jpu->vfd_encoder.name, DRV_NAME, sizeof(jpu->vfd_encoder.name)); in jpu_probe()
1640 jpu->vfd_encoder.fops = &jpu_fops; in jpu_probe()
1641 jpu->vfd_encoder.ioctl_ops = &jpu_ioctl_ops; in jpu_probe()
1642 jpu->vfd_encoder.minor = -1; in jpu_probe()
1643 jpu->vfd_encoder.release = video_device_release_empty; in jpu_probe()
1644 jpu->vfd_encoder.lock = &jpu->mutex; in jpu_probe()
1645 jpu->vfd_encoder.v4l2_dev = &jpu->v4l2_dev; in jpu_probe()
1646 jpu->vfd_encoder.vfl_dir = VFL_DIR_M2M; in jpu_probe()
1647 jpu->vfd_encoder.device_caps = V4L2_CAP_STREAMING | in jpu_probe()
1650 ret = video_register_device(&jpu->vfd_encoder, VFL_TYPE_VIDEO, -1); in jpu_probe()
1652 v4l2_err(&jpu->v4l2_dev, "Failed to register video device\n"); in jpu_probe()
1656 video_set_drvdata(&jpu->vfd_encoder, jpu); in jpu_probe()
1658 strscpy(jpu->vfd_decoder.name, DRV_NAME, sizeof(jpu->vfd_decoder.name)); in jpu_probe()
1659 jpu->vfd_decoder.fops = &jpu_fops; in jpu_probe()
1660 jpu->vfd_decoder.ioctl_ops = &jpu_ioctl_ops; in jpu_probe()
1661 jpu->vfd_decoder.minor = -1; in jpu_probe()
1662 jpu->vfd_decoder.release = video_device_release_empty; in jpu_probe()
1663 jpu->vfd_decoder.lock = &jpu->mutex; in jpu_probe()
1664 jpu->vfd_decoder.v4l2_dev = &jpu->v4l2_dev; in jpu_probe()
1665 jpu->vfd_decoder.vfl_dir = VFL_DIR_M2M; in jpu_probe()
1666 jpu->vfd_decoder.device_caps = V4L2_CAP_STREAMING | in jpu_probe()
1669 ret = video_register_device(&jpu->vfd_decoder, VFL_TYPE_VIDEO, -1); in jpu_probe()
1671 v4l2_err(&jpu->v4l2_dev, "Failed to register video device\n"); in jpu_probe()
1675 video_set_drvdata(&jpu->vfd_decoder, jpu); in jpu_probe()
1676 platform_set_drvdata(pdev, jpu); in jpu_probe()
1678 v4l2_info(&jpu->v4l2_dev, "encoder device registered as /dev/video%d\n", in jpu_probe()
1679 jpu->vfd_encoder.num); in jpu_probe()
1680 v4l2_info(&jpu->v4l2_dev, "decoder device registered as /dev/video%d\n", in jpu_probe()
1681 jpu->vfd_decoder.num); in jpu_probe()
1686 video_unregister_device(&jpu->vfd_encoder); in jpu_probe()
1689 v4l2_m2m_release(jpu->m2m_dev); in jpu_probe()
1692 v4l2_device_unregister(&jpu->v4l2_dev); in jpu_probe()
1699 struct jpu *jpu = platform_get_drvdata(pdev); in jpu_remove() local
1701 video_unregister_device(&jpu->vfd_decoder); in jpu_remove()
1702 video_unregister_device(&jpu->vfd_encoder); in jpu_remove()
1703 v4l2_m2m_release(jpu->m2m_dev); in jpu_remove()
1704 v4l2_device_unregister(&jpu->v4l2_dev); in jpu_remove()
1710 struct jpu *jpu = dev_get_drvdata(dev); in jpu_suspend() local
1712 if (jpu->ref_count == 0) in jpu_suspend()
1715 clk_disable_unprepare(jpu->clk); in jpu_suspend()
1722 struct jpu *jpu = dev_get_drvdata(dev); in jpu_resume() local
1724 if (jpu->ref_count == 0) in jpu_resume()
1727 clk_prepare_enable(jpu->clk); in jpu_resume()