1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2016 MediaTek Inc. 4 * Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com> 5 * Rick Chang <rick.chang@mediatek.com> 6 */ 7 8 #ifndef _MTK_JPEG_CORE_H 9 #define _MTK_JPEG_CORE_H 10 11 #include <linux/interrupt.h> 12 #include <media/v4l2-ctrls.h> 13 #include <media/v4l2-device.h> 14 #include <media/v4l2-fh.h> 15 16 #define MTK_JPEG_NAME "mtk-jpeg" 17 18 #define MTK_JPEG_FMT_FLAG_DEC_OUTPUT BIT(0) 19 #define MTK_JPEG_FMT_FLAG_DEC_CAPTURE BIT(1) 20 21 #define MTK_JPEG_FMT_TYPE_OUTPUT 1 22 #define MTK_JPEG_FMT_TYPE_CAPTURE 2 23 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 28 29 #define MTK_JPEG_DEFAULT_SIZEIMAGE (1 * 1024 * 1024) 30 31 enum mtk_jpeg_ctx_state { 32 MTK_JPEG_INIT = 0, 33 MTK_JPEG_RUNNING, 34 MTK_JPEG_SOURCE_CHANGE, 35 }; 36 37 /** 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 42 * @dev: JPEG device 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 50 * @larb: SMI device 51 */ 52 struct mtk_jpeg_dev { 53 struct mutex lock; 54 spinlock_t hw_lock; 55 struct workqueue_struct *workqueue; 56 struct device *dev; 57 struct v4l2_device v4l2_dev; 58 struct v4l2_m2m_dev *m2m_dev; 59 void *alloc_ctx; 60 struct video_device *dec_vdev; 61 void __iomem *dec_reg_base; 62 struct clk *clk_jdec; 63 struct clk *clk_jdec_smi; 64 struct device *larb; 65 }; 66 67 /** 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 76 */ 77 struct mtk_jpeg_fmt { 78 u32 fourcc; 79 int h_sample[VIDEO_MAX_PLANES]; 80 int v_sample[VIDEO_MAX_PLANES]; 81 int colplanes; 82 int h_align; 83 int v_align; 84 u32 flags; 85 }; 86 87 /** 88 * mtk_jpeg_q_data - parameters of one queue 89 * @fmt: driver-specific format of this queue 90 * @w: image width 91 * @h: image height 92 * @bytesperline: distance in bytes between the leftmost pixels in two adjacent 93 * lines 94 * @sizeimage: image buffer size in bytes 95 */ 96 struct mtk_jpeg_q_data { 97 struct mtk_jpeg_fmt *fmt; 98 u32 w; 99 u32 h; 100 u32 bytesperline[VIDEO_MAX_PLANES]; 101 u32 sizeimage[VIDEO_MAX_PLANES]; 102 }; 103 104 /** 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 117 */ 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; 122 struct v4l2_fh fh; 123 enum mtk_jpeg_ctx_state state; 124 125 enum v4l2_colorspace colorspace; 126 enum v4l2_ycbcr_encoding ycbcr_enc; 127 enum v4l2_quantization quantization; 128 enum v4l2_xfer_func xfer_func; 129 }; 130 131 #endif /* _MTK_JPEG_CORE_H */