1/* 2 * Copyright (c) 2016 MediaTek Inc. 3 * Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com> 4 * Rick Chang <rick.chang@mediatek.com> 5 * 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. 9 * 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. 14 */ 15 16#ifndef _MTK_JPEG_CORE_H 17#define _MTK_JPEG_CORE_H 18 19#include <linux/interrupt.h> 20#include <media/v4l2-ctrls.h> 21#include <media/v4l2-device.h> 22#include <media/v4l2-fh.h> 23 24#define MTK_JPEG_NAME "mtk-jpeg" 25 26#define MTK_JPEG_FMT_FLAG_DEC_OUTPUT BIT(0) 27#define MTK_JPEG_FMT_FLAG_DEC_CAPTURE BIT(1) 28 29#define MTK_JPEG_FMT_TYPE_OUTPUT 1 30#define MTK_JPEG_FMT_TYPE_CAPTURE 2 31 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 36 37#define MTK_JPEG_DEFAULT_SIZEIMAGE (1 * 1024 * 1024) 38 39enum mtk_jpeg_ctx_state { 40 MTK_JPEG_INIT = 0, 41 MTK_JPEG_RUNNING, 42 MTK_JPEG_SOURCE_CHANGE, 43}; 44 45/** 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 50 * @dev: JPEG device 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 58 * @larb: SMI device 59 */ 60struct mtk_jpeg_dev { 61 struct mutex lock; 62 spinlock_t hw_lock; 63 struct workqueue_struct *workqueue; 64 struct device *dev; 65 struct v4l2_device v4l2_dev; 66 struct v4l2_m2m_dev *m2m_dev; 67 void *alloc_ctx; 68 struct video_device *dec_vdev; 69 void __iomem *dec_reg_base; 70 struct clk *clk_jdec; 71 struct clk *clk_jdec_smi; 72 struct device *larb; 73}; 74 75/** 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 84 */ 85struct mtk_jpeg_fmt { 86 u32 fourcc; 87 int h_sample[VIDEO_MAX_PLANES]; 88 int v_sample[VIDEO_MAX_PLANES]; 89 int colplanes; 90 int h_align; 91 int v_align; 92 u32 flags; 93}; 94 95/** 96 * mtk_jpeg_q_data - parameters of one queue 97 * @fmt: driver-specific format of this queue 98 * @w: image width 99 * @h: image height 100 * @bytesperline: distance in bytes between the leftmost pixels in two adjacent 101 * lines 102 * @sizeimage: image buffer size in bytes 103 */ 104struct mtk_jpeg_q_data { 105 struct mtk_jpeg_fmt *fmt; 106 u32 w; 107 u32 h; 108 u32 bytesperline[VIDEO_MAX_PLANES]; 109 u32 sizeimage[VIDEO_MAX_PLANES]; 110}; 111 112/** 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 125 */ 126struct 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; 130 struct v4l2_fh fh; 131 enum mtk_jpeg_ctx_state state; 132 133 enum v4l2_colorspace colorspace; 134 enum v4l2_ycbcr_encoding ycbcr_enc; 135 enum v4l2_quantization quantization; 136 enum v4l2_xfer_func xfer_func; 137}; 138 139#endif /* _MTK_JPEG_CORE_H */ 140