2 * Copyright (c) 2016 MediaTek Inc.
3 * Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
4 * Rick Chang <rick.chang@mediatek.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/clk.h>
17 #include <linux/err.h>
18 #include <linux/interrupt.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/of_platform.h>
23 #include <linux/platform_device.h>
24 #include <linux/pm_runtime.h>
25 #include <linux/slab.h>
26 #include <linux/spinlock.h>
27 #include <media/v4l2-event.h>
28 #include <media/v4l2-mem2mem.h>
29 #include <media/v4l2-ioctl.h>
30 #include <media/videobuf2-core.h>
31 #include <media/videobuf2-dma-contig.h>
32 #include <soc/mediatek/smi.h>
34 #include "mtk_jpeg_hw.h"
35 #include "mtk_jpeg_core.h"
36 #include "mtk_jpeg_parse.h"
38 static struct mtk_jpeg_fmt mtk_jpeg_formats[] = {
40 .fourcc = V4L2_PIX_FMT_JPEG,
42 .flags = MTK_JPEG_FMT_FLAG_DEC_OUTPUT,
45 .fourcc = V4L2_PIX_FMT_YUV420M,
46 .h_sample = {4, 2, 2},
47 .v_sample = {4, 2, 2},
51 .flags = MTK_JPEG_FMT_FLAG_DEC_CAPTURE,
54 .fourcc = V4L2_PIX_FMT_YUV422M,
55 .h_sample = {4, 2, 2},
56 .v_sample = {4, 4, 4},
60 .flags = MTK_JPEG_FMT_FLAG_DEC_CAPTURE,
64 #define MTK_JPEG_NUM_FORMATS ARRAY_SIZE(mtk_jpeg_formats)
67 MTK_JPEG_BUF_FLAGS_INIT = 0,
68 MTK_JPEG_BUF_FLAGS_LAST_FRAME = 1,
71 struct mtk_jpeg_src_buf {
72 struct vb2_v4l2_buffer b;
73 struct list_head list;
75 struct mtk_jpeg_dec_param dec_param;
79 module_param(debug, int, 0644);
81 static inline struct mtk_jpeg_ctx *mtk_jpeg_fh_to_ctx(struct v4l2_fh *fh)
83 return container_of(fh, struct mtk_jpeg_ctx, fh);
86 static inline struct mtk_jpeg_src_buf *mtk_jpeg_vb2_to_srcbuf(
87 struct vb2_buffer *vb)
89 return container_of(to_vb2_v4l2_buffer(vb), struct mtk_jpeg_src_buf, b);
92 static int mtk_jpeg_querycap(struct file *file, void *priv,
93 struct v4l2_capability *cap)
95 struct mtk_jpeg_dev *jpeg = video_drvdata(file);
97 strlcpy(cap->driver, MTK_JPEG_NAME " decoder", sizeof(cap->driver));
98 strlcpy(cap->card, MTK_JPEG_NAME " decoder", sizeof(cap->card));
99 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
100 dev_name(jpeg->dev));
105 static int mtk_jpeg_enum_fmt(struct mtk_jpeg_fmt *mtk_jpeg_formats, int n,
106 struct v4l2_fmtdesc *f, u32 type)
110 for (i = 0; i < n; ++i) {
111 if (mtk_jpeg_formats[i].flags & type) {
121 f->pixelformat = mtk_jpeg_formats[i].fourcc;
126 static int mtk_jpeg_enum_fmt_vid_cap(struct file *file, void *priv,
127 struct v4l2_fmtdesc *f)
129 return mtk_jpeg_enum_fmt(mtk_jpeg_formats, MTK_JPEG_NUM_FORMATS, f,
130 MTK_JPEG_FMT_FLAG_DEC_CAPTURE);
133 static int mtk_jpeg_enum_fmt_vid_out(struct file *file, void *priv,
134 struct v4l2_fmtdesc *f)
136 return mtk_jpeg_enum_fmt(mtk_jpeg_formats, MTK_JPEG_NUM_FORMATS, f,
137 MTK_JPEG_FMT_FLAG_DEC_OUTPUT);
140 static struct mtk_jpeg_q_data *mtk_jpeg_get_q_data(struct mtk_jpeg_ctx *ctx,
141 enum v4l2_buf_type type)
143 if (V4L2_TYPE_IS_OUTPUT(type))
148 static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx,
150 unsigned int fmt_type)
152 unsigned int k, fmt_flag;
154 fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
155 MTK_JPEG_FMT_FLAG_DEC_OUTPUT :
156 MTK_JPEG_FMT_FLAG_DEC_CAPTURE;
158 for (k = 0; k < MTK_JPEG_NUM_FORMATS; k++) {
159 struct mtk_jpeg_fmt *fmt = &mtk_jpeg_formats[k];
161 if (fmt->fourcc == pixelformat && fmt->flags & fmt_flag)
168 static void mtk_jpeg_bound_align_image(u32 *w, unsigned int wmin,
169 unsigned int wmax, unsigned int walign,
170 u32 *h, unsigned int hmin,
171 unsigned int hmax, unsigned int halign)
173 int width, height, w_step, h_step;
177 w_step = 1 << walign;
178 h_step = 1 << halign;
180 v4l_bound_align_image(w, wmin, wmax, walign, h, hmin, hmax, halign, 0);
181 if (*w < width && (*w + w_step) <= wmax)
183 if (*h < height && (*h + h_step) <= hmax)
187 static void mtk_jpeg_adjust_fmt_mplane(struct mtk_jpeg_ctx *ctx,
188 struct v4l2_format *f)
190 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
191 struct mtk_jpeg_q_data *q_data;
194 q_data = mtk_jpeg_get_q_data(ctx, f->type);
196 pix_mp->width = q_data->w;
197 pix_mp->height = q_data->h;
198 pix_mp->pixelformat = q_data->fmt->fourcc;
199 pix_mp->num_planes = q_data->fmt->colplanes;
201 for (i = 0; i < pix_mp->num_planes; i++) {
202 pix_mp->plane_fmt[i].bytesperline = q_data->bytesperline[i];
203 pix_mp->plane_fmt[i].sizeimage = q_data->sizeimage[i];
207 static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
208 struct mtk_jpeg_fmt *fmt,
209 struct mtk_jpeg_ctx *ctx, int q_type)
211 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
212 struct mtk_jpeg_dev *jpeg = ctx->jpeg;
215 memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
216 pix_mp->field = V4L2_FIELD_NONE;
218 if (ctx->state != MTK_JPEG_INIT) {
219 mtk_jpeg_adjust_fmt_mplane(ctx, f);
223 pix_mp->num_planes = fmt->colplanes;
224 pix_mp->pixelformat = fmt->fourcc;
226 if (q_type == MTK_JPEG_FMT_TYPE_OUTPUT) {
227 struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[0];
229 mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
230 MTK_JPEG_MAX_WIDTH, 0,
231 &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
232 MTK_JPEG_MAX_HEIGHT, 0);
234 memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
235 pfmt->bytesperline = 0;
236 /* Source size must be aligned to 128 */
237 pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
238 if (pfmt->sizeimage == 0)
239 pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
243 /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
244 mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
245 MTK_JPEG_MAX_WIDTH, fmt->h_align,
246 &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
247 MTK_JPEG_MAX_HEIGHT, fmt->v_align);
249 for (i = 0; i < fmt->colplanes; i++) {
250 struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[i];
251 u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
252 u32 h = pix_mp->height * fmt->v_sample[i] / 4;
254 memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
255 pfmt->bytesperline = stride;
256 pfmt->sizeimage = stride * h;
259 v4l2_dbg(2, debug, &jpeg->v4l2_dev, "wxh:%ux%u\n",
260 pix_mp->width, pix_mp->height);
261 for (i = 0; i < pix_mp->num_planes; i++) {
262 v4l2_dbg(2, debug, &jpeg->v4l2_dev,
263 "plane[%d] bpl=%u, size=%u\n",
265 pix_mp->plane_fmt[i].bytesperline,
266 pix_mp->plane_fmt[i].sizeimage);
271 static int mtk_jpeg_g_fmt_vid_mplane(struct file *file, void *priv,
272 struct v4l2_format *f)
274 struct vb2_queue *vq;
275 struct mtk_jpeg_q_data *q_data = NULL;
276 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
277 struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
278 struct mtk_jpeg_dev *jpeg = ctx->jpeg;
281 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
285 q_data = mtk_jpeg_get_q_data(ctx, f->type);
287 memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
288 pix_mp->width = q_data->w;
289 pix_mp->height = q_data->h;
290 pix_mp->field = V4L2_FIELD_NONE;
291 pix_mp->pixelformat = q_data->fmt->fourcc;
292 pix_mp->num_planes = q_data->fmt->colplanes;
293 pix_mp->colorspace = ctx->colorspace;
294 pix_mp->ycbcr_enc = ctx->ycbcr_enc;
295 pix_mp->xfer_func = ctx->xfer_func;
296 pix_mp->quantization = ctx->quantization;
298 v4l2_dbg(1, debug, &jpeg->v4l2_dev, "(%d) g_fmt:%c%c%c%c wxh:%ux%u\n",
300 (pix_mp->pixelformat & 0xff),
301 (pix_mp->pixelformat >> 8 & 0xff),
302 (pix_mp->pixelformat >> 16 & 0xff),
303 (pix_mp->pixelformat >> 24 & 0xff),
304 pix_mp->width, pix_mp->height);
306 for (i = 0; i < pix_mp->num_planes; i++) {
307 struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[i];
309 pfmt->bytesperline = q_data->bytesperline[i];
310 pfmt->sizeimage = q_data->sizeimage[i];
311 memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
313 v4l2_dbg(1, debug, &jpeg->v4l2_dev,
314 "plane[%d] bpl=%u, size=%u\n",
322 static int mtk_jpeg_try_fmt_vid_cap_mplane(struct file *file, void *priv,
323 struct v4l2_format *f)
325 struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
326 struct mtk_jpeg_fmt *fmt;
328 fmt = mtk_jpeg_find_format(ctx, f->fmt.pix_mp.pixelformat,
329 MTK_JPEG_FMT_TYPE_CAPTURE);
331 fmt = ctx->cap_q.fmt;
333 v4l2_dbg(2, debug, &ctx->jpeg->v4l2_dev, "(%d) try_fmt:%c%c%c%c\n",
335 (fmt->fourcc & 0xff),
336 (fmt->fourcc >> 8 & 0xff),
337 (fmt->fourcc >> 16 & 0xff),
338 (fmt->fourcc >> 24 & 0xff));
340 return mtk_jpeg_try_fmt_mplane(f, fmt, ctx, MTK_JPEG_FMT_TYPE_CAPTURE);
343 static int mtk_jpeg_try_fmt_vid_out_mplane(struct file *file, void *priv,
344 struct v4l2_format *f)
346 struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
347 struct mtk_jpeg_fmt *fmt;
349 fmt = mtk_jpeg_find_format(ctx, f->fmt.pix_mp.pixelformat,
350 MTK_JPEG_FMT_TYPE_OUTPUT);
352 fmt = ctx->out_q.fmt;
354 v4l2_dbg(2, debug, &ctx->jpeg->v4l2_dev, "(%d) try_fmt:%c%c%c%c\n",
356 (fmt->fourcc & 0xff),
357 (fmt->fourcc >> 8 & 0xff),
358 (fmt->fourcc >> 16 & 0xff),
359 (fmt->fourcc >> 24 & 0xff));
361 return mtk_jpeg_try_fmt_mplane(f, fmt, ctx, MTK_JPEG_FMT_TYPE_OUTPUT);
364 static int mtk_jpeg_s_fmt_mplane(struct mtk_jpeg_ctx *ctx,
365 struct v4l2_format *f)
367 struct vb2_queue *vq;
368 struct mtk_jpeg_q_data *q_data = NULL;
369 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
370 struct mtk_jpeg_dev *jpeg = ctx->jpeg;
374 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
378 q_data = mtk_jpeg_get_q_data(ctx, f->type);
380 if (vb2_is_busy(vq)) {
381 v4l2_err(&jpeg->v4l2_dev, "queue busy\n");
385 f_type = V4L2_TYPE_IS_OUTPUT(f->type) ?
386 MTK_JPEG_FMT_TYPE_OUTPUT : MTK_JPEG_FMT_TYPE_CAPTURE;
388 q_data->fmt = mtk_jpeg_find_format(ctx, pix_mp->pixelformat, f_type);
389 q_data->w = pix_mp->width;
390 q_data->h = pix_mp->height;
391 ctx->colorspace = pix_mp->colorspace;
392 ctx->ycbcr_enc = pix_mp->ycbcr_enc;
393 ctx->xfer_func = pix_mp->xfer_func;
394 ctx->quantization = pix_mp->quantization;
396 v4l2_dbg(1, debug, &jpeg->v4l2_dev, "(%d) s_fmt:%c%c%c%c wxh:%ux%u\n",
398 (q_data->fmt->fourcc & 0xff),
399 (q_data->fmt->fourcc >> 8 & 0xff),
400 (q_data->fmt->fourcc >> 16 & 0xff),
401 (q_data->fmt->fourcc >> 24 & 0xff),
402 q_data->w, q_data->h);
404 for (i = 0; i < q_data->fmt->colplanes; i++) {
405 q_data->bytesperline[i] = pix_mp->plane_fmt[i].bytesperline;
406 q_data->sizeimage[i] = pix_mp->plane_fmt[i].sizeimage;
408 v4l2_dbg(1, debug, &jpeg->v4l2_dev,
409 "plane[%d] bpl=%u, size=%u\n",
410 i, q_data->bytesperline[i], q_data->sizeimage[i]);
416 static int mtk_jpeg_s_fmt_vid_out_mplane(struct file *file, void *priv,
417 struct v4l2_format *f)
421 ret = mtk_jpeg_try_fmt_vid_out_mplane(file, priv, f);
425 return mtk_jpeg_s_fmt_mplane(mtk_jpeg_fh_to_ctx(priv), f);
428 static int mtk_jpeg_s_fmt_vid_cap_mplane(struct file *file, void *priv,
429 struct v4l2_format *f)
433 ret = mtk_jpeg_try_fmt_vid_cap_mplane(file, priv, f);
437 return mtk_jpeg_s_fmt_mplane(mtk_jpeg_fh_to_ctx(priv), f);
440 static void mtk_jpeg_queue_src_chg_event(struct mtk_jpeg_ctx *ctx)
442 static const struct v4l2_event ev_src_ch = {
443 .type = V4L2_EVENT_SOURCE_CHANGE,
444 .u.src_change.changes =
445 V4L2_EVENT_SRC_CH_RESOLUTION,
448 v4l2_event_queue_fh(&ctx->fh, &ev_src_ch);
451 static int mtk_jpeg_subscribe_event(struct v4l2_fh *fh,
452 const struct v4l2_event_subscription *sub)
455 case V4L2_EVENT_SOURCE_CHANGE:
456 return v4l2_src_change_event_subscribe(fh, sub);
462 static int mtk_jpeg_g_selection(struct file *file, void *priv,
463 struct v4l2_selection *s)
465 struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
467 if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
471 case V4L2_SEL_TGT_COMPOSE:
472 case V4L2_SEL_TGT_COMPOSE_DEFAULT:
473 s->r.width = ctx->out_q.w;
474 s->r.height = ctx->out_q.h;
478 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
479 case V4L2_SEL_TGT_COMPOSE_PADDED:
480 s->r.width = ctx->cap_q.w;
481 s->r.height = ctx->cap_q.h;
491 static int mtk_jpeg_s_selection(struct file *file, void *priv,
492 struct v4l2_selection *s)
494 struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
496 if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
500 case V4L2_SEL_TGT_COMPOSE:
503 s->r.width = ctx->out_q.w;
504 s->r.height = ctx->out_q.h;
512 static int mtk_jpeg_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
514 struct v4l2_fh *fh = file->private_data;
515 struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
516 struct vb2_queue *vq;
517 struct vb2_buffer *vb;
518 struct mtk_jpeg_src_buf *jpeg_src_buf;
520 if (buf->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
523 vq = v4l2_m2m_get_vq(fh->m2m_ctx, buf->type);
524 if (buf->index >= vq->num_buffers) {
525 dev_err(ctx->jpeg->dev, "buffer index out of range\n");
529 vb = vq->bufs[buf->index];
530 jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(vb);
531 jpeg_src_buf->flags = (buf->m.planes[0].bytesused == 0) ?
532 MTK_JPEG_BUF_FLAGS_LAST_FRAME : MTK_JPEG_BUF_FLAGS_INIT;
534 return v4l2_m2m_qbuf(file, fh->m2m_ctx, buf);
537 static const struct v4l2_ioctl_ops mtk_jpeg_ioctl_ops = {
538 .vidioc_querycap = mtk_jpeg_querycap,
539 .vidioc_enum_fmt_vid_cap_mplane = mtk_jpeg_enum_fmt_vid_cap,
540 .vidioc_enum_fmt_vid_out_mplane = mtk_jpeg_enum_fmt_vid_out,
541 .vidioc_try_fmt_vid_cap_mplane = mtk_jpeg_try_fmt_vid_cap_mplane,
542 .vidioc_try_fmt_vid_out_mplane = mtk_jpeg_try_fmt_vid_out_mplane,
543 .vidioc_g_fmt_vid_cap_mplane = mtk_jpeg_g_fmt_vid_mplane,
544 .vidioc_g_fmt_vid_out_mplane = mtk_jpeg_g_fmt_vid_mplane,
545 .vidioc_s_fmt_vid_cap_mplane = mtk_jpeg_s_fmt_vid_cap_mplane,
546 .vidioc_s_fmt_vid_out_mplane = mtk_jpeg_s_fmt_vid_out_mplane,
547 .vidioc_qbuf = mtk_jpeg_qbuf,
548 .vidioc_subscribe_event = mtk_jpeg_subscribe_event,
549 .vidioc_g_selection = mtk_jpeg_g_selection,
550 .vidioc_s_selection = mtk_jpeg_s_selection,
552 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs,
553 .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf,
554 .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs,
555 .vidioc_querybuf = v4l2_m2m_ioctl_querybuf,
556 .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
557 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf,
558 .vidioc_streamon = v4l2_m2m_ioctl_streamon,
559 .vidioc_streamoff = v4l2_m2m_ioctl_streamoff,
561 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
564 static int mtk_jpeg_queue_setup(struct vb2_queue *q,
565 unsigned int *num_buffers,
566 unsigned int *num_planes,
567 unsigned int sizes[],
568 struct device *alloc_ctxs[])
570 struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(q);
571 struct mtk_jpeg_q_data *q_data = NULL;
572 struct mtk_jpeg_dev *jpeg = ctx->jpeg;
575 v4l2_dbg(1, debug, &jpeg->v4l2_dev, "(%d) buf_req count=%u\n",
576 q->type, *num_buffers);
578 q_data = mtk_jpeg_get_q_data(ctx, q->type);
583 for (i = 0; i < *num_planes; i++)
584 if (sizes[i] < q_data->sizeimage[i])
589 *num_planes = q_data->fmt->colplanes;
590 for (i = 0; i < q_data->fmt->colplanes; i++) {
591 sizes[i] = q_data->sizeimage[i];
592 v4l2_dbg(1, debug, &jpeg->v4l2_dev, "sizeimage[%d]=%u\n",
599 static int mtk_jpeg_buf_prepare(struct vb2_buffer *vb)
601 struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
602 struct mtk_jpeg_q_data *q_data = NULL;
605 q_data = mtk_jpeg_get_q_data(ctx, vb->vb2_queue->type);
609 for (i = 0; i < q_data->fmt->colplanes; i++)
610 vb2_set_plane_payload(vb, i, q_data->sizeimage[i]);
615 static bool mtk_jpeg_check_resolution_change(struct mtk_jpeg_ctx *ctx,
616 struct mtk_jpeg_dec_param *param)
618 struct mtk_jpeg_dev *jpeg = ctx->jpeg;
619 struct mtk_jpeg_q_data *q_data;
621 q_data = &ctx->out_q;
622 if (q_data->w != param->pic_w || q_data->h != param->pic_h) {
623 v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Picture size change\n");
627 q_data = &ctx->cap_q;
628 if (q_data->fmt != mtk_jpeg_find_format(ctx, param->dst_fourcc,
629 MTK_JPEG_FMT_TYPE_CAPTURE)) {
630 v4l2_dbg(1, debug, &jpeg->v4l2_dev, "format change\n");
636 static void mtk_jpeg_set_queue_data(struct mtk_jpeg_ctx *ctx,
637 struct mtk_jpeg_dec_param *param)
639 struct mtk_jpeg_dev *jpeg = ctx->jpeg;
640 struct mtk_jpeg_q_data *q_data;
643 q_data = &ctx->out_q;
644 q_data->w = param->pic_w;
645 q_data->h = param->pic_h;
647 q_data = &ctx->cap_q;
648 q_data->w = param->dec_w;
649 q_data->h = param->dec_h;
650 q_data->fmt = mtk_jpeg_find_format(ctx,
652 MTK_JPEG_FMT_TYPE_CAPTURE);
654 for (i = 0; i < q_data->fmt->colplanes; i++) {
655 q_data->bytesperline[i] = param->mem_stride[i];
656 q_data->sizeimage[i] = param->comp_size[i];
659 v4l2_dbg(1, debug, &jpeg->v4l2_dev,
660 "set_parse cap:%c%c%c%c pic(%u, %u), buf(%u, %u)\n",
661 (param->dst_fourcc & 0xff),
662 (param->dst_fourcc >> 8 & 0xff),
663 (param->dst_fourcc >> 16 & 0xff),
664 (param->dst_fourcc >> 24 & 0xff),
665 param->pic_w, param->pic_h,
666 param->dec_w, param->dec_h);
669 static void mtk_jpeg_buf_queue(struct vb2_buffer *vb)
671 struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
672 struct mtk_jpeg_dec_param *param;
673 struct mtk_jpeg_dev *jpeg = ctx->jpeg;
674 struct mtk_jpeg_src_buf *jpeg_src_buf;
677 v4l2_dbg(2, debug, &jpeg->v4l2_dev, "(%d) buf_q id=%d, vb=%p\n",
678 vb->vb2_queue->type, vb->index, vb);
680 if (vb->vb2_queue->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
683 jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(vb);
684 param = &jpeg_src_buf->dec_param;
685 memset(param, 0, sizeof(*param));
687 if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
688 v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos\n");
691 header_valid = mtk_jpeg_parse(param, (u8 *)vb2_plane_vaddr(vb, 0),
692 vb2_get_plane_payload(vb, 0));
694 v4l2_err(&jpeg->v4l2_dev, "Header invalid.\n");
695 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
699 if (ctx->state == MTK_JPEG_INIT) {
700 struct vb2_queue *dst_vq = v4l2_m2m_get_vq(
701 ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
703 mtk_jpeg_queue_src_chg_event(ctx);
704 mtk_jpeg_set_queue_data(ctx, param);
705 ctx->state = vb2_is_streaming(dst_vq) ?
706 MTK_JPEG_SOURCE_CHANGE : MTK_JPEG_RUNNING;
709 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, to_vb2_v4l2_buffer(vb));
712 static struct vb2_v4l2_buffer *mtk_jpeg_buf_remove(struct mtk_jpeg_ctx *ctx,
713 enum v4l2_buf_type type)
715 if (V4L2_TYPE_IS_OUTPUT(type))
716 return v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
718 return v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
721 static int mtk_jpeg_start_streaming(struct vb2_queue *q, unsigned int count)
723 struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(q);
724 struct vb2_v4l2_buffer *vb;
727 ret = pm_runtime_get_sync(ctx->jpeg->dev);
733 while ((vb = mtk_jpeg_buf_remove(ctx, q->type)))
734 v4l2_m2m_buf_done(vb, VB2_BUF_STATE_QUEUED);
738 static void mtk_jpeg_stop_streaming(struct vb2_queue *q)
740 struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(q);
741 struct vb2_v4l2_buffer *vb;
744 * STREAMOFF is an acknowledgment for source change event.
745 * Before STREAMOFF, we still have to return the old resolution and
746 * subsampling. Update capture queue when the stream is off.
748 if (ctx->state == MTK_JPEG_SOURCE_CHANGE &&
749 !V4L2_TYPE_IS_OUTPUT(q->type)) {
750 struct mtk_jpeg_src_buf *src_buf;
752 vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
753 src_buf = mtk_jpeg_vb2_to_srcbuf(&vb->vb2_buf);
754 mtk_jpeg_set_queue_data(ctx, &src_buf->dec_param);
755 ctx->state = MTK_JPEG_RUNNING;
756 } else if (V4L2_TYPE_IS_OUTPUT(q->type)) {
757 ctx->state = MTK_JPEG_INIT;
760 while ((vb = mtk_jpeg_buf_remove(ctx, q->type)))
761 v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
763 pm_runtime_put_sync(ctx->jpeg->dev);
766 static const struct vb2_ops mtk_jpeg_qops = {
767 .queue_setup = mtk_jpeg_queue_setup,
768 .buf_prepare = mtk_jpeg_buf_prepare,
769 .buf_queue = mtk_jpeg_buf_queue,
770 .wait_prepare = vb2_ops_wait_prepare,
771 .wait_finish = vb2_ops_wait_finish,
772 .start_streaming = mtk_jpeg_start_streaming,
773 .stop_streaming = mtk_jpeg_stop_streaming,
776 static void mtk_jpeg_set_dec_src(struct mtk_jpeg_ctx *ctx,
777 struct vb2_buffer *src_buf,
778 struct mtk_jpeg_bs *bs)
780 bs->str_addr = vb2_dma_contig_plane_dma_addr(src_buf, 0);
781 bs->end_addr = bs->str_addr +
782 mtk_jpeg_align(vb2_get_plane_payload(src_buf, 0), 16);
783 bs->size = mtk_jpeg_align(vb2_plane_size(src_buf, 0), 128);
786 static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx,
787 struct mtk_jpeg_dec_param *param,
788 struct vb2_buffer *dst_buf,
789 struct mtk_jpeg_fb *fb)
793 if (param->comp_num != dst_buf->num_planes) {
794 dev_err(ctx->jpeg->dev, "plane number mismatch (%u != %u)\n",
795 param->comp_num, dst_buf->num_planes);
799 for (i = 0; i < dst_buf->num_planes; i++) {
800 if (vb2_plane_size(dst_buf, i) < param->comp_size[i]) {
801 dev_err(ctx->jpeg->dev,
802 "buffer size is underflow (%lu < %u)\n",
803 vb2_plane_size(dst_buf, 0),
804 param->comp_size[i]);
807 fb->plane_addr[i] = vb2_dma_contig_plane_dma_addr(dst_buf, i);
813 static void mtk_jpeg_device_run(void *priv)
815 struct mtk_jpeg_ctx *ctx = priv;
816 struct mtk_jpeg_dev *jpeg = ctx->jpeg;
817 struct vb2_v4l2_buffer *src_buf, *dst_buf;
818 enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
820 struct mtk_jpeg_src_buf *jpeg_src_buf;
821 struct mtk_jpeg_bs bs;
822 struct mtk_jpeg_fb fb;
825 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
826 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
827 jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf);
829 if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
830 for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
831 vb2_set_plane_payload(&dst_buf->vb2_buf, i, 0);
832 buf_state = VB2_BUF_STATE_DONE;
836 if (mtk_jpeg_check_resolution_change(ctx, &jpeg_src_buf->dec_param)) {
837 mtk_jpeg_queue_src_chg_event(ctx);
838 ctx->state = MTK_JPEG_SOURCE_CHANGE;
839 v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
843 mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs);
844 if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param, &dst_buf->vb2_buf, &fb))
847 spin_lock_irqsave(&jpeg->hw_lock, flags);
848 mtk_jpeg_dec_reset(jpeg->dec_reg_base);
849 mtk_jpeg_dec_set_config(jpeg->dec_reg_base,
850 &jpeg_src_buf->dec_param, &bs, &fb);
852 mtk_jpeg_dec_start(jpeg->dec_reg_base);
853 spin_unlock_irqrestore(&jpeg->hw_lock, flags);
857 v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
858 v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
859 v4l2_m2m_buf_done(src_buf, buf_state);
860 v4l2_m2m_buf_done(dst_buf, buf_state);
861 v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
864 static int mtk_jpeg_job_ready(void *priv)
866 struct mtk_jpeg_ctx *ctx = priv;
868 return (ctx->state == MTK_JPEG_RUNNING) ? 1 : 0;
871 static void mtk_jpeg_job_abort(void *priv)
875 static const struct v4l2_m2m_ops mtk_jpeg_m2m_ops = {
876 .device_run = mtk_jpeg_device_run,
877 .job_ready = mtk_jpeg_job_ready,
878 .job_abort = mtk_jpeg_job_abort,
881 static int mtk_jpeg_queue_init(void *priv, struct vb2_queue *src_vq,
882 struct vb2_queue *dst_vq)
884 struct mtk_jpeg_ctx *ctx = priv;
887 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
888 src_vq->io_modes = VB2_DMABUF | VB2_MMAP;
889 src_vq->drv_priv = ctx;
890 src_vq->buf_struct_size = sizeof(struct mtk_jpeg_src_buf);
891 src_vq->ops = &mtk_jpeg_qops;
892 src_vq->mem_ops = &vb2_dma_contig_memops;
893 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
894 src_vq->lock = &ctx->jpeg->lock;
895 src_vq->dev = ctx->jpeg->dev;
896 ret = vb2_queue_init(src_vq);
900 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
901 dst_vq->io_modes = VB2_DMABUF | VB2_MMAP;
902 dst_vq->drv_priv = ctx;
903 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
904 dst_vq->ops = &mtk_jpeg_qops;
905 dst_vq->mem_ops = &vb2_dma_contig_memops;
906 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
907 dst_vq->lock = &ctx->jpeg->lock;
908 dst_vq->dev = ctx->jpeg->dev;
909 ret = vb2_queue_init(dst_vq);
914 static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg)
918 ret = mtk_smi_larb_get(jpeg->larb);
920 dev_err(jpeg->dev, "mtk_smi_larb_get larbvdec fail %d\n", ret);
921 clk_prepare_enable(jpeg->clk_jdec_smi);
922 clk_prepare_enable(jpeg->clk_jdec);
925 static void mtk_jpeg_clk_off(struct mtk_jpeg_dev *jpeg)
927 clk_disable_unprepare(jpeg->clk_jdec);
928 clk_disable_unprepare(jpeg->clk_jdec_smi);
929 mtk_smi_larb_put(jpeg->larb);
932 static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
934 struct mtk_jpeg_dev *jpeg = priv;
935 struct mtk_jpeg_ctx *ctx;
936 struct vb2_v4l2_buffer *src_buf, *dst_buf;
937 struct mtk_jpeg_src_buf *jpeg_src_buf;
938 enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
943 dec_ret = mtk_jpeg_dec_get_int_status(jpeg->dec_reg_base);
944 dec_irq_ret = mtk_jpeg_dec_enum_result(dec_ret);
945 ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev);
947 v4l2_err(&jpeg->v4l2_dev, "Context is NULL\n");
951 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
952 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
953 jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf);
955 if (dec_irq_ret >= MTK_JPEG_DEC_RESULT_UNDERFLOW)
956 mtk_jpeg_dec_reset(jpeg->dec_reg_base);
958 if (dec_irq_ret != MTK_JPEG_DEC_RESULT_EOF_DONE) {
959 dev_err(jpeg->dev, "decode failed\n");
963 for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
964 vb2_set_plane_payload(&dst_buf->vb2_buf, i,
965 jpeg_src_buf->dec_param.comp_size[i]);
967 buf_state = VB2_BUF_STATE_DONE;
970 v4l2_m2m_buf_done(src_buf, buf_state);
971 v4l2_m2m_buf_done(dst_buf, buf_state);
972 v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
976 static void mtk_jpeg_set_default_params(struct mtk_jpeg_ctx *ctx)
978 struct mtk_jpeg_q_data *q = &ctx->out_q;
981 ctx->colorspace = V4L2_COLORSPACE_JPEG,
982 ctx->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
983 ctx->quantization = V4L2_QUANTIZATION_DEFAULT;
984 ctx->xfer_func = V4L2_XFER_FUNC_DEFAULT;
986 q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
987 MTK_JPEG_FMT_TYPE_OUTPUT);
988 q->w = MTK_JPEG_MIN_WIDTH;
989 q->h = MTK_JPEG_MIN_HEIGHT;
990 q->bytesperline[0] = 0;
991 q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
994 q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUV420M,
995 MTK_JPEG_FMT_TYPE_CAPTURE);
996 q->w = MTK_JPEG_MIN_WIDTH;
997 q->h = MTK_JPEG_MIN_HEIGHT;
999 for (i = 0; i < q->fmt->colplanes; i++) {
1000 u32 stride = q->w * q->fmt->h_sample[i] / 4;
1001 u32 h = q->h * q->fmt->v_sample[i] / 4;
1003 q->bytesperline[i] = stride;
1004 q->sizeimage[i] = stride * h;
1008 static int mtk_jpeg_open(struct file *file)
1010 struct mtk_jpeg_dev *jpeg = video_drvdata(file);
1011 struct video_device *vfd = video_devdata(file);
1012 struct mtk_jpeg_ctx *ctx;
1015 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
1019 if (mutex_lock_interruptible(&jpeg->lock)) {
1024 v4l2_fh_init(&ctx->fh, vfd);
1025 file->private_data = &ctx->fh;
1026 v4l2_fh_add(&ctx->fh);
1029 ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(jpeg->m2m_dev, ctx,
1030 mtk_jpeg_queue_init);
1031 if (IS_ERR(ctx->fh.m2m_ctx)) {
1032 ret = PTR_ERR(ctx->fh.m2m_ctx);
1036 mtk_jpeg_set_default_params(ctx);
1037 mutex_unlock(&jpeg->lock);
1041 v4l2_fh_del(&ctx->fh);
1042 v4l2_fh_exit(&ctx->fh);
1043 mutex_unlock(&jpeg->lock);
1049 static int mtk_jpeg_release(struct file *file)
1051 struct mtk_jpeg_dev *jpeg = video_drvdata(file);
1052 struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(file->private_data);
1054 mutex_lock(&jpeg->lock);
1055 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
1056 v4l2_fh_del(&ctx->fh);
1057 v4l2_fh_exit(&ctx->fh);
1059 mutex_unlock(&jpeg->lock);
1063 static const struct v4l2_file_operations mtk_jpeg_fops = {
1064 .owner = THIS_MODULE,
1065 .open = mtk_jpeg_open,
1066 .release = mtk_jpeg_release,
1067 .poll = v4l2_m2m_fop_poll,
1068 .unlocked_ioctl = video_ioctl2,
1069 .mmap = v4l2_m2m_fop_mmap,
1072 static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
1074 struct device_node *node;
1075 struct platform_device *pdev;
1077 node = of_parse_phandle(jpeg->dev->of_node, "mediatek,larb", 0);
1080 pdev = of_find_device_by_node(node);
1081 if (WARN_ON(!pdev)) {
1087 jpeg->larb = &pdev->dev;
1089 jpeg->clk_jdec = devm_clk_get(jpeg->dev, "jpgdec");
1090 if (IS_ERR(jpeg->clk_jdec))
1093 jpeg->clk_jdec_smi = devm_clk_get(jpeg->dev, "jpgdec-smi");
1094 if (IS_ERR(jpeg->clk_jdec_smi))
1100 static int mtk_jpeg_probe(struct platform_device *pdev)
1102 struct mtk_jpeg_dev *jpeg;
1103 struct resource *res;
1107 jpeg = devm_kzalloc(&pdev->dev, sizeof(*jpeg), GFP_KERNEL);
1111 mutex_init(&jpeg->lock);
1112 spin_lock_init(&jpeg->hw_lock);
1113 jpeg->dev = &pdev->dev;
1115 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1116 jpeg->dec_reg_base = devm_ioremap_resource(&pdev->dev, res);
1117 if (IS_ERR(jpeg->dec_reg_base)) {
1118 ret = PTR_ERR(jpeg->dec_reg_base);
1122 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1123 dec_irq = platform_get_irq(pdev, 0);
1124 if (!res || dec_irq < 0) {
1125 dev_err(&pdev->dev, "Failed to get dec_irq %d.\n", dec_irq);
1130 ret = devm_request_irq(&pdev->dev, dec_irq, mtk_jpeg_dec_irq, 0,
1133 dev_err(&pdev->dev, "Failed to request dec_irq %d (%d)\n",
1139 ret = mtk_jpeg_clk_init(jpeg);
1141 dev_err(&pdev->dev, "Failed to init clk, err %d\n", ret);
1145 ret = v4l2_device_register(&pdev->dev, &jpeg->v4l2_dev);
1147 dev_err(&pdev->dev, "Failed to register v4l2 device\n");
1149 goto err_dev_register;
1152 jpeg->m2m_dev = v4l2_m2m_init(&mtk_jpeg_m2m_ops);
1153 if (IS_ERR(jpeg->m2m_dev)) {
1154 v4l2_err(&jpeg->v4l2_dev, "Failed to init mem2mem device\n");
1155 ret = PTR_ERR(jpeg->m2m_dev);
1159 jpeg->dec_vdev = video_device_alloc();
1160 if (!jpeg->dec_vdev) {
1162 goto err_dec_vdev_alloc;
1164 snprintf(jpeg->dec_vdev->name, sizeof(jpeg->dec_vdev->name),
1165 "%s-dec", MTK_JPEG_NAME);
1166 jpeg->dec_vdev->fops = &mtk_jpeg_fops;
1167 jpeg->dec_vdev->ioctl_ops = &mtk_jpeg_ioctl_ops;
1168 jpeg->dec_vdev->minor = -1;
1169 jpeg->dec_vdev->release = video_device_release;
1170 jpeg->dec_vdev->lock = &jpeg->lock;
1171 jpeg->dec_vdev->v4l2_dev = &jpeg->v4l2_dev;
1172 jpeg->dec_vdev->vfl_dir = VFL_DIR_M2M;
1173 jpeg->dec_vdev->device_caps = V4L2_CAP_STREAMING |
1174 V4L2_CAP_VIDEO_M2M_MPLANE;
1176 ret = video_register_device(jpeg->dec_vdev, VFL_TYPE_GRABBER, 3);
1178 v4l2_err(&jpeg->v4l2_dev, "Failed to register video device\n");
1179 goto err_dec_vdev_register;
1182 video_set_drvdata(jpeg->dec_vdev, jpeg);
1183 v4l2_info(&jpeg->v4l2_dev,
1184 "decoder device registered as /dev/video%d (%d,%d)\n",
1185 jpeg->dec_vdev->num, VIDEO_MAJOR, jpeg->dec_vdev->minor);
1187 platform_set_drvdata(pdev, jpeg);
1189 pm_runtime_enable(&pdev->dev);
1193 err_dec_vdev_register:
1194 video_device_release(jpeg->dec_vdev);
1197 v4l2_m2m_release(jpeg->m2m_dev);
1200 v4l2_device_unregister(&jpeg->v4l2_dev);
1211 static int mtk_jpeg_remove(struct platform_device *pdev)
1213 struct mtk_jpeg_dev *jpeg = platform_get_drvdata(pdev);
1215 pm_runtime_disable(&pdev->dev);
1216 video_unregister_device(jpeg->dec_vdev);
1217 video_device_release(jpeg->dec_vdev);
1218 v4l2_m2m_release(jpeg->m2m_dev);
1219 v4l2_device_unregister(&jpeg->v4l2_dev);
1224 static __maybe_unused int mtk_jpeg_pm_suspend(struct device *dev)
1226 struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev);
1228 mtk_jpeg_dec_reset(jpeg->dec_reg_base);
1229 mtk_jpeg_clk_off(jpeg);
1234 static __maybe_unused int mtk_jpeg_pm_resume(struct device *dev)
1236 struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev);
1238 mtk_jpeg_clk_on(jpeg);
1239 mtk_jpeg_dec_reset(jpeg->dec_reg_base);
1244 static __maybe_unused int mtk_jpeg_suspend(struct device *dev)
1248 if (pm_runtime_suspended(dev))
1251 ret = mtk_jpeg_pm_suspend(dev);
1255 static __maybe_unused int mtk_jpeg_resume(struct device *dev)
1259 if (pm_runtime_suspended(dev))
1262 ret = mtk_jpeg_pm_resume(dev);
1267 static const struct dev_pm_ops mtk_jpeg_pm_ops = {
1268 SET_SYSTEM_SLEEP_PM_OPS(mtk_jpeg_suspend, mtk_jpeg_resume)
1269 SET_RUNTIME_PM_OPS(mtk_jpeg_pm_suspend, mtk_jpeg_pm_resume, NULL)
1272 static const struct of_device_id mtk_jpeg_match[] = {
1274 .compatible = "mediatek,mt8173-jpgdec",
1278 .compatible = "mediatek,mt2701-jpgdec",
1284 MODULE_DEVICE_TABLE(of, mtk_jpeg_match);
1286 static struct platform_driver mtk_jpeg_driver = {
1287 .probe = mtk_jpeg_probe,
1288 .remove = mtk_jpeg_remove,
1290 .name = MTK_JPEG_NAME,
1291 .of_match_table = mtk_jpeg_match,
1292 .pm = &mtk_jpeg_pm_ops,
1296 module_platform_driver(mtk_jpeg_driver);
1298 MODULE_DESCRIPTION("MediaTek JPEG codec driver");
1299 MODULE_LICENSE("GPL v2");