1 /* SPDX-License-Identifier: GPL-2.0 */
3 * i.MX8QXP/i.MX8QM JPEG encoder/decoder v4l2 driver
5 * Copyright 2018-2019 NXP
8 #include <media/v4l2-ctrls.h>
9 #include <media/v4l2-device.h>
10 #include <media/v4l2-fh.h>
12 #ifndef _MXC_JPEG_CORE_H
13 #define _MXC_JPEG_CORE_H
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_BGR24
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_LINE 0x8000
26 #define MXC_JPEG_MAX_CFG_STREAM 0x1000
27 #define MXC_JPEG_H_ALIGN 3
28 #define MXC_JPEG_W_ALIGN 3
29 #define MXC_JPEG_MAX_SIZEIMAGE 0xFFFFFC00
30 #define MXC_JPEG_MAX_PLANES 2
32 enum mxc_jpeg_enc_state {
33 MXC_JPEG_ENCODING = 0, /* jpeg encode phase */
34 MXC_JPEG_ENC_CONF = 1, /* jpeg encoder config phase */
38 MXC_JPEG_DECODE = 0, /* jpeg decode mode */
39 MXC_JPEG_ENCODE = 1, /* jpeg encode mode */
43 * struct mxc_jpeg_fmt - driver's internal color format data
44 * @name: format description
45 * @fourcc: fourcc code, 0 if not applicable
46 * @subsampling: subsampling of jpeg components
47 * @nc: number of color components
48 * @depth: number of bits per pixel
49 * @mem_planes: number of memory planes (1 for packed formats)
50 * @comp_planes:number of component planes, which includes the alpha plane (1 to 4).
51 * @h_align: horizontal alignment order (align to 2^h_align)
52 * @v_align: vertical alignment order (align to 2^v_align)
53 * @flags: flags describing format applicability
54 * @precision: jpeg sample precision
55 * @is_rgb: is an RGB pixel format
60 enum v4l2_jpeg_chroma_subsampling subsampling;
72 struct mxc_jpeg_desc {
83 struct mxc_jpeg_q_data {
84 const struct mxc_jpeg_fmt *fmt;
85 u32 sizeimage[MXC_JPEG_MAX_PLANES];
86 u32 bytesperline[MXC_JPEG_MAX_PLANES];
91 unsigned int sequence;
92 struct v4l2_rect crop;
96 struct mxc_jpeg_dev *mxc_jpeg;
97 struct mxc_jpeg_q_data out_q;
98 struct mxc_jpeg_q_data cap_q;
100 enum mxc_jpeg_enc_state enc_state;
102 unsigned int source_change;
103 bool need_initial_source_change_evt;
105 struct v4l2_ctrl_handler ctrl_handler;
107 struct delayed_work task_timer;
110 struct mxc_jpeg_slot_data {
113 struct mxc_jpeg_desc *desc; // enc/dec descriptor
114 struct mxc_jpeg_desc *cfg_desc; // configuration descriptor
115 void *cfg_stream_vaddr; // configuration bitstream virtual address
116 unsigned int cfg_stream_size;
117 dma_addr_t desc_handle;
118 dma_addr_t cfg_desc_handle; // configuration descriptor dma address
119 dma_addr_t cfg_stream_handle; // configuration bitstream dma address
122 struct mxc_jpeg_dev {
123 spinlock_t hw_lock; /* hardware access lock */
125 struct mutex lock; /* v4l2 ioctls serialization */
126 struct clk_bulk_data *clks;
128 struct platform_device *pdev;
130 void __iomem *base_reg;
131 struct v4l2_device v4l2_dev;
132 struct v4l2_m2m_dev *m2m_dev;
133 struct video_device *dec_vdev;
134 struct mxc_jpeg_slot_data slot_data;
136 struct device **pd_dev;
137 struct device_link **pd_link;
141 * struct mxc_jpeg_sof_comp - JPEG Start Of Frame component fields
143 * @v: vertical sampling
144 * @h: horizontal sampling
145 * @quantization_table_no: id of quantization table
147 struct mxc_jpeg_sof_comp {
151 u8 quantization_table_no;
154 #define MXC_JPEG_MAX_COMPONENTS 4
156 * struct mxc_jpeg_sof - JPEG Start Of Frame marker fields
157 * @length: Start of Frame length
158 * @precision: precision (bits per pixel per color component)
159 * @height: image height
160 * @width: image width
161 * @components_no: number of color components
162 * @comp: component fields for each color component
164 struct mxc_jpeg_sof {
169 struct mxc_jpeg_sof_comp comp[MXC_JPEG_MAX_COMPONENTS];
173 * struct mxc_jpeg_sos_comp - JPEG Start Of Scan component fields
175 * @huffman_table_no: id of the Huffman table
177 struct mxc_jpeg_sos_comp {
178 u8 id; /*component id*/
183 * struct mxc_jpeg_sos - JPEG Start Of Scan marker fields
184 * @length: Start of Frame length
185 * @components_no: number of color components
186 * @comp: SOS component fields for each color component
187 * @ignorable_bytes: ignorable bytes
189 struct mxc_jpeg_sos {
192 struct mxc_jpeg_sos_comp comp[MXC_JPEG_MAX_COMPONENTS];
193 u8 ignorable_bytes[3];