brintos

brintos / linux-shallow public Read only

0
0
Text · 6.9 KiB · 4b665a3 Raw
258 lines · c
1/* SPDX-License-Identifier: GPL-2.0-only */2/* linux/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.h3 *4 * Copyright (c) 2011 Samsung Electronics Co., Ltd.5 *		http://www.samsung.com6 *7 * Author: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>8 */9 10#ifndef JPEG_CORE_H_11#define JPEG_CORE_H_12 13#include <linux/interrupt.h>14#include <media/jpeg.h>15#include <media/v4l2-device.h>16#include <media/v4l2-fh.h>17#include <media/v4l2-ctrls.h>18 19#define S5P_JPEG_M2M_NAME		"s5p-jpeg"20 21#define JPEG_MAX_CLOCKS			422 23/* JPEG compression quality setting */24#define S5P_JPEG_COMPR_QUAL_BEST	025#define S5P_JPEG_COMPR_QUAL_WORST	326 27/* JPEG RGB to YCbCr conversion matrix coefficients */28#define S5P_JPEG_COEF11			0x4d29#define S5P_JPEG_COEF12			0x9730#define S5P_JPEG_COEF13			0x1e31#define S5P_JPEG_COEF21			0x2c32#define S5P_JPEG_COEF22			0x5733#define S5P_JPEG_COEF23			0x8334#define S5P_JPEG_COEF31			0x8335#define S5P_JPEG_COEF32			0x6e36#define S5P_JPEG_COEF33			0x1337 38#define EXYNOS3250_IRQ_TIMEOUT		0x1000000039 40/* Flags that indicate a format can be used for capture/output */41#define SJPEG_FMT_FLAG_ENC_CAPTURE	(1 << 0)42#define SJPEG_FMT_FLAG_ENC_OUTPUT	(1 << 1)43#define SJPEG_FMT_FLAG_DEC_CAPTURE	(1 << 2)44#define SJPEG_FMT_FLAG_DEC_OUTPUT	(1 << 3)45#define SJPEG_FMT_FLAG_S5P		(1 << 4)46#define SJPEG_FMT_FLAG_EXYNOS3250	(1 << 5)47#define SJPEG_FMT_FLAG_EXYNOS4		(1 << 6)48#define SJPEG_FMT_RGB			(1 << 7)49#define SJPEG_FMT_NON_RGB		(1 << 8)50 51#define S5P_JPEG_ENCODE		052#define S5P_JPEG_DECODE		153#define S5P_JPEG_DISABLE	-154 55#define FMT_TYPE_OUTPUT		056#define FMT_TYPE_CAPTURE	157 58#define SJPEG_SUBSAMPLING_444	0x1159#define SJPEG_SUBSAMPLING_422	0x2160#define SJPEG_SUBSAMPLING_420	0x2261 62#define S5P_JPEG_MAX_MARKER	463 64/* Version numbers */65enum sjpeg_version {66	SJPEG_S5P,67	SJPEG_EXYNOS3250,68	SJPEG_EXYNOS4,69	SJPEG_EXYNOS5420,70	SJPEG_EXYNOS5433,71};72 73enum exynos4_jpeg_result {74	OK_ENC_OR_DEC,75	ERR_PROT,76	ERR_DEC_INVALID_FORMAT,77	ERR_MULTI_SCAN,78	ERR_FRAME,79	ERR_UNKNOWN,80};81 82enum  exynos4_jpeg_img_quality_level {83	QUALITY_LEVEL_1 = 0,	/* high */84	QUALITY_LEVEL_2,85	QUALITY_LEVEL_3,86	QUALITY_LEVEL_4,	/* low */87};88 89enum s5p_jpeg_ctx_state {90	JPEGCTX_RUNNING = 0,91	JPEGCTX_RESOLUTION_CHANGE,92};93 94/**95 * struct s5p_jpeg - JPEG IP abstraction96 * @lock:		the mutex protecting this structure97 * @slock:		spinlock protecting the device contexts98 * @v4l2_dev:		v4l2 device for mem2mem mode99 * @vfd_encoder:	video device node for encoder mem2mem mode100 * @vfd_decoder:	video device node for decoder mem2mem mode101 * @m2m_dev:		v4l2 mem2mem device data102 * @regs:		JPEG IP registers mapping103 * @irq:		JPEG IP irq104 * @irq_ret:		JPEG IP irq result value105 * @clocks:		JPEG IP clock(s)106 * @dev:		JPEG IP struct device107 * @variant:		driver variant to be used108 * @irq_status:		interrupt flags set during single encode/decode109 *			operation110 */111struct s5p_jpeg {112	struct mutex		lock;113	spinlock_t		slock;114 115	struct v4l2_device	v4l2_dev;116	struct video_device	*vfd_encoder;117	struct video_device	*vfd_decoder;118	struct v4l2_m2m_dev	*m2m_dev;119 120	void __iomem		*regs;121	unsigned int		irq;122	enum exynos4_jpeg_result irq_ret;123	struct clk		*clocks[JPEG_MAX_CLOCKS];124	struct device		*dev;125	struct s5p_jpeg_variant *variant;126	u32			irq_status;127};128 129struct s5p_jpeg_variant {130	unsigned int		version;131	unsigned int		fmt_ver_flag;132	unsigned int		hw3250_compat:1;133	unsigned int		htbl_reinit:1;134	unsigned int		hw_ex4_compat:1;135	const struct v4l2_m2m_ops *m2m_ops;136	irqreturn_t		(*jpeg_irq)(int irq, void *priv);137	const char		*clk_names[JPEG_MAX_CLOCKS];138	int			num_clocks;139};140 141/**142 * struct s5p_jpeg_fmt - driver's internal color format data143 * @fourcc:	the fourcc code, 0 if not applicable144 * @depth:	number of bits per pixel145 * @colplanes:	number of color planes (1 for packed formats)146 * @memplanes:	number of memory planes (1 for packed formats)147 * @h_align:	horizontal alignment order (align to 2^h_align)148 * @v_align:	vertical alignment order (align to 2^v_align)149 * @subsampling:subsampling of a raw format or a JPEG150 * @flags:	flags describing format applicability151 */152struct s5p_jpeg_fmt {153	u32	fourcc;154	int	depth;155	int	colplanes;156	int	memplanes;157	int	h_align;158	int	v_align;159	int	subsampling;160	u32	flags;161};162 163/**164 * struct s5p_jpeg_marker - collection of markers from jpeg header165 * @marker:	markers' positions relative to the buffer beginning166 * @len:	markers' payload lengths (without length field)167 * @n:		number of markers in collection168 */169struct s5p_jpeg_marker {170	u32	marker[S5P_JPEG_MAX_MARKER];171	u32	len[S5P_JPEG_MAX_MARKER];172	u32	n;173};174 175/**176 * struct s5p_jpeg_q_data - parameters of one queue177 * @fmt:	driver-specific format of this queue178 * @w:		image width179 * @h:		image height180 * @sos:	JPEG_MARKER_SOS's position relative to the buffer beginning181 * @dht:	JPEG_MARKER_DHT' positions relative to the buffer beginning182 * @dqt:	JPEG_MARKER_DQT' positions relative to the buffer beginning183 * @sof:	JPEG_MARKER_SOF0's position relative to the buffer beginning184 * @sof_len:	JPEG_MARKER_SOF0's payload length (without length field itself)185 * @size:	image buffer size in bytes186 */187struct s5p_jpeg_q_data {188	struct s5p_jpeg_fmt	*fmt;189	u32			w;190	u32			h;191	u32			sos;192	struct s5p_jpeg_marker	dht;193	struct s5p_jpeg_marker	dqt;194	u32			sof;195	u32			sof_len;196	u32			size;197};198 199/**200 * struct s5p_jpeg_ctx - the device context data201 * @jpeg:		JPEG IP device for this context202 * @mode:		compression (encode) operation or decompression (decode)203 * @compr_quality:	destination image quality in compression (encode) mode204 * @restart_interval:	JPEG restart interval for JPEG encoding205 * @subsampling:	subsampling of a raw format or a JPEG206 * @out_q:		source (output) queue information207 * @cap_q:		destination (capture) queue queue information208 * @scale_factor:	scale factor for JPEG decoding209 * @crop_rect:		a rectangle representing crop area of the output buffer210 * @fh:			V4L2 file handle211 * @hdr_parsed:		set if header has been parsed during decompression212 * @crop_altered:	set if crop rectangle has been altered by the user space213 * @ctrl_handler:	controls handler214 * @state:		state of the context215 */216struct s5p_jpeg_ctx {217	struct s5p_jpeg		*jpeg;218	unsigned int		mode;219	unsigned short		compr_quality;220	unsigned short		restart_interval;221	unsigned short		subsampling;222	struct s5p_jpeg_q_data	out_q;223	struct s5p_jpeg_q_data	cap_q;224	unsigned int		scale_factor;225	struct v4l2_rect	crop_rect;226	struct v4l2_fh		fh;227	bool			hdr_parsed;228	bool			crop_altered;229	struct v4l2_ctrl_handler ctrl_handler;230	enum s5p_jpeg_ctx_state	state;231};232 233/**234 * struct s5p_jpeg_buffer - description of memory containing input JPEG data235 * @size:	buffer size236 * @curr:	current position in the buffer237 * @data:	pointer to the data238 */239struct s5p_jpeg_buffer {240	unsigned long size;241	unsigned long curr;242	unsigned long data;243};244 245/**246 * struct s5p_jpeg_addr - JPEG converter physical address set for DMA247 * @y:   luminance plane physical address248 * @cb:  Cb plane physical address249 * @cr:  Cr plane physical address250 */251struct s5p_jpeg_addr {252	u32     y;253	u32     cb;254	u32     cr;255};256 257#endif /* JPEG_CORE_H */258