Lines Matching +full:min +full:- +full:pix +full:- +full:alignment
1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (C) 2014-2015 Cogent Embedded, Inc. <source@cogentembedded.com>
5 * Copyright (C) 2014-2015 Renesas Electronics Corporation
7 * This is based on the drivers/media/platform/samsung/s5p-jpeg driver by
31 #include <media/v4l2-ctrls.h>
32 #include <media/v4l2-device.h>
33 #include <media/v4l2-event.h>
34 #include <media/v4l2-fh.h>
35 #include <media/v4l2-mem2mem.h>
36 #include <media/v4l2-ioctl.h>
37 #include <media/videobuf2-v4l2.h>
38 #include <media/videobuf2-dma-contig.h>
113 #define JCQTN_SHIFT(t) (((t) - 1) << 1)
117 #define JCHTN_AC_SHIFT(t) (((t) << 1) - 1)
118 #define JCHTN_DC_SHIFT(t) (((t) - 1) << 1)
177 * struct jpu - JPEG IP abstraction
208 * struct jpu_buffer - driver's specific video buffer
220 * struct jpu_fmt - driver's internal format data
224 * @h_align: horizontal alignment order (align to 2^h_align)
225 * @v_align: vertical alignment order (align to 2^v_align)
242 * struct jpu_q_data - parameters of one queue
243 * @fmtinfo: driver-specific format of this queue
254 * struct jpu_ctx - the device context data
274 * jpeg_buffer - description of memory containing input JPEG data
315 * SOF0 (17 bytes payload) is Baseline DCT - Sample precision, height, width,
316 * Number of image components, (Ci:8 - Hi:4 - Vi:4 - Tq:8) * 3 - Y,Cb,Cr;
323 JPU_JPEG_QTBL_LUM_OFFSET + JPU_JPEG_QTBL_SIZE - 1] = 0x00, \
326 JPU_JPEG_QTBL_SIZE - 1] = 0x00, \
335 JPU_JPEG_HDCTBL_LUM_OFFSET + JPU_JPEG_HDCTBL_SIZE - 1] = 0x00, \
339 JPU_JPEG_HACTBL_LUM_OFFSET + JPU_JPEG_HACTBL_SIZE - 1] = 0x00, \
343 JPU_JPEG_HDCTBL_CHR_OFFSET + JPU_JPEG_HDCTBL_SIZE - 1] = 0x00, \
347 JPU_JPEG_HACTBL_CHR_OFFSET + JPU_JPEG_HACTBL_SIZE - 1] = 0x00, \
348 [JPU_JPEG_PADDING_OFFSET ... JPU_JPEG_HDR_SIZE - 1] = 0xff \
352 [0 ... JPU_MAX_QUALITY - 1] = JPU_JPEG_HDR_BLOB
470 return ioread32(jpu->regs + reg); in jpu_read()
475 iowrite32(val, jpu->regs + reg); in jpu_write()
480 return container_of(c->handler, struct jpu_ctx, ctrl_handler); in ctrl_to_ctx()
518 dev_err(jpu->dev, "timed out in reset\n"); in jpu_wait_reset()
519 return -ETIMEDOUT; in jpu_wait_reset()
552 p[i + j] = htbl[i + 3 - j]; in put_htbl()
573 if (buf->curr >= buf->end) in get_byte()
574 return -1; in get_byte()
576 return *(u8 *)buf->curr++; in get_byte()
581 if (buf->end - buf->curr < 2) in get_word_be()
582 return -1; in get_word_be()
584 *word = get_unaligned_be16(buf->curr); in get_word_be()
585 buf->curr += 2; in get_word_be()
592 buf->curr += min((unsigned long)(buf->end - buf->curr), len); in skip()
606 * basic size check and EOI - we don't want to let JPU cross in jpu_parse_hdr()
610 *(u8 *)(buffer + size - 1) != JPEG_MARKER_EOI) in jpu_parse_hdr()
644 skip(&jpeg_buffer, (long)word - 2); in jpu_parse_hdr()
661 if (ctx->encoder) in jpu_querycap()
662 strscpy(cap->card, DRV_NAME " encoder", sizeof(cap->card)); in jpu_querycap()
664 strscpy(cap->card, DRV_NAME " decoder", sizeof(cap->card)); in jpu_querycap()
666 strscpy(cap->driver, DRV_NAME, sizeof(cap->driver)); in jpu_querycap()
667 memset(cap->reserved, 0, sizeof(cap->reserved)); in jpu_querycap()
687 if (fmt->fourcc == pixelformat && fmt->types & fmt_flag) in jpu_find_format()
700 if (num == f->index) in jpu_enum_fmt()
707 return -EINVAL; in jpu_enum_fmt()
709 f->pixelformat = jpu_formats[i].fourcc; in jpu_enum_fmt()
719 return jpu_enum_fmt(f, ctx->encoder ? JPU_ENC_CAPTURE : in jpu_enum_fmt_cap()
728 return jpu_enum_fmt(f, ctx->encoder ? JPU_ENC_OUTPUT : JPU_DEC_OUTPUT); in jpu_enum_fmt_out()
735 return &ctx->out_q; in jpu_get_q_data()
737 return &ctx->cap_q; in jpu_get_q_data()
762 struct v4l2_pix_format_mplane *pix, in __jpu_try_fmt() argument
771 fmt = jpu_find_format(ctx->encoder, pix->pixelformat, f_type); in __jpu_try_fmt()
775 dev_dbg(ctx->jpu->dev, "unknown format; set default format\n"); in __jpu_try_fmt()
776 if (ctx->encoder) in __jpu_try_fmt()
782 fmt = jpu_find_format(ctx->encoder, pixelformat, f_type); in __jpu_try_fmt()
785 pix->pixelformat = fmt->fourcc; in __jpu_try_fmt()
786 pix->colorspace = fmt->colorspace; in __jpu_try_fmt()
787 pix->field = V4L2_FIELD_NONE; in __jpu_try_fmt()
788 pix->num_planes = fmt->num_planes; in __jpu_try_fmt()
790 jpu_bound_align_image(&pix->width, JPU_WIDTH_MIN, JPU_WIDTH_MAX, in __jpu_try_fmt()
791 fmt->h_align, &pix->height, JPU_HEIGHT_MIN, in __jpu_try_fmt()
792 JPU_HEIGHT_MAX, fmt->v_align); in __jpu_try_fmt()
794 w = pix->width; in __jpu_try_fmt()
795 h = pix->height; in __jpu_try_fmt()
797 if (fmt->fourcc == V4L2_PIX_FMT_JPEG) { in __jpu_try_fmt()
799 if (pix->plane_fmt[0].sizeimage <= 0 || ctx->encoder) in __jpu_try_fmt()
800 pix->plane_fmt[0].sizeimage = JPU_JPEG_HDR_SIZE + in __jpu_try_fmt()
802 pix->plane_fmt[0].bytesperline = 0; in __jpu_try_fmt()
806 for (i = 0; i < pix->num_planes; ++i) in __jpu_try_fmt()
807 bpl = max(bpl, pix->plane_fmt[i].bytesperline); in __jpu_try_fmt()
812 for (i = 0; i < pix->num_planes; ++i) { in __jpu_try_fmt()
813 pix->plane_fmt[i].bytesperline = bpl; in __jpu_try_fmt()
814 pix->plane_fmt[i].sizeimage = bpl * h * fmt->bpp[i] / 8; in __jpu_try_fmt()
828 if (!v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type)) in jpu_try_fmt()
829 return -EINVAL; in jpu_try_fmt()
831 return __jpu_try_fmt(ctx, NULL, &f->fmt.pix_mp, f->type); in jpu_try_fmt()
838 struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; in jpu_s_fmt()
843 vq = v4l2_m2m_get_vq(m2m_ctx, f->type); in jpu_s_fmt()
845 return -EINVAL; in jpu_s_fmt()
848 v4l2_err(&ctx->jpu->v4l2_dev, "%s queue busy\n", __func__); in jpu_s_fmt()
849 return -EBUSY; in jpu_s_fmt()
852 ret = __jpu_try_fmt(ctx, &fmtinfo, &f->fmt.pix_mp, f->type); in jpu_s_fmt()
856 q_data = jpu_get_q_data(ctx, f->type); in jpu_s_fmt()
858 q_data->format = f->fmt.pix_mp; in jpu_s_fmt()
859 q_data->fmtinfo = fmtinfo; in jpu_s_fmt()
869 if (!v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type)) in jpu_g_fmt()
870 return -EINVAL; in jpu_g_fmt()
872 q_data = jpu_get_q_data(ctx, f->type); in jpu_g_fmt()
873 f->fmt.pix_mp = q_data->format; in jpu_g_fmt()
886 spin_lock_irqsave(&ctx->jpu->lock, flags); in jpu_s_ctrl()
887 if (ctrl->id == V4L2_CID_JPEG_COMPRESSION_QUALITY) in jpu_s_ctrl()
888 ctx->compr_quality = ctrl->val; in jpu_s_ctrl()
889 spin_unlock_irqrestore(&ctx->jpu->lock, flags); in jpu_s_ctrl()
907 if (ctx->encoder) { in jpu_streamon()
919 adj.format.width = ref->format.width; in jpu_streamon()
920 adj.format.height = ref->format.height; in jpu_streamon()
924 if (adj.format.width != orig->format.width || in jpu_streamon()
925 adj.format.height != orig->format.height) { in jpu_streamon()
926 dev_err(ctx->jpu->dev, "src and dst formats do not match.\n"); in jpu_streamon()
927 /* maybe we can return -EPIPE here? */ in jpu_streamon()
928 return -EINVAL; in jpu_streamon()
931 return v4l2_m2m_streamon(file, ctx->fh.m2m_ctx, type); in jpu_streamon()
965 v4l2_ctrl_handler_init(&ctx->ctrl_handler, 1); in jpu_controls_create()
967 ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler, &jpu_ctrl_ops, in jpu_controls_create()
969 0, JPU_MAX_QUALITY - 1, 1, 0); in jpu_controls_create()
971 if (ctx->ctrl_handler.error) { in jpu_controls_create()
972 ret = ctx->ctrl_handler.error; in jpu_controls_create()
976 if (!ctx->encoder) in jpu_controls_create()
977 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE | in jpu_controls_create()
980 ret = v4l2_ctrl_handler_setup(&ctx->ctrl_handler); in jpu_controls_create()
987 v4l2_ctrl_handler_free(&ctx->ctrl_handler); in jpu_controls_create()
1004 q_data = jpu_get_q_data(ctx, vq->type); in jpu_queue_setup()
1007 if (*nplanes != q_data->format.num_planes) in jpu_queue_setup()
1008 return -EINVAL; in jpu_queue_setup()
1011 unsigned int q_size = q_data->format.plane_fmt[i].sizeimage; in jpu_queue_setup()
1014 return -EINVAL; in jpu_queue_setup()
1019 *nplanes = q_data->format.num_planes; in jpu_queue_setup()
1022 sizes[i] = q_data->format.plane_fmt[i].sizeimage; in jpu_queue_setup()
1030 struct jpu_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); in jpu_buf_prepare()
1034 q_data = jpu_get_q_data(ctx, vb->vb2_queue->type); in jpu_buf_prepare()
1036 if (V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) { in jpu_buf_prepare()
1037 if (vbuf->field == V4L2_FIELD_ANY) in jpu_buf_prepare()
1038 vbuf->field = V4L2_FIELD_NONE; in jpu_buf_prepare()
1039 if (vbuf->field != V4L2_FIELD_NONE) { in jpu_buf_prepare()
1040 dev_err(ctx->jpu->dev, "%s field isn't supported\n", in jpu_buf_prepare()
1042 return -EINVAL; in jpu_buf_prepare()
1046 for (i = 0; i < q_data->format.num_planes; i++) { in jpu_buf_prepare()
1047 unsigned long size = q_data->format.plane_fmt[i].sizeimage; in jpu_buf_prepare()
1050 dev_err(ctx->jpu->dev, in jpu_buf_prepare()
1053 return -EINVAL; in jpu_buf_prepare()
1057 if (!ctx->encoder && V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type)) in jpu_buf_prepare()
1067 struct jpu_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); in jpu_buf_queue()
1069 if (!ctx->encoder && V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) { in jpu_buf_queue()
1083 q_data = &ctx->out_q; in jpu_buf_queue()
1092 if (adjust.format.width != q_data->format.width || in jpu_buf_queue()
1093 adjust.format.height != q_data->format.height) in jpu_buf_queue()
1100 jpu_buf->subsampling = subsampling; in jpu_buf_queue()
1103 if (ctx->fh.m2m_ctx) in jpu_buf_queue()
1104 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf); in jpu_buf_queue()
1109 dev_err(ctx->jpu->dev, "incompatible or corrupted JPEG data\n"); in jpu_buf_queue()
1117 struct jpu_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); in jpu_buf_finish()
1118 struct jpu_q_data *q_data = &ctx->out_q; in jpu_buf_finish()
1119 enum v4l2_buf_type type = vb->vb2_queue->type; in jpu_buf_finish()
1122 if (vb->state == VB2_BUF_STATE_DONE) in jpu_buf_finish()
1123 vbuf->sequence = jpu_get_q_data(ctx, type)->sequence++; in jpu_buf_finish()
1125 if (!ctx->encoder || vb->state != VB2_BUF_STATE_DONE || in jpu_buf_finish()
1131 memcpy(buffer, jpeg_hdrs[jpu_buf->compr_quality], JPU_JPEG_HDR_SIZE); in jpu_buf_finish()
1133 cpu_to_be16(q_data->format.height); in jpu_buf_finish()
1135 cpu_to_be16(q_data->format.width); in jpu_buf_finish()
1136 *(buffer + JPU_JPEG_SUBS_OFFSET) = q_data->fmtinfo->subsampling; in jpu_buf_finish()
1142 struct jpu_q_data *q_data = jpu_get_q_data(ctx, vq->type); in jpu_start_streaming()
1144 q_data->sequence = 0; in jpu_start_streaming()
1155 if (V4L2_TYPE_IS_OUTPUT(vq->type)) in jpu_stop_streaming()
1156 vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in jpu_stop_streaming()
1158 vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in jpu_stop_streaming()
1161 spin_lock_irqsave(&ctx->jpu->lock, flags); in jpu_stop_streaming()
1163 spin_unlock_irqrestore(&ctx->jpu->lock, flags); in jpu_stop_streaming()
1185 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; in jpu_queue_init()
1186 src_vq->io_modes = VB2_MMAP | VB2_DMABUF; in jpu_queue_init()
1187 src_vq->drv_priv = ctx; in jpu_queue_init()
1188 src_vq->buf_struct_size = sizeof(struct jpu_buffer); in jpu_queue_init()
1189 src_vq->ops = &jpu_qops; in jpu_queue_init()
1190 src_vq->mem_ops = &vb2_dma_contig_memops; in jpu_queue_init()
1191 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; in jpu_queue_init()
1192 src_vq->lock = &ctx->jpu->mutex; in jpu_queue_init()
1193 src_vq->dev = ctx->jpu->v4l2_dev.dev; in jpu_queue_init()
1200 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; in jpu_queue_init()
1201 dst_vq->io_modes = VB2_MMAP | VB2_DMABUF; in jpu_queue_init()
1202 dst_vq->drv_priv = ctx; in jpu_queue_init()
1203 dst_vq->buf_struct_size = sizeof(struct jpu_buffer); in jpu_queue_init()
1204 dst_vq->ops = &jpu_qops; in jpu_queue_init()
1205 dst_vq->mem_ops = &vb2_dma_contig_memops; in jpu_queue_init()
1206 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 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()
1227 return -ENOMEM; in jpu_open()
1229 v4l2_fh_init(&ctx->fh, vfd); in jpu_open()
1230 ctx->fh.ctrl_handler = &ctx->ctrl_handler; in jpu_open()
1231 file->private_data = &ctx->fh; in jpu_open()
1232 v4l2_fh_add(&ctx->fh); in jpu_open()
1234 ctx->jpu = jpu; in jpu_open()
1235 ctx->encoder = vfd == &jpu->vfd_encoder; in jpu_open()
1237 __jpu_try_fmt(ctx, &ctx->out_q.fmtinfo, &ctx->out_q.format, in jpu_open()
1239 __jpu_try_fmt(ctx, &ctx->cap_q.fmtinfo, &ctx->cap_q.format, in jpu_open()
1242 ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(jpu->m2m_dev, ctx, jpu_queue_init); in jpu_open()
1243 if (IS_ERR(ctx->fh.m2m_ctx)) { in jpu_open()
1244 ret = PTR_ERR(ctx->fh.m2m_ctx); in jpu_open()
1252 if (mutex_lock_interruptible(&jpu->mutex)) { in jpu_open()
1253 ret = -ERESTARTSYS; in jpu_open()
1257 if (jpu->ref_count == 0) { in jpu_open()
1258 ret = clk_prepare_enable(jpu->clk); 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()
1277 v4l2_fh_del(&ctx->fh); in jpu_open()
1278 v4l2_fh_exit(&ctx->fh); in jpu_open()
1286 struct jpu_ctx *ctx = fh_to_ctx(file->private_data); in jpu_release()
1288 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); in jpu_release()
1289 v4l2_ctrl_handler_free(&ctx->ctrl_handler); in jpu_release()
1290 v4l2_fh_del(&ctx->fh); in jpu_release()
1291 v4l2_fh_exit(&ctx->fh); in jpu_release()
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()
1324 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in jpu_cleanup()
1325 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); 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()
1356 spin_lock_irqsave(&ctx->jpu->lock, flags); in jpu_device_run()
1358 jpu->curr = ctx; in jpu_device_run()
1360 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in jpu_device_run()
1361 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in jpu_device_run()
1363 if (ctx->encoder) { in jpu_device_run()
1365 q_data = &ctx->out_q; in jpu_device_run()
1368 q_data = &ctx->cap_q; in jpu_device_run()
1371 w = q_data->format.width; in jpu_device_run()
1372 h = q_data->format.height; in jpu_device_run()
1373 bpl = q_data->format.plane_fmt[0].bytesperline; in jpu_device_run()
1374 num_planes = q_data->fmtinfo->num_planes; in jpu_device_run()
1375 subsampling = q_data->fmtinfo->subsampling; in jpu_device_run()
1377 if (ctx->encoder) { in jpu_device_run()
1381 dst_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0); in jpu_device_run()
1383 vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0); in jpu_device_run()
1386 &src_buf->vb2_buf, 1); in jpu_device_run()
1390 jpu_buf->compr_quality = ctx->compr_quality; in jpu_device_run()
1434 jpu_set_qtbl(jpu, ctx->compr_quality); in jpu_device_run()
1439 if (jpu_buf->subsampling != subsampling) { 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()
1447 src_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0); in jpu_device_run()
1449 vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0); in jpu_device_run()
1450 if (q_data->fmtinfo->num_planes > 1) in jpu_device_run()
1452 &dst_buf->vb2_buf, 1); in jpu_device_run()
1461 /* ...enable interrupts on transfer completion and d-g error */ in jpu_device_run()
1475 spin_unlock_irqrestore(&ctx->jpu->lock, flags); in jpu_device_run()
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()
1519 src_buf = v4l2_m2m_src_buf_remove(curr_ctx->fh.m2m_ctx); in jpu_irq_handler()
1520 dst_buf = v4l2_m2m_dst_buf_remove(curr_ctx->fh.m2m_ctx); in jpu_irq_handler()
1523 if (curr_ctx->encoder) { in jpu_irq_handler()
1527 vb2_set_plane_payload(&dst_buf->vb2_buf, 0, in jpu_irq_handler()
1531 dst_buf->field = src_buf->field; in jpu_irq_handler()
1532 dst_buf->vb2_buf.timestamp = src_buf->vb2_buf.timestamp; in jpu_irq_handler()
1533 if (src_buf->flags & V4L2_BUF_FLAG_TIMECODE) in jpu_irq_handler()
1534 dst_buf->timecode = src_buf->timecode; in jpu_irq_handler()
1535 dst_buf->flags = src_buf->flags & 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()
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" },
1588 jpu = devm_kzalloc(&pdev->dev, sizeof(*jpu), GFP_KERNEL); in jpu_probe()
1590 return -ENOMEM; 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()
1596 /* memory-mapped registers */ 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()
1616 dev_err(&pdev->dev, "cannot get clock\n"); 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()
1623 dev_err(&pdev->dev, "Failed to register v4l2 device\n"); 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()
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()
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()
1712 if (jpu->ref_count == 0) in jpu_suspend()
1715 clk_disable_unprepare(jpu->clk); in jpu_suspend()
1724 if (jpu->ref_count == 0) in jpu_resume()
1727 clk_prepare_enable(jpu->clk); in jpu_resume()
1751 MODULE_DESCRIPTION("Renesas R-Car JPEG processing unit driver");