Lines Matching full:jpeg

3  * V4L2 driver for the JPEG encoder/decoder from i.MX8QXP/i.MX8QM application
8 * Baseline and extended sequential jpeg decoding is supported.
9 * Progressive jpeg decoding is not supported by the IP.
19 * from the jpeg stream, by parsing the jpeg markers.
32 * but the driver works around this by replacing them in the jpeg stream.
38 * This is inspired by the drivers/media/platform/samsung/s5p-jpeg driver
56 #include <media/v4l2-jpeg.h>
63 #include "mxc-jpeg-hw.h"
64 #include "mxc-jpeg.h"
68 .name = "JPEG",
283 * split by JPEG marker, so it's easier to modify & use
560 /* mxc-jpeg specific */
580 MODULE_PARM_DESC(hw_timeout, "MXC JPEG hw timeout, the number of milliseconds");
590 static void print_mxc_buf(struct mxc_jpeg_dev *jpeg, struct vb2_buffer *buf, in print_mxc_buf() argument
607 v4l2_dbg(3, debug, &jpeg->v4l2_dev, in print_mxc_buf()
755 static bool mxc_jpeg_alloc_slot_data(struct mxc_jpeg_dev *jpeg) in mxc_jpeg_alloc_slot_data() argument
761 if (jpeg->slot_data.desc) in mxc_jpeg_alloc_slot_data()
765 desc = dma_alloc_coherent(jpeg->dev, in mxc_jpeg_alloc_slot_data()
767 &jpeg->slot_data.desc_handle, in mxc_jpeg_alloc_slot_data()
771 jpeg->slot_data.desc = desc; in mxc_jpeg_alloc_slot_data()
774 cfg_desc = dma_alloc_coherent(jpeg->dev, in mxc_jpeg_alloc_slot_data()
776 &jpeg->slot_data.cfg_desc_handle, in mxc_jpeg_alloc_slot_data()
780 jpeg->slot_data.cfg_desc = cfg_desc; in mxc_jpeg_alloc_slot_data()
783 cfg_stm = dma_alloc_coherent(jpeg->dev, in mxc_jpeg_alloc_slot_data()
785 &jpeg->slot_data.cfg_stream_handle, in mxc_jpeg_alloc_slot_data()
789 jpeg->slot_data.cfg_stream_vaddr = cfg_stm; in mxc_jpeg_alloc_slot_data()
792 jpeg->slot_data.used = true; in mxc_jpeg_alloc_slot_data()
796 dev_err(jpeg->dev, "Could not allocate descriptors for slot %d", jpeg->slot_data.slot); in mxc_jpeg_alloc_slot_data()
801 static void mxc_jpeg_free_slot_data(struct mxc_jpeg_dev *jpeg) in mxc_jpeg_free_slot_data() argument
804 dma_free_coherent(jpeg->dev, sizeof(struct mxc_jpeg_desc), in mxc_jpeg_free_slot_data()
805 jpeg->slot_data.desc, in mxc_jpeg_free_slot_data()
806 jpeg->slot_data.desc_handle); in mxc_jpeg_free_slot_data()
809 dma_free_coherent(jpeg->dev, sizeof(struct mxc_jpeg_desc), in mxc_jpeg_free_slot_data()
810 jpeg->slot_data.cfg_desc, in mxc_jpeg_free_slot_data()
811 jpeg->slot_data.cfg_desc_handle); in mxc_jpeg_free_slot_data()
814 dma_free_coherent(jpeg->dev, MXC_JPEG_MAX_CFG_STREAM, in mxc_jpeg_free_slot_data()
815 jpeg->slot_data.cfg_stream_vaddr, in mxc_jpeg_free_slot_data()
816 jpeg->slot_data.cfg_stream_handle); in mxc_jpeg_free_slot_data()
818 jpeg->slot_data.used = false; in mxc_jpeg_free_slot_data()
835 struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; in mxc_jpeg_job_finish() local
836 void __iomem *reg = jpeg->base_reg; in mxc_jpeg_job_finish()
848 jpeg->slot_data.used = false; in mxc_jpeg_job_finish()
882 struct mxc_jpeg_dev *jpeg = priv; in mxc_jpeg_dec_irq() local
884 void __iomem *reg = jpeg->base_reg; in mxc_jpeg_dec_irq()
885 struct device *dev = jpeg->dev; in mxc_jpeg_dec_irq()
895 spin_lock(&jpeg->hw_lock); in mxc_jpeg_dec_irq()
901 ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev); in mxc_jpeg_dec_irq()
912 if (!jpeg->slot_data.used) in mxc_jpeg_dec_irq()
940 if (jpeg->mode == MXC_JPEG_ENCODE && in mxc_jpeg_dec_irq()
949 if (jpeg->mode == MXC_JPEG_DECODE && jpeg_src_buf->dht_needed) { in mxc_jpeg_dec_irq()
955 if (jpeg->mode == MXC_JPEG_ENCODE) { in mxc_jpeg_dec_irq()
976 print_mxc_buf(jpeg, &src_buf->vb2_buf, 32); in mxc_jpeg_dec_irq()
978 print_mxc_buf(jpeg, &dst_buf->vb2_buf, 32); in mxc_jpeg_dec_irq()
983 spin_unlock(&jpeg->hw_lock); in mxc_jpeg_dec_irq()
985 v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); in mxc_jpeg_dec_irq()
988 spin_unlock(&jpeg->hw_lock); in mxc_jpeg_dec_irq()
1169 struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; in mxc_jpeg_config_dec_desc() local
1170 void __iomem *reg = jpeg->base_reg; in mxc_jpeg_config_dec_desc()
1172 struct mxc_jpeg_desc *desc = jpeg->slot_data.desc; in mxc_jpeg_config_dec_desc()
1173 struct mxc_jpeg_desc *cfg_desc = jpeg->slot_data.cfg_desc; in mxc_jpeg_config_dec_desc()
1174 dma_addr_t desc_handle = jpeg->slot_data.desc_handle; in mxc_jpeg_config_dec_desc()
1175 dma_addr_t cfg_desc_handle = jpeg->slot_data.cfg_desc_handle; in mxc_jpeg_config_dec_desc()
1176 dma_addr_t cfg_stream_handle = jpeg->slot_data.cfg_stream_handle; in mxc_jpeg_config_dec_desc()
1177 unsigned int *cfg_size = &jpeg->slot_data.cfg_stream_size; in mxc_jpeg_config_dec_desc()
1178 void *cfg_stream_vaddr = jpeg->slot_data.cfg_stream_vaddr; in mxc_jpeg_config_dec_desc()
1198 print_descriptor_info(jpeg->dev, desc); in mxc_jpeg_config_dec_desc()
1224 print_descriptor_info(jpeg->dev, cfg_desc); in mxc_jpeg_config_dec_desc()
1235 struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; in mxc_jpeg_config_enc_desc() local
1236 void __iomem *reg = jpeg->base_reg; in mxc_jpeg_config_enc_desc()
1238 struct mxc_jpeg_desc *desc = jpeg->slot_data.desc; in mxc_jpeg_config_enc_desc()
1239 struct mxc_jpeg_desc *cfg_desc = jpeg->slot_data.cfg_desc; in mxc_jpeg_config_enc_desc()
1240 dma_addr_t desc_handle = jpeg->slot_data.desc_handle; in mxc_jpeg_config_enc_desc()
1241 dma_addr_t cfg_desc_handle = jpeg->slot_data.cfg_desc_handle; in mxc_jpeg_config_enc_desc()
1242 void *cfg_stream_vaddr = jpeg->slot_data.cfg_stream_vaddr; in mxc_jpeg_config_enc_desc()
1249 jpeg->slot_data.cfg_stream_size = in mxc_jpeg_config_enc_desc()
1258 cfg_desc->buf_base0 = jpeg->slot_data.cfg_stream_handle; in mxc_jpeg_config_enc_desc()
1279 dev_err(jpeg->dev, "No valid image format detected\n"); in mxc_jpeg_config_enc_desc()
1288 dev_dbg(jpeg->dev, "cfg_desc:\n"); in mxc_jpeg_config_enc_desc()
1289 print_descriptor_info(jpeg->dev, cfg_desc); in mxc_jpeg_config_enc_desc()
1290 dev_dbg(jpeg->dev, "enc desc:\n"); in mxc_jpeg_config_enc_desc()
1291 print_descriptor_info(jpeg->dev, desc); in mxc_jpeg_config_enc_desc()
1292 print_wrapper_info(jpeg->dev, reg); in mxc_jpeg_config_enc_desc()
1293 print_cast_status(jpeg->dev, reg, MXC_JPEG_ENCODE); in mxc_jpeg_config_enc_desc()
1355 dev_dbg(dev, "Detected jpeg res=(%dx%d)->(%dx%d), pixfmt=%c%c%c%c\n", in mxc_jpeg_source_change()
1365 * detected from the jpeg output stream in mxc_jpeg_source_change()
1417 struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; in mxc_jpeg_device_run_timeout() local
1422 dev_warn(jpeg->dev, "%s timeout, cancel it\n", in mxc_jpeg_device_run_timeout()
1433 struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; in mxc_jpeg_device_run() local
1434 void __iomem *reg = jpeg->base_reg; in mxc_jpeg_device_run()
1435 struct device *dev = jpeg->dev; in mxc_jpeg_device_run()
1474 v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); in mxc_jpeg_device_run()
1481 v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); in mxc_jpeg_device_run()
1489 ctx->slot = mxc_get_free_slot(&jpeg->slot_data); in mxc_jpeg_device_run()
1494 if (!mxc_jpeg_alloc_slot_data(jpeg)) { in mxc_jpeg_device_run()
1502 if (jpeg->mode == MXC_JPEG_ENCODE) { in mxc_jpeg_device_run()
1512 print_mxc_buf(jpeg, &src_buf->vb2_buf, 0); in mxc_jpeg_device_run()
1642 dev_err(ctx->mxc_jpeg->dev, "Failed to power up jpeg\n"); in mxc_jpeg_start_streaming()
1763 bytesperline[1] = q->bytesperline[0]; /*imx-jpeg only support the same line pitch*/ in mxc_jpeg_bytesperline()
1802 /* if no sizeimage from user, assume worst jpeg compression */ in mxc_jpeg_sizeimage()
1810 /* jpeg stream size must be multiple of 1K */ in mxc_jpeg_sizeimage()
1837 dev_err(dev, "Error parsing JPEG stream markers\n"); in mxc_jpeg_parse()
1850 dev_err(dev, "JPEG width or height should be <= 8192: %dx%d\n", in mxc_jpeg_parse()
1856 dev_err(dev, "JPEG width or height should be > 64: %dx%d\n", in mxc_jpeg_parse()
1861 dev_err(dev, "JPEG number of components should be <=%d", in mxc_jpeg_parse()
1869 dev_warn(dev, "JPEG component ids should be 0-3 or 1-4"); in mxc_jpeg_parse()
2123 dev_err(ctx->mxc_jpeg->dev, "failed to setup mxc jpeg controls\n"); in mxc_jpeg_open()
2132 dev_dbg(dev, "Opened JPEG decoder instance %p\n", ctx); in mxc_jpeg_open()
2134 dev_dbg(dev, "Opened JPEG encoder instance %p\n", ctx); in mxc_jpeg_open()
2177 * after jpeg parse on the output buffer) in mxc_jpeg_enum_fmt_vid_cap()
2324 * but since inside JPEG the YUV quantization is full-range, in mxc_jpeg_try_fmt()
2346 struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; in mxc_jpeg_try_fmt_vid_cap() local
2347 struct device *dev = jpeg->dev; in mxc_jpeg_try_fmt_vid_cap()
2365 struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; in mxc_jpeg_try_fmt_vid_out() local
2366 struct device *dev = jpeg->dev; in mxc_jpeg_try_fmt_vid_out()
2397 struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; in mxc_jpeg_s_fmt() local
2404 v4l2_err(&jpeg->v4l2_dev, "queue busy\n"); in mxc_jpeg_s_fmt()
2459 struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; in mxc_jpeg_g_fmt_vid() local
2460 struct device *dev = jpeg->dev; in mxc_jpeg_g_fmt_vid()
2648 dev_dbg(dev, "Release JPEG decoder instance on slot %d.", in mxc_jpeg_release()
2651 dev_dbg(dev, "Release JPEG encoder instance on slot %d.", in mxc_jpeg_release()
2677 static void mxc_jpeg_detach_pm_domains(struct mxc_jpeg_dev *jpeg) in mxc_jpeg_detach_pm_domains() argument
2681 for (i = 0; i < jpeg->num_domains; i++) { in mxc_jpeg_detach_pm_domains()
2682 if (jpeg->pd_link[i] && !IS_ERR(jpeg->pd_link[i])) in mxc_jpeg_detach_pm_domains()
2683 device_link_del(jpeg->pd_link[i]); in mxc_jpeg_detach_pm_domains()
2684 if (jpeg->pd_dev[i] && !IS_ERR(jpeg->pd_dev[i])) in mxc_jpeg_detach_pm_domains()
2685 dev_pm_domain_detach(jpeg->pd_dev[i], true); in mxc_jpeg_detach_pm_domains()
2686 jpeg->pd_dev[i] = NULL; in mxc_jpeg_detach_pm_domains()
2687 jpeg->pd_link[i] = NULL; in mxc_jpeg_detach_pm_domains()
2691 static int mxc_jpeg_attach_pm_domains(struct mxc_jpeg_dev *jpeg) in mxc_jpeg_attach_pm_domains() argument
2693 struct device *dev = jpeg->dev; in mxc_jpeg_attach_pm_domains()
2694 struct device_node *np = jpeg->pdev->dev.of_node; in mxc_jpeg_attach_pm_domains()
2698 jpeg->num_domains = of_count_phandle_with_args(np, "power-domains", in mxc_jpeg_attach_pm_domains()
2700 if (jpeg->num_domains < 0) { in mxc_jpeg_attach_pm_domains()
2701 dev_err(dev, "No power domains defined for jpeg node\n"); in mxc_jpeg_attach_pm_domains()
2702 return jpeg->num_domains; in mxc_jpeg_attach_pm_domains()
2704 if (jpeg->num_domains == 1) { in mxc_jpeg_attach_pm_domains()
2706 jpeg->num_domains = 0; in mxc_jpeg_attach_pm_domains()
2710 jpeg->pd_dev = devm_kmalloc_array(dev, jpeg->num_domains, in mxc_jpeg_attach_pm_domains()
2711 sizeof(*jpeg->pd_dev), GFP_KERNEL); in mxc_jpeg_attach_pm_domains()
2712 if (!jpeg->pd_dev) in mxc_jpeg_attach_pm_domains()
2715 jpeg->pd_link = devm_kmalloc_array(dev, jpeg->num_domains, in mxc_jpeg_attach_pm_domains()
2716 sizeof(*jpeg->pd_link), GFP_KERNEL); in mxc_jpeg_attach_pm_domains()
2717 if (!jpeg->pd_link) in mxc_jpeg_attach_pm_domains()
2720 for (i = 0; i < jpeg->num_domains; i++) { in mxc_jpeg_attach_pm_domains()
2721 jpeg->pd_dev[i] = dev_pm_domain_attach_by_id(dev, i); in mxc_jpeg_attach_pm_domains()
2722 if (IS_ERR(jpeg->pd_dev[i])) { in mxc_jpeg_attach_pm_domains()
2723 ret = PTR_ERR(jpeg->pd_dev[i]); in mxc_jpeg_attach_pm_domains()
2727 jpeg->pd_link[i] = device_link_add(dev, jpeg->pd_dev[i], in mxc_jpeg_attach_pm_domains()
2730 if (!jpeg->pd_link[i]) { in mxc_jpeg_attach_pm_domains()
2738 mxc_jpeg_detach_pm_domains(jpeg); in mxc_jpeg_attach_pm_domains()
2744 struct mxc_jpeg_dev *jpeg; in mxc_jpeg_probe() local
2756 jpeg = devm_kzalloc(dev, sizeof(struct mxc_jpeg_dev), GFP_KERNEL); in mxc_jpeg_probe()
2757 if (!jpeg) in mxc_jpeg_probe()
2760 mutex_init(&jpeg->lock); in mxc_jpeg_probe()
2761 spin_lock_init(&jpeg->hw_lock); in mxc_jpeg_probe()
2769 jpeg->base_reg = devm_platform_ioremap_resource(pdev, 0); in mxc_jpeg_probe()
2770 if (IS_ERR(jpeg->base_reg)) in mxc_jpeg_probe()
2771 return PTR_ERR(jpeg->base_reg); in mxc_jpeg_probe()
2773 ret = of_property_read_u32_index(pdev->dev.of_node, "slot", 0, &jpeg->slot_data.slot); in mxc_jpeg_probe()
2775 jpeg->slot_data.slot = 0; in mxc_jpeg_probe()
2776 dev_info(&pdev->dev, "choose slot %d\n", jpeg->slot_data.slot); in mxc_jpeg_probe()
2783 0, pdev->name, jpeg); in mxc_jpeg_probe()
2790 jpeg->pdev = pdev; in mxc_jpeg_probe()
2791 jpeg->dev = dev; in mxc_jpeg_probe()
2792 jpeg->mode = mode; in mxc_jpeg_probe()
2795 ret = devm_clk_bulk_get_all(&pdev->dev, &jpeg->clks); in mxc_jpeg_probe()
2800 jpeg->num_clks = ret; in mxc_jpeg_probe()
2802 ret = mxc_jpeg_attach_pm_domains(jpeg); in mxc_jpeg_probe()
2809 ret = v4l2_device_register(dev, &jpeg->v4l2_dev); in mxc_jpeg_probe()
2814 jpeg->m2m_dev = v4l2_m2m_init(&mxc_jpeg_m2m_ops); in mxc_jpeg_probe()
2815 if (IS_ERR(jpeg->m2m_dev)) { in mxc_jpeg_probe()
2817 ret = PTR_ERR(jpeg->m2m_dev); in mxc_jpeg_probe()
2821 jpeg->dec_vdev = video_device_alloc(); in mxc_jpeg_probe()
2822 if (!jpeg->dec_vdev) { in mxc_jpeg_probe()
2828 snprintf(jpeg->dec_vdev->name, in mxc_jpeg_probe()
2829 sizeof(jpeg->dec_vdev->name), in mxc_jpeg_probe()
2832 snprintf(jpeg->dec_vdev->name, in mxc_jpeg_probe()
2833 sizeof(jpeg->dec_vdev->name), in mxc_jpeg_probe()
2836 jpeg->dec_vdev->fops = &mxc_jpeg_fops; in mxc_jpeg_probe()
2837 jpeg->dec_vdev->ioctl_ops = &mxc_jpeg_ioctl_ops; in mxc_jpeg_probe()
2838 jpeg->dec_vdev->minor = -1; in mxc_jpeg_probe()
2839 jpeg->dec_vdev->release = video_device_release; in mxc_jpeg_probe()
2840 jpeg->dec_vdev->lock = &jpeg->lock; /* lock for ioctl serialization */ in mxc_jpeg_probe()
2841 jpeg->dec_vdev->v4l2_dev = &jpeg->v4l2_dev; in mxc_jpeg_probe()
2842 jpeg->dec_vdev->vfl_dir = VFL_DIR_M2M; in mxc_jpeg_probe()
2843 jpeg->dec_vdev->device_caps = V4L2_CAP_STREAMING | in mxc_jpeg_probe()
2846 v4l2_disable_ioctl(jpeg->dec_vdev, VIDIOC_DECODER_CMD); in mxc_jpeg_probe()
2847 v4l2_disable_ioctl(jpeg->dec_vdev, VIDIOC_TRY_DECODER_CMD); in mxc_jpeg_probe()
2849 v4l2_disable_ioctl(jpeg->dec_vdev, VIDIOC_ENCODER_CMD); in mxc_jpeg_probe()
2850 v4l2_disable_ioctl(jpeg->dec_vdev, VIDIOC_TRY_ENCODER_CMD); in mxc_jpeg_probe()
2852 ret = video_register_device(jpeg->dec_vdev, VFL_TYPE_VIDEO, -1); in mxc_jpeg_probe()
2857 video_set_drvdata(jpeg->dec_vdev, jpeg); in mxc_jpeg_probe()
2859 v4l2_info(&jpeg->v4l2_dev, in mxc_jpeg_probe()
2861 jpeg->dec_vdev->num, VIDEO_MAJOR, in mxc_jpeg_probe()
2862 jpeg->dec_vdev->minor); in mxc_jpeg_probe()
2864 v4l2_info(&jpeg->v4l2_dev, in mxc_jpeg_probe()
2866 jpeg->dec_vdev->num, VIDEO_MAJOR, in mxc_jpeg_probe()
2867 jpeg->dec_vdev->minor); in mxc_jpeg_probe()
2869 platform_set_drvdata(pdev, jpeg); in mxc_jpeg_probe()
2875 video_device_release(jpeg->dec_vdev); in mxc_jpeg_probe()
2878 v4l2_m2m_release(jpeg->m2m_dev); in mxc_jpeg_probe()
2881 v4l2_device_unregister(&jpeg->v4l2_dev); in mxc_jpeg_probe()
2884 mxc_jpeg_detach_pm_domains(jpeg); in mxc_jpeg_probe()
2894 struct mxc_jpeg_dev *jpeg = dev_get_drvdata(dev); in mxc_jpeg_runtime_resume() local
2897 ret = clk_bulk_prepare_enable(jpeg->num_clks, jpeg->clks); in mxc_jpeg_runtime_resume()
2908 struct mxc_jpeg_dev *jpeg = dev_get_drvdata(dev); in mxc_jpeg_runtime_suspend() local
2910 clk_bulk_disable_unprepare(jpeg->num_clks, jpeg->clks); in mxc_jpeg_runtime_suspend()
2919 struct mxc_jpeg_dev *jpeg = dev_get_drvdata(dev); in mxc_jpeg_suspend() local
2921 v4l2_m2m_suspend(jpeg->m2m_dev); in mxc_jpeg_suspend()
2927 struct mxc_jpeg_dev *jpeg = dev_get_drvdata(dev); in mxc_jpeg_resume() local
2934 v4l2_m2m_resume(jpeg->m2m_dev); in mxc_jpeg_resume()
2947 struct mxc_jpeg_dev *jpeg = platform_get_drvdata(pdev); in mxc_jpeg_remove() local
2949 mxc_jpeg_free_slot_data(jpeg); in mxc_jpeg_remove()
2952 video_unregister_device(jpeg->dec_vdev); in mxc_jpeg_remove()
2953 v4l2_m2m_release(jpeg->m2m_dev); in mxc_jpeg_remove()
2954 v4l2_device_unregister(&jpeg->v4l2_dev); in mxc_jpeg_remove()
2955 mxc_jpeg_detach_pm_domains(jpeg); in mxc_jpeg_remove()
2964 .name = "mxc-jpeg",
2973 MODULE_DESCRIPTION("V4L2 driver for i.MX8 QXP/QM JPEG encoder/decoder");