1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2016 MediaTek Inc.
4 * Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
5 * Rick Chang <rick.chang@mediatek.com>
8 #ifndef _MTK_JPEG_CORE_H
9 #define _MTK_JPEG_CORE_H
11 #include <linux/interrupt.h>
12 #include <media/v4l2-ctrls.h>
13 #include <media/v4l2-device.h>
14 #include <media/v4l2-fh.h>
16 #define MTK_JPEG_NAME "mtk-jpeg"
18 #define MTK_JPEG_FMT_FLAG_DEC_OUTPUT BIT(0)
19 #define MTK_JPEG_FMT_FLAG_DEC_CAPTURE BIT(1)
21 #define MTK_JPEG_FMT_TYPE_OUTPUT 1
22 #define MTK_JPEG_FMT_TYPE_CAPTURE 2
24 #define MTK_JPEG_MIN_WIDTH 32
25 #define MTK_JPEG_MIN_HEIGHT 32
26 #define MTK_JPEG_MAX_WIDTH 8192
27 #define MTK_JPEG_MAX_HEIGHT 8192
29 #define MTK_JPEG_DEFAULT_SIZEIMAGE (1 * 1024 * 1024)
31 enum mtk_jpeg_ctx_state {
34 MTK_JPEG_SOURCE_CHANGE,
38 * struct mt_jpeg - JPEG IP abstraction
39 * @lock: the mutex protecting this structure
40 * @hw_lock: spinlock protecting the hw device resource
41 * @workqueue: decode work queue
43 * @v4l2_dev: v4l2 device for mem2mem mode
44 * @m2m_dev: v4l2 mem2mem device data
45 * @alloc_ctx: videobuf2 memory allocator's context
46 * @dec_vdev: video device node for decoder mem2mem mode
47 * @dec_reg_base: JPEG registers mapping
48 * @clk_jdec: JPEG hw working clock
49 * @clk_jdec_smi: JPEG SMI bus clock
55 struct workqueue_struct *workqueue;
57 struct v4l2_device v4l2_dev;
58 struct v4l2_m2m_dev *m2m_dev;
60 struct video_device *dec_vdev;
61 void __iomem *dec_reg_base;
63 struct clk *clk_jdec_smi;
68 * struct jpeg_fmt - driver's internal color format data
69 * @fourcc: the fourcc code, 0 if not applicable
70 * @h_sample: horizontal sample count of plane in 4 * 4 pixel image
71 * @v_sample: vertical sample count of plane in 4 * 4 pixel image
72 * @colplanes: number of color planes (1 for packed formats)
73 * @h_align: horizontal alignment order (align to 2^h_align)
74 * @v_align: vertical alignment order (align to 2^v_align)
75 * @flags: flags describing format applicability
79 int h_sample[VIDEO_MAX_PLANES];
80 int v_sample[VIDEO_MAX_PLANES];
88 * mtk_jpeg_q_data - parameters of one queue
89 * @fmt: driver-specific format of this queue
92 * @bytesperline: distance in bytes between the leftmost pixels in two adjacent
94 * @sizeimage: image buffer size in bytes
96 struct mtk_jpeg_q_data {
97 struct mtk_jpeg_fmt *fmt;
100 u32 bytesperline[VIDEO_MAX_PLANES];
101 u32 sizeimage[VIDEO_MAX_PLANES];
105 * mtk_jpeg_ctx - the device context data
106 * @jpeg: JPEG IP device for this context
107 * @out_q: source (output) queue information
108 * @cap_q: destination (capture) queue queue information
109 * @fh: V4L2 file handle
110 * @dec_param parameters for HW decoding
111 * @state: state of the context
112 * @header_valid: set if header has been parsed and valid
113 * @colorspace: enum v4l2_colorspace; supplemental to pixelformat
114 * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
115 * @quantization: enum v4l2_quantization, colorspace quantization
116 * @xfer_func: enum v4l2_xfer_func, colorspace transfer function
118 struct mtk_jpeg_ctx {
119 struct mtk_jpeg_dev *jpeg;
120 struct mtk_jpeg_q_data out_q;
121 struct mtk_jpeg_q_data cap_q;
123 enum mtk_jpeg_ctx_state state;
125 enum v4l2_colorspace colorspace;
126 enum v4l2_ycbcr_encoding ycbcr_enc;
127 enum v4l2_quantization quantization;
128 enum v4l2_xfer_func xfer_func;
131 #endif /* _MTK_JPEG_CORE_H */