1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * i.MX8QXP/i.MX8QM JPEG encoder/decoder v4l2 driver 4 * 5 * Copyright 2018-2019 NXP 6 */ 7 8#include <media/v4l2-ctrls.h> 9#include <media/v4l2-device.h> 10#include <media/v4l2-fh.h> 11 12#ifndef _MXC_JPEG_CORE_H 13#define _MXC_JPEG_CORE_H 14 15#define MXC_JPEG_NAME "mxc-jpeg" 16#define MXC_JPEG_FMT_TYPE_ENC 0 17#define MXC_JPEG_FMT_TYPE_RAW 1 18#define MXC_JPEG_DEFAULT_WIDTH 1280 19#define MXC_JPEG_DEFAULT_HEIGHT 720 20#define MXC_JPEG_DEFAULT_PFMT V4L2_PIX_FMT_RGB24 21#define MXC_JPEG_MIN_WIDTH 64 22#define MXC_JPEG_MIN_HEIGHT 64 23#define MXC_JPEG_MAX_WIDTH 0x2000 24#define MXC_JPEG_MAX_HEIGHT 0x2000 25#define MXC_JPEG_MAX_CFG_STREAM 0x1000 26#define MXC_JPEG_H_ALIGN 3 27#define MXC_JPEG_W_ALIGN 3 28#define MXC_JPEG_MAX_SIZEIMAGE 0xFFFFFC00 29#define MXC_JPEG_MAX_PLANES 2 30 31enum mxc_jpeg_enc_state { 32 MXC_JPEG_ENCODING = 0, /* jpeg encode phase */ 33 MXC_JPEG_ENC_CONF = 1, /* jpeg encoder config phase */ 34}; 35 36enum mxc_jpeg_mode { 37 MXC_JPEG_DECODE = 0, /* jpeg decode mode */ 38 MXC_JPEG_ENCODE = 1, /* jpeg encode mode */ 39}; 40 41/** 42 * struct mxc_jpeg_fmt - driver's internal color format data 43 * @name: format description 44 * @fourcc: fourcc code, 0 if not applicable 45 * @subsampling: subsampling of jpeg components 46 * @nc: number of color components 47 * @depth: number of bits per pixel 48 * @colplanes: number of color planes (1 for packed formats) 49 * @h_align: horizontal alignment order (align to 2^h_align) 50 * @v_align: vertical alignment order (align to 2^v_align) 51 * @flags: flags describing format applicability 52 */ 53struct mxc_jpeg_fmt { 54 const char *name; 55 u32 fourcc; 56 enum v4l2_jpeg_chroma_subsampling subsampling; 57 int nc; 58 int depth; 59 int colplanes; 60 int h_align; 61 int v_align; 62 u32 flags; 63}; 64 65struct mxc_jpeg_desc { 66 u32 next_descpt_ptr; 67 u32 buf_base0; 68 u32 buf_base1; 69 u32 line_pitch; 70 u32 stm_bufbase; 71 u32 stm_bufsize; 72 u32 imgsize; 73 u32 stm_ctrl; 74} __packed; 75 76struct mxc_jpeg_q_data { 77 const struct mxc_jpeg_fmt *fmt; 78 u32 sizeimage[MXC_JPEG_MAX_PLANES]; 79 u32 bytesperline[MXC_JPEG_MAX_PLANES]; 80 int w; 81 int w_adjusted; 82 int h; 83 int h_adjusted; 84 unsigned int sequence; 85}; 86 87struct mxc_jpeg_ctx { 88 struct mxc_jpeg_dev *mxc_jpeg; 89 struct mxc_jpeg_q_data out_q; 90 struct mxc_jpeg_q_data cap_q; 91 struct v4l2_fh fh; 92 enum mxc_jpeg_enc_state enc_state; 93 unsigned int stopping; 94 unsigned int slot; 95}; 96 97struct mxc_jpeg_slot_data { 98 bool used; 99 struct mxc_jpeg_desc *desc; // enc/dec descriptor 100 struct mxc_jpeg_desc *cfg_desc; // configuration descriptor 101 void *cfg_stream_vaddr; // configuration bitstream virtual address 102 unsigned int cfg_stream_size; 103 dma_addr_t desc_handle; 104 dma_addr_t cfg_desc_handle; // configuration descriptor dma address 105 dma_addr_t cfg_stream_handle; // configuration bitstream dma address 106}; 107 108struct mxc_jpeg_dev { 109 spinlock_t hw_lock; /* hardware access lock */ 110 unsigned int mode; 111 struct mutex lock; /* v4l2 ioctls serialization */ 112 struct platform_device *pdev; 113 struct device *dev; 114 void __iomem *base_reg; 115 struct v4l2_device v4l2_dev; 116 struct v4l2_m2m_dev *m2m_dev; 117 struct video_device *dec_vdev; 118 struct mxc_jpeg_slot_data slot_data[MXC_MAX_SLOTS]; 119 int num_domains; 120 struct device **pd_dev; 121 struct device_link **pd_link; 122}; 123 124/** 125 * struct mxc_jpeg_sof_comp - JPEG Start Of Frame component fields 126 * @id: component id 127 * @v: vertical sampling 128 * @h: horizontal sampling 129 * @quantization_table_no: id of quantization table 130 */ 131struct mxc_jpeg_sof_comp { 132 u8 id; 133 u8 v :4; 134 u8 h :4; 135 u8 quantization_table_no; 136} __packed; 137 138#define MXC_JPEG_MAX_COMPONENTS 4 139/** 140 * struct mxc_jpeg_sof - JPEG Start Of Frame marker fields 141 * @length: Start of Frame length 142 * @precision: precision (bits per pixel per color component) 143 * @height: image height 144 * @width: image width 145 * @components_no: number of color components 146 * @comp: component fields for each color component 147 */ 148struct mxc_jpeg_sof { 149 u16 length; 150 u8 precision; 151 u16 height, width; 152 u8 components_no; 153 struct mxc_jpeg_sof_comp comp[MXC_JPEG_MAX_COMPONENTS]; 154} __packed; 155 156/** 157 * struct mxc_jpeg_sos_comp - JPEG Start Of Scan component fields 158 * @id: component id 159 * @huffman_table_no: id of the Huffman table 160 */ 161struct mxc_jpeg_sos_comp { 162 u8 id; /*component id*/ 163 u8 huffman_table_no; 164} __packed; 165 166/** 167 * struct mxc_jpeg_sos - JPEG Start Of Scan marker fields 168 * @length: Start of Frame length 169 * @components_no: number of color components 170 * @comp: SOS component fields for each color component 171 * @ignorable_bytes: ignorable bytes 172 */ 173struct mxc_jpeg_sos { 174 u16 length; 175 u8 components_no; 176 struct mxc_jpeg_sos_comp comp[MXC_JPEG_MAX_COMPONENTS]; 177 u8 ignorable_bytes[3]; 178} __packed; 179 180#endif 181