File Index
Files and directories
Sign in
FILE

mxc-jpeg.h

File preview with syntax highlighting.

linux-6.19.14/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h C
  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_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
 31#define MXC_JPEG_PATTERN_WIDTH		128
 32#define MXC_JPEG_PATTERN_HEIGHT		64
 33#define MXC_JPEG_ADDR_ALIGNMENT		16
 34
 35enum mxc_jpeg_enc_state {
 36	MXC_JPEG_ENCODING	= 0, /* jpeg encode phase */
 37	MXC_JPEG_ENC_CONF	= 1, /* jpeg encoder config phase */
 38};
 39
 40enum mxc_jpeg_mode {
 41	MXC_JPEG_DECODE	= 0, /* jpeg decode mode */
 42	MXC_JPEG_ENCODE	= 1, /* jpeg encode mode */
 43};
 44
 45/**
 46 * struct mxc_jpeg_fmt - driver's internal color format data
 47 * @name:	format description
 48 * @fourcc:	fourcc code, 0 if not applicable
 49 * @subsampling: subsampling of jpeg components
 50 * @nc:		number of color components
 51 * @depth:	number of bits per pixel
 52 * @mem_planes:	number of memory planes (1 for packed formats)
 53 * @comp_planes:number of component planes, which includes the alpha plane (1 to 4).
 54 * @h_align:	horizontal alignment order (align to 2^h_align)
 55 * @v_align:	vertical alignment order (align to 2^v_align)
 56 * @flags:	flags describing format applicability
 57 * @precision:  jpeg sample precision
 58 * @is_rgb:     is an RGB pixel format
 59 */
 60struct mxc_jpeg_fmt {
 61	const char				*name;
 62	u32					fourcc;
 63	enum v4l2_jpeg_chroma_subsampling	subsampling;
 64	int					nc;
 65	int					depth;
 66	int					mem_planes;
 67	int					comp_planes;
 68	int					h_align;
 69	int					v_align;
 70	u32					flags;
 71	u8					precision;
 72	u8					is_rgb;
 73};
 74
 75struct mxc_jpeg_desc {
 76	u32 next_descpt_ptr;
 77	u32 buf_base0;
 78	u32 buf_base1;
 79	u32 line_pitch;
 80	u32 stm_bufbase;
 81	u32 stm_bufsize;
 82	u32 imgsize;
 83	u32 stm_ctrl;
 84} __packed;
 85
 86struct mxc_jpeg_q_data {
 87	const struct mxc_jpeg_fmt	*fmt;
 88	u32				sizeimage[MXC_JPEG_MAX_PLANES];
 89	u32				bytesperline[MXC_JPEG_MAX_PLANES];
 90	int				w;
 91	int				w_adjusted;
 92	int				h;
 93	int				h_adjusted;
 94	unsigned int			sequence;
 95	struct v4l2_rect		crop;
 96};
 97
 98struct mxc_jpeg_ctx {
 99	struct mxc_jpeg_dev		*mxc_jpeg;
100	struct mxc_jpeg_q_data		out_q;
101	struct mxc_jpeg_q_data		cap_q;
102	struct v4l2_fh			fh;
103	enum mxc_jpeg_enc_state		enc_state;
104	int				slot;
105	unsigned int			source_change;
106	bool				need_initial_source_change_evt;
107	bool				header_parsed;
108	struct v4l2_ctrl_handler	ctrl_handler;
109	u8				jpeg_quality;
110	struct delayed_work		task_timer;
111};
112
113struct mxc_jpeg_slot_data {
114	int slot;
115	bool used;
116	struct mxc_jpeg_desc *desc; // enc/dec descriptor
117	struct mxc_jpeg_desc *cfg_desc; // configuration descriptor
118	void *cfg_stream_vaddr; // configuration bitstream virtual address
119	unsigned int cfg_stream_size;
120	dma_addr_t desc_handle;
121	dma_addr_t cfg_desc_handle; // configuration descriptor dma address
122	dma_addr_t cfg_stream_handle; // configuration bitstream dma address
123	dma_addr_t cfg_dec_size;
124	void *cfg_dec_vaddr;
125	dma_addr_t cfg_dec_daddr;
126};
127
128struct mxc_jpeg_dev {
129	spinlock_t			hw_lock; /* hardware access lock */
130	unsigned int			mode;
131	struct mutex			lock; /* v4l2 ioctls serialization */
132	struct clk_bulk_data		*clks;
133	int				num_clks;
134	struct platform_device		*pdev;
135	struct device			*dev;
136	void __iomem			*base_reg;
137	struct v4l2_device		v4l2_dev;
138	struct v4l2_m2m_dev		*m2m_dev;
139	struct video_device		*dec_vdev;
140	struct mxc_jpeg_slot_data	slot_data;
141	int				num_domains;
142	struct device			**pd_dev;
143	struct device_link		**pd_link;
144};
145
146/**
147 * struct mxc_jpeg_sof_comp - JPEG Start Of Frame component fields
148 * @id:				component id
149 * @v:				vertical sampling
150 * @h:				horizontal sampling
151 * @quantization_table_no:	id of quantization table
152 */
153struct mxc_jpeg_sof_comp {
154	u8 id;
155	u8 v :4;
156	u8 h :4;
157	u8 quantization_table_no;
158} __packed;
159
160#define MXC_JPEG_MAX_COMPONENTS 4
161/**
162 * struct mxc_jpeg_sof - JPEG Start Of Frame marker fields
163 * @length:		Start of Frame length
164 * @precision:		precision (bits per pixel per color component)
165 * @height:		image height
166 * @width:		image width
167 * @components_no:	number of color components
168 * @comp:		component fields for each color component
169 */
170struct mxc_jpeg_sof {
171	u16 length;
172	u8 precision;
173	u16 height, width;
174	u8 components_no;
175	struct mxc_jpeg_sof_comp comp[MXC_JPEG_MAX_COMPONENTS];
176} __packed;
177
178/**
179 * struct mxc_jpeg_sos_comp - JPEG Start Of Scan component fields
180 * @id:			component id
181 * @huffman_table_no:	id of the Huffman table
182 */
183struct mxc_jpeg_sos_comp {
184	u8 id; /*component id*/
185	u8 huffman_table_no;
186} __packed;
187
188/**
189 * struct mxc_jpeg_sos - JPEG Start Of Scan marker fields
190 * @length:		Start of Frame length
191 * @components_no:	number of color components
192 * @comp:		SOS component fields for each color component
193 * @ignorable_bytes:	ignorable bytes
194 */
195struct mxc_jpeg_sos {
196	u16 length;
197	u8 components_no;
198	struct mxc_jpeg_sos_comp comp[MXC_JPEG_MAX_COMPONENTS];
199	u8 ignorable_bytes[3];
200} __packed;
201
202#endif
~/ Read-only file preview.