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 #ifndef _MTK_JPEG_CORE_H
17 #define _MTK_JPEG_CORE_H
19 #include <linux/interrupt.h>
20 #include <media/v4l2-ctrls.h>
21 #include <media/v4l2-device.h>
22 #include <media/v4l2-fh.h>
24 #define MTK_JPEG_NAME "mtk-jpeg"
26 #define MTK_JPEG_FMT_FLAG_DEC_OUTPUT BIT(0)
27 #define MTK_JPEG_FMT_FLAG_DEC_CAPTURE BIT(1)
29 #define MTK_JPEG_FMT_TYPE_OUTPUT 1
30 #define MTK_JPEG_FMT_TYPE_CAPTURE 2
32 #define MTK_JPEG_MIN_WIDTH 32
33 #define MTK_JPEG_MIN_HEIGHT 32
34 #define MTK_JPEG_MAX_WIDTH 8192
35 #define MTK_JPEG_MAX_HEIGHT 8192
37 #define MTK_JPEG_DEFAULT_SIZEIMAGE (1 * 1024 * 1024)
39 enum mtk_jpeg_ctx_state {
42 MTK_JPEG_SOURCE_CHANGE,
46 * struct mt_jpeg - JPEG IP abstraction
47 * @lock: the mutex protecting this structure
48 * @hw_lock: spinlock protecting the hw device resource
49 * @workqueue: decode work queue
51 * @v4l2_dev: v4l2 device for mem2mem mode
52 * @m2m_dev: v4l2 mem2mem device data
53 * @alloc_ctx: videobuf2 memory allocator's context
54 * @dec_vdev: video device node for decoder mem2mem mode
55 * @dec_reg_base: JPEG registers mapping
56 * @clk_jdec: JPEG hw working clock
57 * @clk_jdec_smi: JPEG SMI bus clock
63 struct workqueue_struct *workqueue;
65 struct v4l2_device v4l2_dev;
66 struct v4l2_m2m_dev *m2m_dev;
68 struct video_device *dec_vdev;
69 void __iomem *dec_reg_base;
71 struct clk *clk_jdec_smi;
76 * struct jpeg_fmt - driver's internal color format data
77 * @fourcc: the fourcc code, 0 if not applicable
78 * @h_sample: horizontal sample count of plane in 4 * 4 pixel image
79 * @v_sample: vertical sample count of plane in 4 * 4 pixel image
80 * @colplanes: number of color planes (1 for packed formats)
81 * @h_align: horizontal alignment order (align to 2^h_align)
82 * @v_align: vertical alignment order (align to 2^v_align)
83 * @flags: flags describing format applicability
87 int h_sample[VIDEO_MAX_PLANES];
88 int v_sample[VIDEO_MAX_PLANES];
96 * mtk_jpeg_q_data - parameters of one queue
97 * @fmt: driver-specific format of this queue
100 * @bytesperline: distance in bytes between the leftmost pixels in two adjacent
102 * @sizeimage: image buffer size in bytes
104 struct mtk_jpeg_q_data {
105 struct mtk_jpeg_fmt *fmt;
108 u32 bytesperline[VIDEO_MAX_PLANES];
109 u32 sizeimage[VIDEO_MAX_PLANES];
113 * mtk_jpeg_ctx - the device context data
114 * @jpeg: JPEG IP device for this context
115 * @out_q: source (output) queue information
116 * @cap_q: destination (capture) queue queue information
117 * @fh: V4L2 file handle
118 * @dec_param parameters for HW decoding
119 * @state: state of the context
120 * @header_valid: set if header has been parsed and valid
121 * @colorspace: enum v4l2_colorspace; supplemental to pixelformat
122 * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
123 * @quantization: enum v4l2_quantization, colorspace quantization
124 * @xfer_func: enum v4l2_xfer_func, colorspace transfer function
126 struct mtk_jpeg_ctx {
127 struct mtk_jpeg_dev *jpeg;
128 struct mtk_jpeg_q_data out_q;
129 struct mtk_jpeg_q_data cap_q;
131 enum mtk_jpeg_ctx_state state;
133 enum v4l2_colorspace colorspace;
134 enum v4l2_ycbcr_encoding ycbcr_enc;
135 enum v4l2_quantization quantization;
136 enum v4l2_xfer_func xfer_func;
139 #endif /* _MTK_JPEG_CORE_H */